Browse Source

kncasic: Minimal changes to get it compiling

Luke Dashjr 11 years ago
parent
commit
131e602085
3 changed files with 101 additions and 18 deletions
  1. 4 0
      Makefile.am
  2. 47 3
      configure.ac
  3. 50 15
      driver-kncasic.c

+ 4 - 0
Makefile.am

@@ -281,6 +281,10 @@ if USE_KNC
 bfgminer_SOURCES += driver-knc.c
 bfgminer_SOURCES += driver-knc.c
 endif
 endif
 
 
+if USE_KNCASIC
+bfgminer_SOURCES += driver-kncasic.c
+endif
+
 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
 endif
 endif

+ 47 - 3
configure.ac

@@ -619,6 +619,40 @@ if test "x$knc" = xyes; then
 fi
 fi
 AM_CONDITIONAL([USE_KNC], [test x$knc = xyes])
 AM_CONDITIONAL([USE_KNC], [test x$knc = xyes])
 
 
+driverlist="$driverlist kncasic"
+AC_ARG_ENABLE([kncasic],
+	[AC_HELP_STRING([--enable-kncasic],[Compile support for KnC gen 2 (default disabled)])],
+	[kncasic=$enableval],
+	[kncasic=$ddno]
+	)
+if test "x$kncasic" != xno && test "x$kncasic" != xauto; then
+	kncasic_controller=$kncasic
+	if test "x$kncasic" = xyes; then
+		kncasic_controller=BBB
+	fi
+	kncasic=yes
+	AC_CHECK_HEADERS([linux/i2c-dev-user.h])
+	AC_CHECK_DECL([i2c_smbus_read_word_data],[true],[
+		AC_MSG_ERROR([linux/i2c-dev.h header from i2c-tools/libi2c-dev (NOT linux headers) is required for knc driver])
+	],[
+		#include <stddef.h>
+		#ifdef HAVE_LINUX_I2C_DEV_USER_H
+		#include <linux/i2c-dev-user.h>
+		#else
+		#ifdef NEED_LINUX_I2C_H
+		#include <linux/i2c.h>
+		#endif
+		#include <linux/i2c-dev.h>
+		#endif
+	])
+	AC_DEFINE([USE_KNCASIC], [1], [Defined to 1 if KnC gen 2 support is wanted])
+	AC_DEFINE_UNQUOTED([CONTROLLER_BOARD_$titan_controller],[1])
+	AH_TEMPLATE([CONTROLLER_BOARD_BACKPLANE])
+	AH_TEMPLATE([CONTROLLER_BOARD_BBB])
+	AH_TEMPLATE([CONTROLLER_BOARD_RPI])
+fi
+AM_CONDITIONAL([USE_KNCASIC], [test x$kncasic = xyes])
+
 AC_ARG_WITH([libmicrohttpd],
 AC_ARG_WITH([libmicrohttpd],
 	[AC_HELP_STRING([--without-libmicrohttpd],[Compile support for libmicrohttpd getwork server (default enabled)])],
 	[AC_HELP_STRING([--without-libmicrohttpd],[Compile support for libmicrohttpd getwork server (default enabled)])],
 	[httpsrv=$withval],
 	[httpsrv=$withval],
@@ -791,11 +825,21 @@ AC_ARG_ENABLE([titan],
 	[titan=$ddno]
 	[titan=$ddno]
 	)
 	)
 if test "x$titan" != xno && test "x$titan" != xauto; then
 if test "x$titan" != xno && test "x$titan" != xauto; then
-	titan_controller=$titan
 	if test "x$titan" = xyes; then
 	if test "x$titan" = xyes; then
-		titan_controller=RPI
+		if test "x$kncasic" = "xyes"; then
+			titan_controller="$kncasic_controller"
+		else
+			titan_controller=RPI
+		fi
+	else
+		titan_controller=$titan
+		titan=yes
+		if test "x$kncasic" = "xyes"; then
+			if test "x$kncasic_controller" != "$titan_controller"; then
+				AC_MSG_ERROR([Can only build kncasic and titan drivers together for the same controller (kncasic=$kncasic_controller vs titan=$titan_controller)])
+			fi
+		fi
 	fi
 	fi
-	titan=yes
 	if test "x$scrypt" = "xno"; then
 	if test "x$scrypt" = "xno"; then
 		AC_MSG_ERROR([You explicitly enabled KnC Titan, but did not enable scrypt])
 		AC_MSG_ERROR([You explicitly enabled KnC Titan, but did not enable scrypt])
 	fi
 	fi

+ 50 - 15
driver-kncasic.c

@@ -21,10 +21,11 @@
 
 
 #include <zlib.h>
 #include <zlib.h>
 
 
+#include "deviceapi.h"
 #include "logging.h"
 #include "logging.h"
 #include "miner.h"
 #include "miner.h"
-#include "knc-transport.h"
-#include "knc-asic.h"
+#include "knc-asic/knc-transport.h"
+#include "knc-asic/knc-asic.h"
 
 
 #define MAX_ASICS               6
 #define MAX_ASICS               6
 #define DIES_PER_ASIC           4
 #define DIES_PER_ASIC           4
@@ -38,6 +39,8 @@
 #define CORE_TIMEOUT		20
 #define CORE_TIMEOUT		20
 #define SCAN_ADJUST_RANGE	32
 #define SCAN_ADJUST_RANGE	32
 
 
+BFG_REGISTER_DRIVER(kncasic_drv)
+
 static struct timeval now;
 static struct timeval now;
 static const struct timeval core_check_interval = {
 static const struct timeval core_check_interval = {
 	CORE_ERROR_INTERVAL, 0
 	CORE_ERROR_INTERVAL, 0
@@ -152,7 +155,6 @@ struct knc_state {
 	struct knc_core_state core[];
 	struct knc_core_state core[];
 };
 };
 
 
-int opt_knc_device_idx = 0;
 int opt_knc_device_bus = -1;
 int opt_knc_device_bus = -1;
 char *knc_log_file = NULL;
 char *knc_log_file = NULL;
 
 
@@ -249,7 +251,7 @@ static void knc_transfer(struct thr_info *thr, struct knc_core_state *core, int
 	struct knc_state *knc = cgpu->device_data;
 	struct knc_state *knc = cgpu->device_data;
 	struct knc_spi_buffer *buffer = &knc->spi_buffer[knc->send_buffer];
 	struct knc_spi_buffer *buffer = &knc->spi_buffer[knc->send_buffer];
 	/* FPGA control, request header, request body/response, CRC(4), ACK(1), EXTRA(3) */
 	/* FPGA control, request header, request body/response, CRC(4), ACK(1), EXTRA(3) */
-	int msglen = 2 + MAX(request_length, 4 + response_length ) + 4 + 1 + 3;
+	int msglen = 2 + max(request_length, 4 + response_length) + 4 + 1 + 3;
 	if (buffer->size + msglen > MAX_SPI_SIZE || buffer->responses >= MAX_SPI_RESPONSES) {
 	if (buffer->size + msglen > MAX_SPI_SIZE || buffer->responses >= MAX_SPI_RESPONSES) {
 		applog(LOG_INFO, "KnC: SPI buffer sent, %d messages %d bytes", buffer->responses, buffer->size);
 		applog(LOG_INFO, "KnC: SPI buffer sent, %d messages %d bytes", buffer->responses, buffer->size);
 		knc_flush(thr);
 		knc_flush(thr);
@@ -344,7 +346,7 @@ static bool knc_detect_one(void *ctx)
 	knc->cores = cores;
 	knc->cores = cores;
 	knc->startup = 2;
 	knc->startup = 2;
 
 
-	cgpu->drv = &knc_drv;
+	cgpu->drv = &kncasic_drv;
 	cgpu->name = "KnCminer";
 	cgpu->name = "KnCminer";
 	cgpu->threads = 1;
 	cgpu->threads = 1;
 
 
@@ -366,14 +368,30 @@ static bool knc_detect_one(void *ctx)
 }
 }
 
 
 /* Probe devices and register with add_cgpu */
 /* Probe devices and register with add_cgpu */
-void knc_detect(bool __maybe_unused hotplug)
+static
+bool kncasic_detect_one(const char * const devpath)
 {
 {
-	void *ctx = knc_trnsp_new(opt_knc_device_idx);
+	void *ctx = knc_trnsp_new(devpath);
 
 
 	if (ctx != NULL) {
 	if (ctx != NULL) {
 		if (!knc_detect_one(ctx))
 		if (!knc_detect_one(ctx))
 			knc_trnsp_free(ctx);
 			knc_trnsp_free(ctx);
+		else
+			return true;
 	}
 	}
+	return false;
+}
+
+static
+int kncasic_detect_auto(void)
+{
+	return knc_detect_one(NULL) ? 1 : 0;
+}
+
+static
+void kncasic_detect(void)
+{
+	generic_detect(&kncasic_drv, kncasic_detect_one, kncasic_detect_auto, GDF_REQUIRE_DNAME | GDF_DEFAULT_NOAUTO);
 }
 }
 
 
 /* Core helper functions */
 /* Core helper functions */
@@ -448,7 +466,8 @@ static void knc_core_failure(struct knc_core_state *core)
 	}
 	}
 }
 }
 
 
