1203134Sthompsa/* $OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $ */ 2203134Sthompsa 3203134Sthompsa/*- 4203134Sthompsa * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr> 5205042Sthompsa * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca> 6205042Sthompsa * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org> 7203134Sthompsa * 8203134Sthompsa * Permission to use, copy, modify, and distribute this software for any 9203134Sthompsa * purpose with or without fee is hereby granted, provided that the above 10203134Sthompsa * copyright notice and this permission notice appear in all copies. 11203134Sthompsa * 12203134Sthompsa * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13203134Sthompsa * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14203134Sthompsa * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15203134Sthompsa * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16203134Sthompsa * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17203134Sthompsa * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18203134Sthompsa * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19203134Sthompsa * 20203134Sthompsa * $FreeBSD: stable/11/sys/dev/usb/wlan/if_runvar.h 345636 2019-03-28 09:50:25Z avos $ 21203134Sthompsa */ 22203134Sthompsa 23203134Sthompsa#ifndef _IF_RUNVAR_H_ 24203134Sthompsa#define _IF_RUNVAR_H_ 25203134Sthompsa 26259546Skevlo#define RUN_MAX_RXSZ \ 27203134Sthompsa MIN(4096, MJUMPAGESIZE) 28259032Skevlo 29203134Sthompsa/* NB: "11" is the maximum number of padding bytes needed for Tx */ 30259546Skevlo#define RUN_MAX_TXSZ \ 31203134Sthompsa (sizeof (struct rt2870_txd) + \ 32258840Skevlo sizeof (struct rt2860_txwi) + \ 33203134Sthompsa MCLBYTES + 11) 34203134Sthompsa 35259546Skevlo#define RUN_TX_TIMEOUT 5000 /* ms */ 36203134Sthompsa 37203134Sthompsa/* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */ 38259546Skevlo#define RUN_TX_RING_COUNT 32 39259546Skevlo#define RUN_RX_RING_COUNT 1 40203134Sthompsa 41259546Skevlo#define RT2870_WCID_MAX 64 42259546Skevlo#define RUN_AID2WCID(aid) ((aid) & 0xff) 43203134Sthompsa 44259546Skevlo#define RUN_VAP_MAX 8 45208019Sthompsa 46203134Sthompsastruct run_rx_radiotap_header { 47203134Sthompsa struct ieee80211_radiotap_header wr_ihdr; 48287554Skevlo uint64_t wr_tsf; 49203134Sthompsa uint8_t wr_flags; 50203134Sthompsa uint8_t wr_rate; 51203134Sthompsa uint16_t wr_chan_freq; 52203134Sthompsa uint16_t wr_chan_flags; 53208019Sthompsa int8_t wr_dbm_antsignal; 54203134Sthompsa uint8_t wr_antenna; 55203134Sthompsa uint8_t wr_antsignal; 56253757Shselasky} __packed __aligned(8); 57203134Sthompsa 58259546Skevlo#define RUN_RX_RADIOTAP_PRESENT \ 59287554Skevlo (1 << IEEE80211_RADIOTAP_TSFT | \ 60287554Skevlo 1 << IEEE80211_RADIOTAP_FLAGS | \ 61203134Sthompsa 1 << IEEE80211_RADIOTAP_RATE | \ 62203134Sthompsa 1 << IEEE80211_RADIOTAP_CHANNEL | \ 63203134Sthompsa 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 64203134Sthompsa 1 << IEEE80211_RADIOTAP_ANTENNA | \ 65203134Sthompsa 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 66203134Sthompsa 67203134Sthompsastruct run_tx_radiotap_header { 68203134Sthompsa struct ieee80211_radiotap_header wt_ihdr; 69203134Sthompsa uint8_t wt_flags; 70203134Sthompsa uint8_t wt_rate; 71203134Sthompsa uint16_t wt_chan_freq; 72203134Sthompsa uint16_t wt_chan_flags; 73203134Sthompsa uint8_t wt_hwqueue; 74345636Savos} __packed; 75203134Sthompsa 76203134Sthompsa#define IEEE80211_RADIOTAP_HWQUEUE 15 77203134Sthompsa 78259546Skevlo#define RUN_TX_RADIOTAP_PRESENT \ 79345635Savos (1 << IEEE80211_RADIOTAP_FLAGS | \ 80203134Sthompsa 1 << IEEE80211_RADIOTAP_RATE | \ 81203134Sthompsa 1 << IEEE80211_RADIOTAP_CHANNEL | \ 82203134Sthompsa 1 << IEEE80211_RADIOTAP_HWQUEUE) 83203134Sthompsa 84203134Sthompsastruct run_softc; 85203134Sthompsa 86203134Sthompsastruct run_tx_data { 87203134Sthompsa STAILQ_ENTRY(run_tx_data) next; 88203134Sthompsa struct run_softc *sc; 89203134Sthompsa struct mbuf *m; 90203134Sthompsa struct ieee80211_node *ni; 91203134Sthompsa uint32_t align[0]; /* dummy field */ 92203134Sthompsa uint8_t desc[sizeof(struct rt2870_txd) + 93203134Sthompsa sizeof(struct rt2860_txwi)]; 94208019Sthompsa uint8_t ridx; 95203134Sthompsa}; 96203134SthompsaSTAILQ_HEAD(run_tx_data_head, run_tx_data); 97203134Sthompsa 98203134Sthompsastruct run_node { 99203134Sthompsa struct ieee80211_node ni; 100203134Sthompsa uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 101203134Sthompsa uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 102208019Sthompsa uint8_t amrr_ridx; 103208019Sthompsa uint8_t mgt_ridx; 104208019Sthompsa uint8_t fix_ridx; 105203134Sthompsa}; 106287552Skevlo#define RUN_NODE(ni) ((struct run_node *)(ni)) 107203134Sthompsa 108208019Sthompsastruct run_cmdq { 109208019Sthompsa void *arg0; 110208019Sthompsa void *arg1; 111208019Sthompsa void (*func)(void *); 112208019Sthompsa struct ieee80211_key *k; 113208019Sthompsa struct ieee80211_key key; 114208019Sthompsa uint8_t mac[IEEE80211_ADDR_LEN]; 115208019Sthompsa uint8_t wcid; 116208019Sthompsa}; 117208019Sthompsa 118203134Sthompsastruct run_vap { 119203134Sthompsa struct ieee80211vap vap; 120218492Sbschmidt struct mbuf *beacon_mbuf; 121203134Sthompsa 122203134Sthompsa int (*newstate)(struct ieee80211vap *, 123203134Sthompsa enum ieee80211_state, int); 124288603Sadrian void (*recv_mgmt)(struct ieee80211_node *, 125288603Sadrian struct mbuf *, int, 126288603Sadrian const struct ieee80211_rx_stats *, 127288603Sadrian int, int); 128208019Sthompsa 129208019Sthompsa uint8_t rvp_id; 130203134Sthompsa}; 131259546Skevlo#define RUN_VAP(vap) ((struct run_vap *)(vap)) 132203134Sthompsa 133203134Sthompsa/* 134203134Sthompsa * There are 7 bulk endpoints: 1 for RX 135203134Sthompsa * and 6 for TX (4 EDCAs + HCCA + Prio). 136203134Sthompsa * Update 03-14-2009: some devices like the Planex GW-US300MiniS 137203134Sthompsa * seem to have only 4 TX bulk endpoints (Fukaumi Naoki). 138203134Sthompsa */ 139203134Sthompsaenum { 140203134Sthompsa RUN_BULK_TX_BE, /* = WME_AC_BE */ 141203134Sthompsa RUN_BULK_TX_BK, /* = WME_AC_BK */ 142203134Sthompsa RUN_BULK_TX_VI, /* = WME_AC_VI */ 143203134Sthompsa RUN_BULK_TX_VO, /* = WME_AC_VO */ 144203134Sthompsa RUN_BULK_TX_HCCA, 145203134Sthompsa RUN_BULK_TX_PRIO, 146203134Sthompsa RUN_BULK_RX, 147203134Sthompsa RUN_N_XFER, 148203134Sthompsa}; 149203134Sthompsa 150203134Sthompsa#define RUN_EP_QUEUES RUN_BULK_RX 151203134Sthompsa 152203134Sthompsastruct run_endpoint_queue { 153203134Sthompsa struct run_tx_data tx_data[RUN_TX_RING_COUNT]; 154203134Sthompsa struct run_tx_data_head tx_qh; 155203134Sthompsa struct run_tx_data_head tx_fh; 156203134Sthompsa uint32_t tx_nfree; 157203134Sthompsa}; 158203134Sthompsa 159203134Sthompsastruct run_softc { 160287197Sglebius struct mtx sc_mtx; 161287197Sglebius struct ieee80211com sc_ic; 162287197Sglebius struct mbufq sc_snd; 163203134Sthompsa device_t sc_dev; 164203134Sthompsa struct usb_device *sc_udev; 165262465Skevlo int sc_need_fwload; 166262465Skevlo 167262465Skevlo int sc_flags; 168262465Skevlo#define RUN_FLAG_FWLOAD_NEEDED 0x01 169287197Sglebius#define RUN_RUNNING 0x02 170262465Skevlo 171218676Shselasky uint16_t wcid_stats[RT2870_WCID_MAX + 1][3]; 172218676Shselasky#define RUN_TXCNT 0 173218676Shselasky#define RUN_SUCCESS 1 174218676Shselasky#define RUN_RETRY 2 175203134Sthompsa 176203134Sthompsa int (*sc_srom_read)(struct run_softc *, 177203134Sthompsa uint16_t, uint16_t *); 178203134Sthompsa 179205042Sthompsa uint16_t mac_ver; 180205042Sthompsa uint16_t mac_rev; 181257955Skevlo uint16_t rf_rev; 182203134Sthompsa uint8_t freq; 183203134Sthompsa uint8_t ntxchains; 184203134Sthompsa uint8_t nrxchains; 185203134Sthompsa 186205042Sthompsa uint8_t bbp25; 187205042Sthompsa uint8_t bbp26; 188203134Sthompsa uint8_t rf24_20mhz; 189203134Sthompsa uint8_t rf24_40mhz; 190205042Sthompsa uint8_t patch_dac; 191205042Sthompsa uint8_t rfswitch; 192203134Sthompsa uint8_t ext_2ghz_lna; 193203134Sthompsa uint8_t ext_5ghz_lna; 194203134Sthompsa uint8_t calib_2ghz; 195203134Sthompsa uint8_t calib_5ghz; 196205042Sthompsa uint8_t txmixgain_2ghz; 197205042Sthompsa uint8_t txmixgain_5ghz; 198205042Sthompsa int8_t txpow1[54]; 199205042Sthompsa int8_t txpow2[54]; 200260219Skevlo int8_t txpow3[54]; 201203134Sthompsa int8_t rssi_2ghz[3]; 202203134Sthompsa int8_t rssi_5ghz[3]; 203203134Sthompsa uint8_t lna[4]; 204203134Sthompsa 205203134Sthompsa struct { 206203134Sthompsa uint8_t reg; 207203134Sthompsa uint8_t val; 208208019Sthompsa } bbp[10], rf[10]; 209203134Sthompsa uint8_t leds; 210203134Sthompsa uint16_t led[3]; 211203134Sthompsa uint32_t txpow20mhz[5]; 212203134Sthompsa uint32_t txpow40mhz_2ghz[5]; 213203134Sthompsa uint32_t txpow40mhz_5ghz[5]; 214203134Sthompsa 215203134Sthompsa struct run_endpoint_queue sc_epq[RUN_EP_QUEUES]; 216203134Sthompsa 217208019Sthompsa struct task ratectl_task; 218208019Sthompsa struct usb_callout ratectl_ch; 219208019Sthompsa uint8_t ratectl_run; 220259546Skevlo#define RUN_RATECTL_OFF 0 221203134Sthompsa 222208019Sthompsa/* need to be power of 2, otherwise RUN_CMDQ_GET fails */ 223259546Skevlo#define RUN_CMDQ_MAX 16 224259546Skevlo#define RUN_CMDQ_MASQ (RUN_CMDQ_MAX - 1) 225208019Sthompsa struct run_cmdq cmdq[RUN_CMDQ_MAX]; 226208019Sthompsa struct task cmdq_task; 227208019Sthompsa uint32_t cmdq_store; 228208019Sthompsa uint8_t cmdq_exec; 229208019Sthompsa uint8_t cmdq_run; 230209144Sthompsa uint8_t cmdq_key_set; 231259546Skevlo#define RUN_CMDQ_ABORT 0 232259546Skevlo#define RUN_CMDQ_GO 1 233208019Sthompsa 234203134Sthompsa struct usb_xfer *sc_xfer[RUN_N_XFER]; 235203134Sthompsa 236203134Sthompsa struct mbuf *rx_m; 237203134Sthompsa 238208019Sthompsa uint8_t fifo_cnt; 239208019Sthompsa 240208019Sthompsa uint8_t running; 241208019Sthompsa uint8_t runbmap; 242208019Sthompsa uint8_t ap_running; 243208019Sthompsa uint8_t adhoc_running; 244208019Sthompsa uint8_t sta_running; 245208019Sthompsa uint8_t rvp_cnt; 246208019Sthompsa uint8_t rvp_bmap; 247246614Shselasky uint8_t sc_detached; 248208019Sthompsa 249296356Savos uint8_t sc_bssid[IEEE80211_ADDR_LEN]; 250296356Savos 251203134Sthompsa union { 252203134Sthompsa struct run_rx_radiotap_header th; 253203134Sthompsa uint8_t pad[64]; 254203134Sthompsa } sc_rxtapu; 255203134Sthompsa#define sc_rxtap sc_rxtapu.th 256203134Sthompsa 257203134Sthompsa union { 258203134Sthompsa struct run_tx_radiotap_header th; 259203134Sthompsa uint8_t pad[64]; 260203134Sthompsa } sc_txtapu; 261203134Sthompsa#define sc_txtap sc_txtapu.th 262203134Sthompsa}; 263203134Sthompsa 264259546Skevlo#define RUN_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 265259546Skevlo#define RUN_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 266259546Skevlo#define RUN_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 267203134Sthompsa 268203134Sthompsa#endif /* _IF_RUNVAR_H_ */ 269