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$ 21203134Sthompsa */ 22203134Sthompsa 23203134Sthompsa#ifndef _IF_RUNVAR_H_ 24203134Sthompsa#define _IF_RUNVAR_H_ 25203134Sthompsa 26261868Skevlo#define RUN_MAX_RXSZ \ 27203134Sthompsa MIN(4096, MJUMPAGESIZE) 28259453Shselasky 29203134Sthompsa/* NB: "11" is the maximum number of padding bytes needed for Tx */ 30261868Skevlo#define RUN_MAX_TXSZ \ 31203134Sthompsa (sizeof (struct rt2870_txd) + \ 32259453Shselasky sizeof (struct rt2860_txwi) + \ 33203134Sthompsa MCLBYTES + 11) 34203134Sthompsa 35261868Skevlo#define RUN_TX_TIMEOUT 5000 /* ms */ 36203134Sthompsa 37203134Sthompsa/* Tx ring count was 8/endpoint, now 32 for all 4 (or 6) endpoints. */ 38261868Skevlo#define RUN_TX_RING_COUNT 32 39261868Skevlo#define RUN_RX_RING_COUNT 1 40203134Sthompsa 41261868Skevlo#define RT2870_WCID_MAX 64 42261868Skevlo#define RUN_AID2WCID(aid) ((aid) & 0xff) 43203134Sthompsa 44261868Skevlo#define RUN_VAP_MAX 8 45208019Sthompsa 46203134Sthompsastruct run_rx_radiotap_header { 47203134Sthompsa struct ieee80211_radiotap_header wr_ihdr; 48203134Sthompsa uint8_t wr_flags; 49203134Sthompsa uint8_t wr_rate; 50203134Sthompsa uint16_t wr_chan_freq; 51203134Sthompsa uint16_t wr_chan_flags; 52208019Sthompsa int8_t wr_dbm_antsignal; 53203134Sthompsa uint8_t wr_antenna; 54203134Sthompsa uint8_t wr_antsignal; 55253757Shselasky} __packed __aligned(8); 56203134Sthompsa 57261868Skevlo#define RUN_RX_RADIOTAP_PRESENT \ 58203134Sthompsa (1 << IEEE80211_RADIOTAP_FLAGS | \ 59203134Sthompsa 1 << IEEE80211_RADIOTAP_RATE | \ 60203134Sthompsa 1 << IEEE80211_RADIOTAP_CHANNEL | \ 61203134Sthompsa 1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL | \ 62203134Sthompsa 1 << IEEE80211_RADIOTAP_ANTENNA | \ 63203134Sthompsa 1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL) 64203134Sthompsa 65203134Sthompsastruct run_tx_radiotap_header { 66203134Sthompsa struct ieee80211_radiotap_header wt_ihdr; 67203134Sthompsa uint8_t wt_flags; 68203134Sthompsa uint8_t wt_rate; 69203134Sthompsa uint16_t wt_chan_freq; 70203134Sthompsa uint16_t wt_chan_flags; 71203134Sthompsa uint8_t wt_hwqueue; 72253757Shselasky} __packed __aligned(8); 73203134Sthompsa 74203134Sthompsa#define IEEE80211_RADIOTAP_HWQUEUE 15 75203134Sthompsa 76261868Skevlo#define RUN_TX_RADIOTAP_PRESENT \ 77203134Sthompsa (1 << IEEE80211_RADIOTAP_FLAGS | \ 78203134Sthompsa 1 << IEEE80211_RADIOTAP_RATE | \ 79203134Sthompsa 1 << IEEE80211_RADIOTAP_CHANNEL | \ 80203134Sthompsa 1 << IEEE80211_RADIOTAP_HWQUEUE) 81203134Sthompsa 82203134Sthompsastruct run_softc; 83203134Sthompsa 84203134Sthompsastruct run_tx_data { 85203134Sthompsa STAILQ_ENTRY(run_tx_data) next; 86203134Sthompsa struct run_softc *sc; 87203134Sthompsa struct mbuf *m; 88203134Sthompsa struct ieee80211_node *ni; 89203134Sthompsa uint32_t align[0]; /* dummy field */ 90203134Sthompsa uint8_t desc[sizeof(struct rt2870_txd) + 91203134Sthompsa sizeof(struct rt2860_txwi)]; 92208019Sthompsa uint8_t ridx; 93203134Sthompsa}; 94203134SthompsaSTAILQ_HEAD(run_tx_data_head, run_tx_data); 95203134Sthompsa 96203134Sthompsastruct run_node { 97203134Sthompsa struct ieee80211_node ni; 98203134Sthompsa uint8_t ridx[IEEE80211_RATE_MAXSIZE]; 99203134Sthompsa uint8_t ctl_ridx[IEEE80211_RATE_MAXSIZE]; 100208019Sthompsa uint8_t amrr_ridx; 101208019Sthompsa uint8_t mgt_ridx; 102208019Sthompsa uint8_t fix_ridx; 103203134Sthompsa}; 104203134Sthompsa 105208019Sthompsastruct run_cmdq { 106208019Sthompsa void *arg0; 107208019Sthompsa void *arg1; 108208019Sthompsa void (*func)(void *); 109208019Sthompsa struct ieee80211_key *k; 110208019Sthompsa struct ieee80211_key key; 111208019Sthompsa uint8_t mac[IEEE80211_ADDR_LEN]; 112208019Sthompsa uint8_t wcid; 113208019Sthompsa}; 114208019Sthompsa 115203134Sthompsastruct run_vap { 116203134Sthompsa struct ieee80211vap vap; 117203134Sthompsa struct ieee80211_beacon_offsets bo; 118218492Sbschmidt struct mbuf *beacon_mbuf; 119203134Sthompsa 120203134Sthompsa int (*newstate)(struct ieee80211vap *, 121203134Sthompsa enum ieee80211_state, int); 122208019Sthompsa 123208019Sthompsa uint8_t rvp_id; 124203134Sthompsa}; 125261868Skevlo#define RUN_VAP(vap) ((struct run_vap *)(vap)) 126203134Sthompsa 127203134Sthompsa/* 128203134Sthompsa * There are 7 bulk endpoints: 1 for RX 129203134Sthompsa * and 6 for TX (4 EDCAs + HCCA + Prio). 130203134Sthompsa * Update 03-14-2009: some devices like the Planex GW-US300MiniS 131203134Sthompsa * seem to have only 4 TX bulk endpoints (Fukaumi Naoki). 132203134Sthompsa */ 133203134Sthompsaenum { 134203134Sthompsa RUN_BULK_TX_BE, /* = WME_AC_BE */ 135203134Sthompsa RUN_BULK_TX_BK, /* = WME_AC_BK */ 136203134Sthompsa RUN_BULK_TX_VI, /* = WME_AC_VI */ 137203134Sthompsa RUN_BULK_TX_VO, /* = WME_AC_VO */ 138203134Sthompsa RUN_BULK_TX_HCCA, 139203134Sthompsa RUN_BULK_TX_PRIO, 140203134Sthompsa RUN_BULK_RX, 141203134Sthompsa RUN_N_XFER, 142203134Sthompsa}; 143203134Sthompsa 144203134Sthompsa#define RUN_EP_QUEUES RUN_BULK_RX 145203134Sthompsa 146203134Sthompsastruct run_endpoint_queue { 147203134Sthompsa struct run_tx_data tx_data[RUN_TX_RING_COUNT]; 148203134Sthompsa struct run_tx_data_head tx_qh; 149203134Sthompsa struct run_tx_data_head tx_fh; 150203134Sthompsa uint32_t tx_nfree; 151203134Sthompsa}; 152203134Sthompsa 153203134Sthompsastruct run_softc { 154203134Sthompsa device_t sc_dev; 155203134Sthompsa struct usb_device *sc_udev; 156203134Sthompsa struct ifnet *sc_ifp; 157262604Skevlo int sc_need_fwload; 158262604Skevlo 159262604Skevlo int sc_flags; 160262604Skevlo#define RUN_FLAG_FWLOAD_NEEDED 0x01 161262604Skevlo 162218676Shselasky uint16_t wcid_stats[RT2870_WCID_MAX + 1][3]; 163218676Shselasky#define RUN_TXCNT 0 164218676Shselasky#define RUN_SUCCESS 1 165218676Shselasky#define RUN_RETRY 2 166203134Sthompsa 167203134Sthompsa int (*sc_srom_read)(struct run_softc *, 168203134Sthompsa uint16_t, uint16_t *); 169203134Sthompsa 170205042Sthompsa uint16_t mac_ver; 171205042Sthompsa uint16_t mac_rev; 172259453Shselasky uint16_t rf_rev; 173203134Sthompsa uint8_t freq; 174203134Sthompsa uint8_t ntxchains; 175203134Sthompsa uint8_t nrxchains; 176203134Sthompsa 177205042Sthompsa uint8_t bbp25; 178205042Sthompsa uint8_t bbp26; 179203134Sthompsa uint8_t rf24_20mhz; 180203134Sthompsa uint8_t rf24_40mhz; 181205042Sthompsa uint8_t patch_dac; 182205042Sthompsa uint8_t rfswitch; 183203134Sthompsa uint8_t ext_2ghz_lna; 184203134Sthompsa uint8_t ext_5ghz_lna; 185203134Sthompsa uint8_t calib_2ghz; 186203134Sthompsa uint8_t calib_5ghz; 187205042Sthompsa uint8_t txmixgain_2ghz; 188205042Sthompsa uint8_t txmixgain_5ghz; 189205042Sthompsa int8_t txpow1[54]; 190205042Sthompsa int8_t txpow2[54]; 191261868Skevlo int8_t txpow3[54]; 192203134Sthompsa int8_t rssi_2ghz[3]; 193203134Sthompsa int8_t rssi_5ghz[3]; 194203134Sthompsa uint8_t lna[4]; 195203134Sthompsa 196203134Sthompsa struct { 197203134Sthompsa uint8_t reg; 198203134Sthompsa uint8_t val; 199208019Sthompsa } bbp[10], rf[10]; 200203134Sthompsa uint8_t leds; 201203134Sthompsa uint16_t led[3]; 202203134Sthompsa uint32_t txpow20mhz[5]; 203203134Sthompsa uint32_t txpow40mhz_2ghz[5]; 204203134Sthompsa uint32_t txpow40mhz_5ghz[5]; 205203134Sthompsa 206203134Sthompsa uint8_t sc_bssid[6]; 207203134Sthompsa 208203134Sthompsa struct mtx sc_mtx; 209203134Sthompsa 210203134Sthompsa struct run_endpoint_queue sc_epq[RUN_EP_QUEUES]; 211203134Sthompsa 212208019Sthompsa struct task ratectl_task; 213208019Sthompsa struct usb_callout ratectl_ch; 214208019Sthompsa uint8_t ratectl_run; 215261868Skevlo#define RUN_RATECTL_OFF 0 216203134Sthompsa 217208019Sthompsa/* need to be power of 2, otherwise RUN_CMDQ_GET fails */ 218261868Skevlo#define RUN_CMDQ_MAX 16 219261868Skevlo#define RUN_CMDQ_MASQ (RUN_CMDQ_MAX - 1) 220208019Sthompsa struct run_cmdq cmdq[RUN_CMDQ_MAX]; 221208019Sthompsa struct task cmdq_task; 222208019Sthompsa uint32_t cmdq_store; 223208019Sthompsa uint8_t cmdq_exec; 224208019Sthompsa uint8_t cmdq_run; 225209144Sthompsa uint8_t cmdq_key_set; 226261868Skevlo#define RUN_CMDQ_ABORT 0 227261868Skevlo#define RUN_CMDQ_GO 1 228208019Sthompsa 229203134Sthompsa struct usb_xfer *sc_xfer[RUN_N_XFER]; 230203134Sthompsa 231203134Sthompsa struct mbuf *rx_m; 232203134Sthompsa 233208019Sthompsa uint8_t fifo_cnt; 234208019Sthompsa 235208019Sthompsa uint8_t running; 236208019Sthompsa uint8_t runbmap; 237208019Sthompsa uint8_t ap_running; 238208019Sthompsa uint8_t adhoc_running; 239208019Sthompsa uint8_t sta_running; 240208019Sthompsa uint8_t rvp_cnt; 241208019Sthompsa uint8_t rvp_bmap; 242246614Shselasky uint8_t sc_detached; 243208019Sthompsa 244203134Sthompsa union { 245203134Sthompsa struct run_rx_radiotap_header th; 246203134Sthompsa uint8_t pad[64]; 247203134Sthompsa } sc_rxtapu; 248203134Sthompsa#define sc_rxtap sc_rxtapu.th 249203134Sthompsa int sc_rxtap_len; 250203134Sthompsa 251203134Sthompsa union { 252203134Sthompsa struct run_tx_radiotap_header th; 253203134Sthompsa uint8_t pad[64]; 254203134Sthompsa } sc_txtapu; 255203134Sthompsa#define sc_txtap sc_txtapu.th 256203134Sthompsa int sc_txtap_len; 257203134Sthompsa}; 258203134Sthompsa 259261868Skevlo#define RUN_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 260261868Skevlo#define RUN_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 261261868Skevlo#define RUN_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 262203134Sthompsa 263203134Sthompsa#endif /* _IF_RUNVAR_H_ */ 264