Skip to contentSkip to conversation

usb: gadget: f_ncm: Restart timer when eth_start_xmit() fails

PATCH In review Francesco Lavra 3 participants 5 messages Jul 27 – Oct 29 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: f_ncm: Restart timer when eth_start_xmit() fails

The ncm_tx_timeout() function is run by a timer when unsent data has been sitting for some time in the NCM driver waiting for more data to be pushed by the ethernet gadget driver, and calls eth_start_xmit() to trigger a flush of the unsent data. If there is no available struct usb_request (which can happen when there is sustained network traffic from the gadget device to the USB host), the unsent data is not flushed, and remains there until enough new data has been pushed by the ethernet gadget driver to fill a USB packet. This can cause outgoing network traffic to stall for several seconds, during which the gadget device appears unresponsive to the host.

Fix this issue by restarting the ncm_tx_timeout() timer if there is no available struct usb_request.

---
 drivers/usb/gadget/function/f_ncm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_ncm.c +2 -1
index 64eabda2f546..fd84086473d7 100644
@@ -1158,7 +1158,8 @@ static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data)
 		 *
 		 * This will call directly into u_ether's eth_start_xmit()
 		 */
-		netdev->netdev_ops->ndo_start_xmit(NULL, netdev);
+		if (netdev->netdev_ops->ndo_start_xmit(NULL, netdev) == NETDEV_TX_BUSY)
+			return HRTIMER_RESTART;
 	}
 	return HRTIMER_NORESTART;
 }
Signature · 1 line
2.39.5
Tested-by on v1 1/1
#1 lore raw

Hi Francesco,

I tested this patch on a Raspberry Pi 4B running Linux 6.12.105 built with Yocto, using the f_ncm USB gadget.

Without the patch, I can reproducibly observe multi-second TX stalls under sustained network traffic.
With the patch applied, I can no longer reproduce the issue.

Thanks,
Felix

#2 lore raw
In reply to Francesco Lavra

Friendly ping

Quoted 40 lines · Francesco Lavra

The ncm_tx_timeout() function is run by a timer when unsent data has been sitting for some time in the NCM driver waiting for more data to be pushed
by the ethernet gadget driver, and calls eth_start_xmit() to trigger a flush of the unsent data. If there is no available struct usb_request (which can happen when there is sustained network traffic from the gadget device to the USB host), the unsent data is not flushed, and remains there
until enough new data has been pushed by the ethernet gadget driver to fill
a USB packet. This can cause outgoing network traffic to stall for several
seconds, during which the gadget device appears unresponsive to the host.

Fix this issue by restarting the ncm_tx_timeout() timer if there is no available struct usb_request.

---
 drivers/usb/gadget/function/f_ncm.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_ncm.c +2 -1
index 64eabda2f546..fd84086473d7 100644
@@ -1158,7 +1158,8 @@ static enum hrtimer_restart ncm_tx_timeout(struct
 hrtimer *data)
                  *
                  * This will call directly into u_ether's
 eth_start_xmit()
                  */
-               netdev->netdev_ops->ndo_start_xmit(NULL, netdev);
+               if (netdev->netdev_ops->ndo_start_xmit(NULL, netdev) ==
 NETDEV_TX_BUSY)
+                       return HRTIMER_RESTART;

        }
        return HRTIMER_NORESTART;
 }

#3 lore raw
Quoted 1 line · Francesco Lavra

Friendly ping

It is the middle of the merge window, sorry, will try to catch up after -rc1 is out...