Send a shutdown and do a usb_nodev if hfa_reset fails.
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
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 5543aef..b834275 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -369,16 +369,18 @@ static void hfa_choose_opname(struct cgpu_info *hashfast, struct hashfast_info *
hfa_write_opname(hashfast, info);
}
+static bool hfa_send_shutdown(struct cgpu_info *hashfast);
+
static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
{
struct hf_usb_init_header usb_init[2], *hu = usb_init;
struct hf_usb_init_base *db;
struct hf_usb_init_options *ho;
int retries = 0, i;
+ bool ret = false;
char buf[1024];
struct hf_header *h = (struct hf_header *)buf;
uint8_t hcrc;
- bool ret;
/* Hash clock rate in Mhz. Set to opt_hfa_hash_clock if it has not
* been inherited across a restart. */
@@ -409,13 +411,13 @@ static bool hfa_reset(struct cgpu_info *hashfast, struct hashfast_info *info)
hashfast->drv->name, hashfast->device_id);
resend:
if (unlikely(hashfast->usbinfo.nodev))
- return false;
+ goto out;
if (!hfa_clear_readbuf(hashfast))
- return false;
+ goto out;
if (!hfa_send_packet(hashfast, (struct hf_header *)hu, HF_USB_CMD(OP_USB_INIT)))
- return false;
+ goto out;
// Check for the correct response.
// We extend the normal timeout - a complete device initialization, including
@@ -424,7 +426,7 @@ tryagain:
for (i = 0; i < 10; i++) {
ret = hfa_get_header(hashfast, h, &hcrc);
if (unlikely(hashfast->usbinfo.nodev))
- return false;
+ goto out;
if (ret)
break;
}
@@ -432,11 +434,12 @@ tryagain:
if (retries++ < 3)
goto resend;
applog(LOG_WARNING, "%s %d: OP_USB_INIT failed!", hashfast->drv->name, hashfast->device_id);
- return false;
+ goto out;
}
if (h->crc8 != hcrc) {
applog(LOG_WARNING, "%s %d: OP_USB_INIT failed! CRC mismatch", hashfast->drv->name, hashfast->device_id);
- return false;
+ ret = false;
+ goto out;
}
if (h->operation_code != OP_USB_INIT) {
// This can happen if valid packet(s) were in transit *before* the OP_USB_INIT arrived
@@ -446,7 +449,8 @@ tryagain:
hfa_get_data(hashfast, buf, h->data_length);
if (retries++ < 3)
goto tryagain;
- return false;
+ ret = false;
+ goto out;
}
applog(LOG_DEBUG, "%s %d: Good reply to OP_USB_INIT", hashfast->drv->name, hashfast->device_id);
@@ -474,7 +478,8 @@ tryagain:
if (!hfa_get_data(hashfast, (char *)&info->usb_init_base, U32SIZE(info->usb_init_base))) {
applog(LOG_WARNING, "%s %d: OP_USB_INIT failed! Failure to get usb_init_base data",
hashfast->drv->name, hashfast->device_id);
- return false;
+ ret = false;
+ goto out;
}
db = &info->usb_init_base;
applog(LOG_INFO, "%s %d: firmware_rev: %d.%d", hashfast->drv->name, hashfast->device_id,
@@ -494,7 +499,8 @@ tryagain:
if (!hfa_get_data(hashfast, (char *)&info->config_data, U32SIZE(info->config_data))) {
applog(LOG_WARNING, "%s %d: OP_USB_INIT failed! Failure to get config_data",
hashfast->drv->name, hashfast->device_id);
- return false;
+ ret = false;
+ goto out;
}
// Now the core bitmap
@@ -503,7 +509,8 @@ tryagain:
quit(1, "Failed to malloc info core bitmap in hfa_reset");
if (!hfa_get_data(hashfast, (char *)info->core_bitmap, info->core_bitmap_size / 4)) {
applog(LOG_WARNING, "%s %d: OP_USB_INIT failed! Failure to get core_bitmap", hashfast->drv->name, hashfast->device_id);
- return false;
+ ret = false;
+ goto out;
}
// See if the initialization suceeded
@@ -512,21 +519,27 @@ tryagain:
hashfast->drv->name, hashfast->device_id, db->operation_status,
(db->operation_status < sizeof(hf_usb_init_errors)/sizeof(hf_usb_init_errors[0])) ?
hf_usb_init_errors[db->operation_status] : "Unknown error code");
- return false;
+ ret = false;
+ goto out;
}
if (!db->hash_clockrate) {
applog(LOG_INFO, "%s %d: OP_USB_INIT failed! Clockrate reported as zero",
hashfast->drv->name, hashfast->device_id);
- return false;
+ ret = false;
+ goto out;
}
info->num_sequence = db->sequence_modulus;
info->serial_number = db->serial_number;
info->base_clock = db->hash_clockrate;
- hfa_clear_readbuf(hashfast);
-
- return true;
+ ret = hfa_clear_readbuf(hashfast);
+out:
+ if (!ret) {
+ hfa_send_shutdown(hashfast);
+ usb_nodev(hashfast);
+ }
+ return ret;
}
static bool hfa_clear_readbuf(struct cgpu_info *hashfast)