Netdev List
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Pawel Dembicki <paweldembicki@gmail.com>
Cc: netdev@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>,
	Simon Horman <horms@kernel.org>, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	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 v8 07/16] net: dsa: vsc73xx: Add vlan filtering
Date: Fri, 5 Apr 2024 19:07:12 +0300	[thread overview]
Message-ID: <20240405160712.pfgt7lnutsqvxfob@skbuf> (raw)
In-Reply-To: <20240403103734.3033398-8-paweldembicki@gmail.com>

On Wed, Apr 03, 2024 at 12:37:23PM +0200, Pawel Dembicki wrote:
> +static int
> +vsc73xx_port_vlan_filtering(struct dsa_switch *ds, int port,
> +			    bool vlan_filtering, struct netlink_ext_ack *extack)
> +{
> +	enum vsc73xx_port_vlan_conf port_vlan_conf = VSC73XX_VLAN_IGNORE;
> +	u16 vid_pvid = 0, vid_untagged = 0;
> +	struct vsc73xx_portinfo *portinfo;
> +	struct vsc73xx *vsc = ds->priv;
> +	bool set_untagged = false;
> +	bool set_pvid = false;
> +
> +	portinfo = &vsc->portinfo[port];
> +
> +	/* The swap 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. Analogic routine is processed when vlan_filtering

Analogous

> +	 * is disabled, but values used for tag_8021q are restored.
> +	 */
> +	if (vlan_filtering) {
> +		struct vsc73xx_vlan_summary summary;
> +
> +		/* Use VLAN_N_VID to count all vlans */
> +		vsc73xx_bridge_vlan_summary(vsc, port, &summary, VLAN_N_VID);
> +
> +		port_vlan_conf = (summary.num_untagged > 1) ?
> +				 VSC73XX_VLAN_FILTER_UNTAG_ALL :
> +				 VSC73XX_VLAN_FILTER;
> +
> +		if (summary.num_untagged == 1) {
> +			vid_untagged = vsc73xx_find_first_vlan_untagged(vsc,
> +									port);
> +			set_untagged = true;
> +		}

Is there really any functional difference between the above, vs this in
port_vlan_add():

	port_vlan_conf = VSC73XX_VLAN_FILTER;

	if (summary.num_tagged == 0 && untagged)
		port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL;
	vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf);

	if (port_vlan_conf == VSC73XX_VLAN_FILTER_UNTAG_ALL)
		goto update_vlan_table;

vs this in port_vlan_del():

		enum vsc73xx_port_vlan_conf port_vlan_conf =
							VSC73XX_VLAN_FILTER;

		if (summary.num_tagged == 0)
			port_vlan_conf = VSC73XX_VLAN_FILTER_UNTAG_ALL;
		vsc73xx_set_vlan_conf(vsc, port, port_vlan_conf);

		if (summary.num_untagged <= 1) {
			vid = vsc73xx_find_first_vlan_untagged(vsc, port);
			vsc73xx_vlan_change_untagged_hw(vsc, port, vid,
							summary.num_untagged);
		}

?

If not, I have to agree with Florian that it's dizzying to follow the
vsc73xx_set_vlan_conf() calls, all with slightly different input.
Even worse now than before, I think.

I see you've changed the storage variable names, so maybe you are open
to some more refactoring, to make the code more maintainable.

I would suggest calling a single vsc73xx_update_vlan_conf() from all
places, which figures out what to do by itself, based on the current
(updated) state. All ifs and buts are on the inside, not on the outside.

Also, the operate_on_storage variable is not a great name now. Because
you always operate on storage. It means "operate _just_ on storage", aka
"don't commit to hardware".

I wanted to avoid requesting you to make more changes to the
implementation, but you started it, and now it's a confusing mix of
concepts from old and new patch sets.

I would like to also see the "operate_on_storage" logic rewritten and
embedded into those functions which must update shared resources (port
PVID, port untagged VID, etc).

Basically, in the end I would like the driver to be written in the style
of every other similar function: ocelot_port_manage_port_tag(),
sja1105_commit_pvid(), mv88e6xxx_commit_pvid() etc. No arguments, except
the port on which to run. Figure out what to do from the current state,
and make sure it is called from all places that change that state.
It also serves very well as self-documenting code, because "how register
X should be set" is centralized into a single function.

Sorry for making this request so late in the development process. I hope
it's not discouraging.

  reply	other threads:[~2024-04-05 16:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 10:37 [PATCH net-next v8 00/16] net: dsa: vsc73xx: Make vsc73xx usable Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 01/16] net: dsa: vsc73xx: use read_poll_timeout instead delay loop Pawel Dembicki
2024-04-05 14:32   ` Vladimir Oltean
2024-04-03 10:37 ` [PATCH net-next v8 02/16] net: dsa: vsc73xx: convert to PHYLINK Pawel Dembicki
2024-04-05 16:10   ` Vladimir Oltean
2024-04-03 10:37 ` [PATCH net-next v8 03/16] net: dsa: vsc73xx: use macros for rgmii recognition Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 04/16] net: dsa: vsc73xx: Add define for max num of ports Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 05/16] net: dsa: vsc73xx: add structure descriptions Pawel Dembicki
2024-04-05 14:37   ` Vladimir Oltean
2024-04-03 10:37 ` [PATCH net-next v8 06/16] net: dsa: vsc73xx: add port_stp_state_set function Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 07/16] net: dsa: vsc73xx: Add vlan filtering Pawel Dembicki
2024-04-05 16:07   ` Vladimir Oltean [this message]
2024-04-03 10:37 ` [PATCH net-next v8 08/16] net: dsa: tag_sja1105: absorb logic for not overwriting precise info into dsa_8021q_rcv() Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 09/16] net: dsa: tag_sja1105: absorb entire sja1105_vlan_rcv() " Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 10/16] net: dsa: tag_sja1105: prefer precise source port info on SJA1110 too Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 11/16] net: dsa: tag_sja1105: refactor skb->dev assignment to dsa_tag_8021q_find_user() Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 12/16] net: dsa: vsc73xx: introduce tag 8021q for vsc73xx Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 13/16] net: dsa: vsc73xx: Implement the tag_8021q VLAN operations Pawel Dembicki
2024-04-05 15:13   ` Vladimir Oltean
2024-04-03 10:37 ` [PATCH net-next v8 14/16] net: dsa: Define max num of bridges in tag8021q implementation Pawel Dembicki
2024-04-03 10:37 ` [PATCH net-next v8 15/16] net: dsa: vsc73xx: Add bridge support Pawel Dembicki
2024-04-05 15:25   ` Vladimir Oltean
2024-04-03 10:37 ` [PATCH net-next v8 16/16] 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=20240405160712.pfgt7lnutsqvxfob@skbuf \
    --to=olteanv@gmail.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=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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