internal.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2015 Intel Corporation. All rights reserved.
  4. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  5. * Copyright(c) 2016 Intel Deutschland GmbH
  6. *
  7. * Portions of this file are derived from the ipw3945 project, as well
  8. * as portions of the ieee80211 subsystem header files.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  22. *
  23. * The full GNU General Public License is included in this distribution in the
  24. * file called LICENSE.
  25. *
  26. * Contact Information:
  27. * Intel Linux Wireless <linuxwifi@intel.com>
  28. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  29. *
  30. *****************************************************************************/
  31. #ifndef __iwl_trans_int_pcie_h__
  32. #define __iwl_trans_int_pcie_h__
  33. #include <linux/spinlock.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/wait.h>
  37. #include <linux/pci.h>
  38. #include <linux/timer.h>
  39. #include "iwl-fh.h"
  40. #include "iwl-csr.h"
  41. #include "iwl-trans.h"
  42. #include "iwl-debug.h"
  43. #include "iwl-io.h"
  44. #include "iwl-op-mode.h"
  45. /* We need 2 entries for the TX command and header, and another one might
  46. * be needed for potential data in the SKB's head. The remaining ones can
  47. * be used for frags.
  48. */
  49. #define IWL_PCIE_MAX_FRAGS (IWL_NUM_OF_TBS - 3)
  50. /*
  51. * RX related structures and functions
  52. */
  53. #define RX_NUM_QUEUES 1
  54. #define RX_POST_REQ_ALLOC 2
  55. #define RX_CLAIM_REQ_ALLOC 8
  56. #define RX_PENDING_WATERMARK 16
  57. struct iwl_host_cmd;
  58. /*This file includes the declaration that are internal to the
  59. * trans_pcie layer */
  60. /**
  61. * struct iwl_rx_mem_buffer
  62. * @page_dma: bus address of rxb page
  63. * @page: driver's pointer to the rxb page
  64. * @invalid: rxb is in driver ownership - not owned by HW
  65. * @vid: index of this rxb in the global table
  66. */
  67. struct iwl_rx_mem_buffer {
  68. dma_addr_t page_dma;
  69. struct page *page;
  70. u16 vid;
  71. bool invalid;
  72. struct list_head list;
  73. };
  74. /**
  75. * struct isr_statistics - interrupt statistics
  76. *
  77. */
  78. struct isr_statistics {
  79. u32 hw;
  80. u32 sw;
  81. u32 err_code;
  82. u32 sch;
  83. u32 alive;
  84. u32 rfkill;
  85. u32 ctkill;
  86. u32 wakeup;
  87. u32 rx;
  88. u32 tx;
  89. u32 unhandled;
  90. };
  91. /**
  92. * struct iwl_rxq - Rx queue
  93. * @id: queue index
  94. * @bd: driver's pointer to buffer of receive buffer descriptors (rbd).
  95. * Address size is 32 bit in pre-9000 devices and 64 bit in 9000 devices.
  96. * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
  97. * @ubd: driver's pointer to buffer of used receive buffer descriptors (rbd)
  98. * @ubd_dma: physical address of buffer of used receive buffer descriptors (rbd)
  99. * @read: Shared index to newest available Rx buffer
  100. * @write: Shared index to oldest written Rx packet
  101. * @free_count: Number of pre-allocated buffers in rx_free
  102. * @used_count: Number of RBDs handled to allocator to use for allocation
  103. * @write_actual:
  104. * @rx_free: list of RBDs with allocated RB ready for use
  105. * @rx_used: list of RBDs with no RB attached
  106. * @need_update: flag to indicate we need to update read/write index
  107. * @rb_stts: driver's pointer to receive buffer status
  108. * @rb_stts_dma: bus address of receive buffer status
  109. * @lock:
  110. * @queue: actual rx queue. Not used for multi-rx queue.
  111. *
  112. * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
  113. */
  114. struct iwl_rxq {
  115. int id;
  116. void *bd;
  117. dma_addr_t bd_dma;
  118. __le32 *used_bd;
  119. dma_addr_t used_bd_dma;
  120. u32 read;
  121. u32 write;
  122. u32 free_count;
  123. u32 used_count;
  124. u32 write_actual;
  125. u32 queue_size;
  126. struct list_head rx_free;
  127. struct list_head rx_used;
  128. bool need_update;
  129. struct iwl_rb_status *rb_stts;
  130. dma_addr_t rb_stts_dma;
  131. spinlock_t lock;
  132. struct napi_struct napi;
  133. struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
  134. };
  135. /**
  136. * struct iwl_rb_allocator - Rx allocator
  137. * @req_pending: number of requests the allcator had not processed yet
  138. * @req_ready: number of requests honored and ready for claiming
  139. * @rbd_allocated: RBDs with pages allocated and ready to be handled to
  140. * the queue. This is a list of &struct iwl_rx_mem_buffer
  141. * @rbd_empty: RBDs with no page attached for allocator use. This is a list
  142. * of &struct iwl_rx_mem_buffer
  143. * @lock: protects the rbd_allocated and rbd_empty lists
  144. * @alloc_wq: work queue for background calls
  145. * @rx_alloc: work struct for background calls
  146. */
  147. struct iwl_rb_allocator {
  148. atomic_t req_pending;
  149. atomic_t req_ready;
  150. struct list_head rbd_allocated;
  151. struct list_head rbd_empty;
  152. spinlock_t lock;
  153. struct workqueue_struct *alloc_wq;
  154. struct work_struct rx_alloc;
  155. };
  156. struct iwl_dma_ptr {
  157. dma_addr_t dma;
  158. void *addr;
  159. size_t size;
  160. };
  161. /**
  162. * iwl_queue_inc_wrap - increment queue index, wrap back to beginning
  163. * @index -- current index
  164. */
  165. static inline int iwl_queue_inc_wrap(int index)
  166. {
  167. return ++index & (TFD_QUEUE_SIZE_MAX - 1);
  168. }
  169. /**
  170. * iwl_queue_dec_wrap - decrement queue index, wrap back to end
  171. * @index -- current index
  172. */
  173. static inline int iwl_queue_dec_wrap(int index)
  174. {
  175. return --index & (TFD_QUEUE_SIZE_MAX - 1);
  176. }
  177. struct iwl_cmd_meta {
  178. /* only for SYNC commands, iff the reply skb is wanted */
  179. struct iwl_host_cmd *source;
  180. u32 flags;
  181. };
  182. /*
  183. * Generic queue structure
  184. *
  185. * Contains common data for Rx and Tx queues.
  186. *
  187. * Note the difference between TFD_QUEUE_SIZE_MAX and n_window: the hardware
  188. * always assumes 256 descriptors, so TFD_QUEUE_SIZE_MAX is always 256 (unless
  189. * there might be HW changes in the future). For the normal TX
  190. * queues, n_window, which is the size of the software queue data
  191. * is also 256; however, for the command queue, n_window is only
  192. * 32 since we don't need so many commands pending. Since the HW
  193. * still uses 256 BDs for DMA though, TFD_QUEUE_SIZE_MAX stays 256. As a result,
  194. * the software buffers (in the variables @meta, @txb in struct
  195. * iwl_txq) only have 32 entries, while the HW buffers (@tfds in
  196. * the same struct) have 256.
  197. * This means that we end up with the following:
  198. * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
  199. * SW entries: | 0 | ... | 31 |
  200. * where N is a number between 0 and 7. This means that the SW
  201. * data is a window overlayed over the HW queue.
  202. */
  203. struct iwl_queue {
  204. int write_ptr; /* 1-st empty entry (index) host_w*/
  205. int read_ptr; /* last used entry (index) host_r*/
  206. /* use for monitoring and recovering the stuck queue */
  207. dma_addr_t dma_addr; /* physical addr for BD's */
  208. int n_window; /* safe queue window */
  209. u32 id;
  210. int low_mark; /* low watermark, resume queue if free
  211. * space more than this */
  212. int high_mark; /* high watermark, stop queue if free
  213. * space less than this */
  214. };
  215. #define TFD_TX_CMD_SLOTS 256
  216. #define TFD_CMD_SLOTS 32
  217. /*
  218. * The FH will write back to the first TB only, so we need to copy some data
  219. * into the buffer regardless of whether it should be mapped or not.
  220. * This indicates how big the first TB must be to include the scratch buffer
  221. * and the assigned PN.
  222. * Since PN location is 16 bytes at offset 24, it's 40 now.
  223. * If we make it bigger then allocations will be bigger and copy slower, so
  224. * that's probably not useful.
  225. */
  226. #define IWL_FIRST_TB_SIZE 40
  227. #define IWL_FIRST_TB_SIZE_ALIGN ALIGN(IWL_FIRST_TB_SIZE, 64)
  228. struct iwl_pcie_txq_entry {
  229. struct iwl_device_cmd *cmd;
  230. struct sk_buff *skb;
  231. /* buffer to free after command completes */
  232. const void *free_buf;
  233. struct iwl_cmd_meta meta;
  234. };
  235. struct iwl_pcie_first_tb_buf {
  236. u8 buf[IWL_FIRST_TB_SIZE_ALIGN];
  237. };
  238. /**
  239. * struct iwl_txq - Tx Queue for DMA
  240. * @q: generic Rx/Tx queue descriptor
  241. * @tfds: transmit frame descriptors (DMA memory)
  242. * @first_tb_bufs: start of command headers, including scratch buffers, for
  243. * the writeback -- this is DMA memory and an array holding one buffer
  244. * for each command on the queue
  245. * @first_tb_dma: DMA address for the first_tb_bufs start
  246. * @entries: transmit entries (driver state)
  247. * @lock: queue lock
  248. * @stuck_timer: timer that fires if queue gets stuck
  249. * @trans_pcie: pointer back to transport (for timer)
  250. * @need_update: indicates need to update read/write index
  251. * @active: stores if queue is active
  252. * @ampdu: true if this queue is an ampdu queue for an specific RA/TID
  253. * @wd_timeout: queue watchdog timeout (jiffies) - per queue
  254. * @frozen: tx stuck queue timer is frozen
  255. * @frozen_expiry_remainder: remember how long until the timer fires
  256. *
  257. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  258. * descriptors) and required locking structures.
  259. */
  260. struct iwl_txq {
  261. struct iwl_queue q;
  262. struct iwl_tfd *tfds;
  263. struct iwl_pcie_first_tb_buf *first_tb_bufs;
  264. dma_addr_t first_tb_dma;
  265. struct iwl_pcie_txq_entry *entries;
  266. spinlock_t lock;
  267. unsigned long frozen_expiry_remainder;
  268. struct timer_list stuck_timer;
  269. struct iwl_trans_pcie *trans_pcie;
  270. bool need_update;
  271. bool frozen;
  272. u8 active;
  273. bool ampdu;
  274. bool block;
  275. unsigned long wd_timeout;
  276. struct sk_buff_head overflow_q;
  277. };
  278. static inline dma_addr_t
  279. iwl_pcie_get_first_tb_dma(struct iwl_txq *txq, int idx)
  280. {
  281. return txq->first_tb_dma +
  282. sizeof(struct iwl_pcie_first_tb_buf) * idx;
  283. }
  284. struct iwl_tso_hdr_page {
  285. struct page *page;
  286. u8 *pos;
  287. };
  288. /**
  289. * struct iwl_trans_pcie - PCIe transport specific data
  290. * @rxq: all the RX queue data
  291. * @rx_pool: initial pool of iwl_rx_mem_buffer for all the queues
  292. * @global_table: table mapping received VID from hw to rxb
  293. * @rba: allocator for RX replenishing
  294. * @trans: pointer to the generic transport area
  295. * @scd_base_addr: scheduler sram base address in SRAM
  296. * @scd_bc_tbls: pointer to the byte count table of the scheduler
  297. * @kw: keep warm address
  298. * @pci_dev: basic pci-network driver stuff
  299. * @hw_base: pci hardware address support
  300. * @ucode_write_complete: indicates that the ucode has been copied.
  301. * @ucode_write_waitq: wait queue for uCode load
  302. * @cmd_queue - command queue number
  303. * @rx_buf_size: Rx buffer size
  304. * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
  305. * @scd_set_active: should the transport configure the SCD for HCMD queue
  306. * @wide_cmd_header: true when ucode supports wide command header format
  307. * @sw_csum_tx: if true, then the transport will compute the csum of the TXed
  308. * frame.
  309. * @rx_page_order: page order for receive buffer size
  310. * @reg_lock: protect hw register access
  311. * @mutex: to protect stop_device / start_fw / start_hw
  312. * @cmd_in_flight: true when we have a host command in flight
  313. * @fw_mon_phys: physical address of the buffer for the firmware monitor
  314. * @fw_mon_page: points to the first page of the buffer for the firmware monitor
  315. * @fw_mon_size: size of the buffer for the firmware monitor
  316. * @msix_entries: array of MSI-X entries
  317. * @msix_enabled: true if managed to enable MSI-X
  318. * @allocated_vector: the number of interrupt vector allocated by the OS
  319. * @default_irq_num: default irq for non rx interrupt
  320. * @fh_init_mask: initial unmasked fh causes
  321. * @hw_init_mask: initial unmasked hw causes
  322. * @fh_mask: current unmasked fh causes
  323. * @hw_mask: current unmasked hw causes
  324. */
  325. struct iwl_trans_pcie {
  326. struct iwl_rxq *rxq;
  327. struct iwl_rx_mem_buffer rx_pool[RX_POOL_SIZE];
  328. struct iwl_rx_mem_buffer *global_table[RX_POOL_SIZE];
  329. struct iwl_rb_allocator rba;
  330. struct iwl_trans *trans;
  331. struct net_device napi_dev;
  332. struct __percpu iwl_tso_hdr_page *tso_hdr_page;
  333. /* INT ICT Table */
  334. __le32 *ict_tbl;
  335. dma_addr_t ict_tbl_dma;
  336. int ict_index;
  337. bool use_ict;
  338. bool is_down;
  339. struct isr_statistics isr_stats;
  340. spinlock_t irq_lock;
  341. struct mutex mutex;
  342. u32 inta_mask;
  343. u32 scd_base_addr;
  344. struct iwl_dma_ptr scd_bc_tbls;
  345. struct iwl_dma_ptr kw;
  346. struct iwl_txq *txq;
  347. unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  348. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
  349. /* PCI bus related data */
  350. struct pci_dev *pci_dev;
  351. void __iomem *hw_base;
  352. bool ucode_write_complete;
  353. wait_queue_head_t ucode_write_waitq;
  354. wait_queue_head_t wait_command_queue;
  355. wait_queue_head_t d0i3_waitq;
  356. u8 page_offs, dev_cmd_offs;
  357. u8 cmd_queue;
  358. u8 cmd_fifo;
  359. unsigned int cmd_q_wdg_timeout;
  360. u8 n_no_reclaim_cmds;
  361. u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
  362. enum iwl_amsdu_size rx_buf_size;
  363. bool bc_table_dword;
  364. bool scd_set_active;
  365. bool wide_cmd_header;
  366. bool sw_csum_tx;
  367. u32 rx_page_order;
  368. /*protect hw register */
  369. spinlock_t reg_lock;
  370. bool cmd_hold_nic_awake;
  371. bool ref_cmd_in_flight;
  372. dma_addr_t fw_mon_phys;
  373. struct page *fw_mon_page;
  374. u32 fw_mon_size;
  375. struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES];
  376. bool msix_enabled;
  377. u32 allocated_vector;
  378. u32 default_irq_num;
  379. u32 fh_init_mask;
  380. u32 hw_init_mask;
  381. u32 fh_mask;
  382. u32 hw_mask;
  383. };
  384. static inline struct iwl_trans_pcie *
  385. IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans *trans)
  386. {
  387. return (void *)trans->trans_specific;
  388. }
  389. static inline struct iwl_trans *
  390. iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
  391. {
  392. return container_of((void *)trans_pcie, struct iwl_trans,
  393. trans_specific);
  394. }
  395. /*
  396. * Convention: trans API functions: iwl_trans_pcie_XXX
  397. * Other functions: iwl_pcie_XXX
  398. */
  399. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  400. const struct pci_device_id *ent,
  401. const struct iwl_cfg *cfg);
  402. void iwl_trans_pcie_free(struct iwl_trans *trans);
  403. /*****************************************************
  404. * RX
  405. ******************************************************/
  406. int iwl_pcie_rx_init(struct iwl_trans *trans);
  407. irqreturn_t iwl_pcie_msix_isr(int irq, void *data);
  408. irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
  409. irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id);
  410. irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id);
  411. int iwl_pcie_rx_stop(struct iwl_trans *trans);
  412. void iwl_pcie_rx_free(struct iwl_trans *trans);
  413. /*****************************************************
  414. * ICT - interrupt handling
  415. ******************************************************/
  416. irqreturn_t iwl_pcie_isr(int irq, void *data);
  417. int iwl_pcie_alloc_ict(struct iwl_trans *trans);
  418. void iwl_pcie_free_ict(struct iwl_trans *trans);
  419. void iwl_pcie_reset_ict(struct iwl_trans *trans);
  420. void iwl_pcie_disable_ict(struct iwl_trans *trans);
  421. /*****************************************************
  422. * TX / HCMD
  423. ******************************************************/
  424. int iwl_pcie_tx_init(struct iwl_trans *trans);
  425. void iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
  426. int iwl_pcie_tx_stop(struct iwl_trans *trans);
  427. void iwl_pcie_tx_free(struct iwl_trans *trans);
  428. void iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int queue, u16 ssn,
  429. const struct iwl_trans_txq_scd_cfg *cfg,
  430. unsigned int wdg_timeout);
  431. void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue,
  432. bool configure_scd);
  433. void iwl_trans_pcie_txq_set_shared_mode(struct iwl_trans *trans, u32 txq_id,
  434. bool shared_mode);
  435. void iwl_trans_pcie_log_scd_error(struct iwl_trans *trans,
  436. struct iwl_txq *txq);
  437. int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
  438. struct iwl_device_cmd *dev_cmd, int txq_id);
  439. void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans);
  440. int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  441. void iwl_pcie_hcmd_complete(struct iwl_trans *trans,
  442. struct iwl_rx_cmd_buffer *rxb);
  443. void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
  444. struct sk_buff_head *skbs);
  445. void iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
  446. static inline u16 iwl_pcie_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  447. {
  448. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  449. return le16_to_cpu(tb->hi_n_len) >> 4;
  450. }
  451. /*****************************************************
  452. * Error handling
  453. ******************************************************/
  454. void iwl_pcie_dump_csr(struct iwl_trans *trans);
  455. /*****************************************************
  456. * Helpers
  457. ******************************************************/
  458. static inline void _iwl_disable_interrupts(struct iwl_trans *trans)
  459. {
  460. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  461. clear_bit(STATUS_INT_ENABLED, &trans->status);
  462. if (!trans_pcie->msix_enabled) {
  463. /* disable interrupts from uCode/NIC to host */
  464. iwl_write32(trans, CSR_INT_MASK, 0x00000000);
  465. /* acknowledge/clear/reset any interrupts still pending
  466. * from uCode or flow handler (Rx/Tx DMA) */
  467. iwl_write32(trans, CSR_INT, 0xffffffff);
  468. iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
  469. } else {
  470. /* disable all the interrupt we might use */
  471. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  472. trans_pcie->fh_init_mask);
  473. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  474. trans_pcie->hw_init_mask);
  475. }
  476. IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
  477. }
  478. static inline void iwl_disable_interrupts(struct iwl_trans *trans)
  479. {
  480. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  481. spin_lock(&trans_pcie->irq_lock);
  482. _iwl_disable_interrupts(trans);
  483. spin_unlock(&trans_pcie->irq_lock);
  484. }
  485. static inline void _iwl_enable_interrupts(struct iwl_trans *trans)
  486. {
  487. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  488. IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
  489. set_bit(STATUS_INT_ENABLED, &trans->status);
  490. if (!trans_pcie->msix_enabled) {
  491. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  492. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  493. } else {
  494. /*
  495. * fh/hw_mask keeps all the unmasked causes.
  496. * Unlike msi, in msix cause is enabled when it is unset.
  497. */
  498. trans_pcie->hw_mask = trans_pcie->hw_init_mask;
  499. trans_pcie->fh_mask = trans_pcie->fh_init_mask;
  500. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  501. ~trans_pcie->fh_mask);
  502. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  503. ~trans_pcie->hw_mask);
  504. }
  505. }
  506. static inline void iwl_enable_interrupts(struct iwl_trans *trans)
  507. {
  508. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  509. spin_lock(&trans_pcie->irq_lock);
  510. _iwl_enable_interrupts(trans);
  511. spin_unlock(&trans_pcie->irq_lock);
  512. }
  513. static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk)
  514. {
  515. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  516. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk);
  517. trans_pcie->hw_mask = msk;
  518. }
  519. static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk)
  520. {
  521. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  522. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk);
  523. trans_pcie->fh_mask = msk;
  524. }
  525. static inline void iwl_enable_fw_load_int(struct iwl_trans *trans)
  526. {
  527. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  528. IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n");
  529. if (!trans_pcie->msix_enabled) {
  530. trans_pcie->inta_mask = CSR_INT_BIT_FH_TX;
  531. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  532. } else {
  533. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  534. trans_pcie->hw_init_mask);
  535. iwl_enable_fh_int_msk_msix(trans,
  536. MSIX_FH_INT_CAUSES_D2S_CH0_NUM);
  537. }
  538. }
  539. static inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
  540. {
  541. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  542. IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
  543. if (!trans_pcie->msix_enabled) {
  544. trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL;
  545. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  546. } else {
  547. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  548. trans_pcie->fh_init_mask);
  549. iwl_enable_hw_int_msk_msix(trans,
  550. MSIX_HW_INT_CAUSES_REG_RF_KILL);
  551. }
  552. }
  553. static inline void iwl_wake_queue(struct iwl_trans *trans,
  554. struct iwl_txq *txq)
  555. {
  556. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  557. if (test_and_clear_bit(txq->q.id, trans_pcie->queue_stopped)) {
  558. IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->q.id);
  559. iwl_op_mode_queue_not_full(trans->op_mode, txq->q.id);
  560. }
  561. }
  562. static inline void iwl_stop_queue(struct iwl_trans *trans,
  563. struct iwl_txq *txq)
  564. {
  565. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  566. if (!test_and_set_bit(txq->q.id, trans_pcie->queue_stopped)) {
  567. iwl_op_mode_queue_full(trans->op_mode, txq->q.id);
  568. IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->q.id);
  569. } else
  570. IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
  571. txq->q.id);
  572. }
  573. static inline bool iwl_queue_used(const struct iwl_queue *q, int i)
  574. {
  575. return q->write_ptr >= q->read_ptr ?
  576. (i >= q->read_ptr && i < q->write_ptr) :
  577. !(i < q->read_ptr && i >= q->write_ptr);
  578. }
  579. static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
  580. {
  581. return index & (q->n_window - 1);
  582. }
  583. static inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
  584. {
  585. return !(iwl_read32(trans, CSR_GP_CNTRL) &
  586. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
  587. }
  588. static inline void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
  589. u32 reg, u32 mask, u32 value)
  590. {
  591. u32 v;
  592. #ifdef CONFIG_IWLWIFI_DEBUG
  593. WARN_ON_ONCE(value & ~mask);
  594. #endif
  595. v = iwl_read32(trans, reg);
  596. v &= ~mask;
  597. v |= value;
  598. iwl_write32(trans, reg, v);
  599. }
  600. static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
  601. u32 reg, u32 mask)
  602. {
  603. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
  604. }
  605. static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
  606. u32 reg, u32 mask)
  607. {
  608. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
  609. }
  610. void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state);
  611. #ifdef CONFIG_IWLWIFI_DEBUGFS
  612. int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans);
  613. #else
  614. static inline int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
  615. {
  616. return 0;
  617. }
  618. #endif
  619. int iwl_pci_fw_exit_d0i3(struct iwl_trans *trans);
  620. int iwl_pci_fw_enter_d0i3(struct iwl_trans *trans);
  621. void iwl_pcie_enable_rx_wake(struct iwl_trans *trans, bool enable);
  622. #endif /* __iwl_trans_int_pcie_h__ */