linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation
@ 2022-07-29 13:03 Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 01/10] net: dsa: microchip: don't announce extended register support on non Gbit chips Oleksij Rempel
                   ` (9 more replies)
  0 siblings, 10 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

This patch series adds error handling for the PHY read/write path and optional
register access validation.
After adding regmap_ranges for KSZ8563 some bugs was detected, so
critical bug fixes are sorted before ragmap_range patch.

Potentially this bug fixes can be ported to stable kernels, but need to be
reworked.

Oleksij Rempel (10):
  net: dsa: microchip: don't announce extended register support on non
    Gbit chips
  net: dsa: microchip: allow to pass return values for PHY read/write
    accesses
  net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite
    functions
  net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy
  net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy
  net: dsa: microchip: KSZ9893: do not write to not supported Output
    Clock Control Register
  net: dsa: microchip: warn about not supported synclko properties on
    KSZ9893 chips
  net: dsa: microchip: add support for regmap_access_tables
  net: dsa: microchip: add regmap_range for KSZ8563 chip
  net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from
    ksz9477_w_phy()

 drivers/net/dsa/microchip/ksz8.h         |   4 +-
 drivers/net/dsa/microchip/ksz8795.c      | 111 +++++++++++++----
 drivers/net/dsa/microchip/ksz9477.c      |  41 +++++--
 drivers/net/dsa/microchip/ksz9477.h      |   4 +-
 drivers/net/dsa/microchip/ksz_common.c   | 148 ++++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz_common.h   |  76 +++++++++---
 drivers/net/dsa/microchip/ksz_spi.c      |   3 +
 drivers/net/dsa/microchip/lan937x.h      |   4 +-
 drivers/net/dsa/microchip/lan937x_main.c |   8 +-
 9 files changed, 337 insertions(+), 62 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 01/10] net: dsa: microchip: don't announce extended register support on non Gbit chips
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses Oleksij Rempel
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

This issue was detected after adding support of regmap_ranges for KSZ8563R
chip. This chip is reporting extended registers support without having
actual extended registers. This made PHYlib request not existing
registers.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index c108d5444695..841f0d2b15c9 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -264,6 +264,22 @@ void ksz9477_port_init_cnt(struct ksz_device *dev, int port)
 	mutex_unlock(&mib->cnt_mutex);
 }
 
+
+static void ksz9477_r_phy_quirks(struct ksz_device *dev, u16 addr, u16 reg,
+				 u16 *data)
+{
+	/* KSZ8563R do not have extended registers but BMSR_ESTATEN and
+	 * BMSR_ERCAP bits are set.
+	 * Since all KSZ9893 compatible chips, do not support extended
+	 * registers, it should be save to apply this quirk on complete family.
+	 * It is not possible to integrate this code in the PHY driver, since
+	 * we can't use PHYid to distinguish Gbit capable KSZ9477 PHYs from
+	 * 100Mbit KSZ8563R PHYs.
+	 */
+	if (dev->chip_id == KSZ9893_CHIP_ID && reg == MII_BMSR)
+		*data &= ~(BMSR_ESTATEN | BMSR_ERCAP);
+}
+
 void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
 	u16 val = 0xffff;
@@ -308,6 +324,7 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 		}
 	} else {
 		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
+		ksz9477_r_phy_quirks(dev, addr, reg, &val);
 	}
 
 	*data = val;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 01/10] net: dsa: microchip: don't announce extended register support on non Gbit chips Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-02 11:19   ` Vladimir Oltean
  2022-07-29 13:03 ` [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions Oleksij Rempel
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

PHY access may end with errors on different levels. So, allow to forward
return values where possible.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8.h         |  4 ++--
 drivers/net/dsa/microchip/ksz8795.c      |  9 +++++++--
 drivers/net/dsa/microchip/ksz9477.c      | 12 ++++++++----
 drivers/net/dsa/microchip/ksz9477.h      |  4 ++--
 drivers/net/dsa/microchip/ksz_common.c   | 10 ++++++++--
 drivers/net/dsa/microchip/ksz_common.h   |  4 ++--
 drivers/net/dsa/microchip/lan937x.h      |  4 ++--
 drivers/net/dsa/microchip/lan937x_main.c |  8 ++++----
 8 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h
index 42c50cc4d853..8582b4b67d98 100644
--- a/drivers/net/dsa/microchip/ksz8.h
+++ b/drivers/net/dsa/microchip/ksz8.h
@@ -17,8 +17,8 @@ u32 ksz8_get_port_addr(int port, int offset);
 void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member);
 void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port);
 void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port);
-void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
-void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
+int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
+int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
 int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
 			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries);
 int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index c79a5128235f..4b39666cfc9c 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -552,7 +552,7 @@ static void ksz8_w_vlan_table(struct ksz_device *dev, u16 vid, u16 vlan)
 	ksz8_w_table(dev, TABLE_VLAN, addr, buf);
 }
 
-void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
+int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 {
 	u8 restart, speed, ctrl, link;
 	int processed = true;
@@ -674,9 +674,11 @@ void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 	}
 	if (processed)
 		*val = data;
+
+	return 0;
 }
 
-void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
+int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 {
 	u8 restart, speed, ctrl, data;
 	const u16 *regs;
@@ -787,6 +789,9 @@ void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 	default:
 		break;
 	}
+
+
+	return 0;
 }
 
 void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member)
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 841f0d2b15c9..9d749537cf01 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -280,7 +280,7 @@ static void ksz9477_r_phy_quirks(struct ksz_device *dev, u16 addr, u16 reg,
 		*data &= ~(BMSR_ESTATEN | BMSR_ERCAP);
 }
 
-void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
+int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
 	u16 val = 0xffff;
 
@@ -328,19 +328,23 @@ void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 	}
 
 	*data = val;
+
+	return 0;
 }
 
-void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
+int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 {
 	/* No real PHY after this. */
 	if (addr >= dev->phy_port_cnt)
-		return;
+		return 0;
 
 	/* No gigabit support.  Do not write to this register. */
 	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
-		return;
+		return 0;
 
 	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
+
+	return 0;
 }
 
 void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)
diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h
index cd278b307b3c..ce87e4e09ada 100644
--- a/drivers/net/dsa/microchip/ksz9477.h
+++ b/drivers/net/dsa/microchip/ksz9477.h
@@ -16,8 +16,8 @@ u32 ksz9477_get_port_addr(int port, int offset);
 void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member);
 void ksz9477_flush_dyn_mac_table(struct ksz_device *dev, int port);
 void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port);
-void ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
-void ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
+int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
+int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
 void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
 void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
 		       u64 *dropped, u64 *cnt);
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index ed7d137cba99..71b5349d006a 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1089,8 +1089,11 @@ static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
 {
 	struct ksz_device *dev = ds->priv;
 	u16 val = 0xffff;
+	int ret;
 
-	dev->dev_ops->r_phy(dev, addr, reg, &val);
+	ret = dev->dev_ops->r_phy(dev, addr, reg, &val);
+	if (ret)
+		return ret;
 
 	return val;
 }
@@ -1098,8 +1101,11 @@ static int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg)
 static int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
 {
 	struct ksz_device *dev = ds->priv;
+	int ret;
 
-	dev->dev_ops->w_phy(dev, addr, reg, val);
+	ret = dev->dev_ops->w_phy(dev, addr, reg, val);
+	if (ret)
+		return ret;
 
 	return 0;
 }
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 764ada3a0f42..a06b9bf5938b 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -258,8 +258,8 @@ struct ksz_dev_ops {
 	void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
 	void (*port_cleanup)(struct ksz_device *dev, int port);
 	void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
-	void (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
-	void (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
+	int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
+	int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
 	void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
 			  u64 *cnt);
 	void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
diff --git a/drivers/net/dsa/microchip/lan937x.h b/drivers/net/dsa/microchip/lan937x.h
index 4e0b1dccec27..5d78d034a62f 100644
--- a/drivers/net/dsa/microchip/lan937x.h
+++ b/drivers/net/dsa/microchip/lan937x.h
@@ -12,8 +12,8 @@ void lan937x_port_setup(struct ksz_device *dev, int port, bool cpu_port);
 void lan937x_config_cpu_port(struct dsa_switch *ds);
 int lan937x_switch_init(struct ksz_device *dev);
 void lan937x_switch_exit(struct ksz_device *dev);
-void lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
-void lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
+int lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data);
+int lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val);
 int lan937x_change_mtu(struct ksz_device *dev, int port, int new_mtu);
 void lan937x_phylink_get_caps(struct ksz_device *dev, int port,
 			      struct phylink_config *config);
diff --git a/drivers/net/dsa/microchip/lan937x_main.c b/drivers/net/dsa/microchip/lan937x_main.c
index daedd2bf20c1..7b464f1fb5d8 100644
--- a/drivers/net/dsa/microchip/lan937x_main.c
+++ b/drivers/net/dsa/microchip/lan937x_main.c
@@ -128,14 +128,14 @@ static int lan937x_internal_phy_read(struct ksz_device *dev, int addr, int reg,
 	return ksz_read16(dev, REG_VPHY_IND_DATA__2, val);
 }
 
-void lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
+int lan937x_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
-	lan937x_internal_phy_read(dev, addr, reg, data);
+	return lan937x_internal_phy_read(dev, addr, reg, data);
 }
 
-void lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
+int lan937x_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 {
-	lan937x_internal_phy_write(dev, addr, reg, val);
+	return lan937x_internal_phy_write(dev, addr, reg, val);
 }
 
 static int lan937x_sw_mdio_read(struct mii_bus *bus, int addr, int regnum)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 01/10] net: dsa: microchip: don't announce extended register support on non Gbit chips Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-02 11:19   ` Vladimir Oltean
  2022-07-29 13:03 ` [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy Oleksij Rempel
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

ksz_read*/ksz_write* are able to return errors, so forward it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.h | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index a06b9bf5938b..3a64a444fa26 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -390,40 +390,42 @@ static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
 	return regmap_bulk_write(dev->regmap[2], reg, val, 2);
 }
 
-static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
 			      u8 *data)
 {
-	ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
 }
 
-static inline void ksz_pread16(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pread16(struct ksz_device *dev, int port, int offset,
 			       u16 *data)
 {
-	ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
 }
 
-static inline void ksz_pread32(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pread32(struct ksz_device *dev, int port, int offset,
 			       u32 *data)
 {
-	ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
 }
 
-static inline void ksz_pwrite8(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pwrite8(struct ksz_device *dev, int port, int offset,
 			       u8 data)
 {
-	ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
 }
 
-static inline void ksz_pwrite16(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pwrite16(struct ksz_device *dev, int port, int offset,
 				u16 data)
 {
-	ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset),
+			   data);
 }
 
-static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
+static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
 				u32 data)
 {
-	ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data);
+	return ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset),
+			   data);
 }
 
 static inline void ksz_prmw8(struct ksz_device *dev, int port, int offset,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (2 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-02 11:24   ` Vladimir Oltean
  2022-07-29 13:03 ` [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy Oleksij Rempel
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

Now ksz_pread/ksz_pwrite can return error value. So, make use of it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 9d749537cf01..074d4c16d427 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -283,6 +283,7 @@ static void ksz9477_r_phy_quirks(struct ksz_device *dev, u16 addr, u16 reg,
 int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 {
 	u16 val = 0xffff;
+	int ret;
 
 	/* No real PHY after this. Simulate the PHY.
 	 * A fixed PHY can be setup in the device tree, but this function is
@@ -323,7 +324,10 @@ int ksz9477_r_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 *data)
 			break;
 		}
 	} else {
-		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
+		ret = ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
+		if (ret)
+			return ret;
+
 		ksz9477_r_phy_quirks(dev, addr, reg, &val);
 	}
 
@@ -340,11 +344,9 @@ int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 
 	/* No gigabit support.  Do not write to this register. */
 	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
-		return 0;
+		return -ENOTSUPP;
 
-	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
-
-	return 0;
+	return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
 }
 
 void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (3 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-02 11:29   ` Vladimir Oltean
  2022-07-29 13:03 ` [PATCH net-next v1 06/10] net: dsa: microchip: KSZ9893: do not write to not supported Output Clock Control Register Oleksij Rempel
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

Now ksz_pread/ksz_pwrite can return error value. So, make use of it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz8795.c | 102 ++++++++++++++++++++++------
 1 file changed, 81 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 4b39666cfc9c..1aaf765611e8 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -560,14 +560,24 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 	u8 val1, val2;
 	u16 data = 0;
 	u8 p = phy;
+	int ret;
 
 	regs = dev->info->regs;
 
 	switch (reg) {
 	case MII_BMCR:
-		ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
-		ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
-		ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
+		ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
+		if (ret)
+			return ret;
+
+		ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
+		if (ret)
+			return ret;
+
+		ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
+		if (ret)
+			return ret;
+
 		if (restart & PORT_PHY_LOOPBACK)
 			data |= BMCR_LOOPBACK;
 		if (ctrl & PORT_FORCE_100_MBIT)
@@ -597,7 +607,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 			data |= KSZ886X_BMCR_DISABLE_LED;
 		break;
 	case MII_BMSR:
-		ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
+		ret = ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
+		if (ret)
+			return ret;
+
 		data = BMSR_100FULL |
 		       BMSR_100HALF |
 		       BMSR_10FULL |
@@ -618,7 +631,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 			data = KSZ8795_ID_LO;
 		break;
 	case MII_ADVERTISE:
-		ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
+		ret = ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
+		if (ret)
+			return ret;
+
 		data = ADVERTISE_CSMA;
 		if (ctrl & PORT_AUTO_NEG_SYM_PAUSE)
 			data |= ADVERTISE_PAUSE_CAP;
@@ -632,7 +648,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 			data |= ADVERTISE_10HALF;
 		break;
 	case MII_LPA:
-		ksz_pread8(dev, p, regs[P_REMOTE_STATUS], &link);
+		ret = ksz_pread8(dev, p, regs[P_REMOTE_STATUS], &link);
+		if (ret)
+			return ret;
+
 		data = LPA_SLCT;
 		if (link & PORT_REMOTE_SYM_PAUSE)
 			data |= LPA_PAUSE_CAP;
@@ -648,8 +667,14 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 			data |= LPA_LPACK;
 		break;
 	case PHY_REG_LINK_MD:
-		ksz_pread8(dev, p, REG_PORT_LINK_MD_CTRL, &val1);
-		ksz_pread8(dev, p, REG_PORT_LINK_MD_RESULT, &val2);
+		ret = ksz_pread8(dev, p, REG_PORT_LINK_MD_CTRL, &val1);
+		if (ret)
+			return ret;
+
+		ret = ksz_pread8(dev, p, REG_PORT_LINK_MD_RESULT, &val2);
+		if (ret)
+			return ret;
+
 		if (val1 & PORT_START_CABLE_DIAG)
 			data |= PHY_START_CABLE_DIAG;
 
@@ -664,7 +689,10 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
 				FIELD_GET(PORT_CABLE_FAULT_COUNTER_L, val2));
 		break;
 	case PHY_REG_PHY_CTRL:
-		ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
+		ret = ksz_pread8(dev, p, regs[P_LINK_STATUS], &link);
+		if (ret)
+			return ret;
+
 		if (link & PORT_MDIX_STATUS)
 			data |= KSZ886X_CTRL_MDIX_STAT;
 		break;
@@ -683,6 +711,7 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 	u8 restart, speed, ctrl, data;
 	const u16 *regs;
 	u8 p = phy;
+	int ret;
 
 	regs = dev->info->regs;
 
@@ -692,15 +721,26 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 		/* Do not support PHY reset function. */
 		if (val & BMCR_RESET)
 			break;
-		ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
+		ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS], &speed);
+		if (ret)
+			return ret;
+
 		data = speed;
 		if (val & KSZ886X_BMCR_HP_MDIX)
 			data |= PORT_HP_MDIX;
 		else
 			data &= ~PORT_HP_MDIX;
-		if (data != speed)
-			ksz_pwrite8(dev, p, regs[P_SPEED_STATUS], data);
-		ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
+
+		if (data != speed) {
+			ret = ksz_pwrite8(dev, p, regs[P_SPEED_STATUS], data);
+			if (ret)
+				return ret;
+		}
+
+		ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
+		if (ret)
+			return ret;
+
 		data = ctrl;
 		if (ksz_is_ksz88x3(dev)) {
 			if ((val & BMCR_ANENABLE))
@@ -726,9 +766,17 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 			data |= PORT_FORCE_FULL_DUPLEX;
 		else
 			data &= ~PORT_FORCE_FULL_DUPLEX;
-		if (data != ctrl)
-			ksz_pwrite8(dev, p, regs[P_FORCE_CTRL], data);
-		ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
+
+		if (data != ctrl) {
+			ret = ksz_pwrite8(dev, p, regs[P_FORCE_CTRL], data);
+			if (ret)
+				return ret;
+		}
+
+		ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL], &restart);
+		if (ret)
+			return ret;
+
 		data = restart;
 		if (val & KSZ886X_BMCR_DISABLE_LED)
 			data |= PORT_LED_OFF;
@@ -758,11 +806,19 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 			data |= PORT_PHY_LOOPBACK;
 		else
 			data &= ~PORT_PHY_LOOPBACK;
-		if (data != restart)
-			ksz_pwrite8(dev, p, regs[P_NEG_RESTART_CTRL], data);
+
+		if (data != restart) {
+			ret = ksz_pwrite8(dev, p, regs[P_NEG_RESTART_CTRL],
+					  data);
+			if (ret)
+				return ret;
+		}
 		break;
 	case MII_ADVERTISE:
-		ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
+		ret = ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
+		if (ret)
+			return ret;
+
 		data = ctrl;
 		data &= ~(PORT_AUTO_NEG_SYM_PAUSE |
 			  PORT_AUTO_NEG_100BTX_FD |
@@ -779,8 +835,12 @@ int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
 			data |= PORT_AUTO_NEG_10BT_FD;
 		if (val & ADVERTISE_10HALF)
 			data |= PORT_AUTO_NEG_10BT;
-		if (data != ctrl)
-			ksz_pwrite8(dev, p, regs[P_LOCAL_CTRL], data);
+
+		if (data != ctrl) {
+			ret = ksz_pwrite8(dev, p, regs[P_LOCAL_CTRL], data);
+			if (ret)
+				return ret;
+		}
 		break;
 	case PHY_REG_LINK_MD:
 		if (val & PHY_START_CABLE_DIAG)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 06/10] net: dsa: microchip: KSZ9893: do not write to not supported Output Clock Control Register
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (4 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips Oleksij Rempel
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

This issue was detected after adding regmap register access validation.
KSZ9893 compatible chips do not have "Output Clock Control Register 0x0103".
So, avoid writing to it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 074d4c16d427..a3ddc9021af3 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -193,6 +193,10 @@ int ksz9477_reset_switch(struct ksz_device *dev)
 	ksz_write32(dev, REG_SW_PORT_INT_MASK__4, 0x7F);
 	ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data32);
 
+	/* KSZ9893 compatible chips do not support refclk configuration */
+	if (dev->chip_id == KSZ9893_CHIP_ID)
+		return 0;
+
 	data8 = SW_ENABLE_REFCLKO;
 	if (dev->synclko_disable)
 		data8 = 0;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (5 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 06/10] net: dsa: microchip: KSZ9893: do not write to not supported Output Clock Control Register Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-02 11:36   ` Vladimir Oltean
  2022-07-29 13:03 ` [PATCH net-next v1 08/10] net: dsa: microchip: add support for regmap_access_tables Oleksij Rempel
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

KSZ9893 family of chips do not support synclko property. So warn about
without preventing driver from start.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 71b5349d006a..d3a9836c706f 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1916,6 +1916,13 @@ int ksz_switch_register(struct ksz_device *dev)
 			dev_err(dev->dev, "inconsistent synclko settings\n");
 			return -EINVAL;
 		}
+
+		if (dev->chip_id == KSZ9893_CHIP_ID && (dev->synclko_125 ||
+							dev->synclko_disable)) {
+			dev_warn(dev->dev, "microchip,synclko-125 and microchip,synclko-disable "
+				 "properties are not supported on this chip. "
+				 "Please fix you devicetree.\n");
+		}
 	}
 
 	ret = dsa_register_switch(dev->ds);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 08/10] net: dsa: microchip: add support for regmap_access_tables
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (6 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 10/10] net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from ksz9477_w_phy() Oleksij Rempel
  9 siblings, 0 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

This is complex driver with support for different chips with different
layouts. To detect at least some bugs earlier, we should validate register
accesses by using regmap_access_table support.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.h | 46 +++++++++++++++++++++++---
 drivers/net/dsa/microchip/ksz_spi.c    |  3 ++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 3a64a444fa26..d460ae6ea82d 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -61,6 +61,8 @@ struct ksz_chip_data {
 	bool supports_rmii[KSZ_MAX_NUM_PORTS];
 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
 	bool internal_phy[KSZ_MAX_NUM_PORTS];
+	const struct regmap_access_table *wr_table;
+	const struct regmap_access_table *rd_table;
 };
 
 struct ksz_port {
@@ -329,6 +331,10 @@ static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
 	unsigned int value;
 	int ret = regmap_read(dev->regmap[0], reg, &value);
 
+	if (ret)
+		dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
 	*val = value;
 	return ret;
 }
@@ -338,6 +344,10 @@ static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
 	unsigned int value;
 	int ret = regmap_read(dev->regmap[1], reg, &value);
 
+	if (ret)
+		dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
 	*val = value;
 	return ret;
 }
@@ -347,6 +357,10 @@ static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
 	unsigned int value;
 	int ret = regmap_read(dev->regmap[2], reg, &value);
 
+	if (ret)
+		dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
 	*val = value;
 	return ret;
 }
@@ -357,7 +371,10 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
 	int ret;
 
 	ret = regmap_bulk_read(dev->regmap[2], reg, value, 2);
-	if (!ret)
+	if (ret)
+		dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+	else
 		*val = (u64)value[0] << 32 | value[1];
 
 	return ret;
@@ -365,17 +382,38 @@ static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
 
 static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
 {
-	return regmap_write(dev->regmap[0], reg, value);
+	int ret;
+
+	ret = regmap_write(dev->regmap[0], reg, value);
+	if (ret)
+		dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
+	return ret;
 }
 
 static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
 {
-	return regmap_write(dev->regmap[1], reg, value);
+	int ret;
+
+	ret = regmap_write(dev->regmap[1], reg, value);
+	if (ret)
+		dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
+	return ret;
 }
 
 static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
 {
-	return regmap_write(dev->regmap[2], reg, value);
+	int ret;
+
+	ret = regmap_write(dev->regmap[2], reg, value);
+	if (ret)
+		dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe \n", reg,
+			ERR_PTR(ret));
+
+	return ret;
 }
 
 static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
diff --git a/drivers/net/dsa/microchip/ksz_spi.c b/drivers/net/dsa/microchip/ksz_spi.c
index 05bd089795f8..a377454450b3 100644
--- a/drivers/net/dsa/microchip/ksz_spi.c
+++ b/drivers/net/dsa/microchip/ksz_spi.c
@@ -66,7 +66,10 @@ static int ksz_spi_probe(struct spi_device *spi)
 	for (i = 0; i < ARRAY_SIZE(ksz8795_regmap_config); i++) {
 		rc = regmap_config[i];
 		rc.lock_arg = &dev->regmap_mutex;
+		rc.wr_table = chip->wr_table;
+		rc.rd_table = chip->rd_table;
 		dev->regmap[i] = devm_regmap_init_spi(spi, &rc);
+
 		if (IS_ERR(dev->regmap[i])) {
 			ret = PTR_ERR(dev->regmap[i]);
 			dev_err(&spi->dev,
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (7 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 08/10] net: dsa: microchip: add support for regmap_access_tables Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  2022-08-01  5:11   ` Oleksij Rempel
  2022-07-29 13:03 ` [PATCH net-next v1 10/10] net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from ksz9477_w_phy() Oleksij Rempel
  9 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

Add register validation for KSZ8563.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz_common.c | 131 +++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index d3a9836c706f..97b5fb75b489 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -412,6 +412,135 @@ static const u8 lan937x_shifts[] = {
 	[ALU_STAT_INDEX]		= 8,
 };
 
+static const struct regmap_range ksz8563_valid_regs[] = {
+	regmap_reg_range(0x0000, 0x0003),
+	regmap_reg_range(0x0006, 0x0006),
+	regmap_reg_range(0x000f, 0x001f),
+	regmap_reg_range(0x0100, 0x0100),
+	regmap_reg_range(0x0104, 0x0107),
+	regmap_reg_range(0x010d, 0x010d),
+	regmap_reg_range(0x0110, 0x0113),
+	regmap_reg_range(0x0120, 0x012b),
+	regmap_reg_range(0x0201, 0x0201),
+	regmap_reg_range(0x0210, 0x0213),
+	regmap_reg_range(0x0300, 0x0300),
+	regmap_reg_range(0x0302, 0x031b),
+	regmap_reg_range(0x0320, 0x032b),
+	regmap_reg_range(0x0330, 0x0336),
+	regmap_reg_range(0x0338, 0x033e),
+	regmap_reg_range(0x0340, 0x035f),
+	regmap_reg_range(0x0370, 0x0370),
+	regmap_reg_range(0x0378, 0x0378),
+	regmap_reg_range(0x037c, 0x037d),
+	regmap_reg_range(0x0390, 0x0393),
+	regmap_reg_range(0x0400, 0x040e),
+	regmap_reg_range(0x0410, 0x042f),
+	regmap_reg_range(0x0500, 0x0519),
+	regmap_reg_range(0x0520, 0x054b),
+	regmap_reg_range(0x0550, 0x05b3),
+
+	/* port 1 */
+	regmap_reg_range(0x1000, 0x1001),
+	regmap_reg_range(0x1004, 0x100b),
+	regmap_reg_range(0x1013, 0x1013),
+	regmap_reg_range(0x1017, 0x1017),
+	regmap_reg_range(0x101b, 0x101b),
+	regmap_reg_range(0x101f, 0x1021),
+	regmap_reg_range(0x1030, 0x1030),
+	regmap_reg_range(0x1100, 0x1111),
+	regmap_reg_range(0x111a, 0x111d),
+	regmap_reg_range(0x1122, 0x1127),
+	regmap_reg_range(0x112a, 0x112b),
+	regmap_reg_range(0x1136, 0x1139),
+	regmap_reg_range(0x113e, 0x113f),
+	regmap_reg_range(0x1300, 0x1301),
+	regmap_reg_range(0x1303, 0x1303),
+	regmap_reg_range(0x1400, 0x1401),
+	regmap_reg_range(0x1403, 0x1403),
+	regmap_reg_range(0x1410, 0x1417),
+	regmap_reg_range(0x1420, 0x1423),
+	regmap_reg_range(0x1500, 0x1507),
+	regmap_reg_range(0x1600, 0x1612),
+	regmap_reg_range(0x1800, 0x180f),
+	regmap_reg_range(0x1900, 0x1907),
+	regmap_reg_range(0x1914, 0x191b),
+	regmap_reg_range(0x1a00, 0x1a03),
+	regmap_reg_range(0x1a04, 0x1a08),
+	regmap_reg_range(0x1b00, 0x1b01),
+	regmap_reg_range(0x1b04, 0x1b04),
+	regmap_reg_range(0x1c00, 0x1c05),
+	regmap_reg_range(0x1c08, 0x1c1b),
+
+	/* port 2 */
+	regmap_reg_range(0x2000, 0x2001),
+	regmap_reg_range(0x2004, 0x200b),
+	regmap_reg_range(0x2013, 0x2013),
+	regmap_reg_range(0x2017, 0x2017),
+	regmap_reg_range(0x201b, 0x201b),
+	regmap_reg_range(0x201f, 0x2021),
+	regmap_reg_range(0x2030, 0x2030),
+	regmap_reg_range(0x2100, 0x2111),
+	regmap_reg_range(0x211a, 0x211d),
+	regmap_reg_range(0x2122, 0x2127),
+	regmap_reg_range(0x212a, 0x212b),
+	regmap_reg_range(0x2136, 0x2139),
+	regmap_reg_range(0x213e, 0x213f),
+	regmap_reg_range(0x2300, 0x2301),
+	regmap_reg_range(0x2303, 0x2303),
+	regmap_reg_range(0x2400, 0x2401),
+	regmap_reg_range(0x2403, 0x2403),
+	regmap_reg_range(0x2410, 0x2417),
+	regmap_reg_range(0x2420, 0x2423),
+	regmap_reg_range(0x2500, 0x2507),
+	regmap_reg_range(0x2600, 0x2612),
+	regmap_reg_range(0x2800, 0x280f),
+	regmap_reg_range(0x2900, 0x2907),
+	regmap_reg_range(0x2914, 0x291b),
+	regmap_reg_range(0x2a00, 0x2a03),
+	regmap_reg_range(0x2a04, 0x2a08),
+	regmap_reg_range(0x2b00, 0x2b01),
+	regmap_reg_range(0x2b04, 0x2b04),
+	regmap_reg_range(0x2c00, 0x2c05),
+	regmap_reg_range(0x2c08, 0x2c1b),
+
+	/* port 3 */
+	regmap_reg_range(0x3000, 0x3001),
+	regmap_reg_range(0x3004, 0x300b),
+	regmap_reg_range(0x3013, 0x3013),
+	regmap_reg_range(0x3017, 0x3017),
+	regmap_reg_range(0x301b, 0x301b),
+	regmap_reg_range(0x301f, 0x3021),
+	regmap_reg_range(0x3030, 0x3030),
+	regmap_reg_range(0x3100, 0x3111),
+	regmap_reg_range(0x311a, 0x311d),
+	regmap_reg_range(0x3122, 0x3127),
+	regmap_reg_range(0x312a, 0x312b),
+	regmap_reg_range(0x3136, 0x3139),
+	regmap_reg_range(0x313e, 0x313f),
+	regmap_reg_range(0x3300, 0x3301),
+	regmap_reg_range(0x3303, 0x3303),
+	regmap_reg_range(0x3400, 0x3401),
+	regmap_reg_range(0x3403, 0x3403),
+	regmap_reg_range(0x3410, 0x3417),
+	regmap_reg_range(0x3420, 0x3423),
+	regmap_reg_range(0x3500, 0x3507),
+	regmap_reg_range(0x3600, 0x3612),
+	regmap_reg_range(0x3800, 0x380f),
+	regmap_reg_range(0x3900, 0x3907),
+	regmap_reg_range(0x3914, 0x391b),
+	regmap_reg_range(0x3a00, 0x3a03),
+	regmap_reg_range(0x3a04, 0x3a08),
+	regmap_reg_range(0x3b00, 0x3b01),
+	regmap_reg_range(0x3b04, 0x3b04),
+	regmap_reg_range(0x3c00, 0x3c05),
+	regmap_reg_range(0x3c08, 0x3c1b),
+};
+
+static const struct regmap_access_table ksz8563_register_set = {
+	.yes_ranges = ksz8563_valid_regs,
+	.n_yes_ranges = ARRAY_SIZE(ksz8563_valid_regs),
+};
+
 const struct ksz_chip_data ksz_switch_chips[] = {
 	[KSZ8795] = {
 		.chip_id = KSZ8795_CHIP_ID,
@@ -596,6 +725,8 @@ const struct ksz_chip_data ksz_switch_chips[] = {
 		.supports_rmii = {false, false, true},
 		.supports_rgmii = {false, false, true},
 		.internal_phy = {true, true, false},
+		.wr_table = &ksz8563_register_set,
+		.rd_table = &ksz8563_register_set,
 	},
 
 	[KSZ9567] = {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH net-next v1 10/10] net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from ksz9477_w_phy()
  2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
                   ` (8 preceding siblings ...)
  2022-07-29 13:03 ` [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip Oleksij Rempel
@ 2022-07-29 13:03 ` Oleksij Rempel
  9 siblings, 0 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-07-29 13:03 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Oleksij Rempel, kernel, linux-kernel, netdev

