Browse Source

avalon2: Fix build within BFGMiner

Luke Dashjr 12 years ago
parent
commit
f1f60a9e7e
7 changed files with 63 additions and 380 deletions
  1. 2 10
      Makefile.am
  2. 0 14
      api.c
  3. 18 203
      configure.ac
  4. 37 31
      driver-avalon2.c
  5. 1 1
      driver-avalon2.h
  6. 4 38
      miner.c
  7. 1 83
      miner.h

+ 2 - 10
Makefile.am

@@ -273,20 +273,12 @@ if USE_KNC
 bfgminer_SOURCES += driver-knc.c
 bfgminer_SOURCES += driver-knc.c
 endif
 endif
 
 
-<<<<<<< HEAD
 if HAS_KLONDIKE
 if HAS_KLONDIKE
 bfgminer_SOURCES += driver-klondike.c driver-klondike.h driver-hashbusteravalon.c
 bfgminer_SOURCES += driver-klondike.c driver-klondike.h driver-hashbusteravalon.c
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-if HAS_MINION
-cgminer_SOURCES += driver-minion.c
-=======
-if HAS_AVALON2
-cgminer_SOURCES += driver-avalon2.c driver-avalon2.h crc16.c crc.h
 endif
 endif
 
 
-if HAS_MINION
-cgminer_SOURCES += driver-minion.c
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
+if HAS_AVALON2
+bfgminer_SOURCES += driver-avalon2.c driver-avalon2.h crc16.c crc.h
 endif
 endif
 
 
 if HAS_MODMINER
 if HAS_MODMINER

+ 0 - 14
api.c

@@ -33,23 +33,9 @@
 #endif
 #endif
 #include "miner.h"
 #include "miner.h"
 #include "util.h"
 #include "util.h"
-<<<<<<<
 #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 #include "driver-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 #include "driver-opencl.h"
 #include "driver-opencl.h"
 #include "version.h"
 #include "version.h"
-|||||||
-#include "klist.h"
-
-#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_HASHFAST) || defined(USE_BITFURY) || defined(USE_KLONDIKE) || defined(USE_KNC) || defined(USE_BAB) || defined(USE_DRILLBIT) || defined(USE_MINION)
-#define HAVE_AN_ASIC 1
-#endif
-=======
-#include "klist.h"
-
-#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_AVALON2) || defined(USE_HASHFAST) || defined(USE_BITFURY) || defined(USE_KLONDIKE) || defined(USE_KNC) || defined(USE_BAB) || defined(USE_DRILLBIT) || defined(USE_MINION)
-#define HAVE_AN_ASIC 1
-#endif
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 
 
 #define HAVE_AN_FPGA 1
 #define HAVE_AN_FPGA 1
 
 

+ 18 - 203
configure.ac

@@ -556,6 +556,20 @@ fi
 AM_CONDITIONAL([HAS_AVALON], [test x$avalon = xyes])
 AM_CONDITIONAL([HAS_AVALON], [test x$avalon = xyes])
 
 
 
 
