internal.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. * @tx_cmd_queue_size: the size of the tx command queue
  360. */
  361. struct iwl_trans_pcie {
  362. struct iwl_rxq *rxq;
  363. struct iwl_rx_mem_buffer rx_pool[RX_POOL_SIZE];
  364. struct iwl_rx_mem_buffer *global_table[RX_POOL_SIZE];
  365. struct iwl_rb_allocator rba;
  366. struct iwl_context_info *ctxt_info;
  367. dma_addr_t ctxt_info_dma_addr;
  368. struct iwl_self_init_dram init_dram;
  369. struct iwl_trans *trans;
  370. struct net_device napi_dev;
  371. struct __percpu iwl_tso_hdr_page *tso_hdr_page;
  372. /* INT ICT Table */
  373. __le32 *ict_tbl;
  374. dma_addr_t ict_tbl_dma;
  375. int ict_index;
  376. bool use_ict;
  377. bool is_down, opmode_down;
  378. bool debug_rfkill;
  379. struct isr_statistics isr_stats;
  380. spinlock_t irq_lock;
  381. struct mutex mutex;
  382. u32 inta_mask;
  383. u32 scd_base_addr;
  384. struct iwl_dma_ptr scd_bc_tbls;
  385. struct iwl_dma_ptr kw;
  386. struct iwl_txq *txq_memory;
  387. struct iwl_txq *txq[IWL_MAX_TVQM_QUEUES];
  388. unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  389. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  390. /* PCI bus related data */
  391. struct pci_dev *pci_dev;
  392. void __iomem *hw_base;
  393. bool ucode_write_complete;
  394. wait_queue_head_t ucode_write_waitq;
  395. wait_queue_head_t wait_command_queue;
  396. wait_queue_head_t d0i3_waitq;
  397. u8 page_offs, dev_cmd_offs;
  398. u8 cmd_queue;
  399. u8 cmd_fifo;
  400. unsigned int cmd_q_wdg_timeout;
  401. u8 n_no_reclaim_cmds;
  402. u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
  403. u8 max_tbs;
  404. u16 tfd_size;
  405. enum iwl_amsdu_size rx_buf_size;
  406. bool bc_table_dword;
  407. bool scd_set_active;
  408. bool sw_csum_tx;
  409. bool pcie_dbg_dumped_once;
  410. u32 rx_page_order;
  411. /*protect hw register */
  412. spinlock_t reg_lock;
  413. bool cmd_hold_nic_awake;
  414. bool ref_cmd_in_flight;
  415. dma_addr_t fw_mon_phys;
  416. struct page *fw_mon_page;
  417. u32 fw_mon_size;
  418. struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES];
  419. bool msix_enabled;
  420. u8 shared_vec_mask;
  421. u32 alloc_vecs;
  422. u32 def_irq;
  423. u32 fh_init_mask;
  424. u32 hw_init_mask;
  425. u32 fh_mask;
  426. u32 hw_mask;
  427. cpumask_t affinity_mask[IWL_MAX_RX_HW_QUEUES];
  428. u16 tx_cmd_queue_size;
  429. };
  430. static inline struct iwl_trans_pcie *
  431. IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans *trans)
  432. {
  433. return (void *)trans->trans_specific;
  434. }
  435. static inline struct iwl_trans *
  436. iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
  437. {
  438. return container_of((void *)trans_pcie, struct iwl_trans,
  439. trans_specific);
  440. }
  441. /*
  442. * Convention: trans API functions: iwl_trans_pcie_XXX
  443. * Other functions: iwl_pcie_XXX
  444. */
  445. struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
  446. const struct pci_device_id *ent,
  447. const struct iwl_cfg *cfg);
  448. void iwl_trans_pcie_free(struct iwl_trans *trans);
  449. /*****************************************************
  450. * RX
  451. ******************************************************/
  452. int iwl_pcie_rx_init(struct iwl_trans *trans);
  453. int iwl_pcie_gen2_rx_init(struct iwl_trans *trans);
  454. irqreturn_t iwl_pcie_msix_isr(int irq, void *data);
  455. irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
  456. irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id);
  457. irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id);
  458. int iwl_pcie_rx_stop(struct iwl_trans *trans);
  459. void iwl_pcie_rx_free(struct iwl_trans *trans);
  460. /*****************************************************
  461. * ICT - interrupt handling
  462. ******************************************************/
  463. irqreturn_t iwl_pcie_isr(int irq, void *data);
  464. int iwl_pcie_alloc_ict(struct iwl_trans *trans);
  465. void iwl_pcie_free_ict(struct iwl_trans *trans);
  466. void iwl_pcie_reset_ict(struct iwl_trans *trans);
  467. void iwl_pcie_disable_ict(struct iwl_trans *trans);
  468. /*****************************************************
  469. * TX / HCMD
  470. ******************************************************/
  471. int iwl_pcie_tx_init(struct iwl_trans *trans);
  472. int iwl_pcie_gen2_tx_init(struct iwl_trans *trans);
  473. void iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
  474. int iwl_pcie_tx_stop(struct iwl_trans *trans);
  475. void iwl_pcie_tx_free(struct iwl_trans *trans);
  476. bool iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int queue, u16 ssn,
  477. const struct iwl_trans_txq_scd_cfg *cfg,
  478. unsigned int wdg_timeout);
  479. void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue,
  480. bool configure_scd);
  481. void iwl_trans_pcie_txq_set_shared_mode(struct iwl_trans *trans, u32 txq_id,
  482. bool shared_mode);
  483. void iwl_trans_pcie_log_scd_error(struct iwl_trans *trans,
  484. struct iwl_txq *txq);
  485. int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
  486. struct iwl_device_cmd *dev_cmd, int txq_id);
  487. void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans);
  488. int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  489. void iwl_pcie_hcmd_complete(struct iwl_trans *trans,
  490. struct iwl_rx_cmd_buffer *rxb);
  491. void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
  492. struct sk_buff_head *skbs);
  493. void iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
  494. void iwl_pcie_set_tx_cmd_queue_size(struct iwl_trans *trans);
  495. static inline u16 iwl_pcie_tfd_tb_get_len(struct iwl_trans *trans, void *_tfd,
  496. u8 idx)
  497. {
  498. if (trans->cfg->use_tfh) {
  499. struct iwl_tfh_tfd *tfd = _tfd;
  500. struct iwl_tfh_tb *tb = &tfd->tbs[idx];
  501. return le16_to_cpu(tb->tb_len);
  502. } else {
  503. struct iwl_tfd *tfd = _tfd;
  504. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  505. return le16_to_cpu(tb->hi_n_len) >> 4;
  506. }
  507. }
  508. /*****************************************************
  509. * Error handling
  510. ******************************************************/
  511. void iwl_pcie_dump_csr(struct iwl_trans *trans);
  512. /*****************************************************
  513. * Helpers
  514. ******************************************************/
  515. static inline void _iwl_disable_interrupts(struct iwl_trans *trans)
  516. {
  517. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  518. clear_bit(STATUS_INT_ENABLED, &trans->status);
  519. if (!trans_pcie->msix_enabled) {
  520. /* disable interrupts from uCode/NIC to host */
  521. iwl_write32(trans, CSR_INT_MASK, 0x00000000);
  522. /* acknowledge/clear/reset any interrupts still pending
  523. * from uCode or flow handler (Rx/Tx DMA) */
  524. iwl_write32(trans, CSR_INT, 0xffffffff);
  525. iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
  526. } else {
  527. /* disable all the interrupt we might use */
  528. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  529. trans_pcie->fh_init_mask);
  530. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  531. trans_pcie->hw_init_mask);
  532. }
  533. IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
  534. }
  535. static inline void iwl_disable_interrupts(struct iwl_trans *trans)
  536. {
  537. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  538. spin_lock(&trans_pcie->irq_lock);
  539. _iwl_disable_interrupts(trans);
  540. spin_unlock(&trans_pcie->irq_lock);
  541. }
  542. static inline void _iwl_enable_interrupts(struct iwl_trans *trans)
  543. {
  544. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  545. IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
  546. set_bit(STATUS_INT_ENABLED, &trans->status);
  547. if (!trans_pcie->msix_enabled) {
  548. trans_pcie->inta_mask = CSR_INI_SET_MASK;
  549. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  550. } else {
  551. /*
  552. * fh/hw_mask keeps all the unmasked causes.
  553. * Unlike msi, in msix cause is enabled when it is unset.
  554. */
  555. trans_pcie->hw_mask = trans_pcie->hw_init_mask;
  556. trans_pcie->fh_mask = trans_pcie->fh_init_mask;
  557. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  558. ~trans_pcie->fh_mask);
  559. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  560. ~trans_pcie->hw_mask);
  561. }
  562. }
  563. static inline void iwl_enable_interrupts(struct iwl_trans *trans)
  564. {
  565. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  566. spin_lock(&trans_pcie->irq_lock);
  567. _iwl_enable_interrupts(trans);
  568. spin_unlock(&trans_pcie->irq_lock);
  569. }
  570. static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk)
  571. {
  572. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  573. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk);
  574. trans_pcie->hw_mask = msk;
  575. }
  576. static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk)
  577. {
  578. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  579. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk);
  580. trans_pcie->fh_mask = msk;
  581. }
  582. static inline void iwl_enable_fw_load_int(struct iwl_trans *trans)
  583. {
  584. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  585. IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n");
  586. if (!trans_pcie->msix_enabled) {
  587. trans_pcie->inta_mask = CSR_INT_BIT_FH_TX;
  588. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  589. } else {
  590. iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
  591. trans_pcie->hw_init_mask);
  592. iwl_enable_fh_int_msk_msix(trans,
  593. MSIX_FH_INT_CAUSES_D2S_CH0_NUM);
  594. }
  595. }
  596. static inline void iwl_pcie_sw_reset(struct iwl_trans *trans)
  597. {
  598. /* Reset entire device - do controller reset (results in SHRD_HW_RST) */
  599. iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  600. usleep_range(5000, 6000);
  601. }
  602. static inline u8 iwl_pcie_get_cmd_index(struct iwl_txq *q, u32 index)
  603. {
  604. return index & (q->n_window - 1);
  605. }
  606. static inline void *iwl_pcie_get_tfd(struct iwl_trans_pcie *trans_pcie,
  607. struct iwl_txq *txq, int idx)
  608. {
  609. return txq->tfds + trans_pcie->tfd_size * iwl_pcie_get_cmd_index(txq,
  610. idx);
  611. }
  612. static inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
  613. {
  614. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  615. IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
  616. if (!trans_pcie->msix_enabled) {
  617. trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL;
  618. iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
  619. } else {
  620. iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
  621. trans_pcie->fh_init_mask);
  622. iwl_enable_hw_int_msk_msix(trans,
  623. MSIX_HW_INT_CAUSES_REG_RF_KILL);
  624. }
  625. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_9000) {
  626. /*
  627. * On 9000-series devices this bit isn't enabled by default, so
  628. * when we power down the device we need set the bit to allow it
  629. * to wake up the PCI-E bus for RF-kill interrupts.
  630. */
  631. iwl_set_bit(trans, CSR_GP_CNTRL,
  632. CSR_GP_CNTRL_REG_FLAG_RFKILL_WAKE_L1A_EN);
  633. }
  634. }
  635. void iwl_pcie_handle_rfkill_irq(struct iwl_trans *trans);
  636. static inline void iwl_wake_queue(struct iwl_trans *trans,
  637. struct iwl_txq *txq)
  638. {
  639. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  640. if (test_and_clear_bit(txq->id, trans_pcie->queue_stopped)) {
  641. IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->id);
  642. iwl_op_mode_queue_not_full(trans->op_mode, txq->id);
  643. }
  644. }
  645. static inline void iwl_stop_queue(struct iwl_trans *trans,
  646. struct iwl_txq *txq)
  647. {
  648. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  649. if (!test_and_set_bit(txq->id, trans_pcie->queue_stopped)) {
  650. iwl_op_mode_queue_full(trans->op_mode, txq->id);
  651. IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->id);
  652. } else
  653. IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
  654. txq->id);
  655. }
  656. static inline bool iwl_queue_used(const struct iwl_txq *q, int i)
  657. {
  658. return q->write_ptr >= q->read_ptr ?
  659. (i >= q->read_ptr && i < q->write_ptr) :
  660. !(i < q->read_ptr && i >= q->write_ptr);
  661. }
  662. static inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
  663. {
  664. struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
  665. lockdep_assert_held(&trans_pcie->mutex);
  666. if (trans_pcie->debug_rfkill)
  667. return true;
  668. return !(iwl_read32(trans, CSR_GP_CNTRL) &
  669. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
  670. }
  671. static inline void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
  672. u32 reg, u32 mask, u32 value)
  673. {
  674. u32 v;
  675. #ifdef CONFIG_IWLWIFI_DEBUG
  676. WARN_ON_ONCE(value & ~mask);
  677. #endif
  678. v = iwl_read32(trans, reg);
  679. v &= ~mask;
  680. v |= value;
  681. iwl_write32(trans, reg, v);
  682. }
  683. static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
  684. u32 reg, u32 mask)
  685. {
  686. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
  687. }
  688. static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
  689. u32 reg, u32 mask)
  690. {
  691. __iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
  692. }
  693. void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state);
  694. #ifdef CONFIG_IWLWIFI_DEBUGFS
  695. int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans);
  696. #else
  697. static inline int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
  698. {
  699. return 0;
  700. }
  701. #endif
  702. int iwl_pci_fw_exit_d0i3(struct iwl_trans *trans);
  703. int iwl_pci_fw_enter_d0i3(struct iwl_trans *trans);
  704. void iwl_pcie_enable_rx_wake(struct iwl_trans *trans, bool enable);
  705. void iwl_pcie_rx_allocator_work(struct work_struct *data);
  706. /* common functions that are used by gen2 transport */
  707. void iwl_pcie_apm_config(struct iwl_trans *trans);
  708. int iwl_pcie_prepare_card_hw(struct iwl_trans *trans);
  709. void iwl_pcie_synchronize_irqs(struct iwl_trans *trans);
  710. bool iwl_pcie_check_hw_rf_kill(struct iwl_trans *trans);
  711. void iwl_trans_pcie_handle_stop_rfkill(struct iwl_trans *trans,
  712. bool was_in_rfkill);
  713. void iwl_pcie_txq_free_tfd(struct iwl_trans *trans, struct iwl_txq *txq);
  714. int iwl_queue_space(const struct iwl_txq *q);
  715. void iwl_pcie_apm_stop_master(struct iwl_trans *trans);
  716. void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie);
  717. int iwl_pcie_txq_init(struct iwl_trans *trans, struct iwl_txq *txq,
  718. int slots_num, bool cmd_queue);
  719. int iwl_pcie_txq_alloc(struct iwl_trans *trans,
  720. struct iwl_txq *txq, int slots_num, bool cmd_queue);
  721. int iwl_pcie_alloc_dma_ptr(struct iwl_trans *trans,
  722. struct iwl_dma_ptr *ptr, size_t size);
  723. void iwl_pcie_free_dma_ptr(struct iwl_trans *trans, struct iwl_dma_ptr *ptr);
  724. void iwl_pcie_apply_destination(struct iwl_trans *trans);
  725. void iwl_pcie_free_tso_page(struct iwl_trans_pcie *trans_pcie,
  726. struct sk_buff *skb);
  727. #ifdef CONFIG_INET
  728. struct iwl_tso_hdr_page *get_page_hdr(struct iwl_trans *trans, size_t len);
  729. #endif
  730. /* transport gen 2 exported functions */
  731. int iwl_trans_pcie_gen2_start_fw(struct iwl_trans *trans,
  732. const struct fw_img *fw, bool run_in_rfkill);
  733. void iwl_trans_pcie_gen2_fw_alive(struct iwl_trans *trans, u32 scd_addr);
  734. int iwl_trans_pcie_dyn_txq_alloc(struct iwl_trans *trans,
  735. struct iwl_tx_queue_cfg_cmd *cmd,
  736. int cmd_id,
  737. unsigned int timeout);
  738. void iwl_trans_pcie_dyn_txq_free(struct iwl_trans *trans, int queue);
  739. int iwl_trans_pcie_gen2_tx(struct iwl_trans *trans, struct sk_buff *skb,
  740. struct iwl_device_cmd *dev_cmd, int txq_id);
  741. int iwl_trans_pcie_gen2_send_hcmd(struct iwl_trans *trans,
  742. struct iwl_host_cmd *cmd);
  743. void iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans,
  744. bool low_power);
  745. void _iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans, bool low_power);
  746. void iwl_pcie_gen2_txq_unmap(struct iwl_trans *trans, int txq_id);
  747. void iwl_pcie_gen2_tx_free(struct iwl_trans *trans);
  748. void iwl_pcie_gen2_tx_stop(struct iwl_trans *trans);
  749. #endif /* __iwl_trans_int_pcie_h__ */