1 /* $FreeBSD$ */ 2 3 /*- 4 * Copyright (c) 2005, 2006 Damien Bergamini <damien.bergamini@free.fr> 5 * Copyright (c) 2006 Niall O'Higgins <niallo@openbsd.org> 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 #define RUM_TX_LIST_COUNT 8 21 #define RUM_TX_MINFREE 2 22 23 struct rum_rx_radiotap_header { 24 struct ieee80211_radiotap_header wr_ihdr; 25 uint64_t wr_tsf; 26 uint8_t wr_flags; 27 uint8_t wr_rate; 28 uint16_t wr_chan_freq; 29 uint16_t wr_chan_flags; 30 int8_t wr_antsignal; 31 int8_t wr_antnoise; 32 uint8_t wr_antenna; 33 } __packed __aligned(8); 34 35 #define RT2573_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 (1 << IEEE80211_RADIOTAP_ANTENNA) | \ 43 0) 44 45 struct rum_tx_radiotap_header { 46 struct ieee80211_radiotap_header wt_ihdr; 47 uint64_t wt_tsf; 48 uint8_t wt_flags; 49 uint8_t wt_rate; 50 uint16_t wt_chan_freq; 51 uint16_t wt_chan_flags; 52 uint8_t wt_antenna; 53 } __packed __aligned(8); 54 55 #define RT2573_TX_RADIOTAP_PRESENT \ 56 ((1 << IEEE80211_RADIOTAP_TSFT) | \ 57 (1 << IEEE80211_RADIOTAP_FLAGS) | \ 58 (1 << IEEE80211_RADIOTAP_RATE) | \ 59 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 60 (1 << IEEE80211_RADIOTAP_ANTENNA)) 61 62 struct rum_softc; 63 64 struct rum_tx_data { 65 STAILQ_ENTRY(rum_tx_data) next; 66 struct rum_softc *sc; 67 struct rum_tx_desc desc; 68 struct mbuf *m; 69 struct ieee80211_node *ni; 70 int rate; 71 }; 72 typedef STAILQ_HEAD(, rum_tx_data) rum_txdhead; 73 74 union sec_param { 75 struct ieee80211_key key; 76 struct wmeParams wme_params[WME_NUM_AC]; 77 uint8_t macaddr[IEEE80211_ADDR_LEN]; 78 struct ieee80211vap *vap; 79 }; 80 #define CMD_FUNC_PROTO void (*func)(struct rum_softc *, \ 81 union sec_param *, uint8_t) 82 83 struct rum_cmdq { 84 union sec_param data; 85 uint8_t rvp_id; 86 87 CMD_FUNC_PROTO; 88 }; 89 #define RUM_CMDQ_SIZE 16 90 91 struct rum_vap { 92 struct ieee80211vap vap; 93 struct mbuf *bcn_mbuf; 94 struct usb_callout ratectl_ch; 95 struct task ratectl_task; 96 uint8_t maxretry; 97 98 int (*newstate)(struct ieee80211vap *, 99 enum ieee80211_state, int); 100 }; 101 #define RUM_VAP(vap) ((struct rum_vap *)(vap)) 102 103 enum { 104 RUM_BULK_WR, 105 RUM_BULK_RD, 106 RUM_N_TRANSFER = 2, 107 }; 108 109 struct rum_softc { 110 struct ieee80211com sc_ic; 111 struct mbufq sc_snd; 112 device_t sc_dev; 113 struct usb_device *sc_udev; 114 115 struct usb_xfer *sc_xfer[RUM_N_TRANSFER]; 116 117 uint8_t rf_rev; 118 uint8_t rffreq; 119 120 struct rum_tx_data tx_data[RUM_TX_LIST_COUNT]; 121 rum_txdhead tx_q; 122 rum_txdhead tx_free; 123 int tx_nfree; 124 struct rum_rx_desc sc_rx_desc; 125 126 struct mtx sc_mtx; 127 128 struct rum_cmdq cmdq[RUM_CMDQ_SIZE]; 129 struct mtx cmdq_mtx; 130 struct task cmdq_task; 131 uint8_t cmdq_first; 132 uint8_t cmdq_last; 133 134 uint32_t sta[6]; 135 uint32_t rf_regs[4]; 136 uint8_t txpow[44]; 137 u_int sc_detached:1, 138 sc_running:1, 139 sc_clr_shkeys:1; 140 141 uint8_t sc_bssid[IEEE80211_ADDR_LEN]; 142 struct wmeParams wme_params[WME_NUM_AC]; 143 144 uint8_t vap_key_count[1]; 145 uint64_t keys_bmap; 146 147 struct { 148 uint8_t val; 149 uint8_t reg; 150 } __packed bbp_prom[16]; 151 152 int hw_radio; 153 int rx_ant; 154 int tx_ant; 155 int nb_ant; 156 int ext_2ghz_lna; 157 int ext_5ghz_lna; 158 int rssi_2ghz_corr; 159 int rssi_5ghz_corr; 160 uint8_t bbp17; 161 162 struct rum_rx_radiotap_header sc_rxtap; 163 struct rum_tx_radiotap_header sc_txtap; 164 }; 165 166 #define RUM_LOCK_INIT(sc) \ 167 mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \ 168 MTX_NETWORK_LOCK, MTX_DEF); 169 #define RUM_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 170 #define RUM_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 171 #define RUM_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 172 #define RUM_LOCK_DESTROY(sc) mtx_destroy(&(sc)->sc_mtx) 173 174 #define RUM_CMDQ_LOCK_INIT(sc) \ 175 mtx_init(&(sc)->cmdq_mtx, "cmdq lock", NULL, MTX_DEF) 176 #define RUM_CMDQ_LOCK(sc) mtx_lock(&(sc)->cmdq_mtx) 177 #define RUM_CMDQ_UNLOCK(sc) mtx_unlock(&(sc)->cmdq_mtx) 178 #define RUM_CMDQ_LOCK_DESTROY(sc) mtx_destroy(&(sc)->cmdq_mtx) 179