+driverlist="$driverlist avalon2"
+AC_ARG_ENABLE([avalon2],
+	[AC_HELP_STRING([--disable-avalon2],[Compile support for Avalon2 (default enabled)])],
+	[avalon2=$enableval],
+	[avalon2=yes]
+	)
+if test "x$avalon2" = xyes; then
+	AC_DEFINE([USE_AVALON2], [1], [Defined to 1 if Avalon2 support is wanted])
+	need_lowl_vcom=yes
+	has_asic=yes
+fi
+AM_CONDITIONAL([HAS_AVALON2], [test x$avalon2 = xyes])
+
+
 driverlist="$driverlist knc"
 driverlist="$driverlist knc"
 AC_ARG_ENABLE([knc],
 AC_ARG_ENABLE([knc],
 	[AC_HELP_STRING([--enable-knc],[Compile support for KnC (default disabled)])],
 	[AC_HELP_STRING([--enable-knc],[Compile support for KnC (default disabled)])],
@@ -642,6 +656,10 @@ else
 fi
 fi
 AM_CONDITIONAL([NEED_BFG_DRIVER_PROXY], [test x$libevent$httpsrv != xnono])
 AM_CONDITIONAL([NEED_BFG_DRIVER_PROXY], [test x$libevent$httpsrv != xnono])
 
 
+driverlist="$driverlist avalon2"
+avalon2="no"
+
+
 driverlist="$driverlist modminer"
 driverlist="$driverlist modminer"
 AC_ARG_ENABLE([modminer],
 AC_ARG_ENABLE([modminer],
 	[AC_HELP_STRING([--disable-modminer],[Compile support for ModMiner (default enabled)])],
 	[AC_HELP_STRING([--disable-modminer],[Compile support for ModMiner (default enabled)])],
@@ -1025,25 +1043,6 @@ if test "x$hashbuster" = "xyes"; then
 fi
 fi
 AM_CONDITIONAL([USE_HASHBUSTER], [test x$hashbuster = xyes])
 AM_CONDITIONAL([USE_HASHBUSTER], [test x$hashbuster = xyes])
 
 
-<<<<<<< HEAD
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-minion="no"
-=======
-avalon2="no"
-
-AC_ARG_ENABLE([avalon2],
-	[AC_HELP_STRING([--enable-avalon2],[Compile support for Avalon2 (default disabled)])],
-	[avalon2=$enableval]
-	)
-if test "x$avalon2" = xyes; then
-	AC_DEFINE([USE_FPGA_SERIAL], [1], [Defined to 1 if serial support required])
-	AC_DEFINE([USE_AVALON2], [1], [Defined to 1 if Avalon2 support is wanted])
-fi
-AM_CONDITIONAL([HAS_AVALON2], [test x$avalon2 = xyes])
-
-
-minion="no"
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 
 
 driverlist="$driverlist hashbusterusb"
 driverlist="$driverlist hashbusterusb"
 AC_ARG_ENABLE([hashbusterusb],
 AC_ARG_ENABLE([hashbusterusb],
@@ -1421,7 +1420,6 @@ if $use_udevrules; then
 	fi
 	fi
 fi
 fi
 
 
-<<<<<<< HEAD
 
 
 AM_CONDITIONAL([NEED_LIBBLKMAKER], [test x$with_system_libblkmaker != xyes])
 AM_CONDITIONAL([NEED_LIBBLKMAKER], [test x$with_system_libblkmaker != xyes])
 AM_CONDITIONAL([NEED_BFG_BINLOADER], [test x$need_binloader = xyes])
 AM_CONDITIONAL([NEED_BFG_BINLOADER], [test x$need_binloader = xyes])
@@ -1436,15 +1434,6 @@ AM_CONDITIONAL([NEED_BFG_LOWL_SPI], [test x$need_lowl_spi = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWLEVEL], [test x$need_lowlevel = xyes])
 AM_CONDITIONAL([NEED_BFG_LOWLEVEL], [test x$need_lowlevel = xyes])
 AM_CONDITIONAL([NEED_BFG_WORK2D], [test x$need_work2d = xyes])
 AM_CONDITIONAL([NEED_BFG_WORK2D], [test x$need_work2d = xyes])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
 AM_CONDITIONAL([HAS_SCRYPT], [test x$scrypt = xyes])
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-AM_CONDITIONAL([NEED_FPGAUTILS], [test x$modminer != xno])
-AM_CONDITIONAL([WANT_USBUTILS], [test x$want_usbutils != xfalse])
-AM_CONDITIONAL([WANT_LIBBITFURY], [test x$want_libbitfury != xfalse])
-=======
-AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon2$modminer != xno])
-AM_CONDITIONAL([WANT_USBUTILS], [test x$want_usbutils != xfalse])
-AM_CONDITIONAL([WANT_LIBBITFURY], [test x$want_libbitfury != xfalse])
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
 AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes])
 AM_CONDITIONAL([HAVE_SENSORS], [test x$with_sensors = xyes])
 AM_CONDITIONAL([HAVE_SENSORS], [test x$with_sensors = xyes])
 AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
 AM_CONDITIONAL([HAVE_CYGWIN], [test x$have_cygwin = xtrue])
@@ -1838,170 +1827,6 @@ AC_CONFIG_FILES([
 	ccan.bfg/Makefile
 	ccan.bfg/Makefile
 	lib/Makefile
 	lib/Makefile
 	])
 	])
