Skip to content

Commit c70470d

Browse files
committed
Recover from potential USB stuck
This commit has changes to recover from potential USB stuck after USB retransmission timeout. RM #4604090
1 parent 268fcc8 commit c70470d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/rshim_usb.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define USB_BLUEFIELD_2_PRODUCT_ID 0x0214 /* Mellanox Bluefield-2 */
1919
#define USB_BLUEFIELD_3_PRODUCT_ID 0x021c /* Mellanox Bluefield-3 */
2020

21-
#define READ_RETRIES 5
21+
#define READ_RETRIES 2
2222
#define WRITE_RETRIES 5
2323

2424
#define BF_MMIO_BASE 0x1000
@@ -341,6 +341,7 @@ static void rshim_usb_fifo_read_callback(struct libusb_transfer *urb)
341341
rshim_usb_t *dev = urb->user_data;
342342
rshim_backend_t *bd = &dev->bd;
343343
bool lock;
344+
int rc;
344345

345346
RSHIM_DBG("rshim%d(fifo_read_callback) %s urb completed, status %d, "
346347
"actual length %d, intr buf 0x%x\n",
@@ -389,8 +390,6 @@ static void rshim_usb_fifo_read_callback(struct libusb_transfer *urb)
389390
* handle partial reads; it's hard, and we haven't really
390391
* seen them.
391392
*/
392-
int rc;
393-
394393
dev->read_or_intr_retries++;
395394
rc = libusb_submit_transfer(urb);
396395
if (rc) {
@@ -405,6 +404,14 @@ static void rshim_usb_fifo_read_callback(struct libusb_transfer *urb)
405404
bd->spin_flags |= RSH_SFLG_READING;
406405
}
407406
break;
407+
} else {
408+
RSHIM_ERR("rshim%d(fifo_read_callback) retry timeout\n", bd->index);
409+
libusb_free_transfer(urb);
410+
rc = libusb_clear_halt(dev->handle, urb->endpoint);
411+
if (rc) {
412+
RSHIM_ERR("rshim%d clear_halt failed: %s\n",
413+
bd->index, libusb_error_name(rc));
414+
}
408415
}
409416

410417
case LIBUSB_TRANSFER_CANCELLED:
@@ -1017,6 +1024,10 @@ static void rshim_usb_disconnect(struct libusb_device *usb_dev)
10171024
libusb_cancel_transfer(dev->write_urb);
10181025
dev->write_urb = NULL;
10191026

1027+
pthread_mutex_lock(&bd->ringlock);
1028+
bd->spin_flags &= ~RSH_SFLG_READING;
1029+
pthread_mutex_unlock(&bd->ringlock);
1030+
10201031
free(dev->intr_buf);
10211032
dev->intr_buf = NULL;
10221033

0 commit comments

Comments
 (0)