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:32] – [Overview] rpjday | ndo_change_carrier [2018/08/04 17:31] (current) – [Overview] rpjday | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Overview ===== | ===== Overview ===== | ||
| - | The implications of setting '' | + | Setting/ |
| - | ===== include/ | + | ===== Normal behaviour ===== |
| + | |||
| + | ==== Net device state ==== | ||
| + | |||
| + | From '' | ||
| + | |||
| + | Net device state: | ||
| < | < | ||
| struct net_device { | struct net_device { | ||
| ... snip ... | ... snip ... | ||
| - | | + | |
| ... snip ... | ... snip ... | ||
| </ | </ | ||
| + | |||
| + | State flag bits for later testing: | ||
| < | < | ||
| - | struct net_device_ops | + | enum netdev_state_t |
| + | __LINK_STATE_START, | ||
| + | __LINK_STATE_PRESENT, | ||
| + | __LINK_STATE_NOCARRIER, | ||
| + | __LINK_STATE_LINKWATCH_PENDING, | ||
| + | __LINK_STATE_DORMANT, | ||
| + | }; | ||
| + | </ | ||
| - | ... snip ... | + | ==== Checking for state of carrier ==== |
| - | * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier); | + | Again from '' |
| - | | + | |
| - | * which do not represent real hardware may define this to allow their | + | < |
| - | | + | /** |
| - | | + | |
| - | | + | |
| - | | + | |
| * | * | ||
| + | * Check if carrier is present on device | ||
| + | */ | ||
| + | static inline bool netif_carrier_ok(const struct net_device *dev) | ||
| + | { | ||
| + | return !test_bit(__LINK_STATE_NOCARRIER, | ||
| + | } | ||
| + | |||
| + | void netif_carrier_on(struct net_device *dev); | ||
| + | void netif_carrier_off(struct net_device *dev); | ||
| </ | </ | ||
| - | ===== net/ | + | |
| + | ==== Test for interface running | ||
| + | |||
| + | Still in '' | ||
| < | < | ||
| - | static | + | /** |
| + | | ||
| + | | ||
| + | * | ||
| + | | ||
| + | */ | ||
| + | static | ||
| { | { | ||
| - | if (!netif_running(dev)) | + | return test_bit(__LINK_STATE_START, |
| - | return | + | |
| - | return dev_change_carrier(dev, | + | |
| } | } | ||
| + | </ | ||
| + | ==== Test if carrier on or off ==== | ||
| - | static ssize_t carrier_store(struct device | + | From '' |
| - | const char *buf, size_t len) | + | |
| + | < | ||
| + | /** | ||
| + | | ||
| + | | ||
| + | * | ||
| + | | ||
| + | */ | ||
| + | void netif_carrier_on(struct net_device *dev) | ||
| { | { | ||
| - | return | + | |
| + | if (dev-> | ||
| + | | ||
| + | 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); |
| </ | </ | ||
| - | |||
| - | Note how showing the value of '' | ||
| - | |||
| - | * '' | ||
| - | * '' | ||