1*1000Sxc151355 /* 2*1000Sxc151355 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*1000Sxc151355 * Use is subject to license terms. 4*1000Sxc151355 */ 5*1000Sxc151355 6*1000Sxc151355 /* 7*1000Sxc151355 * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting 8*1000Sxc151355 * All rights reserved. 9*1000Sxc151355 * 10*1000Sxc151355 * Redistribution and use in source and binary forms, with or without 11*1000Sxc151355 * modification, are permitted provided that the following conditions 12*1000Sxc151355 * are met: 13*1000Sxc151355 * 1. Redistributions of source code must retain the above copyright 14*1000Sxc151355 * notice, this list of conditions and the following disclaimer, 15*1000Sxc151355 * without modification. 16*1000Sxc151355 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 17*1000Sxc151355 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 18*1000Sxc151355 * redistribution must be conditioned upon including a substantially 19*1000Sxc151355 * similar Disclaimer requirement for further binary redistribution. 20*1000Sxc151355 * 3. Neither the names of the above-listed copyright holders nor the names 21*1000Sxc151355 * of any contributors may be used to endorse or promote products derived 22*1000Sxc151355 * from this software without specific prior written permission. 23*1000Sxc151355 * 24*1000Sxc151355 * NO WARRANTY 25*1000Sxc151355 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26*1000Sxc151355 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27*1000Sxc151355 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 28*1000Sxc151355 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 29*1000Sxc151355 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 30*1000Sxc151355 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31*1000Sxc151355 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32*1000Sxc151355 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 33*1000Sxc151355 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34*1000Sxc151355 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 35*1000Sxc151355 * THE POSSIBILITY OF SUCH DAMAGES. 36*1000Sxc151355 * 37*1000Sxc151355 */ 38*1000Sxc151355 39*1000Sxc151355 /* 40*1000Sxc151355 * ath_impl.h is a bridge between the HAL and the driver. It 41*1000Sxc151355 * defines some data structures encapsulating the HAL interface 42*1000Sxc151355 * and communicating with the IEEE80211 MAC layer and other 43*1000Sxc151355 * driver components. 44*1000Sxc151355 */ 45*1000Sxc151355 46*1000Sxc151355 #ifndef _ATH_IMPL_H 47*1000Sxc151355 #define _ATH_IMPL_H 48*1000Sxc151355 49*1000Sxc151355 #pragma ident "%Z%%M% %I% %E% SMI" 50*1000Sxc151355 51*1000Sxc151355 #ifdef __cplusplus 52*1000Sxc151355 extern "C" { 53*1000Sxc151355 #endif 54*1000Sxc151355 55*1000Sxc151355 /* 56*1000Sxc151355 * Defintions for the Atheros Wireless LAN controller driver. 57*1000Sxc151355 */ 58*1000Sxc151355 59*1000Sxc151355 #include <sys/list.h> 60*1000Sxc151355 #include "ath_ieee80211.h" 61*1000Sxc151355 #include "ath_hal.h" 62*1000Sxc151355 63*1000Sxc151355 /* 64*1000Sxc151355 * Bit flags in the ath_dbg_flags 65*1000Sxc151355 */ 66*1000Sxc151355 #define ATH_DBG_INIT 0x00000001 /* initialisation */ 67*1000Sxc151355 #define ATH_DBG_GLD 0x00000002 /* GLD entry points */ 68*1000Sxc151355 #define ATH_DBG_HAL 0x00000004 /* HAL related code */ 69*1000Sxc151355 #define ATH_DBG_INT 0x00000008 /* interrupt handler */ 70*1000Sxc151355 #define ATH_DBG_RECV 0x00000010 /* receive-side code */ 71*1000Sxc151355 #define ATH_DBG_SEND 0x00000020 /* packet-send code */ 72*1000Sxc151355 #define ATH_DBG_80211 0x00000040 /* 80211 state machine */ 73*1000Sxc151355 #define ATH_DBG_IOCTL 0x00000080 /* ioctl code */ 74*1000Sxc151355 #define ATH_DBG_STATS 0x00000100 /* statistics */ 75*1000Sxc151355 #define ATH_DBG_RATE 0x00000200 /* rate control */ 76*1000Sxc151355 #define ATH_DBG_AUX 0x00000400 /* for ath_aux.c */ 77*1000Sxc151355 #define ATH_DBG_WIFICFG 0x00000800 /* wificonfig */ 78*1000Sxc151355 #define ATH_DBG_OSDEP 0x00001000 /* osdep */ 79*1000Sxc151355 #define ATH_DBG_ATTACH 0x00002000 /* attach */ 80*1000Sxc151355 #define ATH_DBG_DETACH 0x00004000 /* detach */ 81*1000Sxc151355 #define ATH_DBG_ALL 0x00007fff /* all */ 82*1000Sxc151355 83*1000Sxc151355 #ifdef DEBUG 84*1000Sxc151355 #define ATH_DDB(command) do { \ 85*1000Sxc151355 { command; } \ 86*1000Sxc151355 _NOTE(CONSTANTCONDITION)\ 87*1000Sxc151355 } while (0) 88*1000Sxc151355 #else 89*1000Sxc151355 #define ATH_DDB(command) 90*1000Sxc151355 #endif /* DEBUG */ 91*1000Sxc151355 92*1000Sxc151355 /* 93*1000Sxc151355 * Node type of wifi device 94*1000Sxc151355 */ 95*1000Sxc151355 #ifndef DDI_NT_NET_WIFI 96*1000Sxc151355 #define DDI_NT_NET_WIFI "ddi_network:wifi" 97*1000Sxc151355 #endif 98*1000Sxc151355 #define ATH_NODENAME "ath" 99*1000Sxc151355 100*1000Sxc151355 #define ATH_DEBUG(args) ATH_DDB(ath_dbg args) 101*1000Sxc151355 102*1000Sxc151355 #define list_empty(a) ((a)->list_head.list_next == &(a)->list_head) 103*1000Sxc151355 #define ATH_LE_READ_4(p) \ 104*1000Sxc151355 ((uint32_t) \ 105*1000Sxc151355 ((((uint8_t *)(p))[0]) | (((uint8_t *)(p))[1] << 8) | \ 106*1000Sxc151355 (((uint8_t *)(p))[2] << 16) | (((uint8_t *)(p))[3] << 24))) 107*1000Sxc151355 #define ATH_N(a) (sizeof (a) / sizeof (a[0])) 108*1000Sxc151355 #define ATH_TXQ_SETUP(asc, i) ((asc)->asc_txqsetup & (1<<i)) 109*1000Sxc151355 #define ATH_PA2DESC(_asc, _pa) \ 110*1000Sxc151355 ((struct ath_desc *)((caddr_t)(_asc)->asc_desc + \ 111*1000Sxc151355 ((_pa) - (_asc)->asc_desc_dma.cookie.dmac_address))) 112*1000Sxc151355 /* 113*1000Sxc151355 * Sync a DMA area described by a dma_area_t 114*1000Sxc151355 */ 115*1000Sxc151355 #define ATH_DMA_SYNC(area, flag) ((void) ddi_dma_sync((area).dma_hdl, \ 116*1000Sxc151355 (area).offset, (area).alength, (flag))) 117*1000Sxc151355 118*1000Sxc151355 #define ATH_TXINTR_PERIOD 5 119*1000Sxc151355 #define ATH_TIMEOUT 1000 120*1000Sxc151355 #define ATH_RXBUF 80 /* number of RX buffers */ 121*1000Sxc151355 #define ATH_TXBUF 200 /* number of TX buffers */ 122*1000Sxc151355 #define ATH_TXDESC 1 /* number of descriptors per buffer */ 123*1000Sxc151355 #define ATH_TXMAXTRY 11 /* max number of transmit attempts */ 124*1000Sxc151355 125*1000Sxc151355 /* driver-specific node state */ 126*1000Sxc151355 struct ath_node { 127*1000Sxc151355 struct ieee80211_node an_node; /* base class */ 128*1000Sxc151355 uint32_t an_tx_times; /* rate ctl times on one rate */ 129*1000Sxc151355 uint32_t an_tx_ok; /* tx ok pkt */ 130*1000Sxc151355 uint32_t an_tx_err; /* tx !ok pkt */ 131*1000Sxc151355 uint32_t an_tx_retr; /* tx retry count */ 132*1000Sxc151355 int32_t an_tx_upper; /* tx upper rate req cnt */ 133*1000Sxc151355 uint32_t an_tx_antenna; /* antenna for last good frame */ 134*1000Sxc151355 uint8_t an_tx_rix0; /* series 0 rate index */ 135*1000Sxc151355 uint8_t an_tx_try0; /* series 0 try count */ 136*1000Sxc151355 uint8_t an_tx_mgtrate; /* h/w rate for management/ctl frames */ 137*1000Sxc151355 uint8_t an_tx_mgtratesp; /* short preamble h/w rate for " " */ 138*1000Sxc151355 uint8_t an_tx_rate0; /* series 0 h/w rate */ 139*1000Sxc151355 uint8_t an_tx_rate1; /* series 1 h/w rate */ 140*1000Sxc151355 uint8_t an_tx_rate2; /* series 2 h/w rate */ 141*1000Sxc151355 uint8_t an_tx_rate3; /* series 3 h/w rate */ 142*1000Sxc151355 uint8_t an_tx_rate0sp; /* series 0 short preamble h/w rate */ 143*1000Sxc151355 uint8_t an_tx_rate1sp; /* series 1 short preamble h/w rate */ 144*1000Sxc151355 uint8_t an_tx_rate2sp; /* series 2 short preamble h/w rate */ 145*1000Sxc151355 uint8_t an_tx_rate3sp; /* series 3 short preamble h/w rate */ 146*1000Sxc151355 }; 147*1000Sxc151355 #define ATH_NODE(_n) ((struct ath_node *)(_n)) 148*1000Sxc151355 149*1000Sxc151355 150*1000Sxc151355 struct ath_stats { 151*1000Sxc151355 uint32_t ast_hardware; /* fatal hardware error interrupts */ 152*1000Sxc151355 uint32_t ast_rxorn; /* rx overrun interrupts */ 153*1000Sxc151355 uint32_t ast_rxeol; /* rx eol interrupts */ 154*1000Sxc151355 uint32_t ast_txurn; /* tx underrun interrupts */ 155*1000Sxc151355 uint32_t ast_tx_mgmt; /* management frames transmitted */ 156*1000Sxc151355 uint32_t ast_tx_discard; /* frames discarded prior to assoc */ 157*1000Sxc151355 uint32_t ast_tx_invalid; /* frames discarded 'cuz device gone */ 158*1000Sxc151355 uint32_t ast_tx_qstop; /* tx queue stopped 'cuz full */ 159*1000Sxc151355 uint32_t ast_tx_nobuf; /* tx failed 'cuz no tx buffer (data) */ 160*1000Sxc151355 uint32_t ast_tx_nobufmgt; /* tx failed 'cuz no tx buffer(mgmt) */ 161*1000Sxc151355 uint32_t ast_tx_xretries; /* tx failed 'cuz too many retries */ 162*1000Sxc151355 uint32_t ast_tx_fifoerr; /* tx failed 'cuz FIFO underrun */ 163*1000Sxc151355 uint32_t ast_tx_filtered; /* tx failed 'cuz xmit filtered */ 164*1000Sxc151355 uint32_t ast_tx_shortretry; /* tx on-chip retries (short) */ 165*1000Sxc151355 uint32_t ast_tx_longretry; /* tx on-chip retries (long) */ 166*1000Sxc151355 uint32_t ast_tx_noack; /* tx frames with no ack marked */ 167*1000Sxc151355 uint32_t ast_tx_rts; /* tx frames with rts enabled */ 168*1000Sxc151355 uint32_t ast_tx_shortpre; /* tx frames with short preamble */ 169*1000Sxc151355 uint32_t ast_tx_altrate; /* tx frames with alternate rate */ 170*1000Sxc151355 int16_t ast_tx_rssi; /* tx rssi of last ack */ 171*1000Sxc151355 int16_t ast_tx_rssidelta; /* tx rssi delta */ 172*1000Sxc151355 uint32_t ast_rx_crcerr; /* rx failed 'cuz of bad CRC */ 173*1000Sxc151355 uint32_t ast_rx_fifoerr; /* rx failed 'cuz of FIFO overrun */ 174*1000Sxc151355 uint32_t ast_rx_badcrypt; /* rx failed 'cuz decryption */ 175*1000Sxc151355 uint32_t ast_rx_phyerr; /* rx PHY error summary count */ 176*1000Sxc151355 uint32_t ast_rx_phy[32]; /* rx PHY error per-code counts */ 177*1000Sxc151355 uint32_t ast_rx_tooshort; /* rx discarded 'cuz frame too short */ 178*1000Sxc151355 uint32_t ast_per_cal; /* periodic calibration calls */ 179*1000Sxc151355 uint32_t ast_per_calfail; /* periodic calibration failed */ 180*1000Sxc151355 uint32_t ast_per_rfgain; /* periodic calibration rfgain reset */ 181*1000Sxc151355 uint32_t ast_rate_calls; /* rate control checks */ 182*1000Sxc151355 uint32_t ast_rate_raise; /* rate control raised xmit rate */ 183*1000Sxc151355 uint32_t ast_rate_drop; /* rate control dropped xmit rate */ 184*1000Sxc151355 }; 185*1000Sxc151355 186*1000Sxc151355 187*1000Sxc151355 /* 188*1000Sxc151355 * Describes one chunk of allocated DMA-able memory 189*1000Sxc151355 * 190*1000Sxc151355 * In some cases, this is a single chunk as allocated from the system; 191*1000Sxc151355 * but we also use this structure to represent slices carved off such 192*1000Sxc151355 * a chunk. Even when we don't really need all the information, we 193*1000Sxc151355 * use this structure as a convenient way of correlating the various 194*1000Sxc151355 * ways of looking at a piece of memory (kernel VA, IO space DVMA, 195*1000Sxc151355 * handle+offset, etc). 196*1000Sxc151355 */ 197*1000Sxc151355 struct dma_area { 198*1000Sxc151355 ddi_acc_handle_t acc_hdl; /* handle for memory */ 199*1000Sxc151355 caddr_t mem_va; /* CPU VA of memory */ 200*1000Sxc151355 uint32_t nslots; /* number of slots */ 201*1000Sxc151355 uint32_t size; /* size per slot */ 202*1000Sxc151355 size_t alength; /* allocated size */ 203*1000Sxc151355 /* >= product of above */ 204*1000Sxc151355 205*1000Sxc151355 ddi_dma_handle_t dma_hdl; /* DMA handle */ 206*1000Sxc151355 offset_t offset; /* relative to handle */ 207*1000Sxc151355 ddi_dma_cookie_t cookie; /* associated cookie */ 208*1000Sxc151355 uint32_t ncookies; /* must be 1 */ 209*1000Sxc151355 uint32_t token; /* arbitrary identifier */ 210*1000Sxc151355 }; /* 0x50 (80) bytes */ 211*1000Sxc151355 typedef struct dma_area dma_area_t; 212*1000Sxc151355 213*1000Sxc151355 struct ath_buf { 214*1000Sxc151355 struct ath_desc *bf_desc; /* virtual addr of desc */ 215*1000Sxc151355 uint32_t bf_daddr; /* physical addr of desc */ 216*1000Sxc151355 dma_area_t bf_dma; /* dma area for buf */ 217*1000Sxc151355 struct ieee80211_node *bf_in; /* pointer to the node */ 218*1000Sxc151355 219*1000Sxc151355 /* we're in list of asc->asc_txbuf_list or asc->asc_rxbuf_list */ 220*1000Sxc151355 list_node_t bf_node; 221*1000Sxc151355 }; 222*1000Sxc151355 223*1000Sxc151355 224*1000Sxc151355 /* 225*1000Sxc151355 * Data transmit queue state. One of these exists for each 226*1000Sxc151355 * hardware transmit queue. Packets sent to us from above 227*1000Sxc151355 * are assigned to queues based on their priority. Not all 228*1000Sxc151355 * devices support a complete set of hardware transmit queues. 229*1000Sxc151355 * For those devices the array sc_ac2q will map multiple 230*1000Sxc151355 * priorities to fewer hardware queues (typically all to one 231*1000Sxc151355 * hardware queue). 232*1000Sxc151355 */ 233*1000Sxc151355 struct ath_txq { 234*1000Sxc151355 uint_t axq_qnum; /* hardware q number */ 235*1000Sxc151355 uint_t axq_depth; /* queue depth (stat only) */ 236*1000Sxc151355 uint_t axq_intrcnt; /* interrupt count */ 237*1000Sxc151355 uint32_t *axq_link; /* link ptr in last TX desc */ 238*1000Sxc151355 list_t axq_list; /* transmit queue */ 239*1000Sxc151355 kmutex_t axq_lock; /* lock on q and link */ 240*1000Sxc151355 }; 241*1000Sxc151355 242*1000Sxc151355 243*1000Sxc151355 /* 244*1000Sxc151355 * asc_isc must be the first element, for convience of 245*1000Sxc151355 * casting between iee80211com and ath 246*1000Sxc151355 */ 247*1000Sxc151355 typedef struct ath { 248*1000Sxc151355 ieee80211com_t asc_isc; /* IEEE 802.11 common */ 249*1000Sxc151355 dev_info_t *asc_dev; /* back pointer to dev_info_t */ 250*1000Sxc151355 struct ath_hal *asc_ah; /* Atheros HAL */ 251*1000Sxc151355 uint32_t asc_invalid : 1, /* being detached */ 252*1000Sxc151355 asc_mrretry : 1, /* multi-rate retry support */ 253*1000Sxc151355 asc_have11g : 1, /* have 11g support */ 254*1000Sxc151355 asc_splitmic : 1; /* Split TKIP mic keys */ 255*1000Sxc151355 const HAL_RATE_TABLE *asc_rates[IEEE80211_MODE_MAX]; /* h/w rate */ 256*1000Sxc151355 257*1000Sxc151355 ddi_acc_handle_t asc_cfg_handle; /* DDI I/O handle */ 258*1000Sxc151355 ddi_acc_handle_t asc_io_handle; /* DDI I/O handle */ 259*1000Sxc151355 uint16_t asc_cachelsz; /* cache line size */ 260*1000Sxc151355 ddi_iblock_cookie_t asc_iblock; 261*1000Sxc151355 ddi_softintr_t asc_softint_id; 262*1000Sxc151355 263*1000Sxc151355 struct ath_desc *asc_desc; /* TX/RX descriptors */ 264*1000Sxc151355 dma_area_t asc_desc_dma; /* descriptor structure */ 265*1000Sxc151355 /* pointer to the first "struct ath_buf" */ 266*1000Sxc151355 struct ath_buf *asc_vbufptr; 267*1000Sxc151355 /* length of all allocated "struct ath_buf" */ 268*1000Sxc151355 uint32_t asc_vbuflen; 269*1000Sxc151355 /* size of one DMA TX/RX buffer based on 802.11 MTU */ 270*1000Sxc151355 int32_t asc_dmabuf_size; 271*1000Sxc151355 272*1000Sxc151355 list_t asc_rxbuf_list; 273*1000Sxc151355 kmutex_t asc_rxbuflock; /* recv lock for above data */ 274*1000Sxc151355 uint32_t *asc_rxlink; /* link ptr in last RX desc */ 275*1000Sxc151355 uint32_t asc_rx_pend; 276*1000Sxc151355 277*1000Sxc151355 list_t asc_txbuf_list; 278*1000Sxc151355 kmutex_t asc_txbuflock; /* txbuf lock */ 279*1000Sxc151355 280*1000Sxc151355 uint_t asc_txqsetup; /* h/w queues setup */ 281*1000Sxc151355 struct ath_txq asc_txq[HAL_NUM_TX_QUEUES]; /* tx queues */ 282*1000Sxc151355 struct ath_txq *asc_ac2q[5]; /* WME AC -> h/w qnum */ 283*1000Sxc151355 284*1000Sxc151355 const HAL_RATE_TABLE *asc_currates; /* current rate table */ 285*1000Sxc151355 enum ieee80211_phymode asc_curmode; /* current phy mode */ 286*1000Sxc151355 uint8_t asc_rixmap[256]; /* IEEE to h/w rate table ix */ 287*1000Sxc151355 HAL_INT asc_imask; /* interrupt mask copy */ 288*1000Sxc151355 struct ath_stats asc_stats; /* interface statistics */ 289*1000Sxc151355 int32_t asc_promisc; /* Promiscuous mode enabled */ 290*1000Sxc151355 uint8_t asc_mcast_cnt[64]; 291*1000Sxc151355 uint32_t asc_mfilt[2]; 292*1000Sxc151355 kmutex_t asc_genlock; 293*1000Sxc151355 294*1000Sxc151355 uint32_t asc_need_gld_sched; 295*1000Sxc151355 kmutex_t asc_gld_sched_lock; 296*1000Sxc151355 } ath_t; 297*1000Sxc151355 298*1000Sxc151355 #define ATH_STATE(macinfo) ((ath_t *)((macinfo)->gldm_private)) 299*1000Sxc151355 300*1000Sxc151355 /* Debug and log functions */ 301*1000Sxc151355 void ath_dbg(uint32_t dbg_flags, const char *fmt, ...); /* debug function */ 302*1000Sxc151355 void ath_log(const char *fmt, ...); /* event log function */ 303*1000Sxc151355 void ath_problem(const char *fmt, ...); /* run-time problem function */ 304*1000Sxc151355 305*1000Sxc151355 #ifdef __cplusplus 306*1000Sxc151355 } 307*1000Sxc151355 #endif 308*1000Sxc151355 309*1000Sxc151355 #endif /* _ATH_IMPL_H */ 310