2 * Copyright (c) 2008-2011 Atheros Communications Inc.
4 * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
5 * Original from Linux kernel 3.0.1
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 FILE_LICENCE ( BSD2 );
28 * Header for the ath9k.ko driver core *only* -- hw code nor any other driver
29 * should rely on this file or its contents.
35 /* Macro to expand scalars to 64-bit objects */
37 #define ito64(x) (sizeof(x) == 1) ? \
38 (((unsigned long long int)(x)) & (0xff)) : \
40 (((unsigned long long int)(x)) & 0xffff) : \
42 (((unsigned long long int)(x)) & 0xffffffff) : \
43 (unsigned long long int)(x))
45 /* increment with wrap-around */
46 #define INCR(_l, _sz) do { \
48 (_l) &= ((_sz) - 1); \
51 /* decrement with wrap-around */
52 #define DECR(_l, _sz) do { \
54 (_l) &= ((_sz) - 1); \
57 #define A_MAX(a, b) ((a) > (b) ? (a) : (b))
59 #define TSF_TO_TU(_h,_l) \
60 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
62 #define ATH_TXQ_SETUP(sc, i) ((sc)->tx.txqsetup & (1<<i))
69 /*************************/
70 /* Descriptor Management */
71 /*************************/
73 #define ATH_TXBUF_RESET(_bf) do { \
74 (_bf)->bf_stale = 0; \
75 (_bf)->bf_lastbf = NULL; \
76 (_bf)->bf_next = NULL; \
77 memset(&((_bf)->bf_state), 0, \
78 sizeof(struct ath_buf_state)); \
81 #define ATH_RXBUF_RESET(_bf) do { \
82 (_bf)->bf_stale = 0; \
86 * enum buffer_type - Buffer type flags
88 * @BUF_AMPDU: This buffer is an ampdu, as part of an aggregate (during TX)
89 * @BUF_AGGR: Indicates whether the buffer can be aggregated
90 * (used in aggregation scheduling)
91 * @BUF_XRETRY: To denote excessive retries of the buffer
99 #define bf_isampdu(bf) (bf->bf_state.bf_type & BUF_AMPDU)
100 #define bf_isaggr(bf) (bf->bf_state.bf_type & BUF_AGGR)
101 #define bf_isxretried(bf) (bf->bf_state.bf_type & BUF_XRETRY)
103 #define ATH_TXSTATUS_RING_SIZE 64
109 struct ath_buf *dd_bufptr;
112 int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
113 struct list_head *head, const char *name,
114 int nbuf, int ndesc, int is_tx);
115 void ath_descdma_cleanup(struct ath_softc *sc, struct ath_descdma *dd,
116 struct list_head *head);
124 #define ATH_TXBUF_RESERVE 5
125 #define ATH_MAX_QDEPTH (ATH_TXBUF / 4 - ATH_TXBUF_RESERVE)
126 #define ATH_TXMAXTRY 13
128 #define TID_TO_WME_AC(_tid) \
129 ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
130 (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
131 (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
134 #define ATH_AGGR_DELIM_SZ 4
135 #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */
136 /* number of delimiters for encryption padding */
137 #define ATH_AGGR_ENCRYPTDELIM 10
138 /* minimum h/w qdepth to be sustained to maximize aggregation */
139 #define ATH_AGGR_MIN_QDEPTH 2
140 #define ATH_AMPDU_SUBFRAME_DEFAULT 32
143 #define IEEE80211_SEQ_SEQ_SHIFT 4
144 #define IEEE80211_SEQ_MAX 4096
145 #define IEEE80211_WEP_IVLEN 3
146 #define IEEE80211_WEP_KIDLEN 1
147 #define IEEE80211_WEP_CRCLEN 4
148 #define IEEE80211_MAX_MPDU_LEN (3840 + FCS_LEN + \
149 (IEEE80211_WEP_IVLEN + \
150 IEEE80211_WEP_KIDLEN + \
151 IEEE80211_WEP_CRCLEN))
153 /* return whether a bit at index _n in bitmap _bm is set
154 * _sz is the size of the bitmap */
155 #define ATH_BA_ISSET(_bm, _n) (((_n) < (WME_BA_BMP_SIZE)) && \
156 ((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))
158 /* return block-ack bitmap index given sequence and starting sequence */
159 #define ATH_BA_INDEX(_st, _seq) (((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))
161 /* returns delimiter padding required given the packet length */
162 #define ATH_AGGR_GET_NDELIM(_len) \
163 (((_len) >= ATH_AGGR_MINPLEN) ? 0 : \
164 DIV_ROUND_UP(ATH_AGGR_MINPLEN - (_len), ATH_AGGR_DELIM_SZ))
166 #define BAW_WITHIN(_start, _bawsz, _seqno) \
167 ((((_seqno) - (_start)) & 4095) < (_bawsz))
169 #define ATH_AN_2_TID(_an, _tidno) (&(_an)->tid[(_tidno)])
171 #define ATH_TX_COMPLETE_POLL_INT 1000
173 enum ATH_AGGR_STATUS {
179 #define ATH_TXFIFO_DEPTH 8
181 int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
182 u32 axq_qnum; /* ath9k hardware queue number */
184 struct list_head axq_q;
188 int axq_tx_inprogress;
189 struct list_head axq_acq;
190 struct list_head txq_fifo[ATH_TXFIFO_DEPTH];
191 struct list_head txq_fifo_pending;
200 struct list_head list;
201 struct list_head tid_q;
205 struct ath_frame_info {
208 enum ath9k_key_type keytype;
213 struct ath_buf_state {
216 unsigned long bfs_paprd_timestamp;
220 struct list_head list;
221 struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or
223 struct ath_buf *bf_next; /* next subframe in the aggregate */
224 struct io_buffer *bf_mpdu; /* enclosing frame structure */
225 void *bf_desc; /* virtual addr of desc */
226 u32 bf_daddr; /* physical addr of desc */
227 u32 bf_buf_addr; /* physical addr of data buffer, for DMA */
230 struct ath_buf_state bf_state;
234 struct list_head list;
235 struct list_head buf_q;
237 struct ath_atx_ac *ac;
238 unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
243 int baw_head; /* first un-acked tx buffer */
244 int baw_tail; /* next unused tx buffer slot */
251 struct ath_atx_tid tid[WME_NUM_TID];
252 struct ath_atx_ac ac[WME_NUM_AC];
261 #define AGGR_CLEANUP BIT(1)
262 #define AGGR_ADDBA_COMPLETE BIT(2)
263 #define AGGR_ADDBA_PROGRESS BIT(3)
265 struct ath_tx_control {
272 #define ATH_TX_ERROR 0x01
273 #define ATH_TX_XRETRY 0x02
274 #define ATH_TX_BAR 0x04
277 * @txq_map: Index is mac80211 queue number. This is
278 * not necessarily the same as the hardware queue number
284 struct list_head txbuf;
285 struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
286 struct ath_descdma txdma;
287 struct ath_txq *txq_map[WME_NUM_AC];
291 struct list_head rx_fifo;
292 struct list_head rx_buffers;
300 unsigned int rxfilter;
301 struct list_head rxbuf;
302 struct ath_descdma rxdma;
303 struct ath_buf *rx_bufptr;
304 struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
306 struct io_buffer *frag;
309 int ath_startrecv(struct ath_softc *sc);
310 int ath_stoprecv(struct ath_softc *sc);
311 void ath_flushrecv(struct ath_softc *sc);
312 u32 ath_calcrxfilter(struct ath_softc *sc);
313 int ath_rx_init(struct ath_softc *sc, int nbufs);
314 void ath_rx_cleanup(struct ath_softc *sc);
315 int ath_rx_tasklet(struct ath_softc *sc, int flush, int hp);
316 struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
317 void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
318 int ath_drain_all_txq(struct ath_softc *sc, int retry_tx);
319 void ath_draintxq(struct ath_softc *sc,
320 struct ath_txq *txq, int retry_tx);
321 void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
322 int ath_tx_init(struct ath_softc *sc, int nbufs);
323 void ath_tx_cleanup(struct ath_softc *sc);
324 int ath_txq_update(struct ath_softc *sc, int qnum,
325 struct ath9k_tx_queue_info *q);
326 int ath_tx_start(struct net80211_device *dev, struct io_buffer *iob,
327 struct ath_tx_control *txctl);
328 void ath_tx_tasklet(struct ath_softc *sc);
334 #define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */
335 #define ATH_AP_SHORT_CALINTERVAL 100 /* 100 ms */
336 #define ATH_ANI_POLLINTERVAL_OLD 100 /* 100 ms */
337 #define ATH_ANI_POLLINTERVAL_NEW 1000 /* 1000 ms */
338 #define ATH_LONG_CALINTERVAL_INT 1000 /* 1000 ms */
339 #define ATH_LONG_CALINTERVAL 30000 /* 30 seconds */
340 #define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
342 void ath_hw_pll_work(struct ath_softc *sc);
343 void ath_ani_calibrate(struct ath_softc *sc);
345 /********************/
346 /* Main driver core */
347 /********************/
350 * Default cache line size, in bytes.
351 * Used when PCI device not fully initialized by bootrom/BIOS
353 #define DEFAULT_CACHELINE 32
354 #define ATH_REGCLASSIDS_MAX 10
355 #define ATH_CABQ_READY_TIME 80 /* % of beacon interval */
356 #define ATH_MAX_SW_RETRIES 10
357 #define ATH_CHAN_MAX 255
359 #define ATH_TXPOWER_MAX 100 /* .5 dBm units */
360 #define ATH_RATE_DUMMY_MARKER 0
362 #define SC_OP_INVALID BIT(0)
363 #define SC_OP_BEACONS BIT(1)
364 #define SC_OP_RXAGGR BIT(2)
365 #define SC_OP_TXAGGR BIT(3)
366 #define SC_OP_OFFCHANNEL BIT(4)
367 #define SC_OP_PREAMBLE_SHORT BIT(5)
368 #define SC_OP_PROTECT_ENABLE BIT(6)
369 #define SC_OP_RXFLUSH BIT(7)
370 #define SC_OP_LED_ASSOCIATED BIT(8)
371 #define SC_OP_LED_ON BIT(9)
372 #define SC_OP_TSF_RESET BIT(11)
373 #define SC_OP_BT_PRIORITY_DETECTED BIT(12)
374 #define SC_OP_BT_SCAN BIT(13)
375 #define SC_OP_ANI_RUN BIT(14)
376 #define SC_OP_ENABLE_APM BIT(15)
377 #define SC_OP_PRIM_STA_VIF BIT(16)
379 /* Powersave flags */
380 #define PS_WAIT_FOR_BEACON BIT(0)
381 #define PS_WAIT_FOR_CAB BIT(1)
382 #define PS_WAIT_FOR_PSPOLL_DATA BIT(2)
383 #define PS_WAIT_FOR_TX_ACK BIT(3)
384 #define PS_BEACON_SYNC BIT(4)
385 #define PS_TSFOOR_SYNC BIT(5)
387 struct ath_rate_table;
389 struct ath9k_legacy_rate {
396 enum ath9k_rate_control_flags {
397 IEEE80211_TX_RC_USE_RTS_CTS = BIT(0),
398 IEEE80211_TX_RC_USE_CTS_PROTECT = BIT(1),
399 IEEE80211_TX_RC_USE_SHORT_PREAMBLE = BIT(2),
401 /* rate index is an MCS rate number instead of an index */
402 IEEE80211_TX_RC_MCS = BIT(3),
403 IEEE80211_TX_RC_GREEN_FIELD = BIT(4),
404 IEEE80211_TX_RC_40_MHZ_WIDTH = BIT(5),
405 IEEE80211_TX_RC_DUP_DATA = BIT(6),
406 IEEE80211_TX_RC_SHORT_GI = BIT(7),
410 struct net80211_channel *channel;
412 u64 channel_time_busy;
413 u64 channel_time_ext_busy;
420 enum survey_info_flags {
421 SURVEY_INFO_NOISE_DBM = 1<<0,
422 SURVEY_INFO_IN_USE = 1<<1,
423 SURVEY_INFO_CHANNEL_TIME = 1<<2,
424 SURVEY_INFO_CHANNEL_TIME_BUSY = 1<<3,
425 SURVEY_INFO_CHANNEL_TIME_EXT_BUSY = 1<<4,
426 SURVEY_INFO_CHANNEL_TIME_RX = 1<<5,
427 SURVEY_INFO_CHANNEL_TIME_TX = 1<<6,
430 struct ath9k_vif_iter_data {
431 const u8 *hw_macaddr; /* phy's hardware address, set
432 * before starting iteration for
435 u8 mask[ETH_ALEN]; /* bssid mask */
436 int naps; /* number of AP vifs */
437 int nmeshes; /* number of mesh vifs */
438 int nstations; /* number of station vifs */
439 int nwds; /* number of nwd vifs */
440 int nadhocs; /* number of adhoc vifs */
441 int nothers; /* number of vifs not specified above. */
445 struct net80211_device *dev;
446 struct pci_device *pdev;
450 struct survey_info *cur_survey;
451 struct survey_info survey[ATH9K_NUM_CHANNELS];
453 void (*intr_tq)(struct ath_softc *sc);
454 struct ath_hw *sc_ah;
458 void (*paprd_work)(struct ath_softc *sc);
459 void (*hw_check_work)(struct ath_softc *sc);
460 void (*paprd_complete)(struct ath_softc *sc);
462 unsigned int hw_busy_count;
465 u32 sc_flags; /* SC_OP_* */
466 u16 ps_flags; /* PS_* */
472 unsigned long ps_usecount;
474 struct ath_config config;
477 struct net80211_hw_info *hwinfo;
478 struct ath9k_legacy_rate rates[NET80211_MAX_RATES];
481 struct ath9k_hw_cal_data caldata;
484 void (*tx_complete_work)(struct ath_softc *sc);
485 unsigned long tx_complete_work_timer;
486 void (*hw_pll_work)(struct ath_softc *sc);
487 unsigned long hw_pll_work_timer;
489 struct ath_descdma txsdma;
492 void ath9k_tasklet(struct ath_softc *sc);
493 int ath_reset(struct ath_softc *sc, int retry_tx);
495 static inline void ath_read_cachesize(struct ath_common *common, int *csz)
497 common->bus_ops->read_cachesize(common, csz);
500 extern struct net80211_device_operations ath9k_ops;
501 extern int ath9k_modparam_nohwcrypt;
502 extern int is_ath9k_unloaded;
504 void ath_isr(struct net80211_device *dev);
505 void ath9k_init_crypto(struct ath_softc *sc);
506 int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
507 const struct ath_bus_ops *bus_ops);
508 void ath9k_deinit_device(struct ath_softc *sc);
509 void ath9k_set_hw_capab(struct ath_softc *sc, struct net80211_device *dev);
510 int ath_set_channel(struct ath_softc *sc, struct net80211_device *dev,
511 struct ath9k_channel *hchan);
513 void ath_radio_enable(struct ath_softc *sc, struct net80211_device *dev);
514 void ath_radio_disable(struct ath_softc *sc, struct net80211_device *dev);
515 int ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode);
516 int ath9k_uses_beacons(int type);
518 u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate);
520 void ath_start_rfkill_poll(struct ath_softc *sc);
521 extern void ath9k_rfkill_poll_state(struct net80211_device *dev);