Commit ff6a4aba80435719d85af131f3185aed9566df5c

Con Kolivas 2014-03-08T12:15:26

Add an hfa-options command line that allows the clockspeed to be chosen per device by name comma separated, with a function that can be expanded with more options in the future.

diff --git a/cgminer.c b/cgminer.c
index e3b401d..a15818e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1114,6 +1114,15 @@ static char *set_bitburner_fury_options(const char *arg)
 }
 #endif
 
+#ifdef USE_HASHFAST
+static char *set_hfa_options(const char *arg)
+{
+	opt_set_charp(arg, &opt_hfa_options);
+
+	return NULL;
+}
+#endif
+
 #ifdef USE_KLONDIKE
 static char *set_klondike_options(const char *arg)
 {
@@ -1365,6 +1374,9 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--hfa-ntime-roll",
 		     opt_set_intval, NULL, &opt_hfa_ntime_roll,
 		     opt_hidden),
+	OPT_WITH_ARG("--hfa-options",
+		     set_hfa_options, NULL, NULL,
+		     "Set hashfast options name:clock (comma separated)"),
 	OPT_WITHOUT_ARG("--hfa-pll-bypass",
 			opt_set_bool, &opt_hfa_pll_bypass,
 			opt_hidden),
diff --git a/driver-hashfast.c b/driver-hashfast.c
index 15bf6d4..9ba1d9a 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -31,6 +31,7 @@ int opt_hfa_fail_drop = 10;
 bool opt_hfa_noshed;
 
 char *opt_hfa_name;
+char *opt_hfa_options;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Support for the CRC's used in header (CRC-8) and packet body (CRC-32)
@@ -627,6 +628,60 @@ static void hfa_set_clock(struct cgpu_info *hashfast, struct hashfast_info *info
 		info->die_data[i].hash_clock = info->base_clock;
 }
 
+/* Look for an op name match and apply any options to its first attempted
+ * init sequence. This function allows any arbitrary number of extra parameters
+ * to be added in the future. */
+static void hfa_check_options(struct hashfast_info *info)
+{
+	char *p, *options, *found = NULL;
+	int maxlen, option = 0;
+
+	if (!opt_hfa_options)
+		return;
+
+	if (!info->op_name)
+		return;
+
+	maxlen = strlen(info->op_name);
+
+	options = strdup(opt_hfa_options);
+	for (p = strtok(options, ","); p; p = strtok(NULL, ",")) {
+		int cmplen = strlen(p);
+
+		if (maxlen < cmplen)
+			cmplen = maxlen;
+		if (cmplen < maxlen)
+			continue;
+		if (!strncmp(info->op_name, p, cmplen)) {
+			found = strdup(p);
+			break;
+		}
+	}
+	free(options);
+	if (!found)
+		return;
+
+	for (p = strtok(found, ":"); p; p = strtok(NULL, ":")) {
+		long lval;
+
+		/* Parse each option in order, leaving room to add more */
+		switch(option++) {
+			default:
+				break;
+			case 1:
+				lval = strtol(p, NULL, 10);
+				if (lval < HFA_CLOCK_MIN || lval > HFA_CLOCK_MAX) {
+					applog(LOG_ERR, "Invalid clock speed %ld set with hashfast option for %s",
+					       lval, info->op_name);
+					break;
+				}
+				info->hash_clock_rate = lval;
+				break;
+		}
+	}
+	free(found);
+}
+
 static bool hfa_detect_common(struct cgpu_info *hashfast)
 {
 	struct hashfast_info *info;
@@ -700,6 +755,7 @@ static bool hfa_detect_common(struct cgpu_info *hashfast)
 		} else {
 			applog(LOG_NOTICE, "%s: Found device with name %s", hashfast->drv->name,
 			       info->op_name);
+			hfa_check_options(info);
 		}
 	}
 
diff --git a/driver-hashfast.h b/driver-hashfast.h
index 1a71f58..d204c83 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -30,10 +30,12 @@ bool opt_hfa_noshed;
 
 char *set_hfa_fan(char *arg);
 char *opt_hfa_name;
+char *opt_hfa_options;
 
 #define HASHFAST_MINER_THREADS 1
 #define HFA_CLOCK_DEFAULT 550
 #define HFA_CLOCK_MIN 125
+#define HFA_CLOCK_MAX 1000
 #define HFA_CLOCK_MAXDIFF 100
 #define HFA_TEMP_OVERHEAT 95
 #define HFA_TEMP_TARGET 88