-<<<<<<< HEAD
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-AC_OUTPUT
-
-
-echo
-echo
-echo
-echo "------------------------------------------------------------------------"
-echo "$PACKAGE $VERSION"
-echo "------------------------------------------------------------------------"
-echo
-echo
-echo "Configuration Options Summary:"
-echo
-
-if test "x$libcurl" != xno; then
-	echo "  libcurl(GBT+getwork).: Enabled: $LIBCURL_LIBS"
-else
-	echo "  libcurl(GBT+getwork).: Disabled"
-fi
-
-echo "  curses.TUI...........: $cursesmsg"
-
-
-echo
-if test "x$avalon" = xyes; then
-	echo "  Avalon.ASICs.........: Enabled"
-else
-	echo "  Avalon.ASICs.........: Disabled"
-fi
-
-if test "x$minion" = xyes; then
-	echo "  BlackArrowMinion.ASIC: Enabled"
-else
-	echo "  BlackArrowMinion.ASIC: Disabled"
-fi
-
-if test "x$bab" = xyes; then
-	echo "  BlackArrow.ASICs.....: Enabled"
-else
-	echo "  BlackArrow.ASICs.....: Disabled"
-fi
-
-if test "x$bflsc" = xyes; then
-	echo "  BFL.ASICs............: Enabled"
-else
-	echo "  BFL.ASICs............: Disabled"
-fi
-
-if test "x$bitforce" = xyes; then
-	echo "  BitForce.FPGAs.......: Enabled"
-else
-	echo "  BitForce.FPGAs.......: Disabled"
-fi
-
-if test "x$bitfury" = xyes; then
-	echo "  BitFury.ASICs........: Enabled"
-else
-	echo "  BitFury.ASICs........: Disabled"
-fi
-
-if test "x$drillbit" = xyes; then
-	echo "  Drillbit.BitFury.....: Enabled"
-else
-	echo "  Drillbit.BitFury.....: Disabled"
-fi
-
-if test "x$hashfast" = xyes; then
-	echo "  Hashfast.ASICs.......: Enabled"
-else
-	echo "  Hashfast.ASICs.......: Disabled"
-fi
-
-if test "x$icarus" = xyes; then
-	echo "  Icarus.ASICs/FPGAs...: Enabled"
-else
-	echo "  Icarus.ASICs/FPGAs...: Disabled"
-fi
-=======
-AC_OUTPUT
-
-
-echo
-echo
-echo
-echo "------------------------------------------------------------------------"
-echo "$PACKAGE $VERSION"
-echo "------------------------------------------------------------------------"
-echo
-echo
-echo "Configuration Options Summary:"
-echo
-
-if test "x$libcurl" != xno; then
-	echo "  libcurl(GBT+getwork).: Enabled: $LIBCURL_LIBS"
-else
-	echo "  libcurl(GBT+getwork).: Disabled"
-fi
-
-echo "  curses.TUI...........: $cursesmsg"
-
-
-echo
-if test "x$avalon" = xyes; then
-	echo "  Avalon.ASICs.........: Enabled"
-else
-	echo "  Avalon.ASICs.........: Disabled"
-fi
-
-if test "x$avalon2" = xyes; then
-	echo "  Avalon2.ASICs.........: Enabled"
-else
-	echo "  Avalon2.ASICs.........: Disabled"
-fi
-
-if test "x$minion" = xyes; then
-	echo "  BlackArrowMinion.ASIC: Enabled"
-else
-	echo "  BlackArrowMinion.ASIC: Disabled"
-fi
-
-if test "x$bab" = xyes; then
-	echo "  BlackArrow.ASICs.....: Enabled"
-else
-	echo "  BlackArrow.ASICs.....: Disabled"
-fi
-
-if test "x$bflsc" = xyes; then
-	echo "  BFL.ASICs............: Enabled"
-else
-	echo "  BFL.ASICs............: Disabled"
-fi
-
-if test "x$bitforce" = xyes; then
-	echo "  BitForce.FPGAs.......: Enabled"
-else
-	echo "  BitForce.FPGAs.......: Disabled"
-fi
-
-if test "x$bitfury" = xyes; then
-	echo "  BitFury.ASICs........: Enabled"
-else
-	echo "  BitFury.ASICs........: Disabled"
-fi
-
-if test "x$drillbit" = xyes; then
-	echo "  Drillbit.BitFury.....: Enabled"
-else
-	echo "  Drillbit.BitFury.....: Disabled"
-fi
-
-if test "x$hashfast" = xyes; then
-	echo "  Hashfast.ASICs.......: Enabled"
-else
-	echo "  Hashfast.ASICs.......: Disabled"
-fi
-
-if test "x$icarus" = xyes; then
-	echo "  Icarus.ASICs/FPGAs...: Enabled"
-else
-	echo "  Icarus.ASICs/FPGAs...: Disabled"
-fi
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 
 
 if $use_udevrules; then
 if $use_udevrules; then
 	AC_CONFIG_FILES([70-bfgminer.rules])
 	AC_CONFIG_FILES([70-bfgminer.rules])
@@ -2010,20 +1835,10 @@ fi
 AC_OUTPUT
 AC_OUTPUT
 
 
 
 
