Commit 67c3826b152deab2c8114e6b999d73033abd7e72

Con Kolivas 2013-11-14T10:37:23

Uniquely identify the BF1 and BXF bitfury devices.

diff --git a/driver-bitfury.c b/driver-bitfury.c
index 3331d82..c5b9d64 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -126,26 +126,13 @@ static bool bitfury_reset(struct cgpu_info *bitfury)
 	return true;
 }
 
-static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+static bool bxf_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
 {
-	struct cgpu_info *bitfury;
-	struct bitfury_info *info;
-
-	bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
-
-	if (!usb_init(bitfury, dev, found))
-		goto out;
-	applog(LOG_INFO, "%s %d: Found at %s", bitfury->drv->name,
-	       bitfury->device_id, bitfury->device_path);
-
-	info = calloc(sizeof(struct bitfury_info), 1);
-	if (!info)
-		quit(1, "Failed to calloc info in bitfury_detect_one");
-	bitfury->device_data = info;
-	/* This does not artificially raise hashrate, it simply allows the
-	 * hashrate to adapt quickly on starting. */
-	info->total_nonces = 1;
+	return false;
+}
 
+static bool bf1_detect_one(struct cgpu_info *bitfury, struct bitfury_info *info)
+{
 	if (!bitfury_open(bitfury))
 		goto out_close;
 
@@ -166,15 +153,57 @@ static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_device
 	update_usb_stats(bitfury);
 	applog(LOG_INFO, "%s %d: Successfully initialised %s",
 	       bitfury->drv->name, bitfury->device_id, bitfury->device_path);
+
+	/* This does not artificially raise hashrate, it simply allows the
+	 * hashrate to adapt quickly on starting. */
+	info->total_nonces = 1;
+
 	return true;
 out_close:
 	bitfury_close(bitfury);
-	usb_uninit(bitfury);
-out:
-	bitfury = usb_free_cgpu(bitfury);
 	return false;
 }
 
+static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+{
+	struct cgpu_info *bitfury;
+	struct bitfury_info *info;
+	enum sub_ident ident;
+	bool ret = false;
+
+	bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
+
+	if (!usb_init(bitfury, dev, found))
+		goto out;
+	applog(LOG_INFO, "%s %d: Found at %s", bitfury->drv->name,
+	       bitfury->device_id, bitfury->device_path);
+
+	info = calloc(sizeof(struct bitfury_info), 1);
+	if (!info)
+		quit(1, "Failed to calloc info in bitfury_detect_one");
+	bitfury->device_data = info;
+	ident = usb_ident(bitfury);
+	switch (ident) {
+		case IDENT_BF1:
+			ret = bf1_detect_one(bitfury, info);
+			break;
+		case IDENT_BXF:
+			ret = bxf_detect_one(bitfury, info);
+			break;
+		default:
+			applog(LOG_INFO, "%s %d: Unrecognised bitfury device",
+			       bitfury->drv->name, bitfury->device_id);
+			break;
+	}
+
+	if (!ret) {
+		usb_uninit(bitfury);
+out:
+		bitfury = usb_free_cgpu(bitfury);
+	}
+	return ret;
+}
+
 static void bitfury_detect(bool __maybe_unused hotplug)
 {
 	usb_detect(&bitfury_drv, bitfury_detect_one);
diff --git a/usbutils.c b/usbutils.c
index e29f598..16e383f 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -313,7 +313,7 @@ static struct usb_find_devices find_dev[] = {
 	{
 		.drv = DRIVER_bitfury,
 		.name = "BF1",
-		.ident = IDENT_BFU,
+		.ident = IDENT_BF1,
 		.idVendor = 0x03eb,
 		.idProduct = 0x204b,
 		.config = 1,
@@ -323,6 +323,19 @@ static struct usb_find_devices find_dev[] = {
 		.iProduct = "Bitfury BF1",
 		INTINFO(bfu_ints)
 	},
+	{
+		.drv = DRIVER_bitfury,
+		.name = "BXF",
+		.ident = IDENT_BXF,
+		.idVendor = 0x198c,
+		.idProduct = 0xb1f1,
+		.config = 1,
+		.timeout = BITFURY_TIMEOUT_MS,
+		.latency = LATENCY_UNUSED,
+		//.iManufacturer = something,
+		// .iProduct = something,
+		INTINFO(bfu_ints)
+	},
 #endif
 #ifdef USE_MODMINER
 	{
diff --git a/usbutils.h b/usbutils.h
index 9a22247..3fbc9cb 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -134,24 +134,25 @@ struct usb_intinfo {
 
 enum sub_ident {
 	IDENT_UNK = 0,
+	IDENT_AMU,
+	IDENT_AVA,
 	IDENT_BAJ,
 	IDENT_BAL,
-	IDENT_BAS,
 	IDENT_BAM,
+	IDENT_BAS,
+	IDENT_BBF,
+	IDENT_BF1,
 	IDENT_BFL,
-	IDENT_BFU,
-	IDENT_MMQ,
-	IDENT_AVA,
+	IDENT_BLT,
 	IDENT_BTB,
+	IDENT_BXF,
+	IDENT_CMR1,
+	IDENT_CMR2,
 	IDENT_HFA,
-	IDENT_BBF,
-	IDENT_KLN,
 	IDENT_ICA,
-	IDENT_AMU,
-	IDENT_BLT,
+	IDENT_KLN,
 	IDENT_LLT,
-	IDENT_CMR1,
-	IDENT_CMR2,
+	IDENT_MMQ,
 	IDENT_ZTX
 };