Scanhash split into separate functions Some adjustment of log reporting
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 13a7a9d..5d4c0bb 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -37,6 +37,8 @@
#include "elist.h"
#include "miner.h"
+#define BITFORCE_SLEEP_US 4500000
+#define BITFORCE_SLEEP_MS (BITFORCE_SLEEP_US/1000)
struct device_api bitforce_api;
@@ -103,7 +105,7 @@ static bool bitforce_detect_one(const char *devpath)
int fdDev = BFopen(devpath);
if (unlikely(fdDev == -1)) {
- applog(LOG_DEBUG, "BitForce Detect: Failed to open %s", devpath);
+ applog(LOG_ERR, "BitForce Detect: Failed to open %s", devpath);
return false;
}
BFwrite(fdDev, "ZGX", 3);
@@ -114,7 +116,7 @@ static bool bitforce_detect_one(const char *devpath)
}
BFclose(fdDev);
if (unlikely(!strstr(pdevbuf, "SHA256"))) {
- applog(LOG_DEBUG, "BitForce Detect: Didn't recognise BitForce on %s", devpath);
+ applog(LOG_ERR, "BitForce Detect: Didn't recognise BitForce on %s", devpath);
return false;
}
@@ -264,27 +266,52 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
return true;
}
-static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
+static bool bitforce_get_temp(struct cgpu_info *bitforce)
{
- struct cgpu_info *bitforce = thr->cgpu;
int fdDev = bitforce->device_fd;
+ char pdevbuf[0x100];
+ char *s;
+ BFwrite(fdDev, "ZLX", 3);
+ BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
+ if (unlikely(!pdevbuf[0])) {
+ applog(LOG_ERR, "Error reading temp from BitForce (ZLX)");
+ return false;
+ }
+ if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) {
+ float temp = strtof(s + 1, NULL);
+ if (temp > 0) {
+ bitforce->temp = temp;
+ if (temp > bitforce->cutofftemp) {
+ applog(LOG_WARNING, "Hit thermal cutoff limit on %s %d, disabling!", bitforce->api->name, bitforce->device_id);
+ bitforce->deven = DEV_RECOVER;
+
+ bitforce->device_last_not_well = time(NULL);
+ bitforce->device_not_well_reason = REASON_DEV_THERMAL_CUTOFF;
+ bitforce->dev_thermal_cutoff_count++;
+ }
+ }
+ }
+ return true;
+}
+
+static bool bitforce_send_work(struct thr_info *thr, struct work *work)
+{
+ struct cgpu_info *bitforce = thr->cgpu;
+ int fdDev = bitforce->device_fd;
char pdevbuf[0x100];
unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>";
- int i;
- char *pnoncebuf;
char *s;
- uint32_t nonce;
BFwrite(fdDev, "ZDX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (ZDX)");
- return 0;
+ return false;
}
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) {
applog(LOG_ERR, "BitForce ZDX reports: %s", pdevbuf);
- return 0;
+ return false;
}
memcpy(ob + 8, work->midstate, 32);
@@ -299,37 +326,27 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
applog(LOG_ERR, "Error reading from BitForce (block data)");
- return 0;
+ return false;
}
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) {
applog(LOG_ERR, "BitForce block data reports: %s", pdevbuf);
- return 0;
+ return false;
}
+ return true;
+}
- BFwrite(fdDev, "ZLX", 3);
- BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
- if (unlikely(!pdevbuf[0])) {
- applog(LOG_ERR, "Error reading from BitForce (ZKX)");
- return 0;
- }
- if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) {
- float temp = strtof(s + 1, NULL);
- if (temp > 0) {
- bitforce->temp = temp;
- if (temp > bitforce->cutofftemp) {
- applog(LOG_WARNING, "Hit thermal cutoff limit on %s %d, disabling!", bitforce->api->name, bitforce->device_id);
- bitforce->deven = DEV_RECOVER;
+static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
+{
+ struct cgpu_info *bitforce = thr->cgpu;
+ int fdDev = bitforce->device_fd;
- bitforce->device_last_not_well = time(NULL);
- bitforce->device_not_well_reason = REASON_DEV_THERMAL_CUTOFF;
- bitforce->dev_thermal_cutoff_count++;
- }
- }
- }
+ char pdevbuf[0x100];
+ char *pnoncebuf;
+ uint32_t nonce;
+ int i;
- usleep(4500000);
- i = 4500;
- while (i < 10000) {
+ i = BITFORCE_SLEEP_MS;
+ while (1) {
BFwrite(fdDev, "ZFX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
@@ -337,23 +354,20 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
return 0;
}
if (pdevbuf[0] != 'B')
- break;
+ break;
usleep(10000);
i += 10;
}
- if (i >= 10000) {
- applog(LOG_DEBUG, "BitForce took longer than 10s");
- return 0;
- }
-
applog(LOG_DEBUG, "BitForce waited %dms until %s\n", i, pdevbuf);
work->blk.nonce = 0xffffffff;
- if (pdevbuf[2] == '-')
- return 0xffffffff;
+ if (pdevbuf[2] == '-')
+ return 0xffffffff; /* No valid nonce found */
+ else if (pdevbuf[0] == 'I')
+ return 1; /* Device idle */
else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) {
- applog(LOG_ERR, "BitForce result reports: %s", pdevbuf);
- return 0;
+ applog(LOG_WARNING, "BitForce result reports: %s", pdevbuf);
+ return 1;
}
pnoncebuf = &pdevbuf[12];
@@ -373,6 +387,21 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
return 0xffffffff;
}
+static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
+{
+ struct cgpu_info *bitforce = thr->cgpu;
+
+ if (!bitforce_send_work(thr, work))
+ return 0;
+
+ if (!bitforce_get_temp(bitforce))
+ return 0;
+
+ usleep(BITFORCE_SLEEP_US);
+
+ return bitforce_get_result(thr, work);
+}
+
struct device_api bitforce_api = {
.dname = "bitforce",
.name = "BFL",