Browse Source

Merge pull request #405 from kanoi/bflsc

USB modify -n and --usb-dump to only show known devices or use new --usb-list-all option to see all
nfactor-troky
Con Kolivas 12 years ago
parent
commit
e5a5be005a
  1. 7
      README
  2. 4
      cgminer.c
  3. 1
      miner.h
  4. 60
      usbutils.c

7
README

@ -252,10 +252,11 @@ which means any devices on USB bus_number 1
This is useful if you unplug a device then plug it back in the same port, This is useful if you unplug a device then plug it back in the same port,
it usually reappears with the same bus_number but a different device_address it usually reappears with the same bus_number but a different device_address
You can see the list of USB devices on linux with 'sudo lsusb' You can see the list of all USB devices on linux with 'sudo lsusb'
Cgminer will list the USB devices with the '--usb-dump 0' option Cgminer will list the recognised USB devices with the '--usb-dump 0' option
The '--usb-dump N' option with a value of N greater than 0 will dump a lot The '--usb-dump N' option with a value of N greater than 0 will dump a lot
of details about each USB device of details about each recognised USB device
If you wish to see all USB devices, include the --usb-list-all option
The second version The second version
--usb BAS:1,BFL:1,MMQ:0 --usb BAS:1,BFL:1,MMQ:0

4
cgminer.c