-<<<<<<< HEAD
 wordfilter ()
 wordfilter ()
 {
 {
   echo "$1" | sed 's/ \+/ /g;s/^ *//;s/ *$//'
   echo "$1" | sed 's/ \+/ /g;s/^ *//;s/ *$//'
 }
 }
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-if test "x$avalon$bab$bflsc$bitforce$bitfury$hashfast$icarus$klondike$knc$modminer$drillbit$minion" = xnononononononononononono; then
-	AC_MSG_ERROR([No mining configured in])
-fi
-=======
-if test "x$avalon$avalon2$bab$bflsc$bitforce$bitfury$hashfast$icarus$klondike$knc$modminer$drillbit$minion" = xnononononononononononono; then
-	AC_MSG_ERROR([No mining configured in])
-fi
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 
 
 echo
 echo
 echo "------------------------------------------------------------------------"
 echo "------------------------------------------------------------------------"

+ 37 - 31
driver-avalon2.c

@@ -32,16 +32,18 @@
   #include <io.h>
   #include <io.h>
 #endif
 #endif
 
 
-#include "elist.h"
+#include <utlist.h>
+
 #include "miner.h"
 #include "miner.h"
-#include "fpgautils.h"
 #include "driver-avalon2.h"
 #include "driver-avalon2.h"
 #include "crc.h"
 #include "crc.h"
-#include "hexdump.c"
+#include "lowl-vcom.h"
 
 
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
 #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
 ASSERT1(sizeof(uint32_t) == 4);
 ASSERT1(sizeof(uint32_t) == 4);
 
 
+BFG_REGISTER_DRIVER(avalon2_drv)
+
 int opt_avalon2_freq_min = AVA2_DEFAULT_FREQUENCY;
 int opt_avalon2_freq_min = AVA2_DEFAULT_FREQUENCY;
 int opt_avalon2_freq_max = AVA2_DEFAULT_FREQUENCY_MAX;
 int opt_avalon2_freq_max = AVA2_DEFAULT_FREQUENCY_MAX;
 
 
@@ -372,28 +374,28 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 
 
 	/* Send out the first stratum message STATIC */
 	/* Send out the first stratum message STATIC */
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message STATIC: %ld, %d, %d, %d, %d",
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message STATIC: %ld, %d, %d, %d, %d",
-	       pool->swork.cb_len,
-	       pool->nonce2_offset,
-	       pool->n2size,
-	       pool->merkle_offset,
+	       bytes_len(&pool->swork.coinbase),
+	       pool->swork.nonce2_offset,
+	       pool->swork.n2size,
+	       36,
 	       pool->swork.merkles);
 	       pool->swork.merkles);
 	memset(pkg.data, 0, AVA2_P_DATA_LEN);
 	memset(pkg.data, 0, AVA2_P_DATA_LEN);
-	tmp = be32toh(pool->swork.cb_len);
+	tmp = be32toh(bytes_len(&pool->swork.coinbase));
 	memcpy(pkg.data, &tmp, 4);
 	memcpy(pkg.data, &tmp, 4);
 
 
-	tmp = be32toh(pool->nonce2_offset);
+	tmp = be32toh(pool->swork.nonce2_offset);
 	memcpy(pkg.data + 4, &tmp, 4);
 	memcpy(pkg.data + 4, &tmp, 4);
 
 
-	tmp = be32toh(pool->n2size);
+	tmp = be32toh(pool->swork.n2size);
 	memcpy(pkg.data + 8, &tmp, 4);
 	memcpy(pkg.data + 8, &tmp, 4);
 
 
-	tmp = be32toh(pool->merkle_offset);
+	tmp = be32toh(36);
 	memcpy(pkg.data + 12, &tmp, 4);
 	memcpy(pkg.data + 12, &tmp, 4);
 
 
 	tmp = be32toh(pool->swork.merkles);
 	tmp = be32toh(pool->swork.merkles);
 	memcpy(pkg.data + 16, &tmp, 4);
 	memcpy(pkg.data + 16, &tmp, 4);
 
 
-	tmp = be32toh((int)pool->swork.diff);
+	tmp = be32toh((int)pdiff_to_bdiff(target_diff(pool->swork.target)));
 	memcpy(pkg.data + 20, &tmp, 4);
 	memcpy(pkg.data + 20, &tmp, 4);
 
 
 	tmp = be32toh((int)pool->pool_no);
 	tmp = be32toh((int)pool->pool_no);
@@ -403,13 +405,12 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		;
 		;
 
 
