xref: /linux/drivers/net/wireless/marvell/mwifiex/pcie.h (revision 3860e5e39532050c010a0c61c3a980f4a7d4542c)
1277b024eSKalle Valo /* @file mwifiex_pcie.h
2277b024eSKalle Valo  *
3277b024eSKalle Valo  * @brief This file contains definitions for PCI-E interface.
4277b024eSKalle Valo  * driver.
5277b024eSKalle Valo  *
6277b024eSKalle Valo  * Copyright (C) 2011-2014, Marvell International Ltd.
7277b024eSKalle Valo  *
8277b024eSKalle Valo  * This software file (the "File") is distributed by Marvell International
9277b024eSKalle Valo  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
10277b024eSKalle Valo  * (the "License").  You may use, redistribute and/or modify this File in
11277b024eSKalle Valo  * accordance with the terms and conditions of the License, a copy of which
12277b024eSKalle Valo  * is available by writing to the Free Software Foundation, Inc.,
13277b024eSKalle Valo  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
14277b024eSKalle Valo  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
15277b024eSKalle Valo  *
16277b024eSKalle Valo  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
17277b024eSKalle Valo  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
18277b024eSKalle Valo  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
19277b024eSKalle Valo  * this warranty disclaimer.
20277b024eSKalle Valo  */
21277b024eSKalle Valo 
22277b024eSKalle Valo #ifndef	_MWIFIEX_PCIE_H
23277b024eSKalle Valo #define	_MWIFIEX_PCIE_H
24277b024eSKalle Valo 
254a79aa17SBrian Norris #include    <linux/completion.h>
26277b024eSKalle Valo #include    <linux/pci.h>
27277b024eSKalle Valo #include    <linux/interrupt.h>
28277b024eSKalle Valo 
299a862322SXinming Hu #include    "decl.h"
30277b024eSKalle Valo #include    "main.h"
31277b024eSKalle Valo 
32277b024eSKalle Valo #define PCIE8766_DEFAULT_FW_NAME "mrvl/pcie8766_uapsta.bin"
33b9db3978SShengzhen Li #define PCIE8897_DEFAULT_FW_NAME "mrvl/pcie8897_uapsta.bin"
34a362e16bSShengzhen Li #define PCIE8897_A0_FW_NAME "mrvl/pcie8897_uapsta_a0.bin"
35a362e16bSShengzhen Li #define PCIE8897_B0_FW_NAME "mrvl/pcie8897_uapsta.bin"
3675696fe7SAmitkumar Karwar #define PCIEUART8997_FW_NAME_V4 "mrvl/pcieuart8997_combo_v4.bin"
3775696fe7SAmitkumar Karwar #define PCIEUSB8997_FW_NAME_V4 "mrvl/pcieusb8997_combo_v4.bin"
3875696fe7SAmitkumar Karwar #define PCIE8997_DEFAULT_WIFIFW_NAME "mrvl/pcie8997_wlan_v4.bin"
39277b024eSKalle Valo 
40277b024eSKalle Valo #define PCIE_VENDOR_ID_MARVELL              (0x11ab)
41a362e16bSShengzhen Li #define PCIE_VENDOR_ID_V2_MARVELL           (0x1b4b)
42277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8766P		(0x2b30)
43277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8897		(0x2b38)
44277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8997		(0x2b42)
45277b024eSKalle Valo 
46a362e16bSShengzhen Li #define PCIE8897_A0	0x1100
47a362e16bSShengzhen Li #define PCIE8897_B0	0x1200
4875696fe7SAmitkumar Karwar #define PCIE8997_A0	0x10
4975696fe7SAmitkumar Karwar #define PCIE8997_A1	0x11
50473dfbfaSAmitkumar Karwar #define CHIP_VER_PCIEUART	0x3
5175696fe7SAmitkumar Karwar #define CHIP_MAGIC_VALUE	0x24
52a362e16bSShengzhen Li 
53277b024eSKalle Valo /* Constants for Buffer Descriptor (BD) rings */
54277b024eSKalle Valo #define MWIFIEX_MAX_TXRX_BD			0x20
55277b024eSKalle Valo #define MWIFIEX_TXBD_MASK			0x3F
56277b024eSKalle Valo #define MWIFIEX_RXBD_MASK			0x3F
57277b024eSKalle Valo 
58277b024eSKalle Valo #define MWIFIEX_MAX_EVT_BD			0x08
59277b024eSKalle Valo #define MWIFIEX_EVTBD_MASK			0x0f
60277b024eSKalle Valo 
61277b024eSKalle Valo /* PCIE INTERNAL REGISTERS */
62277b024eSKalle Valo #define PCIE_SCRATCH_0_REG				0xC10
63277b024eSKalle Valo #define PCIE_SCRATCH_1_REG				0xC14
64277b024eSKalle Valo #define PCIE_CPU_INT_EVENT				0xC18
65277b024eSKalle Valo #define PCIE_CPU_INT_STATUS				0xC1C
66277b024eSKalle Valo #define PCIE_HOST_INT_STATUS				0xC30
67277b024eSKalle Valo #define PCIE_HOST_INT_MASK				0xC34
68277b024eSKalle Valo #define PCIE_HOST_INT_STATUS_MASK			0xC3C
69277b024eSKalle Valo #define PCIE_SCRATCH_2_REG				0xC40
70277b024eSKalle Valo #define PCIE_SCRATCH_3_REG				0xC44
71277b024eSKalle Valo #define PCIE_SCRATCH_4_REG				0xCD0
72277b024eSKalle Valo #define PCIE_SCRATCH_5_REG				0xCD4
73277b024eSKalle Valo #define PCIE_SCRATCH_6_REG				0xCD8
74277b024eSKalle Valo #define PCIE_SCRATCH_7_REG				0xCDC
75277b024eSKalle Valo #define PCIE_SCRATCH_8_REG				0xCE0
76277b024eSKalle Valo #define PCIE_SCRATCH_9_REG				0xCE4
77277b024eSKalle Valo #define PCIE_SCRATCH_10_REG				0xCE8
78277b024eSKalle Valo #define PCIE_SCRATCH_11_REG				0xCEC
79277b024eSKalle Valo #define PCIE_SCRATCH_12_REG				0xCF0
804646968bSXinming Hu #define PCIE_SCRATCH_13_REG				0xCF8
814646968bSXinming Hu #define PCIE_SCRATCH_14_REG				0xCFC
82277b024eSKalle Valo #define PCIE_RD_DATA_PTR_Q0_Q1                          0xC08C
83277b024eSKalle Valo #define PCIE_WR_DATA_PTR_Q0_Q1                          0xC05C
84277b024eSKalle Valo 
85277b024eSKalle Valo #define CPU_INTR_DNLD_RDY				BIT(0)
86277b024eSKalle Valo #define CPU_INTR_DOOR_BELL				BIT(1)
87277b024eSKalle Valo #define CPU_INTR_SLEEP_CFM_DONE			BIT(2)
88277b024eSKalle Valo #define CPU_INTR_RESET					BIT(3)
89277b024eSKalle Valo #define CPU_INTR_EVENT_DONE				BIT(5)
90277b024eSKalle Valo 
91277b024eSKalle Valo #define HOST_INTR_DNLD_DONE				BIT(0)
92277b024eSKalle Valo #define HOST_INTR_UPLD_RDY				BIT(1)
93277b024eSKalle Valo #define HOST_INTR_CMD_DONE				BIT(2)
94277b024eSKalle Valo #define HOST_INTR_EVENT_RDY				BIT(3)
95277b024eSKalle Valo #define HOST_INTR_MASK					(HOST_INTR_DNLD_DONE | \
96277b024eSKalle Valo 							 HOST_INTR_UPLD_RDY  | \
97277b024eSKalle Valo 							 HOST_INTR_CMD_DONE  | \
98277b024eSKalle Valo 							 HOST_INTR_EVENT_RDY)
99277b024eSKalle Valo 
100277b024eSKalle Valo #define MWIFIEX_BD_FLAG_ROLLOVER_IND			BIT(7)
101277b024eSKalle Valo #define MWIFIEX_BD_FLAG_FIRST_DESC			BIT(0)
102277b024eSKalle Valo #define MWIFIEX_BD_FLAG_LAST_DESC			BIT(1)
103277b024eSKalle Valo #define MWIFIEX_BD_FLAG_SOP				BIT(0)
104277b024eSKalle Valo #define MWIFIEX_BD_FLAG_EOP				BIT(1)
105277b024eSKalle Valo #define MWIFIEX_BD_FLAG_XS_SOP				BIT(2)
106277b024eSKalle Valo #define MWIFIEX_BD_FLAG_XS_EOP				BIT(3)
107277b024eSKalle Valo #define MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND		BIT(7)
108277b024eSKalle Valo #define MWIFIEX_BD_FLAG_RX_ROLLOVER_IND			BIT(10)
109277b024eSKalle Valo #define MWIFIEX_BD_FLAG_TX_START_PTR			BIT(16)
110277b024eSKalle Valo #define MWIFIEX_BD_FLAG_TX_ROLLOVER_IND			BIT(26)
111277b024eSKalle Valo 
112277b024eSKalle Valo /* Max retry number of command write */
113277b024eSKalle Valo #define MAX_WRITE_IOMEM_RETRY				2
114277b024eSKalle Valo /* Define PCIE block size for firmware download */
115277b024eSKalle Valo #define MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD		256
116277b024eSKalle Valo /* FW awake cookie after FW ready */
117277b024eSKalle Valo #define FW_AWAKE_COOKIE						(0xAA55AA55)
118277b024eSKalle Valo #define MWIFIEX_DEF_SLEEP_COOKIE			0xBEEFBEEF
119251a9605SShengzhen Li #define MWIFIEX_MAX_DELAY_COUNT				100
120277b024eSKalle Valo 
121277b024eSKalle Valo struct mwifiex_pcie_card_reg {
122277b024eSKalle Valo 	u16 cmd_addr_lo;
123277b024eSKalle Valo 	u16 cmd_addr_hi;
124277b024eSKalle Valo 	u16 fw_status;
125277b024eSKalle Valo 	u16 cmd_size;
126277b024eSKalle Valo 	u16 cmdrsp_addr_lo;
127277b024eSKalle Valo 	u16 cmdrsp_addr_hi;
128277b024eSKalle Valo 	u16 tx_rdptr;
129277b024eSKalle Valo 	u16 tx_wrptr;
130277b024eSKalle Valo 	u16 rx_rdptr;
131277b024eSKalle Valo 	u16 rx_wrptr;
132277b024eSKalle Valo 	u16 evt_rdptr;
133277b024eSKalle Valo 	u16 evt_wrptr;
134277b024eSKalle Valo 	u16 drv_rdy;
135277b024eSKalle Valo 	u16 tx_start_ptr;
136277b024eSKalle Valo 	u32 tx_mask;
137277b024eSKalle Valo 	u32 tx_wrap_mask;
138277b024eSKalle Valo 	u32 rx_mask;
139277b024eSKalle Valo 	u32 rx_wrap_mask;
140277b024eSKalle Valo 	u32 tx_rollover_ind;
141277b024eSKalle Valo 	u32 rx_rollover_ind;
142277b024eSKalle Valo 	u32 evt_rollover_ind;
143277b024eSKalle Valo 	u8 ring_flag_sop;
144277b024eSKalle Valo 	u8 ring_flag_eop;
145277b024eSKalle Valo 	u8 ring_flag_xs_sop;
146277b024eSKalle Valo 	u8 ring_flag_xs_eop;
147277b024eSKalle Valo 	u32 ring_tx_start_ptr;
148277b024eSKalle Valo 	u8 pfu_enabled;
149277b024eSKalle Valo 	u8 sleep_cookie;
150277b024eSKalle Valo 	u16 fw_dump_ctrl;
151277b024eSKalle Valo 	u16 fw_dump_start;
152277b024eSKalle Valo 	u16 fw_dump_end;
15350632092SXinming Hu 	u8 fw_dump_host_ready;
15450632092SXinming Hu 	u8 fw_dump_read_done;
15599074fc1SXinming Hu 	u8 msix_support;
156277b024eSKalle Valo };
157277b024eSKalle Valo 
158277b024eSKalle Valo static const struct mwifiex_pcie_card_reg mwifiex_reg_8766 = {
159277b024eSKalle Valo 	.cmd_addr_lo = PCIE_SCRATCH_0_REG,
160277b024eSKalle Valo 	.cmd_addr_hi = PCIE_SCRATCH_1_REG,
161277b024eSKalle Valo 	.cmd_size = PCIE_SCRATCH_2_REG,
162277b024eSKalle Valo 	.fw_status = PCIE_SCRATCH_3_REG,
163277b024eSKalle Valo 	.cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
164277b024eSKalle Valo 	.cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
165277b024eSKalle Valo 	.tx_rdptr = PCIE_SCRATCH_6_REG,
166277b024eSKalle Valo 	.tx_wrptr = PCIE_SCRATCH_7_REG,
167277b024eSKalle Valo 	.rx_rdptr = PCIE_SCRATCH_8_REG,
168277b024eSKalle Valo 	.rx_wrptr = PCIE_SCRATCH_9_REG,
169277b024eSKalle Valo 	.evt_rdptr = PCIE_SCRATCH_10_REG,
170277b024eSKalle Valo 	.evt_wrptr = PCIE_SCRATCH_11_REG,
171277b024eSKalle Valo 	.drv_rdy = PCIE_SCRATCH_12_REG,
172277b024eSKalle Valo 	.tx_start_ptr = 0,
173277b024eSKalle Valo 	.tx_mask = MWIFIEX_TXBD_MASK,
174277b024eSKalle Valo 	.tx_wrap_mask = 0,
175277b024eSKalle Valo 	.rx_mask = MWIFIEX_RXBD_MASK,
176277b024eSKalle Valo 	.rx_wrap_mask = 0,
177277b024eSKalle Valo 	.tx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
178277b024eSKalle Valo 	.rx_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
179277b024eSKalle Valo 	.evt_rollover_ind = MWIFIEX_BD_FLAG_ROLLOVER_IND,
180277b024eSKalle Valo 	.ring_flag_sop = 0,
181277b024eSKalle Valo 	.ring_flag_eop = 0,
182277b024eSKalle Valo 	.ring_flag_xs_sop = 0,
183277b024eSKalle Valo 	.ring_flag_xs_eop = 0,
184277b024eSKalle Valo 	.ring_tx_start_ptr = 0,
185277b024eSKalle Valo 	.pfu_enabled = 0,
186277b024eSKalle Valo 	.sleep_cookie = 1,
18799074fc1SXinming Hu 	.msix_support = 0,
188277b024eSKalle Valo };
189277b024eSKalle Valo 
190277b024eSKalle Valo static const struct mwifiex_pcie_card_reg mwifiex_reg_8897 = {
191277b024eSKalle Valo 	.cmd_addr_lo = PCIE_SCRATCH_0_REG,
192277b024eSKalle Valo 	.cmd_addr_hi = PCIE_SCRATCH_1_REG,
193277b024eSKalle Valo 	.cmd_size = PCIE_SCRATCH_2_REG,
194277b024eSKalle Valo 	.fw_status = PCIE_SCRATCH_3_REG,
195277b024eSKalle Valo 	.cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
196277b024eSKalle Valo 	.cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
197277b024eSKalle Valo 	.tx_rdptr = PCIE_RD_DATA_PTR_Q0_Q1,
198277b024eSKalle Valo 	.tx_wrptr = PCIE_WR_DATA_PTR_Q0_Q1,
199277b024eSKalle Valo 	.rx_rdptr = PCIE_WR_DATA_PTR_Q0_Q1,
200277b024eSKalle Valo 	.rx_wrptr = PCIE_RD_DATA_PTR_Q0_Q1,
201277b024eSKalle Valo 	.evt_rdptr = PCIE_SCRATCH_10_REG,
202277b024eSKalle Valo 	.evt_wrptr = PCIE_SCRATCH_11_REG,
203277b024eSKalle Valo 	.drv_rdy = PCIE_SCRATCH_12_REG,
204277b024eSKalle Valo 	.tx_start_ptr = 16,
205277b024eSKalle Valo 	.tx_mask = 0x03FF0000,
206277b024eSKalle Valo 	.tx_wrap_mask = 0x07FF0000,
207277b024eSKalle Valo 	.rx_mask = 0x000003FF,
208277b024eSKalle Valo 	.rx_wrap_mask = 0x000007FF,
209277b024eSKalle Valo 	.tx_rollover_ind = MWIFIEX_BD_FLAG_TX_ROLLOVER_IND,
210277b024eSKalle Valo 	.rx_rollover_ind = MWIFIEX_BD_FLAG_RX_ROLLOVER_IND,
211277b024eSKalle Valo 	.evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
212277b024eSKalle Valo 	.ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
213277b024eSKalle Valo 	.ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
214277b024eSKalle Valo 	.ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
215277b024eSKalle Valo 	.ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
216277b024eSKalle Valo 	.ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
217277b024eSKalle Valo 	.pfu_enabled = 1,
218277b024eSKalle Valo 	.sleep_cookie = 0,
219277b024eSKalle Valo 	.fw_dump_ctrl = 0xcf4,
220277b024eSKalle Valo 	.fw_dump_start = 0xcf8,
221277b024eSKalle Valo 	.fw_dump_end = 0xcff,
22250632092SXinming Hu 	.fw_dump_host_ready = 0xee,
22350632092SXinming Hu 	.fw_dump_read_done = 0xfe,
22499074fc1SXinming Hu 	.msix_support = 0,
225277b024eSKalle Valo };
226277b024eSKalle Valo 
227277b024eSKalle Valo static const struct mwifiex_pcie_card_reg mwifiex_reg_8997 = {
228277b024eSKalle Valo 	.cmd_addr_lo = PCIE_SCRATCH_0_REG,
229277b024eSKalle Valo 	.cmd_addr_hi = PCIE_SCRATCH_1_REG,
230277b024eSKalle Valo 	.cmd_size = PCIE_SCRATCH_2_REG,
231277b024eSKalle Valo 	.fw_status = PCIE_SCRATCH_3_REG,
232277b024eSKalle Valo 	.cmdrsp_addr_lo = PCIE_SCRATCH_4_REG,
233277b024eSKalle Valo 	.cmdrsp_addr_hi = PCIE_SCRATCH_5_REG,
234277b024eSKalle Valo 	.tx_rdptr = 0xC1A4,
235ce0c58d9SAmitkumar Karwar 	.tx_wrptr = 0xC174,
236ce0c58d9SAmitkumar Karwar 	.rx_rdptr = 0xC174,
237277b024eSKalle Valo 	.rx_wrptr = 0xC1A4,
238277b024eSKalle Valo 	.evt_rdptr = PCIE_SCRATCH_10_REG,
239277b024eSKalle Valo 	.evt_wrptr = PCIE_SCRATCH_11_REG,
240277b024eSKalle Valo 	.drv_rdy = PCIE_SCRATCH_12_REG,
241277b024eSKalle Valo 	.tx_start_ptr = 16,
242277b024eSKalle Valo 	.tx_mask = 0x0FFF0000,
243ce0c58d9SAmitkumar Karwar 	.tx_wrap_mask = 0x1FFF0000,
244277b024eSKalle Valo 	.rx_mask = 0x00000FFF,
245ce0c58d9SAmitkumar Karwar 	.rx_wrap_mask = 0x00001FFF,
246277b024eSKalle Valo 	.tx_rollover_ind = BIT(28),
247277b024eSKalle Valo 	.rx_rollover_ind = BIT(12),
248277b024eSKalle Valo 	.evt_rollover_ind = MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND,
249277b024eSKalle Valo 	.ring_flag_sop = MWIFIEX_BD_FLAG_SOP,
250277b024eSKalle Valo 	.ring_flag_eop = MWIFIEX_BD_FLAG_EOP,
251277b024eSKalle Valo 	.ring_flag_xs_sop = MWIFIEX_BD_FLAG_XS_SOP,
252277b024eSKalle Valo 	.ring_flag_xs_eop = MWIFIEX_BD_FLAG_XS_EOP,
253277b024eSKalle Valo 	.ring_tx_start_ptr = MWIFIEX_BD_FLAG_TX_START_PTR,
254277b024eSKalle Valo 	.pfu_enabled = 1,
255277b024eSKalle Valo 	.sleep_cookie = 0,
25611e70824SXinming Hu 	.fw_dump_ctrl = 0xcf4,
25711e70824SXinming Hu 	.fw_dump_start = 0xcf8,
25811e70824SXinming Hu 	.fw_dump_end = 0xcff,
25911e70824SXinming Hu 	.fw_dump_host_ready = 0xcc,
26011e70824SXinming Hu 	.fw_dump_read_done = 0xdd,
261bf942091SShengzhen Li 	.msix_support = 0,
262277b024eSKalle Valo };
263277b024eSKalle Valo 
26450632092SXinming Hu static struct memory_type_mapping mem_type_mapping_tbl_w8897[] = {
26550632092SXinming Hu 	{"ITCM", NULL, 0, 0xF0},
26650632092SXinming Hu 	{"DTCM", NULL, 0, 0xF1},
26750632092SXinming Hu 	{"SQRAM", NULL, 0, 0xF2},
26850632092SXinming Hu 	{"IRAM", NULL, 0, 0xF3},
26950632092SXinming Hu 	{"APU", NULL, 0, 0xF4},
27050632092SXinming Hu 	{"CIU", NULL, 0, 0xF5},
27150632092SXinming Hu 	{"ICU", NULL, 0, 0xF6},
27250632092SXinming Hu 	{"MAC", NULL, 0, 0xF7},
27350632092SXinming Hu };
27450632092SXinming Hu 
27511e70824SXinming Hu static struct memory_type_mapping mem_type_mapping_tbl_w8997[] = {
27611e70824SXinming Hu 	{"DUMP", NULL, 0, 0xDD},
27711e70824SXinming Hu };
27811e70824SXinming Hu 
279277b024eSKalle Valo struct mwifiex_pcie_device {
280277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg;
281277b024eSKalle Valo 	u16 blksz_fw_dl;
282277b024eSKalle Valo 	u16 tx_buf_size;
283277b024eSKalle Valo 	bool can_dump_fw;
28450632092SXinming Hu 	struct memory_type_mapping *mem_type_mapping_tbl;
28550632092SXinming Hu 	u8 num_mem_types;
286277b024eSKalle Valo 	bool can_ext_scan;
287277b024eSKalle Valo };
288277b024eSKalle Valo 
289277b024eSKalle Valo static const struct mwifiex_pcie_device mwifiex_pcie8766 = {
290277b024eSKalle Valo 	.reg            = &mwifiex_reg_8766,
291277b024eSKalle Valo 	.blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
292277b024eSKalle Valo 	.tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K,
293277b024eSKalle Valo 	.can_dump_fw = false,
294277b024eSKalle Valo 	.can_ext_scan = true,
295277b024eSKalle Valo };
296277b024eSKalle Valo 
297277b024eSKalle Valo static const struct mwifiex_pcie_device mwifiex_pcie8897 = {
298277b024eSKalle Valo 	.reg            = &mwifiex_reg_8897,
299277b024eSKalle Valo 	.blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
300277b024eSKalle Valo 	.tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
301277b024eSKalle Valo 	.can_dump_fw = true,
30250632092SXinming Hu 	.mem_type_mapping_tbl = mem_type_mapping_tbl_w8897,
30350632092SXinming Hu 	.num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl_w8897),
304277b024eSKalle Valo 	.can_ext_scan = true,
305277b024eSKalle Valo };
306277b024eSKalle Valo 
307277b024eSKalle Valo static const struct mwifiex_pcie_device mwifiex_pcie8997 = {
308277b024eSKalle Valo 	.reg            = &mwifiex_reg_8997,
309277b024eSKalle Valo 	.blksz_fw_dl = MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD,
310277b024eSKalle Valo 	.tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K,
31111e70824SXinming Hu 	.can_dump_fw = true,
31211e70824SXinming Hu 	.mem_type_mapping_tbl = mem_type_mapping_tbl_w8997,
31311e70824SXinming Hu 	.num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl_w8997),
314277b024eSKalle Valo 	.can_ext_scan = true,
315277b024eSKalle Valo };
316277b024eSKalle Valo 
317277b024eSKalle Valo struct mwifiex_evt_buf_desc {
318277b024eSKalle Valo 	u64 paddr;
319277b024eSKalle Valo 	u16 len;
320277b024eSKalle Valo 	u16 flags;
321277b024eSKalle Valo } __packed;
322277b024eSKalle Valo 
323277b024eSKalle Valo struct mwifiex_pcie_buf_desc {
324277b024eSKalle Valo 	u64 paddr;
325277b024eSKalle Valo 	u16 len;
326277b024eSKalle Valo 	u16 flags;
327277b024eSKalle Valo } __packed;
328277b024eSKalle Valo 
329277b024eSKalle Valo struct mwifiex_pfu_buf_desc {
330277b024eSKalle Valo 	u16 flags;
331277b024eSKalle Valo 	u16 offset;
332277b024eSKalle Valo 	u16 frag_len;
333277b024eSKalle Valo 	u16 len;
334277b024eSKalle Valo 	u64 paddr;
335277b024eSKalle Valo 	u32 reserved;
336277b024eSKalle Valo } __packed;
337277b024eSKalle Valo 
33899074fc1SXinming Hu #define MWIFIEX_NUM_MSIX_VECTORS   4
33999074fc1SXinming Hu 
34099074fc1SXinming Hu struct mwifiex_msix_context {
34199074fc1SXinming Hu 	struct pci_dev *dev;
34299074fc1SXinming Hu 	u16 msg_id;
34399074fc1SXinming Hu };
34499074fc1SXinming Hu 
345277b024eSKalle Valo struct pcie_service_card {
346277b024eSKalle Valo 	struct pci_dev *dev;
347277b024eSKalle Valo 	struct mwifiex_adapter *adapter;
348277b024eSKalle Valo 	struct mwifiex_pcie_device pcie;
3494a79aa17SBrian Norris 	struct completion fw_done;
350277b024eSKalle Valo 
351277b024eSKalle Valo 	u8 txbd_flush;
352277b024eSKalle Valo 	u32 txbd_wrptr;
353277b024eSKalle Valo 	u32 txbd_rdptr;
354277b024eSKalle Valo 	u32 txbd_ring_size;
355277b024eSKalle Valo 	u8 *txbd_ring_vbase;
356277b024eSKalle Valo 	dma_addr_t txbd_ring_pbase;
357277b024eSKalle Valo 	void *txbd_ring[MWIFIEX_MAX_TXRX_BD];
358277b024eSKalle Valo 	struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD];
359277b024eSKalle Valo 
360277b024eSKalle Valo 	u32 rxbd_wrptr;
361277b024eSKalle Valo 	u32 rxbd_rdptr;
362277b024eSKalle Valo 	u32 rxbd_ring_size;
363277b024eSKalle Valo 	u8 *rxbd_ring_vbase;
364277b024eSKalle Valo 	dma_addr_t rxbd_ring_pbase;
365277b024eSKalle Valo 	void *rxbd_ring[MWIFIEX_MAX_TXRX_BD];
366277b024eSKalle Valo 	struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD];
367277b024eSKalle Valo 
368277b024eSKalle Valo 	u32 evtbd_wrptr;
369277b024eSKalle Valo 	u32 evtbd_rdptr;
370277b024eSKalle Valo 	u32 evtbd_ring_size;
371277b024eSKalle Valo 	u8 *evtbd_ring_vbase;
372277b024eSKalle Valo 	dma_addr_t evtbd_ring_pbase;
373277b024eSKalle Valo 	void *evtbd_ring[MWIFIEX_MAX_EVT_BD];
374277b024eSKalle Valo 	struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD];
375277b024eSKalle Valo 
376277b024eSKalle Valo 	struct sk_buff *cmd_buf;
377277b024eSKalle Valo 	struct sk_buff *cmdrsp_buf;
378277b024eSKalle Valo 	u8 *sleep_cookie_vbase;
379277b024eSKalle Valo 	dma_addr_t sleep_cookie_pbase;
380277b024eSKalle Valo 	void __iomem *pci_mmap;
381277b024eSKalle Valo 	void __iomem *pci_mmap1;
3827be0f5b5SAvinash Patil 	int msi_enable;
38399074fc1SXinming Hu 	int msix_enable;
38499074fc1SXinming Hu #ifdef CONFIG_PCI
38599074fc1SXinming Hu 	struct msix_entry msix_entries[MWIFIEX_NUM_MSIX_VECTORS];
38699074fc1SXinming Hu #endif
38799074fc1SXinming Hu 	struct mwifiex_msix_context msix_ctx[MWIFIEX_NUM_MSIX_VECTORS];
38899074fc1SXinming Hu 	struct mwifiex_msix_context share_irq_ctx;
389*3860e5e3SGanapathi Bhat 	struct work_struct work;
390*3860e5e3SGanapathi Bhat 	unsigned long work_flags;
391277b024eSKalle Valo };
392277b024eSKalle Valo 
393277b024eSKalle Valo static inline int
394277b024eSKalle Valo mwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr)
395277b024eSKalle Valo {
396277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
397277b024eSKalle Valo 
398277b024eSKalle Valo 	switch (card->dev->device) {
399277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8766P:
400277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) ==
401277b024eSKalle Valo 		     (rdptr & reg->tx_mask)) &&
402277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) !=
403277b024eSKalle Valo 		     (rdptr & reg->tx_rollover_ind)))
404277b024eSKalle Valo 			return 1;
405277b024eSKalle Valo 		break;
406277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8897:
407f3b35f28SAmitkumar Karwar 	case PCIE_DEVICE_ID_MARVELL_88W8997:
408277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) ==
409277b024eSKalle Valo 		     (rdptr & reg->tx_mask)) &&
410277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) ==
411277b024eSKalle Valo 			(rdptr & reg->tx_rollover_ind)))
412277b024eSKalle Valo 			return 1;
413277b024eSKalle Valo 		break;
414277b024eSKalle Valo 	}
415277b024eSKalle Valo 
416277b024eSKalle Valo 	return 0;
417277b024eSKalle Valo }
418277b024eSKalle Valo 
419277b024eSKalle Valo static inline int
420277b024eSKalle Valo mwifiex_pcie_txbd_not_full(struct pcie_service_card *card)
421277b024eSKalle Valo {
422277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
423277b024eSKalle Valo 
424277b024eSKalle Valo 	switch (card->dev->device) {
425277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8766P:
426277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) !=
427277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_mask)) ||
428277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) !=
429277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_rollover_ind)))
430277b024eSKalle Valo 			return 1;
431277b024eSKalle Valo 		break;
432277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8897:
433277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8997:
434277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) !=
435277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_mask)) ||
436277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) ==
437277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_rollover_ind)))
438277b024eSKalle Valo 			return 1;
439277b024eSKalle Valo 		break;
440277b024eSKalle Valo 	}
441277b024eSKalle Valo 
442277b024eSKalle Valo 	return 0;
443277b024eSKalle Valo }
444277b024eSKalle Valo 
445277b024eSKalle Valo #endif /* _MWIFIEX_PCIE_H */
446