Commit f30804229537ad4f63f385e51aa2818bb90050cb

Con Kolivas 2014-02-23T22:02:47

Reset the hfa hash clock rate to the old one if we find an old instance, only setting the device id in hfa_prepare

diff --git a/driver-hashfast.c b/driver-hashfast.c
index 8015243..827d3a4 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -495,11 +495,10 @@ static bool hfa_send_shutdown(struct cgpu_info *hashfast)
 	return ret;
 }
 
-/* Look for a matching zombie instance and inherit values from it if it exists */
-static bool hfa_inherit_device(struct cgpu_info *hashfast)
+static struct cgpu_info *hfa_old_device(struct cgpu_info *hashfast, struct hashfast_info *info)
 {
-	struct hashfast_info *info = hashfast->device_data, *cinfo = NULL;
 	struct cgpu_info *cgpu, *found = NULL;
+	struct hashfast_info *cinfo = NULL;
 	int i;
 
 	/* If the device doesn't have a serial number, don't try to match it
@@ -526,20 +525,7 @@ static bool hfa_inherit_device(struct cgpu_info *hashfast)
 			break;
 		}
 	}
-	if (!found)
-		return false;
-
-	applog(LOG_INFO, "Found matching zombie device for %s %d at device %d",
-	       hashfast->drv->name, hashfast->device_id, found->device_id);
-	/* Make the new device instance inherit relevant data
-	 * from the old instance. */
-	hashfast->device_id = found->device_id;
-	info->resets = cinfo->resets;
-	if (info->hash_clock_rate != cinfo->hash_clock_rate) {
-		info->hash_clock_rate = cinfo->hash_clock_rate;
-		hfa_reset(hashfast, hashfast->device_data);
-	}
-	return true;
+	return found;
 }
 
 static bool hfa_detect_common(struct cgpu_info *hashfast)
@@ -586,6 +572,24 @@ static bool hfa_detect_common(struct cgpu_info *hashfast)
 		quit(1, "Failed to calloc info works in hfa_detect_common");
 
 	info->cgpu = hashfast;
+	/* Look for a matching zombie instance and inherit values from it if it
+	 * exists. */
+	info->old_cgpu = hfa_old_device(hashfast, info);
+	if (info->old_cgpu) {
+		struct hashfast_info *cinfo = info->old_cgpu->device_data;
+
+		applog(LOG_INFO, "Found matching zombie device for %s %d at device %d",
+		       hashfast->drv->name, hashfast->device_id, info->old_cgpu->device_id);
+		info->resets = cinfo->resets;
+		/* Reset the device with the last hash_clock_rate if it's
+		 * different. */
+		if (info->hash_clock_rate != cinfo->hash_clock_rate) {
+			info->hash_clock_rate = cinfo->hash_clock_rate;
+			ret = hfa_reset(hashfast, hashfast->device_data);
+			if (!ret)
+				return false;
+		}
+	}
 
 	return true;
 }
@@ -1057,8 +1061,9 @@ static bool hfa_prepare(struct thr_info *thr)
 	struct hashfast_info *info = hashfast->device_data;
 	struct timeval now;
 
-	if (info->serial_number)
-		hfa_inherit_device(hashfast);
+	/* Inherit the old device id */
+	if (info->old_cgpu)
+		hashfast->device_id = info->old_cgpu->device_id;
 
 	mutex_init(&info->lock);
 	mutex_init(&info->rlock);
diff --git a/driver-hashfast.h b/driver-hashfast.h
index 140e388..ae1ab89 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -96,6 +96,7 @@ struct hf_die_data {
 
 struct hashfast_info {
 	struct cgpu_info *cgpu;                     // Points back to parent structure
+	struct cgpu_info *old_cgpu  ;               // Points to old structure if hotplugged same device
 	int asic_count;                             // # of chips in the chain
 	int core_count;                             // # of cores per chip
 	int device_type;                            // What sort of device this is