Using the Ethernet Drivers as Modules

Using the Ethernet Drivers as Modules

Most of the linux distributions now ship kernels that have very few drivers built-in. The drivers are instead supplied as a bunch of independent dynamically loadable modules. These modular drivers are typically loaded by the administrator with the modprobe(8) command, or in some cases they are automatically loaded by the kernel through `kerneld' (in 2.0) or `kmod' (in 2.1) which then calls modprobe.

Your particular distribution may offer nice graphical configuration tools for setting up ethernet modules. If possible you should try and use them first. The description that follows here gives information on what underlies any fancy configuration program, and what these programs change.

The information that controls what modules are to be used and what options are supplied to each module is usually stored in the file /etc/modules.conf. The two main options of interest (for ethernet cards) that will be used in this file are alias and options. The modprobe command consults this file for module information.

The actual modules themselves are typically stored in a directory named /lib/modules/`uname -r`/net where the uname -r command gives the kernel version (e.g. 2.0.34). You can look in there to see which module matches your card.

The first thing you need in your modules.conf file is something to tell modprobe what driver to use for the eth0 (and eth1 and...) network interface. You use the alias command for this. For example, if you have an ISA SMC EtherEZ card which uses the smc-ultra.o driver module, you need to alias this driver to eth0 by adding the line:

        alias eth0 smc-ultra

Important Note: The alias above is only used by the module utilities to translate a generic device name (e.g.eth0) into a hardware specific driver module name. When the driver loads, it never even sees this alias; instead it will simply choose the first free ethN (N=0,1,2,...) device name available. Thus, if more than one ethernet module is being loaded, the ethN assigned to the driver by the kernel may or may not be the same as the one given on the alias line, depending on the order in which the modules have been loaded. If you need to ensure that a particular card is given a particular IP address, then read the station address and assign your IP address based upon that. If you are writing your own shell scripts for this, you can just parse the ifconfig output; if using C, then you would use ioctl(ethfd, SIOCGIFHWADDR, &ifreq).

The other thing you may need is an options line indicating what options are to be used with a particular module (or module alias). Continuing with the above example, if you only used the single alias line with no options line, the kernel would warn you (see dmesg) that autoprobing for ISA cards is not a good idea. To get rid of this warning, you would add another line telling the module what I/O base the card is configured to, in this case say the hexidecimal address 0x280 for example.

        options smc-ultra io=0x280

Most ISA modules accept parameters like io=0x340 and irq=12 on the insmod command line. It is REQUIRED or at least STRONGLY ADVISED that you supply these parameters to avoid probing for the card. Unlike PCI and EISA devices, there is no real safe way to do auto-probing for most ISA devices, and so it should be avoided when using drivers as modules.

A list of all the options that each module accepts can be found in the file:

/usr/src/linux/Documentation/networking/net-modules.txt

It is recommended that you read that to find out what options you can use for your particular card. Note that some modules support comma separated value lists for modules that have the capability to handle multiple devices from a single module, such as all the 8390 based drivers, and the PLIP driver. For exmple:


        options 3c503 io=0x280,0x300,0x330,0x350 xcvr=0,1,0,1

The above would have the one module controlling four 3c503 cards, with card 2 and 4 using external transcievers. Don't put spaces around the `=' or commas.

Also note that a busy module can't be removed. That means that you will have to ifconfig eth0 down (shut down the ethernet card) before you can remove the module(s).

The command lsmod will show you what modules are loaded, whether they are in use, and rmmod will remove them.

No comments:

Post a Comment