1 From 463a71af080fbc77339bee2037fb1e081e3824f7 Mon Sep 17 00:00:00 2001
2 Message-Id: <463a71af080fbc77339bee2037fb1e081e3824f7.1662886034.git.lorenzo@kernel.org>
3 In-Reply-To: <e5ecb4f619197b93fa682d722452dc8412864cdb.1662886033.git.lorenzo@kernel.org>
4 References: <e5ecb4f619197b93fa682d722452dc8412864cdb.1662886033.git.lorenzo@kernel.org>
5 From: Lorenzo Bianconi <lorenzo@kernel.org>
6 Date: Sat, 27 Aug 2022 16:15:14 +0200
7 Subject: [PATCH net-next 2/5] net: ethernet: mtk_eth_wed: add wed support for
10 Introduce Wireless Etherne Dispatcher support on transmission side
13 Co-developed-by: Bo Jiao <Bo.Jiao@mediatek.com>
14 Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
15 Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
16 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
17 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
19 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 34 +-
20 drivers/net/ethernet/mediatek/mtk_wed.c | 371 ++++++++++++++----
21 drivers/net/ethernet/mediatek/mtk_wed.h | 8 +-
22 .../net/ethernet/mediatek/mtk_wed_debugfs.c | 3 +
23 drivers/net/ethernet/mediatek/mtk_wed_regs.h | 81 +++-
24 include/linux/soc/mediatek/mtk_wed.h | 8 +
25 6 files changed, 408 insertions(+), 97 deletions(-)
27 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
28 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
29 @@ -3888,6 +3888,7 @@ void mtk_eth_set_dma_device(struct mtk_e
31 static int mtk_probe(struct platform_device *pdev)
33 + struct resource *res = NULL;
34 struct device_node *mac_np;
37 @@ -3968,16 +3969,31 @@ static int mtk_probe(struct platform_dev
42 - struct device_node *np = of_parse_phandle(pdev->dev.of_node,
46 - if (!np || i >= ARRAY_SIZE(eth->soc->reg_map->wdma_base))
49 - wdma = eth->base + eth->soc->reg_map->wdma_base[i];
50 - mtk_wed_add_hw(np, eth, wdma, i);
51 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
52 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
57 + if (eth->soc->offload_version) {
59 + struct device_node *np;
60 + phys_addr_t wdma_phy;
63 + if (i >= ARRAY_SIZE(eth->soc->reg_map->wdma_base))
66 + np = of_parse_phandle(pdev->dev.of_node,
71 + wdma_base = eth->soc->reg_map->wdma_base[i];
72 + wdma_phy = res ? res->start + wdma_base : 0;
73 + mtk_wed_add_hw(np, eth, eth->base + wdma_base,
78 for (i = 0; i < 3; i++) {
79 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
80 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
83 #define MTK_WED_TX_RING_SIZE 2048
84 #define MTK_WED_WDMA_RING_SIZE 1024
85 +#define MTK_WED_MAX_GROUP_SIZE 0x100
86 +#define MTK_WED_VLD_GROUP_SIZE 0x40
87 +#define MTK_WED_PER_GROUP_PKT 128
89 +#define MTK_WED_FBUF_SIZE 128
91 static struct mtk_wed_hw *hw_list[2];
92 static DEFINE_MUTEX(hw_lock);
93 @@ -150,10 +155,17 @@ mtk_wed_buffer_alloc(struct mtk_wed_devi
95 desc->buf0 = cpu_to_le32(buf_phys);
96 desc->buf1 = cpu_to_le32(buf_phys + txd_size);
97 - ctrl = FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN0, txd_size) |
98 - FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN1,
99 - MTK_WED_BUF_SIZE - txd_size) |
100 - MTK_WDMA_DESC_CTRL_LAST_SEG1;
102 + if (dev->hw->version == 1)
103 + ctrl = FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN0, txd_size) |
104 + FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN1,
105 + MTK_WED_BUF_SIZE - txd_size) |
106 + MTK_WDMA_DESC_CTRL_LAST_SEG1;
108 + ctrl = FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN0, txd_size) |
109 + FIELD_PREP(MTK_WDMA_DESC_CTRL_LEN1_V2,
110 + MTK_WED_BUF_SIZE - txd_size) |
111 + MTK_WDMA_DESC_CTRL_LAST_SEG0;
112 desc->ctrl = cpu_to_le32(ctrl);
115 @@ -209,7 +221,7 @@ mtk_wed_free_ring(struct mtk_wed_device
119 - dma_free_coherent(dev->hw->dev, ring->size * sizeof(*ring->desc),
120 + dma_free_coherent(dev->hw->dev, ring->size * ring->desc_size,
121 ring->desc, ring->desc_phys);
124 @@ -229,6 +241,14 @@ mtk_wed_set_ext_int(struct mtk_wed_devic
126 u32 mask = MTK_WED_EXT_INT_STATUS_ERROR_MASK;
128 + if (dev->hw->version == 1)
129 + mask |= MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR;
131 + mask |= MTK_WED_EXT_INT_STATUS_RX_FBUF_LO_TH |
132 + MTK_WED_EXT_INT_STATUS_RX_FBUF_HI_TH |
133 + MTK_WED_EXT_INT_STATUS_RX_DRV_COHERENT |
134 + MTK_WED_EXT_INT_STATUS_TX_DMA_W_RESP_ERR;
136 if (!dev->hw->num_flows)
137 mask &= ~MTK_WED_EXT_INT_STATUS_TKID_WO_PYLD;
139 @@ -237,6 +257,20 @@ mtk_wed_set_ext_int(struct mtk_wed_devic
143 +mtk_wed_set_512_support(struct mtk_wed_device *dev, bool enable)
146 + wed_w32(dev, MTK_WED_TXDP_CTRL, MTK_WED_TXDP_DW9_OVERWR);
147 + wed_w32(dev, MTK_WED_TXP_DW1,
148 + FIELD_PREP(MTK_WED_WPDMA_WRITE_TXP, 0x0103));
150 + wed_w32(dev, MTK_WED_TXP_DW1,
151 + FIELD_PREP(MTK_WED_WPDMA_WRITE_TXP, 0x0100));
152 + wed_clr(dev, MTK_WED_TXDP_CTRL, MTK_WED_TXDP_DW9_OVERWR);
157 mtk_wed_dma_disable(struct mtk_wed_device *dev)
159 wed_clr(dev, MTK_WED_WPDMA_GLO_CFG,
160 @@ -249,12 +283,22 @@ mtk_wed_dma_disable(struct mtk_wed_devic
161 MTK_WED_GLO_CFG_TX_DMA_EN |
162 MTK_WED_GLO_CFG_RX_DMA_EN);
164 - regmap_write(dev->hw->mirror, dev->hw->index * 4, 0);
165 wdma_m32(dev, MTK_WDMA_GLO_CFG,
166 MTK_WDMA_GLO_CFG_TX_DMA_EN |
167 MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
168 - MTK_WDMA_GLO_CFG_RX_INFO2_PRERES |
169 - MTK_WDMA_GLO_CFG_RX_INFO3_PRERES, 0);
170 + MTK_WDMA_GLO_CFG_RX_INFO2_PRERES, 0);
172 + if (dev->hw->version == 1) {
173 + regmap_write(dev->hw->mirror, dev->hw->index * 4, 0);
174 + wdma_m32(dev, MTK_WDMA_GLO_CFG,
175 + MTK_WDMA_GLO_CFG_RX_INFO3_PRERES, 0);
177 + wed_clr(dev, MTK_WED_WPDMA_GLO_CFG,
178 + MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_PKT_PROC |
179 + MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_CRX_SYNC);
181 + mtk_wed_set_512_support(dev, false);
186 @@ -293,7 +337,7 @@ mtk_wed_detach(struct mtk_wed_device *de
187 mtk_wed_free_buffer(dev);
188 mtk_wed_free_tx_rings(dev);
190 - if (of_dma_is_coherent(wlan_node))
191 + if (of_dma_is_coherent(wlan_node) && hw->hifsys)
192 regmap_update_bits(hw->hifsys, HIFSYS_DMA_AG_MAP,
193 BIT(hw->index), BIT(hw->index));
195 @@ -308,14 +352,69 @@ mtk_wed_detach(struct mtk_wed_device *de
196 mutex_unlock(&hw_lock);
199 +#define PCIE_BASE_ADDR0 0x11280000
201 +mtk_wed_bus_init(struct mtk_wed_device *dev)
203 + struct device_node *np = dev->hw->eth->dev->of_node;
204 + struct regmap *regs;
207 + regs = syscon_regmap_lookup_by_phandle(np, "mediatek,wed-pcie");
211 + regmap_update_bits(regs, 0, BIT(0), BIT(0));
213 + wed_w32(dev, MTK_WED_PCIE_INT_CTRL,
214 + FIELD_PREP(MTK_WED_PCIE_INT_CTRL_POLL_EN, 2));
216 + /* pcie interrupt control: pola/source selection */
217 + wed_set(dev, MTK_WED_PCIE_INT_CTRL,
218 + MTK_WED_PCIE_INT_CTRL_MSK_EN_POLA |
219 + FIELD_PREP(MTK_WED_PCIE_INT_CTRL_SRC_SEL, 1));
220 + wed_r32(dev, MTK_WED_PCIE_INT_CTRL);
222 + val = wed_r32(dev, MTK_WED_PCIE_CFG_INTM);
223 + val = wed_r32(dev, MTK_WED_PCIE_CFG_BASE);
224 + wed_w32(dev, MTK_WED_PCIE_CFG_INTM, PCIE_BASE_ADDR0 | 0x180);
225 + wed_w32(dev, MTK_WED_PCIE_CFG_BASE, PCIE_BASE_ADDR0 | 0x184);
227 + val = wed_r32(dev, MTK_WED_PCIE_CFG_INTM);
228 + val = wed_r32(dev, MTK_WED_PCIE_CFG_BASE);
230 + /* pcie interrupt status trigger register */
231 + wed_w32(dev, MTK_WED_PCIE_INT_TRIGGER, BIT(24));
232 + wed_r32(dev, MTK_WED_PCIE_INT_TRIGGER);
235 + val = wed_r32(dev, MTK_WED_PCIE_INT_CTRL);
236 + wed_set(dev, MTK_WED_PCIE_INT_CTRL, MTK_WED_PCIE_INT_CTRL_MSK_EN_POLA);
240 +mtk_wed_set_wpdma(struct mtk_wed_device *dev)
242 + if (dev->hw->version == 1) {
243 + wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_phys);
245 + mtk_wed_bus_init(dev);
247 + wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_int);
248 + wed_w32(dev, MTK_WED_WPDMA_CFG_INT_MASK, dev->wlan.wpdma_mask);
249 + wed_w32(dev, MTK_WED_WPDMA_CFG_TX, dev->wlan.wpdma_tx);
250 + wed_w32(dev, MTK_WED_WPDMA_CFG_TX_FREE, dev->wlan.wpdma_txfree);
255 mtk_wed_hw_init_early(struct mtk_wed_device *dev)
261 mtk_wed_reset(dev, MTK_WED_RESET_WED);
262 + mtk_wed_set_wpdma(dev);
264 mask = MTK_WED_WDMA_GLO_CFG_BT_SIZE |
265 MTK_WED_WDMA_GLO_CFG_DYNAMIC_DMAD_RECYCLE |
266 @@ -325,17 +424,33 @@ mtk_wed_hw_init_early(struct mtk_wed_dev
267 MTK_WED_WDMA_GLO_CFG_IDLE_DMAD_SUPPLY;
268 wed_m32(dev, MTK_WED_WDMA_GLO_CFG, mask, set);
270 - wdma_set(dev, MTK_WDMA_GLO_CFG,
271 - MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
272 - MTK_WDMA_GLO_CFG_RX_INFO2_PRERES |
273 - MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
275 - offset = dev->hw->index ? 0x04000400 : 0;
276 - wed_w32(dev, MTK_WED_WDMA_OFFSET0, 0x2a042a20 + offset);
277 - wed_w32(dev, MTK_WED_WDMA_OFFSET1, 0x29002800 + offset);
278 + if (dev->hw->version == 1) {
279 + u32 offset = dev->hw->index ? 0x04000400 : 0;
281 - wed_w32(dev, MTK_WED_PCIE_CFG_BASE, MTK_PCIE_BASE(dev->hw->index));
282 - wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_phys);
283 + wdma_set(dev, MTK_WDMA_GLO_CFG,
284 + MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
285 + MTK_WDMA_GLO_CFG_RX_INFO2_PRERES |
286 + MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
288 + wed_w32(dev, MTK_WED_WDMA_OFFSET0, 0x2a042a20 + offset);
289 + wed_w32(dev, MTK_WED_WDMA_OFFSET1, 0x29002800 + offset);
290 + wed_w32(dev, MTK_WED_PCIE_CFG_BASE,
291 + MTK_PCIE_BASE(dev->hw->index));
293 + wed_w32(dev, MTK_WED_WDMA_CFG_BASE, dev->hw->wdma_phy);
294 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_ETH_DMAD_FMT);
295 + wed_w32(dev, MTK_WED_WDMA_OFFSET0,
296 + FIELD_PREP(MTK_WED_WDMA_OFST0_GLO_INTS,
297 + MTK_WDMA_INT_STATUS) |
298 + FIELD_PREP(MTK_WED_WDMA_OFST0_GLO_CFG,
299 + MTK_WDMA_GLO_CFG));
301 + wed_w32(dev, MTK_WED_WDMA_OFFSET1,
302 + FIELD_PREP(MTK_WED_WDMA_OFST1_TX_CTRL,
303 + MTK_WDMA_RING_TX(0)) |
304 + FIELD_PREP(MTK_WED_WDMA_OFST1_RX_CTRL,
305 + MTK_WDMA_RING_RX(0)));
310 @@ -355,37 +470,65 @@ mtk_wed_hw_init(struct mtk_wed_device *d
312 wed_w32(dev, MTK_WED_TX_BM_BASE, dev->buf_ring.desc_phys);
314 - wed_w32(dev, MTK_WED_TX_BM_TKID,
315 - FIELD_PREP(MTK_WED_TX_BM_TKID_START,
316 - dev->wlan.token_start) |
317 - FIELD_PREP(MTK_WED_TX_BM_TKID_END,
318 - dev->wlan.token_start + dev->wlan.nbuf - 1));
320 wed_w32(dev, MTK_WED_TX_BM_BUF_LEN, MTK_WED_PKT_SIZE);
322 - wed_w32(dev, MTK_WED_TX_BM_DYN_THR,
323 - FIELD_PREP(MTK_WED_TX_BM_DYN_THR_LO, 1) |
324 - MTK_WED_TX_BM_DYN_THR_HI);
325 + if (dev->hw->version == 1) {
326 + wed_w32(dev, MTK_WED_TX_BM_TKID,
327 + FIELD_PREP(MTK_WED_TX_BM_TKID_START,
328 + dev->wlan.token_start) |
329 + FIELD_PREP(MTK_WED_TX_BM_TKID_END,
330 + dev->wlan.token_start +
331 + dev->wlan.nbuf - 1));
332 + wed_w32(dev, MTK_WED_TX_BM_DYN_THR,
333 + FIELD_PREP(MTK_WED_TX_BM_DYN_THR_LO, 1) |
334 + MTK_WED_TX_BM_DYN_THR_HI);
336 + wed_w32(dev, MTK_WED_TX_BM_TKID_V2,
337 + FIELD_PREP(MTK_WED_TX_BM_TKID_START,
338 + dev->wlan.token_start) |
339 + FIELD_PREP(MTK_WED_TX_BM_TKID_END,
340 + dev->wlan.token_start +
341 + dev->wlan.nbuf - 1));
342 + wed_w32(dev, MTK_WED_TX_BM_DYN_THR,
343 + FIELD_PREP(MTK_WED_TX_BM_DYN_THR_LO_V2, 0) |
344 + MTK_WED_TX_BM_DYN_THR_HI_V2);
345 + wed_w32(dev, MTK_WED_TX_TKID_CTRL,
346 + MTK_WED_TX_TKID_CTRL_PAUSE |
347 + FIELD_PREP(MTK_WED_TX_TKID_CTRL_VLD_GRP_NUM,
348 + dev->buf_ring.size / 128) |
349 + FIELD_PREP(MTK_WED_TX_TKID_CTRL_RSV_GRP_NUM,
350 + dev->buf_ring.size / 128));
351 + wed_w32(dev, MTK_WED_TX_TKID_DYN_THR,
352 + FIELD_PREP(MTK_WED_TX_TKID_DYN_THR_LO, 0) |
353 + MTK_WED_TX_TKID_DYN_THR_HI);
356 mtk_wed_reset(dev, MTK_WED_RESET_TX_BM);
358 - wed_set(dev, MTK_WED_CTRL,
359 - MTK_WED_CTRL_WED_TX_BM_EN |
360 - MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
361 + if (dev->hw->version == 1)
362 + wed_set(dev, MTK_WED_CTRL,
363 + MTK_WED_CTRL_WED_TX_BM_EN |
364 + MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
366 + wed_clr(dev, MTK_WED_TX_TKID_CTRL, MTK_WED_TX_TKID_CTRL_PAUSE);
368 wed_clr(dev, MTK_WED_TX_BM_CTRL, MTK_WED_TX_BM_CTRL_PAUSE);
372 -mtk_wed_ring_reset(struct mtk_wdma_desc *desc, int size)
373 +mtk_wed_ring_reset(struct mtk_wed_ring *ring, int size)
375 + void *head = (void *)ring->desc;
378 for (i = 0; i < size; i++) {
380 - desc[i].ctrl = cpu_to_le32(MTK_WDMA_DESC_CTRL_DMA_DONE);
383 + struct mtk_wdma_desc *desc;
385 + desc = (struct mtk_wdma_desc *)(head + i * ring->desc_size);
387 + desc->ctrl = cpu_to_le32(MTK_WDMA_DESC_CTRL_DMA_DONE);
393 @@ -436,12 +579,10 @@ mtk_wed_reset_dma(struct mtk_wed_device
396 for (i = 0; i < ARRAY_SIZE(dev->tx_ring); i++) {
397 - struct mtk_wdma_desc *desc = dev->tx_ring[i].desc;
400 + if (!dev->tx_ring[i].desc)
403 - mtk_wed_ring_reset(desc, MTK_WED_TX_RING_SIZE);
404 + mtk_wed_ring_reset(&dev->tx_ring[i], MTK_WED_TX_RING_SIZE);
407 if (mtk_wed_poll_busy(dev))
408 @@ -498,16 +639,16 @@ mtk_wed_reset_dma(struct mtk_wed_device
411 mtk_wed_ring_alloc(struct mtk_wed_device *dev, struct mtk_wed_ring *ring,
413 + int size, u32 desc_size)
415 - ring->desc = dma_alloc_coherent(dev->hw->dev,
416 - size * sizeof(*ring->desc),
417 + ring->desc = dma_alloc_coherent(dev->hw->dev, size * desc_size,
418 &ring->desc_phys, GFP_KERNEL);
422 + ring->desc_size = desc_size;
424 - mtk_wed_ring_reset(ring->desc, size);
425 + mtk_wed_ring_reset(ring, size);
429 @@ -515,9 +656,10 @@ mtk_wed_ring_alloc(struct mtk_wed_device
431 mtk_wed_wdma_ring_setup(struct mtk_wed_device *dev, int idx, int size)
433 + u32 desc_size = sizeof(struct mtk_wdma_desc) * dev->hw->version;
434 struct mtk_wed_ring *wdma = &dev->tx_wdma[idx];
436 - if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE))
437 + if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, desc_size))
440 wdma_w32(dev, MTK_WDMA_RING_RX(idx) + MTK_WED_RING_OFS_BASE,
441 @@ -546,16 +688,41 @@ mtk_wed_configure_irq(struct mtk_wed_dev
442 MTK_WED_CTRL_WED_TX_BM_EN |
443 MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
445 - wed_w32(dev, MTK_WED_PCIE_INT_TRIGGER,
446 - MTK_WED_PCIE_INT_TRIGGER_STATUS);
447 + if (dev->hw->version == 1) {
448 + wed_w32(dev, MTK_WED_PCIE_INT_TRIGGER,
449 + MTK_WED_PCIE_INT_TRIGGER_STATUS);
451 + wed_w32(dev, MTK_WED_WPDMA_INT_TRIGGER,
452 + MTK_WED_WPDMA_INT_TRIGGER_RX_DONE |
453 + MTK_WED_WPDMA_INT_TRIGGER_TX_DONE);
455 - wed_w32(dev, MTK_WED_WPDMA_INT_TRIGGER,
456 - MTK_WED_WPDMA_INT_TRIGGER_RX_DONE |
457 - MTK_WED_WPDMA_INT_TRIGGER_TX_DONE);
458 + wed_clr(dev, MTK_WED_WDMA_INT_CTRL, wdma_mask);
460 + /* initail tx interrupt trigger */
461 + wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_TX,
462 + MTK_WED_WPDMA_INT_CTRL_TX0_DONE_EN |
463 + MTK_WED_WPDMA_INT_CTRL_TX0_DONE_CLR |
464 + MTK_WED_WPDMA_INT_CTRL_TX1_DONE_EN |
465 + MTK_WED_WPDMA_INT_CTRL_TX1_DONE_CLR |
466 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_TX0_DONE_TRIG,
467 + dev->wlan.tx_tbit[0]) |
468 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_TX1_DONE_TRIG,
469 + dev->wlan.tx_tbit[1]));
471 + /* initail txfree interrupt trigger */
472 + wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_TX_FREE,
473 + MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_EN |
474 + MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_CLR |
475 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_TRIG,
476 + dev->wlan.txfree_tbit));
478 + wed_w32(dev, MTK_WED_WDMA_INT_CLR, wdma_mask);
479 + wed_set(dev, MTK_WED_WDMA_INT_CTRL,
480 + FIELD_PREP(MTK_WED_WDMA_INT_CTRL_POLL_SRC_SEL,
484 - /* initail wdma interrupt agent */
485 wed_w32(dev, MTK_WED_WDMA_INT_TRIGGER, wdma_mask);
486 - wed_clr(dev, MTK_WED_WDMA_INT_CTRL, wdma_mask);
488 wdma_w32(dev, MTK_WDMA_INT_MASK, wdma_mask);
489 wdma_w32(dev, MTK_WDMA_INT_GRP2, wdma_mask);
490 @@ -580,14 +747,28 @@ mtk_wed_dma_enable(struct mtk_wed_device
491 wdma_set(dev, MTK_WDMA_GLO_CFG,
492 MTK_WDMA_GLO_CFG_TX_DMA_EN |
493 MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
494 - MTK_WDMA_GLO_CFG_RX_INFO2_PRERES |
495 - MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
496 + MTK_WDMA_GLO_CFG_RX_INFO2_PRERES);
498 + if (dev->hw->version == 1) {
499 + wdma_set(dev, MTK_WDMA_GLO_CFG,
500 + MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
502 + wed_set(dev, MTK_WED_WPDMA_CTRL,
503 + MTK_WED_WPDMA_CTRL_SDL1_FIXED);
505 + wed_set(dev, MTK_WED_WPDMA_GLO_CFG,
506 + MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_PKT_PROC |
507 + MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_CRX_SYNC);
509 + wed_clr(dev, MTK_WED_WPDMA_GLO_CFG,
510 + MTK_WED_WPDMA_GLO_CFG_TX_TKID_KEEP |
511 + MTK_WED_WPDMA_GLO_CFG_TX_DMAD_DW3_PREV);
516 mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)
521 for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++)
522 @@ -598,14 +779,17 @@ mtk_wed_start(struct mtk_wed_device *dev
523 mtk_wed_configure_irq(dev, irq_mask);
525 mtk_wed_set_ext_int(dev, true);
526 - val = dev->wlan.wpdma_phys |
527 - MTK_PCIE_MIRROR_MAP_EN |
528 - FIELD_PREP(MTK_PCIE_MIRROR_MAP_WED_ID, dev->hw->index);
530 - if (dev->hw->index)
533 - regmap_write(dev->hw->mirror, dev->hw->index * 4, val);
535 + if (dev->hw->version == 1) {
536 + u32 val = dev->wlan.wpdma_phys | MTK_PCIE_MIRROR_MAP_EN |
537 + FIELD_PREP(MTK_PCIE_MIRROR_MAP_WED_ID,
540 + val |= BIT(0) | (BIT(1) * !!dev->hw->index);
541 + regmap_write(dev->hw->mirror, dev->hw->index * 4, val);
543 + mtk_wed_set_512_support(dev, true);
546 mtk_wed_dma_enable(dev);
548 @@ -639,7 +823,9 @@ mtk_wed_attach(struct mtk_wed_device *de
552 - dev_info(&dev->wlan.pci_dev->dev, "attaching wed device %d\n", hw->index);
553 + dev_info(&dev->wlan.pci_dev->dev,
554 + "attaching wed device %d version %d\n",
555 + hw->index, hw->version);
559 @@ -657,7 +843,9 @@ mtk_wed_attach(struct mtk_wed_device *de
562 mtk_wed_hw_init_early(dev);
563 - regmap_update_bits(hw->hifsys, HIFSYS_DMA_AG_MAP, BIT(hw->index), 0);
565 + regmap_update_bits(hw->hifsys, HIFSYS_DMA_AG_MAP,
566 + BIT(hw->index), 0);
569 mutex_unlock(&hw_lock);
570 @@ -684,7 +872,8 @@ mtk_wed_tx_ring_setup(struct mtk_wed_dev
572 BUG_ON(idx >= ARRAY_SIZE(dev->tx_ring));
574 - if (mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE))
575 + if (mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE,
576 + sizeof(*ring->desc)))
579 if (mtk_wed_wdma_ring_setup(dev, idx, MTK_WED_WDMA_RING_SIZE))
580 @@ -711,21 +900,21 @@ static int
581 mtk_wed_txfree_ring_setup(struct mtk_wed_device *dev, void __iomem *regs)
583 struct mtk_wed_ring *ring = &dev->txfree_ring;
585 + int i, index = dev->hw->version == 1;
588 * For txfree event handling, the same DMA ring is shared between WED
589 * and WLAN. The WLAN driver accesses the ring index registers through
592 - ring->reg_base = MTK_WED_RING_RX(1);
593 + ring->reg_base = MTK_WED_RING_RX(index);
596 for (i = 0; i < 12; i += 4) {
597 u32 val = readl(regs + i);
599 - wed_w32(dev, MTK_WED_RING_RX(1) + i, val);
600 - wed_w32(dev, MTK_WED_WPDMA_RING_RX(1) + i, val);
601 + wed_w32(dev, MTK_WED_RING_RX(index) + i, val);
602 + wed_w32(dev, MTK_WED_WPDMA_RING_RX(index) + i, val);
606 @@ -734,11 +923,19 @@ mtk_wed_txfree_ring_setup(struct mtk_wed
608 mtk_wed_irq_get(struct mtk_wed_device *dev, u32 mask)
611 + u32 val, ext_mask = MTK_WED_EXT_INT_STATUS_ERROR_MASK;
613 + if (dev->hw->version == 1)
614 + ext_mask |= MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR;
616 + ext_mask |= MTK_WED_EXT_INT_STATUS_RX_FBUF_LO_TH |
617 + MTK_WED_EXT_INT_STATUS_RX_FBUF_HI_TH |
618 + MTK_WED_EXT_INT_STATUS_RX_DRV_COHERENT |
619 + MTK_WED_EXT_INT_STATUS_TX_DMA_W_RESP_ERR;
621 val = wed_r32(dev, MTK_WED_EXT_INT_STATUS);
622 wed_w32(dev, MTK_WED_EXT_INT_STATUS, val);
623 - val &= MTK_WED_EXT_INT_STATUS_ERROR_MASK;
625 if (!dev->hw->num_flows)
626 val &= ~MTK_WED_EXT_INT_STATUS_TKID_WO_PYLD;
627 if (val && net_ratelimit())
628 @@ -813,7 +1010,8 @@ out:
631 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
632 - void __iomem *wdma, int index)
633 + void __iomem *wdma, phys_addr_t wdma_phy,
636 static const struct mtk_wed_ops wed_ops = {
637 .attach = mtk_wed_attach,
638 @@ -860,26 +1058,33 @@ void mtk_wed_add_hw(struct device_node *
639 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
646 hw->dev = &pdev->dev;
647 + hw->wdma_phy = wdma_phy;
651 - hw->mirror = syscon_regmap_lookup_by_phandle(eth_np,
652 - "mediatek,pcie-mirror");
653 - hw->hifsys = syscon_regmap_lookup_by_phandle(eth_np,
654 - "mediatek,hifsys");
655 - if (IS_ERR(hw->mirror) || IS_ERR(hw->hifsys)) {
659 + hw->version = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
662 - regmap_write(hw->mirror, 0, 0);
663 - regmap_write(hw->mirror, 4, 0);
664 + if (hw->version == 1) {
665 + hw->mirror = syscon_regmap_lookup_by_phandle(eth_np,
666 + "mediatek,pcie-mirror");
667 + hw->hifsys = syscon_regmap_lookup_by_phandle(eth_np,
668 + "mediatek,hifsys");
669 + if (IS_ERR(hw->mirror) || IS_ERR(hw->hifsys)) {
675 + regmap_write(hw->mirror, 0, 0);
676 + regmap_write(hw->mirror, 4, 0);
680 mtk_wed_hw_add_debugfs(hw);
683 --- a/drivers/net/ethernet/mediatek/mtk_wed.h
684 +++ b/drivers/net/ethernet/mediatek/mtk_wed.h
685 @@ -18,11 +18,13 @@ struct mtk_wed_hw {
686 struct regmap *hifsys;
689 + phys_addr_t wdma_phy;
690 struct regmap *mirror;
691 struct dentry *debugfs_dir;
692 struct mtk_wed_device *wed_dev;
699 @@ -101,14 +103,16 @@ wpdma_txfree_w32(struct mtk_wed_device *
702 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
703 - void __iomem *wdma, int index);
704 + void __iomem *wdma, phys_addr_t wdma_phy,
706 void mtk_wed_exit(void);
707 int mtk_wed_flow_add(int index);
708 void mtk_wed_flow_remove(int index);
711 mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
712 - void __iomem *wdma, int index)
713 + void __iomem *wdma, phys_addr_t wdma_phy,
718 --- a/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
719 +++ b/drivers/net/ethernet/mediatek/mtk_wed_debugfs.c
720 @@ -116,6 +116,9 @@ wed_txinfo_show(struct seq_file *s, void
721 DUMP_WDMA(WDMA_GLO_CFG),
722 DUMP_WDMA_RING(WDMA_RING_RX(0)),
723 DUMP_WDMA_RING(WDMA_RING_RX(1)),
725 + DUMP_STR("TX FREE"),
726 + DUMP_WED(WED_RX_MIB(0)),
728 struct mtk_wed_hw *hw = s->private;
729 struct mtk_wed_device *dev = hw->wed_dev;
730 --- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
731 +++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
733 #define __MTK_WED_REGS_H
735 #define MTK_WDMA_DESC_CTRL_LEN1 GENMASK(14, 0)
736 +#define MTK_WDMA_DESC_CTRL_LEN1_V2 GENMASK(13, 0)
737 #define MTK_WDMA_DESC_CTRL_LAST_SEG1 BIT(15)
738 #define MTK_WDMA_DESC_CTRL_BURST BIT(16)
739 #define MTK_WDMA_DESC_CTRL_LEN0 GENMASK(29, 16)
740 @@ -41,6 +42,7 @@ struct mtk_wdma_desc {
741 #define MTK_WED_CTRL_RESERVE_EN BIT(12)
742 #define MTK_WED_CTRL_RESERVE_BUSY BIT(13)
743 #define MTK_WED_CTRL_FINAL_DIDX_READ BIT(24)
744 +#define MTK_WED_CTRL_ETH_DMAD_FMT BIT(25)
745 #define MTK_WED_CTRL_MIB_READ_CLEAR BIT(28)
747 #define MTK_WED_EXT_INT_STATUS 0x020
748 @@ -57,7 +59,8 @@ struct mtk_wdma_desc {
749 #define MTK_WED_EXT_INT_STATUS_RX_DRV_INIT_WDMA_EN BIT(19)
750 #define MTK_WED_EXT_INT_STATUS_RX_DRV_BM_DMAD_COHERENT BIT(20)
751 #define MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR BIT(21)
752 -#define MTK_WED_EXT_INT_STATUS_TX_DRV_W_RESP_ERR BIT(22)
753 +#define MTK_WED_EXT_INT_STATUS_TX_DMA_R_RESP_ERR BIT(22)
754 +#define MTK_WED_EXT_INT_STATUS_TX_DMA_W_RESP_ERR BIT(23)
755 #define MTK_WED_EXT_INT_STATUS_RX_DRV_DMA_RECYCLE BIT(24)
756 #define MTK_WED_EXT_INT_STATUS_ERROR_MASK (MTK_WED_EXT_INT_STATUS_TF_LEN_ERR | \
757 MTK_WED_EXT_INT_STATUS_TKID_WO_PYLD | \
758 @@ -65,8 +68,7 @@ struct mtk_wdma_desc {
759 MTK_WED_EXT_INT_STATUS_RX_DRV_R_RESP_ERR | \
760 MTK_WED_EXT_INT_STATUS_RX_DRV_W_RESP_ERR | \
761 MTK_WED_EXT_INT_STATUS_RX_DRV_INIT_WDMA_EN | \
762 - MTK_WED_EXT_INT_STATUS_TX_DRV_R_RESP_ERR | \
763 - MTK_WED_EXT_INT_STATUS_TX_DRV_W_RESP_ERR)
764 + MTK_WED_EXT_INT_STATUS_TX_DMA_R_RESP_ERR)
766 #define MTK_WED_EXT_INT_MASK 0x028
768 @@ -81,6 +83,7 @@ struct mtk_wdma_desc {
769 #define MTK_WED_TX_BM_BASE 0x084
771 #define MTK_WED_TX_BM_TKID 0x088
772 +#define MTK_WED_TX_BM_TKID_V2 0x0c8
773 #define MTK_WED_TX_BM_TKID_START GENMASK(15, 0)
774 #define MTK_WED_TX_BM_TKID_END GENMASK(31, 16)
776 @@ -94,7 +97,25 @@ struct mtk_wdma_desc {
778 #define MTK_WED_TX_BM_DYN_THR 0x0a0
779 #define MTK_WED_TX_BM_DYN_THR_LO GENMASK(6, 0)
780 +#define MTK_WED_TX_BM_DYN_THR_LO_V2 GENMASK(8, 0)
781 #define MTK_WED_TX_BM_DYN_THR_HI GENMASK(22, 16)
782 +#define MTK_WED_TX_BM_DYN_THR_HI_V2 GENMASK(24, 16)
784 +#define MTK_WED_TX_TKID_CTRL 0x0c0
785 +#define MTK_WED_TX_TKID_CTRL_VLD_GRP_NUM GENMASK(6, 0)
786 +#define MTK_WED_TX_TKID_CTRL_RSV_GRP_NUM GENMASK(22, 16)
787 +#define MTK_WED_TX_TKID_CTRL_PAUSE BIT(28)
789 +#define MTK_WED_TX_TKID_DYN_THR 0x0e0
790 +#define MTK_WED_TX_TKID_DYN_THR_LO GENMASK(6, 0)
791 +#define MTK_WED_TX_TKID_DYN_THR_HI GENMASK(22, 16)
793 +#define MTK_WED_TXP_DW0 0x120
794 +#define MTK_WED_TXP_DW1 0x124
795 +#define MTK_WED_WPDMA_WRITE_TXP GENMASK(31, 16)
796 +#define MTK_WED_TXDP_CTRL 0x130
797 +#define MTK_WED_TXDP_DW9_OVERWR BIT(9)
798 +#define MTK_WED_RX_BM_TKID_MIB 0x1cc
800 #define MTK_WED_INT_STATUS 0x200
801 #define MTK_WED_INT_MASK 0x204
802 @@ -125,6 +146,7 @@ struct mtk_wdma_desc {
803 #define MTK_WED_RESET_IDX_RX GENMASK(17, 16)
805 #define MTK_WED_TX_MIB(_n) (0x2a0 + (_n) * 4)
806 +#define MTK_WED_RX_MIB(_n) (0x2e0 + (_n) * 4)
808 #define MTK_WED_RING_TX(_n) (0x300 + (_n) * 0x10)
810 @@ -155,21 +177,62 @@ struct mtk_wdma_desc {
811 #define MTK_WED_WPDMA_GLO_CFG_BYTE_SWAP BIT(29)
812 #define MTK_WED_WPDMA_GLO_CFG_RX_2B_OFFSET BIT(31)
814 +/* CONFIG_MEDIATEK_NETSYS_V2 */
815 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_PKT_PROC BIT(4)
816 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_R1_PKT_PROC BIT(5)
817 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_CRX_SYNC BIT(6)
818 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_R1_CRX_SYNC BIT(7)
819 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_EVENT_PKT_FMT_VER GENMASK(18, 16)
820 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_UNSUPPORT_FMT BIT(19)
821 +#define MTK_WED_WPDMA_GLO_CFG_RX_DRV_UEVENT_PKT_FMT_CHK BIT(20)
822 +#define MTK_WED_WPDMA_GLO_CFG_RX_DDONE2_WR BIT(21)
823 +#define MTK_WED_WPDMA_GLO_CFG_TX_TKID_KEEP BIT(24)
824 +#define MTK_WED_WPDMA_GLO_CFG_TX_DMAD_DW3_PREV BIT(28)
826 #define MTK_WED_WPDMA_RESET_IDX 0x50c
827 #define MTK_WED_WPDMA_RESET_IDX_TX GENMASK(3, 0)
828 #define MTK_WED_WPDMA_RESET_IDX_RX GENMASK(17, 16)
830 +#define MTK_WED_WPDMA_CTRL 0x518
831 +#define MTK_WED_WPDMA_CTRL_SDL1_FIXED BIT(31)
833 #define MTK_WED_WPDMA_INT_CTRL 0x520
834 #define MTK_WED_WPDMA_INT_CTRL_SUBRT_ADV BIT(21)
836 #define MTK_WED_WPDMA_INT_MASK 0x524
838 +#define MTK_WED_WPDMA_INT_CTRL_TX 0x530
839 +#define MTK_WED_WPDMA_INT_CTRL_TX0_DONE_EN BIT(0)
840 +#define MTK_WED_WPDMA_INT_CTRL_TX0_DONE_CLR BIT(1)
841 +#define MTK_WED_WPDMA_INT_CTRL_TX0_DONE_TRIG GENMASK(6, 2)
842 +#define MTK_WED_WPDMA_INT_CTRL_TX1_DONE_EN BIT(8)
843 +#define MTK_WED_WPDMA_INT_CTRL_TX1_DONE_CLR BIT(9)
844 +#define MTK_WED_WPDMA_INT_CTRL_TX1_DONE_TRIG GENMASK(14, 10)
846 +#define MTK_WED_WPDMA_INT_CTRL_RX 0x534
848 +#define MTK_WED_WPDMA_INT_CTRL_TX_FREE 0x538
849 +#define MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_EN BIT(0)
850 +#define MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_CLR BIT(1)
851 +#define MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_TRIG GENMASK(6, 2)
853 #define MTK_WED_PCIE_CFG_BASE 0x560
855 +#define MTK_WED_PCIE_CFG_BASE 0x560
856 +#define MTK_WED_PCIE_CFG_INTM 0x564
857 +#define MTK_WED_PCIE_CFG_MSIS 0x568
858 #define MTK_WED_PCIE_INT_TRIGGER 0x570
859 #define MTK_WED_PCIE_INT_TRIGGER_STATUS BIT(16)
861 +#define MTK_WED_PCIE_INT_CTRL 0x57c
862 +#define MTK_WED_PCIE_INT_CTRL_MSK_EN_POLA BIT(20)
863 +#define MTK_WED_PCIE_INT_CTRL_SRC_SEL GENMASK(17, 16)
864 +#define MTK_WED_PCIE_INT_CTRL_POLL_EN GENMASK(13, 12)
866 #define MTK_WED_WPDMA_CFG_BASE 0x580
867 +#define MTK_WED_WPDMA_CFG_INT_MASK 0x584
868 +#define MTK_WED_WPDMA_CFG_TX 0x588
869 +#define MTK_WED_WPDMA_CFG_TX_FREE 0x58c
871 #define MTK_WED_WPDMA_TX_MIB(_n) (0x5a0 + (_n) * 4)
872 #define MTK_WED_WPDMA_TX_COHERENT_MIB(_n) (0x5d0 + (_n) * 4)
873 @@ -203,15 +266,24 @@ struct mtk_wdma_desc {
874 #define MTK_WED_WDMA_RESET_IDX_RX GENMASK(17, 16)
875 #define MTK_WED_WDMA_RESET_IDX_DRV GENMASK(25, 24)
877 +#define MTK_WED_WDMA_INT_CLR 0xa24
878 +#define MTK_WED_WDMA_INT_CLR_RX_DONE GENMASK(17, 16)
880 #define MTK_WED_WDMA_INT_TRIGGER 0xa28
881 #define MTK_WED_WDMA_INT_TRIGGER_RX_DONE GENMASK(17, 16)
883 #define MTK_WED_WDMA_INT_CTRL 0xa2c
884 #define MTK_WED_WDMA_INT_CTRL_POLL_SRC_SEL GENMASK(17, 16)
886 +#define MTK_WED_WDMA_CFG_BASE 0xaa0
887 #define MTK_WED_WDMA_OFFSET0 0xaa4
888 #define MTK_WED_WDMA_OFFSET1 0xaa8
890 +#define MTK_WED_WDMA_OFST0_GLO_INTS GENMASK(15, 0)
891 +#define MTK_WED_WDMA_OFST0_GLO_CFG GENMASK(31, 16)
892 +#define MTK_WED_WDMA_OFST1_TX_CTRL GENMASK(15, 0)
893 +#define MTK_WED_WDMA_OFST1_RX_CTRL GENMASK(31, 16)
895 #define MTK_WED_WDMA_RX_MIB(_n) (0xae0 + (_n) * 4)
896 #define MTK_WED_WDMA_RX_RECYCLE_MIB(_n) (0xae8 + (_n) * 4)
897 #define MTK_WED_WDMA_RX_PROCESSED_MIB(_n) (0xaf0 + (_n) * 4)
898 @@ -221,6 +293,7 @@ struct mtk_wdma_desc {
899 #define MTK_WED_RING_OFS_CPU_IDX 0x08
900 #define MTK_WED_RING_OFS_DMA_IDX 0x0c
902 +#define MTK_WDMA_RING_TX(_n) (0x000 + (_n) * 0x10)
903 #define MTK_WDMA_RING_RX(_n) (0x100 + (_n) * 0x10)
905 #define MTK_WDMA_GLO_CFG 0x204
906 @@ -234,6 +307,8 @@ struct mtk_wdma_desc {
907 #define MTK_WDMA_RESET_IDX_TX GENMASK(3, 0)
908 #define MTK_WDMA_RESET_IDX_RX GENMASK(17, 16)
910 +#define MTK_WDMA_INT_STATUS 0x220
912 #define MTK_WDMA_INT_MASK 0x228
913 #define MTK_WDMA_INT_MASK_TX_DONE GENMASK(3, 0)
914 #define MTK_WDMA_INT_MASK_RX_DONE GENMASK(17, 16)
915 --- a/include/linux/soc/mediatek/mtk_wed.h
916 +++ b/include/linux/soc/mediatek/mtk_wed.h
917 @@ -14,6 +14,7 @@ struct mtk_wdma_desc;
918 struct mtk_wed_ring {
919 struct mtk_wdma_desc *desc;
920 dma_addr_t desc_phys;
925 @@ -45,10 +46,17 @@ struct mtk_wed_device {
926 struct pci_dev *pci_dev;
937 + u8 tx_tbit[MTK_WED_TX_QUEUES];
940 u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id);
941 int (*offload_enable)(struct mtk_wed_device *wed);
942 void (*offload_disable)(struct mtk_wed_device *wed);