From 31f89b03036f14d113e989184ee3698689b4f5b9 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Thu, 9 Aug 2018 16:08:27 +0300 Subject: [PATCH] net: eth: Add start and stop L2 functions If the driver has created start() and stop() functions, then those are called when ethernet L2 is enabled or disabled. Signed-off-by: Jukka Rissanen --- include/net/ethernet.h | 6 ++++++ subsys/net/l2/ethernet/ethernet.c | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/net/ethernet.h b/include/net/ethernet.h index 750c432a301..a007b5ecbf6 100644 --- a/include/net/ethernet.h +++ b/include/net/ethernet.h @@ -185,6 +185,12 @@ struct ethernet_api { struct net_stats_eth *(*get_stats)(struct device *dev); #endif + /** Start the device */ + int (*start)(struct device *dev); + + /** Stop the device */ + int (*stop)(struct device *dev); + /** Get the device capabilities */ enum ethernet_hw_caps (*get_capabilities)(struct device *dev); diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index b24fda41af3..b4815d2a5fb 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -576,8 +576,19 @@ static inline u16_t ethernet_reserve(struct net_if *iface, void *unused) static inline int ethernet_enable(struct net_if *iface, bool state) { + const struct ethernet_api *eth = + net_if_get_device(iface)->driver_api; + if (!state) { net_arp_clear_cache(iface); + + if (eth->stop) { + eth->stop(net_if_get_device(iface)); + } + } else { + if (eth->start) { + eth->start(net_if_get_device(iface)); + } } return 0;