From 276ad5716a00194bf5d6856893f1deef0a9e4211 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 9 Aug 2022 14:58:36 +0200 Subject: [PATCH] sys/net/gnrc/netif: allow checking if a netdev is legacy or new API A if `netdev_driver_t::confirm_send()` is provided, it provides the new netdev API. However, detecting the API at runtime and handling both API styles comes at a cost. This can be optimized in case only new or only old style netdevs are in use. To do so, this adds the pseudo modules `netdev_legacy_api` and `netdev_new_api`. As right now no netdev actually implements the new API, all netdevs pull in `netdev_legacy_api`. If `netdev_legacy_api` is in used but `netdev_new_api` is not, we can safely assume at compile time that only legacy netdevs are in use. Similar, if only `netdev_new_api` is used, only support for the new API is needed. Only when both are in use, run time checks are needed. This provides two helper function to check for a netif if the corresponding netdev implements the old or the new API. (With one being the inverse of the other.) They are suitable for constant folding when only new or only legacy devices are in use. Consequently, dead branches should be eliminated by the optimizer. --- cpu/esp_common/Makefile.dep | 1 + cpu/sam0_common/Makefile.dep | 5 ++- cpu/stm32/Makefile.dep | 3 +- drivers/Makefile.dep | 2 +- drivers/at86rf215/Kconfig | 1 + drivers/at86rf215/Makefile.dep | 1 + drivers/at86rf2xx/Kconfig | 5 ++- drivers/at86rf2xx/Makefile.dep | 1 + drivers/atwinc15x0/Makefile.dep | 1 + drivers/cc110x/Makefile.dep | 1 + drivers/cc2420/Kconfig | 7 ++-- drivers/cc2420/Makefile.dep | 1 + drivers/dose/Kconfig | 9 +++-- drivers/dose/Makefile.dep | 1 + drivers/enc28j60/Kconfig | 5 ++- drivers/enc28j60/Makefile.dep | 1 + drivers/encx24j600/Kconfig | 3 +- drivers/encx24j600/Makefile.dep | 1 + drivers/ethos/Kconfig | 3 +- drivers/ethos/Makefile.dep | 1 + drivers/kw2xrf/Kconfig | 13 +++---- drivers/mrf24j40/Kconfig | 7 ++-- drivers/mrf24j40/Makefile.dep | 3 +- drivers/netdev/Kconfig | 17 ++++++++ drivers/netdev_ieee802154_submac/Kconfig | 3 +- drivers/nrf24l01p_ng/Makefile.dep | 1 + drivers/rn2xx3/Kconfig | 3 +- drivers/rn2xx3/Makefile.dep | 3 +- drivers/slipdev/Kconfig | 3 +- drivers/slipdev/Makefile.dep | 3 +- drivers/sx126x/Kconfig | 3 +- drivers/sx126x/Makefile.dep | 1 + drivers/sx127x/Kconfig | 13 ++++--- drivers/sx127x/Makefile.dep | 1 + drivers/sx1280/Makefile.dep | 1 + drivers/w5100/Kconfig | 5 ++- drivers/w5100/Makefile.dep | 3 +- drivers/xbee/Makefile.dep | 1 + makefiles/pseudomodules.inc.mk | 2 + sys/Makefile.dep | 1 + sys/include/net/gnrc/netif.h | 49 ++++++++++++++++++++++++ 41 files changed, 146 insertions(+), 43 deletions(-) diff --git a/cpu/esp_common/Makefile.dep b/cpu/esp_common/Makefile.dep index cbf337ea17..37acc5cd98 100644 --- a/cpu/esp_common/Makefile.dep +++ b/cpu/esp_common/Makefile.dep @@ -97,6 +97,7 @@ ifneq (,$(filter esp_wifi,$(USEMODULE))) endif ifneq (,$(filter esp_wifi_any,$(USEMODULE))) + USEMODULE += netdev_legacy_api USEMODULE += netopt USEMODULE += ztimer_msec endif diff --git a/cpu/sam0_common/Makefile.dep b/cpu/sam0_common/Makefile.dep index 3524f8a1d7..f6e33c8c25 100644 --- a/cpu/sam0_common/Makefile.dep +++ b/cpu/sam0_common/Makefile.dep @@ -14,9 +14,10 @@ endif USEMODULE += sam0_common_periph ifneq (,$(filter sam0_eth,$(USEMODULE))) - USEMODULE += netdev_eth - USEMODULE += netopt USEMODULE += iolist + USEMODULE += netdev_eth + USEMODULE += netdev_legacy_api + USEMODULE += netopt FEATURES_REQUIRED += periph_eth endif include $(RIOTCPU)/cortexm_common/Makefile.dep diff --git a/cpu/stm32/Makefile.dep b/cpu/stm32/Makefile.dep index fd45ed8ac4..519ed17c9c 100644 --- a/cpu/stm32/Makefile.dep +++ b/cpu/stm32/Makefile.dep @@ -22,8 +22,9 @@ endif ifneq (,$(filter stm32_eth,$(USEMODULE))) FEATURES_REQUIRED += periph_eth - USEMODULE += netdev_eth USEMODULE += iolist + USEMODULE += netdev_eth + USEMODULE += netdev_legacy_api USEMODULE += ztimer USEMODULE += ztimer_msec diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 398bdc36fd..5573f73588 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -237,7 +237,7 @@ ifneq (,$(filter periph_timer_periodic,$(USEMODULE))) FEATURES_REQUIRED += periph_timer endif -ifneq (,$(filter-out netdev_default, $(filter netdev_%,$(USEMODULE)))) +ifneq (,$(filter-out netdev_default netdev_new_api netdev_legacy_api, $(filter netdev_%,$(USEMODULE)))) USEMODULE += netdev # Don't register netdevs if there is only a single one of them ifeq (,$(filter gnrc_netif_single,$(USEMODULE))) diff --git a/drivers/at86rf215/Kconfig b/drivers/at86rf215/Kconfig index bdbe60810a..db97110b1e 100644 --- a/drivers/at86rf215/Kconfig +++ b/drivers/at86rf215/Kconfig @@ -16,6 +16,7 @@ menuconfig MODULE_AT86RF215 depends on HAS_PERIPH_SPI select MODULE_NETDEV select MODULE_NETDEV_IEEE802154 + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI diff --git a/drivers/at86rf215/Makefile.dep b/drivers/at86rf215/Makefile.dep index 399dc53aab..132a617595 100644 --- a/drivers/at86rf215/Makefile.dep +++ b/drivers/at86rf215/Makefile.dep @@ -33,3 +33,4 @@ endif USEMODULE += xtimer USEMODULE += ieee802154 USEMODULE += netdev_ieee802154 +USEMODULE += netdev_legacy_api diff --git a/drivers/at86rf2xx/Kconfig b/drivers/at86rf2xx/Kconfig index 4db69eff2d..f93c04e1ab 100644 --- a/drivers/at86rf2xx/Kconfig +++ b/drivers/at86rf2xx/Kconfig @@ -10,10 +10,11 @@ menuconfig MODULE_AT86RF2XX prompt "AT86RF2xx series radios" if !(MODULE_NETDEV_DEFAULT && HAVE_AT86RF2XX) default (MODULE_NETDEV_DEFAULT && HAVE_AT86RF2XX) depends on TEST_KCONFIG - select MODULE_XTIMER + select MODULE_IEEE802154 select MODULE_NETDEV select MODULE_NETDEV_IEEE802154 - select MODULE_IEEE802154 + select MODULE_NETDEV_LEGACY_API + select MODULE_XTIMER if MODULE_AT86RF2XX diff --git a/drivers/at86rf2xx/Makefile.dep b/drivers/at86rf2xx/Makefile.dep index bfd0f3da64..6f377f217f 100644 --- a/drivers/at86rf2xx/Makefile.dep +++ b/drivers/at86rf2xx/Makefile.dep @@ -4,6 +4,7 @@ DEFAULT_MODULE += netdev_ieee802154_oqpsk USEMODULE += xtimer USEMODULE += ieee802154 USEMODULE += netdev_ieee802154 +USEMODULE += netdev_legacy_api # only needed for SPI based variants ifeq (,$(filter at86rfa1 at86rfr2,$(USEMODULE))) diff --git a/drivers/atwinc15x0/Makefile.dep b/drivers/atwinc15x0/Makefile.dep index ab8e7b49b6..f68a18760f 100644 --- a/drivers/atwinc15x0/Makefile.dep +++ b/drivers/atwinc15x0/Makefile.dep @@ -1,5 +1,6 @@ USEMODULE += netdev_eth USEMODULE += ztimer_msec +USEMODULE += netdev_legacy_api USEPKG += driver_atwinc15x0 FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq diff --git a/drivers/cc110x/Makefile.dep b/drivers/cc110x/Makefile.dep index f54ac30bb7..ab5af71496 100644 --- a/drivers/cc110x/Makefile.dep +++ b/drivers/cc110x/Makefile.dep @@ -1,6 +1,7 @@ USEMODULE += cc1xxx_common USEMODULE += luid USEMODULE += xtimer +USEMODULE += netdev_legacy_api FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi diff --git a/drivers/cc2420/Kconfig b/drivers/cc2420/Kconfig index ea32501c79..d1d33ce169 100644 --- a/drivers/cc2420/Kconfig +++ b/drivers/cc2420/Kconfig @@ -11,13 +11,14 @@ config MODULE_CC2420 depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_IEEE802154 + select MODULE_NETDEV + select MODULE_NETDEV_IEEE802154 + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI select MODULE_XTIMER - select MODULE_IEEE802154 - select MODULE_NETDEV - select MODULE_NETDEV_IEEE802154 config HAVE_CC2420 bool diff --git a/drivers/cc2420/Makefile.dep b/drivers/cc2420/Makefile.dep index 611bf7fdb2..3841e82624 100644 --- a/drivers/cc2420/Makefile.dep +++ b/drivers/cc2420/Makefile.dep @@ -1,6 +1,7 @@ USEMODULE += xtimer USEMODULE += ieee802154 USEMODULE += netdev_ieee802154 +USEMODULE += netdev_legacy_api FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi diff --git a/drivers/dose/Kconfig b/drivers/dose/Kconfig index c7876ba9b9..aab666ba92 100644 --- a/drivers/dose/Kconfig +++ b/drivers/dose/Kconfig @@ -28,15 +28,16 @@ menuconfig MODULE_DOSE depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_UART + select MODULE_CHUNKED_RINGBUFFER + select MODULE_EUI_PROVIDER + select MODULE_IOLIST + select MODULE_NETDEV_ETH + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_UART select MODULE_PERIPH_UART_COLLISION if HAS_PERIPH_UART_COLLISION select MODULE_PERIPH_UART_RXSTART_IRQ if HAS_PERIPH_UART_RXSTART_IRQ - select MODULE_CHUNKED_RINGBUFFER - select MODULE_EUI_PROVIDER - select MODULE_IOLIST - select MODULE_NETDEV_ETH select MODULE_RANDOM select MODULE_ZTIMER select ZTIMER_USEC diff --git a/drivers/dose/Makefile.dep b/drivers/dose/Makefile.dep index 6f3cc3507b..9de44766c6 100644 --- a/drivers/dose/Makefile.dep +++ b/drivers/dose/Makefile.dep @@ -11,5 +11,6 @@ USEMODULE += chunked_ringbuffer USEMODULE += eui_provider USEMODULE += iolist USEMODULE += netdev_eth +USEMODULE += netdev_legacy_api USEMODULE += random USEMODULE += ztimer_usec diff --git a/drivers/enc28j60/Kconfig b/drivers/enc28j60/Kconfig index de5b667382..34147d9532 100644 --- a/drivers/enc28j60/Kconfig +++ b/drivers/enc28j60/Kconfig @@ -11,11 +11,12 @@ config MODULE_ENC28J60 depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_NETDEV_ETH + select MODULE_NETDEV_LEGACY_API + select MODULE_PERIPH_EUI_PROVIDER select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI - select MODULE_PERIPH_EUI_PROVIDER - select MODULE_NETDEV_ETH select MODULE_XTIMER config HAVE_ENC28J60 diff --git a/drivers/enc28j60/Makefile.dep b/drivers/enc28j60/Makefile.dep index 8f58cfca72..d5ac8cce0a 100644 --- a/drivers/enc28j60/Makefile.dep +++ b/drivers/enc28j60/Makefile.dep @@ -4,4 +4,5 @@ FEATURES_REQUIRED += periph_spi USEMODULE += eui_provider USEMODULE += netdev_eth +USEMODULE += netdev_legacy_api USEMODULE += xtimer diff --git a/drivers/encx24j600/Kconfig b/drivers/encx24j600/Kconfig index 5d85caf191..033aa9a594 100644 --- a/drivers/encx24j600/Kconfig +++ b/drivers/encx24j600/Kconfig @@ -11,10 +11,11 @@ config MODULE_ENCX24J600 depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_NETDEV_ETH + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI - select MODULE_NETDEV_ETH select MODULE_XTIMER config HAVE_ENCX24J600 diff --git a/drivers/encx24j600/Makefile.dep b/drivers/encx24j600/Makefile.dep index 3b58521764..64d7a5c90b 100644 --- a/drivers/encx24j600/Makefile.dep +++ b/drivers/encx24j600/Makefile.dep @@ -1,4 +1,5 @@ FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi USEMODULE += netdev_eth +USEMODULE += netdev_legacy_api USEMODULE += xtimer diff --git a/drivers/ethos/Kconfig b/drivers/ethos/Kconfig index 7290fce1d1..6ecd54307c 100644 --- a/drivers/ethos/Kconfig +++ b/drivers/ethos/Kconfig @@ -9,9 +9,10 @@ config MODULE_ETHOS bool "Ethernet-over-serial (ETHOS)" depends on TEST_KCONFIG depends on HAS_PERIPH_UART - select MODULE_PERIPH_UART select MODULE_IOLIST select MODULE_NETDEV_ETH + select MODULE_NETDEV_LEGACY_API + select MODULE_PERIPH_UART select MODULE_RANDOM select MODULE_TSRB diff --git a/drivers/ethos/Makefile.dep b/drivers/ethos/Makefile.dep index 4ed515dcdc..0a65c3629c 100644 --- a/drivers/ethos/Makefile.dep +++ b/drivers/ethos/Makefile.dep @@ -1,6 +1,7 @@ FEATURES_REQUIRED += periph_uart USEMODULE += iolist USEMODULE += netdev_eth +USEMODULE += netdev_legacy_api USEMODULE += random USEMODULE += tsrb diff --git a/drivers/kw2xrf/Kconfig b/drivers/kw2xrf/Kconfig index 2d4b2eafa7..ee59c6c17b 100644 --- a/drivers/kw2xrf/Kconfig +++ b/drivers/kw2xrf/Kconfig @@ -13,16 +13,15 @@ menuconfig MODULE_KW2XRF depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_CORE_THREAD_FLAGS + select MODULE_IEEE802154 + select MODULE_LUID + select MODULE_NETDEV + select MODULE_NETDEV_IEEE802154 + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI - select MODULE_LUID - select MODULE_IEEE802154 - select MODULE_NETDEV - select MODULE_NETDEV_IEEE802154 - select MODULE_CORE_THREAD_FLAGS - select MODULE_IOLIST - select HAVE_BHP_IRQ_HANDLER config MODULE_KW2XRF_TESTMODE bool "Test mode" diff --git a/drivers/mrf24j40/Kconfig b/drivers/mrf24j40/Kconfig index 18786e0091..d6da36cfa3 100644 --- a/drivers/mrf24j40/Kconfig +++ b/drivers/mrf24j40/Kconfig @@ -13,13 +13,14 @@ menuconfig MODULE_MRF24J40 depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_IEEE802154 + select MODULE_NETDEV + select MODULE_NETDEV_IEEE802154 + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI select MODULE_XTIMER - select MODULE_IEEE802154 - select MODULE_NETDEV - select MODULE_NETDEV_IEEE802154 if MODULE_MRF24J40 diff --git a/drivers/mrf24j40/Makefile.dep b/drivers/mrf24j40/Makefile.dep index 58f8cc263c..4035b1963c 100644 --- a/drivers/mrf24j40/Makefile.dep +++ b/drivers/mrf24j40/Makefile.dep @@ -1,6 +1,7 @@ -USEMODULE += xtimer USEMODULE += ieee802154 USEMODULE += netdev_ieee802154 +USEMODULE += netdev_legacy_api +USEMODULE += xtimer FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi diff --git a/drivers/netdev/Kconfig b/drivers/netdev/Kconfig index 344305b07b..4bd545f1a2 100644 --- a/drivers/netdev/Kconfig +++ b/drivers/netdev/Kconfig @@ -82,6 +82,23 @@ config MODULE_NETDEV_REGISTER endif # MODULE_NETDEV +# This does not depend on MODULE_NETDEV, as it is merely a flag to say if a +# given network driver is used via the netdev API, it provides the new netdev +# API. However, the driver may also provide a API other than netdev that might +# be used directly. +config MODULE_NETDEV_NEW_API + bool + help + Support for new API (non-blocking send). With this, netdev + drivers implementing `netdev_driver_t::confirm_send()` can be used. + +# Comment above MODULE_NETDEV_NEW_API also applies here. +config MODULE_NETDEV_LEGACY_API + bool + help + Support for legacy netdev API (blocking send). With this, netdev drivers + **NOT** implementing `netdev_driver_t::confirm_send()` can be used. + endif # TEST_KCONFIG config HAVE_NON_NETDEV_INTERFACE diff --git a/drivers/netdev_ieee802154_submac/Kconfig b/drivers/netdev_ieee802154_submac/Kconfig index 8f00238d6e..f435ac7529 100644 --- a/drivers/netdev_ieee802154_submac/Kconfig +++ b/drivers/netdev_ieee802154_submac/Kconfig @@ -10,9 +10,10 @@ config MODULE_NETDEV_IEEE802154_SUBMAC depends on TEST_KCONFIG depends on MODULE_NETDEV default y if HAVE_IEEE802154_RADIO_HAL_INTERFACE - select MODULE_NETDEV_IEEE802154 select MODULE_IEEE802154 select MODULE_IEEE802154_SUBMAC + select MODULE_NETDEV_IEEE802154 + select MODULE_NETDEV_LEGACY_API help This module implements the netdev API on top of the IEEE 802.15.4 radio HAL. diff --git a/drivers/nrf24l01p_ng/Makefile.dep b/drivers/nrf24l01p_ng/Makefile.dep index 8c7dc0b1ed..2df81ba28d 100644 --- a/drivers/nrf24l01p_ng/Makefile.dep +++ b/drivers/nrf24l01p_ng/Makefile.dep @@ -1,4 +1,5 @@ USEMODULE += luid +USEMODULE += netdev_legacy_api USEMODULE += netif USEMODULE += xtimer ifneq (,$(filter gnrc_ipv6,$(USEMODULE))) diff --git a/drivers/rn2xx3/Kconfig b/drivers/rn2xx3/Kconfig index b001faca58..5d8b2390bd 100644 --- a/drivers/rn2xx3/Kconfig +++ b/drivers/rn2xx3/Kconfig @@ -27,9 +27,10 @@ config MODULE_RN2XX3 bool depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_UART + select MODULE_FMT + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_UART - select MODULE_FMT select MODULE_ZTIMER select MODULE_ZTIMER_MSEC diff --git a/drivers/rn2xx3/Makefile.dep b/drivers/rn2xx3/Makefile.dep index a3f5cf86e0..9ff785b446 100644 --- a/drivers/rn2xx3/Makefile.dep +++ b/drivers/rn2xx3/Makefile.dep @@ -1,5 +1,6 @@ FEATURES_REQUIRED += periph_gpio FEATURES_REQUIRED += periph_uart +USEMODULE += fmt +USEMODULE += netdev_legacy_api USEMODULE += ztimer USEMODULE += ztimer_msec -USEMODULE += fmt diff --git a/drivers/slipdev/Kconfig b/drivers/slipdev/Kconfig index b5769f7453..e1a9045e56 100644 --- a/drivers/slipdev/Kconfig +++ b/drivers/slipdev/Kconfig @@ -10,8 +10,9 @@ menuconfig MODULE_SLIPDEV bool "SLIP over UART network device" depends on HAS_PERIPH_UART depends on TEST_KCONFIG - select MODULE_TSRB + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_UART + select MODULE_TSRB menuconfig KCONFIG_USEMODULE_SLIPDEV bool "Configure SLIPDEV driver" diff --git a/drivers/slipdev/Makefile.dep b/drivers/slipdev/Makefile.dep index 0ec3dd39cf..53faff5069 100644 --- a/drivers/slipdev/Makefile.dep +++ b/drivers/slipdev/Makefile.dep @@ -1,6 +1,7 @@ -USEMODULE += tsrb USEMODULE += eui_provider +USEMODULE += netdev_legacy_api USEMODULE += netdev_register +USEMODULE += tsrb FEATURES_REQUIRED += periph_uart ifneq (,$(filter slipdev_stdio,$(USEMODULE))) diff --git a/drivers/sx126x/Kconfig b/drivers/sx126x/Kconfig index 0b46259518..1b10769836 100644 --- a/drivers/sx126x/Kconfig +++ b/drivers/sx126x/Kconfig @@ -13,10 +13,11 @@ menuconfig MODULE_SX126X depends on HAS_PERIPH_SPI depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ + select MODULE_IOLIST + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_SPI select PACKAGE_DRIVER_SX126X - select MODULE_IOLIST choice bool "Radio variant" diff --git a/drivers/sx126x/Makefile.dep b/drivers/sx126x/Makefile.dep index c3de4b4ce3..2862d6ff22 100644 --- a/drivers/sx126x/Makefile.dep +++ b/drivers/sx126x/Makefile.dep @@ -1,3 +1,4 @@ USEMODULE += iolist +USEMODULE += netdev_legacy_api USEPKG += driver_sx126x FEATURES_REQUIRED += periph_gpio_irq diff --git a/drivers/sx127x/Kconfig b/drivers/sx127x/Kconfig index 689798942c..d17f567ac9 100644 --- a/drivers/sx127x/Kconfig +++ b/drivers/sx127x/Kconfig @@ -14,14 +14,15 @@ menuconfig MODULE_SX127X depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI depends on HAS_PERIPH_TIMER - select MODULE_PERIPH_GPIO - select MODULE_PERIPH_GPIO_IRQ - select MODULE_PERIPH_SPI_GPIO_MODE if HAS_PERIPH_SPI_GPIO_MODE - select MODULE_PERIPH_SPI - select MODULE_ZTIMER - select MODULE_ZTIMER_MSEC select MODULE_IOLIST select MODULE_LORA + select MODULE_NETDEV_LEGACY_API + select MODULE_PERIPH_GPIO + select MODULE_PERIPH_GPIO_IRQ + select MODULE_PERIPH_SPI + select MODULE_PERIPH_SPI_GPIO_MODE if HAS_PERIPH_SPI_GPIO_MODE + select MODULE_ZTIMER + select MODULE_ZTIMER_MSEC help Only LoRa long range modem is supported at the moment. diff --git a/drivers/sx127x/Makefile.dep b/drivers/sx127x/Makefile.dep index 0dbc8ab7a5..42eed37846 100644 --- a/drivers/sx127x/Makefile.dep +++ b/drivers/sx127x/Makefile.dep @@ -3,6 +3,7 @@ FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi FEATURES_OPTIONAL += periph_spi_gpio_mode USEMODULE += iolist +USEMODULE += netdev_legacy_api USEMODULE += ztimer_msec USEMODULE += lora diff --git a/drivers/sx1280/Makefile.dep b/drivers/sx1280/Makefile.dep index f402c8e2da..c970b0ea28 100644 --- a/drivers/sx1280/Makefile.dep +++ b/drivers/sx1280/Makefile.dep @@ -1,2 +1,3 @@ USEPKG += lorabasics USEMODULE += lorabasics_sx1280_driver +USEMODULE += netdev_legacy_api diff --git a/drivers/w5100/Kconfig b/drivers/w5100/Kconfig index 5162fe5500..7c363f8c70 100644 --- a/drivers/w5100/Kconfig +++ b/drivers/w5100/Kconfig @@ -11,11 +11,12 @@ config MODULE_W5100 depends on HAS_PERIPH_GPIO depends on HAS_PERIPH_GPIO_IRQ depends on HAS_PERIPH_SPI + select MODULE_LUID + select MODULE_NETDEV_ETH + select MODULE_NETDEV_LEGACY_API select MODULE_PERIPH_GPIO select MODULE_PERIPH_GPIO_IRQ select MODULE_PERIPH_SPI - select MODULE_NETDEV_ETH - select MODULE_LUID config HAVE_W5100 bool diff --git a/drivers/w5100/Makefile.dep b/drivers/w5100/Makefile.dep index 682df427e8..49da3e4cf6 100644 --- a/drivers/w5100/Makefile.dep +++ b/drivers/w5100/Makefile.dep @@ -1,4 +1,5 @@ FEATURES_REQUIRED += periph_gpio_irq FEATURES_REQUIRED += periph_spi -USEMODULE += netdev_eth USEMODULE += luid +USEMODULE += netdev_eth +USEMODULE += netdev_legacy_api diff --git a/drivers/xbee/Makefile.dep b/drivers/xbee/Makefile.dep index 3a41c95328..49b4faab42 100644 --- a/drivers/xbee/Makefile.dep +++ b/drivers/xbee/Makefile.dep @@ -1,5 +1,6 @@ FEATURES_REQUIRED += periph_uart FEATURES_REQUIRED += periph_gpio USEMODULE += ieee802154 +USEMODULE += netdev_legacy_api USEMODULE += ztimer USEMODULE += ztimer_msec diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 8b05650bca..71dce205b0 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -156,6 +156,8 @@ PSEUDOMODULES += netdev_ieee802154_rx_timestamp PSEUDOMODULES += netdev_ieee802154 PSEUDOMODULES += netdev_eth PSEUDOMODULES += netdev_layer +PSEUDOMODULES += netdev_legacy_api +PSEUDOMODULES += netdev_new_api PSEUDOMODULES += netdev_register PSEUDOMODULES += netstats PSEUDOMODULES += netstats_l2 diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 4ca4fc7315..4314ba8fd9 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -173,6 +173,7 @@ endif ifneq (,$(filter netdev_ieee802154_submac,$(USEMODULE))) USEMODULE += netdev_ieee802154 + USEMODULE += netdev_legacy_api USEMODULE += ieee802154 USEMODULE += ieee802154_submac endif diff --git a/sys/include/net/gnrc/netif.h b/sys/include/net/gnrc/netif.h index 01b5b26170..9247e00f45 100644 --- a/sys/include/net/gnrc/netif.h +++ b/sys/include/net/gnrc/netif.h @@ -187,6 +187,55 @@ typedef struct { kernel_pid_t pid; /**< PID of the network interface's thread */ } gnrc_netif_t; +/** + * @brief Check if the device belonging to the given netif uses the legacy + * netdev API + * + * Check @ref netdev_driver_t::confirm_send for info about the old and new + * netdev API. + * + * netdevs using the legacy API have to depend on the (pseudo-)module + * netdev_legaqcy_api, netdevs using the new API have to depend on the + * (pseudo-)module netdev_new_api. If only one of the pseudo modules is used, + * this function can be constant folded. For boards mixing legacy and new API + * netdevs, this will check the flavor at runtime. + * + * @see netdev_driver_t::confirm_send + */ +static inline bool gnrc_netif_netdev_legacy_api(gnrc_netif_t *netif) +{ + if (!IS_USED(MODULE_NETDEV_NEW_API) && !IS_USED(MODULE_NETDEV_LEGACY_API)) { + /* this should only happen for external netdevs or when no netdev is + * used (e.g. examples/gcoap can be used without any netdev, as still + * CoAP requests to ::1 can be send */ + return true; + } + + if (!IS_USED(MODULE_NETDEV_NEW_API)) { + return true; + } + + if (!IS_USED(MODULE_NETDEV_LEGACY_API)) { + return false; + } + + /* both legacy and new API netdevs in use, fall back to runtime test: */ + return (netif->dev->driver->confirm_send == NULL); +} + +/** + * @brief Check if the device belonging to the given netif uses the new + * netdev API + * + * @see gnrc_netif_netdev_legacy_api + * + * @see netdev_driver_t::confirm_send + */ +static inline bool gnrc_netif_netdev_new_api(gnrc_netif_t *netif) +{ + return !gnrc_netif_netdev_legacy_api(netif); +} + /** * @see gnrc_netif_ops_t */