DSA: switch to fwnode_/device_
Subsystems (13)
v2 cover DSA: switch to fwnode_/device_
Hi,
This is a re-spin of the DSA migration to fwnode_/device_ API. As agreed, the ACPI-specific patches were kept aside for now, until the MDIOSerialBus is submitted and accepted in the ACPI Specification.
The patchset addresses all comments from the first version, mostly related to usage of proper device_ helpers. Also, as it was suggested, fwnode_dev_node_match() routine was taken out of the network code and introduced as a generic one in drivers/base/property.c
The details can be found in the changelog below. Any comments or remarks will be appreciated.
Each patch was tested on:
* On EspressoBIN
* On SolidRun CN913x CEx7 Eval Board
IMPORTANT NOTE:
This patchset is rebased on top of the one from Russell
(https://lore.kernel.org/all/[email protected]/),
so a care should be taken, when merging to the net-next tree.
Best regards,
Marcin
Changelog v1->v2:
1/8
* Drop unnecessary check in fixed_phy_get_gpiod()
* Improve line breaking
* Use device_set_node & dev_fwnode
2/8
* Switch to fwnode_property_count_u32 and fix comparison in if statement.
3/8
* Drop dn usage entirely and use dp->fwnode only. Update all dependent drivers to use to_of_node.
* Use device_set_node, dev_fwnode & device_get_named_child_node
* Replace '_of' routines suffix with '_fw'
4/8
* Use device_set_node
5/8
* New patch
6/8
* Use device_match_fwnode
* Restore EXPORT_SYMBOL()
7/8
* Get rid of of_mdiobus_register_device
8/8
* Use dev_fwnode in mv88e6xxx_probe
* Simplify condition checks in mv88e6xxx_probe as suggested by Andy
Marcin Wojtas (8):
net: phy: fixed_phy: switch to fwnode_ API
net: mdio: switch fixed-link PHYs API to fwnode_
net: dsa: switch to device_/fwnode_ APIs
net: mvpp2: initialize port fwnode pointer device property: introduce fwnode_dev_node_match
net: core: switch to fwnode_find_net_device_by_node()
net: mdio: introduce fwnode_mdiobus_register_device()
net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs
include/linux/etherdevice.h | 1 + include/linux/fwnode_mdio.h | 22 ++++ include/linux/of_net.h | 6 - include/linux/phy_fixed.h | 4 +- include/linux/property.h | 2 + include/net/dsa.h | 2 +- net/dsa/dsa_priv.h | 4 +- drivers/base/property.c | 22 ++++ drivers/net/dsa/mt7530.c | 2 +- drivers/net/dsa/mv88e6xxx/chip.c | 57 ++++----- drivers/net/dsa/qca8k.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- drivers/net/mdio/fwnode_mdio.c | 129 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 111 +---------------- drivers/net/phy/fixed_phy.c | 39 +++--- net/core/net-sysfs.c | 25 ++-- net/dsa/dsa2.c | 101 ++++++++------- net/dsa/port.c | 70 ++++++----- net/dsa/slave.c | 7 +- 20 files changed, 328 insertions(+), 282 deletions(-)
Signature · 1 line
2.29.0
PATCH v2 1/8 net: phy: fixed_phy: switch to fwnode_ API
This patch allows to use fixed_phy driver and its helper functions without Device Tree dependency, by swtiching from of_ to fwnode_ API.
--- include/linux/phy_fixed.h | 4 +- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-)
include/linux/phy_fixed.h +2 -2
@@ -19,7 +19,7 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status);extern struct phy_device *fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np); +struct fwnode_handle *fwnode);extern struct phy_device * fixed_phy_register_with_gpiod(unsigned int irq,
@@ -38,7 +38,7 @@ static inline int fixed_phy_add(unsigned int irq, int phy_id, }static inline struct phy_device *fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np) +struct fwnode_handle *fwnode) {return ERR_PTR (-ENODEV ); }
drivers/net/mdio/of_mdio.c +1 -1
@@ -421,7 +421,7 @@ int of_phy_register_fixed_link(struct device_node *np)return -ENODEV ; register_phy: -return PTR_ERR_OR_ZERO (fixed_phy_register (PHY_POLL , &status, np)); +return PTR_ERR_OR_ZERO (fixed_phy_register (PHY_POLL , &status,of_fwnode_handle (np))); }EXPORT_SYMBOL (of_phy_register_fixed_link);
drivers/net/phy/fixed_phy.c +14 -25
@@ -15,9 +15,9 @@#include <linux/mii.h> #include <linux/phy.h> #include <linux/phy_fixed.h> +#include <linux/property.h> #include <linux/err.h> #include <linux/slab.h> -#include <linux/of.h> #include <linux/gpio/consumer.h> #include <linux/idr.h> #include <linux/netdevice.h>
@@ -186,16 +186,12 @@ static void fixed_phy_del(int phy_addr) } } -#ifdef CONFIG_OF_GPIO -static struct gpio_desc *fixed_phy_get_gpiod (struct device_node *np) +static struct gpio_desc *fixed_phy_get_gpiod (struct fwnode_handle *fwnode) { -struct device_node *fixed_link_node; +struct fwnode_handle *fixed_link_node;struct gpio_desc *gpiod; -if (!np) -return NULL ; - - fixed_link_node =of_get_child_by_name (np,"fixed-link" ); + fixed_link_node =fwnode_get_named_child_node (fwnode,"fixed-link" );if (!fixed_link_node)return NULL ;
@@ -204,28 +200,21 @@ static struct gpio_desc *fixed_phy_get_gpiod(struct device_node *np)* Linux device associated with it, we simply have obtain * the GPIO descriptor from the device tree like this. */ - gpiod =fwnode_gpiod_get_index (of_fwnode_handle (fixed_link_node), -"link" ,0 ,GPIOD_IN ,"mdio" ); + gpiod =fwnode_gpiod_get_index (fixed_link_node,"link" ,0 ,GPIOD_IN ,"mdio" );if (IS_ERR (gpiod) &&PTR_ERR (gpiod) != -EPROBE_DEFER ) {if (PTR_ERR (gpiod) != -ENOENT )pr_err ("error getting GPIO for fixed link %pOF, proceed without\n" , fixed_link_node); gpiod =NULL ; } -of_node_put (fixed_link_node); +fwnode_handle_put (fixed_link_node);return gpiod; } -#else -static struct gpio_desc *fixed_phy_get_gpiod (struct device_node *np) -{ -return NULL ; -} -#endif static struct phy_device *__fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np, +struct fwnode_handle *fwnode,struct gpio_desc *gpiod) {struct fixed_mdio_bus *fmb = &platform_fmb;
@@ -238,7 +227,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq,/* Check if we have a GPIO associated with this fixed phy */ if (!gpiod) { - gpiod =fixed_phy_get_gpiod (np); + gpiod =fixed_phy_get_gpiod (fwnode);if (IS_ERR (gpiod))return ERR_CAST (gpiod); }
@@ -269,8 +258,8 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, phy->asym_pause = status->asym_pause; } -of_node_get (np); - phy->mdio.dev.of_node = np; +fwnode_handle_get (fwnode); +device_set_node (&phy->mdio.dev, fwnode); phy->is_pseudo_fixed_link = true;switch (status->speed) {
@@ -299,7 +288,7 @@ static struct phy_device *__fixed_phy_register(unsigned int irq, ret =phy_device_register (phy);if (ret) {phy_device_free (phy); -of_node_put (np); +fwnode_handle_put (fwnode);fixed_phy_del (phy_addr);return ERR_PTR (ret); }
@@ -309,9 +298,9 @@ static struct phy_device *__fixed_phy_register(unsigned int irq,struct phy_device *fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np) +struct fwnode_handle *fwnode) { -return __fixed_phy_register (irq, status, np,NULL ); +return __fixed_phy_register (irq, status, fwnode,NULL ); }EXPORT_SYMBOL_GPL (fixed_phy_register);
@@ -327,7 +316,7 @@ EXPORT_SYMBOL_GPL(fixed_phy_register_with_gpiod);void fixed_phy_unregister (struct phy_device *phy) {phy_device_remove (phy); -of_node_put (phy->mdio.dev.of_node); +fwnode_handle_put (dev_fwnode (&phy->mdio.dev));fixed_phy_del (phy->mdio.addr); }EXPORT_SYMBOL_GPL (fixed_phy_unregister);
Signature · 1 line
2.29.0
Re: [net-next: PATCH v2 1/8] net: phy: fixed_phy: switch to fwnode_ API
Quoted 16 lines · Marcin Wojtas
This patch allows to use
fixed_phydriver and its helper functions without Device Tree dependency, by swtiching fromof_tofwnode_API.Signed-off-by Marcin Wojtas <[email protected]>--- include/linux/phy_fixed.h | 4 +- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-)include/linux/phy_fixed.h +0
-0
include/linux/phy_fixed.h extern int fixed_phy_add(unsigned int irq, int phy_id, · line 22
Quoted 5 lines
include/linux/phy_fixed.h +1
-1@@ -19,7 +19,7 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status);extern struct phy_device *fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np); +struct fwnode_handle *fwnode);
I think this ought to require a forward declaration of struct fwnode_handle and a removal of the forward declaration of device_node.
With that fixes:
Signature · 1 line
Florian
Re: [net-next: PATCH v2 1/8] net: phy: fixed_phy: switch to fwnode_ API
pt., 15 lip 2022 o 19:21 Florian Fainelli <[email protected]> napisał(a):
Quoted 13 lines · Marcin Wojtas
Quoted 11 lines
This patch allows to use
fixed_phydriver and its helper functions without Device Tree dependency, by swtiching fromof_tofwnode_API.Signed-off-by Marcin Wojtas <[email protected]>--- include/linux/phy_fixed.h | 4 +- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 17 insertions(+), 28 deletions(-)
Quoted 13 lines
include/linux/phy_fixed.h extern int fixed_phy_add(unsigned int irq, int phy_id, · line 22
Quoted 10 lines
include/linux/phy_fixed.h +1
-1@@ -19,7 +19,7 @@ extern int fixed_phy_add(unsigned int irq, int phy_id, struct fixed_phy_status *status);extern struct phy_device *fixed_phy_register (unsigned int irq,struct fixed_phy_status *status, -struct device_node *np); +struct fwnode_handle *fwnode);I think this ought to require a forward declaration of struct
fwnode_handleand a removal of the forward declaration ofdevice_node.
Ok, I'll replace the declaration.
Quoted 4 lines
With that fixes:
Reviewed-by Florian Fainelli <[email protected]>
Thanks,
Marcin
PATCH v2 2/8 net: mdio: switch fixed-link PHYs API to fwnode_
In reply to Marcin Wojtasfixed-link PHYs API is used by DSA and a number of drivers and was depending on of_. Switch to fwnode_ so to make it hardware description agnostic and allow to be used in ACPI world as well.
--- include/linux/fwnode_mdio.h | 19 ++++ drivers/net/mdio/fwnode_mdio.c | 100 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 122 insertions(+), 76 deletions(-)
include/linux/fwnode_mdio.h +19 -0
@@ -16,6 +16,11 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,int fwnode_mdiobus_register_phy (struct mii_bus *bus,struct fwnode_handle *child,u32 addr); +int fwnode_phy_register_fixed_link (struct fwnode_handle *fwnode); + +void fwnode_phy_deregister_fixed_link (struct fwnode_handle *fwnode); + +bool fwnode_phy_is_fixed_link (struct fwnode_handle *fwnode);#else /* CONFIG_FWNODE_MDIO */ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy,
@@ -30,6 +35,20 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus, {return -EINVAL ; } + +static inline int fwnode_phy_register_fixed_link (struct fwnode_handle *fwnode) +{ +return -ENODEV ; +} + +static inline void fwnode_phy_deregister_fixed_link (struct fwnode_handle *fwnode) +{ +} + +static inline bool fwnode_phy_is_fixed_link (struct fwnode_handle *fwnode) +{ +return false; +}#endif #endif /* __LINUX_FWNODE_MDIO_H */
drivers/net/mdio/fwnode_mdio.c +100 -0
109 lines not on this page · raw message
drivers/net/mdio/of_mdio.c +3 -76
94 lines not on this page · raw message
Signature · 1 line
2.29.0
PATCH v2 3/8 net: dsa: switch to device_/fwnode_ APIs
In reply to Marcin WojtasIn order to support both ACPI and DT, modify the generic DSA code to use device_/fwnode_ equivalent routines. Drop using port's dn field and use only fwnode - update all dependent drivers.
Because support for more generic fwnode is added, replace '_of' suffix with '_fw' in related routines. No functional change is introduced by this patch.
--- include/net/dsa.h | 2 +- net/dsa/dsa_priv.h | 4 +- drivers/net/dsa/mt7530.c | 2 +- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- drivers/net/dsa/qca8k.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- net/dsa/dsa2.c | 100 +++++++++++--------- net/dsa/port.c | 70 +++++++------- net/dsa/slave.c | 7 +- 9 files changed, 97 insertions(+), 94 deletions(-)
include/net/dsa.h +1 -1
@@ -302,7 +302,7 @@ struct dsa_port { u8 setup:1; -struct device_node *dn; +struct fwnode_handle *fwnode;unsigned int ageing_time;struct dsa_bridge *bridge;
net/dsa/dsa_priv.h +2 -2
@@ -285,8 +285,8 @@ int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,int dsa_port_mrp_del_ring_role (const struct dsa_port *dp,const struct switchdev_obj_ring_role_mrp *mrp);int dsa_port_phylink_create (struct dsa_port *dp); -int dsa_port_link_register_of (struct dsa_port *dp); -void dsa_port_link_unregister_of (struct dsa_port *dp); +int dsa_port_link_register_fw (struct dsa_port *dp); +void dsa_port_link_unregister_fw (struct dsa_port *dp);int dsa_port_hsr_join (struct dsa_port *dp,struct net_device *hsr);void dsa_port_hsr_leave (struct dsa_port *dp,struct net_device *hsr);int dsa_port_tag_8021q_vlan_add (struct dsa_port *dp,u16 vid,bool broadcast);
drivers/net/dsa/mt7530.c +1 -1
@@ -2232,7 +2232,7 @@ mt7530_setup(struct dsa_switch *ds)if (!dsa_is_unused_port (ds,5 )) { priv->p5_intf_sel =P5_INTF_SEL_GMAC5 ; - ret =of_get_phy_mode (dsa_to_port (ds,5 )->dn, &interface); + ret =of_get_phy_mode (to_of_node (dsa_to_port (ds,5 )->fwnode), &interface);if (ret && ret != -ENODEV )return ret; }else {
drivers/net/dsa/mv88e6xxx/chip.c +1 -1
@@ -3499,7 +3499,7 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) if (chip->info->ops->serdes_set_tx_amplitude) { if (dp) - phy_handle = of_parse_phandle(dp->dn, "phy-handle", 0); + phy_handle = of_parse_phandle(to_of_node(dp->fwnode), "phy-handle", 0); if (phy_handle && !of_property_read_u32(phy_handle, "tx-p2p-microvolt",
drivers/net/dsa/qca8k.c +1 -1
@@ -1517,7 +1517,7 @@ qca8k_parse_port_config(struct qca8k_priv *priv)continue ; dp =dsa_to_port (priv->ds, port); - port_dn = dp->dn; + port_dn =to_of_node (dp->fwnode); cpu_port_index++;if (!of_device_is_available (port_dn))
drivers/net/dsa/realtek/rtl8365mb.c +1 -1
@@ -887,7 +887,7 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_priv *priv, int port,return -ENODEV ; dp =dsa_to_port (priv->ds, port); - dn = dp->dn; + dn =to_of_node (dp->fwnode);/* Set the RGMII TX/RX delay *
net/dsa/dsa2.c +54 -46
259 lines not on this page · raw message
net/dsa/port.c +34 -36
184 lines not on this page · raw message
net/dsa/slave.c +2 -5
@@ -10,8 +10,6 @@#include <linux/phy.h> #include <linux/phy_fixed.h> #include <linux/phylink.h> -#include <linux/of_net.h> -#include <linux/of_mdio.h> #include <linux/mdio.h> #include <net/rtnetlink.h> #include <net/pkt_cls.h>
@@ -2228,7 +2226,6 @@ static int dsa_slave_phy_connect(struct net_device *slave_dev, int addr,static int dsa_slave_phy_setup (struct net_device *slave_dev) {struct dsa_port *dp =dsa_slave_to_port (slave_dev); -struct device_node *port_dn = dp->dn;struct dsa_switch *ds = dp->ds;u32 phy_flags =0 ;int ret;
@@ -2252,7 +2249,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)if (ds->ops->get_phy_flags) phy_flags = ds->ops->get_phy_flags (ds, dp->index); - ret =phylink_of_phy_connect (dp->pl, port_dn, phy_flags); + ret =phylink_fwnode_phy_connect (dp->pl, dp->fwnode, phy_flags);if (ret == -ENODEV && ds->slave_mii_bus) {/* We could not connect to a designated PHY or SFP, so try to * use the switch internal MDIO bus instead
@@ -2364,7 +2361,7 @@ int dsa_slave_create(struct dsa_port *port)SET_NETDEV_DEVTYPE (slave_dev, &dsa_type);SET_NETDEV_DEV (slave_dev, port->ds->dev); - slave_dev->dev.of_node = port->dn; +device_set_node (&slave_dev->dev, port->fwnode); slave_dev->vlan_features = master->vlan_features; p =netdev_priv (slave_dev);
Signature · 1 line
2.29.0
Andy Shevchenko
reviewerRe: [net-next: PATCH v2 3/8] net: dsa: switch to device_/fwnode_ APIs
Quoted 7 lines · Marcin Wojtas
In order to support both ACPI and DT, modify the generic DSA code to use device_/fwnode_ equivalent routines. Drop using port's dn field and use only fwnode - update all dependent drivers.
Because support for more generic fwnode is added, replace '_of' suffix with '_fw' in related routines. No functional change is introduced by this patch.
It's a bit too narrow text in the commit message, can you use more width?
...
drivers/net/dsa/mt7530.c mt7530_setup(struct dsa_switch *ds) · line 2235
Quoted 2 lines
drivers/net/dsa/mt7530.c +1
-1- ret =of_get_phy_mode (dsa_to_port (ds,5 )->dn, &interface); + ret =of_get_phy_mode (to_of_node (dsa_to_port (ds,5 )->fwnode), &interface);
So, I believe this is expected to be a temporary change and something like fwnode_get_phy_mode() is on its way, correct?
...
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) · line 3502
Quoted 2 lines
drivers/net/dsa/mv88e6xxx/chip.c +1
-1- phy_handle =of_parse_phandle (dp->dn,"phy-handle" ,0 ); + phy_handle =of_parse_phandle (to_of_node (dp->fwnode),"phy-handle" ,0 );
This can be translated to fwnode_find_reference(), but it might require more changes.
Actually you may start from converting drivers one-by-one to fwnode APIs (as much as it's possible), and then do with a library call. Up to you.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [net-next: PATCH v2 3/8] net: dsa: switch to device_/fwnode_ APIs
pt., 15 lip 2022 o 21:25 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 10 lines · Marcin Wojtas
Quoted 7 lines
In order to support both ACPI and DT, modify the generic DSA code to use device_/fwnode_ equivalent routines. Drop using port's dn field and use only fwnode - update all dependent drivers.
Because support for more generic fwnode is added, replace '_of' suffix with '_fw' in related routines. No functional change is introduced by this patch.
Quoted 2 lines
It's a bit too narrow text in the commit message, can you use more width?
Ok.
Quoted 8 lines
...
drivers/net/dsa/mt7530.c mt7530_setup(struct dsa_switch *ds) · line 2235
Quoted 2 lines
drivers/net/dsa/mt7530.c +1
-1- ret =of_get_phy_mode (dsa_to_port (ds,5 )->dn, &interface); + ret =of_get_phy_mode (to_of_node (dsa_to_port (ds,5 )->fwnode), &interface);So, I believe this is expected to be a temporary change and something like
fwnode_get_phy_mode()is on its way, correct?
I use fwnode_get_phy_mode even if this patch. I can do the conversion here in v3.
Quoted 7 lines
...
drivers/net/dsa/mv88e6xxx/chip.c static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port) · line 3502
Quoted 2 lines
drivers/net/dsa/mv88e6xxx/chip.c +1
-1- phy_handle =of_parse_phandle (dp->dn,"phy-handle" ,0 ); + phy_handle =of_parse_phandle (to_of_node (dp->fwnode),"phy-handle" ,0 );This can be translated to
fwnode_find_reference(), but it might require more changes.
Yes.
Quoted 4 lines
Actually you may start from converting drivers one-by-one to fwnode APIs (as much as it's possible), and then do with a library call. Up to you.
I'm dropping the dn and will try to keep the diff in the other drivers minimal (however, for 2 above cases I will consider of_ -> fwnode_ replacements). Except for mv88e6xxx, I can do only compile-check.
Best regards,
Marcin
PATCH v2 4/8 net: mvpp2: initialize port fwnode pointer
In reply to Marcin WojtasAs a preparation to switch the DSA subsystem from using of_find_net_device_by_node() to its more generic fwnode_ equivalent, the port's device structure should be updated with its fwnode pointer, similarly to of_node - see analogous commit c4053ef32208 ("net: mvpp2: initialize port of_node pointer").
This patch is required to prevent a regression before updating the DSA API on boards that connect the mvpp2 port to switch, such as Clearfog GT-8K or CN913x CEx7 Evaluation Board.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1 -1
@@ -6868,7 +6868,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, dev->min_mtu =ETH_MIN_MTU ;/* 9704 == 9728 - 20 and rounding to 8 */ dev->max_mtu =MVPP2_BM_JUMBO_PKT_SIZE ; - dev->dev.of_node = port_node; +device_set_node (&dev->dev, port_fwnode); port->pcs_gmac.ops = &mvpp2_phylink_gmac_pcs_ops; port->pcs_xlg.ops = &mvpp2_phylink_xlg_pcs_ops;
Signature · 1 line
2.29.0
PATCH v2 5/8 device property: introduce fwnode_dev_node_match
In reply to Marcin WojtasThis patch adds a new generic routine fwnode_dev_node_match that can be used e.g. as a callback for class_find_device(). It searches for the struct device corresponding to a struct fwnode_handle by iterating over device and its parents.
--- include/linux/property.h | 2 ++ drivers/base/property.c | 22 ++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/linux/property.h +2 -0
@@ -456,6 +456,8 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode,devcon_match_fn_t match, void **matches, unsigned int matches_len); +int fwnode_dev_node_match (struct device *dev,const void *data); +/* -------------------------------------------------------------------------- */ /* Software fwnode support - when HW description is incomplete or missing */
drivers/base/property.c +22 -0
@@ -1344,3 +1344,25 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode,return count_graph + count_ref; }EXPORT_SYMBOL_GPL (fwnode_connection_find_matches); + +/* +* fwnode_dev_node_match - look for a device matching the struct fwnode_handle +* @dev: the struct device to initiate the search +* @data: pointer to the fwnode_handle +* +* Looks up the device structure corresponding with the fwnode by iterating +* over @dev and its parents. +* The routine can be used e.g. as a callback for class_find_device(). +* +* Return: 1 - if match is found, 0 - otherwise. +*/ +int fwnode_dev_node_match (struct device *dev,const void *data) +{ +for (; dev; dev = dev->parent) { +if (device_match_fwnode (dev, data)) +return 1 ; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (fwnode_dev_node_match);
Signature · 1 line
2.29.0
Andy Shevchenko
reviewerRe: [net-next: PATCH v2 5/8] device property: introduce fwnode_dev_node_match
Quoted 5 lines · Marcin Wojtas
This patch adds a new generic routine
fwnode_dev_node_matchthat can be used e.g. as a callback forclass_find_device(). It searches for the struct device corresponding to a structfwnode_handleby iterating over device and its parents.
Implementation
1) misses the word 'parent';
2) located outside of the group of fwnode APIs operating on parents.
I would suggest to rename to fwnode_get_next_parent_node() and place near to fwnode_get_next_parent_dev() (either before or after, where it makes more sense).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [net-next: PATCH v2 5/8] device property: introduce fwnode_dev_node_match
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Marcin Wojtas
This patch adds a new generic routine
fwnode_dev_node_matchthat can be used e.g. as a callback forclass_find_device(). It searches for the struct device corresponding to a structfwnode_handleby iterating over device and its parents.
Quoted 7 lines
Implementation
1) misses the word 'parent';
2) located outside of the group of fwnode APIs operating on parents.I would suggest to rename to
fwnode_get_next_parent_node()and place near tofwnode_get_next_parent_dev()(either before or after, where it makes more sense).
And matching function will be after that:
return fwnode_get_next_parent_node(...) != NULL;
Think about it. Maybe current solution is good enough, just needs better naming (fwnode_match_parent_node()? Dunno).
P.S. Actually _get maybe misleading as we won't bump reference counting,
rather _find?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [net-next: PATCH v2 5/8] device property: introduce fwnode_dev_node_match
pt., 15 lip 2022 o 21:42 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Marcin Wojtas
Quoted 5 lines
This patch adds a new generic routine
fwnode_dev_node_matchthat can be used e.g. as a callback forclass_find_device(). It searches for the struct device corresponding to a structfwnode_handleby iterating over device and its parents.Implementation
1) misses the word 'parent';
I'm not sure. We don't necessarily look for parent device(s). We start with a struct device and if it matches the fwnode, success is returned immediately. Only otherwise we iterate over parent devices to find a match.
Quoted 1 line
Quoted 1 line
2) located outside of the group of fwnode APIs operating on parents.
I can shift it right below fwnode_get_nth_parent if you prefer.
Quoted 7 lines
Quoted 4 lines
I would suggest to rename to
fwnode_get_next_parent_node()and place near tofwnode_get_next_parent_dev()(either before or after, where it makes more sense).And matching function will be after that:
Quoted 8 lines
return fwnode_get_next_parent_node(...) != NULL;Think about it. Maybe current solution is good enough, just needs better naming (
fwnode_match_parent_node()? Dunno).
P.S. Actually_getmaybe misleading as we won't bump reference counting,
rather_find?
How about the following name:fwnode_find_dev_match()
?
Thanks,
Marcin
Andy Shevchenko
reviewerRe: [net-next: PATCH v2 5/8] device property: introduce fwnode_dev_node_match
Quoted 11 lines · Marcin Wojtas
pt., 15 lip 2022 o 21:42 Andy Shevchenko
<[email protected]> napisał(a):Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Marcin Wojtas
Quoted 5 lines
This patch adds a new generic routine
fwnode_dev_node_matchthat can be used e.g. as a callback forclass_find_device(). It searches for the struct device corresponding to a structfwnode_handleby iterating over device and its parents.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Implementation
1) misses the word 'parent';I'm not sure. We don't necessarily look for parent device(s). We start with a struct device and if it matches the fwnode, success is returned immediately. Only otherwise we iterate over parent devices to find a match.
Yes, you iterate over parents. 0 iterations doesn't change semantics of all cases, right?
Quoted 3 lines
Quoted 1 line
Quoted 1 line
2) located outside of the group of fwnode APIs operating on parents.
I can shift it right below
fwnode_get_nth_parentif you prefer.
Yes, please do.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
I would suggest to rename to
fwnode_get_next_parent_node()and place near tofwnode_get_next_parent_dev()(either before or after, where it makes more sense).And matching function will be after that:
return fwnode_get_next_parent_node(...) != NULL;Think about it. Maybe current solution is good enough, just needs better naming (
fwnode_match_parent_node()? Dunno).
Quoted 6 lines
Quoted 2 lines
P.S. Actually_getmaybe misleading as we won't bump reference counting,
rather_find?How about the following name:
fwnode_find_dev_match()
?
fwnode_find_parent_dev_match() LGTM, thanks!
You iterate over parents.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 6/8 net: core: switch to fwnode_find_net_device_by_node()
In reply to Marcin WojtasA helper function which allows getting the struct net_device pointer associated with a given device tree node can be more generic and also support alternative hardware description. Switch to fwnode_ and update the only existing caller in DSA subsystem.
For that purpose use newly added fwnode_dev_node_match helper routine.
--- include/linux/etherdevice.h | 1 + include/linux/of_net.h | 6 ----- net/core/net-sysfs.c | 25 ++++++-------------- net/dsa/dsa2.c | 3 ++- 4 files changed, 10 insertions(+), 25 deletions(-)
include/linux/etherdevice.h +1 -0
@@ -35,6 +35,7 @@ int nvmem_get_mac_address(struct device *dev, void *addrbuf);int device_get_mac_address (struct device *dev,char *addr);int device_get_ethdev_address (struct device *dev,struct net_device *netdev);int fwnode_get_mac_address (struct fwnode_handle *fwnode,char *addr); +struct net_device *fwnode_find_net_device_by_node (struct fwnode_handle *fwnode);u32 eth_get_headlen (const struct net_device *dev,const void *data,u32 len);__be16 eth_type_trans (struct sk_buff *skb,struct net_device *dev);
include/linux/of_net.h +0 -6
@@ -15,7 +15,6 @@ struct net_device;extern int of_get_phy_mode (struct device_node *np,phy_interface_t *interface);extern int of_get_mac_address (struct device_node *np,u8 *mac);int of_get_ethdev_address (struct device_node *np,struct net_device *dev); -extern struct net_device *of_find_net_device_by_node (struct device_node *np);#else static inline int of_get_phy_mode (struct device_node *np,phy_interface_t *interface)
@@ -32,11 +31,6 @@ static inline int of_get_ethdev_address(struct device_node *np, struct net_devic {return -ENODEV ; } - -static inline struct net_device *of_find_net_device_by_node (struct device_node *np) -{ -return NULL ; -}#endif #endif /* __LINUX_OF_NET_H */
net/core/net-sysfs.c +7 -18
@@ -6,6 +6,7 @@*/ #include <linux/capability.h> +#include <linux/etherdevice.h> #include <linux/kernel.h> #include <linux/netdevice.h> #include <linux/if_arp.h>
@@ -1935,38 +1936,26 @@ static struct class net_class __ro_after_init = { .get_ownership = net_get_ownership, }; -#ifdef CONFIG_OF -static int of_dev_node_match (struct device *dev,const void *data) -{ -for (; dev; dev = dev->parent) { -if (dev->of_node == data) -return 1 ; - } - -return 0 ; -} -/* -* of_find_net_device_by_node - lookup the net device for the device node -* @np: OF device node +* fwnode_find_net_device_by_node - lookup the net device for the device fwnode +* @fwnode: firmware node * -* Looks up the net_device structure corresponding with the device node. +* Looks up the net_device structure corresponding with the fwnode. * If successful, returns a pointer to the net_device with the embedded * struct device refcount incremented by one, or NULL on failure. The * refcount must be dropped when done with the net_device. */ -struct net_device *of_find_net_device_by_node (struct device_node *np) +struct net_device *fwnode_find_net_device_by_node (struct fwnode_handle *fwnode) {struct device *dev; - dev =class_find_device (&net_class,NULL , np, of_dev_node_match); + dev =class_find_device (&net_class,NULL , fwnode, fwnode_dev_node_match);if (!dev)return NULL ;return to_net_dev (dev); } -EXPORT_SYMBOL (of_find_net_device_by_node); -#endif +EXPORT_SYMBOL (fwnode_find_net_device_by_node);/* Delete sysfs entries but hold kobject reference until after all * netdev references are gone.
net/dsa/dsa2.c +2 -1
@@ -7,6 +7,7 @@*/ #include <linux/device.h> +#include <linux/etherdevice.h> #include <linux/err.h> #include <linux/list.h> #include <linux/netdevice.h>
@@ -1498,7 +1499,7 @@ static int dsa_port_parse_fw(struct dsa_port *dp, struct fwnode_handle *fwnode)struct net_device *master;const char *user_protocol; - master =of_find_net_device_by_node (to_of_node (ethernet)); + master =fwnode_find_net_device_by_node (ethernet);fwnode_handle_put (ethernet);if (!master)return -EPROBE_DEFER ;
Signature · 1 line
2.29.0
PATCH v2 7/8 net: mdio: introduce fwnode_mdiobus_register_device()
In reply to Marcin WojtasAs a preparation patch to extend MDIO capabilities in the ACPI world, introduce fwnode_mdiobus_register_device() to register non-PHY devices on the mdiobus.
Use the newly introduced routine instead of of_mdiobus_register_device().
--- include/linux/fwnode_mdio.h | 3 ++ drivers/net/mdio/fwnode_mdio.c | 29 ++++++++++++++++++ drivers/net/mdio/of_mdio.c | 32 +------------------- 3 files changed, 33 insertions(+), 31 deletions(-)
include/linux/fwnode_mdio.h +3 -0
@@ -16,6 +16,9 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,int fwnode_mdiobus_register_phy (struct mii_bus *bus,struct fwnode_handle *child,u32 addr); +int fwnode_mdiobus_register_device (struct mii_bus *mdio, +struct fwnode_handle *child,u32 addr); +int fwnode_phy_register_fixed_link (struct fwnode_handle *fwnode);void fwnode_phy_deregister_fixed_link (struct fwnode_handle *fwnode);
drivers/net/mdio/fwnode_mdio.c +29 -0
@@ -149,6 +149,35 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, }EXPORT_SYMBOL (fwnode_mdiobus_register_phy); +int fwnode_mdiobus_register_device (struct mii_bus *mdio, +struct fwnode_handle *child,u32 addr) +{ +struct mdio_device *mdiodev; +int rc; + + mdiodev =mdio_device_create (mdio, addr); +if (IS_ERR (mdiodev)) +return PTR_ERR (mdiodev); + +/* Associate the fwnode with the device structure so it +* can be looked up later. +*/ +device_set_node (&mdiodev->dev, child); + +/* All data is now stored in the mdiodev struct; register it. */ + rc =mdio_device_register (mdiodev); +if (rc) { +mdio_device_free (mdiodev); +fwnode_handle_put (child); +return rc; + } + +dev_dbg (&mdio->dev,"registered mdio device %p fwnode at address %i\n" , + child, addr); +return 0 ; +} +EXPORT_SYMBOL (fwnode_mdiobus_register_device); +/* * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must * support two bindings:
drivers/net/mdio/of_mdio.c +1 -31
@@ -48,36 +48,6 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,return fwnode_mdiobus_register_phy (mdio,of_fwnode_handle (child), addr); } -static int of_mdiobus_register_device (struct mii_bus *mdio, -struct device_node *child,u32 addr) -{ -struct fwnode_handle *fwnode =of_fwnode_handle (child); -struct mdio_device *mdiodev; -int rc; - - mdiodev =mdio_device_create (mdio, addr); -if (IS_ERR (mdiodev)) -return PTR_ERR (mdiodev); - -/* Associate the OF node with the device structure so it -* can be looked up later. -*/ -fwnode_handle_get (fwnode); -device_set_node (&mdiodev->dev, fwnode); - -/* All data is now stored in the mdiodev struct; register it. */ - rc =mdio_device_register (mdiodev); -if (rc) { -mdio_device_free (mdiodev); -of_node_put (child); -return rc; - } - -dev_dbg (&mdio->dev,"registered mdio device %pOFn at address %i\n" , - child, addr); -return 0 ; -} -/* The following is a list of PHY compatible strings which appear in * some DTBs. The compatible string is never matched against a PHY * driver, so is pointless. We only expect devices which are not PHYs
@@ -186,7 +156,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)if (of_mdiobus_child_is_phy (child)) rc =of_mdiobus_register_phy (mdio, child, addr);else - rc =of_mdiobus_register_device (mdio, child, addr); + rc =fwnode_mdiobus_register_device (mdio,of_fwnode_handle (child), addr);if (rc == -ENODEV ) dev_err(&mdio->dev,
Signature · 1 line
2.29.0
PATCH v2 8/8 net: dsa: mv88e6xxx: switch to device_/fwnode_ APIs
In reply to Marcin WojtasIn order to support both DT and ACPI in future, modify the mv88e6xx driver code to use device_/fwnode_ equivalent routines. No functional change is introduced by this patch.
--- drivers/net/dsa/mv88e6xxx/chip.c | 57 ++++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +27 -30
@@ -3312,7 +3312,7 @@ static int mv88e6xxx_setup_upstream_port(struct mv88e6xxx_chip *chip, int port)static int mv88e6xxx_setup_port (struct mv88e6xxx_chip *chip,int port) { -struct device_node *phy_handle =NULL ; +struct fwnode_handle *phy_handle =NULL ;struct dsa_switch *ds = chip->ds;struct dsa_port *dp;int tx_amp;
@@ -3499,15 +3499,15 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)if (chip->info->ops->serdes_set_tx_amplitude) {if (dp) - phy_handle =of_parse_phandle (to_of_node (dp->fwnode),"phy-handle" ,0 ); + phy_handle =fwnode_find_reference (dp->fwnode,"phy-handle" ,0 ); -if (phy_handle && !of_property_read_u32 (phy_handle, -"tx-p2p-microvolt" , - &tx_amp)) +if (!IS_ERR (phy_handle) && !fwnode_property_read_u32 (phy_handle, +"tx-p2p-microvolt" , + &tx_amp)) err = chip->info->ops->serdes_set_tx_amplitude (chip, port, tx_amp); -if (phy_handle) { -of_node_put (phy_handle); +if (!IS_ERR (phy_handle)) { +fwnode_handle_put (phy_handle);if (err)return err; }
@@ -3891,10 +3891,11 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val) }static int mv88e6xxx_mdio_register (struct mv88e6xxx_chip *chip, -struct device_node *np, +struct fwnode_handle *fwnode,bool external) {static int index; +struct device_node *np =to_of_node (fwnode);struct mv88e6xxx_mdio_bus *mdio_bus;struct mii_bus *bus;int err;
@@ -3973,18 +3974,18 @@ static void mv88e6xxx_mdios_unregister(struct mv88e6xxx_chip *chip) }static int mv88e6xxx_mdios_register (struct mv88e6xxx_chip *chip, -struct device_node *np) +struct fwnode_handle *fwnode) { -struct device_node *child; +struct fwnode_handle *child;int err;/* Always register one mdio bus for the internal/default mdio * bus. This maybe represented in the device tree, but is * optional. */ - child =of_get_child_by_name (np,"mdio" ); + child =fwnode_get_named_child_node (fwnode,"mdio" ); err =mv88e6xxx_mdio_register (chip, child, false); -of_node_put (child); +fwnode_handle_put (child);if (err)return err;
@@ -3992,13 +3993,13 @@ static int mv88e6xxx_mdios_register(struct mv88e6xxx_chip *chip,* which say they are compatible with the external mdio * bus. */ -for_each_available_child_of_node (np, child) { -if (of_device_is_compatible ( - child,"marvell,mv88e6xxx-mdio-external" )) { +fwnode_for_each_available_child_node (fwnode, child) { +if (fwnode_property_match_string (child,"compatible" , +"marvell,mv88e6xxx-mdio-external" ) ==0 ) { err =mv88e6xxx_mdio_register (chip, child, true);if (err) {mv88e6xxx_mdios_unregister (chip); -of_node_put (child); +fwnode_handle_put (child);return err; } }
@@ -6975,20 +6976,16 @@ static SIMPLE_DEV_PM_OPS(mv88e6xxx_pm_ops, mv88e6xxx_suspend, mv88e6xxx_resume);static int mv88e6xxx_probe (struct mdio_device *mdiodev) {struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data; +struct fwnode_handle *fwnode =dev_fwnode (&mdiodev->dev);const struct mv88e6xxx_info *compat_info =NULL ;struct device *dev = &mdiodev->dev; -struct device_node *np = dev->of_node;struct mv88e6xxx_chip *chip;int port;int err; -if (!np && !pdata) -return -EINVAL ; - -if (np) - compat_info =of_device_get_match_data (dev); - -if (pdata) { +if (fwnode) + compat_info =device_get_match_data (dev); +else if (pdata) { compat_info =pdata_device_get_match_data (dev);if (!pdata->netdev)
@@ -7045,9 +7042,9 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)mv88e6xxx_phy_init (chip);if (chip->info->ops->get_eeprom) { -if (np) -of_property_read_u32 (np,"eeprom-length" , - &chip->eeprom_len); +if (fwnode) +device_property_read_u32 (dev,"eeprom-length" , + &chip->eeprom_len);else chip->eeprom_len = pdata->eeprom_len; }
@@ -7058,8 +7055,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)if (err) goto out; -if (np) { - chip->irq =of_irq_get (np,0 ); +if (fwnode) { + chip->irq =fwnode_irq_get (fwnode,0 );if (chip->irq == -EPROBE_DEFER ) { err = chip->irq; goto out;
@@ -7097,7 +7094,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)if (err) goto out_g1_atu_prob_irq; - err =mv88e6xxx_mdios_register (chip, np); + err =mv88e6xxx_mdios_register (chip, fwnode);if (err) goto out_g1_vtu_prob_irq;
Signature · 1 line
2.29.0