iwl-trans-int-pcie.h 14 KB

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