core.h 20.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (c) 2008 Atheros Communications Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef CORE_H
#define CORE_H

#include <linux/etherdevice.h>
#include <linux/pci.h>
#include <net/mac80211.h>
23
#include <linux/leds.h>
24
#include <linux/rfkill.h>
25 26 27 28 29 30 31 32

#include "ath9k.h"
#include "rc.h"

struct ath_node;

/* Macro to expand scalars to 64-bit objects */

33 34 35 36 37
#define	ito64(x) (sizeof(x) == 8) ?			\
	(((unsigned long long int)(x)) & (0xff)) :	\
	(sizeof(x) == 16) ?				\
	(((unsigned long long int)(x)) & 0xffff) :	\
	((sizeof(x) == 32) ?				\
38
	 (((unsigned long long int)(x)) & 0xffffffff) : \
39
	 (unsigned long long int)(x))
40 41

/* increment with wrap-around */
42 43 44
#define INCR(_l, _sz)   do {			\
		(_l)++;				\
		(_l) &= ((_sz) - 1);		\
45 46 47
	} while (0)

/* decrement with wrap-around */
48 49 50
#define DECR(_l,  _sz)  do {			\
		(_l)--;				\
		(_l) &= ((_sz) - 1);		\
51 52 53 54 55 56 57 58 59 60
	} while (0)

#define A_MAX(a, b) ((a) > (b) ? (a) : (b))

#define ASSERT(exp) do {			\
		if (unlikely(!(exp))) {		\
			BUG();			\
		}				\
	} while (0)

61 62 63
#define TSF_TO_TU(_h,_l) \
	((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))

64 65
#define	ATH_TXQ_SETUP(sc, i)        ((sc)->sc_txqsetup & (1<<i))

S
Sujith 已提交
66 67
static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};

68 69
enum ATH_DEBUG {
	ATH_DBG_RESET		= 0x00000001,
S
Sujith 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83
	ATH_DBG_REG_IO		= 0x00000002,
	ATH_DBG_QUEUE		= 0x00000004,
	ATH_DBG_EEPROM		= 0x00000008,
	ATH_DBG_CALIBRATE	= 0x00000010,
	ATH_DBG_CHANNEL		= 0x00000020,
	ATH_DBG_INTERRUPT	= 0x00000040,
	ATH_DBG_REGULATORY	= 0x00000080,
	ATH_DBG_ANI		= 0x00000100,
	ATH_DBG_POWER_MGMT	= 0x00000200,
	ATH_DBG_XMIT		= 0x00000400,
	ATH_DBG_BEACON		= 0x00001000,
	ATH_DBG_CONFIG		= 0x00002000,
	ATH_DBG_KEYCACHE	= 0x00004000,
	ATH_DBG_FATAL		= 0x00008000,
84 85 86 87 88
	ATH_DBG_ANY		= 0xffffffff
};

#define DBG_DEFAULT (ATH_DBG_FATAL)

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#ifdef CONFIG_ATH9K_DEBUG

void DPRINTF(struct ath_softc *sc, int dbg_mask, const char *fmt, ...);
void ath9k_init_debug(struct ath_softc *sc);

#else

static inline void DPRINTF(struct ath_softc *sc, int dbg_mask,
			   const char *fmt, ...)
{
}

static inline ath9k_init_debug(struct ath_softc *sc)
{
}

#endif

107
struct ath_config {
108 109 110
	u32 ath_aggr_prot;
	u16 txpowlimit;
	u16 txpowlimit_override;
S
Sujith 已提交
111 112
	u8 cabqReadytime;
	u8 swBeaconProcess;
113 114 115 116 117 118 119 120 121 122 123
};

/*************************/
/* Descriptor Management */
/*************************/

#define ATH_TXBUF_RESET(_bf) do {				\
		(_bf)->bf_status = 0;				\
		(_bf)->bf_lastbf = NULL;			\
		(_bf)->bf_lastfrm = NULL;			\
		(_bf)->bf_next = NULL;				\
124
		memset(&((_bf)->bf_state), 0,			\
125 126 127
			    sizeof(struct ath_buf_state));	\
	} while (0)

