DSA: switch to fwnode_/device_
Subsystems (14)
v4 cover DSA: switch to fwnode_/device_
Hi,
After a longer while this is a re-spin of the DSA migration to fwnode_/device_ API.
It addresses all comments from the previous iteration - the details are summarized in the changelog section below. For reference, here is the discussion under v3.
https://lore.kernel.org/netdev/[email protected]/t/
The ultimate goal of these changes is to prepare the DSA to use ACPI in future, which works locally on my branches [1][2], however, this part needs to be handled separately on the lists, as discussed in v1.
The patchset is based and tested on top of pure net-next/main branch. Each commit was checked on:
* On EspressoBIN
* On SolidRun CN913x CEx7 Eval Board
Any comments or remarks will be appreciated.
Best regards,
Marcin
[1] https://github.com/semihalf-wojtas-marcin/Linux-Kernel/commits/dsa-acpi-dev
[2] https://github.com/semihalf-wojtas-marcin/edk2-platforms/commits/dsa-acpi-v2
Changelog v3 -> v4:
1/8:
* Improve commit message.
2/8:
* Improve handling the old 'fixed-link' binding in fwnode_phy_is_fixed_link()
* Stop shadowing the real error codes in fwnode_phy_register_fixed_link()
3/8
* Make "label" property optional again
* Fix mt7530 compile error reported by kernel test robot <[email protected]>
* Simplify code update in mv88e6xxx
4/8
* Improve commit message
5/8
* Improve commit message
7/8
* Update dev_dbg message
8/8
* Move fwnode declaration
* Simplify obtaining match_data
Changelog v2 -> v3:
1/8:
* Replace forward declaration s/device_node/fwnode_handle/ in include/linux/phy_fixed.h
* Add Florian's RB
* 3/8:
* Extend lines width in the commit message.
* While dropping dp->dn fields in the drivers, switch to fwnode_ API in the updated places.
* 5/8:
* Update routine name to fwnode_find_parent_dev_match()
* Improve comment section
* Move the definition adjacent to a group of fwnode APIs operating on parents
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_find_parent_dev_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 | 6 +- include/linux/property.h | 1 + include/net/dsa.h | 2 +- net/dsa/port.h | 4 +- drivers/base/property.c | 23 ++++ drivers/net/dsa/mt7530.c | 6 +- drivers/net/dsa/mv88e6xxx/chip.c | 57 ++++----- drivers/net/dsa/qca/qca8k-8xxx.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- drivers/net/mdio/fwnode_mdio.c | 125 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 112 +----------------- drivers/net/phy/fixed_phy.c | 39 +++--- net/core/net-sysfs.c | 25 ++-- net/dsa/dsa.c | 118 +++++++++--------- net/dsa/port.c | 85 +++++++------ net/dsa/slave.c | 7 +- 20 files changed, 341 insertions(+), 304 deletions(-)
Signature · 1 line
2.29.0
PATCH v4 1/8 net: phy: fixed_phy: switch to fwnode_ API
Allow 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 | 6 +-- drivers/net/mdio/of_mdio.c | 2 +- drivers/net/phy/fixed_phy.c | 39 +++++++------------- 3 files changed, 18 insertions(+), 29 deletions(-)
include/linux/phy_fixed.h +3 -3
@@ -12,7 +12,7 @@ struct fixed_phy_status {int asym_pause; }; -struct device_node ; +struct fwnode_handle ;struct gpio_desc ;struct net_device ;
@@ -22,7 +22,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,
@@ -41,7 +41,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
@@ -423,7 +423,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
PATCH v4 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 | 96 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 118 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 +96 -0
105 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
Russell King (Oracle)
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Quoted 4 lines · Marcin Wojtas
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.
Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Vladimir Oltean
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Quoted 8 lines · Russell King (Oracle)
Quoted 4 lines · Marcin Wojtas
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Would it be even better if DSA had some driver-level prerequisites to impose for ACPI support - like phylink support rather than adjust_link - and we would simply branch off to a dsa_shared_port_link_register_acpi() function, leaving the current dsa_shared_port_link_register_of() alone, with all its workarounds and hacks? I don't believe that carrying all that logic over to a common fwnode based API is the proper way forward.
Andrew Lunn
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Quoted 10 lines · Vladimir Oltean
Quoted 8 lines · Russell King (Oracle)
Quoted 4 lines · Marcin Wojtas
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Quoted 6 lines
Would it be even better if DSA had some driver-level prerequisites to impose for ACPI support - like phylink support rather than
adjust_link- and we would simply branch off to adsa_shared_port_link_register_acpi()function, leaving the currentdsa_shared_port_link_register_of()alone, with all its workarounds and hacks? I don't believe that carrying all that logic over to a common fwnode based API is the proper way forward.
I agree with you there, here is little attempt to make a clean ACPI binding. Most of the attempts to add ACPI support seem to try to take the short cut for just search/replace of_ with fwnode_. And we then have to push back and say no, and generally it then goes quiet.
Marcin, please approach this from the other end. Please document in Documentation/firmware-guide/acpi/dsd what a clean binding should look like, and then try to implement it.
Andrew
Re: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Hi Andrew and Vladimir,
pon., 16 sty 2023 o 23:04 Andrew Lunn <[email protected]> napisał(a):
Quoted 12 lines · Vladimir Oltean
Quoted 10 lines · Russell King (Oracle)
Quoted 8 lines · Marcin Wojtas
Quoted 4 lines
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Quoted 6 lines
Quoted 6 lines
Would it be even better if DSA had some driver-level prerequisites to impose for ACPI support - like phylink support rather than
adjust_link- and we would simply branch off to adsa_shared_port_link_register_acpi()function, leaving the currentdsa_shared_port_link_register_of()alone, with all its workarounds and hacks? I don't believe that carrying all that logic over to a common fwnode based API is the proper way forward.
In the past couple of years, a number of subsystems have migrated to a more generic HW description abstraction (e.g. a big chunk of network, pinctrl, gpio). ACPI aside, with this patchset one can even try to describe the switch topology with the swnode (I haven't tried that though). I fully agree that there should be no 0-day baggage in the DSA ACPI binding (FYI the more fwnode- version of the dsa_shared_port_validate_of() cought one issue in the WIP ACPI description in my setup). On the other hand, I find fwnode_/device_ APIs really helpful for most of the cases - ACPI/OF/swnode differences can be hidden to a generic layer and the need of maintaining separate code paths related to the hardware description on the driver/subsystem level is minimized. An example could be found in v1 of this series, the last 4 patches in [1] show that it can be done in a simple / seamless way, especially given the ACPI (fwnode) PHY description in phylink is already settled and widely used. I am aware at the end of the day, after final review all this can be more complex.
I expect that the actual DSA ACPI support acceptance will require a lot of discussions and decisions, on whether certain solutions are worth migrating from OF world or require spec modification. For now my goal was to migrate to a more generic HW description API, and so to allow possible follow-up ACPI-related modifications, and additions to be extracted and better tracked.
Quoted 5 lines
I agree with you there, here is little attempt to make a clean ACPI binding. Most of the attempts to add ACPI support seem to try to take the short cut for just search/replace
of_withfwnode_. And we then have to push back and say no, and generally it then goes quiet.
In most cases, the devices' description is pretty straightforward:
* a node (single or with some children), resources (mem, irqs), mmio address space, optionally address on a bus and a couple of properties The DSDT/SSDT tables are very well suited for this. In case of separate, contained drivers that is also really easy to maintain.
However, I fully understand your concerns and caution before blessing any change related to subsystem/generic code. Therefore ACPI support addition was split after v1 (refer to discussion in [1]) and will require ACPI maintainers' input and guidelines.
Quoted 5 lines
Marcin, please approach this from the other end. Please document in
Documentation/firmware-guide/acpi/dsdwhat a clean binding should look like, and then try to implement it.
This is how I initially approached this (original submission: [2]; a bit updated version, working on top of the current patchset: [3]). We then agreed that in order to remove a bit hacky mitigation of the double ACPI scan problem, an MDIOSerialBus _CRS method should be defined in the ACPI spec, similar to the I2CSerialBus/SPISerialBus/UARTSerialBus. I am going to submit the first version for review in the coming days. The DSA purely ACPI-related changes would be updated and submitted, once the method is accepted.
Best regards,
Marcin
[1] https://www.spinics.net/lists/netdev/msg827337.html
[2] https://www.spinics.net/lists/netdev/msg827345.html
[3] https://github.com/semihalf-wojtas-marcin/Linux-Kernel/commit/e017e69c0eda18747029bfe0c335df204670ba59
Vladimir Oltean
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Quoted 17 lines · Marcin Wojtas
In the past couple of years, a number of subsystems have migrated to a more generic HW description abstraction (e.g. a big chunk of network, pinctrl, gpio). ACPI aside, with this patchset one can even try to describe the switch topology with the swnode (I haven't tried that though). I fully agree that there should be no 0-day baggage in the DSA ACPI binding (FYI the more fwnode- version of the
dsa_shared_port_validate_of()cought one issue in the WIP ACPI description in my setup). On the other hand, I find fwnode_/device_ APIs really helpful for most of the cases - ACPI/OF/swnode differences can be hidden to a generic layer and the need of maintaining separate code paths related to the hardware description on the driver/subsystem level is minimized. An example could be found in v1 of this series, the last 4 patches in [1] show that it can be done in a simple / seamless way, especially given the ACPI (fwnode) PHY description in phylink is already settled and widely used. I am aware at the end of the day, after final review all this can be more complex.
Quoted 6 lines
I expect that the actual DSA ACPI support acceptance will require a lot of discussions and decisions, on whether certain solutions are worth migrating from OF world or require spec modification. For now my goal was to migrate to a more generic HW description API, and so to allow possible follow-up ACPI-related modifications, and additions to be extracted and better tracked.
I have a simple question.
If you expect that the DSA ACPI bindings will require a lot of discussions, then how do you know that what you convert to fwnode now will be needed later, and why do you insist to mechanically convert everything to fwnode without having that discussion first?
You see the lack of a need to maintain separate code paths between OF and ACPI as useful. Yet the DSA maintainers don't, and in some cases this is specifically what they want to avoid. So a mechanical conversion will end up making absolutely no progress.
Re: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Hi,
wt., 17 sty 2023 o 17:34 Vladimir Oltean <[email protected]> napisał(a):
Quoted 26 lines · Marcin Wojtas
Quoted 17 lines
In the past couple of years, a number of subsystems have migrated to a more generic HW description abstraction (e.g. a big chunk of network, pinctrl, gpio). ACPI aside, with this patchset one can even try to describe the switch topology with the swnode (I haven't tried that though). I fully agree that there should be no 0-day baggage in the DSA ACPI binding (FYI the more fwnode- version of the
dsa_shared_port_validate_of()cought one issue in the WIP ACPI description in my setup). On the other hand, I find fwnode_/device_ APIs really helpful for most of the cases - ACPI/OF/swnode differences can be hidden to a generic layer and the need of maintaining separate code paths related to the hardware description on the driver/subsystem level is minimized. An example could be found in v1 of this series, the last 4 patches in [1] show that it can be done in a simple / seamless way, especially given the ACPI (fwnode) PHY description in phylink is already settled and widely used. I am aware at the end of the day, after final review all this can be more complex.Quoted 6 lines
I expect that the actual DSA ACPI support acceptance will require a lot of discussions and decisions, on whether certain solutions are worth migrating from OF world or require spec modification. For now my goal was to migrate to a more generic HW description API, and so to allow possible follow-up ACPI-related modifications, and additions to be extracted and better tracked.
Quoted 7 lines
I have a simple question.
If you expect that the DSA ACPI bindings will require a lot of discussions, then how do you know that what you convert to fwnode now will be needed later, and why do you insist to mechanically convert everything to fwnode without having that discussion first?
Ok, let me clarify. From the technical standpoint, I think it is fairly easy and to a very big extent, we should be able to reuse, what is already existing - I made it work with a really minimal set of changes, using a standard nodes' hierarchy and generic methods in the ACPI tables. As more difficult, I consider getting this solution accepted by the ACPI and the network subsystem maintainers, also given the OF quirks/legacy stuff, that apparently needs to be ruled out in such circumstances. However, I perceive a preparation step, with migrating to the more generic HW description API in the generic net/dsa, as a sort of improvement, but I get your point and I will wait with resubmitting these changes again.
Quoted 4 lines
You see the lack of a need to maintain separate code paths between OF and ACPI as useful. Yet the DSA maintainers don't, and in some cases this is specifically what they want to avoid. So a mechanical conversion will end up making absolutely no progress.
Fair enough. I'll keep it on hold until MDIOSerialBus gets accepted and repost a bigger, combined patchset with all changes like in the v1.
Best regards,
Marcin
Andrew Lunn
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
In reply to Marcin WojtasQuoted 22 lines · Marcin Wojtas
Hi Andrew and Vladimir,
pon., 16 sty 2023 o 23:04 Andrew Lunn <[email protected]> napisał(a):
Quoted 12 lines · Vladimir Oltean
Quoted 10 lines · Russell King (Oracle)
Quoted 8 lines · Marcin Wojtas
Quoted 4 lines
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Quoted 6 lines
Quoted 6 lines
Would it be even better if DSA had some driver-level prerequisites to impose for ACPI support - like phylink support rather than
adjust_link- and we would simply branch off to adsa_shared_port_link_register_acpi()function, leaving the currentdsa_shared_port_link_register_of()alone, with all its workarounds and hacks? I don't believe that carrying all that logic over to a common fwnode based API is the proper way forward.
Quoted 12 lines
In the past couple of years, a number of subsystems have migrated to a more generic HW description abstraction (e.g. a big chunk of network, pinctrl, gpio). ACPI aside, with this patchset one can even try to describe the switch topology with the swnode (I haven't tried that though). I fully agree that there should be no 0-day baggage in the DSA ACPI binding (FYI the more fwnode- version of the
dsa_shared_port_validate_of()cought one issue in the WIP ACPI description in my setup). On the other hand, I find fwnode_/device_ APIs really helpful for most of the cases - ACPI/OF/swnode differences can be hidden to a generic layer and the need of maintaining separate code paths related to the hardware description on the driver/subsystem level is minimized.
It looks like we are heading towards three different descriptions. OF, ACPI and swnode. Each is likely to be different. OF has a lot of history in it, deprecated things etc, which should not appear in the others. So i see a big ugly block of code for the OF binding, and hopefully clean and tidy code for ACPI binding and a clean and tidy bit of code for swmode.,
It would be nice if the results of that parsing could be presented to the drivers in a uniform way, so the driver itself does not need to care where the information came from. But to me it is clear that this uniform layer has no direct access to the databases, since the database as are different.
Andrew
A message that is not in the archive (sent off-list or not yet received): CAPv3WKcbuY0kmM0trfS++at=r4KhCsp2bZ1kBL2r+-YJe=kE3w@mail.gmail.com
Russell King (Oracle)
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
Hi Marcin,
Quoted 15 lines · Marcin Wojtas
Hi Russell,
pon., 16 sty 2023 o 18:50 Russell King (Oracle) <[email protected]> napisał(a):
Quoted 10 lines · Marcin Wojtas
Quoted 4 lines
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Quoted 7 lines
,
This patchset did not intend to introduce any functional change, simply switch to a more generic HW description abstraction. Killing of/fwnode_phy_(de)register_fixed_link entirely seems to be a challenge, as there are a lot of users beyond the DSA. Otoh I see a value in having of_/fwnode_phy_is_fixed_link check, afaik there is no equivalent in phylink...
Phylink provides a much improved implementation of fixed-link that is way more flexible than the phylib approach - it can implement speeds in excess of 1G. DSA already supports phylink with modern updated drivers that do not use the "adjust_link" implementation.
What I'm proposing is that we don't bring the baggage of the phylib based fixed link forwards into fwnode, and leave this to be DT-only. I think this is what Andrew and Vladimir have also said.
Thanks.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
wt., 17 sty 2023 o 18:58 Russell King (Oracle) <[email protected]> napisał(a):
Quoted 27 lines
Hi Marcin,
Quoted 15 lines · Marcin Wojtas
Hi Russell,
pon., 16 sty 2023 o 18:50 Russell King (Oracle) <[email protected]> napisał(a):
Quoted 10 lines · Marcin Wojtas
Quoted 4 lines
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Would it be better to let the fixed-link PHY die, and have everyone use the more flexible fixed link implementation in phylink?
Quoted 7 lines
,
This patchset did not intend to introduce any functional change, simply switch to a more generic HW description abstraction. Killing of/fwnode_phy_(de)register_fixed_link entirely seems to be a challenge, as there are a lot of users beyond the DSA. Otoh I see a value in having of_/fwnode_phy_is_fixed_link check, afaik there is no equivalent in phylink...
Quoted 9 lines
Phylink provides a much improved implementation of fixed-link that is way more flexible than the phylib approach - it can implement speeds in excess of 1G. DSA already supports phylink with modern updated drivers that do not use the "
adjust_link" implementation.What I'm proposing is that we don't bring the baggage of the phylib based fixed link forwards into fwnode, and leave this to be DT-only. I think this is what Andrew and Vladimir have also said.
Ok, thanks for clarifying.
Best regards,
Marcin
Andrew Lunn
maintainerRe: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
In reply to Marcin WojtasQuoted 35 lines
drivers/net/mdio/fwnode_mdio.c +35
-0+int fwnode_phy_register_fixed_link (struct fwnode_handle *fwnode) +{ +struct fixed_phy_status status = {}; +struct fwnode_handle *fixed_link_node; +u32 fixed_link_prop[5 ]; +const char *managed; +int rc; + +if (fwnode_property_read_string (fwnode,"managed" , &managed) ==0 && +strcmp (managed,"in-band-status" ) ==0 ) { +/* status is zeroed, namely its .link member */ + goto register_phy; + } + +/* New binding */ + fixed_link_node =fwnode_get_named_child_node (fwnode,"fixed-link" ); +if (fixed_link_node) { + status.link =1 ; + status.duplex =fwnode_property_present (fixed_link_node, +"full-duplex" ); + rc =fwnode_property_read_u32 (fixed_link_node,"speed" , + &status.speed); +if (rc) { +fwnode_handle_put (fixed_link_node); +return rc; + } + status.pause =fwnode_property_present (fixed_link_node,"pause" ); + status.asym_pause =fwnode_property_present (fixed_link_node, +"asym-pause" ); +fwnode_handle_put (fixed_link_node); + + goto register_phy; + } + +/* Old binding */
drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 263
Quoted 10 lines
drivers/net/mdio/fwnode_mdio.c +10
-0+ rc =fwnode_property_read_u32_array (fwnode,"fixed-link" , fixed_link_prop, +ARRAY_SIZE (fixed_link_prop)); +if (rc) +return rc; + + status.link =1 ; + status.duplex = fixed_link_prop[1 ]; + status.speed = fixed_link_prop[2 ]; + status.pause = fixed_link_prop[3 ]; + status.asym_pause = fixed_link_prop[4 ];
This is one example of the issue i just pointed out. The "Old binding" has been deprecated for years. Maybe a decade? There is no reason it should be used in ACPI.
Andrew
Re: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_
In reply to Marcin WojtasHi Marcin,
Quoted 34 lines · Marcin Wojtas
fixed-link PHYs API is used by DSA and a number of drivers and was depending on
of_. Switch tofwnode_so to make it hardware description agnostic and allow to be used in ACPI world as well.Signed-off-by Marcin Wojtas <[email protected]>--- include/linux/fwnode_mdio.h | 19 ++++ drivers/net/mdio/fwnode_mdio.c | 96 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 118 insertions(+), 76 deletions(-)#endif /*
__LINUX_FWNODE_MDIO_H*/drivers/net/mdio/fwnode_mdio.c +4
-0@@ -10,6 +10,7 @@#include <linux/fwnode_mdio.h> #include <linux/of.h> #include <linux/phy.h> +#include <linux/phy_fixed.h> #include <linux/pse-pd/pse.h> MODULE_AUTHOR ("Calvin Johnson <[email protected]>" );@@ -185,3 +186,98 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return rc; }EXPORT_SYMBOL (fwnode_mdiobus_register_phy); + +/* +* fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link()
Quoted 7 lines
must
+ * support two bindings:
+ * - the old binding, where 'fixed-link' was a property with 5
+ * cells encoding various information about the fixed PHY
+ * - the new binding, where 'fixed-link' is a sub-node of the
+ * Ethernet device.
+ */
networking comment style
Quoted 17 lines
drivers/net/mdio/fwnode_mdio.c +7
-0+bool fwnode_phy_is_fixed_link (struct fwnode_handle *fwnode) +{ +struct fwnode_handle *fixed_link_node; +const char *managed; + +/* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link");
drivers/net/mdio/fwnode_mdio.c +6
-0+if (fixed_link_node) { +fwnode_handle_put (fixed_link_node); +return true; + } + + if (fwnode_property_read_string(fwnode, "managed", &managed) ==0 &&
drivers/net/mdio/fwnode_mdio.c +2
-0+ strcmp(managed, "auto") != 0) +return true;
drivers/net/mdio/fwnode_mdio.c int fwnode_mdiobus_register_phy(struct mii_bus *bus, · line 222
Quoted 10 lines
drivers/net/mdio/fwnode_mdio.c +10
-0+ +/* Old binding */ +return fwnode_property_count_u32 (fwnode,"fixed-link" ) ==5 ; +} +EXPORT_SYMBOL (fwnode_phy_is_fixed_link); + +int fwnode_phy_register_fixed_link (struct fwnode_handle *fwnode) +{ +struct fixed_phy_status status = {}; +struct fwnode_handle *fixed_link_node;
Reverse christmas tree
Quoted 58 lines
drivers/net/mdio/fwnode_mdio.c +5
-0+u32 fixed_link_prop[5 ]; +const char *managed; +int rc; + + if (fwnode_property_read_string(fwnode, "managed", &managed) ==0 &&
drivers/net/mdio/fwnode_mdio.c +7
-0+ strcmp(managed, "in-band-status") == 0) { +/* status is zeroed, namely its .link member */ + goto register_phy; + } + +/* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link");
drivers/net/mdio/fwnode_mdio.c +3
-0+if (fixed_link_node) { + status.link =1 ; + status.duplex =fwnode_property_present(fixed_link_node,
drivers/net/mdio/fwnode_mdio.c +8
-0+ "full-duplex"); + rc =fwnode_property_read_u32 (fixed_link_node,"speed" , + &status.speed); +if (rc) { +fwnode_handle_put (fixed_link_node); +return rc; + } + status.pause = fwnode_property_present(fixed_link_node,"pause");
drivers/net/mdio/fwnode_mdio.c +1
-0+ status.asym_pause =fwnode_property_present(fixed_link_node,
drivers/net/mdio/fwnode_mdio.c +1
-0+ "asym-pause");
drivers/net/mdio/fwnode_mdio.c +7
-0+fwnode_handle_put (fixed_link_node); + + goto register_phy; + } + +/* Old binding */ + rc = fwnode_property_read_u32_array(fwnode, "fixed-link",
fixed_link_prop,drivers/net/mdio/fwnode_mdio.c +1
-0+ARRAY_SIZE (fixed_link_prop));
drivers/net/mdio/fwnode_mdio.c +11
-0+if (rc) +return rc; + + status.link =1 ; + status.duplex = fixed_link_prop[1 ]; + status.speed = fixed_link_prop[2 ]; + status.pause = fixed_link_prop[3 ]; + status.asym_pause = fixed_link_prop[4 ]; + +register_phy: + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status,fwnode));
drivers/net/mdio/fwnode_mdio.c +3
-0+} +EXPORT_SYMBOL (fwnode_phy_register_fixed_link); +
PATCH v4 3/8 net: dsa: switch to device_/fwnode_ APIs
In reply to Marcin WojtasIn order to support both DT and ACPI in future, 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/port.h | 4 +- drivers/net/dsa/mt7530.c | 6 +- drivers/net/dsa/mv88e6xxx/chip.c | 16 +-- drivers/net/dsa/qca/qca8k-8xxx.c | 2 +- drivers/net/dsa/realtek/rtl8365mb.c | 2 +- net/dsa/dsa.c | 117 +++++++++++--------- net/dsa/port.c | 85 +++++++------- net/dsa/slave.c | 7 +- 9 files changed, 120 insertions(+), 121 deletions(-)
include/net/dsa.h +1 -1
@@ -300,7 +300,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/port.h +2 -2
@@ -101,8 +101,8 @@ 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);void dsa_port_phylink_destroy (struct dsa_port *dp); -int dsa_shared_port_link_register_of (struct dsa_port *dp); -void dsa_shared_port_link_unregister_of (struct dsa_port *dp); +int dsa_shared_port_link_register_fw (struct dsa_port *dp); +void dsa_shared_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 +4 -2
@@ -2235,8 +2235,10 @@ 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); -if (ret && ret != -ENODEV ) + ret =fwnode_get_phy_mode (dsa_to_port (ds,5 )->fwnode); +if (ret >=0 ) + interface = ret; +else if (ret != -ENODEV )return ret; }else {/* Scan the ethernet nodes. look for GMAC1, lookup used phy */
drivers/net/dsa/mv88e6xxx/chip.c +6 -10
@@ -3285,7 +3285,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;phy_interface_t mode;struct dsa_port *dp;
@@ -3509,18 +3509,14 @@ 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 =fwnode_find_reference (dp->fwnode,"phy-handle" ,0 ); -if (phy_handle && !of_property_read_u32 (phy_handle, -"tx-p2p-microvolt" , - &tx_amp)) +if (!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 (err) -return err; - } +fwnode_handle_put (phy_handle); +if (err) +return err; }/* Port based VLAN map: give each port the same default address
drivers/net/dsa/qca/qca8k-8xxx.c +1 -1
@@ -1088,7 +1088,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/dsa.c +63 -54
286 lines not on this page · raw message
net/dsa/port.c +40 -45
211 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>
@@ -2309,7 +2307,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;
@@ -2333,7 +2330,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
@@ -2455,7 +2452,7 @@ int dsa_slave_create(struct dsa_port *port)SET_NETDEV_DEV (slave_dev, port->ds->dev);SET_NETDEV_DEVLINK_PORT (slave_dev, &port->devlink_port); - 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
PATCH v4 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, and later to allow ACPI description, update the port's device structure also with its fwnode pointer.
--- 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
@@ -6884,7 +6884,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
Re: [net-next: PATCH v4 4/8] net: mvpp2: initialize port fwnode pointer
Quoted 4 lines · Marcin Wojtas
As a preparation to switch the DSA subsystem from using
of_find_net_device_by_node()to its more genericfwnode_equivalent, and later to allow ACPI description, update the port's device structure also with its fwnode pointer.
I believe this patch worth to be submitted even before core of this series. FWIW,
Quoted 21 lines
Signed-off-by Marcin Wojtas <[email protected]>--- 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@@ -6884,7 +6884,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
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 5/8 device property: introduce fwnode_find_parent_dev_match
In reply to Marcin WojtasAdd a new generic routine fwnode_find_parent_dev_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 | 1 + drivers/base/property.c | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/linux/property.h +1 -0
@@ -109,6 +109,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);unsigned int fwnode_count_parents (const struct fwnode_handle *fwn);struct fwnode_handle *fwnode_get_nth_parent (struct fwnode_handle *fwn,unsigned int depth); +int fwnode_find_parent_dev_match (struct device *dev,const void *data);bool fwnode_is_ancestor_of (struct fwnode_handle *ancestor,struct fwnode_handle *child);struct fwnode_handle *fwnode_get_next_child_node (const struct fwnode_handle *fwnode,struct fwnode_handle *child);
drivers/base/property.c +23 -0
@@ -693,6 +693,29 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, }EXPORT_SYMBOL_GPL (fwnode_get_nth_parent); +/** +* fwnode_find_parent_dev_match - look for a device matching the struct fwnode_handle +* @dev: the struct device to initiate the search +* @data: pointer passed for comparison +* +* 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(). +* +* Returns: %1 - match is found +* %0 - match not found +*/ +int fwnode_find_parent_dev_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_find_parent_dev_match); +/** * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child * @ancestor: Firmware which is tested for being an ancestor
Signature · 1 line
2.29.0
Re: [net-next: PATCH v4 5/8] device property: introduce fwnode_find_parent_dev_match
Quoted 4 lines · Marcin Wojtas
Add a new generic routine
fwnode_find_parent_dev_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.
If it helps you, I have no objections, hence
Quoted 55 lines
Signed-off-by Marcin Wojtas <[email protected]>--- include/linux/property.h | 1 + drivers/base/property.c | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+)include/linux/property.h +1
-0@@ -109,6 +109,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);unsigned int fwnode_count_parents (const struct fwnode_handle *fwn);struct fwnode_handle *fwnode_get_nth_parent (struct fwnode_handle *fwn,unsigned int depth); +int fwnode_find_parent_dev_match (struct device *dev,const void *data);bool fwnode_is_ancestor_of (struct fwnode_handle *ancestor,struct fwnode_handle *child);struct fwnode_handle *fwnode_get_next_child_node (const struct fwnode_handle *fwnode,struct fwnode_handle *child);drivers/base/property.c +23
-0@@ -693,6 +693,29 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode, }EXPORT_SYMBOL_GPL (fwnode_get_nth_parent); +/** +* fwnode_find_parent_dev_match - look for a device matching the struct fwnode_handle +* @dev: the struct device to initiate the search +* @data: pointer passed for comparison +* +* 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(). +* +* Returns: %1 - match is found +* %0 - match not found +*/ +int fwnode_find_parent_dev_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_find_parent_dev_match); +/** * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child * @ancestor: Firmware which is tested for being an ancestor Signature · 1 line
2.29.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v4 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 the DSA subsystem). For that purpose use newly added fwnode_find_parent_dev_match routine.
--- include/linux/etherdevice.h | 1 + include/linux/of_net.h | 6 ----- net/core/net-sysfs.c | 25 ++++++-------------- net/dsa/dsa.c | 5 ++-- 4 files changed, 11 insertions(+), 26 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
@@ -16,7 +16,6 @@ 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);extern int of_get_mac_address_nvmem (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)
@@ -38,11 +37,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_find_parent_dev_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/dsa.c +3 -2
@@ -9,6 +9,7 @@#include <linux/device.h> #include <linux/err.h> +#include <linux/etherdevice.h> #include <linux/list.h> #include <linux/module.h> #include <linux/netdevice.h>
@@ -374,7 +375,7 @@ struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst)if (IS_ERR (ethernet))return NULL ; - master =of_find_net_device_by_node (to_of_node (ethernet)); + master =fwnode_find_net_device_by_node (ethernet);fwnode_handle_put (ethernet);return master;
@@ -1233,7 +1234,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 v4 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 | 33 +------------------- 3 files changed, 33 insertions(+), 32 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
@@ -187,6 +187,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) { +device_set_node (&mdiodev->dev,NULL ); +mdio_device_free (mdiodev); +return rc; + } + +dev_dbg (&mdio->dev,"registered mdio device %pfw 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 -32
@@ -48,37 +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) { -device_set_node (&mdiodev->dev,NULL ); -fwnode_handle_put (fwnode); -mdio_device_free (mdiodev); -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
@@ -187,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 v4 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 | 41 +++++++++----------- 1 file changed, 19 insertions(+), 22 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +19 -22
@@ -3932,10 +3932,11 @@ static int mv88e6xxx_mdio_write_c45(struct mii_bus *bus, int phy, int devad, }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;
@@ -4016,18 +4017,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;
@@ -4035,13 +4036,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; } }
@@ -7096,18 +7097,14 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)struct dsa_mv88e6xxx_pdata *pdata = mdiodev->dev.platform_data;const struct mv88e6xxx_info *compat_info =NULL ;struct device *dev = &mdiodev->dev; -struct device_node *np = dev->of_node; +struct fwnode_handle *fwnode =dev_fwnode (dev);struct mv88e6xxx_chip *chip;int port;int err; -if (!np && !pdata) -return -EINVAL ; - -if (np) - compat_info =of_device_get_match_data (dev); + compat_info =device_get_match_data (dev); -if (pdata) { +if (!compat_info && pdata) { compat_info =pdata_device_get_match_data (dev);if (!pdata->netdev)
@@ -7164,9 +7161,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; }
@@ -7177,8 +7174,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;
@@ -7216,7 +7213,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