1 1.6 mrg /* $NetBSD: rt2860var.h,v 1.6 2019/10/05 23:27:20 mrg Exp $ */ 2 1.1 christos /* $OpenBSD: rt2860var.h,v 1.23 2016/03/21 21:16:30 stsp Exp $ */ 3 1.1 christos 4 1.1 christos /*- 5 1.1 christos * Copyright (c) 2007 6 1.1 christos * Damien Bergamini <damien.bergamini (at) free.fr> 7 1.1 christos * 8 1.1 christos * Permission to use, copy, modify, and distribute this software for any 9 1.1 christos * purpose with or without fee is hereby granted, provided that the above 10 1.1 christos * copyright notice and this permission notice appear in all copies. 11 1.1 christos * 12 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 1.1 christos */ 20 1.1 christos 21 1.1 christos #define RT2860_MAX_SCATTER 15 22 1.1 christos #define RT2860_MAX_SCATTER_TXD (1 + (RT2860_MAX_SCATTER / 2)) 23 1.1 christos 24 1.1 christos #define RT2860_RX_RING_COUNT 128 25 1.1 christos #define RT2860_TX_RING_COUNT 64 26 1.1 christos #define RT2860_TX_RING_MAX (RT2860_TX_RING_COUNT - 1) 27 1.1 christos #define RT2860_TX_RING_ONEMORE (RT2860_TX_RING_MAX - RT2860_MAX_SCATTER_TXD) 28 1.1 christos #define RT2860_TX_POOL_COUNT (RT2860_TX_RING_COUNT * 2) 29 1.1 christos 30 1.1 christos /* HW supports up to 255 STAs */ 31 1.1 christos #define RT2860_WCID_MAX 254 32 1.1 christos #define RT2860_AID2WCID(aid) ((aid) & 0xff) 33 1.1 christos 34 1.2 christos #define IEEE80211_NO_HT 35 1.2 christos 36 1.1 christos struct rt2860_rx_radiotap_header { 37 1.1 christos struct ieee80211_radiotap_header wr_ihdr; 38 1.1 christos uint8_t wr_flags; 39 1.1 christos uint8_t wr_rate; 40 1.1 christos uint16_t wr_chan_freq; 41 1.1 christos uint16_t wr_chan_flags; 42 1.1 christos uint8_t wr_dbm_antsignal; 43 1.1 christos uint8_t wr_antenna; 44 1.1 christos uint8_t wr_antsignal; 45 1.6 mrg } __aligned(8); 46 1.1 christos 47 1.1 christos #define RT2860_RX_RADIOTAP_PRESENT \ 48 1.1 christos (1 << IEEE80211_RADIOTAP_FLAGS | \ 49 1.1 christos 1 << IEEE80211_RADIOTAP_RATE | \ 50 1.1 christos 1 << IEEE80211_RADIOTAP_CHANNEL | \ 51 1.1 christos 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 52 1.1 christos 1 << IEEE80211_RADIOTAP_ANTENNA | \ 53 1.1 christos 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 54 1.1 christos 55 1.1 christos struct rt2860_tx_radiotap_header { 56 1.1 christos struct ieee80211_radiotap_header wt_ihdr; 57 1.1 christos uint8_t wt_flags; 58 1.1 christos uint8_t wt_rate; 59 1.1 christos uint16_t wt_chan_freq; 60 1.1 christos uint16_t wt_chan_flags; 61 1.1 christos uint8_t wt_hwqueue; 62 1.6 mrg } __aligned(8); 63 1.1 christos 64 1.1 christos #define RT2860_TX_RADIOTAP_PRESENT \ 65 1.1 christos (1 << IEEE80211_RADIOTAP_FLAGS | \ 66 1.1 christos 1 << IEEE80211_RADIOTAP_RATE | \ 67 1.2 christos 1 << IEEE80211_RADIOTAP_CHANNEL) 68 1.1 christos 69 1.1 christos struct rt2860_tx_data { 70 1.1 christos struct rt2860_txwi *txwi; 71 1.1 christos struct mbuf *m; 72 1.1 christos struct ieee80211_node *ni; 73 1.1 christos bus_dmamap_t map; 74 1.1 christos bus_addr_t paddr; 75 1.1 christos SLIST_ENTRY(rt2860_tx_data) next; 76 1.1 christos }; 77 1.1 christos 78 1.1 christos struct rt2860_tx_ring { 79 1.1 christos struct rt2860_txd *txd; 80 1.1 christos bus_addr_t paddr; 81 1.1 christos bus_dmamap_t map; 82 1.1 christos bus_dma_segment_t seg; 83 1.1 christos struct rt2860_tx_data *data[RT2860_TX_RING_COUNT]; 84 1.1 christos int cur; 85 1.1 christos int next; 86 1.1 christos int queued; 87 1.1 christos }; 88 1.1 christos 89 1.1 christos struct rt2860_rx_data { 90 1.1 christos struct mbuf *m; 91 1.1 christos bus_dmamap_t map; 92 1.1 christos }; 93 1.1 christos 94 1.1 christos struct rt2860_rx_ring { 95 1.1 christos struct rt2860_rxd *rxd; 96 1.1 christos bus_addr_t paddr; 97 1.1 christos bus_dmamap_t map; 98 1.1 christos bus_dma_segment_t seg; 99 1.1 christos unsigned int cur; /* must be unsigned */ 100 1.1 christos struct rt2860_rx_data data[RT2860_RX_RING_COUNT]; 101 1.1 christos }; 102 1.1 christos 103 1.1 christos struct rt2860_node { 104 1.1 christos struct ieee80211_node ni; 105 1.1 christos uint8_t wcid; 106 1.1 christos uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 107 1.1 christos uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 108 1.1 christos }; 109 1.1 christos 110 1.1 christos struct rt2860_softc { 111 1.2 christos device_t sc_dev; 112 1.1 christos 113 1.1 christos struct ieee80211com sc_ic; 114 1.1 christos int (*sc_newstate)(struct ieee80211com *, 115 1.1 christos enum ieee80211_state, int); 116 1.1 christos 117 1.1 christos int (*sc_enable)(struct rt2860_softc *); 118 1.1 christos void (*sc_disable)(struct rt2860_softc *); 119 1.1 christos 120 1.1 christos bus_dma_tag_t sc_dmat; 121 1.1 christos bus_space_tag_t sc_st; 122 1.1 christos bus_space_handle_t sc_sh; 123 1.4 nonaka void *sc_soft_ih; 124 1.1 christos 125 1.2 christos struct ethercom sc_ec; 126 1.2 christos #define sc_if sc_ec.ec_if 127 1.2 christos 128 1.1 christos uint16_t (*sc_srom_read)(struct rt2860_softc *, 129 1.1 christos uint16_t); 130 1.1 christos 131 1.1 christos int sc_flags; 132 1.1 christos #define RT2860_ENABLED (1 << 0) 133 1.1 christos #define RT2860_ADVANCED_PS (1 << 1) 134 1.1 christos #define RT2860_PCIE (1 << 2) 135 1.3 christos #define RT2860_RUNNING (1 << 3) 136 1.1 christos 137 1.2 christos struct ieee80211_amrr amrr; 138 1.2 christos 139 1.1 christos uint32_t sc_ic_flags; 140 1.1 christos int fixed_ridx; 141 1.1 christos 142 1.1 christos u_char *ucode; 143 1.1 christos size_t ucsize; 144 1.1 christos 145 1.1 christos struct rt2860_tx_ring txq[6]; 146 1.1 christos struct rt2860_rx_ring rxq; 147 1.1 christos 148 1.1 christos SLIST_HEAD(, rt2860_tx_data) data_pool; 149 1.1 christos struct rt2860_tx_data data[RT2860_TX_POOL_COUNT]; 150 1.1 christos bus_dmamap_t txwi_map; 151 1.1 christos bus_dma_segment_t txwi_seg; 152 1.2 christos void *txwi_vaddr; 153 1.1 christos 154 1.1 christos int sc_tx_timer; 155 1.2 christos struct ieee80211_beacon_offsets sc_bo; 156 1.1 christos int mgtqid; 157 1.1 christos uint8_t qfullmsk; 158 1.1 christos 159 1.1 christos uint16_t mac_ver; 160 1.1 christos uint16_t mac_rev; 161 1.3 christos uint32_t rf_rev; 162 1.1 christos uint8_t freq; 163 1.1 christos uint8_t ntxchains; 164 1.1 christos uint8_t nrxchains; 165 1.1 christos uint8_t pslevel; 166 1.1 christos int8_t txpow1[54]; 167 1.1 christos int8_t txpow2[54]; 168 1.1 christos int8_t rssi_2ghz[3]; 169 1.1 christos int8_t rssi_5ghz[3]; 170 1.1 christos uint8_t lna[4]; 171 1.1 christos uint8_t rf24_20mhz; 172 1.1 christos uint8_t rf24_40mhz; 173 1.1 christos uint8_t patch_dac; 174 1.1 christos uint8_t rfswitch; 175 1.1 christos uint8_t ext_2ghz_lna; 176 1.1 christos uint8_t ext_5ghz_lna; 177 1.1 christos uint8_t calib_2ghz; 178 1.1 christos uint8_t calib_5ghz; 179 1.1 christos uint8_t txmixgain_2ghz; 180 1.1 christos uint8_t txmixgain_5ghz; 181 1.1 christos uint8_t tssi_2ghz[9]; 182 1.1 christos uint8_t tssi_5ghz[9]; 183 1.1 christos uint8_t step_2ghz; 184 1.1 christos uint8_t step_5ghz; 185 1.1 christos struct { 186 1.1 christos uint8_t reg; 187 1.1 christos uint8_t val; 188 1.1 christos } bbp[8], rf[10]; 189 1.1 christos uint8_t leds; 190 1.1 christos uint16_t led[3]; 191 1.1 christos uint32_t txpow20mhz[5]; 192 1.1 christos uint32_t txpow40mhz_2ghz[5]; 193 1.1 christos uint32_t txpow40mhz_5ghz[5]; 194 1.1 christos 195 1.1 christos struct ieee80211_amrr_node amn[RT2860_WCID_MAX + 1]; 196 1.1 christos 197 1.2 christos struct bpf_if *sc_drvbpf; 198 1.1 christos union { 199 1.1 christos struct rt2860_rx_radiotap_header th; 200 1.1 christos uint8_t pad[64]; 201 1.1 christos } sc_rxtapu; 202 1.1 christos #define sc_rxtap sc_rxtapu.th 203 1.1 christos int sc_rxtap_len; 204 1.1 christos 205 1.1 christos union { 206 1.1 christos struct rt2860_tx_radiotap_header th; 207 1.1 christos uint8_t pad[64]; 208 1.1 christos } sc_txtapu; 209 1.1 christos #define sc_txtap sc_txtapu.th 210 1.1 christos int sc_txtap_len; 211 1.1 christos }; 212 1.1 christos 213 1.1 christos int rt2860_attach(void *, int); 214 1.1 christos int rt2860_detach(void *); 215 1.1 christos int rt2860_intr(void *); 216