|
|
@ -2218,8 +2218,7 @@ static void LIBUSB_CALL bulk_callback(struct libusb_transfer *transfer) |
|
|
|
|
|
|
|
|
|
|
|
/* Wait for callback function to tell us it has finished the USB transfer, but
|
|
|
|
/* Wait for callback function to tell us it has finished the USB transfer, but
|
|
|
|
* use our own timer to cancel the request if we go beyond the timeout. */ |
|
|
|
* use our own timer to cancel the request if we go beyond the timeout. */ |
|
|
|
static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *transferred, |
|
|
|
static int callback_wait(struct usb_transfer *ut, int *transferred, unsigned int timeout) |
|
|
|
unsigned int timeout) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
struct libusb_transfer *transfer= ut->transfer; |
|
|
|
struct libusb_transfer *transfer= ut->transfer; |
|
|
|
struct timespec ts_now, ts_end; |
|
|
|
struct timespec ts_now, ts_end; |
|
|
@ -2227,29 +2226,21 @@ static int callback_wait(struct cgpu_info *cgpu, struct usb_transfer *ut, int *t |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
|
|
cgtime(&tv_now); |
|
|
|
cgtime(&tv_now); |
|
|
|
/* Add enough to the timeout to allow for a normal USB polling interval
|
|
|
|
ms_to_timespec(&ts_end, timeout); |
|
|
|
* of 1ms to pass. */ |
|
|
|
|
|
|
|
ms_to_timespec(&ts_end, timeout + 2); |
|
|
|
|
|
|
|
timeval_to_spec(&ts_now, &tv_now); |
|
|
|
timeval_to_spec(&ts_now, &tv_now); |
|
|
|
timeraddspec(&ts_end, &ts_now); |
|
|
|
timeraddspec(&ts_end, &ts_now); |
|
|
|
ret = pthread_cond_timedwait(&ut->cond, &ut->mutex, &ts_end); |
|
|
|
ret = pthread_cond_timedwait(&ut->cond, &ut->mutex, &ts_end); |
|
|
|
if (ret) { |
|
|
|
if (ret) { |
|
|
|
/* Assume that if we timed out on the conditional then the
|
|
|
|
/* We are emulating a timeout ourself here */ |
|
|
|
* transfer has stalled for some reason. Cancel the transaction, |
|
|
|
|
|
|
|
* treating it the same as a timeout if we receive cancelled as |
|
|
|
|
|
|
|
* the status. */ |
|
|
|
|
|
|
|
libusb_cancel_transfer(transfer); |
|
|
|
libusb_cancel_transfer(transfer); |
|
|
|
applog(LOG_DEBUG, "%s%i: libusb cancelling async bulk transfer", |
|
|
|
|
|
|
|
cgpu->drv->name, cgpu->device_id); |
|
|
|
|
|
|
|
cgpu->usb_cancels++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Now wait for the callback function to be invoked. */ |
|
|
|
/* Now wait for the callback function to be invoked. */ |
|
|
|
pthread_cond_wait(&ut->cond, &ut->mutex); |
|
|
|
pthread_cond_wait(&ut->cond, &ut->mutex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret = transfer->status; |
|
|
|
ret = transfer->status; |
|
|
|
if (ret == LIBUSB_TRANSFER_CANCELLED) |
|
|
|
if (ret == LIBUSB_TRANSFER_CANCELLED) |
|
|
|
ret = LIBUSB_TRANSFER_TIMED_OUT; |
|
|
|
ret = LIBUSB_TRANSFER_TIMED_OUT; |
|
|
|
|
|
|
|
|
|
|
|
/* No need to sort out mutexes here since they won't be reused */ |
|
|
|
/* No need to sort out mutexes here since they won't be reused */ |
|
|
|
*transferred = transfer->actual_length; |
|
|
|
*transferred = transfer->actual_length; |
|
|
|
libusb_free_transfer(transfer); |
|
|
|
libusb_free_transfer(transfer); |
|
|
@ -2292,8 +2283,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, |
|
|
|
|
|
|
|
|
|
|
|
init_usb_transfer(&ut); |
|
|
|
init_usb_transfer(&ut); |
|
|
|
mutex_lock(&ut.mutex); |
|
|
|
mutex_lock(&ut.mutex); |
|
|
|
|
|
|
|
/* We give the transfer no timeout since we manage timeouts ourself */ |
|
|
|
libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length, |
|
|
|
libusb_fill_bulk_transfer(ut.transfer, dev_handle, endpoint, buf, length, |
|
|
|
bulk_callback, &ut, timeout); |
|
|
|
bulk_callback, &ut, 0); |
|
|
|
|
|
|
|
|
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
cg_rlock(&cgusb_fd_lock); |
|
|
|
cg_rlock(&cgusb_fd_lock); |
|
|
@ -2301,7 +2293,7 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo, |
|
|
|
cg_runlock(&cgusb_fd_lock); |
|
|
|
cg_runlock(&cgusb_fd_lock); |
|
|
|
errn = errno; |
|
|
|
errn = errno; |
|
|
|
if (!err) |
|
|
|
if (!err) |
|
|
|
err = callback_wait(cgpu, &ut, transferred, timeout); |
|
|
|
err = callback_wait(&ut, transferred, timeout); |
|
|
|
|
|
|
|
|
|
|
|
STATS_TIMEVAL(&tv_finish); |
|
|
|
STATS_TIMEVAL(&tv_finish); |
|
|
|
USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout); |
|
|
|
USB_STATS(cgpu, &tv_start, &tv_finish, err, mode, cmd, seq, timeout); |
|
|
|