#ifndef _DEV_ATH_ATHVAR_H
#define _DEV_ATH_ATHVAR_H
#ifdef _KERNEL
#include <net80211/ieee80211_radiotap.h>
#include <dev/ic/ar5xxx.h>
#include "bpfilter.h"
#ifdef notyet
#include "gpio.h"
#endif
#define ATH_TIMEOUT 1000
#define ATH_RXBUF 40
#define ATH_TXBUF 60
#define ATH_TXDESC 8
#define ATH_MAXGPIO 10
struct ath_recv_hist {
int arh_ticks;
u_int8_t arh_rssi;
u_int8_t arh_antenna;
};
#define ATH_RHIST_SIZE 16
#define ATH_RHIST_NOTIME (~0)
struct ath_stats {
u_int32_t ast_watchdog;
u_int32_t ast_hardware;
u_int32_t ast_bmiss;
u_int32_t ast_mib;
u_int32_t ast_rxorn;
u_int32_t ast_rxeol;
u_int32_t ast_txurn;
u_int32_t ast_intrcoal;
u_int32_t ast_tx_mgmt;
u_int32_t ast_tx_discard;
u_int32_t ast_tx_qstop;
u_int32_t ast_tx_encap;
u_int32_t ast_tx_nonode;
u_int32_t ast_tx_nombuf;
u_int32_t ast_tx_nomcl;
u_int32_t ast_tx_linear;
u_int32_t ast_tx_nodata;
u_int32_t ast_tx_busdma;
u_int32_t ast_tx_xretries;
u_int32_t ast_tx_fifoerr;
u_int32_t ast_tx_filtered;
u_int32_t ast_tx_shortretry;
u_int32_t ast_tx_longretry;
u_int32_t ast_tx_badrate;
u_int32_t ast_tx_noack;
u_int32_t ast_tx_rts;
u_int32_t ast_tx_cts;
u_int32_t ast_tx_shortpre;
u_int32_t ast_tx_altrate;
u_int32_t ast_tx_protect;
u_int32_t ast_rx_nombuf;
u_int32_t ast_rx_busdma;
u_int32_t ast_rx_orn;
u_int32_t ast_rx_crcerr;
u_int32_t ast_rx_fifoerr;
u_int32_t ast_rx_badcrypt;
u_int32_t ast_rx_phyerr;
u_int32_t ast_rx_phy[32];
u_int32_t ast_rx_tooshort;
u_int32_t ast_rx_toobig;
u_int32_t ast_rx_ctl;
u_int32_t ast_be_nombuf;
u_int32_t ast_per_cal;
u_int32_t ast_per_calfail;
u_int32_t ast_per_rfgain;
u_int32_t ast_rate_calls;
u_int32_t ast_rate_raise;
u_int32_t ast_rate_drop;
};
#define ATH_RX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
(1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_CHANNEL) | \
(1 << IEEE80211_RADIOTAP_ANTENNA) | \
(1 << IEEE80211_RADIOTAP_RSSI) | \
0)
struct ath_rx_radiotap_header {
struct ieee80211_radiotap_header wr_ihdr;
u_int8_t wr_flags;
u_int8_t wr_rate;
u_int16_t wr_chan_freq;
u_int16_t wr_chan_flags;
u_int8_t wr_antenna;
u_int8_t wr_rssi;
u_int8_t wr_max_rssi;
} __packed;
#define ATH_TX_RADIOTAP_PRESENT ( \
(1 << IEEE80211_RADIOTAP_FLAGS) | \
(1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_CHANNEL) | \
(1 << IEEE80211_RADIOTAP_DBM_TX_POWER) | \
(1 << IEEE80211_RADIOTAP_ANTENNA) | \
0)
struct ath_tx_radiotap_header {
struct ieee80211_radiotap_header wt_ihdr;
u_int8_t wt_flags;
u_int8_t wt_rate;
u_int16_t wt_chan_freq;
u_int16_t wt_chan_flags;
u_int8_t wt_txpower;
u_int8_t wt_antenna;
} __packed;
struct ath_node {
struct ieee80211_node an_node;
struct ieee80211_rssadapt an_rssadapt;
u_int an_tx_antenna;
u_int an_rx_antenna;
struct ath_recv_hist an_rx_hist[ATH_RHIST_SIZE];
u_int an_rx_hist_next;
};
#define ATH_NODE(_n) ((struct ath_node *)(_n))
struct ath_buf {
TAILQ_ENTRY(ath_buf) bf_list;
bus_dmamap_t bf_dmamap;
#define bf_nseg bf_dmamap->dm_nsegs
#define bf_mapsize bf_dmamap->dm_mapsize
#define bf_segs bf_dmamap->dm_segs
struct ath_desc *bf_desc;
bus_addr_t bf_daddr;
struct mbuf *bf_m;
struct ieee80211_node *bf_node;
struct ieee80211_rssdesc bf_id;
#define ATH_MAX_SCATTER 64
};
typedef struct ath_task {
void (*t_func)(void*, int);
void *t_context;
} ath_task_t;
struct ath_softc {
struct device sc_dev;
struct ieee80211com sc_ic;
int (*sc_enable)(struct ath_softc *);
void (*sc_disable)(struct ath_softc *);
void (*sc_power)(struct ath_softc *, int);
int (*sc_newstate)(struct ieee80211com *,
enum ieee80211_state, int);
void (*sc_node_free)(struct ieee80211com *,
struct ieee80211_node *);
void (*sc_node_copy)(struct ieee80211com *,
struct ieee80211_node *,
const struct ieee80211_node *);
void (*sc_recv_mgmt)(struct ieee80211com *,
struct mbuf *, struct ieee80211_node *,
struct ieee80211_rxinfo *, int);
bus_space_tag_t sc_st;
bus_space_handle_t sc_sh;
bus_size_t sc_ss;
bus_dma_tag_t sc_dmat;
struct ath_hal *sc_ah;
unsigned int sc_invalid : 1,
sc_doani : 1,
sc_veol : 1,
sc_softled : 1,
sc_probing : 1,
sc_pcie : 1;
u_int sc_nchan;
const HAL_RATE_TABLE *sc_rates[IEEE80211_MODE_MAX];
const HAL_RATE_TABLE *sc_currates;
enum ieee80211_phymode sc_curmode;
u_int8_t sc_rixmap[256];
u_int8_t sc_hwmap[32];
HAL_INT sc_imask;
#if NBPFILTER > 0
caddr_t sc_drvbpf;
union {
struct ath_rx_radiotap_header th;
uint8_t pad[IEEE80211_RADIOTAP_HDRLEN];
} sc_rxtapu;
#define sc_rxtap sc_rxtapu.th
int sc_rxtap_len;
union {
struct ath_tx_radiotap_header th;
uint8_t pad[IEEE80211_RADIOTAP_HDRLEN];
} sc_txtapu;
#define sc_txtap sc_txtapu.th
int sc_txtap_len;
#endif
struct ath_desc *sc_desc;
bus_dma_segment_t sc_dseg;
int sc_dnseg;
bus_dmamap_t sc_ddmamap;
bus_addr_t sc_desc_paddr;
bus_addr_t sc_desc_len;
ath_task_t sc_fataltask;
ath_task_t sc_rxorntask;
TAILQ_HEAD(, ath_buf) sc_rxbuf;
u_int32_t *sc_rxlink;
ath_task_t sc_rxtask;
u_int sc_txhalq[HAL_NUM_TX_QUEUES];
u_int32_t *sc_txlink;
int sc_tx_timer;
TAILQ_HEAD(, ath_buf) sc_txbuf;
TAILQ_HEAD(, ath_buf) sc_txq;
ath_task_t sc_txtask;
u_int sc_bhalq;
struct ath_buf *sc_bcbuf;
struct ath_buf *sc_bufptr;
ath_task_t sc_swbatask;
ath_task_t sc_bmisstask;
struct timeval sc_last_ch;
struct timeout sc_cal_to;
struct timeval sc_last_beacon;
struct timeout sc_scan_to;
struct timeout sc_rssadapt_to;
struct ath_stats sc_stats;
HAL_MIB_STATS sc_mib_stats;
u_int sc_flags;
u_int8_t sc_broadcast_addr[IEEE80211_ADDR_LEN];
struct gpio_chipset_tag sc_gpio_gc;
gpio_pin_t sc_gpio_pins[ATH_MAXGPIO];
};
#define LE_READ_2(p) \
((u_int16_t) \
((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8)))
#define LE_READ_4(p) \
((u_int32_t) \
((((u_int8_t *)(p))[0] ) | (((u_int8_t *)(p))[1] << 8) | \
(((u_int8_t *)(p))[2] << 16) | (((u_int8_t *)(p))[3] << 24)))
#ifdef AR_DEBUG
enum {
ATH_DEBUG_XMIT = 0x00000001,
ATH_DEBUG_XMIT_DESC = 0x00000002,
ATH_DEBUG_RECV = 0x00000004,
ATH_DEBUG_RECV_DESC = 0x00000008,
ATH_DEBUG_RATE = 0x00000010,
ATH_DEBUG_RESET = 0x00000020,
ATH_DEBUG_MODE = 0x00000040,
ATH_DEBUG_BEACON = 0x00000080,
ATH_DEBUG_WATCHDOG = 0x00000100,
ATH_DEBUG_INTR = 0x00001000,
ATH_DEBUG_TX_PROC = 0x00002000,
ATH_DEBUG_RX_PROC = 0x00004000,
ATH_DEBUG_BEACON_PROC = 0x00008000,
ATH_DEBUG_CALIBRATE = 0x00010000,
ATH_DEBUG_ANY = 0xffffffff
};
#define IFF_DUMPPKTS(_ifp, _m) \
((ath_debug & _m) || \
((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2))
#define DPRINTF(_m,X) if (ath_debug & (_m)) printf X
#else
#define IFF_DUMPPKTS(_ifp, _m) \
(((_ifp)->if_flags & (IFF_DEBUG|IFF_LINK2)) == (IFF_DEBUG|IFF_LINK2))
#define DPRINTF(_m, X)
#endif
#undef KASSERT
#define KASSERT(cond, complaint) if (!(cond)) panic complaint
#define ATH_ATTACHED 0x0001
#define ATH_ENABLED 0x0002
#define ATH_GPIO 0x0004
#define ATH_IS_ENABLED(sc) ((sc)->sc_flags & ATH_ENABLED)
#define ATH_LOCK_INIT(_sc) \
mtx_init(&(_sc)->sc_mtx, device_get_nameunit((_sc)->sc_dev), \
MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE)
#define ATH_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
#define ATH_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
#define ATH_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
#define ATH_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
#define ATH_TXBUF_LOCK_INIT(_sc) \
mtx_init(&(_sc)->sc_txbuflock, \
device_get_nameunit((_sc)->sc_dev), "xmit buf q", MTX_DEF)
#define ATH_TXBUF_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_txbuflock)
#define ATH_TXBUF_LOCK(_sc) mtx_lock(&(_sc)->sc_txbuflock)
#define ATH_TXBUF_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_txbuflock)
#define ATH_TXBUF_LOCK_ASSERT(_sc) \
mtx_assert(&(_sc)->sc_txbuflock, MA_OWNED)
#define ATH_TXQ_LOCK_INIT(_sc) \
mtx_init(&(_sc)->sc_txqlock, \
device_get_nameunit((_sc)->sc_dev), "xmit q", MTX_DEF)
#define ATH_TXQ_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_txqlock)
#define ATH_TXQ_LOCK(_sc) mtx_lock(&(_sc)->sc_txqlock)
#define ATH_TXQ_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_txqlock)
#define ATH_TXQ_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_txqlock, MA_OWNED)
#define ATH_TICKS() (ticks)
#define ATH_CALLOUT_INIT(chp) callout_init((chp))
#define ATH_TASK_INIT(task, func, context) \
do { \
(task)->t_func = (func); \
(task)->t_context = (context); \
} while (0)
#define ATH_TASK_RUN_OR_ENQUEUE(task) ((*(task)->t_func)((task)->t_context, 1))
typedef unsigned long u_intptr_t;
int ath_attach(u_int16_t, struct ath_softc *);
int ath_detach(struct ath_softc *, int);
int ath_enable(struct ath_softc *);
int ath_activate(struct device *, int);
int ath_intr(void *);
int ath_enable(struct ath_softc *);
#define ath_hal_reset(_ah, _opmode, _chan, _outdoor, _pstatus) \
((*(_ah)->ah_reset)((_ah), (_opmode), (_chan), (_outdoor), (_pstatus)))
#define ath_hal_get_rate_table(_ah, _mode) \
((*(_ah)->ah_get_rate_table)((_ah), (_mode)))
#define ath_hal_get_lladdr(_ah, _mac) \
((*(_ah)->ah_get_lladdr)((_ah), (_mac)))
#define ath_hal_set_lladdr(_ah, _mac) \
((*(_ah)->ah_set_lladdr)((_ah), (_mac)))
#define ath_hal_set_intr(_ah, _mask) \
((*(_ah)->ah_set_intr)((_ah), (_mask)))
#define ath_hal_get_intr(_ah) \
((*(_ah)->ah_get_intr)((_ah)))
#define ath_hal_is_intr_pending(_ah) \
((*(_ah)->ah_is_intr_pending)((_ah)))
#define ath_hal_get_isr(_ah, _pmask) \
((*(_ah)->ah_get_isr)((_ah), (_pmask)))
#define ath_hal_update_tx_triglevel(_ah, _inc) \
((*(_ah)->ah_update_tx_triglevel)((_ah), (_inc)))
#define ath_hal_set_power(_ah, _mode, _sleepduration) \
((*(_ah)->ah_set_power)((_ah), (_mode), AH_TRUE, (_sleepduration)))
#define ath_hal_reset_key(_ah, _ix) \
((*(_ah)->ah_reset_key)((_ah), (_ix)))
#define ath_hal_set_key(_ah, _ix, _pk) \
((*(_ah)->ah_set_key)((_ah), (_ix), (_pk), NULL, AH_FALSE))
#define ath_hal_is_key_valid(_ah, _ix) \
(((*(_ah)->ah_is_key_valid)((_ah), (_ix))))
#define ath_hal_set_key_lladdr(_ah, _ix, _mac) \
((*(_ah)->ah_set_key_lladdr)((_ah), (_ix), (_mac)))
#define ath_hal_softcrypto(_ah, _val ) \
((*(_ah)->ah_softcrypto)((_ah), (_val)))
#define ath_hal_get_rx_filter(_ah) \
((*(_ah)->ah_get_rx_filter)((_ah)))
#define ath_hal_set_rx_filter(_ah, _filter) \
((*(_ah)->ah_set_rx_filter)((_ah), (_filter)))
#define ath_hal_set_mcast_filter(_ah, _mfilt0, _mfilt1) \
((*(_ah)->ah_set_mcast_filter)((_ah), (_mfilt0), (_mfilt1)))
#define ath_hal_wait_for_beacon(_ah, _bf) \
((*(_ah)->ah_wait_for_beacon)((_ah), (_bf)->bf_daddr))
#define ath_hal_put_rx_buf(_ah, _bufaddr) \
((*(_ah)->ah_put_rx_buf)((_ah), (_bufaddr)))
#define ath_hal_get_tsf32(_ah) \
((*(_ah)->ah_get_tsf32)((_ah)))
#define ath_hal_get_tsf64(_ah) \
((*(_ah)->ah_get_tsf64)((_ah)))
#define ath_hal_reset_tsf(_ah) \
((*(_ah)->ah_reset_tsf)((_ah)))
#define ath_hal_start_rx(_ah) \
((*(_ah)->ah_start_rx)((_ah)))
#define ath_hal_put_tx_buf(_ah, _q, _bufaddr) \
((*(_ah)->ah_put_tx_buf)((_ah), (_q), (_bufaddr)))
#define ath_hal_get_tx_buf(_ah, _q) \
((*(_ah)->ah_get_tx_buf)((_ah), (_q)))
#define ath_hal_get_rx_buf(_ah) \
((*(_ah)->ah_get_rx_buf)((_ah)))
#define ath_hal_tx_start(_ah, _q) \
((*(_ah)->ah_tx_start)((_ah), (_q)))
#define ath_hal_setchannel(_ah, _chan) \
((*(_ah)->ah_setchannel)((_ah), (_chan)))
#define ath_hal_calibrate(_ah, _chan) \
((*(_ah)->ah_calibrate)((_ah), (_chan)))
#define ath_hal_set_ledstate(_ah, _state) \
((*(_ah)->ah_set_ledstate)((_ah), (_state)))
#define ath_hal_init_beacon(_ah, _nextb, _bperiod) \
((*(_ah)->ah_init_beacon)((_ah), (_nextb), (_bperiod)))
#define ath_hal_reset_beacon(_ah) \
((*(_ah)->ah_reset_beacon)((_ah)))
#define ath_hal_set_beacon_timers(_ah, _bs, _tsf, _dc, _cc) \
((*(_ah)->ah_set_beacon_timers)((_ah), (_bs), (_tsf), \
(_dc), (_cc)))
#define ath_hal_set_associd(_ah, _bss, _associd) \
((*(_ah)->ah_set_associd)((_ah), (_bss), (_associd), 0))
#define ath_hal_get_regdomain(_ah, _prd) \
(*(_prd) = (_ah)->ah_get_regdomain(_ah))
#define ath_hal_detach(_ah) \
((*(_ah)->ah_detach)(_ah))
#define ath_hal_set_slot_time(_ah, _t) \
((*(_ah)->ah_set_slot_time)(_ah, _t))
#define ath_hal_set_gpio_output(_ah, _gpio) \
((*(_ah)->ah_set_gpio_output)((_ah), (_gpio)))
#define ath_hal_set_gpio_input(_ah, _gpio) \
((*(_ah)->ah_set_gpio_input)((_ah), (_gpio)))
#define ath_hal_get_gpio(_ah, _gpio) \
((*(_ah)->ah_get_gpio)((_ah), (_gpio)))
#define ath_hal_set_gpio(_ah, _gpio, _b) \
((*(_ah)->ah_set_gpio)((_ah), (_gpio), (_b)))
#define ath_hal_set_gpio_intr(_ah, _gpio, _b) \
((*(_ah)->ah_set_gpio_intr)((_ah), (_gpio), (_b)))
#define ath_hal_set_opmode(_ah) \
((*(_ah)->ah_set_opmode)((_ah)))
#define ath_hal_stop_tx_dma(_ah, _qnum) \
((*(_ah)->ah_stop_tx_dma)((_ah), (_qnum)))
#define ath_hal_stop_pcu_recv(_ah) \
((*(_ah)->ah_stop_pcu_recv)((_ah)))
#define ath_hal_start_rx_pcu(_ah) \
((*(_ah)->ah_start_rx_pcu)((_ah)))
#define ath_hal_stop_rx_dma(_ah) \
((*(_ah)->ah_stop_rx_dma)((_ah)))
#define ath_hal_get_diag_state(_ah, _id, _indata, _insize, _outdata, _outsize) \
((*(_ah)->ah_get_diag_state)((_ah), (_id), \
(_indata), (_insize), (_outdata), (_outsize)))
#define ath_hal_setup_tx_queue(_ah, _type, _qinfo) \
((*(_ah)->ah_setup_tx_queue)((_ah), (_type), (_qinfo)))
#define ath_hal_reset_tx_queue(_ah, _q) \
((*(_ah)->ah_reset_tx_queue)((_ah), (_q)))
#define ath_hal_release_tx_queue(_ah, _q) \
((*(_ah)->ah_release_tx_queue)((_ah), (_q)))
#define ath_hal_has_veol(_ah) \
((*(_ah)->ah_has_veol)((_ah)))
#define ath_hal_update_mib_counters(_ah, _stats) \
((*(_ah)->ah_update_mib_counters)((_ah), (_stats)))
#define ath_hal_get_rf_gain(_ah) \
((*(_ah)->ah_get_rf_gain)((_ah)))
#define ath_hal_set_rx_signal(_ah) \
((*(_ah)->ah_set_rx_signal)((_ah)))
#define ath_hal_setup_rx_desc(_ah, _ds, _size, _intreq) \
((*(_ah)->ah_setup_rx_desc)((_ah), (_ds), (_size), (_intreq)))
#define ath_hal_proc_rx_desc(_ah, _ds, _dspa, _dsnext) \
((*(_ah)->ah_proc_rx_desc)((_ah), (_ds), (_dspa), (_dsnext)))
#define ath_hal_setup_tx_desc(_ah, _ds, _plen, _hlen, _atype, _txpow, \
_txr0, _txtr0, _keyix, _ant, _flags, \
_rtsrate, _rtsdura) \
((*(_ah)->ah_setup_tx_desc)((_ah), (_ds), (_plen), (_hlen), (_atype), \
(_txpow), (_txr0), (_txtr0), (_keyix), (_ant), \
(_flags), (_rtsrate), (_rtsdura)))
#define ath_hal_setup_xtx_desc(_ah, _ds, \
_txr1, _txtr1, _txr2, _txtr2, _txr3, _txtr3) \
((*(_ah)->ah_setup_xtx_desc)((_ah), (_ds), \
(_txr1), (_txtr1), (_txr2), (_txtr2), (_txr3), (_txtr3)))
#define ath_hal_fill_tx_desc(_ah, _ds, _l, _first, _last) \
((*(_ah)->ah_fill_tx_desc)((_ah), (_ds), (_l), (_first), (_last)))
#define ath_hal_proc_tx_desc(_ah, _ds) \
((*(_ah)->ah_proc_tx_desc)((_ah), (_ds)))
#endif
#define SIOCGATHSTATS _IOWR('i', 137, struct ifreq)
#endif