xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlwifi/pcie/internal.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
4*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright(c) 2003 - 2015 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify it
14*4882a593Smuzhiyun  * under the terms of version 2 of the GNU General Public License as
15*4882a593Smuzhiyun  * published by the Free Software Foundation.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but WITHOUT
18*4882a593Smuzhiyun  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
20*4882a593Smuzhiyun  * more details.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution in the
23*4882a593Smuzhiyun  * file called COPYING.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Contact Information:
26*4882a593Smuzhiyun  *  Intel Linux Wireless <linuxwifi@intel.com>
27*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * BSD LICENSE
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * Copyright(c) 2003 - 2015 Intel Corporation. All rights reserved.
32*4882a593Smuzhiyun  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33*4882a593Smuzhiyun  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
35*4882a593Smuzhiyun  * All rights reserved.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
38*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
39*4882a593Smuzhiyun  * are met:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  *  * Redistributions of source code must retain the above copyright
42*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
43*4882a593Smuzhiyun  *  * Redistributions in binary form must reproduce the above copyright
44*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
45*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
46*4882a593Smuzhiyun  *    distribution.
47*4882a593Smuzhiyun  *  * Neither the name Intel Corporation nor the names of its
48*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
49*4882a593Smuzhiyun  *    from this software without specific prior written permission.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  *****************************************************************************/
64*4882a593Smuzhiyun #ifndef __iwl_trans_int_pcie_h__
65*4882a593Smuzhiyun #define __iwl_trans_int_pcie_h__
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #include <linux/spinlock.h>
68*4882a593Smuzhiyun #include <linux/interrupt.h>
69*4882a593Smuzhiyun #include <linux/skbuff.h>
70*4882a593Smuzhiyun #include <linux/wait.h>
71*4882a593Smuzhiyun #include <linux/pci.h>
72*4882a593Smuzhiyun #include <linux/timer.h>
73*4882a593Smuzhiyun #include <linux/cpu.h>
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun #include "iwl-fh.h"
76*4882a593Smuzhiyun #include "iwl-csr.h"
77*4882a593Smuzhiyun #include "iwl-trans.h"
78*4882a593Smuzhiyun #include "iwl-debug.h"
79*4882a593Smuzhiyun #include "iwl-io.h"
80*4882a593Smuzhiyun #include "iwl-op-mode.h"
81*4882a593Smuzhiyun #include "iwl-drv.h"
82*4882a593Smuzhiyun #include "queue/tx.h"
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * RX related structures and functions
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun #define RX_NUM_QUEUES 1
88*4882a593Smuzhiyun #define RX_POST_REQ_ALLOC 2
89*4882a593Smuzhiyun #define RX_CLAIM_REQ_ALLOC 8
90*4882a593Smuzhiyun #define RX_PENDING_WATERMARK 16
91*4882a593Smuzhiyun #define FIRST_RX_QUEUE 512
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun struct iwl_host_cmd;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*This file includes the declaration that are internal to the
96*4882a593Smuzhiyun  * trans_pcie layer */
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /**
99*4882a593Smuzhiyun  * struct iwl_rx_mem_buffer
100*4882a593Smuzhiyun  * @page_dma: bus address of rxb page
101*4882a593Smuzhiyun  * @page: driver's pointer to the rxb page
102*4882a593Smuzhiyun  * @invalid: rxb is in driver ownership - not owned by HW
103*4882a593Smuzhiyun  * @vid: index of this rxb in the global table
104*4882a593Smuzhiyun  * @offset: indicates which offset of the page (in bytes)
105*4882a593Smuzhiyun  *	this buffer uses (if multiple RBs fit into one page)
106*4882a593Smuzhiyun  */
107*4882a593Smuzhiyun struct iwl_rx_mem_buffer {
108*4882a593Smuzhiyun 	dma_addr_t page_dma;
109*4882a593Smuzhiyun 	struct page *page;
110*4882a593Smuzhiyun 	u16 vid;
111*4882a593Smuzhiyun 	bool invalid;
112*4882a593Smuzhiyun 	struct list_head list;
113*4882a593Smuzhiyun 	u32 offset;
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun  * struct isr_statistics - interrupt statistics
118*4882a593Smuzhiyun  *
119*4882a593Smuzhiyun  */
120*4882a593Smuzhiyun struct isr_statistics {
121*4882a593Smuzhiyun 	u32 hw;
122*4882a593Smuzhiyun 	u32 sw;
123*4882a593Smuzhiyun 	u32 err_code;
124*4882a593Smuzhiyun 	u32 sch;
125*4882a593Smuzhiyun 	u32 alive;
126*4882a593Smuzhiyun 	u32 rfkill;
127*4882a593Smuzhiyun 	u32 ctkill;
128*4882a593Smuzhiyun 	u32 wakeup;
129*4882a593Smuzhiyun 	u32 rx;
130*4882a593Smuzhiyun 	u32 tx;
131*4882a593Smuzhiyun 	u32 unhandled;
132*4882a593Smuzhiyun };
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun /**
135*4882a593Smuzhiyun  * struct iwl_rx_transfer_desc - transfer descriptor
136*4882a593Smuzhiyun  * @addr: ptr to free buffer start address
137*4882a593Smuzhiyun  * @rbid: unique tag of the buffer
138*4882a593Smuzhiyun  * @reserved: reserved
139*4882a593Smuzhiyun  */
140*4882a593Smuzhiyun struct iwl_rx_transfer_desc {
141*4882a593Smuzhiyun 	__le16 rbid;
142*4882a593Smuzhiyun 	__le16 reserved[3];
143*4882a593Smuzhiyun 	__le64 addr;
144*4882a593Smuzhiyun } __packed;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun #define IWL_RX_CD_FLAGS_FRAGMENTED	BIT(0)
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /**
149*4882a593Smuzhiyun  * struct iwl_rx_completion_desc - completion descriptor
150*4882a593Smuzhiyun  * @reserved1: reserved
151*4882a593Smuzhiyun  * @rbid: unique tag of the received buffer
152*4882a593Smuzhiyun  * @flags: flags (0: fragmented, all others: reserved)
153*4882a593Smuzhiyun  * @reserved2: reserved
154*4882a593Smuzhiyun  */
155*4882a593Smuzhiyun struct iwl_rx_completion_desc {
156*4882a593Smuzhiyun 	__le32 reserved1;
157*4882a593Smuzhiyun 	__le16 rbid;
158*4882a593Smuzhiyun 	u8 flags;
159*4882a593Smuzhiyun 	u8 reserved2[25];
160*4882a593Smuzhiyun } __packed;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun /**
163*4882a593Smuzhiyun  * struct iwl_rxq - Rx queue
164*4882a593Smuzhiyun  * @id: queue index
165*4882a593Smuzhiyun  * @bd: driver's pointer to buffer of receive buffer descriptors (rbd).
166*4882a593Smuzhiyun  *	Address size is 32 bit in pre-9000 devices and 64 bit in 9000 devices.
167*4882a593Smuzhiyun  *	In AX210 devices it is a pointer to a list of iwl_rx_transfer_desc's
168*4882a593Smuzhiyun  * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
169*4882a593Smuzhiyun  * @ubd: driver's pointer to buffer of used receive buffer descriptors (rbd)
170*4882a593Smuzhiyun  * @ubd_dma: physical address of buffer of used receive buffer descriptors (rbd)
171*4882a593Smuzhiyun  * @tr_tail: driver's pointer to the transmission ring tail buffer
172*4882a593Smuzhiyun  * @tr_tail_dma: physical address of the buffer for the transmission ring tail
173*4882a593Smuzhiyun  * @cr_tail: driver's pointer to the completion ring tail buffer
174*4882a593Smuzhiyun  * @cr_tail_dma: physical address of the buffer for the completion ring tail
175*4882a593Smuzhiyun  * @read: Shared index to newest available Rx buffer
176*4882a593Smuzhiyun  * @write: Shared index to oldest written Rx packet
177*4882a593Smuzhiyun  * @free_count: Number of pre-allocated buffers in rx_free
178*4882a593Smuzhiyun  * @used_count: Number of RBDs handled to allocator to use for allocation
179*4882a593Smuzhiyun  * @write_actual:
180*4882a593Smuzhiyun  * @rx_free: list of RBDs with allocated RB ready for use
181*4882a593Smuzhiyun  * @rx_used: list of RBDs with no RB attached
182*4882a593Smuzhiyun  * @need_update: flag to indicate we need to update read/write index
183*4882a593Smuzhiyun  * @rb_stts: driver's pointer to receive buffer status
184*4882a593Smuzhiyun  * @rb_stts_dma: bus address of receive buffer status
185*4882a593Smuzhiyun  * @lock:
186*4882a593Smuzhiyun  * @queue: actual rx queue. Not used for multi-rx queue.
187*4882a593Smuzhiyun  * @next_rb_is_fragment: indicates that the previous RB that we handled set
188*4882a593Smuzhiyun  *	the fragmented flag, so the next one is still another fragment
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * NOTE:  rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
191*4882a593Smuzhiyun  */
192*4882a593Smuzhiyun struct iwl_rxq {
193*4882a593Smuzhiyun 	int id;
194*4882a593Smuzhiyun 	void *bd;
195*4882a593Smuzhiyun 	dma_addr_t bd_dma;
196*4882a593Smuzhiyun 	union {
197*4882a593Smuzhiyun 		void *used_bd;
198*4882a593Smuzhiyun 		__le32 *bd_32;
199*4882a593Smuzhiyun 		struct iwl_rx_completion_desc *cd;
200*4882a593Smuzhiyun 	};
201*4882a593Smuzhiyun 	dma_addr_t used_bd_dma;
202*4882a593Smuzhiyun 	__le16 *tr_tail;
203*4882a593Smuzhiyun 	dma_addr_t tr_tail_dma;
204*4882a593Smuzhiyun 	__le16 *cr_tail;
205*4882a593Smuzhiyun 	dma_addr_t cr_tail_dma;
206*4882a593Smuzhiyun 	u32 read;
207*4882a593Smuzhiyun 	u32 write;
208*4882a593Smuzhiyun 	u32 free_count;
209*4882a593Smuzhiyun 	u32 used_count;
210*4882a593Smuzhiyun 	u32 write_actual;
211*4882a593Smuzhiyun 	u32 queue_size;
212*4882a593Smuzhiyun 	struct list_head rx_free;
213*4882a593Smuzhiyun 	struct list_head rx_used;
214*4882a593Smuzhiyun 	bool need_update, next_rb_is_fragment;
215*4882a593Smuzhiyun 	void *rb_stts;
216*4882a593Smuzhiyun 	dma_addr_t rb_stts_dma;
217*4882a593Smuzhiyun 	spinlock_t lock;
218*4882a593Smuzhiyun 	struct napi_struct napi;
219*4882a593Smuzhiyun 	struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /**
223*4882a593Smuzhiyun  * struct iwl_rb_allocator - Rx allocator
224*4882a593Smuzhiyun  * @req_pending: number of requests the allcator had not processed yet
225*4882a593Smuzhiyun  * @req_ready: number of requests honored and ready for claiming
226*4882a593Smuzhiyun  * @rbd_allocated: RBDs with pages allocated and ready to be handled to
227*4882a593Smuzhiyun  *	the queue. This is a list of &struct iwl_rx_mem_buffer
228*4882a593Smuzhiyun  * @rbd_empty: RBDs with no page attached for allocator use. This is a list
229*4882a593Smuzhiyun  *	of &struct iwl_rx_mem_buffer
230*4882a593Smuzhiyun  * @lock: protects the rbd_allocated and rbd_empty lists
231*4882a593Smuzhiyun  * @alloc_wq: work queue for background calls
232*4882a593Smuzhiyun  * @rx_alloc: work struct for background calls
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun struct iwl_rb_allocator {
235*4882a593Smuzhiyun 	atomic_t req_pending;
236*4882a593Smuzhiyun 	atomic_t req_ready;
237*4882a593Smuzhiyun 	struct list_head rbd_allocated;
238*4882a593Smuzhiyun 	struct list_head rbd_empty;
239*4882a593Smuzhiyun 	spinlock_t lock;
240*4882a593Smuzhiyun 	struct workqueue_struct *alloc_wq;
241*4882a593Smuzhiyun 	struct work_struct rx_alloc;
242*4882a593Smuzhiyun };
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun /**
245*4882a593Smuzhiyun  * iwl_get_closed_rb_stts - get closed rb stts from different structs
246*4882a593Smuzhiyun  * @rxq - the rxq to get the rb stts from
247*4882a593Smuzhiyun  */
iwl_get_closed_rb_stts(struct iwl_trans * trans,struct iwl_rxq * rxq)248*4882a593Smuzhiyun static inline __le16 iwl_get_closed_rb_stts(struct iwl_trans *trans,
249*4882a593Smuzhiyun 					    struct iwl_rxq *rxq)
250*4882a593Smuzhiyun {
251*4882a593Smuzhiyun 	if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
252*4882a593Smuzhiyun 		__le16 *rb_stts = rxq->rb_stts;
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 		return READ_ONCE(*rb_stts);
255*4882a593Smuzhiyun 	} else {
256*4882a593Smuzhiyun 		struct iwl_rb_status *rb_stts = rxq->rb_stts;
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 		return READ_ONCE(rb_stts->closed_rb_num);
259*4882a593Smuzhiyun 	}
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
263*4882a593Smuzhiyun /**
264*4882a593Smuzhiyun  * enum iwl_fw_mon_dbgfs_state - the different states of the monitor_data
265*4882a593Smuzhiyun  * debugfs file
266*4882a593Smuzhiyun  *
267*4882a593Smuzhiyun  * @IWL_FW_MON_DBGFS_STATE_CLOSED: the file is closed.
268*4882a593Smuzhiyun  * @IWL_FW_MON_DBGFS_STATE_OPEN: the file is open.
269*4882a593Smuzhiyun  * @IWL_FW_MON_DBGFS_STATE_DISABLED: the file is disabled, once this state is
270*4882a593Smuzhiyun  *	set the file can no longer be used.
271*4882a593Smuzhiyun  */
272*4882a593Smuzhiyun enum iwl_fw_mon_dbgfs_state {
273*4882a593Smuzhiyun 	IWL_FW_MON_DBGFS_STATE_CLOSED,
274*4882a593Smuzhiyun 	IWL_FW_MON_DBGFS_STATE_OPEN,
275*4882a593Smuzhiyun 	IWL_FW_MON_DBGFS_STATE_DISABLED,
276*4882a593Smuzhiyun };
277*4882a593Smuzhiyun #endif
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun /**
280*4882a593Smuzhiyun  * enum iwl_shared_irq_flags - level of sharing for irq
281*4882a593Smuzhiyun  * @IWL_SHARED_IRQ_NON_RX: interrupt vector serves non rx causes.
282*4882a593Smuzhiyun  * @IWL_SHARED_IRQ_FIRST_RSS: interrupt vector serves first RSS queue.
283*4882a593Smuzhiyun  */
284*4882a593Smuzhiyun enum iwl_shared_irq_flags {
285*4882a593Smuzhiyun 	IWL_SHARED_IRQ_NON_RX		= BIT(0),
286*4882a593Smuzhiyun 	IWL_SHARED_IRQ_FIRST_RSS	= BIT(1),
287*4882a593Smuzhiyun };
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun /**
290*4882a593Smuzhiyun  * enum iwl_image_response_code - image response values
291*4882a593Smuzhiyun  * @IWL_IMAGE_RESP_DEF: the default value of the register
292*4882a593Smuzhiyun  * @IWL_IMAGE_RESP_SUCCESS: iml was read successfully
293*4882a593Smuzhiyun  * @IWL_IMAGE_RESP_FAIL: iml reading failed
294*4882a593Smuzhiyun  */
295*4882a593Smuzhiyun enum iwl_image_response_code {
296*4882a593Smuzhiyun 	IWL_IMAGE_RESP_DEF		= 0,
297*4882a593Smuzhiyun 	IWL_IMAGE_RESP_SUCCESS		= 1,
298*4882a593Smuzhiyun 	IWL_IMAGE_RESP_FAIL		= 2,
299*4882a593Smuzhiyun };
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun /**
302*4882a593Smuzhiyun  * struct cont_rec: continuous recording data structure
303*4882a593Smuzhiyun  * @prev_wr_ptr: the last address that was read in monitor_data
304*4882a593Smuzhiyun  *	debugfs file
305*4882a593Smuzhiyun  * @prev_wrap_cnt: the wrap count that was used during the last read in
306*4882a593Smuzhiyun  *	monitor_data debugfs file
307*4882a593Smuzhiyun  * @state: the state of monitor_data debugfs file as described
308*4882a593Smuzhiyun  *	in &iwl_fw_mon_dbgfs_state enum
309*4882a593Smuzhiyun  * @mutex: locked while reading from monitor_data debugfs file
310*4882a593Smuzhiyun  */
311*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
312*4882a593Smuzhiyun struct cont_rec {
313*4882a593Smuzhiyun 	u32 prev_wr_ptr;
314*4882a593Smuzhiyun 	u32 prev_wrap_cnt;
315*4882a593Smuzhiyun 	u8  state;
316*4882a593Smuzhiyun 	/* Used to sync monitor_data debugfs file with driver unload flow */
317*4882a593Smuzhiyun 	struct mutex mutex;
318*4882a593Smuzhiyun };
319*4882a593Smuzhiyun #endif
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun /**
322*4882a593Smuzhiyun  * struct iwl_trans_pcie - PCIe transport specific data
323*4882a593Smuzhiyun  * @rxq: all the RX queue data
324*4882a593Smuzhiyun  * @rx_pool: initial pool of iwl_rx_mem_buffer for all the queues
325*4882a593Smuzhiyun  * @global_table: table mapping received VID from hw to rxb
326*4882a593Smuzhiyun  * @rba: allocator for RX replenishing
327*4882a593Smuzhiyun  * @ctxt_info: context information for FW self init
328*4882a593Smuzhiyun  * @ctxt_info_gen3: context information for gen3 devices
329*4882a593Smuzhiyun  * @prph_info: prph info for self init
330*4882a593Smuzhiyun  * @prph_scratch: prph scratch for self init
331*4882a593Smuzhiyun  * @ctxt_info_dma_addr: dma addr of context information
332*4882a593Smuzhiyun  * @prph_info_dma_addr: dma addr of prph info
333*4882a593Smuzhiyun  * @prph_scratch_dma_addr: dma addr of prph scratch
334*4882a593Smuzhiyun  * @ctxt_info_dma_addr: dma addr of context information
335*4882a593Smuzhiyun  * @init_dram: DRAM data of firmware image (including paging).
336*4882a593Smuzhiyun  *	Context information addresses will be taken from here.
337*4882a593Smuzhiyun  *	This is driver's local copy for keeping track of size and
338*4882a593Smuzhiyun  *	count for allocating and freeing the memory.
339*4882a593Smuzhiyun  * @iml: image loader image virtual address
340*4882a593Smuzhiyun  * @iml_dma_addr: image loader image DMA address
341*4882a593Smuzhiyun  * @trans: pointer to the generic transport area
342*4882a593Smuzhiyun  * @scd_base_addr: scheduler sram base address in SRAM
343*4882a593Smuzhiyun  * @kw: keep warm address
344*4882a593Smuzhiyun  * @pnvm_dram: DRAM area that contains the PNVM data
345*4882a593Smuzhiyun  * @pci_dev: basic pci-network driver stuff
346*4882a593Smuzhiyun  * @hw_base: pci hardware address support
347*4882a593Smuzhiyun  * @ucode_write_complete: indicates that the ucode has been copied.
348*4882a593Smuzhiyun  * @ucode_write_waitq: wait queue for uCode load
349*4882a593Smuzhiyun  * @cmd_queue - command queue number
350*4882a593Smuzhiyun  * @def_rx_queue - default rx queue number
351*4882a593Smuzhiyun  * @rx_buf_size: Rx buffer size
352*4882a593Smuzhiyun  * @scd_set_active: should the transport configure the SCD for HCMD queue
353*4882a593Smuzhiyun  * @sw_csum_tx: if true, then the transport will compute the csum of the TXed
354*4882a593Smuzhiyun  *	frame.
355*4882a593Smuzhiyun  * @rx_page_order: page order for receive buffer size
356*4882a593Smuzhiyun  * @rx_buf_bytes: RX buffer (RB) size in bytes
357*4882a593Smuzhiyun  * @reg_lock: protect hw register access
358*4882a593Smuzhiyun  * @mutex: to protect stop_device / start_fw / start_hw
359*4882a593Smuzhiyun  * @cmd_in_flight: true when we have a host command in flight
360*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
361*4882a593Smuzhiyun  * @fw_mon_data: fw continuous recording data
362*4882a593Smuzhiyun #endif
363*4882a593Smuzhiyun  * @msix_entries: array of MSI-X entries
364*4882a593Smuzhiyun  * @msix_enabled: true if managed to enable MSI-X
365*4882a593Smuzhiyun  * @shared_vec_mask: the type of causes the shared vector handles
366*4882a593Smuzhiyun  *	(see iwl_shared_irq_flags).
367*4882a593Smuzhiyun  * @alloc_vecs: the number of interrupt vectors allocated by the OS
368*4882a593Smuzhiyun  * @def_irq: default irq for non rx causes
369*4882a593Smuzhiyun  * @fh_init_mask: initial unmasked fh causes
370*4882a593Smuzhiyun  * @hw_init_mask: initial unmasked hw causes
371*4882a593Smuzhiyun  * @fh_mask: current unmasked fh causes
372*4882a593Smuzhiyun  * @hw_mask: current unmasked hw causes
373*4882a593Smuzhiyun  * @in_rescan: true if we have triggered a device rescan
374*4882a593Smuzhiyun  * @base_rb_stts: base virtual address of receive buffer status for all queues
375*4882a593Smuzhiyun  * @base_rb_stts_dma: base physical address of receive buffer status
376*4882a593Smuzhiyun  * @supported_dma_mask: DMA mask to validate the actual address against,
377*4882a593Smuzhiyun  *	will be DMA_BIT_MASK(11) or DMA_BIT_MASK(12) depending on the device
378*4882a593Smuzhiyun  * @alloc_page_lock: spinlock for the page allocator
379*4882a593Smuzhiyun  * @alloc_page: allocated page to still use parts of
380*4882a593Smuzhiyun  * @alloc_page_used: how much of the allocated page was already used (bytes)
381*4882a593Smuzhiyun  */
382*4882a593Smuzhiyun struct iwl_trans_pcie {
383*4882a593Smuzhiyun 	struct iwl_rxq *rxq;
384*4882a593Smuzhiyun 	struct iwl_rx_mem_buffer *rx_pool;
385*4882a593Smuzhiyun 	struct iwl_rx_mem_buffer **global_table;
386*4882a593Smuzhiyun 	struct iwl_rb_allocator rba;
387*4882a593Smuzhiyun 	union {
388*4882a593Smuzhiyun 		struct iwl_context_info *ctxt_info;
389*4882a593Smuzhiyun 		struct iwl_context_info_gen3 *ctxt_info_gen3;
390*4882a593Smuzhiyun 	};
391*4882a593Smuzhiyun 	struct iwl_prph_info *prph_info;
392*4882a593Smuzhiyun 	struct iwl_prph_scratch *prph_scratch;
393*4882a593Smuzhiyun 	void *iml;
394*4882a593Smuzhiyun 	dma_addr_t ctxt_info_dma_addr;
395*4882a593Smuzhiyun 	dma_addr_t prph_info_dma_addr;
396*4882a593Smuzhiyun 	dma_addr_t prph_scratch_dma_addr;
397*4882a593Smuzhiyun 	dma_addr_t iml_dma_addr;
398*4882a593Smuzhiyun 	struct iwl_trans *trans;
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun 	struct net_device napi_dev;
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun 	/* INT ICT Table */
403*4882a593Smuzhiyun 	__le32 *ict_tbl;
404*4882a593Smuzhiyun 	dma_addr_t ict_tbl_dma;
405*4882a593Smuzhiyun 	int ict_index;
406*4882a593Smuzhiyun 	bool use_ict;
407*4882a593Smuzhiyun 	bool is_down, opmode_down;
408*4882a593Smuzhiyun 	s8 debug_rfkill;
409*4882a593Smuzhiyun 	struct isr_statistics isr_stats;
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	spinlock_t irq_lock;
412*4882a593Smuzhiyun 	struct mutex mutex;
413*4882a593Smuzhiyun 	u32 inta_mask;
414*4882a593Smuzhiyun 	u32 scd_base_addr;
415*4882a593Smuzhiyun 	struct iwl_dma_ptr kw;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	struct iwl_dram_data pnvm_dram;
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	struct iwl_txq *txq_memory;
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun 	/* PCI bus related data */
422*4882a593Smuzhiyun 	struct pci_dev *pci_dev;
423*4882a593Smuzhiyun 	void __iomem *hw_base;
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun 	bool ucode_write_complete;
426*4882a593Smuzhiyun 	bool sx_complete;
427*4882a593Smuzhiyun 	wait_queue_head_t ucode_write_waitq;
428*4882a593Smuzhiyun 	wait_queue_head_t wait_command_queue;
429*4882a593Smuzhiyun 	wait_queue_head_t sx_waitq;
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	u8 def_rx_queue;
432*4882a593Smuzhiyun 	u8 n_no_reclaim_cmds;
433*4882a593Smuzhiyun 	u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
434*4882a593Smuzhiyun 	u16 num_rx_bufs;
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun 	enum iwl_amsdu_size rx_buf_size;
437*4882a593Smuzhiyun 	bool scd_set_active;
438*4882a593Smuzhiyun 	bool sw_csum_tx;
439*4882a593Smuzhiyun 	bool pcie_dbg_dumped_once;
440*4882a593Smuzhiyun 	u32 rx_page_order;
441*4882a593Smuzhiyun 	u32 rx_buf_bytes;
442*4882a593Smuzhiyun 	u32 supported_dma_mask;
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun 	/* allocator lock for the two values below */
445*4882a593Smuzhiyun 	spinlock_t alloc_page_lock;
446*4882a593Smuzhiyun 	struct page *alloc_page;
447*4882a593Smuzhiyun 	u32 alloc_page_used;
448*4882a593Smuzhiyun 
449*4882a593Smuzhiyun 	/*protect hw register */
450*4882a593Smuzhiyun 	spinlock_t reg_lock;
451*4882a593Smuzhiyun 	bool cmd_hold_nic_awake;
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
454*4882a593Smuzhiyun 	struct cont_rec fw_mon_data;
455*4882a593Smuzhiyun #endif
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	struct msix_entry msix_entries[IWL_MAX_RX_HW_QUEUES];
458*4882a593Smuzhiyun 	bool msix_enabled;
459*4882a593Smuzhiyun 	u8 shared_vec_mask;
460*4882a593Smuzhiyun 	u32 alloc_vecs;
461*4882a593Smuzhiyun 	u32 def_irq;
462*4882a593Smuzhiyun 	u32 fh_init_mask;
463*4882a593Smuzhiyun 	u32 hw_init_mask;
464*4882a593Smuzhiyun 	u32 fh_mask;
465*4882a593Smuzhiyun 	u32 hw_mask;
466*4882a593Smuzhiyun 	cpumask_t affinity_mask[IWL_MAX_RX_HW_QUEUES];
467*4882a593Smuzhiyun 	u16 tx_cmd_queue_size;
468*4882a593Smuzhiyun 	bool in_rescan;
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun 	void *base_rb_stts;
471*4882a593Smuzhiyun 	dma_addr_t base_rb_stts_dma;
472*4882a593Smuzhiyun };
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun static inline struct iwl_trans_pcie *
IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans * trans)475*4882a593Smuzhiyun IWL_TRANS_GET_PCIE_TRANS(struct iwl_trans *trans)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun 	return (void *)trans->trans_specific;
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun 
iwl_pcie_clear_irq(struct iwl_trans * trans,struct msix_entry * entry)480*4882a593Smuzhiyun static inline void iwl_pcie_clear_irq(struct iwl_trans *trans,
481*4882a593Smuzhiyun 				      struct msix_entry *entry)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun 	/*
484*4882a593Smuzhiyun 	 * Before sending the interrupt the HW disables it to prevent
485*4882a593Smuzhiyun 	 * a nested interrupt. This is done by writing 1 to the corresponding
486*4882a593Smuzhiyun 	 * bit in the mask register. After handling the interrupt, it should be
487*4882a593Smuzhiyun 	 * re-enabled by clearing this bit. This register is defined as
488*4882a593Smuzhiyun 	 * write 1 clear (W1C) register, meaning that it's being clear
489*4882a593Smuzhiyun 	 * by writing 1 to the bit.
490*4882a593Smuzhiyun 	 */
491*4882a593Smuzhiyun 	iwl_write32(trans, CSR_MSIX_AUTOMASK_ST_AD, BIT(entry->entry));
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun 
494*4882a593Smuzhiyun static inline struct iwl_trans *
iwl_trans_pcie_get_trans(struct iwl_trans_pcie * trans_pcie)495*4882a593Smuzhiyun iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
496*4882a593Smuzhiyun {
497*4882a593Smuzhiyun 	return container_of((void *)trans_pcie, struct iwl_trans,
498*4882a593Smuzhiyun 			    trans_specific);
499*4882a593Smuzhiyun }
500*4882a593Smuzhiyun 
501*4882a593Smuzhiyun /*
502*4882a593Smuzhiyun  * Convention: trans API functions: iwl_trans_pcie_XXX
503*4882a593Smuzhiyun  *	Other functions: iwl_pcie_XXX
504*4882a593Smuzhiyun  */
505*4882a593Smuzhiyun struct iwl_trans
506*4882a593Smuzhiyun *iwl_trans_pcie_alloc(struct pci_dev *pdev,
507*4882a593Smuzhiyun 		      const struct pci_device_id *ent,
508*4882a593Smuzhiyun 		      const struct iwl_cfg_trans_params *cfg_trans);
509*4882a593Smuzhiyun void iwl_trans_pcie_free(struct iwl_trans *trans);
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun /*****************************************************
512*4882a593Smuzhiyun * RX
513*4882a593Smuzhiyun ******************************************************/
514*4882a593Smuzhiyun int iwl_pcie_rx_init(struct iwl_trans *trans);
515*4882a593Smuzhiyun int iwl_pcie_gen2_rx_init(struct iwl_trans *trans);
516*4882a593Smuzhiyun irqreturn_t iwl_pcie_msix_isr(int irq, void *data);
517*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id);
518*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id);
519*4882a593Smuzhiyun irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id);
520*4882a593Smuzhiyun int iwl_pcie_rx_stop(struct iwl_trans *trans);
521*4882a593Smuzhiyun void iwl_pcie_rx_free(struct iwl_trans *trans);
522*4882a593Smuzhiyun void iwl_pcie_free_rbs_pool(struct iwl_trans *trans);
523*4882a593Smuzhiyun void iwl_pcie_rx_init_rxb_lists(struct iwl_rxq *rxq);
524*4882a593Smuzhiyun int iwl_pcie_dummy_napi_poll(struct napi_struct *napi, int budget);
525*4882a593Smuzhiyun void iwl_pcie_rxq_alloc_rbs(struct iwl_trans *trans, gfp_t priority,
526*4882a593Smuzhiyun 			    struct iwl_rxq *rxq);
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun /*****************************************************
529*4882a593Smuzhiyun * ICT - interrupt handling
530*4882a593Smuzhiyun ******************************************************/
531*4882a593Smuzhiyun irqreturn_t iwl_pcie_isr(int irq, void *data);
532*4882a593Smuzhiyun int iwl_pcie_alloc_ict(struct iwl_trans *trans);
533*4882a593Smuzhiyun void iwl_pcie_free_ict(struct iwl_trans *trans);
534*4882a593Smuzhiyun void iwl_pcie_reset_ict(struct iwl_trans *trans);
535*4882a593Smuzhiyun void iwl_pcie_disable_ict(struct iwl_trans *trans);
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun /*****************************************************
538*4882a593Smuzhiyun * TX / HCMD
539*4882a593Smuzhiyun ******************************************************/
540*4882a593Smuzhiyun int iwl_pcie_tx_init(struct iwl_trans *trans);
541*4882a593Smuzhiyun void iwl_pcie_tx_start(struct iwl_trans *trans, u32 scd_base_addr);
542*4882a593Smuzhiyun int iwl_pcie_tx_stop(struct iwl_trans *trans);
543*4882a593Smuzhiyun void iwl_pcie_tx_free(struct iwl_trans *trans);
544*4882a593Smuzhiyun bool iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int queue, u16 ssn,
545*4882a593Smuzhiyun 			       const struct iwl_trans_txq_scd_cfg *cfg,
546*4882a593Smuzhiyun 			       unsigned int wdg_timeout);
547*4882a593Smuzhiyun void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue,
548*4882a593Smuzhiyun 				bool configure_scd);
549*4882a593Smuzhiyun void iwl_trans_pcie_txq_set_shared_mode(struct iwl_trans *trans, u32 txq_id,
550*4882a593Smuzhiyun 					bool shared_mode);
551*4882a593Smuzhiyun int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
552*4882a593Smuzhiyun 		      struct iwl_device_tx_cmd *dev_cmd, int txq_id);
553*4882a593Smuzhiyun void iwl_pcie_txq_check_wrptrs(struct iwl_trans *trans);
554*4882a593Smuzhiyun int iwl_trans_pcie_send_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
555*4882a593Smuzhiyun void iwl_pcie_hcmd_complete(struct iwl_trans *trans,
556*4882a593Smuzhiyun 			    struct iwl_rx_cmd_buffer *rxb);
557*4882a593Smuzhiyun void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
558*4882a593Smuzhiyun 			    struct sk_buff_head *skbs);
559*4882a593Smuzhiyun void iwl_trans_pcie_set_q_ptrs(struct iwl_trans *trans, int txq_id, int ptr);
560*4882a593Smuzhiyun void iwl_trans_pcie_tx_reset(struct iwl_trans *trans);
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun /*****************************************************
563*4882a593Smuzhiyun * Error handling
564*4882a593Smuzhiyun ******************************************************/
565*4882a593Smuzhiyun void iwl_pcie_dump_csr(struct iwl_trans *trans);
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun /*****************************************************
568*4882a593Smuzhiyun * Helpers
569*4882a593Smuzhiyun ******************************************************/
_iwl_disable_interrupts(struct iwl_trans * trans)570*4882a593Smuzhiyun static inline void _iwl_disable_interrupts(struct iwl_trans *trans)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun 	clear_bit(STATUS_INT_ENABLED, &trans->status);
575*4882a593Smuzhiyun 	if (!trans_pcie->msix_enabled) {
576*4882a593Smuzhiyun 		/* disable interrupts from uCode/NIC to host */
577*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT_MASK, 0x00000000);
578*4882a593Smuzhiyun 
579*4882a593Smuzhiyun 		/* acknowledge/clear/reset any interrupts still pending
580*4882a593Smuzhiyun 		 * from uCode or flow handler (Rx/Tx DMA) */
581*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT, 0xffffffff);
582*4882a593Smuzhiyun 		iwl_write32(trans, CSR_FH_INT_STATUS, 0xffffffff);
583*4882a593Smuzhiyun 	} else {
584*4882a593Smuzhiyun 		/* disable all the interrupt we might use */
585*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
586*4882a593Smuzhiyun 			    trans_pcie->fh_init_mask);
587*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
588*4882a593Smuzhiyun 			    trans_pcie->hw_init_mask);
589*4882a593Smuzhiyun 	}
590*4882a593Smuzhiyun 	IWL_DEBUG_ISR(trans, "Disabled interrupts\n");
591*4882a593Smuzhiyun }
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun #define IWL_NUM_OF_COMPLETION_RINGS	31
594*4882a593Smuzhiyun #define IWL_NUM_OF_TRANSFER_RINGS	527
595*4882a593Smuzhiyun 
iwl_pcie_get_num_sections(const struct fw_img * fw,int start)596*4882a593Smuzhiyun static inline int iwl_pcie_get_num_sections(const struct fw_img *fw,
597*4882a593Smuzhiyun 					    int start)
598*4882a593Smuzhiyun {
599*4882a593Smuzhiyun 	int i = 0;
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	while (start < fw->num_sec &&
602*4882a593Smuzhiyun 	       fw->sec[start].offset != CPU1_CPU2_SEPARATOR_SECTION &&
603*4882a593Smuzhiyun 	       fw->sec[start].offset != PAGING_SEPARATOR_SECTION) {
604*4882a593Smuzhiyun 		start++;
605*4882a593Smuzhiyun 		i++;
606*4882a593Smuzhiyun 	}
607*4882a593Smuzhiyun 
608*4882a593Smuzhiyun 	return i;
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun 
iwl_pcie_ctxt_info_free_fw_img(struct iwl_trans * trans)611*4882a593Smuzhiyun static inline void iwl_pcie_ctxt_info_free_fw_img(struct iwl_trans *trans)
612*4882a593Smuzhiyun {
613*4882a593Smuzhiyun 	struct iwl_self_init_dram *dram = &trans->init_dram;
614*4882a593Smuzhiyun 	int i;
615*4882a593Smuzhiyun 
616*4882a593Smuzhiyun 	if (!dram->fw) {
617*4882a593Smuzhiyun 		WARN_ON(dram->fw_cnt);
618*4882a593Smuzhiyun 		return;
619*4882a593Smuzhiyun 	}
620*4882a593Smuzhiyun 
621*4882a593Smuzhiyun 	for (i = 0; i < dram->fw_cnt; i++)
622*4882a593Smuzhiyun 		dma_free_coherent(trans->dev, dram->fw[i].size,
623*4882a593Smuzhiyun 				  dram->fw[i].block, dram->fw[i].physical);
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun 	kfree(dram->fw);
626*4882a593Smuzhiyun 	dram->fw_cnt = 0;
627*4882a593Smuzhiyun 	dram->fw = NULL;
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun 
iwl_disable_interrupts(struct iwl_trans * trans)630*4882a593Smuzhiyun static inline void iwl_disable_interrupts(struct iwl_trans *trans)
631*4882a593Smuzhiyun {
632*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun 	spin_lock(&trans_pcie->irq_lock);
635*4882a593Smuzhiyun 	_iwl_disable_interrupts(trans);
636*4882a593Smuzhiyun 	spin_unlock(&trans_pcie->irq_lock);
637*4882a593Smuzhiyun }
638*4882a593Smuzhiyun 
_iwl_enable_interrupts(struct iwl_trans * trans)639*4882a593Smuzhiyun static inline void _iwl_enable_interrupts(struct iwl_trans *trans)
640*4882a593Smuzhiyun {
641*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
642*4882a593Smuzhiyun 
643*4882a593Smuzhiyun 	IWL_DEBUG_ISR(trans, "Enabling interrupts\n");
644*4882a593Smuzhiyun 	set_bit(STATUS_INT_ENABLED, &trans->status);
645*4882a593Smuzhiyun 	if (!trans_pcie->msix_enabled) {
646*4882a593Smuzhiyun 		trans_pcie->inta_mask = CSR_INI_SET_MASK;
647*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
648*4882a593Smuzhiyun 	} else {
649*4882a593Smuzhiyun 		/*
650*4882a593Smuzhiyun 		 * fh/hw_mask keeps all the unmasked causes.
651*4882a593Smuzhiyun 		 * Unlike msi, in msix cause is enabled when it is unset.
652*4882a593Smuzhiyun 		 */
653*4882a593Smuzhiyun 		trans_pcie->hw_mask = trans_pcie->hw_init_mask;
654*4882a593Smuzhiyun 		trans_pcie->fh_mask = trans_pcie->fh_init_mask;
655*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
656*4882a593Smuzhiyun 			    ~trans_pcie->fh_mask);
657*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
658*4882a593Smuzhiyun 			    ~trans_pcie->hw_mask);
659*4882a593Smuzhiyun 	}
660*4882a593Smuzhiyun }
661*4882a593Smuzhiyun 
iwl_enable_interrupts(struct iwl_trans * trans)662*4882a593Smuzhiyun static inline void iwl_enable_interrupts(struct iwl_trans *trans)
663*4882a593Smuzhiyun {
664*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	spin_lock(&trans_pcie->irq_lock);
667*4882a593Smuzhiyun 	_iwl_enable_interrupts(trans);
668*4882a593Smuzhiyun 	spin_unlock(&trans_pcie->irq_lock);
669*4882a593Smuzhiyun }
iwl_enable_hw_int_msk_msix(struct iwl_trans * trans,u32 msk)670*4882a593Smuzhiyun static inline void iwl_enable_hw_int_msk_msix(struct iwl_trans *trans, u32 msk)
671*4882a593Smuzhiyun {
672*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun 	iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD, ~msk);
675*4882a593Smuzhiyun 	trans_pcie->hw_mask = msk;
676*4882a593Smuzhiyun }
677*4882a593Smuzhiyun 
iwl_enable_fh_int_msk_msix(struct iwl_trans * trans,u32 msk)678*4882a593Smuzhiyun static inline void iwl_enable_fh_int_msk_msix(struct iwl_trans *trans, u32 msk)
679*4882a593Smuzhiyun {
680*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun 	iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD, ~msk);
683*4882a593Smuzhiyun 	trans_pcie->fh_mask = msk;
684*4882a593Smuzhiyun }
685*4882a593Smuzhiyun 
iwl_enable_fw_load_int(struct iwl_trans * trans)686*4882a593Smuzhiyun static inline void iwl_enable_fw_load_int(struct iwl_trans *trans)
687*4882a593Smuzhiyun {
688*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	IWL_DEBUG_ISR(trans, "Enabling FW load interrupt\n");
691*4882a593Smuzhiyun 	if (!trans_pcie->msix_enabled) {
692*4882a593Smuzhiyun 		trans_pcie->inta_mask = CSR_INT_BIT_FH_TX;
693*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
694*4882a593Smuzhiyun 	} else {
695*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_HW_INT_MASK_AD,
696*4882a593Smuzhiyun 			    trans_pcie->hw_init_mask);
697*4882a593Smuzhiyun 		iwl_enable_fh_int_msk_msix(trans,
698*4882a593Smuzhiyun 					   MSIX_FH_INT_CAUSES_D2S_CH0_NUM);
699*4882a593Smuzhiyun 	}
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun 
iwl_enable_fw_load_int_ctx_info(struct iwl_trans * trans)702*4882a593Smuzhiyun static inline void iwl_enable_fw_load_int_ctx_info(struct iwl_trans *trans)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	IWL_DEBUG_ISR(trans, "Enabling ALIVE interrupt only\n");
707*4882a593Smuzhiyun 
708*4882a593Smuzhiyun 	if (!trans_pcie->msix_enabled) {
709*4882a593Smuzhiyun 		/*
710*4882a593Smuzhiyun 		 * When we'll receive the ALIVE interrupt, the ISR will call
711*4882a593Smuzhiyun 		 * iwl_enable_fw_load_int_ctx_info again to set the ALIVE
712*4882a593Smuzhiyun 		 * interrupt (which is not really needed anymore) but also the
713*4882a593Smuzhiyun 		 * RX interrupt which will allow us to receive the ALIVE
714*4882a593Smuzhiyun 		 * notification (which is Rx) and continue the flow.
715*4882a593Smuzhiyun 		 */
716*4882a593Smuzhiyun 		trans_pcie->inta_mask =  CSR_INT_BIT_ALIVE | CSR_INT_BIT_FH_RX;
717*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
718*4882a593Smuzhiyun 	} else {
719*4882a593Smuzhiyun 		iwl_enable_hw_int_msk_msix(trans,
720*4882a593Smuzhiyun 					   MSIX_HW_INT_CAUSES_REG_ALIVE);
721*4882a593Smuzhiyun 		/*
722*4882a593Smuzhiyun 		 * Leave all the FH causes enabled to get the ALIVE
723*4882a593Smuzhiyun 		 * notification.
724*4882a593Smuzhiyun 		 */
725*4882a593Smuzhiyun 		iwl_enable_fh_int_msk_msix(trans, trans_pcie->fh_init_mask);
726*4882a593Smuzhiyun 	}
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun 
queue_name(struct device * dev,struct iwl_trans_pcie * trans_p,int i)729*4882a593Smuzhiyun static inline const char *queue_name(struct device *dev,
730*4882a593Smuzhiyun 				     struct iwl_trans_pcie *trans_p, int i)
731*4882a593Smuzhiyun {
732*4882a593Smuzhiyun 	if (trans_p->shared_vec_mask) {
733*4882a593Smuzhiyun 		int vec = trans_p->shared_vec_mask &
734*4882a593Smuzhiyun 			  IWL_SHARED_IRQ_FIRST_RSS ? 1 : 0;
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 		if (i == 0)
737*4882a593Smuzhiyun 			return DRV_NAME ": shared IRQ";
738*4882a593Smuzhiyun 
739*4882a593Smuzhiyun 		return devm_kasprintf(dev, GFP_KERNEL,
740*4882a593Smuzhiyun 				      DRV_NAME ": queue %d", i + vec);
741*4882a593Smuzhiyun 	}
742*4882a593Smuzhiyun 	if (i == 0)
743*4882a593Smuzhiyun 		return DRV_NAME ": default queue";
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun 	if (i == trans_p->alloc_vecs - 1)
746*4882a593Smuzhiyun 		return DRV_NAME ": exception";
747*4882a593Smuzhiyun 
748*4882a593Smuzhiyun 	return devm_kasprintf(dev, GFP_KERNEL,
749*4882a593Smuzhiyun 			      DRV_NAME  ": queue %d", i);
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun 
iwl_enable_rfkill_int(struct iwl_trans * trans)752*4882a593Smuzhiyun static inline void iwl_enable_rfkill_int(struct iwl_trans *trans)
753*4882a593Smuzhiyun {
754*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
755*4882a593Smuzhiyun 
756*4882a593Smuzhiyun 	IWL_DEBUG_ISR(trans, "Enabling rfkill interrupt\n");
757*4882a593Smuzhiyun 	if (!trans_pcie->msix_enabled) {
758*4882a593Smuzhiyun 		trans_pcie->inta_mask = CSR_INT_BIT_RF_KILL;
759*4882a593Smuzhiyun 		iwl_write32(trans, CSR_INT_MASK, trans_pcie->inta_mask);
760*4882a593Smuzhiyun 	} else {
761*4882a593Smuzhiyun 		iwl_write32(trans, CSR_MSIX_FH_INT_MASK_AD,
762*4882a593Smuzhiyun 			    trans_pcie->fh_init_mask);
763*4882a593Smuzhiyun 		iwl_enable_hw_int_msk_msix(trans,
764*4882a593Smuzhiyun 					   MSIX_HW_INT_CAUSES_REG_RF_KILL);
765*4882a593Smuzhiyun 	}
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun 	if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) {
768*4882a593Smuzhiyun 		/*
769*4882a593Smuzhiyun 		 * On 9000-series devices this bit isn't enabled by default, so
770*4882a593Smuzhiyun 		 * when we power down the device we need set the bit to allow it
771*4882a593Smuzhiyun 		 * to wake up the PCI-E bus for RF-kill interrupts.
772*4882a593Smuzhiyun 		 */
773*4882a593Smuzhiyun 		iwl_set_bit(trans, CSR_GP_CNTRL,
774*4882a593Smuzhiyun 			    CSR_GP_CNTRL_REG_FLAG_RFKILL_WAKE_L1A_EN);
775*4882a593Smuzhiyun 	}
776*4882a593Smuzhiyun }
777*4882a593Smuzhiyun 
778*4882a593Smuzhiyun void iwl_pcie_handle_rfkill_irq(struct iwl_trans *trans);
779*4882a593Smuzhiyun 
iwl_is_rfkill_set(struct iwl_trans * trans)780*4882a593Smuzhiyun static inline bool iwl_is_rfkill_set(struct iwl_trans *trans)
781*4882a593Smuzhiyun {
782*4882a593Smuzhiyun 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
783*4882a593Smuzhiyun 
784*4882a593Smuzhiyun 	lockdep_assert_held(&trans_pcie->mutex);
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun 	if (trans_pcie->debug_rfkill == 1)
787*4882a593Smuzhiyun 		return true;
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	return !(iwl_read32(trans, CSR_GP_CNTRL) &
790*4882a593Smuzhiyun 		CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun 
__iwl_trans_pcie_set_bits_mask(struct iwl_trans * trans,u32 reg,u32 mask,u32 value)793*4882a593Smuzhiyun static inline void __iwl_trans_pcie_set_bits_mask(struct iwl_trans *trans,
794*4882a593Smuzhiyun 						  u32 reg, u32 mask, u32 value)
795*4882a593Smuzhiyun {
796*4882a593Smuzhiyun 	u32 v;
797*4882a593Smuzhiyun 
798*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUG
799*4882a593Smuzhiyun 	WARN_ON_ONCE(value & ~mask);
800*4882a593Smuzhiyun #endif
801*4882a593Smuzhiyun 
802*4882a593Smuzhiyun 	v = iwl_read32(trans, reg);
803*4882a593Smuzhiyun 	v &= ~mask;
804*4882a593Smuzhiyun 	v |= value;
805*4882a593Smuzhiyun 	iwl_write32(trans, reg, v);
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun 
__iwl_trans_pcie_clear_bit(struct iwl_trans * trans,u32 reg,u32 mask)808*4882a593Smuzhiyun static inline void __iwl_trans_pcie_clear_bit(struct iwl_trans *trans,
809*4882a593Smuzhiyun 					      u32 reg, u32 mask)
810*4882a593Smuzhiyun {
811*4882a593Smuzhiyun 	__iwl_trans_pcie_set_bits_mask(trans, reg, mask, 0);
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun 
__iwl_trans_pcie_set_bit(struct iwl_trans * trans,u32 reg,u32 mask)814*4882a593Smuzhiyun static inline void __iwl_trans_pcie_set_bit(struct iwl_trans *trans,
815*4882a593Smuzhiyun 					    u32 reg, u32 mask)
816*4882a593Smuzhiyun {
817*4882a593Smuzhiyun 	__iwl_trans_pcie_set_bits_mask(trans, reg, mask, mask);
818*4882a593Smuzhiyun }
819*4882a593Smuzhiyun 
iwl_pcie_dbg_on(struct iwl_trans * trans)820*4882a593Smuzhiyun static inline bool iwl_pcie_dbg_on(struct iwl_trans *trans)
821*4882a593Smuzhiyun {
822*4882a593Smuzhiyun 	return (trans->dbg.dest_tlv || iwl_trans_dbg_ini_valid(trans));
823*4882a593Smuzhiyun }
824*4882a593Smuzhiyun 
825*4882a593Smuzhiyun void iwl_trans_pcie_rf_kill(struct iwl_trans *trans, bool state);
826*4882a593Smuzhiyun void iwl_trans_pcie_dump_regs(struct iwl_trans *trans);
827*4882a593Smuzhiyun void iwl_trans_pcie_sync_nmi(struct iwl_trans *trans);
828*4882a593Smuzhiyun 
829*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
830*4882a593Smuzhiyun void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans);
831*4882a593Smuzhiyun #else
iwl_trans_pcie_dbgfs_register(struct iwl_trans * trans)832*4882a593Smuzhiyun static inline void iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans) { }
833*4882a593Smuzhiyun #endif
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun void iwl_pcie_rx_allocator_work(struct work_struct *data);
836*4882a593Smuzhiyun 
837*4882a593Smuzhiyun /* common functions that are used by gen2 transport */
838*4882a593Smuzhiyun int iwl_pcie_gen2_apm_init(struct iwl_trans *trans);
839*4882a593Smuzhiyun void iwl_pcie_apm_config(struct iwl_trans *trans);
840*4882a593Smuzhiyun int iwl_pcie_prepare_card_hw(struct iwl_trans *trans);
841*4882a593Smuzhiyun void iwl_pcie_synchronize_irqs(struct iwl_trans *trans);
842*4882a593Smuzhiyun bool iwl_pcie_check_hw_rf_kill(struct iwl_trans *trans);
843*4882a593Smuzhiyun void iwl_trans_pcie_handle_stop_rfkill(struct iwl_trans *trans,
844*4882a593Smuzhiyun 				       bool was_in_rfkill);
845*4882a593Smuzhiyun void iwl_pcie_txq_free_tfd(struct iwl_trans *trans, struct iwl_txq *txq);
846*4882a593Smuzhiyun void iwl_pcie_apm_stop_master(struct iwl_trans *trans);
847*4882a593Smuzhiyun void iwl_pcie_conf_msix_hw(struct iwl_trans_pcie *trans_pcie);
848*4882a593Smuzhiyun int iwl_pcie_alloc_dma_ptr(struct iwl_trans *trans,
849*4882a593Smuzhiyun 			   struct iwl_dma_ptr *ptr, size_t size);
850*4882a593Smuzhiyun void iwl_pcie_free_dma_ptr(struct iwl_trans *trans, struct iwl_dma_ptr *ptr);
851*4882a593Smuzhiyun void iwl_pcie_apply_destination(struct iwl_trans *trans);
852*4882a593Smuzhiyun 
853*4882a593Smuzhiyun /* common functions that are used by gen3 transport */
854*4882a593Smuzhiyun void iwl_pcie_alloc_fw_monitor(struct iwl_trans *trans, u8 max_power);
855*4882a593Smuzhiyun 
856*4882a593Smuzhiyun /* transport gen 2 exported functions */
857*4882a593Smuzhiyun int iwl_trans_pcie_gen2_start_fw(struct iwl_trans *trans,
858*4882a593Smuzhiyun 				 const struct fw_img *fw, bool run_in_rfkill);
859*4882a593Smuzhiyun void iwl_trans_pcie_gen2_fw_alive(struct iwl_trans *trans, u32 scd_addr);
860*4882a593Smuzhiyun int iwl_trans_pcie_gen2_send_hcmd(struct iwl_trans *trans,
861*4882a593Smuzhiyun 				  struct iwl_host_cmd *cmd);
862*4882a593Smuzhiyun void iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans);
863*4882a593Smuzhiyun void _iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans);
864*4882a593Smuzhiyun void iwl_pcie_d3_complete_suspend(struct iwl_trans *trans,
865*4882a593Smuzhiyun 				  bool test, bool reset);
866*4882a593Smuzhiyun #endif /* __iwl_trans_int_pcie_h__ */
867