mtk_wed.h (3483B)
1#ifndef __MTK_WED_H 2#define __MTK_WED_H 3 4#include <linux/kernel.h> 5#include <linux/rcupdate.h> 6#include <linux/regmap.h> 7#include <linux/pci.h> 8 9#define MTK_WED_TX_QUEUES 2 10 11struct mtk_wed_hw; 12struct mtk_wdma_desc; 13 14struct mtk_wed_ring { 15 struct mtk_wdma_desc *desc; 16 dma_addr_t desc_phys; 17 int size; 18 19 u32 reg_base; 20 void __iomem *wpdma; 21}; 22 23struct mtk_wed_device { 24#ifdef CONFIG_NET_MEDIATEK_SOC_WED 25 const struct mtk_wed_ops *ops; 26 struct device *dev; 27 struct mtk_wed_hw *hw; 28 bool init_done, running; 29 int wdma_idx; 30 int irq; 31 32 struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES]; 33 struct mtk_wed_ring txfree_ring; 34 struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES]; 35 36 struct { 37 int size; 38 void **pages; 39 struct mtk_wdma_desc *desc; 40 dma_addr_t desc_phys; 41 } buf_ring; 42 43 /* filled by driver: */ 44 struct { 45 struct pci_dev *pci_dev; 46 47 u32 wpdma_phys; 48 49 u16 token_start; 50 unsigned int nbuf; 51 52 u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id); 53 int (*offload_enable)(struct mtk_wed_device *wed); 54 void (*offload_disable)(struct mtk_wed_device *wed); 55 } wlan; 56#endif 57}; 58 59struct mtk_wed_ops { 60 int (*attach)(struct mtk_wed_device *dev); 61 int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring, 62 void __iomem *regs); 63 int (*txfree_ring_setup)(struct mtk_wed_device *dev, 64 void __iomem *regs); 65 void (*detach)(struct mtk_wed_device *dev); 66 67 void (*stop)(struct mtk_wed_device *dev); 68 void (*start)(struct mtk_wed_device *dev, u32 irq_mask); 69 void (*reset_dma)(struct mtk_wed_device *dev); 70 71 u32 (*reg_read)(struct mtk_wed_device *dev, u32 reg); 72 void (*reg_write)(struct mtk_wed_device *dev, u32 reg, u32 val); 73 74 u32 (*irq_get)(struct mtk_wed_device *dev, u32 mask); 75 void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask); 76}; 77 78extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops; 79 80static inline int 81mtk_wed_device_attach(struct mtk_wed_device *dev) 82{ 83 int ret = -ENODEV; 84 85#ifdef CONFIG_NET_MEDIATEK_SOC_WED 86 rcu_read_lock(); 87 dev->ops = rcu_dereference(mtk_soc_wed_ops); 88 if (dev->ops) 89 ret = dev->ops->attach(dev); 90 else 91 rcu_read_unlock(); 92 93 if (ret) 94 dev->ops = NULL; 95#endif 96 97 return ret; 98} 99 100#ifdef CONFIG_NET_MEDIATEK_SOC_WED 101#define mtk_wed_device_active(_dev) !!(_dev)->ops 102#define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev) 103#define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask) 104#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) \ 105 (_dev)->ops->tx_ring_setup(_dev, _ring, _regs) 106#define mtk_wed_device_txfree_ring_setup(_dev, _regs) \ 107 (_dev)->ops->txfree_ring_setup(_dev, _regs) 108#define mtk_wed_device_reg_read(_dev, _reg) \ 109 (_dev)->ops->reg_read(_dev, _reg) 110#define mtk_wed_device_reg_write(_dev, _reg, _val) \ 111 (_dev)->ops->reg_write(_dev, _reg, _val) 112#define mtk_wed_device_irq_get(_dev, _mask) \ 113 (_dev)->ops->irq_get(_dev, _mask) 114#define mtk_wed_device_irq_set_mask(_dev, _mask) \ 115 (_dev)->ops->irq_set_mask(_dev, _mask) 116#else 117static inline bool mtk_wed_device_active(struct mtk_wed_device *dev) 118{ 119 return false; 120} 121#define mtk_wed_device_detach(_dev) do {} while (0) 122#define mtk_wed_device_start(_dev, _mask) do {} while (0) 123#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) -ENODEV 124#define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV 125#define mtk_wed_device_reg_read(_dev, _reg) 0 126#define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0) 127#define mtk_wed_device_irq_get(_dev, _mask) 0 128#define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0) 129#endif 130 131#endif