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