S
Sujith 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141
enum buffer_type {
	BUF_DATA		= BIT(0),
	BUF_AGGR		= BIT(1),
	BUF_AMPDU		= BIT(2),
	BUF_HT			= BIT(3),
	BUF_RETRY		= BIT(4),
	BUF_XRETRY		= BIT(5),
	BUF_SHORT_PREAMBLE	= BIT(6),
	BUF_BAR			= BIT(7),
	BUF_PSPOLL		= BIT(8),
	BUF_AGGR_BURST		= BIT(9),
	BUF_CALC_AIRTIME	= BIT(10),
};

142
struct ath_buf_state {
S
Sujith 已提交
143 144 145 146 147 148 149
	int bfs_nframes;		/* # frames in aggregate */
	u16 bfs_al;			/* length of aggregate */
	u16 bfs_frmlen;			/* length of frame */
	int bfs_seqno;			/* sequence number */
	int bfs_tidno;			/* tid of this frame */
	int bfs_retries;		/* current retries */
	u32 bf_type;			/* BUF_* (enum buffer_type) */
S
Sujith 已提交
150
	u32 bfs_keyix;
151 152 153 154 155 156 157 158 159 160
	enum ath9k_key_type bfs_keytype;
};

#define bf_nframes      	bf_state.bfs_nframes
#define bf_al           	bf_state.bfs_al
#define bf_frmlen       	bf_state.bfs_frmlen
#define bf_retries      	bf_state.bfs_retries
#define bf_seqno        	bf_state.bfs_seqno
#define bf_tidno        	bf_state.bfs_tidno
#define bf_rcs          	bf_state.bfs_rcs
S
Sujith 已提交
161
#define bf_keyix                bf_state.bfs_keyix
162
#define bf_keytype      	bf_state.bfs_keytype
S
Sujith 已提交
163 164 165 166 167 168 169 170 171 172
#define bf_isdata(bf)		(bf->bf_state.bf_type & BUF_DATA)
#define bf_isaggr(bf)		(bf->bf_state.bf_type & BUF_AGGR)
#define bf_isampdu(bf)		(bf->bf_state.bf_type & BUF_AMPDU)
#define bf_isht(bf)		(bf->bf_state.bf_type & BUF_HT)
#define bf_isretried(bf)	(bf->bf_state.bf_type & BUF_RETRY)
#define bf_isxretried(bf)	(bf->bf_state.bf_type & BUF_XRETRY)
#define bf_isshpreamble(bf)	(bf->bf_state.bf_type & BUF_SHORT_PREAMBLE)
#define bf_isbar(bf)		(bf->bf_state.bf_type & BUF_BAR)
#define bf_ispspoll(bf) 	(bf->bf_state.bf_type & BUF_PSPOLL)
#define bf_isaggrburst(bf)	(bf->bf_state.bf_type & BUF_AGGR_BURST)
173 174 175 176 177 178 179 180 181

/*
 * Abstraction of a contiguous buffer to transmit/receive.  There is only
 * a single hw descriptor encapsulated here.
 */
struct ath_buf {
	struct list_head list;
	struct list_head *last;
	struct ath_buf *bf_lastbf;	/* last buf of this unit (a frame or
182
					   an aggregate) */
183 184 185 186 187 188 189
	struct ath_buf *bf_lastfrm;	/* last buf of this frame */
	struct ath_buf *bf_next;	/* next subframe in the aggregate */
	void *bf_mpdu;			/* enclosing frame structure */
	struct ath_desc *bf_desc;	/* virtual addr of desc */
	dma_addr_t bf_daddr;		/* physical addr of desc */
	dma_addr_t bf_buf_addr;		/* physical addr of data buffer */
	u32 bf_status;
190
	u16 bf_flags;			/* tx descriptor flags */
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	struct ath_buf_state bf_state;	/* buffer state */
	dma_addr_t bf_dmacontext;
};

#define ATH_RXBUF_RESET(_bf)    ((_bf)->bf_status = 0)

/* hw processing complete, desc processed by hal */
#define ATH_BUFSTATUS_DONE      0x00000001
/* hw processing complete, desc hold for hw */
#define ATH_BUFSTATUS_STALE     0x00000002
/* Rx-only: OS is done with this packet and it's ok to queued it to hw */
#define ATH_BUFSTATUS_FREE      0x00000004

/* DMA state for tx/rx descriptors */

struct ath_descdma {
	const char *dd_name;
	struct ath_desc *dd_desc;	/* descriptors  */
	dma_addr_t dd_desc_paddr;	/* physical addr of dd_desc  */
	u32 dd_desc_len;		/* size of dd_desc  */
	struct ath_buf *dd_bufptr;	/* associated buffers */
	dma_addr_t dd_dmacontext;
};

