drivers: ethernet: nxp: use net_if_carrier correct#100809
Conversation
bcd5442 to
80e8362
Compare
| 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); |
There was a problem hiding this comment.
This way it is no longer wrong. To really make use of it, net_if_carrier should be changed at the points where a connection is established or disconnected. But that is for later.
Aren't these points simply usbd_cdc_ncm_enable() and usbd_cdc_ncm_disable()? If yes, why not just put the calls there instead of commenting "that is for later".
There was a problem hiding this comment.
Or is it more like usbd_cdc_ncm_shutdown and .update callback in struct usbd_class_api which are bound to functional state (device configured)?
There was a problem hiding this comment.
I now changed it, so that it works with plugging the usb cable out and in. (tested on a renesas ek_ra8d1 with the zperf sample and the provided confs and overlays)
80e8362 to
6bc7751
Compare
|
|
||
| atomic_set_bit(&data->state, CDC_NCM_CLASS_SUSPENDED); | ||
|
|
||
| net_if_carrier_off(data->iface); |
There was a problem hiding this comment.
I would argue that suspend is not removing carrier. When suspended the device is still connected to host. It may even be possible for the device to issue Remote Wakeup if device reported that it supports Remote Wakeup and host did allow it (enabled the feature before suspending device).
There was a problem hiding this comment.
But where are we getting the info, that for example the cable is no longer connected?
There was a problem hiding this comment.
What cable do you mean? If "USB cable" then suspend is low power state when the cable is physically connected.
When USB cable is disconnected, all USB classes disable callbacks are called - here it is usbd_cdc_ncm_disable(). When the cable is connected, and device gets configured (so USB functions can operate) then all USB classes enable callbacks are called - here it is usbd_cdc_ncm_enable().
There was a problem hiding this comment.
When USB cable is disconnected, all USB classes disable callbacks are called - here it is
usbd_cdc_ncm_disable(). When the cable is connected, and device gets configured (so USB functions can operate) then all USB classes enable callbacks are called - here it isusbd_cdc_ncm_enable().
No it isn't, at least for the device_next subsys. The disable callbacks (usbd_class_disable) are only called on UDC_EVT_RESET by event_handler_bus_reset.
UDC_EVT_VBUS_REMOVED is not used for that.
There was a problem hiding this comment.
I removed the the net_if_carrier_off() in the suspend therefore.
|
ping @sumitbatra-nxp for the GMAC changes for S32 |
6bc7751 to
f2aac10
Compare
|
@maass-hamburg the changes for the NXP S32 GMAC drivers look reasonable to me, but I currently don’t have hardware to test them. Tagging @bperseghetti @PetervdPerk-NXP @sumitbatra-nxp in case you can help with a quick smoke test. Thanks! |
|
@maass-hamburg thanks for the fix aligning carrier with link state. Could you confirm you tested (or can reason about) these scenarios for eth_nxp_s32_gmac: TX while link is down: if an application calls .send() while carrier/link is down, do we recover cleanly once link comes back? Initial carrier state with PHY: the PR sets net_eth_carrier_off(iface) in eth_nxp_s32_iface_init() for PHY-present cases, which makes sense so iface doesn’t look “link up” until PHY reports it. Please double-check the no-PHY / fixed-link case still sets carrier ON (e.g. if (cfg->phy_dev == NULL) net_if_carrier_on(iface);). Also, does phy_link_callback_set() guarantee an immediate callback for the PHYs used on S32? If not, carrier could remain OFF until the first link transition/poll. If that’s a concern, we might need a one-time phy_get_link_state() after registering the callback to seed initial carrier state. |
|
Optional validation matrix (what I had in mind while reviewing): For PHY-based Ethernet (S32 GMAC): Boot with cable unplugged → carrier stays OFF Plug cable → carrier ON, traffic works Unplug cable → carrier OFF, traffic stops cleanly Admin down/up with cable plugged → traffic stops/resumes without needing cable replug TX attempted while link down → no TX deadlock or permanent ENOBUFS after link comes back Rapid link flap → no stuck semaphores / TX mutex / IRQ storm For USB CDC-NCM: USB plug/unplug while running iperf → carrier tracks connection, no stale carrier ON after unplug |
|
@manuargue , assigned this PR to you as you added this driver and are more familiar. |
| 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); |
There was a problem hiding this comment.
Handling notifications (interrupt endpoint transfer is completed) is the consequence of cdc_ncm_iface_start() scheduling notification work. Removing it from cdc_ncm_iface_start() and calling it here does not really change what happened from network interfaces view. What is the point of this commit?
There was a problem hiding this comment.
cdc_ncm_iface_start() will be called by the networking subsystem only once. Meaning, if i disconnect the cable between the board and the host and connect it again, the networking subsystem won't be informed about the disconnection in between and won't f.e. restart the dhcp client. Doing it this way it will be notified. Also this will only be called when there is a connection, if the board is started without the usb cable plugged in, the iface will only go up when it is plugged in.
There was a problem hiding this comment.
iface_start and iface_stop should never directly contain net_if_carrier_on and net_if_carrier_off. The carrier is independent of it.
|
|
||
| if (data_iface == iface && alternate == 0) { | ||
| atomic_clear_bit(&data->state, CDC_NCM_DATA_IFACE_ENABLED); | ||
| net_if_carrier_off(data->iface); |
There was a problem hiding this comment.
In the current implementation, the network interface on the Zephyr side determines whether the carrier is switched on or off for both sides. Mixing it like that is not correct.
net_if_carrier is to be used independently of the
administrative state (start and stop of the ethernet_api).
This seem to work.
Also it does belong in this commit and looks like a stray change.
Please work on your commit messages.
| 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); |
There was a problem hiding this comment.
Same as for changes in usbd_cdc_ncm_update().
There was a problem hiding this comment.
Thanks @sumitbatra-nxp for your feedback on the NXP GMAC driver. Judging by the discussion, the changes LGTM for NXP GMAC driver.
651e07d to
e29d230
Compare
Objected part no longer part of this PR, now in #104379
Only the nxp driver part remains
|
To continue I removed the usb part of this PR and split it into #104379 |
|
ping @manuargue |
manuargue
left a comment
There was a problem hiding this comment.
approved based on the comments above, I don't have hw to test this.
net_if_carrier is to be used independently of the administrative state (start and stop of the ethernet_api). Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
e29d230 to
ad0bd97
Compare
|
replaced the |
|
|
please take a look @zejiang0jason @mmahadevan108 |
|
please take a look @yangbolu1991 |
yangbolu1991
left a comment
There was a problem hiding this comment.
I don't work on s32 platform.
But reviewed the changes, It looks good to me.
Thanks.



net_if_carrier is to be used independently of the
administrative state (start and stop of the ethernet_api).