1 /* $OpenBSD: rt2860var.h,v 1.20 2010/09/07 16:21:42 deraadt Exp $ */ 2 3 /*- 4 * Copyright (c) 2007 5 * Damien Bergamini <damien.bergamini@free.fr> 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 RT2860_TX_RING_COUNT 64 21 #define RT2860_RX_RING_COUNT 128 22 #define RT2860_TX_POOL_COUNT (RT2860_TX_RING_COUNT * 2) 23 24 #define RT2860_MAX_SCATTER ((RT2860_TX_RING_COUNT * 2) - 1) 25 26 /* HW supports up to 255 STAs */ 27 #define RT2860_WCID_MAX 254 28 #define RT2860_AID2WCID(aid) ((aid) & 0xff) 29 30 struct rt2860_rx_radiotap_header { 31 struct ieee80211_radiotap_header wr_ihdr; 32 uint8_t wr_flags; 33 uint8_t wr_rate; 34 uint16_t wr_chan_freq; 35 uint16_t wr_chan_flags; 36 uint8_t wr_dbm_antsignal; 37 uint8_t wr_antenna; 38 uint8_t wr_antsignal; 39 } __packed; 40 41 #define RT2860_RX_RADIOTAP_PRESENT \ 42 (1 << IEEE80211_RADIOTAP_FLAGS | \ 43 1 << IEEE80211_RADIOTAP_RATE | \ 44 1 << IEEE80211_RADIOTAP_CHANNEL | \ 45 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 46 1 << IEEE80211_RADIOTAP_ANTENNA | \ 47 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 48 49 struct rt2860_tx_radiotap_header { 50 struct ieee80211_radiotap_header wt_ihdr; 51 uint8_t wt_flags; 52 uint8_t wt_rate; 53 uint16_t wt_chan_freq; 54 uint16_t wt_chan_flags; 55 uint8_t wt_hwqueue; 56 } __packed; 57 58 #define RT2860_TX_RADIOTAP_PRESENT \ 59 (1 << IEEE80211_RADIOTAP_FLAGS | \ 60 1 << IEEE80211_RADIOTAP_RATE | \ 61 1 << IEEE80211_RADIOTAP_CHANNEL | \ 62 1 << IEEE80211_RADIOTAP_HWQUEUE) 63 64 struct rt2860_tx_data { 65 struct rt2860_txwi *txwi; 66 struct mbuf *m; 67 struct ieee80211_node *ni; 68 bus_dmamap_t map; 69 bus_addr_t paddr; 70 SLIST_ENTRY(rt2860_tx_data) next; 71 }; 72 73 struct rt2860_tx_ring { 74 struct rt2860_txd *txd; 75 bus_addr_t paddr; 76 bus_dmamap_t map; 77 bus_dma_segment_t seg; 78 struct rt2860_tx_data *data[RT2860_TX_RING_COUNT]; 79 int cur; 80 int next; 81 int queued; 82 }; 83 84 struct rt2860_rx_data { 85 struct mbuf *m; 86 bus_dmamap_t map; 87 }; 88 89 struct rt2860_rx_ring { 90 struct rt2860_rxd *rxd; 91 bus_addr_t paddr; 92 bus_dmamap_t map; 93 bus_dma_segment_t seg; 94 unsigned int cur; /* must be unsigned */ 95 struct rt2860_rx_data data[RT2860_RX_RING_COUNT]; 96 }; 97 98 struct rt2860_node { 99 struct ieee80211_node ni; 100 uint8_t wcid; 101 uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 102 uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 103 }; 104 105 struct rt2860_softc { 106 struct device sc_dev; 107 108 struct ieee80211com sc_ic; 109 int (*sc_newstate)(struct ieee80211com *, 110 enum ieee80211_state, int); 111 struct ieee80211_amrr amrr; 112 113 int (*sc_enable)(struct rt2860_softc *); 114 void (*sc_disable)(struct rt2860_softc *); 115 116 bus_dma_tag_t sc_dmat; 117 bus_space_tag_t sc_st; 118 bus_space_handle_t sc_sh; 119 120 uint16_t (*sc_srom_read)(struct rt2860_softc *, 121 uint16_t); 122 123 int sc_flags; 124 #define RT2860_ENABLED (1 << 0) 125 #define RT2860_ADVANCED_PS (1 << 1) 126 #define RT2860_PCIE (1 << 2) 127 128 uint32_t sc_ic_flags; 129 int fixed_ridx; 130 131 u_char *ucode; 132 size_t ucsize; 133 134 struct rt2860_tx_ring txq[6]; 135 struct rt2860_rx_ring rxq; 136 137 SLIST_HEAD(, rt2860_tx_data) data_pool; 138 struct rt2860_tx_data data[RT2860_TX_POOL_COUNT]; 139 bus_dmamap_t txwi_map; 140 bus_dma_segment_t txwi_seg; 141 caddr_t txwi_vaddr; 142 143 int sc_tx_timer; 144 int mgtqid; 145 uint8_t qfullmsk; 146 147 uint16_t mac_ver; 148 uint16_t mac_rev; 149 uint8_t rf_rev; 150 uint8_t freq; 151 uint8_t ntxchains; 152 uint8_t nrxchains; 153 uint8_t pslevel; 154 int8_t txpow1[54]; 155 int8_t txpow2[54]; 156 int8_t rssi_2ghz[3]; 157 int8_t rssi_5ghz[3]; 158 uint8_t lna[4]; 159 uint8_t rf24_20mhz; 160 uint8_t rf24_40mhz; 161 uint8_t patch_dac; 162 uint8_t rfswitch; 163 uint8_t ext_2ghz_lna; 164 uint8_t ext_5ghz_lna; 165 uint8_t calib_2ghz; 166 uint8_t calib_5ghz; 167 uint8_t txmixgain_2ghz; 168 uint8_t txmixgain_5ghz; 169 uint8_t tssi_2ghz[9]; 170 uint8_t tssi_5ghz[9]; 171 uint8_t step_2ghz; 172 uint8_t step_5ghz; 173 struct { 174 uint8_t reg; 175 uint8_t val; 176 } bbp[8], rf[10]; 177 uint8_t leds; 178 uint16_t led[3]; 179 uint32_t txpow20mhz[5]; 180 uint32_t txpow40mhz_2ghz[5]; 181 uint32_t txpow40mhz_5ghz[5]; 182 183 struct ieee80211_amrr_node amn[RT2860_WCID_MAX + 1]; 184 185 #if NBPFILTER > 0 186 caddr_t sc_drvbpf; 187 union { 188 struct rt2860_rx_radiotap_header th; 189 uint8_t pad[64]; 190 } sc_rxtapu; 191 #define sc_rxtap sc_rxtapu.th 192 int sc_rxtap_len; 193 194 union { 195 struct rt2860_tx_radiotap_header th; 196 uint8_t pad[64]; 197 } sc_txtapu; 198 #define sc_txtap sc_txtapu.th 199 int sc_txtap_len; 200 #endif 201 }; 202 203 int rt2860_attach(void *, int); 204 int rt2860_detach(void *); 205 void rt2860_suspend(void *); 206 void rt2860_resume(void *); 207 int rt2860_intr(void *); 208