1 /* $OpenBSD: if_runvar.h,v 1.13 2020/11/27 14:45:03 krw Exp $ */ 2 3 /*- 4 * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #define RUN_MAX_RXSZ \ 20 4096 21 #if 0 22 (sizeof (uint32_t) + \ 23 sizeof (struct rt2860_rxwi) + \ 24 sizeof (uint16_t) + \ 25 MCLBYTES + \ 26 sizeof (struct rt2870_rxd)) 27 #endif 28 /* NB: "11" is the maximum number of padding bytes needed for Tx */ 29 #define RUN_MAX_TXSZ \ 30 (sizeof (struct rt2870_txd) + \ 31 sizeof (struct rt2860_txwi) + \ 32 MCLBYTES + 11) 33 34 #define RUN_TX_TIMEOUT 5000 /* ms */ 35 36 #define RUN_RX_RING_COUNT 1 37 #define RUN_TX_RING_COUNT 8 38 39 #define RT2870_WCID_MAX 64 40 #define RUN_AID2WCID(aid) ((aid) & 0xff) 41 42 struct run_rx_radiotap_header { 43 struct ieee80211_radiotap_header wr_ihdr; 44 uint8_t wr_flags; 45 uint8_t wr_rate; 46 uint16_t wr_chan_freq; 47 uint16_t wr_chan_flags; 48 uint8_t wr_dbm_antsignal; 49 uint8_t wr_antenna; 50 uint8_t wr_antsignal; 51 } __packed; 52 53 #define RUN_RX_RADIOTAP_PRESENT \ 54 (1 << IEEE80211_RADIOTAP_FLAGS | \ 55 1 << IEEE80211_RADIOTAP_RATE | \ 56 1 << IEEE80211_RADIOTAP_CHANNEL | \ 57 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 58 1 << IEEE80211_RADIOTAP_ANTENNA | \ 59 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 60 61 struct run_tx_radiotap_header { 62 struct ieee80211_radiotap_header wt_ihdr; 63 uint8_t wt_flags; 64 uint8_t wt_rate; 65 uint16_t wt_chan_freq; 66 uint16_t wt_chan_flags; 67 } __packed; 68 69 #define RUN_TX_RADIOTAP_PRESENT \ 70 (1 << IEEE80211_RADIOTAP_FLAGS | \ 71 1 << IEEE80211_RADIOTAP_RATE | \ 72 1 << IEEE80211_RADIOTAP_CHANNEL) 73 74 struct run_softc; 75 76 struct run_tx_data { 77 struct run_softc *sc; 78 struct usbd_xfer *xfer; 79 uint8_t *buf; 80 uint8_t qid; 81 }; 82 83 struct run_rx_data { 84 struct run_softc *sc; 85 struct usbd_xfer *xfer; 86 uint8_t *buf; 87 }; 88 89 struct run_tx_ring { 90 struct run_tx_data data[RUN_TX_RING_COUNT]; 91 struct usbd_pipe *pipeh; 92 int cur; 93 int queued; 94 uint8_t pipe_no; 95 }; 96 97 struct run_rx_ring { 98 struct run_rx_data data[RUN_RX_RING_COUNT]; 99 struct usbd_pipe *pipeh; 100 uint8_t pipe_no; 101 }; 102 103 struct run_host_cmd { 104 void (*cb)(struct run_softc *, void *); 105 uint8_t data[256]; 106 }; 107 108 struct run_cmd_newstate { 109 enum ieee80211_state state; 110 int arg; 111 }; 112 113 struct run_cmd_key { 114 struct ieee80211_key key; 115 struct ieee80211_node *ni; 116 }; 117 118 #define RUN_HOST_CMD_RING_COUNT 32 119 struct run_host_cmd_ring { 120 struct run_host_cmd cmd[RUN_HOST_CMD_RING_COUNT]; 121 int cur; 122 int next; 123 int queued; 124 }; 125 126 struct run_node { 127 struct ieee80211_node ni; 128 uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 129 uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 130 }; 131 132 struct run_softc { 133 struct device sc_dev; 134 struct ieee80211com sc_ic; 135 int (*sc_newstate)(struct ieee80211com *, 136 enum ieee80211_state, int); 137 int (*sc_srom_read)(struct run_softc *, 138 uint16_t, uint16_t *); 139 140 struct usbd_device *sc_udev; 141 struct usbd_interface *sc_iface; 142 143 uint16_t mac_ver; 144 uint16_t mac_rev; 145 uint16_t rf_rev; 146 uint8_t freq; 147 uint8_t ntxchains; 148 uint8_t nrxchains; 149 int fixed_ridx; 150 151 uint8_t bbp25; 152 uint8_t bbp26; 153 uint8_t rf24_20mhz; 154 uint8_t rf24_40mhz; 155 uint8_t patch_dac; 156 uint8_t rfswitch; 157 uint8_t ext_2ghz_lna; 158 uint8_t ext_5ghz_lna; 159 uint8_t calib_2ghz; 160 uint8_t calib_5ghz; 161 uint8_t txmixgain_2ghz; 162 uint8_t txmixgain_5ghz; 163 int8_t txpow1[54]; 164 int8_t txpow2[54]; 165 int8_t txpow3[54]; 166 int8_t rssi_2ghz[3]; 167 int8_t rssi_5ghz[3]; 168 uint8_t lna[4]; 169 170 struct { 171 uint8_t reg; 172 uint8_t val; 173 } bbp[10], rf[10]; 174 uint8_t leds; 175 uint16_t led[3]; 176 uint32_t txpow20mhz[5]; 177 uint32_t txpow40mhz_2ghz[5]; 178 uint32_t txpow40mhz_5ghz[5]; 179 180 struct usb_task sc_task; 181 182 struct ieee80211_amrr amrr; 183 struct ieee80211_amrr_node amn; 184 185 struct timeout scan_to; 186 struct timeout calib_to; 187 188 struct run_rx_ring rxq; 189 struct run_tx_ring txq[4]; 190 struct run_host_cmd_ring cmdq; 191 uint8_t qfullmsk; 192 int sc_tx_timer; 193 194 #if NBPFILTER > 0 195 caddr_t sc_drvbpf; 196 197 union { 198 struct run_rx_radiotap_header th; 199 uint8_t pad[64]; 200 } sc_rxtapu; 201 #define sc_rxtap sc_rxtapu.th 202 int sc_rxtap_len; 203 204 union { 205 struct run_tx_radiotap_header th; 206 uint8_t pad[64]; 207 } sc_txtapu; 208 #define sc_txtap sc_txtapu.th 209 int sc_txtap_len; 210 #endif 211 int sc_key_tasks; 212 }; 213