Use separate ep for avalon tasks vs avalon reset and do not loop in write indefinitely.
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
diff --git a/driver-avalon.c b/driver-avalon.c
index fbb1668..1cc2722 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -121,23 +121,21 @@ static inline void avalon_create_task(struct avalon_task *at,
memcpy(at->data, work->data + 64, 12);
}
-static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len)
+static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len, int ep)
{
- ssize_t wrote = 0;
+ int err, amount;
- while (len > 0) {
- int amount, err;
+ err = usb_write(avalon, buf, len, &amount, ep);
+ applog(LOG_DEBUG, "%s%i: usb_write got err %d", avalon->drv->name,
+ avalon->device_id, err);
- err = usb_write(avalon, buf + wrote, len, &amount, C_AVALON_TASK);
- applog(LOG_DEBUG, "%s%i: usb_write got err %d",
- avalon->drv->name, avalon->device_id, err);
-
- if (unlikely(err != 0)) {
- applog(LOG_WARNING, "usb_write error on avalon_write");
- return AVA_SEND_ERROR;
- }
- wrote += amount;
- len -= amount;
+ if (unlikely(err != 0)) {
+ applog(LOG_WARNING, "usb_write error on avalon_write");
+ return AVA_SEND_ERROR;
+ }
+ if (amount != len) {
+ applog(LOG_WARNING, "usb_write length mismatch on avalon_write");
+ return AVA_SEND_ERROR;
}
return AVA_SEND_OK;
@@ -152,7 +150,7 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
struct avalon_info *info;
uint64_t delay = 32000000; /* Default 32ms for B19200 */
uint32_t nonce_range;
- int ret, i;
+ int ret, i, ep = C_AVALON_TASK;
if (at->nonce_elf)
nr_len = AVALON_WRITE_SIZE + 4 * at->asic_num;
@@ -197,13 +195,15 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
delay = delay / info->baud;
}
- if (at->reset)
+ if (at->reset) {
+ ep = C_AVALON_RESET;
nr_len = 1;
+ }
if (opt_debug) {
applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
hexdump(buf, nr_len);
}
- ret = avalon_write(avalon, (char *)buf, nr_len);
+ ret = avalon_write(avalon, (char *)buf, nr_len, ep);
p.tv_sec = 0;
p.tv_nsec = (long)delay + 4000000;