xref: /linux/drivers/net/wireless/marvell/mwifiex/pcie.h (revision 4add4d988f95f47493500a7a19c623827061589b)
1277b024eSKalle Valo /* @file mwifiex_pcie.h
2277b024eSKalle Valo  *
3277b024eSKalle Valo  * @brief This file contains definitions for PCI-E interface.
4277b024eSKalle Valo  * driver.
5277b024eSKalle Valo  *
6932183aaSGanapathi Bhat  * Copyright 2011-2020 NXP
7277b024eSKalle Valo  *
8932183aaSGanapathi Bhat  * This software file (the "File") is distributed by NXP
9932183aaSGanapathi Bhat  * 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"
38277b024eSKalle Valo 
39277b024eSKalle Valo #define PCIE_VENDOR_ID_MARVELL              (0x11ab)
40a362e16bSShengzhen Li #define PCIE_VENDOR_ID_V2_MARVELL           (0x1b4b)
41277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8766P		(0x2b30)
42277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8897		(0x2b38)
43277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8997		(0x2b42)
44277b024eSKalle Valo 
45a362e16bSShengzhen Li #define PCIE8897_A0	0x1100
46a362e16bSShengzhen Li #define PCIE8897_B0	0x1200
4775696fe7SAmitkumar Karwar #define PCIE8997_A0	0x10
4875696fe7SAmitkumar Karwar #define PCIE8997_A1	0x11
49473dfbfaSAmitkumar Karwar #define CHIP_VER_PCIEUART	0x3
5075696fe7SAmitkumar Karwar #define CHIP_MAGIC_VALUE	0x24
51a362e16bSShengzhen Li 
52277b024eSKalle Valo /* Constants for Buffer Descriptor (BD) rings */
53277b024eSKalle Valo #define MWIFIEX_MAX_TXRX_BD			0x20
54277b024eSKalle Valo #define MWIFIEX_TXBD_MASK			0x3F
55277b024eSKalle Valo #define MWIFIEX_RXBD_MASK			0x3F
56277b024eSKalle Valo 
57277b024eSKalle Valo #define MWIFIEX_MAX_EVT_BD			0x08
58277b024eSKalle Valo #define MWIFIEX_EVTBD_MASK			0x0f
59277b024eSKalle Valo 
60277b024eSKalle Valo /* PCIE INTERNAL REGISTERS */
61277b024eSKalle Valo #define PCIE_SCRATCH_0_REG				0xC10
62277b024eSKalle Valo #define PCIE_SCRATCH_1_REG				0xC14
63277b024eSKalle Valo #define PCIE_CPU_INT_EVENT				0xC18
64277b024eSKalle Valo #define PCIE_CPU_INT_STATUS				0xC1C
65277b024eSKalle Valo #define PCIE_HOST_INT_STATUS				0xC30
66277b024eSKalle Valo #define PCIE_HOST_INT_MASK				0xC34
67277b024eSKalle Valo #define PCIE_HOST_INT_STATUS_MASK			0xC3C
68277b024eSKalle Valo #define PCIE_SCRATCH_2_REG				0xC40
69277b024eSKalle Valo #define PCIE_SCRATCH_3_REG				0xC44
70277b024eSKalle Valo #define PCIE_SCRATCH_4_REG				0xCD0
71277b024eSKalle Valo #define PCIE_SCRATCH_5_REG				0xCD4
72277b024eSKalle Valo #define PCIE_SCRATCH_6_REG				0xCD8
73277b024eSKalle Valo #define PCIE_SCRATCH_7_REG				0xCDC
74277b024eSKalle Valo #define PCIE_SCRATCH_8_REG				0xCE0
75277b024eSKalle Valo #define PCIE_SCRATCH_9_REG				0xCE4
76277b024eSKalle Valo #define PCIE_SCRATCH_10_REG				0xCE8
77277b024eSKalle Valo #define PCIE_SCRATCH_11_REG				0xCEC
78277b024eSKalle Valo #define PCIE_SCRATCH_12_REG				0xCF0
79127ee1dbSXinming Hu #define PCIE_SCRATCH_13_REG				0xCF4
80127ee1dbSXinming Hu #define PCIE_SCRATCH_14_REG				0xCF8
81127ee1dbSXinming Hu #define PCIE_SCRATCH_15_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
1193e668498SAmitkumar Karwar #define MWIFIEX_SLEEP_COOKIE_SIZE			4
120251a9605SShengzhen Li #define MWIFIEX_MAX_DELAY_COUNT				100
121277b024eSKalle Valo 
122efde6648SXinming Hu #define MWIFIEX_PCIE_FLR_HAPPENS 0xFEDCBABA
123efde6648SXinming Hu 
124277b024eSKalle Valo struct mwifiex_pcie_card_reg {
125277b024eSKalle Valo 	u16 cmd_addr_lo;
126277b024eSKalle Valo 	u16 cmd_addr_hi;
127277b024eSKalle Valo 	u16 fw_status;
128277b024eSKalle Valo 	u16 cmd_size;
129277b024eSKalle Valo 	u16 cmdrsp_addr_lo;
130277b024eSKalle Valo 	u16 cmdrsp_addr_hi;
131277b024eSKalle Valo 	u16 tx_rdptr;
132277b024eSKalle Valo 	u16 tx_wrptr;
133277b024eSKalle Valo 	u16 rx_rdptr;
134277b024eSKalle Valo 	u16 rx_wrptr;
135277b024eSKalle Valo 	u16 evt_rdptr;
136277b024eSKalle Valo 	u16 evt_wrptr;
137277b024eSKalle Valo 	u16 drv_rdy;
138277b024eSKalle Valo 	u16 tx_start_ptr;
139277b024eSKalle Valo 	u32 tx_mask;
140277b024eSKalle Valo 	u32 tx_wrap_mask;
141277b024eSKalle Valo 	u32 rx_mask;
142277b024eSKalle Valo 	u32 rx_wrap_mask;
143277b024eSKalle Valo 	u32 tx_rollover_ind;
144277b024eSKalle Valo 	u32 rx_rollover_ind;
145277b024eSKalle Valo 	u32 evt_rollover_ind;
146277b024eSKalle Valo 	u8 ring_flag_sop;
147277b024eSKalle Valo 	u8 ring_flag_eop;
148277b024eSKalle Valo 	u8 ring_flag_xs_sop;
149277b024eSKalle Valo 	u8 ring_flag_xs_eop;
150277b024eSKalle Valo 	u32 ring_tx_start_ptr;
151277b024eSKalle Valo 	u8 pfu_enabled;
152277b024eSKalle Valo 	u8 sleep_cookie;
153277b024eSKalle Valo 	u16 fw_dump_ctrl;
154277b024eSKalle Valo 	u16 fw_dump_start;
155277b024eSKalle Valo 	u16 fw_dump_end;
15650632092SXinming Hu 	u8 fw_dump_host_ready;
15750632092SXinming Hu 	u8 fw_dump_read_done;
15899074fc1SXinming Hu 	u8 msix_support;
159277b024eSKalle Valo };
160277b024eSKalle Valo 
161277b024eSKalle Valo struct mwifiex_pcie_device {
162277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg;
163277b024eSKalle Valo 	u16 blksz_fw_dl;
164277b024eSKalle Valo 	u16 tx_buf_size;
165277b024eSKalle Valo 	bool can_dump_fw;
16650632092SXinming Hu 	struct memory_type_mapping *mem_type_mapping_tbl;
16750632092SXinming Hu 	u8 num_mem_types;
168277b024eSKalle Valo 	bool can_ext_scan;
169277b024eSKalle Valo };
170277b024eSKalle Valo 
171277b024eSKalle Valo struct mwifiex_evt_buf_desc {
172277b024eSKalle Valo 	u64 paddr;
173277b024eSKalle Valo 	u16 len;
174277b024eSKalle Valo 	u16 flags;
175277b024eSKalle Valo } __packed;
176277b024eSKalle Valo 
177277b024eSKalle Valo struct mwifiex_pcie_buf_desc {
178277b024eSKalle Valo 	u64 paddr;
179277b024eSKalle Valo 	u16 len;
180277b024eSKalle Valo 	u16 flags;
181277b024eSKalle Valo } __packed;
182277b024eSKalle Valo 
183277b024eSKalle Valo struct mwifiex_pfu_buf_desc {
184277b024eSKalle Valo 	u16 flags;
185277b024eSKalle Valo 	u16 offset;
186277b024eSKalle Valo 	u16 frag_len;
187277b024eSKalle Valo 	u16 len;
188277b024eSKalle Valo 	u64 paddr;
189277b024eSKalle Valo 	u32 reserved;
190277b024eSKalle Valo } __packed;
191277b024eSKalle Valo 
19299074fc1SXinming Hu #define MWIFIEX_NUM_MSIX_VECTORS   4
19399074fc1SXinming Hu 
19499074fc1SXinming Hu struct mwifiex_msix_context {
19599074fc1SXinming Hu 	struct pci_dev *dev;
19699074fc1SXinming Hu 	u16 msg_id;
19799074fc1SXinming Hu };
19899074fc1SXinming Hu 
199277b024eSKalle Valo struct pcie_service_card {
200277b024eSKalle Valo 	struct pci_dev *dev;
201277b024eSKalle Valo 	struct mwifiex_adapter *adapter;
202277b024eSKalle Valo 	struct mwifiex_pcie_device pcie;
2034a79aa17SBrian Norris 	struct completion fw_done;
204277b024eSKalle Valo 
205277b024eSKalle Valo 	u8 txbd_flush;
206277b024eSKalle Valo 	u32 txbd_wrptr;
207277b024eSKalle Valo 	u32 txbd_rdptr;
208277b024eSKalle Valo 	u32 txbd_ring_size;
209277b024eSKalle Valo 	u8 *txbd_ring_vbase;
210277b024eSKalle Valo 	dma_addr_t txbd_ring_pbase;
211277b024eSKalle Valo 	void *txbd_ring[MWIFIEX_MAX_TXRX_BD];
212277b024eSKalle Valo 	struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD];
213277b024eSKalle Valo 
214277b024eSKalle Valo 	u32 rxbd_wrptr;
215277b024eSKalle Valo 	u32 rxbd_rdptr;
216277b024eSKalle Valo 	u32 rxbd_ring_size;
217277b024eSKalle Valo 	u8 *rxbd_ring_vbase;
218277b024eSKalle Valo 	dma_addr_t rxbd_ring_pbase;
219277b024eSKalle Valo 	void *rxbd_ring[MWIFIEX_MAX_TXRX_BD];
220277b024eSKalle Valo 	struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD];
221277b024eSKalle Valo 
222277b024eSKalle Valo 	u32 evtbd_wrptr;
223277b024eSKalle Valo 	u32 evtbd_rdptr;
224277b024eSKalle Valo 	u32 evtbd_ring_size;
225277b024eSKalle Valo 	u8 *evtbd_ring_vbase;
226277b024eSKalle Valo 	dma_addr_t evtbd_ring_pbase;
227277b024eSKalle Valo 	void *evtbd_ring[MWIFIEX_MAX_EVT_BD];
228277b024eSKalle Valo 	struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD];
229277b024eSKalle Valo 
230277b024eSKalle Valo 	struct sk_buff *cmd_buf;
231277b024eSKalle Valo 	struct sk_buff *cmdrsp_buf;
232277b024eSKalle Valo 	u8 *sleep_cookie_vbase;
233277b024eSKalle Valo 	dma_addr_t sleep_cookie_pbase;
234277b024eSKalle Valo 	void __iomem *pci_mmap;
235277b024eSKalle Valo 	void __iomem *pci_mmap1;
2367be0f5b5SAvinash Patil 	int msi_enable;
23799074fc1SXinming Hu 	int msix_enable;
23899074fc1SXinming Hu #ifdef CONFIG_PCI
23999074fc1SXinming Hu 	struct msix_entry msix_entries[MWIFIEX_NUM_MSIX_VECTORS];
24099074fc1SXinming Hu #endif
24199074fc1SXinming Hu 	struct mwifiex_msix_context msix_ctx[MWIFIEX_NUM_MSIX_VECTORS];
24299074fc1SXinming Hu 	struct mwifiex_msix_context share_irq_ctx;
2433860e5e3SGanapathi Bhat 	struct work_struct work;
2443860e5e3SGanapathi Bhat 	unsigned long work_flags;
245*4add4d98STsuchiya Yuto 
246*4add4d98STsuchiya Yuto 	bool pci_reset_ongoing;
247277b024eSKalle Valo };
248277b024eSKalle Valo 
249277b024eSKalle Valo static inline int
250277b024eSKalle Valo mwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr)
251277b024eSKalle Valo {
252277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
253277b024eSKalle Valo 
254277b024eSKalle Valo 	switch (card->dev->device) {
255277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8766P:
256277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) ==
257277b024eSKalle Valo 		     (rdptr & reg->tx_mask)) &&
258277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) !=
259277b024eSKalle Valo 		     (rdptr & reg->tx_rollover_ind)))
260277b024eSKalle Valo 			return 1;
261277b024eSKalle Valo 		break;
262277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8897:
263f3b35f28SAmitkumar Karwar 	case PCIE_DEVICE_ID_MARVELL_88W8997:
264277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) ==
265277b024eSKalle Valo 		     (rdptr & reg->tx_mask)) &&
266277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) ==
267277b024eSKalle Valo 			(rdptr & reg->tx_rollover_ind)))
268277b024eSKalle Valo 			return 1;
269277b024eSKalle Valo 		break;
270277b024eSKalle Valo 	}
271277b024eSKalle Valo 
272277b024eSKalle Valo 	return 0;
273277b024eSKalle Valo }
274277b024eSKalle Valo 
275277b024eSKalle Valo static inline int
276277b024eSKalle Valo mwifiex_pcie_txbd_not_full(struct pcie_service_card *card)
277277b024eSKalle Valo {
278277b024eSKalle Valo 	const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
279277b024eSKalle Valo 
280277b024eSKalle Valo 	switch (card->dev->device) {
281277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8766P:
282277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) !=
283277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_mask)) ||
284277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) !=
285277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_rollover_ind)))
286277b024eSKalle Valo 			return 1;
287277b024eSKalle Valo 		break;
288277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8897:
289277b024eSKalle Valo 	case PCIE_DEVICE_ID_MARVELL_88W8997:
290277b024eSKalle Valo 		if (((card->txbd_wrptr & reg->tx_mask) !=
291277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_mask)) ||
292277b024eSKalle Valo 		    ((card->txbd_wrptr & reg->tx_rollover_ind) ==
293277b024eSKalle Valo 		     (card->txbd_rdptr & reg->tx_rollover_ind)))
294277b024eSKalle Valo 			return 1;
295277b024eSKalle Valo 		break;
296277b024eSKalle Valo 	}
297277b024eSKalle Valo 
298277b024eSKalle Valo 	return 0;
299277b024eSKalle Valo }
300277b024eSKalle Valo 
301277b024eSKalle Valo #endif /* _MWIFIEX_PCIE_H */
302