linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Woojung Huh <woojung.huh@microchip.com>,
	UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
	kernel@pengutronix.de, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH net-next v3 09/17] net: dsa: microchip: add support for regmap_access_tables
Date: Tue, 23 Aug 2022 10:02:23 +0200	[thread overview]
Message-ID: <20220823080231.2466017-10-o.rempel@pengutronix.de> (raw)
In-Reply-To: <20220823080231.2466017-1-o.rempel@pengutronix.de>

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 be0e5d6ef2bf0..769b3ec45a3b5 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -62,6 +62,8 @@ struct ksz_chip_data {
 	bool supports_rgmii[KSZ_MAX_NUM_PORTS];
 	bool internal_phy[KSZ_MAX_NUM_PORTS];
 	bool gbit_capable[KSZ_MAX_NUM_PORTS];
+	const struct regmap_access_table *wr_table;
+	const struct regmap_access_table *rd_table;
 };
 
 struct ksz_port {
@@ -332,6 +334,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;
 }
@@ -341,6 +347,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;
 }
@@ -350,6 +360,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;
 }
@@ -360,7 +374,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;
@@ -368,17 +385,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 746b725b09ec4..44c2d99124066 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


  parent reply	other threads:[~2022-08-23  8:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-23  8:02 [PATCH net-next v3 00/17] net: dsa: microchip: add error handling and register access validation Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 01/17] net: dsa: microchip: add separate struct ksz_chip_data for KSZ8563 chip Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 02/17] net: dsa: microchip: do per-port Gbit detection instead of per-chip Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 03/17] net: dsa: microchip: don't announce extended register support on non Gbit chips Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 04/17] net: dsa: microchip: allow to pass return values for PHY read/write accesses Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 05/17] net: dsa: microchip: forward error value on all ksz_pread/ksz_pwrite functions Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 06/17] net: dsa: microchip: ksz9477: add error handling to ksz9477_r/w_phy Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 07/17] net: dsa: microchip: ksz8795: add error handling to ksz8_r/w_phy Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 08/17] net: dsa: microchip: KSZ9893: do not write to not supported Output Clock Control Register Oleksij Rempel
2022-08-23  8:02 ` Oleksij Rempel [this message]
2022-08-23  8:02 ` [PATCH net-next v3 10/17] net: dsa: microchip: add regmap_range for KSZ8563 chip Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 11/17] net: dsa: microchip: ksz9477: remove MII_CTRL1000 check from ksz9477_w_phy() Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 12/17] net: dsa: microchip: add regmap_range for KSZ9477 chip Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 13/17] net: dsa: microchip: ksz9477: use internal_phy instead of phy_port_cnt Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 14/17] net: dsa: microchip: remove unused port phy variable Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 15/17] net: dsa: microchip: ksz9477: remove unused "on" variable Oleksij Rempel
2022-08-25 20:54   ` Vladimir Oltean
2022-08-26  7:51     ` Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 16/17] net: dsa: microchip: remove unused sgmii variable Oleksij Rempel
2022-08-23  8:02 ` [PATCH net-next v3 17/17] net: dsa: microchip: remove IS_9893 flag Oleksij Rempel
2022-08-25  9:00 ` [PATCH net-next v3 00/17] net: dsa: microchip: add error handling and register access validation Paolo Abeni
2022-08-25 21:44   ` Vladimir Oltean
2022-08-25 22:57     ` Jakub Kicinski

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=20220823080231.2466017-10-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.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).