Configure the MTU on DSA switches
Subsystems (9)
Vladimir Oltean
maintainerv3 cover Configure the MTU on DSA switches
From: Vladimir Oltean <[email protected]>
This series adds support for configuring the MTU on front-panel switch ports, while seamlessly adapting the CPU port and the DSA master to the largest value plus the tagger overhead.
It also implements bridge MTU auto-normalization within the DSA core, as resulted after the feedback of the implementation of this feature inside the bridge driver in v2.
Support was added for quite a number of switches, in the hope that this series would gain some traction:
- sja1105
- felix
- vsc73xx
- b53 and rest of the platform
V2 of this series was submitted here:
https://patchwork.ozlabs.org/cover/1261471/
V1 of this series was submitted here:
https://patchwork.ozlabs.org/cover/1199868/
Murali Krishna Policharla (3):
net: phy: bcm7xx: add jumbo frame configuration to PHY
bgmac: configure MTU and add support for frames beyond 8192 byte size
net: dsa: b53: add MTU configuration support
Vladimir Oltean (5):
net: dsa: configure the MTU for switch ports
net: dsa: implement auto-normalization of MTU for bridge hardware
datapath
net: dsa: sja1105: implement the port MTU callbacks
net: dsa: vsc73xx: make the MTU configurable
net: dsa: felix: support changing the MTU
drivers/net/dsa/b53/b53_common.c | 27 ++- drivers/net/dsa/ocelot/felix.c | 19 +++ drivers/net/dsa/sja1105/sja1105.h | 1 + drivers/net/dsa/sja1105/sja1105_main.c | 50 +++++- drivers/net/dsa/vitesse-vsc73xx-core.c | 30 ++-- drivers/net/ethernet/broadcom/bgmac.c | 12 ++ drivers/net/ethernet/broadcom/bgmac.h | 5 +- drivers/net/ethernet/mscc/ocelot.c | 45 +++-- drivers/net/phy/bcm-phy-lib.c | 22 +++ drivers/net/phy/bcm-phy-lib.h | 1 + drivers/net/phy/bcm7xxx.c | 4 + include/linux/brcmphy.h | 2 + include/net/dsa.h | 16 ++ include/soc/mscc/ocelot.h | 7 + net/dsa/dsa2.c | 2 +- net/dsa/dsa_priv.h | 15 ++ net/dsa/master.c | 23 +-- net/dsa/port.c | 13 ++ net/dsa/slave.c | 219 ++++++++++++++++++++++++- net/dsa/switch.c | 37 +++++ 20 files changed, 502 insertions(+), 48 deletions(-)
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 1/8 net: phy: bcm7xx: add jumbo frame configuration to PHY
From: Murali Krishna Policharla <[email protected]>
The BCM7XX PHY family requires special configuration to pass jumbo frames. Do that during initial PHY setup.
---
Changes in v3:
Using the bcm54xx_auxctl_read and phy_set_bits helpers. Corrected the value of the shadow register from 7 to 0.
Changes in v2:
Patch is new.
drivers/net/phy/bcm-phy-lib.c | 22 ++++++++++++++++++++++ drivers/net/phy/bcm-phy-lib.h | 1 + drivers/net/phy/bcm7xxx.c | 4 ++++ include/linux/brcmphy.h | 2 ++ 4 files changed, 29 insertions(+)
drivers/net/phy/bcm-phy-lib.c +22 -0
@@ -423,6 +423,28 @@ int bcm_phy_28nm_a0b0_afe_config_init(struct phy_device *phydev) }EXPORT_SYMBOL_GPL (bcm_phy_28nm_a0b0_afe_config_init); +int bcm_phy_enable_jumbo (struct phy_device *phydev) +{ +int ret; + + ret =bcm54xx_auxctl_read (phydev,MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL ); +if (ret <0 ) +return ret; + +/* Enable extended length packet reception */ + ret =bcm54xx_auxctl_write (phydev,MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL , + ret |MII_BCM54XX_AUXCTL_ACTL_EXT_PKT_LEN ); +if (ret <0 ) +return ret; + +/* Enable the elastic FIFO for raising the transmission limit from +* 4.5KB to 10KB, at the expense of an additional 16 ns in propagation +* latency. +*/ +return phy_set_bits (phydev,MII_BCM54XX_ECR ,MII_BCM54XX_ECR_FIFOE ); +} +EXPORT_SYMBOL_GPL (bcm_phy_enable_jumbo); +MODULE_DESCRIPTION ("Broadcom PHY Library" );MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Broadcom Corporation" );
drivers/net/phy/bcm-phy-lib.h +1 -0
@@ -65,5 +65,6 @@ void bcm_phy_get_stats(struct phy_device *phydev, u64 *shadow, struct ethtool_stats *stats, u64 *data);void bcm_phy_r_rc_cal_reset (struct phy_device *phydev);int bcm_phy_28nm_a0b0_afe_config_init (struct phy_device *phydev); +int bcm_phy_enable_jumbo (struct phy_device *phydev);#endif /* _LINUX_BCM_PHY_LIB_H */
drivers/net/phy/bcm7xxx.c +4 -0
@@ -178,6 +178,10 @@ static int bcm7xxx_28nm_config_init(struct phy_device *phydev)break ; } +if (ret) +return ret; + + ret =bcm_phy_enable_jumbo (phydev);if (ret)return ret;
include/linux/brcmphy.h +2 -0
@@ -79,6 +79,7 @@#define MII_BCM54XX_ECR 0x10/* BCM54xx extended control register */ #define MII_BCM54XX_ECR_IM 0x1000/* Interrupt mask */ #define MII_BCM54XX_ECR_IF 0x0800/* Interrupt force */ +#define MII_BCM54XX_ECR_FIFOE 0x0001/* FIFO elasticity */ #define MII_BCM54XX_ESR 0x11/* BCM54xx extended status register */ #define MII_BCM54XX_ESR_IS 0x1000/* Interrupt status */
@@ -119,6 +120,7 @@#define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x00#define MII_BCM54XX_AUXCTL_ACTL_TX_6DB 0x0400#define MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA 0x0800 +#define MII_BCM54XX_AUXCTL_ACTL_EXT_PKT_LEN 0x4000#define MII_BCM54XX_AUXCTL_SHDWSEL_MISC 0x07#define MII_BCM54XX_AUXCTL_SHDWSEL_MISC_WIRESPEED_EN 0x0010
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 1/8] net: phy: bcm7xx: add jumbo frame configuration to PHY
Quoted 8 lines · Vladimir Oltean
From: Murali Krishna Policharla <[email protected]>
The BCM7XX PHY family requires special configuration to pass jumbo frames. Do that during initial PHY setup.
Signed-off-by Murali Krishna Policharla <[email protected]>Reviewed-by Scott Branden <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 2/8 bgmac: configure MTU and add support for frames beyond 8192 byte size
In reply to Vladimir OlteanFrom: Murali Krishna Policharla <[email protected]>
Change DMA descriptor length to handle jumbo frames beyond 8192 bytes. Also update jumbo frame max size to include FCS, the DMA packet length received includes FCS.
---
Changes in v3:
Squashed the entire bgmac implementation in one patch.
Changes in v2:
Patch is new.
drivers/net/ethernet/broadcom/bgmac.c | 12 ++++++++++++ drivers/net/ethernet/broadcom/bgmac.h | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +12 -0
@@ -1248,6 +1248,14 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)return 0 ; } +static int bgmac_change_mtu (struct net_device *net_dev,int mtu) +{ +struct bgmac *bgmac =netdev_priv (net_dev); + +bgmac_write (bgmac,BGMAC_RXMAX_LENGTH ,32 + mtu); +return 0 ; +} +static const struct net_device_ops bgmac_netdev_ops = { .ndo_open = bgmac_open, .ndo_stop = bgmac_stop,
@@ -1256,6 +1264,7 @@ static const struct net_device_ops bgmac_netdev_ops = { .ndo_set_mac_address = bgmac_set_mac_address, .ndo_validate_addr = eth_validate_addr, .ndo_do_ioctl = phy_do_ioctl_running, + .ndo_change_mtu = bgmac_change_mtu, };/**************************************************
@@ -1530,6 +1539,9 @@ int bgmac_enet_probe(struct bgmac *bgmac) net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; +/* Omit FCS from max MTU size */ + net_dev->max_mtu =BGMAC_RX_MAX_FRAME_SIZE -ETH_FCS_LEN ; + err =register_netdev (bgmac->net_dev);if (err) {dev_err (bgmac->dev,"Cannot register net device\n" );
drivers/net/ethernet/broadcom/bgmac.h +3 -2
@@ -351,7 +351,7 @@#define BGMAC_DESC_CTL0_IOC 0x20000000/* IRQ on complete */ #define BGMAC_DESC_CTL0_EOF 0x40000000/* End of frame */ #define BGMAC_DESC_CTL0_SOF 0x80000000/* Start of frame */ -#define BGMAC_DESC_CTL1_LEN 0x00001FFF +#define BGMAC_DESC_CTL1_LEN 0x00003FFF#define BGMAC_PHY_NOREGS BRCM_PSEUDO_PHY_ADDR#define BGMAC_PHY_MASK 0x1F
@@ -366,7 +366,8 @@#define BGMAC_RX_FRAME_OFFSET 30/* There are 2 unused bytes between header and real data */ #define BGMAC_RX_BUF_OFFSET (NET_SKB_PAD + NET_IP_ALIGN - \ BGMAC_RX_FRAME_OFFSET) -#define BGMAC_RX_MAX_FRAME_SIZE 1536/* Copied from b44/tg3 */ +/* Jumbo frame size with FCS */ +#define BGMAC_RX_MAX_FRAME_SIZE 9724#define BGMAC_RX_BUF_SIZE (BGMAC_RX_FRAME_OFFSET + BGMAC_RX_MAX_FRAME_SIZE)#define BGMAC_RX_ALLOC_SIZE (SKB_DATA_ALIGN(BGMAC_RX_BUF_SIZE + BGMAC_RX_BUF_OFFSET) + \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 3/8 net: dsa: configure the MTU for switch ports
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
It is useful be able to configure port policers on a switch to accept frames of various sizes:
- Increase the MTU for better throughput from the default of 1500 if it is known that there is no 10/100 Mbps device in the network.
- Decrease the MTU to limit the latency of high-priority frames under congestion, or work around various network segments that add extra headers to packets which can't be fragmented.
For DSA slave ports, this is mostly a pass-through callback, called through the regular ndo ops and at probe time (to ensure consistency across all supported switches).
The CPU port is called with an MTU equal to the largest configured MTU of the slave ports. The assumption is that the user might want to sustain a bidirectional conversation with a partner over any switch port.
The DSA master is configured the same as the CPU port, plus the tagger overhead. Since the MTU is by definition L2 payload (sans Ethernet header), it is up to each individual driver to figure out if it needs to do anything special for its frame tags on the CPU port (it shouldn't except in special cases). So the MTU does not contain the tagger overhead on the CPU port.
However the MTU of the DSA master, minus the tagger overhead, is used as a proxy for the MTU of the CPU port, which does not have a net device. This is to avoid uselessly calling the .change_mtu function on the CPU port when nothing should change.
So it is safe to assume that the DSA master and the CPU port MTUs are apart by exactly the tagger's overhead in bytes.
Some changes were made around dsa_master_set_mtu(), function which was now removed, for 2 reasons:
- dev_set_mtu() already calls dev_validate_mtu(), so it's redundant to do the same thing in DSA
- __dev_set_mtu() returns 0 if ops->ndo_change_mtu is an absent method
That is to say, there's no need for this function in DSA, we can safely call dev_set_mtu() directly, take the rtnl lock when necessary, and just propagate whatever errors get reported (since the user probably wants to be informed).
Some inspiration (mainly in the MTU DSA notifier) was taken from a vaguely similar patch from Murali and Florian, who are credited as co-developers down below.
---
Changes in v3:
- Introduced the propagate_upstream variable in the notifier structure to prevent intermediate MTU configuration to be propagated upstream when it is going to be overwritten anyway by the MTU setting on the CPU port.
- Refined the dsa_switch_mtu_match such that the CPU port on the local switch does not match (it is explicitly programmed).
- Removed the dsa_master_set_mtu function (explanation in commit message).
Changes in v2:
Introduced a DSA switch notifier for propagating the MTU setting towards upstream switches.
include/net/dsa.h | 10 +++++ net/dsa/dsa_priv.h | 11 +++++ net/dsa/master.c | 23 ++++------ net/dsa/port.c | 13 ++++++ net/dsa/slave.c | 105 ++++++++++++++++++++++++++++++++++++++++++++- net/dsa/switch.c | 37 ++++++++++++++++ 6 files changed, 183 insertions(+), 16 deletions(-)
include/net/dsa.h +10 -0
@@ -579,6 +579,16 @@ struct dsa_switch_ops { struct devlink_param_gset_ctx *ctx);int (*devlink_param_set)(struct dsa_switch *ds,u32 id,struct devlink_param_gset_ctx *ctx); + +/* +* MTU change functionality. Switches can also adjust their MRU through +* this method. By MTU, one understands the SDU, aka L2 payload length. +* If the switch needs to account for the DSA tag on the CPU port, this +* method needs to to do so privately. +*/ +int (*port_change_mtu)(struct dsa_switch *ds,int port, +int new_mtu); +int (*port_max_mtu)(struct dsa_switch *ds,int port); };#define DSA_DEVLINK_PARAM_DRIVER (_id, _name, _type, _cmodes) \
net/dsa/dsa_priv.h +11 -0
@@ -22,6 +22,7 @@ enum {DSA_NOTIFIER_MDB_DEL ,DSA_NOTIFIER_VLAN_ADD ,DSA_NOTIFIER_VLAN_DEL , + DSA_NOTIFIER_MTU, };/* DSA_NOTIFIER_AGEING_TIME */
@@ -61,6 +62,14 @@ struct dsa_notifier_vlan_info {int port; }; +/* DSA_NOTIFIER_MTU */ +struct dsa_notifier_mtu_info { +bool propagate_upstream; +int sw_index; +int port; +int mtu; +}; +struct dsa_slave_priv {/* Copy of CPU port xmit for faster access in slave transmit hot path */ struct sk_buff * (*xmit)(struct sk_buff *skb,
@@ -127,6 +136,8 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, struct switchdev_trans *trans);int dsa_port_ageing_time (struct dsa_port *dp,clock_t ageing_clock,struct switchdev_trans *trans); +int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu, +bool propagate_upstream);int dsa_port_fdb_add (struct dsa_port *dp,const unsigned char *addr,u16 vid); int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
net/dsa/master.c +8 -15
@@ -314,20 +314,6 @@ static const struct attribute_group dsa_group = { .attrs = dsa_slave_attrs, }; -static void dsa_master_set_mtu (struct net_device *dev,struct dsa_port *cpu_dp) -{ -unsigned int mtu =ETH_DATA_LEN + cpu_dp->tag_ops->overhead; -int err; - -rtnl_lock (); -if (mtu <= dev->max_mtu) { - err =dev_set_mtu (dev, mtu); -if (err) -netdev_dbg (dev,"Unable to set MTU to include for DSA overheads\n" ); - } -rtnl_unlock (); -} -static void dsa_master_reset_mtu (struct net_device *dev) {int err;
@@ -344,7 +330,14 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) {int ret; -dsa_master_set_mtu (dev, cpu_dp); +rtnl_lock (); + ret =dev_set_mtu (dev,ETH_DATA_LEN + cpu_dp->tag_ops->overhead); +rtnl_unlock (); +if (ret) { +netdev_err (dev,"error %d setting MTU to include DSA overhead\n" , + ret); +return ret; + }/* If we use a tagging format that doesn't have an ethertype * field, make sure that all packets from this point on get
net/dsa/port.c +13 -0
@@ -297,6 +297,19 @@ int dsa_port_mrouter(struct dsa_port *dp, bool mrouter,return ds->ops->port_egress_floods (ds, port, true, mrouter); } +int dsa_port_mtu_change (struct dsa_port *dp,int new_mtu, +bool propagate_upstream) +{ +struct dsa_notifier_mtu_info info = { + .sw_index = dp->ds->index, + .propagate_upstream = propagate_upstream, + .port = dp->index, + .mtu = new_mtu, + }; + +return dsa_port_notify (dp,DSA_NOTIFIER_MTU , &info); +} +int dsa_port_fdb_add (struct dsa_port *dp,const unsigned char *addr,u16 vid) {
net/dsa/slave.c +104 -1
129 lines not on this page · raw message
net/dsa/switch.c +37 -0
@@ -52,6 +52,40 @@ static int dsa_switch_ageing_time(struct dsa_switch *ds,return 0 ; } +static bool dsa_switch_mtu_match (struct dsa_switch *ds,int port, +struct dsa_notifier_mtu_info *info) +{ +if (ds->index == info->sw_index) +return (port == info->port) ||dsa_is_dsa_port (ds, port); + +if (!info->propagate_upstream) +return false; + +if (dsa_is_dsa_port (ds, port) ||dsa_is_cpu_port (ds, port)) +return true; + +return false; +} + +static int dsa_switch_mtu (struct dsa_switch *ds, +struct dsa_notifier_mtu_info *info) +{ +int port, ret; + +if (!ds->ops->port_change_mtu) +return -EOPNOTSUPP ; + +for (port =0 ; port < ds->num_ports; port++) { +if (dsa_switch_mtu_match (ds, port, info)) { + ret = ds->ops->port_change_mtu (ds, port, info->mtu); +if (ret) +return ret; + } + } + +return 0 ; +} +static int dsa_switch_bridge_join (struct dsa_switch *ds,struct dsa_notifier_bridge_info *info) {
@@ -328,6 +362,9 @@ static int dsa_switch_event(struct notifier_block *nb,case DSA_NOTIFIER_VLAN_DEL : err =dsa_switch_vlan_del (ds, info);break ; +case DSA_NOTIFIER_MTU : + err =dsa_switch_mtu (ds, info); +break ;default : err = -EOPNOTSUPP ;break ;
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH v3 net-next 3/8] net: dsa: configure the MTU for switch ports
Quoted 20 lines
net/dsa/master.c +0
-14-static void dsa_master_set_mtu (struct net_device *dev,struct dsa_port *cpu_dp) -{ -unsigned int mtu =ETH_DATA_LEN + cpu_dp->tag_ops->overhead; -int err; - -rtnl_lock (); -if (mtu <= dev->max_mtu) { - err =dev_set_mtu (dev, mtu); -if (err) -netdev_dbg (dev,"Unable to set MTU to include for DSA overheads\n" ); - } -rtnl_unlock (); -} -static void dsa_master_reset_mtu (struct net_device *dev) {int err;@@ -344,7 +330,14 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) {int ret;
net/dsa/master.c int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) · line 340
Quoted 10 lines
net/dsa/master.c +8
-1-dsa_master_set_mtu (dev, cpu_dp); +rtnl_lock (); + ret =dev_set_mtu (dev,ETH_DATA_LEN + cpu_dp->tag_ops->overhead); +rtnl_unlock (); +if (ret) { +netdev_err (dev,"error %d setting MTU to include DSA overhead\n" , + ret); +return ret; + }
I suspect this will break devices. dsa_master_set_mtu() was not fatal if it failed. I did this deliberately because i suspect there are some MAC drivers which are unhappy to have the MTU changed, but will still send and receive frames which are bigger than the MTU.
So please keep setting the MTU of ETH_DATA_LEN + cpu_dp->tag_ops->overhead or less as non-fatal. Jumbo frame sizes you should however check the return code.
net/dsa/slave.c int dsa_slave_create(struct dsa_port *port) · line 1562
Quoted 9 lines
net/dsa/slave.c +4
-1@@ -1465,7 +1556,10 @@ int dsa_slave_create(struct dsa_port *port) slave_dev->priv_flags |=IFF_NO_QUEUE ; slave_dev->netdev_ops = &dsa_slave_netdev_ops; slave_dev->min_mtu =0 ; - slave_dev->max_mtu =ETH_MAX_MTU ; +if (ds->ops->port_max_mtu) + slave_dev->max_mtu = ds->ops->port_max_mtu (ds, port->index); +else + slave_dev->max_mtu =ETH_MAX_MTU ;
Does this bring you anything. You have a lot more checks you perform when performing the actual change. Seems better to keep them all together.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 3/8] net: dsa: configure the MTU for switch ports
Quoted 37 lines · Andrew Lunn
Quoted 21 lines
net/dsa/master.c +0
-14-static void dsa_master_set_mtu (struct net_device *dev,struct dsa_port *cpu_dp) -{ -unsigned int mtu =ETH_DATA_LEN + cpu_dp->tag_ops->overhead; -int err; - -rtnl_lock (); -if (mtu <= dev->max_mtu) { - err =dev_set_mtu (dev, mtu); -if (err) -netdev_dbg (dev,"Unable to set MTU to include for DSA overheads\n" ); - } -rtnl_unlock (); -} -static void dsa_master_reset_mtu (struct net_device *dev) {int err;@@ -344,7 +330,14 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) {int ret;net/dsa/master.c int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) · line 340
Quoted 10 lines
net/dsa/master.c +8
-1-dsa_master_set_mtu (dev, cpu_dp); +rtnl_lock (); + ret =dev_set_mtu (dev,ETH_DATA_LEN + cpu_dp->tag_ops->overhead); +rtnl_unlock (); +if (ret) { +netdev_err (dev,"error %d setting MTU to include DSA overhead\n" , + ret); +return ret; + }I suspect this will break devices.
dsa_master_set_mtu()was not fatal if it failed. I did this deliberately because i suspect there are some MAC drivers which are unhappy to have the MTU changed, but will still send and receive frames which are bigger than the MTU.
Quoted 4 lines
So please keep setting the MTU of
ETH_DATA_LEN+cpu_dp->tag_ops->overheador less as non-fatal. Jumbo frame sizes you should however check the return code.
Ok, I'll leave it non-fatal here.
Quoted 5 lines
Quoted 5 lines
net/dsa/slave.c +0
-1@@ -1465,7 +1556,10 @@ int dsa_slave_create(struct dsa_port *port) slave_dev->priv_flags |=IFF_NO_QUEUE ; slave_dev->netdev_ops = &dsa_slave_netdev_ops; slave_dev->min_mtu =0 ; - slave_dev->max_mtu =ETH_MAX_MTU ;
Quoted 9 lines
net/dsa/slave.c int dsa_slave_create(struct dsa_port *port) · line 1562
Quoted 4 lines
net/dsa/slave.c +4
-0+if (ds->ops->port_max_mtu) + slave_dev->max_mtu = ds->ops->port_max_mtu (ds, port->index); +else + slave_dev->max_mtu =ETH_MAX_MTU ;Does this bring you anything. You have a lot more checks you perform when performing the actual change. Seems better to keep them all together.
This here is for cooperating with dev_validate_mtu() so I can get this nice message:
ip link set dev sw0p1 mtu 2400
Error: mtu greater than device maximum.
Quoted 1 line
Andrew
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 4/8 net: dsa: implement auto-normalization of MTU for bridge hardware datapath
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Many switches don't have an explicit knob for configuring the MTU (maximum transmission unit per interface). Instead, they do the length-based packet admission checks on the ingress interface, for reasons that are easy to understand (why would you accept a packet in the queuing subsystem if you know you're going to drop it anyway).
So it is actually the MRU that these switches permit configuring.
In Linux there only exists the IFLA_MTU netlink attribute and the associated dev_set_mtu function. The comments like to play blind and say that it's changing the "maximum transfer unit", which is to say that there isn't any directionality in the meaning of the MTU word. So that is the interpretation that this patch is giving to things: MTU == MRU.
When 2 interfaces having different MTUs are bridged, the bridge driver MTU auto-adjustment logic kicks in: what br_mtu_auto_adjust() does is it adjusts the MTU of the bridge net device itself (and not that of the slave net devices) to the minimum value of all slave interfaces, in order for forwarded packets to not exceed the MTU regardless of the interface they are received and send on.
The idea behind this behavior, and why the slave MTUs are not adjusted, is that normal termination from Linux over the L2 forwarding domain should happen over the bridge net device, which _is_ properly limited by the minimum MTU. And termination over individual slave devices is possible even if those are bridged. But that is not "forwarding", so there's no reason to do normalization there, since only a single interface sees that packet.
The problem with those switches that can only control the MRU is with the offloaded data path, where a packet received on an interface with MRU 9000 would still be forwarded to an interface with MRU 1500. And the br_mtu_auto_adjust() function does not really help, since the MTU configured on the bridge net device is ignored.
In order to enforce the de-facto MTU == MRU rule for these switches, we need to do MTU normalization, which means: in order for no packet larger than the MTU configured on this port to be sent, then we need to limit the MRU on all ports that this packet could possibly come from. AKA since we are configuring the MRU via MTU, it means that all ports within a bridge forwarding domain should have the same MTU.
And that is exactly what this patch is trying to do.
From an implementation perspective, we try to follow the intent of the user, otherwise there is a risk that we might livelock them (they try to change the MTU on an already-bridged interface, but we just keep changing it back in an attempt to keep the MTU normalized). So the MTU that the bridge is normalized to is either:
- The most recently changed one:
ip link set dev swp0 master br0
ip link set dev swp1 master br0
ip link set dev swp0 mtu 1400
This sequence will make swp1 inherit MTU 1400 from swp0.
- The one of the most recently added interface to the bridge:
ip link set dev swp0 master br0
ip link set dev swp1 mtu 1400
ip link set dev swp1 master br0
The above sequence will make swp0 inherit MTU 1400 as well.
---
Changes in v3:
Moved the implementation to the DSA core (it was in the bridge driver previously).
Added a variable by which drivers should denote if they require this behavior or not.
Changes in v2:
Patch is new.
include/net/dsa.h | 6 +++ net/dsa/dsa2.c | 2 +- net/dsa/dsa_priv.h | 4 ++ net/dsa/slave.c | 114 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-)
include/net/dsa.h +6 -0
@@ -284,6 +284,12 @@ struct dsa_switch {*/ bool pcs_poll; +/* For switches that only have the MRU configurable. To ensure the +* configured MTU is not exceeded, normalization of MRU on all bridged +* interfaces is needed. +*/ +bool mtu_enforcement_ingress; +size_t num_ports; };
net/dsa/dsa2.c +1 -1
@@ -18,8 +18,8 @@#include "dsa_priv.h" -static LIST_HEAD (dsa_tree_list);static DEFINE_MUTEX (dsa2_mutex); +LIST_HEAD (dsa_tree_list);static const struct devlink_ops dsa_devlink_ops = { };
net/dsa/dsa_priv.h +4 -0
@@ -194,4 +194,8 @@ dsa_slave_to_master(const struct net_device *dev)/* switch.c */ int dsa_switch_register_notifier (struct dsa_switch *ds);void dsa_switch_unregister_notifier (struct dsa_switch *ds); + +/* dsa2.c */ +extern struct list_head dsa_tree_list; +#endif
net/dsa/slave.c +114 -0
132 lines not on this page · raw message
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [PATCH v3 net-next 4/8] net: dsa: implement auto-normalization of MTU for bridge hardware datapath
I love your patch! Perhaps something to improve:
Hi Vladimir,
I love your patch! Perhaps something to improve:
[auto build test WARNING on net-next/master]
[also build test WARNING on linus/master v5.6-rc7 next-20200327] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Vladimir-Oltean/Configure-the-MTU-on-DSA-switches/20200327-094801 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 92b7e62e5630a370955a4760bbeb3967457034ec reproduce: # apt-get install sparse # sparse version: v0.6.1-187-gbff9b106-dirty make ARCH=x86_64 allmodconfig make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' :::::: branch date: 17 hours ago :::::: commit date: 17 hours ago
If you fix the issue, kindly add following tag
net/dsa/slave.c:506:13: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] <asn:3> *__vpp_verify @@ got const [noderef] <asn:3> *__vpp_verify @@
net/dsa/slave.c:506:13: sparse: expected void const [noderef] <asn:3> *__vpp_verify
net/dsa/slave.c:506:13: sparse: got struct pcpu_sw_netstats *
net/dsa/slave.c:640:21: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] <asn:3> *__vpp_verify @@ got const [noderef] <asn:3> *__vpp_verify @@
net/dsa/slave.c:640:21: sparse: expected void const [noderef] <asn:3> *__vpp_verify
net/dsa/slave.c:640:21: sparse: got struct pcpu_sw_netstats *
net/dsa/slave.c:1106:21: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void const [noderef] <asn:3> *__vpp_verify @@ got const [noderef] <asn:3> *__vpp_verify @@
net/dsa/slave.c:1106:21: sparse: expected void const [noderef] <asn:3> *__vpp_verify
net/dsa/slave.c:1106:21: sparse: got struct pcpu_sw_netstats *
>> net/dsa/slave.c:1264:6: sparse: sparse: symbol 'dsa_bridge_mtu_normalization' was not declared. Should it be static?
net/dsa/slave.c:1682:20: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct pcpu_sw_netstats *stats64 @@ got struct pcpu_sw_netstruct pcpu_sw_netstats *stats64 @@
net/dsa/slave.c:1682:20: sparse: expected struct pcpu_sw_netstats *stats64
net/dsa/slave.c:1682:20: sparse: got struct pcpu_sw_netstats [noderef] <asn:3> *pcpu_stats
net/dsa/slave.c:1726:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:3> *__pdata @@ got svoid [noderef] <asn:3> *__pdata @@
net/dsa/slave.c:1726:22: sparse: expected void [noderef] <asn:3> *__pdata
net/dsa/slave.c:1726:22: sparse: got struct pcpu_sw_netstats *stats64
net/dsa/slave.c:1745:22: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:3> *__pdata @@ got svoid [noderef] <asn:3> *__pdata @@
net/dsa/slave.c:1745:22: sparse: expected void [noderef] <asn:3> *__pdata
net/dsa/slave.c:1745:22: sparse: got struct pcpu_sw_netstats *stats64
Please review and possibly fold the followup patch.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Vladimir Oltean
maintainerPATCH v3 5/8 net: dsa: b53: add MTU configuration support
In reply to Vladimir OlteanFrom: Murali Krishna Policharla <[email protected]>
It looks like the Broadcomm switches supported by the b53 driver don't support precise configuration of the MTU, but just a mumbo-jumbo boolean flag. Set that.
Also configure BCM583XX devices to send and receive jumbo frames when ports are configured with 10/100 Mbps speed.
---
Changes in v3:
Using the b53_set_jumbo function that was already there.
Changes in v2:
Patch is new.
drivers/net/dsa/b53/b53_common.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-)
drivers/net/dsa/b53/b53_common.c +22 -5
@@ -699,9 +699,6 @@ int b53_configure_vlan(struct dsa_switch *ds)b53_write16 (dev,B53_VLAN_PAGE ,B53_VLAN_PORT_DEF_TAG (i), def_vid); -if (!is5325 (dev) && !is5365 (dev)) -b53_set_jumbo (dev, dev->enable_jumbo, false); -return 0 ; }EXPORT_SYMBOL (b53_configure_vlan);
@@ -807,8 +804,6 @@ static int b53_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)static int b53_reset_switch (struct b53_device *priv) {/* reset vlans */ - priv->enable_jumbo = false; -memset (priv->vlans,0 ,sizeof (*priv->vlans) * priv->num_vlans);memset (priv->ports,0 ,sizeof (*priv->ports) * priv->num_ports);
@@ -2065,6 +2060,26 @@ int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) }EXPORT_SYMBOL (b53_set_mac_eee); +static int b53_change_mtu (struct dsa_switch *ds,int port,int mtu) +{ +struct b53_device *dev = ds->priv; +bool enable_jumbo; +bool allow_10_100; + +if (is5325 (dev) ||is5365 (dev)) +return -EOPNOTSUPP ; + + enable_jumbo = (mtu >=JMS_MIN_SIZE ); + allow_10_100 = (dev->chip_id ==BCM58XX_DEVICE_ID ); + +return b53_set_jumbo (dev, enable_jumbo, allow_10_100); +} + +static int b53_get_max_mtu (struct dsa_switch *ds,int port) +{ +return JMS_MAX_SIZE ; +} +static const struct dsa_switch_ops b53_switch_ops = { .get_tag_protocol = b53_get_tag_protocol, .setup = b53_setup,
@@ -2102,6 +2117,8 @@ static const struct dsa_switch_ops b53_switch_ops = { .port_mdb_prepare = b53_mdb_prepare, .port_mdb_add = b53_mdb_add, .port_mdb_del = b53_mdb_del, + .port_max_mtu = b53_get_max_mtu, + .port_change_mtu = b53_change_mtu, };struct b53_chip_data {
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 5/8] net: dsa: b53: add MTU configuration support
Quoted 3 lines · Vladimir Oltean
From: Murali Krishna Policharla <[email protected]>
It looks like the Broadcomm switches supported by the b53 driver don't
^= one too many m's, the attempt to acquire
Qualcomm failed a few years ago :)
Quoted 9 lines
support precise configuration of the MTU, but just a mumbo-jumbo boolean flag. Set that.
Also configure BCM583XX devices to send and receive jumbo frames when ports are configured with 10/100 Mbps speed.
Signed-off-by Murali Krishna Policharla <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
drivers/net/dsa/b53/b53_common.c int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) · line 2073
Quoted 11 lines
drivers/net/dsa/b53/b53_common.c +11
-0+static int b53_change_mtu (struct dsa_switch *ds,int port,int mtu) +{ +struct b53_device *dev = ds->priv; +bool enable_jumbo; +bool allow_10_100; + +if (is5325 (dev) ||is5365 (dev)) +return -EOPNOTSUPP ; + + enable_jumbo = (mtu >=JMS_MIN_SIZE ); + allow_10_100 = (dev->chip_id ==BCM58XX_DEVICE_ID );
I believe this was meant to be BCM583XX_DEVICE_ID to be consistent with the previous patch version. With that:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 5/8] net: dsa: b53: add MTU configuration support
Quoted 8 lines · Florian Fainelli
Quoted 3 lines · Vladimir Oltean
From: Murali Krishna Policharla <[email protected]>
It looks like the Broadcomm switches supported by the b53 driver don't
^= one too many m's, the attempt to acquire
Qualcomm failed a few years ago :)
I knew you guys were jealous of their extra m!
Quoted 2 lines
Quoted 2 lines
support precise configuration of the MTU, but just a mumbo-jumbo boolean flag. Set that.
I'm more concerned of the mumbo-jumbo, in fact. Right now, DSA sets dev->mtu = mtu in slave.c. But for hardware like this, it would be confusing to do that. I would do dev->mtu = JMS_MIN_SIZE or dev->mtu = JMS_MAX_SIZE depending on configuration, so that the user isn't led into thinking that their exact requested value went into the hardware. Any ideas on how I could structure things differently for that?
Quoted 10 lines
Quoted 7 lines
Also configure BCM583XX devices to send and receive jumbo frames when ports are configured with 10/100 Mbps speed.
Signed-off-by Murali Krishna Policharla <[email protected]>Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
Quoted 15 lines
drivers/net/dsa/b53/b53_common.c int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e) · line 2073
Quoted 11 lines
drivers/net/dsa/b53/b53_common.c +11
-0+static int b53_change_mtu (struct dsa_switch *ds,int port,int mtu) +{ +struct b53_device *dev = ds->priv; +bool enable_jumbo; +bool allow_10_100; + +if (is5325 (dev) ||is5365 (dev)) +return -EOPNOTSUPP ; + + enable_jumbo = (mtu >=JMS_MIN_SIZE ); + allow_10_100 = (dev->chip_id ==BCM58XX_DEVICE_ID );I believe this was meant to be
BCM583XX_DEVICE_IDto be consistent with the previous patch version. With that:
Ok.
Quoted 3 lines
Acked-by Florian Fainelli <[email protected]>--
Florian
Vladimir Oltean
maintainerPATCH v3 6/8 net: dsa: sja1105: implement the port MTU callbacks
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
On this switch, the frame length enforcements are performed by the ingress policers. There are 2 types of those: regular L2 (also called best-effort) and Virtual Link policers (an ARINC664/AFDX concept for defining L2 streams with certain QoS abilities). To avoid future confusion, I prefer to call the reset reason "Best-effort policers", even though the VL policers are not yet supported.
We also need to change the setup of the initial static config, such that DSA calls to .change_mtu (which are expensive) become no-ops and don't reset the switch 5 times.
A driver-level decision is to unconditionally allow single VLAN-tagged traffic on all ports. The CPU port must accept an additional VLAN header for the DSA tag, which is again a driver-level decision.
The policers actually count bytes not only from the SDU, but also from the Ethernet header and FCS, so those need to be accounted for as well.
---
Changes in v3:
Now setting the ds->mtu_enforcement_ingress variable to true.
Changes in v2:
None.
drivers/net/dsa/sja1105/sja1105.h | 1 + drivers/net/dsa/sja1105/sja1105_main.c | 50 +++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +1 -0
@@ -126,6 +126,7 @@ enum sja1105_reset_reason {SJA1105_RX_HWTSTAMPING ,SJA1105_AGEING_TIME ,SJA1105_SCHEDULING , + SJA1105_BEST_EFFORT_POLICING, }; int sja1105_static_config_reload(struct sja1105_private *priv,
drivers/net/dsa/sja1105/sja1105_main.c +46 -4
94 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 7/8 net: dsa: vsc73xx: make the MTU configurable
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Instead of hardcoding the MTU to the maximum value allowed by the hardware, obey the value known by the operating system.
---
Changes in v3:
None.
Changes in v2:
None.
drivers/net/dsa/vitesse-vsc73xx-core.c | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +20 -10
@@ -664,16 +664,6 @@ static void vsc73xx_init_port(struct vsc73xx *vsc, int port)VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); -/* Max length, we can do up to 9.6 KiB, so allow that. -* According to application not "VSC7398 Jumbo Frames" setting -* up the MTU to 9.6 KB does not affect the performance on standard -* frames, so just enable it. It is clear from the application note -* that "9.6 kilobytes" == 9600 bytes. -*/ -vsc73xx_write (vsc,VSC73XX_BLOCK_MAC , - port, -VSC73XX_MAXLEN ,9600 ); -/* Flow control for the CPU port: * Use a zero delay pause frame when pause condition is left * Obey pause control frames
@@ -1030,6 +1020,24 @@ static void vsc73xx_get_ethtool_stats(struct dsa_switch *ds, int port, } } +static int vsc73xx_change_mtu (struct dsa_switch *ds,int port,int new_mtu) +{ +struct vsc73xx *vsc = ds->priv; + +return vsc73xx_write (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_MAXLEN , new_mtu); +} + +/* According to application not "VSC7398 Jumbo Frames" setting +* up the MTU to 9.6 KB does not affect the performance on standard +* frames. It is clear from the application note that +* "9.6 kilobytes" == 9600 bytes. +*/ +static int vsc73xx_get_max_mtu (struct dsa_switch *ds,int port) +{ +return 9600 ; +} +static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_tag_protocol = vsc73xx_get_tag_protocol, .setup = vsc73xx_setup,
@@ -1041,6 +1049,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_sset_count = vsc73xx_get_sset_count, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_change_mtu = vsc73xx_change_mtu, + .port_max_mtu = vsc73xx_get_max_mtu, };static int vsc73xx_gpio_get (struct gpio_chip *chip,unsigned int offset)
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v3 8/8 net: dsa: felix: support changing the MTU
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Changing the MTU for this switch means altering the DEV_GMII:MAC_CFG_STATUS:MAC_MAXLEN_CFG field MAX_LEN, which in turn limits the size of frames that can be received.
Special accounting needs to be done for the DSA CPU port (NPI port in hardware terms). The NPI port configuration needs to be held inside the private ocelot structure, since it is now accessed from multiple places.
---
Changes in v3:
Now setting the ds->mtu_enforcement_ingress variable to true.
Changes in v2:
None.
drivers/net/dsa/ocelot/felix.c | 19 +++++++++++++ drivers/net/ethernet/mscc/ocelot.c | 45 +++++++++++++++++++++++------- include/soc/mscc/ocelot.h | 7 +++++ 3 files changed, 61 insertions(+), 10 deletions(-)
drivers/net/dsa/ocelot/felix.c +19 -0
@@ -533,6 +533,7 @@ static int felix_setup(struct dsa_switch *ds)ANA_PGID_PGID_PGID (GENMASK (ocelot->num_phys_ports,0 )), ANA_PGID_PGID, PGID_UC); + ds->mtu_enforcement_ingress = true;/* It looks like the MAC/PCS interrupt register - PM0_IEVENT (0x8040) * isn't instantiated for the Felix PF. * In-band AN may take a few ms to complete, so we need to poll.
@@ -610,6 +611,22 @@ static bool felix_txtstamp(struct dsa_switch *ds, int port,return false; } +static int felix_change_mtu (struct dsa_switch *ds,int port,int new_mtu) +{ +struct ocelot *ocelot = ds->priv; + +ocelot_port_set_maxlen (ocelot, port, new_mtu); + +return 0 ; +} + +static int felix_get_max_mtu (struct dsa_switch *ds,int port) +{ +struct ocelot *ocelot = ds->priv; + +return ocelot_get_max_mtu (ocelot, port); +} +static int felix_cls_flower_add (struct dsa_switch *ds,int port,struct flow_cls_offload *cls,bool ingress) {
@@ -665,6 +682,8 @@ static const struct dsa_switch_ops felix_switch_ops = { .port_hwtstamp_set = felix_hwtstamp_set, .port_rxtstamp = felix_rxtstamp, .port_txtstamp = felix_txtstamp, + .port_change_mtu = felix_change_mtu, + .port_max_mtu = felix_get_max_mtu, .cls_flower_add = felix_cls_flower_add, .cls_flower_del = felix_cls_flower_del, .cls_flower_stats = felix_cls_flower_stats,
drivers/net/ethernet/mscc/ocelot.c +35 -10
79 lines not on this page · raw message
include/soc/mscc/ocelot.h +7 -0
@@ -522,6 +522,11 @@ struct ocelot {*/ u8 num_phys_ports; +int npi; + +enum ocelot_tag_prefix inj_prefix; +enum ocelot_tag_prefix xtr_prefix; +u32 *lags;struct list_head multicast;
@@ -616,6 +621,8 @@ int ocelot_hwstamp_set(struct ocelot *ocelot, int port, struct ifreq *ifr);int ocelot_port_add_txtstamp_skb (struct ocelot_port *ocelot_port,struct sk_buff *skb);void ocelot_get_txtstamp (struct ocelot *ocelot); +void ocelot_port_set_maxlen (struct ocelot *ocelot,int port,size_t sdu); +int ocelot_get_max_mtu (struct ocelot *ocelot,int port);int ocelot_cls_flower_replace (struct ocelot *ocelot,int port,struct flow_cls_offload *f,bool ingress); int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
Signature · 1 line
2.17.1