Retry on usb IO errors instead of faking success.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/usbutils.c b/usbutils.c
index 1b64184..0147c39 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -562,15 +562,6 @@ static const char *BLANK = "";
static const char *space = " ";
static const char *nodatareturned = "no data returned ";
-/* Fake success on IO errors allowing code to retry up to USB_RETRY_MAX */
-#define IOERR_CHECK(cgpu, err) \
- if (err == LIBUSB_ERROR_IO) { \
- cgpu->usbinfo.ioerr_count++; \
- if (++cgpu->usbinfo.continuous_ioerr_count < USB_RETRY_MAX) \
- err = LIBUSB_SUCCESS; \
- } else \
- cgpu->usbinfo.continuous_ioerr_count = 0;
-
#if 0 // enable USBDEBUG - only during development testing
static const char *debug_true_str = "true";
static const char *debug_false_str = "false";
@@ -2493,7 +2484,7 @@ usb_perform_transfer(struct cgpu_info *cgpu, struct cg_usb_device *usbdev, int i
unsigned int timeout, __maybe_unused int mode, enum usb_cmds cmd,
__maybe_unused int seq, bool cancellable, bool tt)
{
- int bulk_timeout, callback_timeout = timeout, pipe_retries = 0;
+ int bulk_timeout, callback_timeout = timeout, err_retries = 0;
struct libusb_device_handle *dev_handle = usbdev->handle;
struct usb_epinfo *usb_epinfo;
struct usb_transfer ut;
@@ -2522,7 +2513,7 @@ usb_perform_transfer(struct cgpu_info *cgpu, struct cg_usb_device *usbdev, int i
* thread to be shut down after all existing transfers are complete */
if (opt_lowmem || cgpu->shutdown)
return libusb_bulk_transfer(dev_handle, endpoint, data, length, transferred, timeout);
-pipe_retry:
+err_retry:
init_usb_transfer(&ut);
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
@@ -2586,9 +2577,11 @@ pipe_retry:
if (pipeerr)
cgpu->usbinfo.clear_fail_count++;
} while (pipeerr && ++retries < USB_RETRY_MAX);
- if (!pipeerr && ++pipe_retries < USB_RETRY_MAX)
- goto pipe_retry;
+ if (!pipeerr && ++err_retries < USB_RETRY_MAX)
+ goto err_retry;
}
+ if (err == LIBUSB_ERROR_IO && ++err_retries < USB_RETRY_MAX)
+ goto err_retry;
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
memcpy(data, buf, *transferred);
@@ -2664,8 +2657,6 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
USBDEBUG("USB debug: @_usb_read(%s (nodev=%s)) first=%s err=%d%s got=%d ptr='%s' usbbufread=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), bool_str(first), err, isnodev(err), got, (char *)str_text((char *)ptr), (int)usbbufread);
- IOERR_CHECK(cgpu, err);
-
if (ftdi) {
// first 2 bytes returned are an FTDI status
if (got > 2) {
@@ -2800,8 +2791,6 @@ int _usb_write(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_
USBDEBUG("USB debug: @_usb_write(%s (nodev=%s)) err=%d%s sent=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), sent);
- IOERR_CHECK(cgpu, err);
-
tot += sent;
/* Unlike reads, even a timeout error is unrecoverable on
@@ -2926,8 +2915,6 @@ int __usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bReques
USBDEBUG("USB debug: @_usb_transfer(%s (nodev=%s)) err=%d%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err));
- IOERR_CHECK(cgpu, err);
-
if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) {
applog(LOG_WARNING, "%s %i usb transfer err:(%d) %s", cgpu->drv->name, cgpu->device_id,
err, libusb_error_name(err));
@@ -2991,8 +2978,6 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe
USBDEBUG("USB debug: @_usb_transfer_read(%s (nodev=%s)) amt/err=%d%s%s%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), err > 0 ? " = " : BLANK, err > 0 ? bin2hex((unsigned char *)buf, (size_t)err) : BLANK);
- IOERR_CHECK(cgpu, err);
-
if (err > 0) {
*amount = err;
err = 0;