多个 PCIe 卡:读取当前 PCIe 卡实例的设备树属性(在内核驱动程序中)

Multiple PCIe cards: Read device tree properties of the CURRENT PCIe card instance (within a kernel driver)

问题:

我们正在扩展设备驱动程序。我们的 PCIe 设备具有无法自动检测的属性。为了与 Linux 内核维护者保持一致,我们希望将此属性添加到设备树中。当系统中存在多个 PCIe 卡时,如何在驱动程序代码中访问驱动程序正在处理的 CURRENT 实例的属性?

上下文:

我们在以太网驱动程序的上下文中执行此操作,但是该问题对于 PCIe 连接设备(甚至总线连接设备)的任何驱动程序都是通用的。

示例:

pcie@1ff00000 {
    ...
    host@0 {
        reg = < 0x00 0x00 0x00 0x00 0x00 >;
        #address-cells = < 0x03 >;
        #size-cells = < 0x02 >;

        ethernet@0 {
            compatible = "weiland-yutani,nostromo";
            reg = < 0x00 0x00 0x00 0x00 0x00 >;
            phy-connection-type = "rgmii";
        };
    };
    host@1 {
        reg = < 0x00 0x00 0x00 0x00 0x00 >;
        #address-cells = < 0x03 >;
        #size-cells = < 0x02 >;

        ethernet@0 {
            compatible = "weiland-yutani,nostromo";
            reg = < 0x00 0x00 0x00 0x00 0x00 >;
            phy-connection-type = "mii";
        };
    };
};

此示例显示了两个 PCIe 以太网卡,其中一个使用 "rgmii",另一个使用 "mii" 作为传输模式。 (作为示例,我们正在进行更多配置)。

在内核驱动程序代码中,我如何才能访问属于我正在处理的当前 PCIe 实例 (pci_dev *pdev) 的节点?我的意思是,哪种 of_find_node_by_path() 调用或任何可以引导我找到正确实例的方法?因此,我可以向我的以太网驱动程序添加一个 if 语句,该语句对正确的 rgmii 或 mii 配置做出反应,具体取决于驱动程序目前正在处理的 PCIe 卡中的哪一个。

该方法需要通用,因为我们的目标是将其贡献回 Linux 内核。 (任意数量的 PCI 总线、卡、拓扑...)

非常感谢。

当前节点通过pdev->dev->of_node传递给驱动实例。

示例:在上面的设备树中,驱动程序将直接访问 ethernet@0 节点,无需进一步遍历:

static int nostromo_pcidev_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
    const char *conn-type;    
    of_property_read_string(pdev->dev->of_node, "phy-connection-type", &conn-type);