diff --git a/drivers/ethernet/eth_dw.c b/drivers/ethernet/eth_dw.c index c74780b19e7..1997cfb8e05 100644 --- a/drivers/ethernet/eth_dw.c +++ b/drivers/ethernet/eth_dw.c @@ -329,6 +329,20 @@ static void eth_initialize(struct net_if *iface) } } +static enum eth_hw_caps eth_dw_get_capabilities(struct device *dev) +{ + ARG_UNUSED(dev); + + return ETH_LINK_10BASE_T | ETH_LINK_100BASE_T; +} + +static const struct ethernet_api api_funcs = { + .iface_api.init = eth_initialize, + .iface_api.send = eth_tx, + + .get_capabilities = eth_dw_get_capabilities, +}; + /* Bindings to the plaform */ #if CONFIG_ETH_DW_0 static void eth_config_0_irq(struct device *port) @@ -373,11 +387,6 @@ static struct eth_runtime eth_0_runtime = { #endif }; -static const struct ethernet_api api_funcs = { - .iface_api.init = eth_initialize, - .iface_api.send = eth_tx, -}; - NET_DEVICE_INIT(eth_dw_0, CONFIG_ETH_DW_0_NAME, eth_setup, ð_0_runtime, ð_config_0, CONFIG_ETH_INIT_PRIORITY, &api_funcs, diff --git a/drivers/ethernet/eth_enc28j60.c b/drivers/ethernet/eth_enc28j60.c index 6d2b78e8ce9..ad7a9bbde18 100644 --- a/drivers/ethernet/eth_enc28j60.c +++ b/drivers/ethernet/eth_enc28j60.c @@ -764,6 +764,13 @@ static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt) return ret; } +static enum eth_hw_caps eth_enc28j60_get_capabilities(struct device *dev) +{ + ARG_UNUSED(dev); + + return ETH_LINK_10BASE_T; +} + #ifdef CONFIG_ETH_ENC28J60_0 static u8_t mac_address_0[6] = { MICROCHIP_OUI_B0, @@ -773,7 +780,7 @@ static u8_t mac_address_0[6] = { MICROCHIP_OUI_B0, CONFIG_ETH_ENC28J60_0_MAC4, CONFIG_ETH_ENC28J60_0_MAC5 }; -static void eth_enc28j60_iface_init_0(struct net_if *iface) +static void eth_enc28j60_iface_init(struct net_if *iface) { struct device *dev = net_if_get_device(iface); struct eth_enc28j60_runtime *context = dev->driver_data; @@ -785,9 +792,11 @@ static void eth_enc28j60_iface_init_0(struct net_if *iface) context->iface = iface; } -static const struct ethernet_api api_funcs_0 = { - .iface_api.init = eth_enc28j60_iface_init_0, +static const struct ethernet_api api_funcs = { + .iface_api.init = eth_enc28j60_iface_init, .iface_api.send = eth_net_tx, + + .get_capabilities = eth_enc28j60_get_capabilities, }; static struct eth_enc28j60_runtime eth_enc28j60_0_runtime; @@ -808,7 +817,7 @@ static const struct eth_enc28j60_config eth_enc28j60_0_config = { NET_DEVICE_INIT(enc28j60_0, CONFIG_ETH_ENC28J60_0_NAME, eth_enc28j60_init, ð_enc28j60_0_runtime, - ð_enc28j60_0_config, CONFIG_ETH_INIT_PRIORITY, &api_funcs_0, + ð_enc28j60_0_config, CONFIG_ETH_INIT_PRIORITY, &api_funcs, ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2), 1500); #endif /* CONFIG_ETH_ENC28J60_0 */ diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 2c211bea417..3792d906cf3 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -643,7 +643,7 @@ static void net_if_mcast_cb(struct net_if *iface, } #endif /* CONFIG_NET_IPV6 */ -static void eth_0_iface_init(struct net_if *iface) +static void eth_iface_init(struct net_if *iface) { struct device *dev = net_if_get_device(iface); struct eth_context *context = dev->driver_data; @@ -664,22 +664,18 @@ static void eth_0_iface_init(struct net_if *iface) ethernet_init(iface); } -#if defined(CONFIG_NET_VLAN) -static enum eth_hw_caps eth_capabilities(struct device *dev) +static enum eth_hw_caps eth_mcux_get_capabilities(struct device *dev) { ARG_UNUSED(dev); - return ETH_HW_VLAN; + return ETH_HW_VLAN | ETH_LINK_10BASE_T | ETH_LINK_100BASE_T; } -#endif -static const struct ethernet_api api_funcs_0 = { - .iface_api.init = eth_0_iface_init, +static const struct ethernet_api api_funcs = { + .iface_api.init = eth_iface_init, .iface_api.send = eth_tx, -#if defined(CONFIG_NET_VLAN) - .get_capabilities = eth_capabilities, -#endif + .get_capabilities = eth_mcux_get_capabilities, }; static void eth_mcux_rx_isr(void *p) @@ -728,7 +724,7 @@ static struct eth_context eth_0_context = { ETH_NET_DEVICE_INIT(eth_mcux_0, CONFIG_ETH_MCUX_0_NAME, eth_0_init, ð_0_context, NULL, CONFIG_ETH_INIT_PRIORITY, - &api_funcs_0, 1500); + &api_funcs, 1500); static void eth_0_config_func(void) { diff --git a/drivers/ethernet/eth_native_posix.c b/drivers/ethernet/eth_native_posix.c index 8022b0cc290..3ae0177a19c 100644 --- a/drivers/ethernet/eth_native_posix.c +++ b/drivers/ethernet/eth_native_posix.c @@ -269,22 +269,18 @@ static void eth_iface_init(struct net_if *iface) } } -#if defined(CONFIG_NET_VLAN) -static enum eth_hw_caps eth_capabilities(struct device *dev) +static enum eth_hw_caps eth_posix_native_get_capabilities(struct device *dev) { ARG_UNUSED(dev); return ETH_HW_VLAN; } -#endif static const struct ethernet_api eth_if_api = { .iface_api.init = eth_iface_init, .iface_api.send = eth_send, -#if defined(CONFIG_NET_VLAN) - .get_capabilities = eth_capabilities, -#endif + .get_capabilities = eth_posix_native_get_capabilities, }; ETH_NET_DEVICE_INIT(eth_native_posix, CONFIG_ETH_NATIVE_POSIX_DRV_NAME, diff --git a/drivers/ethernet/eth_sam_gmac.c b/drivers/ethernet/eth_sam_gmac.c index bf901d9c40c..a4be87ec2ef 100644 --- a/drivers/ethernet/eth_sam_gmac.c +++ b/drivers/ethernet/eth_sam_gmac.c @@ -899,22 +899,18 @@ static void eth0_iface_init(struct net_if *iface) init_done = true; } -#if defined(CONFIG_NET_VLAN) -static enum eth_hw_caps eth_capabilities(struct device *dev) +static enum eth_hw_caps eth_sam_gmac_get_capabilities(struct device *dev) { ARG_UNUSED(dev); - return ETH_HW_VLAN; + return ETH_HW_VLAN | ETH_LINK_10BASE_T | ETH_LINK_100BASE_T; } -#endif -static const struct ethernet_api eth0_api = { +static const struct ethernet_api eth_api = { .iface_api.init = eth0_iface_init, .iface_api.send = eth_tx, -#if defined(CONFIG_NET_VLAN) - .get_capabilities = eth_capabilities, -#endif + .get_capabilities = eth_sam_gmac_get_capabilities, }; static struct device DEVICE_NAME_GET(eth0_sam_gmac); @@ -992,4 +988,4 @@ static struct eth_sam_dev_data eth0_data = { ETH_NET_DEVICE_INIT(eth0_sam_gmac, CONFIG_ETH_SAM_GMAC_NAME, eth_initialize, ð0_data, ð0_config, CONFIG_ETH_INIT_PRIORITY, - ð0_api, GMAC_MTU); + ð_api, GMAC_MTU); diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c index 32a2459b07c..da12ab3ee00 100644 --- a/drivers/ethernet/eth_stm32_hal.c +++ b/drivers/ethernet/eth_stm32_hal.c @@ -306,7 +306,7 @@ static void generate_mac(u8_t *mac_addr) } #endif -static void eth0_iface_init(struct net_if *iface) +static void eth_iface_init(struct net_if *iface) { struct device *dev; struct eth_stm32_hal_dev_data *dev_data; @@ -369,9 +369,18 @@ static void eth0_iface_init(struct net_if *iface) NET_LINK_ETHERNET); } -static const struct ethernet_api eth0_api = { - .iface_api.init = eth0_iface_init, +static enum eth_hw_caps eth_stm32_hal_get_capabilities(struct device *dev) +{ + ARG_UNUSED(dev); + + return ETH_LINK_10BASE_T | ETH_LINK_100BASE_T; +} + +static const struct ethernet_api eth_api = { + .iface_api.init = eth_iface_init, .iface_api.send = eth_tx, + + .get_capabilities = eth_stm32_hal_get_capabilities, }; static struct device DEVICE_NAME_GET(eth0_stm32_hal); @@ -420,5 +429,5 @@ static struct eth_stm32_hal_dev_data eth0_data = { }; NET_DEVICE_INIT(eth0_stm32_hal, CONFIG_ETH_STM32_HAL_NAME, eth_initialize, - ð0_data, ð0_config, CONFIG_ETH_INIT_PRIORITY, ð0_api, + ð0_data, ð0_config, CONFIG_ETH_INIT_PRIORITY, ð_api, ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2), ETH_STM32_HAL_MTU); diff --git a/drivers/net/slip.c b/drivers/net/slip.c index fc159319d26..adfc84b5160 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -508,23 +508,19 @@ use_random_mac: static struct slip_context slip_context_data; -#if defined(CONFIG_NET_VLAN) static enum eth_hw_caps eth_capabilities(struct device *dev) { ARG_UNUSED(dev); return ETH_HW_VLAN; } -#endif #if defined(CONFIG_SLIP_TAP) && defined(CONFIG_NET_L2_ETHERNET) static const struct ethernet_api slip_if_api = { .iface_api.init = slip_iface_init, .iface_api.send = slip_send, -#if defined(CONFIG_NET_VLAN) .get_capabilities = eth_capabilities, -#endif }; #define _SLIP_L2_LAYER ETHERNET_L2 diff --git a/include/net/ethernet.h b/include/net/ethernet.h index 882ccc8c311..88c0f4811e9 100644 --- a/include/net/ethernet.h +++ b/include/net/ethernet.h @@ -45,13 +45,28 @@ extern "C" { enum eth_hw_caps { /** TX Checksum offloading supported */ - ETH_HW_TX_CHKSUM_OFFLOAD = BIT(0), + ETH_HW_TX_CHKSUM_OFFLOAD = BIT(0), /** RX Checksum offloading supported */ - ETH_HW_RX_CHKSUM_OFFLOAD = BIT(1), + ETH_HW_RX_CHKSUM_OFFLOAD = BIT(1), /** VLAN supported */ - ETH_HW_VLAN = BIT(2), + ETH_HW_VLAN = BIT(2), + + /** Enabling/disabling auto negotiation supported */ + ETH_AUTO_NEGOTIATION_SET = BIT(3), + + /** 10 Mbits link supported */ + ETH_LINK_10BASE_T = BIT(4), + + /** 100 Mbits link supported */ + ETH_LINK_100BASE_T = BIT(5), + + /** 1 Gbits link supported */ + ETH_LINK_1000BASE_T = BIT(6), + + /** Changing duplex (half/full) supported */ + ETH_DUPLEX_SET = BIT(7), }; struct ethernet_api { diff --git a/tests/net/checksum_offload/src/main.c b/tests/net/checksum_offload/src/main.c index fd447bf7b3d..eb7888680d9 100644 --- a/tests/net/checksum_offload/src/main.c +++ b/tests/net/checksum_offload/src/main.c @@ -220,9 +220,16 @@ static enum eth_hw_caps eth_offloading_enabled(struct device *dev) ETH_HW_RX_CHKSUM_OFFLOAD; } +static enum eth_hw_caps eth_offloading_disabled(struct device *dev) +{ + return 0; +} + static struct ethernet_api api_funcs_offloading_disabled = { .iface_api.init = eth_iface_init, .iface_api.send = eth_tx_offloading_disabled, + + .get_capabilities = eth_offloading_disabled, }; static struct ethernet_api api_funcs_offloading_enabled = {