[PATCH 06/16] PCI: of: Set fwnode.dev of newly created PCI device nodes

Herve Codina posted 16 patches 10 months ago
There is a newer version of this series
[PATCH 06/16] PCI: of: Set fwnode.dev of newly created PCI device nodes
Posted by Herve Codina 10 months ago
Device-tree node can be created when CONFIG_PCI_DYNAMIC_OF_NODES. Those
node are created and filled based on PCI core information but the
fwnode.dev field is not set.

When later an overlay is applied, this consuses fw_devlink. Indeed,
without any device attached to the node, fw_devlink considers that this
node will never become a device. When this node is pointed as a
supplier, devlink looks at its ancestors in order to find a node with a
device that could be used as the supplier.

In the PCI use case, this leads to links that wrongly use the PCI root
bridge device as the supplier instead of the expected PCI device.

Setting fwnode.dev to the dev of the PCI device allows devlink to use
this device as a supplier and so, correct links are created.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 drivers/pci/of.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index ab7a8252bf41..ac6c4e1d68e5 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -709,6 +709,13 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 	if (ret)
 		goto out_free_node;
 
+	/*
+	 * Set the fwnode.dev in order to have fw_devlink creating links
+	 * pointing to this PCI device instead of walking up to the PCI host
+	 * bridge.
+	 */
+	np->fwnode.dev = &pdev->dev;
+
 	ret = of_changeset_apply(cset);
 	if (ret)
 		goto out_free_node;
-- 
2.49.0
Re: [PATCH 06/16] PCI: of: Set fwnode.dev of newly created PCI device nodes
Posted by Andy Shevchenko 10 months ago
On Mon, Apr 07, 2025 at 04:55:35PM +0200, Herve Codina wrote:
> Device-tree node can be created when CONFIG_PCI_DYNAMIC_OF_NODES. Those
> node are created and filled based on PCI core information but the
> fwnode.dev field is not set.
> 
> When later an overlay is applied, this consuses fw_devlink. Indeed,
> without any device attached to the node, fw_devlink considers that this
> node will never become a device. When this node is pointed as a
> supplier, devlink looks at its ancestors in order to find a node with a
> device that could be used as the supplier.
> 
> In the PCI use case, this leads to links that wrongly use the PCI root
> bridge device as the supplier instead of the expected PCI device.
> 
> Setting fwnode.dev to the dev of the PCI device allows devlink to use
> this device as a supplier and so, correct links are created.

...

> +	/*
> +	 * Set the fwnode.dev in order to have fw_devlink creating links
> +	 * pointing to this PCI device instead of walking up to the PCI host
> +	 * bridge.
> +	 */
> +	np->fwnode.dev = &pdev->dev;

This is too invasive. I suppose here should be a helper for this kind of
operation. If not, create one.

	fw_devlink_set_device(...);


or alike.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 06/16] PCI: of: Set fwnode.dev of newly created PCI device nodes
Posted by Herve Codina 10 months ago
Hi Andy,

On Mon, 7 Apr 2025 18:30:13 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Mon, Apr 07, 2025 at 04:55:35PM +0200, Herve Codina wrote:
> > Device-tree node can be created when CONFIG_PCI_DYNAMIC_OF_NODES. Those
> > node are created and filled based on PCI core information but the
> > fwnode.dev field is not set.
> > 
> > When later an overlay is applied, this consuses fw_devlink. Indeed,
> > without any device attached to the node, fw_devlink considers that this
> > node will never become a device. When this node is pointed as a
> > supplier, devlink looks at its ancestors in order to find a node with a
> > device that could be used as the supplier.
> > 
> > In the PCI use case, this leads to links that wrongly use the PCI root
> > bridge device as the supplier instead of the expected PCI device.
> > 
> > Setting fwnode.dev to the dev of the PCI device allows devlink to use
> > this device as a supplier and so, correct links are created.  
> 
> ...
> 
> > +	/*
> > +	 * Set the fwnode.dev in order to have fw_devlink creating links
> > +	 * pointing to this PCI device instead of walking up to the PCI host
> > +	 * bridge.
> > +	 */
> > +	np->fwnode.dev = &pdev->dev;  
> 
> This is too invasive. I suppose here should be a helper for this kind of
> operation. If not, create one.
> 
> 	fw_devlink_set_device(...);
> 
> 
> or alike.

Yes, I will add
  void fw_devlink_set_device(struct fwnode_handle *fwnode, struct device *dev);

Also, I will probably add a new patch in this series in order to use
the new fw_devlink_set_device() when relevant in the already existing code.

Best regards,
Hervé