diff mbox series

[net-next,RFC,v6,11/16] net: dsa: qca8k: add tracking state of master port

Message ID 20211214224409.5770-12-ansuelsmth@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Add support for qca8k mdio rw in Ethernet packet | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 86 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Dec. 14, 2021, 10:44 p.m. UTC
MDIO/MIB Ethernet require the master port and the tagger availabale to
correctly work. Use the new api master_state_change to track when master
is operational or not and set a bool in qca8k_priv.
We cache the first cached master available and we check if other cpu
port are operational when the cached one goes down.
This cached master will later be used by mdio read/write and mib request to
correctly use the working function.

qca8k implementation for MDIO/MIB Ethernet is bad. CPU port0 is the only
one that answers with the ack packet or sends MIB Ethernet packets. For
this reason the master_state_change ignore CPU port6 and checkes only
CPU port0 if it's operational and enables this mode.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 drivers/net/dsa/qca8k.c | 18 ++++++++++++++++++
 drivers/net/dsa/qca8k.h |  1 +
 2 files changed, 19 insertions(+)

Comments

Vladimir Oltean Dec. 15, 2021, 9:51 a.m. UTC | #1
On Tue, Dec 14, 2021 at 11:44:04PM +0100, Ansuel Smith wrote:
> MDIO/MIB Ethernet require the master port and the tagger availabale to
> correctly work. Use the new api master_state_change to track when master
> is operational or not and set a bool in qca8k_priv.
> We cache the first cached master available and we check if other cpu
> port are operational when the cached one goes down.
> This cached master will later be used by mdio read/write and mib request to
> correctly use the working function.
> 
> qca8k implementation for MDIO/MIB Ethernet is bad. CPU port0 is the only
> one that answers with the ack packet or sends MIB Ethernet packets. For
> this reason the master_state_change ignore CPU port6 and checkes only
> CPU port0 if it's operational and enables this mode.

CPU port 0 may not always be wired, it depends on board design, right?
So the Ethernet management protocol may or may not be available to all users.

> 
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> ---
> diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
> index ab4a417b25a9..6edd6adc3063 100644
> --- a/drivers/net/dsa/qca8k.h
> +++ b/drivers/net/dsa/qca8k.h
> @@ -353,6 +353,7 @@ struct qca8k_priv {
>  	struct dsa_switch_ops ops;
>  	struct gpio_desc *reset_gpio;
>  	unsigned int port_mtu[QCA8K_NUM_PORTS];
> +	const struct net_device *master; /* Track if mdio/mib Ethernet is available */

Maybe "mgmt_master" would be a clearer naming scheme?

>  };
>  
>  struct qca8k_mib_desc {
> -- 
> 2.33.1
>
Christian Marangi Dec. 16, 2021, midnight UTC | #2
On Wed, Dec 15, 2021 at 11:51:46AM +0200, Vladimir Oltean wrote:
> On Tue, Dec 14, 2021 at 11:44:04PM +0100, Ansuel Smith wrote:
> > MDIO/MIB Ethernet require the master port and the tagger availabale to
> > correctly work. Use the new api master_state_change to track when master
> > is operational or not and set a bool in qca8k_priv.
> > We cache the first cached master available and we check if other cpu
> > port are operational when the cached one goes down.
> > This cached master will later be used by mdio read/write and mib request to
> > correctly use the working function.
> > 
> > qca8k implementation for MDIO/MIB Ethernet is bad. CPU port0 is the only
> > one that answers with the ack packet or sends MIB Ethernet packets. For
> > this reason the master_state_change ignore CPU port6 and checkes only
> > CPU port0 if it's operational and enables this mode.
> 
> CPU port 0 may not always be wired, it depends on board design, right?
> So the Ethernet management protocol may or may not be available to all users.
>

Out of 130 device we found only 2 device that had cpu 0 disconnected and
were Xiaomi device (so not really top of following standard and advised
config from qcom). Only qca833x supports the use of cpu port6 as an
alternative port. qca8327 doesn't work with cpu port6 as the only cpu
port and cpu0 port is mandatory.
I also tested out of curiosity if mac swap handle this case and no luck,
the switch still doesn't answer with ack packet.
(config I tested was declaring only port6 as cpu port, forcing mac swap
and test if this works. Every request timeouts. Normal connection works 
and the tagger correctly works.)

> > 
> > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> > ---
> > diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
> > index ab4a417b25a9..6edd6adc3063 100644
> > --- a/drivers/net/dsa/qca8k.h
> > +++ b/drivers/net/dsa/qca8k.h
> > @@ -353,6 +353,7 @@ struct qca8k_priv {
> >  	struct dsa_switch_ops ops;
> >  	struct gpio_desc *reset_gpio;
> >  	unsigned int port_mtu[QCA8K_NUM_PORTS];
> > +	const struct net_device *master; /* Track if mdio/mib Ethernet is available */
> 
> Maybe "mgmt_master" would be a clearer naming scheme?
> 
> >  };
> >  
> >  struct qca8k_mib_desc {
> > -- 
> > 2.33.1
> > 
>
diff mbox series

Patch

diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c
index 039694518788..f317f527dd6d 100644
--- a/drivers/net/dsa/qca8k.c
+++ b/drivers/net/dsa/qca8k.c
@@ -2383,6 +2383,23 @@  qca8k_port_lag_leave(struct dsa_switch *ds, int port,
 	return qca8k_lag_refresh_portmap(ds, port, lag, true);
 }
 
+static void
+qca8k_master_change(struct dsa_switch *ds, const struct net_device *master,
+		    bool operational)
+{
+	struct dsa_port *dp = master->dsa_ptr;
+	struct qca8k_priv *priv = ds->priv;
+
+	/* Ethernet MIB/MDIO is only supported for CPU port 0 */
+	if (dp->index != 0)
+		return;
+
+	if (operational)
+		priv->master = master;
+	else
+		priv->master = NULL;
+}
+
 static const struct dsa_switch_ops qca8k_switch_ops = {
 	.get_tag_protocol	= qca8k_get_tag_protocol,
 	.setup			= qca8k_setup,
@@ -2418,6 +2435,7 @@  static const struct dsa_switch_ops qca8k_switch_ops = {
 	.get_phy_flags		= qca8k_get_phy_flags,
 	.port_lag_join		= qca8k_port_lag_join,
 	.port_lag_leave		= qca8k_port_lag_leave,
+	.master_state_change	= qca8k_master_change,
 };
 
 static int qca8k_read_switch_id(struct qca8k_priv *priv)
diff --git a/drivers/net/dsa/qca8k.h b/drivers/net/dsa/qca8k.h
index ab4a417b25a9..6edd6adc3063 100644
--- a/drivers/net/dsa/qca8k.h
+++ b/drivers/net/dsa/qca8k.h
@@ -353,6 +353,7 @@  struct qca8k_priv {
 	struct dsa_switch_ops ops;
 	struct gpio_desc *reset_gpio;
 	unsigned int port_mtu[QCA8K_NUM_PORTS];
+	const struct net_device *master; /* Track if mdio/mib Ethernet is available */
 };
 
 struct qca8k_mib_desc {