1 /* $FreeBSD$ */ 2 /* $OpenBSD: if_iwnvar.h,v 1.12 2009/05/29 08:25:45 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 struct iwn_rx_radiotap_header { 23 struct ieee80211_radiotap_header wr_ihdr; 24 uint64_t wr_tsft; 25 uint8_t wr_flags; 26 uint8_t wr_rate; 27 uint16_t wr_chan_freq; 28 uint16_t wr_chan_flags; 29 int8_t wr_dbm_antsignal; 30 int8_t wr_dbm_antnoise; 31 } __packed; 32 33 #define IWN_RX_RADIOTAP_PRESENT \ 34 ((1 << IEEE80211_RADIOTAP_TSFT) | \ 35 (1 << IEEE80211_RADIOTAP_FLAGS) | \ 36 (1 << IEEE80211_RADIOTAP_RATE) | \ 37 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 38 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \ 39 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)) 40 41 struct iwn_tx_radiotap_header { 42 struct ieee80211_radiotap_header wt_ihdr; 43 uint8_t wt_flags; 44 uint8_t wt_rate; 45 uint16_t wt_chan_freq; 46 uint16_t wt_chan_flags; 47 } __packed; 48 49 #define IWN_TX_RADIOTAP_PRESENT \ 50 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 51 (1 << IEEE80211_RADIOTAP_RATE) | \ 52 (1 << IEEE80211_RADIOTAP_CHANNEL)) 53 54 struct iwn_dma_info { 55 bus_dma_tag_t tag; 56 bus_dmamap_t map; 57 bus_dma_segment_t seg; 58 bus_addr_t paddr; 59 caddr_t vaddr; 60 bus_size_t size; 61 }; 62 63 struct iwn_tx_data { 64 bus_dmamap_t map; 65 bus_addr_t cmd_paddr; 66 bus_addr_t scratch_paddr; 67 struct mbuf *m; 68 struct ieee80211_node *ni; 69 }; 70 71 struct iwn_tx_ring { 72 struct iwn_dma_info desc_dma; 73 struct iwn_dma_info cmd_dma; 74 struct iwn_tx_desc *desc; 75 struct iwn_tx_cmd *cmd; 76 struct iwn_tx_data data[IWN_TX_RING_COUNT]; 77 int qid; 78 int queued; 79 int cur; 80 }; 81 82 struct iwn_softc; 83 84 struct iwn_rx_data { 85 struct mbuf *m; 86 bus_dmamap_t map; 87 }; 88 89 struct iwn_rx_ring { 90 struct iwn_dma_info desc_dma; 91 struct iwn_dma_info stat_dma; 92 uint32_t *desc; 93 struct iwn_rx_status *stat; 94 struct iwn_rx_data data[IWN_RX_RING_COUNT]; 95 int cur; 96 }; 97 98 struct iwn_node { 99 struct ieee80211_node ni; /* must be the first */ 100 #define IWN_NODE(_ni) ((struct iwn_node *)(_ni)) 101 102 struct ieee80211_amrr_node amn; 103 uint16_t disable_tid; 104 uint8_t id; 105 uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 106 }; 107 108 struct iwn_calib_state { 109 uint8_t state; 110 #define IWN_CALIB_STATE_INIT 0 111 #define IWN_CALIB_STATE_ASSOC 1 112 #define IWN_CALIB_STATE_RUN 2 113 114 u_int nbeacons; 115 uint32_t noise[3]; 116 uint32_t rssi[3]; 117 uint32_t ofdm_x1; 118 uint32_t ofdm_mrc_x1; 119 uint32_t ofdm_x4; 120 uint32_t ofdm_mrc_x4; 121 uint32_t cck_x4; 122 uint32_t cck_mrc_x4; 123 uint32_t bad_plcp_ofdm; 124 uint32_t fa_ofdm; 125 uint32_t bad_plcp_cck; 126 uint32_t fa_cck; 127 uint32_t low_fa; 128 uint8_t cck_state; 129 #define IWN_CCK_STATE_INIT 0 130 #define IWN_CCK_STATE_LOFA 1 131 #define IWN_CCK_STATE_HIFA 2 132 133 uint8_t noise_samples[20]; 134 u_int cur_noise_sample; 135 uint8_t noise_ref; 136 uint32_t energy_samples[10]; 137 u_int cur_energy_sample; 138 uint32_t energy_cck; 139 }; 140 141 struct iwn_calib_info { 142 uint8_t *buf; 143 u_int len; 144 }; 145 146 struct iwn_fw_part { 147 const uint8_t *text; 148 uint32_t textsz; 149 const uint8_t *data; 150 uint32_t datasz; 151 }; 152 153 struct iwn_fw_info { 154 u_char *data; 155 struct iwn_fw_part init; 156 struct iwn_fw_part main; 157 struct iwn_fw_part boot; 158 }; 159 160 struct iwn_hal { 161 int (*load_firmware)(struct iwn_softc *); 162 void (*read_eeprom)(struct iwn_softc *); 163 int (*post_alive)(struct iwn_softc *); 164 int (*apm_init)(struct iwn_softc *); 165 int (*nic_config)(struct iwn_softc *); 166 void (*update_sched)(struct iwn_softc *, int, int, uint8_t, 167 uint16_t); 168 int (*get_temperature)(struct iwn_softc *); 169 int (*get_rssi)(struct iwn_softc *, struct iwn_rx_stat *); 170 int (*set_txpower)(struct iwn_softc *, 171 struct ieee80211_channel *, int); 172 int (*init_gains)(struct iwn_softc *); 173 int (*set_gains)(struct iwn_softc *); 174 int (*add_node)(struct iwn_softc *, struct iwn_node_info *, 175 int); 176 void (*tx_done)(struct iwn_softc *, struct iwn_rx_desc *, 177 struct iwn_rx_data *); 178 const struct iwn_sensitivity_limits *limits; 179 int ntxqs; 180 int ndmachnls; 181 uint8_t broadcast_id; 182 int rxonsz; 183 int schedsz; 184 uint32_t fw_text_maxsz; 185 uint32_t fw_data_maxsz; 186 uint32_t fwsz; 187 bus_size_t sched_txfact_addr; 188 }; 189 190 struct iwn_vap { 191 struct ieee80211vap iv_vap; 192 struct ieee80211_amrr iv_amrr; 193 struct callout iv_amrr_to; 194 uint8_t iv_ridx; 195 196 int (*iv_newstate)(struct ieee80211vap *, 197 enum ieee80211_state, int); 198 }; 199 #define IWN_VAP(_vap) ((struct iwn_vap *)(_vap)) 200 201 struct iwn_softc { 202 struct ifnet *sc_ifp; 203 int sc_debug; 204 205 /* locks */ 206 struct mtx sc_mtx; 207 208 /* Bus */ 209 device_t sc_dev; 210 int mem_rid; 211 int irq_rid; 212 struct resource *mem; 213 struct resource *irq; 214 215 u_int sc_flags; 216 #define IWN_FLAG_HAS_5GHZ (1 << 0) 217 #define IWN_FLAG_HAS_OTPROM (1 << 1) 218 #define IWN_FLAG_FIRST_BOOT (1 << 2) 219 220 uint8_t hw_type; 221 const struct iwn_hal *sc_hal; 222 const char *fwname; 223 224 /* TX scheduler rings. */ 225 struct iwn_dma_info sched_dma; 226 uint16_t *sched; 227 uint32_t sched_base; 228 229 /* "Keep Warm" page. */ 230 struct iwn_dma_info kw_dma; 231 232 /* Firmware image. */ 233 const struct firmware *fw_fp; 234 235 /* Firmware DMA transfer. */ 236 struct iwn_dma_info fw_dma; 237 238 /* TX/RX rings. */ 239 struct iwn_tx_ring txq[IWN5000_NTXQUEUES]; 240 struct iwn_rx_ring rxq; 241 242 bus_space_tag_t sc_st; 243 bus_space_handle_t sc_sh; 244 void *sc_ih; 245 bus_size_t sc_sz; 246 int sc_cap_off; /* PCIe Capabilities. */ 247 248 /* Tasks used by the driver */ 249 struct task sc_reinit_task; 250 struct task sc_radioon_task; 251 struct task sc_radiooff_task; 252 253 int calib_cnt; 254 struct iwn_calib_state calib; 255 256 struct iwn_fw_info fw; 257 struct iwn_calib_info calibcmd[5]; 258 uint32_t errptr; 259 260 struct iwn_rx_stat last_rx_stat; 261 int last_rx_valid; 262 struct iwn_ucode_info ucode_info; 263 struct iwn_rxon rxon; 264 uint32_t rawtemp; 265 int temp; 266 int noise; 267 uint32_t qfullmsk; 268 269 struct iwn4965_eeprom_band 270 bands[IWN_NBANDS]; 271 uint16_t rfcfg; 272 char eeprom_domain[4]; 273 uint32_t eeprom_crystal; 274 int16_t eeprom_voltage; 275 int8_t maxpwr2GHz; 276 int8_t maxpwr5GHz; 277 int8_t maxpwr[IEEE80211_CHAN_MAX]; 278 279 uint32_t critical_temp; 280 uint8_t ntxchains; 281 uint8_t nrxchains; 282 uint8_t txantmsk; 283 uint8_t rxantmsk; 284 uint8_t antmsk; 285 286 struct callout sc_timer_to; 287 int sc_tx_timer; 288 289 struct iwn_rx_radiotap_header sc_rxtap; 290 struct iwn_tx_radiotap_header sc_txtap; 291 const struct ieee80211_channel *sc_curchan; 292 }; 293 294 #define IWN_LOCK_INIT(_sc) \ 295 mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \ 296 MTX_NETWORK_LOCK, MTX_DEF) 297 #define IWN_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) 298 #define IWN_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) 299 #define IWN_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) 300 #define IWN_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx) 301