@ -20,9 +20,13 @@
@@ -20,9 +20,13 @@
# include "fpgautils.h"
# include "miner.h"
# define BITFORCE_SLEEP_US 4500000
# define BITFORCE_SLEEP_MS (BITFORCE_SLEEP_US / 1000)
# define BITFORCE_TIMEOUT_MS 30000
/* @832MH/s wait time is ~4500ms
@ 864 MH / s wait time is ~ 4430 ms
- > @ 896 MH / s wait time will be ~ 4350 ms */
# define BITFORCE_SLEEP_MS 4300
# define BITFORCE_TIMEOUT_MS 15000
# define BITFORCE_CHECK_INTERVAL_MS 10
# define WORK_CHECK_INTERVAL_MS 100
struct device_api bitforce_api ;
@ -44,7 +48,7 @@ static ssize_t BFwrite2(int fd, const void *buf, ssize_t bufLen)
@@ -44,7 +48,7 @@ static ssize_t BFwrite2(int fd, const void *buf, ssize_t bufLen)
# define BFwrite(fd, buf, bufLen) do { \
if ( ( bufLen ) ! = BFwrite2 ( fd , buf , bufLen ) ) { \
applog ( LOG_ERR , " Error writing to BitForce ( " # buf " ) " ) ; \
applog ( LOG_ERR , " BFL: Error writing (" # buf " ) " ) ; \
return 0 ; \
} \
} while ( 0 )
@ -58,18 +62,18 @@ static bool bitforce_detect_one(const char *devpath)
@@ -58,18 +62,18 @@ static bool bitforce_detect_one(const char *devpath)
int fdDev = BFopen ( devpath ) ;
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 ;
}
BFwrite ( fdDev , " ZGX " , 3 ) ;
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading from BitForce (ZGX) " ) ;
applog ( LOG_ERR , " BFL: Error reading (ZGX)" ) ;
return 0 ;
}
BFclose ( fdDev ) ;
if ( unlikely ( ! strstr ( pdevbuf , " SHA256 " ) ) ) {
applog ( LOG_ERR , " BitForce Detect : Didn't recognise BitForce on %s " , devpath ) ;
applog ( LOG_ERR , " BFL : Didn't recognise BitForce on %s " , devpath ) ;
return false ;
}
@ -86,7 +90,7 @@ static bool bitforce_detect_one(const char *devpath)
@@ -86,7 +90,7 @@ static bool bitforce_detect_one(const char *devpath)
bitforce - > name = strdup ( pdevbuf + 7 ) ;
}
mutex_init ( & bitforce - > dev_lock ) ;
mutex_init ( & bitforce - > device_mutex ) ;
return add_cgpu ( bitforce ) ;
}
@ -122,13 +126,13 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
@@ -122,13 +126,13 @@ static bool bitforce_thread_prepare(struct thr_info *thr)
int fdDev = BFopen ( bitforce - > device_path ) ;
if ( unlikely ( - 1 = = fdDev ) ) {
applog ( LOG_ERR , " Failed to open BitForce on %s " , bitforce - > device_path ) ;
applog ( LOG_ERR , " BFL%i: Failed to open %s " , bitforce - > device_id , bitforce - > device_path ) ;
return false ;
}
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 ) ;
get_datestamp ( bitforce - > init , & now ) ;
@ -142,30 +146,33 @@ static bool bitforce_init(struct cgpu_info *bitforce)
@@ -142,30 +146,33 @@ static bool bitforce_init(struct cgpu_info *bitforce)
char pdevbuf [ 0x100 ] ;
char * s ;
applog ( LOG_DEBUG , " BFL%i: Re-initalizing " , bitforce - > device_id ) ;
applog ( LOG_INFO , " BFL%i: Re-initalizing " , bitforce - > device_id ) ;
BFclose ( fdDev ) ;
if ( fdDev ) {
BFclose ( fdDev ) ;
bitforce - > device_fd = 0 ;
}
fdDev = BFopen ( devpath ) ;
if ( unlikely ( fdDev = = - 1 ) ) {
applog ( LOG_ERR , " BitForce init: Failed to open %s " , devpath ) ;
applog ( LOG_ERR , " BFL%i: Failed to open %s " , bitforce - > device_id , devpath ) ;
return false ;
}
bitforce - > device_fd = fdDev ;
mutex_lock ( & bitforce - > dev_lock ) ;
mutex_lock ( & bitforce - > device_mutex ) ;
BFwrite ( fdDev , " ZGX " , 3 ) ;
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading from BitForce (ZGX) " ) ;
applog ( LOG_ERR , " BFL%i: Error reading (ZGX)" , bitforce - > device_id ) ;
return false ;
}
if ( unlikely ( ! strstr ( pdevbuf , " SHA256 " ) ) ) {
applog ( LOG_ERR , " BitForce init : Didn't recognise BitForce on %s " , devpath ) ;
applog ( LOG_ERR , " BFL%i : Didn't recognise BitForce on %s " , bitforce - > device_id , devpath ) ;
return false ;
}
@ -184,13 +191,13 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
@@ -184,13 +191,13 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
char pdevbuf [ 0x100 ] ;
char * s ;
mutex_lock ( & bitforce - > dev_lock ) ;
mutex_lock ( & bitforce - > device_mutex ) ;
BFwrite ( fdDev , " ZLX " , 3 ) ;
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading temp from BitForce (ZLX) " ) ;
applog ( LOG_ERR , " BFL%i: Error reading (ZLX) " , bitforce - > device_id ) ;
return false ;
}
if ( ( ! strncasecmp ( pdevbuf , " TEMP " , 4 ) ) & & ( s = strchr ( pdevbuf + 4 , ' : ' ) ) ) {
@ -198,7 +205,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
@@ -198,7 +205,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
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 ) ;
applog ( LOG_WARNING , " BFL%i: Hit thermal cutoff limit, disabling!" , bitforce - > device_id ) ;
bitforce - > deven = DEV_RECOVER ;
bitforce - > device_last_not_well = time ( NULL ) ;
@ -218,17 +225,22 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
@@ -218,17 +225,22 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
unsigned char ob [ 61 ] = " >>>>>>>>12345678901234567890123456789012123456789012>>>>>>>> " ;
char * s ;
mutex_lock ( & bitforce - > dev_lock ) ;
mutex_lock ( & bitforce - > device_mutex ) ;
BFwrite ( fdDev , " ZDX " , 3 ) ;
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading from BitForce (ZDX) " ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
applog ( LOG_ERR , " BFL%i: Error reading (ZDX)" , bitforce - > device_id ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
return false ;
}
if ( unlikely ( pdevbuf [ 0 ] ! = ' O ' | | pdevbuf [ 1 ] ! = ' K ' ) ) {
applog ( LOG_ERR , " BitForce ZDX reports: %s " , pdevbuf ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
if ( pdevbuf [ 0 ] = = ' B ' ) {
applog ( LOG_WARNING , " BFL%i: Throttling " , bitforce - > device_id ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
return true ;
}
else if ( unlikely ( pdevbuf [ 0 ] ! = ' O ' | | pdevbuf [ 1 ] ! = ' K ' ) ) {
applog ( LOG_ERR , " BFL%i: ZDX reports: %s " , bitforce - > device_id , pdevbuf ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
return false ;
}
memcpy ( ob + 8 , work - > midstate , 32 ) ;
@ -237,17 +249,17 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
@@ -237,17 +249,17 @@ static bool bitforce_send_work(struct thr_info *thr, struct work *work)
BFwrite ( fdDev , ob , 60 ) ;
if ( opt_debug ) {
s = bin2hex ( ob + 8 , 44 ) ;
applog ( LOG_DEBUG , " BitForce block data: %s " , s ) ;
applog ( LOG_DEBUG , " BFL%i: block data: %s " , bitforce - > device_id , s ) ;
free ( s ) ;
}
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading from BitForce (block data) " ) ;
applog ( LOG_ERR , " BFL%i: Error reading (block data)" , bitforce - > device_id ) ;
return false ;
}
if ( unlikely ( pdevbuf [ 0 ] ! = ' O ' | | pdevbuf [ 1 ] ! = ' K ' ) ) {
applog ( LOG_ERR , " BitForce block data reports: %s " , pdevbuf ) ;
applog ( LOG_ERR , " BFL%i: block data reports: %s " , bitforce - > device_id , pdevbuf ) ;
return false ;
}
return true ;
@ -261,41 +273,39 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
@@ -261,41 +273,39 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
char pdevbuf [ 0x100 ] ;
char * pnoncebuf ;
uint32_t nonce ;
int i ;
unsigned int wa it_ms = BITFORCE_SLEEP_MS ;
i = BITFORCE_SLEEP_MS ;
while ( i < BITFORCE_TIMEOUT_MS ) {
mutex_lock ( & bitforce - > dev_lock ) ;
while ( wait_ms < BITFORCE_TIMEOUT_MS ) {
mutex_lock ( & bitforce - > device_mutex ) ;
BFwrite ( fdDev , " ZFX " , 3 ) ;
BFgets ( pdevbuf , sizeof ( pdevbuf ) , fdDev ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
if ( unlikely ( ! pdevbuf [ 0 ] ) ) {
applog ( LOG_ERR , " Error reading from BitForce (ZFX) " ) ;
mutex_unlock ( & bitforce - > dev_lock ) ;
applog ( LOG_ERR , " BFL%i: Error reading (ZFX)" , bitforce - > device_id ) ;
mutex_unlock ( & bitforce - > device_mutex ) ;
return 0 ;
}
if ( pdevbuf [ 0 ] ! = ' B ' )
break ;
usleep ( 10 000 ) ;
i + = 10 ;
usleep ( BITFORCE_CHECK_INTERVAL_MS * 1000 ) ;
wa it_ms + = BITFORCE_CHECK_INTERVAL_MS ;
}
if ( i > = BITFORCE_TIMEOUT_MS ) {
applog ( LOG_ERR , " BitForce took longer than 30s " ) ;
if ( wait_ms > = BITFORCE_TIMEOUT_MS ) {
applog ( LOG_ERR , " BFL%i took longer than 15s " ) ;
bitforce - > device_last_not_well = time ( NULL ) ;
bitforce - > device_not_well_reason = REASON_THREAD_ZERO_HASH ;
bitforce - > thread_zero_hash_count + + ;
return 1 ;
}
applog ( LOG_DEBUG , " BitForce waited %dms until %s \n " , i , pdevbuf ) ;
applog ( LOG_DEBUG , " BFL%i: waited %dms until %s \n " , b itforce - > device_id , wait_ms , pdevbuf ) ;
work - > blk . nonce = 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_WARNING , " BitForce result reports: %s " , pdevbuf ) ;
applog ( LOG_WARNING , " BFL%i: result reports: %s " , bitforce - > device_id , pdevbuf ) ;
return 1 ;
}
@ -319,42 +329,34 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
@@ -319,42 +329,34 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
static void bitforce_shutdown ( struct thr_info * thr )
{
struct cgpu_info * bitforce = thr - > cgpu ;
int fdDev = bitforce - > device_fd ;
BFclose ( fdDev ) ;
BFclose ( bitforce - > device_fd ) ;
bitforce - > device_fd = 0 ;
}
# define CHECK_INTERVAL_MS 200
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 ;
bool dev_enabled = ( bitforce - > deven = = DEV_ENABLED ) ;
static enum dev_enable last_dev_state = DEV_ENABLED ;
int wait_ms = 0 ;
if ( bitforce - > deven = = DEV_DISABLED ) {
bitforce_shutdown ( thr ) ;
return 1 ;
}
// if device has just gone from disabled to enabled, re-initialise it
if ( last_dev_state = = DEV_DISABLED & & dev_enabled )
bitforce_init ( bitforce ) ;
last_dev_state = bitforce - > deven ;
unsigned int wait_ms = 0 ;
if ( ! bitforce_send_work ( thr , work ) )
return 0 ;
while ( wait_ms < BITFORCE_SLEEP_MS ) {
usleep ( CHECK_INTERVAL_MS * 1000 ) ;
wait_ms + = CHECK_INTERVAL_MS ;
usleep ( WORK_CHECK_INTERVAL_MS * 1000 ) ;
wait_ms + = WORK_CHECK_INTERVAL_MS ;
if ( work_restart [ thr - > id ] . restart ) {
applog ( LOG_DEBUG , " BFL%i: New work detected, discarding current job " , bitforce - > device_id ) ;
return 1 ; //we have discard all work; equivilent to 0 hashes done.
applog ( LOG_DEBUG , " BFL%i: Work restart, discarding after %dms " , bitforce - > device_id , wait_ms ) ;
return 1 ; //we have discarded all work; equivilent to 0 hashes done.
}
}
return bitforce_get_result ( thr , work ) ;
}
@ -367,9 +369,11 @@ struct device_api bitforce_api = {
@@ -367,9 +369,11 @@ struct device_api bitforce_api = {
. dname = " bitforce " ,
. name = " BFL " ,
. api_detect = bitforce_detect ,
. reinit_device = bitforce_init ,
. get_statline_before = get_bitforce_statline_before ,
. get_stats = bitforce_get_stats ,
. thread_prepare = bitforce_thread_prepare ,
. scanhash = bitforce_scanhash ,
. thread_shutdown = bitforce_shutdown
. thread_shutdown = bitforce_shutdown ,
. thread_enable = biforce_thread_enable
} ;