internal.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 - 2017 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 8 bytes at offset 12, it's 20 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 20
  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. * @ampdu: true if this queue is an ampdu queue for an specific RA/TID
  221. * @wd_timeout: queue watchdog timeout (jiffies) - per queue
  222. * @frozen: tx stuck queue timer is frozen
  223. * @frozen_expiry_remainder: remember how long until the timer fires
  224. * @bc_tbl: byte count table of the queue (relevant only for gen2 transport)
  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. bool ampdu;
  261. int block;
  262. unsigned long wd_timeout;
  263. struct sk_buff_head overflow_q;
  264. struct iwl_dma_ptr bc_tbl;
  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_dram_data
  294. * @physical: page phy pointer
  295. * @block: pointer to the allocated block/page
  296. * @size: size of the block/page
  297. */
  298. struct iwl_dram_data {
  299. dma_addr_t physical;
  300. void *block;
  301. int size;
  302. };
  303. /**
  304. * struct iwl_self_init_dram - dram data used by self init process
  305. * @fw: lmac and umac dram data
  306. * @fw_cnt: total number of items in array
  307. * @paging: paging dram data
  308. * @paging_cnt: total number of items in array
  309. */
  310. struct iwl_self_init_dram {
  311. struct iwl_dram_data *fw;
  312. int fw_cnt;
  313. struct iwl_dram_data *paging;
  314. int paging_cnt;
  315. };
  316. /**
  317. * struct iwl_trans_pcie - PCIe transport specific data
  318. * @rxq: all the RX queue data
  319. * @rx_pool: initial pool of iwl_rx_mem_buffer for all the queues
  320. * @global_table: table mapping received VID from hw to rxb
  321. * @rba: allocator for RX replenishing
  322. * @ctxt_info: context information for FW self init
  323. * @ctxt_info_dma_addr: dma addr of context information
  324. * @init_dram: DRAM data of firmware image (including paging).
  325. * Context information addresses will be taken from here.
  326. * This is driver's local copy for keeping track of size and
  327. * count for allocating and freeing the memory.
  328. * @trans: pointer to the generic transport area
  329. * @scd_base_addr: scheduler sram base address in SRAM
  330. * @scd_bc_tbls: pointer to the byte count table of the scheduler
  331. * @kw: keep warm address
  332. * @pci_dev: basic pci-network driver stuff
  333. * @hw_base: pci hardware address support
  334. * @ucode_write_complete: indicates that the ucode has been copied.
  335. * @ucode_write_waitq: wait queue for uCode load
  336. * @cmd_queue - command queue number
  337. * @rx_buf_size: Rx buffer size
  338. * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
  339. * @scd_set_active: should the transport configure the SCD for HCMD queue
  340. * @sw_csum_tx: if true, then the transport will compute the csum of the TXed
  341. * frame.
  342. * @rx_page_order: page order for receive buffer size
  343. * @reg_lock: protect hw register access
  344. * @mutex: to protect stop_device / start_fw / start_hw
  345. * @cmd_in_flight: true when we have a host command in flight
  346. * @fw_mon_phys: physical address of the buffer for the firmware monitor
  347. * @fw_mon_page: points to the first page of the buffer for the firmware monitor
  348. * @fw_mon_size: size of the buffer for the firmware monitor
  349. * @msix_entries: array of MSI-X entries
  350. * @msix_enabled: true if managed to enable MSI-X
  351. * @shared_vec_mask: the type of causes the shared vector handles
  352. * (see iwl_shared_irq_flags).
  353. * @alloc_vecs: the number of interrupt vectors allocated by the OS
  354. * @def_irq: default irq for non rx causes
  355. * @fh_init_mask: initial unmasked fh causes
  356. * @hw_init_mask: initial unmasked hw causes
  357. * @fh_mask: current unmasked fh causes
  358. * @hw_mask: current unmasked hw causes
  359. */
  360. struct iwl_trans_pcie {
  361. struct iwl_rxq *rxq;
  362. struct iwl_rx_mem_buffer rx_pool[RX_POOL_SIZE];
  363. struct iwl_rx_mem_buffer *global_table[RX_POOL_SIZE];
  364. struct iwl_rb_allocator rba;
  365. struct iwl_context_info *ctxt_info;
  366. dma_addr_t ctxt_info_dma_addr;
  367. struct iwl_self_init_dram init_dram;
  368. struct iwl_trans *trans;
  369. struct net_device napi_dev;
  370. struct __percpu iwl_tso_hdr_page *tso_hdr_page;
  371. /* INT ICT Table */
  372. __le32 *ict_tbl;
  373. dma_addr_t ict_tbl_dma;
  374. int ict_index;
  375. bool use_ict;
  376. bool is_down, opmode_down;
  377. bool debug_rfkill;
  378. struct isr_statistics isr_stats;
  379. spinlock_t irq_lock;
  380. struct mutex mutex;
  381. u32 inta_mask;
  382. u32 scd_base_addr;
  383. struct iwl_dma_ptr scd_bc_tbls;
  384. struct iwl_dma_ptr kw;
  385. struct iwl_txq *txq_memory;
  386. struct iwl_txq *txq[IWL_MAX_TVQM_QUEUES];
  387. unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  388. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  389. /* PCI bus related data */
  390. struct pci_dev *pci_dev;
  391. void __iomem *hw_base;
  392. bool ucode_write_complete;
  393. wait_queue_head_t ucode_write_waitq;
  394. wait_queue_head_t wait_command_queue;
  395. wait_queue_head_t d0i3_waitq;
  396. u8 page_offs, dev_cmd_offs;
  397. u8 cmd_queue;
  398. u8 cmd_fifo;
  399. unsigned int cmd_q_wdg_timeout;
  400. u8 n_no_reclaim_cmds;
  401. u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
  402. u8 max_tbs;
  403. u16 tfd_size;
  404. enum iwl_amsdu_size rx_buf_size;
  405. bool bc_table_dword;
  406. bool scd_set_active;
  407. bool sw_csum_tx;
  408. u32 rx_page_order;
  409. /*protect hw register */
  410. spinlock_t reg_lock;
  411. bool cmd_hold_nic_awake;
  412. bool ref_cmd_in_flight;
  413. dma_addr_t fw_mon_phys;
  414. struct page *fw_mon_page;
  415. u32 fw_mon_size;
  416. struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES];
  417. bool msix_enabled;
  418. u8 shared_vec_mask;
  419. u32 alloc_vecs;
  420. u32 def_irq;
  421. u32 fh_init_mask;
  422. u32 hw_init_mask;
  423. u32 fh_mask;
  424. u32 hw_mask;
  425. cpumask_t affinity_mask[IWL_MAX_RX_HW_QUEUES];
  426. };
  427. static inline struct iwl_trans_pcie *
  428. IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans *trans)
  429. {
  430. return (void *)trans->trans_specific;
  431. }
  432. static inline struct iwl_trans *
  433. iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
  434. {
  435. return container_of((void *)trans_pcie, struct iwl_trans,
  436. trans_specific);
  437. }
  438. /*
  439. * Convention: trans API functions: iwl_trans_pcie_XXX
  440. * Other functions: iwl_pcie_XXX
  441. */
  442. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  443. const struct pci_device_id *ent,
  444. const struct iwl_cfg *cfg);
  445. void iwl_trans_pcie_free(struct iwl_trans *trans);
  446. /*****************************************************
  447. * RX
  448. ******************************************************/
  449. int iwl_pcie_rx_init(struct iwl_trans *trans);
  450. int iwl_pcie_gen2_rx_init(struct iwl_trans *trans);
  451. irqreturn_t iwl_pcie_msix_isr(int irq, void *data);
  452. irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
  453. irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id);
  454. irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id);
  455. int iwl_pcie_rx_stop(struct iwl_trans *trans);
  456. void iwl_pcie_rx_free(struct iwl_trans *trans);
  457. /*****************************************************
  458. * ICT - interrupt handling
  459. ******************************************************/
  460. irqreturn_t iwl_pcie_isr(int irq, void *data);
  461. int iwl_pcie_alloc_ict(struct iwl_trans *trans);
  462. void iwl_pcie_free_ict(struct iwl_trans *trans);
  463. void iwl_pcie_reset_ict(struct iwl_trans *trans);
  464. void iwl_pcie_disable_ict(struct iwl_trans *trans);
  465. /*****************************************************
  466. * TX / HCMD
  467. ******************************************************/
  468. int iwl_pcie_tx_init(struct iwl_trans *trans);
  469. int iwl_pcie_gen2_tx_init(struct iwl_trans *trans);
  470. void iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
  471. int iwl_pcie_tx_stop(struct iwl_trans *trans);
  472. void iwl_pcie_tx_free(struct iwl_trans *trans);
  473. bool iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int queue, u16 ssn,
  474. const struct iwl_trans_txq_scd_cfg *cfg,
  475. unsigned int wdg_timeout);
  476. void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue,
  477. bool configure_scd);
  478. void iwl_trans_pcie_txq_set_shared_mode(struct iwl_trans *trans, u32 txq_id,
  479. bool shared_mode);
  480. void iwl_trans_pcie_log_scd_error(struct iwl_trans *trans,
  481. struct iwl_txq *txq);
  482. int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
  483. struct iwl_device_cmd *dev_cmd, int txq_id);
  484. void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans);
  485. int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  486. void iwl_pcie_hcmd_complete(struct iwl_trans *trans,
  487. struct iwl_rx_cmd_buffer *rxb);
  488. void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
  489. struct sk_buff_head *skbs);
  490. void iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
  491. static inline u16 iwl_pcie_tfd_tb_get_len(struct iwl_trans *trans, void *_tfd,
  492. u8 idx)
  493. {
  494. if (trans->cfg->use_tfh) {
  495. struct iwl_tfh_tfd *tfd = _tfd;
  496. struct iwl_tfh_tb *tb = &tfd->tbs[idx];
  497. return le16_to_cpu(tb->tb_len);
  498. } else {
  499. struct iwl_tfd *tfd = _tfd;
  500. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  501. return le16_to_cpu(tb->hi_n_len) >> 4;
  502. }
  503. }
  504. /*****************************************************
  505. * Error handling
  506. ******************************************************/
  507. void iwl_pcie_dump_csr(struct iwl_trans *trans);
  508. /*****************************************************
  509. * Helpers
  510. ******************************************************/
  511. static inline void _iwl_disable_interrupts(struct iwl_trans *trans)
  512. {
  513. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  514. clear_bit(STATUS_INT_ENABLED, &trans->status);
  515. if (!trans_pcie->msix_enabled) {
  516. /* disable interrupts from uCode/NIC to host */
  517. iwl_write32(trans, CSR_INT_MASK, 0x00000000);
  518. /* acknowledge/clear/reset any interrupts still pending
  519. * from uCode or flow handler (Rx/Tx DMA) */
  520. iwl_write32(trans, CSR_INT, 0xffffffff);
  521. iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
  522. } else {
  523. /* disable all the interrupt we might use */
  524. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  525. trans_pcie->fh_init_mask);
  526. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  527. trans_pcie->hw_init_mask);
  528. }
  529. IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
  530. }
  531. static inline void iwl_disable_interrupts(struct iwl_trans *trans)
  532. {
  533. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  534. spin_lock(&trans_pcie->irq_lock);
  535. _iwl_disable_interrupts(trans);
  536. spin_unlock(&trans_pcie->irq_lock);
  537. }
  538. static inline void _iwl_enable_interrupts(struct iwl_trans *trans)
  539. {
  540. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  541. IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
  542. set_bit(STATUS_INT_ENABLED, &trans->status);
  543. if (!trans_pcie->msix_enabled) {
  544. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  545. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  546. } else {
  547. /*
  548. * fh/hw_mask keeps all the unmasked causes.
  549. * Unlike msi, in msix cause is enabled when it is unset.
  550. */
  551. trans_pcie->hw_mask = trans_pcie->hw_init_mask;
  552. trans_pcie->fh_mask = trans_pcie->fh_init_mask;
  553. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  554. ~trans_pcie->fh_mask);
  555. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  556. ~trans_pcie->hw_mask);
  557. }
  558. }
  559. static inline void iwl_enable_interrupts(struct iwl_trans *trans)
  560. {
  561. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  562. spin_lock(&trans_pcie->irq_lock);
  563. _iwl_enable_interrupts(trans);
  564. spin_unlock(&trans_pcie->irq_lock);
  565. }
  566. static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk)
  567. {
  568. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  569. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk);
  570. trans_pcie->hw_mask = msk;
  571. }
  572. static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk)
  573. {
  574. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  575. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk);
  576. trans_pcie->fh_mask = msk;
  577. }
  578. static inline void iwl_enable_fw_load_int(struct iwl_trans *trans)
  579. {
  580. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  581. IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n");
  582. if (!trans_pcie->msix_enabled) {
  583. trans_pcie->inta_mask = CSR_INT_BIT_FH_TX;
  584. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  585. } else {
  586. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  587. trans_pcie->hw_init_mask);
  588. iwl_enable_fh_int_msk_msix(trans,
  589. MSIX_FH_INT_CAUSES_D2S_CH0_NUM);
  590. }
  591. }
  592. static inline void iwl_pcie_sw_reset(struct iwl_trans *trans)
  593. {
  594. /* Reset entire device - do controller reset (results in SHRD_HW_RST) */
  595. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  596. usleep_range(5000, 6000);
  597. }
  598. static inline u8 iwl_pcie_get_cmd_index(struct iwl_txq *q, u32 index)
  599. {
  600. return index & (q->n_window - 1);
  601. }
  602. static inline void *iwl_pcie_get_tfd(struct iwl_trans_pcie *trans_pcie,
  603. struct iwl_txq *txq, int idx)
  604. {
  605. return txq->tfds + trans_pcie->tfd_size * iwl_pcie_get_cmd_index(txq,
  606. idx);
  607. }
  608. static inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
  609. {
  610. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  611. IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
  612. if (!trans_pcie->msix_enabled) {
  613. trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL;
  614. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  615. } else {
  616. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  617. trans_pcie->fh_init_mask);
  618. iwl_enable_hw_int_msk_msix(trans,
  619. MSIX_HW_INT_CAUSES_REG_RF_KILL);
  620. }
  621. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_9000) {
  622. /*
  623. * On 9000-series devices this bit isn't enabled by default, so
  624. * when we power down the device we need set the bit to allow it
  625. * to wake up the PCI-E bus for RF-kill interrupts.
  626. */
  627. iwl_set_bit(trans, CSR_GP_CNTRL,
  628. CSR_GP_CNTRL_REG_FLAG_RFKILL_WAKE_L1A_EN);
  629. }
  630. }
  631. void iwl_pcie_handle_rfkill_irq(struct iwl_trans *trans);
  632. static inline void iwl_wake_queue(struct iwl_trans *trans,
  633. struct iwl_txq *txq)
  634. {
  635. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  636. if (test_and_clear_bit(txq->id, trans_pcie->queue_stopped)) {
  637. IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->id);
  638. iwl_op_mode_queue_not_full(trans->op_mode, txq->id);
  639. }
  640. }
  641. static inline void iwl_stop_queue(struct iwl_trans *trans,
  642. struct iwl_txq *txq)
  643. {
  644. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  645. if (!test_and_set_bit(txq->id, trans_pcie->queue_stopped)) {
  646. iwl_op_mode_queue_full(trans->op_mode, txq->id);
  647. IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->id);
  648. } else
  649. IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
  650. txq->id);
  651. }
  652. static inline bool iwl_queue_used(const struct iwl_txq *q, int i)
  653. {
  654. return q->write_ptr >= q->read_ptr ?
  655. (i >= q->read_ptr && i < q->write_ptr) :
  656. !(i < q->read_ptr && i >= q->write_ptr);
  657. }
  658. static inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
  659. {
  660. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  661. lockdep_assert_held(&trans_pcie->mutex);
  662. if (trans_pcie->debug_rfkill)
  663. return true;
  664. return !(iwl_read32(trans, CSR_GP_CNTRL) &
  665. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
  666. }
  667. static inline void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
  668. u32 reg, u32 mask, u32 value)
  669. {
  670. u32 v;
  671. #ifdef CONFIG_IWLWIFI_DEBUG
  672. WARN_ON_ONCE(value & ~mask);
  673. #endif
  674. v = iwl_read32(trans, reg);
  675. v &= ~mask;
  676. v |= value;
  677. iwl_write32(trans, reg, v);
  678. }
  679. static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
  680. u32 reg, u32 mask)
  681. {
  682. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
  683. }
  684. static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
  685. u32 reg, u32 mask)
  686. {
  687. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
  688. }
  689. void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state);
  690. #ifdef CONFIG_IWLWIFI_DEBUGFS
  691. int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans);
  692. #else
  693. static inline int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
  694. {
  695. return 0;
  696. }
  697. #endif
  698. int iwl_pci_fw_exit_d0i3(struct iwl_trans *trans);
  699. int iwl_pci_fw_enter_d0i3(struct iwl_trans *trans);
  700. void iwl_pcie_enable_rx_wake(struct iwl_trans *trans, bool enable);
  701. void iwl_pcie_rx_allocator_work(struct work_struct *data);
  702. /* common functions that are used by gen2 transport */
  703. void iwl_pcie_apm_config(struct iwl_trans *trans);
  704. int iwl_pcie_prepare_card_hw(struct iwl_trans *trans);
  705. void iwl_pcie_synchronize_irqs(struct iwl_trans *trans);
  706. bool iwl_pcie_check_hw_rf_kill(struct iwl_trans *trans);
  707. void iwl_trans_pcie_handle_stop_rfkill(struct iwl_trans *trans,
  708. bool was_in_rfkill);
  709. void iwl_pcie_txq_free_tfd(struct iwl_trans *trans, struct iwl_txq *txq);
  710. int iwl_queue_space(const struct iwl_txq *q);
  711. void iwl_pcie_apm_stop_master(struct iwl_trans *trans);
  712. void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie);
  713. int iwl_pcie_txq_init(struct iwl_trans *trans, struct iwl_txq *txq,
  714. int slots_num, bool cmd_queue);
  715. int iwl_pcie_txq_alloc(struct iwl_trans *trans,
  716. struct iwl_txq *txq, int slots_num, bool cmd_queue);
  717. int iwl_pcie_alloc_dma_ptr(struct iwl_trans *trans,
  718. struct iwl_dma_ptr *ptr, size_t size);
  719. void iwl_pcie_free_dma_ptr(struct iwl_trans *trans, struct iwl_dma_ptr *ptr);
  720. void iwl_pcie_apply_destination(struct iwl_trans *trans);
  721. void iwl_pcie_free_tso_page(struct iwl_trans_pcie *trans_pcie,
  722. struct sk_buff *skb);
  723. #ifdef CONFIG_INET
  724. struct iwl_tso_hdr_page *get_page_hdr(struct iwl_trans *trans, size_t len);
  725. #endif
  726. /* transport gen 2 exported functions */
  727. int iwl_trans_pcie_gen2_start_fw(struct iwl_trans *trans,
  728. const struct fw_img *fw, bool run_in_rfkill);
  729. void iwl_trans_pcie_gen2_fw_alive(struct iwl_trans *trans, u32 scd_addr);
  730. int iwl_trans_pcie_dyn_txq_alloc(struct iwl_trans *trans,
  731. struct iwl_tx_queue_cfg_cmd *cmd,
  732. int cmd_id,
  733. unsigned int timeout);
  734. void iwl_trans_pcie_dyn_txq_free(struct iwl_trans *trans, int queue);
  735. int iwl_trans_pcie_gen2_tx(struct iwl_trans *trans, struct sk_buff *skb,
  736. struct iwl_device_cmd *dev_cmd, int txq_id);
  737. int iwl_trans_pcie_gen2_send_hcmd(struct iwl_trans *trans,
  738. struct iwl_host_cmd *cmd);
  739. void iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans,
  740. bool low_power);
  741. void _iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans, bool low_power);
  742. void iwl_pcie_gen2_txq_unmap(struct iwl_trans *trans, int txq_id);
  743. void iwl_pcie_gen2_tx_free(struct iwl_trans *trans);
  744. void iwl_pcie_gen2_tx_stop(struct iwl_trans *trans);
  745. #endif /* __iwl_trans_int_pcie_h__ */