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 uint8_t wr_flags; 26 uint8_t wr_rate; 27 uint16_t wr_chan_freq; 28 uint16_t wr_chan_flags; 29 uint8_t wr_antenna; 30 uint8_t wr_antsignal; 31 }; 32 33 #define RT2573_RX_RADIOTAP_PRESENT \ 34 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 35 (1 << IEEE80211_RADIOTAP_RATE) | \ 36 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 37 (1 << IEEE80211_RADIOTAP_ANTENNA) | \ 38 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)) 39 40 struct rum_tx_radiotap_header { 41 struct ieee80211_radiotap_header wt_ihdr; 42 uint8_t wt_flags; 43 uint8_t wt_rate; 44 uint16_t wt_chan_freq; 45 uint16_t wt_chan_flags; 46 uint8_t wt_antenna; 47 }; 48 49 #define RT2573_TX_RADIOTAP_PRESENT \ 50 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 51 (1 << IEEE80211_RADIOTAP_RATE) | \ 52 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 53 (1 << IEEE80211_RADIOTAP_ANTENNA)) 54 55 struct rum_softc; 56 57 struct rum_task { 58 struct usb2_proc_msg hdr; 59 usb2_proc_callback_t *func; 60 struct rum_softc *sc; 61 }; 62 63 struct rum_tx_data { 64 STAILQ_ENTRY(rum_tx_data) next; 65 struct rum_softc *sc; 66 struct rum_tx_desc desc; 67 struct mbuf *m; 68 struct ieee80211_node *ni; 69 int rate; 70 }; 71 typedef STAILQ_HEAD(, rum_tx_data) rum_txdhead; 72 73 struct rum_node { 74 struct ieee80211_node ni; 75 struct ieee80211_amrr_node amn; 76 }; 77 #define RUM_NODE(ni) ((struct rum_node *)(ni)) 78 79 struct rum_vap { 80 struct ieee80211vap vap; 81 struct rum_softc *sc; 82 struct ieee80211_beacon_offsets bo; 83 struct ieee80211_amrr amrr; 84 struct usb2_callout amrr_ch; 85 struct rum_task amrr_task[2]; 86 87 int (*newstate)(struct ieee80211vap *, 88 enum ieee80211_state, int); 89 }; 90 #define RUM_VAP(vap) ((struct rum_vap *)(vap)) 91 92 enum { 93 RUM_BULK_WR, 94 RUM_BULK_RD, 95 RUM_N_TRANSFER = 2, 96 }; 97 98 struct rum_softc { 99 struct ifnet *sc_ifp; 100 device_t sc_dev; 101 struct usb2_device *sc_udev; 102 struct usb2_process sc_tq; 103 104 const struct ieee80211_rate_table *sc_rates; 105 struct usb2_xfer *sc_xfer[RUM_N_TRANSFER]; 106 struct rum_task *sc_last_task; 107 108 uint8_t rf_rev; 109 uint8_t rffreq; 110 111 enum ieee80211_state sc_state; 112 int sc_arg; 113 struct rum_task sc_synctask[2]; 114 struct rum_task sc_task[2]; 115 struct rum_task sc_promisctask[2]; 116 struct rum_task sc_scantask[2]; 117 int sc_scan_action; 118 #define RUM_SCAN_START 0 119 #define RUM_SCAN_END 1 120 #define RUM_SET_CHANNEL 2 121 122 struct rum_tx_data tx_data[RUM_TX_LIST_COUNT]; 123 rum_txdhead tx_q; 124 rum_txdhead tx_free; 125 int tx_nfree; 126 struct rum_rx_desc sc_rx_desc; 127 128 struct cv sc_cmd_cv; 129 struct mtx sc_mtx; 130 131 uint32_t sta[6]; 132 uint32_t rf_regs[4]; 133 uint8_t txpow[44]; 134 uint8_t sc_bssid[6]; 135 136 struct { 137 uint8_t val; 138 uint8_t reg; 139 } __packed bbp_prom[16]; 140 141 int hw_radio; 142 int rx_ant; 143 int tx_ant; 144 int nb_ant; 145 int ext_2ghz_lna; 146 int ext_5ghz_lna; 147 int rssi_2ghz_corr; 148 int rssi_5ghz_corr; 149 uint8_t bbp17; 150 151 struct rum_rx_radiotap_header sc_rxtap; 152 int sc_rxtap_len; 153 154 struct rum_tx_radiotap_header sc_txtap; 155 int sc_txtap_len; 156 }; 157 158 #define RUM_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 159 #define RUM_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 160 #define RUM_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 161