netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>, "Andrew Lunn" <andrew@lunn.ch>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Oleksij Rempel" <linux@rempel-privat.de>,
	"Christian Marangi" <ansuelsmth@gmail.com>,
	"John Crispin" <john@phrozen.org>,
	"Kurt Kanzenbach" <kurt@linutronix.de>,
	"Mans Rullgard" <mans@mansr.com>,
	"Arun Ramadoss" <arun.ramadoss@microchip.com>,
	"Woojung Huh" <woojung.huh@microchip.com>,
	UNGLinuxDriver@microchip.com,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"George McCollister" <george.mccollister@gmail.com>,
	"DENG Qingfang" <dqfext@gmail.com>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Landen Chao" <Landen.Chao@mediatek.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Aleksander Jan Bajkowski" <olek2@wp.pl>,
	"Alvin Šipraga" <alsi@bang-olufsen.dk>,
	"Luiz Angelo Daros de Luca" <luizluca@gmail.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Pawel Dembicki" <paweldembicki@gmail.com>,
	"Clément Léger" <clement.leger@bootlin.com>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"Russell King" <rmk+kernel@armlinux.org.uk>
Subject: Re: [PATCH net-next] net: dsa: validate that DT nodes of shared ports have the properties they need
Date: Mon, 25 Jul 2022 09:27:42 -0700	[thread overview]
Message-ID: <41ef4895-0450-c0ae-558c-45cdd4f8739b@gmail.com> (raw)
In-Reply-To: <20220723164635.1621911-1-vladimir.oltean@nxp.com>

On 7/23/22 09:46, Vladimir Oltean wrote:

[snip]

> +static int dsa_shared_port_validate_of_node(struct dsa_port *dp,
> +					    const char *description)
> +{
> +	struct device_node *dn = dp->dn, *phy_np;
> +	struct dsa_switch *ds = dp->ds;
> +	phy_interface_t mode;
> +
> +	/* Suppress validation if using platform data */
> +	if (!dn)
> +		return 0;
> +
> +	if (of_device_compatible_match(ds->dev->of_node,
> +				       dsa_switches_skipping_validation))
> +		return 0;
> +
> +	if (of_get_phy_mode(dn, &mode)) {
> +		dev_err(ds->dev,
> +			"%s port %d lacks the required \"phy-mode\" property\n",
> +			description, dp->index);
> +		return -EINVAL;
> +	}
> +
> +	phy_np = of_parse_phandle(dn, "phy-handle", 0);
> +	if (phy_np) {
> +		of_node_put(phy_np);
> +		return 0;
> +	}
> +
> +	/* Note: of_phy_is_fixed_link() also returns true for
> +	 * managed = "in-band-status"
> +	 */
> +	if (of_phy_is_fixed_link(dn))
> +		return 0;

To echo back my reply from the other email here, if we look beyond the rabbit hole and also attempt to parse these properties from the device_node pointed to us by the "ethernet" property, then I think we can trim down the list, and we still have some assurance that we can use phylink and a fixed link property, except we have to replicate the information from the CPU-port connected Ethernet controller.

> +
> +	/* TODO support SFP cages on DSA/CPU ports,
> +	 * here and in dsa_port_link_register_of()
> +	 */
> +	dev_err(ds->dev,
> +		"%s port %d lacks the required \"phy-handle\", \"fixed-link\" or \"managed\" properties\n",
> +		description, dp->index);
> +
> +	return -EINVAL;
> +}
> +
>  static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
>  {
>  	if (!name)
> @@ -1373,6 +1534,12 @@ static int dsa_port_parse_user(struct dsa_port *dp, const char *name)
>  
>  static int dsa_port_parse_dsa(struct dsa_port *dp)
>  {
> +	int err;
> +
> +	err = dsa_shared_port_validate_of_node(dp, "DSA");
> +	if (err)
> +		return err;
> +
>  	dp->type = DSA_PORT_TYPE_DSA;

Move up the assignment so you can just read the type from dsa_shared_port_validate_of_node()?

>  
>  	return 0;
> @@ -1411,6 +1578,11 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master,
>  	struct dsa_switch_tree *dst = ds->dst;
>  	const struct dsa_device_ops *tag_ops;
>  	enum dsa_tag_protocol default_proto;
> +	int err;
> +
> +	err = dsa_shared_port_validate_of_node(dp, "CPU");
> +	if (err)
> +		return err;

Likewise, I don't think there are adverse effects of moving up the dp->type assignment all the way to the top?

>  
>  	/* Find out which protocol the switch would prefer. */
>  	default_proto = dsa_get_tag_protocol(dp, master);


-- 
Florian

  parent reply	other threads:[~2022-07-25 16:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-23 16:46 [PATCH net-next] net: dsa: validate that DT nodes of shared ports have the properties they need Vladimir Oltean
2022-07-23 18:09 ` Andrew Lunn
2022-07-24 14:21   ` Vladimir Oltean
2022-07-24 14:39     ` Andrew Lunn
2022-07-24 16:59     ` Florian Fainelli
2022-07-24 20:28       ` Vladimir Oltean
2022-07-25 16:37         ` Florian Fainelli
2022-07-23 21:50 ` kernel test robot
2022-07-24  0:30 ` Alvin Šipraga
2022-07-25 16:27 ` Florian Fainelli [this message]
2022-07-25 19:21 ` Martin Blumenstingl
2022-07-26  7:12 ` Kurt Kanzenbach

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=41ef4895-0450-c0ae-558c-45cdd4f8739b@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=Landen.Chao@mediatek.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alsi@bang-olufsen.dk \
    --cc=andrew@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=arun.ramadoss@microchip.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=clement.leger@bootlin.com \
    --cc=davem@davemloft.net \
    --cc=dqfext@gmail.com \
    --cc=edumazet@google.com \
    --cc=geert+renesas@glider.be \
    --cc=george.mccollister@gmail.com \
    --cc=hauke@hauke-m.de \
    --cc=john@phrozen.org \
    --cc=kuba@kernel.org \
    --cc=kurt@linutronix.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux@rempel-privat.de \
    --cc=luizluca@gmail.com \
    --cc=mans@mansr.com \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olek2@wp.pl \
    --cc=pabeni@redhat.com \
    --cc=paweldembicki@gmail.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=sean.wang@mediatek.com \
    --cc=vivien.didelot@gmail.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=woojung.huh@microchip.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;
as well as URLs for NNTP newsgroup(s).