iwl-trans-int-pcie.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 "iwl-fh.h"
  35. #include "iwl-csr.h"
  36. #include "iwl-shared.h"
  37. #include "iwl-trans.h"
  38. #include "iwl-debug.h"
  39. #include "iwl-io.h"
  40. struct iwl_tx_queue;
  41. struct iwl_queue;
  42. struct iwl_host_cmd;
  43. /*This file includes the declaration that are internal to the
  44. * trans_pcie layer */
  45. /**
  46. * struct isr_statistics - interrupt statistics
  47. *
  48. */
  49. struct isr_statistics {
  50. u32 hw;
  51. u32 sw;
  52. u32 err_code;
  53. u32 sch;
  54. u32 alive;
  55. u32 rfkill;
  56. u32 ctkill;
  57. u32 wakeup;
  58. u32 rx;
  59. u32 tx;
  60. u32 unhandled;
  61. };
  62. /**
  63. * struct iwl_rx_queue - Rx queue
  64. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
  65. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  66. * @pool:
  67. * @queue:
  68. * @read: Shared index to newest available Rx buffer
  69. * @write: Shared index to oldest written Rx packet
  70. * @free_count: Number of pre-allocated buffers in rx_free
  71. * @write_actual:
  72. * @rx_free: list of free SKBs for use
  73. * @rx_used: List of Rx buffers with no SKB
  74. * @need_update: flag to indicate we need to update read/write index
  75. * @rb_stts: driver's pointer to receive buffer status
  76. * @rb_stts_dma: bus address of receive buffer status
  77. * @lock:
  78. *
  79. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  80. */
  81. struct iwl_rx_queue {
  82. __le32 *bd;
  83. dma_addr_t bd_dma;
  84. struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
  85. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  86. u32 read;
  87. u32 write;
  88. u32 free_count;
  89. u32 write_actual;
  90. struct list_head rx_free;
  91. struct list_head rx_used;
  92. int need_update;
  93. struct iwl_rb_status *rb_stts;
  94. dma_addr_t rb_stts_dma;
  95. spinlock_t lock;
  96. };
  97. struct iwl_dma_ptr {
  98. dma_addr_t dma;
  99. void *addr;
  100. size_t size;
  101. };
  102. /*
  103. * This queue number is required for proper operation
  104. * because the ucode will stop/start the scheduler as
  105. * required.
  106. */
  107. #define IWL_IPAN_MCAST_QUEUE 8
  108. /**
  109. * struct iwl_trans_pcie - PCIe transport specific data
  110. * @rxq: all the RX queue data
  111. * @rx_replenish: work that will be called when buffers need to be allocated
  112. * @trans: pointer to the generic transport area
  113. * @scd_base_addr: scheduler sram base address in SRAM
  114. * @scd_bc_tbls: pointer to the byte count table of the scheduler
  115. * @kw: keep warm address
  116. * @ac_to_fifo: to what fifo is a specifc AC mapped ?
  117. * @ac_to_queue: to what tx queue is a specifc AC mapped ?
  118. * @mcast_queue:
  119. * @txq: Tx DMA processing queues
  120. * @txq_ctx_active_msk: what queue is active
  121. * queue_stopped: tracks what queue is stopped
  122. * queue_stop_count: tracks what SW queue is stopped
  123. */
  124. struct iwl_trans_pcie {
  125. struct iwl_rx_queue rxq;
  126. struct work_struct rx_replenish;
  127. struct iwl_trans *trans;
  128. /* INT ICT Table */
  129. __le32 *ict_tbl;
  130. void *ict_tbl_vir;
  131. dma_addr_t ict_tbl_dma;
  132. dma_addr_t aligned_ict_tbl_dma;
  133. int ict_index;
  134. u32 inta;
  135. bool use_ict;
  136. struct tasklet_struct irq_tasklet;
  137. struct isr_statistics isr_stats;
  138. u32 inta_mask;
  139. u32 scd_base_addr;
  140. struct iwl_dma_ptr scd_bc_tbls;
  141. struct iwl_dma_ptr kw;
  142. const u8 *ac_to_fifo[NUM_IWL_RXON_CTX];
  143. const u8 *ac_to_queue[NUM_IWL_RXON_CTX];
  144. u8 mcast_queue[NUM_IWL_RXON_CTX];
  145. struct iwl_tx_queue *txq;
  146. unsigned long txq_ctx_active_msk;
  147. #define IWL_MAX_HW_QUEUES 32
  148. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  149. atomic_t queue_stop_count[4];
  150. };
  151. #define IWL_TRANS_GET_PCIE_TRANS(_iwl_trans) \
  152. ((struct iwl_trans_pcie *) ((_iwl_trans)->trans_specific))
  153. /*****************************************************
  154. * RX
  155. ******************************************************/
  156. void iwl_bg_rx_replenish(struct work_struct *data);
  157. void iwl_irq_tasklet(struct iwl_trans *trans);
  158. void iwlagn_rx_replenish(struct iwl_trans *trans);
  159. void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
  160. struct iwl_rx_queue *q);
  161. /*****************************************************
  162. * ICT
  163. ******************************************************/
  164. int iwl_reset_ict(struct iwl_trans *trans);
  165. void iwl_disable_ict(struct iwl_trans *trans);
  166. int iwl_alloc_isr_ict(struct iwl_trans *trans);
  167. void iwl_free_isr_ict(struct iwl_trans *trans);
  168. irqreturn_t iwl_isr_ict(int irq, void *data);
  169. /*****************************************************
  170. * TX / HCMD
  171. ******************************************************/
  172. void iwl_txq_update_write_ptr(struct iwl_trans *trans,
  173. struct iwl_tx_queue *txq);
  174. int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
  175. struct iwl_tx_queue *txq,
  176. dma_addr_t addr, u16 len, u8 reset);
  177. int iwl_queue_init(struct iwl_queue *q, int count, int slots_num, u32 id);
  178. int iwl_trans_pcie_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  179. int __must_check iwl_trans_pcie_send_cmd_pdu(struct iwl_trans *trans, u8 id,
  180. u32 flags, u16 len, const void *data);
  181. void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
  182. void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans,
  183. struct iwl_tx_queue *txq,
  184. u16 byte_cnt);
  185. void iwl_trans_pcie_txq_agg_disable(struct iwl_trans *trans, int txq_id);
  186. int iwl_trans_pcie_tx_agg_disable(struct iwl_trans *trans,
  187. enum iwl_rxon_context_id ctx, int sta_id,
  188. int tid);
  189. void iwl_trans_set_wr_ptrs(struct iwl_trans *trans, int txq_id, u32 index);
  190. void iwl_trans_tx_queue_set_status(struct iwl_trans *trans,
  191. struct iwl_tx_queue *txq,
  192. int tx_fifo_id, int scd_retry);
  193. int iwl_trans_pcie_tx_agg_alloc(struct iwl_trans *trans,
  194. enum iwl_rxon_context_id ctx, int sta_id,
  195. int tid, u16 *ssn);
  196. void iwl_trans_pcie_tx_agg_setup(struct iwl_trans *trans,
  197. enum iwl_rxon_context_id ctx,
  198. int sta_id, int tid, int frame_limit);
  199. void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
  200. int index);
  201. int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
  202. struct sk_buff_head *skbs);
  203. int iwl_queue_space(const struct iwl_queue *q);
  204. /*****************************************************
  205. * Error handling
  206. ******************************************************/
  207. int iwl_dump_nic_event_log(struct iwl_trans *trans, bool full_log,
  208. char **buf, bool display);
  209. int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display);
  210. void iwl_dump_csr(struct iwl_trans *trans);
  211. /*****************************************************
  212. * Helpers
  213. ******************************************************/
  214. static inline void iwl_disable_interrupts(struct iwl_trans *trans)
  215. {
  216. clear_bit(STATUS_INT_ENABLED, &trans->shrd->status);
  217. /* disable interrupts from uCode/NIC to host */
  218. iwl_write32(bus(trans), CSR_INT_MASK, 0x00000000);
  219. /* acknowledge/clear/reset any interrupts still pending
  220. * from uCode or flow handler (Rx/Tx DMA) */
  221. iwl_write32(bus(trans), CSR_INT, 0xffffffff);
  222. iwl_write32(bus(trans), CSR_FH_INT_STATUS, 0xffffffff);
  223. IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
  224. }
  225. static inline void iwl_enable_interrupts(struct iwl_trans *trans)
  226. {
  227. struct iwl_trans_pcie *trans_pcie =
  228. IWL_TRANS_GET_PCIE_TRANS(trans);
  229. IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
  230. set_bit(STATUS_INT_ENABLED, &trans->shrd->status);
  231. iwl_write32(bus(trans), CSR_INT_MASK, trans_pcie->inta_mask);
  232. }
  233. /*
  234. * we have 8 bits used like this:
  235. *
  236. * 7 6 5 4 3 2 1 0
  237. * | | | | | | | |
  238. * | | | | | | +-+-------- AC queue (0-3)
  239. * | | | | | |
  240. * | +-+-+-+-+------------ HW queue ID
  241. * |
  242. * +---------------------- unused
  243. */
  244. static inline void iwl_set_swq_id(struct iwl_tx_queue *txq, u8 ac, u8 hwq)
  245. {
  246. BUG_ON(ac > 3); /* only have 2 bits */
  247. BUG_ON(hwq > 31); /* only use 5 bits */
  248. txq->swq_id = (hwq << 2) | ac;
  249. }
  250. static inline void iwl_wake_queue(struct iwl_trans *trans,
  251. struct iwl_tx_queue *txq)
  252. {
  253. u8 queue = txq->swq_id;
  254. u8 ac = queue & 3;
  255. u8 hwq = (queue >> 2) & 0x1f;
  256. struct iwl_trans_pcie *trans_pcie =
  257. IWL_TRANS_GET_PCIE_TRANS(trans);
  258. if (unlikely(!trans->shrd->mac80211_registered))
  259. return;
  260. if (test_and_clear_bit(hwq, trans_pcie->queue_stopped))
  261. if (atomic_dec_return(&trans_pcie->queue_stop_count[ac]) <= 0)
  262. ieee80211_wake_queue(trans->shrd->hw, ac);
  263. }
  264. static inline void iwl_stop_queue(struct iwl_trans *trans,
  265. struct iwl_tx_queue *txq)
  266. {
  267. u8 queue = txq->swq_id;
  268. u8 ac = queue & 3;
  269. u8 hwq = (queue >> 2) & 0x1f;
  270. struct iwl_trans_pcie *trans_pcie =
  271. IWL_TRANS_GET_PCIE_TRANS(trans);
  272. if (unlikely(!trans->shrd->mac80211_registered))
  273. return;
  274. if (!test_and_set_bit(hwq, trans_pcie->queue_stopped))
  275. if (atomic_inc_return(&trans_pcie->queue_stop_count[ac]) > 0)
  276. ieee80211_stop_queue(trans->shrd->hw, ac);
  277. }
  278. #ifdef ieee80211_stop_queue
  279. #undef ieee80211_stop_queue
  280. #endif
  281. #define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
  282. #ifdef ieee80211_wake_queue
  283. #undef ieee80211_wake_queue
  284. #endif
  285. #define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
  286. static inline void iwl_txq_ctx_activate(struct iwl_trans_pcie *trans_pcie,
  287. int txq_id)
  288. {
  289. set_bit(txq_id, &trans_pcie->txq_ctx_active_msk);
  290. }
  291. static inline void iwl_txq_ctx_deactivate(struct iwl_trans_pcie *trans_pcie,
  292. int txq_id)
  293. {
  294. clear_bit(txq_id, &trans_pcie->txq_ctx_active_msk);
  295. }
  296. static inline int iwl_queue_used(const struct iwl_queue *q, int i)
  297. {
  298. return q->write_ptr >= q->read_ptr ?
  299. (i >= q->read_ptr && i < q->write_ptr) :
  300. !(i < q->read_ptr && i >= q->write_ptr);
  301. }
  302. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
  303. {
  304. return index & (q->n_window - 1);
  305. }
  306. #endif /* __iwl_trans_int_pcie_h__ */