S
Sujith 已提交
215 216 217 218
int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
		      struct list_head *head, const char *name,
		      int nbuf, int ndesc);
void ath_descdma_cleanup(struct ath_softc *sc, struct ath_descdma *dd,
219 220
			 struct list_head *head);

S
Sujith 已提交
221 222 223
/***********/
/* RX / TX */
/***********/
224 225 226 227 228 229 230 231 232 233 234 235 236

#define ATH_MAX_ANTENNA          3
#define ATH_RXBUF                512
#define WME_NUM_TID              16

int ath_startrecv(struct ath_softc *sc);
bool ath_stoprecv(struct ath_softc *sc);
void ath_flushrecv(struct ath_softc *sc);
u32 ath_calcrxfilter(struct ath_softc *sc);
int ath_rx_init(struct ath_softc *sc, int nbufs);
void ath_rx_cleanup(struct ath_softc *sc);
int ath_rx_tasklet(struct ath_softc *sc, int flush);

S
Sujith 已提交
237
#define ATH_TXBUF               512
238 239 240 241 242 243 244 245 246 247 248 249 250
#define ATH_TXMAXTRY            13
#define ATH_11N_TXMAXTRY        10
#define ATH_MGT_TXMAXTRY        4
#define WME_BA_BMP_SIZE         64
#define WME_MAX_BA              WME_BA_BMP_SIZE
#define ATH_TID_MAX_BUFS        (2 * WME_MAX_BA)
#define TID_TO_WME_AC(_tid)				\
	((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE :	\
	 (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK :	\
	 (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI :	\
	 WME_AC_VO)


S
Sujith 已提交
251 252 253 254 255
#define WME_AC_BE   0
#define WME_AC_BK   1
#define WME_AC_VI   2
#define WME_AC_VO   3
#define WME_NUM_AC  4
256 257

struct ath_txq {
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
	u32 axq_qnum;			/* hardware q number */
	u32 *axq_link;			/* link ptr in last TX desc */
	struct list_head axq_q;		/* transmit queue */
	spinlock_t axq_lock;
	unsigned long axq_lockflags;	/* intr state when must cli */
	u32 axq_depth;			/* queue depth */
	u8 axq_aggr_depth;		/* aggregates queued */
	u32 axq_totalqueued;		/* total ever queued */

	bool stopped;			/* Is mac80211 queue stopped ? */
	struct ath_buf *axq_linkbuf;	/* virtual addr of last buffer*/

	/* first desc of the last descriptor that contains CTS */
	struct ath_desc *axq_lastdsWithCTS;

	/* final desc of the gating desc that determines whether
	   lastdsWithCTS has been DMA'ed or not */
	struct ath_desc *axq_gatingds;

	struct list_head axq_acq;
278 279
};

280 281 282 283
#define AGGR_CLEANUP         BIT(1)
#define AGGR_ADDBA_COMPLETE  BIT(2)
#define AGGR_ADDBA_PROGRESS  BIT(3)

284 285
/* per TID aggregate tx state for a destination */
struct ath_atx_tid {
286 287 288 289 290 291 292 293 294 295 296 297 298
	struct list_head list;		/* round-robin tid entry */
	struct list_head buf_q;		/* pending buffers */
	struct ath_node *an;
	struct ath_atx_ac *ac;
	struct ath_buf *tx_buf[ATH_TID_MAX_BUFS]; /* active tx frames */
	u16 seq_start;
	u16 seq_next;
	u16 baw_size;
	int tidno;
	int baw_head;			/* first un-acked tx buffer */
	int baw_tail;			/* next unused tx buffer slot */
	int sched;
	int paused;
299
	u8 state;
300
	int addba_exchangeattempts;
301 302 303 304
};

/* per access-category aggregate tx state for a destination */
struct ath_atx_ac {
305 306 307 308 309
	int sched;			/* dest-ac is scheduled */
	int qnum;			/* H/W queue number associated
					   with this AC */
	struct list_head list;		/* round-robin txq entry */
	struct list_head tid_q;		/* queue of TIDs with buffers */
310 311 312 313
};

/* per dest tx state */
struct ath_atx {
314 315
	struct ath_atx_tid tid[WME_NUM_TID];
	struct ath_atx_ac ac[WME_NUM_AC];
316 317 318 319
};

/* per-frame tx control block */
struct ath_tx_control {
S
Sujith 已提交
320
	struct ath_txq *txq;
321
	int if_id;
322 323 324 325
};

/* per frame tx status block */
struct ath_xmit_status {
326 327 328
	int retries;	/* number of retries to successufully
			   transmit this frame */
	int flags;	/* status of transmit */
329 330 331 332 333
#define ATH_TX_ERROR        0x01
#define ATH_TX_XRETRY       0x02
#define ATH_TX_BAR          0x04
};

S
Sujith 已提交
334
/* All RSSI values are noise floor adjusted */
335
struct ath_tx_stat {
S
Sujith 已提交
336 337 338 339 340 341 342
	int rssi;
	int rssictl[ATH_MAX_ANTENNA];
	int rssiextn[ATH_MAX_ANTENNA];
	int rateieee;
	int rateKbps;
	int ratecode;
	int flags;
343 344 345 346 347 348 349 350 351 352 353 354
/* if any of ctl,extn chain rssis are valid */
#define ATH_TX_CHAIN_RSSI_VALID 0x01
/* if extn chain rssis are valid */
#define ATH_TX_RSSI_EXTN_VALID  0x02
	u32 airtime;	/* time on air per final tx rate */
};

struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
int ath_tx_setup(struct ath_softc *sc, int haltype);
void ath_draintxq(struct ath_softc *sc, bool retry_tx);
void ath_tx_draintxq(struct ath_softc *sc,
S
Sujith 已提交
355
		     struct ath_txq *txq, bool retry_tx);
356
void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
S
Sujith 已提交
357
void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
358 359 360 361 362
void ath_tx_node_free(struct ath_softc *sc, struct ath_node *an);
void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
int ath_tx_init(struct ath_softc *sc, int nbufs);
int ath_tx_cleanup(struct ath_softc *sc);
int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype);
S
Sujith 已提交
363
struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb);
364 365
int ath_txq_update(struct ath_softc *sc, int qnum,
		   struct ath9k_tx_queue_info *q);
S
Sujith 已提交
366 367
int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
		 struct ath_tx_control *txctl);
