Netdev List
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Ansuel Smith <ansuelsmth@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [net-next PATCH v2 3/4] drivers: net: dsa: qca8k: rework and simplify mdiobus logic
Date: Thu, 14 Apr 2022 17:08:23 +0300	[thread overview]
Message-ID: <20220414140823.btcvlebraynaw6wr@skbuf> (raw)
In-Reply-To: <20220412173019.4189-4-ansuelsmth@gmail.com>

On Tue, Apr 12, 2022 at 07:30:18PM +0200, Ansuel Smith wrote:
> In an attempt to reduce qca8k_priv space, rework and simplify mdiobus
> logic.
> We now declare a mdiobus instead of relying on DSA phy_read/write even
> if a mdio node is not present. This is all to make the qca8k ops static
> and not switch specific. With a legacy implementation where port doesn't
> have a phy map declared in the dts with a mdio node, we declare a
> 'qca8k-legacy' mdiobus. The conversion logic is used as legacy read and
> write ops are used instead of the internal one.
> While at it also improve the bus id to support multiple switch.
> Also drop the legacy_phy_port_mapping as we now declare mdiobus with ops
> that already address the workaround.
> 
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> ---
>  drivers/net/dsa/qca8k.c | 101 ++++++++++++++--------------------------
>  drivers/net/dsa/qca8k.h |   1 -
>  2 files changed, 34 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
> index 5f447b586cfa..9c4c5af79f9a 100644
> --- a/drivers/net/dsa/qca8k.c
> +++ b/drivers/net/dsa/qca8k.c
> @@ -1287,87 +1287,71 @@ qca8k_internal_mdio_read(struct mii_bus *slave_bus, int phy, int regnum)
>  	if (ret >= 0)
>  		return ret;
>  
> -	return qca8k_mdio_read(priv, phy, regnum);
> +	ret = qca8k_mdio_read(priv, phy, regnum);
> +
> +	if (ret < 0)
> +		return 0xffff;
> +
> +	return ret;

Unrelated change?

>  }
>  
>  static int
> -qca8k_phy_write(struct dsa_switch *ds, int port, int regnum, u16 data)
> +qca8k_legacy_mdio_write(struct mii_bus *slave_bus, int port, int regnum, u16 data)
>  {
> -	struct qca8k_priv *priv = ds->priv;
> -	int ret;
> -
> -	/* Check if the legacy mapping should be used and the
> -	 * port is not correctly mapped to the right PHY in the
> -	 * devicetree
> -	 */
> -	if (priv->legacy_phy_port_mapping)
> -		port = qca8k_port_to_phy(port) % PHY_MAX_ADDR;
> -
> -	/* Use mdio Ethernet when available, fallback to legacy one on error */
> -	ret = qca8k_phy_eth_command(priv, false, port, regnum, 0);
> -	if (!ret)
> -		return ret;
> +	port = qca8k_port_to_phy(port) % PHY_MAX_ADDR;
>  
> -	return qca8k_mdio_write(priv, port, regnum, data);
> +	return qca8k_internal_mdio_write(slave_bus, port, regnum, data);
>  }
>  
>  static int
> -qca8k_phy_read(struct dsa_switch *ds, int port, int regnum)
> +qca8k_legacy_mdio_read(struct mii_bus *slave_bus, int port, int regnum)
>  {
> -	struct qca8k_priv *priv = ds->priv;
> -	int ret;
> -
> -	/* Check if the legacy mapping should be used and the
> -	 * port is not correctly mapped to the right PHY in the
> -	 * devicetree
> -	 */
> -	if (priv->legacy_phy_port_mapping)
> -		port = qca8k_port_to_phy(port) % PHY_MAX_ADDR;
> -
> -	/* Use mdio Ethernet when available, fallback to legacy one on error */
> -	ret = qca8k_phy_eth_command(priv, true, port, regnum, 0);
> -	if (ret >= 0)
> -		return ret;
> -
> -	ret = qca8k_mdio_read(priv, port, regnum);
> -
> -	if (ret < 0)
> -		return 0xffff;
> +	port = qca8k_port_to_phy(port) % PHY_MAX_ADDR;
>  
> -	return ret;
> +	return qca8k_internal_mdio_read(slave_bus, port, regnum);
>  }
>  
>  static int
> -qca8k_mdio_register(struct qca8k_priv *priv, struct device_node *mdio)
> +qca8k_mdio_register(struct qca8k_priv *priv)
>  {
>  	struct dsa_switch *ds = priv->ds;
> +	struct device_node *mdio;
>  	struct mii_bus *bus;
>  
>  	bus = devm_mdiobus_alloc(ds->dev);
> -
>  	if (!bus)
>  		return -ENOMEM;
>  
>  	bus->priv = (void *)priv;
> -	bus->name = "qca8k slave mii";
> -	bus->read = qca8k_internal_mdio_read;
> -	bus->write = qca8k_internal_mdio_write;
> -	snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d",
> -		 ds->index);
> -
> +	snprintf(bus->id, MII_BUS_ID_SIZE, "qca8k-%d.%d",
> +		 ds->dst->index, ds->index);

