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_tx_data { 58 STAILQ_ENTRY(rum_tx_data) next; 59 struct rum_softc *sc; 60 struct rum_tx_desc desc; 61 struct mbuf *m; 62 struct ieee80211_node *ni; 63 int rate; 64 }; 65 typedef STAILQ_HEAD(, rum_tx_data) rum_txdhead; 66 67 struct rum_node { 68 struct ieee80211_node ni; 69 struct ieee80211_amrr_node amn; 70 }; 71 #define RUM_NODE(ni) ((struct rum_node *)(ni)) 72 73 struct rum_vap { 74 struct ieee80211vap vap; 75 struct ieee80211_beacon_offsets bo; 76 struct ieee80211_amrr amrr; 77 struct usb2_callout amrr_ch; 78 struct task amrr_task; 79 80 int (*newstate)(struct ieee80211vap *, 81 enum ieee80211_state, int); 82 }; 83 #define RUM_VAP(vap) ((struct rum_vap *)(vap)) 84 85 enum { 86 RUM_BULK_WR, 87 RUM_BULK_RD, 88 RUM_N_TRANSFER = 2, 89 }; 90 91 struct rum_softc { 92 struct ifnet *sc_ifp; 93 device_t sc_dev; 94 struct usb2_device *sc_udev; 95 96 struct usb2_xfer *sc_xfer[RUM_N_TRANSFER]; 97 98 uint8_t rf_rev; 99 uint8_t rffreq; 100 101 struct rum_tx_data tx_data[RUM_TX_LIST_COUNT]; 102 rum_txdhead tx_q; 103 rum_txdhead tx_free; 104 int tx_nfree; 105 struct rum_rx_desc sc_rx_desc; 106 107 struct mtx sc_mtx; 108 109 uint32_t sta[6]; 110 uint32_t rf_regs[4]; 111 uint8_t txpow[44]; 112 uint8_t sc_bssid[6]; 113 114 struct { 115 uint8_t val; 116 uint8_t reg; 117 } __packed bbp_prom[16]; 118 119 int hw_radio; 120 int rx_ant; 121 int tx_ant; 122 int nb_ant; 123 int ext_2ghz_lna; 124 int ext_5ghz_lna; 125 int rssi_2ghz_corr; 126 int rssi_5ghz_corr; 127 uint8_t bbp17; 128 129 struct rum_rx_radiotap_header sc_rxtap; 130 int sc_rxtap_len; 131 132 struct rum_tx_radiotap_header sc_txtap; 133 int sc_txtap_len; 134 }; 135 136 #define RUM_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 137 #define RUM_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 138 #define RUM_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 139