首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pci_rescan_bus()不能在Linux中重新扫描PCI总线

pci_rescan_bus()不能在Linux中重新扫描PCI总线
EN

Stack Overflow用户
提问于 2020-10-27 14:01:33
回答 1查看 297关注 0票数 0

我尝试在pci_rescan_bus()内核函数的帮助下,在我自己的内核驱动程序中重新扫描PCI总线,但我看不到它的功能相同。

如果我尝试通过运行以下命令从用户空间执行相同的操作,我会看到重新扫描发生了:

代码语言:javascript
复制
echo 1 > /sys/devices/pci0000:00/0000:00:14.1/rescan

我正在尝试重新初始化位于PCI总线上的以太网端口。下面是我现在使用的代码:

代码语言:javascript
复制
struct pci_dev *pci_eth_dev01, *pci_eth_dev02 = NULL;
pci_eth_dev01 = pci_get_device(0x10ec, 0x8168, NULL);
if (pci_eth_dev01 != NULL)
    dev_info(&info->client->dev, "class - %2X\tbus number - %d\n", pci_eth_dev01->class, pci_eth_dev01->bus->number);
else
    dev_info(&info->client->dev, "Error retreiving pci device\n");

pci_eth_dev02 = pci_get_device(0x10ec, 0x8168, pci_eth_dev01);
if (pci_eth_dev02 != NULL)
    dev_info(&info->client->dev, "class - %2X\tbus number - %d\n", pci_eth_dev02->class, pci_eth_dev02->bus->number);
else
    dev_info(&info->client->dev, "Error retreiving pci device\n");

pci_stop_and_remove_bus_device(pci_eth_dev02);
pci_remove_bus(pci_eth_dev02->bus);

unsigned int ret = 0;
pci_lock_rescan_remove();
ret = pci_rescan_bus(pci_eth_dev02->bus);
pci_unlock_rescan_remove();
dev_info(&info->client->dev, "ret from pci_rescan_bus - %d\n", ret);

我从pci_rescan_bus()函数调用中获得2作为返回值。

我做错什么了吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-30 11:59:54

我发现pci_rescan_bus(pci_eth_dev02->bus->parent)是正确的调用,而不是pci_rescan_bus(pci_eth_dev02->bus),只需稍作修改,这就是我当前的实现,

代码语言:javascript
复制
    static bool re_initialize_eth_ports(struct supercap_info *info)
    {
        struct pci_dev *pci_eth_dev01 = NULL;
        struct pci_dev *pci_eth_dev02 = NULL;
    
        // Get PCI device structures since ethernet ports sit on PCI bus.
        pci_eth_dev01 = pci_get_device(REALTEK_ETH_VENDOR_ID,
                                       REALTEK_ETH_DEVICE_ID, NULL);
        pci_eth_dev02 = pci_get_device(REALTEK_ETH_VENDOR_ID,
                                       REALTEK_ETH_DEVICE_ID, pci_eth_dev01);
        if (!pci_eth_dev01 || !pci_eth_dev02) {
            dev_err(&info->client->dev, "Error retrieving PCI device structure\n");
            return false;
        }
        dev_dbg(&info->client->dev, "Device Class - 0x%X\tPCI Bus Number - %d\n",
                pci_eth_dev01->class, pci_eth_dev01->bus->number);
        dev_dbg(&info->client->dev, "Device Class - 0x%X\tPCI Bus Number - %d\n",
                pci_eth_dev02->class, pci_eth_dev02->bus->number);
        // Remove PCI bus devices from the device lists.
        pci_stop_and_remove_bus_device_locked(pci_eth_dev01);
        pci_stop_and_remove_bus_device_locked(pci_eth_dev02);
        // Acquire a mutex lock before re-scanning PCI buses.
        pci_lock_rescan_remove();
        // Re-scan PCI parent buses for devices.
        pci_rescan_bus(pci_eth_dev01->bus->parent);
        pci_rescan_bus(pci_eth_dev02->bus->parent);
        // Release a mutex lock.
        pci_unlock_rescan_remove();
        return true;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64549023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档