Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| ndo_change_carrier [2018/08/04 10:24] – rpjday | ndo_change_carrier [2018/08/04 17:31] (current) – [Overview] rpjday | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Overview ===== | ===== Overview ===== | ||
| - | The implications of setting '' | + | Setting/ |
| - | ===== net/ | + | ===== Normal behaviour |
| + | |||
| + | ==== Net device state ==== | ||
| + | |||
| + | From '' | ||
| + | |||
| + | Net device state: | ||
| < | < | ||
| - | static | + | struct net_device { |
| + | ... snip ... | ||
| + | unsigned long | ||
| + | ... snip ... | ||
| + | </ | ||
| + | |||
| + | State flag bits for later testing: | ||
| + | |||
| + | < | ||
| + | enum netdev_state_t { | ||
| + | __LINK_STATE_START, | ||
| + | __LINK_STATE_PRESENT, | ||
| + | __LINK_STATE_NOCARRIER, | ||
| + | __LINK_STATE_LINKWATCH_PENDING, | ||
| + | __LINK_STATE_DORMANT, | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | ==== Checking for state of carrier ==== | ||
| + | |||
| + | Again from '' | ||
| + | |||
| + | < | ||
| + | /** | ||
| + | | ||
| + | | ||
| + | * | ||
| + | * Check if carrier is present on device | ||
| + | */ | ||
| + | static | ||
| { | { | ||
| - | | + | |
| - | return | + | |
| - | return dev_change_carrier(dev, | + | |
| } | } | ||
| - | static ssize_t carrier_store(struct | + | void netif_carrier_on(struct |
| - | | + | void netif_carrier_off(struct |
| + | </ | ||
| + | |||
| + | ==== Test for interface running ==== | ||
| + | |||
| + | Still in '' | ||
| + | |||
| + | < | ||
| + | /** | ||
| + | | ||
| + | | ||
| + | * | ||
| + | | ||
| + | */ | ||
| + | static inline bool netif_running(const struct net_device | ||
| { | { | ||
| - | | + | return |
| + | } | ||
| + | </ | ||
| + | ==== Test if carrier on or off ==== | ||
| + | |||
| + | From '' | ||
| + | |||
| + | < | ||
| + | /** | ||
| + | | ||
| + | | ||
| + | * | ||
| + | * Device has detected that carrier. | ||
| + | */ | ||
| + | void netif_carrier_on(struct net_device *dev) | ||
| + | { | ||
| + | if (test_and_clear_bit(__LINK_STATE_NOCARRIER, & | ||
| + | if (dev-> | ||
| + | return; | ||
| + | atomic_inc(& | ||
| + | linkwatch_fire_event(dev); | ||
| + | if (netif_running(dev)) | ||
| + | __netdev_watchdog_up(dev); | ||
| + | } | ||
| } | } | ||
| + | EXPORT_SYMBOL(netif_carrier_on); | ||
| - | static ssize_t carrier_show(struct device | + | /** |
| - | | + | |
| + | | ||
| + | * | ||
| + | * Device has detected loss of carrier. | ||
| + | */ | ||
| + | void netif_carrier_off(struct net_device *dev) | ||
| { | { | ||
| - | | + | if (!test_and_set_bit(__LINK_STATE_NOCARRIER, |
| - | | + | |
| - | return | + | |
| + | atomic_inc(& | ||
| + | linkwatch_fire_event(dev); | ||
| } | } | ||
| - | return -EINVAL; | ||
| } | } | ||
| - | static DEVICE_ATTR_RW(carrier); | + | EXPORT_SYMBOL(netif_carrier_off); |
| </ | </ | ||