This page contains instructions on using Linux device drivers as
loadable kernel modules.
Linux has a facility for linking device drivers into the running
kernel.
This is called Modules support. With the vast variety of supported
devices, pre-linking a kernel with all device drivers is impractical. Using
loadable modules allow a commercial Linux distribution to use a small
initial kernel and link in the device support needed after the machine has
booted.
Compiling a Device Driver Module
You may skip this step if a pre-compiled module is available for your
Linux distribution. In many cases drivers compiled for similar kernel
versions will work. Pre-compiled modules in the form of RPMS for popular
distributions are frequently available.
If a pre-compiled module is not available, you'll have to compile one
from the driver source code, or the source code RPM (SRPM). In the
instructions below driver.c refers to the name of the driver source
file for your device e.g. 3c59x.c, and driver.o refers to
the compiled driver module binary.
- Verify that the source code for your current kernel version is installed.
- If you don't have a /usr/include/linux/version.h file, do
cd /usr/src/linux; make include/linux/version.h
- Copy the driver source code to a source directory.
I usually use /usr/src/modules/driver.c.
- Compile the file using the compile-command at the bottom of the
driver
source file. If a compile-command is not there use the following
compile command:
gcc -DMODULE -D__KERNEL__ -O6 -c driver.c
- As 'root', test the module by doing "insmod driver.o".
- Install the driver module in the proper location for your
distribution.
This is usually
/lib/modules/kernel-version/net/driver.o.
The command to do this is
install -m 644 driver.o /lib/modules/`uname -r`/net/
Possible problems and solutions
If you get an "linux/version.h no such file or directory" message when
compiling the driver, you either
have not installed the kernel source code, or you haven't run
cd /usr/src/linux; make include/linux/version.h
yet. Most modern distributions install the essential header files
of the kernel source code, including a pre-built "version.h", so this isn't
always necessary.
If you get a "modversions.h not found" message when compiling the driver,
delete '-DMODVERSIONS' from the command used to compile the driver module.
Testing the New Module
As 'root', load the module using "insmod driver.o" and execute the
appropriate 'route add -net ...' for your local network.
If the networking works correctly, add the module to your system
configuration. For Slackware and most other systems, add the insmod
command to /etc/rc.d/rc.inet1 or /etc/rc.d/rc.local.
RedHat users should add the insmod line to /etc/rc.d/rc.modules or copy
driver.o to /lib/modules/`uname -r`/net/ and add the
following line to /etc/conf.modules:
alias eth0 driver
Modifying Driver Operation Through Options
Drivers are designed with the goal that no options should be needed in most
environments. However not all cards and networks can be automatically
configured, thus drivers allow operational parameters to be modified when
they are loaded as a module. Typically the following variables may be set:
name type description
debug int The debug message level, 0 (no messages) to 6 (wordy).
options int[] Per-card media type override and card operation
settings, typically the media type.
full_duplex int[] Set to '1' to force this interface to always be used in
FD mode.
To test an option, load the module (as above) with a command such as
"/sbin/insmod driver.o full_duplex=1,0,1". This command sets the
full_duplex flag for the first and third cards of this type.
To set module parameters when the module is loaded automatically, add
the
following line to /etc/conf.modules
alias eth0 driver
options driver full_duplex=1,0,1 debug=0
Note that spaces are permitted only between parameter names, not between
the comma-separated numeric options.
Problems and Solutions
What if the card is detected with a ff:ff:ff:ff:ff:ff station
address?
There are three known causes of this problem.
- Warm-booting from Win95 OSR2.1 or Win98 (power-managed cards only)
- "PnP OS" is set in the PCI BIOS setup.
- Broken PCI BIOSes (reportedly version "AI78" is broken).
The "D3-cold" problem
Quick summary: restore operation by unplugging the machine after
running an OS that disables the card. Merely using the "soft-off"
pushbutton on a ATX case is not sufficient.
Many modern PCI chips have ACPI power management capability. Some
include
a mode known as "D3-cold", where the chip can power itself off. When
in this mode the chip uses only the tiny amount of stand-by power
always available when an ATX power supply is plugged in.
In the D3-cold mode the chip can be turned on only by writing a PCI
configuration space register.
This works great if you have a ACPI-aware BIOS that knows how to
re-enable the chip on a warm boot, but older BIOS don't know that the
chip cannot retain configuration information. When the machine is
warm booted the chip has only invalid configuration information.
The PnP OS problem occurs because Microsoft has convinced BIOS makers
to modify their PCI device configuration from the previous rational
standard, to one that works well only with Microsoft operating
systems. Where previously the BIOS allocated resources for and
enabled the PCI device by default, it now does so only for boot
devices and audio devices. (Why are audio devices specifically an
exception? Because MS-Windows can't handle the resource allocation
for them!)
The solution is to either update to the latest driver, (the drivers are
being re-worked to enable the devices) or to disable the "PnP OS" setting
in the machine's BIOS setup.
The reason Microsoft had to have this change implemented for them was that
MS-Windows still handles some devices with "real-mode" drivers, and this
change makes it easier to mix real-mode and protected-mode device drivers.
This is an excellent example of Microsoft using its dominant position in the
software industry force a technical change that is detrimental to other
operating systems.
This a not a legal statement. Read the Gnu General Public
License (GPL) to find your actual rights. These are just guidelines to
assist in interpreting that document. More here.
Legal status of a loaded Module
Loading a device driver module is functionally identical to conventionally
building a kernel. The final result is a single Work, as that term is used
in the license. The time that the linking is done does not affect the legal
status of the individual parts or the whole: legally, changes in structure,
procedure or nomenclature are evaluated by the conventional usage.