1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */ 3 4 #ifndef __MTK_WED_PRIV_H 5 #define __MTK_WED_PRIV_H 6 7 #include <linux/soc/mediatek/mtk_wed.h> 8 #include <linux/debugfs.h> 9 #include <linux/regmap.h> 10 #include <linux/netdevice.h> 11 12 struct mtk_eth; 13 14 struct mtk_wed_hw { 15 struct device_node *node; 16 struct mtk_eth *eth; 17 struct regmap *regs; 18 struct regmap *hifsys; 19 struct device *dev; 20 void __iomem *wdma; 21 struct regmap *mirror; 22 struct dentry *debugfs_dir; 23 struct mtk_wed_device *wed_dev; 24 u32 debugfs_reg; 25 u32 num_flows; 26 char dirname[5]; 27 int irq; 28 int index; 29 }; 30 31 struct mtk_wdma_info { 32 u8 wdma_idx; 33 u8 queue; 34 u16 wcid; 35 u8 bss; 36 }; 37 38 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 39 static inline void 40 wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 41 { 42 regmap_write(dev->hw->regs, reg, val); 43 } 44 45 static inline u32 46 wed_r32(struct mtk_wed_device *dev, u32 reg) 47 { 48 unsigned int val; 49 50 regmap_read(dev->hw->regs, reg, &val); 51 52 return val; 53 } 54 55 static inline void 56 wdma_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 57 { 58 writel(val, dev->hw->wdma + reg); 59 } 60 61 static inline u32 62 wdma_r32(struct mtk_wed_device *dev, u32 reg) 63 { 64 return readl(dev->hw->wdma + reg); 65 } 66 67 static inline u32 68 wpdma_tx_r32(struct mtk_wed_device *dev, int ring, u32 reg) 69 { 70 if (!dev->tx_ring[ring].wpdma) 71 return 0; 72 73 return readl(dev->tx_ring[ring].wpdma + reg); 74 } 75 76 static inline void 77 wpdma_tx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val) 78 { 79 if (!dev->tx_ring[ring].wpdma) 80 return; 81 82 writel(val, dev->tx_ring[ring].wpdma + reg); 83 } 84 85 static inline u32 86 wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg) 87 { 88 if (!dev->txfree_ring.wpdma) 89 return 0; 90 91 return readl(dev->txfree_ring.wpdma + reg); 92 } 93 94 static inline void 95 wpdma_txfree_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 96 { 97 if (!dev->txfree_ring.wpdma) 98 return; 99 100 writel(val, dev->txfree_ring.wpdma + reg); 101 } 102 103 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth, 104 void __iomem *wdma, int index); 105 void mtk_wed_exit(void); 106 int mtk_wed_flow_add(int index); 107 void mtk_wed_flow_remove(int index); 108 #else 109 static inline void 110 mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth, 111 void __iomem *wdma, int index) 112 { 113 } 114 static inline void 115 mtk_wed_exit(void) 116 { 117 } 118 static inline int mtk_wed_flow_add(int index) 119 { 120 return -EINVAL; 121 } 122 static inline void mtk_wed_flow_remove(int index) 123 { 124 } 125 #endif 126 127 #ifdef CONFIG_DEBUG_FS 128 void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw); 129 #else 130 static inline void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw) 131 { 132 } 133 #endif 134 135 #endif 136