1069f1a80SAndrew Thompson /* $OpenBSD: if_runvar.h,v 1.3 2009/03/26 20:17:27 damien Exp $ */ 2069f1a80SAndrew Thompson 3069f1a80SAndrew Thompson /*- 4069f1a80SAndrew Thompson * Copyright (c) 2008,2009 Damien Bergamini <damien.bergamini@free.fr> 5069f1a80SAndrew Thompson * ported to FreeBSD by Akinori Furukoshi <moonlightakkiy@yahoo.ca> 63707a5e9SAndrew Thompson * USB Consulting, Hans Petter Selasky <hselasky@freebsd.org> 7069f1a80SAndrew Thompson * 8069f1a80SAndrew Thompson * Permission to use, copy, modify, and distribute this software for any 9069f1a80SAndrew Thompson * purpose with or without fee is hereby granted, provided that the above 10069f1a80SAndrew Thompson * copyright notice and this permission notice appear in all copies. 11069f1a80SAndrew Thompson * 12069f1a80SAndrew Thompson * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13069f1a80SAndrew Thompson * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14069f1a80SAndrew Thompson * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15069f1a80SAndrew Thompson * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16069f1a80SAndrew Thompson * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17069f1a80SAndrew Thompson * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18069f1a80SAndrew Thompson * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19069f1a80SAndrew Thompson */ 20069f1a80SAndrew Thompson 21069f1a80SAndrew Thompson #ifndef _IF_RUNVAR_H_ 22069f1a80SAndrew Thompson #define _IF_RUNVAR_H_ 23069f1a80SAndrew Thompson 24e649b526SAdrian Chadd /* Support up to 4KB frames - useful for A-MSDU/FF. */ 25069f1a80SAndrew Thompson #define RUN_MAX_RXSZ \ 26069f1a80SAndrew Thompson MIN(4096, MJUMPAGESIZE) 27242dbae3SKevin Lo 28e649b526SAdrian Chadd /* Support up to 8KB frames - useful for A-MSDU/FF. */ 29069f1a80SAndrew Thompson #define RUN_MAX_TXSZ \ 30069f1a80SAndrew Thompson (sizeof (struct rt2870_txd) + \ 3140588688SKevin Lo sizeof (struct rt2860_txwi) + \ 32e649b526SAdrian Chadd 8192 + 11) 33069f1a80SAndrew Thompson 34069f1a80SAndrew Thompson #define RUN_TX_TIMEOUT 5000 /* ms */ 35069f1a80SAndrew Thompson 36069f1a80SAndrew Thompson /* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */ 37069f1a80SAndrew Thompson #define RUN_TX_RING_COUNT 32 38069f1a80SAndrew Thompson #define RUN_RX_RING_COUNT 1 39069f1a80SAndrew Thompson 4085e7bb81SAndrew Thompson #define RT2870_WCID_MAX 64 41069f1a80SAndrew Thompson #define RUN_AID2WCID(aid) ((aid) & 0xff) 42069f1a80SAndrew Thompson 4385e7bb81SAndrew Thompson #define RUN_VAP_MAX 8 4485e7bb81SAndrew Thompson 45069f1a80SAndrew Thompson struct run_rx_radiotap_header { 46069f1a80SAndrew Thompson struct ieee80211_radiotap_header wr_ihdr; 47ef9c0768SKevin Lo uint64_t wr_tsf; 48069f1a80SAndrew Thompson uint8_t wr_flags; 49069f1a80SAndrew Thompson uint8_t wr_rate; 50069f1a80SAndrew Thompson uint16_t wr_chan_freq; 51069f1a80SAndrew Thompson uint16_t wr_chan_flags; 5285e7bb81SAndrew Thompson int8_t wr_dbm_antsignal; 53069f1a80SAndrew Thompson uint8_t wr_antenna; 54069f1a80SAndrew Thompson uint8_t wr_antsignal; 55e8353a7aSHans Petter Selasky } __packed __aligned(8); 56069f1a80SAndrew Thompson 57069f1a80SAndrew Thompson #define RUN_RX_RADIOTAP_PRESENT \ 58ef9c0768SKevin Lo (1 << IEEE80211_RADIOTAP_TSFT | \ 59ef9c0768SKevin Lo 1 << IEEE80211_RADIOTAP_FLAGS | \ 60069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_RATE | \ 61069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_CHANNEL | \ 62069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 63069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_ANTENNA | \ 64069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 65069f1a80SAndrew Thompson 66069f1a80SAndrew Thompson struct run_tx_radiotap_header { 67069f1a80SAndrew Thompson struct ieee80211_radiotap_header wt_ihdr; 68069f1a80SAndrew Thompson uint8_t wt_flags; 69069f1a80SAndrew Thompson uint8_t wt_rate; 70069f1a80SAndrew Thompson uint16_t wt_chan_freq; 71069f1a80SAndrew Thompson uint16_t wt_chan_flags; 72069f1a80SAndrew Thompson uint8_t wt_hwqueue; 73786ac703SAndriy Voskoboinyk } __packed; 74069f1a80SAndrew Thompson 75069f1a80SAndrew Thompson #define IEEE80211_RADIOTAP_HWQUEUE 15 76069f1a80SAndrew Thompson 77069f1a80SAndrew Thompson #define RUN_TX_RADIOTAP_PRESENT \ 78887a6324SAndriy Voskoboinyk (1 << IEEE80211_RADIOTAP_FLAGS | \ 79069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_RATE | \ 80069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_CHANNEL | \ 81069f1a80SAndrew Thompson 1 << IEEE80211_RADIOTAP_HWQUEUE) 82069f1a80SAndrew Thompson 83069f1a80SAndrew Thompson struct run_softc; 84069f1a80SAndrew Thompson 85069f1a80SAndrew Thompson struct run_tx_data { 86069f1a80SAndrew Thompson STAILQ_ENTRY(run_tx_data) next; 87069f1a80SAndrew Thompson struct run_softc *sc; 88069f1a80SAndrew Thompson struct mbuf *m; 89069f1a80SAndrew Thompson struct ieee80211_node *ni; 90069f1a80SAndrew Thompson uint32_t align[0]; /* dummy field */ 91069f1a80SAndrew Thompson uint8_t desc[sizeof(struct rt2870_txd) + 92069f1a80SAndrew Thompson sizeof(struct rt2860_txwi)]; 9385e7bb81SAndrew Thompson uint8_t ridx; 94069f1a80SAndrew Thompson }; 95069f1a80SAndrew Thompson STAILQ_HEAD(run_tx_data_head, run_tx_data); 96069f1a80SAndrew Thompson 97069f1a80SAndrew Thompson struct run_node { 98069f1a80SAndrew Thompson struct ieee80211_node ni; 9985e7bb81SAndrew Thompson uint8_t amrr_ridx; 10085e7bb81SAndrew Thompson uint8_t mgt_ridx; 10185e7bb81SAndrew Thompson uint8_t fix_ridx; 10285e7bb81SAndrew Thompson }; 103de7eb46eSKevin Lo #define RUN_NODE(ni) ((struct run_node *)(ni)) 10485e7bb81SAndrew Thompson 10585e7bb81SAndrew Thompson struct run_cmdq { 10685e7bb81SAndrew Thompson void *arg0; 10785e7bb81SAndrew Thompson void *arg1; 10885e7bb81SAndrew Thompson void (*func)(void *); 10985e7bb81SAndrew Thompson struct ieee80211_key *k; 11085e7bb81SAndrew Thompson struct ieee80211_key key; 11185e7bb81SAndrew Thompson uint8_t mac[IEEE80211_ADDR_LEN]; 11285e7bb81SAndrew Thompson uint8_t wcid; 113069f1a80SAndrew Thompson }; 114069f1a80SAndrew Thompson 115069f1a80SAndrew Thompson struct run_vap { 116069f1a80SAndrew Thompson struct ieee80211vap vap; 117e7d14e9bSBernhard Schmidt struct mbuf *beacon_mbuf; 118069f1a80SAndrew Thompson 119069f1a80SAndrew Thompson int (*newstate)(struct ieee80211vap *, 120069f1a80SAndrew Thompson enum ieee80211_state, int); 12199feb202SAdrian Chadd void (*recv_mgmt)(struct ieee80211_node *, 12299feb202SAdrian Chadd struct mbuf *, int, 12399feb202SAdrian Chadd const struct ieee80211_rx_stats *, 12499feb202SAdrian Chadd int, int); 12585e7bb81SAndrew Thompson 12685e7bb81SAndrew Thompson uint8_t rvp_id; 127069f1a80SAndrew Thompson }; 128069f1a80SAndrew Thompson #define RUN_VAP(vap) ((struct run_vap *)(vap)) 129069f1a80SAndrew Thompson 130069f1a80SAndrew Thompson /* 131069f1a80SAndrew Thompson * There are 7 bulk endpoints: 1 for RX 132069f1a80SAndrew Thompson * and 6 for TX (4 EDCAs + HCCA + Prio). 133069f1a80SAndrew Thompson * Update 03-14-2009: some devices like the Planex GW-US300MiniS 134069f1a80SAndrew Thompson * seem to have only 4 TX bulk endpoints (Fukaumi Naoki). 135069f1a80SAndrew Thompson */ 136069f1a80SAndrew Thompson enum { 137069f1a80SAndrew Thompson RUN_BULK_TX_BE, /* = WME_AC_BE */ 138069f1a80SAndrew Thompson RUN_BULK_TX_BK, /* = WME_AC_BK */ 139069f1a80SAndrew Thompson RUN_BULK_TX_VI, /* = WME_AC_VI */ 140069f1a80SAndrew Thompson RUN_BULK_TX_VO, /* = WME_AC_VO */ 141069f1a80SAndrew Thompson RUN_BULK_TX_HCCA, 142069f1a80SAndrew Thompson RUN_BULK_TX_PRIO, 143069f1a80SAndrew Thompson RUN_BULK_RX, 144069f1a80SAndrew Thompson RUN_N_XFER, 145069f1a80SAndrew Thompson }; 146069f1a80SAndrew Thompson 147069f1a80SAndrew Thompson #define RUN_EP_QUEUES RUN_BULK_RX 148069f1a80SAndrew Thompson 149069f1a80SAndrew Thompson struct run_endpoint_queue { 150069f1a80SAndrew Thompson struct run_tx_data tx_data[RUN_TX_RING_COUNT]; 151069f1a80SAndrew Thompson struct run_tx_data_head tx_qh; 152069f1a80SAndrew Thompson struct run_tx_data_head tx_fh; 153069f1a80SAndrew Thompson uint32_t tx_nfree; 154069f1a80SAndrew Thompson }; 155069f1a80SAndrew Thompson 156069f1a80SAndrew Thompson struct run_softc { 1577a79cebfSGleb Smirnoff struct mtx sc_mtx; 1587a79cebfSGleb Smirnoff struct ieee80211com sc_ic; 159f6930becSAndriy Voskoboinyk struct ieee80211_ratectl_tx_stats sc_txs; 1607a79cebfSGleb Smirnoff struct mbufq sc_snd; 161069f1a80SAndrew Thompson device_t sc_dev; 162069f1a80SAndrew Thompson struct usb_device *sc_udev; 1635c5e99d2SKevin Lo int sc_need_fwload; 1645c5e99d2SKevin Lo 1655c5e99d2SKevin Lo int sc_flags; 1665c5e99d2SKevin Lo #define RUN_FLAG_FWLOAD_NEEDED 0x01 1677a79cebfSGleb Smirnoff #define RUN_RUNNING 0x02 1685c5e99d2SKevin Lo 169f417369bSHans Petter Selasky uint16_t wcid_stats[RT2870_WCID_MAX + 1][3]; 170f417369bSHans Petter Selasky #define RUN_TXCNT 0 171f417369bSHans Petter Selasky #define RUN_SUCCESS 1 172f417369bSHans Petter Selasky #define RUN_RETRY 2 173069f1a80SAndrew Thompson 174069f1a80SAndrew Thompson int (*sc_srom_read)(struct run_softc *, 175069f1a80SAndrew Thompson uint16_t, uint16_t *); 176069f1a80SAndrew Thompson 1773707a5e9SAndrew Thompson uint16_t mac_ver; 1783707a5e9SAndrew Thompson uint16_t mac_rev; 17964891211SKevin Lo uint16_t rf_rev; 180069f1a80SAndrew Thompson uint8_t freq; 181069f1a80SAndrew Thompson uint8_t ntxchains; 182069f1a80SAndrew Thompson uint8_t nrxchains; 183069f1a80SAndrew Thompson 1843707a5e9SAndrew Thompson uint8_t bbp25; 1853707a5e9SAndrew Thompson uint8_t bbp26; 186069f1a80SAndrew Thompson uint8_t rf24_20mhz; 187069f1a80SAndrew Thompson uint8_t rf24_40mhz; 1883707a5e9SAndrew Thompson uint8_t patch_dac; 1893707a5e9SAndrew Thompson uint8_t rfswitch; 190069f1a80SAndrew Thompson uint8_t ext_2ghz_lna; 191069f1a80SAndrew Thompson uint8_t ext_5ghz_lna; 192069f1a80SAndrew Thompson uint8_t calib_2ghz; 193069f1a80SAndrew Thompson uint8_t calib_5ghz; 1943707a5e9SAndrew Thompson uint8_t txmixgain_2ghz; 1953707a5e9SAndrew Thompson uint8_t txmixgain_5ghz; 1963707a5e9SAndrew Thompson int8_t txpow1[54]; 1973707a5e9SAndrew Thompson int8_t txpow2[54]; 1987a7e01caSKevin Lo int8_t txpow3[54]; 199069f1a80SAndrew Thompson int8_t rssi_2ghz[3]; 200069f1a80SAndrew Thompson int8_t rssi_5ghz[3]; 201069f1a80SAndrew Thompson uint8_t lna[4]; 202069f1a80SAndrew Thompson 203069f1a80SAndrew Thompson struct { 204069f1a80SAndrew Thompson uint8_t reg; 205069f1a80SAndrew Thompson uint8_t val; 20685e7bb81SAndrew Thompson } bbp[10], rf[10]; 207069f1a80SAndrew Thompson uint8_t leds; 208069f1a80SAndrew Thompson uint16_t led[3]; 209069f1a80SAndrew Thompson uint32_t txpow20mhz[5]; 210069f1a80SAndrew Thompson uint32_t txpow40mhz_2ghz[5]; 211069f1a80SAndrew Thompson uint32_t txpow40mhz_5ghz[5]; 212069f1a80SAndrew Thompson 213069f1a80SAndrew Thompson struct run_endpoint_queue sc_epq[RUN_EP_QUEUES]; 214069f1a80SAndrew Thompson 21585e7bb81SAndrew Thompson struct task ratectl_task; 21685e7bb81SAndrew Thompson struct usb_callout ratectl_ch; 21785e7bb81SAndrew Thompson uint8_t ratectl_run; 21885e7bb81SAndrew Thompson #define RUN_RATECTL_OFF 0 21985e7bb81SAndrew Thompson 22085e7bb81SAndrew Thompson /* need to be power of 2, otherwise RUN_CMDQ_GET fails */ 22185e7bb81SAndrew Thompson #define RUN_CMDQ_MAX 16 22285e7bb81SAndrew Thompson #define RUN_CMDQ_MASQ (RUN_CMDQ_MAX - 1) 22385e7bb81SAndrew Thompson struct run_cmdq cmdq[RUN_CMDQ_MAX]; 22485e7bb81SAndrew Thompson struct task cmdq_task; 22585e7bb81SAndrew Thompson uint32_t cmdq_store; 22685e7bb81SAndrew Thompson uint8_t cmdq_exec; 22785e7bb81SAndrew Thompson uint8_t cmdq_run; 228beaa0537SAndrew Thompson uint8_t cmdq_key_set; 22985e7bb81SAndrew Thompson #define RUN_CMDQ_ABORT 0 23085e7bb81SAndrew Thompson #define RUN_CMDQ_GO 1 231069f1a80SAndrew Thompson 232069f1a80SAndrew Thompson struct usb_xfer *sc_xfer[RUN_N_XFER]; 233069f1a80SAndrew Thompson 234069f1a80SAndrew Thompson struct mbuf *rx_m; 235069f1a80SAndrew Thompson 23685e7bb81SAndrew Thompson uint8_t fifo_cnt; 23785e7bb81SAndrew Thompson 23885e7bb81SAndrew Thompson uint8_t running; 23985e7bb81SAndrew Thompson uint8_t runbmap; 24085e7bb81SAndrew Thompson uint8_t ap_running; 24185e7bb81SAndrew Thompson uint8_t adhoc_running; 24285e7bb81SAndrew Thompson uint8_t sta_running; 24385e7bb81SAndrew Thompson uint8_t rvp_cnt; 24485e7bb81SAndrew Thompson uint8_t rvp_bmap; 245645e4d17SHans Petter Selasky uint8_t sc_detached; 24685e7bb81SAndrew Thompson 247ae132f11SAndriy Voskoboinyk uint8_t sc_bssid[IEEE80211_ADDR_LEN]; 248ae132f11SAndriy Voskoboinyk 249069f1a80SAndrew Thompson union { 250069f1a80SAndrew Thompson struct run_rx_radiotap_header th; 251069f1a80SAndrew Thompson uint8_t pad[64]; 252069f1a80SAndrew Thompson } sc_rxtapu; 253069f1a80SAndrew Thompson #define sc_rxtap sc_rxtapu.th 254069f1a80SAndrew Thompson 255069f1a80SAndrew Thompson union { 256069f1a80SAndrew Thompson struct run_tx_radiotap_header th; 257069f1a80SAndrew Thompson uint8_t pad[64]; 258069f1a80SAndrew Thompson } sc_txtapu; 259069f1a80SAndrew Thompson #define sc_txtap sc_txtapu.th 260069f1a80SAndrew Thompson }; 261069f1a80SAndrew Thompson 262069f1a80SAndrew Thompson #define RUN_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 263069f1a80SAndrew Thompson #define RUN_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 264069f1a80SAndrew Thompson #define RUN_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 265069f1a80SAndrew Thompson 266069f1a80SAndrew Thompson #endif /* _IF_RUNVAR_H_ */ 267