Device Registration and Initialization

来源:互联网 发布:值得买的电子产品知乎 编辑:程序博客网 时间:2024/06/05 16:05

When a Device Is Registered

Loading an NIC’s device driver
An NIC’s device driver is initialized at boot time if it is built into the kernel, and at runtime if it is loaded as a module. Whenever initialization occurs, all the NICs controlled by that driver are registered.
Inserting a hot-pluggable network device
When a user inserts a hot-pluggable NIC, the kernel notifies its driver, which then registers the device. (For the sake of simplicity, we’ll assume the device driver is already loaded.)

When a Device Is Unregistered

Unloading an NIC device driver
This can be done only for drivers loaded as modules, of course, not for those built into the kernel. When the administrator unloads an NIC’s device driver, all the associated NICs must be unregistered.

Removing a hot-pluggable network device
When a user removes a hot-pluggable NIC from a system whose running kernel has support for hot-pluggable devices, the network device is unregistered

Allocating net_device Structures

Network devices are defined with net_device structures.These data structures are allocated with alloc_netdev, defined in net/core/dev.c, which requires three input parameters:

Size of private data structure
the net_device data structure can be extended by device drivers with a private data block to store the driver’s parameters. This parameter specifies the size of the block.
Device name
This may be a partial name that the kernel will complete through some scheme that ensures unique device names.
Setup routine
This routine is used to initialize a portion of the net_device’s fields.
The return value is a pointer to the net_device structure allocated, or NULL in case of errors.

Every device is assigned a name that depends on the device type and that, to be unique, contains a number that is assigned sequentially as devices of the same type are registered. Ethernet devices, for instance, are called eth0, eth1, and so on. A single device may be called with different names depending on the order with which the www.it-devices are registered. For instance, if you had two cards handled by two different modules, the names of the devices would depend on the order in which the two modules were loaded. Hot-pluggable devices lend themselves particularly to unanticipated name changes.

Skeleton of NIC Registration and Unregistration

Device Initialization


0 0
原创粉丝点击