internal.h 22 KB

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