1 /* $NetBSD: if_urtwnvar.h,v 1.11 2018/06/29 04:02:10 thorpej Exp $ */ 2 /* $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $ */ 3 4 /*- 5 * Copyright (c) 2010 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 #ifndef _IF_URTWNVAR_H_ 20 #define _IF_URTWNVAR_H_ 21 22 /* 23 * Driver definitions. 24 */ 25 #define URTWN_RX_LIST_COUNT 1 26 #define URTWN_TX_LIST_COUNT 8 27 28 #define URTWN_HOST_CMD_RING_COUNT 32 29 30 #define URTWN_RXBUFSZ (16 * 1024) 31 #define URTWN_TXBUFSZ (sizeof(struct r92c_tx_desc_usb) + IEEE80211_MAX_LEN + 8) 32 33 #define URTWN_RIDX_COUNT 28 34 35 #define URTWN_TX_TIMEOUT 5000 /* ms */ 36 37 #define URTWN_LED_LINK 0 38 #define URTWN_LED_DATA 1 39 40 struct urtwn_rx_radiotap_header { 41 struct ieee80211_radiotap_header wr_ihdr; 42 uint8_t wr_flags; 43 uint8_t wr_rate; 44 uint16_t wr_chan_freq; 45 uint16_t wr_chan_flags; 46 uint8_t wr_dbm_antsignal; 47 } __packed; 48 49 #define URTWN_RX_RADIOTAP_PRESENT \ 50 (1 << IEEE80211_RADIOTAP_FLAGS | \ 51 1 << IEEE80211_RADIOTAP_RATE | \ 52 1 << IEEE80211_RADIOTAP_CHANNEL | \ 53 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) 54 55 struct urtwn_tx_radiotap_header { 56 struct ieee80211_radiotap_header wt_ihdr; 57 uint8_t wt_flags; 58 uint16_t wt_chan_freq; 59 uint16_t wt_chan_flags; 60 } __packed; 61 62 #define URTWN_TX_RADIOTAP_PRESENT \ 63 (1 << IEEE80211_RADIOTAP_FLAGS | \ 64 1 << IEEE80211_RADIOTAP_CHANNEL) 65 66 struct urtwn_softc; 67 68 struct urtwn_rx_data { 69 struct urtwn_softc *sc; 70 size_t pidx; 71 struct usbd_xfer *xfer; 72 uint8_t *buf; 73 TAILQ_ENTRY(urtwn_rx_data) next; 74 }; 75 76 struct urtwn_tx_data { 77 struct urtwn_softc *sc; 78 size_t pidx; 79 struct usbd_xfer *xfer; 80 uint8_t *buf; 81 TAILQ_ENTRY(urtwn_tx_data) next; 82 }; 83 84 struct urtwn_host_cmd { 85 void (*cb)(struct urtwn_softc *, void *); 86 uint8_t data[256]; 87 }; 88 89 struct urtwn_cmd_newstate { 90 enum ieee80211_state state; 91 int arg; 92 }; 93 94 struct urtwn_host_cmd_ring { 95 struct urtwn_host_cmd cmd[URTWN_HOST_CMD_RING_COUNT]; 96 int cur; 97 int next; 98 int queued; 99 }; 100 101 #if 1 /* XXX: sys/net80211/ieee80211.h */ 102 103 #define IEEE80211_HTINFO_2NDCHAN 0x03 /* secondary/ext chan offset */ 104 #define IEEE80211_HTINFO_2NDCHAN_S 0 105 #define IEEE80211_HTINFO_2NDCHAN_NONE 0x00 /* no secondary/ext channel */ 106 #define IEEE80211_HTINFO_2NDCHAN_ABOVE 0x01 /* above private channel */ 107 /* NB: 2 is reserved */ 108 #define IEEE80211_HTINFO_2NDCHAN_BELOW 0x03 /* below primary channel */ 109 #endif /* XXX: 1 */ 110 111 struct urtwn_softc { 112 device_t sc_dev; 113 struct ieee80211com sc_ic; 114 struct ethercom sc_ec; 115 #define sc_if sc_ec.ec_if 116 int (*sc_newstate)(struct ieee80211com *, 117 enum ieee80211_state, int); 118 119 struct usbd_device * sc_udev; 120 struct usbd_interface * sc_iface; 121 u_int sc_flags; 122 #define URTWN_FLAG_CCK_HIPWR __BIT(0) 123 #define URTWN_FLAG_ATTACHED __BIT(1) 124 #define URTWN_FLAG_FWREADY __BIT(2) 125 int sc_dying; 126 127 struct usb_task sc_task; 128 callout_t sc_scan_to; 129 callout_t sc_calib_to; 130 131 kmutex_t sc_task_mtx; 132 kmutex_t sc_fwcmd_mtx; 133 kmutex_t sc_tx_mtx; 134 kmutex_t sc_rx_mtx; 135 kmutex_t sc_write_mtx; 136 137 struct usbd_pipe * rx_pipe[R92C_MAX_EPIN]; 138 int rx_npipe; 139 struct usbd_pipe * tx_pipe[R92C_MAX_EPOUT]; 140 int tx_npipe; 141 int ac2idx[WME_NUM_AC]; 142 143 u_int chip; 144 #define URTWN_CHIP_92C 0x01 145 #define URTWN_CHIP_92C_1T2R 0x02 146 #define URTWN_CHIP_UMC 0x04 147 #define URTWN_CHIP_UMC_A_CUT 0x08 148 #define URTWN_CHIP_88E 0x10 149 #define URTWN_CHIP_92EU 0x20 150 151 void (*sc_rf_write)(struct urtwn_softc *, 152 int, uint8_t, uint32_t); 153 int (*sc_power_on)(struct urtwn_softc *); 154 int (*sc_dma_init)(struct urtwn_softc *); 155 156 uint8_t board_type; 157 uint8_t regulatory; 158 uint8_t pa_setting; 159 int avg_pwdb; 160 int thcal_state; 161 int thcal_lctemp; 162 size_t ntxchains; 163 size_t nrxchains; 164 int ledlink; 165 bool iqk_inited; 166 167 int tx_timer; 168 169 struct urtwn_host_cmd_ring cmdq; 170 int fwcur; 171 struct urtwn_rx_data rx_data[R92C_MAX_EPIN][URTWN_RX_LIST_COUNT]; 172 struct urtwn_tx_data tx_data[R92C_MAX_EPOUT][URTWN_TX_LIST_COUNT]; 173 TAILQ_HEAD(, urtwn_tx_data) tx_free_list[R92C_MAX_EPOUT]; 174 TAILQ_HEAD(, urtwn_rx_data) rx_free_list[R92C_MAX_EPIN]; 175 176 struct r92c_rom rom; 177 uint8_t r88e_rom[4096]; 178 uint8_t cck_tx_pwr[6]; 179 uint8_t ht40_tx_pwr[5]; 180 int8_t bw20_tx_pwr_diff; 181 int8_t ofdm_tx_pwr_diff; 182 183 uint32_t rf_chnlbw[R92C_MAX_CHAINS]; 184 185 struct bpf_if * sc_drvbpf; 186 union { 187 struct urtwn_rx_radiotap_header th; 188 uint8_t pad[64]; 189 } sc_rxtapu; 190 #define sc_rxtap sc_rxtapu.th 191 int sc_rxtap_len; 192 union { 193 struct urtwn_tx_radiotap_header th; 194 uint8_t pad[64]; 195 } sc_txtapu; 196 #define sc_txtap sc_txtapu.th 197 int sc_txtap_len; 198 bool sc_running; 199 }; 200 201 #endif /* _IF_URTWNVAR_H_ */ 202