The reason why PHYlib may access MII_CTRL1000 on the chip without GBit
support is only if chip provides wrong information about extended caps
register. This issue is now handled by ksz9477_r_phy_quirks()

With proper regmap_ranges provided for all chips we will be able to catch this
kind of bugs any way. So, remove this sanity check.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa/microchip/ksz9477.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index a3ddc9021af3..caef13ae9070 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -346,10 +346,6 @@ int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
 	if (addr >= dev->phy_port_cnt)
 		return 0;
 
-	/* No gigabit support.  Do not write to this register. */
-	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
-		return -ENOTSUPP;
-
 	return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip
  2022-07-29 13:03 ` [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip Oleksij Rempel
@ 2022-08-01  5:11   ` Oleksij Rempel
  0 siblings, 0 replies; 25+ messages in thread
From: Oleksij Rempel @ 2022-08-01  5:11 UTC (permalink / raw)
  To: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:45PM +0200, Oleksij Rempel wrote:
> Add register validation for KSZ8563.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz_common.c | 131 +++++++++++++++++++++++++
>  1 file changed, 131 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index d3a9836c706f..97b5fb75b489 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -412,6 +412,135 @@ static const u8 lan937x_shifts[] = {
>  	[ALU_STAT_INDEX]		= 8,
>  };
>  
> +static const struct regmap_range ksz8563_valid_regs[] = {
> +	regmap_reg_range(0x0000, 0x0003),
> +	regmap_reg_range(0x0006, 0x0006),
> +	regmap_reg_range(0x000f, 0x001f),
> +	regmap_reg_range(0x0100, 0x0100),
> +	regmap_reg_range(0x0104, 0x0107),
> +	regmap_reg_range(0x010d, 0x010d),
> +	regmap_reg_range(0x0110, 0x0113),
> +	regmap_reg_range(0x0120, 0x012b),
> +	regmap_reg_range(0x0201, 0x0201),
> +	regmap_reg_range(0x0210, 0x0213),
> +	regmap_reg_range(0x0300, 0x0300),
> +	regmap_reg_range(0x0302, 0x031b),
> +	regmap_reg_range(0x0320, 0x032b),
> +	regmap_reg_range(0x0330, 0x0336),
> +	regmap_reg_range(0x0338, 0x033e),
> +	regmap_reg_range(0x0340, 0x035f),
> +	regmap_reg_range(0x0370, 0x0370),
> +	regmap_reg_range(0x0378, 0x0378),
> +	regmap_reg_range(0x037c, 0x037d),
> +	regmap_reg_range(0x0390, 0x0393),
> +	regmap_reg_range(0x0400, 0x040e),
> +	regmap_reg_range(0x0410, 0x042f),
> +	regmap_reg_range(0x0500, 0x0519),
> +	regmap_reg_range(0x0520, 0x054b),
> +	regmap_reg_range(0x0550, 0x05b3),
> +
> +	/* port 1 */
> +	regmap_reg_range(0x1000, 0x1001),
> +	regmap_reg_range(0x1004, 0x100b),
> +	regmap_reg_range(0x1013, 0x1013),
> +	regmap_reg_range(0x1017, 0x1017),
> +	regmap_reg_range(0x101b, 0x101b),
> +	regmap_reg_range(0x101f, 0x1021),
> +	regmap_reg_range(0x1030, 0x1030),
> +	regmap_reg_range(0x1100, 0x1111),
> +	regmap_reg_range(0x111a, 0x111d),
> +	regmap_reg_range(0x1122, 0x1127),
> +	regmap_reg_range(0x112a, 0x112b),
> +	regmap_reg_range(0x1136, 0x1139),
> +	regmap_reg_range(0x113e, 0x113f),
> +	regmap_reg_range(0x1300, 0x1301),
> +	regmap_reg_range(0x1303, 0x1303),

Some of this register are not supported on port 1 and 2. I'll send new
version of this patches.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses
  2022-07-29 13:03 ` [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses Oleksij Rempel
@ 2022-08-02 11:19   ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-02 11:19 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:38PM +0200, Oleksij Rempel wrote:
> PHY access may end with errors on different levels. So, allow to forward
> return values where possible.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> -void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
> +int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
>  {
>  	u8 restart, speed, ctrl, data;
>  	const u16 *regs;
> @@ -787,6 +789,9 @@ void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
>  	default:
>  		break;
>  	}
> +
> +

Too many empty lines.

> +	return 0;
>  }

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions
  2022-07-29 13:03 ` [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions Oleksij Rempel
@ 2022-08-02 11:19   ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-02 11:19 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:39PM +0200, Oleksij Rempel wrote:
> ksz_read*/ksz_write* are able to return errors, so forward it.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy
  2022-07-29 13:03 ` [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy Oleksij Rempel
@ 2022-08-02 11:24   ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-02 11:24 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:40PM +0200, Oleksij Rempel wrote:
>  	} else {
> -		ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> +		ret = ksz_pread16(dev, addr, 0x100 + (reg << 1), &val);
> +		if (ret)
> +			return ret;
> +
>  		ksz9477_r_phy_quirks(dev, addr, reg, &val);
>  	}
>  
> @@ -340,11 +344,9 @@ int ksz9477_w_phy(struct ksz_device *dev, u16 addr, u16 reg, u16 val)
>  
>  	/* No gigabit support.  Do not write to this register. */
>  	if (!(dev->features & GBIT_SUPPORT) && reg == MII_CTRL1000)
> -		return 0;
> +		return -ENOTSUPP;

I wonder if ENOTSUPP is the most appropriate error code, given that I
see it defined under a comment "Defined for the NFSv3 protocol".
How about -ENXIO?

>  
> -	ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
> -
> -	return 0;
> +	return ksz_pwrite16(dev, addr, 0x100 + (reg << 1), val);
>  }
>  
>  void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member)
> -- 
> 2.30.2
> 


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy
  2022-07-29 13:03 ` [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy Oleksij Rempel
@ 2022-08-02 11:29   ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-02 11:29 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:41PM +0200, Oleksij Rempel wrote:
> Now ksz_pread/ksz_pwrite can return error value. So, make use of it.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---

Reviewed-by: Vladimir Oltean <olteanv@gmail.com>

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-07-29 13:03 ` [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips Oleksij Rempel
@ 2022-08-02 11:36   ` Vladimir Oltean
  2022-08-05 11:56     ` Oleksij Rempel
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-02 11:36 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Jul 29, 2022 at 03:03:43PM +0200, Oleksij Rempel wrote:
> KSZ9893 family of chips do not support synclko property. So warn about
> without preventing driver from start.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa/microchip/ksz_common.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> index 71b5349d006a..d3a9836c706f 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -1916,6 +1916,13 @@ int ksz_switch_register(struct ksz_device *dev)
>  			dev_err(dev->dev, "inconsistent synclko settings\n");
>  			return -EINVAL;
>  		}
> +
> +		if (dev->chip_id == KSZ9893_CHIP_ID && (dev->synclko_125 ||
> +							dev->synclko_disable)) {
> +			dev_warn(dev->dev, "microchip,synclko-125 and microchip,synclko-disable "
> +				 "properties are not supported on this chip. "
> +				 "Please fix you devicetree.\n");

s/you/your/

Does KSZ8 have a REFCLK output of any sort? If it doesn't, then
"microchip,synclko-disable" is kind of supported, right?

I wonder what there is to gain by saying that you should remove some
device tree properties from non-ksz9477. After all, anyone can add any
random properties to a KSZ8 switch OF node and you won't warn about
those.

> +		}
>  	}
>  
>  	ret = dsa_register_switch(dev->ds);
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-02 11:36   ` Vladimir Oltean
@ 2022-08-05 11:56     ` Oleksij Rempel
  2022-08-05 13:42       ` Vladimir Oltean
  0 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-08-05 11:56 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Tue, Aug 02, 2022 at 02:36:33PM +0300, Vladimir Oltean wrote:
> On Fri, Jul 29, 2022 at 03:03:43PM +0200, Oleksij Rempel wrote:
> > KSZ9893 family of chips do not support synclko property. So warn about
> > without preventing driver from start.
> > 
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  drivers/net/dsa/microchip/ksz_common.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
> > index 71b5349d006a..d3a9836c706f 100644
> > --- a/drivers/net/dsa/microchip/ksz_common.c
> > +++ b/drivers/net/dsa/microchip/ksz_common.c
> > @@ -1916,6 +1916,13 @@ int ksz_switch_register(struct ksz_device *dev)
> >  			dev_err(dev->dev, "inconsistent synclko settings\n");
> >  			return -EINVAL;
> >  		}
> > +
> > +		if (dev->chip_id == KSZ9893_CHIP_ID && (dev->synclko_125 ||
> > +							dev->synclko_disable)) {
> > +			dev_warn(dev->dev, "microchip,synclko-125 and microchip,synclko-disable "
> > +				 "properties are not supported on this chip. "
> > +				 "Please fix you devicetree.\n");
> 
> s/you/your/
> 
> Does KSZ8 have a REFCLK output of any sort? If it doesn't, then
> "microchip,synclko-disable" is kind of supported, right?
> 
> I wonder what there is to gain by saying that you should remove some
> device tree properties from non-ksz9477. After all, anyone can add any
> random properties to a KSZ8 switch OF node and you won't warn about
> those.

Hm, if we will have any random not support OF property in the switch
node. We won't be able to warn about it anyway. So, if it is present
but not supported, we will just ignore it.

I'll drop this patch.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-05 11:56     ` Oleksij Rempel
@ 2022-08-05 13:42       ` Vladimir Oltean
  2022-08-13 14:32         ` Oleksij Rempel
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-05 13:42 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> Hm, if we will have any random not support OF property in the switch
> node. We won't be able to warn about it anyway. So, if it is present
> but not supported, we will just ignore it.
> 
> I'll drop this patch.

To continue, I think the right way to go about this is to edit the
dt-schema to say that these properties are only applicable to certain
compatible strings, rather than for all. Then due to the
"unevaluatedProperties: false", you'd get the warnings you want, at
validation time.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-05 13:42       ` Vladimir Oltean
@ 2022-08-13 14:32         ` Oleksij Rempel
  2022-08-13 15:11           ` Andrew Lunn
  0 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-08-13 14:32 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Woojung Huh, UNGLinuxDriver, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Fri, Aug 05, 2022 at 04:42:34PM +0300, Vladimir Oltean wrote:
> On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> > Hm, if we will have any random not support OF property in the switch
> > node. We won't be able to warn about it anyway. So, if it is present
> > but not supported, we will just ignore it.
> > 
> > I'll drop this patch.
> 
> To continue, I think the right way to go about this is to edit the
> dt-schema to say that these properties are only applicable to certain
> compatible strings, rather than for all. Then due to the
> "unevaluatedProperties: false", you'd get the warnings you want, at
> validation time.

Hm, with "unevaluatedProperties: false" i have no warnings. Even if I
create examples with random strings as properties. Are there some new
json libraries i should use?

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-13 14:32         ` Oleksij Rempel
@ 2022-08-13 15:11           ` Andrew Lunn
  2022-08-13 16:18             ` Oleksij Rempel
  0 siblings, 1 reply; 25+ messages in thread
From: Andrew Lunn @ 2022-08-13 15:11 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Vladimir Oltean, Woojung Huh, UNGLinuxDriver, Vivien Didelot,
	Florian Fainelli, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, kernel, linux-kernel, netdev

On Sat, Aug 13, 2022 at 04:32:15PM +0200, Oleksij Rempel wrote:
> On Fri, Aug 05, 2022 at 04:42:34PM +0300, Vladimir Oltean wrote:
> > On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> > > Hm, if we will have any random not support OF property in the switch
> > > node. We won't be able to warn about it anyway. So, if it is present
> > > but not supported, we will just ignore it.
> > > 
> > > I'll drop this patch.
> > 
> > To continue, I think the right way to go about this is to edit the
> > dt-schema to say that these properties are only applicable to certain
> > compatible strings, rather than for all. Then due to the
> > "unevaluatedProperties: false", you'd get the warnings you want, at
> > validation time.
> 
> Hm, with "unevaluatedProperties: false" i have no warnings. Even if I
> create examples with random strings as properties. Are there some new
> json libraries i should use?

Try

additionalProperties: False

	Andrew

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-13 15:11           ` Andrew Lunn
@ 2022-08-13 16:18             ` Oleksij Rempel
  2022-08-13 20:42               ` Andrew Lunn
  0 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-08-13 16:18 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Woojung Huh, Florian Fainelli, netdev, linux-kernel,
	Vivien Didelot, UNGLinuxDriver, Eric Dumazet, Paolo Abeni,
	kernel, Jakub Kicinski, Vladimir Oltean, David S. Miller

On Sat, Aug 13, 2022 at 05:11:45PM +0200, Andrew Lunn wrote:
> On Sat, Aug 13, 2022 at 04:32:15PM +0200, Oleksij Rempel wrote:
> > On Fri, Aug 05, 2022 at 04:42:34PM +0300, Vladimir Oltean wrote:
> > > On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> > > > Hm, if we will have any random not support OF property in the switch
> > > > node. We won't be able to warn about it anyway. So, if it is present
> > > > but not supported, we will just ignore it.
> > > > 
> > > > I'll drop this patch.
> > > 
> > > To continue, I think the right way to go about this is to edit the
> > > dt-schema to say that these properties are only applicable to certain
> > > compatible strings, rather than for all. Then due to the
> > > "unevaluatedProperties: false", you'd get the warnings you want, at
> > > validation time.
> > 
> > Hm, with "unevaluatedProperties: false" i have no warnings. Even if I
> > create examples with random strings as properties. Are there some new
> > json libraries i should use?
> 
> Try
> 
> additionalProperties: False

Yes, it works. But in this case I'll do more changes. Just wont to make
sure I do not fix not broken things.

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-13 16:18             ` Oleksij Rempel
@ 2022-08-13 20:42               ` Andrew Lunn
  2022-08-14  4:26                 ` Oleksij Rempel
  0 siblings, 1 reply; 25+ messages in thread
From: Andrew Lunn @ 2022-08-13 20:42 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Woojung Huh, Florian Fainelli, netdev, linux-kernel,
	Vivien Didelot, UNGLinuxDriver, Eric Dumazet, Paolo Abeni,
	kernel, Jakub Kicinski, Vladimir Oltean, David S. Miller

On Sat, Aug 13, 2022 at 06:18:50PM +0200, Oleksij Rempel wrote:
> On Sat, Aug 13, 2022 at 05:11:45PM +0200, Andrew Lunn wrote:
> > On Sat, Aug 13, 2022 at 04:32:15PM +0200, Oleksij Rempel wrote:
> > > On Fri, Aug 05, 2022 at 04:42:34PM +0300, Vladimir Oltean wrote:
> > > > On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> > > > > Hm, if we will have any random not support OF property in the switch
> > > > > node. We won't be able to warn about it anyway. So, if it is present
> > > > > but not supported, we will just ignore it.
> > > > > 
> > > > > I'll drop this patch.
> > > > 
> > > > To continue, I think the right way to go about this is to edit the
> > > > dt-schema to say that these properties are only applicable to certain
> > > > compatible strings, rather than for all. Then due to the
> > > > "unevaluatedProperties: false", you'd get the warnings you want, at
> > > > validation time.
> > > 
> > > Hm, with "unevaluatedProperties: false" i have no warnings. Even if I
> > > create examples with random strings as properties. Are there some new
> > > json libraries i should use?
> > 
> > Try
> > 
> > additionalProperties: False
> 
> Yes, it works. But in this case I'll do more changes. Just wont to make
> sure I do not fix not broken things.

I've been working on converting some old SoCs bindings from .txt to
.yaml. My observations is that the yaml is sometimes more restrictive
than what the drivers actually imposes. So you might need to change
perfectly working .dts files to get it warning free. Or you just
accept the warnings and move on. At lot will depend on the number of
warnings and how easy it is to see real problems mixed in with
warnings you never intend to fix.

       Andrew


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-13 20:42               ` Andrew Lunn
@ 2022-08-14  4:26                 ` Oleksij Rempel
  2022-08-14  8:04                   ` Vladimir Oltean
  0 siblings, 1 reply; 25+ messages in thread
From: Oleksij Rempel @ 2022-08-14  4:26 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Woojung Huh, Florian Fainelli, David S. Miller, netdev,
	linux-kernel, UNGLinuxDriver, Eric Dumazet, Vladimir Oltean,
	kernel, Jakub Kicinski, Paolo Abeni, Vivien Didelot, Rob Herring,
	devicetree

Ccing Rob Herring.

On Sat, Aug 13, 2022 at 10:42:05PM +0200, Andrew Lunn wrote:
> On Sat, Aug 13, 2022 at 06:18:50PM +0200, Oleksij Rempel wrote:
> > On Sat, Aug 13, 2022 at 05:11:45PM +0200, Andrew Lunn wrote:
> > > On Sat, Aug 13, 2022 at 04:32:15PM +0200, Oleksij Rempel wrote:
> > > > On Fri, Aug 05, 2022 at 04:42:34PM +0300, Vladimir Oltean wrote:
> > > > > On Fri, Aug 05, 2022 at 01:56:01PM +0200, Oleksij Rempel wrote:
> > > > > > Hm, if we will have any random not support OF property in the switch
> > > > > > node. We won't be able to warn about it anyway. So, if it is present
> > > > > > but not supported, we will just ignore it.
> > > > > > 
> > > > > > I'll drop this patch.
> > > > > 
> > > > > To continue, I think the right way to go about this is to edit the
> > > > > dt-schema to say that these properties are only applicable to certain
> > > > > compatible strings, rather than for all. Then due to the
> > > > > "unevaluatedProperties: false", you'd get the warnings you want, at
> > > > > validation time.
> > > > 
> > > > Hm, with "unevaluatedProperties: false" i have no warnings. Even if I
> > > > create examples with random strings as properties. Are there some new
> > > > json libraries i should use?
> > > 
> > > Try
> > > 
> > > additionalProperties: False
> > 
> > Yes, it works. But in this case I'll do more changes. Just wont to make
> > sure I do not fix not broken things.
> 
> I've been working on converting some old SoCs bindings from .txt to
> .yaml. My observations is that the yaml is sometimes more restrictive
> than what the drivers actually imposes. So you might need to change
> perfectly working .dts files to get it warning free. Or you just
> accept the warnings and move on. At lot will depend on the number of
> warnings and how easy it is to see real problems mixed in with
> warnings you never intend to fix.

Heh :) Currently with "unevaluatedProperties: false" restrictions do not
work at all. At least for me. For example with this change I have no
warnings:
diff --git a/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml b/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
index 1e26d876d1463..da38ad98a152f 100644
--- a/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
+++ b/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
@@ -120,6 +120,7 @@ examples:
             ethernet-switch@1 {
                     reg = <0x1>;
                     compatible = "nxp,sja1105t";
+                    something-random-here;
 
                     ethernet-ports {
                             #address-cells = <1>;

make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml

So the main question is, is it broken for all or just for me? If it is
just me, what i'm doing wrong?

Regards,
Oleksij
-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips
  2022-08-14  4:26                 ` Oleksij Rempel
@ 2022-08-14  8:04                   ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2022-08-14  8:04 UTC (permalink / raw)
  To: Oleksij Rempel
  Cc: Andrew Lunn, Woojung Huh, Florian Fainelli, David S. Miller,
	netdev, linux-kernel, UNGLinuxDriver, Eric Dumazet, kernel,
	Jakub Kicinski, Paolo Abeni, Vivien Didelot, Rob Herring,
	devicetree

On Sun, Aug 14, 2022 at 06:26:08AM +0200, Oleksij Rempel wrote:
> Heh :) Currently with "unevaluatedProperties: false" restrictions do not
> work at all. At least for me. For example with this change I have no
> warnings:
> diff --git a/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml b/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
> index 1e26d876d1463..da38ad98a152f 100644
> --- a/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
> +++ b/Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
> @@ -120,6 +120,7 @@ examples:
>              ethernet-switch@1 {
>                      reg = <0x1>;
>                      compatible = "nxp,sja1105t";
> +                    something-random-here;
>  
>                      ethernet-ports {
>                              #address-cells = <1>;
> 
> make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/net/dsa/nxp,sja1105.yaml
> 
> So the main question is, is it broken for all or just for me? If it is
> just me, what i'm doing wrong?

Might it be due to the additionalProperties: true from spi-peripheral-props.yaml?

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2022-08-14  8:04 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29 13:03 [PATCH net-next v1 00/10] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
2022-07-29 13:03 ` [PATCH net-next v1 01/10] net: dsa: microchip: don't announce extended register support on non Gbit chips Oleksij Rempel
2022-07-29 13:03 ` [PATCH net-next v1 02/10] net: dsa: microchip: allow to pass return values for PHY read/write accesses Oleksij Rempel
2022-08-02 11:19   ` Vladimir Oltean
2022-07-29 13:03 ` [PATCH net-next v1 03/10] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions Oleksij Rempel
2022-08-02 11:19   ` Vladimir Oltean
2022-07-29 13:03 ` [PATCH net-next v1 04/10] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy Oleksij Rempel
2022-08-02 11:24   ` Vladimir Oltean
2022-07-29 13:03 ` [PATCH net-next v1 05/10] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy Oleksij Rempel
2022-08-02 11:29   ` Vladimir Oltean
2022-07-29 13:03 ` [PATCH net-next v1 06/10] net: dsa: microchip: KSZ9893: do not write to not supported Output Clock Control Register Oleksij Rempel
2022-07-29 13:03 ` [PATCH net-next v1 07/10] net: dsa: microchip: warn about not supported synclko properties on KSZ9893 chips Oleksij Rempel
2022-08-02 11:36   ` Vladimir Oltean
2022-08-05 11:56     ` Oleksij Rempel
2022-08-05 13:42       ` Vladimir Oltean
2022-08-13 14:32         ` Oleksij Rempel
2022-08-13 15:11           ` Andrew Lunn
2022-08-13 16:18             ` Oleksij Rempel
2022-08-13 20:42               ` Andrew Lunn
2022-08-14  4:26                 ` Oleksij Rempel
2022-08-14  8:04                   ` Vladimir Oltean
2022-07-29 13:03 ` [PATCH net-next v1 08/10] net: dsa: microchip: add support for regmap_access_tables Oleksij Rempel
2022-07-29 13:03 ` [PATCH net-next v1 09/10] net: dsa: microchip: add regmap_range for KSZ8563 chip Oleksij Rempel
2022-08-01  5:11   ` Oleksij Rempel
2022-07-29 13:03 ` [PATCH net-next v1 10/10] net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from ksz9477_w_phy() Oleksij Rempel

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).