368 369 370
void ath_tx_tasklet(struct ath_softc *sc);
u32 ath_txq_depth(struct ath_softc *sc, int qnum);
u32 ath_txq_aggr_depth(struct ath_softc *sc, int qnum);
371
void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb);
372 373 374 375 376 377

/**********************/
/* Node / Aggregation */
/**********************/

#define ADDBA_EXCHANGE_ATTEMPTS    10
S
Sujith 已提交
378
#define ATH_AGGR_DELIM_SZ          4
379 380 381 382 383 384 385 386 387
#define ATH_AGGR_MINPLEN           256 /* in bytes, minimum packet length */
/* number of delimiters for encryption padding */
#define ATH_AGGR_ENCRYPTDELIM      10
/* minimum h/w qdepth to be sustained to maximize aggregation */
#define ATH_AGGR_MIN_QDEPTH        2
#define ATH_AMPDU_SUBFRAME_DEFAULT 32
#define IEEE80211_SEQ_SEQ_SHIFT    4
#define IEEE80211_SEQ_MAX          4096
#define IEEE80211_MIN_AMPDU_BUF    0x8
S
Sujith 已提交
388
#define IEEE80211_HTCAP_MAXRXAMPDU_FACTOR 13
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

/* return whether a bit at index _n in bitmap _bm is set
 * _sz is the size of the bitmap  */
#define ATH_BA_ISSET(_bm, _n)  (((_n) < (WME_BA_BMP_SIZE)) &&		\
				((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))

/* return block-ack bitmap index given sequence and starting sequence */
#define ATH_BA_INDEX(_st, _seq) (((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))

/* returns delimiter padding required given the packet length */
#define ATH_AGGR_GET_NDELIM(_len)					\
	(((((_len) + ATH_AGGR_DELIM_SZ) < ATH_AGGR_MINPLEN) ?           \
	  (ATH_AGGR_MINPLEN - (_len) - ATH_AGGR_DELIM_SZ) : 0) >> 2)

#define BAW_WITHIN(_start, _bawsz, _seqno) \
	((((_seqno) - (_start)) & 4095) < (_bawsz))

