1 /* $FreeBSD: head/sys/dev/iwn/if_iwnvar.h 258035 2013-11-12 05:58:23Z adrian $ */ 2 /* $OpenBSD: if_iwnvar.h,v 1.18 2010/04/30 16:06:46 damien Exp $ */ 3 4 /*- 5 * Copyright (c) 2013 Cedric GROSS <cg@cgross.info> 6 * Copyright (c) 2011 Intel Corporation 7 * Copyright (c) 2007, 2008 8 * Damien Bergamini <damien.bergamini@free.fr> 9 * Copyright (c) 2008 Sam Leffler, Errno Consulting 10 * 11 * Permission to use, copy, modify, and distribute this software for any 12 * purpose with or without fee is hereby granted, provided that the above 13 * copyright notice and this permission notice appear in all copies. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 */ 23 24 #include <netproto/802_11/ieee80211_amrr.h> 25 26 enum iwn_rxon_ctx_id { 27 IWN_RXON_BSS_CTX, 28 IWN_RXON_PAN_CTX, 29 IWN_NUM_RXON_CTX 30 }; 31 32 struct iwn_pan_slot { 33 uint16_t time; 34 uint8_t type; 35 uint8_t reserved; 36 } __packed; 37 38 struct iwn_pan_params_cmd { 39 uint16_t flags; 40 #define IWN_PAN_PARAMS_FLG_SLOTTED_MODE (1 << 3) 41 42 uint8_t reserved; 43 uint8_t num_slots; 44 struct iwn_pan_slot slots[10]; 45 } __packed; 46 47 struct iwn_led_mode 48 { 49 uint8_t led_cur_mode; 50 uint64_t led_cur_bt; 51 uint64_t led_last_bt; 52 uint64_t led_cur_tpt; 53 uint64_t led_last_tpt; 54 uint64_t led_bt_diff; 55 int led_cur_time; 56 int led_last_time; 57 }; 58 59 struct iwn_rx_radiotap_header { 60 struct ieee80211_radiotap_header wr_ihdr; 61 uint64_t wr_tsft; 62 uint8_t wr_flags; 63 uint8_t wr_rate; 64 uint16_t wr_chan_freq; 65 uint16_t wr_chan_flags; 66 int8_t wr_dbm_antsignal; 67 int8_t wr_dbm_antnoise; 68 } __packed; 69 70 #define IWN_RX_RADIOTAP_PRESENT \ 71 ((1 << IEEE80211_RADIOTAP_TSFT) | \ 72 (1 << IEEE80211_RADIOTAP_FLAGS) | \ 73 (1 << IEEE80211_RADIOTAP_RATE) | \ 74 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 75 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \ 76 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)) 77 78 struct iwn_tx_radiotap_header { 79 struct ieee80211_radiotap_header wt_ihdr; 80 uint8_t wt_flags; 81 uint8_t wt_rate; 82 uint16_t wt_chan_freq; 83 uint16_t wt_chan_flags; 84 } __packed; 85 86 #define IWN_TX_RADIOTAP_PRESENT \ 87 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 88 (1 << IEEE80211_RADIOTAP_RATE) | \ 89 (1 << IEEE80211_RADIOTAP_CHANNEL)) 90 91 struct iwn_dma_info { 92 bus_dma_tag_t tag; 93 bus_dmamap_t map; 94 bus_dma_segment_t seg; 95 bus_addr_t paddr; 96 caddr_t vaddr; 97 bus_size_t size; 98 }; 99 100 struct iwn_tx_data { 101 bus_dmamap_t map; 102 bus_addr_t cmd_paddr; 103 bus_addr_t scratch_paddr; 104 struct mbuf *m; 105 struct ieee80211_node *ni; 106 }; 107 108 struct iwn_tx_ring { 109 struct iwn_dma_info desc_dma; 110 struct iwn_dma_info cmd_dma; 111 struct iwn_tx_desc *desc; 112 struct iwn_tx_cmd *cmd; 113 struct iwn_tx_data data[IWN_TX_RING_COUNT]; 114 bus_dma_tag_t data_dmat; 115 int qid; 116 int queued; 117 int cur; 118 int read; 119 }; 120 121 struct iwn_amrr { 122 struct ieee80211_node ni; /* must be the first */ 123 int txcnt; 124 int retrycnt; 125 int success; 126 int success_threshold; 127 int recovery; 128 }; 129 130 struct iwn_softc; 131 132 struct iwn_rx_data { 133 struct mbuf *m; 134 bus_dmamap_t map; 135 }; 136 137 struct iwn_rx_ring { 138 struct iwn_dma_info desc_dma; 139 struct iwn_dma_info stat_dma; 140 uint32_t *desc; 141 struct iwn_rx_status *stat; 142 struct iwn_rx_data data[IWN_RX_RING_COUNT]; 143 bus_dma_tag_t data_dmat; 144 int cur; 145 }; 146 147 struct iwn_node { 148 struct ieee80211_node ni; /* must be the first */ 149 uint16_t disable_tid; 150 uint8_t id; 151 struct { 152 uint64_t bitmap; 153 int startidx; 154 int nframes; 155 } agg[IEEE80211_TID_SIZE]; 156 struct ieee80211_amrr_node amn; 157 }; 158 159 struct iwn_calib_state { 160 uint8_t state; 161 #define IWN_CALIB_STATE_INIT 0 162 #define IWN_CALIB_STATE_ASSOC 1 163 #define IWN_CALIB_STATE_RUN 2 164 165 u_int nbeacons; 166 uint32_t noise[3]; 167 uint32_t rssi[3]; 168 uint32_t ofdm_x1; 169 uint32_t ofdm_mrc_x1; 170 uint32_t ofdm_x4; 171 uint32_t ofdm_mrc_x4; 172 uint32_t cck_x4; 173 uint32_t cck_mrc_x4; 174 uint32_t bad_plcp_ofdm; 175 uint32_t fa_ofdm; 176 uint32_t bad_plcp_cck; 177 uint32_t fa_cck; 178 uint32_t low_fa; 179 uint32_t bad_plcp_ht; 180 uint8_t cck_state; 181 #define IWN_CCK_STATE_INIT 0 182 #define IWN_CCK_STATE_LOFA 1 183 #define IWN_CCK_STATE_HIFA 2 184 185 uint8_t noise_samples[20]; 186 u_int cur_noise_sample; 187 uint8_t noise_ref; 188 uint32_t energy_samples[10]; 189 u_int cur_energy_sample; 190 uint32_t energy_cck; 191 }; 192 193 struct iwn_calib_info { 194 uint8_t *buf; 195 u_int len; 196 }; 197 198 struct iwn_fw_part { 199 const uint8_t *text; 200 uint32_t textsz; 201 const uint8_t *data; 202 uint32_t datasz; 203 }; 204 205 struct iwn_fw_info { 206 const uint8_t *data; 207 size_t size; 208 struct iwn_fw_part init; 209 struct iwn_fw_part main; 210 struct iwn_fw_part boot; 211 }; 212 213 struct iwn_ops { 214 int (*load_firmware)(struct iwn_softc *); 215 void (*read_eeprom)(struct iwn_softc *); 216 int (*post_alive)(struct iwn_softc *); 217 int (*nic_config)(struct iwn_softc *); 218 void (*update_sched)(struct iwn_softc *, int, int, uint8_t, 219 uint16_t); 220 int (*get_temperature)(struct iwn_softc *); 221 int (*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *); 222 int (*set_txpower)(struct iwn_softc *, 223 struct ieee80211_channel *, int); 224 int (*init_gains)(struct iwn_softc *); 225 int (*set_gains)(struct iwn_softc *); 226 int (*add_node)(struct iwn_softc *, struct iwn_node_info *, 227 int); 228 void (*tx_done)(struct iwn_softc *, struct iwn_rx_desc *, 229 struct iwn_rx_data *); 230 void (*ampdu_tx_start)(struct iwn_softc *, 231 struct ieee80211_node *, int, uint8_t, uint16_t); 232 void (*ampdu_tx_stop)(struct iwn_softc *, int, uint8_t, 233 uint16_t); 234 }; 235 236 struct iwn_vap { 237 struct ieee80211vap iv_vap; 238 uint8_t iv_ridx; 239 240 int (*iv_newstate)(struct ieee80211vap *, 241 enum ieee80211_state, int); 242 struct ieee80211_amrr_node iv_amrr; 243 int ctx; 244 int beacon_int; 245 uint8_t macaddr[IEEE80211_ADDR_LEN]; 246 247 }; 248 #define IWN_VAP(_vap) ((struct iwn_vap *)(_vap)) 249 250 struct iwn_softc { 251 struct arpcom arpcom; 252 device_t sc_dev; 253 254 struct ifnet *sc_ifp; 255 int sc_debug; 256 257 struct mtx sc_mtx; 258 259 u_int sc_flags; 260 #define IWN_FLAG_HAS_OTPROM (1 << 1) 261 #define IWN_FLAG_CALIB_DONE (1 << 2) 262 #define IWN_FLAG_USE_ICT (1 << 3) 263 #define IWN_FLAG_INTERNAL_PA (1 << 4) 264 #define IWN_FLAG_HAS_11N (1 << 6) 265 #define IWN_FLAG_ENH_SENS (1 << 7) 266 #define IWN_FLAG_ADV_BTCOEX (1 << 8) 267 #define IWN_FLAG_PAN_SUPPORT (1 << 9) 268 #define IWN_FLAG_BTCOEX (1 << 10) 269 270 uint8_t hw_type; 271 /* subdevice_id used to adjust configuration */ 272 uint16_t subdevice_id; 273 274 struct iwn_ops ops; 275 const char *fwname; 276 const struct iwn_sensitivity_limits 277 *limits; 278 int ntxqs; 279 int firstaggqueue; 280 int ndmachnls; 281 uint8_t broadcast_id; 282 int rxonsz; 283 int schedsz; 284 uint32_t fw_text_maxsz; 285 uint32_t fw_data_maxsz; 286 uint32_t fwsz; 287 bus_size_t sched_txfact_addr; 288 uint32_t reset_noise_gain; 289 uint32_t noise_gain; 290 291 /* TX scheduler rings. */ 292 struct iwn_dma_info sched_dma; 293 uint16_t *sched; 294 uint32_t sched_base; 295 296 /* "Keep Warm" page. */ 297 struct iwn_dma_info kw_dma; 298 299 /* Firmware image. */ 300 const struct firmware *fw_fp; 301 302 /* Firmware DMA transfer. */ 303 struct iwn_dma_info fw_dma; 304 305 /* ICT table. */ 306 struct iwn_dma_info ict_dma; 307 uint32_t *ict; 308 int ict_cur; 309 310 /* TX/RX rings. */ 311 struct iwn_tx_ring txq[IWN5000_NTXQUEUES]; 312 struct iwn_rx_ring rxq; 313 314 struct resource *mem; 315 bus_space_tag_t sc_st; 316 bus_space_handle_t sc_sh; 317 struct resource *irq; 318 bus_dma_tag_t sc_dmat; 319 void *sc_ih; 320 bus_size_t sc_sz; 321 int sc_cap_off; /* PCIe Capabilities. */ 322 323 /* Tasks used by the driver */ 324 struct task sc_reinit_task; 325 struct task sc_radioon_task; 326 struct task sc_radiooff_task; 327 struct task sc_panic_task; 328 329 /* Taskqueue */ 330 struct taskqueue *sc_tq; 331 332 /* Calibration information */ 333 struct callout calib_to; 334 int calib_cnt; 335 struct iwn_calib_state calib; 336 int last_calib_ticks; 337 struct callout watchdog_to; 338 struct callout ct_kill_exit_to; 339 struct iwn_fw_info fw; 340 struct iwn_calib_info calibcmd[IWN5000_PHY_CALIB_MAX_RESULT]; 341 uint32_t errptr; 342 343 struct iwn_rx_stat last_rx_stat; 344 int last_rx_valid; 345 struct iwn_ucode_info ucode_info; 346 struct iwn_rxon rx_on[IWN_NUM_RXON_CTX]; 347 struct iwn_rxon *rxon; 348 int ctx; 349 struct ieee80211vap *ivap[IWN_NUM_RXON_CTX]; 350 351 /* General statistics */ 352 /* 353 * The statistics are reset after each channel 354 * change. So it may be zeroed after things like 355 * a background scan. 356 * 357 * So for now, this is just a cheap hack to 358 * expose the last received statistics dump 359 * via an ioctl(). Later versions of this 360 * could expose the last 'n' messages, or just 361 * provide a pipeline for the firmware responses 362 * via something like BPF. 363 */ 364 struct iwn_stats last_stat; 365 int last_stat_valid; 366 367 uint8_t uc_scan_progress; 368 uint32_t rawtemp; 369 int temp; 370 int noise; 371 uint32_t qfullmsk; 372 373 uint32_t prom_base; 374 struct iwn4965_eeprom_band 375 bands[IWN_NBANDS]; 376 struct iwn_eeprom_chan eeprom_channels[IWN_NBANDS][IWN_MAX_CHAN_PER_BAND]; 377 uint16_t rfcfg; 378 uint8_t calib_ver; 379 char eeprom_domain[4]; 380 uint32_t eeprom_crystal; 381 int16_t eeprom_temp; 382 int16_t eeprom_temp_high; 383 int16_t eeprom_voltage; 384 int8_t maxpwr2GHz; 385 int8_t maxpwr5GHz; 386 int8_t maxpwr[IEEE80211_CHAN_MAX]; 387 388 uint32_t tlv_feature_flags; 389 390 int32_t temp_off; 391 uint32_t int_mask; 392 uint8_t ntxchains; 393 uint8_t nrxchains; 394 uint8_t txchainmask; 395 uint8_t rxchainmask; 396 uint8_t chainmask; 397 398 int sc_tx_timer; 399 int sc_scan_timer; 400 401 /* Are we doing a scan? */ 402 int sc_is_scanning; 403 404 struct ieee80211_tx_ampdu *qid2tap[IWN5000_NTXQUEUES]; 405 406 int (*sc_ampdu_rx_start)(struct ieee80211_node *, 407 struct ieee80211_rx_ampdu *, int, int, int); 408 void (*sc_ampdu_rx_stop)(struct ieee80211_node *, 409 struct ieee80211_rx_ampdu *); 410 int (*sc_addba_request)(struct ieee80211_node *, 411 struct ieee80211_tx_ampdu *, int, int, int); 412 int (*sc_addba_response)(struct ieee80211_node *, 413 struct ieee80211_tx_ampdu *, int, int, int); 414 void (*sc_addba_stop)(struct ieee80211_node *, 415 struct ieee80211_tx_ampdu *); 416 417 struct iwn_led_mode sc_led; 418 419 struct iwn_rx_radiotap_header sc_rxtap; 420 struct iwn_tx_radiotap_header sc_txtap; 421 422 /* The power save level originally configured by user */ 423 int desired_pwrsave_level; 424 425 /* 426 * The current power save level, this may differ from the 427 * configured value due to thermal throttling etc. 428 */ 429 int current_pwrsave_level; 430 431 /* For specific params */ 432 const struct iwn_base_params *base_params; 433 struct sysctl_ctx_list sc_sysctl_ctx; 434 struct sysctl_oid *sc_sysctl_tree; 435 }; 436