1e705c121SKalle Valo /******************************************************************************
2e705c121SKalle Valo  *
3e705c121SKalle Valo  * Copyright(c) 2003 - 2015 Intel Corporation. All rights reserved.
4e705c121SKalle Valo  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
54cbb8e50SLuciano Coelho  * Copyright(c) 2016 Intel Deutschland GmbH
6e705c121SKalle Valo  *
7e705c121SKalle Valo  * Portions of this file are derived from the ipw3945 project, as well
8e705c121SKalle Valo  * as portions of the ieee80211 subsystem header files.
9e705c121SKalle Valo  *
10e705c121SKalle Valo  * This program is free software; you can redistribute it and/or modify it
11e705c121SKalle Valo  * under the terms of version 2 of the GNU General Public License as
12e705c121SKalle Valo  * published by the Free Software Foundation.
13e705c121SKalle Valo  *
14e705c121SKalle Valo  * This program is distributed in the hope that it will be useful, but WITHOUT
15e705c121SKalle Valo  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16e705c121SKalle Valo  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17e705c121SKalle Valo  * more details.
18e705c121SKalle Valo  *
19e705c121SKalle Valo  * You should have received a copy of the GNU General Public License along with
20e705c121SKalle Valo  * this program; if not, write to the Free Software Foundation, Inc.,
21e705c121SKalle Valo  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22e705c121SKalle Valo  *
23e705c121SKalle Valo  * The full GNU General Public License is included in this distribution in the
24e705c121SKalle Valo  * file called LICENSE.
25e705c121SKalle Valo  *
26e705c121SKalle Valo  * Contact Information:
27cb2f8277SEmmanuel Grumbach  *  Intel Linux Wireless <linuxwifi@intel.com>
28e705c121SKalle Valo  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29e705c121SKalle Valo  *
30e705c121SKalle Valo  *****************************************************************************/
31e705c121SKalle Valo #ifndef __iwl_trans_int_pcie_h__
32e705c121SKalle Valo #define __iwl_trans_int_pcie_h__
33e705c121SKalle Valo 
34e705c121SKalle Valo #include <linux/spinlock.h>
35e705c121SKalle Valo #include <linux/interrupt.h>
36e705c121SKalle Valo #include <linux/skbuff.h>
37e705c121SKalle Valo #include <linux/wait.h>
38e705c121SKalle Valo #include <linux/pci.h>
39e705c121SKalle Valo #include <linux/timer.h>
40e705c121SKalle Valo 
41e705c121SKalle Valo #include "iwl-fh.h"
42e705c121SKalle Valo #include "iwl-csr.h"
43e705c121SKalle Valo #include "iwl-trans.h"
44e705c121SKalle Valo #include "iwl-debug.h"
45e705c121SKalle Valo #include "iwl-io.h"
46e705c121SKalle Valo #include "iwl-op-mode.h"
47e705c121SKalle Valo 
48e705c121SKalle Valo /* We need 2 entries for the TX command and header, and another one might
49e705c121SKalle Valo  * be needed for potential data in the SKB's head. The remaining ones can
50e705c121SKalle Valo  * be used for frags.
51e705c121SKalle Valo  */
523cd1980bSSara Sharon #define IWL_PCIE_MAX_FRAGS(x) (x->max_tbs - 3)
53e705c121SKalle Valo 
54e705c121SKalle Valo /*
55e705c121SKalle Valo  * RX related structures and functions
56e705c121SKalle Valo  */
57e705c121SKalle Valo #define RX_NUM_QUEUES 1
58e705c121SKalle Valo #define RX_POST_REQ_ALLOC 2
59e705c121SKalle Valo #define RX_CLAIM_REQ_ALLOC 8
6078485054SSara Sharon #define RX_PENDING_WATERMARK 16
61e705c121SKalle Valo 
62e705c121SKalle Valo struct iwl_host_cmd;
63e705c121SKalle Valo 
64e705c121SKalle Valo /*This file includes the declaration that are internal to the
65e705c121SKalle Valo  * trans_pcie layer */
66e705c121SKalle Valo 
6796a6497bSSara Sharon /**
6896a6497bSSara Sharon  * struct iwl_rx_mem_buffer
6996a6497bSSara Sharon  * @page_dma: bus address of rxb page
7096a6497bSSara Sharon  * @page: driver's pointer to the rxb page
71b1753c62SSara Sharon  * @invalid: rxb is in driver ownership - not owned by HW
7296a6497bSSara Sharon  * @vid: index of this rxb in the global table
7396a6497bSSara Sharon  */
74e705c121SKalle Valo struct iwl_rx_mem_buffer {
75e705c121SKalle Valo 	dma_addr_t page_dma;
76e705c121SKalle Valo 	struct page *page;
7796a6497bSSara Sharon 	u16 vid;
78b1753c62SSara Sharon 	bool invalid;
79e705c121SKalle Valo 	struct list_head list;
80e705c121SKalle Valo };
81e705c121SKalle Valo 
82e705c121SKalle Valo /**
83e705c121SKalle Valo  * struct isr_statistics - interrupt statistics
84e705c121SKalle Valo  *
85e705c121SKalle Valo  */
86e705c121SKalle Valo struct isr_statistics {
87e705c121SKalle Valo 	u32 hw;
88e705c121SKalle Valo 	u32 sw;
89e705c121SKalle Valo 	u32 err_code;
90e705c121SKalle Valo 	u32 sch;
91e705c121SKalle Valo 	u32 alive;
92e705c121SKalle Valo 	u32 rfkill;
93e705c121SKalle Valo 	u32 ctkill;
94e705c121SKalle Valo 	u32 wakeup;
95e705c121SKalle Valo 	u32 rx;
96e705c121SKalle Valo 	u32 tx;
97e705c121SKalle Valo 	u32 unhandled;
98e705c121SKalle Valo };
99e705c121SKalle Valo 
100e705c121SKalle Valo /**
101e705c121SKalle Valo  * struct iwl_rxq - Rx queue
10296a6497bSSara Sharon  * @id: queue index
10396a6497bSSara Sharon  * @bd: driver's pointer to buffer of receive buffer descriptors (rbd).
10496a6497bSSara Sharon  *	Address size is 32 bit in pre-9000 devices and 64 bit in 9000 devices.
105e705c121SKalle Valo  * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
10696a6497bSSara Sharon  * @ubd: driver's pointer to buffer of used receive buffer descriptors (rbd)
10796a6497bSSara Sharon  * @ubd_dma: physical address of buffer of used receive buffer descriptors (rbd)
108e705c121SKalle Valo  * @read: Shared index to newest available Rx buffer
109e705c121SKalle Valo  * @write: Shared index to oldest written Rx packet
110e705c121SKalle Valo  * @free_count: Number of pre-allocated buffers in rx_free
111e705c121SKalle Valo  * @used_count: Number of RBDs handled to allocator to use for allocation
112e705c121SKalle Valo  * @write_actual:
113e705c121SKalle Valo  * @rx_free: list of RBDs with allocated RB ready for use
114e705c121SKalle Valo  * @rx_used: list of RBDs with no RB attached
115e705c121SKalle Valo  * @need_update: flag to indicate we need to update read/write index
116e705c121SKalle Valo  * @rb_stts: driver's pointer to receive buffer status
117e705c121SKalle Valo  * @rb_stts_dma: bus address of receive buffer status
118e705c121SKalle Valo  * @lock:
11996a6497bSSara Sharon  * @queue: actual rx queue. Not used for multi-rx queue.
120e705c121SKalle Valo  *
121e705c121SKalle Valo  * NOTE:  rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
122e705c121SKalle Valo  */
123e705c121SKalle Valo struct iwl_rxq {
12496a6497bSSara Sharon 	int id;
12596a6497bSSara Sharon 	void *bd;
126e705c121SKalle Valo 	dma_addr_t bd_dma;
12796a6497bSSara Sharon 	__le32 *used_bd;
12896a6497bSSara Sharon 	dma_addr_t used_bd_dma;
129e705c121SKalle Valo 	u32 read;
130e705c121SKalle Valo 	u32 write;
131e705c121SKalle Valo 	u32 free_count;
132e705c121SKalle Valo 	u32 used_count;
133e705c121SKalle Valo 	u32 write_actual;
13496a6497bSSara Sharon 	u32 queue_size;
135e705c121SKalle Valo 	struct list_head rx_free;
136e705c121SKalle Valo 	struct list_head rx_used;
137e705c121SKalle Valo 	bool need_update;
138e705c121SKalle Valo 	struct iwl_rb_status *rb_stts;
139e705c121SKalle Valo 	dma_addr_t rb_stts_dma;
140e705c121SKalle Valo 	spinlock_t lock;
141bce97731SSara Sharon 	struct napi_struct napi;
142e705c121SKalle Valo 	struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
143e705c121SKalle Valo };
144e705c121SKalle Valo 
145e705c121SKalle Valo /**
146e705c121SKalle Valo  * struct iwl_rb_allocator - Rx allocator
147e705c121SKalle Valo  * @req_pending: number of requests the allcator had not processed yet
148e705c121SKalle Valo  * @req_ready: number of requests honored and ready for claiming
149e705c121SKalle Valo  * @rbd_allocated: RBDs with pages allocated and ready to be handled to
150e705c121SKalle Valo  *	the queue. This is a list of &struct iwl_rx_mem_buffer
151e705c121SKalle Valo  * @rbd_empty: RBDs with no page attached for allocator use. This is a list
152e705c121SKalle Valo  *	of &struct iwl_rx_mem_buffer
153e705c121SKalle Valo  * @lock: protects the rbd_allocated and rbd_empty lists
154e705c121SKalle Valo  * @alloc_wq: work queue for background calls
155e705c121SKalle Valo  * @rx_alloc: work struct for background calls
156e705c121SKalle Valo  */
157e705c121SKalle Valo struct iwl_rb_allocator {
158e705c121SKalle Valo 	atomic_t req_pending;
159e705c121SKalle Valo 	atomic_t req_ready;
160e705c121SKalle Valo 	struct list_head rbd_allocated;
161e705c121SKalle Valo 	struct list_head rbd_empty;
162e705c121SKalle Valo 	spinlock_t lock;
163e705c121SKalle Valo 	struct workqueue_struct *alloc_wq;
164e705c121SKalle Valo 	struct work_struct rx_alloc;
165e705c121SKalle Valo };
166e705c121SKalle Valo 
167e705c121SKalle Valo struct iwl_dma_ptr {
168e705c121SKalle Valo 	dma_addr_t dma;
169e705c121SKalle Valo 	void *addr;
170e705c121SKalle Valo 	size_t size;
171e705c121SKalle Valo };
172e705c121SKalle Valo 
173e705c121SKalle Valo /**
174e705c121SKalle Valo  * iwl_queue_inc_wrap - increment queue index, wrap back to beginning
175e705c121SKalle Valo  * @index -- current index
176e705c121SKalle Valo  */
177e705c121SKalle Valo static inline int iwl_queue_inc_wrap(int index)
178e705c121SKalle Valo {
179e705c121SKalle Valo 	return ++index & (TFD_QUEUE_SIZE_MAX - 1);
180e705c121SKalle Valo }
181e705c121SKalle Valo 
182e705c121SKalle Valo /**
183e705c121SKalle Valo  * iwl_queue_dec_wrap - decrement queue index, wrap back to end
184e705c121SKalle Valo  * @index -- current index
185e705c121SKalle Valo  */
186e705c121SKalle Valo static inline int iwl_queue_dec_wrap(int index)
187e705c121SKalle Valo {
188e705c121SKalle Valo 	return --index & (TFD_QUEUE_SIZE_MAX - 1);
189e705c121SKalle Valo }
190e705c121SKalle Valo 
191e705c121SKalle Valo struct iwl_cmd_meta {
192e705c121SKalle Valo 	/* only for SYNC commands, iff the reply skb is wanted */
193e705c121SKalle Valo 	struct iwl_host_cmd *source;
194e705c121SKalle Valo 	u32 flags;
1953cd1980bSSara Sharon 	u32 tbs;
196e705c121SKalle Valo };
197e705c121SKalle Valo 
198e705c121SKalle Valo /*
199e705c121SKalle Valo  * Generic queue structure
200e705c121SKalle Valo  *
201e705c121SKalle Valo  * Contains common data for Rx and Tx queues.
202e705c121SKalle Valo  *
203e705c121SKalle Valo  * Note the difference between TFD_QUEUE_SIZE_MAX and n_window: the hardware
204e705c121SKalle Valo  * always assumes 256 descriptors, so TFD_QUEUE_SIZE_MAX is always 256 (unless
205e705c121SKalle Valo  * there might be HW changes in the future). For the normal TX
206e705c121SKalle Valo  * queues, n_window, which is the size of the software queue data
207e705c121SKalle Valo  * is also 256; however, for the command queue, n_window is only
208e705c121SKalle Valo  * 32 since we don't need so many commands pending. Since the HW
209e705c121SKalle Valo  * still uses 256 BDs for DMA though, TFD_QUEUE_SIZE_MAX stays 256. As a result,
210e705c121SKalle Valo  * the software buffers (in the variables @meta, @txb in struct
211e705c121SKalle Valo  * iwl_txq) only have 32 entries, while the HW buffers (@tfds in
212e705c121SKalle Valo  * the same struct) have 256.
213e705c121SKalle Valo  * This means that we end up with the following:
214e705c121SKalle Valo  *  HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
215e705c121SKalle Valo  *  SW entries:           | 0      | ... | 31          |
216e705c121SKalle Valo  * where N is a number between 0 and 7. This means that the SW
217e705c121SKalle Valo  * data is a window overlayed over the HW queue.
218e705c121SKalle Valo  */
219e705c121SKalle Valo struct iwl_queue {
220e705c121SKalle Valo 	int write_ptr;       /* 1-st empty entry (index) host_w*/
221e705c121SKalle Valo 	int read_ptr;         /* last used entry (index) host_r*/
222e705c121SKalle Valo 	/* use for monitoring and recovering the stuck queue */
223e705c121SKalle Valo 	dma_addr_t dma_addr;   /* physical addr for BD's */
224e705c121SKalle Valo 	int n_window;	       /* safe queue window */
225e705c121SKalle Valo 	u32 id;
226e705c121SKalle Valo 	int low_mark;	       /* low watermark, resume queue if free
227e705c121SKalle Valo 				* space more than this */
228e705c121SKalle Valo 	int high_mark;         /* high watermark, stop queue if free
229e705c121SKalle Valo 				* space less than this */
230e705c121SKalle Valo };
231e705c121SKalle Valo 
232e705c121SKalle Valo #define TFD_TX_CMD_SLOTS 256
233e705c121SKalle Valo #define TFD_CMD_SLOTS 32
234e705c121SKalle Valo 
235e705c121SKalle Valo /*
2368de437c7SSara Sharon  * The FH will write back to the first TB only, so we need to copy some data
2378de437c7SSara Sharon  * into the buffer regardless of whether it should be mapped or not.
2388de437c7SSara Sharon  * This indicates how big the first TB must be to include the scratch buffer
2398de437c7SSara Sharon  * and the assigned PN.
2408de437c7SSara Sharon  * Since PN location is 16 bytes at offset 24, it's 40 now.
2418de437c7SSara Sharon  * If we make it bigger then allocations will be bigger and copy slower, so
2428de437c7SSara Sharon  * that's probably not useful.
243e705c121SKalle Valo  */
2448de437c7SSara Sharon #define IWL_FIRST_TB_SIZE	40
2458de437c7SSara Sharon #define IWL_FIRST_TB_SIZE_ALIGN ALIGN(IWL_FIRST_TB_SIZE, 64)
246e705c121SKalle Valo 
247e705c121SKalle Valo struct iwl_pcie_txq_entry {
248e705c121SKalle Valo 	struct iwl_device_cmd *cmd;
249e705c121SKalle Valo 	struct sk_buff *skb;
250e705c121SKalle Valo 	/* buffer to free after command completes */
251e705c121SKalle Valo 	const void *free_buf;
252e705c121SKalle Valo 	struct iwl_cmd_meta meta;
253e705c121SKalle Valo };
254e705c121SKalle Valo 
2558de437c7SSara Sharon struct iwl_pcie_first_tb_buf {
2568de437c7SSara Sharon 	u8 buf[IWL_FIRST_TB_SIZE_ALIGN];
257e705c121SKalle Valo };
258e705c121SKalle Valo 
259e705c121SKalle Valo /**
260e705c121SKalle Valo  * struct iwl_txq - Tx Queue for DMA
261e705c121SKalle Valo  * @q: generic Rx/Tx queue descriptor
262e705c121SKalle Valo  * @tfds: transmit frame descriptors (DMA memory)
2638de437c7SSara Sharon  * @first_tb_bufs: start of command headers, including scratch buffers, for
264e705c121SKalle Valo  *	the writeback -- this is DMA memory and an array holding one buffer
265e705c121SKalle Valo  *	for each command on the queue
2668de437c7SSara Sharon  * @first_tb_dma: DMA address for the first_tb_bufs start
267e705c121SKalle Valo  * @entries: transmit entries (driver state)
268e705c121SKalle Valo  * @lock: queue lock
269e705c121SKalle Valo  * @stuck_timer: timer that fires if queue gets stuck
270e705c121SKalle Valo  * @trans_pcie: pointer back to transport (for timer)
271e705c121SKalle Valo  * @need_update: indicates need to update read/write index
272e705c121SKalle Valo  * @active: stores if queue is active
273e705c121SKalle Valo  * @ampdu: true if this queue is an ampdu queue for an specific RA/TID
274e705c121SKalle Valo  * @wd_timeout: queue watchdog timeout (jiffies) - per queue
275e705c121SKalle Valo  * @frozen: tx stuck queue timer is frozen
276e705c121SKalle Valo  * @frozen_expiry_remainder: remember how long until the timer fires
277e705c121SKalle Valo  *
278e705c121SKalle Valo  * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
279e705c121SKalle Valo  * descriptors) and required locking structures.
280e705c121SKalle Valo  */
281e705c121SKalle Valo struct iwl_txq {
282e705c121SKalle Valo 	struct iwl_queue q;
2836983ba69SSara Sharon 	void *tfds;
2848de437c7SSara Sharon 	struct iwl_pcie_first_tb_buf *first_tb_bufs;
2858de437c7SSara Sharon 	dma_addr_t first_tb_dma;
286e705c121SKalle Valo 	struct iwl_pcie_txq_entry *entries;
287e705c121SKalle Valo 	spinlock_t lock;
288e705c121SKalle Valo 	unsigned long frozen_expiry_remainder;
289e705c121SKalle Valo 	struct timer_list stuck_timer;
290e705c121SKalle Valo 	struct iwl_trans_pcie *trans_pcie;
291e705c121SKalle Valo 	bool need_update;
292e705c121SKalle Valo 	bool frozen;
293e705c121SKalle Valo 	u8 active;
294e705c121SKalle Valo 	bool ampdu;
2950cd58eaaSEmmanuel Grumbach 	bool block;
296e705c121SKalle Valo 	unsigned long wd_timeout;
2973955525dSEmmanuel Grumbach 	struct sk_buff_head overflow_q;
298e705c121SKalle Valo };
299e705c121SKalle Valo 
300e705c121SKalle Valo static inline dma_addr_t
3018de437c7SSara Sharon iwl_pcie_get_first_tb_dma(struct iwl_txq *txq, int idx)
302e705c121SKalle Valo {
3038de437c7SSara Sharon 	return txq->first_tb_dma +
3048de437c7SSara Sharon 	       sizeof(struct iwl_pcie_first_tb_buf) * idx;
305e705c121SKalle Valo }
306e705c121SKalle Valo 
3076eb5e529SEmmanuel Grumbach struct iwl_tso_hdr_page {
3086eb5e529SEmmanuel Grumbach 	struct page *page;
3096eb5e529SEmmanuel Grumbach 	u8 *pos;
3106eb5e529SEmmanuel Grumbach };
3116eb5e529SEmmanuel Grumbach 
312e705c121SKalle Valo /**
313e705c121SKalle Valo  * struct iwl_trans_pcie - PCIe transport specific data
314e705c121SKalle Valo  * @rxq: all the RX queue data
31578485054SSara Sharon  * @rx_pool: initial pool of iwl_rx_mem_buffer for all the queues
31696a6497bSSara Sharon  * @global_table: table mapping received VID from hw to rxb
317e705c121SKalle Valo  * @rba: allocator for RX replenishing
318e705c121SKalle Valo  * @trans: pointer to the generic transport area
319e705c121SKalle Valo  * @scd_base_addr: scheduler sram base address in SRAM
320e705c121SKalle Valo  * @scd_bc_tbls: pointer to the byte count table of the scheduler
321e705c121SKalle Valo  * @kw: keep warm address
322e705c121SKalle Valo  * @pci_dev: basic pci-network driver stuff
323e705c121SKalle Valo  * @hw_base: pci hardware address support
324e705c121SKalle Valo  * @ucode_write_complete: indicates that the ucode has been copied.
325e705c121SKalle Valo  * @ucode_write_waitq: wait queue for uCode load
326e705c121SKalle Valo  * @cmd_queue - command queue number
3276c4fbcbcSEmmanuel Grumbach  * @rx_buf_size: Rx buffer size
328e705c121SKalle Valo  * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
329e705c121SKalle Valo  * @scd_set_active: should the transport configure the SCD for HCMD queue
330e705c121SKalle Valo  * @wide_cmd_header: true when ucode supports wide command header format
33141837ca9SEmmanuel Grumbach  * @sw_csum_tx: if true, then the transport will compute the csum of the TXed
33241837ca9SEmmanuel Grumbach  *	frame.
333e705c121SKalle Valo  * @rx_page_order: page order for receive buffer size
334e705c121SKalle Valo  * @reg_lock: protect hw register access
335e705c121SKalle Valo  * @mutex: to protect stop_device / start_fw / start_hw
336e705c121SKalle Valo  * @cmd_in_flight: true when we have a host command in flight
337e705c121SKalle Valo  * @fw_mon_phys: physical address of the buffer for the firmware monitor
338e705c121SKalle Valo  * @fw_mon_page: points to the first page of the buffer for the firmware monitor
339e705c121SKalle Valo  * @fw_mon_size: size of the buffer for the firmware monitor
3402e5d4a8fSHaim Dreyfuss  * @msix_entries: array of MSI-X entries
3412e5d4a8fSHaim Dreyfuss  * @msix_enabled: true if managed to enable MSI-X
3422e5d4a8fSHaim Dreyfuss  * @allocated_vector: the number of interrupt vector allocated by the OS
3432e5d4a8fSHaim Dreyfuss  * @default_irq_num: default irq for non rx interrupt
3442e5d4a8fSHaim Dreyfuss  * @fh_init_mask: initial unmasked fh causes
3452e5d4a8fSHaim Dreyfuss  * @hw_init_mask: initial unmasked hw causes
3462e5d4a8fSHaim Dreyfuss  * @fh_mask: current unmasked fh causes
3472e5d4a8fSHaim Dreyfuss  * @hw_mask: current unmasked hw causes
348e705c121SKalle Valo  */
349e705c121SKalle Valo struct iwl_trans_pcie {
35078485054SSara Sharon 	struct iwl_rxq *rxq;
3517b542436SSara Sharon 	struct iwl_rx_mem_buffer rx_pool[RX_POOL_SIZE];
35243146925SSara Sharon 	struct iwl_rx_mem_buffer *global_table[RX_POOL_SIZE];
353e705c121SKalle Valo 	struct iwl_rb_allocator rba;
354e705c121SKalle Valo 	struct iwl_trans *trans;
355e705c121SKalle Valo 
356e705c121SKalle Valo 	struct net_device napi_dev;
357e705c121SKalle Valo 
3586eb5e529SEmmanuel Grumbach 	struct __percpu iwl_tso_hdr_page *tso_hdr_page;
3596eb5e529SEmmanuel Grumbach 
360e705c121SKalle Valo 	/* INT ICT Table */
361e705c121SKalle Valo 	__le32 *ict_tbl;
362e705c121SKalle Valo 	dma_addr_t ict_tbl_dma;
363e705c121SKalle Valo 	int ict_index;
364e705c121SKalle Valo 	bool use_ict;
365e705c121SKalle Valo 	bool is_down;
366e705c121SKalle Valo 	struct isr_statistics isr_stats;
367e705c121SKalle Valo 
368e705c121SKalle Valo 	spinlock_t irq_lock;
369e705c121SKalle Valo 	struct mutex mutex;
370e705c121SKalle Valo 	u32 inta_mask;
371e705c121SKalle Valo 	u32 scd_base_addr;
372e705c121SKalle Valo 	struct iwl_dma_ptr scd_bc_tbls;
373e705c121SKalle Valo 	struct iwl_dma_ptr kw;
374e705c121SKalle Valo 
375e705c121SKalle Valo 	struct iwl_txq *txq;
376e705c121SKalle Valo 	unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
377e705c121SKalle Valo 	unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
378e705c121SKalle Valo 
379e705c121SKalle Valo 	/* PCI bus related data */
380e705c121SKalle Valo 	struct pci_dev *pci_dev;
381e705c121SKalle Valo 	void __iomem *hw_base;
382e705c121SKalle Valo 
383e705c121SKalle Valo 	bool ucode_write_complete;
384e705c121SKalle Valo 	wait_queue_head_t ucode_write_waitq;
385e705c121SKalle Valo 	wait_queue_head_t wait_command_queue;
3864cbb8e50SLuciano Coelho 	wait_queue_head_t d0i3_waitq;
387e705c121SKalle Valo 
38821cb3222SJohannes Berg 	u8 page_offs, dev_cmd_offs;
38921cb3222SJohannes Berg 
390e705c121SKalle Valo 	u8 cmd_queue;
391e705c121SKalle Valo 	u8 cmd_fifo;
392e705c121SKalle Valo 	unsigned int cmd_q_wdg_timeout;
393e705c121SKalle Valo 	u8 n_no_reclaim_cmds;
394e705c121SKalle Valo 	u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
3953cd1980bSSara Sharon 	u8 max_tbs;
3966983ba69SSara Sharon 	u16 tfd_size;
397e705c121SKalle Valo 
3986c4fbcbcSEmmanuel Grumbach 	enum iwl_amsdu_size rx_buf_size;
399e705c121SKalle Valo 	bool bc_table_dword;
400e705c121SKalle Valo 	bool scd_set_active;
401e705c121SKalle Valo 	bool wide_cmd_header;
40241837ca9SEmmanuel Grumbach 	bool sw_csum_tx;
403e705c121SKalle Valo 	u32 rx_page_order;
404e705c121SKalle Valo 
405e705c121SKalle Valo 	/*protect hw register */
406e705c121SKalle Valo 	spinlock_t reg_lock;
407e705c121SKalle Valo 	bool cmd_hold_nic_awake;
408e705c121SKalle Valo 	bool ref_cmd_in_flight;
409e705c121SKalle Valo 
410e705c121SKalle Valo 	dma_addr_t fw_mon_phys;
411e705c121SKalle Valo 	struct page *fw_mon_page;
412e705c121SKalle Valo 	u32 fw_mon_size;
4132e5d4a8fSHaim Dreyfuss 
4142e5d4a8fSHaim Dreyfuss 	struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES];
4152e5d4a8fSHaim Dreyfuss 	bool msix_enabled;
4162e5d4a8fSHaim Dreyfuss 	u32 allocated_vector;
4172e5d4a8fSHaim Dreyfuss 	u32 default_irq_num;
4182e5d4a8fSHaim Dreyfuss 	u32 fh_init_mask;
4192e5d4a8fSHaim Dreyfuss 	u32 hw_init_mask;
4202e5d4a8fSHaim Dreyfuss 	u32 fh_mask;
4212e5d4a8fSHaim Dreyfuss 	u32 hw_mask;
422e705c121SKalle Valo };
423e705c121SKalle Valo 
42485e5a387SJohannes Berg static inline struct iwl_trans_pcie *
42585e5a387SJohannes Berg IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans *trans)
42685e5a387SJohannes Berg {
42785e5a387SJohannes Berg 	return (void *)trans->trans_specific;
42885e5a387SJohannes Berg }
429e705c121SKalle Valo 
430e705c121SKalle Valo static inline struct iwl_trans *
431e705c121SKalle Valo iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
432e705c121SKalle Valo {
433e705c121SKalle Valo 	return container_of((void *)trans_pcie, struct iwl_trans,
434e705c121SKalle Valo 			    trans_specific);
435e705c121SKalle Valo }
436e705c121SKalle Valo 
437e705c121SKalle Valo /*
438e705c121SKalle Valo  * Convention: trans API functions: iwl_trans_pcie_XXX
439e705c121SKalle Valo  *	Other functions: iwl_pcie_XXX
440e705c121SKalle Valo  */
441e705c121SKalle Valo struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
442e705c121SKalle Valo 				       const struct pci_device_id *ent,
443e705c121SKalle Valo 				       const struct iwl_cfg *cfg);
444e705c121SKalle Valo void iwl_trans_pcie_free(struct iwl_trans *trans);
445e705c121SKalle Valo 
446e705c121SKalle Valo /*****************************************************
447e705c121SKalle Valo * RX
448e705c121SKalle Valo ******************************************************/
449e705c121SKalle Valo int iwl_pcie_rx_init(struct iwl_trans *trans);
4502e5d4a8fSHaim Dreyfuss irqreturn_t iwl_pcie_msix_isr(int irq, void *data);
451e705c121SKalle Valo irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
4522e5d4a8fSHaim Dreyfuss irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id);
4532e5d4a8fSHaim Dreyfuss irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id);
454e705c121SKalle Valo int iwl_pcie_rx_stop(struct iwl_trans *trans);
455e705c121SKalle Valo void iwl_pcie_rx_free(struct iwl_trans *trans);
456e705c121SKalle Valo 
457e705c121SKalle Valo /*****************************************************
458e705c121SKalle Valo * ICT - interrupt handling
459e705c121SKalle Valo ******************************************************/
460e705c121SKalle Valo irqreturn_t iwl_pcie_isr(int irq, void *data);
461e705c121SKalle Valo int iwl_pcie_alloc_ict(struct iwl_trans *trans);
462e705c121SKalle Valo void iwl_pcie_free_ict(struct iwl_trans *trans);
463e705c121SKalle Valo void iwl_pcie_reset_ict(struct iwl_trans *trans);
464e705c121SKalle Valo void iwl_pcie_disable_ict(struct iwl_trans *trans);
465e705c121SKalle Valo 
466e705c121SKalle Valo /*****************************************************
467e705c121SKalle Valo * TX / HCMD
468e705c121SKalle Valo ******************************************************/
469e705c121SKalle Valo int iwl_pcie_tx_init(struct iwl_trans *trans);
470e705c121SKalle Valo void iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
471e705c121SKalle Valo int iwl_pcie_tx_stop(struct iwl_trans *trans);
472e705c121SKalle Valo void iwl_pcie_tx_free(struct iwl_trans *trans);
473e705c121SKalle Valo void iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int queue, u16 ssn,
474e705c121SKalle Valo 			       const struct iwl_trans_txq_scd_cfg *cfg,
475e705c121SKalle Valo 			       unsigned int wdg_timeout);
476e705c121SKalle Valo void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue,
477e705c121SKalle Valo 				bool configure_scd);
47842db09c1SLiad Kaufman void iwl_trans_pcie_txq_set_shared_mode(struct iwl_trans *trans, u32 txq_id,
47942db09c1SLiad Kaufman 					bool shared_mode);
4808aacf4b7SSara Sharon dma_addr_t iwl_trans_pcie_get_txq_byte_table(struct iwl_trans *trans, int txq);
48138398efbSSara Sharon void iwl_trans_pcie_log_scd_error(struct iwl_trans *trans,
48238398efbSSara Sharon 				  struct iwl_txq *txq);
483e705c121SKalle Valo int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
484e705c121SKalle Valo 		      struct iwl_device_cmd *dev_cmd, int txq_id);
485e705c121SKalle Valo void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans);
486e705c121SKalle Valo int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
487e705c121SKalle Valo void iwl_pcie_hcmd_complete(struct iwl_trans *trans,
488e705c121SKalle Valo 			    struct iwl_rx_cmd_buffer *rxb);
489e705c121SKalle Valo void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
490e705c121SKalle Valo 			    struct sk_buff_head *skbs);
491e705c121SKalle Valo void iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
492e705c121SKalle Valo 
4936983ba69SSara Sharon static inline u16 iwl_pcie_tfd_tb_get_len(struct iwl_trans *trans, void *tfd,
4946983ba69SSara Sharon 					  u8 idx)
495e705c121SKalle Valo {
4966983ba69SSara Sharon 	struct iwl_tfd *tfd_fh;
4976983ba69SSara Sharon 	struct iwl_tfd_tb *tb;
4986983ba69SSara Sharon 
4996983ba69SSara Sharon 	if (trans->cfg->use_tfh) {
5006983ba69SSara Sharon 		struct iwl_tfh_tfd *tfd_fh = (void *)tfd;
5016983ba69SSara Sharon 		struct iwl_tfh_tb *tb = &tfd_fh->tbs[idx];
5026983ba69SSara Sharon 
5036983ba69SSara Sharon 		return le16_to_cpu(tb->tb_len);
5046983ba69SSara Sharon 	}
5056983ba69SSara Sharon 
5066983ba69SSara Sharon 	tfd_fh = (void *)tfd;
5076983ba69SSara Sharon 	tb = &tfd_fh->tbs[idx];
508e705c121SKalle Valo 
509e705c121SKalle Valo 	return le16_to_cpu(tb->hi_n_len) >> 4;
510e705c121SKalle Valo }
511e705c121SKalle Valo 
512e705c121SKalle Valo /*****************************************************
513e705c121SKalle Valo * Error handling
514e705c121SKalle Valo ******************************************************/
515e705c121SKalle Valo void iwl_pcie_dump_csr(struct iwl_trans *trans);
516e705c121SKalle Valo 
517e705c121SKalle Valo /*****************************************************
518e705c121SKalle Valo * Helpers
519e705c121SKalle Valo ******************************************************/
520f16c3ebfSEmmanuel Grumbach static inline void _iwl_disable_interrupts(struct iwl_trans *trans)
521e705c121SKalle Valo {
5222e5d4a8fSHaim Dreyfuss 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
523e705c121SKalle Valo 
5242e5d4a8fSHaim Dreyfuss 	clear_bit(STATUS_INT_ENABLED, &trans->status);
5252e5d4a8fSHaim Dreyfuss 	if (!trans_pcie->msix_enabled) {
526e705c121SKalle Valo 		/* disable interrupts from uCode/NIC to host */
527e705c121SKalle Valo 		iwl_write32(trans, CSR_INT_MASK, 0x00000000);
528e705c121SKalle Valo 
529e705c121SKalle Valo 		/* acknowledge/clear/reset any interrupts still pending
530e705c121SKalle Valo 		 * from uCode or flow handler (Rx/Tx DMA) */
531e705c121SKalle Valo 		iwl_write32(trans, CSR_INT, 0xffffffff);
532e705c121SKalle Valo 		iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
5332e5d4a8fSHaim Dreyfuss 	} else {
5342e5d4a8fSHaim Dreyfuss 		/* disable all the interrupt we might use */
5352e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
5362e5d4a8fSHaim Dreyfuss 			    trans_pcie->fh_init_mask);
5372e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
5382e5d4a8fSHaim Dreyfuss 			    trans_pcie->hw_init_mask);
5392e5d4a8fSHaim Dreyfuss 	}
540e705c121SKalle Valo 	IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
541e705c121SKalle Valo }
542e705c121SKalle Valo 
543f16c3ebfSEmmanuel Grumbach static inline void iwl_disable_interrupts(struct iwl_trans *trans)
544f16c3ebfSEmmanuel Grumbach {
545f16c3ebfSEmmanuel Grumbach 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
546f16c3ebfSEmmanuel Grumbach 
547f16c3ebfSEmmanuel Grumbach 	spin_lock(&trans_pcie->irq_lock);
548f16c3ebfSEmmanuel Grumbach 	_iwl_disable_interrupts(trans);
549f16c3ebfSEmmanuel Grumbach 	spin_unlock(&trans_pcie->irq_lock);
550f16c3ebfSEmmanuel Grumbach }
551f16c3ebfSEmmanuel Grumbach 
552f16c3ebfSEmmanuel Grumbach static inline void _iwl_enable_interrupts(struct iwl_trans *trans)
553e705c121SKalle Valo {
554e705c121SKalle Valo 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
555e705c121SKalle Valo 
556e705c121SKalle Valo 	IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
557e705c121SKalle Valo 	set_bit(STATUS_INT_ENABLED, &trans->status);
5582e5d4a8fSHaim Dreyfuss 	if (!trans_pcie->msix_enabled) {
559e705c121SKalle Valo 		trans_pcie->inta_mask = CSR_INI_SET_MASK;
560e705c121SKalle Valo 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
5612e5d4a8fSHaim Dreyfuss 	} else {
5622e5d4a8fSHaim Dreyfuss 		/*
5632e5d4a8fSHaim Dreyfuss 		 * fh/hw_mask keeps all the unmasked causes.
5642e5d4a8fSHaim Dreyfuss 		 * Unlike msi, in msix cause is enabled when it is unset.
5652e5d4a8fSHaim Dreyfuss 		 */
5662e5d4a8fSHaim Dreyfuss 		trans_pcie->hw_mask = trans_pcie->hw_init_mask;
5672e5d4a8fSHaim Dreyfuss 		trans_pcie->fh_mask = trans_pcie->fh_init_mask;
5682e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
5692e5d4a8fSHaim Dreyfuss 			    ~trans_pcie->fh_mask);
5702e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
5712e5d4a8fSHaim Dreyfuss 			    ~trans_pcie->hw_mask);
5722e5d4a8fSHaim Dreyfuss 	}
5732e5d4a8fSHaim Dreyfuss }
5742e5d4a8fSHaim Dreyfuss 
575f16c3ebfSEmmanuel Grumbach static inline void iwl_enable_interrupts(struct iwl_trans *trans)
576f16c3ebfSEmmanuel Grumbach {
577f16c3ebfSEmmanuel Grumbach 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
578f16c3ebfSEmmanuel Grumbach 
579f16c3ebfSEmmanuel Grumbach 	spin_lock(&trans_pcie->irq_lock);
580f16c3ebfSEmmanuel Grumbach 	_iwl_enable_interrupts(trans);
581f16c3ebfSEmmanuel Grumbach 	spin_unlock(&trans_pcie->irq_lock);
582f16c3ebfSEmmanuel Grumbach }
5832e5d4a8fSHaim Dreyfuss static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk)
5842e5d4a8fSHaim Dreyfuss {
5852e5d4a8fSHaim Dreyfuss 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
5862e5d4a8fSHaim Dreyfuss 
5872e5d4a8fSHaim Dreyfuss 	iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk);
5882e5d4a8fSHaim Dreyfuss 	trans_pcie->hw_mask = msk;
5892e5d4a8fSHaim Dreyfuss }
5902e5d4a8fSHaim Dreyfuss 
5912e5d4a8fSHaim Dreyfuss static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk)
5922e5d4a8fSHaim Dreyfuss {
5932e5d4a8fSHaim Dreyfuss 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
5942e5d4a8fSHaim Dreyfuss 
5952e5d4a8fSHaim Dreyfuss 	iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk);
5962e5d4a8fSHaim Dreyfuss 	trans_pcie->fh_mask = msk;
597e705c121SKalle Valo }
598e705c121SKalle Valo 
599a6bd005fSEmmanuel Grumbach static inline void iwl_enable_fw_load_int(struct iwl_trans *trans)
600a6bd005fSEmmanuel Grumbach {
601a6bd005fSEmmanuel Grumbach 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
602a6bd005fSEmmanuel Grumbach 
603a6bd005fSEmmanuel Grumbach 	IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n");
6042e5d4a8fSHaim Dreyfuss 	if (!trans_pcie->msix_enabled) {
605a6bd005fSEmmanuel Grumbach 		trans_pcie->inta_mask = CSR_INT_BIT_FH_TX;
606a6bd005fSEmmanuel Grumbach 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
6072e5d4a8fSHaim Dreyfuss 	} else {
6082e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
6092e5d4a8fSHaim Dreyfuss 			    trans_pcie->hw_init_mask);
6102e5d4a8fSHaim Dreyfuss 		iwl_enable_fh_int_msk_msix(trans,
6112e5d4a8fSHaim Dreyfuss 					   MSIX_FH_INT_CAUSES_D2S_CH0_NUM);
6122e5d4a8fSHaim Dreyfuss 	}
613a6bd005fSEmmanuel Grumbach }
614a6bd005fSEmmanuel Grumbach 
615e705c121SKalle Valo static inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
616e705c121SKalle Valo {
617e705c121SKalle Valo 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
618e705c121SKalle Valo 
619e705c121SKalle Valo 	IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
6202e5d4a8fSHaim Dreyfuss 	if (!trans_pcie->msix_enabled) {
621e705c121SKalle Valo 		trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL;
622e705c121SKalle Valo 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
6232e5d4a8fSHaim Dreyfuss 	} else {
6242e5d4a8fSHaim Dreyfuss 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
6252e5d4a8fSHaim Dreyfuss 			    trans_pcie->fh_init_mask);
6262e5d4a8fSHaim Dreyfuss 		iwl_enable_hw_int_msk_msix(trans,
6272e5d4a8fSHaim Dreyfuss 					   MSIX_HW_INT_CAUSES_REG_RF_KILL);
6282e5d4a8fSHaim Dreyfuss 	}
629e705c121SKalle Valo }
630e705c121SKalle Valo 
631e705c121SKalle Valo static inline void iwl_wake_queue(struct iwl_trans *trans,
632e705c121SKalle Valo 				  struct iwl_txq *txq)
633e705c121SKalle Valo {
634e705c121SKalle Valo 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
635e705c121SKalle Valo 
636e705c121SKalle Valo 	if (test_and_clear_bit(txq->q.id, trans_pcie->queue_stopped)) {
637e705c121SKalle Valo 		IWL_DEBUG_TX_QUEUES(trans, "Wake hwq %d\n", txq->q.id);
638e705c121SKalle Valo 		iwl_op_mode_queue_not_full(trans->op_mode, txq->q.id);
639e705c121SKalle Valo 	}
640e705c121SKalle Valo }
641e705c121SKalle Valo 
642e705c121SKalle Valo static inline void iwl_stop_queue(struct iwl_trans *trans,
643e705c121SKalle Valo 				  struct iwl_txq *txq)
644e705c121SKalle Valo {
645e705c121SKalle Valo 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
646e705c121SKalle Valo 
647e705c121SKalle Valo 	if (!test_and_set_bit(txq->q.id, trans_pcie->queue_stopped)) {
648e705c121SKalle Valo 		iwl_op_mode_queue_full(trans->op_mode, txq->q.id);
649e705c121SKalle Valo 		IWL_DEBUG_TX_QUEUES(trans, "Stop hwq %d\n", txq->q.id);
650e705c121SKalle Valo 	} else
651e705c121SKalle Valo 		IWL_DEBUG_TX_QUEUES(trans, "hwq %d already stopped\n",
652e705c121SKalle Valo 				    txq->q.id);
653e705c121SKalle Valo }
654e705c121SKalle Valo 
655e705c121SKalle Valo static inline bool iwl_queue_used(const struct iwl_queue *q, int i)
656e705c121SKalle Valo {
657e705c121SKalle Valo 	return q->write_ptr >= q->read_ptr ?
658e705c121SKalle Valo 		(i >= q->read_ptr && i < q->write_ptr) :
659e705c121SKalle Valo 		!(i < q->read_ptr && i >= q->write_ptr);
660e705c121SKalle Valo }
661e705c121SKalle Valo 
662e705c121SKalle Valo static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
663e705c121SKalle Valo {
664e705c121SKalle Valo 	return index & (q->n_window - 1);
665e705c121SKalle Valo }
666e705c121SKalle Valo 
667e705c121SKalle Valo static inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
668e705c121SKalle Valo {
669e705c121SKalle Valo 	return !(iwl_read32(trans, CSR_GP_CNTRL) &
670e705c121SKalle Valo 		CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
671e705c121SKalle Valo }
672e705c121SKalle Valo 
673e705c121SKalle Valo static inline void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
674e705c121SKalle Valo 						  u32 reg, u32 mask, u32 value)
675e705c121SKalle Valo {
676e705c121SKalle Valo 	u32 v;
677e705c121SKalle Valo 
678e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_DEBUG
679e705c121SKalle Valo 	WARN_ON_ONCE(value & ~mask);
680e705c121SKalle Valo #endif
681e705c121SKalle Valo 
682e705c121SKalle Valo 	v = iwl_read32(trans, reg);
683e705c121SKalle Valo 	v &= ~mask;
684e705c121SKalle Valo 	v |= value;
685e705c121SKalle Valo 	iwl_write32(trans, reg, v);
686e705c121SKalle Valo }
687e705c121SKalle Valo 
688e705c121SKalle Valo static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
689e705c121SKalle Valo 					      u32 reg, u32 mask)
690e705c121SKalle Valo {
691e705c121SKalle Valo 	__iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
692e705c121SKalle Valo }
693e705c121SKalle Valo 
694e705c121SKalle Valo static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
695e705c121SKalle Valo 					    u32 reg, u32 mask)
696e705c121SKalle Valo {
697e705c121SKalle Valo 	__iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
698e705c121SKalle Valo }
699e705c121SKalle Valo 
700e705c121SKalle Valo void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state);
701e705c121SKalle Valo 
702f8a1edb7SJohannes Berg #ifdef CONFIG_IWLWIFI_DEBUGFS
703f8a1edb7SJohannes Berg int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans);
704f8a1edb7SJohannes Berg #else
705f8a1edb7SJohannes Berg static inline int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans)
706f8a1edb7SJohannes Berg {
707f8a1edb7SJohannes Berg 	return 0;
708f8a1edb7SJohannes Berg }
709f8a1edb7SJohannes Berg #endif
710f8a1edb7SJohannes Berg 
7114cbb8e50SLuciano Coelho int iwl_pci_fw_exit_d0i3(struct iwl_trans *trans);
7124cbb8e50SLuciano Coelho int iwl_pci_fw_enter_d0i3(struct iwl_trans *trans);
7134cbb8e50SLuciano Coelho 
7141316d595SSara Sharon void iwl_pcie_enable_rx_wake(struct iwl_trans *trans, bool enable);
7151316d595SSara Sharon 
716e705c121SKalle Valo #endif /* __iwl_trans_int_pcie_h__ */
717