#define ATH_DS_BA_SEQ(_ds)               ((_ds)->ds_us.tx.ts_seqnum)
#define ATH_DS_BA_BITMAP(_ds)            (&(_ds)->ds_us.tx.ba_low)
#define ATH_DS_TX_BA(_ds)	((_ds)->ds_us.tx.ts_flags & ATH9K_TX_BA)
#define ATH_AN_2_TID(_an, _tidno)        (&(_an)->an_aggr.tx.tid[(_tidno)])

enum ATH_AGGR_STATUS {
	ATH_AGGR_DONE,
	ATH_AGGR_BAW_CLOSED,
	ATH_AGGR_LIMITED,
	ATH_AGGR_SHORTPKT,
	ATH_AGGR_8K_LIMITED,
};

struct aggr_rifs_param {
	int param_max_frames;
	int param_max_len;
	int param_rl;
	int param_al;
	struct ath_rc_series *param_rcs;
};

/* Per-node aggregation state */
struct ath_node_aggr {
S
Sujith 已提交
429
	struct ath_atx tx;
430 431 432
};

struct ath_node {
433 434
	struct ath_softc *an_sc;
	struct ath_node_aggr an_aggr;
J
Johannes Berg 已提交
435 436
	u16 maxampdu;
	u8 mpdudensity;
437 438
};

S
Sujith 已提交
439
void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid);
S
Sujith 已提交
440
bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno);
S
Sujith 已提交
441
void ath_tx_aggr_teardown(struct ath_softc *sc,	struct ath_node *an, u8 tidno);
S
Sujith 已提交
442 443 444
int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
		      u16 tid, u16 *ssn);
int ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
445
void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
446

447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
/********/
/* VAPs */
/********/

/*
 * Define the scheme that we select MAC address for multiple
 * BSS on the same radio. The very first VAP will just use the MAC
 * address from the EEPROM. For the next 3 VAPs, we set the
 * U/L bit (bit 1) in MAC address, and use the next two bits as the
 * index of the VAP.
 */

#define ATH_SET_VAP_BSSID_MASK(bssid_mask) \
	((bssid_mask)[0] &= ~(((ATH_BCBUF-1)<<2)|0x02))

struct ath_vap {
S
Sujith 已提交
463 464 465 466
	int av_bslot;
	enum ath9k_opmode av_opmode;
	struct ath_buf *av_bcbuf;
	struct ath_tx_control av_btxctl;
467 468
};

469 470 471 472 473 474 475 476 477 478
/*******************/
/* Beacon Handling */
/*******************/

/*
 * Regardless of the number of beacons we stagger, (i.e. regardless of the
 * number of BSSIDs) if a given beacon does not go out even after waiting this
 * number of beacon intervals, the game's up.
 */
#define BSTUCK_THRESH           	(9 * ATH_BCBUF)
S
Sujith 已提交
479 480
#define	ATH_BCBUF               	4
#define ATH_DEFAULT_BINTVAL     	100 /* TU */
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
#define ATH_DEFAULT_BMISS_LIMIT 	10
#define IEEE80211_MS_TO_TU(x)           (((x) * 1000) / 1024)

struct ath_beacon_config {
	u16 beacon_interval;
	u16 listen_interval;
	u16 dtim_period;
	u16 bmiss_timeout;
	u8 dtim_count;
	u8 tim_offset;
	union {
		u64 last_tsf;
		u8 last_tstamp[8];
	} u; /* last received beacon/probe response timestamp of this BSS. */
};

void ath9k_beacon_tasklet(unsigned long data);
void ath_beacon_config(struct ath_softc *sc, int if_id);
int ath_beaconq_setup(struct ath_hal *ah);
int ath_beacon_alloc(struct ath_softc *sc, int if_id);
void ath_beacon_return(struct ath_softc *sc, struct ath_vap *avp);
void ath_beacon_sync(struct ath_softc *sc, int if_id);

504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
/*******/
/* ANI */
/*******/

/* ANI values for STA only.
   FIXME: Add appropriate values for AP later */

#define ATH_ANI_POLLINTERVAL    100     /* 100 milliseconds between ANI poll */
#define ATH_SHORT_CALINTERVAL   1000    /* 1 second between calibrations */
#define ATH_LONG_CALINTERVAL    30000   /* 30 seconds between calibrations */
#define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes between calibrations */

