if_urtwnvar.h revision 294471
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: head/sys/dev/usb/wlan/if_urtwnvar.h 294471 2016-01-20 23:27:02Z avos $ 18 */ 19 20#define URTWN_RX_LIST_COUNT 1 21#define URTWN_TX_LIST_COUNT 8 22#define URTWN_HOST_CMD_RING_COUNT 32 23 24#define URTWN_RXBUFSZ (16 * 1024) 25#define URTWN_TXBUFSZ (sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN) 26#define URTWN_RX_DESC_SIZE (sizeof(struct r92c_rx_stat)) 27#define URTWN_TX_DESC_SIZE (sizeof(struct r92c_tx_desc)) 28 29#define URTWN_TX_TIMEOUT 5000 /* ms */ 30 31#define URTWN_LED_LINK 0 32#define URTWN_LED_DATA 1 33 34struct urtwn_rx_radiotap_header { 35 struct ieee80211_radiotap_header wr_ihdr; 36 uint64_t wr_tsft; 37 uint8_t wr_flags; 38 uint8_t wr_rate; 39 uint16_t wr_chan_freq; 40 uint16_t wr_chan_flags; 41 int8_t wr_dbm_antsignal; 42 int8_t wr_dbm_antnoise; 43} __packed __aligned(8); 44 45#define URTWN_RX_RADIOTAP_PRESENT \ 46 (1 << IEEE80211_RADIOTAP_TSFT | \ 47 1 << IEEE80211_RADIOTAP_FLAGS | \ 48 1 << IEEE80211_RADIOTAP_RATE | \ 49 1 << IEEE80211_RADIOTAP_CHANNEL | \ 50 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 51 1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) 52 53struct urtwn_tx_radiotap_header { 54 struct ieee80211_radiotap_header wt_ihdr; 55 uint8_t wt_flags; 56 uint16_t wt_chan_freq; 57 uint16_t wt_chan_flags; 58} __packed __aligned(8); 59 60#define URTWN_TX_RADIOTAP_PRESENT \ 61 (1 << IEEE80211_RADIOTAP_FLAGS | \ 62 1 << IEEE80211_RADIOTAP_CHANNEL) 63 64struct urtwn_softc; 65 66struct urtwn_data { 67 struct urtwn_softc *sc; 68 uint8_t *buf; 69 uint16_t buflen; 70 struct mbuf *m; 71 struct ieee80211_node *ni; 72 STAILQ_ENTRY(urtwn_data) next; 73}; 74typedef STAILQ_HEAD(, urtwn_data) urtwn_datahead; 75 76union sec_param { 77 struct ieee80211_key key; 78}; 79 80#define CMD_FUNC_PROTO void (*func)(struct urtwn_softc *, \ 81 union sec_param *) 82 83struct urtwn_cmdq { 84 union sec_param data; 85 CMD_FUNC_PROTO; 86}; 87#define URTWN_CMDQ_SIZE 16 88 89struct urtwn_fw_info { 90 const uint8_t *data; 91 size_t size; 92}; 93 94struct urtwn_node { 95 struct ieee80211_node ni; /* must be the first */ 96 uint8_t id; 97}; 98#define URTWN_NODE(ni) ((struct urtwn_node *)(ni)) 99 100struct urtwn_vap { 101 struct ieee80211vap vap; 102 103 struct r92c_tx_desc bcn_desc; 104 struct mbuf *bcn_mbuf; 105 struct task tsf_task_adhoc; 106 107 int (*newstate)(struct ieee80211vap *, 108 enum ieee80211_state, int); 109 void (*recv_mgmt)(struct ieee80211_node *, 110 struct mbuf *, int, 111 const struct ieee80211_rx_stats *, 112 int, int); 113}; 114#define URTWN_VAP(vap) ((struct urtwn_vap *)(vap)) 115 116struct urtwn_host_cmd { 117 void (*cb)(struct urtwn_softc *, void *); 118 uint8_t data[256]; 119}; 120 121struct urtwn_cmd_newstate { 122 enum ieee80211_state state; 123 int arg; 124}; 125 126struct urtwn_cmd_key { 127 struct ieee80211_key key; 128 uint16_t associd; 129}; 130 131enum { 132 URTWN_BULK_RX, 133 URTWN_BULK_TX_BE, /* = WME_AC_BE */ 134 URTWN_BULK_TX_BK, /* = WME_AC_BK */ 135 URTWN_BULK_TX_VI, /* = WME_AC_VI */ 136 URTWN_BULK_TX_VO, /* = WME_AC_VI */ 137 URTWN_N_TRANSFER = 5, 138}; 139 140#define URTWN_EP_QUEUES URTWN_BULK_RX 141 142union urtwn_rom { 143 struct r92c_rom r92c_rom; 144 struct r88e_rom r88e_rom; 145}; 146 147struct urtwn_softc { 148 struct ieee80211com sc_ic; 149 struct mbufq sc_snd; 150 device_t sc_dev; 151 struct usb_device *sc_udev; 152 153 uint32_t sc_debug; 154 uint8_t sc_iface_index; 155 uint8_t sc_flags; 156#define URTWN_FLAG_CCK_HIPWR 0x01 157#define URTWN_DETACHED 0x02 158#define URTWN_RUNNING 0x04 159 160 u_int chip; 161#define URTWN_CHIP_92C 0x01 162#define URTWN_CHIP_92C_1T2R 0x02 163#define URTWN_CHIP_UMC 0x04 164#define URTWN_CHIP_UMC_A_CUT 0x08 165#define URTWN_CHIP_88E 0x10 166 167#define URTWN_CHIP_HAS_RATECTL(_sc) (!!((_sc)->chip & URTWN_CHIP_88E)) 168 169 void (*sc_node_free)(struct ieee80211_node *); 170 void (*sc_rf_write)(struct urtwn_softc *, 171 int, uint8_t, uint32_t); 172 int (*sc_power_on)(struct urtwn_softc *); 173 174 struct ieee80211_node *node_list[R88E_MACID_MAX + 1]; 175 struct mtx nt_mtx; 176 177 uint8_t board_type; 178 uint8_t regulatory; 179 uint8_t pa_setting; 180 int8_t ofdm_tx_pwr_diff; 181 int8_t bw20_tx_pwr_diff; 182 int avg_pwdb; 183 int thcal_state; 184 int thcal_lctemp; 185 int ntxchains; 186 int nrxchains; 187 int ledlink; 188 int sc_txtimer; 189 190 int fwcur; 191 struct urtwn_data sc_rx[URTWN_RX_LIST_COUNT]; 192 urtwn_datahead sc_rx_active; 193 urtwn_datahead sc_rx_inactive; 194 struct urtwn_data sc_tx[URTWN_TX_LIST_COUNT]; 195 urtwn_datahead sc_tx_active; 196 urtwn_datahead sc_tx_inactive; 197 urtwn_datahead sc_tx_pending; 198 199 const char *fwname; 200 const struct firmware *fw_fp; 201 struct urtwn_fw_info fw; 202 void *fw_virtaddr; 203 204 union urtwn_rom rom; 205 uint16_t last_rom_addr; 206 207 struct callout sc_watchdog_ch; 208 struct mtx sc_mtx; 209 uint32_t keys_bmap; 210 211 struct urtwn_cmdq cmdq[URTWN_CMDQ_SIZE]; 212 struct mtx cmdq_mtx; 213 struct task cmdq_task; 214 uint8_t cmdq_first; 215 uint8_t cmdq_last; 216 217 uint32_t rf_chnlbw[R92C_MAX_CHAINS]; 218 struct usb_xfer *sc_xfer[URTWN_N_TRANSFER]; 219 220 struct urtwn_rx_radiotap_header sc_rxtap; 221 struct urtwn_tx_radiotap_header sc_txtap; 222}; 223 224#define URTWN_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 225#define URTWN_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 226#define URTWN_ASSERT_LOCKED(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 227 228#define URTWN_CMDQ_LOCK_INIT(sc) \ 229 mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF) 230#define URTWN_CMDQ_LOCK(sc) mtx_lock(&(sc)->cmdq_mtx) 231#define URTWN_CMDQ_UNLOCK(sc) mtx_unlock(&(sc)->cmdq_mtx) 232#define URTWN_CMDQ_LOCK_DESTROY(sc) mtx_destroy(&(sc)->cmdq_mtx) 233 234#define URTWN_NT_LOCK_INIT(sc) \ 235 mtx_init(&(sc)->nt_mtx, "node table lock", NULL, MTX_DEF) 236#define URTWN_NT_LOCK(sc) mtx_lock(&(sc)->nt_mtx) 237#define URTWN_NT_UNLOCK(sc) mtx_unlock(&(sc)->nt_mtx) 238#define URTWN_NT_LOCK_DESTROY(sc) mtx_destroy(&(sc)->nt_mtx) 239