1 From: Sujuan Chen <sujuan.chen@mediatek.com>
2 Date: Mon, 18 Sep 2023 12:29:16 +0200
3 Subject: [PATCH] net: ethernet: mtk_wed: introduce hw_rro support for MT7988
5 MT7988 SoC support 802.11 receive reordering offload in hw while
6 MT7986 SoC implements it through the firmware running on the mcu.
8 Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
11 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
14 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
15 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
17 #define MTK_WED_BUF_SIZE 2048
18 #define MTK_WED_PAGE_BUF_SIZE 128
19 #define MTK_WED_BUF_PER_PAGE (PAGE_SIZE / 2048)
20 -#define MTK_WED_RX_PAGE_BUF_PER_PAGE (PAGE_SIZE / 128)
21 +#define MTK_WED_RX_BUF_PER_PAGE (PAGE_SIZE / MTK_WED_PAGE_BUF_SIZE)
22 #define MTK_WED_RX_RING_SIZE 1536
23 #define MTK_WED_RX_PG_BM_CNT 8192
24 #define MTK_WED_AMSDU_BUF_SIZE (PAGE_SIZE << 4)
25 @@ -596,6 +596,68 @@ free_pagelist:
29 +mtk_wed_hwrro_buffer_alloc(struct mtk_wed_device *dev)
31 + int n_pages = MTK_WED_RX_PG_BM_CNT / MTK_WED_RX_BUF_PER_PAGE;
32 + struct mtk_wed_buf *page_list;
33 + struct mtk_wed_bm_desc *desc;
34 + dma_addr_t desc_phys;
35 + int i, page_idx = 0;
37 + if (!dev->wlan.hw_rro)
40 + page_list = kcalloc(n_pages, sizeof(*page_list), GFP_KERNEL);
44 + dev->hw_rro.size = dev->wlan.rx_nbuf & ~(MTK_WED_BUF_PER_PAGE - 1);
45 + dev->hw_rro.pages = page_list;
46 + desc = dma_alloc_coherent(dev->hw->dev,
47 + dev->wlan.rx_nbuf * sizeof(*desc),
48 + &desc_phys, GFP_KERNEL);
52 + dev->hw_rro.desc = desc;
53 + dev->hw_rro.desc_phys = desc_phys;
55 + for (i = 0; i < MTK_WED_RX_PG_BM_CNT; i += MTK_WED_RX_BUF_PER_PAGE) {
56 + dma_addr_t page_phys, buf_phys;
60 + page = __dev_alloc_page(GFP_KERNEL);
64 + page_phys = dma_map_page(dev->hw->dev, page, 0, PAGE_SIZE,
66 + if (dma_mapping_error(dev->hw->dev, page_phys)) {
71 + page_list[page_idx].p = page;
72 + page_list[page_idx++].phy_addr = page_phys;
73 + dma_sync_single_for_cpu(dev->hw->dev, page_phys, PAGE_SIZE,
76 + buf_phys = page_phys;
77 + for (s = 0; s < MTK_WED_RX_BUF_PER_PAGE; s++) {
78 + desc->buf0 = cpu_to_le32(buf_phys);
79 + buf_phys += MTK_WED_PAGE_BUF_SIZE;
83 + dma_sync_single_for_device(dev->hw->dev, page_phys, PAGE_SIZE,
91 mtk_wed_rx_buffer_alloc(struct mtk_wed_device *dev)
93 struct mtk_wed_bm_desc *desc;
94 @@ -612,7 +674,42 @@ mtk_wed_rx_buffer_alloc(struct mtk_wed_d
95 dev->rx_buf_ring.desc_phys = desc_phys;
96 dev->wlan.init_rx_buf(dev, dev->wlan.rx_npkt);
99 + return mtk_wed_hwrro_buffer_alloc(dev);
103 +mtk_wed_hwrro_free_buffer(struct mtk_wed_device *dev)
105 + struct mtk_wed_buf *page_list = dev->hw_rro.pages;
106 + struct mtk_wed_bm_desc *desc = dev->hw_rro.desc;
107 + int i, page_idx = 0;
109 + if (!dev->wlan.hw_rro)
116 + goto free_pagelist;
118 + for (i = 0; i < MTK_WED_RX_PG_BM_CNT; i += MTK_WED_RX_BUF_PER_PAGE) {
119 + dma_addr_t buf_addr = page_list[page_idx].phy_addr;
120 + void *page = page_list[page_idx++].p;
125 + dma_unmap_page(dev->hw->dev, buf_addr, PAGE_SIZE,
126 + DMA_BIDIRECTIONAL);
130 + dma_free_coherent(dev->hw->dev, dev->hw_rro.size * sizeof(*desc),
131 + desc, dev->hw_rro.desc_phys);
138 @@ -626,6 +723,28 @@ mtk_wed_free_rx_buffer(struct mtk_wed_de
139 dev->wlan.release_rx_buf(dev);
140 dma_free_coherent(dev->hw->dev, dev->rx_buf_ring.size * sizeof(*desc),
141 desc, dev->rx_buf_ring.desc_phys);
143 + mtk_wed_hwrro_free_buffer(dev);
147 +mtk_wed_hwrro_init(struct mtk_wed_device *dev)
149 + if (!mtk_wed_get_rx_capa(dev) || !dev->wlan.hw_rro)
152 + wed_set(dev, MTK_WED_RRO_PG_BM_RX_DMAM,
153 + FIELD_PREP(MTK_WED_RRO_PG_BM_RX_SDL0, 128));
155 + wed_w32(dev, MTK_WED_RRO_PG_BM_BASE, dev->hw_rro.desc_phys);
157 + wed_w32(dev, MTK_WED_RRO_PG_BM_INIT_PTR,
158 + MTK_WED_RRO_PG_BM_INIT_SW_TAIL_IDX |
159 + FIELD_PREP(MTK_WED_RRO_PG_BM_SW_TAIL_IDX,
160 + MTK_WED_RX_PG_BM_CNT));
162 + /* enable rx_page_bm to fetch dmad */
163 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_WED_RX_PG_BM_EN);
167 @@ -639,6 +758,8 @@ mtk_wed_rx_buffer_hw_init(struct mtk_wed
168 wed_w32(dev, MTK_WED_RX_BM_DYN_ALLOC_TH,
169 FIELD_PREP(MTK_WED_RX_BM_DYN_ALLOC_TH_H, 0xffff));
170 wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_WED_RX_BM_EN);
172 + mtk_wed_hwrro_init(dev);
176 @@ -934,6 +1055,8 @@ mtk_wed_bus_init(struct mtk_wed_device *
178 mtk_wed_set_wpdma(struct mtk_wed_device *dev)
182 if (mtk_wed_is_v1(dev->hw)) {
183 wed_w32(dev, MTK_WED_WPDMA_CFG_BASE, dev->wlan.wpdma_phys);
185 @@ -951,6 +1074,15 @@ mtk_wed_set_wpdma(struct mtk_wed_device
187 wed_w32(dev, MTK_WED_WPDMA_RX_GLO_CFG, dev->wlan.wpdma_rx_glo);
188 wed_w32(dev, dev->hw->soc->regmap.wpdma_rx_ring0, dev->wlan.wpdma_rx);
190 + if (!dev->wlan.hw_rro)
193 + wed_w32(dev, MTK_WED_RRO_RX_D_CFG(0), dev->wlan.wpdma_rx_rro[0]);
194 + wed_w32(dev, MTK_WED_RRO_RX_D_CFG(1), dev->wlan.wpdma_rx_rro[1]);
195 + for (i = 0; i < MTK_WED_RX_PAGE_QUEUES; i++)
196 + wed_w32(dev, MTK_WED_RRO_MSDU_PG_RING_CFG(i),
197 + dev->wlan.wpdma_rx_pg + i * 0x10);
201 @@ -1762,6 +1894,165 @@ mtk_wed_dma_enable(struct mtk_wed_device
205 +mtk_wed_start_hw_rro(struct mtk_wed_device *dev, u32 irq_mask, bool reset)
209 + wed_w32(dev, MTK_WED_WPDMA_INT_MASK, irq_mask);
210 + wed_w32(dev, MTK_WED_INT_MASK, irq_mask);
212 + if (!mtk_wed_get_rx_capa(dev) || !dev->wlan.hw_rro)
215 + wed_set(dev, MTK_WED_RRO_RX_D_CFG(2), MTK_WED_RRO_MSDU_PG_DRV_CLR);
216 + wed_w32(dev, MTK_WED_RRO_MSDU_PG_RING2_CFG,
217 + MTK_WED_RRO_MSDU_PG_DRV_CLR);
219 + wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_RRO_RX,
220 + MTK_WED_WPDMA_INT_CTRL_RRO_RX0_EN |
221 + MTK_WED_WPDMA_INT_CTRL_RRO_RX0_CLR |
222 + MTK_WED_WPDMA_INT_CTRL_RRO_RX1_EN |
223 + MTK_WED_WPDMA_INT_CTRL_RRO_RX1_CLR |
224 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RRO_RX0_DONE_TRIG,
225 + dev->wlan.rro_rx_tbit[0]) |
226 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RRO_RX1_DONE_TRIG,
227 + dev->wlan.rro_rx_tbit[1]));
229 + wed_w32(dev, MTK_WED_WPDMA_INT_CTRL_RRO_MSDU_PG,
230 + MTK_WED_WPDMA_INT_CTRL_RRO_PG0_EN |
231 + MTK_WED_WPDMA_INT_CTRL_RRO_PG0_CLR |
232 + MTK_WED_WPDMA_INT_CTRL_RRO_PG1_EN |
233 + MTK_WED_WPDMA_INT_CTRL_RRO_PG1_CLR |
234 + MTK_WED_WPDMA_INT_CTRL_RRO_PG2_EN |
235 + MTK_WED_WPDMA_INT_CTRL_RRO_PG2_CLR |
236 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RRO_PG0_DONE_TRIG,
237 + dev->wlan.rx_pg_tbit[0]) |
238 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RRO_PG1_DONE_TRIG,
239 + dev->wlan.rx_pg_tbit[1]) |
240 + FIELD_PREP(MTK_WED_WPDMA_INT_CTRL_RRO_PG2_DONE_TRIG,
241 + dev->wlan.rx_pg_tbit[2]));
243 + /* RRO_MSDU_PG_RING2_CFG1_FLD_DRV_EN should be enabled after
244 + * WM FWDL completed, otherwise RRO_MSDU_PG ring may broken
246 + wed_set(dev, MTK_WED_RRO_MSDU_PG_RING2_CFG,
247 + MTK_WED_RRO_MSDU_PG_DRV_EN);
249 + for (i = 0; i < MTK_WED_RX_QUEUES; i++) {
250 + struct mtk_wed_ring *ring = &dev->rx_rro_ring[i];
252 + if (!(ring->flags & MTK_WED_RING_CONFIGURED))
255 + if (mtk_wed_check_wfdma_rx_fill(dev, ring))
256 + dev_err(dev->hw->dev,
257 + "rx_rro_ring(%d) initialization failed\n", i);
260 + for (i = 0; i < MTK_WED_RX_PAGE_QUEUES; i++) {
261 + struct mtk_wed_ring *ring = &dev->rx_page_ring[i];
263 + if (!(ring->flags & MTK_WED_RING_CONFIGURED))
266 + if (mtk_wed_check_wfdma_rx_fill(dev, ring))
267 + dev_err(dev->hw->dev,
268 + "rx_page_ring(%d) initialization failed\n", i);
273 +mtk_wed_rro_rx_ring_setup(struct mtk_wed_device *dev, int idx,
274 + void __iomem *regs)
276 + struct mtk_wed_ring *ring = &dev->rx_rro_ring[idx];
278 + ring->wpdma = regs;
279 + wed_w32(dev, MTK_WED_RRO_RX_D_RX(idx) + MTK_WED_RING_OFS_BASE,
281 + wed_w32(dev, MTK_WED_RRO_RX_D_RX(idx) + MTK_WED_RING_OFS_COUNT,
282 + readl(regs + MTK_WED_RING_OFS_COUNT));
283 + ring->flags |= MTK_WED_RING_CONFIGURED;
287 +mtk_wed_msdu_pg_rx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs)
289 + struct mtk_wed_ring *ring = &dev->rx_page_ring[idx];
291 + ring->wpdma = regs;
292 + wed_w32(dev, MTK_WED_RRO_MSDU_PG_CTRL0(idx) + MTK_WED_RING_OFS_BASE,
294 + wed_w32(dev, MTK_WED_RRO_MSDU_PG_CTRL0(idx) + MTK_WED_RING_OFS_COUNT,
295 + readl(regs + MTK_WED_RING_OFS_COUNT));
296 + ring->flags |= MTK_WED_RING_CONFIGURED;
300 +mtk_wed_ind_rx_ring_setup(struct mtk_wed_device *dev, void __iomem *regs)
302 + struct mtk_wed_ring *ring = &dev->ind_cmd_ring;
303 + u32 val = readl(regs + MTK_WED_RING_OFS_COUNT);
306 + ring->wpdma = regs;
307 + wed_w32(dev, MTK_WED_IND_CMD_RX_CTRL1 + MTK_WED_RING_OFS_BASE,
308 + readl(regs) & 0xfffffff0);
310 + wed_w32(dev, MTK_WED_IND_CMD_RX_CTRL1 + MTK_WED_RING_OFS_COUNT,
311 + readl(regs + MTK_WED_RING_OFS_COUNT));
314 + wed_w32(dev, MTK_WED_RRO_CFG0, dev->wlan.phy_base +
315 + dev->wlan.ind_cmd.ack_sn_addr);
316 + wed_w32(dev, MTK_WED_RRO_CFG1,
317 + FIELD_PREP(MTK_WED_RRO_CFG1_MAX_WIN_SZ,
318 + dev->wlan.ind_cmd.win_size) |
319 + FIELD_PREP(MTK_WED_RRO_CFG1_PARTICL_SE_ID,
320 + dev->wlan.ind_cmd.particular_sid));
322 + /* particular session addr element */
323 + wed_w32(dev, MTK_WED_ADDR_ELEM_CFG0,
324 + dev->wlan.ind_cmd.particular_se_phys);
326 + for (i = 0; i < dev->wlan.ind_cmd.se_group_nums; i++) {
327 + wed_w32(dev, MTK_WED_RADDR_ELEM_TBL_WDATA,
328 + dev->wlan.ind_cmd.addr_elem_phys[i] >> 4);
329 + wed_w32(dev, MTK_WED_ADDR_ELEM_TBL_CFG,
330 + MTK_WED_ADDR_ELEM_TBL_WR | (i & 0x7f));
332 + val = wed_r32(dev, MTK_WED_ADDR_ELEM_TBL_CFG);
333 + while (!(val & MTK_WED_ADDR_ELEM_TBL_WR_RDY) && count++ < 100)
334 + val = wed_r32(dev, MTK_WED_ADDR_ELEM_TBL_CFG);
336 + dev_err(dev->hw->dev,
337 + "write ba session base failed\n");
340 + /* pn check init */
341 + for (i = 0; i < dev->wlan.ind_cmd.particular_sid; i++) {
342 + wed_w32(dev, MTK_WED_PN_CHECK_WDATA_M,
343 + MTK_WED_PN_CHECK_IS_FIRST);
345 + wed_w32(dev, MTK_WED_PN_CHECK_CFG, MTK_WED_PN_CHECK_WR |
346 + FIELD_PREP(MTK_WED_PN_CHECK_SE_ID, i));
349 + val = wed_r32(dev, MTK_WED_PN_CHECK_CFG);
350 + while (!(val & MTK_WED_PN_CHECK_WR_RDY) && count++ < 100)
351 + val = wed_r32(dev, MTK_WED_PN_CHECK_CFG);
353 + dev_err(dev->hw->dev,
354 + "session(%d) initialization failed\n", i);
357 + wed_w32(dev, MTK_WED_RX_IND_CMD_CNT0, MTK_WED_RX_IND_CMD_DBG_CNT_EN);
358 + wed_set(dev, MTK_WED_CTRL, MTK_WED_CTRL_WED_RX_IND_CMD_EN);
364 mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask)
367 @@ -2215,6 +2506,10 @@ void mtk_wed_add_hw(struct device_node *
368 .detach = mtk_wed_detach,
369 .ppe_check = mtk_wed_ppe_check,
370 .setup_tc = mtk_wed_setup_tc,
371 + .start_hw_rro = mtk_wed_start_hw_rro,
372 + .rro_rx_ring_setup = mtk_wed_rro_rx_ring_setup,
373 + .msdu_pg_rx_ring_setup = mtk_wed_msdu_pg_rx_ring_setup,
374 + .ind_rx_ring_setup = mtk_wed_ind_rx_ring_setup,
376 struct device_node *eth_np = eth->dev->of_node;
377 struct platform_device *pdev;
378 --- a/include/linux/soc/mediatek/mtk_wed.h
379 +++ b/include/linux/soc/mediatek/mtk_wed.h
382 #define MTK_WED_TX_QUEUES 2
383 #define MTK_WED_RX_QUEUES 2
384 +#define MTK_WED_RX_PAGE_QUEUES 3
386 #define WED_WO_STA_REC 0x6
388 @@ -99,6 +100,9 @@ struct mtk_wed_device {
389 struct mtk_wed_ring txfree_ring;
390 struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES];
391 struct mtk_wed_ring rx_wdma[MTK_WED_RX_QUEUES];
392 + struct mtk_wed_ring rx_rro_ring[MTK_WED_RX_QUEUES];
393 + struct mtk_wed_ring rx_page_ring[MTK_WED_RX_PAGE_QUEUES];
394 + struct mtk_wed_ring ind_cmd_ring;
398 @@ -120,6 +124,13 @@ struct mtk_wed_device {
399 dma_addr_t fdbk_phys;
404 + struct mtk_wed_buf *pages;
405 + struct mtk_wed_bm_desc *desc;
406 + dma_addr_t desc_phys;
409 /* filled by driver: */
412 @@ -138,6 +149,8 @@ struct mtk_wed_device {
416 + u32 wpdma_rx_rro[MTK_WED_RX_QUEUES];
421 @@ -152,9 +165,20 @@ struct mtk_wed_device {
423 u8 tx_tbit[MTK_WED_TX_QUEUES];
424 u8 rx_tbit[MTK_WED_RX_QUEUES];
425 + u8 rro_rx_tbit[MTK_WED_RX_QUEUES];
426 + u8 rx_pg_tbit[MTK_WED_RX_PAGE_QUEUES];
428 u8 amsdu_max_subframes;
433 + u16 particular_sid;
435 + dma_addr_t particular_se_phys;
436 + dma_addr_t addr_elem_phys[1024];
439 u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id);
440 int (*offload_enable)(struct mtk_wed_device *wed);
441 void (*offload_disable)(struct mtk_wed_device *wed);
442 @@ -193,6 +217,14 @@ struct mtk_wed_ops {
443 void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask);
444 int (*setup_tc)(struct mtk_wed_device *wed, struct net_device *dev,
445 enum tc_setup_type type, void *type_data);
446 + void (*start_hw_rro)(struct mtk_wed_device *dev, u32 irq_mask,
448 + void (*rro_rx_ring_setup)(struct mtk_wed_device *dev, int ring,
449 + void __iomem *regs);
450 + void (*msdu_pg_rx_ring_setup)(struct mtk_wed_device *dev, int ring,
451 + void __iomem *regs);
452 + int (*ind_rx_ring_setup)(struct mtk_wed_device *dev,
453 + void __iomem *regs);
456 extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops;
457 @@ -264,6 +296,15 @@ static inline bool mtk_wed_is_amsdu_supp
458 #define mtk_wed_device_dma_reset(_dev) (_dev)->ops->reset_dma(_dev)
459 #define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
460 (_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)
461 +#define mtk_wed_device_start_hw_rro(_dev, _mask, _reset) \
462 + (_dev)->ops->start_hw_rro(_dev, _mask, _reset)
463 +#define mtk_wed_device_rro_rx_ring_setup(_dev, _ring, _regs) \
464 + (_dev)->ops->rro_rx_ring_setup(_dev, _ring, _regs)
465 +#define mtk_wed_device_msdu_pg_rx_ring_setup(_dev, _ring, _regs) \
466 + (_dev)->ops->msdu_pg_rx_ring_setup(_dev, _ring, _regs)
467 +#define mtk_wed_device_ind_rx_ring_setup(_dev, _regs) \
468 + (_dev)->ops->ind_rx_ring_setup(_dev, _regs)
471 static inline bool mtk_wed_device_active(struct mtk_wed_device *dev)
473 @@ -283,6 +324,10 @@ static inline bool mtk_wed_device_active
474 #define mtk_wed_device_stop(_dev) do {} while (0)
475 #define mtk_wed_device_dma_reset(_dev) do {} while (0)
476 #define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) -EOPNOTSUPP
477 +#define mtk_wed_device_start_hw_rro(_dev, _mask, _reset) do {} while (0)
478 +#define mtk_wed_device_rro_rx_ring_setup(_dev, _ring, _regs) -ENODEV
479 +#define mtk_wed_device_msdu_pg_rx_ring_setup(_dev, _ring, _regs) -ENODEV
480 +#define mtk_wed_device_ind_rx_ring_setup(_dev, _regs) -ENODEV