Merge pull request #404 from kanoi/bflsc cgminer -n to include a USB device list
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
diff --git a/cgminer.c b/cgminer.c
index 20c2b06..0e70007 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1366,6 +1366,20 @@ static char *opt_verusage_and_exit(const char *extra)
exit(0);
}
+#if defined(HAVE_OPENCL) || defined(USE_USBUTILS)
+char *display_devs(int *ndevs)
+{
+ *ndevs = 0;
+#ifdef HAVE_OPENCL
+ print_ndevs(ndevs);
+#endif
+#ifdef USE_USBUTILS
+ usb_all(0);
+#endif
+ exit(*ndevs);
+}
+#endif
+
/* These options are available from commandline only */
static struct opt_table opt_cmdline_table[] = {
OPT_WITH_ARG("--config|-c",
@@ -1379,10 +1393,17 @@ static struct opt_table opt_cmdline_table[] = {
OPT_WITHOUT_ARG("--help|-h",
opt_verusage_and_exit, NULL,
"Print this message"),
-#ifdef HAVE_OPENCL
+#if defined(HAVE_OPENCL) || defined(USE_USBUTILS)
OPT_WITHOUT_ARG("--ndevs|-n",
- print_ndevs_and_exit, &nDevs,
- "Display number of detected GPUs, OpenCL platform information, and exit"),
+ display_devs, &nDevs,
+ "Display "
+#ifdef HAVE_OPENCL
+ "number of detected GPUs, OpenCL platform information, "
+#endif
+#ifdef USE_USBUTILS
+ "all USB devices, "
+#endif
+ "and exit"),
#endif
OPT_WITHOUT_ARG("--version|-V",
opt_version_and_exit, packagename,
diff --git a/driver-opencl.c b/driver-opencl.c
index 8580b22..5b83349 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -592,13 +592,12 @@ char *set_intensity(char *arg)
return NULL;
}
-char *print_ndevs_and_exit(int *ndevs)
+void print_ndevs(int *ndevs)
{
opt_log_output = true;
opencl_drv.drv_detect();
clear_adl(*ndevs);
applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
- exit(*ndevs);
}
#endif
diff --git a/driver-opencl.h b/driver-opencl.h
index 22bd9ec..1cb8807 100644
--- a/driver-opencl.h
+++ b/driver-opencl.h
@@ -4,7 +4,7 @@
#include "miner.h"
-extern char *print_ndevs_and_exit(int *ndevs);
+extern void print_ndevs(int *ndevs);
extern void *reinit_gpu(void *userdata);
extern char *set_gpu_map(char *arg);
extern char *set_gpu_engine(char *arg);
diff --git a/usbutils.c b/usbutils.c
index 93d918c..e7567ef 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -411,7 +411,7 @@ static bool setgetdes(ssize_t count, libusb_device *dev, struct libusb_device_ha
return true;
}
-static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off, size_t *len)
+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;
uint8_t bus_number;
@@ -437,7 +437,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
bus_number = libusb_get_bus_number(dev);
device_address = libusb_get_device_address(dev);
- if (opt_usbdump == 0) {
+ if (level == 0) {
sprintf(tmp, EOL ".USB dev %d: Bus %d Device %d ID: %04x:%04x",
(int)count, (int)bus_number, (int)device_address,
desc.idVendor, desc.idProduct);
@@ -471,7 +471,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
if (err < 0)
sprintf((char *)prod, "** err(%d)", err);
- if (opt_usbdump == 0) {
+ if (level == 0) {
libusb_close(handle);
sprintf(tmp, EOL " Manufacturer: '%s'" EOL " Product: '%s'", man, prod);
append(buf, tmp, off, len);
@@ -556,7 +556,7 @@ static void usb_full(ssize_t count, libusb_device *dev, char **buf, size_t *off,
}
// Function to dump all USB devices
-static void usb_all()
+void usb_all(int level)
{
libusb_device **list;
ssize_t count, i;
@@ -581,7 +581,7 @@ static void usb_all()
off = strlen(buf);
for (i = 0; i < count; i++)
- usb_full(i, list[i], &buf, &off, &len);
+ usb_full(i, list[i], &buf, &off, &len, level);
applog(LOG_WARNING, "%s", buf);
@@ -599,7 +599,7 @@ static void cgusb_check_init()
// N.B. environment LIBUSB_DEBUG also sets libusb_set_debug()
if (opt_usbdump >= 0) {
libusb_set_debug(NULL, opt_usbdump);
- usb_all();
+ usb_all(opt_usbdump);
}
usb_commands = malloc(sizeof(*usb_commands) * C_MAX);
diff --git a/usbutils.h b/usbutils.h
index 8a364c9..de79312 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -129,6 +129,7 @@ enum usb_cmds {
struct device_drv;
struct cgpu_info;
+void usb_all(int level);
void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));