-static int knc_core_handle_nonce(struct thr_info *thr, struct knc_core_state *core, int slot, uint32_t nonce)
+static
+void knc_core_handle_nonce(struct thr_info *thr, struct knc_core_state *core, int slot, uint32_t nonce)
 {
 {
 	int i;
 	int i;
 	if (!slot)
 	if (!slot)
@@ -727,7 +746,7 @@ static int64_t knc_scanwork(struct thr_info *thr)
 		if (i % SCAN_ADJUST_RANGE == knc->scan_adjust)
 		if (i % SCAN_ADJUST_RANGE == knc->scan_adjust)
 			clean = true;
 			clean = true;
 		if ((knc_core_need_work(core) || clean) && !knc->startup) {
 		if ((knc_core_need_work(core) || clean) && !knc->startup) {
-			struct work *work = get_work(thr, thr->id);
+			struct work *work = get_work(thr);
 			knc_core_send_work(thr, core, work, clean);
 			knc_core_send_work(thr, core, work, clean);
 		} else {
 		} else {
 			knc_core_request_report(thr, core);
 			knc_core_request_report(thr, core);
@@ -852,12 +871,28 @@ static struct api_data *knc_api_stats(struct cgpu_info *cgpu)
 	return root;
 	return root;
 }
 }
 
 
-struct device_drv knc_drv = {
-	.drv_id = DRIVER_knc,
-	.dname = "KnCminer Neptune",
-	.name = "KnC",
-	.drv_detect = knc_detect,
-	.hash_work = hash_driver_work,
+static
+void hash_driver_work(struct thr_info * const thr)
+{
+	struct cgpu_info * const cgpu = thr->cgpu;
+	struct device_drv * const drv = cgpu->drv;
+	
+	while (likely(!cgpu->shutdown))
+	{
+		int64_t hashes = drv->scanwork(thr);
+		if (unlikely(!hashes_done2(thr, hashes, NULL)))
+			break;
+		
+		if (unlikely(thr->pause || cgpu->deven != DEV_ENABLED))
+			mt_disable(thr);
+	}
+}
+
+struct device_drv kncasic_drv = {
+	.dname = "kncasic",
+	.name = "KNC",
+	.drv_detect = kncasic_detect,
+	.minerloop = hash_driver_work,
 	.flush_work = knc_flush_work,
 	.flush_work = knc_flush_work,
 	.scanwork = knc_scanwork,
 	.scanwork = knc_scanwork,
 	.zero_stats = knc_zero_stats,
 	.zero_stats = knc_zero_stats,