[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How the kernel knows?



On Tue, 20 Sep 2011 14:29:06 -0400 (EDT), David Roguin wrote:
> 
> I was wondering, how does the kernel knows what module (or driver)
> to load given any hardware? And, can i see that in any log file?

The kernel knows what module to load because the module contains
alias names based on the hardware's PCI id, USB id, ISA PnP id,
or some other hardware-identifying information.  For example,
consider the following console session:

-----

steve@smp3:~$ /sbin/modinfo 3c59x
filename:       /lib/modules/3.0.0-1custom2-686-pae/kernel/drivers/net/3c59x.ko
license:        GPL
description:    3Com 3c59x/3c9xx ethernet driver 
author:         Donald Becker <becker@scyld.com>
alias:          pci:v000010B7d00009210sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009056sv*sd*bc*sc*i*
alias:          pci:v000010B7d00001202sv*sd*bc*sc*i*
alias:          pci:v000010B7d00001201sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009201sv*sd*bc*sc*i*
alias:          pci:v000010B7d00004500sv*sd*bc*sc*i*
alias:          pci:v000010B7d00006564sv*sd*bc*sc*i*
alias:          pci:v000010B7d00006562sv*sd*bc*sc*i*
alias:          pci:v000010B7d00006560sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005257sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005157sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005057sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005B57sv*sd*bc*sc*i*
alias:          pci:v000010B7d00006056sv*sd*bc*sc*i*
alias:          pci:v000010B7d00006055sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005055sv*sd*bc*sc*i*
alias:          pci:v000010B7d00007646sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009805sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009800sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009202sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009200sv*sd*bc*sc*i*
alias:          pci:v000010B7d0000905Asv*sd*bc*sc*i*
alias:          pci:v000010B7d00009058sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009055sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009054sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009051sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009050sv*sd*bc*sc*i*
alias:          pci:v000010B7d0000900Asv*sd*bc*sc*i*
alias:          pci:v000010B7d00009006sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009005sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009004sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009001sv*sd*bc*sc*i*
alias:          pci:v000010B7d00009000sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005952sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005951sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005950sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005970sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005920sv*sd*bc*sc*i*
alias:          pci:v000010B7d00005900sv*sd*bc*sc*i*
depends:        mii
intree:         Y
vermagic:       3.0.0-1custom2-686-pae SMP mod_unload modversions 686 
parm:           debug:3c59x debug level (0-6) (int)
parm:           options:3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex (array of int)
parm:           global_options:3c59x: same as options, but applies to all NICs if options is unset (int)
parm:           full_duplex:3c59x full duplex setting(s) (1) (array of int)
parm:           global_full_duplex:3c59x: same as full_duplex, but applies to all NICs if full_duplex is unset (int)
parm:           hw_checksums:3c59x Hardware checksum checking by adapter(s) (0-1) (array of int)
parm:           flow_ctrl:3c59x 802.3x flow control usage (PAUSE only) (0-1) (array of int)
parm:           enable_wol:3c59x: Turn on Wake-on-LAN for adapter(s) (0-1) (array of int)
parm:           global_enable_wol:3c59x: same as enable_wol, but applies to all NICs if enable_wol is unset (int)
parm:           rx_copybreak:3c59x copy breakpoint for copy-only-tiny-frames (int)
parm:           max_interrupt_work:3c59x maximum events handled per interrupt (int)
parm:           compaq_ioaddr:3c59x PCI I/O base address (Compaq BIOS problem workaround) (int)
parm:           compaq_irq:3c59x PCI IRQ number (Compaq BIOS problem workaround) (int)
parm:           compaq_device_id:3c59x PCI device ID (Compaq BIOS problem workaround) (int)
parm:           watchdog:3c59x transmit timeout in milliseconds (int)
parm:           global_use_mmio:3c59x: same as use_mmio, but applies to all NICs if options is unset (int)
parm:           use_mmio:3c59x: use memory-mapped PCI I/O resource (0-1) (array of int)
steve@smp3:~$ 

-----

Do you see all those "alias" entries in the output of the modinfo command?  Each alias
entry corresponds to one or more Network Interface Cards (NICs).  In some cases, they are
stand-alone boards installed in an expansion slot.  In other cases they are built-in to
the motherboard.  Now consider the following:

-----

steve@smp3:~$ lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation 82850 850 (Tehama) Chipset Host Bridge (MCH) [8086:2530] (rev 02)
00:01.0 PCI bridge [0604]: Intel Corporation 82850 850 (Tehama) Chipset AGP Bridge [8086:2532] (rev 02)
00:1e.0 PCI bridge [0604]: Intel Corporation 82801 PCI Bridge [8086:244e] (rev 04)
00:1f.0 ISA bridge [0601]: Intel Corporation 82801BA ISA Bridge (LPC) [8086:2440] (rev 04)
00:1f.1 IDE interface [0101]: Intel Corporation 82801BA IDE U100 Controller [8086:244b] (rev 04)
00:1f.2 USB Controller [0c03]: Intel Corporation 82801BA/BAM USB Controller #1 [8086:2442] (rev 04)
00:1f.3 SMBus [0c05]: Intel Corporation 82801BA/BAM SMBus Controller [8086:2443] (rev 04)
00:1f.4 USB Controller [0c03]: Intel Corporation 82801BA/BAM USB Controller #1 [8086:2444] (rev 04)
00:1f.5 Multimedia audio controller [0401]: Intel Corporation 82801BA/BAM AC'97 Audio Controller [8086:2445] (rev 04)
01:00.0 VGA compatible controller [0300]: nVidia Corporation NV5 [RIVA TNT2/TNT2 Pro] [10de:0028] (rev 15)
02:0c.0 Ethernet controller [0200]: 3Com Corporation 3c905C-TX/TX-M [Tornado] [10b7:9200] (rev 78)
steve@smp3:~$ 

-----

Notice that last line of output, which shows the PCI id for the Ethernet controller
as 10b7:9200.  10b7 identifies the vendor (3Com, in this case) and 9200 identifies
a specific card (3c905C-TX/TX-M [Tornado]).  That matches up with alias entry

-----

alias:          pci:v000010B7d00009200sv*sd*bc*sc*i*

-----

Notice the 10B7 and the 9200 as part of the alias name.  When udev discovers this
card, it knows to load kernel module 3c59x.

Sometimes, if you know a kernel module supports a given card, but it doesn't have
a corresponding alias, you can add your own alias entries in a *.conf file in
/etc/modprobe.d.  But be sure that the module really does support the card.

Sometimes more than one module has matching alias entries and you will have to
blacklist one or more modules in a *.conf file in /etc/modprobe.d to prevent
the ones you don't want from loading.

If you make any changes to files in /etc/modprobe.d, be sure to rebuild your
initial RAM file system after making changes and before rebooting.  For example,

   update-initramfs -uk $(uname -r)

Issue the above command as root.

-- 
  .''`.     Stephen Powell    
 : :'  :
 `. `'`
   `-


Reply to: