mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-10 23:08:07 +00:00
USB make device_path handled by usbutils
This commit is contained in:
parent
749fa78d8a
commit
b8b137aeef
@ -574,7 +574,6 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
|
||||
int this_option_offset = ++option_offset;
|
||||
struct avalon_info *info;
|
||||
struct cgpu_info *avalon;
|
||||
char devpath[20];
|
||||
bool configured;
|
||||
int ret;
|
||||
|
||||
@ -591,14 +590,8 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
|
||||
avalon->usbdev->usb_type = USB_TYPE_STD;
|
||||
|
||||
/* We have a real Avalon! */
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(avalon->usbinfo.bus_number),
|
||||
(int)(avalon->usbinfo.device_address));
|
||||
|
||||
avalon_initialise(avalon);
|
||||
|
||||
avalon->device_path = strdup(devpath);
|
||||
|
||||
avalon->device_data = calloc(sizeof(struct avalon_info), 1);
|
||||
if (unlikely(!(avalon->device_data)))
|
||||
quit(1, "Failed to calloc avalon_info data");
|
||||
@ -642,7 +635,7 @@ static bool avalon_detect_one(libusb_device *dev, struct usb_find_devices *found
|
||||
|
||||
applog(LOG_DEBUG, "Avalon Detected: %s "
|
||||
"(miner_count=%d asic_count=%d timeout=%d frequency=%d)",
|
||||
devpath, info->miner_count, info->asic_count, info->timeout,
|
||||
avalon->device_path, info->miner_count, info->asic_count, info->timeout,
|
||||
info->frequency);
|
||||
|
||||
return true;
|
||||
@ -656,9 +649,6 @@ shin:
|
||||
free(avalon->device_data);
|
||||
avalon->device_data = NULL;
|
||||
|
||||
free(avalon->device_path);
|
||||
avalon->device_path = NULL;
|
||||
|
||||
avalon = usb_free_cgpu(avalon);
|
||||
|
||||
return false;
|
||||
|
@ -802,7 +802,6 @@ static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
{
|
||||
struct bflsc_info *sc_info = NULL;
|
||||
char buf[BFLSC_BUFSIZ+1];
|
||||
char devpath[20];
|
||||
int i, err, amount;
|
||||
struct timeval init_start, init_now;
|
||||
int init_sleep, init_count;
|
||||
@ -821,11 +820,6 @@ static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
if (!usb_init(bflsc, dev, found))
|
||||
goto shin;
|
||||
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(bflsc->usbinfo.bus_number),
|
||||
(int)(bflsc->usbinfo.device_address));
|
||||
|
||||
|
||||
// Allow 2 complete attempts if the 1st time returns an unrecognised reply
|
||||
ident_first = true;
|
||||
retry:
|
||||
@ -837,7 +831,7 @@ reinit:
|
||||
err = write_to_dev(bflsc, 0, BFLSC_IDENTIFY, BFLSC_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY);
|
||||
if (err < 0 || amount != BFLSC_IDENTIFY_LEN) {
|
||||
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
|
||||
bflsc->drv->dname, devpath, amount, err);
|
||||
bflsc->drv->dname, bflsc->device_path, amount, err);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
@ -848,7 +842,7 @@ reinit:
|
||||
if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
|
||||
if (init_count == 2) {
|
||||
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
|
||||
bflsc->drv->dname, devpath, amount, err);
|
||||
bflsc->drv->dname, bflsc->device_path, amount, err);
|
||||
}
|
||||
nmsleep(init_sleep);
|
||||
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
|
||||
@ -858,14 +852,14 @@ reinit:
|
||||
|
||||
if (init_count > 0)
|
||||
applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
|
||||
bflsc->drv->dname, devpath, init_count, tdiff(&init_now, &init_start));
|
||||
bflsc->drv->dname, bflsc->device_path, init_count, tdiff(&init_now, &init_start));
|
||||
|
||||
if (err < 0) {
|
||||
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
|
||||
bflsc->drv->dname, devpath, amount, err);
|
||||
bflsc->drv->dname, bflsc->device_path, amount, err);
|
||||
} else {
|
||||
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
|
||||
bflsc->drv->dname, devpath, amount);
|
||||
bflsc->drv->dname, bflsc->device_path, amount);
|
||||
}
|
||||
|
||||
goto unshin;
|
||||
@ -874,24 +868,22 @@ reinit:
|
||||
|
||||
if (unlikely(!strstr(buf, BFLSC_BFLSC))) {
|
||||
applog(LOG_DEBUG, "%s detect (%s) found an FPGA '%s' ignoring",
|
||||
bflsc->drv->dname, devpath, buf);
|
||||
bflsc->drv->dname, bflsc->device_path, buf);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
if (unlikely(strstr(buf, BFLSC_IDENTITY))) {
|
||||
if (ident_first) {
|
||||
applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' trying again ...",
|
||||
bflsc->drv->dname, devpath, buf);
|
||||
bflsc->drv->dname, bflsc->device_path, buf);
|
||||
ident_first = false;
|
||||
goto retry;
|
||||
}
|
||||
applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
|
||||
bflsc->drv->dname, devpath, buf);
|
||||
bflsc->drv->dname, bflsc->device_path, buf);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
bflsc->device_path = strdup(devpath);
|
||||
|
||||
if (!getinfo(bflsc, 0))
|
||||
goto unshin;
|
||||
|
||||
@ -945,7 +937,7 @@ reinit:
|
||||
|
||||
// We have a real BFLSC!
|
||||
applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
|
||||
bflsc->drv->dname, devpath, bflsc->drv->name);
|
||||
bflsc->drv->dname, bflsc->device_path, bflsc->drv->name);
|
||||
|
||||
if (!add_cgpu(bflsc))
|
||||
goto unshin;
|
||||
@ -965,9 +957,6 @@ unshin:
|
||||
|
||||
shin:
|
||||
|
||||
free(bflsc->device_path);
|
||||
bflsc->device_path = NULL;
|
||||
|
||||
free(bflsc->device_data);
|
||||
bflsc->device_data = NULL;
|
||||
|
||||
|
@ -166,7 +166,6 @@ failed:
|
||||
static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
|
||||
{
|
||||
char buf[BITFORCE_BUFSIZ+1];
|
||||
char devpath[20];
|
||||
int err, amount;
|
||||
char *s;
|
||||
struct timeval init_start, init_now;
|
||||
@ -178,10 +177,6 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
|
||||
if (!usb_init(bitforce, dev, found))
|
||||
goto shin;
|
||||
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(bitforce->usbinfo.bus_number),
|
||||
(int)(bitforce->usbinfo.device_address));
|
||||
|
||||
// Allow 2 complete attempts if the 1st time returns an unrecognised reply
|
||||
ident_first = true;
|
||||
retry:
|
||||
@ -192,7 +187,7 @@ reinit:
|
||||
bitforce_initialise(bitforce, false);
|
||||
if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
|
||||
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
|
||||
bitforce->drv->dname, devpath, amount, err);
|
||||
bitforce->drv->dname, bitforce->device_path, amount, err);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
@ -202,7 +197,7 @@ reinit:
|
||||
if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
|
||||
if (init_count == 2) {
|
||||
applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
|
||||
bitforce->drv->dname, devpath, amount, err);
|
||||
bitforce->drv->dname, bitforce->device_path, amount, err);
|
||||
}
|
||||
nmsleep(init_sleep);
|
||||
if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
|
||||
@ -212,14 +207,14 @@ reinit:
|
||||
|
||||
if (init_count > 0)
|
||||
applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
|
||||
bitforce->drv->dname, devpath, init_count, tdiff(&init_now, &init_start));
|
||||
bitforce->drv->dname, bitforce->device_path, init_count, tdiff(&init_now, &init_start));
|
||||
|
||||
if (err < 0) {
|
||||
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
|
||||
bitforce->drv->dname, devpath, amount, err);
|
||||
bitforce->drv->dname, bitforce->device_path, amount, err);
|
||||
} else {
|
||||
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
|
||||
bitforce->drv->dname, devpath, amount);
|
||||
bitforce->drv->dname, bitforce->device_path, amount);
|
||||
}
|
||||
|
||||
goto unshin;
|
||||
@ -229,12 +224,12 @@ reinit:
|
||||
if (unlikely(!strstr(buf, "SHA256"))) {
|
||||
if (ident_first) {
|
||||
applog(LOG_WARNING, "%s detect (%s) didn't recognise '%s' trying again ...",
|
||||
bitforce->drv->dname, devpath, buf);
|
||||
bitforce->drv->dname, bitforce->device_path, buf);
|
||||
ident_first = false;
|
||||
goto retry;
|
||||
}
|
||||
applog(LOG_ERR, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
|
||||
bitforce->drv->dname, devpath, buf);
|
||||
bitforce->drv->dname, bitforce->device_path, buf);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
@ -256,7 +251,7 @@ reinit:
|
||||
|
||||
// We have a real BitForce!
|
||||
applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
|
||||
bitforce->drv->dname, devpath, bitforce->name);
|
||||
bitforce->drv->dname, bitforce->device_path, bitforce->name);
|
||||
|
||||
/* Initially enable support for nonce range and disable it later if it
|
||||
* fails */
|
||||
@ -269,8 +264,6 @@ reinit:
|
||||
bitforce->kname = KNAME_WORK;
|
||||
}
|
||||
|
||||
bitforce->device_path = strdup(devpath);
|
||||
|
||||
if (!add_cgpu(bitforce))
|
||||
goto unshin;
|
||||
|
||||
@ -286,9 +279,6 @@ unshin:
|
||||
|
||||
shin:
|
||||
|
||||
free(bitforce->device_path);
|
||||
bitforce->device_path = NULL;
|
||||
|
||||
if (bitforce->name != blank) {
|
||||
free(bitforce->name);
|
||||
bitforce->name = NULL;
|
||||
|
@ -728,7 +728,6 @@ static void get_options(int this_option_offset, struct cgpu_info *icarus, int *b
|
||||
static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
|
||||
{
|
||||
int this_option_offset = ++option_offset;
|
||||
char devpath[20];
|
||||
struct ICARUS_INFO *info;
|
||||
struct timeval tv_start, tv_finish;
|
||||
|
||||
@ -758,12 +757,6 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
|
||||
get_options(this_option_offset, icarus, &baud, &work_division, &fpga_count);
|
||||
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(icarus->usbinfo.bus_number),
|
||||
(int)(icarus->usbinfo.device_address));
|
||||
|
||||
icarus->device_path = strdup(devpath);
|
||||
|
||||
hex2bin(ob_bin, golden_ob, sizeof(ob_bin));
|
||||
|
||||
tries = 2;
|
||||
@ -789,7 +782,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
applog(LOG_ERR,
|
||||
"Icarus Detect: "
|
||||
"Test failed at %s: get %s, should: %s",
|
||||
devpath, nonce_hex, golden_nonce);
|
||||
icarus->device_path, nonce_hex, golden_nonce);
|
||||
}
|
||||
}
|
||||
free(nonce_hex);
|
||||
@ -801,7 +794,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
applog(LOG_DEBUG,
|
||||
"Icarus Detect: "
|
||||
"Test succeeded at %s: got %s",
|
||||
devpath, golden_nonce);
|
||||
icarus->device_path, golden_nonce);
|
||||
|
||||
/* We have a real Icarus! */
|
||||
if (!add_cgpu(icarus))
|
||||
@ -810,7 +803,7 @@ static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices
|
||||
update_usb_stats(icarus);
|
||||
|
||||
applog(LOG_INFO, "%s%d: Found at %s",
|
||||
icarus->drv->name, icarus->device_id, devpath);
|
||||
icarus->drv->name, icarus->device_id, icarus->device_path);
|
||||
|
||||
applog(LOG_DEBUG, "%s%d: Init baud=%d work_division=%d fpga_count=%d",
|
||||
icarus->drv->name, icarus->device_id, baud, work_division, fpga_count);
|
||||
@ -842,9 +835,6 @@ unshin:
|
||||
|
||||
usb_uninit(icarus);
|
||||
|
||||
free(icarus->device_path);
|
||||
icarus->device_path = NULL;
|
||||
|
||||
shin:
|
||||
|
||||
icarus = usb_free_cgpu(icarus);
|
||||
|
@ -115,7 +115,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
||||
{
|
||||
char buf[0x100+1];
|
||||
char *devname = NULL;
|
||||
char devpath[20];
|
||||
char devpath[32];
|
||||
int err, i, amount;
|
||||
bool added = false;
|
||||
|
||||
@ -128,44 +128,40 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
||||
if (!usb_init(modminer, dev, found))
|
||||
goto shin;
|
||||
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(modminer->usbinfo.bus_number),
|
||||
(int)(modminer->usbinfo.device_address));
|
||||
|
||||
do_ping(modminer);
|
||||
|
||||
if ((err = usb_write(modminer, MODMINER_GET_VERSION, 1, &amount, C_REQUESTVERSION)) < 0 || amount != 1) {
|
||||
applog(LOG_ERR, "%s detect (%s) send version request failed (%d:%d)",
|
||||
modminer->drv->dname, devpath, amount, err);
|
||||
modminer->drv->dname, modminer->device_path, amount, err);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
if ((err = usb_read_once(modminer, buf, sizeof(buf)-1, &amount, C_GETVERSION)) < 0 || amount < 1) {
|
||||
if (err < 0)
|
||||
applog(LOG_ERR, "%s detect (%s) no version reply (%d)",
|
||||
modminer->drv->dname, devpath, err);
|
||||
modminer->drv->dname, modminer->device_path, err);
|
||||
else
|
||||
applog(LOG_ERR, "%s detect (%s) empty version reply (%d)",
|
||||
modminer->drv->dname, devpath, amount);
|
||||
modminer->drv->dname, modminer->device_path, amount);
|
||||
|
||||
applog(LOG_DEBUG, "%s detect (%s) check the firmware",
|
||||
modminer->drv->dname, devpath);
|
||||
modminer->drv->dname, modminer->device_path);
|
||||
|
||||
goto unshin;
|
||||
}
|
||||
buf[amount] = '\0';
|
||||
devname = strdup(buf);
|
||||
applog(LOG_DEBUG, "%s (%s) identified as: %s", modminer->drv->dname, devpath, devname);
|
||||
applog(LOG_DEBUG, "%s (%s) identified as: %s", modminer->drv->dname, modminer->device_path, devname);
|
||||
|
||||
if ((err = usb_write(modminer, MODMINER_FPGA_COUNT, 1, &amount, C_REQUESTFPGACOUNT) < 0 || amount != 1)) {
|
||||
applog(LOG_ERR, "%s detect (%s) FPGA count request failed (%d:%d)",
|
||||
modminer->drv->dname, devpath, amount, err);
|
||||
modminer->drv->dname, modminer->device_path, amount, err);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
if ((err = usb_read(modminer, buf, 1, &amount, C_GETFPGACOUNT)) < 0 || amount != 1) {
|
||||
applog(LOG_ERR, "%s detect (%s) no FPGA count reply (%d:%d)",
|
||||
modminer->drv->dname, devpath, amount, err);
|
||||
modminer->drv->dname, modminer->device_path, amount, err);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
@ -174,18 +170,18 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
||||
|
||||
if (buf[0] == 0) {
|
||||
applog(LOG_ERR, "%s detect (%s) zero FPGA count from %s",
|
||||
modminer->drv->dname, devpath, devname);
|
||||
modminer->drv->dname, modminer->device_path, devname);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
if (buf[0] < 1 || buf[0] > 4) {
|
||||
applog(LOG_ERR, "%s detect (%s) invalid FPGA count (%u) from %s",
|
||||
modminer->drv->dname, devpath, buf[0], devname);
|
||||
modminer->drv->dname, modminer->device_path, buf[0], devname);
|
||||
goto unshin;
|
||||
}
|
||||
|
||||
applog(LOG_DEBUG, "%s (%s) %s has %u FPGAs",
|
||||
modminer->drv->dname, devpath, devname, buf[0]);
|
||||
modminer->drv->dname, modminer->device_path, devname, buf[0]);
|
||||
|
||||
modminer->name = devname;
|
||||
|
||||
@ -209,8 +205,6 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
|
||||
tmp->modminer_mutex = modminer->modminer_mutex;
|
||||
|
||||
if (!add_cgpu(tmp)) {
|
||||
free(tmp->device_path);
|
||||
tmp->device_path = NULL;
|
||||
tmp = usb_free_cgpu(tmp);
|
||||
goto unshin;
|
||||
}
|
||||
|
12
usbutils.c
12
usbutils.c
@ -1423,6 +1423,8 @@ struct cgpu_info *usb_free_cgpu(struct cgpu_info *cgpu)
|
||||
if (cgpu->drv->copy)
|
||||
free(cgpu->drv);
|
||||
|
||||
free(cgpu->device_path);
|
||||
|
||||
free(cgpu);
|
||||
|
||||
return NULL;
|
||||
@ -1439,6 +1441,7 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
|
||||
const struct libusb_interface_descriptor *idesc;
|
||||
const struct libusb_endpoint_descriptor *epdesc;
|
||||
unsigned char strbuf[STRBUFLEN+1];
|
||||
char devpath[32];
|
||||
char devstr[STRBUFLEN+1];
|
||||
int err, i, j, k;
|
||||
int bad = USB_INIT_FAIL;
|
||||
@ -1446,8 +1449,13 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u
|
||||
cgpu->usbinfo.bus_number = libusb_get_bus_number(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);
|
||||
sprintf(devpath, "%d:%d",
|
||||
(int)(cgpu->usbinfo.bus_number),
|
||||
(int)(cgpu->usbinfo.device_address));
|
||||
|
||||
cgpu->device_path = strdup(devpath);
|
||||
|
||||
sprintf(devstr, "- %s device %s", found->name, devpath);
|
||||
|
||||
cgusb = calloc(1, sizeof(*cgusb));
|
||||
if (unlikely(!cgusb))
|
||||
|
Loading…
Reference in New Issue
Block a user