mtk_eth_soc rx vlan offload improvement + dsa hardware untag support
Subsystems (6)
Felix Fietkau
maintainerv4 cover mtk_eth_soc rx vlan offload improvement + dsa hardware untag support
This series improves rx vlan offloading on mtk_eth_soc and extends it to support hardware DSA untagging where possible.
This improves performance by avoiding calls into the DSA tag driver receive function, including mangling of skb->data.
This is split out of a previous series, which added other fixes and multiqueue support
Changes in v4:
- fix reverse christmas tree in dsa patch
- use skb_dst_drop to support metadata dst refcounting
- disable dsa untag offload in mtk_eth_soc if xdp is used
Felix Fietkau (4):
net: dsa: add support for DSA rx offloading via metadata dst
net: ethernet: mtk_eth_soc: pass correct VLAN protocol ID to the
network stack
net: ethernet: mtk_eth_soc: add support for configuring vlan rx
offload
net: ethernet: mtk_eth_soc: enable hardware DSA untagging
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 93 ++++++++++++++++++--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 8 ++ net/core/flow_dissector.c | 4 +- net/dsa/dsa.c | 19 ++++- 4 files changed, 109 insertions(+), 15 deletions(-)
Signature · 1 line
2.38.1
Felix Fietkau
maintainerPATCH v4 1/4 net: dsa: add support for DSA rx offloading via metadata dst
If a metadata dst is present with the type METADATA_HW_PORT_MUX on a dsa cpu port netdev, assume that it carries the port number and that there is no DSA tag present in the skb data.
--- net/core/flow_dissector.c | 4 +++- net/dsa/dsa.c | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-)
net/core/flow_dissector.c +3 -1
@@ -971,12 +971,14 @@ bool __skb_flow_dissect(const struct net *net,#if IS_ENABLED (CONFIG_NET_DSA )if (unlikely (skb->dev &&netdev_uses_dsa (skb->dev) && proto ==htons (ETH_P_XDSA ))) { +struct metadata_dst *md_dst =skb_metadata_dst (skb);const struct dsa_device_ops *ops;int offset =0 ; ops = skb->dev->dsa_ptr->tag_ops;/* Only DSA header taggers break flow dissection */ -if (ops->needed_headroom) { +if (ops->needed_headroom && + (!md_dst || md_dst->type !=METADATA_HW_PORT_MUX )) {if (ops->flow_dissect) ops->flow_dissect (skb, &proto, &offset);else
net/dsa/dsa.c +18 -1
@@ -11,6 +11,7 @@#include <linux/netdevice.h> #include <linux/sysfs.h> #include <linux/ptp_classify.h> +#include <net/dst_metadata.h> #include "dsa_priv.h"
@@ -216,6 +217,7 @@ static bool dsa_skb_defer_rx_timestamp(struct dsa_slave_priv *p,static int dsa_switch_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *unused) { +struct metadata_dst *md_dst =skb_metadata_dst (skb);struct dsa_port *cpu_dp = dev->dsa_ptr;struct sk_buff *nskb =NULL ;struct dsa_slave_priv *p;
@@ -229,7 +231,22 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,if (!skb)return 0 ; - nskb = cpu_dp->rcv (skb, dev); +if (md_dst && md_dst->type ==METADATA_HW_PORT_MUX ) { +unsigned int port = md_dst->u.port_info.port_id; + +skb_dst_drop (skb); +if (!skb_has_extensions (skb)) + skb->slow_gro =0 ; + + skb->dev =dsa_master_find_slave (dev,0 , port); +if (likely (skb->dev)) { +dsa_default_offload_fwd_mark (skb); + nskb = skb; + } + }else { + nskb = cpu_dp->rcv (skb, dev); + } +if (!nskb) {kfree_skb (skb);return 0 ;
Signature · 1 line
2.38.1
Re: [PATCH net-next v4 1/4] net: dsa: add support for DSA rx offloading via metadata dst
Quoted 6 lines · Felix Fietkau
If a metadata dst is present with the type
METADATA_HW_PORT_MUXon a dsa cpu port netdev, assume that it carries the port number and that there is no DSA tag present in the skb data.Signed-off-by Felix Fietkau <[email protected]>---
Re: [PATCH net-next v4 1/4] net: dsa: add support for DSA rx offloading via metadata dst
In reply to Felix FietkauQuoted 5 lines · Felix Fietkau
If a metadata dst is present with the type
METADATA_HW_PORT_MUXon a dsa cpu port netdev, assume that it carries the port number and that there is no DSA tag present in the skb data.Signed-off-by Felix Fietkau <[email protected]>
Is the plan to use the lwoer bits of the 32-bit port_id as the port number for now, and we can use the remaining 24 or so bits for passing classification (reason why we forward the packet, QoS etc. ) information in the future?
Might be time for me to revive the systemport patches supporting Broadcom tags in the the DMA descriptor.
Thanks!
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH net-next v4 1/4] net: dsa: add support for DSA rx offloading via metadata dst
Quoted 9 lines · Florian Fainelli
Quoted 5 lines · Felix Fietkau
If a metadata dst is present with the type
METADATA_HW_PORT_MUXon a dsa cpu port netdev, assume that it carries the port number and that there is no DSA tag present in the skb data.Signed-off-by Felix Fietkau <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Quoted 7 lines
Is the plan to use the lwoer bits of the 32-bit
port_idas the port number for now, and we can use the remaining 24 or so bits for passing classification (reason why we forward the packet, QoS etc. ) information in the future?Might be time for me to revive the systemport patches supporting Broadcom tags in the the DMA descriptor.
It's not really clear how to expand the HW_PORT_MUX model to provide QoS info and trap reason, without switching to per-packet allocation, which is what Jakub seemingly wanted to avoid with skb extensions (among other more minor things).
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/#25078661
Felix didn't present a need for more than the port id either, so this is why we have what we have right now.
Felix Fietkau
maintainerPATCH v4 2/4 net: ethernet: mtk_eth_soc: pass correct VLAN protocol ID to the network stack
In reply to Felix FietkauUse the id from the DMA descriptor instead of hardcoding 802.1q
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +1 -1
@@ -1936,7 +1936,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,htons (RX_DMA_VPID (trxd.rxd4)), RX_DMA_VID(trxd.rxd4)); }else if (trxd.rxd2 &RX_DMA_VTAG ) { -__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), +__vlan_hwaccel_put_tag (skb,htons (RX_DMA_VPID (trxd.rxd3)),RX_DMA_VID (trxd.rxd3)); }
Signature · 1 line
2.38.1
Felix Fietkau
maintainerPATCH v4 3/4 net: ethernet: mtk_eth_soc: add support for configuring vlan rx offload
In reply to Felix FietkauKeep the vlan rx offload feature in sync across all netdevs belonging to the device, since the feature is global and can't be turned off per MAC
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +20 -5
@@ -2724,15 +2724,30 @@ static netdev_features_t mtk_fix_features(struct net_device *dev,static int mtk_set_features (struct net_device *dev,netdev_features_t features) { -int err =0 ; +struct mtk_mac *mac =netdev_priv (dev); +struct mtk_eth *eth = mac->hw; +netdev_features_t diff = dev->features ^ features; +int i; -if (!((dev->features ^ features) &NETIF_F_LRO )) +if ((diff &NETIF_F_LRO ) && !(features &NETIF_F_LRO )) +mtk_hwlro_netdev_disable (dev); + +/* Set RX VLAN offloading */ +if (!(diff &NETIF_F_HW_VLAN_CTAG_RX ))return 0 ; -if (!(features &NETIF_F_LRO )) -mtk_hwlro_netdev_disable (dev); +mtk_w32 (eth, !!(features &NETIF_F_HW_VLAN_CTAG_RX ), +MTK_CDMP_EG_CTRL ); -return err; +/* sync features with other MAC */ +for (i =0 ; i <MTK_MAC_COUNT ; i++) { +if (!eth->netdev[i] || eth->netdev[i] == dev) +continue ; + eth->netdev[i]->features &= ~NETIF_F_HW_VLAN_CTAG_RX ; + eth->netdev[i]->features |= features &NETIF_F_HW_VLAN_CTAG_RX ; + } + +return 0 ; }/* wait for DMA to finish whatever it is doing before we start using it again */
Signature · 1 line
2.38.1
Felix Fietkau
maintainerPATCH v4 4/4 net: ethernet: mtk_eth_soc: enable hardware DSA untagging
In reply to Felix Fietkau- pass the tag to DSA via metadata dst
- disabled on 7986 for now, since it's not working yet
- disabled if a MAC is enabled that does not use DSA
This improves performance by bypassing the DSA tag driver and avoiding extra skb data mangling
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 66 ++++++++++++++++++--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 8 +++ 2 files changed, 67 insertions(+), 7 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +59 -7
@@ -23,6 +23,7 @@#include <linux/jhash.h> #include <linux/bitfield.h> #include <net/dsa.h> +#include <net/dst_metadata.h> #include "mtk_eth_soc.h" #include "mtk_wed.h"
@@ -1939,13 +1940,19 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,__vlan_hwaccel_put_tag (skb,htons (RX_DMA_VPID (trxd.rxd3)),RX_DMA_VID (trxd.rxd3)); } + } + +/* When using VLAN untagging in combination with DSA, the +* hardware treats the MTK special tag as a VLAN and untags it. +*/ +if (skb_vlan_tag_present (skb) &&netdev_uses_dsa (netdev)) { +unsigned int port =ntohs (skb->vlan_proto) &GENMASK (2 ,0 ); -/* If the device is attached to a dsa switch, the special -* tag inserted in VLAN field by hw switch can * be offloaded -* by RX HW VLAN offload. Clear vlan info. -*/ -if (netdev_uses_dsa (netdev)) -__vlan_hwaccel_clear_tag (skb); +if (port <ARRAY_SIZE (eth->dsa_meta) && + eth->dsa_meta[port]) +skb_dst_set_noref (skb, ð->dsa_meta[port]->dst); + +__vlan_hwaccel_clear_tag (skb); }skb_record_rx_queue (skb,0 );
@@ -2990,11 +2997,46 @@ static void mtk_gdm_config(struct mtk_eth *eth, u32 config)mtk_w32 (eth,0 ,MTK_RST_GL ); } + +static bool mtk_uses_dsa (struct net_device *dev) +{ +#if IS_ENABLED (CONFIG_NET_DSA ) +return netdev_uses_dsa (dev) && + dev->dsa_ptr->tag_ops->proto ==DSA_TAG_PROTO_MTK ; +#else +return false; +#endif +} +static int mtk_open (struct net_device *dev) {struct mtk_mac *mac =netdev_priv (dev);struct mtk_eth *eth = mac->hw; -int err; +int i, err; + +if (mtk_uses_dsa (dev) && !eth->prog) { +for (i =0 ; i <ARRAY_SIZE (eth->dsa_meta); i++) { +struct metadata_dst *md_dst = eth->dsa_meta[i]; + +if (md_dst) +continue ; + + md_dst =metadata_dst_alloc (0 ,METADATA_HW_PORT_MUX , +GFP_KERNEL ); +if (!md_dst) +return -ENOMEM ; + + md_dst->u.port_info.port_id = i; + eth->dsa_meta[i] = md_dst; + } + }else { +/* Hardware special tag parsing needs to be disabled if at least +* one MAC does not use DSA. +*/ +u32 val =mtk_r32 (eth,MTK_CDMP_IG_CTRL ); + val &= ~MTK_CDMP_STAG_EN ; +mtk_w32 (eth, val,MTK_CDMP_IG_CTRL ); + } err =phylink_of_phy_connect (mac->phylink, mac->of_node,0 );if (err) {
@@ -3321,6 +3363,10 @@ static int mtk_hw_init(struct mtk_eth *eth)*/ val =mtk_r32 (eth,MTK_CDMQ_IG_CTRL );mtk_w32 (eth, val |MTK_CDMQ_STAG_EN ,MTK_CDMQ_IG_CTRL ); +if (!MTK_HAS_CAPS (eth->soc->caps,MTK_NETSYS_V2 )) { + val =mtk_r32 (eth,MTK_CDMP_IG_CTRL ); +mtk_w32 (eth, val |MTK_CDMP_STAG_EN ,MTK_CDMP_IG_CTRL ); + }/* Enable RX VLan Offloading */ mtk_w32 (eth,1 ,MTK_CDMP_EG_CTRL );
@@ -3538,6 +3584,12 @@ static int mtk_free_dev(struct mtk_eth *eth)free_netdev (eth->netdev[i]); } +for (i =0 ; i <ARRAY_SIZE (eth->dsa_meta); i++) { +if (!eth->dsa_meta[i]) +break ; +metadata_dst_free (eth->dsa_meta[i]); + } +return 0 ; }
drivers/net/ethernet/mediatek/mtk_eth_soc.h +8 -0
@@ -22,6 +22,9 @@#include <linux/bpf_trace.h> #include "mtk_ppe.h" +#define MTK_MAX_DSA_PORTS 7 +#define MTK_DSA_PORT_MASK GENMASK(2, 0) +#define MTK_QDMA_PAGE_SIZE 2048#define MTK_MAX_RX_LENGTH 1536#define MTK_MAX_RX_LENGTH_2K 2048
@@ -91,6 +94,9 @@#define MTK_CDMQ_IG_CTRL 0x1400#define MTK_CDMQ_STAG_EN BIT(0) +/* CDMQ Exgress Control Register */ +#define MTK_CDMQ_EG_CTRL 0x1404 +/* CDMP Ingress Control Register */ #define MTK_CDMP_IG_CTRL 0x400#define MTK_CDMP_STAG_EN BIT(0)
@@ -1121,6 +1127,8 @@ struct mtk_eth {int ip_align; +struct metadata_dst *dsa_meta[MTK_MAX_DSA_PORTS ]; +struct mtk_ppe *ppe[2 ];struct rhashtable flow_table;
Signature · 1 line
2.38.1
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 14 Nov 2022 13:42:10 +0100 you wrote:
This series improves rx vlan offloading on
mtk_eth_socand extends it to support hardware DSA untagging where possible.
This improves performance by avoiding calls into the DSA tag driver receive function, including mangling ofskb->data.This is split out of a previous series, which added other fixes and multiqueue support
[...]
Here is the summary with links:
- [net-next,v4,1/4] net: dsa: add support for DSA rx offloading via metadata dst
https://git.kernel.org/netdev/net-next/c/570d0a588dfb - [net-next,v4,2/4] net: ethernet: mtk_eth_soc: pass correct VLAN protocol ID to the network stack https://git.kernel.org/netdev/net-next/c/190487031584 - [net-next,v4,3/4] net: ethernet: mtk_eth_soc: add support for configuring vlan rx offload https://git.kernel.org/netdev/net-next/c/08666cbb7dd5 - [net-next,v4,4/4] net: ethernet: mtk_eth_soc: enable hardware DSA untagging https://git.kernel.org/netdev/net-next/c/2d7605a72906
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html