Reliably extract BF1 information at startup and reset the device.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 66f35ff..81c3ef0 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -26,9 +26,20 @@ static void bitfury_close(struct cgpu_info *bitfury)
usb_transfer(bitfury, 0x21, 0x22, 0, 0, C_BFO_CLOSE);
}
+static void bitfury_empty_buffer(struct cgpu_info *bitfury)
+{
+ char buf[512];
+ int amount;
+
+ do {
+ usb_read(bitfury, buf, 512, &amount, C_PING);
+ } while (amount);
+}
+
static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
struct cgpu_info *bitfury;
+ struct bitfury_info *info;
char buf[512];
int amount;
@@ -41,17 +52,44 @@ static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_device
applog(LOG_INFO, "%s%d: Found at %s", bitfury->drv->name,
bitfury->device_id, bitfury->device_path);
+ info = calloc(sizeof(struct bitfury_info), 1);
+ if (!info)
+ quit(1, "Failed to calloc info in bitfury_detect_one");
+ bitfury->device_data = info;
+
+ bitfury_empty_buffer(bitfury);
usb_buffer_enable(bitfury);
+
bitfury_open(bitfury);
+
+ /* Send getinfo request */
usb_write(bitfury, "I", 1, &amount, C_BFO_REQINFO);
usb_read(bitfury, buf, 14, &amount, C_BFO_GETINFO);
if (amount != 14) {
- applog(LOG_WARNING, "%s%d: Getinfo received %d",
+ applog(LOG_WARNING, "%s%d: Getinfo received %d bytes",
+ bitfury->drv->name, bitfury->device_id, amount);
+ goto out_close;
+ }
+ info->version = buf[1];
+ memcpy(&info->product, buf + 2, 8);
+ memcpy(&info->serial, buf + 10, 4);
+
+ applog(LOG_INFO, "%s%d: Getinfo returned version %d, product %s serial %08x", bitfury->drv->name,
+ bitfury->device_id, info->version, info->product, info->serial);
+ bitfury_empty_buffer(bitfury);
+
+ /* Send reset request */
+ usb_write(bitfury, "R", 1, &amount, C_BFO_REQRESET);
+ usb_read_timeout(bitfury, buf, 7, &amount, 1000, C_BFO_GETRESET);
+
+ if (amount != 7) {
+ applog(LOG_WARNING, "%s%d: Getreset received %d bytes",
bitfury->drv->name, bitfury->device_id, amount);
goto out_close;
}
- applog(LOG_INFO, "%s%d: Getinfo returned %s", bitfury->drv->name,
+ applog(LOG_INFO, "%s%d: Getreset returned %s", bitfury->drv->name,
bitfury->device_id, buf);
+ bitfury_empty_buffer(bitfury);
//return true;
out_close:
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 52592bb..c427fdc 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -12,4 +12,10 @@
#include "usbutils.h"
+struct bitfury_info {
+ uint8_t version;
+ char product[8];
+ uint32_t serial;
+};
+
#endif /* BITFURY_H */