|
|
@ -1319,32 +1319,23 @@ static struct cg_usb_device *free_cgusb(struct cg_usb_device *cgusb) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Called with cgpu->usbinfo.lock held */ |
|
|
|
void usb_uninit(struct cgpu_info *cgpu) |
|
|
|
static void __usb_uninit(struct cgpu_info *cgpu) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "USB uninit %s%i", |
|
|
|
|
|
|
|
cgpu->drv->name, cgpu->device_id); |
|
|
|
|
|
|
|
|
|
|
|
// May have happened already during a failed initialisation
|
|
|
|
// May have happened already during a failed initialisation
|
|
|
|
// if __release_cgpu() was called due to a USB NODEV(err)
|
|
|
|
// if release_cgpu() was called due to a USB NODEV(err)
|
|
|
|
if (!cgpu->usbdev) |
|
|
|
if (!cgpu->usbdev) |
|
|
|
return; |
|
|
|
return; |
|
|
|
if (!libusb_release_interface(cgpu->usbdev->handle, cgpu->usbdev->found->interface)) |
|
|
|
libusb_release_interface(cgpu->usbdev->handle, cgpu->usbdev->found->interface); |
|
|
|
libusb_close(cgpu->usbdev->handle); |
|
|
|
libusb_close(cgpu->usbdev->handle); |
|
|
|
cgpu->usbdev = free_cgusb(cgpu->usbdev); |
|
|
|
cgpu->usbdev = free_cgusb(cgpu->usbdev); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void usb_uninit(struct cgpu_info *cgpu) |
|
|
|
static void release_cgpu(struct cgpu_info *cgpu) |
|
|
|
{ |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "USB uninit %s%i", |
|
|
|
|
|
|
|
cgpu->drv->name, cgpu->device_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
__usb_uninit(cgpu); |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Called with cgpu->usbinfo.lock held */ |
|
|
|
|
|
|
|
static void __release_cgpu(struct cgpu_info *cgpu) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cg_usb_device *cgusb; |
|
|
|
struct cg_usb_device *cgusb = cgpu->usbdev; |
|
|
|
struct cgpu_info *lookcgpu; |
|
|
|
struct cgpu_info *lookcgpu; |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
@ -1355,7 +1346,6 @@ static void __release_cgpu(struct cgpu_info *cgpu) |
|
|
|
if (cgpu->usbinfo.nodev) |
|
|
|
if (cgpu->usbinfo.nodev) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
cgusb = cgpu->usbdev; |
|
|
|
|
|
|
|
total_count--; |
|
|
|
total_count--; |
|
|
|
drv_count[cgpu->drv->drv_id].count--; |
|
|
|
drv_count[cgpu->drv->drv_id].count--; |
|
|
|
|
|
|
|
|
|
|
@ -1379,20 +1369,11 @@ static void __release_cgpu(struct cgpu_info *cgpu) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "USB uninit %s%i", |
|
|
|
usb_uninit(cgpu); |
|
|
|
cgpu->drv->name, cgpu->device_id); |
|
|
|
|
|
|
|
__usb_uninit(cgpu); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address); |
|
|
|
cgminer_usb_unlock_bd(cgpu->drv, cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void release_cgpu(struct cgpu_info *cgpu) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
__release_cgpu(cgpu); |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define USB_INIT_FAIL 0 |
|
|
|
#define USB_INIT_FAIL 0 |
|
|
|
#define USB_INIT_OK 1 |
|
|
|
#define USB_INIT_OK 1 |
|
|
|
#define USB_INIT_IGNORE 2 |
|
|
|
#define USB_INIT_IGNORE 2 |
|
|
@ -1640,8 +1621,6 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u |
|
|
|
cgpu->drv->name = (char *)(found->name); |
|
|
|
cgpu->drv->name = (char *)(found->name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mutex_init(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return USB_INIT_OK; |
|
|
|
return USB_INIT_OK; |
|
|
|
|
|
|
|
|
|
|
|
cldame: |
|
|
|
cldame: |
|
|
@ -2082,7 +2061,7 @@ static char *find_end(unsigned char *buf, unsigned char *ptr, int ptrlen, int to |
|
|
|
|
|
|
|
|
|
|
|
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, __maybe_unused enum usb_cmds cmd, bool readonce) |
|
|
|
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, __maybe_unused enum usb_cmds cmd, bool readonce) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cg_usb_device *usbdev; |
|
|
|
struct cg_usb_device *usbdev = cgpu->usbdev; |
|
|
|
bool ftdi; |
|
|
|
bool ftdi; |
|
|
|
#if DO_USB_STATS |
|
|
|
#if DO_USB_STATS |
|
|
|
struct timeval tv_start; |
|
|
|
struct timeval tv_start; |
|
|
@ -2099,17 +2078,14 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro |
|
|
|
unsigned char usbbuf[USB_MAX_READ+4], *ptr; |
|
|
|
unsigned char usbbuf[USB_MAX_READ+4], *ptr; |
|
|
|
size_t usbbufread; |
|
|
|
size_t usbbufread; |
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
*buf = '\0'; |
|
|
|
*buf = '\0'; |
|
|
|
*processed = 0; |
|
|
|
*processed = 0; |
|
|
|
USB_REJECT(cgpu, MODE_BULK_READ); |
|
|
|
USB_REJECT(cgpu, MODE_BULK_READ); |
|
|
|
|
|
|
|
|
|
|
|
err = LIBUSB_ERROR_NO_DEVICE; |
|
|
|
return LIBUSB_ERROR_NO_DEVICE; |
|
|
|
goto out_unlock; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
usbdev = cgpu->usbdev; |
|
|
|
|
|
|
|
ftdi = (usbdev->usb_type == USB_TYPE_FTDI); |
|
|
|
ftdi = (usbdev->usb_type == USB_TYPE_FTDI); |
|
|
|
|
|
|
|
|
|
|
|
USBDEBUG("USB debug: _usb_read(%s (nodev=%s),ep=%d,buf=%p,bufsiz=%zu,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), ep, buf, bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce)); |
|
|
|
USBDEBUG("USB debug: _usb_read(%s (nodev=%s),ep=%d,buf=%p,bufsiz=%zu,proc=%p,timeout=%u,end=%s,cmd=%s,ftdi=%s,readonce=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), ep, buf, bufsiz, processed, timeout, end ? (char *)str_text((char *)end) : "NULL", usb_cmdname(cmd), bool_str(ftdi), bool_str(readonce)); |
|
|
@ -2206,9 +2182,9 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro |
|
|
|
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz); |
|
|
|
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz); |
|
|
|
|
|
|
|
|
|
|
|
if (NODEV(err)) |
|
|
|
if (NODEV(err)) |
|
|
|
__release_cgpu(cgpu); |
|
|
|
release_cgpu(cgpu); |
|
|
|
|
|
|
|
|
|
|
|
goto out_unlock; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (usbdev->buffer && usbdev->bufamt) { |
|
|
|
if (usbdev->buffer && usbdev->bufamt) { |
|
|
@ -2321,17 +2297,14 @@ int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pro |
|
|
|
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz); |
|
|
|
memcpy((char *)buf, (const char *)usbbuf, (tot < (int)bufsiz) ? tot + 1 : (int)bufsiz); |
|
|
|
|
|
|
|
|
|
|
|
if (NODEV(err)) |
|
|
|
if (NODEV(err)) |
|
|
|
__release_cgpu(cgpu); |
|
|
|
release_cgpu(cgpu); |
|
|
|
|
|
|
|
|
|
|
|
out_unlock: |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cg_usb_device *usbdev; |
|
|
|
struct cg_usb_device *usbdev = cgpu->usbdev; |
|
|
|
#if DO_USB_STATS |
|
|
|
#if DO_USB_STATS |
|
|
|
struct timeval tv_start; |
|
|
|
struct timeval tv_start; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2345,16 +2318,12 @@ int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pr |
|
|
|
|
|
|
|
|
|
|
|
*processed = 0; |
|
|
|
*processed = 0; |
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
USB_REJECT(cgpu, MODE_BULK_WRITE); |
|
|
|
USB_REJECT(cgpu, MODE_BULK_WRITE); |
|
|
|
|
|
|
|
|
|
|
|
err = LIBUSB_ERROR_NO_DEVICE; |
|
|
|
return LIBUSB_ERROR_NO_DEVICE; |
|
|
|
goto out_unlock; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
usbdev = cgpu->usbdev; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (timeout == DEVTIMEOUT) |
|
|
|
if (timeout == DEVTIMEOUT) |
|
|
|
timeout = usbdev->found->timeout; |
|
|
|
timeout = usbdev->found->timeout; |
|
|
|
|
|
|
|
|
|
|
@ -2400,17 +2369,14 @@ int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *pr |
|
|
|
*processed = tot; |
|
|
|
*processed = tot; |
|
|
|
|
|
|
|
|
|
|
|
if (NODEV(err)) |
|
|
|
if (NODEV(err)) |
|
|
|
__release_cgpu(cgpu); |
|
|
|
release_cgpu(cgpu); |
|
|
|
|
|
|
|
|
|
|
|
out_unlock: |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cg_usb_device *usbdev; |
|
|
|
struct cg_usb_device *usbdev = cgpu->usbdev; |
|
|
|
#if DO_USB_STATS |
|
|
|
#if DO_USB_STATS |
|
|
|
struct timeval tv_start, tv_finish; |
|
|
|
struct timeval tv_start, tv_finish; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2419,12 +2385,10 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest |
|
|
|
|
|
|
|
|
|
|
|
USBDEBUG("USB debug: _usb_transfer(%s (nodev=%s),type=%"PRIu8",req=%"PRIu8",value=%"PRIu16",index=%"PRIu16",siz=%d,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), request_type, bRequest, wValue, wIndex, siz, timeout, usb_cmdname(cmd)); |
|
|
|
USBDEBUG("USB debug: _usb_transfer(%s (nodev=%s),type=%"PRIu8",req=%"PRIu8",value=%"PRIu16",index=%"PRIu16",siz=%d,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), request_type, bRequest, wValue, wIndex, siz, timeout, usb_cmdname(cmd)); |
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
USB_REJECT(cgpu, MODE_CTRL_WRITE); |
|
|
|
USB_REJECT(cgpu, MODE_CTRL_WRITE); |
|
|
|
|
|
|
|
|
|
|
|
err = LIBUSB_ERROR_NO_DEVICE; |
|
|
|
return LIBUSB_ERROR_NO_DEVICE; |
|
|
|
goto out_unlock; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
USBDEBUG("USB debug: @_usb_transfer() data=%s", bin2hex((unsigned char *)data, (size_t)siz)); |
|
|
|
USBDEBUG("USB debug: @_usb_transfer() data=%s", bin2hex((unsigned char *)data, (size_t)siz)); |
|
|
@ -2442,8 +2406,6 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest |
|
|
|
|
|
|
|
|
|
|
|
USBDEBUG("USB debug: @_usb_transfer() buf=%s", bin2hex((unsigned char *)buf, (size_t)siz)); |
|
|
|
USBDEBUG("USB debug: @_usb_transfer() buf=%s", bin2hex((unsigned char *)buf, (size_t)siz)); |
|
|
|
|
|
|
|
|
|
|
|
usbdev = cgpu->usbdev; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
err = libusb_control_transfer(usbdev->handle, request_type, |
|
|
|
err = libusb_control_transfer(usbdev->handle, request_type, |
|
|
|
bRequest, wValue, wIndex, (unsigned char *)buf, (uint16_t)siz, |
|
|
|
bRequest, wValue, wIndex, (unsigned char *)buf, (uint16_t)siz, |
|
|
@ -2459,16 +2421,14 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest |
|
|
|
free(buf); |
|
|
|
free(buf); |
|
|
|
|
|
|
|
|
|
|
|
if (NODEV(err)) |
|
|
|
if (NODEV(err)) |
|
|
|
__release_cgpu(cgpu); |
|
|
|
release_cgpu(cgpu); |
|
|
|
out_unlock: |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, __maybe_unused enum usb_cmds cmd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cg_usb_device *usbdev; |
|
|
|
struct cg_usb_device *usbdev = cgpu->usbdev; |
|
|
|
#if DO_USB_STATS |
|
|
|
#if DO_USB_STATS |
|
|
|
struct timeval tv_start, tv_finish; |
|
|
|
struct timeval tv_start, tv_finish; |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -2476,18 +2436,14 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe |
|
|
|
|
|
|
|
|
|
|
|
USBDEBUG("USB debug: _usb_transfer_read(%s (nodev=%s),type=%"PRIu8",req=%"PRIu8",value=%"PRIu16",index=%"PRIu16",bufsiz=%d,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), request_type, bRequest, wValue, wIndex, bufsiz, timeout, usb_cmdname(cmd)); |
|
|
|
USBDEBUG("USB debug: _usb_transfer_read(%s (nodev=%s),type=%"PRIu8",req=%"PRIu8",value=%"PRIu16",index=%"PRIu16",bufsiz=%d,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), request_type, bRequest, wValue, wIndex, bufsiz, timeout, usb_cmdname(cmd)); |
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
if (cgpu->usbinfo.nodev) { |
|
|
|
USB_REJECT(cgpu, MODE_CTRL_READ); |
|
|
|
USB_REJECT(cgpu, MODE_CTRL_READ); |
|
|
|
|
|
|
|
|
|
|
|
err = LIBUSB_ERROR_NO_DEVICE; |
|
|
|
return LIBUSB_ERROR_NO_DEVICE; |
|
|
|
goto out_unlock; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
*amount = 0; |
|
|
|
*amount = 0; |
|
|
|
|
|
|
|
|
|
|
|
usbdev = cgpu->usbdev; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
STATS_TIMEVAL(&tv_start); |
|
|
|
err = libusb_control_transfer(usbdev->handle, request_type, |
|
|
|
err = libusb_control_transfer(usbdev->handle, request_type, |
|
|
|
bRequest, wValue, wIndex, |
|
|
|
bRequest, wValue, wIndex, |
|
|
@ -2504,10 +2460,7 @@ int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRe |
|
|
|
*amount = err; |
|
|
|
*amount = err; |
|
|
|
err = 0; |
|
|
|
err = 0; |
|
|
|
} else if (NODEV(err)) |
|
|
|
} else if (NODEV(err)) |
|
|
|
__release_cgpu(cgpu); |
|
|
|
release_cgpu(cgpu); |
|
|
|
|
|
|
|
|
|
|
|
out_unlock: |
|
|
|
|
|
|
|
mutex_unlock(&cgpu->usbinfo.lock); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return err; |
|
|
|
return err; |
|
|
|
} |
|
|
|
} |
|
|
|