net: dsa: realtek: variants to drivers, interfaces to a common module
Subsystems (6)
Luiz Angelo Daros de Luca
maintainerv3 cover net: dsa: realtek: variants to drivers, interfaces to a common module
The current driver consists of two interface modules (SMI and MDIO) and two family/variant modules (RTL8365MB and RTL8366RB). The SMI and MDIO modules serve as the platform and MDIO drivers, respectively, calling functions from the variant modules. In this setup, one interface module can be loaded independently of the other, but both variants must be loaded (if not disabled at build time) for any type of interface. This approach doesn't scale well, especially with the addition of more switch variants (e.g., RTL8366B), leading to loaded but unused modules. Additionally, this also seems upside down, as the specific driver code normally depends on the more generic functions and not the other way around.
The series begins by removing an unused function pointer at realtek_ops->cleanup.
Each variant module was converted into real drivers, serving as both a platform driver (for switches connected using the SMI interface) and an MDIO driver (for MDIO-connected switches). The relationship between the variant and interface modules is reversed, with the variant module now calling both interface functions (if not disabled at build time). While in most devices only one interface is likely used, the interface code is significantly smaller than a variant module, consuming fewer resources than the previous code. With variant modules now functioning as real drivers, compatible strings are published only in a single variant module, preventing conflicts.
The patch series introduces a new common module for functions shared by both variants. This module also absorbs the two previous interface modules, as they would always be loaded anyway.
The series relocates the user MII driver from realtek-smi to common. It is now used by MDIO-connected switches instead of the generic DSA driver. There's a change in how this driver locates the MDIO node. It now only searches for a child node named "mdio", which is required by both interfaces in binding docs.
The dsa_switch in realtek_priv->ds is now embedded in the struct. It is always in use and avoids dynamic memory allocation.
Testing has been performed with an RTL8367S (rtl8365mb) using MDIO interface and an RTL8366RB (rtl8366) with SMI interface.
Luiz
---
Changes:
v2-v3:
1) Look for the MDIO bus searching for a child node named "mdio" instead of the compatible string.
2) Removed the check for a phy-handle in ports. ds->user_mii_bus will not be used anymore.
3) Dropped comments for realtek_common_{probe,register_switch}
4) Fixed a compile error in "net: dsa: OF-ware slave_mii_bus"
5) Used the wrapper realtek_smi_driver_register instead of platform_driver_register
v1-v2:
1) Renamed realtek_common module to realtek-dsa. 2) Removed the warning when the MDIO node is not named "mdio." 3) ds->user_mii_bus is only assigned if all user ports do not have a
phy-handle.
4) of_node_put is now back to the driver remove method.
5) Renamed realtek_common_probe_{pre,post} to realtek_common_{probe,register_switch}.
6) Added some comments for realtek_common_{probe,register_switch}.
7) Using dev_err_probe whenever possible.
8) Embedded priv->ds into realtek_priv, removing its dynamic allocation.
9) Fixed realtek-common.h macros.
10) Save and check the return value in functions, even when it is the last one.
11) Added the #if expression as a comment to #else and #endif in header files.
12) Unregister the platform and the MDIO driver in the reverse order they are registered.
13) Unregister the first driver if the second one failed to register.
14) Added the revert patch for "net: dsa: OF-ware slave_mii_bus."
Luiz Angelo Daros de Luca
maintainerPATCH v3 1/8 net: dsa: realtek: drop cleanup from realtek_ops
It was never used and never referenced.
--- drivers/net/dsa/realtek/realtek.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/dsa/realtek/realtek.h +0 -1
@@ -91,7 +91,6 @@ struct realtek_ops {int (*detect)(struct realtek_priv *priv);int (*reset_chip)(struct realtek_priv *priv);int (*setup)(struct realtek_priv *priv); -void (*cleanup)(struct realtek_priv *priv); int (*get_mib_counter)(struct realtek_priv *priv, int port, struct rtl8366_mib_counter *mib,
Signature · 1 line
2.43.0
Re: [PATCH net-next v3 1/8] net: dsa: realtek: drop cleanup from realtek_ops
Quoted 4 lines · Luiz Angelo Daros de Luca
It was never used and never referenced.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>Reviewed-by Alvin Šipraga <[email protected]>
Signature · 1 line
Florian
Re: [PATCH net-next v3 1/8] net: dsa: realtek: drop cleanup from realtek_ops
In reply to Luiz Angelo Daros de LucaQuoted 4 lines · Luiz Angelo Daros de Luca
It was never used and never referenced.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>Reviewed-by Alvin Šipraga <[email protected]>
Yours,
Linus Walleij
Luiz Angelo Daros de Luca
maintainerPATCH v3 2/8 net: dsa: realtek: convert variants into real drivers
In reply to Luiz Angelo Daros de LucaPreviously, the interface modules realtek-smi and realtek-mdio served as a platform and an MDIO driver, respectively. Each interface module redundantly specified the same compatible strings for both variants and referenced symbols from the variants.
Now, each variant module has been transformed into a unified driver serving both as a platform and an MDIO driver. This modification reverses the relationship between the interface and variant modules, with the variant module now utilizing symbols from the interface modules.
--- drivers/net/dsa/realtek/Kconfig | 20 +++------- drivers/net/dsa/realtek/realtek-mdio.c | 33 ++++------------ drivers/net/dsa/realtek/realtek-mdio.h | 48 +++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 38 ++++-------------- drivers/net/dsa/realtek/realtek-smi.h | 48 +++++++++++++++++++++++ drivers/net/dsa/realtek/rtl8365mb.c | 54 +++++++++++++++++++++++++- drivers/net/dsa/realtek/rtl8366rb.c | 54 +++++++++++++++++++++++++- 7 files changed, 222 insertions(+), 73 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-mdio.h create mode 100644 drivers/net/dsa/realtek/realtek-smi.h
drivers/net/dsa/realtek/Kconfig +6 -14
@@ -16,37 +16,29 @@ menuconfig NET_DSA_REALTEK if NET_DSA_REALTEK config NET_DSA_REALTEK_MDIO - tristate "Realtek MDIO interface driver" + tristate "Realtek MDIO interface support" depends on OF - depends on NET_DSA_REALTEK_RTL8365MB || NET_DSA_REALTEK_RTL8366RB - depends on NET_DSA_REALTEK_RTL8365MB || !NET_DSA_REALTEK_RTL8365MB - depends on NET_DSA_REALTEK_RTL8366RB || !NET_DSA_REALTEK_RTL8366RB help Select to enable support for registering switches configured through MDIO. config NET_DSA_REALTEK_SMI - tristate "Realtek SMI interface driver" + tristate "Realtek SMI interface support" depends on OF - depends on NET_DSA_REALTEK_RTL8365MB || NET_DSA_REALTEK_RTL8366RB - depends on NET_DSA_REALTEK_RTL8365MB || !NET_DSA_REALTEK_RTL8365MB - depends on NET_DSA_REALTEK_RTL8366RB || !NET_DSA_REALTEK_RTL8366RB help Select to enable support for registering switches connected through SMI. config NET_DSA_REALTEK_RTL8365MB - tristate "Realtek RTL8365MB switch subdriver" - imply NET_DSA_REALTEK_SMI - imply NET_DSA_REALTEK_MDIO + tristate "Realtek RTL8365MB switch driver" + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL8_4 help Select to enable support for Realtek RTL8365MB-VC and RTL8367S. config NET_DSA_REALTEK_RTL8366RB - tristate "Realtek RTL8366RB switch subdriver" - imply NET_DSA_REALTEK_SMI - imply NET_DSA_REALTEK_MDIO + tristate "Realtek RTL8366RB switch driver" + depends on NET_DSA_REALTEK_SMI || NET_DSA_REALTEK_MDIO select NET_DSA_TAG_RTL4_A help Select to enable support for Realtek RTL8366RB.
drivers/net/dsa/realtek/realtek-mdio.c +7 -26
@@ -25,6 +25,7 @@#include <linux/regmap.h> #include "realtek.h" +#include "realtek-mdio.h" /* Read/write via mdiobus */ #define REALTEK_MDIO_CTRL0_REG 31
@@ -140,7 +141,7 @@ static const struct regmap_config realtek_mdio_nolock_regmap_config = { .disable_locking = true, }; -static int realtek_mdio_probe (struct mdio_device *mdiodev) +int realtek_mdio_probe (struct mdio_device *mdiodev) {struct realtek_priv *priv;struct device *dev = &mdiodev->dev;
@@ -235,8 +236,9 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev)return 0 ; } +EXPORT_SYMBOL_GPL (realtek_mdio_probe); -static void realtek_mdio_remove (struct mdio_device *mdiodev) +void realtek_mdio_remove (struct mdio_device *mdiodev) {struct realtek_priv *priv =dev_get_drvdata (&mdiodev->dev);
@@ -249,8 +251,9 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev)if (priv->reset)gpiod_set_value (priv->reset,1 ); } +EXPORT_SYMBOL_GPL (realtek_mdio_remove); -static void realtek_mdio_shutdown (struct mdio_device *mdiodev) +void realtek_mdio_shutdown (struct mdio_device *mdiodev) {struct realtek_priv *priv =dev_get_drvdata (&mdiodev->dev);
@@ -261,29 +264,7 @@ static void realtek_mdio_shutdown(struct mdio_device *mdiodev)dev_set_drvdata (&mdiodev->dev,NULL ); } - -static const struct of_device_id realtek_mdio_of_match[] = { -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB) - { .compatible ="realtek,rtl8366rb" , .data = &rtl8366rb_variant, }, -#endif -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) - { .compatible ="realtek,rtl8365mb" , .data = &rtl8365mb_variant, }, -#endif - {/* sentinel */ }, -}; -MODULE_DEVICE_TABLE (of, realtek_mdio_of_match); - -static struct mdio_driver realtek_mdio_driver = { - .mdiodrv.driver = { - .name ="realtek-mdio" , - .of_match_table = realtek_mdio_of_match, - }, - .probe = realtek_mdio_probe, - .remove = realtek_mdio_remove, - .shutdown = realtek_mdio_shutdown, -}; - -mdio_module_driver (realtek_mdio_driver); +EXPORT_SYMBOL_GPL (realtek_mdio_shutdown);MODULE_AUTHOR ("Luiz Angelo Daros de Luca <[email protected]>" );MODULE_DESCRIPTION ("Driver for Realtek ethernet switch connected via MDIO interface" );
drivers/net/dsa/realtek/realtek-mdio.h new file +48 -0
48 lines not on this page · raw message
drivers/net/dsa/realtek/realtek-smi.c +7 -31
@@ -40,6 +40,7 @@#include <linux/if_bridge.h> #include "realtek.h" +#include "realtek-smi.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5
@@ -408,7 +409,7 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds)return ret; } -static int realtek_smi_probe (struct platform_device *pdev) +int realtek_smi_probe (struct platform_device *pdev) {const struct realtek_variant *var;struct device *dev = &pdev->dev;
@@ -505,8 +506,9 @@ static int realtek_smi_probe(struct platform_device *pdev) }return 0 ; } +EXPORT_SYMBOL_GPL (realtek_smi_probe); -static void realtek_smi_remove (struct platform_device *pdev) +void realtek_smi_remove (struct platform_device *pdev) {struct realtek_priv *priv =platform_get_drvdata (pdev);
@@ -521,8 +523,9 @@ static void realtek_smi_remove(struct platform_device *pdev)if (priv->reset)gpiod_set_value (priv->reset,1 ); } +EXPORT_SYMBOL_GPL (realtek_smi_remove); -static void realtek_smi_shutdown (struct platform_device *pdev) +void realtek_smi_shutdown (struct platform_device *pdev) {struct realtek_priv *priv =platform_get_drvdata (pdev);
@@ -533,34 +536,7 @@ static void realtek_smi_shutdown(struct platform_device *pdev)platform_set_drvdata (pdev,NULL ); } - -static const struct of_device_id realtek_smi_of_match[] = { -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB) - { - .compatible ="realtek,rtl8366rb" , - .data = &rtl8366rb_variant, - }, -#endif -#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8365MB) - { - .compatible ="realtek,rtl8365mb" , - .data = &rtl8365mb_variant, - }, -#endif - {/* sentinel */ }, -}; -MODULE_DEVICE_TABLE (of, realtek_smi_of_match); - -static struct platform_driver realtek_smi_driver = { - .driver = { - .name ="realtek-smi" , - .of_match_table = realtek_smi_of_match, - }, - .probe = realtek_smi_probe, - .remove_new = realtek_smi_remove, - .shutdown = realtek_smi_shutdown, -}; -module_platform_driver (realtek_smi_driver); +EXPORT_SYMBOL_GPL (realtek_smi_shutdown);MODULE_AUTHOR ("Linus Walleij <[email protected]>" );MODULE_DESCRIPTION ("Driver for Realtek ethernet switch connected via SMI interface" );
drivers/net/dsa/realtek/realtek-smi.h new file +48 -0
48 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8365mb.c +53 -1
66 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8366rb.c +53 -1
66 lines not on this page · raw message
Signature · 1 line
2.43.0
Luiz Angelo Daros de Luca
maintainerPATCH v3 3/8 net: dsa: realtek: common realtek-dsa module
In reply to Luiz Angelo Daros de LucaSome code can be shared between both interface modules (MDIO and SMI) and among variants. These interface functions migrated to a common module:
- realtek_common_lock
- realtek_common_unlock
- realtek_common_probe
- realtek_common_register_switch
- realtek_common_remove
The reset during probe was moved to the end of the common probe. This way, we avoid a reset if anything else fails.
--- drivers/net/dsa/realtek/Makefile | 2 + drivers/net/dsa/realtek/realtek-common.c | 132 +++++++++++++++++++++++ drivers/net/dsa/realtek/realtek-common.h | 16 +++ drivers/net/dsa/realtek/realtek-mdio.c | 114 +++----------------- drivers/net/dsa/realtek/realtek-smi.c | 117 ++++---------------- drivers/net/dsa/realtek/realtek.h | 6 +- drivers/net/dsa/realtek/rtl8365mb.c | 9 +- drivers/net/dsa/realtek/rtl8366rb.c | 9 +- 8 files changed, 194 insertions(+), 211 deletions(-) create mode 100644 drivers/net/dsa/realtek/realtek-common.c create mode 100644 drivers/net/dsa/realtek/realtek-common.h
drivers/net/dsa/realtek/Makefile +2 -0
@@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o +realtek-dsa-objs := realtek-common.o obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o
drivers/net/dsa/realtek/realtek-common.c new file +132 -0
132 lines not on this page · raw message
drivers/net/dsa/realtek/realtek-common.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _REALTEK_COMMON_H +#define _REALTEK_COMMON_H + +#include <linux/regmap.h> + +void realtek_common_lock (void *ctx); +void realtek_common_unlock (void *ctx); +struct realtek_priv * +realtek_common_probe (struct device *dev,struct regmap_config rc, +struct regmap_config rc_nolock); +int realtek_common_register_switch (struct realtek_priv *priv); +void realtek_common_remove (struct realtek_priv *priv); + +#endif /* _REALTEK_COMMON_H */
drivers/net/dsa/realtek/realtek-mdio.c +13 -101
152 lines not on this page · raw message
drivers/net/dsa/realtek/realtek-smi.c +18 -99
183 lines not on this page · raw message
drivers/net/dsa/realtek/realtek.h +3 -3
@@ -58,11 +58,9 @@ struct realtek_priv {struct mii_bus *bus;int mdio_addr; -unsigned int clk_delay; -u8 cmd_read; -u8 cmd_write;spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; +const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;
@@ -79,6 +77,8 @@ struct realtek_priv {int vlan_enabled;int vlan4k_enabled; +const struct realtek_variant *variant; +char buf[4096 ];void *chip_data;/* Per-chip extra variant data */ };
drivers/net/dsa/realtek/rtl8365mb.c +5 -4
@@ -103,6 +103,7 @@#include "realtek.h" #include "realtek-smi.h" #include "realtek-mdio.h" +#include "realtek-common.h" /* Family-specific data and limits */ #define RTL8365MB_PHYADDRMAX 7
@@ -691,7 +692,7 @@ static int rtl8365mb_phy_ocp_read(struct realtek_priv *priv, int phy,u32 val;int ret; -mutex_lock (&priv->map_lock); +realtek_common_lock (priv); ret =rtl8365mb_phy_poll_busy (priv);if (ret)
@@ -724,7 +725,7 @@ static int rtl8365mb_phy_ocp_read(struct realtek_priv *priv, int phy, *data = val &0xFFFF ; out: -mutex_unlock (&priv->map_lock); +realtek_common_unlock (priv);return ret; }
@@ -735,7 +736,7 @@ static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy,u32 val;int ret; -mutex_lock (&priv->map_lock); +realtek_common_lock (priv); ret =rtl8365mb_phy_poll_busy (priv);if (ret)
@@ -766,7 +767,7 @@ static int rtl8365mb_phy_ocp_write(struct realtek_priv *priv, int phy, goto out; out: -mutex_unlock (&priv->map_lock); +realtek_common_unlock (priv);return 0 ; }
drivers/net/dsa/realtek/rtl8366rb.c +5 -4
@@ -24,6 +24,7 @@#include "realtek.h" #include "realtek-smi.h" #include "realtek-mdio.h" +#include "realtek-common.h" #define RTL8366RB_PORT_NUM_CPU 5#define RTL8366RB_NUM_PORTS 6
@@ -1707,7 +1708,7 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)if (phy >RTL8366RB_PHY_NO_MAX )return -EINVAL ; -mutex_lock (&priv->map_lock); +realtek_common_lock (priv); ret =regmap_write (priv->map_nolock,RTL8366RB_PHY_ACCESS_CTRL_REG ,RTL8366RB_PHY_CTRL_READ );
@@ -1735,7 +1736,7 @@ static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum) phy, regnum, reg, val); out: -mutex_unlock (&priv->map_lock); +realtek_common_unlock (priv);return ret; }
@@ -1749,7 +1750,7 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,if (phy >RTL8366RB_PHY_NO_MAX )return -EINVAL ; -mutex_lock (&priv->map_lock); +realtek_common_lock (priv); ret =regmap_write (priv->map_nolock,RTL8366RB_PHY_ACCESS_CTRL_REG ,RTL8366RB_PHY_CTRL_WRITE );
@@ -1766,7 +1767,7 @@ static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum, goto out; out: -mutex_unlock (&priv->map_lock); +realtek_common_unlock (priv);return ret; }
Signature · 1 line
2.43.0
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 25 lines · Luiz Angelo Daros de Luca
Some code can be shared between both interface modules (MDIO and SMI) and among variants. These interface functions migrated to a common module:
-
realtek_common_lock
-realtek_common_unlock
-realtek_common_probe
-realtek_common_register_switch
-realtek_common_removeThe reset during probe was moved to the end of the common probe. This way, we avoid a reset if anything else fails.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>---
drivers/net/dsa/realtek/realtek-common.c new file +4
-0@@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <linux/module.h> +
drivers/net/dsa/realtek/realtek-common.c line 14
Quoted 10 lines
drivers/net/dsa/realtek/realtek-common.c new file +10
-0+#include "realtek.h" +#include "realtek-common.h" + +void realtek_common_lock (void *ctx) +{ +struct realtek_priv *priv = ctx; + +mutex_lock (&priv->map_lock); +} +EXPORT_SYMBOL_GPL (realtek_common_lock);
Would you mind adding some kernel-doc comments above each of these exported functions? https://docs.kernel.org/doc-guide/kernel-doc.html
says "Every function that is exported to loadable modules using EXPORT_SYMBOL or EXPORT_SYMBOL_GPL should have a kernel-doc comment. Functions and data structures in header files which are intended to be used by modules should also have kernel-doc comments."
It is something I only recently started paying attention to, so we don't have consistency in this regard. But we should try to adhere to this practice for code we change.
drivers/net/dsa/realtek/realtek-common.c line 26
Quoted 12 lines
drivers/net/dsa/realtek/realtek-common.c new file +12
-0+ +void realtek_common_unlock (void *ctx) +{ +struct realtek_priv *priv = ctx; + +mutex_unlock (&priv->map_lock); +} +EXPORT_SYMBOL_GPL (realtek_common_unlock); + +struct realtek_priv * +realtek_common_probe (struct device *dev,struct regmap_config rc, +struct regmap_config rc_nolock)
Could you use "const struct regmap_config *" as the data types here, to avoid two on-stack variable copies? Regmap will copy the config structures anyway.
Quoted 80 lines
drivers/net/dsa/realtek/realtek-common.c new file +62
-0+{ +const struct realtek_variant *var; +struct realtek_priv *priv; +int ret; + + var =of_device_get_match_data (dev); +if (!var) +return ERR_PTR (-EINVAL ); + + priv =devm_kzalloc (dev,size_add (sizeof (*priv), var->chip_data_sz), +GFP_KERNEL ); +if (!priv) +return ERR_PTR (-ENOMEM ); + +mutex_init (&priv->map_lock); + + rc.lock_arg = priv; + priv->map =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map)) { + ret =PTR_ERR (priv->map); +dev_err (dev,"regmap init failed: %d\n" , ret); +return ERR_PTR (ret); + } + + priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc_nolock); +if (IS_ERR (priv->map_nolock)) { + ret =PTR_ERR (priv->map_nolock); +dev_err (dev,"regmap init failed: %d\n" , ret); +return ERR_PTR (ret); + } + +/* Link forward and backward */ + priv->dev = dev; + priv->variant = var; + priv->ops = var->ops; + priv->chip_data = (void *)priv +sizeof (*priv); + +dev_set_drvdata (dev, priv); +spin_lock_init (&priv->lock); + + priv->leds_disabled =of_property_read_bool (dev->of_node, +"realtek,disable-leds" ); + +/* TODO: if power is software controlled, set up any regulators here */ + + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->reset)) { +dev_err (dev,"failed to get RESET GPIO\n" ); +return ERR_CAST (priv->reset); + } +if (priv->reset) { +gpiod_set_value (priv->reset,1 ); +dev_dbg (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_dbg (dev,"deasserted RESET\n" ); + } + +return priv; +} +EXPORT_SYMBOL (realtek_common_probe);drivers/net/dsa/realtek/realtek.h +1
-3@@ -58,11 +58,9 @@ struct realtek_priv {struct mii_bus *bus;int mdio_addr; -unsigned int clk_delay; -u8 cmd_read; -u8 cmd_write;spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; +const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;
drivers/net/dsa/realtek/realtek.h struct realtek_priv { · line 84
Quoted 8 lines
drivers/net/dsa/realtek/realtek.h +2
-0@@ -79,6 +77,8 @@ struct realtek_priv {int vlan_enabled;int vlan4k_enabled; +const struct realtek_variant *variant; +char buf[4096 ];void *chip_data;/* Per-chip extra variant data */ };
Can the changes to struct realtek_priv be a separate patch, to clarify what is being changed, and to leave the noisy code movement more isolated?
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Em seg., 8 de jan. de 2024 às 11:00, Vladimir Oltean <[email protected]> escreveu:
Quoted 45 lines · Luiz Angelo Daros de Luca
Quoted 25 lines
Some code can be shared between both interface modules (MDIO and SMI) and among variants. These interface functions migrated to a common module:
-
realtek_common_lock
-realtek_common_unlock
-realtek_common_probe
-realtek_common_register_switch
-realtek_common_removeThe reset during probe was moved to the end of the common probe. This way, we avoid a reset if anything else fails.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>---
drivers/net/dsa/realtek/realtek-common.c new file +4
-0@@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <linux/module.h> +drivers/net/dsa/realtek/realtek-common.c line 14
Quoted 10 lines
drivers/net/dsa/realtek/realtek-common.c new file +10
-0+#include "realtek.h" +#include "realtek-common.h" + +void realtek_common_lock (void *ctx) +{ +struct realtek_priv *priv = ctx; + +mutex_lock (&priv->map_lock); +} +EXPORT_SYMBOL_GPL (realtek_common_lock);Would you mind adding some kernel-doc comments above each of these exported functions? https://docs.kernel.org/doc-guide/kernel-doc.html
says "Every function that is exported to loadable modules usingEXPORT_SYMBOLorEXPORT_SYMBOL_GPLshould have a kernel-doc comment. Functions and data structures in header files which are intended to be used by modules should also have kernel-doc comments."
Quoted 4 lines
It is something I only recently started paying attention to, so we don't have consistency in this regard. But we should try to adhere to this practice for code we change.
Sure. I'll pay attention to that too.
Quoted 8 lines
Quoted 8 lines
drivers/net/dsa/realtek/realtek-common.c new file +8
-0+ +void realtek_common_unlock (void *ctx) +{ +struct realtek_priv *priv = ctx; + +mutex_unlock (&priv->map_lock); +} +EXPORT_SYMBOL_GPL (realtek_common_unlock);
Quoted 8 lines
drivers/net/dsa/realtek/realtek-common.c line 26
Quoted 4 lines
drivers/net/dsa/realtek/realtek-common.c new file +4
-0+ +struct realtek_priv * +realtek_common_probe (struct device *dev,struct regmap_config rc, +struct regmap_config rc_nolock)Could you use "const struct
regmap_config*" as the data types here, to avoid two on-stack variable copies? Regmap will copy the config structures anyway.
I could do that for rc_nolock but not for rc as we need to modify it before passing to regmap. I would still need to duplicate rc, either using the stack or heap. What would be the best option?
1) pass two pointers and copy one to stack
2) pass two pointers and copy one to heap
3) pass two structs (as it is today)
4) pass one pointer and one struct
The old code was using 1) and I'm inclined to adopt it and save a hundred and so bytes from the stack, although 2) would save even more.
Quoted 83 lines
Quoted 83 lines
drivers/net/dsa/realtek/realtek-common.c new file +62
-0+{ +const struct realtek_variant *var; +struct realtek_priv *priv; +int ret; + + var =of_device_get_match_data (dev); +if (!var) +return ERR_PTR (-EINVAL ); + + priv =devm_kzalloc (dev,size_add (sizeof (*priv), var->chip_data_sz), +GFP_KERNEL ); +if (!priv) +return ERR_PTR (-ENOMEM ); + +mutex_init (&priv->map_lock); + + rc.lock_arg = priv; + priv->map =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map)) { + ret =PTR_ERR (priv->map); +dev_err (dev,"regmap init failed: %d\n" , ret); +return ERR_PTR (ret); + } + + priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc_nolock); +if (IS_ERR (priv->map_nolock)) { + ret =PTR_ERR (priv->map_nolock); +dev_err (dev,"regmap init failed: %d\n" , ret); +return ERR_PTR (ret); + } + +/* Link forward and backward */ + priv->dev = dev; + priv->variant = var; + priv->ops = var->ops; + priv->chip_data = (void *)priv +sizeof (*priv); + +dev_set_drvdata (dev, priv); +spin_lock_init (&priv->lock); + + priv->leds_disabled =of_property_read_bool (dev->of_node, +"realtek,disable-leds" ); + +/* TODO: if power is software controlled, set up any regulators here */ + + priv->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (priv->reset)) { +dev_err (dev,"failed to get RESET GPIO\n" ); +return ERR_CAST (priv->reset); + } +if (priv->reset) { +gpiod_set_value (priv->reset,1 ); +dev_dbg (dev,"asserted RESET\n" ); +msleep (REALTEK_HW_STOP_DELAY ); +gpiod_set_value (priv->reset,0 ); +msleep (REALTEK_HW_START_DELAY ); +dev_dbg (dev,"deasserted RESET\n" ); + } + +return priv; +} +EXPORT_SYMBOL (realtek_common_probe);drivers/net/dsa/realtek/realtek.h +1
-3@@ -58,11 +58,9 @@ struct realtek_priv {struct mii_bus *bus;int mdio_addr; -unsigned int clk_delay; -u8 cmd_read; -u8 cmd_write;spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; +const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;@@ -79,6 +77,8 @@ struct realtek_priv {int vlan_enabled;int vlan4k_enabled;
Quoted 9 lines
drivers/net/dsa/realtek/realtek.h struct realtek_priv { · line 84
Quoted 5 lines
drivers/net/dsa/realtek/realtek.h +2
-0+const struct realtek_variant *variant; +char buf[4096 ];void *chip_data;/* Per-chip extra variant data */ };Can the changes to struct
realtek_privbe a separate patch, to clarify what is being changed, and to leave the noisy code movement more isolated?
Sure, although it will not be a patch that makes sense by itself. If it helps with the review, I'll split it. We can fold it back if needed.
Regards,
Luiz
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 12 lines · Luiz Angelo Daros de Luca
Quoted 7 lines
drivers/net/dsa/realtek/realtek-common.c line 26
Quoted 3 lines
drivers/net/dsa/realtek/realtek-common.c new file +3
-0+struct realtek_priv * +realtek_common_probe (struct device *dev,struct regmap_config rc, +struct regmap_config rc_nolock)Could you use "const struct
regmap_config*" as the data types here, to avoid two on-stack variable copies? Regmap will copy the config structures anyway.I could do that for
rc_nolockbut not for rc as we need to modify it before passing to regmap. I would still need to duplicate rc, either using the stack or heap. What would be the best option?
Quoted 7 lines
1) pass two pointers and copy one to stack
2) pass two pointers and copy one to heap
3) pass two structs (as it is today)
4) pass one pointer and one structThe old code was using 1) and I'm inclined to adopt it and save a hundred and so bytes from the stack, although 2) would save even more.
I didn't notice the "rc.lock_arg = priv" assignment...
I'm not sure what you mean by "copy to heap". Perform a dynamic memory allocation?
Also, the old code was not using exactly 1). It copied both the normal and the nolock regmap config to an on-stack local variable, even though only the normal regmap config had to be copied (to be fixed up).
I went back to study the 4 regmap configs, and only the reg_read() and reg_write() methods differ between SMI and MDIO. The rest seems boilerplate that can be dynamically constructed by realtek_common_probe(). Sure, spelling out 4 regmap_config structures is more flexible, but do we need that flexibility? What if realtek_common_probe() takes just the reg_read() and reg_write() function prototypes as arguments, rather than pointers to regmap_config structures it then has to fix up?
Quoted 32 lines
Quoted 22 lines
Quoted 22 lines
drivers/net/dsa/realtek/realtek-common.c new file +1
-0+EXPORT_SYMBOL (realtek_common_probe);drivers/net/dsa/realtek/realtek.h +1
-3@@ -58,11 +58,9 @@ struct realtek_priv {struct mii_bus *bus;int mdio_addr; -unsigned int clk_delay; -u8 cmd_read; -u8 cmd_write;spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; +const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;@@ -79,6 +77,8 @@ struct realtek_priv {int vlan_enabled;int vlan4k_enabled;Quoted 9 lines
drivers/net/dsa/realtek/realtek.h struct realtek_priv { · line 84
Quoted 5 lines
drivers/net/dsa/realtek/realtek.h +2
-0+const struct realtek_variant *variant; +char buf[4096 ];void *chip_data;/* Per-chip extra variant data */ };Can the changes to struct
realtek_privbe a separate patch, to clarify what is being changed, and to leave the noisy code movement more isolated?
Quoted 3 lines
Sure, although it will not be a patch that makes sense by itself. If it helps with the review, I'll split it. We can fold it back if needed.
Well, I don't mean only the changes to the private structure, but also the code changes that accompany them.
As Andrew usually says, what you want is lots of small patches that are each obviously correct, where there is only one thing being changed. Code movement with small renames is trivial to review. Consolidation of two identical code paths in a single function is also possible to follow. The insertion of a new variable and its usage is also easy to review. The removal of a variable, the same. But superimposing them all into a single patch makes everything much more difficult to follow.
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 18 lines · Luiz Angelo Daros de Luca
Quoted 17 lines
Quoted 7 lines
drivers/net/dsa/realtek/realtek-common.c line 26
Quoted 3 lines
drivers/net/dsa/realtek/realtek-common.c new file +3
-0+struct realtek_priv * +realtek_common_probe (struct device *dev,struct regmap_config rc, +struct regmap_config rc_nolock)Could you use "const struct
regmap_config*" as the data types here, to avoid two on-stack variable copies? Regmap will copy the config structures anyway.I could do that for
rc_nolockbut not for rc as we need to modify it before passing to regmap. I would still need to duplicate rc, either using the stack or heap. What would be the best option?1) pass two pointers and copy one to stack
2) pass two pointers and copy one to heap
3) pass two structs (as it is today)
4) pass one pointer and one struct
Quoted 7 lines
Quoted 2 lines
The old code was using 1) and I'm inclined to adopt it and save a hundred and so bytes from the stack, although 2) would save even more.
I didn't notice the "rc.lock_arg = priv" assignment...
I'm not sure what you mean by "copy to heap". Perform a dynamic memory allocation?
Yes. However, I guess the stack can handle that structure in this context.
Quoted 11 lines
Also, the old code was not using exactly 1). It copied both the normal and the nolock regmap config to an on-stack local variable, even though only the normal regmap config had to be copied (to be fixed up).
I went back to study the 4 regmap configs, and only the
reg_read()andreg_write()methods differ between SMI and MDIO. The rest seems boilerplate that can be dynamically constructed byrealtek_common_probe(). Sure, spelling out 4regmap_configstructures is more flexible, but do we need that flexibility? What ifrealtek_common_probe()takes just thereg_read()andreg_write()function prototypes as arguments, rather than pointers toregmap_configstructures it then has to fix up?
IMHO, the constant regmap_config looks cleaner than a sequence of assignments. However, we don't actually need 4 of them. As we already have a writable regmap_config in stack (to assign lock_arg), we can reuse the same struct and simply set disable_locking.
It makes the regmap ignore all locking fields and we don't even need to unset them for map_nolock. Something like this:
realtek_common_probe(struct device *dev, const struct regmap_config *rc_base) {
(...)
rc = *rc_base;
rc.lock_arg = priv;
priv->map = devm_regmap_init(dev, NULL, priv, &rc);
if (IS_ERR(priv->map)) {
ret = PTR_ERR(priv->map);
dev_err(dev, "regmap init failed: %d\n", ret);
return ERR_PTR(ret);
}
rc.disable_locking = true;
priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc);
if (IS_ERR(priv->map_nolock)) {
ret = PTR_ERR(priv->map_nolock);
dev_err(dev, "regmap init failed: %d\n", ret);
return ERR_PTR(ret);
}It has a cleaner function signature and we can remove the _nolock constants as well.
The regmap configs still have some room for improvement, like moving from interfaces to variants, but this series is already too big. We can leave that as it is.
Quoted 39 lines
Quoted 32 lines
Quoted 22 lines
Quoted 22 lines
drivers/net/dsa/realtek/realtek-common.c new file +1
-0+EXPORT_SYMBOL (realtek_common_probe);drivers/net/dsa/realtek/realtek.h +1
-3@@ -58,11 +58,9 @@ struct realtek_priv {struct mii_bus *bus;int mdio_addr; -unsigned int clk_delay; -u8 cmd_read; -u8 cmd_write;spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; +const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;@@ -79,6 +77,8 @@ struct realtek_priv {int vlan_enabled;int vlan4k_enabled;Quoted 9 lines
drivers/net/dsa/realtek/realtek.h struct realtek_priv { · line 84
Quoted 5 lines
drivers/net/dsa/realtek/realtek.h +2
-0+const struct realtek_variant *variant; +char buf[4096 ];void *chip_data;/* Per-chip extra variant data */ };Can the changes to struct
realtek_privbe a separate patch, to clarify what is being changed, and to leave the noisy code movement more isolated?Quoted 3 lines
Sure, although it will not be a patch that makes sense by itself. If it helps with the review, I'll split it. We can fold it back if needed.
Well, I don't mean only the changes to the private structure, but also the code changes that accompany them.
Quoted 7 lines
As Andrew usually says, what you want is lots of small patches that are each obviously correct, where there is only one thing being changed. Code movement with small renames is trivial to review. Consolidation of two identical code paths in a single function is also possible to follow. The insertion of a new variable and its usage is also easy to review. The removal of a variable, the same. But superimposing them all into a single patch makes everything much more difficult to follow.
This case in particular might be hard to justify in the commit message other than "preliminary work". I'll split it as it makes review much easier. this series will grow from 7 to 10 patches, even after dropping the revert patch.
Regards,
Luiz
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 30 lines · Luiz Angelo Daros de Luca
IMHO, the constant
regmap_configlooks cleaner than a sequence of assignments. However, we don't actually need 4 of them. As we already have a writableregmap_configin stack (to assignlock_arg), we can reuse the same struct and simply setdisable_locking.
It makes the regmap ignore all locking fields and we don't even need to unset them formap_nolock. Something like this:
realtek_common_probe(struct device *dev, const struct regmap_config *rc_base){(...) rc = *rc_base; rc.lock_arg = priv; priv->map = devm_regmap_init(dev, NULL, priv, &rc); if (IS_ERR(priv->map)) { ret = PTR_ERR(priv->map); dev_err(dev, "regmap init failed: %d\n", ret); return ERR_PTR(ret); } rc.disable_locking = true; priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); if (IS_ERR(priv->map_nolock)) { ret = PTR_ERR(priv->map_nolock); dev_err(dev, "regmap init failed: %d\n", ret); return ERR_PTR(ret); }
Quoted 6 lines
It has a cleaner function signature and we can remove the
_nolockconstants as well.The regmap configs still have some room for improvement, like moving from interfaces to variants, but this series is already too big. We can leave that as it is.
I was thinking something like this, does it look bad?
From 2e462507171ed0fd8393598842dc0f7e6c50d499 Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <[email protected]>
Date: Thu, 11 Jan 2024 11:38:17 +0200
Subject: [PATCH] realtek_common_info
--- drivers/net/dsa/realtek/realtek-common.c | 35 ++++++++++++++++++------ drivers/net/dsa/realtek/realtek-common.h | 9 ++++-- drivers/net/dsa/realtek/realtek-mdio.c | 27 ++---------------- drivers/net/dsa/realtek/realtek-smi.c | 35 ++++-------------------- 4 files changed, 41 insertions(+), 65 deletions(-)
drivers/net/dsa/realtek/realtek-common.c +26 -9
@@ -22,10 +22,21 @@ void realtek_common_unlock(void *ctx)EXPORT_SYMBOL_GPL (realtek_common_unlock);struct realtek_priv * -realtek_common_probe (struct device *dev,struct regmap_config rc, -struct regmap_config rc_nolock) +realtek_common_probe (struct device *dev, +const struct realtek_common_info *info) {const struct realtek_variant *var; +struct regmap_config rc = { + .reg_bits =10 ,/* A4..A0 R4..R0 */ + .val_bits =16 , + .reg_stride =1 , +/* PHY regs are at 0x8000 */ + .max_register =0xffff , + .reg_format_endian =REGMAP_ENDIAN_BIG , + .reg_read = info->reg_read, + .reg_write = info->reg_write, + .cache_type =REGCACHE_NONE , + };struct realtek_priv *priv;int ret;
@@ -40,17 +51,23 @@ realtek_common_probe(struct device *dev, struct regmap_config rc,mutex_init (&priv->map_lock); - rc.lock_arg = priv; - priv->map =devm_regmap_init (dev,NULL , priv, &rc); -if (IS_ERR (priv->map)) { - ret =PTR_ERR (priv->map); +/* Initialize the non-locking regmap first */ + rc.disable_locking = true; + priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map_nolock)) { + ret =PTR_ERR (priv->map_nolock);dev_err (dev,"regmap init failed: %d\n" , ret);return ERR_PTR (ret); } - priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc_nolock); -if (IS_ERR (priv->map_nolock)) { - ret =PTR_ERR (priv->map_nolock); +/* Then the locking regmap */ + rc.disable_locking = false; + rc.lock = realtek_common_lock; + rc.unlock = realtek_common_unlock; + rc.lock_arg = priv; + priv->map =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map)) { + ret =PTR_ERR (priv->map);dev_err (dev,"regmap init failed: %d\n" , ret);return ERR_PTR (ret); }
drivers/net/dsa/realtek/realtek-common.h +7 -2
@@ -5,11 +5,16 @@#include <linux/regmap.h> +struct realtek_common_info { +int (*reg_read)(void *ctx,u32 reg,u32 *val); +int (*reg_write)(void *ctx,u32 reg,u32 val); +}; +void realtek_common_lock (void *ctx);void realtek_common_unlock (void *ctx);struct realtek_priv * -realtek_common_probe (struct device *dev,struct regmap_config rc, -struct regmap_config rc_nolock); +realtek_common_probe (struct device *dev, +const struct realtek_common_info *info);int realtek_common_register_switch (struct realtek_priv *priv);void realtek_common_remove (struct realtek_priv *priv);
drivers/net/dsa/realtek/realtek-mdio.c +2 -25
@@ -101,31 +101,9 @@ static int realtek_mdio_read(void *ctx, u32 reg, u32 *val)return ret; } -static const struct regmap_config realtek_mdio_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , +static const struct realtek_common_info realtek_mdio_info = { .reg_read = realtek_mdio_read, .reg_write = realtek_mdio_write, - .cache_type =REGCACHE_NONE , - .lock = realtek_common_lock, - .unlock = realtek_common_unlock, -}; - -static const struct regmap_config realtek_mdio_nolock_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_mdio_read, - .reg_write = realtek_mdio_write, - .cache_type =REGCACHE_NONE , - .disable_locking = true, };int realtek_mdio_probe (struct mdio_device *mdiodev)
@@ -134,8 +112,7 @@ int realtek_mdio_probe(struct mdio_device *mdiodev)struct realtek_priv *priv;int ret; - priv =realtek_common_probe (dev, realtek_mdio_regmap_config, - realtek_mdio_nolock_regmap_config); + priv =realtek_common_probe (dev, &realtek_mdio_info);if (IS_ERR (priv))return PTR_ERR (priv);
drivers/net/dsa/realtek/realtek-smi.c +6 -29
@@ -312,33 +312,6 @@ static int realtek_smi_read(void *ctx, u32 reg, u32 *val)return realtek_smi_read_reg (priv, reg, val); } -static const struct regmap_config realtek_smi_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type =REGCACHE_NONE , - .lock = realtek_common_lock, - .unlock = realtek_common_unlock, -}; - -static const struct regmap_config realtek_smi_nolock_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type =REGCACHE_NONE , - .disable_locking = true, -}; -static int realtek_smi_mdio_read (struct mii_bus *bus,int addr,int regnum) {struct realtek_priv *priv = bus->priv;
@@ -396,14 +369,18 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds)return ret; } +static const struct realtek_common_info realtek_smi_info = { + .reg_read = realtek_smi_read, + .reg_write = realtek_smi_write, +}; +int realtek_smi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct realtek_priv *priv;int ret; - priv =realtek_common_probe (dev, realtek_smi_regmap_config, - realtek_smi_nolock_regmap_config); + priv =realtek_common_probe (dev, &realtek_smi_info);if (IS_ERR (priv))return PTR_ERR (priv);
Signature · 1 line
2.34.1
Quoted 4 lines
This case in particular might be hard to justify in the commit message other than "preliminary work". I'll split it as it makes review much easier. this series will grow from 7 to 10 patches, even after dropping the revert patch.
Preliminary work is fine if you explain a bit in advance why it will be needed.
Re: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
drivers/net/dsa/realtek/realtek-common.h line 12
Quoted 13 lines · Vladimir Oltean
drivers/net/dsa/realtek/realtek-common.h +5
-0@@ -5,11 +5,16 @@#include <linux/regmap.h> +struct realtek_common_info { +int (*reg_read)(void *ctx,u32 reg,u32 *val); +int (*reg_write)(void *ctx,u32 reg,u32 val); +}; +
Yes, this is good. Makes it easier to expand later if necessary, too.
Quoted 9 lines
drivers/net/dsa/realtek/realtek-common.h +2
-2void realtek_common_lock (void *ctx);void realtek_common_unlock (void *ctx);struct realtek_priv * -realtek_common_probe (struct device *dev,struct regmap_config rc, -struct regmap_config rc_nolock); +realtek_common_probe (struct device *dev, +const struct realtek_common_info *info);int realtek_common_register_switch (struct realtek_priv *priv);void realtek_common_remove (struct realtek_priv *priv);
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
In reply to Vladimir OlteanEm qui., 11 de jan. de 2024 às 06:41, Vladimir Oltean <[email protected]> escreveu:
Quoted 243 lines · Luiz Angelo Daros de Luca
Quoted 30 lines
IMHO, the constant
regmap_configlooks cleaner than a sequence of assignments. However, we don't actually need 4 of them. As we already have a writableregmap_configin stack (to assignlock_arg), we can reuse the same struct and simply setdisable_locking.
It makes the regmap ignore all locking fields and we don't even need to unset them formap_nolock. Something like this:
realtek_common_probe(struct device *dev, const struct regmap_config *rc_base){(...) rc = *rc_base; rc.lock_arg = priv; priv->map = devm_regmap_init(dev, NULL, priv, &rc); if (IS_ERR(priv->map)) { ret = PTR_ERR(priv->map); dev_err(dev, "regmap init failed: %d\n", ret); return ERR_PTR(ret); } rc.disable_locking = true; priv->map_nolock = devm_regmap_init(dev, NULL, priv, &rc); if (IS_ERR(priv->map_nolock)) { ret = PTR_ERR(priv->map_nolock); dev_err(dev, "regmap init failed: %d\n", ret); return ERR_PTR(ret); }Quoted 6 lines
It has a cleaner function signature and we can remove the
_nolockconstants as well.The regmap configs still have some room for improvement, like moving from interfaces to variants, but this series is already too big. We can leave that as it is.
I was thinking something like this, does it look bad?
From
2e462507171ed0fd8393598842dc0f7e6c50d499Mon Sep 17 00:00:00 2001
From: Vladimir Oltean <[email protected]>
Date: Thu, 11 Jan 2024 11:38:17 +0200
Subject: [PATCH]realtek_common_infoSigned-off-by Vladimir Oltean <[email protected]>--- drivers/net/dsa/realtek/realtek-common.c | 35 ++++++++++++++++++------ drivers/net/dsa/realtek/realtek-common.h | 9 ++++-- drivers/net/dsa/realtek/realtek-mdio.c | 27 ++---------------- drivers/net/dsa/realtek/realtek-smi.c | 35 ++++-------------------- 4 files changed, 41 insertions(+), 65 deletions(-)drivers/net/dsa/realtek/realtek-common.c +26
-9@@ -22,10 +22,21 @@ void realtek_common_unlock(void *ctx)EXPORT_SYMBOL_GPL (realtek_common_unlock);struct realtek_priv * -realtek_common_probe (struct device *dev,struct regmap_config rc, -struct regmap_config rc_nolock) +realtek_common_probe (struct device *dev, +const struct realtek_common_info *info) {const struct realtek_variant *var; +struct regmap_config rc = { + .reg_bits =10 ,/* A4..A0 R4..R0 */ + .val_bits =16 , + .reg_stride =1 , +/* PHY regs are at 0x8000 */ + .max_register =0xffff , + .reg_format_endian =REGMAP_ENDIAN_BIG , + .reg_read = info->reg_read, + .reg_write = info->reg_write, + .cache_type =REGCACHE_NONE , + };struct realtek_priv *priv;int ret;@@ -40,17 +51,23 @@ realtek_common_probe(struct device *dev, struct regmap_config rc,mutex_init (&priv->map_lock); - rc.lock_arg = priv; - priv->map =devm_regmap_init (dev,NULL , priv, &rc); -if (IS_ERR (priv->map)) { - ret =PTR_ERR (priv->map); +/* Initialize the non-locking regmap first */ + rc.disable_locking = true; + priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map_nolock)) { + ret =PTR_ERR (priv->map_nolock);dev_err (dev,"regmap init failed: %d\n" , ret);return ERR_PTR (ret); } - priv->map_nolock =devm_regmap_init (dev,NULL , priv, &rc_nolock); -if (IS_ERR (priv->map_nolock)) { - ret =PTR_ERR (priv->map_nolock); +/* Then the locking regmap */ + rc.disable_locking = false; + rc.lock = realtek_common_lock; + rc.unlock = realtek_common_unlock; + rc.lock_arg = priv; + priv->map =devm_regmap_init (dev,NULL , priv, &rc); +if (IS_ERR (priv->map)) { + ret =PTR_ERR (priv->map);dev_err (dev,"regmap init failed: %d\n" , ret);return ERR_PTR (ret); }drivers/net/dsa/realtek/realtek-common.h +7
-2@@ -5,11 +5,16 @@#include <linux/regmap.h> +struct realtek_common_info { +int (*reg_read)(void *ctx,u32 reg,u32 *val); +int (*reg_write)(void *ctx,u32 reg,u32 val); +}; +void realtek_common_lock (void *ctx);void realtek_common_unlock (void *ctx);struct realtek_priv * -realtek_common_probe (struct device *dev,struct regmap_config rc, -struct regmap_config rc_nolock); +realtek_common_probe (struct device *dev, +const struct realtek_common_info *info);int realtek_common_register_switch (struct realtek_priv *priv);void realtek_common_remove (struct realtek_priv *priv);drivers/net/dsa/realtek/realtek-mdio.c +2
-25@@ -101,31 +101,9 @@ static int realtek_mdio_read(void *ctx, u32 reg, u32 *val)return ret; } -static const struct regmap_config realtek_mdio_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , +static const struct realtek_common_info realtek_mdio_info = { .reg_read = realtek_mdio_read, .reg_write = realtek_mdio_write, - .cache_type =REGCACHE_NONE , - .lock = realtek_common_lock, - .unlock = realtek_common_unlock, -}; - -static const struct regmap_config realtek_mdio_nolock_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_mdio_read, - .reg_write = realtek_mdio_write, - .cache_type =REGCACHE_NONE , - .disable_locking = true, };int realtek_mdio_probe (struct mdio_device *mdiodev)@@ -134,8 +112,7 @@ int realtek_mdio_probe(struct mdio_device *mdiodev)struct realtek_priv *priv;int ret; - priv =realtek_common_probe (dev, realtek_mdio_regmap_config, - realtek_mdio_nolock_regmap_config); + priv =realtek_common_probe (dev, &realtek_mdio_info);if (IS_ERR (priv))return PTR_ERR (priv);drivers/net/dsa/realtek/realtek-smi.c +6
-30@@ -312,33 +312,6 @@ static int realtek_smi_read(void *ctx, u32 reg, u32 *val)return realtek_smi_read_reg (priv, reg, val); } -static const struct regmap_config realtek_smi_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type =REGCACHE_NONE , - .lock = realtek_common_lock, - .unlock = realtek_common_unlock, -}; - -static const struct regmap_config realtek_smi_nolock_regmap_config = { - .reg_bits =10 ,/* A4..A0 R4..R0 */ - .val_bits =16 , - .reg_stride =1 , -/* PHY regs are at 0x8000 */ - .max_register =0xffff , - .reg_format_endian =REGMAP_ENDIAN_BIG , - .reg_read = realtek_smi_read, - .reg_write = realtek_smi_write, - .cache_type =REGCACHE_NONE , - .disable_locking = true, -}; -static int realtek_smi_mdio_read (struct mii_bus *bus,int addr,int regnum) {struct realtek_priv *priv = bus->priv;@@ -396,14 +369,18 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds)return ret; } +static const struct realtek_common_info realtek_smi_info = { + .reg_read = realtek_smi_read, + .reg_write = realtek_smi_write, +}; +int realtek_smi_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct realtek_priv *priv;int ret; - priv =realtek_common_probe (dev, realtek_smi_regmap_config, - realtek_smi_nolock_regmap_config); + priv =realtek_common_probe (dev, &realtek_smi_info);if (IS_ERR (priv))return PTR_ERR (priv); --
Quoted 2 lines
2.34.1
I don't have a strong opinion on how the regmap config is prepared. I'll adopt your suggestion, with some minor changes.
Regmap config for realtek dsa driver should be composed of values that (should) depend on the variant, the management interface (read/write) and some common values. Today it is only dependent on the interface and common values (with register range being a forced coincidence). However, that is a topic for another series. We do need to stop this series at some point. It already has 11 patches (and not counting the 2 bindings + 1 code that are actually my target). We already have some nice features for delivery.
Regards,
Luiz
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
In reply to Luiz Angelo Daros de Lucadrivers/net/dsa/realtek/realtek-common.c line 128
Quoted 5 lines · Luiz Angelo Daros de Luca
drivers/net/dsa/realtek/realtek-common.c new file +5
-0+EXPORT_SYMBOL_GPL (realtek_common_lock); +EXPORT_SYMBOL_GPL (realtek_common_unlock); +EXPORT_SYMBOL (realtek_common_probe); +EXPORT_SYMBOL (realtek_common_register_switch); +EXPORT_SYMBOL (realtek_common_remove);
Is there any reason for the lack of consistency between GPL and non-GPL symbols?
Also, I don't like too much the naming of symbols like "realtek_common_probe", exported to the entire kernel. I wonder if it would be better to drop the word "common" altogether, and use EXPORT_SYMBOL_NS_GPL(*, REALTEK_DSA) + MODULE_IMPORT_NS(REALTEK_DSA) instead of plain EXPORT_SYMBOL_GPL()?
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 9 lines · Luiz Angelo Daros de Luca
drivers/net/dsa/realtek/realtek-common.c line 128
Quoted 5 lines
drivers/net/dsa/realtek/realtek-common.c new file +5
-0+EXPORT_SYMBOL_GPL (realtek_common_lock); +EXPORT_SYMBOL_GPL (realtek_common_unlock); +EXPORT_SYMBOL (realtek_common_probe); +EXPORT_SYMBOL (realtek_common_register_switch); +EXPORT_SYMBOL (realtek_common_remove);Is there any reason for the lack of consistency between GPL and non-GPL symbols?
No. I might have just copied the string from the wrong example.
Quoted 4 lines
Also, I don't like too much the naming of symbols like "
realtek_common_probe", exported to the entire kernel. I wonder if it would be better to drop the word "common" altogether, and useEXPORT_SYMBOL_NS_GPL(*, REALTEK_DSA)+MODULE_IMPORT_NS(REALTEK_DSA)instead of plainEXPORT_SYMBOL_GPL()?
Introducing a namespace seems to be a nice ideia. Let the series grow :-)
What do you mean by dropping the "common"? Use "realtek_probe" or "realtek_dsa_probe"?
Regards,
Luiz
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 2 lines · Luiz Angelo Daros de Luca
What do you mean by dropping the "common"? Use "
realtek_probe" or "realtek_dsa_probe"?
Yes, I meant "realtek_probe()" etc. It's just that the word "common" has no added value in function names, and I can't come up with something good to replace it with.
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 7 lines · Luiz Angelo Daros de Luca
Quoted 2 lines
What do you mean by dropping the "common"? Use "
realtek_probe" or "realtek_dsa_probe"?Yes, I meant "
realtek_probe()" etc. It's just that the word "common" has no added value in function names, and I can't come up with something good to replace it with.
I didn't like realtek_probe() either. It is too generic, although now in a specific name space.
How about replacing all realtek_common with rtl83xx? I guess all rtl83xx chips are switch controllers, even though some of them have an embedded mips core.
Or we could include a prefix/suffix as well like rtl83xx_dsa or realtek_dsa..
Regards,
Luiz
Vladimir Oltean
maintainerRe: [PATCH net-next v3 3/8] net: dsa: realtek: common realtek-dsa module
Quoted 6 lines · Luiz Angelo Daros de Luca
I didn't like
realtek_probe()either. It is too generic, although now in a specific name space.
How about replacing allrealtek_commonwith rtl83xx? I guess all rtl83xx chips are switch controllers, even though some of them have an embedded mips core.
Or we could include a prefix/suffix as well likertl83xx_dsaorrealtek_dsa..
I don't have a problem with just rtl83xx.
Luiz Angelo Daros de Luca
maintainerPATCH v3 4/8 net: dsa: realtek: merge common and interface modules into realtek-dsa
In reply to Luiz Angelo Daros de LucaSince realtek-common and realtek-{smi,mdio} are always loaded together, we can optimize resource usage by consolidating them into a single module.
--- drivers/net/dsa/realtek/Kconfig | 4 ++-- drivers/net/dsa/realtek/Makefile | 7 ++++--- drivers/net/dsa/realtek/realtek-common.c | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 4 ---- drivers/net/dsa/realtek/realtek-smi.c | 4 ---- 5 files changed, 7 insertions(+), 13 deletions(-)
drivers/net/dsa/realtek/Kconfig +2 -2
@@ -16,14 +16,14 @@ menuconfig NET_DSA_REALTEK if NET_DSA_REALTEK config NET_DSA_REALTEK_MDIO - tristate "Realtek MDIO interface support" + bool "Realtek MDIO interface support" depends on OF help Select to enable support for registering switches configured through MDIO. config NET_DSA_REALTEK_SMI - tristate "Realtek SMI interface support" + bool "Realtek SMI interface support" depends on OF help Select to enable support for registering switches connected
drivers/net/dsa/realtek/Makefile +4 -3
@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o -realtek-dsa-objs := realtek-common.o -obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs-y := realtek-common.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs := $(realtek-dsa-objs-y) obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
drivers/net/dsa/realtek/realtek-common.c +1 -0
@@ -128,5 +128,6 @@ void realtek_common_remove(struct realtek_priv *priv)EXPORT_SYMBOL (realtek_common_remove);MODULE_AUTHOR ("Luiz Angelo Daros de Luca <[email protected]>" ); +MODULE_AUTHOR ("Linus Walleij <[email protected]>" );MODULE_DESCRIPTION ("Realtek DSA switches common module" );MODULE_LICENSE ("GPL" );
drivers/net/dsa/realtek/realtek-mdio.c +0 -4
@@ -177,7 +177,3 @@ void realtek_mdio_shutdown(struct mdio_device *mdiodev)dev_set_drvdata (&mdiodev->dev,NULL ); }EXPORT_SYMBOL_GPL (realtek_mdio_shutdown); - -MODULE_AUTHOR ("Luiz Angelo Daros de Luca <[email protected]>" ); -MODULE_DESCRIPTION ("Driver for Realtek ethernet switch connected via MDIO interface" ); -MODULE_LICENSE ("GPL" );
drivers/net/dsa/realtek/realtek-smi.c +0 -4
@@ -456,7 +456,3 @@ void realtek_smi_shutdown(struct platform_device *pdev)platform_set_drvdata (pdev,NULL ); }EXPORT_SYMBOL_GPL (realtek_smi_shutdown); - -MODULE_AUTHOR ("Linus Walleij <[email protected]>" ); -MODULE_DESCRIPTION ("Driver for Realtek ethernet switch connected via SMI interface" ); -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.43.0
Vladimir Oltean
maintainerRe: [PATCH net-next v3 4/8] net: dsa: realtek: merge common and interface modules into realtek-dsa
Quoted 7 lines · Luiz Angelo Daros de Luca
drivers/net/dsa/realtek/Makefile +0
-0@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o
drivers/net/dsa/realtek/Makefile line 9
Quoted 10 lines
drivers/net/dsa/realtek/Makefile +4
-3-realtek-dsa-objs := realtek-common.o -obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs-y := realtek-common.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs := $(realtek-dsa-objs-y) obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
Does "realtek-dsa-objs-y" have any particular meaning in the Kbuild system, or is it just a random variable name?
Am I the only one for whom this is clearer in intent?
drivers/net/dsa/realtek/Makefile +10 -4
@@ -1,9 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o -realtek-dsa-objs-y := realtek-common.o -realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o -realtek-dsa-objs := $(realtek-dsa-objs-y) +realtek-dsa-objs := realtek-common.o + +ifdef CONFIG_NET_DSA_REALTEK_MDIO +realtek-dsa-objs += realtek-mdio.o +endif + +ifdef CONFIG_NET_DSA_REALTEK_SMI +realtek-dsa-objs += realtek-smi.o +endif + obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 4/8] net: dsa: realtek: merge common and interface modules into realtek-dsa
Quoted 34 lines
Quoted 4 lines
+++ b/drivers/net/dsa/realtek/Makefile
(quoted diff) +0
-0@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.oReview line 9
Quoted 10 lines
(quoted diff) +4
-3-realtek-dsa-objs := realtek-common.o -obj-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs-y := realtek-common.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs := $(realtek-dsa-objs-y) obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.oDoes "realtek-dsa-objs-y" have any particular meaning in the
Kbuildsystem, or is it just a random variable name?Am I the only one for whom this is clearer in intent?
drivers/net/dsa/realtek/Makefile +3
-4@@ -1,9 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_NET_DSA_REALTEK) += realtek-dsa.o -realtek-dsa-objs-y := realtek-common.o -realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o -realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o -realtek-dsa-objs := $(realtek-dsa-objs-y) +realtek-dsa-objs := realtek-common.o + +ifdef CONFIG_NET_DSA_REALTEK_MDIO
drivers/net/dsa/realtek/Makefile line 15
Quoted 10 lines
drivers/net/dsa/realtek/Makefile +7
-0+realtek-dsa-objs += realtek-mdio.o +endif + +ifdef CONFIG_NET_DSA_REALTEK_SMI +realtek-dsa-objs += realtek-smi.o +endif + obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
I also prefer ifdef but it was suggested to use the realtek-dsa-objs-y magic and nobody argued about that. It is an easy fix.
Regards,
Luiz
Re: [PATCH net-next v3 4/8] net: dsa: realtek: merge common and interface modules into realtek-dsa
In reply to Vladimir OlteanQuoted 12 lines · Vladimir Oltean
Review
Quoted 7 lines · Luiz Angelo Daros de Luca
(quoted diff) +4
-0+realtek-dsa-objs-y := realtek-common.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_MDIO) += realtek-mdio.o +realtek-dsa-objs-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o +realtek-dsa-objs := $(realtek-dsa-objs-y) obj-$(CONFIG_NET_DSA_REALTEK_RTL8366RB) += rtl8366.o rtl8366-objs := rtl8366-core.o rtl8366rb.o obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.oDoes "realtek-dsa-objs-y" have any particular meaning in the
Kbuildsystem, or is it just a random variable name?
It's a Makefile naming convention, meaning this is always enabled.
linux$ git grep 'objs\-y' | wc -l
52
Yours,
Linus Walleij
Luiz Angelo Daros de Luca
maintainerPATCH v3 5/8 net: dsa: realtek: get internal MDIO node by name
In reply to Luiz Angelo Daros de LucaThe binding docs requires for SMI-connected devices that the switch must have a child node named "mdio" and with a compatible string of "realtek,smi-mdio". Meanwile, for MDIO-connected switches, the binding docs only requires a child node named "mdio".
This patch changes the driver to use the common denominator for both interfaces, looking for the MDIO node by name, ignoring the compatible string.
--- drivers/net/dsa/realtek/realtek-smi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/realtek/realtek-smi.c +1 -1
@@ -360,7 +360,7 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds)struct device_node *mdio_np;int ret; - mdio_np =of_get_compatible_child (priv->dev->of_node,"realtek,smi-mdio" ); + mdio_np =of_get_child_by_name (priv->dev->of_node,"mdio" );if (!mdio_np) {dev_err (priv->dev,"no MDIO bus node\n" );return -ENODEV ;
Signature · 1 line
2.43.0
Re: [PATCH net-next v3 5/8] net: dsa: realtek: get internal MDIO node by name
Quoted 11 lines · Luiz Angelo Daros de Luca
The binding docs requires for SMI-connected devices that the switch must have a child node named "mdio" and with a compatible string of "realtek,smi-mdio". Meanwile, for MDIO-connected switches, the binding docs only requires a child node named "mdio".
This patch changes the driver to use the common denominator for both interfaces, looking for the MDIO node by name, ignoring the compatible string.
Signed-off-by Luiz Angelo Daros de Luca <[email protected]>---
Luiz Angelo Daros de Luca
maintainerPATCH v3 6/8 net: dsa: realtek: migrate user_mii_bus setup to realtek-dsa
In reply to Luiz Angelo Daros de LucaIn the user MDIO driver, despite numerous references to SMI, including its compatible string, there's nothing inherently specific about the SMI interface in the user MDIO bus. Consequently, the code has been migrated to the common module. All references to SMI have been eliminated.
The realtek-mdio will now use this driver instead of the generic DSA driver ("dsa user smi"), which should not be used with OF[1].
The driver now looks for the MDIO node searchking for a child node named "mdio" instead of using the compatible string. This requirement is already present in binding docs for both interfaces.
The line assigning dev.of_node in mdio_bus has been removed since the subsequent of_mdiobus_register will always overwrite it.
ds->user_mii_bus is not assigned anymore[2]. It should work as before as long as the switch ports have a valid phy-handle property.
With a single ds_ops for both interfaces, the ds_ops in realtek_priv is no longer necessary. Now, the realtek_variant.ds_ops can be used directly.
The realtek_priv.setup_interface() has been removed as we can directly call the new common function.
The switch unregistration and the MDIO node decrement in refcount were moved into realtek_common_remove() as both interfaces now need to put the MDIO node.
[1] https://lkml.kernel.org/netdev/[email protected]/T/
[2] https://lkml.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/T/#u
--- drivers/net/dsa/realtek/realtek-common.c | 65 +++++++++++++++++++++- drivers/net/dsa/realtek/realtek-common.h | 1 + drivers/net/dsa/realtek/realtek-mdio.c | 6 --- drivers/net/dsa/realtek/realtek-smi.c | 68 ------------------------ drivers/net/dsa/realtek/realtek.h | 5 +- drivers/net/dsa/realtek/rtl8365mb.c | 49 +++-------------- drivers/net/dsa/realtek/rtl8366rb.c | 52 +++--------------- 7 files changed, 78 insertions(+), 168 deletions(-)
drivers/net/dsa/realtek/realtek-common.c +64 -1
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0+ #include <linux/module.h> +#include <linux/of_mdio.h> #include "realtek.h" #include "realtek-common.h"
@@ -21,6 +22,63 @@ void realtek_common_unlock(void *ctx) }EXPORT_SYMBOL_GPL (realtek_common_unlock); +static int realtek_common_user_mdio_read (struct mii_bus *bus,int addr, +int regnum) +{ +struct realtek_priv *priv = bus->priv; + +return priv->ops->phy_read (priv, addr, regnum); +} + +static int realtek_common_user_mdio_write (struct mii_bus *bus,int addr, +int regnum,u16 val) +{ +struct realtek_priv *priv = bus->priv; + +return priv->ops->phy_write (priv, addr, regnum, val); +} + +int realtek_common_setup_user_mdio (struct dsa_switch *ds) +{ +struct realtek_priv *priv = ds->priv; +struct device_node *mdio_np; +int ret; + + mdio_np =of_get_child_by_name (priv->dev->of_node,"mdio" ); +if (!mdio_np) { +dev_err (priv->dev,"no MDIO bus node\n" ); +return -ENODEV ; + } + + priv->user_mii_bus =devm_mdiobus_alloc (priv->dev); +if (!priv->user_mii_bus) { + ret = -ENOMEM ; + goto err_put_node; + } + priv->user_mii_bus->priv = priv; + priv->user_mii_bus->name ="Realtek user MII" ; + priv->user_mii_bus->read = realtek_common_user_mdio_read; + priv->user_mii_bus->write = realtek_common_user_mdio_write; +snprintf (priv->user_mii_bus->id,MII_BUS_ID_SIZE ,"Realtek-%d" , + ds->index); + priv->user_mii_bus->parent = priv->dev; + + ret =devm_of_mdiobus_register (priv->dev, priv->user_mii_bus, mdio_np); +if (ret) { +dev_err (priv->dev,"unable to register MDIO bus %s\n" , + priv->user_mii_bus->id); + goto err_put_node; + } + +return 0 ; + +err_put_node: +of_node_put (mdio_np); + +return ret; +} +EXPORT_SYMBOL_GPL (realtek_common_setup_user_mdio); +struct realtek_priv *realtek_common_probe (struct device *dev,struct regmap_config rc,struct regmap_config rc_nolock)
@@ -103,7 +161,7 @@ int realtek_common_register_switch(struct realtek_priv *priv) priv->ds->priv = priv; priv->ds->dev = priv->dev; - priv->ds->ops = priv->ds_ops; + priv->ds->ops = priv->variant->ds_ops; priv->ds->num_ports = priv->num_ports; ret =dsa_register_switch (priv->ds);
@@ -121,6 +179,11 @@ void realtek_common_remove(struct realtek_priv *priv)if (!priv)return ; +dsa_unregister_switch (priv->ds); + +if (priv->user_mii_bus) +of_node_put (priv->user_mii_bus->dev.of_node); +/* leave the device reset asserted */ if (priv->reset)gpiod_set_value (priv->reset,1 );
drivers/net/dsa/realtek/realtek-common.h +1 -0
@@ -7,6 +7,7 @@void realtek_common_lock (void *ctx);void realtek_common_unlock (void *ctx); +int realtek_common_setup_user_mdio (struct dsa_switch *ds);struct realtek_priv *realtek_common_probe (struct device *dev,struct regmap_config rc,struct regmap_config rc_nolock);
drivers/net/dsa/realtek/realtek-mdio.c +0 -6
@@ -142,7 +142,6 @@ int realtek_mdio_probe(struct mdio_device *mdiodev) priv->bus = mdiodev->bus; priv->mdio_addr = mdiodev->addr; priv->write_reg_noack = realtek_mdio_write; - priv->ds_ops = priv->variant->ds_ops_mdio; ret =realtek_common_register_switch (priv);if (ret)
@@ -156,11 +155,6 @@ void realtek_mdio_remove(struct mdio_device *mdiodev) {struct realtek_priv *priv =dev_get_drvdata (&mdiodev->dev); -if (!priv) -return ; - -dsa_unregister_switch (priv->ds); -realtek_common_remove (priv); }EXPORT_SYMBOL_GPL (realtek_mdio_remove);
drivers/net/dsa/realtek/realtek-smi.c +0 -68
92 lines not on this page · raw message
drivers/net/dsa/realtek/realtek.h +1 -4
@@ -60,7 +60,6 @@ struct realtek_priv {spinlock_t lock;/* Locks around command writes */ struct dsa_switch *ds; -const struct dsa_switch_ops *ds_ops;struct irq_domain *irqdomain;bool leds_disabled;
@@ -71,7 +70,6 @@ struct realtek_priv {struct rtl8366_mib_counter *mib_counters;const struct realtek_ops *ops; -int (*setup_interface)(struct dsa_switch *ds);int (*write_reg_noack)(void *ctx,u32 addr,u32 data);int vlan_enabled;
@@ -115,8 +113,7 @@ struct realtek_ops { };struct realtek_variant { -const struct dsa_switch_ops *ds_ops_smi; -const struct dsa_switch_ops *ds_ops_mdio; +const struct dsa_switch_ops *ds_ops;const struct realtek_ops *ops;unsigned int clk_delay;u8 cmd_read;
drivers/net/dsa/realtek/rtl8365mb.c +6 -43
79 lines not on this page · raw message
drivers/net/dsa/realtek/rtl8366rb.c +6 -46
78 lines not on this page · raw message
Signature · 1 line
2.43.0
Vladimir Oltean
maintainerRe: [PATCH net-next v3 6/8] net: dsa: realtek: migrate user_mii_bus setup to realtek-dsa
Quoted 22 lines · Luiz Angelo Daros de Luca
In the user MDIO driver, despite numerous references to SMI, including its compatible string, there's nothing inherently specific about the SMI interface in the user MDIO bus. Consequently, the code has been migrated to the common module. All references to SMI have been eliminated.
The realtek-mdio will now use this driver instead of the generic DSA driver ("dsa user smi"), which should not be used with OF[1].
The driver now looks for the MDIO node searchking for a child node named "mdio" instead of using the compatible string. This requirement is already present in binding docs for both interfaces.
The line assigning dev.of_node in
mdio_bushas been removed since the subsequentof_mdiobus_registerwill always overwrite it.
ds->user_mii_busis not assigned anymore[2]. It should work as before as long as the switch ports have a valid phy-handle property.With a single
ds_opsfor both interfaces, theds_opsinrealtek_privis no longer necessary. Now, the realtek_variant.ds_ops can be used directly.
Quoted 6 lines
The
realtek_priv.setup_interface()has been removed as we can directly call the new common function.The switch unregistration and the MDIO node decrement in refcount were moved into
realtek_common_remove()as both interfaces now need to put the MDIO node.
Can you please make all these individual changes separate patches, some before moving the code to realtek_common, and some after? There's a lot of stuff happening at once here.
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 6/8] net: dsa: realtek: migrate user_mii_bus setup to realtek-dsa
Quoted 3 lines
Can you please make all these individual changes separate patches, some before moving the code to
realtek_common, and some after? There's a lot of stuff happening at once here.
Sure. I'll split into 3 parts:
1) change the user mdio bus setup code in place (with some cleanups related to that)
2) move the code to common, just changing strings
3) make realtek-mdio use it and remove duplicated code.
Regards,
Luiz
Luiz Angelo Daros de Luca
maintainerPATCH v3 7/8 net: dsa: realtek: embed dsa_switch into realtek_priv
In reply to Luiz Angelo Daros de LucaTo eliminate the need for a second memory allocation for dsa_switch, it has been embedded within realtek_priv.
--- drivers/net/dsa/realtek/realtek-common.c | 16 ++++++---------- drivers/net/dsa/realtek/realtek-mdio.c | 2 +- drivers/net/dsa/realtek/realtek-smi.c | 2 +- drivers/net/dsa/realtek/realtek.h | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 12 ++++++------ drivers/net/dsa/realtek/rtl8366rb.c | 2 +- 6 files changed, 16 insertions(+), 20 deletions(-)
drivers/net/dsa/realtek/realtek-common.c +6 -10
@@ -155,16 +155,12 @@ int realtek_common_register_switch(struct realtek_priv *priv)return ret; } - priv->ds =devm_kzalloc (priv->dev,sizeof (*priv->ds),GFP_KERNEL ); -if (!priv->ds) -return -ENOMEM ; + priv->ds.priv = priv; + priv->ds.dev = priv->dev; + priv->ds.ops = priv->variant->ds_ops; + priv->ds.num_ports = priv->num_ports; - priv->ds->priv = priv; - priv->ds->dev = priv->dev; - priv->ds->ops = priv->variant->ds_ops; - priv->ds->num_ports = priv->num_ports; - - ret =dsa_register_switch (priv->ds); + ret =dsa_register_switch (&priv->ds);if (ret) {dev_err_probe (priv->dev, ret,"unable to register switch\n" );return ret;
@@ -179,7 +175,7 @@ void realtek_common_remove(struct realtek_priv *priv)if (!priv)return ; -dsa_unregister_switch (priv->ds); +dsa_unregister_switch (&priv->ds);if (priv->user_mii_bus)of_node_put (priv->user_mii_bus->dev.of_node);
drivers/net/dsa/realtek/realtek-mdio.c +1 -1
@@ -166,7 +166,7 @@ void realtek_mdio_shutdown(struct mdio_device *mdiodev)if (!priv)return ; -dsa_switch_shutdown (priv->ds); +dsa_switch_shutdown (&priv->ds);dev_set_drvdata (&mdiodev->dev,NULL ); }
drivers/net/dsa/realtek/realtek-smi.c +1 -1
@@ -383,7 +383,7 @@ void realtek_smi_shutdown(struct platform_device *pdev)if (!priv)return ; -dsa_switch_shutdown (priv->ds); +dsa_switch_shutdown (&priv->ds);platform_set_drvdata (pdev,NULL ); }
drivers/net/dsa/realtek/realtek.h +1 -1
@@ -59,7 +59,7 @@ struct realtek_priv {int mdio_addr;spinlock_t lock;/* Locks around command writes */ -struct dsa_switch *ds; +struct dsa_switch ds;struct irq_domain *irqdomain;bool leds_disabled;
drivers/net/dsa/realtek/rtl8365mb.c +6 -6
@@ -880,7 +880,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,if (!extint)return -ENODEV ; - dp =dsa_to_port (priv->ds, port); + dp =dsa_to_port (&priv->ds, port); dn = dp->dn;/* Set the RGMII TX/RX delay
@@ -1543,7 +1543,7 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv)for (i =0 ; i < priv->num_ports; i++) {struct rtl8365mb_port *p = &mb->ports[i]; -if (dsa_is_unused_port (priv->ds, i)) +if (dsa_is_unused_port (&priv->ds, i))continue ;/* Per-port spinlock to protect the stats64 data */
@@ -1564,7 +1564,7 @@ static void rtl8365mb_stats_teardown(struct realtek_priv *priv)for (i =0 ; i < priv->num_ports; i++) {struct rtl8365mb_port *p = &mb->ports[i]; -if (dsa_is_unused_port (priv->ds, i)) +if (dsa_is_unused_port (&priv->ds, i))continue ;cancel_delayed_work_sync (&p->mib_work);
@@ -1963,7 +1963,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)dev_info (priv->dev,"no interrupt support\n" );/* Configure CPU tagging */ -dsa_switch_for_each_cpu_port (cpu_dp, priv->ds) { +dsa_switch_for_each_cpu_port (cpu_dp, &priv->ds) { cpu->mask |=BIT (cpu_dp->index);if (cpu->trap_port ==RTL8365MB_MAX_NUM_PORTS )
@@ -1978,7 +1978,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)for (i =0 ; i < priv->num_ports; i++) {struct rtl8365mb_port *p = &mb->ports[i]; -if (dsa_is_unused_port (priv->ds, i)) +if (dsa_is_unused_port (&priv->ds, i))continue ;/* Forward only to the CPU */
@@ -1995,7 +1995,7 @@ static int rtl8365mb_setup(struct dsa_switch *ds)* ports will still forward frames to the CPU despite being * administratively down by default. */ -rtl8365mb_port_stp_state_set (priv->ds, i,BR_STATE_DISABLED ); +rtl8365mb_port_stp_state_set (&priv->ds, i,BR_STATE_DISABLED );/* Set up per-port private data */ p->priv = priv;
drivers/net/dsa/realtek/rtl8366rb.c +1 -1
@@ -1662,7 +1662,7 @@ static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index* not drop any untagged or C-tagged frames. Make sure to update the * filtering setting. */ -if (dsa_port_is_vlan_filtering (dsa_to_port (priv->ds, port))) +if (dsa_port_is_vlan_filtering (dsa_to_port (&priv->ds, port))) ret =rtl8366rb_drop_untagged (priv, port, !pvid_enabled);return ret;
Signature · 1 line
2.43.0
Luiz Angelo Daros de Luca
maintainerPATCH v3 8/8 Revert "net: dsa: OF-ware slave_mii_bus"
In reply to Luiz Angelo Daros de LucaThis reverts commit fe7324b932222574a0721b80e72c6c5fe57960d1.
The use of user_mii_bus is inappropriate when the hardware is described with a device-tree [1].
Since all drivers currently implementing ds_switch_ops.phy_{read,write} were not updated to utilize the MDIO information from OF with the generic "dsa user mii", they might not be affected by this change.
[1] https://lkml.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/T/#u
--- net/dsa/dsa.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
net/dsa/dsa.c +1 -6
@@ -15,7 +15,6 @@#include <linux/slab.h> #include <linux/rtnetlink.h> #include <linux/of.h> -#include <linux/of_mdio.h> #include <linux/of_net.h> #include <net/dsa_stubs.h> #include <net/sch_generic.h>
@@ -626,7 +625,6 @@ static void dsa_switch_teardown_tag_protocol(struct dsa_switch *ds)static int dsa_switch_setup (struct dsa_switch *ds) { -struct device_node *dn;int err;if (ds->setup)
@@ -666,10 +664,7 @@ static int dsa_switch_setup(struct dsa_switch *ds)dsa_user_mii_bus_init (ds); - dn =of_get_child_by_name (ds->dev->of_node,"mdio" ); - - err =of_mdiobus_register (ds->user_mii_bus, dn); -of_node_put (dn); + err =mdiobus_register (ds->user_mii_bus);if (err <0 ) goto free_user_mii_bus; }
Signature · 1 line
2.43.0
Re: [PATCH net-next v3 8/8] Revert "net: dsa: OF-ware slave_mii_bus"
Quoted 10 lines · Luiz Angelo Daros de Luca
This reverts commit
fe7324b932222574a0721b80e72c6c5fe57960d1.The use of
user_mii_busis inappropriate when the hardware is described with a device-tree [1].Since all drivers currently implementing ds_switch_ops.phy_{read,write} were not updated to utilize the MDIO information from OF with the generic "dsa user mii", they might not be affected by this change.
[1] https://lkml.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/T/#u
This doesn't make sense to me: "The use of user_mii_bus is inappropriate when the hardware is described with a device-tree." I think this is the correct statement: "The use of user_mii_bus is inappropriate when the MDIO bus of the switch is described on the device-tree."
The patch log is also not clear on why this leads to the removal of OF-based registration from the DSA core driver.
I would change the patch log here to something like this:
net: dsa: do not populate user_mii_bus when switch MDIO bus is described
The use of ds->user_mii_bus is inappropriate when the MDIO bus of the switch is described on the device-tree [1].
To keep things simple, make [all subdrivers that control a switch [with MDIO bus] probed on OF] register the bus on the subdriver.
The subdrivers that control switches [with MDIO bus] probed on OF must follow this logic to support all cases properly:
No switch MDIO bus defined: Populate ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if "interrupt-controller" is defined at the switch node.
Switch MDIO bus defined: Don't populate ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if ["interrupt-controller" is defined at the switch node and "interrupts" is defined at the PHY nodes under the switch MDIO bus node].
There can be a case where ds->user_mii_bus is not populated, but ds_switch_ops.phy_{read,write} is. That would mean the subdriver controls a switch probed on OF, and it lets the DSA core driver to populate ds->user_mii_bus and register the bus. We don't want this to happen. Therefore, ds_switch_ops.phy_{read,write} should be only used on the subdrivers that control switches probed on platform_data.
With that, the "!ds->user_mii_bus && ds->ops->phy_read" check under dsa_switch_setup() remains in use only for switches probed on platform_data. Therefore, remove OF-based registration as it's useless now.
---
I think we should do all this in a single patch. I've done it on the MT7530 DSA subdriver which I maintain.
drivers/net/dsa/mt7530.c +10 -3
@@ -2155,15 +2155,21 @@ mt7530_setup_mdio(struct mt7530_priv *priv) {struct dsa_switch *ds = priv->ds;struct device *dev = priv->dev; +struct device_node *np, *mnp;struct mii_bus *bus;static int idx;int ret; + np = priv->dev->of_node; + mnp =of_get_child_by_name (np,"mdio" ); + bus =devm_mdiobus_alloc (dev);if (!bus)return -ENOMEM ; - ds->user_mii_bus = bus; +if (mnp ==NULL ) + ds->user_mii_bus = bus; + bus->priv = priv; bus->name =KBUILD_MODNAME "-mii" ;snprintf (bus->id,MII_BUS_ID_SIZE ,KBUILD_MODNAME "-%d" , idx++);
@@ -2174,10 +2180,11 @@ mt7530_setup_mdio(struct mt7530_priv *priv) bus->parent = dev; bus->phy_mask = ~ds->phys_mii_mask; -if (priv->irq) +if (priv->irq && mnp ==NULL )mt7530_setup_mdio_irq (priv); - ret =devm_mdiobus_register (dev, bus); + ret =devm_of_mdiobus_register (dev, bus, mnp); +of_node_put (mnp);if (ret) {dev_err (dev,"failed to register MDIO bus: %d\n" , ret);if (priv->irq)
Arınç
Re: [PATCH net-next v3 8/8] Revert "net: dsa: OF-ware slave_mii_bus"
Quoted 49 lines · Arınç ÜNAL
Quoted 10 lines · Luiz Angelo Daros de Luca
This reverts commit
fe7324b932222574a0721b80e72c6c5fe57960d1.The use of
user_mii_busis inappropriate when the hardware is described with a device-tree [1].Since all drivers currently implementing ds_switch_ops.phy_{read,write} were not updated to utilize the MDIO information from OF with the generic "dsa user mii", they might not be affected by this change.
[1] https://lkml.kernel.org/netdev/20231213120656.x46fyad6ls7sqyzv@skbuf/T/#u
This doesn't make sense to me: "The use of
user_mii_busis inappropriate when the hardware is described with a device-tree." I think this is the correct statement: "The use ofuser_mii_busis inappropriate when the MDIO bus of the switch is described on the device-tree."The patch log is also not clear on why this leads to the removal of OF-based registration from the DSA core driver.
I would change the patch log here to something like this:
net: dsa: do not populate
user_mii_buswhen switch MDIO bus is describedThe use of
ds->user_mii_busis inappropriate when the MDIO bus of the switch is described on the device-tree [1].To keep things simple, make [all subdrivers that control a switch [with MDIO bus] probed on OF] register the bus on the subdriver.
The subdrivers that control switches [with MDIO bus] probed on OF must follow this logic to support all cases properly:
No switch MDIO bus defined: Populate
ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if "interrupt-controller" is defined at the switch node.Switch MDIO bus defined: Don't populate
ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if ["interrupt-controller" is defined at the switch node and "interrupts" is defined at the PHY nodes under the switch MDIO bus node].There can be a case where
ds->user_mii_busis not populated, but ds_switch_ops.phy_{read,write} is. That would mean the subdriver controls a switch probed on OF, and it lets the DSA core driver to populateds->user_mii_busand register the bus. We don't want this to happen. Therefore, ds_switch_ops.phy_{read,write} should be only used on the subdrivers that control switches probed onplatform_data.
Quoted 8 lines
With that, the "!ds->user_mii_bus &&
ds->ops->phy_read" check underdsa_switch_setup()remains in use only for switches probed onplatform_data. Therefore, remove OF-based registration as it's useless now.---
I think we should do all this in a single patch. I've done it on the MT7530 DSA subdriver which I maintain.
Actually, there's no need to drag this patch further by including the improvement of handling the MDIO bus on all relevant subdrivers.
That said, I'd like to submit this patch myself, if it is OK by everyone here.
Here's the patch log I've prepared:
net: dsa: do not populate user_mii_bus when switch MDIO bus is described
The use of ds->user_mii_bus is inappropriate when the MDIO bus of the switch is described on the device-tree [1].
To keep things simple, make [all subdrivers that control switches [with MDIO bus] probed on OF] register the bus on the subdriver. This is already the case on all of these subdrivers.
There can be a case where ds->user_mii_bus is not populated, but ds_switch_ops.phy_{read,write} is. That would mean the subdriver controls switches probed on OF, and it lets the DSA core driver to populate ds->user_mii_bus and register the bus. We don't want this to happen. Therefore, ds_switch_ops.phy_{read,write} should be only used on the subdrivers that control switches probed on platform_data.
With that, the "!ds->user_mii_bus && ds->ops->phy_read" check under dsa_switch_setup() remains in use only for switches probed on platform_data. Therefore, remove OF-based registration as it's useless now.
Currently, none of the subdrivers that control switches [with MDIO bus] probed on OF implements ds_switch_ops.phy_{read,write} so no subdriver will be affected by this patch.
The subdrivers that control switches [with MDIO bus] probed on OF must follow this logic to support all cases properly:
No switch MDIO bus defined: Populate ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if "interrupt-controller" is defined at the switch node. This case should only be covered for the switches which their dt-bindings documentation didn't document the MDIO bus from the start. This is to keep supporting the device trees that do not describe the MDIO bus on the device tree but the MDIO bus is being used nonetheless.
Switch MDIO bus defined: Don't populate ds->user_mii_bus, register the MDIO bus, set the interrupts for PHYs if ["interrupt-controller" is defined at the switch node and "interrupts" is defined at the PHY nodes under the switch MDIO bus node].
Let's leave the improvement of handling the MDIO bus on relevant subdrivers to future patches.
Arınç
Re: [PATCH net-next v3 8/8] Revert "net: dsa: OF-ware slave_mii_bus"
Quoted 28 lines · Arınç ÜNAL
Quoted 2 lines · Arınç ÜNAL
I think we should do all this in a single patch. I've done it on the MT7530 DSA subdriver which I maintain.
Actually, there's no need to drag this patch further by including the improvement of handling the MDIO bus on all relevant subdrivers.
That said, I'd like to submit this patch myself, if it is OK by everyone here.
Here's the patch log I've prepared:
net: dsa: do not populate
user_mii_buswhen switch MDIO bus is describedThe use of
ds->user_mii_busis inappropriate when the MDIO bus of the switch is described on the device-tree [1].To keep things simple, make [all subdrivers that control switches [with MDIO bus] probed on OF] register the bus on the subdriver. This is already the case on all of these subdrivers.
There can be a case where
ds->user_mii_busis not populated, but ds_switch_ops.phy_{read,write} is. That would mean the subdriver controls switches probed on OF, and it lets the DSA core driver to populateds->user_mii_busand register the bus. We don't want this to happen. Therefore, ds_switch_ops.phy_{read,write} should be only used on the subdrivers that control switches probed onplatform_data.
Quoted 7 lines
With that, the "!ds->user_mii_bus &&
ds->ops->phy_read" check underdsa_switch_setup()remains in use only for switches probed onplatform_data. Therefore, remove OF-based registration as it's useless now.Currently, none of the subdrivers that control switches [with MDIO bus] probed on OF implements ds_switch_ops.phy_{read,write} so no subdriver will be affected by this patch.
It looks like this patch will cause the MDIO bus of the switches probed on OF which are controlled by these subdrivers to only be registered non-OF-based.
drivers/net/dsa/b53/b53_common.cdrivers/net/dsa/lan9303-core.cdrivers/net/dsa/vitesse-vsc73xx-core.c
These subdrivers let the DSA driver register the bus OF-based or non-OF-based:
- ds->ops->phy_read() and ds->ops->phy_write() are present.
- ds->user_mii_bus is not populated.
Not being able to register the bus OF-based may cause issues. There is an example for the switch on the MT7988 SoC which is controlled by the MT7530 DSA subdriver. Being able to reference the PHYs on the switch MDIO bus is mandatory on MT7988 as calibration data from NVMEM for each PHY is required.
I suggest that we hold off on this patch until these subdrivers are made to be capable of registering the MDIO bus as OF-based on their own.
Arınç
Luiz Angelo Daros de Luca
maintainerRe: [PATCH net-next v3 8/8] Revert "net: dsa: OF-ware slave_mii_bus"
Hi Arinç,
Quoted 4 lines
It looks like this patch will cause the MDIO bus of the switches probed on OF which are controlled by these subdrivers to only be registered non-OF-based.
Quoted 8 lines
drivers/net/dsa/b53/b53_common.cdrivers/net/dsa/lan9303-core.cdrivers/net/dsa/vitesse-vsc73xx-core.cThese subdrivers let the DSA driver register the bus OF-based or non-OF-based:
-ds->ops->phy_read()andds->ops->phy_write()are present.
-ds->user_mii_busis not populated.
I checked the changes on those drivers since fe7324b932222574a0721b80e72c6c5fe57960d1 and nothing indicates that they were changing anything related to the user mii bus. I also checked bindings for the mdio node requirement. None of them mentioned the mdio node.
Quoted 8 lines
Not being able to register the bus OF-based may cause issues. There is an example for the switch on the MT7988 SoC which is controlled by the MT7530 DSA subdriver. Being able to reference the PHYs on the switch MDIO bus is mandatory on MT7988 as calibration data from NVMEM for each PHY is required.
I suggest that we hold off on this patch until these subdrivers are made to be capable of registering the MDIO bus as OF-based on their own.
We might be over cautious keeping this for more time after the realtek refactoring gets merged. The using OF with the generic user mii bus driver is just a broken design and probably not in use. Anyway, it is not a requirement for the series. If there is no objection, I can drop it.
I would like to send v4 with the OF node handling simplified by the change in the MDIO API. However, I'm reluctant to send mostly the same code without any reviews.
Regards,
Luiz
Re: [PATCH net-next v3 8/8] Revert "net: dsa: OF-ware slave_mii_bus"
Quoted 15 lines · Luiz Angelo Daros de Luca
Hi Arinç,
Quoted 4 lines
It looks like this patch will cause the MDIO bus of the switches probed on OF which are controlled by these subdrivers to only be registered non-OF-based.
Quoted 8 lines
drivers/net/dsa/b53/b53_common.cdrivers/net/dsa/lan9303-core.cdrivers/net/dsa/vitesse-vsc73xx-core.cThese subdrivers let the DSA driver register the bus OF-based or non-OF-based:
-ds->ops->phy_read()andds->ops->phy_write()are present.
-ds->user_mii_busis not populated.
Quoted 5 lines
I checked the changes on those drivers since
fe7324b932222574a0721b80e72c6c5fe57960d1and nothing indicates that they were changing anything related to the user mii bus. I also checked bindings for the mdio node requirement. None of them mentioned the mdio node.
Ok, we need to specifically mention the latter on the patch log.
Quoted 7 lines
Quoted 7 lines
Not being able to register the bus OF-based may cause issues. There is an example for the switch on the MT7988 SoC which is controlled by the MT7530 DSA subdriver. Being able to reference the PHYs on the switch MDIO bus is mandatory on MT7988 as calibration data from NVMEM for each PHY is required.
Quoted 8 lines
Quoted 2 lines
I suggest that we hold off on this patch until these subdrivers are made to be capable of registering the MDIO bus as OF-based on their own.
We might be over cautious keeping this for more time after the realtek refactoring gets merged. The using OF with the generic user mii bus driver is just a broken design and probably not in use. Anyway, it is not a requirement for the series. If there is no objection, I can drop it.
Sounds good to me. I'd like to take this patch off your hands.
Quoted 4 lines
I would like to send v4 with the OF node handling simplified by the change in the MDIO API. However, I'm reluctant to send mostly the same code without any reviews.
I suppose our conversation here will remind Vladimir and Alvin to review.
Arınç
Vladimir Oltean
maintainerQuoted 18 lines · Luiz Angelo Daros de Luca
The series begins by removing an unused function pointer at
realtek_ops->cleanup.Each variant module was converted into real drivers, serving as both a platform driver (for switches connected using the SMI interface) and an MDIO driver (for MDIO-connected switches). The relationship between the variant and interface modules is reversed, with the variant module now calling both interface functions (if not disabled at build time). While in most devices only one interface is likely used, the interface code is significantly smaller than a variant module, consuming fewer resources than the previous code. With variant modules now functioning as real drivers, compatible strings are published only in a single variant module, preventing conflicts.
The patch series introduces a new common module for functions shared by both variants. This module also absorbs the two previous interface modules, as they would always be loaded anyway.
Quoted 8 lines
The series relocates the user MII driver from realtek-smi to common. It is now used by MDIO-connected switches instead of the generic DSA driver. There's a change in how this driver locates the MDIO node. It now only searches for a child node named "mdio", which is required by both interfaces in binding docs.
The
dsa_switchinrealtek_priv->dsis now embedded in the struct. It is always in use and avoids dynamic memory allocation.
git format-patch --cover-letter generates a nice patch series overview with a diffstat and the commit titles, you should include it next time.
Quoted 2 lines · Vladimir Oltean
git format-patch --cover-letter generates a nice patch series overview with a diffstat and the commit titles, you should include it next time.
Thanks a lot for mentioning this. I didn't know this and now that I use it, it helps a lot.
Arınç
Quoted 7 lines · Arınç ÜNAL
Quoted 2 lines · Vladimir Oltean
git format-patch --cover-letter generates a nice patch series overview with a diffstat and the commit titles, you should include it next time.
Thanks a lot for mentioning this. I didn't know this and now that I use it, it helps a lot.
There are some even nicer tools you can use on top, i.e. "b4":
https://people.kernel.org/monsieuricon/sending-a-kernel-patch-with-b4-part-1
This blog post doesn't mention the magic trick:
b4 prep --set-prefixes net-next
And
b4 trailers -u
Which is what you need to make it an awesome net contribution patch series tool.
Yours,
Linus Walleij
Quoted 12 lines · Linus Walleij
Quoted 7 lines · Arınç ÜNAL
Quoted 2 lines · Vladimir Oltean
git format-patch --cover-letter generates a nice patch series overview with a diffstat and the commit titles, you should include it next time.
Thanks a lot for mentioning this. I didn't know this and now that I use it, it helps a lot.
There are some even nicer tools you can use on top, i.e. "b4":
https://people.kernel.org/monsieuricon/sending-a-kernel-patch-with-b4-part-1
Quoted 8 lines
This blog post doesn't mention the magic trick:
b4 prep --set-prefixes net-nextAnd
b4 trailers -uWhich is what you need to make it an awesome net contribution patch series tool.
I've spent a day thinking I probably don't need this. I've spent the next day giving it a go. I need this. Diffstat, the auto formatting of new version change log, and linking to the previous version on the cover letter, patch version comparison, and auto adding trailers features make my life so much easier.
I've had trouble with every mail provider's SMTP server that I've ever used for submitting patches, so the web endpoint is a godsend. It would've been great if b4 supported openssh keys to submit patches via the web endpoint. Patatt at least supports it to sign patches. I've got a single ed25519 openssh keypair I use across all my devices, now I'll have to backup another key pair. Or create a new key and authenticate with the web endpoint on each device.
Safe to say, I will submit my next patch series using b4. Thanks for telling me about this tool Linus!
Arınç
Quoted 3 lines · Arınç ÜNAL
I've had trouble with every mail provider's SMTP server that I've ever used for submitting patches, so the web endpoint is a godsend. It would've been great if b4 supported openssh keys to submit patches via the web endpoint.
The only reason it's not currently supported is because we don't have a recent enough version of openssh on the system where the endpoint is listening. This will change in the near future, at which point using ssh keys will be possible.
Quoted 7 lines
Patatt at least supports it to sign patches. I've got a single ed25519 openssh keypair I use across all my devices, now I'll have to backup another key pair. Or create a new key and authenticate with the web endpoint on each device.
Safe to say, I will submit my next patch series using b4. Thanks for telling me about this tool Linus!
\o/
Please feel free to provide any feedback you have to the [email protected] list.
-K
Luiz Angelo Daros de Luca
maintainerQuoted 17 lines
Quoted 3 lines
I've had trouble with every mail provider's SMTP server that I've ever used for submitting patches, so the web endpoint is a godsend. It would've been great if b4 supported openssh keys to submit patches via the web endpoint.
The only reason it's not currently supported is because we don't have a recent enough version of openssh on the system where the endpoint is listening. This will change in the near future, at which point using ssh keys will be possible.
Quoted 7 lines
Patatt at least supports it to sign patches. I've got a single ed25519 openssh keypair I use across all my devices, now I'll have to backup another key pair. Or create a new key and authenticate with the web endpoint on each device.
Safe to say, I will submit my next patch series using b4. Thanks for telling me about this tool Linus!
Quoted 6 lines
\o/
Please feel free to provide any feedback you have to the [email protected] list.
-K
+1 to b4 users: v5 just sent using b4. Great tool.
Regards,
Luiz