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 struct mtk_wed_wo;
14
15 struct mtk_wed_hw {
16 struct device_node *node;
17 struct mtk_eth *eth;
18 struct regmap *regs;
19 struct regmap *hifsys;
20 struct device *dev;
21 void __iomem *wdma;
22 phys_addr_t wdma_phy;
23 struct regmap *mirror;
24 struct dentry *debugfs_dir;
25 struct mtk_wed_device *wed_dev;
26 struct mtk_wed_wo *wed_wo;
27 u32 debugfs_reg;
28 u32 num_flows;
29 u8 version;
30 char dirname[5];
31 int irq;
32 int index;
33 };
34
35 struct mtk_wdma_info {
36 u8 wdma_idx;
37 u8 queue;
38 u16 wcid;
39 u8 bss;
40 };
41
42 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
43 static inline void
wed_w32(struct mtk_wed_device * dev,u32 reg,u32 val)44 wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
45 {
46 regmap_write(dev->hw->regs, reg, val);
47 }
48
49 static inline u32
wed_r32(struct mtk_wed_device * dev,u32 reg)50 wed_r32(struct mtk_wed_device *dev, u32 reg)
51 {
52 unsigned int val;
53
54 regmap_read(dev->hw->regs, reg, &val);
55
56 return val;
57 }
58
59 static inline void
wdma_w32(struct mtk_wed_device * dev,u32 reg,u32 val)60 wdma_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
61 {
62 writel(val, dev->hw->wdma + reg);
63 }
64
65 static inline u32
wdma_r32(struct mtk_wed_device * dev,u32 reg)66 wdma_r32(struct mtk_wed_device *dev, u32 reg)
67 {
68 return readl(dev->hw->wdma + reg);
69 }
70
71 static inline u32
wpdma_tx_r32(struct mtk_wed_device * dev,int ring,u32 reg)72 wpdma_tx_r32(struct mtk_wed_device *dev, int ring, u32 reg)
73 {
74 if (!dev->tx_ring[ring].wpdma)
75 return 0;
76
77 return readl(dev->tx_ring[ring].wpdma + reg);
78 }
79
80 static inline void
wpdma_tx_w32(struct mtk_wed_device * dev,int ring,u32 reg,u32 val)81 wpdma_tx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val)
82 {
83 if (!dev->tx_ring[ring].wpdma)
84 return;
85
86 writel(val, dev->tx_ring[ring].wpdma + reg);
87 }
88
89 static inline u32
wpdma_rx_r32(struct mtk_wed_device * dev,int ring,u32 reg)90 wpdma_rx_r32(struct mtk_wed_device *dev, int ring, u32 reg)
91 {
92 if (!dev->rx_ring[ring].wpdma)
93 return 0;
94
95 return readl(dev->rx_ring[ring].wpdma + reg);
96 }
97
98 static inline void
wpdma_rx_w32(struct mtk_wed_device * dev,int ring,u32 reg,u32 val)99 wpdma_rx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val)
100 {
101 if (!dev->rx_ring[ring].wpdma)
102 return;
103
104 writel(val, dev->rx_ring[ring].wpdma + reg);
105 }
106
107 static inline u32
wpdma_txfree_r32(struct mtk_wed_device * dev,u32 reg)108 wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg)
109 {
110 if (!dev->txfree_ring.wpdma)
111 return 0;
112
113 return readl(dev->txfree_ring.wpdma + reg);
114 }
115
116 static inline void
wpdma_txfree_w32(struct mtk_wed_device * dev,u32 reg,u32 val)117 wpdma_txfree_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
118 {
119 if (!dev->txfree_ring.wpdma)
120 return;
121
122 writel(val, dev->txfree_ring.wpdma + reg);
123 }
124
125 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
126 void __iomem *wdma, phys_addr_t wdma_phy,
127 int index);
128 void mtk_wed_exit(void);
129 int mtk_wed_flow_add(int index);
130 void mtk_wed_flow_remove(int index);
131 void mtk_wed_fe_reset(void);
132 void mtk_wed_fe_reset_complete(void);
133 #else
134 static inline void
mtk_wed_add_hw(struct device_node * np,struct mtk_eth * eth,void __iomem * wdma,phys_addr_t wdma_phy,int index)135 mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
136 void __iomem *wdma, phys_addr_t wdma_phy,
137 int index)
138 {
139 }
140 static inline void
mtk_wed_exit(void)141 mtk_wed_exit(void)
142 {
143 }
mtk_wed_flow_add(int index)144 static inline int mtk_wed_flow_add(int index)
145 {
146 return -EINVAL;
147 }
mtk_wed_flow_remove(int index)148 static inline void mtk_wed_flow_remove(int index)
149 {
150 }
151
mtk_wed_fe_reset(void)152 static inline void mtk_wed_fe_reset(void)
153 {
154 }
155
mtk_wed_fe_reset_complete(void)156 static inline void mtk_wed_fe_reset_complete(void)
157 {
158 }
159 #endif
160
161 #ifdef CONFIG_DEBUG_FS
162 void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw);
163 #else
mtk_wed_hw_add_debugfs(struct mtk_wed_hw * hw)164 static inline void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw)
165 {
166 }
167 #endif
168
169 #endif
170