Skip to content

Commit

Permalink
kncasic: Minimal changes to get it compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Oct 17, 2014
1 parent 9103297 commit 131e602
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Expand Up @@ -281,6 +281,10 @@ if USE_KNC
bfgminer_SOURCES += driver-knc.c
endif

if USE_KNCASIC
bfgminer_SOURCES += driver-kncasic.c
endif

if HAS_KLONDIKE
bfgminer_SOURCES += driver-klondike.c driver-klondike.h driver-hashbusteravalon.c
endif
Expand Down
50 changes: 47 additions & 3 deletions configure.ac
Expand Up @@ -619,6 +619,40 @@ if test "x$knc" = xyes; then
fi
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_HELP_STRING([--without-libmicrohttpd],[Compile support for libmicrohttpd getwork server (default enabled)])],
[httpsrv=$withval],
Expand Down Expand Up @@ -791,11 +825,21 @@ AC_ARG_ENABLE([titan],
[titan=$ddno]
)
if test "x$titan" != xno && test "x$titan" != xauto; then
titan_controller=$titan
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
titan=yes
if test "x$scrypt" = "xno"; then
AC_MSG_ERROR([You explicitly enabled KnC Titan, but did not enable scrypt])
fi
Expand Down
65 changes: 50 additions & 15 deletions driver-kncasic.c
Expand Up @@ -21,10 +21,11 @@

#include <zlib.h>

#include "deviceapi.h"
#include "logging.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 DIES_PER_ASIC 4
Expand All @@ -38,6 +39,8 @@
#define CORE_TIMEOUT 20
#define SCAN_ADJUST_RANGE 32

BFG_REGISTER_DRIVER(kncasic_drv)

static struct timeval now;
static const struct timeval core_check_interval = {
CORE_ERROR_INTERVAL, 0
Expand Down Expand Up @@ -152,7 +155,6 @@ struct knc_state {
struct knc_core_state core[];
};

int opt_knc_device_idx = 0;
int opt_knc_device_bus = -1;
char *knc_log_file = NULL;

Expand Down Expand Up @@ -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_spi_buffer *buffer = &knc->spi_buffer[knc->send_buffer];
/* 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) {
applog(LOG_INFO, "KnC: SPI buffer sent, %d messages %d bytes", buffer->responses, buffer->size);
knc_flush(thr);
Expand Down Expand Up @@ -344,7 +346,7 @@ static bool knc_detect_one(void *ctx)
knc->cores = cores;
knc->startup = 2;

cgpu->drv = &knc_drv;
cgpu->drv = &kncasic_drv;
cgpu->name = "KnCminer";
cgpu->threads = 1;

Expand All @@ -366,14 +368,30 @@ static bool knc_detect_one(void *ctx)
}

/* 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 (!knc_detect_one(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 */
Expand Down Expand Up @@ -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;
if (!slot)
Expand Down Expand Up @@ -727,7 +746,7 @@ static int64_t knc_scanwork(struct thr_info *thr)
if (i % SCAN_ADJUST_RANGE == knc->scan_adjust)
clean = true;
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);
} else {
knc_core_request_report(thr, core);
Expand Down Expand Up @@ -852,12 +871,28 @@ static struct api_data *knc_api_stats(struct cgpu_info *cgpu)
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,
.scanwork = knc_scanwork,
.zero_stats = knc_zero_stats,
Expand Down

0 comments on commit 131e602

Please sign in to comment.