Support variable numbers of chips with NFU and BXM drivers
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 368ea7b..581fa0e 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -389,13 +389,23 @@ static void nfu_close(struct cgpu_info *bitfury)
static bool nfu_reinit(struct cgpu_info *bitfury, struct bitfury_info *info)
{
- spi_clear_buf(info);
- spi_add_break(info);
- spi_set_freq(info);
- spi_send_conf(info);
- spi_send_init(info);
- spi_reset(bitfury, info);
- return info->spi_txrx(bitfury, info);
+ bool ret;
+
+ int i;
+
+ for (i = 0; i < info->chips; i++) {
+ spi_clear_buf(info);
+ spi_add_break(info);
+ spi_add_fasync(info, i);
+ spi_set_freq(info);
+ spi_send_conf(info);
+ spi_send_init(info);
+ spi_reset(bitfury, info);
+ ret = info->spi_txrx(bitfury, info);
+ if (!ret)
+ break;
+ }
+ return ret;
}
static bool nfu_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info *info)
@@ -406,6 +416,16 @@ static bool nfu_set_spi_settings(struct cgpu_info *bitfury, struct bitfury_info
mcp->acsv, mcp->cstdd, mcp->ldbtcsd, mcp->sdbd, mcp->bpst, mcp->spimode);
}
+static void nfu_alloc_arrays(struct bitfury_info *info)
+{
+ info->payload = calloc(sizeof(struct bitfury_payload), info->chips);
+ info->oldbuf = calloc(sizeof(unsigned int) * 17, info->chips);
+ info->job_switched = calloc(sizeof(bool), info->chips);
+ info->second_run = calloc(sizeof(bool), info->chips);
+ info->work = calloc(sizeof(struct work *), info->chips);
+ info->owork = calloc(sizeof(struct work *), info->chips);
+}
+
static bool nfu_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
{
struct mcp_settings *mcp = &info->mcp;
@@ -423,6 +443,7 @@ static bool nfu_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
sprintf(info->product, "NF%u", info->chips);
bitfury->drv->name = info->product;
}
+ nfu_alloc_arrays(info);
info->spi_txrx = &mcp_spi_txrx;
mcp2210_get_gpio_settings(bitfury, mcp);
@@ -531,7 +552,7 @@ static bool nfu_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;
+ info->total_nonces = info->chips;
out:
if (!ret)
nfu_close(bitfury);
@@ -766,6 +787,10 @@ static bool bxm_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
if (!ret)
goto out;
info->osc6_bits = opt_bxm_bits;
+ /* Only have 2 chip devices for now */
+ info->chips = 2;
+ nfu_alloc_arrays(info);
+
ret = bxm_reinit(bitfury, info);
if (!ret)
goto out;
@@ -1336,28 +1361,10 @@ static int64_t nfu_scan(struct thr_info *thr, struct cgpu_info *bitfury,
struct bitfury_info *info)
{
int64_t ret = 0;
+ int i;
- bitfury_check_work(thr, bitfury, info, 0);
-
- 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 bxm_scan(struct thr_info *thr, struct cgpu_info *bitfury,
- struct bitfury_info *info)
-{
- int64_t ret = 0;
- int chip_n;
-
- for (chip_n = 0; chip_n < 2; chip_n++)
- bitfury_check_work(thr, bitfury, info, chip_n);
+ for (i = 0; i < info->chips; i++)
+ bitfury_check_work(thr, bitfury, info, i);
ret = bitfury_rate(info);
@@ -1403,10 +1410,8 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
ret = bxf_scan(bitfury, info);
break;
case IDENT_NFU:
- ret = nfu_scan(thr, bitfury, info);
- break;
case IDENT_BXM:
- ret = bxm_scan(thr, bitfury, info);
+ ret = nfu_scan(thr, bitfury, info);
break;
default:
ret = 0;
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 00db7c1..ccd322a 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -100,12 +100,14 @@ struct bitfury_info {
char spibuf[SPIBUF_SIZE];
unsigned int spibufsz;
int osc6_bits;
- struct bitfury_payload payload[2];
- unsigned oldbuf[17 * 2];
- bool job_switched[2];
- bool second_run[2];
- struct work *work[2];
- struct work *owork[2];
+
+ /* Chip sized arrays */
+ struct bitfury_payload *payload;
+ unsigned int *oldbuf; // 17 vals per chip
+ bool *job_switched;
+ bool *second_run;
+ struct work **work;
+ struct work **owork;
bool (*spi_txrx)(struct cgpu_info *, struct bitfury_info *info);
};