Browse Source

hashbuster2: Integrate into BFGMiner as a separate driver

Luke Dashjr 12 years ago
parent
commit
1dd2e56469
3 changed files with 63 additions and 35 deletions
  1. 4 0
      Makefile.am
  2. 29 4
      configure.ac
  3. 30 31
      driver-hashbuster2.c

+ 4 - 0
Makefile.am

@@ -275,6 +275,10 @@ if USE_HASHBUSTER
 bfgminer_SOURCES += driver-hashbuster.c
 endif
 
+if USE_HASHBUSTER2
+bfgminer_SOURCES += driver-hashbuster2.c
+endif
+
 endif
 
 if NEED_BFG_LOWL_HID

+ 29 - 4
configure.ac

@@ -769,7 +769,7 @@ AM_CONDITIONAL([HAS_NANOFURY], [test x$nanofury = xyes])
 driverlist="$driverlist hashbuster"
 hashbuster=auto
 AC_ARG_ENABLE([hashbuster],
-	[AC_HELP_STRING([--disable-hashbuster],[Compile support for HashBuster (default enabled)])],
+	[AC_HELP_STRING([--disable-hashbuster],[Compile support for HashBuster Nano (default enabled)])],
 	[hashbuster=$enableval]
 	)
 if test "x$hashbuster" = "xno"; then
@@ -782,22 +782,47 @@ elif test "x$bitfury" = "xyes"; then
 			hashbuster=no
 			hashbuster_enableaction="install hidapi"
 		else
-			AC_MSG_ERROR([Could not find hidapi, required for HashBuster support])
+			AC_MSG_ERROR([Could not find hidapi, required for HashBuster Nano support])
 		fi
 	fi
 elif test "x$hashbuster" = "xyes"; then
-	AC_MSG_ERROR([You explicitly disabled Bitfury and explicitly enabled HashBuster])
+	AC_MSG_ERROR([You explicitly disabled Bitfury and explicitly enabled HashBuster Nano])
 else
 	hashbuster=no
 fi
 if test "x$hashbuster" = "xyes"; then
-	AC_DEFINE([USE_HASHBUSTER], [1], [Defined to 1 if HashBuster support is wanted])
+	AC_DEFINE([USE_HASHBUSTER], [1], [Defined to 1 if HashBuster Nano support is wanted])
 	need_lowl_hid=yes
 	has_asic=yes
 fi
 AM_CONDITIONAL([USE_HASHBUSTER], [test x$hashbuster = xyes])
 
 
