简体   繁体   English

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

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

Question:问题:

We are extending a device driver.我们正在扩展设备驱动程序。 Our PCIe devices have properties that cannot be auto-detected.我们的 PCIe 设备具有无法自动检测的属性。 In alignment with the Linux kernel maintainers we want to add this properties to the device tree.在 alignment 和 Linux kernel 维护者中,我们希望将此属性添加到设备树中。 How can I access, in the driver code, the properties of the CURRENT instance, the driver is handling at the moment, when more than one PCIe card is present in the system?当系统中存在多个 PCIe 卡时,如何在驱动程序代码中访问驱动程序当前正在处理的 CURRENT 实例的属性?

Context:语境:

We're doing this in the context of an Ethernet driver, however the problem is generic for any driver of PCIe connected devices (or even bus-connected devices).我们在以太网驱动程序的上下文中执行此操作,但是对于任何 PCIe 连接设备(甚至总线连接设备)的驱动程序,该问题都是通用的。

Example:例子:

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";
        };
    };
};

This example shows two PCIe ethernet-cards with one using "rgmii" and another using "mii" as transfer mode.此示例显示了两个 PCIe 以太网卡,其中一个使用“rgmii”,另一个使用“mii”作为传输模式。 (Just as an example, we have more configuration going on). (作为一个例子,我们有更多的配置正在进行)。

In the kernel driver code, how can I get access to the node that belongs to the current PCIe instance (pci_dev *pdev) I'm dealing with?在 kernel 驱动程序代码中,如何访问属于我正在处理的当前 PCIe 实例 (pci_dev *pdev) 的节点? I mean, which kind of of_find_node_by_path() call or whatever can lead me to the correct instance?我的意思是,哪种 of_find_node_by_path() 调用或任何可以引导我找到正确实例的方法? So I can add an if-statement to my ethernet driver that reacts on the correct rgmii or mii configuration, depending on which one of both PCIe cards the driver is handling at the moment.因此,我可以向我的以太网驱动程序添加一个 if 语句,该语句对正确的 rgmii 或 mii 配置作出反应,具体取决于驱动程序当前正在处理的两张 PCIe 卡中的哪一张。

The approach needs to be generic as we aim to contribute it back to the Linux kernel.该方法需要通用,因为我们的目标是将其贡献回 Linux kernel。 (Arbitrary amounts of PCI busses, cards, topologies...) (任意数量的 PCI 总线、卡、拓扑……)

Thanks a lot.非常感谢。

The current node is passed to the driver instance by pdev->dev->of_node .当前节点通过pdev->dev->of_node传递给驱动程序实例。

Example: In above's device tree the driver would get direct access to the ethernet@0 node, with no further traversing:示例:在上面的设备树中,驱动程序将直接访问 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM