Browse Source

USB usb_init() consistent err/warning/debug messages

nfactor-troky
Kano 12 years ago
parent
commit
59c73ae59a
  1. 72
      usbutils.c

72
usbutils.c

@ -781,11 +781,15 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
const struct libusb_interface_descriptor *idesc; const struct libusb_interface_descriptor *idesc;
const struct libusb_endpoint_descriptor *epdesc; const struct libusb_endpoint_descriptor *epdesc;
unsigned char strbuf[STRBUFLEN+1]; unsigned char strbuf[STRBUFLEN+1];
char devstr[STRBUFLEN+1];
int err, i, j, k; int err, i, j, k;
cgpu->usbinfo.bus_number = libusb_get_bus_number(dev); cgpu->usbinfo.bus_number = libusb_get_bus_number(dev);
cgpu->usbinfo.device_address = libusb_get_device_address(dev); cgpu->usbinfo.device_address = libusb_get_device_address(dev);
sprintf(devstr, "- %s device %d:%d", found->name,
cgpu->usbinfo.bus_number, cgpu->usbinfo.device_address);
cgusb = calloc(1, sizeof(*cgusb)); cgusb = calloc(1, sizeof(*cgusb));
cgusb->found = found; cgusb->found = found;
@ -793,7 +797,9 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
err = libusb_get_device_descriptor(dev, cgusb->descriptor); err = libusb_get_device_descriptor(dev, cgusb->descriptor);
if (err) { if (err) {
applog(LOG_ERR, "USB init failed to get descriptor, err %d", err); applog(LOG_DEBUG,
"USB init failed to get descriptor, err %d %s",
err, devstr);
goto dame; goto dame;
} }
@ -801,31 +807,39 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
if (err) { if (err) {
switch (err) { switch (err) {
case LIBUSB_ERROR_ACCESS: case LIBUSB_ERROR_ACCESS:
applog(LOG_ERR, "USB init open device failed, err %d, you dont have priviledge to access the device", err); applog(LOG_ERR,
"USB init open device failed, err %d, "
"you dont have priviledge to access %s",
err, devstr);
break; break;
#ifdef WIN32 #ifdef WIN32
// Windows specific message // Windows specific message
case LIBUSB_ERROR_NOT_SUPPORTED: case LIBUSB_ERROR_NOT_SUPPORTED:
applog(LOG_ERR, "USB init, open device failed, err %d, you need to install a Windows USB driver for the device", err); applog(LOG_ERR,
"USB init, open device failed, err %d, "
"you need to install a Windows USB driver for %s",
err, devstr);
break; break;
#endif #endif
default: default:
applog(LOG_ERR, "USB init, open device failed, err %d", err); applog(LOG_DEBUG,
"USB init, open failed, err %d %s",
err, devstr);
} }
goto dame; goto dame;
} }
if (libusb_kernel_driver_active(cgusb->handle, found->config) == 1) { if (libusb_kernel_driver_active(cgusb->handle, found->config) == 1) {
applog(LOG_DEBUG, "USB init, kernel attached ..."); applog(LOG_DEBUG, "USB init, kernel attached ... %s", devstr);
err = libusb_detach_kernel_driver(cgusb->handle, found->config); err = libusb_detach_kernel_driver(cgusb->handle, found->config);
if (err == 0) if (err == 0) {
applog(LOG_DEBUG, "USB init, kernel detached successfully"); applog(LOG_DEBUG,
else { "USB init, kernel detached successfully %s",
devstr);
} else {
applog(LOG_WARNING, applog(LOG_WARNING,
"USB init, kernel detach failed, err %s - %s device %d:%d in use?", "USB init, kernel detach failed, err %d in use? %s",
err, found->name, err, devstr);
(int)(cgpu->usbinfo.bus_number),
(int)(cgpu->usbinfo.device_address));
goto cldame; goto cldame;
} }
} }
@ -834,21 +848,23 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
if (err) { if (err) {
switch(err) { switch(err) {
case LIBUSB_ERROR_BUSY: case LIBUSB_ERROR_BUSY:
applog(LOG_WARNING, "USB init, set config - %s device %d:%d in use", applog(LOG_WARNING,
found->name, (int)(cgpu->usbinfo.bus_number), "USB init, set config %d in use %s",
(int)(cgpu->usbinfo.device_address)); found->config, devstr);
break; break;
default: default:
applog(LOG_DEBUG, "USB init, failed to set config to %d, err %d", applog(LOG_DEBUG,
found->config, err); "USB init, failed to set config to %d, err %d %s",
found->config, err, devstr);
} }
goto cldame; goto cldame;
} }
err = libusb_get_active_config_descriptor(dev, &config); err = libusb_get_active_config_descriptor(dev, &config);
if (err) { if (err) {
applog(LOG_DEBUG, "USB init, failed to get config descriptor %d, err %d", applog(LOG_DEBUG,
found->config, err); "USB init, failed to get config descriptor %d, err %d %s",
found->config, err, devstr);
goto cldame; goto cldame;
} }
@ -881,8 +897,17 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
err = libusb_claim_interface(cgusb->handle, found->interface); err = libusb_claim_interface(cgusb->handle, found->interface);
if (err) { if (err) {
applog(LOG_DEBUG, "USB init, claim interface %d failed, err %d", switch(err) {
found->interface, err); case LIBUSB_ERROR_BUSY:
applog(LOG_WARNING,
"USB init, claim interface %d in use %s",
found->interface, devstr);
break;
default:
applog(LOG_DEBUG,
"USB init, claim interface %d failed, err %d %s",
found->interface, err, devstr);
}
goto cldame; goto cldame;
} }
@ -916,7 +941,10 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find
// cgusb->fwVersion <- for temp1/temp2 decision? or serial? (driver-modminer.c) // cgusb->fwVersion <- for temp1/temp2 decision? or serial? (driver-modminer.c)
// cgusb->interfaceVersion // cgusb->interfaceVersion
applog(LOG_DEBUG, "USB init device bus_number=%d device_address=%d usbver=%04x prod='%s' manuf='%s' serial='%s'", (int)(cgpu->usbinfo.bus_number), (int)(cgpu->usbinfo.device_address), cgusb->usbver, cgusb->prod_string, cgusb->manuf_string, cgusb->serial_string); applog(LOG_DEBUG,
"USB init %s usbver=%04x prod='%s' manuf='%s' serial='%s'",
devstr, cgusb->usbver, cgusb->prod_string,
cgusb->manuf_string, cgusb->serial_string);
cgpu->usbdev = cgusb; cgpu->usbdev = cgusb;

Loading…
Cancel
Save