internal.h 26 KB

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