1/* $NetBSD: if_rtwnreg.h,v 1.6 2019/10/05 23:27:20 mrg Exp $ */ 2/* $OpenBSD: if_rtwnreg.h,v 1.3 2015/06/14 08:02:47 stsp Exp $ */ 3 4/*- 5 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 6 * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#ifndef _DEV_PCI_RTWNREG_H_ 22#define _DEV_PCI_RTWNREG_H_ 23 24/* Maximum number of output pipes is 3. */ 25#define R92C_MAX_EPOUT 3 26 27#define R92C_PUBQ_NPAGES 176 28#define R92C_HPQ_NPAGES 41 29#define R92C_LPQ_NPAGES 28 30#define R92C_TXPKTBUF_COUNT 256 31#define R92C_TX_PAGE_COUNT \ 32 (R92C_PUBQ_NPAGES + R92C_HPQ_NPAGES + R92C_LPQ_NPAGES) 33#define R92C_TX_PAGE_BOUNDARY (R92C_TX_PAGE_COUNT + 1) 34 35/* USB Requests. */ 36#define R92C_REQ_REGS 0x05 37 38/* 39 * Driver definitions. 40 */ 41#define RTWN_NTXQUEUES 9 42#define RTWN_RX_LIST_COUNT 256 43#define RTWN_TX_LIST_COUNT 256 44#define RTWN_TX_LIST_LOMARK 192 45#define RTWN_TX_LIST_HIMARK 255 46#define RTWN_HOST_CMD_RING_COUNT 32 47 48/* TX queue indices. */ 49#define RTWN_BK_QUEUE 0 50#define RTWN_BE_QUEUE 1 51#define RTWN_VI_QUEUE 2 52#define RTWN_VO_QUEUE 3 53#define RTWN_BEACON_QUEUE 4 54#define RTWN_TXCMD_QUEUE 5 55#define RTWN_MGNT_QUEUE 6 56#define RTWN_HIGH_QUEUE 7 57#define RTWN_HCCA_QUEUE 8 58 59/* RX queue indices. */ 60#define RTWN_RX_QUEUE 0 61 62#define RTWN_RXBUFSZ (16 * 1024) 63#define RTWN_TXBUFSZ (sizeof(struct r92c_tx_desc) + IEEE80211_MAX_LEN) 64 65#define RTWN_RIDX_COUNT 28 66 67#define RTWN_TX_TIMEOUT 5000 /* ms */ 68 69#define RTWN_LED_LINK 0 70#define RTWN_LED_DATA 1 71 72struct rtwn_rx_radiotap_header { 73 struct ieee80211_radiotap_header wr_ihdr; 74 uint8_t wr_flags; 75 uint8_t wr_rate; 76 uint16_t wr_chan_freq; 77 uint16_t wr_chan_flags; 78 uint8_t wr_dbm_antsignal; 79}; 80 81#define RTWN_RX_RADIOTAP_PRESENT \ 82 (1 << IEEE80211_RADIOTAP_FLAGS | \ 83 1 << IEEE80211_RADIOTAP_RATE | \ 84 1 << IEEE80211_RADIOTAP_CHANNEL | \ 85 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) 86 87struct rtwn_tx_radiotap_header { 88 struct ieee80211_radiotap_header wt_ihdr; 89 uint8_t wt_flags; 90 uint16_t wt_chan_freq; 91 uint16_t wt_chan_flags; 92}; 93 94#define RTWN_TX_RADIOTAP_PRESENT \ 95 (1 << IEEE80211_RADIOTAP_FLAGS | \ 96 1 << IEEE80211_RADIOTAP_CHANNEL) 97 98struct rtwn_softc; 99 100struct rtwn_rx_data { 101 bus_dmamap_t map; 102 struct mbuf *m; 103}; 104 105struct rtwn_rx_ring { 106 struct r92c_rx_desc_pci *desc; 107 bus_dmamap_t map; 108 bus_dma_segment_t seg; 109 int nsegs; 110 struct rtwn_rx_data rx_data[RTWN_RX_LIST_COUNT]; 111 112}; 113struct rtwn_tx_data { 114 bus_dmamap_t map; 115 struct mbuf *m; 116 struct ieee80211_node *ni; 117}; 118 119struct rtwn_tx_ring { 120 bus_dmamap_t map; 121 bus_dma_segment_t seg; 122 int nsegs; 123 struct r92c_tx_desc_pci *desc; 124 struct rtwn_tx_data tx_data[RTWN_TX_LIST_COUNT]; 125 int queued; 126 int cur; 127}; 128 129struct rtwn_host_cmd { 130 void (*cb)(struct rtwn_softc *, void *); 131 uint8_t data[256]; 132}; 133 134struct rtwn_cmd_key { 135 struct ieee80211_key key; 136 uint16_t associd; 137}; 138 139struct rtwn_host_cmd_ring { 140 struct rtwn_host_cmd cmd[RTWN_HOST_CMD_RING_COUNT]; 141 int cur; 142 int next; 143 int queued; 144}; 145 146struct rtwn_softc { 147 device_t sc_dev; 148 struct ethercom sc_ec; 149 struct ieee80211com sc_ic; 150 int (*sc_newstate)(struct ieee80211com *, 151 enum ieee80211_state, int); 152 153 /* PCI specific goo. */ 154 bus_dma_tag_t sc_dmat; 155 pci_chipset_tag_t sc_pc; 156 pcitag_t sc_tag; 157 void *sc_ih; 158 pci_intr_handle_t *sc_pihp; 159 bus_space_tag_t sc_st; 160 bus_space_handle_t sc_sh; 161 bus_size_t sc_mapsize; 162 int sc_cap_off; 163 void *sc_soft_ih; 164 165 struct callout scan_to; 166 struct callout calib_to; 167 void *init_task; 168 int ac2idx[WME_NUM_AC]; 169 uint32_t sc_flags; 170#define RTWN_FLAG_FW_LOADED __BIT(0) 171#define RTWN_FLAG_CCK_HIPWR __BIT(1) 172 173 uint32_t chip; 174#define RTWN_CHIP_88C __BIT(0) 175#define RTWN_CHIP_92C __BIT(1) 176#define RTWN_CHIP_92C_1T2R __BIT(2) 177#define RTWN_CHIP_UMC __BIT(3) 178#define RTWN_CHIP_UMC_A_CUT __BIT(4) 179#define RTWN_CHIP_UMC_B_CUT __BIT(5) 180 181 uint8_t board_type; 182 uint8_t regulatory; 183 uint8_t pa_setting; 184 int avg_pwdb; 185 int thcal_state; 186 int thcal_lctemp; 187 int ntxchains; 188 int nrxchains; 189 int ledlink; 190 191 int sc_tx_timer; 192 int fwcur; 193 struct rtwn_rx_ring rx_ring; 194 struct rtwn_tx_ring tx_ring[RTWN_NTXQUEUES]; 195 uint32_t qfullmsk; 196 struct r92c_rom rom; 197 198 uint32_t rf_chnlbw[R92C_MAX_CHAINS]; 199 struct bpf_if *sc_drvbpf; 200 201 union { 202 struct rtwn_rx_radiotap_header th; 203 uint8_t pad[64]; 204 } sc_rxtapu; 205#define sc_rxtap sc_rxtapu.th 206 int sc_rxtap_len; 207 208 union { 209 struct rtwn_tx_radiotap_header th; 210 uint8_t pad[64]; 211 } sc_txtapu; 212#define sc_txtap sc_txtapu.th 213 int sc_txtap_len; 214}; 215 216#define sc_if sc_ec.ec_if 217#define GET_IFP(sc) (&(sc)->sc_if) 218#define IC2IFP(ic) ((ic)->ic_ifp) 219 220#endif /* _DEV_PCI_RTWNREG_H_ */ 221