1 /* $OpenBSD: if_runvar.h,v 1.8 2010/02/08 18:46:47 damien 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_rxwi) + \ 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 253 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 uint8_t wt_hwqueue; 68 } __packed; 69 70 #define RUN_TX_RADIOTAP_PRESENT \ 71 (1 << IEEE80211_RADIOTAP_FLAGS | \ 72 1 << IEEE80211_RADIOTAP_RATE | \ 73 1 << IEEE80211_RADIOTAP_CHANNEL | \ 74 1 << IEEE80211_RADIOTAP_HWQUEUE) 75 76 struct run_softc; 77 78 struct run_tx_data { 79 struct run_softc *sc; 80 usbd_xfer_handle xfer; 81 uint8_t *buf; 82 uint8_t qid; 83 }; 84 85 struct run_rx_data { 86 struct run_softc *sc; 87 usbd_xfer_handle xfer; 88 uint8_t *buf; 89 }; 90 91 struct run_tx_ring { 92 struct run_tx_data data[RUN_TX_RING_COUNT]; 93 usbd_pipe_handle pipeh; 94 int cur; 95 int queued; 96 uint8_t pipe_no; 97 }; 98 99 struct run_rx_ring { 100 struct run_rx_data data[RUN_RX_RING_COUNT]; 101 usbd_pipe_handle pipeh; 102 uint8_t pipe_no; 103 }; 104 105 struct run_host_cmd { 106 void (*cb)(struct run_softc *, void *); 107 uint8_t data[256]; 108 }; 109 110 struct run_cmd_newstate { 111 enum ieee80211_state state; 112 int arg; 113 }; 114 115 struct run_cmd_key { 116 struct ieee80211_key key; 117 uint16_t associd; 118 }; 119 120 #define RUN_HOST_CMD_RING_COUNT 32 121 struct run_host_cmd_ring { 122 struct run_host_cmd cmd[RUN_HOST_CMD_RING_COUNT]; 123 int cur; 124 int next; 125 int queued; 126 }; 127 128 struct run_node { 129 struct ieee80211_node ni; 130 uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 131 uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 132 }; 133 134 struct run_softc { 135 struct device sc_dev; 136 struct ieee80211com sc_ic; 137 int (*sc_newstate)(struct ieee80211com *, 138 enum ieee80211_state, int); 139 int (*sc_srom_read)(struct run_softc *, 140 uint16_t, uint16_t *); 141 142 usbd_device_handle sc_udev; 143 usbd_interface_handle sc_iface; 144 145 uint16_t mac_ver; 146 uint16_t mac_rev; 147 uint8_t rf_rev; 148 uint8_t freq; 149 uint8_t ntxchains; 150 uint8_t nrxchains; 151 int fixed_ridx; 152 153 uint8_t bbp25; 154 uint8_t bbp26; 155 uint8_t rf24_20mhz; 156 uint8_t rf24_40mhz; 157 uint8_t patch_dac; 158 uint8_t rfswitch; 159 uint8_t ext_2ghz_lna; 160 uint8_t ext_5ghz_lna; 161 uint8_t calib_2ghz; 162 uint8_t calib_5ghz; 163 uint8_t txmixgain_2ghz; 164 uint8_t txmixgain_5ghz; 165 int8_t txpow1[54]; 166 int8_t txpow2[54]; 167 int8_t rssi_2ghz[3]; 168 int8_t rssi_5ghz[3]; 169 uint8_t lna[4]; 170 171 struct { 172 uint8_t reg; 173 uint8_t val; 174 } bbp[10], rf[10]; 175 uint8_t leds; 176 uint16_t led[3]; 177 uint32_t txpow20mhz[5]; 178 uint32_t txpow40mhz_2ghz[5]; 179 uint32_t txpow40mhz_5ghz[5]; 180 181 struct usb_task sc_task; 182 183 struct ieee80211_amrr amrr; 184 struct ieee80211_amrr_node amn; 185 186 struct timeout scan_to; 187 struct timeout calib_to; 188 189 struct run_rx_ring rxq; 190 struct run_tx_ring txq[4]; 191 struct run_host_cmd_ring cmdq; 192 uint8_t qfullmsk; 193 int sc_tx_timer; 194 195 #if NBPFILTER > 0 196 caddr_t sc_drvbpf; 197 198 union { 199 struct run_rx_radiotap_header th; 200 uint8_t pad[64]; 201 } sc_rxtapu; 202 #define sc_rxtap sc_rxtapu.th 203 int sc_rxtap_len; 204 205 union { 206 struct run_tx_radiotap_header th; 207 uint8_t pad[64]; 208 } sc_txtapu; 209 #define sc_txtap sc_txtapu.th 210 int sc_txtap_len; 211 #endif 212 }; 213