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