How to Check If a Linux Kernel Supports My System Devices

Channel: Linux
Abstract: fe1d1d7f/64 Scope

In this article, I will demonstrate a practical example which illustrates how the kernel supports a device and its drivers.

Find the name of the network device

Following are the names associated with network devices. Note: lo is the loopback device name, it is not attached to any of network devices.

bobbin@linoxide:~$ ls /sys/class/net/
eth0 eth1 lo
bobbin@linoxide:~$
Find device attached to above names

You can see eth0 is set with Ip address and active with RX/TX values. Its using standard frames with 1500 MTU size.

What is an Embedded system?

To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video

What is an Embedded system?
bobbin@linoxide:~$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:1d:20:09
inet addr:10.0.3.17 Bcast:10.0.3.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe1d:2009/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:124 errors:0 dropped:0 overruns:0 frame:0
TX packets:177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:33456 (33.4 KB) TX bytes:19854 (19.8 KB)

eth1 Link encap:Ethernet HWaddr 08:00:27:e7:1d:7f
inet6 addr: fe80::a00:27ff:fee7:1d7f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:100 errors:0 dropped:0 overruns:0 frame:0
TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7864 (7.8 KB) TX bytes:7864 (7.8 KB)

bobbin@linoxide:~$
Find which module supports eth0

Which driver is controlling the eth0 device? The following output shows that the e1000 driver is controlling the eth0 network card.

bobbin@linoxide:/$ ls /sys/class/net/eth0/device/driver/module/drivers/
pci:e1000
bobbin@linoxide:/$
Find ethernet PCI device attached to the server

As you can see from the following output, there are two intel network cards on the server with revision 02.The first few bits of the lspci command output show the PCI bus ID for this device ie, 00:03.0 and 00:08.0

bobbin@linoxide:~$ lspci | grep -i Ethernet
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
00:08.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)
bobbin@linoxide:~$

Go into /sys/bus/pci/devices/ where all different PCI devices are listed,

bobbin@linoxide:~$ cd /sys/bus/pci/devices/
bobbin@linoxide:/sys/bus/pci/devices$ ls
0000:00:00.0 0000:00:02.0 0000:00:05.0 0000:00:08.0
0000:00:01.0 0000:00:03.0 0000:00:06.0 0000:00:0d.0
0000:00:01.1 0000:00:04.0 0000:00:07.0
bobbin@linoxide:/sys/bus/pci/devices$

The kernel numbers PCI devices with a leading 0000: that do not show up in the output of the lspci program. So add the leading 0000: onto the number that you found using lspci and go into that directory.

bobbin@linoxide:/sys/bus/pci/devices$ cd 0000:00:03.0
bobbin@linoxide:/sys/bus/pci/devices/0000:00:03.0$ ls
broken_parity_status driver net resource2
class enable power subsystem
config irq remove subsystem_device
consistent_dma_mask_bits local_cpulist rescan subsystem_vendor
d3cold_allowed local_cpus reset uevent
device modalias resource vendor
dma_mask_bits msi_bus resource0
bobbin@linoxide:/sys/bus/pci/devices/0000:00:03.0$

In this directory, you can find the vendor and device filenames

bobbin@linoxide:/sys/bus/pci/devices/0000:00:03.0$ cat vendor
0x8086
bobbin@linoxide:/sys/bus/pci/devices/0000:00:03.0$ cat device
0x100e
bobbin@linoxide:/sys/bus/pci/devices/0000:00:03.0$

The kernel uses these values to match a driver to a device properly.PCI drivers tell the kernel which vendor and device IDs they will support so that the kernel knows how to bind the driver to the proper device.

Find what Kernel and Driver Support

Search in kernel source file for vendor and device id

bobbin@linoxide:/usr/src/linux-headers-3.8.0-29$ grep -i 0x8086 include/linux/pci_ids.h
#define PCI_VENDOR_ID_INTEL 0x8086
bobbin@linoxide:/usr/src/linux-headers-3.8.0-29$
bobbin@linoxide:/usr/src/linux-headers-3.8.0-29$ grep -i 0x100e include/linux/pci_ids.h
#define 0x100e
bobbin@linoxide:/usr/src/linux-headers-3.8.0-29$

Now search in driver source files for "PCI_VENDOR_ID_INTEL" . Now you need to look for concerned C file for the driver and look inside the file for

bobbin@linoxide:/usr/src/linux-source-3.2.0/drivers/net$ grep -Rl PCI_VENDOR_ID_INTEL *
can/pch_can.c
ethernet/dec/tulip/tulip_core.c
ethernet/oki-semi/pch_gbe/pch_gbe_main.c
ethernet/broadcom/tg3.c
ethernet/intel/e100.c
ethernet/intel/e1000/e1000_main.c
ethernet/intel/e1000/e1000.h
irda/smsc-ircc2.c
wireless/iwlegacy/iwl-core.h
wireless/iwlwifi/iwl-pci.c
wireless/ipw2x00/ipw2100.c
wireless/ipw2x00/ipw2200.c
wireless/rtlwifi/pci.c
bobbin@linoxide:/usr/src/linux-source-3.2.0/drivers/net$
bobbin@linoxide:/usr/src/linux-source-3.2.0/drivers/net/ethernet/intel$ cat e1000_main.c | more
* {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
*/
static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
INTEL_E1000_ETHERNET_DEVICE(0x1000),
INTEL_E1000_ETHERNET_DEVICE(0x1001),
INTEL_E1000_ETHERNET_DEVICE(0x1004),
INTEL_E1000_ETHERNET_DEVICE(0x1008),
INTEL_E1000_ETHERNET_DEVICE(0x1009),
INTEL_E1000_ETHERNET_DEVICE(0x100C),
INTEL_E1000_ETHERNET_DEVICE(0x100D),
INTEL_E1000_ETHERNET_DEVICE(0x100E),
INTEL_E1000_ETHERNET_DEVICE(0x100F),
INTEL_E1000_ETHERNET_DEVICE(0x1010),
INTEL_E1000_ETHERNET_DEVICE(0x1011),
INTEL_E1000_ETHERNET_DEVICE(0x1012),
INTEL_E1000_ETHERNET_DEVICE(0x1013),
INTEL_E1000_ETHERNET_DEVICE(0x1014),

All PCI drivers contain a list of the different devices that they support. The list is contained in a static definition in the DEFINE_PCI_DEVICE_TABLE table, just like this one. That is what we need to look at in order to determine whether our device is supported by this driver. In our case the vendor value and device Id match , so this driver will be able to support our device.

Ref From: linoxide
Channels:

Related articles