嵌入式linux中文站在线图书

Previous Page
Next Page

8.11. Enabling and Disabling a Network Device

Once a device has been registered it is available for use, but it will not transmit and receive traffic until it is explicitly enabled by the user (or a user-space application). Requests to enable a device are taken care of by dev_open, defined in net/core/dev.c. Enabling a device consists of the following tasks:

  • Call dev->open if it is defined. Not all device drivers initialize this function.

  • Set the _ _LINK_STATE_START flag in dev->state to mark the device as up and running.

    Figure 8-6. Function netdev_wait_allrefs

  • Set the IFF_UP flag in dev->flags to mark the device as up.

  • Call dev_activate to initialize the egress queuing discipline used by Traffic Control, and start the watchdog timer.[*] If there is no user configuration for Traffic Control, assign a default First In, First Out (FIFO) queue.

    [*] See Chapter 11 for more details on the watchdog timer.

  • Send a NEtdEV_UP notification to the netdev_chain notification chain to notify interested kernel components that the device is now enabled.

While a device needs to be explicitly enabled, it can be disabled either explicitly by a user command or implicitly by other events. For example, before a device is unregistered, it is first disabled (see the section "Device Unregistration"). Network devices are disabled with dev_close. Disabling a device consists of the following tasks:

  • Send a NETDEV_GOING_DOWN notification to the netdev_chain notification chain to notify interested kernel components that the device is about to be disabled.

  • Call dev_deactivate to disable the egress queuing discipline, thus making sure the device cannot be used for transmission anymore, and stop the watchdog timer because it is not needed anymore.

  • Clear the _ _LINK_STATE_START flag in dev->state to mark the device as down.

  • If a polling action was scheduled to read ingress packets on the device, wait for that action to complete. Because the _ _LINK_STATE_START flag has been cleared, no more receive polling will be scheduled on the device, but one could have been pending before the flag was cleared. See Chapter 10 for more detail on receive polling.

  • Call dev->stop if it is defined. Not all device drivers initialize this function.

  • Clear the IFF_UP flag in dev->flags to mark the device as down.

  • Send a NEtdEV_DOWN notification to the netdev_chain notification chain to notify interested kernel components that the device is now disabled.


Previous Page
Next Page