|
|
@ -20,6 +20,11 @@ |
|
|
|
#include "fpgautils.h" |
|
|
|
#include "fpgautils.h" |
|
|
|
#include "miner.h" |
|
|
|
#include "miner.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BITFORCE_SLEEP_MS 3000 |
|
|
|
|
|
|
|
#define BITFORCE_TIMEOUT_MS 10000 |
|
|
|
|
|
|
|
#define BITFORCE_CHECK_INTERVAL_MS 10 |
|
|
|
|
|
|
|
#define WORK_CHECK_INTERVAL_MS 50 |
|
|
|
|
|
|
|
#define MAX_START_DELAY_US 100000 |
|
|
|
|
|
|
|
|
|
|
|
struct device_api bitforce_api; |
|
|
|
struct device_api bitforce_api; |
|
|
|
|
|
|
|
|
|
|
@ -29,71 +34,71 @@ static void BFgets(char *buf, size_t bufLen, int fd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
do |
|
|
|
do |
|
|
|
--bufLen; |
|
|
|
--bufLen; |
|
|
|
while (likely(bufLen && read(fd, buf, 1) && (buf++)[0] != '\n')) |
|
|
|
while (likely(bufLen && read(fd, buf, 1) && (buf++)[0] != '\n')); |
|
|
|
; |
|
|
|
|
|
|
|
buf[0] = '\0'; |
|
|
|
buf[0] = '\0'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static ssize_t BFwrite2(int fd, const void *buf, ssize_t bufLen) |
|
|
|
static ssize_t BFwrite(int fd, const void *buf, ssize_t bufLen) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return write(fd, buf, bufLen); |
|
|
|
if ((bufLen) != write(fd, buf, bufLen)) |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return bufLen; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define BFwrite(fd, buf, bufLen) do { \ |
|
|
|
|
|
|
|
if ((bufLen) != BFwrite2(fd, buf, bufLen)) { \ |
|
|
|
|
|
|
|
applog(LOG_ERR, "Error writing to BitForce (" #buf ")"); \ |
|
|
|
|
|
|
|
return 0; \ |
|
|
|
|
|
|
|
} \ |
|
|
|
|
|
|
|
} while(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BFclose(fd) close(fd) |
|
|
|
#define BFclose(fd) close(fd) |
|
|
|
|
|
|
|
|
|
|
|
static bool bitforce_detect_one(const char *devpath) |
|
|
|
static bool bitforce_detect_one(const char *devpath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char *s; |
|
|
|
int fdDev = BFopen(devpath); |
|
|
|
|
|
|
|
struct cgpu_info *bitforce; |
|
|
|
char pdevbuf[0x100]; |
|
|
|
char pdevbuf[0x100]; |
|
|
|
|
|
|
|
char *s; |
|
|
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BitForce Detect: Attempting to open %s", devpath); |
|
|
|
applog(LOG_DEBUG, "BFL: Attempting to open %s", devpath); |
|
|
|
|
|
|
|
|
|
|
|
int fdDev = BFopen(devpath); |
|
|
|
|
|
|
|
if (unlikely(fdDev == -1)) { |
|
|
|
if (unlikely(fdDev == -1)) { |
|
|
|
applog(LOG_ERR, "BitForce Detect: Failed to open %s", devpath); |
|
|
|
applog(LOG_ERR, "BFL: Failed to open %s", devpath); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BFwrite(fdDev, "ZGX", 3); |
|
|
|
BFwrite(fdDev, "ZGX", 3); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
applog(LOG_ERR, "Error reading from BitForce (ZGX)"); |
|
|
|
applog(LOG_ERR, "BFL: Error reading (ZGX)"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BFclose(fdDev); |
|
|
|
BFclose(fdDev); |
|
|
|
if (unlikely(!strstr(pdevbuf, "SHA256"))) { |
|
|
|
if (unlikely(!strstr(pdevbuf, "SHA256"))) { |
|
|
|
applog(LOG_DEBUG, "BitForce Detect: Didn't recognise BitForce on %s", devpath); |
|
|
|
applog(LOG_ERR, "BFL: Didn't recognise BitForce on %s", devpath); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// We have a real BitForce!
|
|
|
|
// We have a real BitForce!
|
|
|
|
struct cgpu_info *bitforce; |
|
|
|
|
|
|
|
bitforce = calloc(1, sizeof(*bitforce)); |
|
|
|
bitforce = calloc(1, sizeof(*bitforce)); |
|
|
|
bitforce->api = &bitforce_api; |
|
|
|
bitforce->api = &bitforce_api; |
|
|
|
bitforce->device_path = strdup(devpath); |
|
|
|
bitforce->device_path = strdup(devpath); |
|
|
|
bitforce->deven = DEV_ENABLED; |
|
|
|
bitforce->deven = DEV_ENABLED; |
|
|
|
bitforce->threads = 1; |
|
|
|
bitforce->threads = 1; |
|
|
|
if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) |
|
|
|
bitforce->sleep_ms = BITFORCE_SLEEP_MS; |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) { |
|
|
|
s[0] = '\0'; |
|
|
|
s[0] = '\0'; |
|
|
|
bitforce->name = strdup(pdevbuf + 7); |
|
|
|
bitforce->name = strdup(pdevbuf + 7); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_init(&bitforce->device_mutex); |
|
|
|
|
|
|
|
|
|
|
|
return add_cgpu(bitforce); |
|
|
|
return add_cgpu(bitforce); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char bitforce_detect_auto() |
|
|
|
static char bitforce_detect_auto() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return |
|
|
|
return (serial_autodetect_udev (bitforce_detect_one, "BitFORCE*SHA256") ?: |
|
|
|
serial_autodetect_udev (bitforce_detect_one, "BitFORCE*SHA256") ?: |
|
|
|
|
|
|
|
serial_autodetect_devserial(bitforce_detect_one, "BitFORCE_SHA256") ?: |
|
|
|
serial_autodetect_devserial(bitforce_detect_one, "BitFORCE_SHA256") ?: |
|
|
|
0; |
|
|
|
0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void bitforce_detect() |
|
|
|
static void bitforce_detect() |
|
|
@ -104,6 +109,7 @@ static void bitforce_detect() |
|
|
|
static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce) |
|
|
|
static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce) |
|
|
|
{ |
|
|
|
{ |
|
|
|
float gt = bitforce->temp; |
|
|
|
float gt = bitforce->temp; |
|
|
|
|
|
|
|
|
|
|
|
if (gt > 0) |
|
|
|
if (gt > 0) |
|
|
|
tailsprintf(buf, "%5.1fC ", gt); |
|
|
|
tailsprintf(buf, "%5.1fC ", gt); |
|
|
|
else |
|
|
|
else |
|
|
@ -114,79 +120,112 @@ static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce) |
|
|
|
static bool bitforce_thread_prepare(struct thr_info *thr) |
|
|
|
static bool bitforce_thread_prepare(struct thr_info *thr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
int fdDev = BFopen(bitforce->device_path); |
|
|
|
struct timeval now; |
|
|
|
struct timeval now; |
|
|
|
|
|
|
|
|
|
|
|
int fdDev = BFopen(bitforce->device_path); |
|
|
|
if (unlikely(fdDev == -1)) { |
|
|
|
if (unlikely(-1 == fdDev)) { |
|
|
|
applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, bitforce->device_path); |
|
|
|
applog(LOG_ERR, "Failed to open BitForce on %s", bitforce->device_path); |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bitforce->device_fd = fdDev; |
|
|
|
bitforce->device_fd = fdDev; |
|
|
|
|
|
|
|
|
|
|
|
applog(LOG_INFO, "Opened BitForce on %s", bitforce->device_path); |
|
|
|
applog(LOG_INFO, "BFL%i: Opened %s", bitforce->device_id, bitforce->device_path); |
|
|
|
gettimeofday(&now, NULL); |
|
|
|
gettimeofday(&now, NULL); |
|
|
|
get_datestamp(bitforce->init, &now); |
|
|
|
get_datestamp(bitforce->init, &now); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce) |
|
|
|
static void biforce_clear_buffer(struct cgpu_info *bitforce) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
|
|
|
|
char pdevbuf[0x100]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BFL%i: Clearing read buffer", bitforce->device_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
pdevbuf[0] = '\0'; |
|
|
|
|
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
} while (pdevbuf[0]); |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int i, thr_id = thr->id; |
|
|
|
void bitforce_init(struct cgpu_info *bitforce) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char *devpath = bitforce->device_path; |
|
|
|
|
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
char pdevbuf[0x100]; |
|
|
|
char pdevbuf[0x100]; |
|
|
|
unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>"; |
|
|
|
|
|
|
|
struct timeval tdiff; |
|
|
|
|
|
|
|
char *pnoncebuf; |
|
|
|
|
|
|
|
char *s; |
|
|
|
char *s; |
|
|
|
uint32_t nonce; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BFwrite(fdDev, "ZDX", 3); |
|
|
|
applog(LOG_WARNING, "BFL%i: Re-initalizing", bitforce->device_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
biforce_clear_buffer(bitforce); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
if (fdDev) |
|
|
|
|
|
|
|
BFclose(fdDev); |
|
|
|
|
|
|
|
bitforce->device_fd = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fdDev = BFopen(devpath); |
|
|
|
|
|
|
|
if (unlikely(fdDev == -1)) { |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
applog(LOG_ERR, "BFL%i: Failed to open %s", bitforce->device_id, devpath); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BFwrite(fdDev, "ZGX", 3); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
applog(LOG_ERR, "Error reading from BitForce (ZDX)"); |
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
return 0; |
|
|
|
applog(LOG_ERR, "BFL%i: Error reading (ZGX)", bitforce->device_id); |
|
|
|
} |
|
|
|
return; |
|
|
|
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) { |
|
|
|
|
|
|
|
applog(LOG_ERR, "BitForce ZDX reports: %s", pdevbuf); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy(ob + 8, work->midstate, 32); |
|
|
|
if (unlikely(!strstr(pdevbuf, "SHA256"))) { |
|
|
|
memcpy(ob + 8 + 32, work->data + 64, 12); |
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
BFwrite(fdDev, ob, 60); |
|
|
|
applog(LOG_ERR, "BFL%i: Didn't recognise BitForce on %s returned: %s", bitforce->device_id, devpath, pdevbuf); |
|
|
|
if (opt_debug) { |
|
|
|
return; |
|
|
|
s = bin2hex(ob + 8, 44); |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BitForce block data: %s", s); |
|
|
|
|
|
|
|
free(s); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>")))) { |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
s[0] = '\0'; |
|
|
|
applog(LOG_ERR, "Error reading from BitForce (block data)"); |
|
|
|
bitforce->name = strdup(pdevbuf + 7); |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) { |
|
|
|
|
|
|
|
applog(LOG_ERR, "BitForce block data reports: %s", pdevbuf); |
|
|
|
bitforce->device_fd = fdDev; |
|
|
|
return 0; |
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool bitforce_get_temp(struct cgpu_info *bitforce) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
|
|
|
|
char pdevbuf[0x100]; |
|
|
|
|
|
|
|
char *s; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fdDev) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex_lock(&bitforce->device_mutex); |
|
|
|
BFwrite(fdDev, "ZLX", 3); |
|
|
|
BFwrite(fdDev, "ZLX", 3); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
applog(LOG_ERR, "Error reading from BitForce (ZKX)"); |
|
|
|
applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string", bitforce->device_id); |
|
|
|
return 0; |
|
|
|
bitforce->temp = 0; |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) { |
|
|
|
if ((!strncasecmp(pdevbuf, "TEMP", 4)) && (s = strchr(pdevbuf + 4, ':'))) { |
|
|
|
float temp = strtof(s + 1, NULL); |
|
|
|
float temp = strtof(s + 1, NULL); |
|
|
|
|
|
|
|
|
|
|
|
if (temp > 0) { |
|
|
|
if (temp > 0) { |
|
|
|
bitforce->temp = temp; |
|
|
|
bitforce->temp = temp; |
|
|
|
if (temp > bitforce->cutofftemp) { |
|
|
|
if (temp > bitforce->cutofftemp) { |
|
|
|
applog(LOG_WARNING, "Hit thermal cutoff limit on %s %d, disabling!", bitforce->api->name, bitforce->device_id); |
|
|
|
applog(LOG_WARNING, "BFL%i: Hit thermal cutoff limit, disabling!", bitforce->device_id); |
|
|
|
bitforce->deven = DEV_RECOVER; |
|
|
|
bitforce->deven = DEV_RECOVER; |
|
|
|
|
|
|
|
|
|
|
|
bitforce->device_last_not_well = time(NULL); |
|
|
|
bitforce->device_last_not_well = time(NULL); |
|
|
@ -195,46 +234,114 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Initially wait 2/3 of the average cycle time so we can request more
|
|
|
|
static bool bitforce_send_work(struct thr_info *thr, struct work *work) |
|
|
|
* work before full scan is up ~ 3.4 seconds */ |
|
|
|
{ |
|
|
|
tdiff.tv_sec = 3; |
|
|
|
unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>"; |
|
|
|
tdiff.tv_usec = 4000000; |
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
if (!restart_wait(&tdiff)) |
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
return 0; |
|
|
|
char pdevbuf[0x100]; |
|
|
|
queue_request(thr, false); |
|
|
|
char *s; |
|
|
|
i = 3400; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Now wait another second; no bistream should be finished by now */ |
|
|
|
if (!fdDev) |
|
|
|
tdiff.tv_sec = 1; |
|
|
|
return false; |
|
|
|
tdiff.tv_usec = 0; |
|
|
|
re_send: |
|
|
|
if (!restart_wait(&tdiff)) |
|
|
|
mutex_lock(&bitforce->device_mutex); |
|
|
|
return 0; |
|
|
|
BFwrite(fdDev, "ZDX", 3); |
|
|
|
i += 1000; |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
if (!pdevbuf[0] || (pdevbuf[0] == 'B')) { |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
bitforce->wait_ms += WORK_CHECK_INTERVAL_MS; |
|
|
|
|
|
|
|
usleep(WORK_CHECK_INTERVAL_MS * 1000); |
|
|
|
|
|
|
|
goto re_send; |
|
|
|
|
|
|
|
} else if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) { |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
applog(LOG_ERR, "BFL%i: Error: Send work reports: %s", bitforce->device_id, pdevbuf); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Now start looking for results. Stupid polling every 10ms... */ |
|
|
|
memcpy(ob + 8, work->midstate, 32); |
|
|
|
while (42) { |
|
|
|
memcpy(ob + 8 + 32, work->data + 64, 12); |
|
|
|
if (unlikely(work_restart[thr_id].restart)) |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
usleep(10000); |
|
|
|
|
|
|
|
i += 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BFwrite(fdDev, "ZFX", 3); |
|
|
|
BFwrite(fdDev, ob, 60); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opt_debug) { |
|
|
|
|
|
|
|
s = bin2hex(ob + 8, 44); |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BFL%i: block data: %s", bitforce->device_id, s); |
|
|
|
|
|
|
|
free(s); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
if (unlikely(!pdevbuf[0])) { |
|
|
|
applog(LOG_ERR, "Error reading from BitForce (ZFX)"); |
|
|
|
applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string", bitforce->device_id); |
|
|
|
return 0; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (pdevbuf[0] != 'B') |
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(pdevbuf[0] != 'O' || pdevbuf[1] != 'K')) { |
|
|
|
|
|
|
|
applog(LOG_ERR, "BFL%i: Error: Send block data reports: %s", bitforce->device_id, pdevbuf); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
unsigned int delay_time_ms = BITFORCE_CHECK_INTERVAL_MS; |
|
|
|
|
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
int fdDev = bitforce->device_fd; |
|
|
|
|
|
|
|
char pdevbuf[0x100]; |
|
|
|
|
|
|
|
char *pnoncebuf; |
|
|
|
|
|
|
|
uint32_t nonce; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fdDev) |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (bitforce->wait_ms < BITFORCE_TIMEOUT_MS) { |
|
|
|
|
|
|
|
if (unlikely(work_restart[thr->id].restart)) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
mutex_lock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
BFwrite(fdDev, "ZFX", 3); |
|
|
|
|
|
|
|
BFgets(pdevbuf, sizeof(pdevbuf), fdDev); |
|
|
|
|
|
|
|
mutex_unlock(&bitforce->device_mutex); |
|
|
|
|
|
|
|
if (pdevbuf[0] && pdevbuf[0] != 'B') /* BFL does not respond during throttling */ |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
/* if BFL is throttling, no point checking so quickly */ |
|
|
|
|
|
|
|
delay_time_ms = (pdevbuf[0] ? BITFORCE_CHECK_INTERVAL_MS : 2*WORK_CHECK_INTERVAL_MS); |
|
|
|
|
|
|
|
usleep(delay_time_ms * 1000); |
|
|
|
|
|
|
|
bitforce->wait_ms += delay_time_ms; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bitforce->wait_ms >= BITFORCE_TIMEOUT_MS) { |
|
|
|
|
|
|
|
applog(LOG_ERR, "BFL%i: took longer than 10s", bitforce->device_id); |
|
|
|
|
|
|
|
bitforce->device_last_not_well = time(NULL); |
|
|
|
|
|
|
|
bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT; |
|
|
|
|
|
|
|
bitforce->dev_over_heat_count++; |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} else if (pdevbuf[0] == 'N') {/* Hashing complete (NONCE-FOUND or NO-NONCE) */ |
|
|
|
|
|
|
|
/* Simple timing adjustment */ |
|
|
|
|
|
|
|
delay_time_ms = bitforce->sleep_ms; |
|
|
|
|
|
|
|
if (bitforce->wait_ms > (bitforce->sleep_ms + BITFORCE_CHECK_INTERVAL_MS)) |
|
|
|
|
|
|
|
bitforce->sleep_ms += (unsigned int) ((double) (bitforce->wait_ms - bitforce->sleep_ms) / 1.6); |
|
|
|
|
|
|
|
else if (bitforce->wait_ms == bitforce->sleep_ms) |
|
|
|
|
|
|
|
bitforce->sleep_ms -= BITFORCE_CHECK_INTERVAL_MS; |
|
|
|
|
|
|
|
if (delay_time_ms != bitforce->sleep_ms) |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d. Waited: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms); |
|
|
|
} |
|
|
|
} |
|
|
|
applog(LOG_DEBUG, "BitForce waited %dms until %s\n", i, pdevbuf); |
|
|
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf); |
|
|
|
work->blk.nonce = 0xffffffff; |
|
|
|
work->blk.nonce = 0xffffffff; |
|
|
|
if (pdevbuf[2] == '-') |
|
|
|
if (pdevbuf[2] == '-') |
|
|
|
return 0xffffffff; |
|
|
|
return 0xffffffff; /* No valid nonce found */ |
|
|
|
|
|
|
|
else if (pdevbuf[0] == 'I') |
|
|
|
|
|
|
|
return 1; /* Device idle */ |
|
|
|
else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) { |
|
|
|
else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) { |
|
|
|
applog(LOG_ERR, "BitForce result reports: %s", pdevbuf); |
|
|
|
applog(LOG_WARNING, "BFL%i: Error: Get result reports: %s", bitforce->device_id, pdevbuf); |
|
|
|
return 0; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pnoncebuf = &pdevbuf[12]; |
|
|
|
pnoncebuf = &pdevbuf[12]; |
|
|
@ -244,7 +351,6 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6 |
|
|
|
#ifndef __BIG_ENDIAN__ |
|
|
|
#ifndef __BIG_ENDIAN__ |
|
|
|
nonce = swab32(nonce); |
|
|
|
nonce = swab32(nonce); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
submit_nonce(thr, work, nonce); |
|
|
|
submit_nonce(thr, work, nonce); |
|
|
|
if (pnoncebuf[8] != ',') |
|
|
|
if (pnoncebuf[8] != ',') |
|
|
|
break; |
|
|
|
break; |
|
|
@ -254,11 +360,95 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6 |
|
|
|
return 0xffffffff; |
|
|
|
return 0xffffffff; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void bitforce_shutdown(struct thr_info *thr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BFclose(bitforce->device_fd); |
|
|
|
|
|
|
|
bitforce->device_fd = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void biforce_thread_enable(struct thr_info *thr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitforce_init(bitforce); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
unsigned int sleep_time; |
|
|
|
|
|
|
|
struct timeval tdiff; |
|
|
|
|
|
|
|
uint64_t ret; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitforce->wait_ms = 0; |
|
|
|
|
|
|
|
ret = bitforce_send_work(thr, work); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Initially wait 2/3 of the average cycle time so we can request more
|
|
|
|
|
|
|
|
work before full scan is up */ |
|
|
|
|
|
|
|
sleep_time = (2 * bitforce->sleep_ms) / 3; |
|
|
|
|
|
|
|
tdiff.tv_sec = sleep_time / 1000; |
|
|
|
|
|
|
|
tdiff.tv_usec = sleep_time * 1000 - (tdiff.tv_sec * 1000000); |
|
|
|
|
|
|
|
if (!restart_wait(&tdiff)) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitforce->wait_ms += sleep_time; |
|
|
|
|
|
|
|
queue_request(thr, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Now wait athe final 1/3rd; no bitforce should be finished by now */ |
|
|
|
|
|
|
|
sleep_time = bitforce->sleep_ms - sleep_time; |
|
|
|
|
|
|
|
tdiff.tv_sec = sleep_time / 1000; |
|
|
|
|
|
|
|
tdiff.tv_usec = sleep_time * 1000 - (tdiff.tv_sec * 1000000); |
|
|
|
|
|
|
|
if (!restart_wait(&tdiff)) |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bitforce->wait_ms += sleep_time; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ret) |
|
|
|
|
|
|
|
ret = bitforce_get_result(thr, work); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ret) { |
|
|
|
|
|
|
|
ret = 1; |
|
|
|
|
|
|
|
applog(LOG_ERR, "BFL%i: Comms error", bitforce->device_id); |
|
|
|
|
|
|
|
bitforce->device_last_not_well = time(NULL); |
|
|
|
|
|
|
|
bitforce->device_not_well_reason = REASON_DEV_NOSTART; |
|
|
|
|
|
|
|
bitforce->dev_nostart_count++; |
|
|
|
|
|
|
|
/* empty read buffer */ |
|
|
|
|
|
|
|
biforce_clear_buffer(bitforce); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool bitforce_get_stats(struct cgpu_info *bitforce) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return bitforce_get_temp(bitforce); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool bitforce_thread_init(struct thr_info *thr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
struct cgpu_info *bitforce = thr->cgpu; |
|
|
|
|
|
|
|
unsigned int wait; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Pause each new thread a random time between 0-100ms
|
|
|
|
|
|
|
|
so the devices aren't making calls all at the same time. */ |
|
|
|
|
|
|
|
wait = (rand() * MAX_START_DELAY_US)/RAND_MAX; |
|
|
|
|
|
|
|
applog(LOG_DEBUG, "BFL%i: Delaying start by %dms", bitforce->device_id, wait / 1000); |
|
|
|
|
|
|
|
usleep(wait); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct device_api bitforce_api = { |
|
|
|
struct device_api bitforce_api = { |
|
|
|
.dname = "bitforce", |
|
|
|
.dname = "bitforce", |
|
|
|
.name = "BFL", |
|
|
|
.name = "BFL", |
|
|
|
.api_detect = bitforce_detect, |
|
|
|
.api_detect = bitforce_detect, |
|
|
|
|
|
|
|
.reinit_device = bitforce_init, |
|
|
|
.get_statline_before = get_bitforce_statline_before, |
|
|
|
.get_statline_before = get_bitforce_statline_before, |
|
|
|
|
|
|
|
.get_stats = bitforce_get_stats, |
|
|
|
.thread_prepare = bitforce_thread_prepare, |
|
|
|
.thread_prepare = bitforce_thread_prepare, |
|
|
|
|
|
|
|
.thread_init = bitforce_thread_init, |
|
|
|
.scanhash = bitforce_scanhash, |
|
|
|
.scanhash = bitforce_scanhash, |
|
|
|
|
|
|
|
.thread_shutdown = bitforce_shutdown, |
|
|
|
|
|
|
|
.thread_enable = biforce_thread_enable |
|
|
|
}; |
|
|
|
}; |
|
|
|