8f59cea33fd6fa5db9830216a2bec32114460e55
[deliverable/linux.git] / drivers / net / wireless / ath / ath9k / ath9k.h
1 /*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef ATH9K_H
18 #define ATH9K_H
19
20 #include <linux/etherdevice.h>
21 #include <linux/device.h>
22 #include <linux/interrupt.h>
23 #include <linux/leds.h>
24 #include <linux/completion.h>
25
26 #include "common.h"
27 #include "debug.h"
28 #include "mci.h"
29 #include "dfs.h"
30 #include "spectral.h"
31
32 struct ath_node;
33
34 extern struct ieee80211_ops ath9k_ops;
35 extern int ath9k_modparam_nohwcrypt;
36 extern int led_blink;
37 extern bool is_ath9k_unloaded;
38
39 /*************************/
40 /* Descriptor Management */
41 /*************************/
42
43 #define ATH_TXSTATUS_RING_SIZE 512
44
45 /* Macro to expand scalars to 64-bit objects */
46 #define ito64(x) (sizeof(x) == 1) ? \
47 (((unsigned long long int)(x)) & (0xff)) : \
48 (sizeof(x) == 2) ? \
49 (((unsigned long long int)(x)) & 0xffff) : \
50 ((sizeof(x) == 4) ? \
51 (((unsigned long long int)(x)) & 0xffffffff) : \
52 (unsigned long long int)(x))
53
54 #define ATH_TXBUF_RESET(_bf) do { \
55 (_bf)->bf_lastbf = NULL; \
56 (_bf)->bf_next = NULL; \
57 memset(&((_bf)->bf_state), 0, \
58 sizeof(struct ath_buf_state)); \
59 } while (0)
60
61 #define DS2PHYS(_dd, _ds) \
62 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
63 #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
64 #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
65
66 struct ath_descdma {
67 void *dd_desc;
68 dma_addr_t dd_desc_paddr;
69 u32 dd_desc_len;
70 };
71
72 int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
73 struct list_head *head, const char *name,
74 int nbuf, int ndesc, bool is_tx);
75
76 /***********/
77 /* RX / TX */
78 /***********/
79
80 #define ATH_TXQ_SETUP(sc, i) ((sc)->tx.txqsetup & (1<<i))
81
82 /* increment with wrap-around */
83 #define INCR(_l, _sz) do { \
84 (_l)++; \
85 (_l) &= ((_sz) - 1); \
86 } while (0)
87
88 #define ATH_RXBUF 512
89 #define ATH_TXBUF 512
90 #define ATH_TXBUF_RESERVE 5
91 #define ATH_MAX_QDEPTH (ATH_TXBUF / 4 - ATH_TXBUF_RESERVE)
92 #define ATH_TXMAXTRY 13
93 #define ATH_MAX_SW_RETRIES 30
94
95 #define TID_TO_WME_AC(_tid) \
96 ((((_tid) == 0) || ((_tid) == 3)) ? IEEE80211_AC_BE : \
97 (((_tid) == 1) || ((_tid) == 2)) ? IEEE80211_AC_BK : \
98 (((_tid) == 4) || ((_tid) == 5)) ? IEEE80211_AC_VI : \
99 IEEE80211_AC_VO)
100
101 #define ATH_AGGR_DELIM_SZ 4
102 #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */
103 /* number of delimiters for encryption padding */
104 #define ATH_AGGR_ENCRYPTDELIM 10
105 /* minimum h/w qdepth to be sustained to maximize aggregation */
106 #define ATH_AGGR_MIN_QDEPTH 2
107 /* minimum h/w qdepth for non-aggregated traffic */
108 #define ATH_NON_AGGR_MIN_QDEPTH 8
109 #define ATH_TX_COMPLETE_POLL_INT 1000
110 #define ATH_TXFIFO_DEPTH 8
111 #define ATH_TX_ERROR 0x01
112
113 /* Stop tx traffic 1ms before the GO goes away */
114 #define ATH_P2P_PS_STOP_TIME 1000
115
116 #define IEEE80211_SEQ_SEQ_SHIFT 4
117 #define IEEE80211_SEQ_MAX 4096
118 #define IEEE80211_WEP_IVLEN 3
119 #define IEEE80211_WEP_KIDLEN 1
120 #define IEEE80211_WEP_CRCLEN 4
121 #define IEEE80211_MAX_MPDU_LEN (3840 + FCS_LEN + \
122 (IEEE80211_WEP_IVLEN + \
123 IEEE80211_WEP_KIDLEN + \
124 IEEE80211_WEP_CRCLEN))
125
126 /* return whether a bit at index _n in bitmap _bm is set
127 * _sz is the size of the bitmap */
128 #define ATH_BA_ISSET(_bm, _n) (((_n) < (WME_BA_BMP_SIZE)) && \
129 ((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))
130
131 /* return block-ack bitmap index given sequence and starting sequence */
132 #define ATH_BA_INDEX(_st, _seq) (((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))
133
134 /* return the seqno for _start + _offset */
135 #define ATH_BA_INDEX2SEQ(_seq, _offset) (((_seq) + (_offset)) & (IEEE80211_SEQ_MAX - 1))
136
137 /* returns delimiter padding required given the packet length */
138 #define ATH_AGGR_GET_NDELIM(_len) \
139 (((_len) >= ATH_AGGR_MINPLEN) ? 0 : \
140 DIV_ROUND_UP(ATH_AGGR_MINPLEN - (_len), ATH_AGGR_DELIM_SZ))
141
142 #define BAW_WITHIN(_start, _bawsz, _seqno) \
143 ((((_seqno) - (_start)) & 4095) < (_bawsz))
144
145 #define ATH_AN_2_TID(_an, _tidno) (&(_an)->tid[(_tidno)])
146
147 #define IS_HT_RATE(rate) (rate & 0x80)
148 #define IS_CCK_RATE(rate) ((rate >= 0x18) && (rate <= 0x1e))
149 #define IS_OFDM_RATE(rate) ((rate >= 0x8) && (rate <= 0xf))
150
151 enum {
152 WLAN_RC_PHY_OFDM,
153 WLAN_RC_PHY_CCK,
154 };
155
156 struct ath_txq {
157 int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
158 u32 axq_qnum; /* ath9k hardware queue number */
159 void *axq_link;
160 struct list_head axq_q;
161 spinlock_t axq_lock;
162 u32 axq_depth;
163 u32 axq_ampdu_depth;
164 bool stopped;
165 bool axq_tx_inprogress;
166 struct list_head txq_fifo[ATH_TXFIFO_DEPTH];
167 u8 txq_headidx;
168 u8 txq_tailidx;
169 int pending_frames;
170 struct sk_buff_head complete_q;
171 };
172
173 struct ath_atx_ac {
174 struct ath_txq *txq;
175 struct list_head list;
176 struct list_head tid_q;
177 bool clear_ps_filter;
178 bool sched;
179 };
180
181 struct ath_frame_info {
182 struct ath_buf *bf;
183 int framelen;
184 enum ath9k_key_type keytype;
185 u8 keyix;
186 u8 rtscts_rate;
187 u8 retries : 7;
188 u8 baw_tracked : 1;
189 };
190
191 struct ath_rxbuf {
192 struct list_head list;
193 struct sk_buff *bf_mpdu;
194 void *bf_desc;
195 dma_addr_t bf_daddr;
196 dma_addr_t bf_buf_addr;
197 };
198
199 /**
200 * enum buffer_type - Buffer type flags
201 *
202 * @BUF_AMPDU: This buffer is an ampdu, as part of an aggregate (during TX)
203 * @BUF_AGGR: Indicates whether the buffer can be aggregated
204 * (used in aggregation scheduling)
205 */
206 enum buffer_type {
207 BUF_AMPDU = BIT(0),
208 BUF_AGGR = BIT(1),
209 };
210
211 #define bf_isampdu(bf) (bf->bf_state.bf_type & BUF_AMPDU)
212 #define bf_isaggr(bf) (bf->bf_state.bf_type & BUF_AGGR)
213
214 struct ath_buf_state {
215 u8 bf_type;
216 u8 bfs_paprd;
217 u8 ndelim;
218 bool stale;
219 u16 seqno;
220 unsigned long bfs_paprd_timestamp;
221 };
222
223 struct ath_buf {
224 struct list_head list;
225 struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or
226 an aggregate) */
227 struct ath_buf *bf_next; /* next subframe in the aggregate */
228 struct sk_buff *bf_mpdu; /* enclosing frame structure */
229 void *bf_desc; /* virtual addr of desc */
230 dma_addr_t bf_daddr; /* physical addr of desc */
231 dma_addr_t bf_buf_addr; /* physical addr of data buffer, for DMA */
232 struct ieee80211_tx_rate rates[4];
233 struct ath_buf_state bf_state;
234 };
235
236 struct ath_atx_tid {
237 struct list_head list;
238 struct sk_buff_head buf_q;
239 struct sk_buff_head retry_q;
240 struct ath_node *an;
241 struct ath_atx_ac *ac;
242 unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
243 u16 seq_start;
244 u16 seq_next;
245 u16 baw_size;
246 u8 tidno;
247 int baw_head; /* first un-acked tx buffer */
248 int baw_tail; /* next unused tx buffer slot */
249
250 s8 bar_index;
251 bool sched;
252 bool active;
253 };
254
255 struct ath_node {
256 struct ath_softc *sc;
257 struct ieee80211_sta *sta; /* station struct we're part of */
258 struct ieee80211_vif *vif; /* interface with which we're associated */
259 struct ath_atx_tid tid[IEEE80211_NUM_TIDS];
260 struct ath_atx_ac ac[IEEE80211_NUM_ACS];
261
262 u16 maxampdu;
263 u8 mpdudensity;
264 s8 ps_key;
265
266 bool sleeping;
267 bool no_ps_filter;
268
269 #ifdef CONFIG_ATH9K_STATION_STATISTICS
270 struct ath_rx_rate_stats rx_rate_stats;
271 #endif
272 u8 key_idx[4];
273 };
274
275 struct ath_tx_control {
276 struct ath_txq *txq;
277 struct ath_node *an;
278 u8 paprd;
279 struct ieee80211_sta *sta;
280 };
281
282
283 /**
284 * @txq_map: Index is mac80211 queue number. This is
285 * not necessarily the same as the hardware queue number
286 * (axq_qnum).
287 */
288 struct ath_tx {
289 u16 seq_no;
290 u32 txqsetup;
291 spinlock_t txbuflock;
292 struct list_head txbuf;
293 struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
294 struct ath_descdma txdma;
295 struct ath_txq *txq_map[IEEE80211_NUM_ACS];
296 struct ath_txq *uapsdq;
297 u32 txq_max_pending[IEEE80211_NUM_ACS];
298 u16 max_aggr_framelen[IEEE80211_NUM_ACS][4][32];
299 };
300
301 struct ath_rx_edma {
302 struct sk_buff_head rx_fifo;
303 u32 rx_fifo_hwsize;
304 };
305
306 struct ath_rx {
307 u8 defant;
308 u8 rxotherant;
309 bool discard_next;
310 u32 *rxlink;
311 u32 num_pkts;
312 unsigned int rxfilter;
313 struct list_head rxbuf;
314 struct ath_descdma rxdma;
315 struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
316
317 struct ath_rxbuf *buf_hold;
318 struct sk_buff *frag;
319
320 u32 ampdu_ref;
321 };
322
323 struct ath_chanctx {
324 struct cfg80211_chan_def chandef;
325 struct list_head vifs;
326 struct list_head acq[IEEE80211_NUM_ACS];
327
328 u16 txpower;
329 bool offchannel;
330 bool stopped;
331 };
332
333 void ath_chanctx_init(struct ath_softc *sc);
334 void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx,
335 struct cfg80211_chan_def *chandef);
336 void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx,
337 struct cfg80211_chan_def *chandef);
338 int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan);
339 int ath_startrecv(struct ath_softc *sc);
340 bool ath_stoprecv(struct ath_softc *sc);
341 u32 ath_calcrxfilter(struct ath_softc *sc);
342 int ath_rx_init(struct ath_softc *sc, int nbufs);
343 void ath_rx_cleanup(struct ath_softc *sc);
344 int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp);
345 struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
346 void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq);
347 void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq);
348 void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq);
349 void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
350 bool ath_drain_all_txq(struct ath_softc *sc);
351 void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq);
352 void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
353 void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
354 void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
355 void ath_txq_schedule_all(struct ath_softc *sc);
356 int ath_tx_init(struct ath_softc *sc, int nbufs);
357 int ath_txq_update(struct ath_softc *sc, int qnum,
358 struct ath9k_tx_queue_info *q);
359 void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop);
360 int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
361 struct ath_tx_control *txctl);
362 void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
363 struct sk_buff *skb);
364 void ath_tx_tasklet(struct ath_softc *sc);
365 void ath_tx_edma_tasklet(struct ath_softc *sc);
366 int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
367 u16 tid, u16 *ssn);
368 void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
369 void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
370
371 void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
372 void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
373 struct ath_node *an);
374 void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
375 struct ieee80211_sta *sta,
376 u16 tids, int nframes,
377 enum ieee80211_frame_release_type reason,
378 bool more_data);
379
380 /********/
381 /* VIFs */
382 /********/
383
384 struct ath_vif {
385 struct list_head list;
386
387 struct ieee80211_vif *vif;
388 struct ath_node mcast_node;
389 int av_bslot;
390 bool primary_sta_vif;
391 __le64 tsf_adjust; /* TSF adjustment for staggered beacons */
392 struct ath_buf *av_bcbuf;
393 struct ath_chanctx *chanctx;
394
395 /* P2P Client */
396 struct ieee80211_noa_data noa;
397 };
398
399 struct ath9k_vif_iter_data {
400 u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
401 u8 mask[ETH_ALEN]; /* bssid mask */
402 bool has_hw_macaddr;
403
404 int naps; /* number of AP vifs */
405 int nmeshes; /* number of mesh vifs */
406 int nstations; /* number of station vifs */
407 int nwds; /* number of WDS vifs */
408 int nadhocs; /* number of adhoc vifs */
409 };
410
411 void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
412 struct ieee80211_vif *vif,
413 struct ath9k_vif_iter_data *iter_data);
414
415 /*******************/
416 /* Beacon Handling */
417 /*******************/
418
419 /*
420 * Regardless of the number of beacons we stagger, (i.e. regardless of the
421 * number of BSSIDs) if a given beacon does not go out even after waiting this
422 * number of beacon intervals, the game's up.
423 */
424 #define BSTUCK_THRESH 9
425 #define ATH_BCBUF 8
426 #define ATH_DEFAULT_BINTVAL 100 /* TU */
427 #define ATH_DEFAULT_BMISS_LIMIT 10
428
429 #define TSF_TO_TU(_h,_l) \
430 ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
431
432 struct ath_beacon {
433 enum {
434 OK, /* no change needed */
435 UPDATE, /* update pending */
436 COMMIT /* beacon sent, commit change */
437 } updateslot; /* slot time update fsm */
438
439 u32 beaconq;
440 u32 bmisscnt;
441 struct ieee80211_vif *bslot[ATH_BCBUF];
442 int slottime;
443 int slotupdate;
444 struct ath_descdma bdma;
445 struct ath_txq *cabq;
446 struct list_head bbuf;
447
448 bool tx_processed;
449 bool tx_last;
450 };
451
452 void ath9k_beacon_tasklet(unsigned long data);
453 void ath9k_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif,
454 u32 changed);
455 void ath9k_beacon_assign_slot(struct ath_softc *sc, struct ieee80211_vif *vif);
456 void ath9k_beacon_remove_slot(struct ath_softc *sc, struct ieee80211_vif *vif);
457 void ath9k_set_beacon(struct ath_softc *sc);
458 bool ath9k_csa_is_finished(struct ath_softc *sc, struct ieee80211_vif *vif);
459 void ath9k_csa_update(struct ath_softc *sc);
460
461 /*******************/
462 /* Link Monitoring */
463 /*******************/
464
465 #define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */
466 #define ATH_AP_SHORT_CALINTERVAL 100 /* 100 ms */
467 #define ATH_ANI_POLLINTERVAL_OLD 100 /* 100 ms */
468 #define ATH_ANI_POLLINTERVAL_NEW 1000 /* 1000 ms */
469 #define ATH_LONG_CALINTERVAL_INT 1000 /* 1000 ms */
470 #define ATH_LONG_CALINTERVAL 30000 /* 30 seconds */
471 #define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
472 #define ATH_ANI_MAX_SKIP_COUNT 10
473 #define ATH_PAPRD_TIMEOUT 100 /* msecs */
474 #define ATH_PLL_WORK_INTERVAL 100
475
476 void ath_chanctx_work(struct work_struct *work);
477 void ath_tx_complete_poll_work(struct work_struct *work);
478 void ath_reset_work(struct work_struct *work);
479 bool ath_hw_check(struct ath_softc *sc);
480 void ath_hw_pll_work(struct work_struct *work);
481 void ath_paprd_calibrate(struct work_struct *work);
482 void ath_ani_calibrate(unsigned long data);
483 void ath_start_ani(struct ath_softc *sc);
484 void ath_stop_ani(struct ath_softc *sc);
485 void ath_check_ani(struct ath_softc *sc);
486 int ath_update_survey_stats(struct ath_softc *sc);
487 void ath_update_survey_nf(struct ath_softc *sc, int channel);
488 void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
489 void ath_ps_full_sleep(unsigned long data);
490 void ath9k_p2p_ps_timer(void *priv);
491 void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif);
492 void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop);
493
494 /**********/
495 /* BTCOEX */
496 /**********/
497
498 #define ATH_DUMP_BTCOEX(_s, _val) \
499 do { \
500 len += scnprintf(buf + len, size - len, \
501 "%20s : %10d\n", _s, (_val)); \
502 } while (0)
503
504 enum bt_op_flags {
505 BT_OP_PRIORITY_DETECTED,
506 BT_OP_SCAN,
507 };
508
509 struct ath_btcoex {
510 spinlock_t btcoex_lock;
511 struct timer_list period_timer; /* Timer for BT period */
512 struct timer_list no_stomp_timer;
513 u32 bt_priority_cnt;
514 unsigned long bt_priority_time;
515 unsigned long op_flags;
516 int bt_stomp_type; /* Types of BT stomping */
517 u32 btcoex_no_stomp; /* in msec */
518 u32 btcoex_period; /* in msec */
519 u32 btscan_no_stomp; /* in msec */
520 u32 duty_cycle;
521 u32 bt_wait_time;
522 int rssi_count;
523 struct ath_mci_profile mci;
524 u8 stomp_audio;
525 };
526
527 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
528 int ath9k_init_btcoex(struct ath_softc *sc);
529 void ath9k_deinit_btcoex(struct ath_softc *sc);
530 void ath9k_start_btcoex(struct ath_softc *sc);
531 void ath9k_stop_btcoex(struct ath_softc *sc);
532 void ath9k_btcoex_timer_resume(struct ath_softc *sc);
533 void ath9k_btcoex_timer_pause(struct ath_softc *sc);
534 void ath9k_btcoex_handle_interrupt(struct ath_softc *sc, u32 status);
535 u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen);
536 void ath9k_btcoex_stop_gen_timer(struct ath_softc *sc);
537 int ath9k_dump_btcoex(struct ath_softc *sc, u8 *buf, u32 size);
538 #else
539 static inline int ath9k_init_btcoex(struct ath_softc *sc)
540 {
541 return 0;
542 }
543 static inline void ath9k_deinit_btcoex(struct ath_softc *sc)
544 {
545 }
546 static inline void ath9k_start_btcoex(struct ath_softc *sc)
547 {
548 }
549 static inline void ath9k_stop_btcoex(struct ath_softc *sc)
550 {
551 }
552 static inline void ath9k_btcoex_handle_interrupt(struct ath_softc *sc,
553 u32 status)
554 {
555 }
556 static inline u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc,
557 u32 max_4ms_framelen)
558 {
559 return 0;
560 }
561 static inline void ath9k_btcoex_stop_gen_timer(struct ath_softc *sc)
562 {
563 }
564 static inline int ath9k_dump_btcoex(struct ath_softc *sc, u8 *buf, u32 size)
565 {
566 return 0;
567 }
568 #endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
569
570 /********************/
571 /* LED Control */
572 /********************/
573
574 #define ATH_LED_PIN_DEF 1
575 #define ATH_LED_PIN_9287 8
576 #define ATH_LED_PIN_9300 10
577 #define ATH_LED_PIN_9485 6
578 #define ATH_LED_PIN_9462 4
579
580 #ifdef CONFIG_MAC80211_LEDS
581 void ath_init_leds(struct ath_softc *sc);
582 void ath_deinit_leds(struct ath_softc *sc);
583 void ath_fill_led_pin(struct ath_softc *sc);
584 #else
585 static inline void ath_init_leds(struct ath_softc *sc)
586 {
587 }
588
589 static inline void ath_deinit_leds(struct ath_softc *sc)
590 {
591 }
592 static inline void ath_fill_led_pin(struct ath_softc *sc)
593 {
594 }
595 #endif
596
597 /************************/
598 /* Wake on Wireless LAN */
599 /************************/
600
601 struct ath9k_wow_pattern {
602 u8 pattern_bytes[MAX_PATTERN_SIZE];
603 u8 mask_bytes[MAX_PATTERN_SIZE];
604 u32 pattern_len;
605 };
606
607 #ifdef CONFIG_ATH9K_WOW
608 void ath9k_init_wow(struct ieee80211_hw *hw);
609 int ath9k_suspend(struct ieee80211_hw *hw,
610 struct cfg80211_wowlan *wowlan);
611 int ath9k_resume(struct ieee80211_hw *hw);
612 void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled);
613 #else
614 static inline void ath9k_init_wow(struct ieee80211_hw *hw)
615 {
616 }
617 static inline int ath9k_suspend(struct ieee80211_hw *hw,
618 struct cfg80211_wowlan *wowlan)
619 {
620 return 0;
621 }
622 static inline int ath9k_resume(struct ieee80211_hw *hw)
623 {
624 return 0;
625 }
626 static inline void ath9k_set_wakeup(struct ieee80211_hw *hw, bool enabled)
627 {
628 }
629 #endif /* CONFIG_ATH9K_WOW */
630
631 /*******************************/
632 /* Antenna diversity/combining */
633 /*******************************/
634
635 #define ATH_ANT_RX_CURRENT_SHIFT 4
636 #define ATH_ANT_RX_MAIN_SHIFT 2
637 #define ATH_ANT_RX_MASK 0x3
638
639 #define ATH_ANT_DIV_COMB_SHORT_SCAN_INTR 50
640 #define ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT 0x100
641 #define ATH_ANT_DIV_COMB_MAX_PKTCOUNT 0x200
642 #define ATH_ANT_DIV_COMB_INIT_COUNT 95
643 #define ATH_ANT_DIV_COMB_MAX_COUNT 100
644 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO 30
645 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2 20
646 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI 50
647 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI 50
648
649 #define ATH_ANT_DIV_COMB_LNA1_DELTA_HI -4
650 #define ATH_ANT_DIV_COMB_LNA1_DELTA_MID -2
651 #define ATH_ANT_DIV_COMB_LNA1_DELTA_LOW 2
652
653 struct ath_ant_comb {
654 u16 count;
655 u16 total_pkt_count;
656 bool scan;
657 bool scan_not_start;
658 int main_total_rssi;
659 int alt_total_rssi;
660 int alt_recv_cnt;
661 int main_recv_cnt;
662 int rssi_lna1;
663 int rssi_lna2;
664 int rssi_add;
665 int rssi_sub;
666 int rssi_first;
667 int rssi_second;
668 int rssi_third;
669 int ant_ratio;
670 int ant_ratio2;
671 bool alt_good;
672 int quick_scan_cnt;
673 enum ath9k_ant_div_comb_lna_conf main_conf;
674 enum ath9k_ant_div_comb_lna_conf first_quick_scan_conf;
675 enum ath9k_ant_div_comb_lna_conf second_quick_scan_conf;
676 bool first_ratio;
677 bool second_ratio;
678 unsigned long scan_start_time;
679
680 /*
681 * Card-specific config values.
682 */
683 int low_rssi_thresh;
684 int fast_div_bias;
685 };
686
687 void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
688
689 /********************/
690 /* Main driver core */
691 /********************/
692
693 #define ATH9K_PCI_CUS198 0x0001
694 #define ATH9K_PCI_CUS230 0x0002
695 #define ATH9K_PCI_CUS217 0x0004
696 #define ATH9K_PCI_CUS252 0x0008
697 #define ATH9K_PCI_WOW 0x0010
698 #define ATH9K_PCI_BT_ANT_DIV 0x0020
699 #define ATH9K_PCI_D3_L1_WAR 0x0040
700 #define ATH9K_PCI_AR9565_1ANT 0x0080
701 #define ATH9K_PCI_AR9565_2ANT 0x0100
702 #define ATH9K_PCI_NO_PLL_PWRSAVE 0x0200
703 #define ATH9K_PCI_KILLER 0x0400
704
705 /*
706 * Default cache line size, in bytes.
707 * Used when PCI device not fully initialized by bootrom/BIOS
708 */
709 #define DEFAULT_CACHELINE 32
710 #define ATH_CABQ_READY_TIME 80 /* % of beacon interval */
711 #define ATH_TXPOWER_MAX 100 /* .5 dBm units */
712 #define MAX_GTT_CNT 5
713
714 /* Powersave flags */
715 #define PS_WAIT_FOR_BEACON BIT(0)
716 #define PS_WAIT_FOR_CAB BIT(1)
717 #define PS_WAIT_FOR_PSPOLL_DATA BIT(2)
718 #define PS_WAIT_FOR_TX_ACK BIT(3)
719 #define PS_BEACON_SYNC BIT(4)
720 #define PS_WAIT_FOR_ANI BIT(5)
721
722 #define ATH9K_NUM_CHANCTX 2 /* supports 2 operating channels */
723
724 struct ath_softc {
725 struct ieee80211_hw *hw;
726 struct device *dev;
727
728 struct survey_info *cur_survey;
729 struct survey_info survey[ATH9K_NUM_CHANNELS];
730
731 struct tasklet_struct intr_tq;
732 struct tasklet_struct bcon_tasklet;
733 struct ath_hw *sc_ah;
734 void __iomem *mem;
735 int irq;
736 spinlock_t sc_serial_rw;
737 spinlock_t sc_pm_lock;
738 spinlock_t sc_pcu_lock;
739 struct mutex mutex;
740 struct work_struct paprd_work;
741 struct work_struct hw_reset_work;
742 struct work_struct chanctx_work;
743 struct completion paprd_complete;
744 wait_queue_head_t tx_wait;
745
746 struct ath_gen_timer *p2p_ps_timer;
747 struct ath_vif *p2p_ps_vif;
748
749 unsigned long driver_data;
750
751 u8 gtt_cnt;
752 u32 intrstatus;
753 u16 ps_flags; /* PS_* */
754 u16 curtxpow;
755 bool ps_enabled;
756 bool ps_idle;
757 short nbcnvifs;
758 short nvifs;
759 unsigned long ps_usecount;
760
761 struct ath_rx rx;
762 struct ath_tx tx;
763 struct ath_beacon beacon;
764
765 struct cfg80211_chan_def cur_chandef;
766 struct ath_chanctx chanctx[ATH9K_NUM_CHANCTX];
767 struct ath_chanctx *cur_chan;
768 struct ath_chanctx *next_chan;
769 spinlock_t chan_lock;
770
771 #ifdef CONFIG_MAC80211_LEDS
772 bool led_registered;
773 char led_name[32];
774 struct led_classdev led_cdev;
775 #endif
776
777 struct ath9k_hw_cal_data caldata;
778
779 #ifdef CONFIG_ATH9K_DEBUGFS
780 struct ath9k_debug debug;
781 #endif
782 struct ath_beacon_config cur_beacon_conf;
783 struct delayed_work tx_complete_work;
784 struct delayed_work hw_pll_work;
785 struct timer_list sleep_timer;
786
787 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
788 struct ath_btcoex btcoex;
789 struct ath_mci_coex mci_coex;
790 struct work_struct mci_work;
791 #endif
792
793 struct ath_descdma txsdma;
794
795 struct ath_ant_comb ant_comb;
796 u8 ant_tx, ant_rx;
797 struct dfs_pattern_detector *dfs_detector;
798 u64 dfs_prev_pulse_ts;
799 u32 wow_enabled;
800 /* relay(fs) channel for spectral scan */
801 struct rchan *rfs_chan_spec_scan;
802 enum spectral_mode spectral_mode;
803 struct ath_spec_scan spec_config;
804
805 struct ieee80211_vif *tx99_vif;
806 struct sk_buff *tx99_skb;
807 bool tx99_state;
808 s16 tx99_power;
809
810 #ifdef CONFIG_ATH9K_WOW
811 atomic_t wow_got_bmiss_intr;
812 atomic_t wow_sleep_proc_intr; /* in the middle of WoW sleep ? */
813 u32 wow_intr_before_sleep;
814 #endif
815 };
816
817 /********/
818 /* TX99 */
819 /********/
820
821 #ifdef CONFIG_ATH9K_TX99
822 void ath9k_tx99_init_debug(struct ath_softc *sc);
823 int ath9k_tx99_send(struct ath_softc *sc, struct sk_buff *skb,
824 struct ath_tx_control *txctl);
825 #else
826 static inline void ath9k_tx99_init_debug(struct ath_softc *sc)
827 {
828 }
829 static inline int ath9k_tx99_send(struct ath_softc *sc,
830 struct sk_buff *skb,
831 struct ath_tx_control *txctl)
832 {
833 return 0;
834 }
835 #endif /* CONFIG_ATH9K_TX99 */
836
837 static inline void ath_read_cachesize(struct ath_common *common, int *csz)
838 {
839 common->bus_ops->read_cachesize(common, csz);
840 }
841
842 void ath9k_tasklet(unsigned long data);
843 int ath_cabq_update(struct ath_softc *);
844 u8 ath9k_parse_mpdudensity(u8 mpdudensity);
845 irqreturn_t ath_isr(int irq, void *dev);
846 int ath_reset(struct ath_softc *sc);
847 void ath_cancel_work(struct ath_softc *sc);
848 void ath_restart_work(struct ath_softc *sc);
849 int ath9k_init_device(u16 devid, struct ath_softc *sc,
850 const struct ath_bus_ops *bus_ops);
851 void ath9k_deinit_device(struct ath_softc *sc);
852 void ath9k_reload_chainmask_settings(struct ath_softc *sc);
853 u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate);
854 void ath_start_rfkill_poll(struct ath_softc *sc);
855 void ath9k_rfkill_poll_state(struct ieee80211_hw *hw);
856 void ath9k_ps_wakeup(struct ath_softc *sc);
857 void ath9k_ps_restore(struct ath_softc *sc);
858
859 #ifdef CONFIG_ATH9K_PCI
860 int ath_pci_init(void);
861 void ath_pci_exit(void);
862 #else
863 static inline int ath_pci_init(void) { return 0; };
864 static inline void ath_pci_exit(void) {};
865 #endif
866
867 #ifdef CONFIG_ATH9K_AHB
868 int ath_ahb_init(void);
869 void ath_ahb_exit(void);
870 #else
871 static inline int ath_ahb_init(void) { return 0; };
872 static inline void ath_ahb_exit(void) {};
873 #endif
874
875 #endif /* ATH9K_H */
This page took 0.050125 seconds and 4 git commands to generate.