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> 8804775dfSFelix Fietkau 9804775dfSFelix Fietkau #define MTK_WED_TX_QUEUES 2 10804775dfSFelix Fietkau 11804775dfSFelix Fietkau struct mtk_wed_hw; 12804775dfSFelix Fietkau struct mtk_wdma_desc; 13804775dfSFelix Fietkau 14804775dfSFelix Fietkau struct mtk_wed_ring { 15804775dfSFelix Fietkau struct mtk_wdma_desc *desc; 16804775dfSFelix Fietkau dma_addr_t desc_phys; 17*de84a090SLorenzo Bianconi u32 desc_size; 18804775dfSFelix Fietkau int size; 19804775dfSFelix Fietkau 20804775dfSFelix Fietkau u32 reg_base; 21804775dfSFelix Fietkau void __iomem *wpdma; 22804775dfSFelix Fietkau }; 23804775dfSFelix Fietkau 24804775dfSFelix Fietkau struct mtk_wed_device { 25804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 26804775dfSFelix Fietkau const struct mtk_wed_ops *ops; 27804775dfSFelix Fietkau struct device *dev; 28804775dfSFelix Fietkau struct mtk_wed_hw *hw; 29804775dfSFelix Fietkau bool init_done, running; 30804775dfSFelix Fietkau int wdma_idx; 31804775dfSFelix Fietkau int irq; 32804775dfSFelix Fietkau 33804775dfSFelix Fietkau struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES]; 34804775dfSFelix Fietkau struct mtk_wed_ring txfree_ring; 35804775dfSFelix Fietkau struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES]; 36804775dfSFelix Fietkau 37804775dfSFelix Fietkau struct { 38804775dfSFelix Fietkau int size; 39804775dfSFelix Fietkau void **pages; 40804775dfSFelix Fietkau struct mtk_wdma_desc *desc; 41804775dfSFelix Fietkau dma_addr_t desc_phys; 42804775dfSFelix Fietkau } buf_ring; 43804775dfSFelix Fietkau 44804775dfSFelix Fietkau /* filled by driver: */ 45804775dfSFelix Fietkau struct { 46804775dfSFelix Fietkau struct pci_dev *pci_dev; 47804775dfSFelix Fietkau 48804775dfSFelix Fietkau u32 wpdma_phys; 49*de84a090SLorenzo Bianconi u32 wpdma_int; 50*de84a090SLorenzo Bianconi u32 wpdma_mask; 51*de84a090SLorenzo Bianconi u32 wpdma_tx; 52*de84a090SLorenzo Bianconi u32 wpdma_txfree; 53804775dfSFelix Fietkau 54804775dfSFelix Fietkau u16 token_start; 55804775dfSFelix Fietkau unsigned int nbuf; 56804775dfSFelix Fietkau 57*de84a090SLorenzo Bianconi u8 tx_tbit[MTK_WED_TX_QUEUES]; 58*de84a090SLorenzo Bianconi u8 txfree_tbit; 59*de84a090SLorenzo Bianconi 60804775dfSFelix Fietkau u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id); 61804775dfSFelix Fietkau int (*offload_enable)(struct mtk_wed_device *wed); 62804775dfSFelix Fietkau void (*offload_disable)(struct mtk_wed_device *wed); 63804775dfSFelix Fietkau } wlan; 64804775dfSFelix Fietkau #endif 65804775dfSFelix Fietkau }; 66804775dfSFelix Fietkau 67804775dfSFelix Fietkau struct mtk_wed_ops { 68804775dfSFelix Fietkau int (*attach)(struct mtk_wed_device *dev); 69804775dfSFelix Fietkau int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring, 70804775dfSFelix Fietkau void __iomem *regs); 71804775dfSFelix Fietkau int (*txfree_ring_setup)(struct mtk_wed_device *dev, 72804775dfSFelix Fietkau void __iomem *regs); 73804775dfSFelix Fietkau void (*detach)(struct mtk_wed_device *dev); 74804775dfSFelix Fietkau 75804775dfSFelix Fietkau void (*stop)(struct mtk_wed_device *dev); 76804775dfSFelix Fietkau void (*start)(struct mtk_wed_device *dev, u32 irq_mask); 77804775dfSFelix Fietkau void (*reset_dma)(struct mtk_wed_device *dev); 78804775dfSFelix Fietkau 79804775dfSFelix Fietkau u32 (*reg_read)(struct mtk_wed_device *dev, u32 reg); 80804775dfSFelix Fietkau void (*reg_write)(struct mtk_wed_device *dev, u32 reg, u32 val); 81804775dfSFelix Fietkau 82804775dfSFelix Fietkau u32 (*irq_get)(struct mtk_wed_device *dev, u32 mask); 83804775dfSFelix Fietkau void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask); 84804775dfSFelix Fietkau }; 85804775dfSFelix Fietkau 86804775dfSFelix Fietkau extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops; 87804775dfSFelix Fietkau 88804775dfSFelix Fietkau static inline int 89804775dfSFelix Fietkau mtk_wed_device_attach(struct mtk_wed_device *dev) 90804775dfSFelix Fietkau { 91804775dfSFelix Fietkau int ret = -ENODEV; 92804775dfSFelix Fietkau 93804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 94804775dfSFelix Fietkau rcu_read_lock(); 95804775dfSFelix Fietkau dev->ops = rcu_dereference(mtk_soc_wed_ops); 96804775dfSFelix Fietkau if (dev->ops) 97804775dfSFelix Fietkau ret = dev->ops->attach(dev); 98804775dfSFelix Fietkau else 99804775dfSFelix Fietkau rcu_read_unlock(); 100804775dfSFelix Fietkau 101804775dfSFelix Fietkau if (ret) 102804775dfSFelix Fietkau dev->ops = NULL; 103804775dfSFelix Fietkau #endif 104804775dfSFelix Fietkau 105804775dfSFelix Fietkau return ret; 106804775dfSFelix Fietkau } 107804775dfSFelix Fietkau 108804775dfSFelix Fietkau #ifdef CONFIG_NET_MEDIATEK_SOC_WED 109804775dfSFelix Fietkau #define mtk_wed_device_active(_dev) !!(_dev)->ops 110804775dfSFelix Fietkau #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev) 111804775dfSFelix Fietkau #define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask) 112804775dfSFelix Fietkau #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) \ 113804775dfSFelix Fietkau (_dev)->ops->tx_ring_setup(_dev, _ring, _regs) 114804775dfSFelix Fietkau #define mtk_wed_device_txfree_ring_setup(_dev, _regs) \ 115804775dfSFelix Fietkau (_dev)->ops->txfree_ring_setup(_dev, _regs) 116804775dfSFelix Fietkau #define mtk_wed_device_reg_read(_dev, _reg) \ 117804775dfSFelix Fietkau (_dev)->ops->reg_read(_dev, _reg) 118804775dfSFelix Fietkau #define mtk_wed_device_reg_write(_dev, _reg, _val) \ 119804775dfSFelix Fietkau (_dev)->ops->reg_write(_dev, _reg, _val) 120804775dfSFelix Fietkau #define mtk_wed_device_irq_get(_dev, _mask) \ 121804775dfSFelix Fietkau (_dev)->ops->irq_get(_dev, _mask) 122804775dfSFelix Fietkau #define mtk_wed_device_irq_set_mask(_dev, _mask) \ 123804775dfSFelix Fietkau (_dev)->ops->irq_set_mask(_dev, _mask) 124804775dfSFelix Fietkau #else 125804775dfSFelix Fietkau static inline bool mtk_wed_device_active(struct mtk_wed_device *dev) 126804775dfSFelix Fietkau { 127804775dfSFelix Fietkau return false; 128804775dfSFelix Fietkau } 129804775dfSFelix Fietkau #define mtk_wed_device_detach(_dev) do {} while (0) 130804775dfSFelix Fietkau #define mtk_wed_device_start(_dev, _mask) do {} while (0) 131804775dfSFelix Fietkau #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) -ENODEV 132804775dfSFelix Fietkau #define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV 133804775dfSFelix Fietkau #define mtk_wed_device_reg_read(_dev, _reg) 0 134804775dfSFelix Fietkau #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0) 135804775dfSFelix Fietkau #define mtk_wed_device_irq_get(_dev, _mask) 0 136804775dfSFelix Fietkau #define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0) 137804775dfSFelix Fietkau #endif 138804775dfSFelix Fietkau 139804775dfSFelix Fietkau #endif 140