1 /*- 2 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * 16 * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $ 17 * $FreeBSD$ 18 */ 19 20 #define URTWN_RX_LIST_COUNT 64 21 #define URTWN_TX_LIST_COUNT 8 22 #define URTWN_HOST_CMD_RING_COUNT 32 23 24 #define URTWN_RXBUFSZ (8 * 1024) 25 //#define URTWN_TXBUFSZ (sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN) 26 /* Leave enough space for an A-MSDU frame */ 27 #define URTWN_TXBUFSZ (16 * 1024) 28 #define URTWN_RX_DESC_SIZE (sizeof(struct r92c_rx_stat)) 29 #define URTWN_TX_DESC_SIZE (sizeof(struct r92c_tx_desc)) 30 31 #define URTWN_TX_TIMEOUT 5000 /* ms */ 32 33 #define URTWN_LED_LINK 0 34 #define URTWN_LED_DATA 1 35 36 struct urtwn_rx_radiotap_header { 37 struct ieee80211_radiotap_header wr_ihdr; 38 uint64_t wr_tsft; 39 uint8_t wr_flags; 40 uint8_t wr_rate; 41 uint16_t wr_chan_freq; 42 uint16_t wr_chan_flags; 43 int8_t wr_dbm_antsignal; 44 int8_t wr_dbm_antnoise; 45 } __packed __aligned(8); 46 47 #define URTWN_RX_RADIOTAP_PRESENT \ 48 (1 << IEEE80211_RADIOTAP_TSFT | \ 49 1 << IEEE80211_RADIOTAP_FLAGS | \ 50 1 << IEEE80211_RADIOTAP_RATE | \ 51 1 << IEEE80211_RADIOTAP_CHANNEL | \ 52 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 53 1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) 54 55 struct urtwn_tx_radiotap_header { 56 struct ieee80211_radiotap_header wt_ihdr; 57 uint8_t wt_flags; 58 uint16_t wt_chan_freq; 59 uint16_t wt_chan_flags; 60 } __packed __aligned(8); 61 62 #define URTWN_TX_RADIOTAP_PRESENT \ 63 (1 << IEEE80211_RADIOTAP_FLAGS | \ 64 1 << IEEE80211_RADIOTAP_CHANNEL) 65 66 struct urtwn_softc; 67 68 struct urtwn_data { 69 struct urtwn_softc *sc; 70 uint8_t *buf; 71 uint16_t buflen; 72 struct mbuf *m; 73 struct ieee80211_node *ni; 74 STAILQ_ENTRY(urtwn_data) next; 75 }; 76 typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead; 77 78 union sec_param { 79 struct ieee80211_key key; 80 }; 81 82 #define CMD_FUNC_PROTO void (*func)(struct urtwn_softc *, \ 83 union sec_param *) 84 85 struct urtwn_cmdq { 86 union sec_param data; 87 CMD_FUNC_PROTO; 88 }; 89 #define URTWN_CMDQ_SIZE 16 90 91 struct urtwn_fw_info { 92 const uint8_t *data; 93 size_t size; 94 }; 95 96 struct urtwn_node { 97 struct ieee80211_node ni; /* must be the first */ 98 uint8_t id; 99 int last_rssi; 100 }; 101 #define URTWN_NODE(ni) ((struct urtwn_node *)(ni)) 102 103 struct urtwn_vap { 104 struct ieee80211vap vap; 105 106 struct r92c_tx_desc bcn_desc; 107 struct mbuf *bcn_mbuf; 108 struct task tsf_task_adhoc; 109 110 int (*newstate)(struct ieee80211vap *, 111 enum ieee80211_state, int); 112 void (*recv_mgmt)(struct ieee80211_node *, 113 struct mbuf *, int, 114 const struct ieee80211_rx_stats *, 115 int, int); 116 }; 117 #define URTWN_VAP(vap) ((struct urtwn_vap *)(vap)) 118 119 struct urtwn_host_cmd { 120 void (*cb)(struct urtwn_softc *, void *); 121 uint8_t data[256]; 122 }; 123 124 struct urtwn_cmd_newstate { 125 enum ieee80211_state state; 126 int arg; 127 }; 128 129 struct urtwn_cmd_key { 130 struct ieee80211_key key; 131 uint16_t associd; 132 }; 133 134 enum { 135 URTWN_BULK_RX, 136 URTWN_BULK_TX_BE, /* = WME_AC_BE */ 137 URTWN_BULK_TX_BK, /* = WME_AC_BK */ 138 URTWN_BULK_TX_VI, /* = WME_AC_VI */ 139 URTWN_BULK_TX_VO, /* = WME_AC_VI */ 140 URTWN_N_TRANSFER = 5, 141 }; 142 143 #define URTWN_EP_QUEUES URTWN_BULK_RX 144 145 union urtwn_rom { 146 struct r92c_rom r92c_rom; 147 struct r88e_rom r88e_rom; 148 }; 149 150 struct urtwn_softc { 151 struct ieee80211com sc_ic; 152 struct mbufq sc_snd; 153 device_t sc_dev; 154 struct usb_device *sc_udev; 155 156 uint32_t sc_debug; 157 uint8_t sc_iface_index; 158 uint8_t sc_flags; 159 #define URTWN_FLAG_CCK_HIPWR 0x01 160 #define URTWN_DETACHED 0x02 161 #define URTWN_RUNNING 0x04 162 #define URTWN_FW_LOADED 0x08 163 #define URTWN_TEMP_MEASURED 0x10 164 165 u_int chip; 166 #define URTWN_CHIP_92C 0x01 167 #define URTWN_CHIP_92C_1T2R 0x02 168 #define URTWN_CHIP_UMC 0x04 169 #define URTWN_CHIP_UMC_A_CUT 0x08 170 #define URTWN_CHIP_88E 0x10 171 172 #define URTWN_CHIP_HAS_RATECTL(_sc) (!!((_sc)->chip & URTWN_CHIP_88E)) 173 174 void (*sc_node_free)(struct ieee80211_node *); 175 void (*sc_rf_write)(struct urtwn_softc *, 176 int, uint8_t, uint32_t); 177 int (*sc_power_on)(struct urtwn_softc *); 178 void (*sc_power_off)(struct urtwn_softc *); 179 180 struct ieee80211_node *node_list[R88E_MACID_MAX + 1]; 181 #if defined(__DragonFly__) 182 struct lock nt_mtx; 183 #else 184 struct mtx nt_mtx; 185 #endif 186 187 uint8_t board_type; 188 uint8_t regulatory; 189 uint8_t pa_setting; 190 int8_t ofdm_tx_pwr_diff; 191 int8_t bw20_tx_pwr_diff; 192 int avg_pwdb; 193 uint8_t thcal_lctemp; 194 int ntxchains; 195 int nrxchains; 196 int ledlink; 197 int sc_txtimer; 198 199 int last_rssi; 200 201 int fwcur; 202 struct urtwn_data sc_rx[URTWN_RX_LIST_COUNT]; 203 urtwn_datahead sc_rx_active; 204 urtwn_datahead sc_rx_inactive; 205 struct urtwn_data sc_tx[URTWN_TX_LIST_COUNT]; 206 urtwn_datahead sc_tx_active; 207 int sc_tx_n_active; 208 urtwn_datahead sc_tx_inactive; 209 urtwn_datahead sc_tx_pending; 210 211 union urtwn_rom rom; 212 uint16_t last_rom_addr; 213 214 struct callout sc_calib_to; 215 struct callout sc_watchdog_ch; 216 #if defined(__DragonFly__) 217 struct lock sc_mtx; 218 #else 219 struct mtx sc_mtx; 220 #endif 221 uint32_t keys_bmap; 222 223 struct urtwn_cmdq cmdq[URTWN_CMDQ_SIZE]; 224 #if defined(__DragonFly__) 225 struct lock cmdq_mtx; 226 #else 227 struct mtx cmdq_mtx; 228 #endif 229 struct task cmdq_task; 230 uint8_t cmdq_first; 231 uint8_t cmdq_last; 232 233 uint32_t rf_chnlbw[R92C_MAX_CHAINS]; 234 struct usb_xfer *sc_xfer[URTWN_N_TRANSFER]; 235 236 struct urtwn_rx_radiotap_header sc_rxtap; 237 struct urtwn_tx_radiotap_header sc_txtap; 238 }; 239 240 #if defined(__DragonFly__) 241 242 #define URTWN_LOCK(sc) lockmgr(&(sc)->sc_mtx, LK_EXCLUSIVE) 243 #define URTWN_UNLOCK(sc) lockmgr(&(sc)->sc_mtx, LK_RELEASE) 244 #define URTWN_ASSERT_LOCKED(sc) KKASSERT(lockstatus(&(sc)->sc_mtx, curthread) == LK_EXCLUSIVE) 245 246 #define URTWN_CMDQ_LOCK_INIT(sc) lockinit(&(sc)->cmdq_mtx, "cmdq lock", 0, 0); 247 #define URTWN_CMDQ_LOCK(sc) lockmgr(&(sc)->cmdq_mtx, LK_EXCLUSIVE) 248 #define URTWN_CMDQ_UNLOCK(sc) lockmgr(&(sc)->cmdq_mtx, LK_RELEASE) 249 #define URTWN_CMDQ_LOCK_DESTROY(sc) lockuninit(&(sc)->cmdq_mtx) 250 251 #define URTWN_NT_LOCK_INIT(sc) lockinit(&(sc)->nt_mtx, "node table lock", 0, 0) 252 #define URTWN_NT_LOCK(sc) lockmgr(&(sc)->nt_mtx, LK_EXCLUSIVE) 253 #define URTWN_NT_UNLOCK(sc) lockmgr(&(sc)->nt_mtx, LK_RELEASE) 254 #define URTWN_NT_LOCK_DESTROY(sc) lockuninit(&(sc)->nt_mtx) 255 256 #else 257 258 #define URTWN_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 259 #define URTWN_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 260 #define URTWN_ASSERT_LOCKED(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 261 262 #define URTWN_CMDQ_LOCK_INIT(sc) \ 263 mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF) 264 #define URTWN_CMDQ_LOCK(sc) mtx_lock(&(sc)->cmdq_mtx) 265 #define URTWN_CMDQ_UNLOCK(sc) mtx_unlock(&(sc)->cmdq_mtx) 266 #define URTWN_CMDQ_LOCK_DESTROY(sc) mtx_destroy(&(sc)->cmdq_mtx) 267 268 #define URTWN_NT_LOCK_INIT(sc) \ 269 mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF) 270 #define URTWN_NT_LOCK(sc) mtx_lock(&(sc)->nt_mtx) 271 #define URTWN_NT_UNLOCK(sc) mtx_unlock(&(sc)->nt_mtx) 272 #define URTWN_NT_LOCK_DESTROY(sc) mtx_destroy(&(sc)->nt_mtx) 273 274 #endif 275