+driverlist="$driverlist hashbuster2"
+AC_ARG_ENABLE([hashbuster2],
+	[AC_HELP_STRING([--disable-hashbuster2],[Compile support for HashBuster Micro (default if libusb)])],
+	[hashbuster2=$enableval],
+	[hashbuster2=auto]
+	)
+if test "x$hashbuster2$want_libusb" = xyesno; then
+	AC_MSG_ERROR([You disabled libusb, required for HashBuster Micro support])
+elif test "x$hashbuster2$libusb" = xyesno; then
+	AC_MSG_ERROR([Could not find libusb, required for HashBuster Micro support])
+elif test "x$hashbuster2" = xauto; then
+	hashbuster2="$libusb"
+	if test "x$libusb" = xno; then
+		AC_MSG_WARN([Could not find libusb, required for HashBuster Micro support])
+		hashbuster2_enableaction="install libusb 1.0+"
+	fi
+fi
+if test "x$hashbuster2" = xyes; then
+	AC_DEFINE([USE_HASHBUSTER2], [1], [Defined to 1 if HashBuster Micro support is wanted])
+	need_lowl_usb=yes
+	has_asic=yes
+fi
+AM_CONDITIONAL([USE_HASHBUSTER2], [test x$hashbuster2 = xyes])
+
+
 driverlist="$driverlist metabank"
 metabank=no
 AC_ARG_ENABLE([metabank],

+ 30 - 31
driver-hashbuster2.c

@@ -26,10 +26,10 @@
 
 #define HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER 61
 
-BFG_REGISTER_DRIVER(hashbuster_drv)
+BFG_REGISTER_DRIVER(hashbuster2_drv)
 
 static
-bool hashbuster_io(libusb_device_handle * const h, unsigned char *buf, unsigned char *cmd)
+bool hashbuster2_io(libusb_device_handle * const h, unsigned char *buf, unsigned char *cmd)
 {
 	const uint8_t cmdbyte = *((uint8_t *)cmd);
 	int result;
@@ -57,40 +57,40 @@ bool hashbuster_io(libusb_device_handle * const h, unsigned char *buf, unsigned
 }
 
 static
-bool hashbuster_spi_config(libusb_device_handle * const h, const uint8_t mode, const uint8_t miso, const uint32_t freq)
+bool hashbuster2_spi_config(libusb_device_handle * const h, const uint8_t mode, const uint8_t miso, const uint32_t freq)
 {
 	uint8_t buf[0x40] = {'\x01', '\x01'};
-	if (!hashbuster_io(h, buf, buf))
+	if (!hashbuster2_io(h, buf, buf))
 		return false;
 	return (buf[1] == '\x00');
 }
 
 static
-bool hashbuster_spi_disable(libusb_device_handle * const h)
+bool hashbuster2_spi_disable(libusb_device_handle * const h)
 {
 	uint8_t buf[0x40] = {'\x01', '\x00'};
-	if (!hashbuster_io(h, buf, buf))
+	if (!hashbuster2_io(h, buf, buf))
 		return false;
 	return (buf[1] == '\x00');
 }
 
 static
-bool hashbuster_spi_reset(libusb_device_handle * const h, uint8_t chips)
+bool hashbuster2_spi_reset(libusb_device_handle * const h, uint8_t chips)
 {
 	uint8_t buf[0x40] = {'\x02', '\x00', chips};
-	if (!hashbuster_io(h, buf, buf))
+	if (!hashbuster2_io(h, buf, buf))
 		return false;
 	return (buf[1] == '\x00');
 }
 
 static
-bool hashbuster_spi_transfer(libusb_device_handle * const h, void * const buf, const void * const data, size_t datasz)
+bool hashbuster2_spi_transfer(libusb_device_handle * const h, void * const buf, const void * const data, size_t datasz)
 {
 	if (datasz > HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER)
 		return false;
 	uint8_t cbuf[0x40] = {'\x03', '\x00', datasz};
 	memcpy(&cbuf[3], data, datasz);
-	if (!hashbuster_io(h, cbuf, cbuf))
+	if (!hashbuster2_io(h, cbuf, cbuf))
 		return false;
 	if (cbuf[2] != datasz)
 		return false;
@@ -99,21 +99,21 @@ bool hashbuster_spi_transfer(libusb_device_handle * const h, void * const buf, c
 }
 
 static
-bool hashbuster_spi_txrx(struct spi_port * const port)
+bool hashbuster2_spi_txrx(struct spi_port * const port)
 {
 	libusb_device_handle * const h = port->userp;
 	const uint8_t *wrbuf = spi_gettxbuf(port);
 	uint8_t *rdbuf = spi_getrxbuf(port);
 	size_t bufsz = spi_getbufsz(port);
 	
-	hashbuster_spi_disable(h);
-	hashbuster_spi_reset(h, 0x10);
+	hashbuster2_spi_disable(h);
+	hashbuster2_spi_reset(h, 0x10);
 	
-	hashbuster_spi_config(h, port->mode, 0, port->speed);
+	hashbuster2_spi_config(h, port->mode, 0, port->speed);
 	
 	while (bufsz >= HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER)
 	{
-		if (!hashbuster_spi_transfer(h, rdbuf, wrbuf, HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER))
+		if (!hashbuster2_spi_transfer(h, rdbuf, wrbuf, HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER))
 			return false;
 		rdbuf += HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER;
 		wrbuf += HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER;
@@ -122,7 +122,7 @@ bool hashbuster_spi_txrx(struct spi_port * const port)
 	
 	if (bufsz > 0)
 	{
-		if (!hashbuster_spi_transfer(h, rdbuf, wrbuf, bufsz))
+		if (!hashbuster2_spi_transfer(h, rdbuf, wrbuf, bufsz))
 			return false;
 	}
 	
@@ -130,13 +130,13 @@ bool hashbuster_spi_txrx(struct spi_port * const port)
 }
 
 static
-bool hashbuster_lowl_match(const struct lowlevel_device_info * const info)
+bool hashbuster2_lowl_match(const struct lowlevel_device_info * const info)
 {
 	return lowlevel_match_id(info, &lowl_usb, 0xFA04, 0x000D);
 }
 
 static
-bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
+bool hashbuster2_lowl_probe(const struct lowlevel_device_info * const info)
 {
 	struct cgpu_info *cgpu = NULL, *proc1 = NULL, *prev_cgpu = NULL;
 	struct bitfury_device **devicelist, *bitfury;
@@ -192,9 +192,9 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 			
 			port = malloc(sizeof(*port));
 			port->cgpu = &dummy_cgpu;
-			port->txrx = hashbuster_spi_txrx;
+			port->txrx = hashbuster2_spi_txrx;
 			port->userp=h;
-			port->repr=hashbuster_drv.dname;
+			port->repr = hashbuster2_drv.dname;
 			port->logprio = LOG_DEBUG;
 			port->speed = 100000;
 			port->mode = 0;
@@ -218,12 +218,11 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 				
 				cgpu = malloc(sizeof(*cgpu));
 				*cgpu = (struct cgpu_info){
-					.drv = &hashbuster_drv,
+					.drv = &hashbuster2_drv,
 					.procs = chip_n,
 					.device_data = devicelist,
 					.cutofftemp = 200,
 					.threads = 1,
-					.handle = h,
 					.dev_manufacturer = maybe_strdup(info->manufacturer),
 					.dev_product = maybe_strdup(product),
 					.dev_serial = maybe_strdup(serial),
@@ -235,7 +234,7 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 }
 
 static
-bool hashbuster_init(struct thr_info * const thr)
+bool hashbuster2_init(struct thr_info * const thr)
 {
 	struct cgpu_info * const cgpu = thr->cgpu, *proc;
 	struct spi_port *port;
@@ -266,7 +265,7 @@ bool hashbuster_init(struct thr_info * const thr)
 }
 
 static
-bool hashbuster_get_stats(struct cgpu_info * const cgpu)
+bool hashbuster2_get_stats(struct cgpu_info * const cgpu)
 {
 	struct cgpu_info *proc;
 	if (cgpu != cgpu->device)
@@ -276,7 +275,7 @@ bool hashbuster_get_stats(struct cgpu_info * const cgpu)
 	struct spi_port * const spi = bitfury->spi;
 	libusb_device_handle * const h = spi->userp;
 	uint8_t buf[0x40] = {'\x04'};
-	if (!hashbuster_io(h, buf, buf))
+	if (!hashbuster2_io(h, buf, buf))
 		return false;
 	if (buf[1])
 	{
@@ -286,13 +285,13 @@ bool hashbuster_get_stats(struct cgpu_info * const cgpu)
 	return true;
 }
 
-struct device_drv hashbuster_drv = {
-	.dname = "hashbuster",
+struct device_drv hashbuster2_drv = {
+	.dname = "hashbuster2",
 	.name = "HBR",
-	.lowl_match = hashbuster_lowl_match,
-	.lowl_probe = hashbuster_lowl_probe,
+	.lowl_match = hashbuster2_lowl_match,
+	.lowl_probe = hashbuster2_lowl_probe,
 	
-	.thread_init = hashbuster_init,
+	.thread_init = hashbuster2_init,
 	.thread_disable = bitfury_disable,
 	.thread_enable = bitfury_enable,
 	.thread_shutdown = bitfury_shutdown,
@@ -303,7 +302,7 @@ struct device_drv hashbuster_drv = {
 	.poll = bitfury_do_io,
 	.job_process_results = bitfury_job_process_results,
 	
-	.get_stats = hashbuster_get_stats,
+	.get_stats = hashbuster2_get_stats,
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,