Add bxm scan function and check spi txrx returns only as much as sent.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 4c8c908..3324a1b 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -547,6 +547,13 @@ static bool bxm_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info)
bitfury->device_id, err, amount, info->spibufsz);
return false;
}
+ amount = usb_buffer_size(bitfury);
+ if (amount) {
+ applog(LOG_ERR, "%s %d: SPI RX Extra read buffer size %d", bitfury->drv->name,
+ bitfury->device_id, amount);
+ bxm_empty_buffer(bitfury);
+ return false;
+ }
return true;
}
@@ -1252,6 +1259,89 @@ static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
return ret;
}
+static bool bxm_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
+ struct bitfury_info *info)
+{
+ unsigned *newbuf = info->newbuf;
+ unsigned *oldbuf = info->oldbuf;
+ struct bitfury_payload *p = &(info->payload);
+ struct bitfury_payload *op = &(info->opayload);
+ unsigned int localvec[20];
+
+ /* Programming next value */
+ memcpy(localvec, p, 20 * 4);
+ ms3steps(localvec);
+
+ spi_clear_buf(info);
+ spi_add_break(info);
+ spi_add_data(info, 0x3000, (void*)localvec, 19 * 4);
+ if (!bxm_spi_txrx(bitfury, info))
+ return false;
+
+ memcpy(newbuf, info->spibuf + 4, 17 * 4);
+
+ info->job_switched = newbuf[16] != oldbuf[16];
+
+ if (likely(info->second_run)) {
+ if (info->job_switched) {
+ int i;
+
+ for (i = 0; i < 16; i++) {
+ 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++;
+ }
+ }
+
+ memcpy(op, p, sizeof(struct bitfury_payload));
+ memcpy(oldbuf, newbuf, 17 * 4);
+ }
+ } else
+ info->second_run = true;
+
+ cgsleep_ms(BITFURY_REFRESH_DELAY);
+
+ return true;
+}
+
+static int64_t bxm_scan(struct thr_info *thr, struct cgpu_info *bitfury,
+ struct bitfury_info *info)
+{
+ int64_t ret = 0;
+
+ if (!info->work) {
+ info->work = get_work(thr, thr->id);
+ if (unlikely(thr->work_restart)) {
+ free_work(info->work);
+ info->work = NULL;
+ return 0;
+ }
+ bitfury_work_to_payload(&info->payload, info->work);
+ }
+ if (!bxm_sendHashData(thr, bitfury, info))
+ return -1;
+
+ if (info->job_switched) {
+ if (likely(info->owork))
+ free_work(info->owork);
+ info->owork = info->work;
+ info->work = NULL;
+ }
+
+ 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;
+}
+
static int64_t bitfury_scanwork(struct thr_info *thr)
{
struct cgpu_info *bitfury = thr->cgpu;
@@ -1286,6 +1376,9 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
case IDENT_NF1:
ret = nf1_scan(thr, bitfury, info);
break;
+ case IDENT_BXM:
+ ret = bxm_scan(thr, bitfury, info);
+ break;
default:
ret = 0;
break;