So the bus->id here is the same, regardless if this is the OF-based MDIO
bus or the legacy slave MII bus. dsa_slave_mii_bus_init() used to set
the bus->id to "dsa-%d.%d", ds->dst->index, ds->index), so you're doing
this to kind of preserve the structure (although not completely).

In any case, this is an unrelated change, because not only are you
modifying the bus->id of the legacy MII bus, but also the bus->id of the
OF-based one. I would rather have it be a separate patch just for that.

Does the MDIO bus id constitute unbreakable ABI? I hope not, otherwise
as you say, we couldn't support multiple switches.

>  	bus->parent = ds->dev;
>  	bus->phy_mask = ~ds->phys_mii_mask;
> -
>  	ds->slave_mii_bus = bus;
>  
> -	return devm_of_mdiobus_register(priv->dev, bus, mdio);
> +	/* Check if the devicetree declare the port:phy mapping */
> +	mdio = of_get_child_by_name(priv->dev->of_node, "mdio");
> +	if (of_device_is_available(mdio)) {
> +		bus->name = "qca8k slave mii";
> +		bus->read = qca8k_internal_mdio_read;
> +		bus->write = qca8k_internal_mdio_write;
> +		return devm_of_mdiobus_register(priv->dev, bus, mdio);
> +	}
> +
> +	/* If a mapping can't be found the legacy mapping is used,
> +	 * using the qca8k_port_to_phy function
> +	 */
> +	bus->name = "qca8k-legacy slave mii";
> +	bus->read = qca8k_legacy_mdio_read;
> +	bus->write = qca8k_legacy_mdio_write;
> +	return devm_mdiobus_register(priv->dev, bus);
>  }
>  
>  static int
>  qca8k_setup_mdio_bus(struct qca8k_priv *priv)
>  {
>  	u32 internal_mdio_mask = 0, external_mdio_mask = 0, reg;
> -	struct device_node *ports, *port, *mdio;
> +	struct device_node *ports, *port;
>  	phy_interface_t mode;
>  	int err;
>  
> @@ -1429,24 +1413,7 @@ qca8k_setup_mdio_bus(struct qca8k_priv *priv)
>  					 QCA8K_MDIO_MASTER_EN);
>  	}
>  
> -	/* Check if the devicetree declare the port:phy mapping */
> -	mdio = of_get_child_by_name(priv->dev->of_node, "mdio");
> -	if (of_device_is_available(mdio)) {
> -		err = qca8k_mdio_register(priv, mdio);
> -		if (err)
> -			of_node_put(mdio);
> -
> -		return err;
> -	}
> -
> -	/* If a mapping can't be found the legacy mapping is used,
> -	 * using the qca8k_port_to_phy function
> -	 */
> -	priv->legacy_phy_port_mapping = true;
> -	priv->ops.phy_read = qca8k_phy_read;
> -	priv->ops.phy_write = qca8k_phy_write;
> -
> -	return 0;
> +	return qca8k_mdio_register(priv);
>  }
>  
>  static int
> diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
> index 12d8d090298b..8bbe36f135b5 100644
> --- a/drivers/net/dsa/qca8k.h
> +++ b/drivers/net/dsa/qca8k.h
> @@ -388,7 +388,6 @@ struct qca8k_priv {
>  	 * Bit 1: port enabled. Bit 0: port disabled.
>  	 */
>  	u8 port_enabled_map;
> -	bool legacy_phy_port_mapping;
>  	struct qca8k_ports_config ports_config;
>  	struct regmap *regmap;
>  	struct mii_bus *bus;
> -- 
> 2.34.1
> 


  reply	other threads:[~2022-04-14 14:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-12 17:30 [net-next PATCH v2 0/4] Reduce qca8k_priv space usage Ansuel Smith
2022-04-12 17:30 ` [net-next PATCH v2 1/4] drivers: net: dsa: qca8k: drop MTU tracking from qca8k_priv Ansuel Smith
2022-04-14 13:42   ` Paolo Abeni
2022-04-14 13:48   ` Vladimir Oltean
2022-04-16 19:30   ` Florian Fainelli
2022-04-12 17:30 ` [net-next PATCH v2 2/4] drivers: net: dsa: qca8k: drop port_sts " Ansuel Smith
2022-04-14 13:49   ` Vladimir Oltean
2022-04-16 19:30   ` Florian Fainelli
2022-04-12 17:30 ` [net-next PATCH v2 3/4] drivers: net: dsa: qca8k: rework and simplify mdiobus logic Ansuel Smith
2022-04-14 14:08   ` Vladimir Oltean [this message]
2022-04-16 14:31     ` Andrew Lunn
2022-04-12 17:30 ` [net-next PATCH v2 4/4] drivers: net: dsa: qca8k: drop dsa_switch_ops from qca8k_priv Ansuel Smith
2022-04-14 14:09   ` Vladimir Oltean
2022-04-16 19:30   ` Florian Fainelli

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=20220414140823.btcvlebraynaw6wr@skbuf \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@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