From 7fb1fa26cc0c7bf5d14842f1629ea69b2fb889aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Wed, 10 Dec 2025 13:42:09 +0100 Subject: [PATCH 1/2] drivers: ethernet: nxp: correct net_if_carrier use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit net_if_carrier is to be used independently of the administrative state (start and stop of the ethernet_api). Signed-off-by: Fin Maaß --- drivers/ethernet/eth_nxp_s32_gmac.c | 44 ++--------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/drivers/ethernet/eth_nxp_s32_gmac.c b/drivers/ethernet/eth_nxp_s32_gmac.c index e3b43b2a869fd..e521e0db91ccb 100644 --- a/drivers/ethernet/eth_nxp_s32_gmac.c +++ b/drivers/ethernet/eth_nxp_s32_gmac.c @@ -52,7 +52,6 @@ struct eth_nxp_s32_config { struct eth_nxp_s32_data { struct net_if *iface; uint8_t mac_addr[ETH_NXP_S32_MAC_ADDR_LEN]; - uint8_t if_suspended; struct k_mutex tx_mutex; struct k_sem rx_sem; struct k_sem tx_sem; @@ -119,13 +118,6 @@ static void phy_link_state_changed(const struct device *pdev, cfg->base->MAC_CONFIGURATION |= GMAC_MAC_CONFIGURATION_DM(gmac_cfg.Duplex); - /* net iface should be down even if PHY link state is up - * till the upper network layers have suspended the iface. - */ - if (ctx->if_suspended) { - return; - } - LOG_DBG("Link up"); net_eth_carrier_on(ctx->iface); } else { @@ -230,33 +222,12 @@ static int eth_nxp_s32_init(const struct device *dev) static int eth_nxp_s32_start(const struct device *dev) { const struct eth_nxp_s32_config *cfg = dev->config; - struct eth_nxp_s32_data *ctx = dev->data; - struct phy_link_state state; Gmac_Ip_EnableController(cfg->instance); irq_enable(cfg->rx_irq); irq_enable(cfg->tx_irq); - /* If upper layers enable the net iface then mark it as - * not suspended so that PHY Link changes can have the impact - */ - ctx->if_suspended = false; - - if (cfg->phy_dev) { - phy_get_link_state(cfg->phy_dev, &state); - - /* Enable net_iface only when Ethernet PHY link is up or else - * if net_iface is enabled when link is down and tx happens - * in this state then the used tx buffers will never be recovered back. - */ - if (state.is_up == true) { - net_eth_carrier_on(ctx->iface); - } - } else { - net_eth_carrier_on(ctx->iface); - } - LOG_DBG("GMAC%d started", cfg->instance); return 0; @@ -265,20 +236,12 @@ static int eth_nxp_s32_start(const struct device *dev) static int eth_nxp_s32_stop(const struct device *dev) { const struct eth_nxp_s32_config *cfg = dev->config; - struct eth_nxp_s32_data *ctx = dev->data; Gmac_Ip_StatusType status; int err = 0; irq_disable(cfg->rx_irq); irq_disable(cfg->tx_irq); - /* If upper layers disable the net iface then mark it as suspended - * in order to save it from the PHY link state changes - */ - ctx->if_suspended = true; - - net_eth_carrier_off(ctx->iface); - status = Gmac_Ip_DisableController(cfg->instance); if (status != GMAC_STATUS_SUCCESS) { LOG_ERR("Failed to disable controller GMAC%d (%d)", cfg->instance, status); @@ -308,17 +271,14 @@ static void eth_nxp_s32_iface_init(struct net_if *iface) ctx->mac_addr[0], ctx->mac_addr[1], ctx->mac_addr[2], ctx->mac_addr[3], ctx->mac_addr[4], ctx->mac_addr[5]); - /* Make sure that the net iface state is not suspended unless - * upper layers explicitly stop the iface - */ - ctx->if_suspended = false; - /* No PHY available, link is always up and MAC speed/duplex settings are fixed */ if (cfg->phy_dev == NULL) { net_if_carrier_on(iface); return; } + net_eth_carrier_off(iface); + /* * GMAC controls the PHY. If PHY is configured either as fixed * link or autoneg, the callback is executed at least once From f2aac1084fbdd8e5850818b874d8922361bd363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fin=20Maa=C3=9F?= Date: Wed, 10 Dec 2025 13:55:29 +0100 Subject: [PATCH 2/2] usb: device_next: usbd_cdc_ncm: correct net_if_carrier use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit net_if_carrier is to be used independently of the administrative state (start and stop of the ethernet_api). This seem to work. Signed-off-by: Fin Maaß --- subsys/usb/device_next/class/usbd_cdc_ncm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subsys/usb/device_next/class/usbd_cdc_ncm.c b/subsys/usb/device_next/class/usbd_cdc_ncm.c index 57a98a38dc5ee..5e26d29dfecaf 100644 --- a/subsys/usb/device_next/class/usbd_cdc_ncm.c +++ b/subsys/usb/device_next/class/usbd_cdc_ncm.c @@ -635,6 +635,7 @@ static void ncm_handle_notifications(const struct device *dev, const int err) if (data->if_state == IF_STATE_CONNECTION_STATUS_SUBMITTED) { data->if_state = IF_STATE_CONNECTION_STATUS_SENT; LOG_INF("Connection status sent"); + net_if_carrier_on(data->iface); } } @@ -840,6 +841,7 @@ static void usbd_cdc_ncm_update(struct usbd_class_data *const c_data, if (data_iface == iface && alternate == 0) { atomic_clear_bit(&data->state, CDC_NCM_DATA_IFACE_ENABLED); + net_if_carrier_off(data->iface); data->tx_seq = 0; data->rx_seq = 0; } @@ -868,6 +870,8 @@ static void usbd_cdc_ncm_disable(struct usbd_class_data *const c_data) atomic_clear_bit(&data->state, CDC_NCM_DATA_IFACE_ENABLED); atomic_clear_bit(&data->state, CDC_NCM_CLASS_SUSPENDED); + net_if_carrier_off(data->iface); + LOG_INF("Disabled %s", c_data->name); } @@ -1123,7 +1127,6 @@ static int cdc_ncm_iface_start(const struct device *dev) LOG_DBG("Start interface %d", net_if_get_by_iface(data->iface)); atomic_set_bit(&data->state, CDC_NCM_IFACE_UP); - net_if_carrier_on(data->iface); if (atomic_test_bit(&data->state, CDC_NCM_DATA_IFACE_ENABLED)) { (void)k_work_reschedule(&data->notif_work, K_MSEC(1));