From ce285ba60262a21c4b27b207625d285852d3defd Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 26 Sep 2013 11:46:09 +1000 Subject: [PATCH] Implement basic API stats for BF1 and increase array of results to check for the rare straggling result. --- api.c | 13 ++++++++++++- driver-bitfury.c | 37 ++++++++++++++++++++++++------------- driver-bitfury.h | 5 +++-- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/api.c b/api.c index c60414ff..e86ac7b9 100644 --- a/api.c +++ b/api.c @@ -29,7 +29,7 @@ #include "miner.h" #include "util.h" -#if defined(USE_BFLSC) || defined(USE_AVALON) +#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_BITFURY) #define HAVE_AN_ASIC 1 #endif @@ -176,6 +176,9 @@ static const char *DEVICECODE = "" #ifdef USE_BITFORCE "BFL " #endif +#ifdef USE_BITFURY + "BFU " +#endif #ifdef USE_ICARUS "ICA " #endif @@ -1223,6 +1226,10 @@ static int numascs() #ifdef USE_BFLSC if (devices[i]->drv->drv_id == DRIVER_BFLSC) count++; +#endif +#ifdef USE_BITFURY + if (devices[i]->drv->drv_id == DRIVER_BITFURY) + count++; #endif } rd_unlock(&devices_lock); @@ -1243,6 +1250,10 @@ static int ascdevice(int ascid) #ifdef USE_BFLSC if (devices[i]->drv->drv_id == DRIVER_BFLSC) count++; +#endif +#ifdef USE_BITFURY + if (devices[i]->drv->drv_id == DRIVER_BITFURY) + count++; #endif if (count == (ascid + 1)) goto foundit; diff --git a/driver-bitfury.c b/driver-bitfury.c index f83a0035..2e0b1635 100644 --- a/driver-bitfury.c +++ b/driver-bitfury.c @@ -222,32 +222,32 @@ static int64_t bitfury_scanhash(struct thr_info *thr, struct work *work, usb_read(bitfury, buf, 7, &amount, C_BF1_GETWORK); /* Only happens on startup */ - if (unlikely(!info->prevwork2)) + if (unlikely(!info->prevwork[BF1ARRAY_SIZE])) goto cascade; /* Search for what work the nonce matches in order of likelihood. Last * entry is end of result marker. */ for (i = 0; i < info->tot - 7; i += 7) { uint32_t nonce; + int j; /* Ignore state & switched data in results for now. */ memcpy(&nonce, info->buf + i + 3, 4); nonce = decnonce(nonce); - if (bitfury_checkresults(thr, info->prevwork1, nonce)) { - info->nonces++; - continue; - } - if (bitfury_checkresults(thr, info->prevwork2, nonce)) { - info->nonces++; - continue; + for (j = 0; j < BF1ARRAY_SIZE; j++) { + if (bitfury_checkresults(thr, info->prevwork[j], nonce)) { + info->nonces++; + break; + } } } info->tot = 0; - free_work(info->prevwork2); + free_work(info->prevwork[BF1ARRAY_SIZE]); cascade: - info->prevwork2 = info->prevwork1; - info->prevwork1 = copy_work(work); + for (i = BF1ARRAY_SIZE; i > 0; i--) + info->prevwork[i] = info->prevwork[i - 1]; + info->prevwork[0] = copy_work(work); work->blk.nonce = 0xffffffff; if (info->nonces) { info->nonces--; @@ -256,9 +256,20 @@ cascade: return 0; } -static struct api_data *bitfury_api_stats(struct cgpu_info __maybe_unused *cgpu) +static struct api_data *bitfury_api_stats(struct cgpu_info *cgpu) { - return NULL; + struct bitfury_info *info = cgpu->device_data; + struct api_data *root = NULL; + char serial[16]; + int version; + + version = info->version; + root = api_add_int(root, "Version", &version, true); + root = api_add_string(root, "Product", info->product, false); + sprintf(serial, "%0x", info->serial); + root = api_add_string(root, "Serial", serial, true); + + return root; } static void bitfury_init(struct cgpu_info *bitfury) diff --git a/driver-bitfury.h b/driver-bitfury.h index 72bc2673..4cc1300b 100644 --- a/driver-bitfury.h +++ b/driver-bitfury.h @@ -13,12 +13,13 @@ #include "miner.h" #include "usbutils.h" +#define BF1ARRAY_SIZE 2 + struct bitfury_info { uint8_t version; char product[8]; uint32_t serial; - struct work *prevwork1; - struct work *prevwork2; + struct work *prevwork[BF1ARRAY_SIZE + 1]; char buf[512]; int tot; int nonces;