1 /* $OpenBSD: if_iwnvar.h,v 1.42 2021/11/12 11:41:04 stsp Exp $ */ 2 3 /*- 4 * Copyright (c) 2007, 2008 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 struct iwn_rx_radiotap_header { 21 struct ieee80211_radiotap_header wr_ihdr; 22 uint64_t wr_tsft; 23 uint8_t wr_flags; 24 uint8_t wr_rate; 25 uint16_t wr_chan_freq; 26 uint16_t wr_chan_flags; 27 int8_t wr_dbm_antsignal; 28 int8_t wr_dbm_antnoise; 29 } __packed; 30 31 #define IWN_RX_RADIOTAP_PRESENT \ 32 ((1 << IEEE80211_RADIOTAP_TSFT) | \ 33 (1 << IEEE80211_RADIOTAP_FLAGS) | \ 34 (1 << IEEE80211_RADIOTAP_RATE) | \ 35 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 36 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \ 37 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)) 38 39 struct iwn_tx_radiotap_header { 40 struct ieee80211_radiotap_header wt_ihdr; 41 uint8_t wt_flags; 42 uint8_t wt_rate; 43 uint16_t wt_chan_freq; 44 uint16_t wt_chan_flags; 45 } __packed; 46 47 #define IWN_TX_RADIOTAP_PRESENT \ 48 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 49 (1 << IEEE80211_RADIOTAP_RATE) | \ 50 (1 << IEEE80211_RADIOTAP_CHANNEL)) 51 52 struct iwn_dma_info { 53 bus_dma_tag_t tag; 54 bus_dmamap_t map; 55 bus_dma_segment_t seg; 56 bus_addr_t paddr; 57 caddr_t vaddr; 58 bus_size_t size; 59 }; 60 61 struct iwn_tx_data { 62 bus_dmamap_t map; 63 bus_addr_t cmd_paddr; 64 bus_addr_t scratch_paddr; 65 struct mbuf *m; 66 struct ieee80211_node *ni; 67 int totlen; 68 69 /* A-MPDU subframes */ 70 int ampdu_txmcs; 71 int ampdu_nframes; 72 }; 73 74 struct iwn_tx_ring { 75 struct iwn_dma_info desc_dma; 76 struct iwn_dma_info cmd_dma; 77 struct iwn_tx_desc *desc; 78 struct iwn_tx_cmd *cmd; 79 struct iwn_tx_data data[IWN_TX_RING_COUNT]; 80 int qid; 81 int queued; 82 int cur; 83 int read; 84 }; 85 86 struct iwn_softc; 87 88 struct iwn_rx_data { 89 struct mbuf *m; 90 bus_dmamap_t map; 91 }; 92 93 struct iwn_rx_ring { 94 struct iwn_dma_info desc_dma; 95 struct iwn_dma_info stat_dma; 96 uint32_t *desc; 97 struct iwn_rx_status *stat; 98 struct iwn_rx_data data[IWN_RX_RING_COUNT]; 99 int cur; 100 }; 101 102 struct iwn_node { 103 struct ieee80211_node ni; /* must be the first */ 104 struct ieee80211_amrr_node amn; 105 struct ieee80211_ra_node rn; 106 uint16_t disable_tid; 107 uint8_t id; 108 uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 109 uint32_t next_ampdu_id; 110 int lq_rate_mismatch; 111 }; 112 113 struct iwn_calib_state { 114 uint8_t state; 115 #define IWN_CALIB_STATE_INIT 0 116 #define IWN_CALIB_STATE_ASSOC 1 117 #define IWN_CALIB_STATE_RUN 2 118 119 u_int nbeacons; 120 uint32_t noise[3]; 121 uint32_t rssi[3]; 122 uint32_t ofdm_x1; 123 uint32_t ofdm_mrc_x1; 124 uint32_t ofdm_x4; 125 uint32_t ofdm_mrc_x4; 126 uint32_t cck_x4; 127 uint32_t cck_mrc_x4; 128 uint32_t bad_plcp_ofdm; 129 uint32_t fa_ofdm; 130 uint32_t bad_plcp_cck; 131 uint32_t fa_cck; 132 uint32_t low_fa; 133 uint8_t cck_state; 134 #define IWN_CCK_STATE_INIT 0 135 #define IWN_CCK_STATE_LOFA 1 136 #define IWN_CCK_STATE_HIFA 2 137 138 uint8_t noise_samples[20]; 139 u_int cur_noise_sample; 140 uint8_t noise_ref; 141 uint32_t energy_samples[10]; 142 u_int cur_energy_sample; 143 uint32_t energy_cck; 144 }; 145 146 struct iwn_calib_info { 147 uint8_t *buf; 148 u_int len; 149 }; 150 151 struct iwn_fw_part { 152 const uint8_t *text; 153 uint32_t textsz; 154 const uint8_t *data; 155 uint32_t datasz; 156 }; 157 158 struct iwn_fw_info { 159 u_char *data; 160 size_t size; 161 struct iwn_fw_part init; 162 struct iwn_fw_part main; 163 struct iwn_fw_part boot; 164 }; 165 166 struct iwn_ops { 167 int (*load_firmware)(struct iwn_softc *); 168 void (*read_eeprom)(struct iwn_softc *); 169 int (*post_alive)(struct iwn_softc *); 170 int (*nic_config)(struct iwn_softc *); 171 void (*reset_sched)(struct iwn_softc *, int, int); 172 void (*update_sched)(struct iwn_softc *, int, int, uint8_t, 173 uint16_t); 174 void (*update_rxon)(struct iwn_softc *); 175 int (*get_temperature)(struct iwn_softc *); 176 int (*get_rssi)(const struct iwn_rx_stat *); 177 int (*set_txpower)(struct iwn_softc *, int); 178 int (*init_gains)(struct iwn_softc *); 179 int (*set_gains)(struct iwn_softc *); 180 int (*add_node)(struct iwn_softc *, struct iwn_node_info *, 181 int); 182 void (*tx_done)(struct iwn_softc *, struct iwn_rx_desc *, 183 struct iwn_rx_data *); 184 void (*ampdu_tx_start)(struct iwn_softc *, 185 struct ieee80211_node *, uint8_t, uint16_t); 186 void (*ampdu_tx_stop)(struct iwn_softc *, uint8_t, 187 uint16_t); 188 }; 189 190 struct iwn_tx_ba { 191 struct iwn_node * wn; 192 }; 193 194 struct iwn_softc { 195 struct device sc_dev; 196 197 struct ieee80211com sc_ic; 198 int (*sc_newstate)(struct ieee80211com *, 199 enum ieee80211_state, int); 200 201 struct ieee80211_amrr amrr; 202 uint8_t fixed_ridx; 203 204 bus_dma_tag_t sc_dmat; 205 206 struct rwlock sc_rwlock; 207 u_int sc_flags; 208 #define IWN_FLAG_HAS_5GHZ (1 << 0) 209 #define IWN_FLAG_HAS_OTPROM (1 << 1) 210 #define IWN_FLAG_CALIB_DONE (1 << 2) 211 #define IWN_FLAG_USE_ICT (1 << 3) 212 #define IWN_FLAG_INTERNAL_PA (1 << 4) 213 #define IWN_FLAG_HAS_11N (1 << 6) 214 #define IWN_FLAG_ENH_SENS (1 << 7) 215 #define IWN_FLAG_ADV_BT_COEX (1 << 8) 216 #define IWN_FLAG_BGSCAN (1 << 9) 217 #define IWN_FLAG_SCANNING (1 << 10) 218 219 uint8_t hw_type; 220 221 struct iwn_ops ops; 222 const char *fwname; 223 const struct iwn_sensitivity_limits 224 *limits; 225 int ntxqs; 226 int first_agg_txq; 227 int agg_queue_mask; 228 int ndmachnls; 229 uint8_t broadcast_id; 230 int rxonsz; 231 int schedsz; 232 uint32_t fw_text_maxsz; 233 uint32_t fw_data_maxsz; 234 uint32_t fwsz; 235 bus_size_t sched_txfact_addr; 236 237 /* TX scheduler rings. */ 238 struct iwn_dma_info sched_dma; 239 uint16_t *sched; 240 uint32_t sched_base; 241 242 /* "Keep Warm" page. */ 243 struct iwn_dma_info kw_dma; 244 245 /* Firmware DMA transfer. */ 246 struct iwn_dma_info fw_dma; 247 248 /* ICT table. */ 249 struct iwn_dma_info ict_dma; 250 uint32_t *ict; 251 int ict_cur; 252 253 /* TX/RX rings. */ 254 struct iwn_tx_ring txq[IWN5000_NTXQUEUES]; 255 struct iwn_rx_ring rxq; 256 257 bus_space_tag_t sc_st; 258 bus_space_handle_t sc_sh; 259 void *sc_ih; 260 pci_chipset_tag_t sc_pct; 261 pcitag_t sc_pcitag; 262 bus_size_t sc_sz; 263 int sc_cap_off; /* PCIe Capabilities. */ 264 265 struct timeout calib_to; 266 int calib_cnt; 267 struct iwn_calib_state calib; 268 269 struct task init_task; 270 271 struct iwn_fw_info fw; 272 struct iwn_calib_info calibcmd[5]; 273 uint32_t errptr; 274 275 uint8_t bss_node_addr[IEEE80211_ADDR_LEN]; 276 277 struct iwn_rx_stat last_rx_stat; 278 int last_rx_valid; 279 #define IWN_LAST_RX_VALID 0x01 280 #define IWN_LAST_RX_AMPDU 0x02 281 struct iwn_ucode_info ucode_info; 282 struct iwn_rxon rxon; 283 uint32_t rx_stats_flags; 284 uint32_t rawtemp; 285 int temp; 286 int noise; 287 uint32_t qfullmsk; 288 289 uint32_t prom_base; 290 struct iwn4965_eeprom_band 291 bands[IWN_NBANDS]; 292 uint16_t rfcfg; 293 uint8_t calib_ver; 294 char eeprom_domain[4]; 295 uint32_t eeprom_crystal; 296 int16_t eeprom_temp; 297 int16_t eeprom_voltage; 298 int16_t eeprom_rawtemp; 299 int8_t maxpwr2GHz; 300 int8_t maxpwr5GHz; 301 int8_t maxpwr[IEEE80211_CHAN_MAX]; 302 int8_t maxpwr40[IEEE80211_CHAN_MAX]; 303 int8_t enh_maxpwr[35]; 304 305 uint8_t reset_noise_gain; 306 uint8_t noise_gain; 307 308 uint32_t tlv_feature_flags; 309 310 int32_t temp_off; 311 uint32_t int_mask; 312 uint8_t ntxchains; 313 uint8_t nrxchains; 314 uint8_t txchainmask; 315 uint8_t rxchainmask; 316 uint8_t chainmask; 317 318 int sc_tx_timer; 319 320 struct iwn_tx_ba sc_tx_ba[IEEE80211_NUM_TID]; 321 322 #if NBPFILTER > 0 323 caddr_t sc_drvbpf; 324 325 union { 326 struct iwn_rx_radiotap_header th; 327 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 328 } sc_rxtapu; 329 #define sc_rxtap sc_rxtapu.th 330 int sc_rxtap_len; 331 332 union { 333 struct iwn_tx_radiotap_header th; 334 uint8_t pad[IEEE80211_RADIOTAP_HDRLEN]; 335 } sc_txtapu; 336 #define sc_txtap sc_txtapu.th 337 int sc_txtap_len; 338 #endif 339 }; 340