Где я могу найти объявление pci_find_device (), создающее сетевой драйвер на Debian Stretch? - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь построить сетевой драйвер. Однако, когда я пытаюсь собрать его, он говорит:

error: implicit declaration of function ‘pci_find_device

Вот мой драйвер:

#define REALTEK_VENDER_ID  0x10EC
#define REALTEK_DEVICE_ID   0x8139

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/stddef.h>
#include <linux/pci.h>

int init_module(void)
{
    struct pci_dev *pdev;
    pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
    if(!pdev)
        printk("<1>Device not found\n");
    else
        printk("<1>Device found\n");
    return 0;
}
MODULE_LICENSE("GPL");

Вот мой Makefile

obj-m += ethDriver.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Когда я собираю, Я получаю следующие ошибки:

ethDriver.c: In function ‘init_module’:
/home/xxx/ethDriver/ethDriver.c:13:12: error: implicit declaration of function ‘pci_find_device’ [-Werror=implicit-function-declaration]
     pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
            ^~~~~~~~~~~~~~~
/home/xxx/ethDriver/ethDriver.c:13:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
          ^
cc1: some warnings being treated as errors
/usr/src/linux-headers-4.9.0-3-common/scripts/Makefile.build:315: recipe for target '/home/xxx/ethDriver/ethDriver.o' failed
make[4]: *** [/home/xxx/ethDriver/ethDriver.o] Error 1
/usr/src/linux-headers-4.9.0-3-common/Makefile:1507: recipe for target '_module_/home/xxx/ethDriver' failed
make[3]: *** [_module_/home/xxx/ethDriver] Error 2
Makefile:150: recipe for target 'sub-make' failed
make[2]: *** [sub-make] Error 2
Makefile:8: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.9.0-3-amd64'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

1 Ответ

1 голос
/ 20 апреля 2020

Функция pci_find_device() была удалена в ядре v2.6.34.

С Documentation/PCI/pci.rst:

Устаревшие функции

Есть несколько функций, с которыми вы можете столкнуться при пытается портировать старый драйвер на новый интерфейс PCI. Они больше не присутствуют в ядре, поскольку они несовместимы с доменами горячего подключения или PCI или имеют нормальную блокировку.

pci_find_device() Superseded by pci_get_device()
pci_find_subsys() Superseded by pci_get_subsys()
pci_find_slot()   Superseded by pci_get_domain_bus_and_slot()
pci_get_slot()    Superseded by pci_get_domain_bus_and_slot()

Вам нужно будет использовать pci_get_device(), который также должен быть включен в <linux/pci.h>.

/**
 * pci_get_device - begin or continue searching for a PCI device by vendor/device id
 * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
 * @from: Previous PCI device found in search, or %NULL for new search.
 *
 * Iterates through the list of known PCI devices.  If a PCI device is
 * found with a matching @vendor and @device, the reference count to the
 * device is incremented and a pointer to its device structure is returned.
 * Otherwise, %NULL is returned.  A new search is initiated by passing %NULL
 * as the @from argument.  Otherwise if @from is not %NULL, searches continue
 * from next device on the global list.  The reference count for @from is
 * always decremented if it is not %NULL.
 */
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
                   struct pci_dev *from)
{
    return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
}
EXPORT_SYMBOL(pci_get_device);

PS: ваш #define имеет опечатку, вероятно, он должен быть VENDOR, а не VENDER.

...