iwl-trans-pcie-int.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #ifndef __iwl_trans_int_pcie_h__
  30. #define __iwl_trans_int_pcie_h__
  31. #include <linux/spinlock.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/pci.h>
  35. #include "iwl-fh.h"
  36. #include "iwl-csr.h"
  37. #include "iwl-shared.h"
  38. #include "iwl-trans.h"
  39. #include "iwl-debug.h"
  40. #include "iwl-io.h"
  41. #include "iwl-op-mode.h"
  42. struct iwl_tx_queue;
  43. struct iwl_queue;
  44. struct iwl_host_cmd;
  45. /*This file includes the declaration that are internal to the
  46. * trans_pcie layer */
  47. /**
  48. * struct isr_statistics - interrupt statistics
  49. *
  50. */
  51. struct isr_statistics {
  52. u32 hw;
  53. u32 sw;
  54. u32 err_code;
  55. u32 sch;
  56. u32 alive;
  57. u32 rfkill;
  58. u32 ctkill;
  59. u32 wakeup;
  60. u32 rx;
  61. u32 tx;
  62. u32 unhandled;
  63. };
  64. /**
  65. * struct iwl_rx_queue - Rx queue
  66. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  67. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  68. * @pool:
  69. * @queue:
  70. * @read: Shared index to newest available Rx buffer
  71. * @write: Shared index to oldest written Rx packet
  72. * @free_count: Number of pre-allocated buffers in rx_free
  73. * @write_actual:
  74. * @rx_free: list of free SKBs for use
  75. * @rx_used: List of Rx buffers with no SKB
  76. * @need_update: flag to indicate we need to update read/write index
  77. * @rb_stts: driver's pointer to receive buffer status
  78. * @rb_stts_dma: bus address of receive buffer status
  79. * @lock:
  80. *
  81. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  82. */
  83. struct iwl_rx_queue {
  84. __le32 *bd;
  85. dma_addr_t bd_dma;
  86. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  87. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  88. u32 read;
  89. u32 write;
  90. u32 free_count;
  91. u32 write_actual;
  92. struct list_head rx_free;
  93. struct list_head rx_used;
  94. int need_update;
  95. struct iwl_rb_status *rb_stts;
  96. dma_addr_t rb_stts_dma;
  97. spinlock_t lock;
  98. };
  99. struct iwl_dma_ptr {
  100. dma_addr_t dma;
  101. void *addr;
  102. size_t size;
  103. };
  104. /*
  105. * This queue number is required for proper operation
  106. * because the ucode will stop/start the scheduler as
  107. * required.
  108. */
  109. #define IWL_IPAN_MCAST_QUEUE 8
  110. struct iwl_cmd_meta {
  111. /* only for SYNC commands, iff the reply skb is wanted */
  112. struct iwl_host_cmd *source;
  113. u32 flags;
  114. DEFINE_DMA_UNMAP_ADDR(mapping);
  115. DEFINE_DMA_UNMAP_LEN(len);
  116. };
  117. /*
  118. * Generic queue structure
  119. *
  120. * Contains common data for Rx and Tx queues.
  121. *
  122. * Note the difference between n_bd and n_window: the hardware
  123. * always assumes 256 descriptors, so n_bd is always 256 (unless
  124. * there might be HW changes in the future). For the normal TX
  125. * queues, n_window, which is the size of the software queue data
  126. * is also 256; however, for the command queue, n_window is only
  127. * 32 since we don't need so many commands pending. Since the HW
  128. * still uses 256 BDs for DMA though, n_bd stays 256. As a result,
  129. * the software buffers (in the variables @meta, @txb in struct
  130. * iwl_tx_queue) only have 32 entries, while the HW buffers (@tfds
  131. * in the same struct) have 256.
  132. * This means that we end up with the following:
  133. * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
  134. * SW entries: | 0 | ... | 31 |
  135. * where N is a number between 0 and 7. This means that the SW
  136. * data is a window overlayed over the HW queue.
  137. */
  138. struct iwl_queue {
  139. int n_bd; /* number of BDs in this queue */
  140. int write_ptr; /* 1-st empty entry (index) host_w*/
  141. int read_ptr; /* last used entry (index) host_r*/
  142. /* use for monitoring and recovering the stuck queue */
  143. dma_addr_t dma_addr; /* physical addr for BD's */
  144. int n_window; /* safe queue window */
  145. u32 id;
  146. int low_mark; /* low watermark, resume queue if free
  147. * space more than this */
  148. int high_mark; /* high watermark, stop queue if free
  149. * space less than this */
  150. };
  151. /**
  152. * struct iwl_tx_queue - Tx Queue for DMA
  153. * @q: generic Rx/Tx queue descriptor
  154. * @bd: base of circular buffer of TFDs
  155. * @cmd: array of command/TX buffer pointers
  156. * @meta: array of meta data for each command/tx buffer
  157. * @dma_addr_cmd: physical address of cmd/tx buffer array
  158. * @txb: array of per-TFD driver data
  159. * @time_stamp: time (in jiffies) of last read_ptr change
  160. * @need_update: indicates need to update read/write index
  161. * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
  162. * @sta_id: valid if sched_retry is set
  163. * @tid: valid if sched_retry is set
  164. *
  165. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  166. * descriptors) and required locking structures.
  167. */
  168. #define TFD_TX_CMD_SLOTS 256
  169. #define TFD_CMD_SLOTS 32
  170. struct iwl_tx_queue {
  171. struct iwl_queue q;
  172. struct iwl_tfd *tfds;
  173. struct iwl_device_cmd **cmd;
  174. struct iwl_cmd_meta *meta;
  175. struct sk_buff **skbs;
  176. unsigned long time_stamp;
  177. u8 need_update;
  178. u8 sched_retry;
  179. u8 active;
  180. u8 swq_id;
  181. u16 sta_id;
  182. u16 tid;
  183. };
  184. /**
  185. * struct iwl_trans_pcie - PCIe transport specific data
  186. * @rxq: all the RX queue data
  187. * @rx_replenish: work that will be called when buffers need to be allocated
  188. * @trans: pointer to the generic transport area
  189. * @irq_requested: true when the irq has been requested
  190. * @scd_base_addr: scheduler sram base address in SRAM
  191. * @scd_bc_tbls: pointer to the byte count table of the scheduler
  192. * @kw: keep warm address
  193. * @ac_to_fifo: to what fifo is a specifc AC mapped ?
  194. * @ac_to_queue: to what tx queue is a specifc AC mapped ?
  195. * @mcast_queue:
  196. * @txq: Tx DMA processing queues
  197. * @txq_ctx_active_msk: what queue is active
  198. * queue_stopped: tracks what queue is stopped
  199. * queue_stop_count: tracks what SW queue is stopped
  200. * @pci_dev: basic pci-network driver stuff
  201. * @hw_base: pci hardware address support
  202. */
  203. struct iwl_trans_pcie {
  204. struct iwl_rx_queue rxq;
  205. struct work_struct rx_replenish;
  206. struct iwl_trans *trans;
  207. /* INT ICT Table */
  208. __le32 *ict_tbl;
  209. dma_addr_t ict_tbl_dma;
  210. int ict_index;
  211. u32 inta;
  212. bool use_ict;
  213. bool irq_requested;
  214. struct tasklet_struct irq_tasklet;
  215. struct isr_statistics isr_stats;
  216. spinlock_t irq_lock;
  217. u32 inta_mask;
  218. u32 scd_base_addr;
  219. struct iwl_dma_ptr scd_bc_tbls;
  220. struct iwl_dma_ptr kw;
  221. const u8 *ac_to_fifo[NUM_IWL_RXON_CTX];
  222. const u8 *ac_to_queue[NUM_IWL_RXON_CTX];
  223. u8 mcast_queue[NUM_IWL_RXON_CTX];
  224. u8 agg_txq[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
  225. struct iwl_tx_queue *txq;
  226. unsigned long txq_ctx_active_msk;
  227. #define IWL_MAX_HW_QUEUES 32
  228. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  229. atomic_t queue_stop_count[4];
  230. /* PCI bus related data */
  231. struct pci_dev *pci_dev;
  232. void __iomem *hw_base;
  233. };
  234. #define IWL_TRANS_GET_PCIE_TRANS(_iwl_trans) \
  235. ((struct iwl_trans_pcie *) ((_iwl_trans)->trans_specific))
  236. /*****************************************************
  237. * RX
  238. ******************************************************/
  239. void iwl_bg_rx_replenish(struct work_struct *data);
  240. void iwl_irq_tasklet(struct iwl_trans *trans);
  241. void iwlagn_rx_replenish(struct iwl_trans *trans);
  242. void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
  243. struct iwl_rx_queue *q);
  244. /*****************************************************
  245. * ICT
  246. ******************************************************/
  247. void iwl_reset_ict(struct iwl_trans *trans);
  248. void iwl_disable_ict(struct iwl_trans *trans);
  249. int iwl_alloc_isr_ict(struct iwl_trans *trans);
  250. void iwl_free_isr_ict(struct iwl_trans *trans);
  251. irqreturn_t iwl_isr_ict(int irq, void *data);
  252. /*****************************************************
  253. * TX / HCMD
  254. ******************************************************/
  255. void iwl_txq_update_write_ptr(struct iwl_trans *trans,
  256. struct iwl_tx_queue *txq);
  257. int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
  258. struct iwl_tx_queue *txq,
  259. dma_addr_t addr, u16 len, u8 reset);
  260. int iwl_queue_init(struct iwl_queue *q, int count, int slots_num, u32 id);
  261. int iwl_trans_pcie_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  262. void iwl_tx_cmd_complete(struct iwl_trans *trans,
  263. struct iwl_rx_mem_buffer *rxb, int handler_status);
  264. void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans,
  265. struct iwl_tx_queue *txq,
  266. u16 byte_cnt);
  267. int iwl_trans_pcie_tx_agg_disable(struct iwl_trans *trans,
  268. int sta_id, int tid);
  269. void iwl_trans_set_wr_ptrs(struct iwl_trans *trans, int txq_id, u32 index);
  270. void iwl_trans_tx_queue_set_status(struct iwl_trans *trans,
  271. struct iwl_tx_queue *txq,
  272. int tx_fifo_id, int scd_retry);
  273. int iwl_trans_pcie_tx_agg_alloc(struct iwl_trans *trans, int sta_id, int tid);
  274. void iwl_trans_pcie_tx_agg_setup(struct iwl_trans *trans,
  275. enum iwl_rxon_context_id ctx,
  276. int sta_id, int tid, int frame_limit, u16 ssn);
  277. void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
  278. int index, enum dma_data_direction dma_dir);
  279. int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
  280. struct sk_buff_head *skbs);
  281. int iwl_queue_space(const struct iwl_queue *q);
  282. /*****************************************************
  283. * Error handling
  284. ******************************************************/
  285. int iwl_dump_nic_event_log(struct iwl_trans *trans, bool full_log,
  286. char **buf, bool display);
  287. int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display);
  288. void iwl_dump_csr(struct iwl_trans *trans);
  289. /*****************************************************
  290. * Helpers
  291. ******************************************************/
  292. static inline void iwl_disable_interrupts(struct iwl_trans *trans)
  293. {
  294. clear_bit(STATUS_INT_ENABLED, &trans->shrd->status);
  295. /* disable interrupts from uCode/NIC to host */
  296. iwl_write32(trans, CSR_INT_MASK, 0x00000000);
  297. /* acknowledge/clear/reset any interrupts still pending
  298. * from uCode or flow handler (Rx/Tx DMA) */
  299. iwl_write32(trans, CSR_INT, 0xffffffff);
  300. iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
  301. IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
  302. }
  303. static inline void iwl_enable_interrupts(struct iwl_trans *trans)
  304. {
  305. struct iwl_trans_pcie *trans_pcie =
  306. IWL_TRANS_GET_PCIE_TRANS(trans);
  307. IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
  308. set_bit(STATUS_INT_ENABLED, &trans->shrd->status);
  309. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  310. }
  311. /*
  312. * we have 8 bits used like this:
  313. *
  314. * 7 6 5 4 3 2 1 0
  315. * | | | | | | | |
  316. * | | | | | | +-+-------- AC queue (0-3)
  317. * | | | | | |
  318. * | +-+-+-+-+------------ HW queue ID
  319. * |
  320. * +---------------------- unused
  321. */
  322. static inline void iwl_set_swq_id(struct iwl_tx_queue *txq, u8 ac, u8 hwq)
  323. {
  324. BUG_ON(ac > 3); /* only have 2 bits */
  325. BUG_ON(hwq > 31); /* only use 5 bits */
  326. txq->swq_id = (hwq << 2) | ac;
  327. }
  328. static inline u8 iwl_get_queue_ac(struct iwl_tx_queue *txq)
  329. {
  330. return txq->swq_id & 0x3;
  331. }
  332. static inline void iwl_wake_queue(struct iwl_trans *trans,
  333. struct iwl_tx_queue *txq, const char *msg)
  334. {
  335. u8 queue = txq->swq_id;
  336. u8 ac = queue & 3;
  337. u8 hwq = (queue >> 2) & 0x1f;
  338. struct iwl_trans_pcie *trans_pcie =
  339. IWL_TRANS_GET_PCIE_TRANS(trans);
  340. if (test_and_clear_bit(hwq, trans_pcie->queue_stopped)) {
  341. if (atomic_dec_return(&trans_pcie->queue_stop_count[ac]) <= 0) {
  342. iwl_op_mode_queue_not_full(trans->op_mode, ac);
  343. IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d ac %d. %s",
  344. hwq, ac, msg);
  345. } else {
  346. IWL_DEBUG_TX_QUEUES(trans, "Don't wake hwq %d ac %d"
  347. " stop count %d. %s",
  348. hwq, ac, atomic_read(&trans_pcie->
  349. queue_stop_count[ac]), msg);
  350. }
  351. }
  352. }
  353. static inline void iwl_stop_queue(struct iwl_trans *trans,
  354. struct iwl_tx_queue *txq, const char *msg)
  355. {
  356. u8 queue = txq->swq_id;
  357. u8 ac = queue & 3;
  358. u8 hwq = (queue >> 2) & 0x1f;
  359. struct iwl_trans_pcie *trans_pcie =
  360. IWL_TRANS_GET_PCIE_TRANS(trans);
  361. if (!test_and_set_bit(hwq, trans_pcie->queue_stopped)) {
  362. if (atomic_inc_return(&trans_pcie->queue_stop_count[ac]) > 0) {
  363. iwl_op_mode_queue_full(trans->op_mode, ac);
  364. IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d ac %d"
  365. " stop count %d. %s",
  366. hwq, ac, atomic_read(&trans_pcie->
  367. queue_stop_count[ac]), msg);
  368. } else {
  369. IWL_DEBUG_TX_QUEUES(trans, "Don't stop hwq %d ac %d"
  370. " stop count %d. %s",
  371. hwq, ac, atomic_read(&trans_pcie->
  372. queue_stop_count[ac]), msg);
  373. }
  374. } else {
  375. IWL_DEBUG_TX_QUEUES(trans, "stop hwq %d, but it is stopped/ %s",
  376. hwq, msg);
  377. }
  378. }
  379. #ifdef ieee80211_stop_queue
  380. #undef ieee80211_stop_queue
  381. #endif
  382. #define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
  383. #ifdef ieee80211_wake_queue
  384. #undef ieee80211_wake_queue
  385. #endif
  386. #define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
  387. static inline void iwl_txq_ctx_activate(struct iwl_trans_pcie *trans_pcie,
  388. int txq_id)
  389. {
  390. set_bit(txq_id, &trans_pcie->txq_ctx_active_msk);
  391. }
  392. static inline void iwl_txq_ctx_deactivate(struct iwl_trans_pcie *trans_pcie,
  393. int txq_id)
  394. {
  395. clear_bit(txq_id, &trans_pcie->txq_ctx_active_msk);
  396. }
  397. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  398. {
  399. return q->write_ptr >= q->read_ptr ?
  400. (i >= q->read_ptr && i < q->write_ptr) :
  401. !(i < q->read_ptr && i >= q->write_ptr);
  402. }
  403. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
  404. {
  405. return index & (q->n_window - 1);
  406. }
  407. #define IWL_TX_FIFO_BK 0 /* shared */
  408. #define IWL_TX_FIFO_BE 1
  409. #define IWL_TX_FIFO_VI 2 /* shared */
  410. #define IWL_TX_FIFO_VO 3
  411. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  412. #define IWL_TX_FIFO_BE_IPAN 4
  413. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  414. #define IWL_TX_FIFO_VO_IPAN 5
  415. /* re-uses the VO FIFO, uCode will properly flush/schedule */
  416. #define IWL_TX_FIFO_AUX 5
  417. #define IWL_TX_FIFO_UNUSED -1
  418. /* AUX (TX during scan dwell) queue */
  419. #define IWL_AUX_QUEUE 10
  420. #endif /* __iwl_trans_int_pcie_h__ */