-	set_target(target, pool->swork.diff);
+	memcpy(target, pool->swork.target, sizeof(target));
 	memcpy(pkg.data, target, 32);
 	memcpy(pkg.data, target, 32);
 	if (opt_debug) {
 	if (opt_debug) {
-		char *target_str;
-		target_str = bin2hex(target, 32);
+		char target_str[(32 * 2) + 1];
+		bin2hex(target_str, target, 32);
 		applog(LOG_DEBUG, "Avalon2: Pool stratum target: %s", target_str);
 		applog(LOG_DEBUG, "Avalon2: Pool stratum target: %s", target_str);
-		free(target_str);
 	}
 	}
 	avalon2_init_pkg(&pkg, AVA2_P_TARGET, 1, 1);
 	avalon2_init_pkg(&pkg, AVA2_P_TARGET, 1, 1);
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
@@ -429,18 +430,18 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 	while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		;
 		;
 
 
-	a = pool->swork.cb_len / AVA2_P_DATA_LEN;
-	b = pool->swork.cb_len % AVA2_P_DATA_LEN;
+	a = bytes_len(&pool->swork.coinbase) / AVA2_P_DATA_LEN;
+	b = bytes_len(&pool->swork.coinbase) % AVA2_P_DATA_LEN;
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message COINBASE: %d %d", a, b);
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message COINBASE: %d %d", a, b);
 	for (i = 0; i < a; i++) {
 	for (i = 0; i < a; i++) {
-		memcpy(pkg.data, pool->coinbase + i * 32, 32);
+		memcpy(pkg.data, bytes_buf(&pool->swork.coinbase) + i * 32, 32);
 		avalon2_init_pkg(&pkg, AVA2_P_COINBASE, i + 1, a + (b ? 1 : 0));
 		avalon2_init_pkg(&pkg, AVA2_P_COINBASE, i + 1, a + (b ? 1 : 0));
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 			;
 			;
 	}
 	}
 	if (b) {
 	if (b) {
 		memset(pkg.data, 0, AVA2_P_DATA_LEN);
 		memset(pkg.data, 0, AVA2_P_DATA_LEN);
-		memcpy(pkg.data, pool->coinbase + i * 32, b);
+		memcpy(pkg.data, bytes_buf(&pool->swork.coinbase) + i * 32, b);
 		avalon2_init_pkg(&pkg, AVA2_P_COINBASE, i + 1, i + 1);
 		avalon2_init_pkg(&pkg, AVA2_P_COINBASE, i + 1, i + 1);
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 			;
 			;
@@ -450,16 +451,22 @@ static int avalon2_stratum_pkgs(int fd, struct pool *pool, struct thr_info *thr)
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message MERKLES: %d", b);
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message MERKLES: %d", b);
 	for (i = 0; i < b; i++) {
 	for (i = 0; i < b; i++) {
 		memset(pkg.data, 0, AVA2_P_DATA_LEN);
 		memset(pkg.data, 0, AVA2_P_DATA_LEN);
-		memcpy(pkg.data, pool->swork.merkle_bin[i], 32);
+		memcpy(pkg.data, &bytes_buf(&pool->swork.merkle_bin)[0x20 * i], 32);
 		avalon2_init_pkg(&pkg, AVA2_P_MERKLES, i + 1, b);
 		avalon2_init_pkg(&pkg, AVA2_P_MERKLES, i + 1, b);
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 			;
 			;
 	}
 	}
 
 
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message HEADER: 4");
 	applog(LOG_DEBUG, "Avalon2: Pool stratum message HEADER: 4");
+	uint8_t header_bin[0x80];
+	memcpy(&header_bin[0], pool->swork.header1, 36);
+	*((uint32_t*)&header_bin[68]) = htobe32(pool->swork.ntime);
+	memcpy(&header_bin[72], pool->swork.diffbits, 4);
+	memset(&header_bin[76], 0, 4);  // nonce
+	memcpy(&header_bin[80], bfg_workpadding_bin, 48);
 	for (i = 0; i < 4; i++) {
 	for (i = 0; i < 4; i++) {
 		memset(pkg.data, 0, AVA2_P_HEADER);
 		memset(pkg.data, 0, AVA2_P_HEADER);
-		memcpy(pkg.data, pool->header_bin + i * 32, 32);
+		memcpy(pkg.data, header_bin + i * 32, 32);
 		avalon2_init_pkg(&pkg, AVA2_P_HEADER, i + 1, 4);
 		avalon2_init_pkg(&pkg, AVA2_P_HEADER, i + 1, 4);
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 		while (avalon2_send_pkg(fd, &pkg, thr) != AVA2_SEND_OK)
 			;
 			;
@@ -581,7 +588,7 @@ static bool avalon2_detect_one(const char *devpath)
 
 
 static inline void avalon2_detect()
 static inline void avalon2_detect()
 {
 {
-	serial_detect(&avalon2_drv, avalon2_detect_one);
+	generic_detect(&avalon2_drv, avalon2_detect_one, NULL, 0);
 }
 }
 
 
 static void avalon2_init(struct cgpu_info *avalon2)
 static void avalon2_init(struct cgpu_info *avalon2)
@@ -655,27 +662,27 @@ static int64_t avalon2_scanhash(struct thr_info *thr)
 	uint32_t tmp, range, start;
 	uint32_t tmp, range, start;
 	int i;
 	int i;
 
 
-	if (thr->work_restart || thr->work_update ||
+	if (thr->work_restart || thr->work_restart ||
 	    info->first) {
 	    info->first) {
 		info->new_stratum = true;
 		info->new_stratum = true;
 		applog(LOG_DEBUG, "Avalon2: New stratum: restart: %d, update: %d, first: %d",
 		applog(LOG_DEBUG, "Avalon2: New stratum: restart: %d, update: %d, first: %d",
-		       thr->work_restart, thr->work_update, info->first);
-		thr->work_update = false;
+		       thr->work_restart, thr->work_restart, info->first);
+		thr->work_restart = false;
 		thr->work_restart = false;
 		thr->work_restart = false;
 		if (unlikely(info->first))
 		if (unlikely(info->first))
 			info->first = false;
 			info->first = false;
 
 
-		get_work(thr, thr->id); /* Make sure pool is ready */
+		get_work(thr); /* Make sure pool is ready */
 
 
 		pool = current_pool();
 		pool = current_pool();
 		if (!pool->has_stratum)
 		if (!pool->has_stratum)
 			quit(1, "Avalon2: Miner Manager have to use stratum pool");
 			quit(1, "Avalon2: Miner Manager have to use stratum pool");
-		if (pool->swork.cb_len > AVA2_P_COINBASE_SIZE)
+		if (bytes_len(&pool->swork.coinbase) > AVA2_P_COINBASE_SIZE)
 			quit(1, "Avalon2: Miner Manager pool coinbase length have to less then %d", AVA2_P_COINBASE_SIZE);
 			quit(1, "Avalon2: Miner Manager pool coinbase length have to less then %d", AVA2_P_COINBASE_SIZE);
 		if (pool->swork.merkles > AVA2_P_MERKLES_COUNT)
 		if (pool->swork.merkles > AVA2_P_MERKLES_COUNT)
 			quit(1, "Avalon2: Miner Manager merkles have to less then %d", AVA2_P_MERKLES_COUNT);
 			quit(1, "Avalon2: Miner Manager merkles have to less then %d", AVA2_P_MERKLES_COUNT);
 
 
-		info->diff = (int)pool->swork.diff - 1;
+		info->diff = (int)pdiff_to_bdiff(target_diff(pool->swork.target)) - 1;
 		info->pool_no = pool->pool_no;
 		info->pool_no = pool->pool_no;
 
 
 		cg_wlock(&pool->data_lock);
 		cg_wlock(&pool->data_lock);
@@ -787,14 +794,13 @@ static void avalon2_shutdown(struct thr_info *thr)
 }
 }
 
 
 struct device_drv avalon2_drv = {
 struct device_drv avalon2_drv = {
-	.drv_id = DRIVER_avalon2,
 	.dname = "avalon2",
 	.dname = "avalon2",
 	.name = "AV2",
 	.name = "AV2",
 	.get_api_stats = avalon2_api_stats,
 	.get_api_stats = avalon2_api_stats,
 	.drv_detect = avalon2_detect,
 	.drv_detect = avalon2_detect,
 	.reinit_device = avalon2_init,
 	.reinit_device = avalon2_init,
 	.thread_prepare = avalon2_prepare,
 	.thread_prepare = avalon2_prepare,
-	.hash_work = hash_driver_work,
+	.minerloop = hash_driver_work,
 	.scanwork = avalon2_scanhash,
 	.scanwork = avalon2_scanhash,
 	.thread_shutdown = avalon2_shutdown,
 	.thread_shutdown = avalon2_shutdown,
 };
 };

+ 1 - 1
driver-avalon2.h

@@ -11,8 +11,8 @@
 #ifndef _AVALON2_H_
 #ifndef _AVALON2_H_
 #define _AVALON2_H_
 #define _AVALON2_H_
 
 
+#include "lowl-vcom.h"
 #include "util.h"
 #include "util.h"
-#include "fpgautils.h"
 
 
 #ifdef USE_AVALON2
 #ifdef USE_AVALON2
 
 

+ 4 - 38
miner.c

@@ -86,20 +86,10 @@
 #include "driver-avalon.h"
 #include "driver-avalon.h"
 #endif
 #endif
 
 
-<<<<<<<
-|||||||
-#ifdef USE_BFLSC
-#include "driver-bflsc.h"
-#endif
-=======
 #ifdef USE_AVALON2
 #ifdef USE_AVALON2
 #include "driver-avalon2.h"
 #include "driver-avalon2.h"
 #endif
 #endif
 
 
-#ifdef USE_BFLSC
-#include "driver-bflsc.h"
-#endif
->>>>>>>
 #ifdef HAVE_BFG_LOWLEVEL
 #ifdef HAVE_BFG_LOWLEVEL
 #include "lowlevel.h"
 #include "lowlevel.h"
 #endif
 #endif
@@ -114,15 +104,9 @@
 #include "scrypt.h"
 #include "scrypt.h"
 #endif
 #endif
 
 
-<<<<<<<
 #include "version.h"
 #include "version.h"
 
 
-#if defined(USE_AVALON) || defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) || defined(USE_NANOFURY) || defined(USE_X6500) || defined(USE_ZTEX)
-|||||||
-#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER)
-=======
-#if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_AVALON2) || defined(USE_MODMINER)
->>>>>>>
+#if defined(USE_AVALON) || defined(USE_AVALON2) || defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_MODMINER) || defined(USE_NANOFURY) || defined(USE_X6500) || defined(USE_ZTEX)
 #	define USE_FPGA
 #	define USE_FPGA
 #endif
 #endif
 
 
@@ -2795,7 +2779,8 @@ void free_work(struct work *work)
 	free(work);
 	free(work);
 }
 }
 
 
-static const char *workpadding_bin = "\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\x02\0\0";
+const char *bfg_workpadding_bin = "\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\x02\0\0";
+#define workpadding_bin bfg_workpadding_bin
 
 
 // Must only be called with ch_lock held!
 // Must only be called with ch_lock held!
 static
 static
@@ -3280,18 +3265,7 @@ int bfg_wresize(WINDOW *win, int lines, int columns)
 #else
 #else
 #	define bfg_wresize wresize
 #	define bfg_wresize wresize
 #endif
 #endif
-<<<<<<<
 
 
-|||||||
-#ifdef USE_BFLSC
-		"bflsc "
-=======
-#ifdef USE_AVALON2
-		"avalon2 "
-#endif
-#ifdef USE_BFLSC
-		"bflsc "
->>>>>>>
 #endif
 #endif
 
 
 void tailsprintf(char *buf, size_t bufsz, const char *fmt, ...)
 void tailsprintf(char *buf, size_t bufsz, const char *fmt, ...)
@@ -9347,7 +9321,7 @@ void submit_nonce2_nonce(struct thr_info *thr, uint32_t pool_no, uint32_t nonce2
 	pool->nonce2 = nonce2;
 	pool->nonce2 = nonce2;
 	gen_stratum_work(pool, work);
 	gen_stratum_work(pool, work);
 
 
-	work->device_diff = MIN(drv->working_diff, work->work_difficulty);
+//	work->device_diff = MIN(drv->working_diff, work->work_difficulty);
 	submit_nonce(thr, work, nonce);
 	submit_nonce(thr, work, nonce);
 	free_work(work);
 	free_work(work);
 }
 }
@@ -9965,15 +9939,7 @@ void hash_queued_work(struct thr_info *mythr)
 		struct timeval diff;
 		struct timeval diff;
 		int64_t hashes;
 		int64_t hashes;
 
 
-<<<<<<<
 		fill_queue(mythr, cgpu, drv, thr_id);
 		fill_queue(mythr, cgpu, drv, thr_id);
-|||||||
-		mythr->work_update = false;
-=======
-#ifndef USE_AVALON2
-		mythr->work_update = false;
-#endif
->>>>>>>
 
 
 		thread_reportin(mythr);
 		thread_reportin(mythr);
 		hashes = drv->scanwork(mythr);
 		hashes = drv->scanwork(mythr);

+ 1 - 83
miner.h

@@ -206,83 +206,6 @@ static inline int fsync (int fd)
 #	endif
 #	endif
 #endif
 #endif
 
 
-<<<<<<< HEAD
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-/* Put avalon last to make it the last device it tries to detect to prevent it
- * trying to claim same chip but different devices. Adding a device here will
- * update all macros in the code that use the *_PARSE_COMMANDS macros for each
- * listed driver. */
-#define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	DRIVER_ADD_COMMAND(bitforce) \
-	DRIVER_ADD_COMMAND(icarus) \
-	DRIVER_ADD_COMMAND(modminer)
-
-#define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	DRIVER_ADD_COMMAND(bflsc) \
-	DRIVER_ADD_COMMAND(bitfury) \
-	DRIVER_ADD_COMMAND(hashfast) \
-	DRIVER_ADD_COMMAND(klondike) \
-	DRIVER_ADD_COMMAND(knc) \
-	DRIVER_ADD_COMMAND(drillbit) \
-	DRIVER_ADD_COMMAND(bab) \
-	DRIVER_ADD_COMMAND(minion) \
-	DRIVER_ADD_COMMAND(avalon)
-
-#define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
-
-#define DRIVER_ENUM(X) DRIVER_##X,
-#define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
-
-/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
-enum drv_driver {
-	DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
-	DRIVER_MAX
-};
-
-/* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
-DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
-
-=======
-/* Put avalon last to make it the last device it tries to detect to prevent it
- * trying to claim same chip but different devices. Adding a device here will
- * update all macros in the code that use the *_PARSE_COMMANDS macros for each
- * listed driver. */
-#define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	DRIVER_ADD_COMMAND(bitforce) \
-	DRIVER_ADD_COMMAND(icarus) \
-	DRIVER_ADD_COMMAND(modminer)
-
-#define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	DRIVER_ADD_COMMAND(bflsc) \
-	DRIVER_ADD_COMMAND(bitfury) \
-	DRIVER_ADD_COMMAND(hashfast) \
-	DRIVER_ADD_COMMAND(klondike) \
-	DRIVER_ADD_COMMAND(knc) \
-	DRIVER_ADD_COMMAND(drillbit) \
-	DRIVER_ADD_COMMAND(bab) \
-	DRIVER_ADD_COMMAND(minion) \
-	DRIVER_ADD_COMMAND(avalon2) \
-	DRIVER_ADD_COMMAND(avalon)
-
-#define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
-	ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
-
-#define DRIVER_ENUM(X) DRIVER_##X,
-#define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
-
-/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
-enum drv_driver {
-	DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
-	DRIVER_MAX
-};
-
-/* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
-DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
-
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 enum alive {
 enum alive {
 	LIFE_WELL,
 	LIFE_WELL,
 	LIFE_SICK,
 	LIFE_SICK,
@@ -555,18 +478,12 @@ struct cgpu_info {
 #ifdef USE_ZTEX
 #ifdef USE_ZTEX
 		struct libztex_device *device_ztex;
 		struct libztex_device *device_ztex;
 #endif
 #endif
-<<<<<<< HEAD
 		int device_fd;
 		int device_fd;
 #ifdef USE_X6500
 #ifdef USE_X6500
 		struct ft232r_device_handle *device_ft232r;
 		struct ft232r_device_handle *device_ft232r;
 #endif
 #endif
 	};
 	};
-#ifdef USE_AVALON
-||||||| parent of 7c5b0b8... Add Avalon2 (2U size machine) support
-#ifdef USE_AVALON
-=======
 #if defined(USE_AVALON) || defined(USE_AVALON2)
 #if defined(USE_AVALON) || defined(USE_AVALON2)
->>>>>>> 7c5b0b8... Add Avalon2 (2U size machine) support
 	struct work **works;
 	struct work **works;
 	int work_array;
 	int work_array;
 	int queued;
 	int queued;
@@ -1597,6 +1514,7 @@ extern void clean_work(struct work *work);
 extern void free_work(struct work *work);
 extern void free_work(struct work *work);
 extern void __copy_work(struct work *work, const struct work *base_work);
 extern void __copy_work(struct work *work, const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
 extern struct work *copy_work(const struct work *base_work);
+extern const char *bfg_workpadding_bin;
 extern void set_simple_ntime_roll_limit(struct ntime_roll_limits *, uint32_t ntime_base, int ntime_roll);
 extern void set_simple_ntime_roll_limit(struct ntime_roll_limits *, uint32_t ntime_base, int ntime_roll);
 extern void work_set_simple_ntime_roll_limit(struct work *, int ntime_roll);
 extern void work_set_simple_ntime_roll_limit(struct work *, int ntime_roll);
 extern void work_hash(struct work *);
 extern void work_hash(struct work *);