Commit e97aa32cb2b5cd22e7c65e99e888065299faf700

Con Kolivas 2014-01-09T15:20:40

Use bitfury_checkresults to avoid hashing results twice in nanofury.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 7305f70..b98c641 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -427,6 +427,8 @@ static bool nf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 		bitfury->drv->name, bitfury->device_id, bitfury->device_path);
 		spi_clear_buf(info);
 	}
+
+	info->total_nonces = 1;
 out:
 	if (!ret)
 		nf1_close(bitfury);
@@ -918,18 +920,8 @@ static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
 		return -1;
 
 	if (info->job_switched) {
-		int i, j;
-		unsigned int *res = info->results;
-		struct work *owork = info->owork;
-
-		i = info->results_n;
-		for (j = i - 1; j >= 0; j--) {
-			if (owork)
-				submit_nonce(thr, owork, res[j]);
-		}
 		info->owork = info->work;
 		info->work = NULL;
-		ret += 0xffffffffull * i;
 	}
 
 	aged = age_queued_work(bitfury, 6.0);
@@ -937,6 +929,15 @@ static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
 		applog(LOG_DEBUG, "%s %d: Aged %d work items", bitfury->drv->name,
 		       bitfury->device_id, aged);
 	}
+
+	ret = bitfury_rate(info);
+
+	if (unlikely(bitfury->usbinfo.nodev)) {
+		applog(LOG_WARNING, "%s %d: Device disappeared, disabling thread",
+		       bitfury->drv->name, bitfury->device_id);
+		ret = -1;
+	}
+
 	return ret;
 }
 
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 9afb5b3..4837764 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -30,7 +30,7 @@ extern int opt_bxf_temp_target;
 #define NF1_PIN_PWR_EN 6
 
 #define SPIBUF_SIZE 16384
-#define BITFURY_REFRESH_DELAY 100
+#define BITFURY_REFRESH_DELAY 1200
 #define BITFURY_DETECT_TRIES 3000 / BITFURY_REFRESH_DELAY
 
 struct bitfury_payload {
diff --git a/libbitfury.c b/libbitfury.c
index 97e784d..9c16b0d 100644
--- a/libbitfury.c
+++ b/libbitfury.c
@@ -83,23 +83,6 @@ static unsigned int atrvec[] = {
 };
 static bool atrvec_set;
 
-static bool rehash(unsigned int *mid32, unsigned char *in)
-{
-	unsigned out32[8];
-	unsigned char *out = (unsigned char *) out32;
-	sha256_ctx ctx;
-
-	memset(&ctx, 0, sizeof( sha256_ctx ));
-	memcpy(ctx.h, mid32, 8 * 4);
-	ctx.tot_len = 64;
-
-	sha256_update(&ctx, in, 16);
-	sha256_final(&ctx, out);
-	sha256(out, 32, out);
-
-	return (out32[7] == 0);
-}
-
 void bitfury_work_to_payload(struct bitfury_payload *p, struct work *work)
 {
 	memcpy(p->midstate, work->midstate, 32);
@@ -360,46 +343,16 @@ bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
 
 	if (second_run && info->job_switched) {
 		int i;
-		int results_num = 0;
-		unsigned int *results = info->results;
 
 		for (i = 0; i < 16; i++) {
-			if (oldbuf[i] != newbuf[i]) {
-				unsigned char in[16];
-				unsigned int *in32 = (unsigned int *)in;
-				unsigned int *mid32;
-				uint32_t nonce, pn; //possible nonce
-				bool found = false;
-
-				mid32 = (unsigned int *)op->midstate;
-				pn = decnonce(newbuf[i]);
-				in32[0] = bswap_32(op->m7);
-				in32[1] = bswap_32(op->ntime);
-				in32[2] = bswap_32(op->nbits);
-
-				nonce = pn - 0x800000;
-				in32[3] = bswap_32(nonce);
-				if (rehash(mid32, in)) {
-					found = true;
-					goto out_found;
-				}
-				nonce = pn;
-				in32[3] = bswap_32(nonce);
-				if (rehash(mid32, in)) {
-					found = true;
-					goto out_found;
-
-				}
-				nonce = pn - 0x400000;
-				in32[3] = bswap_32(nonce);
-				if (rehash(mid32, in))
-					found = true;
-out_found:
-				if (found)
-					results[results_num++] = nonce;
+			if (oldbuf[i] != newbuf[i] && info->owork) {
+				uint32_t nonce; //possible nonce
+
+				nonce = decnonce(newbuf[i]);
+				if (bitfury_checkresults(thr, info->owork, nonce))
+					info->nonces++;
 			}
 		}
-		info->results_n = results_num;
 
 		memcpy(op, p, sizeof(struct bitfury_payload));
 		memcpy(oldbuf, newbuf, 17 * 4);