From: Jeremy Kerr <jk@codeconstruct.com.au>
To: Matt Johnston <matt@codeconstruct.com.au>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: netdev@vger.kernel.org, linux-usb@vger.kernel.org
Subject: [PATCH net-next v4 04/12] net: mctp: usb: Improve IN endpoint status handling
Date: Mon, 13 Jul 2026 22:32:57 +0800 [thread overview]
Message-ID: <20260713-dev-mctp-usb-1-1-v4-4-4ae8de764a01@codeconstruct.com.au> (raw)
In-Reply-To: <20260713-dev-mctp-usb-1-1-v4-0-4ae8de764a01@codeconstruct.com.au>
Currently, we give-up on all non-zero status values on our IN/rx urb,
and do not re-queue the urb. This will stall the driver, and prevent
any further receive.
Instead, attempt a re-queue on transient errors, with a max of ten
successive failures. Handle EPIPE specially, by scheduling a
usb_clear_halt() in non-atomic context.
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
---
v4:
- move urb error common code to mctp_usb_in_urb_err, fixing a missing
rx_cancel
- allow retries of usb_clear_halt
v3:
- improved IN urb status handling was introduced in v2, but now split
to a separate change, via sashiko feedback
- now with usb_clear_halt on EPIPE.
---
drivers/net/mctp/mctp-usb.c | 91 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 84 insertions(+), 7 deletions(-)
diff --git a/drivers/net/mctp/mctp-usb.c b/drivers/net/mctp/mctp-usb.c
index 9e5c64e76e4a..d556dd2d91de 100644
--- a/drivers/net/mctp/mctp-usb.c
+++ b/drivers/net/mctp/mctp-usb.c
@@ -32,6 +32,9 @@ struct mctp_usb {
struct urb *tx_urb;
struct urb *rx_urb;
+ int in_err_count;
+ int in_err_orig;
+ bool clear_halt;
/* enforces atomic access to rx_stopped and requeuing the retry work */
spinlock_t rx_lock;
@@ -158,27 +161,75 @@ static int mctp_usb_rx_queue(struct mctp_usb *mctp_usb, gfp_t gfp)
return 0;
}
+static const unsigned int rx_err_max = 10;
+
+/* Returns -1 if we have hit excessive errors, zero otherwise. */
+static int mctp_usb_in_urb_err(struct mctp_usb *mctp_usb, int status,
+ bool stalled)
+{
+ mctp_usblib_rx_cancel(&mctp_usb->rx);
+
+ if (!mctp_usb->in_err_count++)
+ mctp_usb->in_err_orig = status;
+
+ if (mctp_usb->in_err_count >= rx_err_max) {
+ netdev_err(mctp_usb->netdev,
+ "excessive errors from%s IN EP, first: %d\n",
+ stalled ? " (stalled)" : "",
+ mctp_usb->in_err_orig);
+ return -1;
+ }
+
+ return 0;
+}
+
static void mctp_usb_in_complete(struct urb *urb)
{
struct mctp_usb *mctp_usb = urb->context;
struct net_device *netdev = mctp_usb->netdev;
- int status;
+ unsigned long flags;
+ int rc, status;
status = urb->status;
switch (status) {
- default:
- netdev_dbg(netdev, "unexpected rx urb status: %d\n", status);
- fallthrough;
case -ENOENT:
case -ECONNRESET:
case -ESHUTDOWN:
- case -EPROTO:
+ /* device shutdown, don't resubmit */
mctp_usblib_rx_cancel(&mctp_usb->rx);
return;
+
+ case -EPIPE:
+ /* endpoint stall: clear halt, which will cause a resubmit */
+ rc = mctp_usb_in_urb_err(mctp_usb, status, true);
+ if (rc)
+ return;
+
+ mctp_usb->clear_halt = true;
+ spin_lock_irqsave(&mctp_usb->rx_lock, flags);
+ if (!mctp_usb->rx_stopped)
+ schedule_delayed_work(&mctp_usb->rx_retry_work,
+ RX_RETRY_DELAY);
+ spin_unlock_irqrestore(&mctp_usb->rx_lock, flags);
+ return;
+
+ default:
+ netdev_dbg(netdev, "unexpected rx urb status: %d\n", status);
+ fallthrough;
+ case -ETIME:
+ case -EPROTO:
+ case -EILSEQ:
+ case -EOVERFLOW:
+ /* possibly transient; record first failure, resubmit */
+ rc = mctp_usb_in_urb_err(mctp_usb, status, false);
+ if (rc)
+ return;
+ break;
+
case 0:
- mctp_usblib_rx_complete(netdev, &mctp_usb->rx,
- urb->actual_length);
+ mctp_usblib_rx_complete(netdev, &mctp_usb->rx, urb->actual_length);
+ mctp_usb->in_err_count = 0;
break;
}
@@ -189,6 +240,30 @@ static void mctp_usb_rx_retry_work(struct work_struct *work)
{
struct mctp_usb *mctp_usb = container_of(work, struct mctp_usb,
rx_retry_work.work);
+ unsigned long flags;
+ int rc;
+
+ /* We are only called when rx completions are suspended */
+ if (mctp_usb->clear_halt) {
+ int pipe = usb_rcvbulkpipe(mctp_usb->usbdev, mctp_usb->ep_in);
+
+ rc = usb_clear_halt(mctp_usb->usbdev, pipe);
+ if (rc) {
+ netdev_err(mctp_usb->netdev,
+ "can't clear IN EP halt: %d\n", rc);
+
+ if (++mctp_usb->in_err_count >= rx_err_max)
+ return;
+
+ spin_lock_irqsave(&mctp_usb->rx_lock, flags);
+ if (!mctp_usb->rx_stopped)
+ schedule_delayed_work(&mctp_usb->rx_retry_work,
+ RX_RETRY_DELAY);
+ spin_unlock_irqrestore(&mctp_usb->rx_lock, flags);
+ return;
+ }
+ mctp_usb->clear_halt = false;
+ }
mctp_usb_rx_queue(mctp_usb, GFP_KERNEL);
}
@@ -198,6 +273,8 @@ static int mctp_usb_open(struct net_device *dev)
struct mctp_usb *mctp_usb = netdev_priv(dev);
WRITE_ONCE(mctp_usb->rx_stopped, false);
+ mctp_usb->clear_halt = false;
+ mctp_usb->in_err_count = 0;
netif_start_queue(dev);
--
2.47.3
next prev parent reply other threads:[~2026-07-13 14:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 14:32 [PATCH net-next v4 00/12] net: mctp: usb: Add support for MCTP-over-USB v1.1 Jeremy Kerr
2026-07-13 14:32 ` [PATCH net-next v4 01/12] net: mctp: usb: Include version indicator in max packet size defines Jeremy Kerr
2026-07-13 14:32 ` [PATCH net-next v4 02/12] net: mctp: usb: Use packet-length max for maximum packet-size check Jeremy Kerr
2026-07-13 14:32 ` [PATCH net-next v4 03/12] net: mctp: usblib: Move RX transfer processing to a new mctp-usblib Jeremy Kerr
2026-07-13 14:32 ` Jeremy Kerr [this message]
2026-07-13 14:32 ` [PATCH net-next v4 05/12] net: mctp: usblib: Move TX transfer processing to mctp-usblib Jeremy Kerr
2026-07-13 14:32 ` [PATCH net-next v4 06/12] net: mctp: usblib: Add support for multi-packet transmit Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 07/12] net: mctp: usb: Accommodate DSP0283 v1.1 header format Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 08/12] net: mctp: usblib: Implement receive-side packet spanning Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 09/12] net: mctp: usblib: Implement transmit-side " Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 10/12] net: mctp: usblib: Add initial kunit tests Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 11/12] net: mctp: usb: enable v1.1 packet spanning Jeremy Kerr
2026-07-13 14:33 ` [PATCH net-next v4 12/12] net: mctp: usb: Allow multiple urbs in flight Jeremy Kerr
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260713-dev-mctp-usb-1-1-v4-4-4ae8de764a01@codeconstruct.com.au \
--to=jk@codeconstruct.com.au \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=matt@codeconstruct.com.au \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox