1*828c91f7SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2277b024eSKalle Valo /* @file mwifiex_pcie.h 3277b024eSKalle Valo * 4277b024eSKalle Valo * @brief This file contains definitions for PCI-E interface. 5277b024eSKalle Valo * driver. 6277b024eSKalle Valo * 7932183aaSGanapathi Bhat * Copyright 2011-2020 NXP 8277b024eSKalle Valo */ 9277b024eSKalle Valo 10277b024eSKalle Valo #ifndef _MWIFIEX_PCIE_H 11277b024eSKalle Valo #define _MWIFIEX_PCIE_H 12277b024eSKalle Valo 134a79aa17SBrian Norris #include <linux/completion.h> 14277b024eSKalle Valo #include <linux/pci.h> 15277b024eSKalle Valo #include <linux/interrupt.h> 16277b024eSKalle Valo 179a862322SXinming Hu #include "decl.h" 18277b024eSKalle Valo #include "main.h" 19277b024eSKalle Valo 20277b024eSKalle Valo #define PCIE8766_DEFAULT_FW_NAME "mrvl/pcie8766_uapsta.bin" 21b9db3978SShengzhen Li #define PCIE8897_DEFAULT_FW_NAME "mrvl/pcie8897_uapsta.bin" 22a362e16bSShengzhen Li #define PCIE8897_A0_FW_NAME "mrvl/pcie8897_uapsta_a0.bin" 23a362e16bSShengzhen Li #define PCIE8897_B0_FW_NAME "mrvl/pcie8897_uapsta.bin" 2475696fe7SAmitkumar Karwar #define PCIEUART8997_FW_NAME_V4 "mrvl/pcieuart8997_combo_v4.bin" 2575696fe7SAmitkumar Karwar #define PCIEUSB8997_FW_NAME_V4 "mrvl/pcieusb8997_combo_v4.bin" 26277b024eSKalle Valo 27277b024eSKalle Valo #define PCIE_VENDOR_ID_MARVELL (0x11ab) 28a362e16bSShengzhen Li #define PCIE_VENDOR_ID_V2_MARVELL (0x1b4b) 29277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8766P (0x2b30) 30277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8897 (0x2b38) 31277b024eSKalle Valo #define PCIE_DEVICE_ID_MARVELL_88W8997 (0x2b42) 32277b024eSKalle Valo 33a362e16bSShengzhen Li #define PCIE8897_A0 0x1100 34a362e16bSShengzhen Li #define PCIE8897_B0 0x1200 3575696fe7SAmitkumar Karwar #define PCIE8997_A0 0x10 3675696fe7SAmitkumar Karwar #define PCIE8997_A1 0x11 37473dfbfaSAmitkumar Karwar #define CHIP_VER_PCIEUART 0x3 3875696fe7SAmitkumar Karwar #define CHIP_MAGIC_VALUE 0x24 39a362e16bSShengzhen Li 40277b024eSKalle Valo /* Constants for Buffer Descriptor (BD) rings */ 41277b024eSKalle Valo #define MWIFIEX_MAX_TXRX_BD 0x20 42277b024eSKalle Valo #define MWIFIEX_TXBD_MASK 0x3F 43277b024eSKalle Valo #define MWIFIEX_RXBD_MASK 0x3F 44277b024eSKalle Valo 45277b024eSKalle Valo #define MWIFIEX_MAX_EVT_BD 0x08 46277b024eSKalle Valo #define MWIFIEX_EVTBD_MASK 0x0f 47277b024eSKalle Valo 48277b024eSKalle Valo /* PCIE INTERNAL REGISTERS */ 49277b024eSKalle Valo #define PCIE_SCRATCH_0_REG 0xC10 50277b024eSKalle Valo #define PCIE_SCRATCH_1_REG 0xC14 51277b024eSKalle Valo #define PCIE_CPU_INT_EVENT 0xC18 52277b024eSKalle Valo #define PCIE_CPU_INT_STATUS 0xC1C 53277b024eSKalle Valo #define PCIE_HOST_INT_STATUS 0xC30 54277b024eSKalle Valo #define PCIE_HOST_INT_MASK 0xC34 55277b024eSKalle Valo #define PCIE_HOST_INT_STATUS_MASK 0xC3C 56277b024eSKalle Valo #define PCIE_SCRATCH_2_REG 0xC40 57277b024eSKalle Valo #define PCIE_SCRATCH_3_REG 0xC44 58277b024eSKalle Valo #define PCIE_SCRATCH_4_REG 0xCD0 59277b024eSKalle Valo #define PCIE_SCRATCH_5_REG 0xCD4 60277b024eSKalle Valo #define PCIE_SCRATCH_6_REG 0xCD8 61277b024eSKalle Valo #define PCIE_SCRATCH_7_REG 0xCDC 62277b024eSKalle Valo #define PCIE_SCRATCH_8_REG 0xCE0 63277b024eSKalle Valo #define PCIE_SCRATCH_9_REG 0xCE4 64277b024eSKalle Valo #define PCIE_SCRATCH_10_REG 0xCE8 65277b024eSKalle Valo #define PCIE_SCRATCH_11_REG 0xCEC 66277b024eSKalle Valo #define PCIE_SCRATCH_12_REG 0xCF0 67127ee1dbSXinming Hu #define PCIE_SCRATCH_13_REG 0xCF4 68127ee1dbSXinming Hu #define PCIE_SCRATCH_14_REG 0xCF8 69127ee1dbSXinming Hu #define PCIE_SCRATCH_15_REG 0xCFC 70277b024eSKalle Valo #define PCIE_RD_DATA_PTR_Q0_Q1 0xC08C 71277b024eSKalle Valo #define PCIE_WR_DATA_PTR_Q0_Q1 0xC05C 72277b024eSKalle Valo 73277b024eSKalle Valo #define CPU_INTR_DNLD_RDY BIT(0) 74277b024eSKalle Valo #define CPU_INTR_DOOR_BELL BIT(1) 75277b024eSKalle Valo #define CPU_INTR_SLEEP_CFM_DONE BIT(2) 76277b024eSKalle Valo #define CPU_INTR_RESET BIT(3) 77277b024eSKalle Valo #define CPU_INTR_EVENT_DONE BIT(5) 78277b024eSKalle Valo 79277b024eSKalle Valo #define HOST_INTR_DNLD_DONE BIT(0) 80277b024eSKalle Valo #define HOST_INTR_UPLD_RDY BIT(1) 81277b024eSKalle Valo #define HOST_INTR_CMD_DONE BIT(2) 82277b024eSKalle Valo #define HOST_INTR_EVENT_RDY BIT(3) 83277b024eSKalle Valo #define HOST_INTR_MASK (HOST_INTR_DNLD_DONE | \ 84277b024eSKalle Valo HOST_INTR_UPLD_RDY | \ 85277b024eSKalle Valo HOST_INTR_CMD_DONE | \ 86277b024eSKalle Valo HOST_INTR_EVENT_RDY) 87277b024eSKalle Valo 88277b024eSKalle Valo #define MWIFIEX_BD_FLAG_ROLLOVER_IND BIT(7) 89277b024eSKalle Valo #define MWIFIEX_BD_FLAG_FIRST_DESC BIT(0) 90277b024eSKalle Valo #define MWIFIEX_BD_FLAG_LAST_DESC BIT(1) 91277b024eSKalle Valo #define MWIFIEX_BD_FLAG_SOP BIT(0) 92277b024eSKalle Valo #define MWIFIEX_BD_FLAG_EOP BIT(1) 93277b024eSKalle Valo #define MWIFIEX_BD_FLAG_XS_SOP BIT(2) 94277b024eSKalle Valo #define MWIFIEX_BD_FLAG_XS_EOP BIT(3) 95277b024eSKalle Valo #define MWIFIEX_BD_FLAG_EVT_ROLLOVER_IND BIT(7) 96277b024eSKalle Valo #define MWIFIEX_BD_FLAG_RX_ROLLOVER_IND BIT(10) 97277b024eSKalle Valo #define MWIFIEX_BD_FLAG_TX_START_PTR BIT(16) 98277b024eSKalle Valo #define MWIFIEX_BD_FLAG_TX_ROLLOVER_IND BIT(26) 99277b024eSKalle Valo 100277b024eSKalle Valo /* Max retry number of command write */ 101277b024eSKalle Valo #define MAX_WRITE_IOMEM_RETRY 2 102277b024eSKalle Valo /* Define PCIE block size for firmware download */ 103277b024eSKalle Valo #define MWIFIEX_PCIE_BLOCK_SIZE_FW_DNLD 256 104277b024eSKalle Valo /* FW awake cookie after FW ready */ 105277b024eSKalle Valo #define FW_AWAKE_COOKIE (0xAA55AA55) 106277b024eSKalle Valo #define MWIFIEX_DEF_SLEEP_COOKIE 0xBEEFBEEF 1073e668498SAmitkumar Karwar #define MWIFIEX_SLEEP_COOKIE_SIZE 4 108251a9605SShengzhen Li #define MWIFIEX_MAX_DELAY_COUNT 100 109277b024eSKalle Valo 110efde6648SXinming Hu #define MWIFIEX_PCIE_FLR_HAPPENS 0xFEDCBABA 111efde6648SXinming Hu 112277b024eSKalle Valo struct mwifiex_pcie_card_reg { 113277b024eSKalle Valo u16 cmd_addr_lo; 114277b024eSKalle Valo u16 cmd_addr_hi; 115277b024eSKalle Valo u16 fw_status; 116277b024eSKalle Valo u16 cmd_size; 117277b024eSKalle Valo u16 cmdrsp_addr_lo; 118277b024eSKalle Valo u16 cmdrsp_addr_hi; 119277b024eSKalle Valo u16 tx_rdptr; 120277b024eSKalle Valo u16 tx_wrptr; 121277b024eSKalle Valo u16 rx_rdptr; 122277b024eSKalle Valo u16 rx_wrptr; 123277b024eSKalle Valo u16 evt_rdptr; 124277b024eSKalle Valo u16 evt_wrptr; 125277b024eSKalle Valo u16 drv_rdy; 126277b024eSKalle Valo u16 tx_start_ptr; 127277b024eSKalle Valo u32 tx_mask; 128277b024eSKalle Valo u32 tx_wrap_mask; 129277b024eSKalle Valo u32 rx_mask; 130277b024eSKalle Valo u32 rx_wrap_mask; 131277b024eSKalle Valo u32 tx_rollover_ind; 132277b024eSKalle Valo u32 rx_rollover_ind; 133277b024eSKalle Valo u32 evt_rollover_ind; 134277b024eSKalle Valo u8 ring_flag_sop; 135277b024eSKalle Valo u8 ring_flag_eop; 136277b024eSKalle Valo u8 ring_flag_xs_sop; 137277b024eSKalle Valo u8 ring_flag_xs_eop; 138277b024eSKalle Valo u32 ring_tx_start_ptr; 139277b024eSKalle Valo u8 pfu_enabled; 140277b024eSKalle Valo u8 sleep_cookie; 141277b024eSKalle Valo u16 fw_dump_ctrl; 142277b024eSKalle Valo u16 fw_dump_start; 143277b024eSKalle Valo u16 fw_dump_end; 14450632092SXinming Hu u8 fw_dump_host_ready; 14550632092SXinming Hu u8 fw_dump_read_done; 14699074fc1SXinming Hu u8 msix_support; 147277b024eSKalle Valo }; 148277b024eSKalle Valo 149277b024eSKalle Valo struct mwifiex_pcie_device { 150277b024eSKalle Valo const struct mwifiex_pcie_card_reg *reg; 151277b024eSKalle Valo u16 blksz_fw_dl; 152277b024eSKalle Valo u16 tx_buf_size; 153277b024eSKalle Valo bool can_dump_fw; 15450632092SXinming Hu struct memory_type_mapping *mem_type_mapping_tbl; 15550632092SXinming Hu u8 num_mem_types; 156277b024eSKalle Valo bool can_ext_scan; 157277b024eSKalle Valo }; 158277b024eSKalle Valo 159277b024eSKalle Valo struct mwifiex_evt_buf_desc { 160277b024eSKalle Valo u64 paddr; 161277b024eSKalle Valo u16 len; 162277b024eSKalle Valo u16 flags; 163277b024eSKalle Valo } __packed; 164277b024eSKalle Valo 165277b024eSKalle Valo struct mwifiex_pcie_buf_desc { 166277b024eSKalle Valo u64 paddr; 167277b024eSKalle Valo u16 len; 168277b024eSKalle Valo u16 flags; 169277b024eSKalle Valo } __packed; 170277b024eSKalle Valo 171277b024eSKalle Valo struct mwifiex_pfu_buf_desc { 172277b024eSKalle Valo u16 flags; 173277b024eSKalle Valo u16 offset; 174277b024eSKalle Valo u16 frag_len; 175277b024eSKalle Valo u16 len; 176277b024eSKalle Valo u64 paddr; 177277b024eSKalle Valo u32 reserved; 178277b024eSKalle Valo } __packed; 179277b024eSKalle Valo 18099074fc1SXinming Hu #define MWIFIEX_NUM_MSIX_VECTORS 4 18199074fc1SXinming Hu 18299074fc1SXinming Hu struct mwifiex_msix_context { 18399074fc1SXinming Hu struct pci_dev *dev; 18499074fc1SXinming Hu u16 msg_id; 18599074fc1SXinming Hu }; 18699074fc1SXinming Hu 187277b024eSKalle Valo struct pcie_service_card { 188277b024eSKalle Valo struct pci_dev *dev; 189277b024eSKalle Valo struct mwifiex_adapter *adapter; 190277b024eSKalle Valo struct mwifiex_pcie_device pcie; 1914a79aa17SBrian Norris struct completion fw_done; 192277b024eSKalle Valo 193277b024eSKalle Valo u8 txbd_flush; 194277b024eSKalle Valo u32 txbd_wrptr; 195277b024eSKalle Valo u32 txbd_rdptr; 196277b024eSKalle Valo u32 txbd_ring_size; 197277b024eSKalle Valo u8 *txbd_ring_vbase; 198277b024eSKalle Valo dma_addr_t txbd_ring_pbase; 199277b024eSKalle Valo void *txbd_ring[MWIFIEX_MAX_TXRX_BD]; 200277b024eSKalle Valo struct sk_buff *tx_buf_list[MWIFIEX_MAX_TXRX_BD]; 201277b024eSKalle Valo 202277b024eSKalle Valo u32 rxbd_wrptr; 203277b024eSKalle Valo u32 rxbd_rdptr; 204277b024eSKalle Valo u32 rxbd_ring_size; 205277b024eSKalle Valo u8 *rxbd_ring_vbase; 206277b024eSKalle Valo dma_addr_t rxbd_ring_pbase; 207277b024eSKalle Valo void *rxbd_ring[MWIFIEX_MAX_TXRX_BD]; 208277b024eSKalle Valo struct sk_buff *rx_buf_list[MWIFIEX_MAX_TXRX_BD]; 209277b024eSKalle Valo 210277b024eSKalle Valo u32 evtbd_wrptr; 211277b024eSKalle Valo u32 evtbd_rdptr; 212277b024eSKalle Valo u32 evtbd_ring_size; 213277b024eSKalle Valo u8 *evtbd_ring_vbase; 214277b024eSKalle Valo dma_addr_t evtbd_ring_pbase; 215277b024eSKalle Valo void *evtbd_ring[MWIFIEX_MAX_EVT_BD]; 216277b024eSKalle Valo struct sk_buff *evt_buf_list[MWIFIEX_MAX_EVT_BD]; 217277b024eSKalle Valo 218277b024eSKalle Valo struct sk_buff *cmd_buf; 219277b024eSKalle Valo struct sk_buff *cmdrsp_buf; 220277b024eSKalle Valo u8 *sleep_cookie_vbase; 221277b024eSKalle Valo dma_addr_t sleep_cookie_pbase; 222277b024eSKalle Valo void __iomem *pci_mmap; 223277b024eSKalle Valo void __iomem *pci_mmap1; 2247be0f5b5SAvinash Patil int msi_enable; 22599074fc1SXinming Hu int msix_enable; 22699074fc1SXinming Hu #ifdef CONFIG_PCI 22799074fc1SXinming Hu struct msix_entry msix_entries[MWIFIEX_NUM_MSIX_VECTORS]; 22899074fc1SXinming Hu #endif 22999074fc1SXinming Hu struct mwifiex_msix_context msix_ctx[MWIFIEX_NUM_MSIX_VECTORS]; 23099074fc1SXinming Hu struct mwifiex_msix_context share_irq_ctx; 2313860e5e3SGanapathi Bhat struct work_struct work; 2323860e5e3SGanapathi Bhat unsigned long work_flags; 2334add4d98STsuchiya Yuto 2344add4d98STsuchiya Yuto bool pci_reset_ongoing; 2355448bc2aSJonas Dreßler unsigned long quirks; 236277b024eSKalle Valo }; 237277b024eSKalle Valo 238277b024eSKalle Valo static inline int mwifiex_pcie_txbd_empty(struct pcie_service_card * card,u32 rdptr)239277b024eSKalle Valomwifiex_pcie_txbd_empty(struct pcie_service_card *card, u32 rdptr) 240277b024eSKalle Valo { 241277b024eSKalle Valo const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; 242277b024eSKalle Valo 243277b024eSKalle Valo switch (card->dev->device) { 244277b024eSKalle Valo case PCIE_DEVICE_ID_MARVELL_88W8766P: 245277b024eSKalle Valo if (((card->txbd_wrptr & reg->tx_mask) == 246277b024eSKalle Valo (rdptr & reg->tx_mask)) && 247277b024eSKalle Valo ((card->txbd_wrptr & reg->tx_rollover_ind) != 248277b024eSKalle Valo (rdptr & reg->tx_rollover_ind))) 249277b024eSKalle Valo return 1; 250277b024eSKalle Valo break; 251277b024eSKalle Valo case PCIE_DEVICE_ID_MARVELL_88W8897: 252f3b35f28SAmitkumar Karwar case PCIE_DEVICE_ID_MARVELL_88W8997: 253277b024eSKalle Valo if (((card->txbd_wrptr & reg->tx_mask) == 254277b024eSKalle Valo (rdptr & reg->tx_mask)) && 255277b024eSKalle Valo ((card->txbd_wrptr & reg->tx_rollover_ind) == 256277b024eSKalle Valo (rdptr & reg->tx_rollover_ind))) 257277b024eSKalle Valo return 1; 258277b024eSKalle Valo break; 259277b024eSKalle Valo } 260277b024eSKalle Valo 261277b024eSKalle Valo return 0; 262277b024eSKalle Valo } 263277b024eSKalle Valo 264277b024eSKalle Valo static inline int mwifiex_pcie_txbd_not_full(struct pcie_service_card * card)265277b024eSKalle Valomwifiex_pcie_txbd_not_full(struct pcie_service_card *card) 266277b024eSKalle Valo { 267277b024eSKalle Valo const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; 268277b024eSKalle Valo 269277b024eSKalle Valo switch (card->dev->device) { 270277b024eSKalle Valo case PCIE_DEVICE_ID_MARVELL_88W8766P: 271277b024eSKalle Valo if (((card->txbd_wrptr & reg->tx_mask) != 272277b024eSKalle Valo (card->txbd_rdptr & reg->tx_mask)) || 273277b024eSKalle Valo ((card->txbd_wrptr & reg->tx_rollover_ind) != 274277b024eSKalle Valo (card->txbd_rdptr & reg->tx_rollover_ind))) 275277b024eSKalle Valo return 1; 276277b024eSKalle Valo break; 277277b024eSKalle Valo case PCIE_DEVICE_ID_MARVELL_88W8897: 278277b024eSKalle Valo case PCIE_DEVICE_ID_MARVELL_88W8997: 279277b024eSKalle Valo if (((card->txbd_wrptr & reg->tx_mask) != 280277b024eSKalle Valo (card->txbd_rdptr & reg->tx_mask)) || 281277b024eSKalle Valo ((card->txbd_wrptr & reg->tx_rollover_ind) == 282277b024eSKalle Valo (card->txbd_rdptr & reg->tx_rollover_ind))) 283277b024eSKalle Valo return 1; 284277b024eSKalle Valo break; 285277b024eSKalle Valo } 286277b024eSKalle Valo 287277b024eSKalle Valo return 0; 288277b024eSKalle Valo } 289277b024eSKalle Valo 290277b024eSKalle Valo #endif /* _MWIFIEX_PCIE_H */ 291