Handle disconnected hashratio devices
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
diff --git a/driver-hashratio.c b/driver-hashratio.c
index c5a43c1..348335f 100644
--- a/driver-hashratio.c
+++ b/driver-hashratio.c
@@ -324,6 +324,9 @@ static int hashratio_send_pkg(struct cgpu_info *hashratio, const struct hashrati
// hexdump((uint8_t *)buf, nr_len);
// }
+ if (unlikely(hashratio->usbinfo.nodev))
+ return HRTO_SEND_ERROR;
+
err = usb_write(hashratio, (char *)buf, nr_len, &amount, C_HRO_WRITE);
if (err || amount != nr_len) {
applog(LOG_DEBUG, "hashratio: Send(%d)!", amount);
@@ -333,7 +336,19 @@ static int hashratio_send_pkg(struct cgpu_info *hashratio, const struct hashrati
return HRTO_SEND_OK;
}
-static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool)
+static int hashratio_send_pkgs(struct cgpu_info *hashratio, const struct hashratio_pkg *pkg)
+{
+ int ret;
+
+ do {
+ if (unlikely(hashratio->usbinfo.nodev))
+ return -1;
+ ret = hashratio_send_pkg(hashratio, pkg);
+ } while (ret != HRTO_SEND_OK);
+ return 0;
+}
+
+static void hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool)
{
const int merkle_offset = 36;
struct hashratio_pkg pkg;
@@ -373,8 +388,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
memcpy(pkg.data + 24, &tmp, 4);
hashratio_init_pkg(&pkg, HRTO_P_STATIC, 1, 1);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
set_target(target, pool->sdiff);
memcpy(pkg.data, target, 32);
@@ -385,9 +400,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
free(target_str);
}
hashratio_init_pkg(&pkg, HRTO_P_TARGET, 1, 1);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
-
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
applog(LOG_DEBUG, "hashratio: Pool stratum message JOBS_ID: %s",
pool->swork.job_id);
@@ -398,8 +412,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
pkg.data[0] = (crc & 0xff00) >> 8;
pkg.data[1] = crc & 0x00ff;
hashratio_init_pkg(&pkg, HRTO_P_JOB_ID, 1, 1);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
a = pool->coinbase_len / HRTO_P_DATA_LEN;
b = pool->coinbase_len % HRTO_P_DATA_LEN;
@@ -408,8 +422,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
for (i = 0; i < a; i++) {
memcpy(pkg.data, pool->coinbase + i * 32, 32);
hashratio_init_pkg(&pkg, HRTO_P_COINBASE, i + 1, a + (b ? 1 : 0));
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
if (i % 25 == 0) {
cgsleep_ms(2);
}
@@ -418,8 +432,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
memset(pkg.data, 0, HRTO_P_DATA_LEN);
memcpy(pkg.data, pool->coinbase + i * 32, b);
hashratio_init_pkg(&pkg, HRTO_P_COINBASE, i + 1, i + 1);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
}
b = pool->merkles;
@@ -428,8 +442,8 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
memset(pkg.data, 0, HRTO_P_DATA_LEN);
memcpy(pkg.data, pool->swork.merkle_bin[i], 32);
hashratio_init_pkg(&pkg, HRTO_P_MERKLES, i + 1, b);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
}
applog(LOG_DEBUG, "hashratio: Pool stratum message HEADER: 4");
@@ -437,11 +451,10 @@ static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool
memset(pkg.data, 0, HRTO_P_HEADER);
memcpy(pkg.data, pool->header_bin + i * 32, 32);
hashratio_init_pkg(&pkg, HRTO_P_HEADER, i + 1, 4);
- while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
- ;
+ if (hashratio_send_pkgs(hashratio, &pkg))
+ return;
}
- return 0;
}
static int hashratio_get_result(struct thr_info *thr, struct hashratio_ret *ar)
@@ -453,10 +466,8 @@ static int hashratio_get_result(struct thr_info *thr, struct hashratio_ret *ar)
memset(result, 0, HRTO_READ_SIZE);
ret = hashratio_gets(hashratio, result);
- if (ret != HRTO_GETS_OK) {
- applog(LOG_WARNING, "Blah not ok :(");
+ if (ret != HRTO_GETS_OK)
return ret;
- }
// if (opt_debug) {
// applog(LOG_DEBUG, "hashratio: Get(ret = %d):", ret);
@@ -701,8 +712,7 @@ static void hashratio_update_work(struct cgpu_info *hashratio)
/* Package the data */
hashratio_init_pkg(&send_pkg, HRTO_P_SET, 1, 1);
- while (hashratio_send_pkg(hashratio, &send_pkg) != HRTO_SEND_OK)
- ;
+ hashratio_send_pkgs(hashratio, &send_pkg);
}
static int64_t hashratio_scanhash(struct thr_info *thr)
@@ -715,8 +725,11 @@ static int64_t hashratio_scanhash(struct thr_info *thr)
memset(send_pkg.data, 0, HRTO_P_DATA_LEN);
hashratio_init_pkg(&send_pkg, HRTO_P_POLLING, 1, 1);
- while (hashratio_send_pkg(hashratio, &send_pkg) != HRTO_SEND_OK)
- ;
+ if (unlikely(hashratio->usbinfo.nodev || hashratio_send_pkgs(hashratio, &send_pkg))) {
+ applog(LOG_ERR, "%s%d: Device disappeared, shutting down thread",
+ hashratio->drv->name, hashratio->device_id);
+ return -1;
+ }
hashratio_get_result(thr, &ar);
return (int64_t)info->local_work * 64 * 0xffffffff;