简体   繁体   中英

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. In alignment with the Linux kernel maintainers we want to add this properties to the device tree. 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?

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).

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. (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? I mean, which kind of of_find_node_by_path() call or whatever can lead me to the correct instance? 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.

The approach needs to be generic as we aim to contribute it back to the Linux kernel. (Arbitrary amounts of PCI busses, cards, topologies...)

Thanks a lot.

The current node is passed to the driver instance by 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:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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