Browse Source

BFL report USB device numbers for init errors and allow faster 'reinit'

nfactor-troky
Kano 12 years ago
parent
commit
b099615246
  1. 70
      driver-bitforce.c
  2. 5
      usbutils.c

70
driver-bitforce.c

@ -58,7 +58,9 @@
// If initialisation fails the first time, // If initialisation fails the first time,
// sleep this amount (ms) and try again // sleep this amount (ms) and try again
#define REINIT_TIME_MS 6000 #define REINIT_TIME_MS 1000
// But try this many times
#define REINIT_COUNT 6
static const char *blank = ""; static const char *blank = "";
@ -108,18 +110,18 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
bitforce->api->name, bitforce->device_id, err); bitforce->api->name, bitforce->device_id, err);
// Clear any sent data // Clear any sent data
// err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
// FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX); FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX);
// if (opt_debug) if (opt_debug)
// applog(LOG_DEBUG, "%s%i: purgetx got err %d", applog(LOG_DEBUG, "%s%i: purgetx got err %d",
// bitforce->api->name, bitforce->device_id, err); bitforce->api->name, bitforce->device_id, err);
// Clear any received data // Clear any received data
// err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
// FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX); FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX);
// if (opt_debug) if (opt_debug)
// applog(LOG_DEBUG, "%s%i: purgerx got err %d", applog(LOG_DEBUG, "%s%i: purgerx got err %d",
// bitforce->api->name, bitforce->device_id, err); bitforce->api->name, bitforce->device_id, err);
if (lock) if (lock)
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
@ -139,36 +141,49 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
bitforce->threads = 1; bitforce->threads = 1;
if (!usb_init(bitforce, dev, found)) { if (!usb_init(bitforce, dev, found)) {
applog(LOG_ERR, "%s detect: failed to initialise (incorrect device?)", bitforce->api->dname); applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
bitforce->api->dname,
(int)libusb_get_bus_number(dev),
(int)libusb_get_device_address(dev));
goto shin; goto shin;
} }
int init_counter = 0; sprintf(devpath, "%d:%d",
(int)(bitforce->usbdev->bus_number),
(int)(bitforce->usbdev->device_address));
int init_count = 0;
reinit: reinit:
bitforce_initialise(bitforce, false); bitforce_initialise(bitforce, false);
if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) { if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
applog(LOG_ERR, "%s detect: send identify request failed (%d:%d)", applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
bitforce->api->dname, amount, err); bitforce->api->dname, devpath, amount, err);
goto unshin; goto unshin;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) { if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) {
// Maybe it was still processing previous work? // Maybe it was still processing previous work?
if (init_counter++ < 1) { if (++init_count <= REINIT_COUNT) {
applog(LOG_WARNING, "%s detect: 1st init failed - retrying in %dms (%d:%d)", if (init_count < 2) {
bitforce->api->dname, REINIT_TIME_MS, amount, err); applog(LOG_WARNING, "%s detect (%s) 1st init failed - retrying (%d:%d)",
bitforce->api->dname, devpath, amount, err);
}
nmsleep(REINIT_TIME_MS); nmsleep(REINIT_TIME_MS);
goto reinit; goto reinit;
} }
if (init_count > 0)
applog(LOG_WARNING, "%s detect (%s) init failed %d times",
bitforce->api->dname, devpath, init_count);
if (err < 0) { if (err < 0) {
applog(LOG_ERR, "%s detect: error identify reply (%d:%d)", applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
bitforce->api->dname, amount, err); bitforce->api->dname, devpath, amount, err);
} else { } else {
applog(LOG_ERR, "%s detect: empty identify reply (%d)", applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
bitforce->api->dname, amount); bitforce->api->dname, devpath, amount);
} }
goto unshin; goto unshin;
@ -176,8 +191,8 @@ reinit:
buf[amount] = '\0'; buf[amount] = '\0';
if (unlikely(!strstr(buf, "SHA256"))) { if (unlikely(!strstr(buf, "SHA256"))) {
applog(LOG_ERR, "%s detect: didn't recognise %s", applog(LOG_ERR, "%s detect (%s) didn't recognise '%s'",
bitforce->api->dname, buf); bitforce->api->dname, devpath, buf);
goto unshin; goto unshin;
} }
@ -189,7 +204,8 @@ reinit:
} }
// We have a real BitForce! // We have a real BitForce!
applog(LOG_DEBUG, "%s identified as: '%s'", bitforce->api->dname, bitforce->name); applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
bitforce->api->dname, devpath, bitforce->name);
/* Initially enable support for nonce range and disable it later if it /* Initially enable support for nonce range and disable it later if it
* fails */ * fails */
@ -202,10 +218,6 @@ reinit:
bitforce->kname = KNAME_WORK; bitforce->kname = KNAME_WORK;
} }
sprintf(devpath, "%d:%d",
(int)(bitforce->usbdev->bus_number),
(int)(bitforce->usbdev->device_address));
bitforce->device_path = strdup(devpath); bitforce->device_path = strdup(devpath);
if (!add_cgpu(bitforce)) if (!add_cgpu(bitforce))

5
usbutils.c

@ -45,8 +45,13 @@
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
static struct usb_endpoints bfl_eps[] = { static struct usb_endpoints bfl_eps[] = {
#ifdef WIN32
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 },
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 }
#else
{ LIBUSB_TRANSFER_TYPE_BULK, 512, EPI(1), 0 }, { LIBUSB_TRANSFER_TYPE_BULK, 512, EPI(1), 0 },
{ LIBUSB_TRANSFER_TYPE_BULK, 512, EPO(2), 0 } { LIBUSB_TRANSFER_TYPE_BULK, 512, EPO(2), 0 }
#endif
}; };
#endif #endif

Loading…
Cancel
Save