2948188650336319c0433843c793228a1b9ff520
[openwrt/staging/neocturne.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Mon, 18 Sep 2023 12:29:05 +0200
3 Subject: [PATCH] net: ethernet: mtk_wed: introduce versioning utility routines
4
5 Similar to mtk_eth_soc, introduce the following wed versioning
6 utility routines:
7 - mtk_wed_is_v1
8 - mtk_wed_is_v2
9
10 This is a preliminary patch to introduce WED support for MT7988 SoC
11
12 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
13 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
14 ---
15
16 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
18 @@ -277,7 +277,7 @@ mtk_wed_assign(struct mtk_wed_device *de
19 if (!hw->wed_dev)
20 goto out;
21
22 - if (hw->version == 1)
23 + if (mtk_wed_is_v1(hw))
24 return NULL;
25
26 /* MT7986 WED devices do not have any pcie slot restrictions */
27 @@ -358,7 +358,7 @@ mtk_wed_tx_buffer_alloc(struct mtk_wed_d
28 desc->buf0 = cpu_to_le32(buf_phys);
29 desc->buf1 = cpu_to_le32(buf_phys + txd_size);
30
31 - if (dev->hw->version == 1)
32 + if (mtk_wed_is_v1(dev->hw))
33 ctrl = FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN0, txd_size) |
34 FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN1,
35 MTK_WED_BUF_SIZE - txd_size) |
36 @@ -497,7 +497,7 @@ mtk_wed_set_ext_int(struct mtk_wed_devic
37 {
38 u32 mask = MTK_WED_EXT_INT_STATUS_ERROR_MASK;
39
40 - if (dev->hw->version == 1)
41 + if (mtk_wed_is_v1(dev->hw))
42 mask |= MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR;
43 else
44 mask |= MTK_WED_EXT_INT_STATUS_RX_FBUF_LO_TH |
45 @@ -576,7 +576,7 @@ mtk_wed_dma_disable(struct mtk_wed_devic
46 MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
47 MTK_WDMA_GLO_CFG_RX_INFO2_PRERES);
48
49 - if (dev->hw->version == 1) {
50 + if (mtk_wed_is_v1(dev->hw)) {
51 regmap_write(dev->hw->mirror, dev->hw->index * 4, 0);
52 wdma_clr(dev, MTK_WDMA_GLO_CFG,
53 MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
54 @@ -605,7 +605,7 @@ mtk_wed_stop(struct mtk_wed_device *dev)
55 wdma_w32(dev, MTK_WDMA_INT_GRP2, 0);
56 wed_w32(dev, MTK_WED_WPDMA_INT_MASK, 0);
57
58 - if (dev->hw->version == 1)
59 + if (mtk_wed_is_v1(dev->hw))
60 return;
61
62 wed_w32(dev, MTK_WED_EXT_INT_MASK1, 0);
63 @@ -624,7 +624,7 @@ mtk_wed_deinit(struct mtk_wed_device *de
64 MTK_WED_CTRL_WED_TX_BM_EN |
65 MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
66
67 - if (dev->hw->version == 1)
68 + if (mtk_wed_is_v1(dev->hw))
69 return;
70
71 wed_clr(dev, MTK_WED_CTRL,
72 @@ -730,7 +730,7 @@ mtk_wed_bus_init(struct mtk_wed_device *
73 static void
74 mtk_wed_set_wpdma(struct mtk_wed_device *dev)
75 {
76 - if (dev->hw->version == 1) {
77 + if (mtk_wed_is_v1(dev->hw)) {
78 wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_phys);
79 } else {
80 mtk_wed_bus_init(dev);
81 @@ -761,7 +761,7 @@ mtk_wed_hw_init_early(struct mtk_wed_dev
82 MTK_WED_WDMA_GLO_CFG_IDLE_DMAD_SUPPLY;
83 wed_m32(dev, MTK_WED_WDMA_GLO_CFG, mask, set);
84
85 - if (dev->hw->version == 1) {
86 + if (mtk_wed_is_v1(dev->hw)) {
87 u32 offset = dev->hw->index ? 0x04000400 : 0;
88
89 wdma_set(dev, MTK_WDMA_GLO_CFG,
90 @@ -934,7 +934,7 @@ mtk_wed_hw_init(struct mtk_wed_device *d
91
92 wed_w32(dev, MTK_WED_TX_BM_BUF_LEN, MTK_WED_PKT_SIZE);
93
94 - if (dev->hw->version == 1) {
95 + if (mtk_wed_is_v1(dev->hw)) {
96 wed_w32(dev, MTK_WED_TX_BM_TKID,
97 FIELD_PREP(MTK_WED_TX_BM_TKID_START,
98 dev->wlan.token_start) |
99 @@ -967,7 +967,7 @@ mtk_wed_hw_init(struct mtk_wed_device *d
100
101 mtk_wed_reset(dev, MTK_WED_RESET_TX_BM);
102
103 - if (dev->hw->version == 1) {
104 + if (mtk_wed_is_v1(dev->hw)) {
105 wed_set(dev, MTK_WED_CTRL,
106 MTK_WED_CTRL_WED_TX_BM_EN |
107 MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
108 @@ -1217,7 +1217,7 @@ mtk_wed_reset_dma(struct mtk_wed_device
109 }
110
111 dev->init_done = false;
112 - if (dev->hw->version == 1)
113 + if (mtk_wed_is_v1(dev->hw))
114 return;
115
116 if (!busy) {
117 @@ -1343,7 +1343,7 @@ mtk_wed_configure_irq(struct mtk_wed_dev
118 MTK_WED_CTRL_WED_TX_BM_EN |
119 MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
120
121 - if (dev->hw->version == 1) {
122 + if (mtk_wed_is_v1(dev->hw)) {
123 wed_w32(dev, MTK_WED_PCIE_INT_TRIGGER,
124 MTK_WED_PCIE_INT_TRIGGER_STATUS);
125
126 @@ -1416,7 +1416,7 @@ mtk_wed_dma_enable(struct mtk_wed_device
127 MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
128 MTK_WDMA_GLO_CFG_RX_INFO2_PRERES);
129
130 - if (dev->hw->version == 1) {
131 + if (mtk_wed_is_v1(dev->hw)) {
132 wdma_set(dev, MTK_WDMA_GLO_CFG,
133 MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
134 } else {
135 @@ -1465,7 +1465,7 @@ mtk_wed_start(struct mtk_wed_device *dev
136
137 mtk_wed_set_ext_int(dev, true);
138
139 - if (dev->hw->version == 1) {
140 + if (mtk_wed_is_v1(dev->hw)) {
141 u32 val = dev->wlan.wpdma_phys | MTK_PCIE_MIRROR_MAP_EN |
142 FIELD_PREP(MTK_PCIE_MIRROR_MAP_WED_ID,
143 dev->hw->index);
144 @@ -1550,7 +1550,7 @@ mtk_wed_attach(struct mtk_wed_device *de
145 }
146
147 mtk_wed_hw_init_early(dev);
148 - if (hw->version == 1) {
149 + if (mtk_wed_is_v1(hw)) {
150 regmap_update_bits(hw->hifsys, HIFSYS_DMA_AG_MAP,
151 BIT(hw->index), 0);
152 } else {
153 @@ -1618,7 +1618,7 @@ static int
154 mtk_wed_txfree_ring_setup(struct mtk_wed_device *dev, void __iomem *regs)
155 {
156 struct mtk_wed_ring *ring = &dev->txfree_ring;
157 - int i, index = dev->hw->version == 1;
158 + int i, index = mtk_wed_is_v1(dev->hw);
159
160 /*
161 * For txfree event handling, the same DMA ring is shared between WED
162 @@ -1676,7 +1676,7 @@ mtk_wed_irq_get(struct mtk_wed_device *d
163 {
164 u32 val, ext_mask = MTK_WED_EXT_INT_STATUS_ERROR_MASK;
165
166 - if (dev->hw->version == 1)
167 + if (mtk_wed_is_v1(dev->hw))
168 ext_mask |= MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR;
169 else
170 ext_mask |= MTK_WED_EXT_INT_STATUS_RX_FBUF_LO_TH |
171 @@ -1843,7 +1843,7 @@ mtk_wed_setup_tc(struct mtk_wed_device *
172 {
173 struct mtk_wed_hw *hw = wed->hw;
174
175 - if (hw->version < 2)
176 + if (mtk_wed_is_v1(hw))
177 return -EOPNOTSUPP;
178
179 switch (type) {
180 @@ -1917,9 +1917,9 @@ void mtk_wed_add_hw(struct device_node *
181 hw->wdma = wdma;
182 hw->index = index;
183 hw->irq = irq;
184 - hw->version = mtk_is_netsys_v1(eth) ? 1 : 2;
185 + hw->version = eth->soc->version;
186
187 - if (hw->version == 1) {
188 + if (mtk_wed_is_v1(hw)) {
189 hw->mirror = syscon_regmap_lookup_by_phandle(eth_np,
190 "mediatek,pcie-mirror");
191 hw->hifsys = syscon_regmap_lookup_by_phandle(eth_np,
192 --- a/drivers/net/ethernet/mediatek/mtk_wed.h
193 +++ b/drivers/net/ethernet/mediatek/mtk_wed.h
194 @@ -40,6 +40,16 @@ struct mtk_wdma_info {
195 };
196
197 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
198 +static inline bool mtk_wed_is_v1(struct mtk_wed_hw *hw)
199 +{
200 + return hw->version == 1;
201 +}
202 +
203 +static inline bool mtk_wed_is_v2(struct mtk_wed_hw *hw)
204 +{
205 + return hw->version == 2;
206 +}
207 +
208 static inline void
209 wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
210 {
211 --- a/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
212 +++ b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
213 @@ -263,7 +263,7 @@ void mtk_wed_hw_add_debugfs(struct mtk_w
214 debugfs_create_u32("regidx", 0600, dir, &hw->debugfs_reg);
215 debugfs_create_file_unsafe("regval", 0600, dir, hw, &fops_regval);
216 debugfs_create_file_unsafe("txinfo", 0400, dir, hw, &wed_txinfo_fops);
217 - if (hw->version != 1)
218 + if (!mtk_wed_is_v1(hw))
219 debugfs_create_file_unsafe("rxinfo", 0400, dir, hw,
220 &wed_rxinfo_fops);
221 }
222 --- a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
223 +++ b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
224 @@ -207,7 +207,7 @@ int mtk_wed_mcu_msg_update(struct mtk_we
225 {
226 struct mtk_wed_wo *wo = dev->hw->wed_wo;
227
228 - if (dev->hw->version == 1)
229 + if (mtk_wed_is_v1(dev->hw))
230 return 0;
231
232 if (WARN_ON(!wo))