All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing
@ 2023-12-05 16:42 Daniel Danzberger
  2023-12-05 16:42 ` [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include Daniel Danzberger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Daniel Danzberger @ 2023-12-05 16:42 UTC (permalink / raw)
  To: woojung.huh, UNGLinuxDriver
  Cc: andrew, f.fainelli, olteanv, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, Vladimir Oltean, Daniel Danzberger

From: Vladimir Oltean <vladimir.oltean@nxp.com>

The ksz driver has bits and pieces of platform_data probing support, but
it doesn't work.

The conventional thing to do is to have an encapsulating structure for
struct dsa_chip_data that gets put into dev->platform_data. This driver
expects a struct ksz_platform_data, but that doesn't contain a struct
dsa_chip_data as first element, which will obviously not work with
dsa_switch_probe() -> dsa_switch_parse().

Pointing dev->platform_data to a struct dsa_chip_data directly is in
principle possible, but that doesn't work either. The driver has
ksz_switch_detect() to read the device ID from hardware, followed by
ksz_check_device_id() to compare it against a predetermined expected
value. This protects against early errors in the SPI/I2C communication.
With platform_data, the mechanism in ksz_check_device_id() doesn't work
and even leads to NULL pointer dereferences, since of_device_get_match_data()
doesn't work in that probe path.

So obviously, the platform_data support is actually missing, and the
existing handling of struct ksz_platform_data is bogus. Complete the
support by adding a struct dsa_chip_data as first element, and fixing up
ksz_check_device_id() to pick up the platform_data instead of the
unavailable of_device_get_match_data().

The early dev->chip_id assignment from ksz_switch_register() is also
bogus, because ksz_switch_detect() sets it to an initial value. So
remove it.

Also, ksz_platform_data :: enabled_ports isn't used anywhere, delete it.

Link: https://lore.kernel.org/netdev/20231204154315.3906267-1-dd@embedd.com/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Daniel Danzberger <dd@embedd.com>
---
 drivers/net/dsa/microchip/ksz_common.c      | 21 +++++++++++++--------
 include/linux/platform_data/microchip-ksz.h |  4 +++-
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 9545aed905f5..db1bbcf3a5f2 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -1673,15 +1673,23 @@ static const struct ksz_chip_data *ksz_lookup_info(unsigned int prod_num)
 
 static int ksz_check_device_id(struct ksz_device *dev)
 {
-	const struct ksz_chip_data *dt_chip_data;
+	const struct ksz_chip_data *expected_chip_data;
+	u32 expected_chip_id;
 
-	dt_chip_data = of_device_get_match_data(dev->dev);
+	if (dev->pdata) {
+		expected_chip_id = dev->pdata->chip_id;
+		expected_chip_data = ksz_lookup_info(expected_chip_id);
+		if (WARN_ON(!expected_chip_data))
+			return -ENODEV;
+	} else {
+		expected_chip_data = of_device_get_match_data(dev->dev);
+		expected_chip_id = expected_chip_data->chip_id;
+	}
 
-	/* Check for Device Tree and Chip ID */
-	if (dt_chip_data->chip_id != dev->chip_id) {
+	if (expected_chip_id != dev->chip_id) {
 		dev_err(dev->dev,
 			"Device tree specifies chip %s but found %s, please fix it!\n",
-			dt_chip_data->dev_name, dev->info->dev_name);
+			expected_chip_data->dev_name, dev->info->dev_name);
 		return -ENODEV;
 	}
 
@@ -4156,9 +4164,6 @@ int ksz_switch_register(struct ksz_device *dev)
 	int ret;
 	int i;
 
-	if (dev->pdata)
-		dev->chip_id = dev->pdata->chip_id;
-
 	dev->reset_gpio = devm_gpiod_get_optional(dev->dev, "reset",
 						  GPIOD_OUT_LOW);
 	if (IS_ERR(dev->reset_gpio))
diff --git a/include/linux/platform_data/microchip-ksz.h b/include/linux/platform_data/microchip-ksz.h
index ea1cc6d829e9..6480bf4af0fb 100644
--- a/include/linux/platform_data/microchip-ksz.h
+++ b/include/linux/platform_data/microchip-ksz.h
@@ -20,10 +20,12 @@
 #define __MICROCHIP_KSZ_H
 
 #include <linux/types.h>
+#include <linux/platform_data/dsa.h>
 
 struct ksz_platform_data {
+	/* Must be first such that dsa_register_switch() can access it */
+	struct dsa_chip_data cd;
 	u32 chip_id;
-	u16 enabled_ports;
 };
 
 #endif
-- 
2.39.2


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

* [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include
  2023-12-05 16:42 [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Daniel Danzberger
@ 2023-12-05 16:42 ` Daniel Danzberger
  2023-12-06 15:42   ` Andrew Lunn
  2023-12-06 15:42 ` [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Andrew Lunn
  2023-12-07 12:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Daniel Danzberger @ 2023-12-05 16:42 UTC (permalink / raw)
  To: woojung.huh, UNGLinuxDriver
  Cc: andrew, f.fainelli, olteanv, davem, edumazet, kuba, pabeni,
	netdev, linux-kernel, Daniel Danzberger

With the ksz_chip_id enums moved to the platform include file for ksz
switches, platform code that instantiates a device can now use these to
set ksz_platform_data::chip_id.

Signed-off-by: Daniel Danzberger <dd@embedd.com>
---
 drivers/net/dsa/microchip/ksz_common.h      | 20 +-------------------
 include/linux/platform_data/microchip-ksz.h | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index d1a1c876ba0d..15612101a155 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -14,6 +14,7 @@
 #include <linux/regmap.h>
 #include <net/dsa.h>
 #include <linux/irq.h>
+#include <linux/platform_data/microchip-ksz.h>
 
 #include "ksz_ptp.h"
 
@@ -203,25 +204,6 @@ enum ksz_model {
 	LAN9374,
 };
 
-enum ksz_chip_id {
-	KSZ8563_CHIP_ID = 0x8563,
-	KSZ8795_CHIP_ID = 0x8795,
-	KSZ8794_CHIP_ID = 0x8794,
-	KSZ8765_CHIP_ID = 0x8765,
-	KSZ8830_CHIP_ID = 0x8830,
-	KSZ9477_CHIP_ID = 0x00947700,
-	KSZ9896_CHIP_ID = 0x00989600,
-	KSZ9897_CHIP_ID = 0x00989700,
-	KSZ9893_CHIP_ID = 0x00989300,
-	KSZ9563_CHIP_ID = 0x00956300,
-	KSZ9567_CHIP_ID = 0x00956700,
-	LAN9370_CHIP_ID = 0x00937000,
-	LAN9371_CHIP_ID = 0x00937100,
-	LAN9372_CHIP_ID = 0x00937200,
-	LAN9373_CHIP_ID = 0x00937300,
-	LAN9374_CHIP_ID = 0x00937400,
-};
-
 enum ksz_regs {
 	REG_SW_MAC_ADDR,
 	REG_IND_CTRL_0,
diff --git a/include/linux/platform_data/microchip-ksz.h b/include/linux/platform_data/microchip-ksz.h
index 6480bf4af0fb..f177416635a2 100644
--- a/include/linux/platform_data/microchip-ksz.h
+++ b/include/linux/platform_data/microchip-ksz.h
@@ -22,6 +22,25 @@
 #include <linux/types.h>
 #include <linux/platform_data/dsa.h>
 
+enum ksz_chip_id {
+	KSZ8563_CHIP_ID = 0x8563,
+	KSZ8795_CHIP_ID = 0x8795,
+	KSZ8794_CHIP_ID = 0x8794,
+	KSZ8765_CHIP_ID = 0x8765,
+	KSZ8830_CHIP_ID = 0x8830,
+	KSZ9477_CHIP_ID = 0x00947700,
+	KSZ9896_CHIP_ID = 0x00989600,
+	KSZ9897_CHIP_ID = 0x00989700,
+	KSZ9893_CHIP_ID = 0x00989300,
+	KSZ9563_CHIP_ID = 0x00956300,
+	KSZ9567_CHIP_ID = 0x00956700,
+	LAN9370_CHIP_ID = 0x00937000,
+	LAN9371_CHIP_ID = 0x00937100,
+	LAN9372_CHIP_ID = 0x00937200,
+	LAN9373_CHIP_ID = 0x00937300,
+	LAN9374_CHIP_ID = 0x00937400,
+};
+
 struct ksz_platform_data {
 	/* Must be first such that dsa_register_switch() can access it */
 	struct dsa_chip_data cd;
-- 
2.39.2


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

* Re: [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include
  2023-12-05 16:42 ` [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include Daniel Danzberger
@ 2023-12-06 15:42   ` Andrew Lunn
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2023-12-06 15:42 UTC (permalink / raw)
  To: Daniel Danzberger
  Cc: woojung.huh, UNGLinuxDriver, f.fainelli, olteanv, davem,
	edumazet, kuba, pabeni, netdev, linux-kernel

On Tue, Dec 05, 2023 at 05:42:31PM +0100, Daniel Danzberger wrote:
> With the ksz_chip_id enums moved to the platform include file for ksz
> switches, platform code that instantiates a device can now use these to
> set ksz_platform_data::chip_id.
> 
> Signed-off-by: Daniel Danzberger <dd@embedd.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing
  2023-12-05 16:42 [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Daniel Danzberger
  2023-12-05 16:42 ` [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include Daniel Danzberger
@ 2023-12-06 15:42 ` Andrew Lunn
  2023-12-07 12:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2023-12-06 15:42 UTC (permalink / raw)
  To: Daniel Danzberger
  Cc: woojung.huh, UNGLinuxDriver, f.fainelli, olteanv, davem,
	edumazet, kuba, pabeni, netdev, linux-kernel, Vladimir Oltean

On Tue, Dec 05, 2023 at 05:42:30PM +0100, Daniel Danzberger wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> 
> The ksz driver has bits and pieces of platform_data probing support, but
> it doesn't work.
> 
> The conventional thing to do is to have an encapsulating structure for
> struct dsa_chip_data that gets put into dev->platform_data. This driver
> expects a struct ksz_platform_data, but that doesn't contain a struct
> dsa_chip_data as first element, which will obviously not work with
> dsa_switch_probe() -> dsa_switch_parse().
> 
> Pointing dev->platform_data to a struct dsa_chip_data directly is in
> principle possible, but that doesn't work either. The driver has
> ksz_switch_detect() to read the device ID from hardware, followed by
> ksz_check_device_id() to compare it against a predetermined expected
> value. This protects against early errors in the SPI/I2C communication.
> With platform_data, the mechanism in ksz_check_device_id() doesn't work
> and even leads to NULL pointer dereferences, since of_device_get_match_data()
> doesn't work in that probe path.
> 
> So obviously, the platform_data support is actually missing, and the
> existing handling of struct ksz_platform_data is bogus. Complete the
> support by adding a struct dsa_chip_data as first element, and fixing up
> ksz_check_device_id() to pick up the platform_data instead of the
> unavailable of_device_get_match_data().
> 
> The early dev->chip_id assignment from ksz_switch_register() is also
> bogus, because ksz_switch_detect() sets it to an initial value. So
> remove it.
> 
> Also, ksz_platform_data :: enabled_ports isn't used anywhere, delete it.
> 
> Link: https://lore.kernel.org/netdev/20231204154315.3906267-1-dd@embedd.com/
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Signed-off-by: Daniel Danzberger <dd@embedd.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing
  2023-12-05 16:42 [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Daniel Danzberger
  2023-12-05 16:42 ` [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include Daniel Danzberger
  2023-12-06 15:42 ` [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Andrew Lunn
@ 2023-12-07 12:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-07 12:10 UTC (permalink / raw)
  To: Daniel Danzberger
  Cc: woojung.huh, UNGLinuxDriver, andrew, f.fainelli, olteanv, davem,
	edumazet, kuba, pabeni, netdev, linux-kernel, vladimir.oltean

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue,  5 Dec 2023 17:42:30 +0100 you wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> 
> The ksz driver has bits and pieces of platform_data probing support, but
> it doesn't work.
> 
> The conventional thing to do is to have an encapsulating structure for
> struct dsa_chip_data that gets put into dev->platform_data. This driver
> expects a struct ksz_platform_data, but that doesn't contain a struct
> dsa_chip_data as first element, which will obviously not work with
> dsa_switch_probe() -> dsa_switch_parse().
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] net: dsa: microchip: properly support platform_data probing
    https://git.kernel.org/netdev/net-next/c/3bc05faf3787
  - [net-next,2/2] net: dsa: microchip: move ksz_chip_id enum to platform include
    https://git.kernel.org/netdev/net-next/c/d16f1096b320

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-12-07 12:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05 16:42 [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Daniel Danzberger
2023-12-05 16:42 ` [PATCH net-next 2/2] net: dsa: microchip: move ksz_chip_id enum to platform include Daniel Danzberger
2023-12-06 15:42   ` Andrew Lunn
2023-12-06 15:42 ` [PATCH net-next 1/2] net: dsa: microchip: properly support platform_data probing Andrew Lunn
2023-12-07 12:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.