at Tuesday, October 02, 2007
Driver load (attach) follows the probe. During load, the driver initializes the device. Driver unload(detach) is the last step. During unload, the driver frees all initializations made during load.
Network drivers are required to implement some functions like init, stop, ioctl etc. During init, interface will be made active. After this all packet transmit and receive will start. Interface will be made inactive during stop. After this interface stops receiving packets and the Kernel implementation stops sending packets through this interface. Device is controlled through ioctl implementation. Changing IP address, MTU size, Ethernet Address, enabling/disabling interface, Enabling/disabling promiscuous mode etc are done through ioctl.
Interrupt registration is required while enabling interface. Only after registering interrupt the device will be able to receive Tx/Rx completion interrupt service requests. Interrupt service requests can also be due to errors. Tx interrupts indicate completion of transmission (packets have been transmitted through cable). Rx interrupts indicate completion of receiving a packet.
Drivers implement a function to process interrupt service requests. Reason for interrupt will be decided through hardware registers. Reason can be transmit completion, receive completion, errors etc.
If the interrupt was due to transmit completion, the buffer (mbuf) corresponding to the completed packet will be freed. If the interrupt was due to receive completion, the received packet will be sent up to the Network layer for further processing. If the interrupt was due to an error, corresponding actions will be taken (can be reset of hardware etc.).
Transmit function will be called if there are any packets to be sent. Get packets from the queue (maintained for each interface). Encapsulate them within a transmit descriptor, update any required fields in descriptor (hardware dependent). Send it to hardware.
Once transmit operation is complete for that descriptor, an interrupt service request will be raised.
Once reception of a packet is complete, hardware encapsulates that packet into a descriptor and raise an interrupt service request. Driver will decapsulates the packet and send it to the network stack. Before this, if there were any errors in the packet, corresponding actions will be taken.