| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- /*
- * Copyright 2012-2013 Luke Dashjr
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version. See COPYING for more details.
- */
- #include "config.h"
- #include <math.h>
- #include <sys/time.h>
- #include <libusb.h>
- #include "compat.h"
- #include "dynclock.h"
- #include "jtag.h"
- #include "logging.h"
- #include "miner.h"
- #include "fpgautils.h"
- #include "ft232r.h"
- #define X6500_USB_PRODUCT "X6500 FPGA Miner"
- #define X6500_BITSTREAM_FILENAME "fpgaminer_x6500-overclocker-0402.bit"
- // NOTE: X6500_BITSTREAM_USERID is bitflipped
- #define X6500_BITSTREAM_USERID "\x40\x20\x24\x42"
- #define X6500_MINIMUM_CLOCK 2
- #define X6500_DEFAULT_CLOCK 200
- #define X6500_MAXIMUM_CLOCK 250
- struct device_api x6500_api;
- #define fromlebytes(ca, j) (ca[j] | (((uint16_t)ca[j+1])<<8) | (((uint32_t)ca[j+2])<<16) | (((uint32_t)ca[j+3])<<24))
- static
- void int2bits(uint32_t n, uint8_t *b, uint8_t bits)
- {
- uint8_t i;
- for (i = (bits + 7) / 8; i > 0; )
- b[--i] = 0;
- for (i = 0; i < bits; ++i) {
- if (n & 1)
- b[i/8] |= 0x80 >> (i % 8);
- n >>= 1;
- }
- }
- static
- uint32_t bits2int(uint8_t *b, uint8_t bits)
- {
- uint32_t n, i;
- n = 0;
- for (i = 0; i < bits; ++i)
- if (b[i/8] & (0x80 >> (i % 8)))
- n |= 1<<i;
- return n;
- }
- static
- void checksum(uint8_t *b, uint8_t bits)
- {
- uint8_t i;
- uint8_t checksum = 1;
- for(i = 0; i < bits; ++i)
- checksum ^= (b[i/8] & (0x80 >> (i % 8))) ? 1 : 0;
- if (checksum)
- b[i/8] |= 0x80 >> (i % 8);
- }
- static
- void x6500_jtag_set(struct jtag_port *jp, uint8_t pinoffset)
- {
- jp->tck = pinoffset << 3;
- jp->tms = pinoffset << 2;
- jp->tdi = pinoffset << 1;
- jp->tdo = pinoffset << 0;
- jp->ignored = ~(jp->tdo | jp->tdi | jp->tms | jp->tck);
- }
- static uint32_t x6500_get_register(struct jtag_port *jp, uint8_t addr);
- static
- void x6500_set_register(struct jtag_port *jp, uint8_t addr, uint32_t nv)
- {
- uint8_t buf[38];
- retry:
- jtag_write(jp, JTAG_REG_IR, "\x40", 6);
- int2bits(nv, &buf[0], 32);
- int2bits(addr, &buf[4], 4);
- buf[4] |= 8;
- checksum(buf, 37);
- jtag_write(jp, JTAG_REG_DR, buf, 38);
- jtag_run(jp);
- #ifdef DEBUG_X6500_SET_REGISTER
- if (x6500_get_register(jp, addr) != nv)
- #else
- if (0)
- #endif
- {
- applog(LOG_WARNING, "x6500_set_register failed %x=%08x", addr, nv);
- goto retry;
- }
- }
- static
- uint32_t x6500_get_register(struct jtag_port *jp, uint8_t addr)
- {
- uint8_t buf[4] = {0};
- jtag_write(jp, JTAG_REG_IR, "\x40", 6);
- int2bits(addr, &buf[0], 4);
- checksum(buf, 5);
- jtag_write(jp, JTAG_REG_DR, buf, 6);
- jtag_read (jp, JTAG_REG_DR, buf, 32);
- jtag_reset(jp);
- return bits2int(buf, 32);
- }
- static bool x6500_foundusb(libusb_device *dev, const char *product, const char *serial)
- {
- struct cgpu_info *x6500;
- x6500 = calloc(1, sizeof(*x6500));
- x6500->api = &x6500_api;
- mutex_init(&x6500->device_mutex);
- x6500->device_path = strdup(serial);
- x6500->deven = DEV_ENABLED;
- x6500->threads = 2;
- x6500->name = strdup(product);
- x6500->cutofftemp = 85;
- x6500->cgpu_data = dev;
- return add_cgpu(x6500);
- }
- static bool x6500_detect_one(const char *serial)
- {
- return ft232r_detect(X6500_USB_PRODUCT, serial, x6500_foundusb);
- }
- static int x6500_detect_auto()
- {
- return ft232r_detect(X6500_USB_PRODUCT, NULL, x6500_foundusb);
- }
- static void x6500_detect()
- {
- serial_detect_auto(&x6500_api, x6500_detect_one, x6500_detect_auto);
- }
- static bool x6500_prepare(struct thr_info *thr)
- {
- if (thr->device_thread)
- return true;
-
- struct cgpu_info *x6500 = thr->cgpu;
- mutex_init(&x6500->device_mutex);
- struct ft232r_device_handle *ftdi = ft232r_open(x6500->cgpu_data);
- x6500->device_ft232r = NULL;
- if (!ftdi)
- return false;
- if (!ft232r_set_bitmode(ftdi, 0xee, 4))
- return false;
- if (!ft232r_purge_buffers(ftdi, FTDI_PURGE_BOTH))
- return false;
- x6500->device_ft232r = ftdi;
-
- struct jtag_port_a *jtag_a;
- unsigned char *pdone = calloc(1, sizeof(*jtag_a) + 1);
- *pdone = 101;
- jtag_a = (void*)(pdone + 1);
- jtag_a->ftdi = ftdi;
- x6500->cgpu_data = jtag_a;
-
- return true;
- }
- struct x6500_fpga_data {
- struct jtag_port jtag;
- struct work prevwork;
- struct timeval tv_workstart;
- struct dclk_data dclk;
- uint8_t freqMaxMaxM;
- // Time the clock was last reduced due to temperature
- time_t last_cutoff_reduced;
- float temp;
- };
- #define bailout2(...) do { \
- applog(__VA_ARGS__); \
- return false; \
- } while(0)
- static bool
- x6500_fpga_upload_bitstream(struct cgpu_info *x6500, struct jtag_port *jp1)
- {
- char buf[0x100];
- unsigned long len, flen;
- unsigned char *pdone = (unsigned char*)x6500->cgpu_data - 1;
- struct ft232r_device_handle *ftdi = jp1->a->ftdi;
- FILE *f = open_xilinx_bitstream(x6500, X6500_BITSTREAM_FILENAME, &len);
- if (!f)
- return false;
- flen = len;
- applog(LOG_WARNING, "%s %u: Programming %s...",
- x6500->api->name, x6500->device_id, x6500->device_path);
- x6500->status = LIFE_INIT;
-
- // "Magic" jtag_port configured to access both FPGAs concurrently
- struct jtag_port jpt = {
- .a = jp1->a,
- };
- struct jtag_port *jp = &jpt;
- uint8_t i, j;
- x6500_jtag_set(jp, 0x11);
-
- // Need to reset here despite previous FPGA state, since we are programming all at once
- jtag_reset(jp);
-
- jtag_write(jp, JTAG_REG_IR, "\xd0", 6); // JPROGRAM
- // Poll each FPGA status individually since they might not be ready at the same time
- for (j = 0; j < 2; ++j) {
- x6500_jtag_set(jp, j ? 0x10 : 1);
- do {
- i = 0xd0; // Re-set JPROGRAM while reading status
- jtag_read(jp, JTAG_REG_IR, &i, 6);
- } while (i & 8);
- applog(LOG_DEBUG, "%s %u.%u: JPROGRAM ready",
- x6500->api->name, x6500->device_id, j);
- }
- x6500_jtag_set(jp, 0x11);
- jtag_write(jp, JTAG_REG_IR, "\xa0", 6); // CFG_IN
-
- sleep(1);
-
- if (fread(buf, 32, 1, f) != 1)
- bailout2(LOG_ERR, "%s %u: File underrun programming %s (%lu bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
- jtag_swrite(jp, JTAG_REG_DR, buf, 256);
- len -= 32;
-
- // Put ft232r chip in asynchronous bitbang mode so we don't need to read back tdo
- // This takes upload time down from about an hour to about 3 minutes
- if (!ft232r_set_bitmode(ftdi, 0xee, 1))
- return false;
- if (!ft232r_purge_buffers(ftdi, FTDI_PURGE_BOTH))
- return false;
- jp->a->bufread = 0;
- jp->a->async = true;
- ssize_t buflen;
- char nextstatus = 25;
- while (len) {
- buflen = len < 32 ? len : 32;
- if (fread(buf, buflen, 1, f) != 1)
- bailout2(LOG_ERR, "%s %u: File underrun programming %s (%lu bytes left)", x6500->api->name, x6500->device_id, x6500->device_path, len);
- jtag_swrite_more(jp, buf, buflen * 8, len == (unsigned long)buflen);
- *pdone = 100 - ((len * 100) / flen);
- if (*pdone >= nextstatus)
- {
- nextstatus += 25;
- applog(LOG_WARNING, "%s %u: Programming %s... %d%% complete...", x6500->api->name, x6500->device_id, x6500->device_path, *pdone);
- }
- len -= buflen;
- }
-
- // Switch back to synchronous bitbang mode
- if (!ft232r_set_bitmode(ftdi, 0xee, 4))
- return false;
- if (!ft232r_purge_buffers(ftdi, FTDI_PURGE_BOTH))
- return false;
- jp->a->bufread = 0;
- jp->a->async = false;
- jp->a->bufread = 0;
- jtag_write(jp, JTAG_REG_IR, "\x30", 6); // JSTART
- for (i=0; i<16; ++i)
- jtag_run(jp);
- i = 0xff; // BYPASS
- jtag_read(jp, JTAG_REG_IR, &i, 6);
- if (!(i & 4))
- return false;
-
- applog(LOG_WARNING, "%s %u: Done programming %s", x6500->api->name, x6500->device_id, x6500->device_path);
- *pdone = 101;
- return true;
- }
- static bool x6500_change_clock(struct thr_info *thr, int multiplier)
- {
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- struct jtag_port *jp = &fpga->jtag;
- x6500_set_register(jp, 0xD, multiplier * 2);
- ft232r_flush(jp->a->ftdi);
- fpga->dclk.freqM = multiplier;
- return true;
- }
- static bool x6500_dclk_change_clock(struct thr_info *thr, int multiplier)
- {
- struct cgpu_info *x6500 = thr->cgpu;
- char fpgaid = thr->device_thread;
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- uint8_t oldFreq = fpga->dclk.freqM;
- mutex_lock(&x6500->device_mutex);
- if (!x6500_change_clock(thr, multiplier)) {
- mutex_unlock(&x6500->device_mutex);
- return false;
- }
- mutex_unlock(&x6500->device_mutex);
- char repr[0x10];
- sprintf(repr, "%s %u.%u", x6500->api->name, x6500->device_id, fpgaid);
- dclk_msg_freqchange(repr, oldFreq * 2, fpga->dclk.freqM * 2, NULL);
- return true;
- }
- static bool x6500_fpga_init(struct thr_info *thr)
- {
- struct cgpu_info *x6500 = thr->cgpu;
- struct ft232r_device_handle *ftdi = x6500->device_ft232r;
- struct x6500_fpga_data *fpga;
- struct jtag_port *jp;
- int fpgaid = thr->device_thread;
- uint8_t pinoffset = fpgaid ? 0x10 : 1;
- unsigned char buf[4] = {0};
- int i;
-
- if (!ftdi)
- return false;
-
- fpga = calloc(1, sizeof(*fpga));
- jp = &fpga->jtag;
- jp->a = x6500->cgpu_data;
- x6500_jtag_set(jp, pinoffset);
- thr->cgpu_data = fpga;
-
- mutex_lock(&x6500->device_mutex);
- if (!jtag_reset(jp)) {
- mutex_unlock(&x6500->device_mutex);
- applog(LOG_ERR, "%s %u: JTAG reset failed",
- x6500->api->name, x6500->device_id);
- return false;
- }
-
- i = jtag_detect(jp);
- if (i != 1) {
- mutex_unlock(&x6500->device_mutex);
- applog(LOG_ERR, "%s %u: JTAG detect returned %d",
- x6500->api->name, x6500->device_id, i);
- return false;
- }
-
- if (!(1
- && jtag_write(jp, JTAG_REG_IR, "\x10", 6)
- && jtag_read (jp, JTAG_REG_DR, buf, 32)
- && jtag_reset(jp)
- )) {
- mutex_unlock(&x6500->device_mutex);
- applog(LOG_ERR, "%s %u: JTAG error reading user code",
- x6500->api->name, x6500->device_id);
- return false;
- }
-
- if (memcmp(buf, X6500_BITSTREAM_USERID, 4)) {
- applog(LOG_ERR, "%s %u.%u: FPGA not programmed",
- x6500->api->name, x6500->device_id, fpgaid);
- if (!x6500_fpga_upload_bitstream(x6500, jp))
- return false;
- } else if (opt_force_dev_init && x6500->status == LIFE_INIT) {
- applog(LOG_DEBUG, "%s %u.%u: FPGA is already programmed, but --force-dev-init is set",
- x6500->api->name, x6500->device_id, fpgaid);
- if (!x6500_fpga_upload_bitstream(x6500, jp))
- return false;
- } else
- applog(LOG_DEBUG, "%s %u.%u: FPGA is already programmed :)",
- x6500->api->name, x6500->device_id, fpgaid);
-
- dclk_prepare(&fpga->dclk);
- x6500_change_clock(thr, X6500_DEFAULT_CLOCK / 2);
- for (i = 0; 0xffffffff != x6500_get_register(jp, 0xE); ++i)
- {}
- mutex_unlock(&x6500->device_mutex);
- if (i)
- applog(LOG_WARNING, "%s %u.%u: Flushed %d nonces from buffer at init",
- x6500->api->name, x6500->device_id, fpgaid, i);
- fpga->dclk.minGoodSamples = 3;
- fpga->freqMaxMaxM =
- fpga->dclk.freqMaxM = X6500_MAXIMUM_CLOCK / 2;
- fpga->dclk.freqMDefault = fpga->dclk.freqM;
- applog(LOG_WARNING, "%s %u.%u: Frequency set to %u MHz (range: %u-%u)",
- x6500->api->name, x6500->device_id, fpgaid,
- fpga->dclk.freqM * 2,
- X6500_MINIMUM_CLOCK,
- fpga->dclk.freqMaxM * 2);
- return true;
- }
- static
- void x6500_get_temperature(struct cgpu_info *x6500)
- {
- struct x6500_fpga_data *fpga = x6500->thr[0]->cgpu_data;
- struct jtag_port *jp = &fpga->jtag;
- struct ft232r_device_handle *ftdi = jp->a->ftdi;
- int i, code[2];
- bool sio[2];
- code[0] = 0;
- code[1] = 0;
- ft232r_flush(ftdi);
- if (!(ft232r_set_cbus_bits(ftdi, false, true))) return;
- if (!(ft232r_set_cbus_bits(ftdi, true, true))) return;
- if (!(ft232r_set_cbus_bits(ftdi, false, true))) return;
- if (!(ft232r_set_cbus_bits(ftdi, true, true))) return;
- if (!(ft232r_set_cbus_bits(ftdi, false, false))) return;
- for (i = 16; i--; ) {
- if (ft232r_set_cbus_bits(ftdi, true, false)) {
- if (!(ft232r_get_cbus_bits(ftdi, &sio[0], &sio[1]))) {
- return;
- }
- } else {
- return;
- }
- code[0] |= sio[0] << i;
- code[1] |= sio[1] << i;
- if (!ft232r_set_cbus_bits(ftdi, false, false)) {
- return;
- }
- }
- if (!(ft232r_set_cbus_bits(ftdi, false, true))) {
- return;
- }
- if (!(ft232r_set_cbus_bits(ftdi, true, true))) {
- return;
- }
- if (!(ft232r_set_cbus_bits(ftdi, false, true))) {
- return;
- }
- if (!ft232r_set_bitmode(ftdi, 0xee, 4)) {
- return;
- }
- ft232r_purge_buffers(jp->a->ftdi, FTDI_PURGE_BOTH);
- jp->a->bufread = 0;
- for (i = 0; i < 2; ++i) {
- struct thr_info *thr = x6500->thr[i];
- fpga = thr->cgpu_data;
- if (!fpga) continue;
- if (code[i] == 0xffff || !code[i]) {
- fpga->temp = 0;
- continue;
- }
- if ((code[i] >> 15) & 1)
- code[i] -= 0x10000;
- fpga->temp = (float)(code[i] >> 2) * 0.03125f;
- applog(LOG_DEBUG,"x6500_get_temperature: fpga[%d]->temp=%.1fC",i,fpga->temp);
- int temperature = round(fpga->temp);
- if (temperature > x6500->targettemp + opt_hysteresis) {
- time_t now = time(NULL);
- if (fpga->last_cutoff_reduced != now) {
- fpga->last_cutoff_reduced = now;
- int oldFreq = fpga->dclk.freqM;
- if (x6500_change_clock(thr, oldFreq - 1))
- applog(LOG_NOTICE, "%s %u.%u: Frequency dropped from %u to %u MHz (temp: %.1fC)",
- x6500->api->name, x6500->device_id, i,
- oldFreq * 2, fpga->dclk.freqM * 2,
- fpga->temp
- );
- fpga->dclk.freqMaxM = fpga->dclk.freqM;
- }
- }
- else
- if (fpga->dclk.freqMaxM < fpga->freqMaxMaxM && temperature < x6500->targettemp) {
- if (temperature < x6500->targettemp - opt_hysteresis) {
- fpga->dclk.freqMaxM = fpga->freqMaxMaxM;
- } else if (fpga->dclk.freqM == fpga->dclk.freqMaxM) {
- ++fpga->dclk.freqMaxM;
- }
- }
- }
- }
- static bool x6500_get_stats(struct cgpu_info *x6500)
- {
- float hottest = 0;
- if (x6500->deven != DEV_ENABLED) {
- // Getting temperature more efficiently while enabled
- // NOTE: Don't need to mess with mutex here, since the device is disabled
- x6500_get_temperature(x6500);
- }
- for (int i = x6500->threads; i--; ) {
- struct thr_info *thr = x6500->thr[i];
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- if (!fpga)
- continue;
- float temp = fpga->temp;
- if (temp > hottest)
- hottest = temp;
- }
- x6500->temp = hottest;
- return true;
- }
- static void
- get_x6500_statline_before(char *buf, struct cgpu_info *x6500)
- {
- char info[18] = " | ";
- struct x6500_fpga_data *fpga0 = x6500->thr[0]->cgpu_data;
- struct x6500_fpga_data *fpga1 = x6500->thr[1]->cgpu_data;
- unsigned char pdone = *((unsigned char*)x6500->cgpu_data - 1);
- if (pdone != 101) {
- sprintf(&info[1], "%3d%%", pdone);
- info[5] = ' ';
- strcat(buf, info);
- return;
- }
- if (x6500->temp) {
- sprintf(&info[1], "%.1fC/%.1fC", fpga0->temp, fpga1->temp);
- info[strlen(info)] = ' ';
- strcat(buf, info);
- return;
- }
- strcat(buf, " | ");
- }
- static struct api_data*
- get_x6500_api_extra_device_status(struct cgpu_info *x6500)
- {
- struct api_data *root = NULL;
- static char *k[2] = {"FPGA0", "FPGA1"};
- int i;
- for (i = 0; i < 2; ++i) {
- struct thr_info *thr = x6500->thr[i];
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- json_t *o = json_object();
- if (fpga->temp)
- json_object_set_new(o, "Temperature", json_real(fpga->temp));
- json_object_set_new(o, "Frequency", json_real((double)fpga->dclk.freqM * 2 * 1000000.));
- json_object_set_new(o, "Cool Max Frequency", json_real((double)fpga->dclk.freqMaxM * 2 * 1000000.));
- json_object_set_new(o, "Max Frequency", json_real((double)fpga->freqMaxMaxM * 2 * 1000000.));
- root = api_add_json(root, k[i], o, false);
- json_decref(o);
- }
- return root;
- }
- static
- bool x6500_start_work(struct thr_info *thr, struct work *work)
- {
- struct cgpu_info *x6500 = thr->cgpu;
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- struct jtag_port *jp = &fpga->jtag;
- char fpgaid = thr->device_thread;
- mutex_lock(&x6500->device_mutex);
- for (int i = 1, j = 0; i < 9; ++i, j += 4)
- x6500_set_register(jp, i, fromlebytes(work->midstate, j));
- for (int i = 9, j = 64; i < 12; ++i, j += 4)
- x6500_set_register(jp, i, fromlebytes(work->data, j));
- ft232r_flush(jp->a->ftdi);
- gettimeofday(&fpga->tv_workstart, NULL);
- x6500_get_temperature(x6500);
- mutex_unlock(&x6500->device_mutex);
- if (opt_debug) {
- char *xdata = bin2hex(work->data, 80);
- applog(LOG_DEBUG, "%s %u.%u: Started work: %s",
- x6500->api->name, x6500->device_id, fpgaid, xdata);
- free(xdata);
- }
- return true;
- }
- static
- int64_t calc_hashes(struct x6500_fpga_data *fpga, struct timeval *tv_now)
- {
- struct timeval tv_delta;
- int64_t hashes;
- timersub(tv_now, &fpga->tv_workstart, &tv_delta);
- hashes = (((int64_t)tv_delta.tv_sec * 1000000) + tv_delta.tv_usec) * fpga->dclk.freqM * 2;
- if (unlikely(hashes > 0x100000000))
- hashes = 0x100000000;
- return hashes;
- }
- static
- int64_t x6500_process_results(struct thr_info *thr, struct work *work)
- {
- struct cgpu_info *x6500 = thr->cgpu;
- struct x6500_fpga_data *fpga = thr->cgpu_data;
- struct jtag_port *jtag = &fpga->jtag;
- char fpgaid = thr->device_thread;
- struct timeval tv_now;
- int64_t hashes;
- uint32_t nonce;
- bool bad;
- while (1) {
- mutex_lock(&x6500->device_mutex);
- gettimeofday(&tv_now, NULL);
- nonce = x6500_get_register(jtag, 0xE);
- mutex_unlock(&x6500->device_mutex);
- if (nonce != 0xffffffff) {
- bad = !test_nonce(work, nonce, false);
- if (!bad) {
- submit_nonce(thr, work, nonce);
- applog(LOG_DEBUG, "%s %u.%u: Nonce for current work: %08lx",
- x6500->api->name, x6500->device_id, fpgaid,
- (unsigned long)nonce);
- dclk_gotNonces(&fpga->dclk);
- } else if (test_nonce(&fpga->prevwork, nonce, false)) {
- submit_nonce(thr, &fpga->prevwork, nonce);
- applog(LOG_DEBUG, "%s %u.%u: Nonce for PREVIOUS work: %08lx",
- x6500->api->name, x6500->device_id, fpgaid,
- (unsigned long)nonce);
- } else {
- applog(LOG_DEBUG, "%s %u.%u: Nonce with H not zero : %08lx",
- x6500->api->name, x6500->device_id, fpgaid,
- (unsigned long)nonce);
- ++hw_errors;
- ++x6500->hw_errors;
- dclk_gotNonces(&fpga->dclk);
- dclk_errorCount(&fpga->dclk, 1.);
- }
- // Keep reading nonce buffer until it's empty
- // This is necessary to avoid getting hw errors from Freq B after we've moved on to Freq A
- continue;
- }
- hashes = calc_hashes(fpga, &tv_now);
- if (thr->work_restart || hashes >= 0xf0000000)
- break;
- usleep(10000);
- hashes = calc_hashes(fpga, &tv_now);
- if (thr->work_restart || hashes >= 0xf0000000)
- break;
- }
- dclk_preUpdate(&fpga->dclk);
- dclk_updateFreq(&fpga->dclk, x6500_dclk_change_clock, thr);
- clear_work(&fpga->prevwork);
- workcpy(&fpga->prevwork, work);
- return hashes;
- }
- static int64_t
- x6500_scanhash(struct thr_info *thr, struct work *work, int64_t __maybe_unused max_nonce)
- {
- if (!x6500_start_work(thr, work))
- return -1;
- int64_t hashes = x6500_process_results(thr, work);
- if (hashes > 0)
- work->blk.nonce += hashes;
- return hashes;
- }
- struct device_api x6500_api = {
- .dname = "x6500",
- .name = "XBS",
- .api_detect = x6500_detect,
- .thread_prepare = x6500_prepare,
- .thread_init = x6500_fpga_init,
- .get_stats = x6500_get_stats,
- .get_statline_before = get_x6500_statline_before,
- .get_api_extra_device_status = get_x6500_api_extra_device_status,
- .scanhash = x6500_scanhash,
- // .thread_shutdown = x6500_fpga_shutdown,
- };
|