1 2 /*- 3 * Copyright (c) 2005 4 * Damien Bergamini <damien.bergamini@free.fr> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 struct rt2661_rx_radiotap_header { 20 struct ieee80211_radiotap_header wr_ihdr; 21 uint64_t wr_tsf; 22 uint8_t wr_flags; 23 uint8_t wr_rate; 24 uint16_t wr_chan_freq; 25 uint16_t wr_chan_flags; 26 int8_t wr_antsignal; 27 int8_t wr_antnoise; 28 } __packed __aligned(8); 29 30 #define RT2661_RX_RADIOTAP_PRESENT \ 31 ((1 << IEEE80211_RADIOTAP_TSFT) | \ 32 (1 << IEEE80211_RADIOTAP_FLAGS) | \ 33 (1 << IEEE80211_RADIOTAP_RATE) | \ 34 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 35 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \ 36 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE)) 37 38 struct rt2661_tx_radiotap_header { 39 struct ieee80211_radiotap_header wt_ihdr; 40 uint8_t wt_flags; 41 uint8_t wt_rate; 42 uint16_t wt_chan_freq; 43 uint16_t wt_chan_flags; 44 } __packed; 45 46 #define RT2661_TX_RADIOTAP_PRESENT \ 47 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 48 (1 << IEEE80211_RADIOTAP_RATE) | \ 49 (1 << IEEE80211_RADIOTAP_CHANNEL)) 50 51 struct rt2661_tx_data { 52 bus_dmamap_t map; 53 struct mbuf *m; 54 struct ieee80211_node *ni; 55 uint8_t rix; 56 int8_t rssi; 57 }; 58 59 struct rt2661_tx_ring { 60 bus_dma_tag_t desc_dmat; 61 bus_dma_tag_t data_dmat; 62 bus_dmamap_t desc_map; 63 bus_addr_t physaddr; 64 struct rt2661_tx_desc *desc; 65 struct rt2661_tx_data *data; 66 int count; 67 int queued; 68 int cur; 69 int next; 70 int stat; 71 }; 72 73 struct rt2661_rx_data { 74 bus_dmamap_t map; 75 struct mbuf *m; 76 }; 77 78 struct rt2661_rx_ring { 79 bus_dma_tag_t desc_dmat; 80 bus_dma_tag_t data_dmat; 81 bus_dmamap_t desc_map; 82 bus_addr_t physaddr; 83 struct rt2661_rx_desc *desc; 84 struct rt2661_rx_data *data; 85 int count; 86 int cur; 87 int next; 88 }; 89 90 struct rt2661_vap { 91 struct ieee80211vap ral_vap; 92 93 int (*ral_newstate)(struct ieee80211vap *, 94 enum ieee80211_state, int); 95 }; 96 #define RT2661_VAP(vap) ((struct rt2661_vap *)(vap)) 97 98 struct rt2661_softc { 99 struct ieee80211com sc_ic; 100 struct ieee80211_ratectl_tx_status sc_txs; 101 struct mtx sc_mtx; 102 struct mbufq sc_snd; 103 device_t sc_dev; 104 bus_space_tag_t sc_st; 105 bus_space_handle_t sc_sh; 106 107 struct callout watchdog_ch; 108 109 int sc_tx_timer; 110 int sc_invalid; 111 int sc_debug; 112 /* 113 * The same in both up to here 114 * ------------------------------------------------ 115 */ 116 117 int sc_flags; 118 #define RAL_FW_LOADED 0x1 119 #define RAL_INPUT_RUNNING 0x2 120 #define RAL_RUNNING 0x4 121 int sc_id; 122 struct ieee80211_channel *sc_curchan; 123 124 uint8_t rf_rev; 125 126 uint8_t rfprog; 127 uint8_t rffreq; 128 129 struct rt2661_tx_ring txq[4]; 130 struct rt2661_tx_ring mgtq; 131 struct rt2661_rx_ring rxq; 132 133 uint32_t rf_regs[4]; 134 int8_t txpow[38]; 135 136 struct { 137 uint8_t reg; 138 uint8_t val; 139 } 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 150 uint8_t bbp18; 151 uint8_t bbp21; 152 uint8_t bbp22; 153 uint8_t bbp16; 154 uint8_t bbp17; 155 uint8_t bbp64; 156 157 int dwelltime; 158 159 struct rt2661_rx_radiotap_header sc_rxtap; 160 struct rt2661_tx_radiotap_header sc_txtap; 161 }; 162 163 int rt2661_attach(device_t, int); 164 int rt2661_detach(void *); 165 void rt2661_shutdown(void *); 166 void rt2661_suspend(void *); 167 void rt2661_resume(void *); 168 void rt2661_intr(void *); 169 170 #define RAL_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 171 #define RAL_LOCK_ASSERT(sc) mtx_assert(&(sc)->sc_mtx, MA_OWNED) 172 #define RAL_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 173