|
|
@@ -43,12 +43,12 @@ struct device_drv ztex_drv;
|
|
|
static void ztex_disable(struct thr_info* thr);
|
|
|
static bool ztex_prepare(struct thr_info *thr);
|
|
|
|
|
|
-static void ztex_selectFpga(struct libztex_device* ztex)
|
|
|
+static void ztex_selectFpga(struct libztex_device* ztex, int16_t fpgaNum)
|
|
|
{
|
|
|
if (ztex->root->numberOfFpgas > 1) {
|
|
|
- if (ztex->root->selectedFpga != ztex->fpgaNum)
|
|
|
+ if (ztex->root->selectedFpga != fpgaNum)
|
|
|
mutex_lock(&ztex->root->mutex);
|
|
|
- libztex_selectFpga(ztex);
|
|
|
+ libztex_selectFpga(ztex, fpgaNum);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -60,7 +60,7 @@ static void ztex_releaseFpga(struct libztex_device* ztex)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static struct cgpu_info *ztex_setup(struct libztex_device *dev, int j, int fpgacount)
|
|
|
+static struct cgpu_info *ztex_setup(struct libztex_device *dev, int fpgacount)
|
|
|
{
|
|
|
struct cgpu_info *ztex;
|
|
|
char *fpganame = (char*)dev->snString;
|
|
|
@@ -70,9 +70,8 @@ static struct cgpu_info *ztex_setup(struct libztex_device *dev, int j, int fpgac
|
|
|
ztex->device_ztex = dev;
|
|
|
ztex->procs = fpgacount;
|
|
|
ztex->threads = fpgacount;
|
|
|
- dev->fpgaNum = j;
|
|
|
add_cgpu(ztex);
|
|
|
- strcpy(ztex->device_ztex->repr, ztex->proc_repr);
|
|
|
+ strcpy(ztex->device_ztex->repr, ztex->dev_repr);
|
|
|
ztex->name = fpganame;
|
|
|
applog(LOG_INFO, "%"PRIpreprv": Found Ztex (ZTEX %s)", ztex->dev_repr, fpganame);
|
|
|
|
|
|
@@ -97,7 +96,7 @@ static int ztex_autodetect(void)
|
|
|
ztex_master = ztex_devices[i]->dev;
|
|
|
ztex_master->root = ztex_master;
|
|
|
fpgacount = libztex_numberOfFpgas(ztex_master);
|
|
|
- ztex = ztex_setup(ztex_master, 0, fpgacount);
|
|
|
+ ztex = ztex_setup(ztex_master, fpgacount);
|
|
|
|
|
|
totaldevs += fpgacount;
|
|
|
|
|
|
@@ -119,10 +118,11 @@ static void ztex_detect()
|
|
|
|
|
|
static bool ztex_change_clock_func(struct thr_info *thr, int bestM)
|
|
|
{
|
|
|
+ struct cgpu_info *cgpu = thr->cgpu;
|
|
|
struct libztex_device *ztex = thr->cgpu->device_ztex;
|
|
|
|
|
|
- ztex_selectFpga(ztex);
|
|
|
- libztex_setFreq(ztex, bestM);
|
|
|
+ ztex_selectFpga(ztex, cgpu->proc_id);
|
|
|
+ libztex_setFreq(ztex, bestM, cgpu->proc_repr);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
|
|
|
return true;
|
|
|
@@ -130,17 +130,18 @@ static bool ztex_change_clock_func(struct thr_info *thr, int bestM)
|
|
|
|
|
|
static bool ztex_updateFreq(struct thr_info *thr)
|
|
|
{
|
|
|
+ struct cgpu_info *cgpu = thr->cgpu;
|
|
|
struct libztex_device *ztex = thr->cgpu->device_ztex;
|
|
|
bool rv = dclk_updateFreq(&ztex->dclk, ztex_change_clock_func, thr);
|
|
|
if (unlikely(!rv)) {
|
|
|
- ztex_selectFpga(ztex);
|
|
|
+ ztex_selectFpga(ztex, cgpu->proc_id);
|
|
|
libztex_resetFpga(ztex);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
}
|
|
|
return rv;
|
|
|
}
|
|
|
|
|
|
-static bool ztex_checkNonce(struct libztex_device *ztex,
|
|
|
+static bool ztex_checkNonce(struct cgpu_info *cgpu,
|
|
|
struct work *work,
|
|
|
struct libztex_hash_data *hdata)
|
|
|
{
|
|
|
@@ -159,7 +160,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
|
|
|
sha2(hash1, 32, hash2);
|
|
|
|
|
|
if (be32toh(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
|
|
|
- applog(LOG_DEBUG, "%s: checkNonce failed for %08x", ztex->repr, hdata->nonce);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": checkNonce failed for %08x", cgpu->proc_repr, hdata->nonce);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -168,6 +169,7 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
|
|
|
static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
__maybe_unused int64_t max_nonce)
|
|
|
{
|
|
|
+ struct cgpu_info *cgpu = thr->cgpu;
|
|
|
struct libztex_device *ztex;
|
|
|
unsigned char sendbuf[44];
|
|
|
int i, j, k;
|
|
|
@@ -186,28 +188,28 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
memcpy(sendbuf, work->data + 64, 12);
|
|
|
memcpy(sendbuf + 12, work->midstate, 32);
|
|
|
|
|
|
- ztex_selectFpga(ztex);
|
|
|
+ ztex_selectFpga(ztex, cgpu->proc_id);
|
|
|
i = libztex_sendHashData(ztex, sendbuf);
|
|
|
if (i < 0) {
|
|
|
// Something wrong happened in send
|
|
|
- applog(LOG_ERR, "%s: Failed to send hash data with err %d, retrying", ztex->repr, i);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Failed to send hash data with err %d, retrying", cgpu->proc_repr, i);
|
|
|
nmsleep(500);
|
|
|
i = libztex_sendHashData(ztex, sendbuf);
|
|
|
if (i < 0) {
|
|
|
// And there's nothing we can do about it
|
|
|
ztex_disable(thr);
|
|
|
- applog(LOG_ERR, "%s: Failed to send hash data with err %d, giving up", ztex->repr, i);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Failed to send hash data with err %d, giving up", cgpu->proc_repr, i);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
ztex_releaseFpga(ztex);
|
|
|
|
|
|
- applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": sent hashdata", cgpu->proc_repr);
|
|
|
|
|
|
lastnonce = calloc(1, sizeof(uint32_t)*ztex->numNonces);
|
|
|
if (lastnonce == NULL) {
|
|
|
- applog(LOG_ERR, "%s: failed to allocate lastnonce[%d]", ztex->repr, ztex->numNonces);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": failed to allocate lastnonce[%d]", cgpu->proc_repr, ztex->numNonces);
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -215,7 +217,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
backlog_max = ztex->numNonces * (2 + ztex->extraSolutions);
|
|
|
backlog = calloc(1, sizeof(uint32_t) * backlog_max);
|
|
|
if (backlog == NULL) {
|
|
|
- applog(LOG_ERR, "%s: failed to allocate backlog[%d]", ztex->repr, backlog_max);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": failed to allocate backlog[%d]", cgpu->proc_repr, backlog_max);
|
|
|
free(lastnonce);
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -223,25 +225,25 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
overflow = false;
|
|
|
int count = 0;
|
|
|
|
|
|
- applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": entering poll loop", cgpu->proc_repr);
|
|
|
while (!(overflow || thr->work_restart)) {
|
|
|
count++;
|
|
|
if (!restart_wait(thr, 250))
|
|
|
{
|
|
|
- applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": New work detected", cgpu->proc_repr);
|
|
|
break;
|
|
|
}
|
|
|
- ztex_selectFpga(ztex);
|
|
|
+ ztex_selectFpga(ztex, cgpu->proc_id);
|
|
|
i = libztex_readHashData(ztex, &hdata[0]);
|
|
|
if (i < 0) {
|
|
|
// Something wrong happened in read
|
|
|
- applog(LOG_ERR, "%s: Failed to read hash data with err %d, retrying", ztex->repr, i);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Failed to read hash data with err %d, retrying", cgpu->proc_repr, i);
|
|
|
nmsleep(500);
|
|
|
i = libztex_readHashData(ztex, &hdata[0]);
|
|
|
if (i < 0) {
|
|
|
// And there's nothing we can do about it
|
|
|
ztex_disable(thr);
|
|
|
- applog(LOG_ERR, "%s: Failed to read hash data with err %d, giving up", ztex->repr, i);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Failed to read hash data with err %d, giving up", cgpu->proc_repr, i);
|
|
|
free(lastnonce);
|
|
|
free(backlog);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
@@ -251,7 +253,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
ztex_releaseFpga(ztex);
|
|
|
|
|
|
if (thr->work_restart) {
|
|
|
- applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": New work detected", cgpu->proc_repr);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
@@ -262,12 +264,12 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
if (nonce > noncecnt)
|
|
|
noncecnt = nonce;
|
|
|
if (((0xffffffff - nonce) < (nonce - lastnonce[i])) || nonce < lastnonce[i]) {
|
|
|
- applog(LOG_DEBUG, "%s: overflow nonce=%08x lastnonce=%08x", ztex->repr, nonce, lastnonce[i]);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": overflow nonce=%08x lastnonce=%08x", cgpu->proc_repr, nonce, lastnonce[i]);
|
|
|
overflow = true;
|
|
|
} else
|
|
|
lastnonce[i] = nonce;
|
|
|
|
|
|
- if (!ztex_checkNonce(ztex, work, &hdata[i])) {
|
|
|
+ if (!ztex_checkNonce(cgpu, work, &hdata[i])) {
|
|
|
// do not count errors in the first 500ms after sendHashData (2x250 wait time)
|
|
|
if (count > 2)
|
|
|
dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
|
|
|
@@ -299,7 +301,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
work->blk.nonce = 0xffffffff;
|
|
|
if (!j || test_nonce(work, nonce, false))
|
|
|
submit_nonce(thr, work, nonce);
|
|
|
- applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": submitted %08x (from N%dE%d)", cgpu->proc_repr, nonce, i, j);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -315,7 +317,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- applog(LOG_DEBUG, "%s: exit %1.8X", ztex->repr, noncecnt);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": exit %1.8X", cgpu->proc_repr, noncecnt);
|
|
|
|
|
|
work->blk.nonce = 0xffffffff;
|
|
|
|
|
|
@@ -360,17 +362,6 @@ static bool ztex_prepare(struct thr_info *thr)
|
|
|
|
|
|
cgtime(&now);
|
|
|
get_datestamp(cgpu->init, &now);
|
|
|
-
|
|
|
- if (cgpu->proc_id)
|
|
|
- {
|
|
|
- struct libztex_device *ztex_master = cgpu->device->device_ztex;
|
|
|
- ztex = malloc(sizeof(struct libztex_device));
|
|
|
- memcpy(ztex, ztex_master, sizeof(*ztex));
|
|
|
- cgpu->device_ztex = ztex;
|
|
|
- ztex->root = ztex_master;
|
|
|
- ztex->fpgaNum = cgpu->proc_id;
|
|
|
- strcpy(ztex->repr, cgpu->proc_repr);
|
|
|
- }
|
|
|
|
|
|
{
|
|
|
char fpganame[LIBZTEX_SNSTRING_LEN+3+1];
|
|
|
@@ -378,20 +369,20 @@ static bool ztex_prepare(struct thr_info *thr)
|
|
|
cgpu->name = fpganame;
|
|
|
}
|
|
|
|
|
|
- ztex_selectFpga(ztex);
|
|
|
- if (libztex_configureFpga(ztex) != 0) {
|
|
|
+ ztex_selectFpga(ztex, cgpu->proc_id);
|
|
|
+ if (libztex_configureFpga(ztex, cgpu->proc_repr) != 0) {
|
|
|
libztex_resetFpga(ztex);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
- applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Disabling!", cgpu->proc_repr);
|
|
|
thr->cgpu->deven = DEV_DISABLED;
|
|
|
return true;
|
|
|
}
|
|
|
ztex->dclk.freqM = ztex->dclk.freqMaxM+1;;
|
|
|
//ztex_updateFreq(thr);
|
|
|
- libztex_setFreq(ztex, ztex->dclk.freqMDefault);
|
|
|
+ libztex_setFreq(ztex, ztex->dclk.freqMDefault, cgpu->proc_repr);
|
|
|
ztex_releaseFpga(ztex);
|
|
|
notifier_init(thr->work_restart_notifier);
|
|
|
- applog(LOG_DEBUG, "%s: prepare", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": prepare", cgpu->proc_repr);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -404,15 +395,15 @@ static void ztex_shutdown(struct thr_info *thr)
|
|
|
return;
|
|
|
|
|
|
cgpu->device_ztex = NULL;
|
|
|
- if (ztex->root->numberOfFpgas > 1 && ztex->fpgaNum == 0)
|
|
|
+ if (ztex->root->numberOfFpgas > 1 /*&& ztex->fpgaNum == 0*/)
|
|
|
pthread_mutex_destroy(&ztex->mutex);
|
|
|
- applog(LOG_DEBUG, "%s: shutdown", ztex->repr);
|
|
|
+ applog(LOG_DEBUG, "%"PRIpreprv": shutdown", cgpu->proc_repr);
|
|
|
libztex_destroy_device(ztex);
|
|
|
}
|
|
|
|
|
|
static void ztex_disable(struct thr_info *thr)
|
|
|
{
|
|
|
- applog(LOG_ERR, "%s: Disabling!", thr->cgpu->device_ztex->repr);
|
|
|
+ applog(LOG_ERR, "%"PRIpreprv": Disabling!", thr->cgpu->proc_repr);
|
|
|
thr->cgpu->deven = DEV_DISABLED;
|
|
|
ztex_shutdown(thr);
|
|
|
}
|