Add flush and version commands to bxf start up, flush buffer and try to parse version response string.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index c9da184..6055a35 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -169,8 +169,53 @@ static int bxf_recv_msg(struct cgpu_info *bitfury, char *buf)
return err;
}
+/* Keep reading till the first timeout or error */
+static void bxf_clear_buffer(struct cgpu_info *bitfury)
+{
+ int err, retries = 0;
+ char buf[512];
+
+ do {
+ err = bxf_recv_msg(bitfury, buf);
+ usb_buffer_clear(bitfury);
+ if (err < 0)
+ break;
+ } while (retries++ < 10);
+}
+
static bool bxf_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
{
+ int err, retries = 0;
+ char buf[512];
+
+ sprintf(buf, "flush\n");
+ if (!bxf_send_msg(bitfury, buf, C_BXF_FLUSH))
+ return false;
+
+ bxf_clear_buffer(bitfury);
+
+ sprintf(buf, "version\n");
+ if (!bxf_send_msg(bitfury, buf, C_BXF_VERSION))
+ return false;
+
+ do {
+ err = bxf_recv_msg(bitfury, buf);
+ if (err < 0 && err != LIBUSB_ERROR_TIMEOUT)
+ return false;
+ if (err > 0 && !strncmp(buf, "version", 7)) {
+ sscanf(&buf[8], "%d.%d rev %d chips %d", &info->ver_major,
+ &info->ver_minor, &info->hw_rev, &info->chips);
+ applog(LOG_INFO, "%s %d: Version %d.%d rev %d chips %d",
+ bitfury->drv->name, bitfury->device_id, info->ver_major,
+ info->ver_minor, info->hw_rev, info->chips);
+ break;
+ }
+ /* Keep parsing if the buffer is full without counting it as
+ * a retry. */
+ if (usb_buffer_size(bitfury))
+ continue;
+ } while (retries++ < 10);
+
if (!add_cgpu(bitfury))
quit(1, "Failed to add_cgpu in bxf_detect_one");
diff --git a/driver-bitfury.h b/driver-bitfury.h
index de1629f..320f470 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -36,6 +36,10 @@ struct bitfury_info {
int work_id; // Current work->subid
int no_matching_work;
bool can_roll;
+ int ver_major;
+ int ver_minor;
+ int hw_rev;
+ int chips;
};
#endif /* BITFURY_H */