1804775dfSFelix Fietkau #ifndef __MTK_WED_H 2804775dfSFelix Fietkau #define __MTK_WED_H 3804775dfSFelix Fietkau 4804775dfSFelix Fietkau #include <linux/kernel.h> 5804775dfSFelix Fietkau #include <linux/rcupdate.h> 6804775dfSFelix Fietkau #include <linux/regmap.h> 7804775dfSFelix Fietkau #include <linux/pci.h> 84c5de09eSLorenzo Bianconi #include <linux/skbuff.h> 9804775dfSFelix Fietkau 10804775dfSFelix Fietkau #define MTK_WED_TX_QUEUES 2 11084d60ceSLorenzo Bianconi #define MTK_WED_RX_QUEUES 2 12804775dfSFelix Fietkau 134c5de09eSLorenzo Bianconi #define WED_WO_STA_REC 0x6 144c5de09eSLorenzo Bianconi 15804775dfSFelix Fietkau struct mtk_wed_hw; 16804775dfSFelix Fietkau struct mtk_wdma_desc; 17804775dfSFelix Fietkau 18cc514101SSujuan Chen enum mtk_wed_wo_cmd { 19cc514101SSujuan Chen MTK_WED_WO_CMD_WED_CFG, 20cc514101SSujuan Chen MTK_WED_WO_CMD_WED_RX_STAT, 21cc514101SSujuan Chen MTK_WED_WO_CMD_RRO_SER, 22cc514101SSujuan Chen MTK_WED_WO_CMD_DBG_INFO, 23cc514101SSujuan Chen MTK_WED_WO_CMD_DEV_INFO, 24cc514101SSujuan Chen MTK_WED_WO_CMD_BSS_INFO, 25cc514101SSujuan Chen MTK_WED_WO_CMD_STA_REC, 26cc514101SSujuan Chen MTK_WED_WO_CMD_DEV_INFO_DUMP, 27cc514101SSujuan Chen MTK_WED_WO_CMD_BSS_INFO_DUMP, 28cc514101SSujuan Chen MTK_WED_WO_CMD_STA_REC_DUMP, 29cc514101SSujuan Chen MTK_WED_WO_CMD_BA_INFO_DUMP, 30cc514101SSujuan Chen MTK_WED_WO_CMD_FBCMD_Q_DUMP, 31cc514101SSujuan Chen MTK_WED_WO_CMD_FW_LOG_CTRL, 32cc514101SSujuan Chen MTK_WED_WO_CMD_LOG_FLUSH, 33cc514101SSujuan Chen MTK_WED_WO_CMD_CHANGE_STATE, 34cc514101SSujuan Chen MTK_WED_WO_CMD_CPU_STATS_ENABLE, 35cc514101SSujuan Chen MTK_WED_WO_CMD_CPU_STATS_DUMP, 36cc514101SSujuan Chen MTK_WED_WO_CMD_EXCEPTION_INIT, 37cc514101SSujuan Chen MTK_WED_WO_CMD_PROF_CTRL, 38cc514101SSujuan Chen MTK_WED_WO_CMD_STA_BA_DUMP, 39cc514101SSujuan Chen MTK_WED_WO_CMD_BA_CTRL_DUMP, 40cc514101SSujuan Chen MTK_WED_WO_CMD_RXCNT_CTRL, 41cc514101SSujuan Chen MTK_WED_WO_CMD_RXCNT_INFO, 42cc514101SSujuan Chen MTK_WED_WO_CMD_SET_CAP, 43cc514101SSujuan Chen MTK_WED_WO_CMD_CCIF_RING_DUMP, 44cc514101SSujuan Chen MTK_WED_WO_CMD_WED_END 45cc514101SSujuan Chen }; 46cc514101SSujuan Chen 474c5de09eSLorenzo Bianconi struct mtk_rxbm_desc { 484c5de09eSLorenzo Bianconi __le32 buf0; 494c5de09eSLorenzo Bianconi __le32 token; 504c5de09eSLorenzo Bianconi } __packed __aligned(4); 514c5de09eSLorenzo Bianconi 522b2ba3ecSLorenzo Bianconi enum mtk_wed_bus_tye { 532b2ba3ecSLorenzo Bianconi MTK_WED_BUS_PCIE, 542b2ba3ecSLorenzo Bianconi MTK_WED_BUS_AXI, 552b2ba3ecSLorenzo Bianconi }; 562b2ba3ecSLorenzo Bianconi 574c5de09eSLorenzo Bianconi #define MTK_WED_RING_CONFIGURED BIT(0) 58804775dfSFelix Fietkau struct mtk_wed_ring { 59804775dfSFelix Fietkau struct mtk_wdma_desc *desc; 60804775dfSFelix Fietkau dma_addr_t desc_phys; 61de84a090SLorenzo Bianconi u32 desc_size; 62804775dfSFelix Fietkau int size; 634c5de09eSLorenzo Bianconi u32 flags; 64804775dfSFelix Fietkau 65804775dfSFelix Fietkau u32 reg_base; 66804775dfSFelix Fietkau void __iomem *wpdma; 67804775dfSFelix Fietkau }; 68804775dfSFelix Fietkau 694c5de09eSLorenzo Bianconi struct mtk_wed_wo_rx_stats { 704c5de09eSLorenzo Bianconi __le16 wlan_idx; 714c5de09eSLorenzo Bianconi __le16 tid; 724c5de09eSLorenzo Bianconi __le32 rx_pkt_cnt; 734c5de09eSLorenzo Bianconi __le32 rx_byte_cnt; 744c5de09eSLorenzo Bianconi __le32 rx_err_cnt; 754c5de09eSLorenzo Bianconi __le32 rx_drop_cnt; 764c5de09eSLorenzo Bianconi }; 774c5de09eSLorenzo Bianconi 78804775dfSFelix Fietkau struct mtk_wed_device { 79804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 80804775dfSFelix Fietkau const struct mtk_wed_ops *ops; 81804775dfSFelix Fietkau struct device *dev; 82804775dfSFelix Fietkau struct mtk_wed_hw *hw; 83804775dfSFelix Fietkau bool init_done, running; 84804775dfSFelix Fietkau int wdma_idx; 85804775dfSFelix Fietkau int irq; 864c5de09eSLorenzo Bianconi u8 version; 87804775dfSFelix Fietkau 88a66d79eeSSujuan Chen /* used by wlan driver */ 89a66d79eeSSujuan Chen u32 rev_id; 90a66d79eeSSujuan Chen 91804775dfSFelix Fietkau struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES]; 924c5de09eSLorenzo Bianconi struct mtk_wed_ring rx_ring[MTK_WED_RX_QUEUES]; 93804775dfSFelix Fietkau struct mtk_wed_ring txfree_ring; 944c5de09eSLorenzo Bianconi struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES]; 95084d60ceSLorenzo Bianconi struct mtk_wed_ring rx_wdma[MTK_WED_RX_QUEUES]; 96804775dfSFelix Fietkau 97804775dfSFelix Fietkau struct { 98804775dfSFelix Fietkau int size; 99804775dfSFelix Fietkau void **pages; 100804775dfSFelix Fietkau struct mtk_wdma_desc *desc; 101804775dfSFelix Fietkau dma_addr_t desc_phys; 1024c5de09eSLorenzo Bianconi } tx_buf_ring; 1034c5de09eSLorenzo Bianconi 1044c5de09eSLorenzo Bianconi struct { 1054c5de09eSLorenzo Bianconi int size; 1064c5de09eSLorenzo Bianconi struct page_frag_cache rx_page; 1074c5de09eSLorenzo Bianconi struct mtk_rxbm_desc *desc; 1084c5de09eSLorenzo Bianconi dma_addr_t desc_phys; 1094c5de09eSLorenzo Bianconi } rx_buf_ring; 1104c5de09eSLorenzo Bianconi 1114c5de09eSLorenzo Bianconi struct { 1124c5de09eSLorenzo Bianconi struct mtk_wed_ring ring; 1134c5de09eSLorenzo Bianconi dma_addr_t miod_phys; 1144c5de09eSLorenzo Bianconi dma_addr_t fdbk_phys; 1154c5de09eSLorenzo Bianconi } rro; 116804775dfSFelix Fietkau 117804775dfSFelix Fietkau /* filled by driver: */ 118804775dfSFelix Fietkau struct { 1192b2ba3ecSLorenzo Bianconi union { 1202b2ba3ecSLorenzo Bianconi struct platform_device *platform_dev; 121804775dfSFelix Fietkau struct pci_dev *pci_dev; 1222b2ba3ecSLorenzo Bianconi }; 1232b2ba3ecSLorenzo Bianconi enum mtk_wed_bus_tye bus_type; 1244c5de09eSLorenzo Bianconi void __iomem *base; 1254c5de09eSLorenzo Bianconi u32 phy_base; 126804775dfSFelix Fietkau 127804775dfSFelix Fietkau u32 wpdma_phys; 128de84a090SLorenzo Bianconi u32 wpdma_int; 129de84a090SLorenzo Bianconi u32 wpdma_mask; 130de84a090SLorenzo Bianconi u32 wpdma_tx; 131de84a090SLorenzo Bianconi u32 wpdma_txfree; 1324c5de09eSLorenzo Bianconi u32 wpdma_rx_glo; 1334c5de09eSLorenzo Bianconi u32 wpdma_rx; 1344c5de09eSLorenzo Bianconi 1354c5de09eSLorenzo Bianconi bool wcid_512; 136804775dfSFelix Fietkau 137804775dfSFelix Fietkau u16 token_start; 138804775dfSFelix Fietkau unsigned int nbuf; 1394c5de09eSLorenzo Bianconi unsigned int rx_nbuf; 1404c5de09eSLorenzo Bianconi unsigned int rx_npkt; 1414c5de09eSLorenzo Bianconi unsigned int rx_size; 142804775dfSFelix Fietkau 143de84a090SLorenzo Bianconi u8 tx_tbit[MTK_WED_TX_QUEUES]; 1444c5de09eSLorenzo Bianconi u8 rx_tbit[MTK_WED_RX_QUEUES]; 145de84a090SLorenzo Bianconi u8 txfree_tbit; 146de84a090SLorenzo Bianconi 147804775dfSFelix Fietkau u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id); 148804775dfSFelix Fietkau int (*offload_enable)(struct mtk_wed_device *wed); 149804775dfSFelix Fietkau void (*offload_disable)(struct mtk_wed_device *wed); 1504c5de09eSLorenzo Bianconi u32 (*init_rx_buf)(struct mtk_wed_device *wed, int size); 1514c5de09eSLorenzo Bianconi void (*release_rx_buf)(struct mtk_wed_device *wed); 1524c5de09eSLorenzo Bianconi void (*update_wo_rx_stats)(struct mtk_wed_device *wed, 1534c5de09eSLorenzo Bianconi struct mtk_wed_wo_rx_stats *stats); 154804775dfSFelix Fietkau } wlan; 155804775dfSFelix Fietkau #endif 156804775dfSFelix Fietkau }; 157804775dfSFelix Fietkau 158804775dfSFelix Fietkau struct mtk_wed_ops { 159804775dfSFelix Fietkau int (*attach)(struct mtk_wed_device *dev); 160804775dfSFelix Fietkau int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring, 161*23dca7a9SLorenzo Bianconi void __iomem *regs, bool reset); 1624c5de09eSLorenzo Bianconi int (*rx_ring_setup)(struct mtk_wed_device *dev, int ring, 1634c5de09eSLorenzo Bianconi void __iomem *regs); 164804775dfSFelix Fietkau int (*txfree_ring_setup)(struct mtk_wed_device *dev, 165804775dfSFelix Fietkau void __iomem *regs); 1664c5de09eSLorenzo Bianconi int (*msg_update)(struct mtk_wed_device *dev, int cmd_id, 1674c5de09eSLorenzo Bianconi void *data, int len); 168804775dfSFelix Fietkau void (*detach)(struct mtk_wed_device *dev); 1694c5de09eSLorenzo Bianconi void (*ppe_check)(struct mtk_wed_device *dev, struct sk_buff *skb, 1704c5de09eSLorenzo Bianconi u32 reason, u32 hash); 171804775dfSFelix Fietkau 172804775dfSFelix Fietkau void (*stop)(struct mtk_wed_device *dev); 173804775dfSFelix Fietkau void (*start)(struct mtk_wed_device *dev, u32 irq_mask); 174804775dfSFelix Fietkau void (*reset_dma)(struct mtk_wed_device *dev); 175804775dfSFelix Fietkau 176804775dfSFelix Fietkau u32 (*reg_read)(struct mtk_wed_device *dev, u32 reg); 177804775dfSFelix Fietkau void (*reg_write)(struct mtk_wed_device *dev, u32 reg, u32 val); 178804775dfSFelix Fietkau 179804775dfSFelix Fietkau u32 (*irq_get)(struct mtk_wed_device *dev, u32 mask); 180804775dfSFelix Fietkau void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask); 181804775dfSFelix Fietkau }; 182804775dfSFelix Fietkau 183804775dfSFelix Fietkau extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops; 184804775dfSFelix Fietkau 185804775dfSFelix Fietkau static inline int 186804775dfSFelix Fietkau mtk_wed_device_attach(struct mtk_wed_device *dev) 187804775dfSFelix Fietkau { 188804775dfSFelix Fietkau int ret = -ENODEV; 189804775dfSFelix Fietkau 190804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 191804775dfSFelix Fietkau rcu_read_lock(); 192804775dfSFelix Fietkau dev->ops = rcu_dereference(mtk_soc_wed_ops); 193804775dfSFelix Fietkau if (dev->ops) 194804775dfSFelix Fietkau ret = dev->ops->attach(dev); 195804775dfSFelix Fietkau else 196804775dfSFelix Fietkau rcu_read_unlock(); 197804775dfSFelix Fietkau 198804775dfSFelix Fietkau if (ret) 199804775dfSFelix Fietkau dev->ops = NULL; 200804775dfSFelix Fietkau #endif 201804775dfSFelix Fietkau 202804775dfSFelix Fietkau return ret; 203804775dfSFelix Fietkau } 204804775dfSFelix Fietkau 2054c5de09eSLorenzo Bianconi static inline bool 2064c5de09eSLorenzo Bianconi mtk_wed_get_rx_capa(struct mtk_wed_device *dev) 2074c5de09eSLorenzo Bianconi { 2084c5de09eSLorenzo Bianconi #ifdef CONFIG_NET_MEDIATEK_SOC_WED 2094c5de09eSLorenzo Bianconi return dev->version != 1; 2104c5de09eSLorenzo Bianconi #else 2114c5de09eSLorenzo Bianconi return false; 2124c5de09eSLorenzo Bianconi #endif 2134c5de09eSLorenzo Bianconi } 2144c5de09eSLorenzo Bianconi 215804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 216804775dfSFelix Fietkau #define mtk_wed_device_active(_dev) !!(_dev)->ops 217804775dfSFelix Fietkau #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev) 218804775dfSFelix Fietkau #define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask) 219*23dca7a9SLorenzo Bianconi #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ 220*23dca7a9SLorenzo Bianconi (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) 221804775dfSFelix Fietkau #define mtk_wed_device_txfree_ring_setup(_dev, _regs) \ 222804775dfSFelix Fietkau (_dev)->ops->txfree_ring_setup(_dev, _regs) 223804775dfSFelix Fietkau #define mtk_wed_device_reg_read(_dev, _reg) \ 224804775dfSFelix Fietkau (_dev)->ops->reg_read(_dev, _reg) 225804775dfSFelix Fietkau #define mtk_wed_device_reg_write(_dev, _reg, _val) \ 226804775dfSFelix Fietkau (_dev)->ops->reg_write(_dev, _reg, _val) 227804775dfSFelix Fietkau #define mtk_wed_device_irq_get(_dev, _mask) \ 228804775dfSFelix Fietkau (_dev)->ops->irq_get(_dev, _mask) 229804775dfSFelix Fietkau #define mtk_wed_device_irq_set_mask(_dev, _mask) \ 230804775dfSFelix Fietkau (_dev)->ops->irq_set_mask(_dev, _mask) 2314c5de09eSLorenzo Bianconi #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs) \ 2324c5de09eSLorenzo Bianconi (_dev)->ops->rx_ring_setup(_dev, _ring, _regs) 2334c5de09eSLorenzo Bianconi #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) \ 2344c5de09eSLorenzo Bianconi (_dev)->ops->ppe_check(_dev, _skb, _reason, _hash) 2354c5de09eSLorenzo Bianconi #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) \ 2364c5de09eSLorenzo Bianconi (_dev)->ops->msg_update(_dev, _id, _msg, _len) 237f78cd9c7SLorenzo Bianconi #define mtk_wed_device_stop(_dev) (_dev)->ops->stop(_dev) 238f78cd9c7SLorenzo Bianconi #define mtk_wed_device_dma_reset(_dev) (_dev)->ops->reset_dma(_dev) 239804775dfSFelix Fietkau #else 240804775dfSFelix Fietkau static inline bool mtk_wed_device_active(struct mtk_wed_device *dev) 241804775dfSFelix Fietkau { 242804775dfSFelix Fietkau return false; 243804775dfSFelix Fietkau } 244804775dfSFelix Fietkau #define mtk_wed_device_detach(_dev) do {} while (0) 245804775dfSFelix Fietkau #define mtk_wed_device_start(_dev, _mask) do {} while (0) 246*23dca7a9SLorenzo Bianconi #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV 247804775dfSFelix Fietkau #define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV 248804775dfSFelix Fietkau #define mtk_wed_device_reg_read(_dev, _reg) 0 249804775dfSFelix Fietkau #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0) 250804775dfSFelix Fietkau #define mtk_wed_device_irq_get(_dev, _mask) 0 251804775dfSFelix Fietkau #define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0) 2524c5de09eSLorenzo Bianconi #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs) -ENODEV 2534c5de09eSLorenzo Bianconi #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) do {} while (0) 2544c5de09eSLorenzo Bianconi #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) -ENODEV 255f78cd9c7SLorenzo Bianconi #define mtk_wed_device_stop(_dev) do {} while (0) 256f78cd9c7SLorenzo Bianconi #define mtk_wed_device_dma_reset(_dev) do {} while (0) 257804775dfSFelix Fietkau #endif 258804775dfSFelix Fietkau 259804775dfSFelix Fietkau #endif 260