mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Pawel Dembicki <paweldembicki@gmail.com>, netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	 Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Claudiu Manoil <claudiu.manoil@nxp.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	UNGLinuxDriver@microchip.com,
	Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 02/12] net: dsa: vsc73xx: Add vlan filtering
Date: Fri, 14 Jun 2024 11:42:50 +0200	[thread overview]
Message-ID: <84281d30907c09a2f15d741088833b0ae6597b89.camel@redhat.com> (raw)
In-Reply-To: <20240611195007.486919-3-paweldembicki@gmail.com>

Hi,

On Tue, 2024-06-11 at 21:49 +0200, Pawel Dembicki wrote:
> +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;
> +
> +		INIT_LIST_HEAD(&vsc73xx_vlan->list);

INIT_LIST_HEAD() is not needed, as the entry will be unconditionally
added in the statement below.

> +		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) {
> +		vsc73xx_vlan_commit_pvid(vsc, port);
> +		vsc73xx_vlan_commit_untagged(vsc, port);
> +		vsc73xx_vlan_commit_conf(vsc, port);
> +	}
> +
> +update_vlan_table:
> +	ret = vsc73xx_update_vlan_table(vsc, port, vlan->vid, true);
> +	if (!ret)
> +		return 0;
> +
> +	list_del(&vsc73xx_vlan->list);
> +	kfree(vsc73xx_vlan);

This does not look correct. I guess you should clear bit(port) in
vsc73xx_vlan->portmask and dispose the entry only when portmask becomes
0. You probably can factor out a common helper to be used here and in
vsc73xx_port_vlan_del(). 

Thanks,

Paolo


  reply	other threads:[~2024-06-14  9:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11 19:49 [PATCH net-next 00/12] net: dsa: vsc73xx: Implement VLAN operations Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 01/12] net: dsa: vsc73xx: add port_stp_state_set function Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 02/12] net: dsa: vsc73xx: Add vlan filtering Pawel Dembicki
2024-06-14  9:42   ` Paolo Abeni [this message]
2024-06-17 12:10   ` Simon Horman
2024-06-11 19:49 ` [PATCH net-next 03/12] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 04/12] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() " Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 05/12] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 06/12] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Pawel Dembicki
2024-06-11 19:49 ` [PATCH net-next 07/12] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Pawel Dembicki
2024-06-11 19:50 ` [PATCH net-next 08/12] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Pawel Dembicki
2024-06-11 19:50 ` [PATCH net-next 09/12] net: dsa: Define max num of bridges in tag8021q implementation Pawel Dembicki
2024-06-11 19:50 ` [PATCH net-next 10/12] net: dsa: prepare 'dsa_tag_8021q_bridge_join' for standalone use Pawel Dembicki
2024-06-11 19:50 ` [PATCH net-next 11/12] net: dsa: vsc73xx: Add bridge support Pawel Dembicki
2024-06-11 19:50 ` [PATCH net-next 12/12] net: dsa: vsc73xx: start treating the BR_LEARNING flag Pawel Dembicki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84281d30907c09a2f15d741088833b0ae6597b89.camel@redhat.com \
    --to=pabeni@redhat.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=paweldembicki@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®