struct ath_ani {
	bool sc_caldone;
	int16_t sc_noise_floor;
	unsigned int sc_longcal_timer;
	unsigned int sc_shortcal_timer;
	unsigned int sc_resetcal_timer;
	unsigned int sc_checkani_timer;
	struct timer_list timer;
};

526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
/********************/
/*   LED Control    */
/********************/

#define ATH_LED_PIN	1

enum ath_led_type {
	ATH_LED_RADIO,
	ATH_LED_ASSOC,
	ATH_LED_TX,
	ATH_LED_RX
};

struct ath_led {
	struct ath_softc *sc;
	struct led_classdev led_cdev;
	enum ath_led_type led_type;
	char name[32];
	bool registered;
};

547 548 549 550 551 552 553 554 555
/* Rfkill */
#define ATH_RFKILL_POLL_INTERVAL	2000 /* msecs */

struct ath_rfkill {
	struct rfkill *rfkill;
	struct delayed_work rfkill_poll;
	char rfkill_name[32];
};

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
/********************/
/* Main driver core */
/********************/

/*
 * Default cache line size, in bytes.
 * Used when PCI device not fully initialized by bootrom/BIOS
*/
#define DEFAULT_CACHELINE       32
#define	ATH_DEFAULT_NOISE_FLOOR -95
#define ATH_REGCLASSIDS_MAX     10
#define ATH_CABQ_READY_TIME     80  /* % of beacon interval */
#define ATH_MAX_SW_RETRIES      10
#define ATH_CHAN_MAX            255
#define IEEE80211_WEP_NKID      4       /* number of key ids */
#define IEEE80211_RATE_VAL      0x7f
/*
 * The key cache is used for h/w cipher state and also for
 * tracking station state such as the current tx antenna.
 * We also setup a mapping table between key cache slot indices
 * and station state to short-circuit node lookups on rx.
 * Different parts have different size key caches.  We handle
 * up to ATH_KEYMAX entries (could dynamically allocate state).
 */
#define	ATH_KEYMAX	        128        /* max key cache size we handle */

#define ATH_IF_ID_ANY   	0xff
#define ATH_TXPOWER_MAX         100     /* .5 dBm units */
S
Sujith 已提交
584 585
#define ATH_RSSI_DUMMY_MARKER   0x127
#define ATH_RATE_DUMMY_MARKER   0
586 587 588 589 590 591 592

enum PROT_MODE {
	PROT_M_NONE = 0,
	PROT_M_RTSCTS,
	PROT_M_CTSONLY
};

S
Sujith 已提交
593 594 595 596 597 598
#define SC_OP_INVALID		BIT(0)
#define SC_OP_BEACONS		BIT(1)
#define SC_OP_RXAGGR		BIT(2)
#define SC_OP_TXAGGR		BIT(3)
#define SC_OP_CHAINMASK_UPDATE	BIT(4)
#define SC_OP_FULL_RESET	BIT(5)
S
Sujith 已提交
599 600 601 602
#define SC_OP_NO_RESET		BIT(6)
#define SC_OP_PREAMBLE_SHORT	BIT(7)
#define SC_OP_PROTECT_ENABLE	BIT(8)
#define SC_OP_RXFLUSH		BIT(9)
603
#define SC_OP_LED_ASSOCIATED	BIT(10)
604 605 606
#define SC_OP_RFKILL_REGISTERED	BIT(11)
#define SC_OP_RFKILL_SW_BLOCKED	BIT(12)
#define SC_OP_RFKILL_HW_BLOCKED	BIT(13)
S
Sujith 已提交
607

