Add RSS and LRO support
Subsystems (4)
v3 cover Add RSS and LRO support
From: Frank Wunderlich <[email protected]>
This series add RSS and LRO hardware acceleration for terminating traffic on MT798x.
It is currently only for discussion to get the upported SDK driver changes in a good shape.
patches are upported from mtk SDK:
- https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/refs/heads/master/master/files/target/linux/mediatek/patches-6.12/999-eth-08-mtk_eth_soc-add-register-definitions-for-rss-lro-reg.patch
- https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/refs/heads/master/master/files/target/linux/mediatek/patches-6.12/999-eth-09-mtk_eth_soc-add-rss-support.patch
- https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/refs/heads/master/master/files/target/linux/mediatek/patches-6.12/999-eth-10-mtk_eth_soc-add-hw-lro-support.patch
with additional fixes
changes:
v3:
- readded the change dropped in v2 because it was a fix
for getting RSS working on mt7986
- changes requested by jakub
- reworked coverletter (dropped instructions for configuration)
- name all PDMA-IRQ the same way
- retested on
- BPI-R3/mt7986 (RSS needs to be enabled)
- BPI-R4/mt7988
- BPI-R64/mt7622 and BPI-R2/mt7623 for not breaking network functionality
v2:
- drop wrong change (MTK_CDMP_IG_CTRL is only netsys v1)
- Fix immutable string IRQ setup (thx to Emilia Schotte)
- drop links to 6.6 patches/commits in sdk in comments
Mason Chang (3):
net: ethernet: mtk_eth_soc: Add register definitions for RSS and LRO
net: ethernet: mtk_eth_soc: Add RSS support
net: ethernet: mtk_eth_soc: Add LRO support
bpi-r4.its | 16 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 762 ++++++++++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 171 +++-- 3 files changed, 757 insertions(+), 192 deletions(-)
Signature · 1 line
2.43.0
RFC v3 1/3 net: ethernet: mtk_eth_soc: Add register definitions for RSS and LRO
From: Mason Chang <[email protected]>
Add definitions for Receive Side Scaling and Large Receive Offload support.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 23 +++++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 32 +++++++++++++++------ 2 files changed, 46 insertions(+), 9 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +23 -0
@@ -50,13 +50,18 @@ static const struct mtk_reg_map mtk_reg_map = { .rx_ptr = 0x0900, .rx_cnt_cfg = 0x0904, .pcrx_ptr = 0x0908, + .lro_ctrl_dw0 = 0x0980, .glo_cfg = 0x0a04, .rst_idx = 0x0a08, .delay_irq = 0x0a0c, .irq_status = 0x0a20, .irq_mask = 0x0a28, .adma_rx_dbg0 = 0x0a38, + .lro_alt_score_delta = 0x0a4c, .int_grp = 0x0a50, + .lro_rx1_dly_int = 0x0a70, + .lro_ring_dip_dw0 = 0x0b04, + .lro_ring_ctrl_dw1 = 0x0b28, }, .qdma = { .qtx_cfg = 0x1800,
@@ -113,6 +118,7 @@ static const struct mtk_reg_map mt7986_reg_map = { .tx_irq_mask = 0x461c, .tx_irq_status = 0x4618, .pdma = { + .rss_glo_cfg = 0x2800, .rx_ptr = 0x4100, .rx_cnt_cfg = 0x4104, .pcrx_ptr = 0x4108,
@@ -123,6 +129,12 @@ static const struct mtk_reg_map mt7986_reg_map = { .irq_mask = 0x4228, .adma_rx_dbg0 = 0x4238, .int_grp = 0x4250, + .int_grp3 = 0x422c, + .lro_ctrl_dw0 = 0x4180, + .lro_alt_score_delta = 0x424c, + .lro_rx1_dly_int = 0x4270, + .lro_ring_dip_dw0 = 0x4304, + .lro_ring_ctrl_dw1 = 0x4328, }, .qdma = { .qtx_cfg = 0x4400,
@@ -170,10 +182,21 @@ static const struct mtk_reg_map mt7988_reg_map = { .glo_cfg = 0x6a04, .rst_idx = 0x6a08, .delay_irq = 0x6a0c, + .rx_cfg = 0x6a10, .irq_status = 0x6a20, .irq_mask = 0x6a28, .adma_rx_dbg0 = 0x6a38, .int_grp = 0x6a50, + .int_grp3 = 0x6a58, + .tx_delay_irq = 0x6ab0, + .rx_delay_irq = 0x6ac0, + .lro_ctrl_dw0 = 0x6c08, + .lro_alt_score_delta = 0x6c1c, + .lro_ring_dip_dw0 = 0x6c14, + .lro_ring_ctrl_dw1 = 0x6c38, + .lro_alt_dbg = 0x6c40, + .lro_alt_dbg_data = 0x6c44, + .rss_glo_cfg = 0x7000, }, .qdma = { .qtx_cfg = 0x4400,
drivers/net/ethernet/mediatek/mtk_eth_soc.h +23 -9
@@ -1143,16 +1143,30 @@ struct mtk_reg_map {u32 tx_irq_mask;u32 tx_irq_status;struct { -u32 rx_ptr;/* rx base pointer */ -u32 rx_cnt_cfg;/* rx max count configuration */ -u32 pcrx_ptr;/* rx cpu pointer */ -u32 glo_cfg;/* global configuration */ -u32 rst_idx;/* reset index */ -u32 delay_irq;/* delay interrupt */ -u32 irq_status;/* interrupt status */ -u32 irq_mask;/* interrupt mask */ +u32 rx_ptr;/* rx base pointer */ +u32 rx_cnt_cfg;/* rx max count configuration */ +u32 pcrx_ptr;/* rx cpu pointer */ +u32 pdrx_ptr;/* rx dma pointer */ +u32 glo_cfg;/* global configuration */ +u32 rst_idx;/* reset index */ +u32 rx_cfg;/* rx dma configuration */ +u32 delay_irq;/* delay interrupt */ +u32 irq_status;/* interrupt status */ +u32 irq_mask;/* interrupt mask */ u32 adma_rx_dbg0; -u32 int_grp; +u32 int_grp;/* interrupt group1 */ +u32 int_grp3;/* interrupt group3 */ +u32 tx_delay_irq;/* tx delay interrupt */ +u32 rx_delay_irq;/* rx delay interrupt */ +u32 lro_ctrl_dw0;/* lro ctrl dword0 */ +u32 lro_alt_score_delta;/* lro auto-learn score delta */ +u32 lro_rx1_dly_int;/* lro rx ring1 delay interrupt */ +u32 lro_ring_dip_dw0;/* lro ring dip dword0 */ +u32 lro_ring_ctrl_dw1;/* lro ring ctrl dword1 */ +u32 lro_alt_dbg;/* lro auto-learn debug */ +u32 lro_alt_dbg_data;/* lro auto-learn debug data */ +u32 rss_glo_cfg;/* rss global configuration */ + } pdma;struct {u32 qtx_cfg;/* tx queue configuration */
Signature · 1 line
2.43.0
Re: [RFC net-next v3 1/3] net: ethernet: mtk_eth_soc: Add register definitions for RSS and LRO
Quoted 96 lines · Frank Wunderlich
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
From: Mason Chang <[email protected]>
Add definitions for Receive Side Scaling and Large Receive Offload support.
Signed-off-by Mason Chang <[email protected]>Signed-off-by Frank Wunderlich <[email protected]>--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 23 +++++++++++++++ drivers/net/ethernet/mediatek/mtk_eth_soc.h | 32 +++++++++++++++------ 2 files changed, 46 insertions(+), 9 deletions(-)drivers/net/ethernet/mediatek/mtk_eth_soc.c +23
-0@@ -50,13 +50,18 @@ static const struct mtk_reg_map mtk_reg_map = { .rx_ptr = 0x0900, .rx_cnt_cfg = 0x0904, .pcrx_ptr = 0x0908, + .lro_ctrl_dw0 = 0x0980, .glo_cfg = 0x0a04, .rst_idx = 0x0a08, .delay_irq = 0x0a0c, .irq_status = 0x0a20, .irq_mask = 0x0a28, .adma_rx_dbg0 = 0x0a38, + .lro_alt_score_delta = 0x0a4c, .int_grp = 0x0a50, + .lro_rx1_dly_int = 0x0a70, + .lro_ring_dip_dw0 = 0x0b04, + .lro_ring_ctrl_dw1 = 0x0b28, }, .qdma = { .qtx_cfg = 0x1800,@@ -113,6 +118,7 @@ static const struct mtk_reg_map mt7986_reg_map = { .tx_irq_mask = 0x461c, .tx_irq_status = 0x4618, .pdma = { + .rss_glo_cfg = 0x2800, .rx_ptr = 0x4100, .rx_cnt_cfg = 0x4104, .pcrx_ptr = 0x4108,@@ -123,6 +129,12 @@ static const struct mtk_reg_map mt7986_reg_map = { .irq_mask = 0x4228, .adma_rx_dbg0 = 0x4238, .int_grp = 0x4250, + .int_grp3 = 0x422c, + .lro_ctrl_dw0 = 0x4180, + .lro_alt_score_delta = 0x424c, + .lro_rx1_dly_int = 0x4270, + .lro_ring_dip_dw0 = 0x4304, + .lro_ring_ctrl_dw1 = 0x4328, }, .qdma = { .qtx_cfg = 0x4400,@@ -170,10 +182,21 @@ static const struct mtk_reg_map mt7988_reg_map = { .glo_cfg = 0x6a04, .rst_idx = 0x6a08, .delay_irq = 0x6a0c, + .rx_cfg = 0x6a10, .irq_status = 0x6a20, .irq_mask = 0x6a28, .adma_rx_dbg0 = 0x6a38, .int_grp = 0x6a50, + .int_grp3 = 0x6a58, + .tx_delay_irq = 0x6ab0, + .rx_delay_irq = 0x6ac0, + .lro_ctrl_dw0 = 0x6c08, + .lro_alt_score_delta = 0x6c1c, + .lro_ring_dip_dw0 = 0x6c14, + .lro_ring_ctrl_dw1 = 0x6c38, + .lro_alt_dbg = 0x6c40, + .lro_alt_dbg_data = 0x6c44, + .rss_glo_cfg = 0x7000, }, .qdma = { .qtx_cfg = 0x4400,drivers/net/ethernet/mediatek/mtk_eth_soc.h +0
-8@@ -1143,16 +1143,30 @@ struct mtk_reg_map {u32 tx_irq_mask;u32 tx_irq_status;struct { -u32 rx_ptr;/* rx base pointer */ -u32 rx_cnt_cfg;/* rx max count configuration */ -u32 pcrx_ptr;/* rx cpu pointer */ -u32 glo_cfg;/* global configuration */ -u32 rst_idx;/* reset index */ -u32 delay_irq;/* delay interrupt */ -u32 irq_status;/* interrupt status */ -u32 irq_mask;/* interrupt mask */
drivers/net/ethernet/mediatek/mtk_eth_soc.h struct mtk_reg_map { · line 1155
Quoted 10 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +10
-0+u32 rx_ptr;/* rx base pointer */ +u32 rx_cnt_cfg;/* rx max count configuration */ +u32 pcrx_ptr;/* rx cpu pointer */ +u32 pdrx_ptr;/* rx dma pointer */ +u32 glo_cfg;/* global configuration */ +u32 rst_idx;/* reset index */ +u32 rx_cfg;/* rx dma configuration */ +u32 delay_irq;/* delay interrupt */ +u32 irq_status;/* interrupt status */ +u32 irq_mask;/* interrupt mask */
Small nit - is the comment alignment really necessary?
Thanks,
Brett
Quoted 22 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +13
-2u32 adma_rx_dbg0; -u32 int_grp; +u32 int_grp;/* interrupt group1 */ +u32 int_grp3;/* interrupt group3 */ +u32 tx_delay_irq;/* tx delay interrupt */ +u32 rx_delay_irq;/* rx delay interrupt */ +u32 lro_ctrl_dw0;/* lro ctrl dword0 */ +u32 lro_alt_score_delta;/* lro auto-learn score delta */ +u32 lro_rx1_dly_int;/* lro rx ring1 delay interrupt */ +u32 lro_ring_dip_dw0;/* lro ring dip dword0 */ +u32 lro_ring_ctrl_dw1;/* lro ring ctrl dword1 */ +u32 lro_alt_dbg;/* lro auto-learn debug */ +u32 lro_alt_dbg_data;/* lro auto-learn debug data */ +u32 rss_glo_cfg;/* rss global configuration */ + } pdma;struct {u32 qtx_cfg;/* tx queue configuration */ --2.43.0
Re: [RFC net-next v3 1/3] net: ethernet: mtk_eth_soc: Add register definitions for RSS and LRO
Am 15. Dezember 2025 20:28:36 MEZ schrieb "Creeley, Brett" <[email protected]>:
Quoted 23 lines · Frank Wunderlich
Quoted 20 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +4
-8@@ -1143,16 +1143,30 @@ struct mtk_reg_map {u32 tx_irq_mask;u32 tx_irq_status;struct { -u32 rx_ptr;/* rx base pointer */ -u32 rx_cnt_cfg;/* rx max count configuration */ -u32 pcrx_ptr;/* rx cpu pointer */ -u32 glo_cfg;/* global configuration */ -u32 rst_idx;/* reset index */ -u32 delay_irq;/* delay interrupt */ -u32 irq_status;/* interrupt status */ -u32 irq_mask;/* interrupt mask */ +u32 rx_ptr;/* rx base pointer */ +u32 rx_cnt_cfg;/* rx max count configuration */ +u32 pcrx_ptr;/* rx cpu pointer */ +u32 pdrx_ptr;/* rx dma pointer */
Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h struct mtk_reg_map { · line 1155
Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +6
-0+u32 glo_cfg;/* global configuration */ +u32 rst_idx;/* reset index */ +u32 rx_cfg;/* rx dma configuration */ +u32 delay_irq;/* delay interrupt */ +u32 irq_status;/* interrupt status */ +u32 irq_mask;/* interrupt mask */ Small nit - is the comment alignment really necessary?
I could transform it to something like this:
Quoted 3 lines
Thanks,
Brett
regards Frank
Re: [RFC net-next v3 1/3] net: ethernet: mtk_eth_soc: Add register definitions for RSS and LRO
Quoted 33 lines · Frank Wunderlich
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Am 15. Dezember 2025 20:28:36 MEZ schrieb "Creeley, Brett" <[email protected]>:
Quoted 21 lines · Frank Wunderlich
Quoted 19 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +3
-8@@ -1143,16 +1143,30 @@ struct mtk_reg_map {u32 tx_irq_mask;u32 tx_irq_status;struct { -u32 rx_ptr;/* rx base pointer */ -u32 rx_cnt_cfg;/* rx max count configuration */ -u32 pcrx_ptr;/* rx cpu pointer */ -u32 glo_cfg;/* global configuration */ -u32 rst_idx;/* reset index */ -u32 delay_irq;/* delay interrupt */ -u32 irq_status;/* interrupt status */ -u32 irq_mask;/* interrupt mask */ +u32 rx_ptr;/* rx base pointer */ +u32 rx_cnt_cfg;/* rx max count configuration */ +u32 pcrx_ptr;/* rx cpu pointer */ Quoted 8 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h struct mtk_reg_map { · line 1155
Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +7
-0+u32 pdrx_ptr;/* rx dma pointer */ +u32 glo_cfg;/* global configuration */ +u32 rst_idx;/* reset index */ +u32 rx_cfg;/* rx dma configuration */ +u32 delay_irq;/* delay interrupt */ +u32 irq_status;/* interrupt status */ +u32 irq_mask;/* interrupt mask */ Small nit - is the comment alignment really necessary?
Quoted 3 lines
I could transform it to something like this:
I think it's okay as is. I was more concerned about the extra noise, but it's a pretty minimal change.
Brett
Quoted 7 lines
Quoted 4 lines
Thanks,
Brett
regards Frank
RFC v3 2/3 net: ethernet: mtk_eth_soc: Add RSS support
In reply to Frank WunderlichFrom: Mason Chang <[email protected]>
Add support for Receive Side Scaling.
We can adjust SMP affinity with the following command:
echo [CPU bitmap num] > /proc/irq/[virtual IRQ ID]/smp_affinity, with interrupts evenly assigned to 4 CPUs, we were able to measure an RX throughput of 7.3Gbps using iperf3 on the MT7988. Further optimizations will be carried out in the future.
The experimental command is as follows:
PC: iperf3 -c [IP] -P 10
DUT: iperf3 -s
The entire indirection table can be imagined as 128 buckets, we can use the ethtool command to mark which RX ring we want to send the packets in these buckets to.
Show RSS RX ring parameters in indirection table and RSS hash key:
ethtool -x [interface]
Change RSS RX rings weight under uniform distribution:
ethtool --set-rxfh-indir [interface] equal [ring num] Change RSS RX rings weight under non-uniform distribution:
ethtool --set-rxfh-indir [interface] weight [ring0 weight] [ring1 weight] [ring2 weight] [ring3 weight]
---
v3:
- changes requested by jakub
- readded rss fix for mt7986
- name all PDMA-IRQ the same way
v2:
- drop wrong change (MTK_CDMP_IG_CTRL is only netsys v1)
- Fix immutable string IRQ setup (thx to Emilia Schotte)
- drop link to no more existent 6.6 patch in comment
--- bpi-r4.its | 16 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 526 +++++++++++++++----- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 95 +++- 3 files changed, 492 insertions(+), 145 deletions(-)
bpi-r4.its +8 -8
@@ -40,7 +40,7 @@ algo = "sha1"; }; }; - fdt-base-r4pro-4e { + /*fdt-base-r4pro-4e { description = "Flattened Device Tree blob BPI-R4 Pro 4E"; data = /incbin/("./arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4-pro-4e.dtb"); type = "flat_dt";
@@ -72,7 +72,7 @@ hash-1 { algo = "sha1"; }; - }; + };*/ fdt-ov-sd { description = "Flattened Device Tree blob"; data = /incbin/("./arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4-sd.dtbo");
@@ -83,7 +83,7 @@ data = /incbin/("./arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4-emmc.dtbo"); type = "flat_dt"; }; - fdt-ov-lite-sd { + /*fdt-ov-lite-sd { description = "Flattened Device Tree blob"; data = /incbin/("./arch/arm64/boot/dts/mediatek/mt7987a-bananapi-bpi-r4-lite-sd.dtbo"); type = "flat_dt";
@@ -132,7 +132,7 @@ description = "DT overlay for R4Pro EMMC"; data = /incbin/("./arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4-pro-emmc.dtbo"); type = "flat_dt"; - }; + };*/ /* ramdisk-1 { description = "ramdisk"; data = /incbin/("./rootfs_arm64.cpio.gz");
@@ -165,7 +165,7 @@ algo = "sha1"; }; }; - conf-base-r4pro { + /*conf-base-r4pro { description = "Boot Linux kernel with base FDT blob for BPI-R4 Pro"; kernel = "kernel-1"; fdt = "fdt-base-r4pro-8x";
@@ -200,7 +200,7 @@ hash-1 { algo = "sha1"; }; - }; + };*/ conf-sd { description = "Boot Linux kernel with SD FDT blob"; kernel = "kernel-1";
@@ -227,7 +227,7 @@ description = "EMMC FDT overlay blob for R4"; fdt = "fdt-ov-emmc"; }; - ov-lite-sd { + /*ov-lite-sd { description = "SD FDT overlay blob for R4 Lite"; fdt = "fdt-ov-lite-sd"; };
@@ -266,6 +266,6 @@ ov-pro-cn18 { description = "CN18 FDT overlay blob for R4 Pro"; fdt = "fdt-ov-pro-cn18"; - }; + };*/ }; };
drivers/net/ethernet/mediatek/mtk_eth_soc.c +405 -121
939 lines not on this page · raw message
drivers/net/ethernet/mediatek/mtk_eth_soc.h +79 -16
217 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [RFC net-next v3 2/3] net: ethernet: mtk_eth_soc: Add RSS support
Quoted 1 line
bpi-r4.its | 16 +-
I don't think this file belongs in this patch?
drivers/net/ethernet/mediatek/mtk_eth_soc.h line 219
Quoted 5 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +5
-0+#define MTK_RX_RSS_NUM (eth->soc->rss_num) +#define MTK_RSS_HASH_KEY_DW (x) (reg_map->pdma.rss_glo_cfg + 0x20 + \ + ((x) * 0x4)) +#define MTK_RSS_INDR_TABLE_DW (x) (reg_map->pdma.rss_glo_cfg + 0x50 + \ + ((x) * 0x4))
It is bad practice for a macro to access things not passed to it. At minimum, pass eth & reg_map to the macro.
Andrew
---
pw-bot: cr
RFC v3 3/3 net: ethernet: mtk_eth_soc: Add LRO support
In reply to Frank WunderlichFrom: Mason Chang <[email protected]>
Add Large Receive Offload support to mediatek ethernet driver and activate it for MT7988.
---
v2:
- drop link to commit for 6.6 patch
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 213 ++++++++++++++++++-- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 48 +++-- 2 files changed, 221 insertions(+), 40 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +193 -20
@@ -2785,7 +2785,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)if (!ring->data)return -ENOMEM ; -if (mtk_page_pool_enabled (eth)) { +if (mtk_page_pool_enabled (eth) &&rcu_access_pointer (eth->prog)) {struct page_pool *pp; pp = mtk_create_page_pool(eth, &ring->xdp_q, ring_no,
@@ -2932,7 +2932,8 @@ static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring, bool in_static int mtk_hwlro_rx_init (struct mtk_eth *eth) {const struct mtk_reg_map *reg_map = eth->soc->reg_map; -int i; +const struct mtk_soc_data *soc = eth->soc; +int i, val;u32 ring_ctrl_dw1 =0 , ring_ctrl_dw2 =0 , ring_ctrl_dw3 =0 ;u32 lro_ctrl_dw0 =0 , lro_ctrl_dw3 =0 ;
@@ -2953,7 +2954,7 @@ static int mtk_hwlro_rx_init(struct mtk_eth *eth) ring_ctrl_dw2 |=MTK_RING_MAX_AGG_CNT_L ; ring_ctrl_dw3 |=MTK_RING_MAX_AGG_CNT_H ; -for (i =1 ; i <MTK_MAX_RX_RING_NUM ; i++) { +for (i =1 ; i <=MTK_HW_LRO_RING_NUM ; i++) {mtk_w32 (eth, ring_ctrl_dw1,MTK_LRO_CTRL_DW1_CFG (i));mtk_w32 (eth, ring_ctrl_dw2,MTK_LRO_CTRL_DW2_CFG (i));mtk_w32 (eth, ring_ctrl_dw3,MTK_LRO_CTRL_DW3_CFG (i));
@@ -2975,8 +2976,22 @@ static int mtk_hwlro_rx_init(struct mtk_eth *eth)mtk_w32 (eth, (MTK_HW_LRO_TIMER_UNIT <<16 ) |MTK_HW_LRO_REFRESH_TIME ,MTK_PDMA_LRO_ALT_REFRESH_TIMER ); -/* set HW LRO mode & the max aggregation count for rx packets */ - lro_ctrl_dw3 |=MTK_ADMA_MODE | (MTK_HW_LRO_MAX_AGG_CNT &0xff ); +if (mtk_is_netsys_v3_or_greater (eth)) { + val =mtk_r32 (eth, reg_map->pdma.rx_cfg); +mtk_w32 (eth, val | ((MTK_PDMA_LRO_SDL +MTK_MAX_RX_LENGTH ) << +MTK_RX_CFG_SDL_OFFSET ), reg_map->pdma.rx_cfg); + + lro_ctrl_dw0 |=MTK_PDMA_LRO_SDL <<MTK_CTRL_DW0_SDL_OFFSET ; + +/* enable cpu reason black list */ + lro_ctrl_dw0 |=MTK_LRO_CRSN_BNW ; + +/* no use PPE cpu reason */ +mtk_w32 (eth,0xffffffff ,MTK_PDMA_LRO_CTRL_DW1 ); + }else { +/* set HW LRO mode & the max aggregation count for rx packets */ + lro_ctrl_dw3 |=MTK_ADMA_MODE | (MTK_HW_LRO_MAX_AGG_CNT &0xff ); + }/* the minimal remaining room of SDL0 in RXD for lro aggregation */ lro_ctrl_dw3 |=MTK_LRO_MIN_RXD_SDL ;
@@ -2987,6 +3002,16 @@ static int mtk_hwlro_rx_init(struct mtk_eth *eth)mtk_w32 (eth, lro_ctrl_dw3,MTK_PDMA_LRO_CTRL_DW3 );mtk_w32 (eth, lro_ctrl_dw0,MTK_PDMA_LRO_CTRL_DW0 ); +if (mtk_is_netsys_v2_or_greater (eth)) { + i = (soc->rx.desc_size ==sizeof (struct mtk_rx_dma_v2 )) ?1 :0 ; +mtk_m32 (eth,MTK_RX_DONE_INT (MTK_HW_LRO_RING (i)), +MTK_RX_DONE_INT (MTK_HW_LRO_RING (i)), reg_map->pdma.int_grp); +mtk_m32 (eth,MTK_RX_DONE_INT (MTK_HW_LRO_RING (i +1 )), +MTK_RX_DONE_INT (MTK_HW_LRO_RING (i +1 )), reg_map->pdma.int_grp +0x4 ); +mtk_m32 (eth,MTK_RX_DONE_INT (MTK_HW_LRO_RING (i +2 )), +MTK_RX_DONE_INT (MTK_HW_LRO_RING (i +2 )), reg_map->pdma.int_grp3); + } +return 0 ; }
@@ -3010,7 +3035,7 @@ static void mtk_hwlro_rx_uninit(struct mtk_eth *eth) }/* invalidate lro rings */ -for (i =1 ; i <MTK_MAX_RX_RING_NUM ; i++) +for (i =1 ; i <=MTK_HW_LRO_RING_NUM ; i++)mtk_w32 (eth,0 ,MTK_LRO_CTRL_DW2_CFG (i));/* disable HW LRO */
@@ -3059,6 +3084,64 @@ static int mtk_hwlro_get_ip_cnt(struct mtk_mac *mac)return cnt; } +static int mtk_hwlro_add_ipaddr_idx (struct net_device *dev,u32 ip4dst) +{ +struct mtk_mac *mac =netdev_priv (dev); +struct mtk_eth *eth = mac->hw; +const struct mtk_reg_map *reg_map = eth->soc->reg_map; +u32 reg_val; +int i; + +/* check for duplicate IP address in the current DIP list */ +for (i =1 ; i <=MTK_HW_LRO_DIP_NUM ; i++) { + reg_val =mtk_r32 (eth,MTK_LRO_DIP_DW0_CFG (i)); +if (reg_val == ip4dst) +break ; + } + +if (i <MTK_HW_LRO_DIP_NUM +1 ) { +netdev_warn (dev,"Duplicate IP address at DIP(%d)!\n" , i); +return -EEXIST ; + } + +/* find out available DIP index */ +for (i =1 ; i <=MTK_HW_LRO_DIP_NUM ; i++) { + reg_val =mtk_r32 (eth,MTK_LRO_DIP_DW0_CFG (i)); +if (reg_val ==0UL ) +break ; + } + +if (i >=MTK_HW_LRO_DIP_NUM +1 ) { +netdev_warn (dev,"DIP index is currently out of resource!\n" ); +return -EBUSY ; + } + +return i; +} + +static int mtk_hwlro_get_ipaddr_idx (struct net_device *dev,u32 ip4dst) +{ +struct mtk_mac *mac =netdev_priv (dev); +struct mtk_eth *eth = mac->hw; +const struct mtk_reg_map *reg_map = eth->soc->reg_map; +u32 reg_val; +int i; + +/* find out DIP index that matches the given IP address */ +for (i =1 ; i <=MTK_HW_LRO_DIP_NUM ; i++) { + reg_val =mtk_r32 (eth,MTK_LRO_DIP_DW0_CFG (i)); +if (reg_val == ip4dst) +break ; + } + +if (i >=MTK_HW_LRO_DIP_NUM +1 ) { +netdev_warn (dev,"DIP address is not exist!\n" ); +return -ENOENT ; + } + +return i; +} +static int mtk_hwlro_add_ipaddr (struct net_device *dev,struct ethtool_rxnfc *cmd) {
@@ -3067,15 +3150,19 @@ static int mtk_hwlro_add_ipaddr(struct net_device *dev,struct mtk_mac *mac =netdev_priv (dev);struct mtk_eth *eth = mac->hw;int hwlro_idx; +u32 ip4dst;if ((fsp->flow_type !=TCP_V4_FLOW ) || (!fsp->h_u.tcp_ip4_spec.ip4dst) || (fsp->location >1 ))return -EINVAL ; - mac->hwlro_ip[fsp->location] =htonl (fsp->h_u.tcp_ip4_spec.ip4dst); - hwlro_idx = (mac->id *MTK_MAX_LRO_IP_CNT ) + fsp->location; + ip4dst =htonl (fsp->h_u.tcp_ip4_spec.ip4dst); + hwlro_idx =mtk_hwlro_add_ipaddr_idx (dev, ip4dst); +if (hwlro_idx <0 ) +return hwlro_idx; + mac->hwlro_ip[fsp->location] = ip4dst; mac->hwlro_ip_cnt =mtk_hwlro_get_ip_cnt (mac);mtk_hwlro_val_ipaddr (eth, hwlro_idx, mac->hwlro_ip[fsp->location]);
@@ -3091,13 +3178,17 @@ static int mtk_hwlro_del_ipaddr(struct net_device *dev,struct mtk_mac *mac =netdev_priv (dev);struct mtk_eth *eth = mac->hw;int hwlro_idx; +u32 ip4dst;if (fsp->location >1 )return -EINVAL ; - mac->hwlro_ip[fsp->location] =0 ; - hwlro_idx = (mac->id *MTK_MAX_LRO_IP_CNT ) + fsp->location; + ip4dst = mac->hwlro_ip[fsp->location]; + hwlro_idx =mtk_hwlro_get_ipaddr_idx (dev, ip4dst); +if (hwlro_idx <0 ) +return hwlro_idx; + mac->hwlro_ip[fsp->location] =0 ; mac->hwlro_ip_cnt =mtk_hwlro_get_ip_cnt (mac);mtk_hwlro_inval_ipaddr (eth, hwlro_idx);
@@ -3105,6 +3196,24 @@ static int mtk_hwlro_del_ipaddr(struct net_device *dev,return 0 ; } +static void mtk_hwlro_netdev_enable (struct net_device *dev) +{ +struct mtk_mac *mac =netdev_priv (dev); +struct mtk_eth *eth = mac->hw; +int i, hwlro_idx; + +for (i =0 ; i <MTK_MAX_LRO_IP_CNT ; i++) { +if (mac->hwlro_ip[i] ==0 ) +continue ; + + hwlro_idx =mtk_hwlro_get_ipaddr_idx (dev, mac->hwlro_ip[i]); +if (hwlro_idx <0 ) +continue ; + +mtk_hwlro_val_ipaddr (eth, hwlro_idx, mac->hwlro_ip[i]); + } +} +static void mtk_hwlro_netdev_disable (struct net_device *dev) {struct mtk_mac *mac =netdev_priv (dev);
@@ -3112,8 +3221,14 @@ static void mtk_hwlro_netdev_disable(struct net_device *dev)int i, hwlro_idx;for (i =0 ; i <MTK_MAX_LRO_IP_CNT ; i++) { +if (mac->hwlro_ip[i] ==0 ) +continue ; + + hwlro_idx =mtk_hwlro_get_ipaddr_idx (dev, mac->hwlro_ip[i]); +if (hwlro_idx <0 ) +continue ; + mac->hwlro_ip[i] =0 ; - hwlro_idx = (mac->id *MTK_MAX_LRO_IP_CNT ) + i;mtk_hwlro_inval_ipaddr (eth, hwlro_idx); }
@@ -3293,6 +3408,8 @@ static int mtk_set_features(struct net_device *dev, netdev_features_t features)if ((diff &NETIF_F_LRO ) && !(features &NETIF_F_LRO ))mtk_hwlro_netdev_disable (dev); +else if ((diff &NETIF_F_LRO ) && (features &NETIF_F_LRO )) +mtk_hwlro_netdev_enable (dev);return 0 ; }
@@ -3350,8 +3467,8 @@ static int mtk_dma_init(struct mtk_eth *eth)return err;if (eth->hwlro) { -for (i =1 ; i <MTK_MAX_RX_RING_NUM ; i++) { - err =mtk_rx_alloc (eth, i,MTK_RX_FLAGS_HWLRO ); +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { + err =mtk_rx_alloc (eth,MTK_HW_LRO_RING (i),MTK_RX_FLAGS_HWLRO );if (err)return err; }
@@ -3413,8 +3530,8 @@ static void mtk_dma_free(struct mtk_eth *eth)if (eth->hwlro) {mtk_hwlro_rx_uninit (eth); -for (i =1 ; i <MTK_MAX_RX_RING_NUM ; i++) -mtk_rx_clean (eth, ð->rx_ring[i], false); +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) +mtk_rx_clean (eth, ð->rx_ring[MTK_HW_LRO_RING (i)], false); }if (MTK_HAS_CAPS (eth->soc->caps,MTK_RSS )) {
@@ -3609,16 +3726,21 @@ static int mtk_start_dma(struct mtk_eth *eth) val |=MTK_RX_BT_32DWORDS ;mtk_w32 (eth, val, reg_map->qdma.glo_cfg); -mtk_w32 (eth, -MTK_RX_DMA_EN | rx_2b_offset | -MTK_RX_BT_32DWORDS |MTK_MULTI_EN , - reg_map->pdma.glo_cfg); + val =mtk_r32 (eth, reg_map->pdma.glo_cfg); + val |=MTK_RX_DMA_EN | rx_2b_offset | +MTK_RX_BT_32DWORDS |MTK_MULTI_EN ; +mtk_w32 (eth, val, reg_map->pdma.glo_cfg); }else {mtk_w32 (eth,MTK_TX_WB_DDONE |MTK_TX_DMA_EN |MTK_RX_DMA_EN |MTK_MULTI_EN |MTK_PDMA_SIZE_8DWORDS , reg_map->pdma.glo_cfg); } +if (eth->hwlro &&mtk_is_netsys_v3_or_greater (eth)) { + val =mtk_r32 (eth, reg_map->pdma.glo_cfg); +mtk_w32 (eth, val |MTK_RX_DMA_LRO_EN , reg_map->pdma.glo_cfg); + } +return 0 ; }
@@ -3762,6 +3884,13 @@ static int mtk_open(struct net_device *dev) } } +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { +napi_enable (ð->rx_napi[MTK_HW_LRO_RING (i)].napi); +mtk_rx_irq_enable (eth,MTK_RX_DONE_INT (MTK_HW_LRO_RING (i))); + } + } +refcount_set (ð->dma_refcnt,1 ); }else {refcount_inc (ð->dma_refcnt);
@@ -3857,6 +3986,14 @@ static int mtk_stop(struct net_device *dev) } } +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { +mtk_rx_irq_disable (eth,MTK_RX_DONE_INT (MTK_HW_LRO_RING (i))); +napi_synchronize (ð->rx_napi[MTK_HW_LRO_RING (i)].napi); +napi_disable (ð->rx_napi[MTK_HW_LRO_RING (i)].napi); + } + } +cancel_work_sync (ð->rx_dim.work);cancel_work_sync (ð->tx_dim.work);
@@ -4256,6 +4393,14 @@ static int mtk_napi_init(struct mtk_eth *eth) } } +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { + rx_napi = ð->rx_napi[MTK_HW_LRO_RING (i)]; + rx_napi->eth = eth; + rx_napi->rx_ring = ð->rx_ring[MTK_HW_LRO_RING (i)]; + } + } +return 0 ; }
@@ -4818,7 +4963,7 @@ static int mtk_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,switch (cmd->cmd) {case ETHTOOL_GRXRINGS :if (dev->hw_features &NETIF_F_LRO ) { - cmd->data =MTK_MAX_RX_RING_NUM ; + cmd->data =MTK_HW_LRO_RING_NUM ; ret =0 ; }else if (MTK_HAS_CAPS (eth->soc->caps,MTK_RSS )) { cmd->data =MTK_RX_RSS_NUM ;
@@ -5523,6 +5668,21 @@ static int mtk_probe(struct platform_device *pdev) goto err_free_dev; } } + +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { + irqname =devm_kasprintf (eth->dev,GFP_KERNEL , +"%s LRO RX %d" , +dev_name (eth->dev), i); + err =devm_request_irq (eth->dev, + eth->irq_pdma[MTK_HW_LRO_IRQ (i)], + mtk_handle_irq_rx,IRQF_SHARED , + irqname, + ð->rx_napi[MTK_HW_LRO_RING (i)]); +if (err) + goto err_free_dev; + } + } }else { irqname =devm_kasprintf (eth->dev,GFP_KERNEL ,"%s RX" ,dev_name (eth->dev));
@@ -5594,6 +5754,13 @@ static int mtk_probe(struct platform_device *pdev) mtk_napi_rx); } +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) { +netif_napi_add (eth->dummy_dev, ð->rx_napi[MTK_HW_LRO_RING (i)].napi, + mtk_napi_rx); + } + } +platform_set_drvdata (pdev, eth);schedule_delayed_work (ð->reset.monitor_work,MTK_DMA_MONITOR_TIMEOUT );
@@ -5642,6 +5809,12 @@ static void mtk_remove(struct platform_device *pdev)for (i =1 ; i <MTK_RX_RSS_NUM ; i++)netif_napi_del (ð->rx_napi[MTK_RSS_RING (i)].napi); } + +if (eth->hwlro) { +for (i =0 ; i <MTK_HW_LRO_RING_NUM ; i++) +netif_napi_del (ð->rx_napi[MTK_HW_LRO_RING (i)].napi); + } +mtk_cleanup (eth);free_netdev (eth->dummy_dev);mtk_mdio_cleanup (eth);
drivers/net/ethernet/mediatek/mtk_eth_soc.h +28 -20
100 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [RFC net-next v3 3/3] net: ethernet: mtk_eth_soc: Add LRO support
drivers/net/ethernet/mediatek/mtk_eth_soc.c static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring, bool in_ · line 2938
Quoted 8 lines
static int
mtk_hwlro_rx_init(struct mtk_eth *eth){drivers/net/ethernet/mediatek/mtk_eth_soc.c +2
-1const struct mtk_reg_map *reg_map = eth->soc->reg_map; -int i; +const struct mtk_soc_data *soc = eth->soc; +int i, val;u32 ring_ctrl_dw1 =0 , ring_ctrl_dw2 =0 , ring_ctrl_dw3 =0 ;u32 lro_ctrl_dw0 =0 , lro_ctrl_dw3 =0 ;
Reverse Christmas tree. It looks like it was already broken, but you should not make it worse, and i think you can even fix it here.
drivers/net/ethernet/mediatek/mtk_eth_soc.c static int mtk_hwlro_get_ip_cnt(struct mtk_mac *mac) · line 3093
Quoted 7 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +7
-0+static int mtk_hwlro_add_ipaddr_idx (struct net_device *dev,u32 ip4dst) +{ +struct mtk_mac *mac =netdev_priv (dev); +struct mtk_eth *eth = mac->hw; +const struct mtk_reg_map *reg_map = eth->soc->reg_map; +u32 reg_val; +int i;
More Reverse Christmas tree probes. You will need to move the assignment to reg_map into the body of the function.
drivers/net/ethernet/mediatek/mtk_eth_soc.h line 204
Quoted 4 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.h +4
-0+#define MTK_PDMA_LRO_CTRL_DW0 (reg_map->pdma.lro_ctrl_dw0) +#define MTK_PDMA_LRO_CTRL_DW1 (reg_map->pdma.lro_ctrl_dw0 + 0x04) +#define MTK_PDMA_LRO_CTRL_DW2 (reg_map->pdma.lro_ctrl_dw0 + 0x08) +#define MTK_PDMA_LRO_CTRL_DW3 (reg_map->pdma.lro_ctrl_dw0 + 0x0c)
Same comment as the previous patch.
Andrew