net: dsa: vsc73xx: Implement VLAN operations
Subsystems (5)
v2 cover net: dsa: vsc73xx: Implement VLAN operations
This patch series is a result of splitting a larger patch series [0], where some parts was merged before.
The first patch implements port state configuration, which is required for bridge functionality. STP frames are not forwarded at this moment. BPDU frames are only forwarded from/to the PI/SI interface. For more information, see chapter 2.7.1 (CPU Forwarding) in the datasheet.
Patches 2, 7-9 and 11 provide a basic implementation of tag_8021q functionality with QinQ support, without VLAN filtering in the bridge and simple VLAN awareness in VLAN filtering mode.
Patches 3-6 came from Vladimir Oltean. They prepare for making tag8021q more common. VSC73XX uses very similar tag recognition, and some code from tag_sja1105 could be moved to tag_8021q for common use.
Patch 10 is preparation for use tag_8021q bridge functions as generic implementation of the 'ds->ops->port_bridge_*()'.
Patch 12 is required to avoid problem with learning on standalone ports.
[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
Pawel Dembicki (8):
net: dsa: vsc73xx: add port_stp_state_set function
net: dsa: vsc73xx: Add vlan filtering
net: dsa: vsc73xx: introduce tag 8021q for vsc73xx
net: dsa: vsc73xx: Implement the tag_8021q VLAN operations
net: dsa: Define max num of bridges in tag8021q implementation
net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use
net: dsa: vsc73xx: Add bridge support
net: dsa: vsc73xx: start treating the BR_LEARNING flag
Vladimir Oltean (4):
net: dsa: tag_sja1105: absorb logic for not overwriting precise info
into dsa_8021q_rcv()
net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into
dsa_8021q_rcv()
net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too
net: dsa: tag_sja1105: refactor skb->dev assignment to
dsa_tag_8021q_find_user()drivers/net/dsa/Kconfig | 2 +- drivers/net/dsa/sja1105/sja1105_main.c | 8 +- drivers/net/dsa/vitesse-vsc73xx-core.c | 709 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 42 ++ include/linux/dsa/8021q.h | 8 +- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_8021q.c | 86 ++- net/dsa/tag_8021q.h | 7 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 72 +-- net/dsa/tag_vsc73xx_8021q.c | 68 +++ 13 files changed, 914 insertions(+), 99 deletions(-) create mode 100644 net/dsa/tag_vsc73xx_8021q.c
Signature · 1 line
2.34.1
PATCH v2 1/12 net: dsa: vsc73xx: add port_stp_state_set function
This isn't a fully functional implementation of 802.1D, but port_stp_state_set is required for a future tag8021q operations.
This implementation handles properly all states, but vsc73xx doesn't forward STP packets.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v7:
- implement 'vsc73xx_refresh_fwd_map' simplification
v6:
- fix inconsistent indenting
v5:
- remove unneeded 'RECVMASK' operations
- reorganise vsc73xx_refresh_fwd_map function
v4:
- fully reworked port_stp_state_set
v3:
- use 'VSC73XX_MAX_NUM_PORTS' define
- add 'state == BR_STATE_DISABLED' condition
- fix style issues
v2:
- fix kdoc
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 96 +++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 11 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +85 -11
@@ -164,6 +164,10 @@#define VSC73XX_AGENCTRL 0xf0#define VSC73XX_CAPRST 0xff +#define VSC73XX_SRCMASKS_CPU_COPY BIT(27) +#define VSC73XX_SRCMASKS_MIRROR BIT(26) +#define VSC73XX_SRCMASKS_PORTS_MASK GENMASK(7, 0) +#define VSC73XX_MACACCESS_CPU_COPY BIT(14)#define VSC73XX_MACACCESS_FWD_KILL BIT(13)#define VSC73XX_MACACCESS_IGNORE_VLAN BIT(12)
@@ -623,9 +627,6 @@ static int vsc73xx_setup(struct dsa_switch *ds)vsc73xx_write (vsc,VSC73XX_BLOCK_SYSTEM ,0 ,VSC73XX_GMIIDELAY ,VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS |VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS ); -/* Enable reception of frames on all ports */ -vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_RECVMASK , -0x5f );/* IP multicast flood mask (table 144) */ vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_IFLODMSK ,0xff );
@@ -788,10 +789,6 @@ static void vsc73xx_mac_link_down(struct phylink_config *config,/* Allow backward dropping of frames from this port */ vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ARBITER ,0 ,VSC73XX_SBACKWDROP ,BIT (port),BIT (port)); - -/* Receive mask (disable forwarding) */ -vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , -VSC73XX_RECVMASK ,BIT (port),0 ); } static void vsc73xx_mac_link_up(struct phylink_config *config,
@@ -844,10 +841,6 @@ static void vsc73xx_mac_link_up(struct phylink_config *config,vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ARBITER ,0 ,VSC73XX_ARBDISC ,BIT (port),0 ); -/* Enable port (forwarding) in the receive mask */ -vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , -VSC73XX_RECVMASK ,BIT (port),BIT (port)); -/* Disallow backward dropping of frames from this port */ vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ARBITER ,0 ,VSC73XX_SBACKWDROP ,BIT (port),0 );
@@ -1039,6 +1032,86 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, config->mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000 ; } +static void vsc73xx_refresh_fwd_map (struct dsa_switch *ds,int port,u8 state) +{ +struct dsa_port *other_dp, *dp =dsa_to_port (ds, port); +struct vsc73xx *vsc = ds->priv; +u16 mask; + +if (state !=BR_STATE_FORWARDING ) { +/* Ports that aren't in the forwarding state must not +* forward packets anywhere. +*/ +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_SRCMASKS + port, +VSC73XX_SRCMASKS_PORTS_MASK ,0 ); + +dsa_switch_for_each_available_port (other_dp, ds) { +if (other_dp == dp) +continue ; +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_SRCMASKS + other_dp->index, +BIT (port),0 ); + } + +return ; + } + +/* Forwarding ports must forward to the CPU and to other ports +* in the same bridge +*/ +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_SRCMASKS +CPU_PORT ,BIT (port),BIT (port)); + + mask =BIT (CPU_PORT ); + +dsa_switch_for_each_user_port (other_dp, ds) { +int other_port = other_dp->index; + +if (port == other_port || !dsa_port_bridge_same (dp, other_dp) || + other_dp->stp_state !=BR_STATE_FORWARDING ) +continue ; + + mask |=BIT (other_port); + +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_SRCMASKS + other_port, +BIT (port),BIT (port)); + } + +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_SRCMASKS + port, +VSC73XX_SRCMASKS_PORTS_MASK , mask); +} + +/* FIXME: STP frames aren't forwarded at this moment. BPDU frames are +* forwarded only from and to PI/SI interface. For more info see chapter +* 2.7.1 (CPU Forwarding) in datasheet. +* This function is required for tag_8021q operations. +*/ +static void vsc73xx_port_stp_state_set (struct dsa_switch *ds,int port, +u8 state) +{ +struct vsc73xx *vsc = ds->priv; +u32 val; + + val = (state ==BR_STATE_BLOCKING || state ==BR_STATE_DISABLED ) ? +0 :BIT (port); +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_RECVMASK ,BIT (port), val); + + val = (state ==BR_STATE_LEARNING || state ==BR_STATE_FORWARDING ) ? +BIT (port) :0 ; +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_LEARNMASK ,BIT (port), val); + +/* CPU Port should always forward packets when user ports are forwarding +* so let's configure it from other ports only. +*/ +if (port !=CPU_PORT ) +vsc73xx_refresh_fwd_map (ds, port, state); +} +static const struct phylink_mac_ops vsc73xx_phylink_mac_ops = { .mac_config = vsc73xx_mac_config, .mac_link_down = vsc73xx_mac_link_down,
@@ -1057,6 +1130,7 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, + .port_stp_state_set = vsc73xx_port_stp_state_set, .phylink_get_caps = vsc73xx_phylink_get_caps, };
Signature · 1 line
2.34.1
PATCH v2 2/12 net: dsa: vsc73xx: Add vlan filtering
In reply to Pawel DembickiThis patch implements VLAN filtering for the vsc73xx driver.
After starting VLAN filtering, the switch is reconfigured from QinQ to a simple VLAN aware mode. This is required because VSC73XX chips do not support inner VLAN tag filtering.
---
v2:
- removed not needed INIT_LIST_HEAD
- fix vsc73xx_vlan removing procedure
- fix code spell
- handle return codes from 'vsc73xx_vlan_commit*' functions
- move 'vsc73xx_vlan_commit*' call from port_setup to port_enable to avoid unused port configuration
v1:
- refactored pvid, untagged and vlan filter configuration
- fix typo
- simplification
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- set init value of 'ret' in 'vsc73xx_port_vlan_add'
v7:
- rework pvid and untagged configuration routines
- introduce portinfo structure which should make pvid/untagged procedures simpler
- introduce 'vsc73xx_vlan_summary' structure
- replace tagged/untagged count functions with 'vsc73xx_bridge_vlan_summary'
- fix VSC73XX_VLANMASK configuration. It was copy from existing code.
- stop configuring pvid/untagged registers whed pvid/untagged is disabled
v6:
- resend only
v5:
- fix possible leak in 'vsc73xx_port_vlan_add'
- use proper variable in statement from 'vsc73xx_port_vlan_filtering'
- change 'vlan_no' name to 'vid'
- codding style improvements
- comment improvements
- handle return of 'vsc73xx_update_bits'
- reduce I/O operations
- use 'size_t' for counting variables
v4:
- reworked most of conditional register configs
- simplified port_vlan function
- move vlan table clearing from port_setup to setup
- pvid configuration simplified (now kernel take care about no of pvids per port)
- port vlans are stored in list now
- introduce implementation of all untagged vlans state
- many minor changes
v3:
- reworked all vlan commits
- added storage variables for pvid and untagged vlans
- move length extender settings to port setup
- remove vlan table cleaning in wrong places
v2:
- no changes done
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 517 ++++++++++++++++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 42 ++ 2 files changed, 556 insertions(+), 3 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +514 -3
@@ -22,9 +22,11 @@#include <linux/of_mdio.h> #include <linux/bitops.h> #include <linux/if_bridge.h> +#include <linux/if_vlan.h> #include <linux/etherdevice.h> #include <linux/gpio/consumer.h> #include <linux/gpio/driver.h> +#include <linux/dsa/8021q.h> #include <linux/random.h> #include <net/dsa.h>
@@ -62,6 +64,8 @@#define VSC73XX_CAT_DROP 0x6e#define VSC73XX_CAT_PR_MISC_L2 0x6f#define VSC73XX_CAT_PR_USR_PRIO 0x75 +#define VSC73XX_CAT_VLAN_MISC 0x79 +#define VSC73XX_CAT_PORT_VLAN 0x7a#define VSC73XX_Q_MISC_CONF 0xdf/* MAC_CFG register bits */
@@ -122,6 +126,17 @@#define VSC73XX_ADVPORTM_IO_LOOPBACK BIT(1)#define VSC73XX_ADVPORTM_HOST_LOOPBACK BIT(0) +/* TXUPDCFG transmit modify setup bits */ +#define VSC73XX_TXUPDCFG_DSCP_REWR_MODE GENMASK(20, 19) +#define VSC73XX_TXUPDCFG_DSCP_REWR_ENA BIT(18) +#define VSC73XX_TXUPDCFG_TX_INT_TO_USRPRIO_ENA BIT(17) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID GENMASK(15, 4) +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA BIT(3) +#define VSC73XX_TXUPDCFG_TX_UPDATE_CRC_CPU_ENA BIT(1) +#define VSC73XX_TXUPDCFG_TX_INSERT_TAG BIT(0) + +#define VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT 4 +/* CAT_DROP categorizer frame dropping register bits */ #define VSC73XX_CAT_DROP_DROP_MC_SMAC_ENA BIT(6)#define VSC73XX_CAT_DROP_FWD_CTRL_ENA BIT(4)
@@ -135,6 +150,15 @@#define VSC73XX_Q_MISC_CONF_EARLY_TX_512 (1 << 1)#define VSC73XX_Q_MISC_CONF_MAC_PAUSE_MODE BIT(0) +/* CAT_VLAN_MISC categorizer VLAN miscellaneous bits */ +#define VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA BIT(8) +#define VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA BIT(7) + +/* CAT_PORT_VLAN categorizer port VLAN */ +#define VSC73XX_CAT_PORT_VLAN_VLAN_CFI BIT(15) +#define VSC73XX_CAT_PORT_VLAN_VLAN_USR_PRIO GENMASK(14, 12) +#define VSC73XX_CAT_PORT_VLAN_VLAN_VID GENMASK(11, 0) +/* Frame analyzer block 2 registers */ #define VSC73XX_STORMLIMIT 0x02#define VSC73XX_ADVLEARN 0x03
@@ -189,7 +213,8 @@#define VSC73XX_VLANACCESS_VLAN_MIRROR BIT(29)#define VSC73XX_VLANACCESS_VLAN_SRC_CHECK BIT(28)#define VSC73XX_VLANACCESS_VLAN_PORT_MASK GENMASK(9, 2) -#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(2, 0) +#define VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT 2 +#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK GENMASK(1, 0)#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE 0#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY 1#define VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY 2
@@ -347,6 +372,17 @@ static const struct vsc73xx_counter vsc73xx_tx_counters[] = { { 29, "TxQoSClass3" }, /* non-standard counter */ }; +struct vsc73xx_vlan_summary { +size_t num_tagged; +size_t num_untagged; +}; + +enum vsc73xx_port_vlan_conf { +VSC73XX_VLAN_FILTER , +VSC73XX_VLAN_FILTER_UNTAG_ALL , +VSC73XX_VLAN_IGNORE , +}; +int vsc73xx_is_addr_valid (u8 block,u8 subblock) {switch (block) {
@@ -564,6 +600,90 @@ static enum dsa_tag_protocol vsc73xx_get_tag_protocol(struct dsa_switch *ds,return DSA_TAG_PROTO_NONE ; } +static int vsc73xx_wait_for_vlan_table_cmd (struct vsc73xx *vsc) +{ +int ret, err; +u32 val; + + ret =read_poll_timeout (vsc73xx_read, err, + err <0 || + ((val &VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK ) == +VSC73XX_VLANACCESS_VLAN_TBL_CMD_IDLE ), +VSC73XX_POLL_SLEEP_US ,VSC73XX_POLL_TIMEOUT_US , + false, vsc,VSC73XX_BLOCK_ANALYZER , +0 ,VSC73XX_VLANACCESS , &val); +if (ret) +return ret; +return err; +} + +static int +vsc73xx_read_vlan_table_entry (struct vsc73xx *vsc,u16 vid,u8 *portmap) +{ +u32 val; +int ret; + +vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANTIDX , vid); + + ret =vsc73xx_wait_for_vlan_table_cmd (vsc); +if (ret) +return ret; + +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANACCESS , +VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK , +VSC73XX_VLANACCESS_VLAN_TBL_CMD_READ_ENTRY ); + + ret =vsc73xx_wait_for_vlan_table_cmd (vsc); +if (ret) +return ret; + +vsc73xx_read (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANACCESS , &val); + *portmap = (val &VSC73XX_VLANACCESS_VLAN_PORT_MASK ) >> +VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT ; + +return 0 ; +} + +static int +vsc73xx_write_vlan_table_entry (struct vsc73xx *vsc,u16 vid,u8 portmap) +{ +int ret; + +vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANTIDX , vid); + + ret =vsc73xx_wait_for_vlan_table_cmd (vsc); +if (ret) +return ret; + +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANACCESS , +VSC73XX_VLANACCESS_VLAN_TBL_CMD_MASK | +VSC73XX_VLANACCESS_VLAN_SRC_CHECK | +VSC73XX_VLANACCESS_VLAN_PORT_MASK , +VSC73XX_VLANACCESS_VLAN_TBL_CMD_WRITE_ENTRY | +VSC73XX_VLANACCESS_VLAN_SRC_CHECK | + (portmap <<VSC73XX_VLANACCESS_VLAN_PORT_MASK_SHIFT )); + +return vsc73xx_wait_for_vlan_table_cmd (vsc); +} + +static int +vsc73xx_update_vlan_table (struct vsc73xx *vsc,int port,u16 vid,bool set) +{ +u8 portmap; +int ret; + + ret =vsc73xx_read_vlan_table_entry (vsc, vid, &portmap); +if (ret) +return ret; + +if (set) + portmap |=BIT (port); +else + portmap &= ~BIT (port); + +return vsc73xx_write_vlan_table_entry (vsc, vid, portmap); +} +static int vsc73xx_setup (struct dsa_switch *ds) {struct vsc73xx *vsc = ds->priv;
@@ -598,7 +718,7 @@ static int vsc73xx_setup(struct dsa_switch *ds)VSC73XX_MACACCESS , VSC73XX_MACACCESS_CMD_CLEAR_TABLE); -/* Clear VLAN table */ +/* Set VLAN table to default values */ vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANACCESS ,VSC73XX_VLANACCESS_VLAN_TBL_CMD_CLEAR_TABLE );
@@ -627,6 +747,9 @@ static int vsc73xx_setup(struct dsa_switch *ds)vsc73xx_write (vsc,VSC73XX_BLOCK_SYSTEM ,0 ,VSC73XX_GMIIDELAY ,VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS |VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS ); +/* Ingess VLAN reception mask (table 145) */ +vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_VLANMASK , +0xff );/* IP multicast flood mask (table 144) */ vsc73xx_write (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_IFLODMSK ,0xff );
@@ -639,6 +762,12 @@ static int vsc73xx_setup(struct dsa_switch *ds)udelay (4 ); +/* Clear VLAN table */ +for (i =0 ; i <VLAN_N_VID ; i++) +vsc73xx_write_vlan_table_entry (vsc, i,0 ); + +INIT_LIST_HEAD (&vsc->vlans); +return 0 ; }
@@ -825,6 +954,12 @@ static void vsc73xx_mac_link_up(struct phylink_config *config, val |= seed <<VSC73XX_MAC_CFG_SEED_OFFSET ; val |=VSC73XX_MAC_CFG_SEED_LOAD ; val |=VSC73XX_MAC_CFG_WEXC_DIS ; + +/* Those bits are responsible for MTU only. Kernel takes care about MTU, +* let's enable +8 bytes frame length unconditionally. +*/ + val |=VSC73XX_MAC_CFG_VLAN_AWR |VSC73XX_MAC_CFG_VLAN_DBLAWR ; +vsc73xx_write (vsc,VSC73XX_BLOCK_MAC , port,VSC73XX_MAC_CFG , val);/* Flow control for the PHY facing ports:
@@ -853,15 +988,209 @@ static void vsc73xx_mac_link_up(struct phylink_config *config, VSC73XX_MAC_CFG_TX_EN | VSC73XX_MAC_CFG_RX_EN); } +static bool vsc73xx_tag_8021q_active (struct dsa_port *dp) +{ +return !dsa_port_is_vlan_filtering (dp); +} + +static struct vsc73xx_bridge_vlan * +vsc73xx_bridge_vlan_find (struct vsc73xx *vsc,u16 vid) +{ +struct vsc73xx_bridge_vlan *vlan; + +list_for_each_entry (vlan, &vsc->vlans, list) +if (vlan->vid == vid) +return vlan; + +return NULL ; +} + +static void +vsc73xx_bridge_vlan_remove_port (struct vsc73xx_bridge_vlan *vsc73xx_vlan, +int port) +{ + vsc73xx_vlan->portmask &= ~BIT (port); + +if (vsc73xx_vlan->portmask) +return ; + +list_del (&vsc73xx_vlan->list); +kfree (vsc73xx_vlan); +} + +static void vsc73xx_bridge_vlan_summary (struct vsc73xx *vsc,int port, +struct vsc73xx_vlan_summary *summary, +u16 ignored_vid) +{ +size_t num_tagged =0 , num_untagged =0 ; +struct vsc73xx_bridge_vlan *vlan; + +list_for_each_entry (vlan, &vsc->vlans, list) { +if (!(vlan->portmask &BIT (port)) || vlan->vid == ignored_vid) +continue ; + +if (vlan->untagged &BIT (port)) + num_untagged++; +else + num_tagged++; + } + + summary->num_untagged = num_untagged; + summary->num_tagged = num_tagged; +} + +static u16 vsc73xx_find_first_vlan_untagged (struct vsc73xx *vsc,int port) +{ +struct vsc73xx_bridge_vlan *vlan; + +list_for_each_entry (vlan, &vsc->vlans, list) +if ((vlan->portmask &BIT (port)) && + (vlan->untagged &BIT (port))) +return vlan->vid; + +return VLAN_N_VID ; +} + +static int vsc73xx_set_vlan_conf (struct vsc73xx *vsc,int port, +enum vsc73xx_port_vlan_conf port_vlan_conf) +{ +u32 val =0 ; +int ret; + +if (port_vlan_conf ==VSC73XX_VLAN_IGNORE ) + val =VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | +VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA ; + + ret =vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_CAT_VLAN_MISC , +VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | +VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA , val); +if (ret) +return ret; + + val = (port_vlan_conf ==VSC73XX_VLAN_FILTER ) ? +VSC73XX_TXUPDCFG_TX_INSERT_TAG :0 ; + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_TXUPDCFG , +VSC73XX_TXUPDCFG_TX_INSERT_TAG , val); +} + +static int vsc73xx_vlan_commit_conf (struct vsc73xx *vsc,int port) +{ +enum vsc73xx_port_vlan_conf port_vlan_conf =VSC73XX_VLAN_IGNORE ; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); + +if (port ==CPU_PORT ) { + port_vlan_conf =VSC73XX_VLAN_FILTER ; + }else if (dsa_port_is_vlan_filtering (dp)) { +struct vsc73xx_vlan_summary summary; + + port_vlan_conf =VSC73XX_VLAN_FILTER ; + +vsc73xx_bridge_vlan_summary (vsc, port, &summary,VLAN_N_VID ); +if (summary.num_tagged ==0 ) + port_vlan_conf =VSC73XX_VLAN_FILTER_UNTAG_ALL ; + } + +return vsc73xx_set_vlan_conf (vsc, port, port_vlan_conf); +} + +static int +vsc73xx_vlan_change_untagged (struct vsc73xx *vsc,int port,u16 vid,bool set) +{ +u32 val =0 ; + +if (set) + val =VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | + ((vid <<VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT ) & +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID ); + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_TXUPDCFG , +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID , val); +} + +static int vsc73xx_vlan_commit_untagged (struct vsc73xx *vsc,int port) +{ +struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; +bool valid = portinfo->untagged_tag_8021q_configured; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); +u16 vid = portinfo->untagged_tag_8021q; + +if (dsa_port_is_vlan_filtering (dp)) { +struct vsc73xx_vlan_summary summary; + +vsc73xx_bridge_vlan_summary (vsc, port, &summary,VLAN_N_VID ); + +if (summary.num_untagged >1 ) +/* Port must untag all vlans in that case. +* No need to commit untagged config change. +*/ +return 0 ; + + valid = (summary.num_untagged ==1 ); +if (valid) + vid =vsc73xx_find_first_vlan_untagged (vsc, port); + } + +return vsc73xx_vlan_change_untagged (vsc, port, vid, valid); +} + +static int +vsc73xx_vlan_change_pvid (struct vsc73xx *vsc,int port,u16 vid,bool set) +{ +u32 val =0 ; +int ret; + + val = set ?0 :VSC73XX_CAT_DROP_UNTAGGED_ENA ; + + ret =vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_CAT_DROP , +VSC73XX_CAT_DROP_UNTAGGED_ENA , val); +if (!set || ret) +return ret; + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_CAT_PORT_VLAN , +VSC73XX_CAT_PORT_VLAN_VLAN_VID , + vid &VSC73XX_CAT_PORT_VLAN_VLAN_VID ); +} + +static int vsc73xx_vlan_commit_pvid (struct vsc73xx *vsc,int port) +{ +struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; +bool valid = portinfo->pvid_tag_8021q_configured; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); +u16 vid = portinfo->pvid_tag_8021q; + +if (dsa_port_is_vlan_filtering (dp)) { + vid = portinfo->pvid_vlan_filtering; + valid = portinfo->pvid_vlan_filtering_configured; + } + +return vsc73xx_vlan_change_pvid (vsc, port, vid, valid); +} +static int vsc73xx_port_enable (struct dsa_switch *ds,int port,struct phy_device *phy) {struct vsc73xx *vsc = ds->priv; +int ret;dev_info (vsc->dev,"enable port %d\n" , port);vsc73xx_init_port (vsc, port); -return 0 ; + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port); }static void vsc73xx_port_disable (struct dsa_switch *ds,int port)
@@ -1032,6 +1361,184 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, config->mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000 ; } +static int +vsc73xx_port_vlan_filtering (struct dsa_switch *ds,int port, +bool vlan_filtering,struct netlink_ext_ack *extack) +{ +struct vsc73xx *vsc = ds->priv; +int ret; + +/* The commit to hardware processed below is required because vsc73xx +* is using tag_8021q. When vlan_filtering is disabled, tag_8021q uses +* pvid/untagged vlans for port recognition. The values configured for +* vlans and pvid/untagged states are stored in portinfo structure. +* When vlan_filtering is enabled, we need to restore pvid/untagged from +* portinfo structure. Analogous routine is processed when +* vlan_filtering is disabled, but values used for tag_8021q are +* restored. +*/ + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port); +} + +static int vsc73xx_port_vlan_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan, +struct netlink_ext_ack *extack) +{ +bool untagged = vlan->flags &BRIDGE_VLAN_INFO_UNTAGGED ; +bool pvid = vlan->flags &BRIDGE_VLAN_INFO_PVID ; +struct dsa_port *dp =dsa_to_port (ds, port); +struct vsc73xx_bridge_vlan *vsc73xx_vlan; +struct vsc73xx_vlan_summary summary; +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; +bool commit_to_hardware; +int ret =0 ; + +/* Be sure to deny alterations to the configuration done by tag_8021q. +*/ +if (vid_is_dsa_8021q (vlan->vid)) { +NL_SET_ERR_MSG_MOD (extack, +"Range 3072-4095 reserved for dsa_8021q operation" ); +return -EBUSY ; + } + +/* The processed vlan->vid is excluded from the search because the VLAN +* can be re-added with a different set of flags, so it's easiest to +* ignore its old flags from the VLAN database software copy. +*/ +vsc73xx_bridge_vlan_summary (vsc, port, &summary, vlan->vid); + +/* VSC73XX allow only three untagged states: none, one or all */ +if ((untagged && summary.num_tagged >0 && summary.num_untagged >0 ) || + (!untagged && summary.num_untagged >1 )) { +NL_SET_ERR_MSG_MOD (extack, +"Port can have only none, one or all untagged vlan" ); +return -EBUSY ; + } + + vsc73xx_vlan =vsc73xx_bridge_vlan_find (vsc, vlan->vid); + +if (!vsc73xx_vlan) { + vsc73xx_vlan =kzalloc (sizeof (*vsc73xx_vlan),GFP_KERNEL ); +if (!vsc73xx_vlan) +return -ENOMEM ; + + vsc73xx_vlan->vid = vlan->vid; + vsc73xx_vlan->portmask =0 ; + vsc73xx_vlan->untagged =0 ; + +list_add_tail (&vsc73xx_vlan->list, &vsc->vlans); + } + +/* CPU port must be always tagged because port separation is based on +* tag_8021q. +*/ +if (port ==CPU_PORT ) + goto update_vlan_table; + + vsc73xx_vlan->portmask |=BIT (port); + +if (untagged) + vsc73xx_vlan->untagged |=BIT (port); +else + vsc73xx_vlan->untagged &= ~BIT (port); + + portinfo = &vsc->portinfo[port]; + +if (pvid) { + portinfo->pvid_vlan_filtering_configured = true; + portinfo->pvid_vlan_filtering = vlan->vid; + }else if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) { + portinfo->pvid_vlan_filtering_configured = false; + } + + commit_to_hardware = !vsc73xx_tag_8021q_active (dp); +if (commit_to_hardware) { + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) + goto err; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) + goto err; + + ret =vsc73xx_vlan_commit_conf (vsc, port); +if (ret) + goto err; + } + +update_vlan_table: + ret =vsc73xx_update_vlan_table (vsc, port, vlan->vid, true); +if (!ret) +return 0 ; +err: +vsc73xx_bridge_vlan_remove_port (vsc73xx_vlan, port); +return ret; +} + +static int vsc73xx_port_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct vsc73xx_bridge_vlan *vsc73xx_vlan; +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; +bool commit_to_hardware; +int ret; + + ret =vsc73xx_update_vlan_table (vsc, port, vlan->vid, false); +if (ret) +return ret; + + portinfo = &vsc->portinfo[port]; + +if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) + portinfo->pvid_vlan_filtering_configured = false; + + vsc73xx_vlan =vsc73xx_bridge_vlan_find (vsc, vlan->vid); + +if (vsc73xx_vlan) +vsc73xx_bridge_vlan_remove_port (vsc73xx_vlan, port); + + commit_to_hardware = !vsc73xx_tag_8021q_active (dsa_to_port (ds, port)); +if (commit_to_hardware) { + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port); + } + +return 0 ; +} + +static int vsc73xx_port_setup (struct dsa_switch *ds,int port) +{ +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; + + portinfo = &vsc->portinfo[port]; + + portinfo->pvid_vlan_filtering_configured = false; + portinfo->pvid_tag_8021q_configured = false; + portinfo->untagged_tag_8021q_configured = false; + +return 0 ; +} +static void vsc73xx_refresh_fwd_map (struct dsa_switch *ds,int port,u8 state) {struct dsa_port *other_dp, *dp =dsa_to_port (ds, port);
@@ -1126,11 +1633,15 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, + .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set, + .port_vlan_filtering = vsc73xx_port_vlan_filtering, + .port_vlan_add = vsc73xx_port_vlan_add, + .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, };
drivers/net/dsa/vitesse-vsc73xx.h +42 -0
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net-next v2 02/12] net: dsa: vsc73xx: Add vlan filtering
Quoted 7 lines · Pawel Dembicki
This patch implements VLAN filtering for the vsc73xx driver.
After starting VLAN filtering, the switch is reconfigured from QinQ to a simple VLAN aware mode. This is required because VSC73XX chips do not support inner VLAN tag filtering.
Signed-off-by Pawel Dembicki <[email protected]>
Quoted 12 lines
---
v2:
- removed not neededINIT_LIST_HEAD
- fixvsc73xx_vlanremoving procedure
- fix code spell
- handle return codes from 'vsc73xx_vlan_commit*' functions
- move 'vsc73xx_vlan_commit*' call fromport_setuptoport_enableto avoid unused port configuration
v1:
- refactored pvid, untagged and vlan filter configuration
- fix typo
- simplification
Thanks for the changes. This is much simpler for my mind to process. Hopefully you won't mind a few nitpicks below.
Quoted 16 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +16
-0+static int vsc73xx_set_vlan_conf (struct vsc73xx *vsc,int port, +enum vsc73xx_port_vlan_conf port_vlan_conf) +{ +u32 val =0 ; +int ret; + +if (port_vlan_conf ==VSC73XX_VLAN_IGNORE ) + val =VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | +VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA ; + + ret =vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_CAT_VLAN_MISC , +VSC73XX_CAT_VLAN_MISC_VLAN_TCI_IGNORE_ENA | +VSC73XX_CAT_VLAN_MISC_VLAN_KEEP_TAG_ENA , val); +if (ret) +return ret;
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_mac_link_up(struct phylink_config *config, · line 1079
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+ + val = (port_vlan_conf ==VSC73XX_VLAN_FILTER ) ? +VSC73XX_TXUPDCFG_TX_INSERT_TAG :0 ; + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_TXUPDCFG , +VSC73XX_TXUPDCFG_TX_INSERT_TAG , val); +} + +static int vsc73xx_vlan_commit_conf (struct vsc73xx *vsc,int port)
Could you please add a kernel-doc stating what is the logical input and output of this routine? Something like:
/**
* vsc73xx_vlan_commit_conf - Update VLAN configuration of a port
* @vsc: Switch private data structure
* @port: Port index on which to operate
*
* Update the VLAN behavior of a port to make sure that when it is under
* a VLAN filtering bridge, the port is either filtering with tag
* preservation, or filtering with all VLANs egress-untagged. Otherwise,
* the port ignores VLAN tags from packets and applies the port-based
* VID.
*
* Must be called when changes are made to:
* - the bridge VLAN filtering state of the port
* - the number or attributes of VLANs from the bridge VLAN table,
* while the port is currently VLAN-aware
*/
Quoted 26 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +26
-0+{ +enum vsc73xx_port_vlan_conf port_vlan_conf =VSC73XX_VLAN_IGNORE ; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); + +if (port ==CPU_PORT ) { + port_vlan_conf =VSC73XX_VLAN_FILTER ; + }else if (dsa_port_is_vlan_filtering (dp)) { +struct vsc73xx_vlan_summary summary; + + port_vlan_conf =VSC73XX_VLAN_FILTER ; + +vsc73xx_bridge_vlan_summary (vsc, port, &summary,VLAN_N_VID ); +if (summary.num_tagged ==0 ) + port_vlan_conf =VSC73XX_VLAN_FILTER_UNTAG_ALL ; + } + +return vsc73xx_set_vlan_conf (vsc, port, port_vlan_conf); +} + +static int +vsc73xx_vlan_change_untagged (struct vsc73xx *vsc,int port,u16 vid,bool set) +{ +u32 val =0 ; + +if (set) + val = VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA |
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_mac_link_up(struct phylink_config *config, · line 1115
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+ ((vid <<VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_SHIFT ) & +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID ); + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_TXUPDCFG , +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID_ENA | +VSC73XX_TXUPDCFG_TX_UNTAGGED_VID , val); +} + +static int vsc73xx_vlan_commit_untagged (struct vsc73xx *vsc,int port)
/**
* vsc73xx_vlan_commit_untagged - Update native VLAN of a port
* @vsc: Switch private data structure
* @port: Port index on which to operate
*
* Update the native VLAN of a port (the one VLAN which is transmitted
* as egress-tagged on a trunk port).
*
* TODO: I need to figure out more about the implementation :) */
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_mac_link_up(struct phylink_config *config, · line 1120
Quoted 5 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +5
-0+{ +struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; +bool valid = portinfo->untagged_tag_8021q_configured; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); +u16 vid = portinfo->untagged_tag_8021q;
Question: when tag_8021q is active and the port is VSC73XX_VLAN_IGNORE, does the untagged_tag_8021q VID matter at all?
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (dsa_port_is_vlan_filtering(dp)) {
If not, wouldn't it be better to just return early and do nothing if !dsa_port_is_vlan_filtering(dp)?
Quoted 28 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +28
-0+struct vsc73xx_vlan_summary summary; + +vsc73xx_bridge_vlan_summary (vsc, port, &summary,VLAN_N_VID ); + +if (summary.num_untagged >1 ) +/* Port must untag all vlans in that case. +* No need to commit untagged config change. +*/ +return 0 ; + + valid = (summary.num_untagged ==1 ); +if (valid) + vid =vsc73xx_find_first_vlan_untagged (vsc, port); + } + +return vsc73xx_vlan_change_untagged (vsc, port, vid, valid); +} + +static int +vsc73xx_vlan_change_pvid (struct vsc73xx *vsc,int port,u16 vid,bool set) +{ +u32 val =0 ; +int ret; + + val = set ?0 :VSC73XX_CAT_DROP_UNTAGGED_ENA ; + + ret = vsc73xx_update_bits(vsc, VSC73XX_BLOCK_MAC, port, + VSC73XX_CAT_DROP,
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_mac_link_up(struct phylink_config *config, · line 1160
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+ VSC73XX_CAT_DROP_UNTAGGED_ENA, val); +if (!set || ret) +return ret; + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_MAC , port, +VSC73XX_CAT_PORT_VLAN , +VSC73XX_CAT_PORT_VLAN_VLAN_VID , + vid &VSC73XX_CAT_PORT_VLAN_VLAN_VID ); +} +
/**
* vsc73xx_vlan_commit_pvid - Update port-based default VLAN of a port
* @vsc: Switch private data structure
* @port: Port index on which to operate
*
* Update the PVID of a port so that it follows either the bridge PVID
* configuration, when the bridge is currently VLAN-aware, or the PVID
* from tag_8021q, when the port is standalone or under a VLAN-unaware
* bridge. A port with no PVID drops all untagged and VID 0 tagged
* traffic.
*
* Must be called when changes are made to:
* - the bridge VLAN filtering state of the port
* - the number or attributes of VLANs from the bridge VLAN table,
* while the port is currently VLAN-aware
*/
Quoted 56 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +40
-1+static int vsc73xx_vlan_commit_pvid (struct vsc73xx *vsc,int port) +{ +struct vsc73xx_portinfo *portinfo = &vsc->portinfo[port]; +bool valid = portinfo->pvid_tag_8021q_configured; +struct dsa_port *dp =dsa_to_port (vsc->ds, port); +u16 vid = portinfo->pvid_tag_8021q; + +if (dsa_port_is_vlan_filtering (dp)) { + vid = portinfo->pvid_vlan_filtering; + valid = portinfo->pvid_vlan_filtering_configured; + } + +return vsc73xx_vlan_change_pvid (vsc, port, vid, valid); +} +static int vsc73xx_port_enable (struct dsa_switch *ds,int port,struct phy_device *phy) {struct vsc73xx *vsc = ds->priv; +int ret;dev_info (vsc->dev,"enable port %d\n" , port);vsc73xx_init_port (vsc, port); -return 0 ; + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port); }static void vsc73xx_port_disable (struct dsa_switch *ds,int port)@@ -1032,6 +1361,184 @@ static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, config->mac_capabilities =MAC_SYM_PAUSE |MAC_10 |MAC_100 |MAC_1000 ; } +static int +vsc73xx_port_vlan_filtering (struct dsa_switch *ds,int port, +bool vlan_filtering,struct netlink_ext_ack *extack) +{ +struct vsc73xx *vsc = ds->priv; +int ret; + +/* The commit to hardware processed below is required because vsc73xx +* is using tag_8021q. When vlan_filtering is disabled, tag_8021q uses +* pvid/untagged vlans for port recognition. The values configured for +* vlans and pvid/untagged states are stored in portinfo structure. +* When vlan_filtering is enabled, we need to restore pvid/untagged from +* portinfo structure. Analogous routine is processed when +* vlan_filtering is disabled, but values used for tag_8021q are +* restored.
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1388
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+*/ + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port);
Could you please group these 3 calls together in a separate subroutine, like vsc73xx_port_update_vlan(), and just call that? The pattern is repeated in a number of places.
Quoted 21 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +21
-0+} + +static int vsc73xx_port_vlan_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan, +struct netlink_ext_ack *extack) +{ +bool untagged = vlan->flags &BRIDGE_VLAN_INFO_UNTAGGED ; +bool pvid = vlan->flags &BRIDGE_VLAN_INFO_PVID ; +struct dsa_port *dp =dsa_to_port (ds, port); +struct vsc73xx_bridge_vlan *vsc73xx_vlan; +struct vsc73xx_vlan_summary summary; +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; +bool commit_to_hardware; +int ret =0 ; + +/* Be sure to deny alterations to the configuration done by tag_8021q. +*/ +if (vid_is_dsa_8021q (vlan->vid)) { +NL_SET_ERR_MSG_MOD (extack, +"Range 3072-4095 reserved for dsa_8021q operation" );
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1419
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+return -EBUSY ; + } + +/* The processed vlan->vid is excluded from the search because the VLAN +* can be re-added with a different set of flags, so it's easiest to +* ignore its old flags from the VLAN database software copy. +*/ +vsc73xx_bridge_vlan_summary (vsc, port, &summary, vlan->vid); + +/* VSC73XX allow only three untagged states: none, one or all */
allows
Quoted 7 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +7
-0+if ((untagged && summary.num_tagged >0 && summary.num_untagged >0 ) || + (!untagged && summary.num_untagged >1 )) { +NL_SET_ERR_MSG_MOD (extack, +"Port can have only none, one or all untagged vlan" ); +return -EBUSY ; + } +
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1436
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+ vsc73xx_vlan =vsc73xx_bridge_vlan_find (vsc, vlan->vid); + +if (!vsc73xx_vlan) { + vsc73xx_vlan =kzalloc (sizeof (*vsc73xx_vlan),GFP_KERNEL ); +if (!vsc73xx_vlan) +return -ENOMEM ; + + vsc73xx_vlan->vid = vlan->vid; + vsc73xx_vlan->portmask =0 ; + vsc73xx_vlan->untagged =0 ;
kzalloc gives you 0-initialized memory, so "portmask" and "untagged" are already 0.
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1442
Quoted 6 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +6
-0+ +list_add_tail (&vsc73xx_vlan->list, &vsc->vlans); + } + +/* CPU port must be always tagged because port separation is based on +* tag_8021q.
I would say "source port identification" rather than separation.
Quoted 85 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +85
-0+*/ +if (port ==CPU_PORT ) + goto update_vlan_table; + + vsc73xx_vlan->portmask |=BIT (port); + +if (untagged) + vsc73xx_vlan->untagged |=BIT (port); +else + vsc73xx_vlan->untagged &= ~BIT (port); + + portinfo = &vsc->portinfo[port]; + +if (pvid) { + portinfo->pvid_vlan_filtering_configured = true; + portinfo->pvid_vlan_filtering = vlan->vid; + }else if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) { + portinfo->pvid_vlan_filtering_configured = false; + } + + commit_to_hardware = !vsc73xx_tag_8021q_active (dp); +if (commit_to_hardware) { + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) + goto err; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) + goto err; + + ret =vsc73xx_vlan_commit_conf (vsc, port); +if (ret) + goto err; + } + +update_vlan_table: + ret =vsc73xx_update_vlan_table (vsc, port, vlan->vid, true); +if (!ret) +return 0 ; +err: +vsc73xx_bridge_vlan_remove_port (vsc73xx_vlan, port); +return ret; +} + +static int vsc73xx_port_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct vsc73xx_bridge_vlan *vsc73xx_vlan; +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; +bool commit_to_hardware; +int ret; + + ret =vsc73xx_update_vlan_table (vsc, port, vlan->vid, false); +if (ret) +return ret; + + portinfo = &vsc->portinfo[port]; + +if (portinfo->pvid_vlan_filtering_configured && + portinfo->pvid_vlan_filtering == vlan->vid) + portinfo->pvid_vlan_filtering_configured = false; + + vsc73xx_vlan =vsc73xx_bridge_vlan_find (vsc, vlan->vid); + +if (vsc73xx_vlan) +vsc73xx_bridge_vlan_remove_port (vsc73xx_vlan, port); + + commit_to_hardware = !vsc73xx_tag_8021q_active (dsa_to_port (ds, port)); +if (commit_to_hardware) { + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret; + +return vsc73xx_vlan_commit_conf (vsc, port); + } + +return 0 ; +} +
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1537
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+static int vsc73xx_port_setup (struct dsa_switch *ds,int port) +{ +struct vsc73xx_portinfo *portinfo; +struct vsc73xx *vsc = ds->priv; + + portinfo = &vsc->portinfo[port]; + + portinfo->pvid_vlan_filtering_configured = false; + portinfo->pvid_tag_8021q_configured = false; + portinfo->untagged_tag_8021q_configured = false;
Initialization with 0, false etc isn't really needed. Not worth adding a DSA callback for no useful action.
Quoted 33 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +8
-0+ +return 0 ; +} +static void vsc73xx_refresh_fwd_map (struct dsa_switch *ds,int port,u8 state) {struct dsa_port *other_dp, *dp =dsa_to_port (ds, port);@@ -1126,11 +1633,15 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .get_strings = vsc73xx_get_strings, .get_ethtool_stats = vsc73xx_get_ethtool_stats, .get_sset_count = vsc73xx_get_sset_count, + .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set, + .port_vlan_filtering = vsc73xx_port_vlan_filtering, + .port_vlan_add = vsc73xx_port_vlan_add, + .port_vlan_del = vsc73xx_port_vlan_del, .phylink_get_caps = vsc73xx_phylink_get_caps, };drivers/net/dsa/vitesse-vsc73xx.h +2
-0@@ -14,6 +14,27 @@*/ #define VSC73XX_MAX_NUM_PORTS 8 +/** +* struct vsc73xx_portinfo - port data structure: contains storage data
drivers/net/dsa/vitesse-vsc73xx.h line 28
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx.h +10
-0+* @pvid_vlan_filtering_configured: imforms if port have configured pvid in vlan +* filtering mode +* @pvid_vlan_filtering: pvid vlan number used in vlan filtering mode +* @pvid_tag_8021q_configured: imforms if port have configured pvid in tag_8021q +* mode +* @pvid_tag_8021q: pvid vlan number used in tag_8021q mode +* @untagged_tag_8021q_configured: imforms if port have configured untagged vlan +* in tag_8021q mode +* @untagged_tag_8021q: untagged vlan number used in tag_8021q mode +*/
s/imforms/informs/
s/port have/port has/
drivers/net/dsa/vitesse-vsc73xx.h line 37
Quoted 9 lines
drivers/net/dsa/vitesse-vsc73xx.h +9
-0+struct vsc73xx_portinfo { +bool pvid_vlan_filtering_configured; +u16 pvid_vlan_filtering; +bool pvid_tag_8021q_configured; +u16 pvid_tag_8021q; +bool untagged_tag_8021q_configured; +u16 untagged_tag_8021q; +}; +
I think it may be more economical to put all u16 elements first, then all bool elements. Pahole should be able to tell.
Quoted 48 lines
drivers/net/dsa/vitesse-vsc73xx.h +21
-0/** * struct vsc73xx - VSC73xx state container: main data structure * @dev: The device pointer @@ -25,6 +46,10 @@* @addr: MAC address used in flow control frames * @ops: Structure with hardware-dependent operations * @priv: Pointer to the configuration interface structure +* @portinfo: Storage table portinfo structructures +* @vlans: List of configured vlans. Contains port mask and untagged status of +* every vlan configured in port vlan operation. It doesn't cover tag_8021q +* vlans. */ struct vsc73xx {struct device *dev;@@ -35,6 +60,8 @@ struct vsc73xx {u8 addr[ETH_ALEN ];const struct vsc73xx_ops *ops;void *priv; +struct vsc73xx_portinfo portinfo[VSC73XX_MAX_NUM_PORTS ]; +struct list_head vlans; };/** @@ -49,6 +76,21 @@ struct vsc73xx_ops { u32 val); }; +/** +* struct vsc73xx_bridge_vlan - VSC73xx driver structure which keeps vlan +* database copy +* @vid: VLAN number +* @portmask: each bit represents one port +* @untagged: each bit represents one port configured with @vid untagged +* @list: list structure +*/ +struct vsc73xx_bridge_vlan { +u16 vid; +u8 portmask; +u8 untagged; +struct list_head list; +}; +int vsc73xx_is_addr_valid (u8 block,u8 subblock);int vsc73xx_probe (struct vsc73xx *vsc);void vsc73xx_remove (struct vsc73xx *vsc);Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net-next v2 02/12] net: dsa: vsc73xx: Add vlan filtering
In reply to Pawel DembickiQuoted 11 lines · Pawel Dembicki
drivers/net/dsa/vitesse-vsc73xx-core.c +11
-0+ vsc73xx_vlan =vsc73xx_bridge_vlan_find (vsc, vlan->vid); + +if (!vsc73xx_vlan) { + vsc73xx_vlan =kzalloc (sizeof (*vsc73xx_vlan),GFP_KERNEL ); +if (!vsc73xx_vlan) +return -ENOMEM ; + + vsc73xx_vlan->vid = vlan->vid; + vsc73xx_vlan->portmask =0 ; + vsc73xx_vlan->untagged =0 ; +
drivers/net/dsa/vitesse-vsc73xx-core.c static void vsc73xx_phylink_get_caps(struct dsa_switch *dsa, int port, · line 1447
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+list_add_tail (&vsc73xx_vlan->list, &vsc->vlans); + } + +/* CPU port must be always tagged because port separation is based on +* tag_8021q. +*/ +if (port ==CPU_PORT ) + goto update_vlan_table; + + vsc73xx_vlan->portmask |=BIT (port);
This does not look correctly handled.
The CPU port is not recorded in the portmask of the newly created VLAN, because of the early goto.
So the VLAN structure will be freed from memory earlier than expected when it is deleted from a user port. Then the reference to the corresponding VLAN on the CPU port from the hardware VLAN table is lost.
PATCH v2 3/12 net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv()
In reply to Pawel DembickiFrom: Vladimir Oltean <[email protected]>
In both sja1105_rcv() and sja1110_rcv(), we may have precise source port information coming from parallel hardware mechanisms, in addition to the tag_8021q header.
Only sja1105_rcv() has extra logic to not overwrite that precise info with what's present in the VLAN tag. This is because sja1110_rcv() gets by, by having a reversed set of checks when assigning skb->dev. When the source port is imprecise (vbid >=1), source_port and switch_id will be set to zeroes by dsa_8021q_rcv(), which might be problematic. But by checking for vbid >= 1 first, sja1110_rcv() fends that off.
We would like to make more code common between sja1105_rcv() and sja1110_rcv(), and for that, we need to make sure that sja1110_rcv() also goes through the precise source port preservation logic.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8, v7, v6:
- resend only
v5:
- add missing SoB
v4:
- introduced patch
--- net/dsa/tag_8021q.c | 32 +++++++++++++++++++++++++++++--- net/dsa/tag_sja1105.c | 23 +++-------------------- 2 files changed, 32 insertions(+), 23 deletions(-)
net/dsa/tag_8021q.c +29 -3
@@ -497,9 +497,21 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit, }EXPORT_SYMBOL_GPL (dsa_tag_8021q_find_port_by_vbid); +/** +* dsa_8021q_rcv - Decode source information from tag_8021q header +* @skb: RX socket buffer +* @source_port: pointer to storage for precise source port information. +* If this is known already from outside tag_8021q, the pre-initialized +* value is preserved. If not known, pass -1. +* @switch_id: similar to source_port. +* @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized +* with -1. If a positive value is returned, the source_port and switch_id +* are invalid. +*/ void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id,int *vbid) { +int tmp_source_port, tmp_switch_id, tmp_vbid;u16 vid, tci;if (skb_vlan_tag_present (skb)) {
@@ -513,11 +525,25 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, vid = tci &VLAN_VID_MASK ; - *source_port =dsa_8021q_rx_source_port (vid); - *switch_id =dsa_8021q_rx_switch_id (vid); + tmp_source_port =dsa_8021q_rx_source_port (vid); + tmp_switch_id =dsa_8021q_rx_switch_id (vid); + tmp_vbid =dsa_tag_8021q_rx_vbid (vid); + +/* Precise source port information is unknown when receiving from a +* VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id +* are zeroes in this case. +* +* Preserve the source information from hardware-specific mechanisms, +* if available. This allows us to not overwrite a valid source port +* and switch ID with less precise values. +*/ +if (tmp_vbid ==0 && *source_port ==-1 ) + *source_port = tmp_source_port; +if (tmp_vbid ==0 && *switch_id ==-1 ) + *switch_id = tmp_switch_id;if (vbid) - *vbid =dsa_tag_8021q_rx_vbid (vid); + *vbid = tmp_vbid; skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; }
net/dsa/tag_sja1105.c +3 -20
@@ -524,30 +524,13 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,/* Normal data plane traffic and link-local frames are tagged with * a tag_8021q VLAN which we have to strip */ -if (sja1105_skb_has_tag_8021q (skb)) { -int tmp_source_port =-1 , tmp_switch_id =-1 ; - -sja1105_vlan_rcv (skb, &tmp_source_port, &tmp_switch_id, &vbid, - &vid); -/* Preserve the source information from the INCL_SRCPT option, -* if available. This allows us to not overwrite a valid source -* port and switch ID with zeroes when receiving link-local -* frames from a VLAN-unaware bridged port (non-zero vbid) or a -* VLAN-aware bridged port (non-zero vid). Furthermore, the -* tag_8021q source port information is only of trust when the -* vbid is 0 (precise port). Otherwise, tmp_source_port and -* tmp_switch_id will be zeroes. -*/ -if (vbid ==0 && source_port ==-1 ) - source_port = tmp_source_port; -if (vbid ==0 && switch_id ==-1 ) - switch_id = tmp_switch_id; - }else if (source_port ==-1 && switch_id ==-1 ) { +if (sja1105_skb_has_tag_8021q (skb)) +sja1105_vlan_rcv (skb, &source_port, &switch_id, &vbid, &vid); +else if (source_port ==-1 && switch_id ==-1 )/* Packets with no source information have no chance of * getting accepted, drop them straight away. */ return NULL ; - }if (source_port !=-1 && switch_id !=-1 ) skb->dev =dsa_conduit_find_user (netdev, switch_id, source_port);
Signature · 1 line
2.34.1
Re: [PATCH net-next v2 03/12] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv()
Quoted 13 lines · Pawel Dembicki
From: Vladimir Oltean <[email protected]>
In both
sja1105_rcv()andsja1110_rcv(), we may have precise source port information coming from parallel hardware mechanisms, in addition to thetag_8021qheader.Only
sja1105_rcv()has extra logic to not overwrite that precise info with what's present in the VLAN tag. This is becausesja1110_rcv()gets by, by having a reversed set of checks when assigningskb->dev. When the source port is imprecise (vbid >=1),source_portandswitch_idwill be set to zeroes bydsa_8021q_rcv(), which might be problematic. But by checking for vbid >= 1 first,sja1110_rcv()fends that off.
Quoted 7 lines
We would like to make more code common between
sja1105_rcv()andsja1110_rcv(), and for that, we need to make sure thatsja1110_rcv()also goes through the precise source port preservation logic.Signed-off-by Vladimir Oltean <[email protected]>Signed-off-by Pawel Dembicki <[email protected]>---
PATCH v2 4/12 net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv()
In reply to Pawel DembickiFrom: Vladimir Oltean <[email protected]>
tag_sja1105 has a wrapper over dsa_8021q_rcv(): sja1105_vlan_rcv(), which determines whether the packet came from a bridge with vlan_filtering=1 (the case resolved via dsa_find_designated_bridge_port_by_vid()), or if it contains a tag_8021q header.
Looking at a new tagger implementation for vsc73xx, based also on tag_8021q, it is becoming clear that the logic is needed there as well. So instead of forcing each tagger to wrap around dsa_8021q_rcv(), let's merge the logic into the core.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8, v7, v6:
- resend only
v5:
- add missing SoB
v4:
- introduced patch
--- net/dsa/tag_8021q.c | 34 ++++++++++++++++++++++++++++------ net/dsa/tag_8021q.h | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 32 ++++---------------------------- 4 files changed, 34 insertions(+), 36 deletions(-)
net/dsa/tag_8021q.c +28 -6
@@ -507,27 +507,39 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid);* @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized * with -1. If a positive value is returned, the source_port and switch_id * are invalid. +* @vid: pointer to storage for original VID, in case tag_8021q decoding failed. +* +* If the packet has a tag_8021q header, decode it and set @source_port, +* @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the +* header in the hwaccel area of the packet. */ void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id, -int *vbid) +int *vbid,int *vid) {int tmp_source_port, tmp_switch_id, tmp_vbid; -u16 vid, tci; +__be16 vlan_proto; +u16 tmp_vid, tci;if (skb_vlan_tag_present (skb)) { + vlan_proto = skb->vlan_proto; tci =skb_vlan_tag_get (skb);__vlan_hwaccel_clear_tag (skb); }else { +struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); + + vlan_proto = hdr->h_vlan_proto;skb_push_rcsum (skb,ETH_HLEN );__skb_vlan_pop (skb, &tci);skb_pull_rcsum (skb,ETH_HLEN ); } - vid = tci &VLAN_VID_MASK ; + tmp_vid = tci &VLAN_VID_MASK ; +if (!vid_is_dsa_8021q (tmp_vid)) + goto not_tag_8021q; - tmp_source_port =dsa_8021q_rx_source_port (vid); - tmp_switch_id =dsa_8021q_rx_switch_id (vid); - tmp_vbid =dsa_tag_8021q_rx_vbid (vid); + tmp_source_port =dsa_8021q_rx_source_port (tmp_vid); + tmp_switch_id =dsa_8021q_rx_switch_id (tmp_vid); + tmp_vbid =dsa_tag_8021q_rx_vbid (tmp_vid);/* Precise source port information is unknown when receiving from a * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id
@@ -546,5 +558,15 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, *vbid = tmp_vbid; skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; +return ; + +not_tag_8021q: +if (vid) + *vid = tmp_vid; +if (vbid) + *vbid =-1 ; + +/* Put the tag back */ +__vlan_hwaccel_put_tag (skb, vlan_proto, tci); }EXPORT_SYMBOL_GPL (dsa_8021q_rcv);
net/dsa/tag_8021q.h +1 -1
@@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, u16 tpid, u16 tci);void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id, -int *vbid); +int *vbid,int *vid);struct net_device *dsa_tag_8021q_find_port_by_vbid (struct net_device *conduit,int vbid);
net/dsa/tag_ocelot_8021q.c +1 -1
@@ -81,7 +81,7 @@ static struct sk_buff *ocelot_rcv(struct sk_buff *skb, {int src_port, switch_id; -dsa_8021q_rcv (skb, &src_port, &switch_id,NULL ); +dsa_8021q_rcv (skb, &src_port, &switch_id,NULL ,NULL ); skb->dev =dsa_conduit_find_user (netdev, switch_id, src_port);if (!skb->dev)
net/dsa/tag_sja1105.c +4 -28
@@ -472,37 +472,14 @@ static bool sja1110_skb_has_inband_control_extension(const struct sk_buff *skb)return ntohs (eth_hdr (skb)->h_proto) ==ETH_P_SJA1110 ; } -/* If the VLAN in the packet is a tag_8021q one, set @source_port and -* @switch_id and strip the header. Otherwise set @vid and keep it in the -* packet. -*/ -static void sja1105_vlan_rcv (struct sk_buff *skb,int *source_port, -int *switch_id,int *vbid,u16 *vid) -{ -struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); -u16 vlan_tci; - -if (skb_vlan_tag_present (skb)) - vlan_tci =skb_vlan_tag_get (skb); -else - vlan_tci =ntohs (hdr->h_vlan_TCI); - -if (vid_is_dsa_8021q (vlan_tci &VLAN_VID_MASK )) -return dsa_8021q_rcv (skb, source_port, switch_id, vbid); - -/* Try our best with imprecise RX */ - *vid = vlan_tci &VLAN_VID_MASK ; -} -static struct sk_buff *sja1105_rcv (struct sk_buff *skb,struct net_device *netdev) { -int source_port =-1 , switch_id =-1 , vbid =-1 ; +int source_port =-1 , switch_id =-1 , vbid =-1 , vid =-1 ;struct sja1105_meta meta = {0 };struct ethhdr *hdr;bool is_link_local;bool is_meta; -u16 vid; hdr =eth_hdr (skb); is_link_local =sja1105_is_link_local (skb);
@@ -525,7 +502,7 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,* a tag_8021q VLAN which we have to strip */ if (sja1105_skb_has_tag_8021q (skb)) -sja1105_vlan_rcv (skb, &source_port, &switch_id, &vbid, &vid); +dsa_8021q_rcv (skb, &source_port, &switch_id, &vbid, &vid);else if (source_port ==-1 && switch_id ==-1 )/* Packets with no source information have no chance of * getting accepted, drop them straight away.
@@ -660,9 +637,8 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb,static struct sk_buff *sja1110_rcv (struct sk_buff *skb,struct net_device *netdev) { -int source_port =-1 , switch_id =-1 , vbid =-1 ; +int source_port =-1 , switch_id =-1 , vbid =-1 , vid =-1 ;bool host_only = false; -u16 vid =0 ;if (sja1110_skb_has_inband_control_extension (skb)) { skb = sja1110_rcv_inband_control_extension(skb, &source_port,
@@ -674,7 +650,7 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,/* Packets with in-band control extensions might still have RX VLANs */ if (likely (sja1105_skb_has_tag_8021q (skb))) -sja1105_vlan_rcv (skb, &source_port, &switch_id, &vbid, &vid); +dsa_8021q_rcv (skb, &source_port, &switch_id, &vbid, &vid);if (vbid >=1 ) skb->dev =dsa_tag_8021q_find_port_by_vbid (netdev, vbid);
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net-next v2 04/12] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv()
Quoted 64 lines · Pawel Dembicki
From: Vladimir Oltean <[email protected]>
tag_sja1105has a wrapper overdsa_8021q_rcv():sja1105_vlan_rcv(), which determines whether the packet came from a bridge with vlan_filtering=1 (the case resolved viadsa_find_designated_bridge_port_by_vid()), or if it contains atag_8021qheader.Looking at a new tagger implementation for vsc73xx, based also on
tag_8021q, it is becoming clear that the logic is needed there as well. So instead of forcing each tagger to wrap arounddsa_8021q_rcv(), let's merge the logic into the core.Signed-off-by Vladimir Oltean <[email protected]>Signed-off-by Pawel Dembicki <[email protected]>---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8, v7, v6:
- resend only
v5:
- add missing SoB
v4:
- introduced patch--- net/dsa/tag_8021q.c | 34 ++++++++++++++++++++++++++++------ net/dsa/tag_8021q.h | 2 +- net/dsa/tag_ocelot_8021q.c | 2 +- net/dsa/tag_sja1105.c | 32 ++++---------------------------- 4 files changed, 34 insertions(+), 36 deletions(-)net/dsa/tag_8021q.c +11
-2@@ -507,27 +507,39 @@ EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid);* @vbid: pointer to storage for imprecise bridge ID. Must be pre-initialized * with -1. If a positive value is returned, the source_port and switch_id * are invalid. +* @vid: pointer to storage for original VID, in case tag_8021q decoding failed. +* +* If the packet has a tag_8021q header, decode it and set @source_port, +* @switch_id and @vbid, and strip the header. Otherwise set @vid and keep the +* header in the hwaccel area of the packet. */ void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id, -int *vbid) +int *vbid,int *vid) {int tmp_source_port, tmp_switch_id, tmp_vbid; -u16 vid, tci; +__be16 vlan_proto; +u16 tmp_vid, tci;if (skb_vlan_tag_present (skb)) { + vlan_proto = skb->vlan_proto; tci =skb_vlan_tag_get (skb);__vlan_hwaccel_clear_tag (skb); }else { +struct vlan_ethhdr *hdr =vlan_eth_hdr (skb); +
net/dsa/tag_8021q.c EXPORT_SYMBOL_GPL(dsa_tag_8021q_find_port_by_vbid); · line 538
Quoted 10 lines
net/dsa/tag_8021q.c +4
-1+ vlan_proto = hdr->h_vlan_proto;skb_push_rcsum (skb,ETH_HLEN );__skb_vlan_pop (skb, &tci);skb_pull_rcsum (skb,ETH_HLEN ); } - vid = tci &VLAN_VID_MASK ; + tmp_vid = tci &VLAN_VID_MASK ; +if (!vid_is_dsa_8021q (tmp_vid)) + goto not_tag_8021q;
I think this may be more clearly expressed linearly, without a goto.
if (!vid_is_dsa_8021q(tmp_vid)) {
/* Not a tag_8021q frame, so return the VID to the
* caller for further processing, and put the tag back
*/
if (vid)
*vid = tmp_vid;
__vlan_hwaccel_put_tag(skb, vlan_proto, tci);
return;
}Quoted 11 lines
net/dsa/tag_8021q.c +3
-3- tmp_source_port =dsa_8021q_rx_source_port (vid); - tmp_switch_id =dsa_8021q_rx_switch_id (vid); - tmp_vbid =dsa_tag_8021q_rx_vbid (vid); + tmp_source_port =dsa_8021q_rx_source_port (tmp_vid); + tmp_switch_id =dsa_8021q_rx_switch_id (tmp_vid); + tmp_vbid =dsa_tag_8021q_rx_vbid (tmp_vid);/* Precise source port information is unknown when receiving from a * VLAN-unaware bridging domain, and tmp_source_port and tmp_switch_id
net/dsa/tag_8021q.c void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, · line 567
Quoted 10 lines
net/dsa/tag_8021q.c +7
-0@@ -546,5 +558,15 @@ void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, *vbid = tmp_vbid; skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; +return ; + +not_tag_8021q: +if (vid) + *vid = tmp_vid; +if (vbid) + *vbid =-1 ;
Thinking more about it, I don't think this is needed (hence it is missing in my rewritten snippet above). I mean, *vbid is already initialized with -1 (it's a requirement also specified in the kernel-doc) and we haven't changed it.
Quoted 18 lines
net/dsa/tag_8021q.c +3
-0+ +/* Put the tag back */ +__vlan_hwaccel_put_tag (skb, vlan_proto, tci); }EXPORT_SYMBOL_GPL (dsa_8021q_rcv);net/dsa/tag_8021q.h +1
-1@@ -14,7 +14,7 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, u16 tpid, u16 tci);void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id, -int *vbid); +int *vbid,int *vid);struct net_device *dsa_tag_8021q_find_port_by_vbid (struct net_device *conduit,int vbid);
Re: [PATCH net-next v2 04/12] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() into dsa_8021q_rcv()
In reply to Pawel Dembickinet/dsa/tag_8021q.c void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id, · line 567
Quoted 5 lines · Pawel Dembicki
net/dsa/tag_8021q.c +5
-0+not_tag_8021q: +if (vid) + *vid = tmp_vid; +if (vbid) + *vbid =-1 ;
I can confirm that the vbid assignment isn't needed here.
Quoted 4 lines
net/dsa/tag_8021q.c +3
-0+ +/* Put the tag back */ +__vlan_hwaccel_put_tag (skb, vlan_proto, tci); }
PATCH v2 5/12 net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too
In reply to Pawel DembickiFrom: Vladimir Oltean <[email protected]>
Now that dsa_8021q_rcv() handles better the case where we don't overwrite the precise source information if it comes from an external (non-tag_8021q) source, we can now unify the call sequence between sja1105_rcv() and sja1110_rcv().
This is a preparatory change for creating a higher-level wrapper for the entire sequence which will live in tag_8021q.
---
v2, v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8,v7,v6,v5:
- resend only
v4:
- introduce patch and replace 'slave' with 'conduit' after rebase
--- net/dsa/tag_sja1105.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa/tag_sja1105.c +4 -4
@@ -652,12 +652,12 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,if (likely (sja1105_skb_has_tag_8021q (skb)))dsa_8021q_rcv (skb, &source_port, &switch_id, &vbid, &vid); -if (vbid >=1 ) +if (source_port !=-1 && switch_id !=-1 ) + skb->dev =dsa_conduit_find_user (netdev, switch_id, source_port); +else if (vbid >=1 ) skb->dev =dsa_tag_8021q_find_port_by_vbid (netdev, vbid); -else if (source_port ==-1 || switch_id ==-1 ) - skb->dev =dsa_find_designated_bridge_port_by_vid (netdev, vid);else - skb->dev =dsa_conduit_find_user (netdev, switch_id, source_port); + skb->dev =dsa_find_designated_bridge_port_by_vid (netdev, vid);if (!skb->dev) {netdev_warn (netdev,"Couldn't decode source port\n" );return NULL ;
Signature · 1 line
2.34.1
Re: [PATCH net-next v2 05/12] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too
Quoted 7 lines · Pawel Dembicki
From: Vladimir Oltean <[email protected]>
Now that
dsa_8021q_rcv()handles better the case where we don't overwrite the precise source information if it comes from an external (non-tag_8021q) source, we can now unify the call sequence betweensja1105_rcv()andsja1110_rcv().
Quoted 6 lines
This is a preparatory change for creating a higher-level wrapper for the entire sequence which will live in
tag_8021q.Signed-off-by Vladimir Oltean <[email protected]>Signed-off-by Pawel Dembicki <[email protected]>---
PATCH v2 6/12 net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user()
In reply to Pawel DembickiFrom: Vladimir Oltean <[email protected]>
A new tagging protocol implementation based on tag_8021q is on the horizon, and it appears that it also has to open-code the complicated logic of finding a source port based on a VLAN header.
Create a single dsa_tag_8021q_find_user() and make sja1105 call it.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- resend only
v7:
- added 'Reviewed-by' only
v6, v5:
- resend only
v4:
- introduce patch and change from master to conduit and slave to user
--- net/dsa/tag_8021q.c | 19 ++++++++++++++++--- net/dsa/tag_8021q.h | 5 +++-- net/dsa/tag_sja1105.c | 17 +++++------------ 3 files changed, 24 insertions(+), 17 deletions(-)
net/dsa/tag_8021q.c +16 -3
@@ -468,8 +468,8 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, }EXPORT_SYMBOL_GPL (dsa_8021q_xmit); -struct net_device *dsa_tag_8021q_find_port_by_vbid (struct net_device *conduit, -int vbid) +static struct net_device * +dsa_tag_8021q_find_port_by_vbid (struct net_device *conduit,int vbid) {struct dsa_port *cpu_dp = conduit->dsa_ptr;struct dsa_switch_tree *dst = cpu_dp->dst;
@@ -495,7 +495,20 @@ struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *conduit,return NULL ; } -EXPORT_SYMBOL_GPL (dsa_tag_8021q_find_port_by_vbid); + +struct net_device *dsa_tag_8021q_find_user (struct net_device *conduit, +int source_port,int switch_id, +int vid,int vbid) +{ +/* Always prefer precise source port information, if available */ +if (source_port !=-1 && switch_id !=-1 ) +return dsa_conduit_find_user (conduit, switch_id, source_port); +else if (vbid >=1 ) +return dsa_tag_8021q_find_port_by_vbid (conduit, vbid); + +return dsa_find_designated_bridge_port_by_vid (conduit, vid); +} +EXPORT_SYMBOL_GPL (dsa_tag_8021q_find_user);/** * dsa_8021q_rcv - Decode source information from tag_8021q header
net/dsa/tag_8021q.h +3 -2
@@ -16,8 +16,9 @@ struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,void dsa_8021q_rcv (struct sk_buff *skb,int *source_port,int *switch_id,int *vbid,int *vid); -struct net_device *dsa_tag_8021q_find_port_by_vbid (struct net_device *conduit, -int vbid); +struct net_device *dsa_tag_8021q_find_user (struct net_device *conduit, +int source_port,int switch_id, +int vid,int vbid);int dsa_switch_tag_8021q_vlan_add (struct dsa_switch *ds,struct dsa_notifier_tag_8021q_vlan_info *info);
net/dsa/tag_sja1105.c +5 -12
@@ -509,12 +509,8 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,*/ return NULL ; -if (source_port !=-1 && switch_id !=-1 ) - skb->dev =dsa_conduit_find_user (netdev, switch_id, source_port); -else if (vbid >=1 ) - skb->dev =dsa_tag_8021q_find_port_by_vbid (netdev, vbid); -else - skb->dev =dsa_find_designated_bridge_port_by_vid (netdev, vid); + skb->dev =dsa_tag_8021q_find_user (netdev, source_port, switch_id, + vid, vbid);if (!skb->dev) {netdev_warn (netdev,"Couldn't decode source port\n" );return NULL ;
@@ -652,12 +648,9 @@ static struct sk_buff *sja1110_rcv(struct sk_buff *skb,if (likely (sja1105_skb_has_tag_8021q (skb)))dsa_8021q_rcv (skb, &source_port, &switch_id, &vbid, &vid); -if (source_port !=-1 && switch_id !=-1 ) - skb->dev =dsa_conduit_find_user (netdev, switch_id, source_port); -else if (vbid >=1 ) - skb->dev =dsa_tag_8021q_find_port_by_vbid (netdev, vbid); -else - skb->dev =dsa_find_designated_bridge_port_by_vid (netdev, vid); + skb->dev =dsa_tag_8021q_find_user (netdev, source_port, switch_id, + vid, vbid); +if (!skb->dev) {netdev_warn (netdev,"Couldn't decode source port\n" );return NULL ;
Signature · 1 line
2.34.1
PATCH v2 7/12 net: dsa: vsc73xx: introduce tag 8021q for vsc73xx
In reply to Pawel DembickiThis commit introduces a new tagger based on 802.1q tagging. It's designed for the vsc73xx driver. The VSC73xx family doesn't have any tag support for the RGMII port, but it could be based on VLANs.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- added 'Reviewed-by' only
v7:
- replace netdev_warn by dev_warn_ratelimited
v6:
- added missing MODULE_DESCRIPTION()
v5:
- removed skb_vlan_tag_present(skb) checking
- use 80 characters per line limit
v4:
- rebase to net-next/main
v3:
- Introduce a patch after the tagging patch split
--- include/net/dsa.h | 2 ++ net/dsa/Kconfig | 6 ++++ net/dsa/Makefile | 1 + net/dsa/tag_vsc73xx_8021q.c | 68 +++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 net/dsa/tag_vsc73xx_8021q.c
include/net/dsa.h +2 -0
@@ -53,6 +53,7 @@ struct tc_action;#define DSA_TAG_PROTO_RTL8_4T_VALUE 25#define DSA_TAG_PROTO_RZN1_A5PSW_VALUE 26#define DSA_TAG_PROTO_LAN937X_VALUE 27 +#define DSA_TAG_PROTO_VSC73XX_8021Q_VALUE 28enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -83,6 +84,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_RTL8_4T =DSA_TAG_PROTO_RTL8_4T_VALUE ,DSA_TAG_PROTO_RZN1_A5PSW =DSA_TAG_PROTO_RZN1_A5PSW_VALUE ,DSA_TAG_PROTO_LAN937X =DSA_TAG_PROTO_LAN937X_VALUE , + DSA_TAG_PROTO_VSC73XX_8021Q = DSA_TAG_PROTO_VSC73XX_8021Q_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +6 -0
@@ -166,6 +166,12 @@ config NET_DSA_TAG_TRAILER Say Y or M if you want to enable support for tagging frames at with a trailed. e.g. Marvell 88E6060. +config NET_DSA_TAG_VSC73XX_8021Q + tristate "Tag driver for Microchip/Vitesse VSC73xx family of switches, using VLAN" + help + Say Y or M if you want to enable support for tagging frames with a + custom VLAN-based header. + config NET_DSA_TAG_XRS700X tristate "Tag driver for XRS700x switches" help
net/dsa/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_NET_DSA_TAG_RTL8_4) += tag_rtl8_4.o obj-$(CONFIG_NET_DSA_TAG_RZN1_A5PSW) += tag_rzn1_a5psw.o obj-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o obj-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o +obj-$(CONFIG_NET_DSA_TAG_VSC73XX_8021Q) += tag_vsc73xx_8021q.o obj-$(CONFIG_NET_DSA_TAG_XRS700X) += tag_xrs700x.o # for tracing framework to find trace.h
net/dsa/tag_vsc73xx_8021q.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 8/12 net: dsa: vsc73xx: Implement the tag_8021q VLAN operations
In reply to Pawel DembickiThis patch is a simple implementation of 802.1q tagging in the vsc73xx driver. Currently, devices with DSA_TAG_PROTO_NONE are not functional. The VSC73XX family doesn't provide any tag support for external Ethernet ports.
The only option available is VLAN-based tagging, which requires constant hardware VLAN filtering. While the VSC73XX family supports provider bridging, it only supports QinQ without full implementation of 802.1AD. This means it only allows the doubled 0x8100 TPID.
In the simple port mode, QinQ is enabled to preserve forwarding of VLAN-tagged frames.
---
v2:
- handle raturn values of 'vsc73xx_vlan_commit*' functions
v1:
- added dsa_tag_8021q_unregister in teardown function
- moved dsa_tag_8021q_register after vlan database clean operation
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- resend only
v7:
- adjust tag8021q implementation for vlan filtering implementation changes
v6:
- resend only
v5:
- improve commit message
v4:
- adjust tag8021q implementation for changed untagged vlan storage
- minor fixes
v3:
- Split tagger and tag implementation into separate commits
--- drivers/net/dsa/Kconfig | 2 +- drivers/net/dsa/vitesse-vsc73xx-core.c | 62 ++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-)
drivers/net/dsa/Kconfig +1 -1
@@ -127,7 +127,7 @@ config NET_DSA_SMSC_LAN9303_MDIO config NET_DSA_VITESSE_VSC73XX tristate - select NET_DSA_TAG_NONE + select NET_DSA_TAG_VSC73XX_8021Q select FIXED_PHY select VITESSE_PHY select GPIOLIB
drivers/net/dsa/vitesse-vsc73xx-core.c +59 -3
98 lines not on this page · raw message
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net-next v2 08/12] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations
Quoted 6 lines · Pawel Dembicki
drivers/net/dsa/vitesse-vsc73xx-core.c +6
-0+static int vsc73xx_tag_8021q_vlan_add (struct dsa_switch *ds,int port,u16 vid, +u16 flags) +{ +bool untagged = flags &BRIDGE_VLAN_INFO_UNTAGGED ; +bool pvid = flags &BRIDGE_VLAN_INFO_PVID ; +struct vsc73xx_portinfo *portinfo;
drivers/net/dsa/vitesse-vsc73xx-core.c static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, · line 1554
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+struct vsc73xx *vsc = ds->priv; +bool commit_to_hardware; +int ret; + + portinfo = &vsc->portinfo[port]; + +if (untagged) { + portinfo->untagged_tag_8021q_configured = true; + portinfo->untagged_tag_8021q = vid; + }
This is something I don't really like, but I understand why you're doing it. dsa_tag_8021q_bridge_join() first adds the bridge_vid and only then deletes the standalone_vid. Both are egress-untagged.
The fact that you have storage in this driver for a single egress-tagged tag_8021q VLAN makes it awkward if not impossible to track the deletion properly from tag_8021q_vlan_del(). You just record the last added VID in tag_8021q_vlan_add() and silently discard any previous one during the VSC73XX_TXUPDCFG_TX_UNTAGGED_VID setting, earlier than the deletion API.
I'm wondering if this isn't actually a self-inflicted problem created by the data structures in use. I see that when the port is in VSC73XX_VLAN_IGNORE (which it is for tag_8021q), VSC73XX_TXUPDCFG_TX_INSERT_TAG will be unset. So the port is egress-untagged for all VIDs, and there's little point in tracking any one single egress untagged VID coming from tag_8021q. No?
Wouldn't it be better, assuming that is the case, to just return an error if this is a user port and tag_8021q is requesting a VID which is _not_ egress-untagged? If you also respond positively to my comment about returning early in vsc73xx_vlan_commit_untagged() without doing anything in the tag_8021q case, then you can actually get rid of untagged_tag_8021q_configured and untagged_tag_8021q from portinfo.
Quoted 4 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +4
-0+if (pvid) { + portinfo->pvid_tag_8021q_configured = true; + portinfo->pvid_tag_8021q = vid; + }
drivers/net/dsa/vitesse-vsc73xx-core.c static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, · line 1568
Quoted 10 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +10
-0+ + commit_to_hardware =vsc73xx_tag_8021q_active (dsa_to_port (ds, port)); +if (commit_to_hardware) { + ret =vsc73xx_vlan_commit_untagged (vsc, port); +if (ret) +return ret; + + ret =vsc73xx_vlan_commit_pvid (vsc, port); +if (ret) +return ret;
Hmm, here I notice that the vsc73xx_vlan_commit_conf() call is missing. Am I right that if you add it here, then the entire vsc73xx_vlan_commit_*() string of 3 calls from vsc73xx_port_enable() becomes unnecessary?
The tag_8021q VLAN add operations are initiated by you when you call dsa_tag_8021q_register(). So you have good control over when the VLAN configuration of the port for standalone mode is done.
drivers/net/dsa/vitesse-vsc73xx-core.c static int vsc73xx_port_vlan_del(struct dsa_switch *ds, int port, · line 1577
Quoted 9 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +9
-0+ } + +return vsc73xx_update_vlan_table (vsc, port, vid, true); +} + +static int vsc73xx_tag_8021q_vlan_del (struct dsa_switch *ds,int port,u16 vid) +{ +struct vsc73xx *vsc = ds->priv; +
As a matter of API compliance, I guess you could add a snippet:
if (portinfo->pvid_tag_8021q_configured &&
portinfo->pvid_tag_8021q == vid) {
portinfo->pvid_tag_8021q_configured = false;
if (commit_to_hardware) {
err = vsc73xx_vlan_commit_pvid(vsc, port);
if (err)
return err;
}
}Of course, this is not to say that tag_8021q will _currently_ configure ports for an operating mode without PVID. But it's something that the API permits.
Quoted 2 lines
drivers/net/dsa/vitesse-vsc73xx-core.c +2
-0+return vsc73xx_update_vlan_table (vsc, port, vid, false); +}
PATCH v2 9/12 net: dsa: Define max num of bridges in tag8021q implementation
In reply to Pawel DembickiMax number of bridges in tag8021q implementation is strictly limited by VBID size: 3 bits. But zero is reserved and only 7 values can be used.
This patch adds define which describe maximum possible value.
---
v2, v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- resend only
v7:
- added 'Reviewed-by' only
v6:
- resend only
v5:
- added 'Reviewed-by' only
v4:
- introduce patch
--- drivers/net/dsa/sja1105/sja1105_main.c | 3 +-- include/linux/dsa/8021q.h | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +1 -2
@@ -3167,8 +3167,7 @@ static int sja1105_setup(struct dsa_switch *ds) ds->vlan_filtering_is_global = true; ds->untag_bridge_pvid = true; ds->fdb_isolation = true; -/* tag_8021q has 3 bits for the VBID, and the value 0 is reserved */ - ds->max_num_bridges =7 ; + ds->max_num_bridges =DSA_TAG_8021Q_MAX_NUM_BRIDGES ;/* Advertise the 8 egress queues */ ds->num_tx_queues =SJA1105_NUM_TC ;
include/linux/dsa/8021q.h +5 -0
@@ -8,6 +8,11 @@#include <net/dsa.h> #include <linux/types.h> +/* VBID is limited to three bits only and zero is reserved. +* Only 7 bridges can be enumerated. +*/ +#define DSA_TAG_8021Q_MAX_NUM_BRIDGES 7 +int dsa_tag_8021q_register (struct dsa_switch *ds,__be16 proto);void dsa_tag_8021q_unregister (struct dsa_switch *ds);
Signature · 1 line
2.34.1
Re: [PATCH net-next v2 09/12] net: dsa: Define max num of bridges in tag8021q implementation
Quoted 10 lines · Pawel Dembicki
Max number of bridges in tag8021q implementation is strictly limited by VBID size: 3 bits. But zero is reserved and only 7 values can be used.
This patch adds define which describe maximum possible value.
Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Pawel Dembicki <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Reviewed-by Linus Walleij <[email protected]>---
PATCH v2 10/12 net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use
In reply to Pawel DembickiThe 'dsa_tag_8021q_bridge_join' could be used as a generic implementation of the 'ds->ops->port_bridge_join()' function. However, it is necessary to synchronize their arguments.
This patch also moves the 'tx_fwd_offload' flag configuration line into 'dsa_tag_8021q_bridge_join' body. Currently, every (sja1105) driver sets it, and the future vsc73xx implementation will also need it for simplification.
---
v2:
- resend only
v1:
- introduce patch
--- drivers/net/dsa/sja1105/sja1105_main.c | 5 ++--- include/linux/dsa/8021q.h | 3 ++- net/dsa/tag_8021q.c | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +2 -3
@@ -2133,14 +2133,13 @@ static int sja1105_bridge_join(struct dsa_switch *ds, int port,if (rc)return rc; - rc =dsa_tag_8021q_bridge_join (ds, port, bridge); + rc =dsa_tag_8021q_bridge_join (ds, port, bridge, tx_fwd_offload, + extack);if (rc) {sja1105_bridge_member (ds, port, bridge, false);return rc; } - *tx_fwd_offload = true; -return 0 ; }
include/linux/dsa/8021q.h +2 -1
@@ -18,7 +18,8 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto);void dsa_tag_8021q_unregister (struct dsa_switch *ds);int dsa_tag_8021q_bridge_join (struct dsa_switch *ds,int port, -struct dsa_bridge bridge); +struct dsa_bridge bridge,bool *tx_fwd_offload, +struct netlink_ext_ack *extack);void dsa_tag_8021q_bridge_leave (struct dsa_switch *ds,int port,struct dsa_bridge bridge);
net/dsa/tag_8021q.c +4 -1
@@ -286,7 +286,8 @@ int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,* be used for VLAN-unaware bridging. */ int dsa_tag_8021q_bridge_join (struct dsa_switch *ds,int port, -struct dsa_bridge bridge) +struct dsa_bridge bridge,bool *tx_fwd_offload, +struct netlink_ext_ack *extack) {struct dsa_port *dp =dsa_to_port (ds, port);u16 standalone_vid, bridge_vid;
@@ -304,6 +305,8 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,dsa_port_tag_8021q_vlan_del (dp, standalone_vid, false); + *tx_fwd_offload = true; +return 0 ; }EXPORT_SYMBOL_GPL (dsa_tag_8021q_bridge_join);
Signature · 1 line
2.34.1
Re: [PATCH net-next v2 10/12] net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use
Quoted 4 lines · Pawel Dembicki
The '
dsa_tag_8021q_bridge_join' could be used as a generic implementation of the 'ds->ops->port_bridge_join()' function. However, it is necessary to synchronize their arguments.
Quoted 8 lines
This patch also moves the '
tx_fwd_offload' flag configuration line into 'dsa_tag_8021q_bridge_join' body. Currently, every (sja1105) driver sets it, and the future vsc73xx implementation will also need it for simplification.Suggested-by Vladimir Oltean <[email protected]>Signed-off-by Pawel Dembicki <[email protected]>---
PATCH v2 11/12 net: dsa: vsc73xx: Add bridge support
In reply to Pawel DembickiThis patch adds bridge support for vsc73xx driver.
Vsc73xx require minimal operations and generic
dsa_tag_8021q_bridge_* api is sufficient.
---
v2, v1:
- Use generic functions instead unnecessary intermediary shims
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- resend only
v7:
- added 'Reviewed-by' only
v6:
- resend only
v5:
- added 'Reviewed-by' only
v4:
- remove forward configuration after stp patch refactoring
- implement new define with max num of bridges for tag8021q devices
v3:
- All vlan commits was reworked
- move VLAN_AWR and VLAN_DBLAWR to port setup in other commit
- drop vlan table upgrade
v2:
- no changes done
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/dsa/vitesse-vsc73xx-core.c +5 -0
@@ -691,6 +691,9 @@ static int vsc73xx_setup(struct dsa_switch *ds)dev_info (vsc->dev,"set up the switch\n" ); + ds->untag_bridge_pvid = true; + ds->max_num_bridges =DSA_TAG_8021Q_MAX_NUM_BRIDGES ; +/* Issue RESET */ vsc73xx_write (vsc,VSC73XX_BLOCK_SYSTEM ,0 ,VSC73XX_GLORESET ,VSC73XX_GLORESET_MASTER_RESET );
@@ -1690,6 +1693,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_bridge_join = dsa_tag_8021q_bridge_join, + .port_bridge_leave = dsa_tag_8021q_bridge_leave, .port_change_mtu = vsc73xx_change_mtu, .port_max_mtu = vsc73xx_get_max_mtu, .port_stp_state_set = vsc73xx_port_stp_state_set,
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerRe: [PATCH net-next v2 11/12] net: dsa: vsc73xx: Add bridge support
Quoted 10 lines · Pawel Dembicki
This patch adds bridge support for vsc73xx driver.
Vsc73xx require minimal operations and generic
dsa_tag_8021q_bridge_* api is sufficient.Signed-off-by Pawel Dembicki <[email protected]>---
v2, v1:
- Use generic functions instead unnecessary intermediary shims
---
Maybe you could add a small comment to the commit message that the forwarding matrix is taken care of by vsc73xx_port_stp_state_set() -> vsc73xx_refresh_fwd_map(), which is called immediately after .port_bridge_join() and .port_bridge_leave().
Re: [PATCH net-next v2 11/12] net: dsa: vsc73xx: Add bridge support
In reply to Pawel DembickiQuoted 7 lines · Pawel Dembicki
This patch adds bridge support for vsc73xx driver.
Vsc73xx require minimal operations and generic
dsa_tag_8021q_bridge_* api is sufficient.Signed-off-by Pawel Dembicki <[email protected]>---
Other than that:
PATCH v2 12/12 net: dsa: vsc73xx: start treating the BR_LEARNING flag
In reply to Pawel DembickiThis patch implements .port_pre_bridge_flags() and .port_bridge_flags(), which are required for properly treating the BR_LEARNING flag. Also, .port_stp_state_set() is tweaked and now disables learning for standalone ports.
Disabling learning for standalone ports is required to avoid situations where one port sees traffic originating from another, which could cause packet drops.
---
v2,v1:
- resend only
---
Before patch series split:
https://patchwork.kernel.org/project/netdevbpf/list/?series=841034&state=%2A&archive=both
v8:
- resend only
v7:
- added 'Acked-by' and 'Reviewed-by' and improve commit message
v6:
- fix arranging local variables in reverse xmas tree order
v5:
- introduce patch
--- drivers/net/dsa/vitesse-vsc73xx-core.c | 41 ++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-)
drivers/net/dsa/vitesse-vsc73xx-core.c +35 -6
@@ -1581,6 +1581,31 @@ static int vsc73xx_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid)return vsc73xx_update_vlan_table (vsc, port, vid, false); } +static int vsc73xx_port_pre_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack) +{ +if (flags.mask & ~BR_LEARNING ) +return -EINVAL ; + +return 0 ; +} + +static int vsc73xx_port_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack) +{ +if (flags.mask &BR_LEARNING ) { +u32 val = flags.val &BR_LEARNING ?BIT (port) :0 ; +struct vsc73xx *vsc = ds->priv; + +return vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_LEARNMASK ,BIT (port), val); + } + +return 0 ; +} +static int vsc73xx_port_setup (struct dsa_switch *ds,int port) {struct vsc73xx_portinfo *portinfo;
@@ -1655,19 +1680,21 @@ static void vsc73xx_refresh_fwd_map(struct dsa_switch *ds, int port, u8 state)static void vsc73xx_port_stp_state_set (struct dsa_switch *ds,int port,u8 state) { +struct dsa_port *dp =dsa_to_port (ds, port);struct vsc73xx *vsc = ds->priv; -u32 val; +u32 val =0 ; + +if (state ==BR_STATE_LEARNING || state ==BR_STATE_FORWARDING ) + val = dp->learning ?BIT (port) :0 ; + +vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , +VSC73XX_LEARNMASK ,BIT (port), val); val = (state ==BR_STATE_BLOCKING || state ==BR_STATE_DISABLED ) ?0 :BIT (port);vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 ,VSC73XX_RECVMASK ,BIT (port), val); - val = (state ==BR_STATE_LEARNING || state ==BR_STATE_FORWARDING ) ? -BIT (port) :0 ; -vsc73xx_update_bits (vsc,VSC73XX_BLOCK_ANALYZER ,0 , -VSC73XX_LEARNMASK ,BIT (port), val); -/* CPU Port should always forward packets when user ports are forwarding * so let's configure it from other ports only. */
@@ -1693,6 +1720,8 @@ static const struct dsa_switch_ops vsc73xx_ds_ops = { .port_setup = vsc73xx_port_setup, .port_enable = vsc73xx_port_enable, .port_disable = vsc73xx_port_disable, + .port_pre_bridge_flags = vsc73xx_port_pre_bridge_flags, + .port_bridge_flags = vsc73xx_port_bridge_flags, .port_bridge_join = dsa_tag_8021q_bridge_join, .port_bridge_leave = dsa_tag_8021q_bridge_leave, .port_change_mtu = vsc73xx_change_mtu,
Signature · 1 line
2.34.1