Improved ztex device detection
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
diff --git a/ztex.c b/ztex.c
index 02f672f..fa68fdc 100644
--- a/ztex.c
+++ b/ztex.c
@@ -30,16 +30,24 @@
#define GOLDEN_BACKLOG 5
-struct device_api ztex_api;
+struct device_api ztex_api, ztex_hotplug_api;
// Forward declarations
static void ztex_disable (struct thr_info* thr);
+static bool ztex_prepare(struct thr_info *thr);
static void ztex_detect()
{
int cnt;
int i;
struct libztex_dev_list **ztex_devices;
+ struct cgpu_info *ztex;
+
+ ztex = calloc(1, sizeof(struct cgpu_info));
+ ztex->api = &ztex_hotplug_api;
+ ztex->threads = 1;
+ devices[total_devices++] = ztex;
+
cnt = libztex_scanDevices(&ztex_devices);
applog(LOG_WARNING, "Found %d ztex board(s)", cnt);
@@ -47,7 +55,6 @@ static void ztex_detect()
for (i=0; i<cnt; i++) {
if (total_devices == MAX_DEVICES)
break;
- struct cgpu_info *ztex;
ztex = calloc(1, sizeof(struct cgpu_info));
ztex->api = &ztex_api;
ztex->device_id = total_devices;
@@ -280,13 +287,17 @@ static bool ztex_prepare(struct thr_info *thr)
static void ztex_shutdown(struct thr_info *thr)
{
- libztex_destroy_device(thr->cgpu->device);
+ if (thr->cgpu->device != NULL) {
+ libztex_destroy_device(thr->cgpu->device);
+ thr->cgpu->device = NULL;
+ }
}
static void ztex_disable (struct thr_info *thr)
{
applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device->repr);
devices[thr->cgpu->device_id]->deven = DEV_DISABLED;
+ ztex_shutdown(thr);
}
struct device_api ztex_api = {