@ -139,6 +139,7 @@ bool opt_worktime;
#ifdef USE_USBUTILS #ifdef USE_USBUTILS
char *opt_usb_select = NULL; char *opt_usb_select = NULL;
int opt_usbdump = -1; int opt_usbdump = -1;
bool opt_usb_list_all;
#endif #endif
char *opt_kernel_path; char *opt_kernel_path;
@ -1174,6 +1175,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--usb-dump", OPT_WITH_ARG("--usb-dump",
set_int_0_to_10, opt_show_intval, &opt_usbdump, set_int_0_to_10, opt_show_intval, &opt_usbdump,
opt_hidden), opt_hidden),
OPT_WITHOUT_ARG("--usb-list-all",
opt_set_bool, &opt_usb_list_all,
opt_hidden),
#endif #endif
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
OPT_WITH_ARG("--vectors|-v", OPT_WITH_ARG("--vectors|-v",

1
miner.h

@ -781,6 +781,7 @@ extern bool opt_worktime;
#ifdef USE_USBUTILS #ifdef USE_USBUTILS
extern char *opt_usb_select; extern char *opt_usb_select;
extern int opt_usbdump; extern int opt_usbdump;
extern bool opt_usb_list_all;
#endif #endif
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
extern bool opt_bfl_noncerange; extern bool opt_bfl_noncerange;

60
usbutils.c

@ -411,7 +411,7 @@ static bool setgetdes(ssize_t count, libusb_device *dev, struct libusb_device_ha
return true; return true;
} }
static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off, size_t *len, int level) static void usb_full(ssize_t *count, libusb_device *dev, char **buf, size_t *off, size_t *len, int level)
{ {
struct libusb_device_descriptor desc; struct libusb_device_descriptor desc;
uint8_t bus_number; uint8_t bus_number;
@ -427,9 +427,9 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
int err, i, j, k; int err, i, j, k;
err = libusb_get_device_descriptor(dev, &desc); err = libusb_get_device_descriptor(dev, &desc);
if (err) { if (opt_usb_list_all && err) {
sprintf(tmp, EOL ".USB dev %d: Failed to get descriptor, err %d", sprintf(tmp, EOL ".USB dev %d: Failed to get descriptor, err %d",
(int)count, err); (int)(++(*count)), err);
append(buf, tmp, off, len); append(buf, tmp, off, len);
return; return;
} }
@ -437,9 +437,25 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
bus_number = libusb_get_bus_number(dev); bus_number = libusb_get_bus_number(dev);
device_address = libusb_get_device_address(dev); device_address = libusb_get_device_address(dev);
if (!opt_usb_list_all) {
bool known = false;
for (i = 0; find_dev[i].drv != DRV_LAST; i++)
if ((find_dev[i].idVendor == desc.idVendor) &&
(find_dev[i].idProduct == desc.idProduct)) {
known = true;
break;
}
if (!known)
return;
}
(*count)++;
if (level == 0) { if (level == 0) {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d ID: %04x:%04x", sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d ID: %04x:%04x",
(int)count, (int)bus_number, (int)device_address, (int)(*count), (int)bus_number, (int)device_address,
desc.idVendor, desc.idProduct); desc.idVendor, desc.idProduct);
} else { } else {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d Device Descriptor:" EOL "\tLength: %d" EOL sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d Device Descriptor:" EOL "\tLength: %d" EOL
@ -447,7 +463,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tDeviceSubClass: %d" EOL "\tDeviceProtocol: %d" EOL "\tMaxPacketSize0: %d" EOL "\tDeviceSubClass: %d" EOL "\tDeviceProtocol: %d" EOL "\tMaxPacketSize0: %d" EOL
"\tidVendor: %04x" EOL "\tidProduct: %04x" EOL "\tDeviceRelease: %x" EOL "\tidVendor: %04x" EOL "\tidProduct: %04x" EOL "\tDeviceRelease: %x" EOL
"\tNumConfigurations: %d", "\tNumConfigurations: %d",
(int)count, (int)bus_number, (int)device_address, (int)(*count), (int)bus_number, (int)device_address,
(int)(desc.bLength), destype(desc.bDescriptorType), (int)(desc.bLength), destype(desc.bDescriptorType),
desc.bcdUSB, (int)(desc.bDeviceClass), (int)(desc.bDeviceSubClass), desc.bcdUSB, (int)(desc.bDeviceClass), (int)(desc.bDeviceSubClass),
(int)(desc.bDeviceProtocol), (int)(desc.bMaxPacketSize0), (int)(desc.bDeviceProtocol), (int)(desc.bMaxPacketSize0),
@ -458,7 +474,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
err = libusb_open(dev, &handle); err = libusb_open(dev, &handle);
if (err) { if (err) {
sprintf(tmp, EOL " ** dev %d: Failed to open, err %d", (int)count, err); sprintf(tmp, EOL " ** dev %d: Failed to open, err %d", (int)(*count), err);
append(buf, tmp, off, len); append(buf, tmp, off, len);
return; return;
} }
@ -479,17 +495,17 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
} }
if (libusb_kernel_driver_active(handle, 0) == 1) { if (libusb_kernel_driver_active(handle, 0) == 1) {
sprintf(tmp, EOL " * dev %d: kernel attached", (int)count); sprintf(tmp, EOL " * dev %d: kernel attached", (int)(*count));
append(buf, tmp, off, len); append(buf, tmp, off, len);
} }
err = libusb_get_active_config_descriptor(dev, &config); err = libusb_get_active_config_descriptor(dev, &config);
if (err) { if (err) {
if (!setgetdes(count, dev, handle, &config, 1, buf, off, len) if (!setgetdes(*count, dev, handle, &config, 1, buf, off, len)
&& !setgetdes(count, dev, handle, &config, 0, buf, off, len)) { && !setgetdes(*count, dev, handle, &config, 0, buf, off, len)) {
libusb_close(handle); libusb_close(handle);
sprintf(tmp, EOL " ** dev %d: Failed to set config descriptor to %d or %d", sprintf(tmp, EOL " ** dev %d: Failed to set config descriptor to %d or %d",
(int)count, 1, 0); (int)(*count), 1, 0);
append(buf, tmp, off, len); append(buf, tmp, off, len);
return; return;
} }
@ -498,7 +514,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
sprintf(tmp, EOL " dev %d: Active Config:" EOL "\tDescriptorType: %s" EOL sprintf(tmp, EOL " dev %d: Active Config:" EOL "\tDescriptorType: %s" EOL
"\tNumInterfaces: %d" EOL "\tConfigurationValue: %d" EOL "\tNumInterfaces: %d" EOL "\tConfigurationValue: %d" EOL
"\tAttributes: %d" EOL "\tMaxPower: %d", "\tAttributes: %d" EOL "\tMaxPower: %d",
(int)count, destype(config->bDescriptorType), (int)(*count), destype(config->bDescriptorType),
(int)(config->bNumInterfaces), (int)(config->iConfiguration), (int)(config->bNumInterfaces), (int)(config->iConfiguration),
(int)(config->bmAttributes), (int)(config->MaxPower)); (int)(config->bmAttributes), (int)(config->MaxPower));
append(buf, tmp, off, len); append(buf, tmp, off, len);
@ -511,7 +527,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tDescriptorType: %s" EOL "\tInterfaceNumber: %d" EOL "\tDescriptorType: %s" EOL "\tInterfaceNumber: %d" EOL
"\tNumEndpoints: %d" EOL "\tInterfaceClass: %d" EOL "\tNumEndpoints: %d" EOL "\tInterfaceClass: %d" EOL
"\tInterfaceSubClass: %d" EOL "\tInterfaceProtocol: %d", "\tInterfaceSubClass: %d" EOL "\tInterfaceProtocol: %d",
(int)count, j, destype(idesc->bDescriptorType), (int)(*count), j, destype(idesc->bDescriptorType),
(int)(idesc->bInterfaceNumber), (int)(idesc->bInterfaceNumber),
(int)(idesc->bNumEndpoints), (int)(idesc->bNumEndpoints),
(int)(idesc->bInterfaceClass), (int)(idesc->bInterfaceClass),
@ -527,7 +543,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
"\tEndpointAddress: %s0x%x" EOL "\tEndpointAddress: %s0x%x" EOL
"\tAttributes: %s" EOL "\tMaxPacketSize: %d" EOL "\tAttributes: %s" EOL "\tMaxPacketSize: %d" EOL
"\tInterval: %d" EOL "\tRefresh: %d", "\tInterval: %d" EOL "\tRefresh: %d",
(int)count, (int)(idesc->bInterfaceNumber), k, (int)(*count), (int)(idesc->bInterfaceNumber), k,
destype(epdesc->bDescriptorType), destype(epdesc->bDescriptorType),
epdir(epdesc->bEndpointAddress), epdir(epdesc->bEndpointAddress),
(int)(epdesc->bEndpointAddress), (int)(epdesc->bEndpointAddress),
@ -549,7 +565,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
sprintf(tmp, EOL " dev %d: More Info:" EOL "\tManufacturer: '%s'" EOL sprintf(tmp, EOL " dev %d: More Info:" EOL "\tManufacturer: '%s'" EOL
"\tProduct: '%s'" EOL "\tSerial '%s'", "\tProduct: '%s'" EOL "\tSerial '%s'",
(int)count, man, prod, ser); (int)(*count), man, prod, ser);
append(buf, tmp, off, len); append(buf, tmp, off, len);
libusb_close(handle); libusb_close(handle);
@ -559,7 +575,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
void usb_all(int level) void usb_all(int level)
{ {
libusb_device **list; libusb_device **list;
ssize_t count, i; ssize_t count, i, j;
char *buf; char *buf;
size_t len, off; size_t len, off;
@ -577,15 +593,25 @@ void usb_all(int level)
buf = malloc(len+1); buf = malloc(len+1);
sprintf(buf, "USB all: found %d devices", (int)count); sprintf(buf, "USB all: found %d devices", (int)count);
off = strlen(buf); off = strlen(buf);
if (!opt_usb_list_all)
append(&buf, " - listing known devices", &off, &len);
j = -1;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
usb_full(i, list[i], &buf, &off, &len, level); usb_full(&j, list[i], &buf, &off, &len, level);
applog(LOG_WARNING, "%s", buf); applog(LOG_WARNING, "%s", buf);
free(buf); free(buf);
if (j == -1)
applog(LOG_WARNING, "No known USB devices");
else
applog(LOG_WARNING, "%d %sUSB devices",
(int)(++j), opt_usb_list_all ? BLANK : "known ");
} }
libusb_free_device_list(list, 1); libusb_free_device_list(list, 1);

Loading…
Cancel
Save