Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ndo_change_carrier [2018/08/04 12:09] rpjdayndo_change_carrier [2018/08/04 17:31] (current) – [Overview] rpjday
Line 1: Line 1:
 ===== Overview ===== ===== Overview =====
  
-Setting/detecting carrier, and the subsequent implications of setting ''net_device_ops'' ''ndo_change_carrier'' field.+Setting/detecting carrier, and the subsequent implications of setting ''net_device_ops'' ''ndo_change_carrier'' field (if any implications actually exist):
  
-===== include/linux/netdevice.h =====+===== Normal behaviour =====
  
 +==== Net device state ====
  
 +From ''include/linux/netdevice.h'':
 +
 +Net device state:
 +
 +<code>
 +struct net_device {
 +        ... snip ...
 +        unsigned long           state;
 +        ... snip ...
 +</code>
 +
 +State flag bits for later testing:
 +
 +<code>
 +enum netdev_state_t {
 +        __LINK_STATE_START,
 +        __LINK_STATE_PRESENT,
 +        __LINK_STATE_NOCARRIER,
 +        __LINK_STATE_LINKWATCH_PENDING,
 +        __LINK_STATE_DORMANT,
 +};
 +</code>
 +
 +==== Checking for state of carrier ====
 +
 +Again from ''netdevice.h'':
 +
 +<code>
 +/**
 +      netif_carrier_ok - test if carrier present
 +      @dev: network device
 + *
 + * Check if carrier is present on device
 + */
 +static inline bool netif_carrier_ok(const struct net_device *dev)
 +{
 +        return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
 +}
 +
 +void netif_carrier_on(struct net_device *dev);
 +void netif_carrier_off(struct net_device *dev);
 +</code>
 +
 +==== Test for interface running ====
 +
 +Still in ''netdevice.h'':
 +
 +<code>
 +/**
 + * netif_running - test if up
 + * @dev: network device
 + *
 + * Test if the device has been brought up.
 + */
 +static inline bool netif_running(const struct net_device *dev)
 +{
 + return test_bit(__LINK_STATE_START, &dev->state);
 +}
 +</code>
 +==== Test if carrier on or off ====
 +
 +From ''net/sched/sch_generic.c'':
 +
 +<code>
 +/**
 +      netif_carrier_on - set carrier
 +      @dev: network device
 + *
 + * Device has detected that carrier.
 + */
 +void netif_carrier_on(struct net_device *dev)
 +{
 +        if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
 +                if (dev->reg_state == NETREG_UNINITIALIZED)
 +                        return;
 +                atomic_inc(&dev->carrier_up_count);
 +                linkwatch_fire_event(dev);
 +                if (netif_running(dev))
 +                        __netdev_watchdog_up(dev);
 +        }
 +}
 +EXPORT_SYMBOL(netif_carrier_on);
 +
 +/**
 +      netif_carrier_off - clear carrier
 +      @dev: network device
 + *
 + * Device has detected loss of carrier.
 + */
 +void netif_carrier_off(struct net_device *dev)
 +{
 +        if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
 +                if (dev->reg_state == NETREG_UNINITIALIZED)
 +                        return;
 +                atomic_inc(&dev->carrier_down_count);
 +                linkwatch_fire_event(dev);
 +        }
 +}
 +EXPORT_SYMBOL(netif_carrier_off);
 +</code>
  • ndo_change_carrier.1533384579.txt.gz
  • Last modified: 2018/08/04 12:09
  • by rpjday