1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Sat, 5 Nov 2022 23:36:21 +0100
3 Subject: [PATCH] net: ethernet: mtk_wed: add configure wed wo support
5 Enable RX Wireless Ethernet Dispatch available on MT7986 Soc.
7 Tested-by: Daniel Golle <daniel@makrotopia.org>
8 Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
9 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
10 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
14 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
15 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
17 #include <linux/skbuff.h>
18 #include <linux/of_platform.h>
19 #include <linux/of_address.h>
20 +#include <linux/of_reserved_mem.h>
21 #include <linux/mfd/syscon.h>
22 #include <linux/debugfs.h>
23 #include <linux/soc/mediatek/mtk_wed.h>
25 #define MTK_WED_PKT_SIZE 1900
26 #define MTK_WED_BUF_SIZE 2048
27 #define MTK_WED_BUF_PER_PAGE (PAGE_SIZE / 2048)
28 +#define MTK_WED_RX_RING_SIZE 1536
30 #define MTK_WED_TX_RING_SIZE 2048
31 #define MTK_WED_WDMA_RING_SIZE 1024
33 #define MTK_WED_PER_GROUP_PKT 128
35 #define MTK_WED_FBUF_SIZE 128
36 +#define MTK_WED_MIOD_CNT 16
37 +#define MTK_WED_FB_CMD_CNT 1024
38 +#define MTK_WED_RRO_QUE_CNT 8192
39 +#define MTK_WED_MIOD_ENTRY_CNT 128
41 static struct mtk_wed_hw *hw_list[2];
42 static DEFINE_MUTEX(hw_lock);
43 @@ -65,12 +71,76 @@ wdma_set(struct mtk_wed_device *dev, u32
44 wdma_m32(dev, reg, 0, mask);
48 +wdma_clr(struct mtk_wed_device *dev, u32 reg, u32 mask)
50 + wdma_m32(dev, reg, mask, 0);
54 +wifi_r32(struct mtk_wed_device *dev, u32 reg)
56 + return readl(dev->wlan.base + reg);
60 +wifi_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
62 + writel(val, dev->wlan.base + reg);
66 mtk_wed_read_reset(struct mtk_wed_device *dev)
68 return wed_r32(dev, MTK_WED_RESET);
72 +mtk_wdma_read_reset(struct mtk_wed_device *dev)
74 + return wdma_r32(dev, MTK_WDMA_GLO_CFG);
78 +mtk_wdma_rx_reset(struct mtk_wed_device *dev)
80 + u32 status, mask = MTK_WDMA_GLO_CFG_RX_DMA_BUSY;
83 + wdma_clr(dev, MTK_WDMA_GLO_CFG, MTK_WDMA_GLO_CFG_RX_DMA_EN);
84 + if (readx_poll_timeout(mtk_wdma_read_reset, dev, status,
85 + !(status & mask), 0, 1000))
86 + dev_err(dev->hw->dev, "rx reset failed\n");
88 + for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) {
89 + if (dev->rx_wdma[i].desc)
93 + MTK_WDMA_RING_RX(i) + MTK_WED_RING_OFS_CPU_IDX, 0);
98 +mtk_wdma_tx_reset(struct mtk_wed_device *dev)
100 + u32 status, mask = MTK_WDMA_GLO_CFG_TX_DMA_BUSY;
103 + wdma_clr(dev, MTK_WDMA_GLO_CFG, MTK_WDMA_GLO_CFG_TX_DMA_EN);
104 + if (readx_poll_timeout(mtk_wdma_read_reset, dev, status,
105 + !(status & mask), 0, 1000))
106 + dev_err(dev->hw->dev, "tx reset failed\n");
108 + for (i = 0; i < ARRAY_SIZE(dev->tx_wdma); i++) {
109 + if (dev->tx_wdma[i].desc)
113 + MTK_WDMA_RING_TX(i) + MTK_WED_RING_OFS_CPU_IDX, 0);
118 mtk_wed_reset(struct mtk_wed_device *dev, u32 mask)
120 @@ -82,6 +152,54 @@ mtk_wed_reset(struct mtk_wed_device *dev
125 +mtk_wed_wo_read_status(struct mtk_wed_device *dev)
127 + return wed_r32(dev, MTK_WED_SCR0 + 4 * MTK_WED_DUMMY_CR_WO_STATUS);
131 +mtk_wed_wo_reset(struct mtk_wed_device *dev)
133 + struct mtk_wed_wo *wo = dev->hw->wed_wo;
134 + u8 state = MTK_WED_WO_STATE_DISABLE;
138 + mtk_wdma_tx_reset(dev);
139 + mtk_wed_reset(dev, MTK_WED_RESET_WED);
141 + mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
142 + MTK_WED_WO_CMD_CHANGE_STATE, &state,
143 + sizeof(state), false);
145 + if (readx_poll_timeout(mtk_wed_wo_read_status, dev, val,
146 + val == MTK_WED_WOIF_DISABLE_DONE,
147 + 100, MTK_WOCPU_TIMEOUT))
148 + dev_err(dev->hw->dev, "failed to disable wed-wo\n");
150 + reg = ioremap(MTK_WED_WO_CPU_MCUSYS_RESET_ADDR, 4);
153 + switch (dev->hw->index) {
155 + val |= MTK_WED_WO_CPU_WO0_MCUSYS_RESET_MASK;
157 + val &= ~MTK_WED_WO_CPU_WO0_MCUSYS_RESET_MASK;
161 + val |= MTK_WED_WO_CPU_WO1_MCUSYS_RESET_MASK;
163 + val &= ~MTK_WED_WO_CPU_WO1_MCUSYS_RESET_MASK;
172 static struct mtk_wed_hw *
173 mtk_wed_assign(struct mtk_wed_device *dev)
175 @@ -116,7 +234,7 @@ out:
179 -mtk_wed_buffer_alloc(struct mtk_wed_device *dev)
180 +mtk_wed_tx_buffer_alloc(struct mtk_wed_device *dev)
182 struct mtk_wdma_desc *desc;
183 dma_addr_t desc_phys;
184 @@ -133,16 +251,16 @@ mtk_wed_buffer_alloc(struct mtk_wed_devi
188 - dev->buf_ring.size = ring_size;
189 - dev->buf_ring.pages = page_list;
190 + dev->tx_buf_ring.size = ring_size;
191 + dev->tx_buf_ring.pages = page_list;
193 desc = dma_alloc_coherent(dev->hw->dev, ring_size * sizeof(*desc),
194 &desc_phys, GFP_KERNEL);
198 - dev->buf_ring.desc = desc;
199 - dev->buf_ring.desc_phys = desc_phys;
200 + dev->tx_buf_ring.desc = desc;
201 + dev->tx_buf_ring.desc_phys = desc_phys;
203 for (i = 0, page_idx = 0; i < ring_size; i += MTK_WED_BUF_PER_PAGE) {
204 dma_addr_t page_phys, buf_phys;
205 @@ -203,10 +321,10 @@ mtk_wed_buffer_alloc(struct mtk_wed_devi
209 -mtk_wed_free_buffer(struct mtk_wed_device *dev)
210 +mtk_wed_free_tx_buffer(struct mtk_wed_device *dev)
212 - struct mtk_wdma_desc *desc = dev->buf_ring.desc;
213 - void **page_list = dev->buf_ring.pages;
214 + struct mtk_wdma_desc *desc = dev->tx_buf_ring.desc;
215 + void **page_list = dev->tx_buf_ring.pages;
219 @@ -216,7 +334,8 @@ mtk_wed_free_buffer(struct mtk_wed_devic
223 - for (i = 0, page_idx = 0; i < dev->buf_ring.size; i += MTK_WED_BUF_PER_PAGE) {
224 + for (i = 0, page_idx = 0; i < dev->tx_buf_ring.size;
225 + i += MTK_WED_BUF_PER_PAGE) {
226 void *page = page_list[page_idx++];
229 @@ -229,13 +348,59 @@ mtk_wed_free_buffer(struct mtk_wed_devic
233 - dma_free_coherent(dev->hw->dev, dev->buf_ring.size * sizeof(*desc),
234 - desc, dev->buf_ring.desc_phys);
235 + dma_free_coherent(dev->hw->dev, dev->tx_buf_ring.size * sizeof(*desc),
236 + desc, dev->tx_buf_ring.desc_phys);
243 +mtk_wed_rx_buffer_alloc(struct mtk_wed_device *dev)
245 + struct mtk_rxbm_desc *desc;
246 + dma_addr_t desc_phys;
248 + dev->rx_buf_ring.size = dev->wlan.rx_nbuf;
249 + desc = dma_alloc_coherent(dev->hw->dev,
250 + dev->wlan.rx_nbuf * sizeof(*desc),
251 + &desc_phys, GFP_KERNEL);
255 + dev->rx_buf_ring.desc = desc;
256 + dev->rx_buf_ring.desc_phys = desc_phys;
257 + dev->wlan.init_rx_buf(dev, dev->wlan.rx_npkt);
263 +mtk_wed_free_rx_buffer(struct mtk_wed_device *dev)
265 + struct mtk_rxbm_desc *desc = dev->rx_buf_ring.desc;
270 + dev->wlan.release_rx_buf(dev);
271 + dma_free_coherent(dev->hw->dev, dev->rx_buf_ring.size * sizeof(*desc),
272 + desc, dev->rx_buf_ring.desc_phys);
276 +mtk_wed_rx_buffer_hw_init(struct mtk_wed_device *dev)
278 + wed_w32(dev, MTK_WED_RX_BM_RX_DMAD,
279 + FIELD_PREP(MTK_WED_RX_BM_RX_DMAD_SDL0, dev->wlan.rx_size));
280 + wed_w32(dev, MTK_WED_RX_BM_BASE, dev->rx_buf_ring.desc_phys);
281 + wed_w32(dev, MTK_WED_RX_BM_INIT_PTR, MTK_WED_RX_BM_INIT_SW_TAIL |
282 + FIELD_PREP(MTK_WED_RX_BM_SW_TAIL, dev->wlan.rx_npkt));
283 + wed_w32(dev, MTK_WED_RX_BM_DYN_ALLOC_TH,
284 + FIELD_PREP(MTK_WED_RX_BM_DYN_ALLOC_TH_H, 0xffff));
285 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_WED_RX_BM_EN);
289 mtk_wed_free_ring(struct mtk_wed_device *dev, struct mtk_wed_ring *ring)
291 @@ -247,6 +412,13 @@ mtk_wed_free_ring(struct mtk_wed_device
295 +mtk_wed_free_rx_rings(struct mtk_wed_device *dev)
297 + mtk_wed_free_rx_buffer(dev);
298 + mtk_wed_free_ring(dev, &dev->rro.ring);
302 mtk_wed_free_tx_rings(struct mtk_wed_device *dev)
305 @@ -291,6 +463,38 @@ mtk_wed_set_512_support(struct mtk_wed_d
309 +#define MTK_WFMDA_RX_DMA_EN BIT(2)
311 +mtk_wed_check_wfdma_rx_fill(struct mtk_wed_device *dev, int idx)
316 + if (!(dev->rx_ring[idx].flags & MTK_WED_RING_CONFIGURED))
317 + return; /* queue is not configured by mt76 */
319 + for (i = 0; i < 3; i++) {
322 + cur_idx = wed_r32(dev,
323 + MTK_WED_WPDMA_RING_RX_DATA(idx) +
324 + MTK_WED_RING_OFS_CPU_IDX);
325 + if (cur_idx == MTK_WED_RX_RING_SIZE - 1)
328 + usleep_range(100000, 200000);
332 + dev_err(dev->hw->dev, "rx dma enable failed\n");
336 + val = wifi_r32(dev, dev->wlan.wpdma_rx_glo - dev->wlan.phy_base) |
337 + MTK_WFMDA_RX_DMA_EN;
338 + wifi_w32(dev, dev->wlan.wpdma_rx_glo - dev->wlan.phy_base, val);
342 mtk_wed_dma_disable(struct mtk_wed_device *dev)
344 @@ -304,20 +508,25 @@ mtk_wed_dma_disable(struct mtk_wed_devic
345 MTK_WED_GLO_CFG_TX_DMA_EN |
346 MTK_WED_GLO_CFG_RX_DMA_EN);
348 - wdma_m32(dev, MTK_WDMA_GLO_CFG,
349 + wdma_clr(dev, MTK_WDMA_GLO_CFG,
350 MTK_WDMA_GLO_CFG_TX_DMA_EN |
351 MTK_WDMA_GLO_CFG_RX_INFO1_PRERES |
352 - MTK_WDMA_GLO_CFG_RX_INFO2_PRERES, 0);
353 + MTK_WDMA_GLO_CFG_RX_INFO2_PRERES);
355 if (dev->hw->version == 1) {
356 regmap_write(dev->hw->mirror, dev->hw->index * 4, 0);
357 - wdma_m32(dev, MTK_WDMA_GLO_CFG,
358 - MTK_WDMA_GLO_CFG_RX_INFO3_PRERES, 0);
359 + wdma_clr(dev, MTK_WDMA_GLO_CFG,
360 + MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
362 wed_clr(dev, MTK_WED_WPDMA_GLO_CFG,
363 MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_PKT_PROC |
364 MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_CRX_SYNC);
366 + wed_clr(dev, MTK_WED_WPDMA_RX_D_GLO_CFG,
367 + MTK_WED_WPDMA_RX_D_RX_DRV_EN);
368 + wed_clr(dev, MTK_WED_WDMA_GLO_CFG,
369 + MTK_WED_WDMA_GLO_CFG_TX_DDONE_CHK);
371 mtk_wed_set_512_support(dev, false);
374 @@ -338,6 +547,13 @@ mtk_wed_stop(struct mtk_wed_device *dev)
375 wdma_w32(dev, MTK_WDMA_INT_MASK, 0);
376 wdma_w32(dev, MTK_WDMA_INT_GRP2, 0);
377 wed_w32(dev, MTK_WED_WPDMA_INT_MASK, 0);
379 + if (dev->hw->version == 1)
382 + wed_w32(dev, MTK_WED_EXT_INT_MASK1, 0);
383 + wed_w32(dev, MTK_WED_EXT_INT_MASK2, 0);
384 + wed_clr(dev, MTK_WED_CTRL, MTK_WED_CTRL_WED_RX_BM_EN);
388 @@ -353,11 +569,21 @@ mtk_wed_detach(struct mtk_wed_device *de
389 wdma_w32(dev, MTK_WDMA_RESET_IDX, 0);
391 mtk_wed_reset(dev, MTK_WED_RESET_WED);
392 + if (mtk_wed_get_rx_capa(dev)) {
393 + wdma_clr(dev, MTK_WDMA_GLO_CFG, MTK_WDMA_GLO_CFG_TX_DMA_EN);
394 + wdma_w32(dev, MTK_WDMA_RESET_IDX, MTK_WDMA_RESET_IDX_TX);
395 + wdma_w32(dev, MTK_WDMA_RESET_IDX, 0);
398 - mtk_wed_free_buffer(dev);
399 + mtk_wed_free_tx_buffer(dev);
400 mtk_wed_free_tx_rings(dev);
401 - if (hw->version != 1)
403 + if (mtk_wed_get_rx_capa(dev)) {
404 + mtk_wed_wo_reset(dev);
405 + mtk_wed_free_rx_rings(dev);
406 mtk_wed_wo_deinit(hw);
407 + mtk_wdma_rx_reset(dev);
410 if (dev->wlan.bus_type == MTK_WED_BUS_PCIE) {
411 struct device_node *wlan_node;
412 @@ -434,10 +660,12 @@ mtk_wed_set_wpdma(struct mtk_wed_device
414 mtk_wed_bus_init(dev);
416 - wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_int);
417 - wed_w32(dev, MTK_WED_WPDMA_CFG_INT_MASK, dev->wlan.wpdma_mask);
418 - wed_w32(dev, MTK_WED_WPDMA_CFG_TX, dev->wlan.wpdma_tx);
419 - wed_w32(dev, MTK_WED_WPDMA_CFG_TX_FREE, dev->wlan.wpdma_txfree);
420 + wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_int);
421 + wed_w32(dev, MTK_WED_WPDMA_CFG_INT_MASK, dev->wlan.wpdma_mask);
422 + wed_w32(dev, MTK_WED_WPDMA_CFG_TX, dev->wlan.wpdma_tx);
423 + wed_w32(dev, MTK_WED_WPDMA_CFG_TX_FREE, dev->wlan.wpdma_txfree);
424 + wed_w32(dev, MTK_WED_WPDMA_RX_GLO_CFG, dev->wlan.wpdma_rx_glo);
425 + wed_w32(dev, MTK_WED_WPDMA_RX_RING, dev->wlan.wpdma_rx);
429 @@ -487,6 +715,132 @@ mtk_wed_hw_init_early(struct mtk_wed_dev
434 +mtk_wed_rro_ring_alloc(struct mtk_wed_device *dev, struct mtk_wed_ring *ring,
437 + ring->desc = dma_alloc_coherent(dev->hw->dev,
438 + size * sizeof(*ring->desc),
439 + &ring->desc_phys, GFP_KERNEL);
443 + ring->desc_size = sizeof(*ring->desc);
445 + memset(ring->desc, 0, size);
450 +#define MTK_WED_MIOD_COUNT (MTK_WED_MIOD_ENTRY_CNT * MTK_WED_MIOD_CNT)
452 +mtk_wed_rro_alloc(struct mtk_wed_device *dev)
454 + struct reserved_mem *rmem;
455 + struct device_node *np;
458 + index = of_property_match_string(dev->hw->node, "memory-region-names",
463 + np = of_parse_phandle(dev->hw->node, "memory-region", index);
467 + rmem = of_reserved_mem_lookup(np);
473 + dev->rro.miod_phys = rmem->base;
474 + dev->rro.fdbk_phys = MTK_WED_MIOD_COUNT + dev->rro.miod_phys;
476 + return mtk_wed_rro_ring_alloc(dev, &dev->rro.ring,
477 + MTK_WED_RRO_QUE_CNT);
481 +mtk_wed_rro_cfg(struct mtk_wed_device *dev)
483 + struct mtk_wed_wo *wo = dev->hw->wed_wo;
494 + .base = cpu_to_le32(MTK_WED_WOCPU_VIEW_MIOD_BASE),
495 + .cnt = cpu_to_le32(MTK_WED_MIOD_CNT),
496 + .unit = cpu_to_le32(MTK_WED_MIOD_ENTRY_CNT),
499 + .base = cpu_to_le32(MTK_WED_WOCPU_VIEW_MIOD_BASE +
500 + MTK_WED_MIOD_COUNT),
501 + .cnt = cpu_to_le32(MTK_WED_FB_CMD_CNT),
502 + .unit = cpu_to_le32(4),
506 + return mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO,
507 + MTK_WED_WO_CMD_WED_CFG,
508 + &req, sizeof(req), true);
512 +mtk_wed_rro_hw_init(struct mtk_wed_device *dev)
514 + wed_w32(dev, MTK_WED_RROQM_MIOD_CFG,
515 + FIELD_PREP(MTK_WED_RROQM_MIOD_MID_DW, 0x70 >> 2) |
516 + FIELD_PREP(MTK_WED_RROQM_MIOD_MOD_DW, 0x10 >> 2) |
517 + FIELD_PREP(MTK_WED_RROQM_MIOD_ENTRY_DW,
518 + MTK_WED_MIOD_ENTRY_CNT >> 2));
520 + wed_w32(dev, MTK_WED_RROQM_MIOD_CTRL0, dev->rro.miod_phys);
521 + wed_w32(dev, MTK_WED_RROQM_MIOD_CTRL1,
522 + FIELD_PREP(MTK_WED_RROQM_MIOD_CNT, MTK_WED_MIOD_CNT));
523 + wed_w32(dev, MTK_WED_RROQM_FDBK_CTRL0, dev->rro.fdbk_phys);
524 + wed_w32(dev, MTK_WED_RROQM_FDBK_CTRL1,
525 + FIELD_PREP(MTK_WED_RROQM_FDBK_CNT, MTK_WED_FB_CMD_CNT));
526 + wed_w32(dev, MTK_WED_RROQM_FDBK_CTRL2, 0);
527 + wed_w32(dev, MTK_WED_RROQ_BASE_L, dev->rro.ring.desc_phys);
529 + wed_set(dev, MTK_WED_RROQM_RST_IDX,
530 + MTK_WED_RROQM_RST_IDX_MIOD |
531 + MTK_WED_RROQM_RST_IDX_FDBK);
533 + wed_w32(dev, MTK_WED_RROQM_RST_IDX, 0);
534 + wed_w32(dev, MTK_WED_RROQM_MIOD_CTRL2, MTK_WED_MIOD_CNT - 1);
535 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_RX_RRO_QM_EN);
539 +mtk_wed_route_qm_hw_init(struct mtk_wed_device *dev)
541 + wed_w32(dev, MTK_WED_RESET, MTK_WED_RESET_RX_ROUTE_QM);
544 + usleep_range(100, 200);
545 + if (!(wed_r32(dev, MTK_WED_RESET) & MTK_WED_RESET_RX_ROUTE_QM))
549 + /* configure RX_ROUTE_QM */
550 + wed_clr(dev, MTK_WED_RTQM_GLO_CFG, MTK_WED_RTQM_Q_RST);
551 + wed_clr(dev, MTK_WED_RTQM_GLO_CFG, MTK_WED_RTQM_TXDMAD_FPORT);
552 + wed_set(dev, MTK_WED_RTQM_GLO_CFG,
553 + FIELD_PREP(MTK_WED_RTQM_TXDMAD_FPORT, 0x3 + dev->hw->index));
554 + wed_clr(dev, MTK_WED_RTQM_GLO_CFG, MTK_WED_RTQM_Q_RST);
555 + /* enable RX_ROUTE_QM */
556 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_RX_ROUTE_QM_EN);
560 mtk_wed_hw_init(struct mtk_wed_device *dev)
562 @@ -498,11 +852,11 @@ mtk_wed_hw_init(struct mtk_wed_device *d
563 wed_w32(dev, MTK_WED_TX_BM_CTRL,
564 MTK_WED_TX_BM_CTRL_PAUSE |
565 FIELD_PREP(MTK_WED_TX_BM_CTRL_VLD_GRP_NUM,
566 - dev->buf_ring.size / 128) |
567 + dev->tx_buf_ring.size / 128) |
568 FIELD_PREP(MTK_WED_TX_BM_CTRL_RSV_GRP_NUM,
569 MTK_WED_TX_RING_SIZE / 256));
571 - wed_w32(dev, MTK_WED_TX_BM_BASE, dev->buf_ring.desc_phys);
572 + wed_w32(dev, MTK_WED_TX_BM_BASE, dev->tx_buf_ring.desc_phys);
574 wed_w32(dev, MTK_WED_TX_BM_BUF_LEN, MTK_WED_PKT_SIZE);
576 @@ -529,9 +883,9 @@ mtk_wed_hw_init(struct mtk_wed_device *d
577 wed_w32(dev, MTK_WED_TX_TKID_CTRL,
578 MTK_WED_TX_TKID_CTRL_PAUSE |
579 FIELD_PREP(MTK_WED_TX_TKID_CTRL_VLD_GRP_NUM,
580 - dev->buf_ring.size / 128) |
581 + dev->tx_buf_ring.size / 128) |
582 FIELD_PREP(MTK_WED_TX_TKID_CTRL_RSV_GRP_NUM,
583 - dev->buf_ring.size / 128));
584 + dev->tx_buf_ring.size / 128));
585 wed_w32(dev, MTK_WED_TX_TKID_DYN_THR,
586 FIELD_PREP(MTK_WED_TX_TKID_DYN_THR_LO, 0) |
587 MTK_WED_TX_TKID_DYN_THR_HI);
588 @@ -539,18 +893,28 @@ mtk_wed_hw_init(struct mtk_wed_device *d
590 mtk_wed_reset(dev, MTK_WED_RESET_TX_BM);
592 - if (dev->hw->version == 1)
593 + if (dev->hw->version == 1) {
594 wed_set(dev, MTK_WED_CTRL,
595 MTK_WED_CTRL_WED_TX_BM_EN |
596 MTK_WED_CTRL_WED_TX_FREE_AGENT_EN);
599 wed_clr(dev, MTK_WED_TX_TKID_CTRL, MTK_WED_TX_TKID_CTRL_PAUSE);
601 + wed_w32(dev, MTK_WED_WPDMA_RX_D_RST_IDX,
602 + MTK_WED_WPDMA_RX_D_RST_CRX_IDX |
603 + MTK_WED_WPDMA_RX_D_RST_DRV_IDX);
604 + wed_w32(dev, MTK_WED_WPDMA_RX_D_RST_IDX, 0);
606 + mtk_wed_rx_buffer_hw_init(dev);
607 + mtk_wed_rro_hw_init(dev);
608 + mtk_wed_route_qm_hw_init(dev);
611 wed_clr(dev, MTK_WED_TX_BM_CTRL, MTK_WED_TX_BM_CTRL_PAUSE);
615 -mtk_wed_ring_reset(struct mtk_wed_ring *ring, int size)
616 +mtk_wed_ring_reset(struct mtk_wed_ring *ring, int size, bool tx)
618 void *head = (void *)ring->desc;
620 @@ -560,7 +924,10 @@ mtk_wed_ring_reset(struct mtk_wed_ring *
622 desc = (struct mtk_wdma_desc *)(head + i * ring->desc_size);
624 - desc->ctrl = cpu_to_le32(MTK_WDMA_DESC_CTRL_DMA_DONE);
626 + desc->ctrl = cpu_to_le32(MTK_WDMA_DESC_CTRL_DMA_DONE);
628 + desc->ctrl = cpu_to_le32(MTK_WFDMA_DESC_CTRL_TO_HOST);
632 @@ -616,7 +983,8 @@ mtk_wed_reset_dma(struct mtk_wed_device
633 if (!dev->tx_ring[i].desc)
636 - mtk_wed_ring_reset(&dev->tx_ring[i], MTK_WED_TX_RING_SIZE);
637 + mtk_wed_ring_reset(&dev->tx_ring[i], MTK_WED_TX_RING_SIZE,
641 if (mtk_wed_poll_busy(dev))
642 @@ -634,6 +1002,9 @@ mtk_wed_reset_dma(struct mtk_wed_device
643 wdma_w32(dev, MTK_WDMA_RESET_IDX, MTK_WDMA_RESET_IDX_RX);
644 wdma_w32(dev, MTK_WDMA_RESET_IDX, 0);
646 + if (mtk_wed_get_rx_capa(dev))
647 + mtk_wdma_rx_reset(dev);
650 mtk_wed_reset(dev, MTK_WED_RESET_WDMA_INT_AGENT);
651 mtk_wed_reset(dev, MTK_WED_RESET_WDMA_RX_DRV);
652 @@ -668,12 +1039,11 @@ mtk_wed_reset_dma(struct mtk_wed_device
653 MTK_WED_WPDMA_RESET_IDX_RX);
654 wed_w32(dev, MTK_WED_WPDMA_RESET_IDX, 0);
660 mtk_wed_ring_alloc(struct mtk_wed_device *dev, struct mtk_wed_ring *ring,
661 - int size, u32 desc_size)
662 + int size, u32 desc_size, bool tx)
664 ring->desc = dma_alloc_coherent(dev->hw->dev, size * desc_size,
665 &ring->desc_phys, GFP_KERNEL);
666 @@ -682,7 +1052,7 @@ mtk_wed_ring_alloc(struct mtk_wed_device
668 ring->desc_size = desc_size;
670 - mtk_wed_ring_reset(ring, size);
671 + mtk_wed_ring_reset(ring, size, tx);
675 @@ -691,9 +1061,14 @@ static int
676 mtk_wed_wdma_rx_ring_setup(struct mtk_wed_device *dev, int idx, int size)
678 u32 desc_size = sizeof(struct mtk_wdma_desc) * dev->hw->version;
679 - struct mtk_wed_ring *wdma = &dev->rx_wdma[idx];
680 + struct mtk_wed_ring *wdma;
682 - if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, desc_size))
683 + if (idx >= ARRAY_SIZE(dev->rx_wdma))
686 + wdma = &dev->rx_wdma[idx];
687 + if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, desc_size,
691 wdma_w32(dev, MTK_WDMA_RING_RX(idx) + MTK_WED_RING_OFS_BASE,
692 @@ -710,6 +1085,60 @@ mtk_wed_wdma_rx_ring_setup(struct mtk_we
697 +mtk_wed_wdma_tx_ring_setup(struct mtk_wed_device *dev, int idx, int size)
699 + u32 desc_size = sizeof(struct mtk_wdma_desc) * dev->hw->version;
700 + struct mtk_wed_ring *wdma;
702 + if (idx >= ARRAY_SIZE(dev->tx_wdma))
705 + wdma = &dev->tx_wdma[idx];
706 + if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, desc_size,
710 + wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_BASE,
712 + wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_COUNT,
714 + wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_CPU_IDX, 0);
715 + wdma_w32(dev, MTK_WDMA_RING_TX(idx) + MTK_WED_RING_OFS_DMA_IDX, 0);
718 + wed_w32(dev, MTK_WED_WDMA_RING_TX + MTK_WED_RING_OFS_BASE,
720 + wed_w32(dev, MTK_WED_WDMA_RING_TX + MTK_WED_RING_OFS_COUNT,
722 + wed_w32(dev, MTK_WED_WDMA_RING_TX + MTK_WED_RING_OFS_CPU_IDX,
724 + wed_w32(dev, MTK_WED_WDMA_RING_TX + MTK_WED_RING_OFS_DMA_IDX,
732 +mtk_wed_ppe_check(struct mtk_wed_device *dev, struct sk_buff *skb,
733 + u32 reason, u32 hash)
735 + struct mtk_eth *eth = dev->hw->eth;
741 + if (reason != MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
744 + skb_set_mac_header(skb, 0);
746 + skb->protocol = eh->h_proto;
747 + mtk_ppe_check_skb(eth->ppe[dev->hw->index], skb, hash);
751 mtk_wed_configure_irq(struct mtk_wed_device *dev, u32 irq_mask)
753 @@ -732,6 +1161,8 @@ mtk_wed_configure_irq(struct mtk_wed_dev
755 wed_clr(dev, MTK_WED_WDMA_INT_CTRL, wdma_mask);
757 + wdma_mask |= FIELD_PREP(MTK_WDMA_INT_MASK_TX_DONE,
759 /* initail tx interrupt trigger */
760 wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_TX,
761 MTK_WED_WPDMA_INT_CTRL_TX0_DONE_EN |
762 @@ -750,6 +1181,16 @@ mtk_wed_configure_irq(struct mtk_wed_dev
763 FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_TRIG,
764 dev->wlan.txfree_tbit));
766 + wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_RX,
767 + MTK_WED_WPDMA_INT_CTRL_RX0_EN |
768 + MTK_WED_WPDMA_INT_CTRL_RX0_CLR |
769 + MTK_WED_WPDMA_INT_CTRL_RX1_EN |
770 + MTK_WED_WPDMA_INT_CTRL_RX1_CLR |
771 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RX0_DONE_TRIG,
772 + dev->wlan.rx_tbit[0]) |
773 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RX1_DONE_TRIG,
774 + dev->wlan.rx_tbit[1]));
776 wed_w32(dev, MTK_WED_WDMA_INT_CLR, wdma_mask);
777 wed_set(dev, MTK_WED_WDMA_INT_CTRL,
778 FIELD_PREP(MTK_WED_WDMA_INT_CTRL_POLL_SRC_SEL,
779 @@ -787,9 +1228,15 @@ mtk_wed_dma_enable(struct mtk_wed_device
780 wdma_set(dev, MTK_WDMA_GLO_CFG,
781 MTK_WDMA_GLO_CFG_RX_INFO3_PRERES);
785 wed_set(dev, MTK_WED_WPDMA_CTRL,
786 MTK_WED_WPDMA_CTRL_SDL1_FIXED);
788 + wed_set(dev, MTK_WED_WDMA_GLO_CFG,
789 + MTK_WED_WDMA_GLO_CFG_TX_DRV_EN |
790 + MTK_WED_WDMA_GLO_CFG_TX_DDONE_CHK);
792 wed_set(dev, MTK_WED_WPDMA_GLO_CFG,
793 MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_PKT_PROC |
794 MTK_WED_WPDMA_GLO_CFG_RX_DRV_R0_CRX_SYNC);
795 @@ -797,6 +1244,15 @@ mtk_wed_dma_enable(struct mtk_wed_device
796 wed_clr(dev, MTK_WED_WPDMA_GLO_CFG,
797 MTK_WED_WPDMA_GLO_CFG_TX_TKID_KEEP |
798 MTK_WED_WPDMA_GLO_CFG_TX_DMAD_DW3_PREV);
800 + wed_set(dev, MTK_WED_WPDMA_RX_D_GLO_CFG,
801 + MTK_WED_WPDMA_RX_D_RX_DRV_EN |
802 + FIELD_PREP(MTK_WED_WPDMA_RX_D_RXD_READ_LEN, 0x18) |
803 + FIELD_PREP(MTK_WED_WPDMA_RX_D_INIT_PHASE_RXEN_SEL,
806 + for (i = 0; i < MTK_WED_RX_QUEUES; i++)
807 + mtk_wed_check_wfdma_rx_fill(dev, i);
811 @@ -822,7 +1278,19 @@ mtk_wed_start(struct mtk_wed_device *dev
812 val |= BIT(0) | (BIT(1) * !!dev->hw->index);
813 regmap_write(dev->hw->mirror, dev->hw->index * 4, val);
815 - mtk_wed_set_512_support(dev, true);
816 + /* driver set mid ready and only once */
817 + wed_w32(dev, MTK_WED_EXT_INT_MASK1,
818 + MTK_WED_EXT_INT_STATUS_WPDMA_MID_RDY);
819 + wed_w32(dev, MTK_WED_EXT_INT_MASK2,
820 + MTK_WED_EXT_INT_STATUS_WPDMA_MID_RDY);
822 + wed_r32(dev, MTK_WED_EXT_INT_MASK1);
823 + wed_r32(dev, MTK_WED_EXT_INT_MASK2);
825 + if (mtk_wed_rro_cfg(dev))
828 + mtk_wed_set_512_support(dev, dev->wlan.wcid_512);
831 mtk_wed_dma_enable(dev);
832 @@ -856,7 +1324,7 @@ mtk_wed_attach(struct mtk_wed_device *de
834 module_put(THIS_MODULE);
840 device = dev->wlan.bus_type == MTK_WED_BUS_PCIE
841 @@ -869,15 +1337,24 @@ mtk_wed_attach(struct mtk_wed_device *de
844 dev->wdma_idx = hw->index;
845 + dev->version = hw->version;
847 if (hw->eth->dma_dev == hw->eth->dev &&
848 of_dma_is_coherent(hw->eth->dev->of_node))
849 mtk_eth_set_dma_device(hw->eth, hw->dev);
851 - ret = mtk_wed_buffer_alloc(dev);
853 - mtk_wed_detach(dev);
854 + ret = mtk_wed_tx_buffer_alloc(dev);
858 + if (mtk_wed_get_rx_capa(dev)) {
859 + ret = mtk_wed_rx_buffer_alloc(dev);
863 + ret = mtk_wed_rro_alloc(dev);
868 mtk_wed_hw_init_early(dev);
869 @@ -886,8 +1363,10 @@ mtk_wed_attach(struct mtk_wed_device *de
872 ret = mtk_wed_wo_init(hw);
876 + mtk_wed_detach(dev);
878 mutex_unlock(&hw_lock);
881 @@ -910,10 +1389,11 @@ mtk_wed_tx_ring_setup(struct mtk_wed_dev
885 - BUG_ON(idx >= ARRAY_SIZE(dev->tx_ring));
886 + if (WARN_ON(idx >= ARRAY_SIZE(dev->tx_ring)))
889 if (mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE,
890 - sizeof(*ring->desc)))
891 + sizeof(*ring->desc), true))
894 if (mtk_wed_wdma_rx_ring_setup(dev, idx, MTK_WED_WDMA_RING_SIZE))
895 @@ -960,6 +1440,37 @@ mtk_wed_txfree_ring_setup(struct mtk_wed
900 +mtk_wed_rx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs)
902 + struct mtk_wed_ring *ring = &dev->rx_ring[idx];
904 + if (WARN_ON(idx >= ARRAY_SIZE(dev->rx_ring)))
907 + if (mtk_wed_ring_alloc(dev, ring, MTK_WED_RX_RING_SIZE,
908 + sizeof(*ring->desc), false))
911 + if (mtk_wed_wdma_tx_ring_setup(dev, idx, MTK_WED_WDMA_RING_SIZE))
914 + ring->reg_base = MTK_WED_RING_RX_DATA(idx);
915 + ring->wpdma = regs;
916 + ring->flags |= MTK_WED_RING_CONFIGURED;
919 + wpdma_rx_w32(dev, idx, MTK_WED_RING_OFS_BASE, ring->desc_phys);
920 + wpdma_rx_w32(dev, idx, MTK_WED_RING_OFS_COUNT, MTK_WED_RX_RING_SIZE);
922 + wed_w32(dev, MTK_WED_WPDMA_RING_RX_DATA(idx) + MTK_WED_RING_OFS_BASE,
924 + wed_w32(dev, MTK_WED_WPDMA_RING_RX_DATA(idx) + MTK_WED_RING_OFS_COUNT,
925 + MTK_WED_RX_RING_SIZE);
931 mtk_wed_irq_get(struct mtk_wed_device *dev, u32 mask)
933 @@ -1056,7 +1567,9 @@ void mtk_wed_add_hw(struct device_node *
934 static const struct mtk_wed_ops wed_ops = {
935 .attach = mtk_wed_attach,
936 .tx_ring_setup = mtk_wed_tx_ring_setup,
937 + .rx_ring_setup = mtk_wed_rx_ring_setup,
938 .txfree_ring_setup = mtk_wed_txfree_ring_setup,
939 + .msg_update = mtk_wed_mcu_msg_update,
940 .start = mtk_wed_start,
941 .stop = mtk_wed_stop,
942 .reset_dma = mtk_wed_reset_dma,
943 @@ -1065,6 +1578,7 @@ void mtk_wed_add_hw(struct device_node *
944 .irq_get = mtk_wed_irq_get,
945 .irq_set_mask = mtk_wed_irq_set_mask,
946 .detach = mtk_wed_detach,
947 + .ppe_check = mtk_wed_ppe_check,
949 struct device_node *eth_np = eth->dev->of_node;
950 struct platform_device *pdev;
951 --- a/drivers/net/ethernet/mediatek/mtk_wed.h
952 +++ b/drivers/net/ethernet/mediatek/mtk_wed.h
953 @@ -87,6 +87,24 @@ wpdma_tx_w32(struct mtk_wed_device *dev,
957 +wpdma_rx_r32(struct mtk_wed_device *dev, int ring, u32 reg)
959 + if (!dev->rx_ring[ring].wpdma)
962 + return readl(dev->rx_ring[ring].wpdma + reg);
966 +wpdma_rx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val)
968 + if (!dev->rx_ring[ring].wpdma)
971 + writel(val, dev->rx_ring[ring].wpdma + reg);
975 wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg)
977 if (!dev->txfree_ring.wpdma)
978 @@ -128,6 +146,7 @@ static inline int mtk_wed_flow_add(int i
979 static inline void mtk_wed_flow_remove(int index)
985 #ifdef CONFIG_DEBUG_FS
986 --- a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
987 +++ b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
989 #include <linux/of_reserved_mem.h>
990 #include <linux/mfd/syscon.h>
991 #include <linux/soc/mediatek/mtk_wed.h>
992 +#include <asm/unaligned.h>
994 #include "mtk_wed_regs.h"
995 #include "mtk_wed_wo.h"
996 @@ -60,24 +61,37 @@ void mtk_wed_mcu_rx_event(struct mtk_wed
997 wake_up(&wo->mcu.wait);
1001 +mtk_wed_update_rx_stats(struct mtk_wed_device *wed, struct sk_buff *skb)
1003 + u32 count = get_unaligned_le32(skb->data);
1004 + struct mtk_wed_wo_rx_stats *stats;
1007 + if (count * sizeof(*stats) > skb->len - sizeof(u32))
1010 + stats = (struct mtk_wed_wo_rx_stats *)(skb->data + sizeof(u32));
1011 + for (i = 0 ; i < count ; i++)
1012 + wed->wlan.update_wo_rx_stats(wed, &stats[i]);
1015 void mtk_wed_mcu_rx_unsolicited_event(struct mtk_wed_wo *wo,
1016 struct sk_buff *skb)
1018 struct mtk_wed_mcu_hdr *hdr = (struct mtk_wed_mcu_hdr *)skb->data;
1020 - switch (hdr->cmd) {
1021 - case MTK_WED_WO_EVT_LOG_DUMP: {
1022 - const char *msg = (const char *)(skb->data + sizeof(*hdr));
1023 + skb_pull(skb, sizeof(*hdr));
1025 - dev_notice(wo->hw->dev, "%s\n", msg);
1026 + switch (hdr->cmd) {
1027 + case MTK_WED_WO_EVT_LOG_DUMP:
1028 + dev_notice(wo->hw->dev, "%s\n", skb->data);
1031 case MTK_WED_WO_EVT_PROFILING: {
1032 - struct mtk_wed_wo_log_info *info;
1033 - u32 count = (skb->len - sizeof(*hdr)) / sizeof(*info);
1034 + struct mtk_wed_wo_log_info *info = (void *)skb->data;
1035 + u32 count = skb->len / sizeof(*info);
1038 - info = (struct mtk_wed_wo_log_info *)(skb->data + sizeof(*hdr));
1039 for (i = 0 ; i < count ; i++)
1040 dev_notice(wo->hw->dev,
1041 "SN:%u latency: total=%u, rro:%u, mod:%u\n",
1042 @@ -88,6 +102,7 @@ void mtk_wed_mcu_rx_unsolicited_event(st
1045 case MTK_WED_WO_EVT_RXCNT_INFO:
1046 + mtk_wed_update_rx_stats(wo->hw->wed_dev, skb);
1050 @@ -144,6 +159,8 @@ mtk_wed_mcu_parse_response(struct mtk_we
1051 skb_pull(skb, sizeof(*hdr));
1053 case MTK_WED_WO_CMD_RXCNT_INFO:
1054 + mtk_wed_update_rx_stats(wo->hw->wed_dev, skb);
1059 @@ -182,6 +199,18 @@ unlock:
1063 +int mtk_wed_mcu_msg_update(struct mtk_wed_device *dev, int id, void *data,
1066 + struct mtk_wed_wo *wo = dev->hw->wed_wo;
1068 + if (dev->hw->version == 1)
1071 + return mtk_wed_mcu_send_msg(wo, MTK_WED_MODULE_ID_WO, id, data, len,
1076 mtk_wed_get_memory_region(struct mtk_wed_wo *wo,
1077 struct mtk_wed_wo_memory_region *region)
1078 --- a/drivers/net/ethernet/mediatek/mtk_wed_regs.h
1079 +++ b/drivers/net/ethernet/mediatek/mtk_wed_regs.h
1081 #ifndef __MTK_WED_REGS_H
1082 #define __MTK_WED_REGS_H
1084 +#define MTK_WFDMA_DESC_CTRL_TO_HOST BIT(8)
1085 #define MTK_WDMA_DESC_CTRL_LEN1 GENMASK(14, 0)
1086 #define MTK_WDMA_DESC_CTRL_LEN1_V2 GENMASK(13, 0)
1087 #define MTK_WDMA_DESC_CTRL_LAST_SEG1 BIT(15)
1088 @@ -28,6 +29,8 @@ struct mtk_wdma_desc {
1089 #define MTK_WED_RESET_WED_TX_DMA BIT(12)
1090 #define MTK_WED_RESET_WDMA_RX_DRV BIT(17)
1091 #define MTK_WED_RESET_WDMA_INT_AGENT BIT(19)
1092 +#define MTK_WED_RESET_RX_RRO_QM BIT(20)
1093 +#define MTK_WED_RESET_RX_ROUTE_QM BIT(21)
1094 #define MTK_WED_RESET_WED BIT(31)
1096 #define MTK_WED_CTRL 0x00c
1097 @@ -39,8 +42,12 @@ struct mtk_wdma_desc {
1098 #define MTK_WED_CTRL_WED_TX_BM_BUSY BIT(9)
1099 #define MTK_WED_CTRL_WED_TX_FREE_AGENT_EN BIT(10)
1100 #define MTK_WED_CTRL_WED_TX_FREE_AGENT_BUSY BIT(11)
1101 -#define MTK_WED_CTRL_RESERVE_EN BIT(12)
1102 -#define MTK_WED_CTRL_RESERVE_BUSY BIT(13)
1103 +#define MTK_WED_CTRL_WED_RX_BM_EN BIT(12)
1104 +#define MTK_WED_CTRL_WED_RX_BM_BUSY BIT(13)
1105 +#define MTK_WED_CTRL_RX_RRO_QM_EN BIT(14)
1106 +#define MTK_WED_CTRL_RX_RRO_QM_BUSY BIT(15)
1107 +#define MTK_WED_CTRL_RX_ROUTE_QM_EN BIT(16)
1108 +#define MTK_WED_CTRL_RX_ROUTE_QM_BUSY BIT(17)
1109 #define MTK_WED_CTRL_FINAL_DIDX_READ BIT(24)
1110 #define MTK_WED_CTRL_ETH_DMAD_FMT BIT(25)
1111 #define MTK_WED_CTRL_MIB_READ_CLEAR BIT(28)
1112 @@ -62,6 +69,9 @@ struct mtk_wdma_desc {
1113 #define MTK_WED_EXT_INT_STATUS_TX_DMA_R_RESP_ERR BIT(22)
1114 #define MTK_WED_EXT_INT_STATUS_TX_DMA_W_RESP_ERR BIT(23)
1115 #define MTK_WED_EXT_INT_STATUS_RX_DRV_DMA_RECYCLE BIT(24)
1116 +#define MTK_WED_EXT_INT_STATUS_RX_DRV_GET_BM_DMAD_SKIP BIT(25)
1117 +#define MTK_WED_EXT_INT_STATUS_WPDMA_RX_D_DRV_ERR BIT(26)
1118 +#define MTK_WED_EXT_INT_STATUS_WPDMA_MID_RDY BIT(27)
1119 #define MTK_WED_EXT_INT_STATUS_ERROR_MASK (MTK_WED_EXT_INT_STATUS_TF_LEN_ERR | \
1120 MTK_WED_EXT_INT_STATUS_TKID_WO_PYLD | \
1121 MTK_WED_EXT_INT_STATUS_TKID_TITO_INVALID | \
1122 @@ -71,6 +81,8 @@ struct mtk_wdma_desc {
1123 MTK_WED_EXT_INT_STATUS_TX_DMA_R_RESP_ERR)
1125 #define MTK_WED_EXT_INT_MASK 0x028
1126 +#define MTK_WED_EXT_INT_MASK1 0x02c
1127 +#define MTK_WED_EXT_INT_MASK2 0x030
1129 #define MTK_WED_STATUS 0x060
1130 #define MTK_WED_STATUS_TX GENMASK(15, 8)
1131 @@ -151,6 +163,7 @@ struct mtk_wdma_desc {
1132 #define MTK_WED_RING_TX(_n) (0x300 + (_n) * 0x10)
1134 #define MTK_WED_RING_RX(_n) (0x400 + (_n) * 0x10)
1135 +#define MTK_WED_RING_RX_DATA(_n) (0x420 + (_n) * 0x10)
1137 #define MTK_WED_SCR0 0x3c0
1138 #define MTK_WED_WPDMA_INT_TRIGGER 0x504
1139 @@ -213,6 +226,12 @@ struct mtk_wdma_desc {
1140 #define MTK_WED_WPDMA_INT_CTRL_TX1_DONE_TRIG GENMASK(14, 10)
1142 #define MTK_WED_WPDMA_INT_CTRL_RX 0x534
1143 +#define MTK_WED_WPDMA_INT_CTRL_RX0_EN BIT(0)
1144 +#define MTK_WED_WPDMA_INT_CTRL_RX0_CLR BIT(1)
1145 +#define MTK_WED_WPDMA_INT_CTRL_RX0_DONE_TRIG GENMASK(6, 2)
1146 +#define MTK_WED_WPDMA_INT_CTRL_RX1_EN BIT(8)
1147 +#define MTK_WED_WPDMA_INT_CTRL_RX1_CLR BIT(9)
1148 +#define MTK_WED_WPDMA_INT_CTRL_RX1_DONE_TRIG GENMASK(14, 10)
1150 #define MTK_WED_WPDMA_INT_CTRL_TX_FREE 0x538
1151 #define MTK_WED_WPDMA_INT_CTRL_TX_FREE_DONE_EN BIT(0)
1152 @@ -242,11 +261,34 @@ struct mtk_wdma_desc {
1154 #define MTK_WED_WPDMA_RING_TX(_n) (0x600 + (_n) * 0x10)
1155 #define MTK_WED_WPDMA_RING_RX(_n) (0x700 + (_n) * 0x10)
1156 +#define MTK_WED_WPDMA_RING_RX_DATA(_n) (0x730 + (_n) * 0x10)
1158 +#define MTK_WED_WPDMA_RX_D_GLO_CFG 0x75c
1159 +#define MTK_WED_WPDMA_RX_D_RX_DRV_EN BIT(0)
1160 +#define MTK_WED_WPDMA_RX_D_INIT_PHASE_RXEN_SEL GENMASK(11, 7)
1161 +#define MTK_WED_WPDMA_RX_D_RXD_READ_LEN GENMASK(31, 24)
1163 +#define MTK_WED_WPDMA_RX_D_RST_IDX 0x760
1164 +#define MTK_WED_WPDMA_RX_D_RST_CRX_IDX GENMASK(17, 16)
1165 +#define MTK_WED_WPDMA_RX_D_RST_DRV_IDX GENMASK(25, 24)
1167 +#define MTK_WED_WPDMA_RX_GLO_CFG 0x76c
1168 +#define MTK_WED_WPDMA_RX_RING 0x770
1170 +#define MTK_WED_WPDMA_RX_D_MIB(_n) (0x774 + (_n) * 4)
1171 +#define MTK_WED_WPDMA_RX_D_PROCESSED_MIB(_n) (0x784 + (_n) * 4)
1172 +#define MTK_WED_WPDMA_RX_D_COHERENT_MIB 0x78c
1174 +#define MTK_WED_WDMA_RING_TX 0x800
1176 +#define MTK_WED_WDMA_TX_MIB 0x810
1178 #define MTK_WED_WDMA_RING_RX(_n) (0x900 + (_n) * 0x10)
1179 #define MTK_WED_WDMA_RX_THRES(_n) (0x940 + (_n) * 0x4)
1181 #define MTK_WED_WDMA_GLO_CFG 0xa04
1182 #define MTK_WED_WDMA_GLO_CFG_TX_DRV_EN BIT(0)
1183 +#define MTK_WED_WDMA_GLO_CFG_TX_DDONE_CHK BIT(1)
1184 #define MTK_WED_WDMA_GLO_CFG_RX_DRV_EN BIT(2)
1185 #define MTK_WED_WDMA_GLO_CFG_RX_DRV_BUSY BIT(3)
1186 #define MTK_WED_WDMA_GLO_CFG_BT_SIZE GENMASK(5, 4)
1187 @@ -291,6 +333,20 @@ struct mtk_wdma_desc {
1188 #define MTK_WED_WDMA_RX_RECYCLE_MIB(_n) (0xae8 + (_n) * 4)
1189 #define MTK_WED_WDMA_RX_PROCESSED_MIB(_n) (0xaf0 + (_n) * 4)
1191 +#define MTK_WED_RX_BM_RX_DMAD 0xd80
1192 +#define MTK_WED_RX_BM_RX_DMAD_SDL0 GENMASK(13, 0)
1194 +#define MTK_WED_RX_BM_BASE 0xd84
1195 +#define MTK_WED_RX_BM_INIT_PTR 0xd88
1196 +#define MTK_WED_RX_BM_SW_TAIL GENMASK(15, 0)
1197 +#define MTK_WED_RX_BM_INIT_SW_TAIL BIT(16)
1199 +#define MTK_WED_RX_PTR 0xd8c
1201 +#define MTK_WED_RX_BM_DYN_ALLOC_TH 0xdb4
1202 +#define MTK_WED_RX_BM_DYN_ALLOC_TH_H GENMASK(31, 16)
1203 +#define MTK_WED_RX_BM_DYN_ALLOC_TH_L GENMASK(15, 0)
1205 #define MTK_WED_RING_OFS_BASE 0x00
1206 #define MTK_WED_RING_OFS_COUNT 0x04
1207 #define MTK_WED_RING_OFS_CPU_IDX 0x08
1208 @@ -301,7 +357,9 @@ struct mtk_wdma_desc {
1210 #define MTK_WDMA_GLO_CFG 0x204
1211 #define MTK_WDMA_GLO_CFG_TX_DMA_EN BIT(0)
1212 +#define MTK_WDMA_GLO_CFG_TX_DMA_BUSY BIT(1)
1213 #define MTK_WDMA_GLO_CFG_RX_DMA_EN BIT(2)
1214 +#define MTK_WDMA_GLO_CFG_RX_DMA_BUSY BIT(3)
1215 #define MTK_WDMA_GLO_CFG_RX_INFO3_PRERES BIT(26)
1216 #define MTK_WDMA_GLO_CFG_RX_INFO2_PRERES BIT(27)
1217 #define MTK_WDMA_GLO_CFG_RX_INFO1_PRERES BIT(28)
1218 @@ -330,4 +388,70 @@ struct mtk_wdma_desc {
1219 /* DMA channel mapping */
1220 #define HIFSYS_DMA_AG_MAP 0x008
1222 +#define MTK_WED_RTQM_GLO_CFG 0xb00
1223 +#define MTK_WED_RTQM_BUSY BIT(1)
1224 +#define MTK_WED_RTQM_Q_RST BIT(2)
1225 +#define MTK_WED_RTQM_Q_DBG_BYPASS BIT(5)
1226 +#define MTK_WED_RTQM_TXDMAD_FPORT GENMASK(23, 20)
1228 +#define MTK_WED_RTQM_R2H_MIB(_n) (0xb70 + (_n) * 0x4)
1229 +#define MTK_WED_RTQM_R2Q_MIB(_n) (0xb78 + (_n) * 0x4)
1230 +#define MTK_WED_RTQM_Q2N_MIB 0xb80
1231 +#define MTK_WED_RTQM_Q2H_MIB(_n) (0xb84 + (_n) * 0x4)
1233 +#define MTK_WED_RTQM_Q2B_MIB 0xb8c
1234 +#define MTK_WED_RTQM_PFDBK_MIB 0xb90
1236 +#define MTK_WED_RROQM_GLO_CFG 0xc04
1237 +#define MTK_WED_RROQM_RST_IDX 0xc08
1238 +#define MTK_WED_RROQM_RST_IDX_MIOD BIT(0)
1239 +#define MTK_WED_RROQM_RST_IDX_FDBK BIT(4)
1241 +#define MTK_WED_RROQM_MIOD_CTRL0 0xc40
1242 +#define MTK_WED_RROQM_MIOD_CTRL1 0xc44
1243 +#define MTK_WED_RROQM_MIOD_CNT GENMASK(11, 0)
1245 +#define MTK_WED_RROQM_MIOD_CTRL2 0xc48
1246 +#define MTK_WED_RROQM_MIOD_CTRL3 0xc4c
1248 +#define MTK_WED_RROQM_FDBK_CTRL0 0xc50
1249 +#define MTK_WED_RROQM_FDBK_CTRL1 0xc54
1250 +#define MTK_WED_RROQM_FDBK_CNT GENMASK(11, 0)
1252 +#define MTK_WED_RROQM_FDBK_CTRL2 0xc58
1254 +#define MTK_WED_RROQ_BASE_L 0xc80
1255 +#define MTK_WED_RROQ_BASE_H 0xc84
1257 +#define MTK_WED_RROQM_MIOD_CFG 0xc8c
1258 +#define MTK_WED_RROQM_MIOD_MID_DW GENMASK(5, 0)
1259 +#define MTK_WED_RROQM_MIOD_MOD_DW GENMASK(13, 8)
1260 +#define MTK_WED_RROQM_MIOD_ENTRY_DW GENMASK(22, 16)
1262 +#define MTK_WED_RROQM_MID_MIB 0xcc0
1263 +#define MTK_WED_RROQM_MOD_MIB 0xcc4
1264 +#define MTK_WED_RROQM_MOD_COHERENT_MIB 0xcc8
1265 +#define MTK_WED_RROQM_FDBK_MIB 0xcd0
1266 +#define MTK_WED_RROQM_FDBK_COHERENT_MIB 0xcd4
1267 +#define MTK_WED_RROQM_FDBK_IND_MIB 0xce0
1268 +#define MTK_WED_RROQM_FDBK_ENQ_MIB 0xce4
1269 +#define MTK_WED_RROQM_FDBK_ANC_MIB 0xce8
1270 +#define MTK_WED_RROQM_FDBK_ANC2H_MIB 0xcec
1272 +#define MTK_WED_RX_BM_RX_DMAD 0xd80
1273 +#define MTK_WED_RX_BM_BASE 0xd84
1274 +#define MTK_WED_RX_BM_INIT_PTR 0xd88
1275 +#define MTK_WED_RX_BM_PTR 0xd8c
1276 +#define MTK_WED_RX_BM_PTR_HEAD GENMASK(32, 16)
1277 +#define MTK_WED_RX_BM_PTR_TAIL GENMASK(15, 0)
1279 +#define MTK_WED_RX_BM_BLEN 0xd90
1280 +#define MTK_WED_RX_BM_STS 0xd94
1281 +#define MTK_WED_RX_BM_INTF2 0xd98
1282 +#define MTK_WED_RX_BM_INTF 0xd9c
1283 +#define MTK_WED_RX_BM_ERR_STS 0xda8
1285 +#define MTK_WED_WOCPU_VIEW_MIOD_BASE 0x8000
1286 +#define MTK_WED_PCIE_INT_MASK 0x0
1289 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.h
1290 +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.h
1291 @@ -49,6 +49,10 @@ enum {
1292 MTK_WED_WARP_CMD_FLAG_FROM_TO_WO = BIT(2),
1295 +#define MTK_WED_WO_CPU_MCUSYS_RESET_ADDR 0x15194050
1296 +#define MTK_WED_WO_CPU_WO0_MCUSYS_RESET_MASK 0x20
1297 +#define MTK_WED_WO_CPU_WO1_MCUSYS_RESET_MASK 0x1
1300 MTK_WED_WO_REGION_EMI,
1301 MTK_WED_WO_REGION_ILM,
1302 @@ -57,6 +61,28 @@ enum {
1303 __MTK_WED_WO_REGION_MAX,
1306 +enum mtk_wed_wo_state {
1307 + MTK_WED_WO_STATE_UNDEFINED,
1308 + MTK_WED_WO_STATE_INIT,
1309 + MTK_WED_WO_STATE_ENABLE,
1310 + MTK_WED_WO_STATE_DISABLE,
1311 + MTK_WED_WO_STATE_HALT,
1312 + MTK_WED_WO_STATE_GATING,
1313 + MTK_WED_WO_STATE_SER_RESET,
1314 + MTK_WED_WO_STATE_WF_RESET,
1317 +enum mtk_wed_wo_done_state {
1318 + MTK_WED_WOIF_UNDEFINED,
1319 + MTK_WED_WOIF_DISABLE_DONE,
1320 + MTK_WED_WOIF_TRIGGER_ENABLE,
1321 + MTK_WED_WOIF_ENABLE_DONE,
1322 + MTK_WED_WOIF_TRIGGER_GATING,
1323 + MTK_WED_WOIF_GATING_DONE,
1324 + MTK_WED_WOIF_TRIGGER_HALT,
1325 + MTK_WED_WOIF_HALT_DONE,
1328 enum mtk_wed_dummy_cr_idx {
1329 MTK_WED_DUMMY_CR_FWDL,
1330 MTK_WED_DUMMY_CR_WO_STATUS,
1331 @@ -245,6 +271,8 @@ void mtk_wed_mcu_rx_unsolicited_event(st
1332 struct sk_buff *skb);
1333 int mtk_wed_mcu_send_msg(struct mtk_wed_wo *wo, int id, int cmd,
1334 const void *data, int len, bool wait_resp);
1335 +int mtk_wed_mcu_msg_update(struct mtk_wed_device *dev, int id, void *data,
1337 int mtk_wed_mcu_init(struct mtk_wed_wo *wo);
1338 int mtk_wed_wo_init(struct mtk_wed_hw *hw);
1339 void mtk_wed_wo_deinit(struct mtk_wed_hw *hw);
1340 --- a/include/linux/soc/mediatek/mtk_wed.h
1341 +++ b/include/linux/soc/mediatek/mtk_wed.h
1343 #include <linux/rcupdate.h>
1344 #include <linux/regmap.h>
1345 #include <linux/pci.h>
1346 +#include <linux/skbuff.h>
1348 #define MTK_WED_TX_QUEUES 2
1349 #define MTK_WED_RX_QUEUES 2
1351 +#define WED_WO_STA_REC 0x6
1354 struct mtk_wdma_desc;
1356 @@ -41,21 +44,37 @@ enum mtk_wed_wo_cmd {
1357 MTK_WED_WO_CMD_WED_END
1360 +struct mtk_rxbm_desc {
1363 +} __packed __aligned(4);
1365 enum mtk_wed_bus_tye {
1370 +#define MTK_WED_RING_CONFIGURED BIT(0)
1371 struct mtk_wed_ring {
1372 struct mtk_wdma_desc *desc;
1373 dma_addr_t desc_phys;
1379 void __iomem *wpdma;
1382 +struct mtk_wed_wo_rx_stats {
1385 + __le32 rx_pkt_cnt;
1386 + __le32 rx_byte_cnt;
1387 + __le32 rx_err_cnt;
1388 + __le32 rx_drop_cnt;
1391 struct mtk_wed_device {
1392 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
1393 const struct mtk_wed_ops *ops;
1394 @@ -64,9 +83,12 @@ struct mtk_wed_device {
1395 bool init_done, running;
1400 struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES];
1401 + struct mtk_wed_ring rx_ring[MTK_WED_RX_QUEUES];
1402 struct mtk_wed_ring txfree_ring;
1403 + struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES];
1404 struct mtk_wed_ring rx_wdma[MTK_WED_RX_QUEUES];
1407 @@ -74,7 +96,20 @@ struct mtk_wed_device {
1409 struct mtk_wdma_desc *desc;
1410 dma_addr_t desc_phys;
1416 + struct page_frag_cache rx_page;
1417 + struct mtk_rxbm_desc *desc;
1418 + dma_addr_t desc_phys;
1422 + struct mtk_wed_ring ring;
1423 + dma_addr_t miod_phys;
1424 + dma_addr_t fdbk_phys;
1427 /* filled by driver: */
1429 @@ -83,22 +118,36 @@ struct mtk_wed_device {
1430 struct pci_dev *pci_dev;
1432 enum mtk_wed_bus_tye bus_type;
1433 + void __iomem *base;
1448 + unsigned int rx_nbuf;
1449 + unsigned int rx_npkt;
1450 + unsigned int rx_size;
1452 u8 tx_tbit[MTK_WED_TX_QUEUES];
1453 + u8 rx_tbit[MTK_WED_RX_QUEUES];
1456 u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id);
1457 int (*offload_enable)(struct mtk_wed_device *wed);
1458 void (*offload_disable)(struct mtk_wed_device *wed);
1459 + u32 (*init_rx_buf)(struct mtk_wed_device *wed, int size);
1460 + void (*release_rx_buf)(struct mtk_wed_device *wed);
1461 + void (*update_wo_rx_stats)(struct mtk_wed_device *wed,
1462 + struct mtk_wed_wo_rx_stats *stats);
1466 @@ -107,9 +156,15 @@ struct mtk_wed_ops {
1467 int (*attach)(struct mtk_wed_device *dev);
1468 int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring,
1469 void __iomem *regs);
1470 + int (*rx_ring_setup)(struct mtk_wed_device *dev, int ring,
1471 + void __iomem *regs);
1472 int (*txfree_ring_setup)(struct mtk_wed_device *dev,
1473 void __iomem *regs);
1474 + int (*msg_update)(struct mtk_wed_device *dev, int cmd_id,
1475 + void *data, int len);
1476 void (*detach)(struct mtk_wed_device *dev);
1477 + void (*ppe_check)(struct mtk_wed_device *dev, struct sk_buff *skb,
1478 + u32 reason, u32 hash);
1480 void (*stop)(struct mtk_wed_device *dev);
1481 void (*start)(struct mtk_wed_device *dev, u32 irq_mask);
1482 @@ -144,6 +199,16 @@ mtk_wed_device_attach(struct mtk_wed_dev
1487 +mtk_wed_get_rx_capa(struct mtk_wed_device *dev)
1489 +#ifdef CONFIG_NET_MEDIATEK_SOC_WED
1490 + return dev->version != 1;
1496 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
1497 #define mtk_wed_device_active(_dev) !!(_dev)->ops
1498 #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev)
1499 @@ -160,6 +225,12 @@ mtk_wed_device_attach(struct mtk_wed_dev
1500 (_dev)->ops->irq_get(_dev, _mask)
1501 #define mtk_wed_device_irq_set_mask(_dev, _mask) \
1502 (_dev)->ops->irq_set_mask(_dev, _mask)
1503 +#define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs) \
1504 + (_dev)->ops->rx_ring_setup(_dev, _ring, _regs)
1505 +#define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) \
1506 + (_dev)->ops->ppe_check(_dev, _skb, _reason, _hash)
1507 +#define mtk_wed_device_update_msg(_dev, _id, _msg, _len) \
1508 + (_dev)->ops->msg_update(_dev, _id, _msg, _len)
1510 static inline bool mtk_wed_device_active(struct mtk_wed_device *dev)
1512 @@ -173,6 +244,9 @@ static inline bool mtk_wed_device_active
1513 #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0)
1514 #define mtk_wed_device_irq_get(_dev, _mask) 0
1515 #define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0)
1516 +#define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs) -ENODEV
1517 +#define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) do {} while (0)
1518 +#define mtk_wed_device_update_msg(_dev, _id, _msg, _len) -ENODEV