Initial import of Atheros Hardware Access Layer (HAL) version 0.9.16.16
[dragonfly.git] / sys / contrib / dev / ath / ah.h
1 /*-
2  * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting, Atheros
3  * Communications, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the following conditions are met:
7  * 1. The materials contained herein are unmodified and are used
8  *    unmodified.
9  * 2. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following NO
11  *    ''WARRANTY'' disclaimer below (''Disclaimer''), without
12  *    modification.
13  * 3. Redistributions in binary form must reproduce at minimum a
14  *    disclaimer similar to the Disclaimer below and any redistribution
15  *    must be conditioned upon including a substantially similar
16  *    Disclaimer requirement for further binary redistribution.
17  * 4. Neither the names of the above-listed copyright holders nor the
18  *    names of any contributors may be used to endorse or promote
19  *    product derived from this software without specific prior written
20  *    permission.
21  *
22  * NO WARRANTY
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT,
26  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
28  * FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGES.
35  *
36  * $Id: //depot/sw/linuxsrc/src/802_11/madwifi/hal/main/ah.h#134 $
37  */
38
39 #ifndef _ATH_AH_H_
40 #define _ATH_AH_H_
41 /*
42  * Atheros Hardware Access Layer
43  *
44  * Clients of the HAL call ath_hal_attach to obtain a reference to an ath_hal
45  * structure for use with the device.  Hardware-related operations that
46  * follow must call back into the HAL through interface, supplying the
47  * reference as the first parameter.
48  */
49 #include "ah_osdep.h"
50
51 /*
52  * __ahdecl is analogous to _cdecl; it defines the calling
53  * convention used within the HAL.  For most systems this
54  * can just default to be empty and the compiler will (should)
55  * use _cdecl.  For systems where _cdecl is not compatible this
56  * must be defined.  See linux/ah_osdep.h for an example.
57  */
58 #ifndef __ahdecl
59 #define __ahdecl
60 #endif
61
62 /*
63  * Status codes that may be returned by the HAL.  Note that
64  * interfaces that return a status code set it only when an
65  * error occurs--i.e. you cannot check it for success.
66  */
67 typedef enum {
68         HAL_OK          = 0,    /* No error */
69         HAL_ENXIO       = 1,    /* No hardware present */
70         HAL_ENOMEM      = 2,    /* Memory allocation failed */
71         HAL_EIO         = 3,    /* Hardware didn't respond as expected */
72         HAL_EEMAGIC     = 4,    /* EEPROM magic number invalid */
73         HAL_EEVERSION   = 5,    /* EEPROM version invalid */
74         HAL_EELOCKED    = 6,    /* EEPROM unreadable */
75         HAL_EEBADSUM    = 7,    /* EEPROM checksum invalid */
76         HAL_EEREAD      = 8,    /* EEPROM read problem */
77         HAL_EEBADMAC    = 9,    /* EEPROM mac address invalid */
78         HAL_EESIZE      = 10,   /* EEPROM size not supported */
79         HAL_EEWRITE     = 11,   /* Attempt to change write-locked EEPROM */
80         HAL_EINVAL      = 12,   /* Invalid parameter to function */
81         HAL_ENOTSUPP    = 13,   /* Hardware revision not supported */
82         HAL_ESELFTEST   = 14,   /* Hardware self-test failed */
83         HAL_EINPROGRESS = 15,   /* Operation incomplete */
84 } HAL_STATUS;
85
86 typedef enum {
87         AH_FALSE = 0,           /* NB: lots of code assumes false is zero */
88         AH_TRUE  = 1,
89 } HAL_BOOL;
90
91 typedef enum {
92         HAL_CAP_REG_DMN         = 0,    /* current regulatory domain */
93         HAL_CAP_CIPHER          = 1,    /* hardware supports cipher */
94         HAL_CAP_TKIP_MIC        = 2,    /* handle TKIP MIC in hardware */
95         HAL_CAP_TKIP_SPLIT      = 3,    /* hardware TKIP uses split keys */
96         HAL_CAP_PHYCOUNTERS     = 4,    /* hardware PHY error counters */
97         HAL_CAP_DIVERSITY       = 5,    /* hardware supports fast diversity */
98         HAL_CAP_KEYCACHE_SIZE   = 6,    /* number of entries in key cache */
99         HAL_CAP_NUM_TXQUEUES    = 7,    /* number of hardware xmit queues */
100         HAL_CAP_VEOL            = 9,    /* hardware supports virtual EOL */
101         HAL_CAP_PSPOLL          = 10,   /* hardware has working PS-Poll support */
102         HAL_CAP_DIAG            = 11,   /* hardware diagnostic support */
103         HAL_CAP_COMPRESSION     = 12,   /* hardware supports compression */
104         HAL_CAP_BURST           = 13,   /* hardware supports packet bursting */
105         HAL_CAP_FASTFRAME       = 14,   /* hardware supoprts fast frames */
106         HAL_CAP_TXPOW           = 15,   /* global tx power limit  */
107         HAL_CAP_TPC             = 16,   /* per-packet tx power control  */
108         HAL_CAP_PHYDIAG         = 17,   /* hardware phy error diagnostic */
109         HAL_CAP_BSSIDMASK       = 18,   /* hardware supports bssid mask */
110         HAL_CAP_MCAST_KEYSRCH   = 19,   /* hardware has multicast key search */
111         HAL_CAP_TSF_ADJUST      = 20,   /* hardware has beacon tsf adjust */
112         HAL_CAP_XR              = 21,   /* hardware has XR support  */
113         HAL_CAP_WME_TKIPMIC     = 22,   /* hardware can support TKIP MIC when WMM is turned on */
114         HAL_CAP_CHAN_HALFRATE   = 23,   /* hardware can support half rate channels */
115         HAL_CAP_CHAN_QUARTERRATE = 24,  /* hardware can support quarter rate channels */
116         HAL_CAP_RFSILENT        = 25,   /* hardware has rfsilent support  */
117         HAL_CAP_TPC_ACK         = 26,   /* ack txpower with per-packet tpc */
118         HAL_CAP_TPC_CTS         = 27,   /* cts txpower with per-packet tpc */
119         HAL_CAP_11D             = 28,   /* 11d beacon support for changing cc */
120 } HAL_CAPABILITY_TYPE;
121
122 /* 
123  * "States" for setting the LED.  These correspond to
124  * the possible 802.11 operational states and there may
125  * be a many-to-one mapping between these states and the
126  * actual hardware state for the LED's (i.e. the hardware
127  * may have fewer states).
128  */
129 typedef enum {
130         HAL_LED_INIT    = 0,
131         HAL_LED_SCAN    = 1,
132         HAL_LED_AUTH    = 2,
133         HAL_LED_ASSOC   = 3,
134         HAL_LED_RUN     = 4
135 } HAL_LED_STATE;
136
137 /*
138  * Transmit queue types/numbers.  These are used to tag
139  * each transmit queue in the hardware and to identify a set
140  * of transmit queues for operations such as start/stop dma.
141  */
142 typedef enum {
143         HAL_TX_QUEUE_INACTIVE   = 0,            /* queue is inactive/unused */
144         HAL_TX_QUEUE_DATA       = 1,            /* data xmit q's */
145         HAL_TX_QUEUE_BEACON     = 2,            /* beacon xmit q */
146         HAL_TX_QUEUE_CAB        = 3,            /* "crap after beacon" xmit q */
147         HAL_TX_QUEUE_UAPSD      = 4,            /* u-apsd power save xmit q */
148 } HAL_TX_QUEUE;
149
150 #define HAL_NUM_TX_QUEUES       10              /* max possible # of queues */
151
152 /*
153  * Transmit queue subtype.  These map directly to
154  * WME Access Categories (except for UPSD).  Refer
155  * to Table 5 of the WME spec.
156  */
157 typedef enum {
158         HAL_WME_AC_BK   = 0,                    /* background access category */
159         HAL_WME_AC_BE   = 1,                    /* best effort access category*/
160         HAL_WME_AC_VI   = 2,                    /* video access category */
161         HAL_WME_AC_VO   = 3,                    /* voice access category */
162         HAL_WME_UPSD    = 4,                    /* uplink power save */
163         HAL_XR_DATA     = 5,                    /* uplink power save */
164 } HAL_TX_QUEUE_SUBTYPE;
165
166 /*
167  * Transmit queue flags that control various
168  * operational parameters.
169  */
170 typedef enum {
171         /*
172          * Per queue interrupt enables.  When set the associated
173          * interrupt may be delivered for packets sent through
174          * the queue.  Without these enabled no interrupts will
175          * be delivered for transmits through the queue.
176          */
177         HAL_TXQ_TXOKINT_ENABLE     = 0x0001,    /* enable TXOK interrupt */
178         HAL_TXQ_TXERRINT_ENABLE    = 0x0001,    /* enable TXERR interrupt */
179         HAL_TXQ_TXDESCINT_ENABLE   = 0x0002,    /* enable TXDESC interrupt */
180         HAL_TXQ_TXEOLINT_ENABLE    = 0x0004,    /* enable TXEOL interrupt */
181         HAL_TXQ_TXURNINT_ENABLE    = 0x0008,    /* enable TXURN interrupt */
182         /*
183          * Enable hardware compression for packets sent through
184          * the queue.  The compression buffer must be setup and
185          * packets must have a key entry marked in the tx descriptor.
186          */
187         HAL_TXQ_COMPRESSION_ENABLE  = 0x0010,   /* enable h/w compression */
188         /*
189          * Disable queue when veol is hit or ready time expires.
190          * By default the queue is disabled only on reaching the
191          * physical end of queue (i.e. a null link ptr in the
192          * descriptor chain).
193          */
194         HAL_TXQ_RDYTIME_EXP_POLICY_ENABLE = 0x0020,
195         /*
196          * Schedule frames on delivery of a DBA (DMA Beacon Alert)
197          * event.  Frames will be transmitted only when this timer
198          * fires, e.g to transmit a beacon in ap or adhoc modes.
199          */
200         HAL_TXQ_DBA_GATED           = 0x0040,   /* schedule based on DBA */
201         /*
202          * Each transmit queue has a counter that is incremented
203          * each time the queue is enabled and decremented when
204          * the list of frames to transmit is traversed (or when
205          * the ready time for the queue expires).  This counter
206          * must be non-zero for frames to be scheduled for
207          * transmission.  The following controls disable bumping
208          * this counter under certain conditions.  Typically this
209          * is used to gate frames based on the contents of another
210          * queue (e.g. CAB traffic may only follow a beacon frame).
211          * These are meaningful only when frames are scheduled
212          * with a non-ASAP policy (e.g. DBA-gated).
213          */
214         HAL_TXQ_CBR_DIS_QEMPTY      = 0x0080,   /* disable on this q empty */
215         HAL_TXQ_CBR_DIS_BEMPTY      = 0x0100,   /* disable on beacon q empty */
216
217         /*
218          * Fragment burst backoff policy.  Normally the no backoff
219          * is done after a successful transmission, the next fragment
220          * is sent at SIFS.  If this flag is set backoff is done
221          * after each fragment, regardless whether it was ack'd or
222          * not, after the backoff count reaches zero a normal channel
223          * access procedure is done before the next transmit (i.e.
224          * wait AIFS instead of SIFS).
225          */
226         HAL_TXQ_FRAG_BURST_BACKOFF_ENABLE = 0x00800000,
227         /*
228          * Disable post-tx backoff following each frame.
229          */
230         HAL_TXQ_BACKOFF_DISABLE     = 0x00010000, /* disable post backoff  */
231         /*
232          * DCU arbiter lockout control.  This controls how
233          * lower priority tx queues are handled with respect to
234          * to a specific queue when multiple queues have frames
235          * to send.  No lockout means lower priority queues arbitrate
236          * concurrently with this queue.  Intra-frame lockout
237          * means lower priority queues are locked out until the
238          * current frame transmits (e.g. including backoffs and bursting).
239          * Global lockout means nothing lower can arbitrary so
240          * long as there is traffic activity on this queue (frames,
241          * backoff, etc).
242          */
243         HAL_TXQ_ARB_LOCKOUT_INTRA   = 0x00020000, /* intra-frame lockout */
244         HAL_TXQ_ARB_LOCKOUT_GLOBAL  = 0x00040000, /* full lockout s */
245
246         HAL_TXQ_IGNORE_VIRTCOL      = 0x00080000, /* ignore virt collisions */
247         HAL_TXQ_SEQNUM_INC_DIS      = 0x00100000, /* disable seqnum increment */
248 } HAL_TX_QUEUE_FLAGS;
249
250 typedef struct {
251         u_int32_t       tqi_ver;                /* hal TXQ version */
252         HAL_TX_QUEUE_SUBTYPE tqi_subtype;       /* subtype if applicable */
253         HAL_TX_QUEUE_FLAGS tqi_qflags;          /* flags (see above) */
254         u_int32_t       tqi_priority;           /* (not used) */
255         u_int32_t       tqi_aifs;               /* aifs */
256         u_int32_t       tqi_cwmin;              /* cwMin */
257         u_int32_t       tqi_cwmax;              /* cwMax */
258         u_int16_t       tqi_shretry;            /* rts retry limit */
259         u_int16_t       tqi_lgretry;            /* long retry limit (not used)*/
260         u_int32_t       tqi_cbrPeriod;          /* CBR period (us) */
261         u_int32_t       tqi_cbrOverflowLimit;   /* threshold for CBROVF int */
262         u_int32_t       tqi_burstTime;          /* max burst duration (us) */
263         u_int32_t       tqi_readyTime;          /* frame schedule time (us) */
264         u_int32_t       tqi_compBuf;            /* comp buffer phys addr */
265 } HAL_TXQ_INFO;
266
267 #define HAL_TQI_NONVAL 0xffff
268
269 /* token to use for aifs, cwmin, cwmax */
270 #define HAL_TXQ_USEDEFAULT      ((u_int32_t) -1)
271
272 /* compression definitions */
273 #define HAL_COMP_BUF_MAX_SIZE           9216            /* 9K */
274 #define HAL_COMP_BUF_ALIGN_SIZE         512
275 #define HAL_DECOMP_MASK_SIZE            128
276
277
278 /*
279  * Transmit packet types.  This belongs in ah_desc.h, but
280  * is here so we can give a proper type to various parameters
281  * (and not require everyone include the file).
282  *
283  * NB: These values are intentionally assigned for
284  *     direct use when setting up h/w descriptors.
285  */
286 typedef enum {
287         HAL_PKT_TYPE_NORMAL     = 0,
288         HAL_PKT_TYPE_ATIM       = 1,
289         HAL_PKT_TYPE_PSPOLL     = 2,
290         HAL_PKT_TYPE_BEACON     = 3,
291         HAL_PKT_TYPE_PROBE_RESP = 4,
292         HAL_PKT_TYPE_CHIRP      = 5,
293         HAL_PKT_TYPE_GRP_POLL = 6,
294 } HAL_PKT_TYPE;
295
296 /* Rx Filter Frame Types */
297 typedef enum {
298         HAL_RX_FILTER_UCAST     = 0x00000001,   /* Allow unicast frames */
299         HAL_RX_FILTER_MCAST     = 0x00000002,   /* Allow multicast frames */
300         HAL_RX_FILTER_BCAST     = 0x00000004,   /* Allow broadcast frames */
301         HAL_RX_FILTER_CONTROL   = 0x00000008,   /* Allow control frames */
302         HAL_RX_FILTER_BEACON    = 0x00000010,   /* Allow beacon frames */
303         HAL_RX_FILTER_PROM      = 0x00000020,   /* Promiscuous mode */
304         HAL_RX_FILTER_XRPOLL    = 0x00000040,   /* Allow XR poll frmae */
305         HAL_RX_FILTER_PROBEREQ  = 0x00000080,   /* Allow probe request frames */
306         HAL_RX_FILTER_PHYERR    = 0x00000100,   /* Allow phy errors */
307         HAL_RX_FILTER_PHYRADAR  = 0x00000200,   /* Allow phy radar errors*/
308 } HAL_RX_FILTER;
309
310 typedef enum {
311         HAL_PM_AWAKE            = 0,
312         HAL_PM_FULL_SLEEP       = 1,
313         HAL_PM_NETWORK_SLEEP    = 2,
314         HAL_PM_UNDEFINED        = 3
315 } HAL_POWER_MODE;
316
317 /*
318  * NOTE WELL:
319  * These are mapped to take advantage of the common locations for many of
320  * the bits on all of the currently supported MAC chips. This is to make
321  * the ISR as efficient as possible, while still abstracting HW differences.
322  * When new hardware breaks this commonality this enumerated type, as well
323  * as the HAL functions using it, must be modified. All values are directly
324  * mapped unless commented otherwise.
325  */
326 typedef enum {
327         HAL_INT_RX      = 0x00000001,   /* Non-common mapping */
328         HAL_INT_RXDESC  = 0x00000002,
329         HAL_INT_RXNOFRM = 0x00000008,
330         HAL_INT_RXEOL   = 0x00000010,
331         HAL_INT_RXORN   = 0x00000020,
332         HAL_INT_TX      = 0x00000040,   /* Non-common mapping */
333         HAL_INT_TXDESC  = 0x00000080,
334         HAL_INT_TXURN   = 0x00000800,
335         HAL_INT_MIB     = 0x00001000,
336         HAL_INT_RXPHY   = 0x00004000,
337         HAL_INT_RXKCM   = 0x00008000,
338         HAL_INT_SWBA    = 0x00010000,
339         HAL_INT_BMISS   = 0x00040000,
340         HAL_INT_BNR     = 0x00100000,   /* Non-common mapping */
341         HAL_INT_TIM     = 0x00200000,   /* Non-common mapping */
342         HAL_INT_DTIM    = 0x00400000,   /* Non-common mapping */
343         HAL_INT_DTIMSYNC= 0x00800000,   /* Non-common mapping */
344         HAL_INT_GPIO    = 0x01000000,
345         HAL_INT_CABEND  = 0x02000000,   /* Non-common mapping */
346         HAL_INT_FATAL   = 0x40000000,   /* Non-common mapping */
347         HAL_INT_GLOBAL  = 0x80000000,   /* Set/clear IER */
348         HAL_INT_BMISC   = HAL_INT_TIM
349                         | HAL_INT_DTIM
350                         | HAL_INT_DTIMSYNC
351                         | HAL_INT_CABEND,
352
353         /* Interrupt bits that map directly to ISR/IMR bits */
354         HAL_INT_COMMON  = HAL_INT_RXNOFRM
355                         | HAL_INT_RXDESC
356                         | HAL_INT_RXEOL
357                         | HAL_INT_RXORN
358                         | HAL_INT_TXURN
359                         | HAL_INT_TXDESC
360                         | HAL_INT_MIB
361                         | HAL_INT_RXPHY
362                         | HAL_INT_RXKCM
363                         | HAL_INT_SWBA
364                         | HAL_INT_BMISS
365                         | HAL_INT_GPIO,
366         HAL_INT_NOCARD  = 0xffffffff    /* To signal the card was removed */
367 } HAL_INT;
368
369 typedef enum {
370         HAL_RFGAIN_INACTIVE             = 0,
371         HAL_RFGAIN_READ_REQUESTED       = 1,
372         HAL_RFGAIN_NEED_CHANGE          = 2
373 } HAL_RFGAIN;
374
375 /*
376  * Channels are specified by frequency.
377  */
378 typedef struct {
379         u_int16_t       channel;        /* setting in Mhz */
380         u_int16_t       channelFlags;   /* see below */
381         u_int8_t        privFlags;
382         int8_t          maxRegTxPower;  /* max regulatory tx power in dBm */
383         int8_t          maxTxPower;     /* max true tx power in 0.25 dBm */
384         int8_t          minTxPower;     /* min true tx power in 0.25 dBm */
385 } HAL_CHANNEL;
386
387 /* channelFlags */
388 #define CHANNEL_CW_INT  0x0002  /* CW interference detected on channel */
389 #define CHANNEL_TURBO   0x0010  /* Turbo Channel */
390 #define CHANNEL_CCK     0x0020  /* CCK channel */
391 #define CHANNEL_OFDM    0x0040  /* OFDM channel */
392 #define CHANNEL_2GHZ    0x0080  /* 2 GHz spectrum channel. */
393 #define CHANNEL_5GHZ    0x0100  /* 5 GHz spectrum channel */
394 #define CHANNEL_PASSIVE 0x0200  /* Only passive scan allowed in the channel */
395 #define CHANNEL_DYN     0x0400  /* dynamic CCK-OFDM channel */
396 #define CHANNEL_XR      0x0800  /* XR channel */
397 #define CHANNEL_STURBO  0x2000  /* Static turbo, no 11a-only usage */
398 #define CHANNEL_HALF    0x4000  /* Half rate channel */
399 #define CHANNEL_QUARTER 0x8000  /* Quarter rate channel */
400
401 /* privFlags */
402 #define CHANNEL_INTERFERENCE    0x01 /* Software use: channel interference 
403                                         used for as AR as well as RADAR 
404                                         interference detection */
405 #define CHANNEL_DFS             0x02 /* DFS required on channel */
406 #define CHANNEL_4MS_LIMIT       0x04 /* 4msec packet limit on this channel */
407 #define CHANNEL_DFS_CLEAR       0x08 /* if channel has been checked for DFS */
408
409 #define CHANNEL_A       (CHANNEL_5GHZ|CHANNEL_OFDM)
410 #define CHANNEL_B       (CHANNEL_2GHZ|CHANNEL_CCK)
411 #define CHANNEL_PUREG   (CHANNEL_2GHZ|CHANNEL_OFDM)
412 #ifdef notdef
413 #define CHANNEL_G       (CHANNEL_2GHZ|CHANNEL_DYN)
414 #else
415 #define CHANNEL_G       (CHANNEL_2GHZ|CHANNEL_OFDM)
416 #endif
417 #define CHANNEL_T       (CHANNEL_5GHZ|CHANNEL_OFDM|CHANNEL_TURBO)
418 #define CHANNEL_ST      (CHANNEL_T|CHANNEL_STURBO)
419 #define CHANNEL_108G    (CHANNEL_2GHZ|CHANNEL_OFDM|CHANNEL_TURBO)
420 #define CHANNEL_108A    CHANNEL_T
421 #define CHANNEL_X       (CHANNEL_5GHZ|CHANNEL_OFDM|CHANNEL_XR)
422 #define CHANNEL_ALL \
423         (CHANNEL_OFDM|CHANNEL_CCK| CHANNEL_2GHZ | CHANNEL_5GHZ | CHANNEL_TURBO)
424 #define CHANNEL_ALL_NOTURBO     (CHANNEL_ALL &~ CHANNEL_TURBO)
425
426 #define HAL_ANTENNA_MIN_MODE  0
427 #define HAL_ANTENNA_FIXED_A   1
428 #define HAL_ANTENNA_FIXED_B   2
429 #define HAL_ANTENNA_MAX_MODE  3
430
431 typedef struct {
432         u_int32_t       ackrcv_bad;
433         u_int32_t       rts_bad;
434         u_int32_t       rts_good;
435         u_int32_t       fcs_bad;
436         u_int32_t       beacons;
437 } HAL_MIB_STATS;
438
439 typedef u_int16_t HAL_CTRY_CODE;                /* country code */
440 typedef u_int16_t HAL_REG_DOMAIN;               /* regulatory domain code */
441
442 enum {
443         CTRY_DEBUG      = 0x1ff,                /* debug country code */
444         CTRY_DEFAULT    = 0                     /* default country code */
445 };
446
447 enum {
448         HAL_MODE_11A    = 0x001,                /* 11a channels */
449         HAL_MODE_TURBO  = 0x002,                /* 11a turbo-only channels */
450         HAL_MODE_11B    = 0x004,                /* 11b channels */
451         HAL_MODE_PUREG  = 0x008,                /* 11g channels (OFDM only) */
452 #ifdef notdef
453         HAL_MODE_11G    = 0x010,                /* 11g channels (OFDM/CCK) */
454 #else
455         HAL_MODE_11G    = 0x008,                /* XXX historical */
456 #endif
457         HAL_MODE_108G   = 0x020,                /* 11a+Turbo channels */
458         HAL_MODE_108A   = 0x040,                /* 11g+Turbo channels */
459         HAL_MODE_XR     = 0x100,                /* XR channels */
460         HAL_MODE_11A_HALF_RATE = 0x200,         /* 11A half rate channels */
461         HAL_MODE_11A_QUARTER_RATE = 0x400,      /* 11A quarter rate channels */
462         HAL_MODE_ALL    = 0xfff
463 };
464
465 typedef struct {
466         int             rateCount;              /* NB: for proper padding */
467         u_int8_t        rateCodeToIndex[32];    /* back mapping */
468         struct {
469                 u_int8_t        valid;          /* valid for rate control use */
470                 u_int8_t        phy;            /* CCK/OFDM/XR */
471                 u_int16_t       rateKbps;       /* transfer rate in kbs */
472                 u_int8_t        rateCode;       /* rate for h/w descriptors */
473                 u_int8_t        shortPreamble;  /* mask for enabling short
474                                                  * preamble in CCK rate code */
475                 u_int8_t        dot11Rate;      /* value for supported rates
476                                                  * info element of MLME */
477                 u_int8_t        controlRate;    /* index of next lower basic
478                                                  * rate; used for dur. calcs */
479                 u_int16_t       lpAckDuration;  /* long preamble ACK duration */
480                 u_int16_t       spAckDuration;  /* short preamble ACK duration*/
481         } info[32];
482 } HAL_RATE_TABLE;
483
484 typedef struct {
485         u_int           rs_count;               /* number of valid entries */
486         u_int8_t        rs_rates[32];           /* rates */
487 } HAL_RATE_SET;
488
489 typedef enum {
490         HAL_ANT_VARIABLE = 0,                   /* variable by programming */
491         HAL_ANT_FIXED_A  = 1,                   /* fixed to 11a frequencies */
492         HAL_ANT_FIXED_B  = 2,                   /* fixed to 11b frequencies */
493 } HAL_ANT_SETTING;
494
495 typedef enum {
496         HAL_M_STA       = 1,                    /* infrastructure station */
497         HAL_M_IBSS      = 0,                    /* IBSS (adhoc) station */
498         HAL_M_HOSTAP    = 6,                    /* Software Access Point */
499         HAL_M_MONITOR   = 8                     /* Monitor mode */
500 } HAL_OPMODE;
501
502 typedef struct {
503         u_int8_t        kv_type;                /* one of HAL_CIPHER */
504         u_int8_t        kv_pad;
505         u_int16_t       kv_len;                 /* length in bits */
506         u_int8_t        kv_val[16];             /* enough for 128-bit keys */
507         u_int8_t        kv_mic[8];              /* TKIP MIC key */
508 } HAL_KEYVAL;
509
510 typedef enum {
511         HAL_CIPHER_WEP          = 0,
512         HAL_CIPHER_AES_OCB      = 1,
513         HAL_CIPHER_AES_CCM      = 2,
514         HAL_CIPHER_CKIP         = 3,
515         HAL_CIPHER_TKIP         = 4,
516         HAL_CIPHER_CLR          = 5,            /* no encryption */
517
518         HAL_CIPHER_MIC          = 127           /* TKIP-MIC, not a cipher */
519 } HAL_CIPHER;
520
521 enum {
522         HAL_SLOT_TIME_9  = 9,
523         HAL_SLOT_TIME_20 = 20,
524 };
525
526 /*
527  * Per-station beacon timer state.  Note that the specified
528  * beacon interval (given in TU's) can also include flags
529  * to force a TSF reset and to enable the beacon xmit logic.
530  * If bs_cfpmaxduration is non-zero the hardware is setup to
531  * coexist with a PCF-capable AP.
532  */
533 typedef struct {
534         u_int32_t       bs_nexttbtt;            /* next beacon in TU */
535         u_int32_t       bs_nextdtim;            /* next DTIM in TU */
536         u_int32_t       bs_intval;              /* beacon interval+flags */
537 #define HAL_BEACON_PERIOD       0x0000ffff      /* beacon interval period */
538 #define HAL_BEACON_ENA          0x00800000      /* beacon xmit enable */
539 #define HAL_BEACON_RESET_TSF    0x01000000      /* clear TSF */
540         u_int32_t       bs_dtimperiod;
541         u_int16_t       bs_cfpperiod;           /* CFP period in TU */
542         u_int16_t       bs_cfpmaxduration;      /* max CFP duration in TU */
543         u_int32_t       bs_cfpnext;             /* next CFP in TU */
544         u_int16_t       bs_timoffset;           /* byte offset to TIM bitmap */
545         u_int16_t       bs_bmissthreshold;      /* beacon miss threshold */
546         u_int32_t       bs_sleepduration;       /* max sleep duration */
547 } HAL_BEACON_STATE;
548
549 /*
550  * Per-node statistics maintained by the driver for use in
551  * optimizing signal quality and other operational aspects.
552  */
553 typedef struct {
554         u_int32_t       ns_avgbrssi;    /* average beacon rssi */
555         u_int32_t       ns_avgrssi;     /* average data rssi */
556         u_int32_t       ns_avgtxrssi;   /* average tx rssi */
557 } HAL_NODE_STATS;
558
559 #define HAL_RSSI_EP_MULTIPLIER  (1<<7)  /* pow2 to optimize out * and / */
560
561 struct ath_desc;
562
563 /*
564  * Hardware Access Layer (HAL) API.
565  *
566  * Clients of the HAL call ath_hal_attach to obtain a reference to an
567  * ath_hal structure for use with the device.  Hardware-related operations
568  * that follow must call back into the HAL through interface, supplying
569  * the reference as the first parameter.  Note that before using the
570  * reference returned by ath_hal_attach the caller should verify the
571  * ABI version number.
572  */
573 struct ath_hal {
574         u_int32_t       ah_magic;       /* consistency check magic number */
575         u_int32_t       ah_abi;         /* HAL ABI version */
576 #define HAL_ABI_VERSION 0x05122200      /* YYMMDDnn */
577         u_int16_t       ah_devid;       /* PCI device ID */
578         u_int16_t       ah_subvendorid; /* PCI subvendor ID */
579         HAL_SOFTC       ah_sc;          /* back pointer to driver/os state */
580         HAL_BUS_TAG     ah_st;          /* params for register r+w */
581         HAL_BUS_HANDLE  ah_sh;
582         HAL_CTRY_CODE   ah_countryCode;
583
584         u_int32_t       ah_macVersion;  /* MAC version id */
585         u_int16_t       ah_macRev;      /* MAC revision */
586         u_int16_t       ah_phyRev;      /* PHY revision */
587         /* NB: when only one radio is present the rev is in 5Ghz */
588         u_int16_t       ah_analog5GhzRev;/* 5GHz radio revision */
589         u_int16_t       ah_analog2GhzRev;/* 2GHz radio revision */
590         u_int8_t        ah_decompMask[HAL_DECOMP_MASK_SIZE]; /* decomp mask array */
591         const HAL_RATE_TABLE *__ahdecl(*ah_getRateTable)(struct ath_hal *,
592                                 u_int mode);
593         void      __ahdecl(*ah_detach)(struct ath_hal*);
594
595         /* Reset functions */
596         HAL_BOOL  __ahdecl(*ah_reset)(struct ath_hal *, HAL_OPMODE,
597                                 HAL_CHANNEL *, HAL_BOOL bChannelChange,
598                                 HAL_STATUS *status);
599         HAL_BOOL  __ahdecl(*ah_phyDisable)(struct ath_hal *);
600         void      __ahdecl(*ah_setPCUConfig)(struct ath_hal *);
601         HAL_BOOL  __ahdecl(*ah_perCalibration)(struct ath_hal*, HAL_CHANNEL *, HAL_BOOL *);
602         HAL_BOOL  __ahdecl(*ah_setTxPowerLimit)(struct ath_hal *, u_int32_t);
603
604         void      __ahdecl(*ah_arEnable)(struct ath_hal *);
605         void      __ahdecl(*ah_arDisable)(struct ath_hal *);
606         void      __ahdecl(*ah_arReset)(struct ath_hal *);
607         HAL_BOOL  __ahdecl(*ah_radarHaveEvent)(struct ath_hal *);
608         HAL_BOOL  __ahdecl(*ah_processDfs)(struct ath_hal *, HAL_CHANNEL *);
609         u_int32_t __ahdecl(*ah_dfsNolCheck)(struct ath_hal *, HAL_CHANNEL *, u_int32_t);
610         HAL_BOOL  __ahdecl(*ah_radarWait)(struct ath_hal *, HAL_CHANNEL *);
611
612         /* Transmit functions */
613         HAL_BOOL  __ahdecl(*ah_updateTxTrigLevel)(struct ath_hal*,
614                                 HAL_BOOL incTrigLevel);
615         int       __ahdecl(*ah_setupTxQueue)(struct ath_hal *, HAL_TX_QUEUE,
616                                 const HAL_TXQ_INFO *qInfo);
617         HAL_BOOL  __ahdecl(*ah_setTxQueueProps)(struct ath_hal *, int q, 
618                                 const HAL_TXQ_INFO *qInfo);
619         HAL_BOOL  __ahdecl(*ah_getTxQueueProps)(struct ath_hal *, int q, 
620                                 HAL_TXQ_INFO *qInfo);
621         HAL_BOOL  __ahdecl(*ah_releaseTxQueue)(struct ath_hal *ah, u_int q);
622         HAL_BOOL  __ahdecl(*ah_resetTxQueue)(struct ath_hal *ah, u_int q);
623         u_int32_t __ahdecl(*ah_getTxDP)(struct ath_hal*, u_int);
624         HAL_BOOL  __ahdecl(*ah_setTxDP)(struct ath_hal*, u_int, u_int32_t txdp);
625         u_int32_t __ahdecl(*ah_numTxPending)(struct ath_hal *, u_int q);
626         HAL_BOOL  __ahdecl(*ah_startTxDma)(struct ath_hal*, u_int);
627         HAL_BOOL  __ahdecl(*ah_stopTxDma)(struct ath_hal*, u_int);
628         HAL_BOOL  __ahdecl(*ah_setupTxDesc)(struct ath_hal *, struct ath_desc *,
629                                 u_int pktLen, u_int hdrLen,
630                                 HAL_PKT_TYPE type, u_int txPower,
631                                 u_int txRate0, u_int txTries0,
632                                 u_int keyIx, u_int antMode, u_int flags,
633                                 u_int rtsctsRate, u_int rtsctsDuration,
634                                 u_int compicvLen, u_int compivLen,
635                                 u_int comp);
636         HAL_BOOL  __ahdecl(*ah_setupXTxDesc)(struct ath_hal *, struct ath_desc*,
637                                 u_int txRate1, u_int txTries1,
638                                 u_int txRate2, u_int txTries2,
639                                 u_int txRate3, u_int txTries3);
640         HAL_BOOL  __ahdecl(*ah_fillTxDesc)(struct ath_hal *, struct ath_desc *,
641                                 u_int segLen, HAL_BOOL firstSeg,
642                                 HAL_BOOL lastSeg, const struct ath_desc *);
643         HAL_STATUS __ahdecl(*ah_procTxDesc)(struct ath_hal *, struct ath_desc*);
644         void       __ahdecl(*ah_getTxIntrQueue)(struct ath_hal *, u_int32_t *);
645         void       __ahdecl(*ah_reqTxIntrDesc)(struct ath_hal *, struct ath_desc*);
646
647         /* Receive Functions */
648         u_int32_t __ahdecl(*ah_getRxDP)(struct ath_hal*);
649         void      __ahdecl(*ah_setRxDP)(struct ath_hal*, u_int32_t rxdp);
650         void      __ahdecl(*ah_enableReceive)(struct ath_hal*);
651         HAL_BOOL  __ahdecl(*ah_stopDmaReceive)(struct ath_hal*);
652         void      __ahdecl(*ah_startPcuReceive)(struct ath_hal*);
653         void      __ahdecl(*ah_stopPcuReceive)(struct ath_hal*);
654         void      __ahdecl(*ah_setMulticastFilter)(struct ath_hal*,
655                                 u_int32_t filter0, u_int32_t filter1);
656         HAL_BOOL  __ahdecl(*ah_setMulticastFilterIndex)(struct ath_hal*,
657                                 u_int32_t index);
658         HAL_BOOL  __ahdecl(*ah_clrMulticastFilterIndex)(struct ath_hal*,
659                                 u_int32_t index);
660         u_int32_t __ahdecl(*ah_getRxFilter)(struct ath_hal*);
661         void      __ahdecl(*ah_setRxFilter)(struct ath_hal*, u_int32_t);
662         HAL_BOOL  __ahdecl(*ah_setupRxDesc)(struct ath_hal *, struct ath_desc *,
663                                 u_int32_t size, u_int flags);
664         HAL_STATUS __ahdecl(*ah_procRxDesc)(struct ath_hal *, struct ath_desc *,
665                                 u_int32_t phyAddr, struct ath_desc *next,
666                                 u_int64_t tsf);
667         void      __ahdecl(*ah_rxMonitor)(struct ath_hal *,
668                                 const HAL_NODE_STATS *, HAL_CHANNEL *);
669         void      __ahdecl(*ah_procMibEvent)(struct ath_hal *,
670                                 const HAL_NODE_STATS *);
671
672         /* Misc Functions */
673         HAL_STATUS __ahdecl(*ah_getCapability)(struct ath_hal *,
674                                 HAL_CAPABILITY_TYPE, u_int32_t capability,
675                                 u_int32_t *result);
676         HAL_BOOL   __ahdecl(*ah_setCapability)(struct ath_hal *,
677                                 HAL_CAPABILITY_TYPE, u_int32_t capability,
678                                 u_int32_t setting, HAL_STATUS *);
679         HAL_BOOL   __ahdecl(*ah_getDiagState)(struct ath_hal *, int request,
680                                 const void *args, u_int32_t argsize,
681                                 void **result, u_int32_t *resultsize);
682         void      __ahdecl(*ah_getMacAddress)(struct ath_hal *, u_int8_t *);
683         HAL_BOOL  __ahdecl(*ah_setMacAddress)(struct ath_hal *, const u_int8_t*);
684         void      __ahdecl(*ah_getBssIdMask)(struct ath_hal *, u_int8_t *);
685         HAL_BOOL  __ahdecl(*ah_setBssIdMask)(struct ath_hal *, const u_int8_t*);
686         HAL_BOOL  __ahdecl(*ah_setRegulatoryDomain)(struct ath_hal*,
687                                 u_int16_t, HAL_STATUS *);
688         void      __ahdecl(*ah_setLedState)(struct ath_hal*, HAL_LED_STATE);
689         void      __ahdecl(*ah_writeAssocid)(struct ath_hal*,
690                                 const u_int8_t *bssid, u_int16_t assocId);
691         HAL_BOOL  __ahdecl(*ah_gpioCfgOutput)(struct ath_hal *, u_int32_t gpio);
692         HAL_BOOL  __ahdecl(*ah_gpioCfgInput)(struct ath_hal *, u_int32_t gpio);
693         u_int32_t __ahdecl(*ah_gpioGet)(struct ath_hal *, u_int32_t gpio);
694         HAL_BOOL  __ahdecl(*ah_gpioSet)(struct ath_hal *,
695                                 u_int32_t gpio, u_int32_t val);
696         void      __ahdecl(*ah_gpioSetIntr)(struct ath_hal*, u_int, u_int32_t);
697         u_int32_t __ahdecl(*ah_getTsf32)(struct ath_hal*);
698         u_int64_t __ahdecl(*ah_getTsf64)(struct ath_hal*);
699         void      __ahdecl(*ah_resetTsf)(struct ath_hal*);
700         HAL_BOOL  __ahdecl(*ah_detectCardPresent)(struct ath_hal*);
701         void      __ahdecl(*ah_updateMibCounters)(struct ath_hal*,
702                                 HAL_MIB_STATS*);
703         HAL_RFGAIN __ahdecl(*ah_getRfGain)(struct ath_hal*);
704         u_int     __ahdecl(*ah_getDefAntenna)(struct ath_hal*);
705         void      __ahdecl(*ah_setDefAntenna)(struct ath_hal*, u_int);
706         HAL_BOOL  __ahdecl(*ah_setSlotTime)(struct ath_hal*, u_int);
707         u_int     __ahdecl(*ah_getSlotTime)(struct ath_hal*);
708         HAL_BOOL  __ahdecl(*ah_setAckTimeout)(struct ath_hal*, u_int);
709         u_int     __ahdecl(*ah_getAckTimeout)(struct ath_hal*);
710         HAL_BOOL  __ahdecl(*ah_setCTSTimeout)(struct ath_hal*, u_int);
711         u_int     __ahdecl(*ah_getCTSTimeout)(struct ath_hal*);
712         HAL_BOOL  __ahdecl(*ah_setDecompMask)(struct ath_hal*, u_int16_t, int);
713         void      __ahdecl(*ah_setCoverageClass)(struct ath_hal*, u_int8_t, int);
714
715
716         /* Key Cache Functions */
717         u_int32_t __ahdecl(*ah_getKeyCacheSize)(struct ath_hal*);
718         HAL_BOOL  __ahdecl(*ah_resetKeyCacheEntry)(struct ath_hal*, u_int16_t);
719         HAL_BOOL  __ahdecl(*ah_isKeyCacheEntryValid)(struct ath_hal *,
720                                 u_int16_t);
721         HAL_BOOL  __ahdecl(*ah_setKeyCacheEntry)(struct ath_hal*,
722                                 u_int16_t, const HAL_KEYVAL *,
723                                 const u_int8_t *, int);
724         HAL_BOOL  __ahdecl(*ah_setKeyCacheEntryMac)(struct ath_hal*,
725                                 u_int16_t, const u_int8_t *);
726
727         /* Power Management Functions */
728         HAL_BOOL  __ahdecl(*ah_setPowerMode)(struct ath_hal*,
729                                 HAL_POWER_MODE mode, int setChip);
730         HAL_POWER_MODE __ahdecl(*ah_getPowerMode)(struct ath_hal*);
731         int16_t   __ahdecl(*ah_getChanNoise)(struct ath_hal *, HAL_CHANNEL *);
732
733
734         /* Beacon Management Functions */
735         void      __ahdecl(*ah_beaconInit)(struct ath_hal *,
736                                 u_int32_t nexttbtt, u_int32_t intval);
737         void      __ahdecl(*ah_setStationBeaconTimers)(struct ath_hal*,
738                                 const HAL_BEACON_STATE *);
739         void      __ahdecl(*ah_resetStationBeaconTimers)(struct ath_hal*);
740         HAL_BOOL  __ahdecl(*ah_waitForBeaconDone)(struct ath_hal *,
741                                 HAL_BUS_ADDR);
742
743         /* Interrupt functions */
744         HAL_BOOL  __ahdecl(*ah_isInterruptPending)(struct ath_hal*);
745         HAL_BOOL  __ahdecl(*ah_getPendingInterrupts)(struct ath_hal*, HAL_INT*);
746         HAL_INT   __ahdecl(*ah_getInterrupts)(struct ath_hal*);
747         HAL_INT   __ahdecl(*ah_setInterrupts)(struct ath_hal*, HAL_INT);
748 };
749
750 /* 
751  * Check the PCI vendor ID and device ID against Atheros' values
752  * and return a printable description for any Atheros hardware.
753  * AH_NULL is returned if the ID's do not describe Atheros hardware.
754  */
755 extern  const char *__ahdecl ath_hal_probe(u_int16_t vendorid, u_int16_t devid);
756
757 /*
758  * Attach the HAL for use with the specified device.  The device is
759  * defined by the PCI device ID.  The caller provides an opaque pointer
760  * to an upper-layer data structure (HAL_SOFTC) that is stored in the
761  * HAL state block for later use.  Hardware register accesses are done
762  * using the specified bus tag and handle.  On successful return a
763  * reference to a state block is returned that must be supplied in all
764  * subsequent HAL calls.  Storage associated with this reference is
765  * dynamically allocated and must be freed by calling the ah_detach
766  * method when the client is done.  If the attach operation fails a
767  * null (AH_NULL) reference will be returned and a status code will
768  * be returned if the status parameter is non-zero.
769  */
770 extern  struct ath_hal * __ahdecl ath_hal_attach(u_int16_t devid, HAL_SOFTC,
771                 HAL_BUS_TAG, HAL_BUS_HANDLE, HAL_STATUS* status);
772
773 /*
774  * Set the Vendor ID for Vendor SKU's which can modify the
775  * channel properties returned by ath_hal_init_channels.
776  * Return AH_TRUE if set succeeds
777  */
778
779 extern  HAL_BOOL __ahdecl ath_hal_setvendor(struct ath_hal *, u_int32_t );
780
781 /*
782  * Return a list of channels available for use with the hardware.
783  * The list is based on what the hardware is capable of, the specified
784  * country code, the modeSelect mask, and whether or not outdoor
785  * channels are to be permitted.
786  *
787  * The channel list is returned in the supplied array.  maxchans
788  * defines the maximum size of this array.  nchans contains the actual
789  * number of channels returned.  If a problem occurred or there were
790  * no channels that met the criteria then AH_FALSE is returned.
791  */
792 extern  HAL_BOOL __ahdecl ath_hal_init_channels(struct ath_hal *,
793                 HAL_CHANNEL *chans, u_int maxchans, u_int *nchans,
794                 u_int8_t *regclassids, u_int maxregids, u_int *nregids,
795                 HAL_CTRY_CODE cc, u_int16_t modeSelect,
796                 HAL_BOOL enableOutdoor, HAL_BOOL enableExtendedChannels);
797
798 /*
799  * Calibrate noise floor data following a channel scan or similar.
800  * This must be called prior retrieving noise floor data.
801  */
802 extern  void __ahdecl ath_hal_process_noisefloor(struct ath_hal *ah);
803
804 /*
805  * Return bit mask of wireless modes supported by the hardware.
806  */
807 extern  u_int __ahdecl ath_hal_getwirelessmodes(struct ath_hal*, HAL_CTRY_CODE);
808
809 /*
810  * Return rate table for specified mode (11a, 11b, 11g, etc).
811  */
812 extern  const HAL_RATE_TABLE * __ahdecl ath_hal_getratetable(struct ath_hal *,
813                 u_int mode);
814
815 /*
816  * Calculate the transmit duration of a frame.
817  */
818 extern u_int16_t __ahdecl ath_hal_computetxtime(struct ath_hal *,
819                 const HAL_RATE_TABLE *rates, u_int32_t frameLen,
820                 u_int16_t rateix, HAL_BOOL shortPreamble);
821
822 /*
823  * Return if device is public safety.
824  */
825 extern HAL_BOOL __ahdecl ath_hal_ispublicsafetysku(struct ath_hal *);
826
827 /*
828  * Convert between IEEE channel number and channel frequency
829  * using the specified channel flags; e.g. CHANNEL_2GHZ.
830  */
831 extern  int __ahdecl ath_hal_mhz2ieee(struct ath_hal *, u_int mhz, u_int flags);
832
833 /*
834  * Return a version string for the HAL release.
835  */
836 extern  char ath_hal_version[];
837 /*
838  * Return a NULL-terminated array of build/configuration options.
839  */
840 extern  const char* ath_hal_buildopts[];
841 #endif /* _ATH_AH_H_ */