net: dsa: tag_qca: return early if dev is not found
Christian Marangi
maintainerPATCH v3 1/5 net: dsa: tag_qca: return early if dev is not found
Currently checksum is recalculated and dsa tag stripped even if we later don't find the dev.
To improve code, exit early if we don't find the dev and skip additional operation on the skb since it will be freed anyway.
---
changes v2:
- Add review tag
net/dsa/tag_qca.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa/tag_qca.c +4 -4
@@ -75,10 +75,6 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)return NULL ; } -/* Remove QCA tag and recalculate checksum */ -skb_pull_rcsum (skb,QCA_HDR_LEN ); -dsa_strip_etype_header (skb,QCA_HDR_LEN ); -/* Get source port information */ port =FIELD_GET (QCA_HDR_RECV_SOURCE_PORT , hdr);
@@ -86,6 +82,10 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)if (!skb->dev)return NULL ; +/* Remove QCA tag and recalculate checksum */ +skb_pull_rcsum (skb,QCA_HDR_LEN ); +dsa_strip_etype_header (skb,QCA_HDR_LEN ); +return skb; }
Signature · 1 line
2.40.1
Christian Marangi
maintainerPATCH v3 2/5 net: dsa: qca8k: make learning configurable and keep off if standalone
Address learning should initially be turned off by the driver for port operation in standalone mode, then the DSA core handles changes to it via ds->ops->port_bridge_flags().
Currently this is not the case for qca8k where learning is enabled unconditionally in qca8k_setup for every user port.
Handle ports configured in standalone mode by making the learning configurable and not enabling it by default.
Implement .port_pre_bridge_flags and .port_bridge_flags dsa ops to enable learning for bridge that request it and tweak .port_stp_state_set to correctly disable learning when port is configured in standalone mode.
---
changes v2:
- Add review tag
- Change qca8k_port_bridge_flags to be more explicit with flag handling as suggested by Vladimir
drivers/net/dsa/qca/qca8k-8xxx.c | 7 +++-- drivers/net/dsa/qca/qca8k-common.c | 48 ++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 6 ++++ 3 files changed, 58 insertions(+), 3 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +4 -3
@@ -1870,9 +1870,8 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; -/* Enable ARP Auto-learning by default */ - ret =regmap_set_bits (priv->regmap,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_LEARN ); + ret =regmap_clear_bits (priv->regmap,QCA8K_PORT_LOOKUP_CTRL (i), +QCA8K_PORT_LOOKUP_LEARN );if (ret)return ret;
@@ -1978,6 +1977,8 @@ static const struct dsa_switch_ops qca8k_switch_ops = { .port_change_mtu = qca8k_port_change_mtu, .port_max_mtu = qca8k_port_max_mtu, .port_stp_state_set = qca8k_port_stp_state_set, + .port_pre_bridge_flags = qca8k_port_pre_bridge_flags, + .port_bridge_flags = qca8k_port_bridge_flags, .port_bridge_join = qca8k_port_bridge_join, .port_bridge_leave = qca8k_port_bridge_leave, .port_fast_age = qca8k_port_fast_age,
drivers/net/dsa/qca/qca8k-common.c +48 -0
71 lines not on this page · raw message
drivers/net/dsa/qca/qca8k.h +6 -0
@@ -522,6 +522,12 @@ int qca8k_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);/* Common bridge function */ void qca8k_port_stp_state_set (struct dsa_switch *ds,int port,u8 state); +int qca8k_port_pre_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack); +int qca8k_port_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack); int qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge, bool *tx_fwd_offload,
Signature · 1 line
2.40.1
Christian Marangi
maintainerPATCH v3 3/5 net: dsa: qca8k: limit user ports access to the first CPU port on setup
In reply to Christian MarangiIn preparation for multi-CPU support, set CPU port LOOKUP MEMBER outside the port loop and setup the LOOKUP MEMBER mask for user ports only to the first CPU port.
This is to handle flooding condition where every CPU port is set as target and prevent packet duplication for unknown frames from user ports.
Secondary CPU port LOOKUP MEMBER mask will be setup later when port_change_master will be implemented.
---
changes v2:
- Add review tag
drivers/net/dsa/qca/qca8k-8xxx.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +6 -8
@@ -1850,18 +1850,16 @@ qca8k_setup(struct dsa_switch *ds)if (ret)return ret; +/* CPU port gets connected to all user ports of the switch */ + ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (cpu_port), +QCA8K_PORT_LOOKUP_MEMBER ,dsa_user_ports (ds)); +if (ret) +return ret; +/* Setup connection between CPU port & user ports * Configure specific switch configuration for ports */ for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { -/* CPU port gets connected to all user ports of the switch */ -if (dsa_is_cpu_port (ds, i)) { - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_MEMBER ,dsa_user_ports (ds)); -if (ret) -return ret; - } -/* Individual user ports get connected to CPU port only */ if (dsa_is_user_port (ds, i)) { ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
Signature · 1 line
2.40.1
Christian Marangi
maintainerPATCH v3 4/5 net: dsa: qca8k: move qca8xxx hol fixup to separate function
In reply to Christian MarangiMove qca8xxx hol fixup to separate function to tidy things up and to permit using a more efficent loop in future patch.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 78 +++++++++++++++++--------------- 1 file changed, 42 insertions(+), 36 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +42 -36
@@ -1756,6 +1756,46 @@ static int qca8k_connect_tag_protocol(struct dsa_switch *ds,return 0 ; } +static void qca8k_setup_hol_fixup (struct qca8k_priv *priv,int port) +{ +u32 mask; + +switch (port) { +/* The 2 CPU port and port 5 requires some different +* priority than any other ports. +*/ +case 0 : +case 5 : +case 6 : + mask =QCA8K_PORT_HOL_CTRL0_EG_PRI0 (0x3 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI1 (0x4 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI2 (0x4 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI3 (0x4 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI4 (0x6 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI5 (0x8 ) | +QCA8K_PORT_HOL_CTRL0_EG_PORT (0x1e ); +break ; +default : + mask =QCA8K_PORT_HOL_CTRL0_EG_PRI0 (0x3 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI1 (0x4 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI2 (0x6 ) | +QCA8K_PORT_HOL_CTRL0_EG_PRI3 (0x8 ) | +QCA8K_PORT_HOL_CTRL0_EG_PORT (0x19 ); + } +regmap_write (priv->regmap,QCA8K_REG_PORT_HOL_CTRL0 (port), mask); + + mask =QCA8K_PORT_HOL_CTRL1_ING (0x6 ) | +QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN | +QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN | +QCA8K_PORT_HOL_CTRL1_WRED_EN ; +regmap_update_bits (priv->regmap,QCA8K_REG_PORT_HOL_CTRL1 (port), +QCA8K_PORT_HOL_CTRL1_ING_BUF_MASK | +QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN | +QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN | +QCA8K_PORT_HOL_CTRL1_WRED_EN , + mask); +} +static int qca8k_setup (struct dsa_switch *ds) {
@@ -1895,42 +1935,8 @@ qca8k_setup(struct dsa_switch *ds)* missing settings to improve switch stability under load condition. * This problem is limited to qca8337 and other qca8k switch are not affected. */ -if (priv->switch_id ==QCA8K_ID_QCA8337 ) { -switch (i) { -/* The 2 CPU port and port 5 requires some different -* priority than any other ports. -*/ -case 0 : -case 5 : -case 6 : - mask =QCA8K_PORT_HOL_CTRL0_EG_PRI0 (0x3 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI1 (0x4 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI2 (0x4 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI3 (0x4 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI4 (0x6 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI5 (0x8 ) | -QCA8K_PORT_HOL_CTRL0_EG_PORT (0x1e ); -break ; -default : - mask =QCA8K_PORT_HOL_CTRL0_EG_PRI0 (0x3 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI1 (0x4 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI2 (0x6 ) | -QCA8K_PORT_HOL_CTRL0_EG_PRI3 (0x8 ) | -QCA8K_PORT_HOL_CTRL0_EG_PORT (0x19 ); - } -qca8k_write (priv,QCA8K_REG_PORT_HOL_CTRL0 (i), mask); - - mask =QCA8K_PORT_HOL_CTRL1_ING (0x6 ) | -QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN | -QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN | -QCA8K_PORT_HOL_CTRL1_WRED_EN ; -qca8k_rmw (priv,QCA8K_REG_PORT_HOL_CTRL1 (i), -QCA8K_PORT_HOL_CTRL1_ING_BUF_MASK | -QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN | -QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN | -QCA8K_PORT_HOL_CTRL1_WRED_EN , - mask); - } +if (priv->switch_id ==QCA8K_ID_QCA8337 ) +qca8k_setup_hol_fixup (priv, i); }/* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */
Signature · 1 line
2.40.1
Re: [net-next PATCH v3 4/5] net: dsa: qca8k: move qca8xxx hol fixup to separate function
Quoted 4 lines · Christian Marangi
Move qca8xxx hol fixup to separate function to tidy things up and to permit using a more efficent loop in future patch.
Signed-off-by Christian Marangi <[email protected]>
Signature · 1 line
Florian
Christian Marangi
maintainerPATCH v3 5/5 net: dsa: qca8k: use dsa_for_each macro instead of for loop
In reply to Christian MarangiConvert for loop to dsa_for_each macro to save some redundant write on unconnected/unused port and tidy things up.
---
changes v3:
- Fix compilation error with unfinished patch in v2
drivers/net/dsa/qca/qca8k-8xxx.c | 107 ++++++++++++++++--------------- 1 file changed, 54 insertions(+), 53 deletions(-)
drivers/net/dsa/qca/qca8k-8xxx.c +54 -53
@@ -1800,7 +1800,8 @@ static int qca8k_setup(struct dsa_switch *ds) {struct qca8k_priv *priv = ds->priv; -int cpu_port, ret, i; +struct dsa_port *dp; +int cpu_port, ret;u32 mask; cpu_port =qca8k_find_cpu_port (ds);
@@ -1855,27 +1856,27 @@ qca8k_setup(struct dsa_switch *ds)dev_warn (priv->dev,"mib init failed" );/* Initial setup of all ports */ -for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { +dsa_switch_for_each_port (dp, ds) {/* Disable forwarding by default on all ports */ - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i), + ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (dp->index),QCA8K_PORT_LOOKUP_MEMBER ,0 );if (ret)return ret; + } -/* Enable QCA header mode on all cpu ports */ -if (dsa_is_cpu_port (ds, i)) { - ret =qca8k_write (priv,QCA8K_REG_PORT_HDR_CTRL (i), -FIELD_PREP (QCA8K_PORT_HDR_CTRL_TX_MASK ,QCA8K_PORT_HDR_CTRL_ALL ) | -FIELD_PREP (QCA8K_PORT_HDR_CTRL_RX_MASK ,QCA8K_PORT_HDR_CTRL_ALL )); -if (ret) { -dev_err (priv->dev,"failed enabling QCA header mode" ); -return ret; - } +/* Disable MAC by default on all user ports */ +dsa_switch_for_each_user_port (dp, ds) +qca8k_port_set_status (priv, dp->index,0 ); + +/* Enable QCA header mode on all cpu ports */ +dsa_switch_for_each_cpu_port (dp, ds) { + ret =qca8k_write (priv,QCA8K_REG_PORT_HDR_CTRL (dp->index), +FIELD_PREP (QCA8K_PORT_HDR_CTRL_TX_MASK ,QCA8K_PORT_HDR_CTRL_ALL ) | +FIELD_PREP (QCA8K_PORT_HDR_CTRL_RX_MASK ,QCA8K_PORT_HDR_CTRL_ALL )); +if (ret) { +dev_err (priv->dev,"failed enabling QCA header mode on port %d" , dp->index); +return ret; } - -/* Disable MAC by default on all user ports */ -if (dsa_is_user_port (ds, i)) -qca8k_port_set_status (priv, i,0 ); }/* Forward all unknown frames to CPU port for Linux processing
@@ -1897,48 +1898,48 @@ qca8k_setup(struct dsa_switch *ds)return ret;/* Setup connection between CPU port & user ports -* Configure specific switch configuration for ports +* Individual user ports get connected to CPU port only */ -for (i =0 ; i <QCA8K_NUM_PORTS ; i++) { -/* Individual user ports get connected to CPU port only */ -if (dsa_is_user_port (ds, i)) { - ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_MEMBER , -BIT (cpu_port)); -if (ret) -return ret; - - ret =regmap_clear_bits (priv->regmap,QCA8K_PORT_LOOKUP_CTRL (i), -QCA8K_PORT_LOOKUP_LEARN ); -if (ret) -return ret; - -/* For port based vlans to work we need to set the -* default egress vid -*/ - ret =qca8k_rmw (priv,QCA8K_EGRESS_VLAN (i), -QCA8K_EGREES_VLAN_PORT_MASK (i), -QCA8K_EGREES_VLAN_PORT (i,QCA8K_PORT_VID_DEF )); -if (ret) -return ret; - - ret =qca8k_write (priv,QCA8K_REG_PORT_VLAN_CTRL0 (i), -QCA8K_PORT_VLAN_CVID (QCA8K_PORT_VID_DEF ) | -QCA8K_PORT_VLAN_SVID (QCA8K_PORT_VID_DEF )); -if (ret) -return ret; - } +dsa_switch_for_each_user_port (dp, ds) { +u8 port = dp->index; + + ret =qca8k_rmw (priv,QCA8K_PORT_LOOKUP_CTRL (port), +QCA8K_PORT_LOOKUP_MEMBER , +BIT (cpu_port)); +if (ret) +return ret; + + ret =regmap_clear_bits (priv->regmap,QCA8K_PORT_LOOKUP_CTRL (port), +QCA8K_PORT_LOOKUP_LEARN ); +if (ret) +return ret; -/* The port 5 of the qca8337 have some problem in flood condition. The -* original legacy driver had some specific buffer and priority settings -* for the different port suggested by the QCA switch team. Add this -* missing settings to improve switch stability under load condition. -* This problem is limited to qca8337 and other qca8k switch are not affected. +/* For port based vlans to work we need to set the +* default egress vid */ -if (priv->switch_id ==QCA8K_ID_QCA8337 ) -qca8k_setup_hol_fixup (priv, i); + ret =qca8k_rmw (priv,QCA8K_EGRESS_VLAN (port), +QCA8K_EGREES_VLAN_PORT_MASK (port), +QCA8K_EGREES_VLAN_PORT (port,QCA8K_PORT_VID_DEF )); +if (ret) +return ret; + + ret =qca8k_write (priv,QCA8K_REG_PORT_VLAN_CTRL0 (port), +QCA8K_PORT_VLAN_CVID (QCA8K_PORT_VID_DEF ) | +QCA8K_PORT_VLAN_SVID (QCA8K_PORT_VID_DEF )); +if (ret) +return ret; } +/* The port 5 of the qca8337 have some problem in flood condition. The +* original legacy driver had some specific buffer and priority settings +* for the different port suggested by the QCA switch team. Add this +* missing settings to improve switch stability under load condition. +* This problem is limited to qca8337 and other qca8k switch are not affected. +*/ +if (priv->switch_id ==QCA8K_ID_QCA8337 ) +dsa_switch_for_each_available_port (dp, ds) +qca8k_setup_hol_fixup (priv, dp->index); +/* Special GLOBAL_FC_THRESH value are needed for ar8327 switch */ if (priv->switch_id ==QCA8K_ID_QCA8327 ) { mask = QCA8K_GLOBAL_FC_GOL_XON_THRES(288) |
Signature · 1 line
2.40.1
Re: [net-next PATCH v3 5/5] net: dsa: qca8k: use dsa_for_each macro instead of for loop
Quoted 4 lines · Christian Marangi
Convert for loop to
dsa_for_eachmacro to save some redundant write on unconnected/unused port and tidy things up.Signed-off-by Christian Marangi <[email protected]>
Signature · 1 line
Florian
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 6 lines · On Sun, 30 Jul 2023 09:41:09 +0200 you wrote:
Currently checksum is recalculated and dsa tag stripped even if we later don't find the dev.
To improve code, exit early if we don't find the dev and skip additional operation on the skb since it will be freed anyway.
Quoted 6 lines
Signed-off-by Christian Marangi <[email protected]>Reviewed-by Simon Horman <[email protected]>Reviewed-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>[...]
Here is the summary with links:
- [net-next,v3,1/5] net: dsa: tag_qca: return early if dev is not found
https://git.kernel.org/netdev/net-next/c/de9db136dcc3 - [net-next,v3,2/5] net: dsa: qca8k: make learning configurable and keep off if standalone https://git.kernel.org/netdev/net-next/c/23cfc7172e52 - [net-next,v3,3/5] net: dsa: qca8k: limit user ports access to the first CPU port on setup https://git.kernel.org/netdev/net-next/c/18e8feae4a80 - [net-next,v3,4/5] net: dsa: qca8k: move qca8xxx hol fixup to separate function https://git.kernel.org/netdev/net-next/c/a9108b0712bf - [net-next,v3,5/5] net: dsa: qca8k: use dsa_for_each macro instead of for loop https://git.kernel.org/netdev/net-next/c/01e6f8ad8d26
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html