608
struct ath_softc {
609 610 611 612
	struct ieee80211_hw *hw;
	struct pci_dev *pdev;
	struct tasklet_struct intr_tq;
	struct tasklet_struct bcon_tasklet;
S
Sujith 已提交
613
	struct ath_config sc_config;
614
	struct ath_hal *sc_ah;
S
Sujith 已提交
615 616
	void __iomem *mem;

S
Sujith 已提交
617 618 619 620
	u8 sc_curbssid[ETH_ALEN];
	u8 sc_myaddr[ETH_ALEN];
	u8 sc_bssidmask[ETH_ALEN];

621
#ifdef CONFIG_ATH9K_DEBUG
S
Sujith 已提交
622
	int sc_debug;
623
#endif
624
	u32 sc_intrstatus;
S
Sujith 已提交
625
	u32 sc_flags; /* SC_OP_* */
S
Sujith 已提交
626
	unsigned int rx_filter;
627 628
	u16 sc_curtxpow;
	u16 sc_curaid;
S
Sujith 已提交
629 630 631 632 633 634 635
	u16 sc_cachelsz;
	int sc_slotupdate;		/* slot to next advance fsm */
	int sc_slottime;
	int sc_bslot[ATH_BCBUF];
	u8 sc_tx_chainmask;
	u8 sc_rx_chainmask;
	enum ath9k_int sc_imask;
S
Sujith 已提交
636
	enum wireless_mode sc_curmode;
637
	enum PROT_MODE sc_protmode;
S
Sujith 已提交
638

S
Sujith 已提交
639 640
	u8 sc_nbcnvaps;
	u16 sc_nvaps;
S
Sujith 已提交
641
	struct ieee80211_vif *sc_vaps[ATH_BCBUF];
S
Sujith 已提交
642 643

	u8 sc_mcastantenna;
S
Sujith 已提交
644 645
	u8 sc_defant;
	u8 sc_rxotherant;
S
Sujith 已提交
646

S
Sujith 已提交
647
	struct ath9k_node_stats sc_halstats;
648
	enum ath9k_ht_extprotspacing sc_ht_extprotspacing;
649
	enum ath9k_ht_macmode tx_chan_width;
S
Sujith 已提交
650

651
#ifdef CONFIG_SLOW_ANT_DIV
652
	struct ath_antdiv sc_antdiv;
653 654
#endif
	enum {
655 656 657 658
		OK,		/* no change needed */
		UPDATE,		/* update pending */
		COMMIT		/* beacon sent, commit change */
	} sc_updateslot;	/* slot time update fsm */
659 660

	/* Crypto */
S
Sujith 已提交
661 662
	u32 sc_keymax;
	DECLARE_BITMAP(sc_keymap, ATH_KEYMAX);
663
	u8 sc_splitmic;		/* split TKIP MIC keys */
664 665

	/* RX */
666 667
	struct list_head sc_rxbuf;
	struct ath_descdma sc_rxdma;
S
Sujith 已提交
668 669
	int sc_rxbufsize;
	u32 *sc_rxlink;
670 671

	/* TX */
672 673 674 675
	struct list_head sc_txbuf;
	struct ath_txq sc_txq[ATH9K_NUM_TX_QUEUES];
	struct ath_descdma sc_txdma;
	u32 sc_txqsetup;
S
Sujith 已提交
676
	int sc_haltype2q[ATH9K_WME_AC_VO+1];
677
	u16 seq_no; /* TX sequence number */
678 679

	/* Beacon */
680 681 682 683 684 685
	struct ath9k_tx_queue_info sc_beacon_qi;
	struct ath_descdma sc_bdma;
	struct ath_txq *sc_cabq;
	struct list_head sc_bbuf;
	u32 sc_bhalq;
	u32 sc_bmisscount;
S
Sujith 已提交
686
	u32 ast_be_xmit;
S
Sujith 已提交
687
	u64 bc_tstamp;
688 689

	/* Rate */
690
	struct ieee80211_rate rates[IEEE80211_NUM_BANDS][ATH_RATE_MAX];
S
Sujith 已提交
691
	struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX];
S
Sujith 已提交
692
	u8 sc_protrix;
693 694 695 696 697 698

	/* Channel, Band */
	struct ieee80211_channel channels[IEEE80211_NUM_BANDS][ATH_CHAN_MAX];
	struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];

	/* Locks */
699 700 701 702
	spinlock_t sc_rxflushlock;
	spinlock_t sc_rxbuflock;
	spinlock_t sc_txbuflock;
	spinlock_t sc_resetlock;
703 704 705 706 707 708

	/* LEDs */
	struct ath_led radio_led;
	struct ath_led assoc_led;
	struct ath_led tx_led;
	struct ath_led rx_led;
709 710 711

	/* Rfkill */
	struct ath_rfkill rf_kill;
712 713 714

	/* ANI */
	struct ath_ani sc_ani;
715 716
};

S
Sujith 已提交
717
int ath_reset(struct ath_softc *sc, bool retry_tx);
718 719 720 721 722
int ath_get_hal_qnum(u16 queue, struct ath_softc *sc);
int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc);
int ath_cabq_update(struct ath_softc *);

#endif /* CORE_H */