Commit 7c7a324f609876d2193640ee87fbf97a4d06198f

Con Kolivas 2013-12-17T21:53:10

Add support for newer protocol bi*fury commands job, clock and hwerror, setting clock to default 54 value, turning parsing into a compact macro.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 8de63ce..569a69b 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -399,6 +399,47 @@ static void parse_bxf_needwork(struct cgpu_info *bitfury, struct bitfury_info *i
 		bxf_update_work(bitfury, info);
 }
 
+static void parse_bxf_job(struct cgpu_info *bitfury, struct bitfury_info *info, char *buf)
+{
+	int job_id, timestamp, chip;
+
+	if (sscanf(&buf[4], "%x %x %x", &job_id, &timestamp, &chip) != 3) {
+		applog(LOG_INFO, "%s %d: Failed to parse job",
+		       bitfury->drv->name, bitfury->device_id);
+		return;
+	}
+	if (chip > 1) {
+		applog(LOG_INFO, "%s %d: Invalid job chip number %d",
+		       bitfury->drv->name, bitfury->device_id, chip);
+		return;
+	}
+	++info->job[chip];
+}
+
+static void parse_bxf_hwerror(struct cgpu_info *bitfury, struct bitfury_info *info, char *buf)
+{
+	int chip;
+
+	if (!sscanf(&buf[8], "%d", &chip)) {
+		applog(LOG_INFO, "%s %d: Failed to parse hwerror",
+		       bitfury->drv->name, bitfury->device_id);
+		return;
+	}
+	if (chip > 1) {
+		applog(LOG_INFO, "%s %d: Invalid hwerror chip number %d",
+		       bitfury->drv->name, bitfury->device_id, chip);
+		return;
+	}
+	++info->filtered_hw[chip];
+}
+
+#define PARSE_BXF_MSG(MSG) \
+	msg = strstr(buf, #MSG); \
+	if (msg) { \
+		parse_bxf_##MSG(bitfury, info, msg); \
+		continue; \
+	}
+
 static void *bxf_get_results(void *userdata)
 {
 	struct cgpu_info *bitfury = userdata;
@@ -435,21 +476,12 @@ static void *bxf_get_results(void *userdata)
 		if (!err)
 			continue;
 
-		msg = strstr(buf, "submit");
-		if (msg) {
-			parse_bxf_submit(bitfury, info, msg);
-			continue;
-		}
-		msg = strstr(buf, "temp");
-		if (msg) {
-			parse_bxf_temp(bitfury, info, msg);
-			continue;
-		}
-		msg = strstr(buf, "needwork");
-		if (msg) {
-			parse_bxf_needwork(bitfury, info, msg);
-			continue;
-		}
+		PARSE_BXF_MSG(submit);
+		PARSE_BXF_MSG(temp);
+		PARSE_BXF_MSG(needwork);
+		PARSE_BXF_MSG(job);
+		PARSE_BXF_MSG(hwerror);
+
 		applog(LOG_DEBUG, "%s %d: Unrecognised string %s",
 		       bitfury->drv->name, bitfury->device_id, buf);
 	}
@@ -459,10 +491,14 @@ out:
 
 static bool bxf_prepare(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
+	char buf[64];
+
 	mutex_init(&info->lock);
 	if (pthread_create(&info->read_thr, NULL, bxf_get_results, (void *)bitfury))
 		quit(1, "Failed to create bxf read_thr");
-	return true;
+	info->clocks = BXF_DEFAULT_CLOCK;
+	sprintf(buf, "clock %d %d\n", info->clocks, info->clocks);
+	return bxf_send_msg(bitfury, buf, C_BXF_CLOCK);
 }
 
 static bool bitfury_prepare(struct thr_info *thr)
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 851d3cc..9ddb2c6 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -13,6 +13,10 @@
 #include "miner.h"
 #include "usbutils.h"
 
+#define BXF_DEFAULT_CLOCK 54
+#define BXF_MIN_CLOCK 0
+#define BXF_MAX_CLOCK 63
+
 struct bitfury_info {
 	struct cgpu_info *base_cgpu;
 	struct thr_info *thr;
@@ -40,6 +44,9 @@ struct bitfury_info {
 	int ver_minor;
 	int hw_rev;
 	int chips;
+	uint8_t clocks; // There are two but we set them equal
+	int filtered_hw[2]; // Hardware errors we're told about but are filtered
+	int job[2]; // Completed jobs we're told about
 };
 
 #endif /* BITFURY_H */
diff --git a/usbutils.h b/usbutils.h
index 0b883bd..7ab77ac 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -347,6 +347,7 @@ struct cg_usb_info {
 	USB_ADD_COMMAND(C_BXF_VERSION, "BXFVersion") \
 	USB_ADD_COMMAND(C_BXF_MAXROLL, "BXFMaxRoll") \
 	USB_ADD_COMMAND(C_BXF_FLUSH, "BXFFlush") \
+	USB_ADD_COMMAND(C_BXF_CLOCK, "BXFClock") \
 	USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
 	USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
 	USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \