I/O technology can be used to realize the communication between the PC and the NIC through the data bus. Currently, I/O technologies are widely used: programming I/O, Direct Memory Access (DMA), shared memory, and bus master DMA.
Ethernet in LinuxNicInstallation and configuration
Abstract As Linux operating systems are increasingly accepted by people, it is becoming increasingly concerned about how to expand network applications on Linux systems. This article discusses in detailNicThe principles, methods, and steps of installation and configuration are described as an example in actual work.
Keywords Linux EthernetNicLinux core load-able Module
The Linux operating system is favored by more and more people of insight with its unique openness, stability, and efficiency. As it giants announce their support for Linux, Linux is rapidly expanding its application market, especially the server market. As a standard, Linux is compatible with posix1003.1, but it has a more reasonable kernel structure than a UNIX system. Due to its openness, various widely used network protocols have been implemented in this system. Currently, the Linux system is generally a release version consisting of the Linux core, shell, and peripheral application software. Linux releases are the result of Linux core, Shell, Installation tool, and application software effectively bundled by different companies or organizations. However, in general, these releases have as manyNic. This article only coversNicThe selection, installation, and configuration of is discussed. We hope to provide some reference for the same issues of other releases.
Like UNIX, Linux supportsNicMainly EthernetNic. Such as 3Com, accton, at&t, IBM, crystal, D-LINK and many other brands of EthernetNicAs long as the installation and configuration are correct, you can get the expected results.
I. LinuxNicWorking principle
In order to clarify this issue, we may first briefly analyze how Linux enablesNicWork. In general, the Linux core has implemented the network layer and upper layer of the OSI reference model. The implementation of the network layer depends on the effective work of the data link layer.NicThe driver is the interface between the data link layer and the physical layer. By calling the sending routine of the driver to send data to the physical port, the receiving routine of the driver is called to receive data from the physical port.
1.NicDriver
To put it simplyNicThe only thing you have to do is get thisNic. The driver provides the core interface for the operating system and the interface for the physical layer.
The operating system interface of the driver is used for discovery.Nic, DetectionNicParameters and routines for sending and receiving data. When the driver starts to run, the operating system first calls the detection routine to findNic. IfNicPlug-and-play is supported, so detection routines can be automatically discoveredNicOr you must set the parameters before the driver is running.Nic. When the core needs to send data, it calls the sending routine of the driver. The sending routine writes data to the correct space and then activates the physical sending process.
The physical layer interface of the driver is the interrupt processing routine. WhenNicWhen data is received, the sending process ends, or an error is found,NicGenerates an interrupt, and then the core calls the interrupt processing routine. The Interrupt Processing Routine determines the cause of the interruption and processes the response. For example, whenNicWhen data is interrupted when it is received, the interrupt processing routine calls the receiving routine to receive the data.
2. Driver Operating Parameters
Working Parameters of the driverNicDifferent properties, including I/O port number, interrupt number,DMAChannels and shared storage areas. The input/output port is also called the input/output base address.NicUsed in Port input/output mode. The input/output mode requires full CPU intervention, but requires low hardware and storage space. The space specified by the CPU through the port number andNicExchange data. The interrupt number isNicAs long as it does not conflict with other devices. WhenNicUseDMAMethod, it needs to useDMAThe channel transfers data in batches without CPU intervention.
For a specificNic, IfNicSupports automatic detection. You do not need to specify a parameter. The detection routine of the driver automatically sets the required parameter. Generally, you need to manually set some of these parameters. If yourNicIn Port input/output mode, you must set the port number and interrupt number. If yourNicUseDMAMode, you need to setDMAChannel and interrupt number. If yourNicTo use the shared storage area mode, you must set the address range of the shared storage area.
3. How to Use the driver
WithNicAfter the driver program, you can choose to add the driver to the Linux core or process the driver into an independent module. A fascinating advantage of Linux systems is the core of customized systems. Adding features that require frequent calls to the core of the system can greatly improve the system efficiency. In this case, the system core is automatically loaded when the system is started.Nic. The driver parameters can be specified through the Lilo command parameters. After the system starts, the driver permanently stays at the core and cannot be detached in a conventional way. As for the custom system core, it is obtained through re-compilation; how to compile the core will be described later.
If you compile the driver into a load-able module, you can use the commands provided by the system to load it at any time after the system starts. The advantage of loading at any time is reduced memory overhead and ease of management, but it also sacrifices the efficiency of network transmission. The driver parameters are directly input in the command line or specified through the configuration file. II,NicPreparations before installationNicBefore, check whether the following conditions are met:
1. Hardware
● EthernetNic
● Network connection line and connection head, such as 10base-t is generally 8-core twisted pair wire with RJ-45 Interface
2. Software
● Linux operating system
●NicDriver (target code or source code)
● *NicConfiguration program
● * Software development tools, such as the GNU toolkit (including the GCC and make compilers)
3. system configuration information
● Available port addresses
● Available interrupt number
The preceding conditions are not marked with asterisks. The conditions with asterisks depend on the situation. The details are further described below.
III,NicInstallation and configuration
Step 1: configure the EthernetNicParameters
ConfigurationNicIs the configurationNicSuch as the port address and interrupt number.NicThe default parameters of are generally stored inNicInternal EEPROM, which isNicSet before leaving the factory. Default parameters are feasible in most cases, but if these parameters conflict with your system andNicDynamic software settings are not supported, so you need to useNic. Not allNicThis step is required becauseNicIt can be determined by the driver software and its input parameters.Nic. You can referNicThe statement of use to determine this.
NicThe setup program is different from the driver. The setup program is only usedNicModify the settings in the EEPROM.NicPrograms may run in other operating systems, such as Windows 95/98, OS/2, and DOS. If it is not a Linux platform, you should first installNic, Set according to the settings program instructionsNicParameters. Then installNic.
Step 2: Install the Linux System
If you want to install EthernetNicThe Linux system is not yet installed, You can first try to installNic. The premise of success in this step is that your Linux release version containsNic.
Run the Linux installer and follow the prompts to install the core network. When you configure the LAN, the installer will list allNic. Look at yourNicWhether the name is on the list. As the Linux release version continues to upgrade, RedHat 6.0 has already covered commonNicType. If you're lucky enoughNicIn this case, you do not have to consider the steps discussed below. The installation program will automatically complete.NicInstallation and driver. However, if you do not findNicType, do not worry, continue to the next step.
Step 3: manual InstallationNic
InstallNicThat is, installNic.NicTo work, you must have a driver, and the more mature the driver, the better. The driver is generally composedNicProduction or supplier provision. As Linux is a new operating system that has just started,NicThe producer does not necessarily provide drivers in Linux. At this time, you have to find a solution from other channels. For example, you can find a website that provides hardware drivers on the Internet, or you can post a help message on the newsgroup. In short, only getNicBefore proceeding to the next step.
NicThere are two types of drivers. One is binary code that can be used directly; the other is the source code of the driver. Binary Code is generally a pre-compiled and load-able module. The source code can be compiled into a loadable module or a part of the core of the system. How to compile the source code into a loadable module is not discussed in this article. For details, refer to the driver manual.
1. Use of loadable modules
The system provides a set of commands to load the driver module into the memory for execution. These commands include modprobe, insmod, ismod, and rmmod. Modprobe is similar to the insmod command, but in different ways.
● The modprobe command uses the configuration file/ERC/config. modules to load the executable module. Use the modprobe command to load the EthernetNicYou can add the following to the config. Modules file:
Alias eth0 drivermodule (drivermodule is the name of the driver module)
This line of configuration information sets the EthernetNicThe device name is associated with the driver module. Based on this information, The modprobe command automatically loads the module named drivermodule. O stored in the/lib/library/xxxx/NET directory. Therefore, to make the modprobe command find the driver module, you must put the module in the/lib/library/xxxx/NET directory.
How do I specify the driver parameters? Or use the conf. Modules file. You can add the following downstream information after the preceding configuration information:
Options drivermodule parml = valuel, parm2 = value2 ,......
Here, parm1 is the parameter name acceptable to the driver, valuel is the parameter value, and so on.
Such as options cs89x0 IO = 0x200 IRQ = 0xa media = AuI
● The insmod command directly loads the driver module into the memory using the command line parameters, and you can specify the driver parameters in the command. For example:
Insmod drivermodule. O parml = valuel, parm2 = value2 ,......
The above two commands can use the driver parameters according to the specificNicDepends on the driver, read carefullyNicAnd driver specification. YesNicThe driver can use these parameters to overwriteNicParameters stored in the EEPROM. Some must use parameters in the EEPROM. Some because the driver does not automatically detectNicSo you haveNicParameters in the eeprom used are passed to the driver.
Run the rmmod command to uninstall the driver module:
Rmmod drivermodule. o
2. Compile the driver into the system core.
In addition to using the driver in the form of a load module, you can also compile the driver into the Linux core for higher efficiency. This method requires the source code of the driver, the Linux core source code, and the compilation tool. The Linux core compilation process includes core configuration, dependency reconstruction, and core code generation. The core configuration process is to use the system-provided Configuration tool (make config or make menuconfig) to re-generate the many make files used to compile the core. To let the core Configuration tool know about yourNicDriver, you need to modify some core configuration files.
(1) modify the configuration file: It mainly modifies four files under the core source code directory, namely the drivers/NET/config file and Drivers/NET/config. in file, drivers/NET/MAKEFILE file, and drivers/NET/space. c file. The Config and config. In files are used to control the running of the core Configuration tool (make config or make menuconfig). They mainly includeNic. Makefile and space. c files are used to compile core code and describe core-oriented interfaces. For detailed statements, see the example below.
(2) run the core Configuration tool: Execute the make config or make menuconfig command in the core source code directory. Make config is for command line. You can configure the core by answering questions one by one. It is inconvenient because it cannot be changed during the configuration process or the previous answer is revoked. Make menuconfig is a window menu that is easy to use. As far as this article is concerned, if you modify the configuration file correctly in the previous step, you will see in the configNicYou can select 'y' for the supported questions '. Alternatively, this parameter is displayed in the network menu of menuconfig.NicAnd select it.
(3) re-build the dependency: Execute the make Dep and make clean commands.
(4) generate the core code: Execute the make zimage command. This command is used to compile the core code and store the core code as zimage in the arch/i386/boot directory.
(5) to use the new core code, you need to replace the original with the new core code. The original core code is generally stored in the/boot directory, the file name is similar to the vmlinuz-v.s.r-m (V. S. r-m) represents the core version number ). Like vmlinuz-2.0.34-1. Run the following command:
Cp arch/i386/boot/zimage/boot/vmlinuz-v.s.r-m
For the sake of security, you can back up the original core code so that it can be restored when an error occurs.
So far, you can reboot the system to use the newNicLinux core supported by the driver. The only thing that remains unsolved is the driver parameter issue. SomeNicIf the driver does not enter a parameter, it will not work properly, or even not. BecauseNicThe driver is loaded and run by the core at system startup. After the system is started, it is difficult for users to change these parameters. Therefore, you must tell the Linux core at system startup.NicThe parameters used by the driver. There are two methods:
(1) input in the system boot program Lilo.
When lilo starts to boot the system, use the ether sub-command to set the EthernetNicDriver parameters. The ether command is used as follows:
Lilo: linu xether = IRO. base_addr, name
The underline indicates the part to be entered. IRQ indicates the interrupt number, base_addr indicates the port number, and name indicates the interrupt number.NicDevice Name. For example: Linux ether = 15, 0x320, eth0
(2) set it in the Lilo configuration file.
It seems too troublesome to input driver parameters at system startup every time. Fortunately, the system provides the Lilo configuration file which can be used to permanently set sub-commands during Linux Startup. In the/etc/Lilo. conf file, add the following line:
Append = "ether = IRQ, base_addr, name"
The underlined part indicates the same as above. After adding this line, you also need to use the/sbin/lilo command to write this configuration to the boot program.
Step 4: network configuration and Testing
After installationNicYou can configure network communication. To configure the network, simply use the ifconfig command,
For example:
Ifconfig eth0 1.2.3.4 netmask 255.0.0.0 up
Finally, ping the IP addresses of other machines on the Internet and check whether the network is connected.
5. An EthernetNicInstall an instance
The crystal cs8920 Ethernet produced by cirrusNicFor example, describe the installation and configuration process in detail. In this example, some command parameters, such as the core source code directory, are based on my system environment. The specific application must be localized. In order to be closer to reality, the example also describes the problems encountered during installation.
1. ThisNicIs an internal built-in IBM PCNicThe host only provides drivers in Windows 95/98. Because the RedHat 5.0 release does not provideNicSo you can find and downloadNicThe Linux driver is a compressed file named linux102_tar.gz.
2. The linux102_tar.gz file contains five files. Including source code, applicable only to the target modules of Linux 2.0 and readme files.
3. Check the README file and find that this driver can only useNicThe port number (I/O base address) and interrupt number set in the EEPROM. To understandNicThe eeprom settings are downloaded from the Cirrus site.NicSetup.exe
4.run setup.exe in dosand findNicThe starting port number is 0x360, And the interrupt number is 10, which is in conflict with other devices. Select the corresponding menu of the setup.exe program and change the interrupt number to 5. In addition, this driver does not support plug and play, so it is also in setup.exeNic.
5. the Linux core version of RedHat 5.0 I use is 2.0.34. Therefore, the ready-made driver target module cannot be used and must be compiled by myself. As described above, there are two ways to use this driver.
6. To compile the program into an independent module, run the following command:
Gcc-D_KERNEL_-I/usr/src/Linux/include-I/usr/src/Linux/NET/inet-wall-wstrictprototypes-02-fomit-frame-pointer-dmodule-dconfig_modversions- ccs89x0. c
The compilation result is the driver target module named cs89x0. O. To load this driver, enter the following command: insmod cs89x0. o io = 0x360 IRQ = 10
To uninstall the driver, run the rmmod command:
Rmmod cs89x0. o
7. If you want to compile the driver into the system core,
Modify/usr/src/Linux/Drivers/NET/config and add:
Cs89x0_opts =
Modify/usr/src/Linux/Drivers/NET/config. In and add:
Tristate 'cs8920 support 'config _ cs8920
The preceding two rows are used to enable make config to check whether cs8920 is added during configuration.Nic. Add/usr/src/Linux/Drivers/NET/makefile:
Ifeq (config_cs8920), Y)
L_objs + = cs89x0. o
Endif
Modify/usr/src/Linux/Drivers/NET/space. C and add:
Extern int cs89x0_probe (struct device * Dev );
......
# Ifdef config_cs8920
& Amp; cs89x0_probe (Dev );
# Endif
The above two sections are for compilation and OutputNicDriver and its routine.
Copy the driver source code to the/usr/src/Linux/Drivers/NET directory.
Run make config or make menuconfig in the/usr/src/Linux directory and select core cs8920NicYes.
Run make Dep and make clean commands. Finally, use make zimage to compile the Linux core.
The preceding section describes how to set core driver parameters.
Vi. Conclusion
Like other peripherals, EthernetNicThere are many types of operating system Linux. Whether these devices can be effectively supported is directly related to the future of Linux. Ethernet described in this articleNicThe installation configuration is only a small part of the configuration, and we hope to discuss the issues with our experts.