Abstract out bxf send message to allow us to easily add extra commands.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 59a4719..5d1c671 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -140,6 +140,21 @@ static bool bf1_reset(struct cgpu_info *bitfury)
return true;
}
+static bool bxf_send_msg(struct cgpu_info *bitfury, char *buf, enum usb_cmds cmd)
+{
+ int err, amount, len;
+
+ len = strlen(buf);
+ applog(LOG_DEBUG, "%s %d: Sending %s", bitfury->drv->name, bitfury->device_id, buf);
+ err = usb_write(bitfury, buf, len, &amount, cmd);
+ if (err || amount != len) {
+ applog(LOG_WARNING, "%s %d: Error %d sending %s sent %d of %d", bitfury->drv->name,
+ bitfury->device_id, err, usb_cmdname(cmd), amount, len);
+ return false;
+ }
+ return true;
+}
+
static bool bxf_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
{
if (!add_cgpu(bitfury))
@@ -303,7 +318,6 @@ static void *bxf_get_results(void *userdata)
struct cgpu_info *bitfury = userdata;
struct bitfury_info *info = bitfury->device_data;
char threadname[24], buf[512];
- int err, amount, len;
snprintf(threadname, 24, "bxf_recv/%d", bitfury->device_id);
@@ -311,19 +325,16 @@ static void *bxf_get_results(void *userdata)
* to process and gives us a better indicator of the nonce return rate
* and hardware errors. */
sprintf(buf, "target ffffffff\n");
- len = strlen(buf);
- applog(LOG_DEBUG, "%s %d: Sending %s", bitfury->drv->name, bitfury->device_id, buf);
- err = usb_write(bitfury, buf, len, &amount, C_BXF_TARGET);
- if (err || amount != len) {
- applog(LOG_WARNING, "%s %d: Error %d sending work sent %d of %d", bitfury->drv->name,
- bitfury->device_id, err, amount, len);
+ if (!bxf_send_msg(bitfury, buf, C_BXF_TARGET))
goto out;
- }
+
/* Read thread sends the first work item to get the device started
* since it will roll ntime and make work itself from there on. */
bxf_update_work(bitfury, info);
while (likely(!bitfury->shutdown)) {
+ int err, amount;
+
if (unlikely(bitfury->usbinfo.nodev))
break;
@@ -596,20 +607,13 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
}
}
-static void bxf_send_work(struct cgpu_info *bitfury, struct work *work)
+static bool bxf_send_work(struct cgpu_info *bitfury, struct work *work)
{
char buf[512], hexwork[156];
- int err, amount, len;
__bin2hex(hexwork, work->data, 76);
sprintf(buf, "work %s %x\n", hexwork, work->subid);
- len = strlen(buf);
- applog(LOG_DEBUG, "%s %d: Sending %s", bitfury->drv->name, bitfury->device_id, buf);
- err = usb_write(bitfury, buf, len, &amount, C_BXF_WORK);
- if (err || amount != len) {
- applog(LOG_WARNING, "%s %d: Error %d sending work sent %d of %d", bitfury->drv->name,
- bitfury->device_id, err, amount, len);
- }
+ return bxf_send_msg(bitfury, buf, C_BXF_WORK);
}
static void bxf_update_work(struct cgpu_info *bitfury, struct bitfury_info *info)