Provide support for 2 chips in libbitfury sendhashdata and enable the 2nd chip on BXM devices.
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
diff --git a/driver-bitfury.c b/driver-bitfury.c
index fcca8dd..5cdf0e6 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -658,12 +658,21 @@ static bool bxm_reset_bitfury(struct cgpu_info *bitfury)
static bool bxm_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);
- return info->spi_txrx(bitfury, info);
+ bool ret;
+ int i;
+
+ for (i = 0; i < 2; 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);
+ ret = info->spi_txrx(bitfury, info);
+ if (!ret)
+ break;
+ }
+ return ret;
}
static bool bxm_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
@@ -1180,30 +1189,41 @@ static int64_t bxf_scan(struct cgpu_info *bitfury, struct bitfury_info *info)
return ret;
}
-static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
- struct bitfury_info *info)
+static void bitfury_check_work(struct thr_info *thr, struct cgpu_info *bitfury,
+ struct bitfury_info *info, int chip_n)
{
- int64_t ret = 0;
-
- if (!info->work) {
- info->work = get_work(thr, thr->id);
+ if (!info->work[chip_n]) {
+ info->work[chip_n] = get_work(thr, thr->id);
if (unlikely(thr->work_restart)) {
- free_work(info->work);
- info->work = NULL;
- return 0;
+ free_work(info->work[chip_n]);
+ info->work[chip_n] = NULL;
+ return;
}
- bitfury_work_to_payload(&info->payload, info->work);
+ bitfury_work_to_payload(&info->payload[chip_n], info->work[chip_n]);
}
- if (!libbitfury_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;
+
+ if (unlikely(bitfury->usbinfo.nodev))
+ return;
+
+ if (!libbitfury_sendHashData(thr, bitfury, info, chip_n))
+ usb_nodev(bitfury);
+
+ if (info->job_switched[chip_n]) {
+ if (likely(info->owork[chip_n]))
+ free_work(info->owork[chip_n]);
+ info->owork[chip_n] = info->work[chip_n];
+ info->work[chip_n] = NULL;
}
+}
+
+static int64_t nf1_scan(struct thr_info *thr, struct cgpu_info *bitfury,
+ struct bitfury_info *info)
+{
+ int64_t ret = 0;
+
+ bitfury_check_work(thr, bitfury, info, 0);
+
ret = bitfury_rate(info);
if (unlikely(bitfury->usbinfo.nodev)) {
@@ -1219,25 +1239,10 @@ static int64_t bxm_scan(struct thr_info *thr, struct cgpu_info *bitfury,
struct bitfury_info *info)
{
int64_t ret = 0;
+ int chip_n;
- 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 (!libbitfury_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;
- }
+ for (chip_n = 0; chip_n < 2; chip_n++)
+ bitfury_check_work(thr, bitfury, info, chip_n);
ret = bitfury_rate(info);
diff --git a/driver-bitfury.h b/driver-bitfury.h
index b8d8ff8..fa8bef9 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -96,12 +96,12 @@ struct bitfury_info {
char spibuf[SPIBUF_SIZE];
unsigned int spibufsz;
int osc6_bits;
- struct bitfury_payload payload;
- unsigned oldbuf[17];
- bool job_switched;
- bool second_run;
- struct work *work;
- struct work *owork;
+ 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];
bool (*spi_txrx)(struct cgpu_info *, struct bitfury_info *info);
};
diff --git a/libbitfury.c b/libbitfury.c
index c6c62d9..1857464 100644
--- a/libbitfury.c
+++ b/libbitfury.c
@@ -337,12 +337,13 @@ bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonc
return false;
}
+/* Currently really only supports 2 chips, so chip_n can only be 0 or 1 */
bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
- struct bitfury_info *info)
+ struct bitfury_info *info, int chip_n)
{
unsigned newbuf[17];
- unsigned *oldbuf = info->oldbuf;
- struct bitfury_payload *p = &(info->payload);
+ unsigned *oldbuf = &info->oldbuf[17 * chip_n];
+ struct bitfury_payload *p = &info->payload[chip_n];
unsigned int localvec[20];
/* Programming next value */
@@ -351,32 +352,32 @@ bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
spi_clear_buf(info);
spi_add_break(info);
+ spi_add_fasync(info, chip_n);
spi_add_data(info, 0x3000, (void*)localvec, 19 * 4);
if (!info->spi_txrx(bitfury, info))
return false;
- memcpy(newbuf, info->spibuf + 4, 17 * 4);
+ memcpy(newbuf, info->spibuf + 4 + chip_n, 17 * 4);
- info->job_switched = newbuf[16] != oldbuf[16];
+ info->job_switched[chip_n] = newbuf[16] != oldbuf[16];
- if (likely(info->second_run)) {
- if (info->job_switched) {
+ if (likely(info->second_run[chip_n])) {
+ if (info->job_switched[chip_n]) {
int i;
for (i = 0; i < 16; i++) {
- if (oldbuf[i] != newbuf[i] && info->owork) {
+ if (oldbuf[i] != newbuf[i] && info->owork[chip_n]) {
uint32_t nonce; //possible nonce
nonce = decnonce(newbuf[i]);
- if (bitfury_checkresults(thr, info->owork, nonce))
+ if (bitfury_checkresults(thr, info->owork[chip_n], nonce))
info->nonces++;
}
}
-
memcpy(oldbuf, newbuf, 17 * 4);
}
} else
- info->second_run = true;
+ info->second_run[chip_n] = true;
cgsleep_ms(BITFURY_REFRESH_DELAY);
diff --git a/libbitfury.h b/libbitfury.h
index 884ee57..7d59573 100644
--- a/libbitfury.h
+++ b/libbitfury.h
@@ -28,6 +28,6 @@ bool mcp_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info);
bool ftdi_spi_txrx(struct cgpu_info *bitfury, struct bitfury_info *info);
bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonce);
bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
- struct bitfury_info *info);
+ struct bitfury_info *info, int chip_n);
#endif /* LIBBITFURY_H */