You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  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.
  10. *
  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.
  18. */
  19. #ifndef ATH9K_H
  20. #define ATH9K_H
  21. #include "common.h"
  22. /*
  23. * Header for the ath9k.ko driver core *only* -- hw code nor any other driver
  24. * should rely on this file or its contents.
  25. */
  26. struct ath_node;
  27. struct ath_softc;
  28. /* Macro to expand scalars to 64-bit objects */
  29. #define ito64(x) (sizeof(x) == 1) ? \
  30. (((unsigned long long int)(x)) & (0xff)) : \
  31. (sizeof(x) == 2) ? \
  32. (((unsigned long long int)(x)) & 0xffff) : \
  33. ((sizeof(x) == 4) ? \
  34. (((unsigned long long int)(x)) & 0xffffffff) : \
  35. (unsigned long long int)(x))
  36. /* increment with wrap-around */
  37. #define INCR(_l, _sz) do { \
  38. (_l)++; \
  39. (_l) &= ((_sz) - 1); \
  40. } while (0)
  41. /* decrement with wrap-around */
  42. #define DECR(_l, _sz) do { \
  43. (_l)--; \
  44. (_l) &= ((_sz) - 1); \
  45. } while (0)
  46. #define A_MAX(a, b) ((a) > (b) ? (a) : (b))
  47. #define TSF_TO_TU(_h,_l) \
  48. ((((u32)(_h)) << 22) | (((u32)(_l)) >> 10))
  49. #define ATH_TXQ_SETUP(sc, i) ((sc)->tx.txqsetup & (1<<i))
  50. struct ath_config {
  51. u16 txpowlimit;
  52. u8 cabqReadytime;
  53. };
  54. /*************************/
  55. /* Descriptor Management */
  56. /*************************/
  57. #define ATH_TXBUF_RESET(_bf) do { \
  58. (_bf)->bf_stale = 0; \
  59. (_bf)->bf_lastbf = NULL; \
  60. (_bf)->bf_next = NULL; \
  61. memset(&((_bf)->bf_state), 0, \
  62. sizeof(struct ath_buf_state)); \
  63. } while (0)
  64. #define ATH_RXBUF_RESET(_bf) do { \
  65. (_bf)->bf_stale = 0; \
  66. } while (0)
  67. /**
  68. * enum buffer_type - Buffer type flags
  69. *
  70. * @BUF_AMPDU: This buffer is an ampdu, as part of an aggregate (during TX)
  71. * @BUF_AGGR: Indicates whether the buffer can be aggregated
  72. * (used in aggregation scheduling)
  73. * @BUF_XRETRY: To denote excessive retries of the buffer
  74. */
  75. enum buffer_type {
  76. BUF_AMPDU = BIT(0),
  77. BUF_AGGR = BIT(1),
  78. BUF_XRETRY = BIT(2),
  79. };
  80. #define bf_isampdu(bf) (bf->bf_state.bf_type & BUF_AMPDU)
  81. #define bf_isaggr(bf) (bf->bf_state.bf_type & BUF_AGGR)
  82. #define bf_isxretried(bf) (bf->bf_state.bf_type & BUF_XRETRY)
  83. #define ATH_TXSTATUS_RING_SIZE 64
  84. struct ath_descdma {
  85. void *dd_desc;
  86. u32 dd_desc_paddr;
  87. u32 dd_desc_len;
  88. struct ath_buf *dd_bufptr;
  89. };
  90. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  91. struct list_head *head, const char *name,
  92. int nbuf, int ndesc, int is_tx);
  93. void ath_descdma_cleanup(struct ath_softc *sc, struct ath_descdma *dd,
  94. struct list_head *head);
  95. /***********/
  96. /* RX / TX */
  97. /***********/
  98. #define ATH_RXBUF 16
  99. #define ATH_TXBUF 16
  100. #define ATH_TXBUF_RESERVE 5
  101. #define ATH_MAX_QDEPTH (ATH_TXBUF / 4 - ATH_TXBUF_RESERVE)
  102. #define ATH_TXMAXTRY 13
  103. #define TID_TO_WME_AC(_tid) \
  104. ((((_tid) == 0) || ((_tid) == 3)) ? WME_AC_BE : \
  105. (((_tid) == 1) || ((_tid) == 2)) ? WME_AC_BK : \
  106. (((_tid) == 4) || ((_tid) == 5)) ? WME_AC_VI : \
  107. WME_AC_VO)
  108. #define ATH_AGGR_DELIM_SZ 4
  109. #define ATH_AGGR_MINPLEN 256 /* in bytes, minimum packet length */
  110. /* number of delimiters for encryption padding */
  111. #define ATH_AGGR_ENCRYPTDELIM 10
  112. /* minimum h/w qdepth to be sustained to maximize aggregation */
  113. #define ATH_AGGR_MIN_QDEPTH 2
  114. #define ATH_AMPDU_SUBFRAME_DEFAULT 32
  115. #define FCS_LEN 4
  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. /* return whether a bit at index _n in bitmap _bm is set
  126. * _sz is the size of the bitmap */
  127. #define ATH_BA_ISSET(_bm, _n) (((_n) < (WME_BA_BMP_SIZE)) && \
  128. ((_bm)[(_n) >> 5] & (1 << ((_n) & 31))))
  129. /* return block-ack bitmap index given sequence and starting sequence */
  130. #define ATH_BA_INDEX(_st, _seq) (((_seq) - (_st)) & (IEEE80211_SEQ_MAX - 1))
  131. /* returns delimiter padding required given the packet length */
  132. #define ATH_AGGR_GET_NDELIM(_len) \
  133. (((_len) >= ATH_AGGR_MINPLEN) ? 0 : \
  134. DIV_ROUND_UP(ATH_AGGR_MINPLEN - (_len), ATH_AGGR_DELIM_SZ))
  135. #define BAW_WITHIN(_start, _bawsz, _seqno) \
  136. ((((_seqno) - (_start)) & 4095) < (_bawsz))
  137. #define ATH_AN_2_TID(_an, _tidno) (&(_an)->tid[(_tidno)])
  138. #define ATH_TX_COMPLETE_POLL_INT 1000
  139. enum ATH_AGGR_STATUS {
  140. ATH_AGGR_DONE,
  141. ATH_AGGR_BAW_CLOSED,
  142. ATH_AGGR_LIMITED,
  143. };
  144. #define ATH_TXFIFO_DEPTH 8
  145. struct ath_txq {
  146. int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
  147. u32 axq_qnum; /* ath9k hardware queue number */
  148. u32 *axq_link;
  149. struct list_head axq_q;
  150. u32 axq_depth;
  151. u32 axq_ampdu_depth;
  152. int stopped;
  153. int axq_tx_inprogress;
  154. struct list_head axq_acq;
  155. struct list_head txq_fifo[ATH_TXFIFO_DEPTH];
  156. struct list_head txq_fifo_pending;
  157. u8 txq_headidx;
  158. u8 txq_tailidx;
  159. int pending_frames;
  160. };
  161. struct ath_atx_ac {
  162. struct ath_txq *txq;
  163. int sched;
  164. struct list_head list;
  165. struct list_head tid_q;
  166. int clear_ps_filter;
  167. };
  168. struct ath_frame_info {
  169. int framelen;
  170. u32 keyix;
  171. enum ath9k_key_type keytype;
  172. u8 retries;
  173. u16 seqno;
  174. };
  175. struct ath_buf_state {
  176. u8 bf_type;
  177. u8 bfs_paprd;
  178. unsigned long bfs_paprd_timestamp;
  179. };
  180. struct ath_buf {
  181. struct list_head list;
  182. struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or
  183. an aggregate) */
  184. struct ath_buf *bf_next; /* next subframe in the aggregate */
  185. struct io_buffer *bf_mpdu; /* enclosing frame structure */
  186. void *bf_desc; /* virtual addr of desc */
  187. u32 bf_daddr; /* physical addr of desc */
  188. u32 bf_buf_addr; /* physical addr of data buffer, for DMA */
  189. int bf_stale;
  190. u16 bf_flags;
  191. struct ath_buf_state bf_state;
  192. };
  193. struct ath_atx_tid {
  194. struct list_head list;
  195. struct list_head buf_q;
  196. struct ath_node *an;
  197. struct ath_atx_ac *ac;
  198. unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
  199. u16 seq_start;
  200. u16 seq_next;
  201. u16 baw_size;
  202. int tidno;
  203. int baw_head; /* first un-acked tx buffer */
  204. int baw_tail; /* next unused tx buffer slot */
  205. int sched;
  206. int paused;
  207. u8 state;
  208. };
  209. struct ath_node {
  210. struct ath_atx_tid tid[WME_NUM_TID];
  211. struct ath_atx_ac ac[WME_NUM_AC];
  212. int ps_key;
  213. u16 maxampdu;
  214. u8 mpdudensity;
  215. int sleeping;
  216. };
  217. #define AGGR_CLEANUP BIT(1)
  218. #define AGGR_ADDBA_COMPLETE BIT(2)
  219. #define AGGR_ADDBA_PROGRESS BIT(3)
  220. struct ath_tx_control {
  221. struct ath_txq *txq;
  222. struct ath_node *an;
  223. int if_id;
  224. u8 paprd;
  225. };
  226. #define ATH_TX_ERROR 0x01
  227. #define ATH_TX_XRETRY 0x02
  228. #define ATH_TX_BAR 0x04
  229. /**
  230. * @txq_map: Index is mac80211 queue number. This is
  231. * not necessarily the same as the hardware queue number
  232. * (axq_qnum).
  233. */
  234. struct ath_tx {
  235. u16 seq_no;
  236. u32 txqsetup;
  237. struct list_head txbuf;
  238. struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
  239. struct ath_descdma txdma;
  240. struct ath_txq *txq_map[WME_NUM_AC];
  241. };
  242. struct ath_rx_edma {
  243. struct list_head rx_fifo;
  244. struct list_head rx_buffers;
  245. u32 rx_fifo_hwsize;
  246. };
  247. struct ath_rx {
  248. u8 defant;
  249. u8 rxotherant;
  250. u32 *rxlink;
  251. unsigned int rxfilter;
  252. struct list_head rxbuf;
  253. struct ath_descdma rxdma;
  254. struct ath_buf *rx_bufptr;
  255. struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
  256. struct io_buffer *frag;
  257. };
  258. int ath_startrecv(struct ath_softc *sc);
  259. int ath_stoprecv(struct ath_softc *sc);
  260. void ath_flushrecv(struct ath_softc *sc);
  261. u32 ath_calcrxfilter(struct ath_softc *sc);
  262. int ath_rx_init(struct ath_softc *sc, int nbufs);
  263. void ath_rx_cleanup(struct ath_softc *sc);
  264. int ath_rx_tasklet(struct ath_softc *sc, int flush, int hp);
  265. struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
  266. void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
  267. int ath_drain_all_txq(struct ath_softc *sc, int retry_tx);
  268. void ath_draintxq(struct ath_softc *sc,
  269. struct ath_txq *txq, int retry_tx);
  270. void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
  271. int ath_tx_init(struct ath_softc *sc, int nbufs);
  272. void ath_tx_cleanup(struct ath_softc *sc);
  273. int ath_txq_update(struct ath_softc *sc, int qnum,
  274. struct ath9k_tx_queue_info *q);
  275. int ath_tx_start(struct net80211_device *dev, struct io_buffer *iob,
  276. struct ath_tx_control *txctl);
  277. void ath_tx_tasklet(struct ath_softc *sc);
  278. /*******/
  279. /* ANI */
  280. /*******/
  281. #define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */
  282. #define ATH_AP_SHORT_CALINTERVAL 100 /* 100 ms */
  283. #define ATH_ANI_POLLINTERVAL_OLD 100 /* 100 ms */
  284. #define ATH_ANI_POLLINTERVAL_NEW 1000 /* 1000 ms */
  285. #define ATH_LONG_CALINTERVAL_INT 1000 /* 1000 ms */
  286. #define ATH_LONG_CALINTERVAL 30000 /* 30 seconds */
  287. #define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
  288. void ath_hw_pll_work(struct ath_softc *sc);
  289. void ath_ani_calibrate(struct ath_softc *sc);
  290. /********************/
  291. /* Main driver core */
  292. /********************/
  293. /*
  294. * Default cache line size, in bytes.
  295. * Used when PCI device not fully initialized by bootrom/BIOS
  296. */
  297. #define DEFAULT_CACHELINE 32
  298. #define ATH_REGCLASSIDS_MAX 10
  299. #define ATH_CABQ_READY_TIME 80 /* % of beacon interval */
  300. #define ATH_MAX_SW_RETRIES 10
  301. #define ATH_CHAN_MAX 255
  302. #define ATH_TXPOWER_MAX 100 /* .5 dBm units */
  303. #define ATH_RATE_DUMMY_MARKER 0
  304. #define SC_OP_INVALID BIT(0)
  305. #define SC_OP_BEACONS BIT(1)
  306. #define SC_OP_RXAGGR BIT(2)
  307. #define SC_OP_TXAGGR BIT(3)
  308. #define SC_OP_OFFCHANNEL BIT(4)
  309. #define SC_OP_PREAMBLE_SHORT BIT(5)
  310. #define SC_OP_PROTECT_ENABLE BIT(6)
  311. #define SC_OP_RXFLUSH BIT(7)
  312. #define SC_OP_LED_ASSOCIATED BIT(8)
  313. #define SC_OP_LED_ON BIT(9)
  314. #define SC_OP_TSF_RESET BIT(11)
  315. #define SC_OP_BT_PRIORITY_DETECTED BIT(12)
  316. #define SC_OP_BT_SCAN BIT(13)
  317. #define SC_OP_ANI_RUN BIT(14)
  318. #define SC_OP_ENABLE_APM BIT(15)
  319. #define SC_OP_PRIM_STA_VIF BIT(16)
  320. /* Powersave flags */
  321. #define PS_WAIT_FOR_BEACON BIT(0)
  322. #define PS_WAIT_FOR_CAB BIT(1)
  323. #define PS_WAIT_FOR_PSPOLL_DATA BIT(2)
  324. #define PS_WAIT_FOR_TX_ACK BIT(3)
  325. #define PS_BEACON_SYNC BIT(4)
  326. #define PS_TSFOOR_SYNC BIT(5)
  327. struct ath_rate_table;
  328. struct ath9k_legacy_rate {
  329. u16 bitrate;
  330. u32 flags;
  331. u16 hw_value;
  332. u16 hw_value_short;
  333. };
  334. enum ath9k_rate_control_flags {
  335. IEEE80211_TX_RC_USE_RTS_CTS = BIT(0),
  336. IEEE80211_TX_RC_USE_CTS_PROTECT = BIT(1),
  337. IEEE80211_TX_RC_USE_SHORT_PREAMBLE = BIT(2),
  338. /* rate index is an MCS rate number instead of an index */
  339. IEEE80211_TX_RC_MCS = BIT(3),
  340. IEEE80211_TX_RC_GREEN_FIELD = BIT(4),
  341. IEEE80211_TX_RC_40_MHZ_WIDTH = BIT(5),
  342. IEEE80211_TX_RC_DUP_DATA = BIT(6),
  343. IEEE80211_TX_RC_SHORT_GI = BIT(7),
  344. };
  345. struct survey_info {
  346. struct net80211_channel *channel;
  347. u64 channel_time;
  348. u64 channel_time_busy;
  349. u64 channel_time_ext_busy;
  350. u64 channel_time_rx;
  351. u64 channel_time_tx;
  352. u32 filled;
  353. s8 noise;
  354. };
  355. enum survey_info_flags {
  356. SURVEY_INFO_NOISE_DBM = 1<<0,
  357. SURVEY_INFO_IN_USE = 1<<1,
  358. SURVEY_INFO_CHANNEL_TIME = 1<<2,
  359. SURVEY_INFO_CHANNEL_TIME_BUSY = 1<<3,
  360. SURVEY_INFO_CHANNEL_TIME_EXT_BUSY = 1<<4,
  361. SURVEY_INFO_CHANNEL_TIME_RX = 1<<5,
  362. SURVEY_INFO_CHANNEL_TIME_TX = 1<<6,
  363. };
  364. struct ath9k_vif_iter_data {
  365. const u8 *hw_macaddr; /* phy's hardware address, set
  366. * before starting iteration for
  367. * valid bssid mask.
  368. */
  369. u8 mask[ETH_ALEN]; /* bssid mask */
  370. int naps; /* number of AP vifs */
  371. int nmeshes; /* number of mesh vifs */
  372. int nstations; /* number of station vifs */
  373. int nwds; /* number of nwd vifs */
  374. int nadhocs; /* number of adhoc vifs */
  375. int nothers; /* number of vifs not specified above. */
  376. };
  377. struct ath_softc {
  378. struct net80211_device *dev;
  379. struct pci_device *pdev;
  380. int chan_idx;
  381. int chan_is_ht;
  382. struct survey_info *cur_survey;
  383. struct survey_info survey[ATH9K_NUM_CHANNELS];
  384. void (*intr_tq)(struct ath_softc *sc);
  385. struct ath_hw *sc_ah;
  386. void *mem;
  387. int irq;
  388. void (*paprd_work)(struct ath_softc *sc);
  389. void (*hw_check_work)(struct ath_softc *sc);
  390. void (*paprd_complete)(struct ath_softc *sc);
  391. unsigned int hw_busy_count;
  392. u32 intrstatus;
  393. u32 sc_flags; /* SC_OP_* */
  394. u16 ps_flags; /* PS_* */
  395. u16 curtxpow;
  396. int ps_enabled;
  397. int ps_idle;
  398. short nbcnvifs;
  399. short nvifs;
  400. unsigned long ps_usecount;
  401. struct ath_config config;
  402. struct ath_rx rx;
  403. struct ath_tx tx;
  404. struct net80211_hw_info *hwinfo;
  405. struct ath9k_legacy_rate rates[NET80211_MAX_RATES];
  406. int hw_rix;
  407. struct ath9k_hw_cal_data caldata;
  408. int last_rssi;
  409. void (*tx_complete_work)(struct ath_softc *sc);
  410. unsigned long tx_complete_work_timer;
  411. void (*hw_pll_work)(struct ath_softc *sc);
  412. unsigned long hw_pll_work_timer;
  413. struct ath_descdma txsdma;
  414. };
  415. void ath9k_tasklet(struct ath_softc *sc);
  416. int ath_reset(struct ath_softc *sc, int retry_tx);
  417. static inline void ath_read_cachesize(struct ath_common *common, int *csz)
  418. {
  419. common->bus_ops->read_cachesize(common, csz);
  420. }
  421. extern struct net80211_device_operations ath9k_ops;
  422. extern int ath9k_modparam_nohwcrypt;
  423. extern int is_ath9k_unloaded;
  424. void ath_isr(struct net80211_device *dev);
  425. void ath9k_init_crypto(struct ath_softc *sc);
  426. int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
  427. const struct ath_bus_ops *bus_ops);
  428. void ath9k_deinit_device(struct ath_softc *sc);
  429. void ath9k_set_hw_capab(struct ath_softc *sc, struct net80211_device *dev);
  430. int ath_set_channel(struct ath_softc *sc, struct net80211_device *dev,
  431. struct ath9k_channel *hchan);
  432. void ath_radio_enable(struct ath_softc *sc, struct net80211_device *dev);
  433. void ath_radio_disable(struct ath_softc *sc, struct net80211_device *dev);
  434. int ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode);
  435. int ath9k_uses_beacons(int type);
  436. u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate);
  437. void ath_start_rfkill_poll(struct ath_softc *sc);
  438. extern void ath9k_rfkill_poll_state(struct net80211_device *dev);
  439. #endif /* ATH9K_H */