Network Device Initialization
To make a network device available, it must be correctly identified by the kernel and associated with the correct device driver. First, the device driver can be dynamically loaded as the kernel module or a static component of the kernel. Secondly, the device can be identified at startup or load during runtime (hot swapping device usb pci ieee ...)
Device registration and initialization for Statically compiled Device Drivers/startup identifiers
System initialization process (Both the kernel subsystem and the device driver with static compilation are initialized in do_initcils, And the parse_args processing system is started.ProgramThe parameter that LILO/GRUB passes to the kernel. init_irq/softing_init initializes hardware interruption. and software interruption, free_init_mem releases the memory occupied by the Code that is no longer in use.
device registration and initialization for startup recognition are roughly divided into three steps;
1) hardware initialization: the device driver completes hardware initialization under the coordination of the bus (PCI, USB) and allocates the interrupt number and I/O address.
2) software initialization --- some parameters need to be configured before the device is available, such as IP address
3) function initialization --- Related to the device, for example, traffic control
1 2 will be detailed in the following chapters. Here, we will only briefly mention 3. The Code is as follows;
static in _ init net_dev_init {
...
}< br> subsys_initcall (net_dev_init)
net_dev_init includes initialization of the following functions
initialize the CPU-related data structure for soft network interruptions
call dev_proc_init, dev_mcast_init Add the corresponding file under/proc
call netdev_sysfs to add the corresponding configuration file under/sys
call net_random_init to initialize the CPU seed array, these arrays are used to generate random numbers in net_random
call dst_init to initialize DST
initialize the network processing function array ptype_base, these functions are used to break down received packets.
the callback function is registered on the notification linked list to receive CPU Hot swapping events.
In addition to the above initialization, for network devices, it is more important to initialize their net_device structure. This will be detailed in chapter 8th.
Dynamic device/Device Driver Loading
2 user space programs and 1 kernel function are introduced before dynamic loading.
/Sbin/modprobe is called when the kernel needs to load a module to determine whether the module passed by the kernel is an alias defined in the/etc/modprobe. conf file.
/Sbin/hotplug is called when the kernel detects that a new device is inserted or pulled out of the system. Its task is to load the correct driver according to the device ID.
The two user processes in the kernel function call_usermodehelper are called by this function. The ARG [0] parameter indicates the user process called by call_usermodehelper. Arg [1] indicates the call... which configuration is used Set the script. For details about the process, see;
In fact, I have understood what I mentioned above. The concept of dynamic loading should be very clear. Finally, let's talk about the use scenario.
1) load data in Modules
The kmod module loader allows kernel components to load a module by calling request_module requests.
For example, if the system administrator uses ifconfig to configure a nic, but the NIC driver is not loaded yet, for example, eth0, the kernel will send a request to/sbin/modprobe, load it with the name Eth0 module. If/etc/modprobe. conf contains the "alias eth0 XXX" character,/sbin/modprobe will try to load the XXX. Ko module.
2) PNP hot swapping
Hotplug allows the kernel to detect the insertion and removal of hot swapping devices and notify the user process (/sbin/hotplug). The user process loads the corresponding Driver Based on these notifications.
During kernel compilation, modules is generated under the kernel directory. pcimap and modules. the USB map files include the pci id and usb id of the devices supported by the kernel. The name of the kernel module corresponding to the ID of each device. When the user process receives the kernel's message about PNP, it will use this file to find the correct device driver.