Re: [net-next: PATCH v3 6/8] net: core: switch to fwnode_find_net_device_by_node()

From: Vladimir Oltean
Date: Wed Jul 27 2022 - 17:11:55 EST


On Wed, Jul 27, 2022 at 07:40:00PM +0200, Marcin Wojtas wrote:
> SET_NETDEV_DEV() fills net_device->dev.parent with &pdev->dev
> and in most cases it is sufficient apparently it is sufficient for
> fwnode_find_parent_dev_match (at least tests with mvneta case proves
> it's fine).

Indeed, mvneta works, which is a plain old platform device that hasn't
even been converted to fwnode, so why don't the others?

Well, as it turns out, it's one of the cases where I spoke to soon,
thinking I knew what was the problem why probing failed, before actually
debugging.

I thought there was no dmesg output from DSA at all, which would have
indicated an eternal -EPROBE_DEFER situation. But there's one tiny line
I had overlooked:

[ 5.094013] mscc_felix 0000:00:00.5: error -EINVAL: Failed to register DSA switch

This comes from here:

static int dsa_port_parse_fw(struct dsa_port *dp, struct fwnode_handle *fwnode)
{
struct fwnode_handle *ethernet = fwnode_find_reference(fwnode, "ethernet", 0);
bool link = fwnode_property_present(fwnode, "link");
const char *name = NULL;
int ret;

ret = fwnode_property_read_string(fwnode, "label", &name);
// if (ret)
// return ret;

dp->fwnode = fwnode;

The 'label' property of a port was optional, you've made it mandatory by accident.
It is used only by DSA drivers that register using platform data.

(side note, I can't believe you actually have a 'label' property for the
CPU port and how many people are in the same situation as you; you know
it isn't used for anything, right? how do we stop the cargo cult?)

> Can you please check applying following diff:
>
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -695,20 +695,22 @@ EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
> * 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;
> + else if (device_match_of_node(dev, to_of_node(data))
> + return 1;
> }
>
> return 0;
> }
> EXPORT_SYMBOL_GPL(fwnode_find_parent_dev_match);

So, nothing to do with device_match_fwnode() failing, that would have
been strange, come to think about it. Sorry for the noise here.

But looking at the deeper implementation of dev_fwnode() as:

struct fwnode_handle *dev_fwnode(struct device *dev)
{
return IS_ENABLED(CONFIG_OF) && dev->of_node ?
of_fwnode_handle(dev->of_node) : dev->fwnode;
}

I wonder, why did you have to modify mvpp2? It looks at dev->of_node
prior to returning dev->fwnode. It should work.