Browse Source

rename device_api -> device_drv and all related api -> drv and add a device_drv->drv enum for identifying which driver each is

nfactor-troky
Kano 12 years ago
parent
commit
a344deb6ac
  1. 64
      api.c
  2. 119
      cgminer.c
  3. 87
      driver-bitforce.c
  4. 6
      driver-cpu.c
  5. 2
      driver-cpu.h
  6. 11
      driver-icarus.c
  7. 93
      driver-modminer.c
  8. 38
      driver-opencl.c
  9. 2
      driver-opencl.h
  10. 10
      driver-ztex.c
  11. 2
      findnonce.c
  12. 10
      fpgautils.c
  13. 14
      fpgautils.h
  14. 19
      miner.h
  15. 38
      usbutils.c
  16. 4
      usbutils.h

64
api.c

@ -599,22 +599,6 @@ struct APIGROUPS {
static struct IP4ACCESS *ipaccess = NULL; static struct IP4ACCESS *ipaccess = NULL;
static int ips = 0; static int ips = 0;
#ifdef USE_BITFORCE
extern struct device_api bitforce_api;
#endif
#ifdef USE_ICARUS
extern struct device_api icarus_api;
#endif
#ifdef USE_ZTEX
extern struct device_api ztex_api;
#endif
#ifdef USE_MODMINER
extern struct device_api modminer_api;
#endif
struct io_data { struct io_data {
size_t siz; size_t siz;
char *ptr; char *ptr;
@ -1153,19 +1137,19 @@ static int numpgas()
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (devices[i]->api == &bitforce_api) if (devices[i]->drv->drv == DRIVER_BITFORCE)
count++; count++;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (devices[i]->api == &icarus_api) if (devices[i]->drv->drv == DRIVER_ICARUS)
count++; count++;
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (devices[i]->api == &ztex_api) if (devices[i]->drv->drv == DRIVER_ZTEX)
count++; count++;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (devices[i]->api == &modminer_api) if (devices[i]->drv->drv == DRIVER_MODMINER)
count++; count++;
#endif #endif
} }
@ -1179,19 +1163,19 @@ static int pgadevice(int pgaid)
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (devices[i]->api == &bitforce_api) if (devices[i]->drv->drv == DRIVER_BITFORCE)
count++; count++;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (devices[i]->api == &icarus_api) if (devices[i]->drv->drv == DRIVER_ICARUS)
count++; count++;
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (devices[i]->api == &ztex_api) if (devices[i]->drv->drv == DRIVER_ZTEX)
count++; count++;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (devices[i]->api == &modminer_api) if (devices[i]->drv->drv == DRIVER_MODMINER)
count++; count++;
#endif #endif
if (count == (pgaid + 1)) if (count == (pgaid + 1))
@ -1535,11 +1519,11 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
float temp = cgpu->temp; float temp = cgpu->temp;
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (cgpu->api == &ztex_api && cgpu->device_ztex) if (cgpu->drv->drv == DRIVER_ZTEX && cgpu->device_ztex)
frequency = cgpu->device_ztex->freqM1 * (cgpu->device_ztex->freqM + 1); frequency = cgpu->device_ztex->freqM1 * (cgpu->device_ztex->freqM + 1);
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (cgpu->api == &modminer_api) if (cgpu->drv->drv == DRIVER_MODMINER)
frequency = cgpu->clock; frequency = cgpu->clock;
#endif #endif
@ -1553,7 +1537,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
status = (char *)status2str(cgpu->status); status = (char *)status2str(cgpu->status);
root = api_add_int(root, "PGA", &pga, false); root = api_add_int(root, "PGA", &pga, false);
root = api_add_string(root, "Name", cgpu->api->name, false); root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false); root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_string(root, "Enabled", enabled, false); root = api_add_string(root, "Enabled", enabled, false);
root = api_add_string(root, "Status", status, false); root = api_add_string(root, "Status", status, false);
@ -1868,12 +1852,12 @@ static void pgaidentify(struct io_data *io_data, __maybe_unused SOCKETTYPE c, ch
} }
struct cgpu_info *cgpu = devices[dev]; struct cgpu_info *cgpu = devices[dev];
struct device_api *api = cgpu->api; struct device_drv *drv = cgpu->drv;
if (!api->identify_device) if (!drv->identify_device)
message(io_data, MSG_PGANOID, id, NULL, isjson); message(io_data, MSG_PGANOID, id, NULL, isjson);
else { else {
api->identify_device(cgpu); drv->identify_device(cgpu);
message(io_data, MSG_PGAIDENT, id, NULL, isjson); message(io_data, MSG_PGAIDENT, id, NULL, isjson);
} }
} }
@ -2753,7 +2737,7 @@ void notifystatus(struct io_data *io_data, int device, struct cgpu_info *cgpu, b
// ALL counters (and only counters) must start the name with a '*' // ALL counters (and only counters) must start the name with a '*'
// Simplifies future external support for identifying new counters // Simplifies future external support for identifying new counters
root = api_add_int(root, "NOTIFY", &device, false); root = api_add_int(root, "NOTIFY", &device, false);
root = api_add_string(root, "Name", cgpu->api->name, false); root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false); root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_time(root, "Last Well", &(cgpu->device_last_well), false); root = api_add_time(root, "Last Well", &(cgpu->device_last_well), false);
root = api_add_time(root, "Last Not Well", &(cgpu->device_last_not_well), false); root = api_add_time(root, "Last Not Well", &(cgpu->device_last_not_well), false);
@ -2817,9 +2801,9 @@ static void devdetails(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
cgpu = devices[i]; cgpu = devices[i];
root = api_add_int(root, "DEVDETAILS", &i, false); root = api_add_int(root, "DEVDETAILS", &i, false);
root = api_add_string(root, "Name", cgpu->api->name, false); root = api_add_string(root, "Name", cgpu->drv->name, false);
root = api_add_int(root, "ID", &(cgpu->device_id), false); root = api_add_int(root, "ID", &(cgpu->device_id), false);
root = api_add_string(root, "Driver", cgpu->api->dname, false); root = api_add_string(root, "Driver", cgpu->drv->dname, false);
root = api_add_const(root, "Kernel", cgpu->kname ? : BLANK, false); root = api_add_const(root, "Kernel", cgpu->kname ? : BLANK, false);
root = api_add_const(root, "Model", cgpu->name ? : BLANK, false); root = api_add_const(root, "Model", cgpu->name ? : BLANK, false);
root = api_add_const(root, "Device Path", cgpu->device_path ? : BLANK, false); root = api_add_const(root, "Device Path", cgpu->device_path ? : BLANK, false);
@ -2923,13 +2907,13 @@ static void minerstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
for (j = 0; j < total_devices; j++) { for (j = 0; j < total_devices; j++) {
struct cgpu_info *cgpu = devices[j]; struct cgpu_info *cgpu = devices[j];
if (cgpu && cgpu->api) { if (cgpu && cgpu->drv) {
if (cgpu->api->get_api_stats) if (cgpu->drv->get_api_stats)
extra = cgpu->api->get_api_stats(cgpu); extra = cgpu->drv->get_api_stats(cgpu);
else else
extra = NULL; extra = NULL;
sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id); sprintf(id, "%s%d", cgpu->drv->name, cgpu->device_id);
i = itemstats(io_data, i, id, &(cgpu->cgminer_stats), NULL, extra, isjson); i = itemstats(io_data, i, id, &(cgpu->cgminer_stats), NULL, extra, isjson);
} }
} }
@ -3195,16 +3179,16 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe
} }
struct cgpu_info *cgpu = devices[dev]; struct cgpu_info *cgpu = devices[dev];
struct device_api *api = cgpu->api; struct device_drv *drv = cgpu->drv;
char *set = strchr(opt, ','); char *set = strchr(opt, ',');
if (set) if (set)
*(set++) = '\0'; *(set++) = '\0';
if (!api->set_device) if (!drv->set_device)
message(io_data, MSG_PGANOSET, id, NULL, isjson); message(io_data, MSG_PGANOSET, id, NULL, isjson);
else { else {
char *ret = api->set_device(cgpu, opt, set, buf); char *ret = drv->set_device(cgpu, opt, set, buf);
if (ret) { if (ret) {
if (strcasecmp(opt, "help") == 0) if (strcasecmp(opt, "help") == 0)
message(io_data, MSG_PGAHELP, id, ret, isjson); message(io_data, MSG_PGAHELP, id, ret, isjson);

119
cgminer.c

@ -385,7 +385,7 @@ static void sharelog(const char*disposition, const struct work*work)
data = bin2hex(work->data, sizeof(work->data)); data = bin2hex(work->data, sizeof(work->data));
// timestamp,disposition,target,pool,dev,thr,sharehash,sharedata // timestamp,disposition,target,pool,dev,thr,sharehash,sharedata
rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->api->name, cgpu->device_id, thr_id, hash, data); rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->drv->name, cgpu->device_id, thr_id, hash, data);
free(target); free(target);
free(hash); free(hash);
free(data); free(data);
@ -1875,9 +1875,9 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
suffix_string(dh64, displayed_hashes, 4); suffix_string(dh64, displayed_hashes, 4);
suffix_string(dr64, displayed_rolling, 4); suffix_string(dr64, displayed_rolling, 4);
sprintf(buf, "%s%d ", cgpu->api->name, cgpu->device_id); sprintf(buf, "%s%d ", cgpu->drv->name, cgpu->device_id);
if (cgpu->api->get_statline_before) if (cgpu->drv->get_statline_before)
cgpu->api->get_statline_before(buf, cgpu); cgpu->drv->get_statline_before(buf, cgpu);
else else
tailsprintf(buf, " | "); tailsprintf(buf, " | ");
tailsprintf(buf, "(%ds):%s (avg):%sh/s | A:%d R:%d HW:%d U:%.1f/m", tailsprintf(buf, "(%ds):%s (avg):%sh/s | A:%d R:%d HW:%d U:%.1f/m",
@ -1888,8 +1888,8 @@ static void get_statline(char *buf, struct cgpu_info *cgpu)
cgpu->rejected, cgpu->rejected,
cgpu->hw_errors, cgpu->hw_errors,
cgpu->utility); cgpu->utility);
if (cgpu->api->get_statline) if (cgpu->drv->get_statline)
cgpu->api->get_statline(buf, cgpu); cgpu->drv->get_statline(buf, cgpu);
} }
static void text_print_status(int thr_id) static void text_print_status(int thr_id)
@ -1971,10 +1971,10 @@ static void curses_print_devstatus(int thr_id)
cgpu->utility = cgpu->accepted / total_secs * 60; cgpu->utility = cgpu->accepted / total_secs * 60;
wmove(statuswin,devcursor + cgpu->cgminer_id, 0); wmove(statuswin,devcursor + cgpu->cgminer_id, 0);
wprintw(statuswin, " %s %*d: ", cgpu->api->name, dev_width, cgpu->device_id); wprintw(statuswin, " %s %*d: ", cgpu->drv->name, dev_width, cgpu->device_id);
if (cgpu->api->get_statline_before) { if (cgpu->drv->get_statline_before) {
logline[0] = '\0'; logline[0] = '\0';
cgpu->api->get_statline_before(logline, cgpu); cgpu->drv->get_statline_before(logline, cgpu);
wprintw(statuswin, "%s", logline); wprintw(statuswin, "%s", logline);
} }
else else
@ -2007,9 +2007,9 @@ static void curses_print_devstatus(int thr_id)
hwwidth, cgpu->hw_errors, hwwidth, cgpu->hw_errors,
uwidth + 3, cgpu->utility); uwidth + 3, cgpu->utility);
if (cgpu->api->get_statline) { if (cgpu->drv->get_statline) {
logline[0] = '\0'; logline[0] = '\0';
cgpu->api->get_statline(logline, cgpu); cgpu->drv->get_statline(logline, cgpu);
wprintw(statuswin, "%s", logline); wprintw(statuswin, "%s", logline);
} }
@ -2234,10 +2234,10 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
if (!QUIET) { if (!QUIET) {
if (total_pools > 1) if (total_pools > 1)
applog(LOG_NOTICE, "Accepted %s %s %d pool %d %s%s", applog(LOG_NOTICE, "Accepted %s %s %d pool %d %s%s",
hashshow, cgpu->api->name, cgpu->device_id, work->pool->pool_no, resubmit ? "(resubmit)" : "", worktime); hashshow, cgpu->drv->name, cgpu->device_id, work->pool->pool_no, resubmit ? "(resubmit)" : "", worktime);
else else
applog(LOG_NOTICE, "Accepted %s %s %d %s%s", applog(LOG_NOTICE, "Accepted %s %s %d %s%s",
hashshow, cgpu->api->name, cgpu->device_id, resubmit ? "(resubmit)" : "", worktime); hashshow, cgpu->drv->name, cgpu->device_id, resubmit ? "(resubmit)" : "", worktime);
} }
sharelog("accept", work); sharelog("accept", work);
if (opt_shares && total_accepted >= opt_shares) { if (opt_shares && total_accepted >= opt_shares) {
@ -2302,7 +2302,7 @@ share_result(json_t *val, json_t *res, json_t *err, const struct work *work,
} }
applog(LOG_NOTICE, "Rejected %s %s %d %s%s %s%s", applog(LOG_NOTICE, "Rejected %s %s %d %s%s %s%s",
hashshow, cgpu->api->name, cgpu->device_id, where, reason, resubmit ? "(resubmit)" : "", worktime); hashshow, cgpu->drv->name, cgpu->device_id, where, reason, resubmit ? "(resubmit)" : "", worktime);
sharelog(disposition, work); sharelog(disposition, work);
} }
@ -5238,15 +5238,15 @@ static bool hashtest(struct thr_info *thr, struct work *work)
if (hash2_32[7] != 0) { if (hash2_32[7] != 0) {
applog(LOG_WARNING, "%s%d: invalid nonce - HW error", applog(LOG_WARNING, "%s%d: invalid nonce - HW error",
thr->cgpu->api->name, thr->cgpu->device_id); thr->cgpu->drv->name, thr->cgpu->device_id);
mutex_lock(&stats_lock); mutex_lock(&stats_lock);
hw_errors++; hw_errors++;
thr->cgpu->hw_errors++; thr->cgpu->hw_errors++;
mutex_unlock(&stats_lock); mutex_unlock(&stats_lock);
if (thr->cgpu->api->hw_error) if (thr->cgpu->drv->hw_error)
thr->cgpu->api->hw_error(thr); thr->cgpu->drv->hw_error(thr);
goto out; goto out;
} }
@ -5294,7 +5294,7 @@ static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64
} }
static void mt_disable(struct thr_info *mythr, const int thr_id, static void mt_disable(struct thr_info *mythr, const int thr_id,
struct device_api *api) struct device_drv *drv)
{ {
applog(LOG_WARNING, "Thread %d being disabled", thr_id); applog(LOG_WARNING, "Thread %d being disabled", thr_id);
mythr->rolling = mythr->cgpu->rolling = 0; mythr->rolling = mythr->cgpu->rolling = 0;
@ -5305,8 +5305,8 @@ static void mt_disable(struct thr_info *mythr, const int thr_id,
} while (mythr->pause); } while (mythr->pause);
thread_reportin(mythr); thread_reportin(mythr);
applog(LOG_WARNING, "Thread %d being re-enabled", thr_id); applog(LOG_WARNING, "Thread %d being re-enabled", thr_id);
if (api->thread_enable) if (drv->thread_enable)
api->thread_enable(mythr); drv->thread_enable(mythr);
} }
void *miner_thread(void *userdata) void *miner_thread(void *userdata)
@ -5314,7 +5314,7 @@ void *miner_thread(void *userdata)
struct thr_info *mythr = userdata; struct thr_info *mythr = userdata;
const int thr_id = mythr->id; const int thr_id = mythr->id;
struct cgpu_info *cgpu = mythr->cgpu; struct cgpu_info *cgpu = mythr->cgpu;
struct device_api *api = cgpu->api; struct device_drv *drv = cgpu->drv;
struct cgminer_stats *dev_stats = &(cgpu->cgminer_stats); struct cgminer_stats *dev_stats = &(cgpu->cgminer_stats);
struct cgminer_stats *pool_stats; struct cgminer_stats *pool_stats;
struct timeval getwork_start; struct timeval getwork_start;
@ -5323,7 +5323,7 @@ void *miner_thread(void *userdata)
const long cycle = opt_log_interval / 5 ? : 1; const long cycle = opt_log_interval / 5 ? : 1;
struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate; struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
struct timeval diff, sdiff, wdiff = {0, 0}; struct timeval diff, sdiff, wdiff = {0, 0};
uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff; uint32_t max_nonce = drv->can_limit_work ? drv->can_limit_work(mythr) : 0xffffffff;
int64_t hashes_done = 0; int64_t hashes_done = 0;
int64_t hashes; int64_t hashes;
struct work *work; struct work *work;
@ -5337,7 +5337,7 @@ void *miner_thread(void *userdata)
gettimeofday(&getwork_start, NULL); gettimeofday(&getwork_start, NULL);
if (api->thread_init && !api->thread_init(mythr)) { if (drv->thread_init && !drv->thread_init(mythr)) {
dev_error(cgpu, REASON_THREAD_FAIL_INIT); dev_error(cgpu, REASON_THREAD_FAIL_INIT);
goto out; goto out;
} }
@ -5357,7 +5357,7 @@ void *miner_thread(void *userdata)
gettimeofday(&tv_workstart, NULL); gettimeofday(&tv_workstart, NULL);
work->blk.nonce = 0; work->blk.nonce = 0;
cgpu->max_hashes = 0; cgpu->max_hashes = 0;
if (api->prepare_work && !api->prepare_work(mythr, work)) { if (drv->prepare_work && !drv->prepare_work(mythr, work)) {
applog(LOG_ERR, "work prepare failed, exiting " applog(LOG_ERR, "work prepare failed, exiting "
"mining thread %d", thr_id); "mining thread %d", thr_id);
break; break;
@ -5399,16 +5399,16 @@ void *miner_thread(void *userdata)
gettimeofday(&(work->tv_work_start), NULL); gettimeofday(&(work->tv_work_start), NULL);
thread_reportin(mythr); thread_reportin(mythr);
hashes = api->scanhash(mythr, work, work->blk.nonce + max_nonce); hashes = drv->scanhash(mythr, work, work->blk.nonce + max_nonce);
thread_reportin(mythr); thread_reportin(mythr);
gettimeofday(&getwork_start, NULL); gettimeofday(&getwork_start, NULL);
if (unlikely(hashes == -1)) { if (unlikely(hashes == -1)) {
applog(LOG_ERR, "%s %d failure, disabling!", api->name, cgpu->device_id); applog(LOG_ERR, "%s %d failure, disabling!", drv->name, cgpu->device_id);
cgpu->deven = DEV_DISABLED; cgpu->deven = DEV_DISABLED;
dev_error(cgpu, REASON_THREAD_ZERO_HASH); dev_error(cgpu, REASON_THREAD_ZERO_HASH);
mt_disable(mythr, thr_id, api); mt_disable(mythr, thr_id, drv);
} }
hashes_done += hashes; hashes_done += hashes;
@ -5429,7 +5429,7 @@ void *miner_thread(void *userdata)
if (unlikely((long)sdiff.tv_sec < cycle)) { if (unlikely((long)sdiff.tv_sec < cycle)) {
int mult; int mult;
if (likely(!api->can_limit_work || max_nonce == 0xffffffff)) if (likely(!drv->can_limit_work || max_nonce == 0xffffffff))
continue; continue;
mult = 1000000 / ((sdiff.tv_usec + 0x400) / 0x400) + 0x10; mult = 1000000 / ((sdiff.tv_usec + 0x400) / 0x400) + 0x10;
@ -5438,9 +5438,9 @@ void *miner_thread(void *userdata)
max_nonce = 0xffffffff; max_nonce = 0xffffffff;
else else
max_nonce = (max_nonce * mult) / 0x400; max_nonce = (max_nonce * mult) / 0x400;
} else if (unlikely(sdiff.tv_sec > cycle) && api->can_limit_work) } else if (unlikely(sdiff.tv_sec > cycle) && drv->can_limit_work)
max_nonce = max_nonce * cycle / sdiff.tv_sec; max_nonce = max_nonce * cycle / sdiff.tv_sec;
else if (unlikely(sdiff.tv_usec > 100000) && api->can_limit_work) else if (unlikely(sdiff.tv_usec > 100000) && drv->can_limit_work)
max_nonce = max_nonce * 0x400 / (((cycle * 1000000) + sdiff.tv_usec) / (cycle * 1000000 / 0x400)); max_nonce = max_nonce * 0x400 / (((cycle * 1000000) + sdiff.tv_usec) / (cycle * 1000000 / 0x400));
timersub(&tv_end, &tv_lastupdate, &diff); timersub(&tv_end, &tv_lastupdate, &diff);
@ -5466,7 +5466,7 @@ void *miner_thread(void *userdata)
} }
if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED)) if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED))
mt_disable(mythr, thr_id, api); mt_disable(mythr, thr_id, drv);
sdiff.tv_sec = sdiff.tv_usec = 0; sdiff.tv_sec = sdiff.tv_usec = 0;
} while (!abandon_work(work, &wdiff, cgpu->max_hashes)); } while (!abandon_work(work, &wdiff, cgpu->max_hashes));
@ -5474,8 +5474,8 @@ void *miner_thread(void *userdata)
} }
out: out:
if (api->thread_shutdown) if (drv->thread_shutdown)
api->thread_shutdown(mythr); drv->thread_shutdown(mythr);
thread_reportin(mythr); thread_reportin(mythr);
applog(LOG_ERR, "Thread %d failure, exiting", thr_id); applog(LOG_ERR, "Thread %d failure, exiting", thr_id);
@ -5703,8 +5703,8 @@ out:
void reinit_device(struct cgpu_info *cgpu) void reinit_device(struct cgpu_info *cgpu)
{ {
if (cgpu->api->reinit_device) if (cgpu->drv->reinit_device)
cgpu->api->reinit_device(cgpu); cgpu->drv->reinit_device(cgpu);
} }
static struct timeval rotate_tv; static struct timeval rotate_tv;
@ -5879,12 +5879,12 @@ static void *watchdog_thread(void __maybe_unused *userdata)
char dev_str[8]; char dev_str[8];
int gpu; int gpu;
if (cgpu->api->get_stats) if (cgpu->drv->get_stats)
cgpu->api->get_stats(cgpu); cgpu->drv->get_stats(cgpu);
gpu = cgpu->device_id; gpu = cgpu->device_id;
denable = &cgpu->deven; denable = &cgpu->deven;
sprintf(dev_str, "%s%d", cgpu->api->name, gpu); sprintf(dev_str, "%s%d", cgpu->drv->name, gpu);
#ifdef HAVE_ADL #ifdef HAVE_ADL
if (adl_active && cgpu->has_adl) if (adl_active && cgpu->has_adl)
@ -5904,7 +5904,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
continue; continue;
#ifdef WANT_CPUMINE #ifdef WANT_CPUMINE
if (!strcmp(cgpu->api->dname, "cpu")) if (cgpu->drv->drv != DRIVER_CPU)
continue; continue;
#endif #endif
if (cgpu->status != LIFE_WELL && (now.tv_sec - thr->last.tv_sec < WATCHDOG_SICK_TIME)) { if (cgpu->status != LIFE_WELL && (now.tv_sec - thr->last.tv_sec < WATCHDOG_SICK_TIME)) {
@ -6294,26 +6294,27 @@ void enable_curses(void) {
/* TODO: fix need a dummy CPU device_api even if no support for CPU mining */ /* TODO: fix need a dummy CPU device_api even if no support for CPU mining */
#ifndef WANT_CPUMINE #ifndef WANT_CPUMINE
struct device_api cpu_api; struct device_drv cpu_drv;
struct device_api cpu_api = { struct device_drv cpu_drv = {
.drv = DRIVER_CPU,
.name = "CPU", .name = "CPU",
}; };
#endif #endif
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
extern struct device_api bitforce_api; extern struct device_drv bitforce_drv;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
extern struct device_api icarus_api; extern struct device_drv icarus_drv;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
extern struct device_api modminer_api; extern struct device_drv modminer_drv;
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
extern struct device_api ztex_api; extern struct device_drv ztex_drv;
#endif #endif
@ -6328,7 +6329,7 @@ void enable_device(struct cgpu_info *cgpu)
adj_width(mining_threads, &dev_width); adj_width(mining_threads, &dev_width);
#endif #endif
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
if (cgpu->api == &opencl_api) { if (cgpu->drv->drv == DRIVER_OPENCL) {
gpu_threads += cgpu->threads; gpu_threads += cgpu->threads;
} }
#endif #endif
@ -6345,12 +6346,12 @@ bool add_cgpu(struct cgpu_info*cgpu)
static struct _cgpu_devid_counter *devids = NULL; static struct _cgpu_devid_counter *devids = NULL;
struct _cgpu_devid_counter *d; struct _cgpu_devid_counter *d;
HASH_FIND_STR(devids, cgpu->api->name, d); HASH_FIND_STR(devids, cgpu->drv->name, d);
if (d) if (d)
cgpu->device_id = ++d->lastid; cgpu->device_id = ++d->lastid;
else { else {
d = malloc(sizeof(*d)); d = malloc(sizeof(*d));
memcpy(d->name, cgpu->api->name, sizeof(d->name)); memcpy(d->name, cgpu->drv->name, sizeof(d->name));
cgpu->device_id = d->lastid = 0; cgpu->device_id = d->lastid = 0;
HASH_ADD_STR(devids, name, d); HASH_ADD_STR(devids, name, d);
} }
@ -6568,32 +6569,32 @@ int main(int argc, char *argv[])
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
if (!opt_nogpu) if (!opt_nogpu)
opencl_api.api_detect(); opencl_drv.drv_detect();
gpu_threads = 0; gpu_threads = 0;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (!opt_scrypt) if (!opt_scrypt)
icarus_api.api_detect(); icarus_drv.drv_detect();
#endif #endif
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (!opt_scrypt) if (!opt_scrypt)
bitforce_api.api_detect(); bitforce_drv.drv_detect();
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (!opt_scrypt) if (!opt_scrypt)
modminer_api.api_detect(); modminer_drv.drv_detect();
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (!opt_scrypt) if (!opt_scrypt)
ztex_api.api_detect(); ztex_drv.drv_detect();
#endif #endif
#ifdef WANT_CPUMINE #ifdef WANT_CPUMINE
cpu_api.api_detect(); cpu_drv.drv_detect();
#endif #endif
if (devices_enabled == -1) { if (devices_enabled == -1) {
@ -6601,9 +6602,9 @@ int main(int argc, char *argv[])
for (i = 0; i < total_devices; ++i) { for (i = 0; i < total_devices; ++i) {
struct cgpu_info *cgpu = devices[i]; struct cgpu_info *cgpu = devices[i];
if (cgpu->name) if (cgpu->name)
applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->name, cgpu->api->dname); applog(LOG_ERR, " %2d. %s %d: %s (driver: %s)", i, cgpu->drv->name, cgpu->device_id, cgpu->name, cgpu->drv->dname);
else else
applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->api->name, cgpu->device_id, cgpu->api->dname); applog(LOG_ERR, " %2d. %s %d (driver: %s)", i, cgpu->drv->name, cgpu->device_id, cgpu->drv->dname);
} }
quit(0, "%d devices listed", total_devices); quit(0, "%d devices listed", total_devices);
} }
@ -6617,7 +6618,7 @@ int main(int argc, char *argv[])
enable_device(devices[i]); enable_device(devices[i]);
} else if (i < total_devices) { } else if (i < total_devices) {
if (opt_removedisabled) { if (opt_removedisabled) {
if (devices[i]->api == &cpu_api) if (devices[i]->drv->drv == DRIVER_CPU)
--opt_n_threads; --opt_n_threads;
} else { } else {
enable_device(devices[i]); enable_device(devices[i]);
@ -6789,7 +6790,7 @@ begin_bench:
thr->q = tq_new(); thr->q = tq_new();
if (!thr->q) if (!thr->q)
quit(1, "tq_new failed in starting %s%d mining thread (#%d)", cgpu->api->name, cgpu->device_id, i); quit(1, "tq_new failed in starting %s%d mining thread (#%d)", cgpu->drv->name, cgpu->device_id, i);
/* Enable threads for devices set not to mine but disable /* Enable threads for devices set not to mine but disable
* their queue in case we wish to enable them later */ * their queue in case we wish to enable them later */
@ -6799,7 +6800,7 @@ begin_bench:
tq_push(thr->q, &ping); tq_push(thr->q, &ping);
} }
if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr)) if (cgpu->drv->thread_prepare && !cgpu->drv->thread_prepare(thr))
continue; continue;
thread_reportout(thr); thread_reportout(thr);

87
driver-bitforce.c

@ -64,7 +64,7 @@
static const char *blank = ""; static const char *blank = "";
struct device_api bitforce_api; struct device_drv bitforce_drv;
static void bitforce_initialise(struct cgpu_info *bitforce, bool lock) static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
{ {
@ -78,14 +78,14 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
FTDI_VALUE_RESET, bitforce->usbdev->found->interface, C_RESET); FTDI_VALUE_RESET, bitforce->usbdev->found->interface, C_RESET);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: reset got err %d", applog(LOG_DEBUG, "%s%i: reset got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Set data control // Set data control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
FTDI_VALUE_DATA, bitforce->usbdev->found->interface, C_SETDATA); FTDI_VALUE_DATA, bitforce->usbdev->found->interface, C_SETDATA);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: setdata got err %d", applog(LOG_DEBUG, "%s%i: setdata got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Set the baud // Set the baud
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD,
@ -93,35 +93,35 @@ static void bitforce_initialise(struct cgpu_info *bitforce, bool lock)
C_SETBAUD); C_SETBAUD);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: setbaud got err %d", applog(LOG_DEBUG, "%s%i: setbaud got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Set Flow Control // Set Flow Control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
FTDI_VALUE_FLOW, bitforce->usbdev->found->interface, C_SETFLOW); FTDI_VALUE_FLOW, bitforce->usbdev->found->interface, C_SETFLOW);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: setflowctrl got err %d", applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Set Modem Control // Set Modem Control
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
FTDI_VALUE_MODEM, bitforce->usbdev->found->interface, C_SETMODEM); FTDI_VALUE_MODEM, bitforce->usbdev->found->interface, C_SETMODEM);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d", applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Clear any sent data // Clear any sent data
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX); FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: purgetx got err %d", applog(LOG_DEBUG, "%s%i: purgetx got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
// Clear any received data // Clear any received data
err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX); FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX);
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%i: purgerx got err %d", applog(LOG_DEBUG, "%s%i: purgerx got err %d",
bitforce->api->name, bitforce->device_id, err); bitforce->drv->name, bitforce->device_id, err);
if (lock) if (lock)
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
@ -136,13 +136,13 @@ static bool bitforce_detect_one(struct libusb_device *dev, struct usb_find_devic
struct cgpu_info *bitforce = NULL; struct cgpu_info *bitforce = NULL;
bitforce = calloc(1, sizeof(*bitforce)); bitforce = calloc(1, sizeof(*bitforce));
bitforce->api = &bitforce_api; bitforce->drv = &bitforce_drv;
bitforce->deven = DEV_ENABLED; bitforce->deven = DEV_ENABLED;
bitforce->threads = 1; bitforce->threads = 1;
if (!usb_init(bitforce, dev, found)) { if (!usb_init(bitforce, dev, found)) {
applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)", applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
bitforce->api->dname, bitforce->drv->dname,
(int)libusb_get_bus_number(dev), (int)libusb_get_bus_number(dev),
(int)libusb_get_device_address(dev)); (int)libusb_get_device_address(dev));
goto shin; goto shin;
@ -159,7 +159,7 @@ reinit:
if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) { if ((err = usb_write(bitforce, BITFORCE_IDENTIFY, BITFORCE_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY)) < 0 || amount != BITFORCE_IDENTIFY_LEN) {
applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)", applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
bitforce->api->dname, devpath, amount, err); bitforce->drv->dname, devpath, amount, err);
goto unshin; goto unshin;
} }
@ -168,7 +168,7 @@ reinit:
if (++init_count <= REINIT_COUNT) { if (++init_count <= REINIT_COUNT) {
if (init_count < 2) { if (init_count < 2) {
applog(LOG_WARNING, "%s detect (%s) 1st init failed - retrying (%d:%d)", applog(LOG_WARNING, "%s detect (%s) 1st init failed - retrying (%d:%d)",
bitforce->api->dname, devpath, amount, err); bitforce->drv->dname, devpath, amount, err);
} }
nmsleep(REINIT_TIME_MS); nmsleep(REINIT_TIME_MS);
goto reinit; goto reinit;
@ -176,14 +176,14 @@ reinit:
if (init_count > 0) if (init_count > 0)
applog(LOG_WARNING, "%s detect (%s) init failed %d times", applog(LOG_WARNING, "%s detect (%s) init failed %d times",
bitforce->api->dname, devpath, init_count); bitforce->drv->dname, devpath, init_count);
if (err < 0) { if (err < 0) {
applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)", applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
bitforce->api->dname, devpath, amount, err); bitforce->drv->dname, devpath, amount, err);
} else { } else {
applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)", applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
bitforce->api->dname, devpath, amount); bitforce->drv->dname, devpath, amount);
} }
goto unshin; goto unshin;
@ -192,7 +192,7 @@ reinit:
if (unlikely(!strstr(buf, "SHA256"))) { if (unlikely(!strstr(buf, "SHA256"))) {
applog(LOG_ERR, "%s detect (%s) didn't recognise '%s'", applog(LOG_ERR, "%s detect (%s) didn't recognise '%s'",
bitforce->api->dname, devpath, buf); bitforce->drv->dname, devpath, buf);
goto unshin; goto unshin;
} }
@ -205,7 +205,7 @@ reinit:
// We have a real BitForce! // We have a real BitForce!
applog(LOG_DEBUG, "%s (%s) identified as: '%s'", applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
bitforce->api->dname, devpath, bitforce->name); bitforce->drv->dname, devpath, bitforce->name);
/* Initially enable support for nonce range and disable it later if it /* Initially enable support for nonce range and disable it later if it
* fails */ * fails */
@ -247,7 +247,7 @@ shin:
static void bitforce_detect(void) static void bitforce_detect(void)
{ {
usb_detect(&bitforce_api, bitforce_detect_one); usb_detect(&bitforce_drv, bitforce_detect_one);
} }
static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce) static void get_bitforce_statline_before(char *buf, struct cgpu_info *bitforce)
@ -288,7 +288,7 @@ static void bitforce_flash_led(struct cgpu_info *bitforce)
if ((err = usb_write(bitforce, BITFORCE_FLASH, BITFORCE_FLASH_LEN, &amount, C_REQUESTFLASH)) < 0 || amount != BITFORCE_FLASH_LEN) { if ((err = usb_write(bitforce, BITFORCE_FLASH, BITFORCE_FLASH_LEN, &amount, C_REQUESTFLASH)) < 0 || amount != BITFORCE_FLASH_LEN) {
applog(LOG_ERR, "%s%i: flash request failed (%d:%d)", applog(LOG_ERR, "%s%i: flash request failed (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
} else { } else {
/* However, this stops anything else getting a reply /* However, this stops anything else getting a reply
* So best to delay any other access to the BFL */ * So best to delay any other access to the BFL */
@ -328,7 +328,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
if ((err = usb_write(bitforce, BITFORCE_TEMPERATURE, BITFORCE_TEMPERATURE_LEN, &amount, C_REQUESTTEMPERATURE)) < 0 || amount != BITFORCE_TEMPERATURE_LEN) { if ((err = usb_write(bitforce, BITFORCE_TEMPERATURE, BITFORCE_TEMPERATURE_LEN, &amount, C_REQUESTTEMPERATURE)) < 0 || amount != BITFORCE_TEMPERATURE_LEN) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: Error: Request temp invalid/timed out (%d:%d)", applog(LOG_ERR, "%s%i: Error: Request temp invalid/timed out (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
bitforce->hw_errors++; bitforce->hw_errors++;
return false; return false;
} }
@ -337,10 +337,10 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
if (err < 0) { if (err < 0) {
applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)", applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
} else { } else {
applog(LOG_ERR, "%s%i: Error: Get temp returned nothing (%d:%d)", applog(LOG_ERR, "%s%i: Error: Get temp returned nothing (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
} }
bitforce->hw_errors++; bitforce->hw_errors++;
return false; return false;
@ -360,7 +360,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
bitforce->temp = temp; bitforce->temp = temp;
if (unlikely(bitforce->cutofftemp > 0 && temp > bitforce->cutofftemp)) { if (unlikely(bitforce->cutofftemp > 0 && temp > bitforce->cutofftemp)) {
applog(LOG_WARNING, "%s%i: Hit thermal cutoff limit, disabling!", applog(LOG_WARNING, "%s%i: Hit thermal cutoff limit, disabling!",
bitforce->api->name, bitforce->device_id); bitforce->drv->name, bitforce->device_id);
bitforce->deven = DEV_RECOVER; bitforce->deven = DEV_RECOVER;
dev_error(bitforce, REASON_DEV_THERMAL_CUTOFF); dev_error(bitforce, REASON_DEV_THERMAL_CUTOFF);
} }
@ -370,7 +370,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
* our responses are out of sync and flush the buffer to * our responses are out of sync and flush the buffer to
* hopefully recover */ * hopefully recover */
applog(LOG_WARNING, "%s%i: Garbled response probably throttling, clearing buffer", applog(LOG_WARNING, "%s%i: Garbled response probably throttling, clearing buffer",
bitforce->api->name, bitforce->device_id); bitforce->drv->name, bitforce->device_id);
dev_error(bitforce, REASON_DEV_THROTTLE); dev_error(bitforce, REASON_DEV_THROTTLE);
/* Count throttling episodes as hardware errors */ /* Count throttling episodes as hardware errors */
bitforce->hw_errors++; bitforce->hw_errors++;
@ -404,14 +404,14 @@ re_send:
if ((err = usb_write(bitforce, cmd, len, &amount, C_REQUESTSENDWORK)) < 0 || amount != len) { if ((err = usb_write(bitforce, cmd, len, &amount, C_REQUESTSENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: request send work failed (%d:%d)", applog(LOG_ERR, "%s%i: request send work failed (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
return false; return false;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) { if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)", applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
return false; return false;
} }
@ -423,14 +423,14 @@ re_send:
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
if (bitforce->nonce_range) { if (bitforce->nonce_range) {
applog(LOG_WARNING, "%s%i: Does not support nonce range, disabling", applog(LOG_WARNING, "%s%i: Does not support nonce range, disabling",
bitforce->api->name, bitforce->device_id); bitforce->drv->name, bitforce->device_id);
bitforce->nonce_range = false; bitforce->nonce_range = false;
bitforce->sleep_ms *= 5; bitforce->sleep_ms *= 5;
bitforce->kname = KNAME_WORK; bitforce->kname = KNAME_WORK;
goto re_send; goto re_send;
} }
applog(LOG_ERR, "%s%i: Error: Send work reports: %s", applog(LOG_ERR, "%s%i: Error: Send work reports: %s",
bitforce->api->name, bitforce->device_id, buf); bitforce->drv->name, bitforce->device_id, buf);
return false; return false;
} }
@ -458,14 +458,14 @@ re_send:
if ((err = usb_write(bitforce, (char *)ob, len, &amount, C_SENDWORK)) < 0 || amount != len) { if ((err = usb_write(bitforce, (char *)ob, len, &amount, C_SENDWORK)) < 0 || amount != len) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%i: send work failed (%d:%d)", applog(LOG_ERR, "%s%i: send work failed (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
return false; return false;
} }
if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) { if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) {
mutex_unlock(&bitforce->device_mutex); mutex_unlock(&bitforce->device_mutex);
applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)", applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)",
bitforce->api->name, bitforce->device_id, amount, err); bitforce->drv->name, bitforce->device_id, amount, err);
return false; return false;
} }
@ -474,19 +474,19 @@ re_send:
if (opt_debug) { if (opt_debug) {
s = bin2hex(ob + 8, 44); s = bin2hex(ob + 8, 44);
applog(LOG_DEBUG, "%s%i: block data: %s", applog(LOG_DEBUG, "%s%i: block data: %s",
bitforce->api->name, bitforce->device_id, s); bitforce->drv->name, bitforce->device_id, s);
free(s); free(s);
} }
if (amount == 0 || !buf[0]) { if (amount == 0 || !buf[0]) {
applog(LOG_ERR, "%s%i: Error: Send block data returned empty string/timed out", applog(LOG_ERR, "%s%i: Error: Send block data returned empty string/timed out",
bitforce->api->name, bitforce->device_id); bitforce->drv->name, bitforce->device_id);
return false; return false;
} }
if (unlikely(strncasecmp(buf, "OK", 2))) { if (unlikely(strncasecmp(buf, "OK", 2))) {
applog(LOG_ERR, "%s%i: Error: Send block data reports: %s", applog(LOG_ERR, "%s%i: Error: Send block data reports: %s",
bitforce->api->name, bitforce->device_id, buf); bitforce->drv->name, bitforce->device_id, buf);
return false; return false;
} }
@ -519,7 +519,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) { if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %dms - longer than %dms", applog(LOG_ERR, "%s%i: took %dms - longer than %dms",
bitforce->api->name, bitforce->device_id, bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS); tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
return 0; return 0;
} }
@ -535,7 +535,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) { if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
applog(LOG_ERR, "%s%i: took %dms - longer than %dms", applog(LOG_ERR, "%s%i: took %dms - longer than %dms",
bitforce->api->name, bitforce->device_id, bitforce->drv->name, bitforce->device_id,
tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS); tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
dev_error(bitforce, REASON_DEV_OVER_HEAT); dev_error(bitforce, REASON_DEV_OVER_HEAT);
@ -560,7 +560,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (delay_time_ms != bitforce->sleep_ms) if (delay_time_ms != bitforce->sleep_ms)
applog(LOG_DEBUG, "%s%i: Wait time changed to: %d, waited %u", applog(LOG_DEBUG, "%s%i: Wait time changed to: %d, waited %u",
bitforce->api->name, bitforce->device_id, bitforce->drv->name, bitforce->device_id,
bitforce->sleep_ms, bitforce->wait_ms); bitforce->sleep_ms, bitforce->wait_ms);
/* Work out the average time taken. Float for calculation, uint for display */ /* Work out the average time taken. Float for calculation, uint for display */
@ -569,7 +569,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
} }
applog(LOG_DEBUG, "%s%i: waited %dms until %s", applog(LOG_DEBUG, "%s%i: waited %dms until %s",
bitforce->api->name, bitforce->device_id, bitforce->drv->name, bitforce->device_id,
bitforce->wait_ms, buf); bitforce->wait_ms, buf);
if (!strncasecmp(&buf[2], "-", 1)) if (!strncasecmp(&buf[2], "-", 1))
return bitforce->nonces; /* No valid nonce found */ return bitforce->nonces; /* No valid nonce found */
@ -578,7 +578,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
else if (strncasecmp(buf, "NONCE-FOUND", 11)) { else if (strncasecmp(buf, "NONCE-FOUND", 11)) {
bitforce->hw_errors++; bitforce->hw_errors++;
applog(LOG_WARNING, "%s%i: Error: Get result reports: %s", applog(LOG_WARNING, "%s%i: Error: Get result reports: %s",
bitforce->api->name, bitforce->device_id, buf); bitforce->drv->name, bitforce->device_id, buf);
bitforce_initialise(bitforce, true); bitforce_initialise(bitforce, true);
return 0; return 0;
} }
@ -593,7 +593,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (unlikely(bitforce->nonce_range && (nonce >= work->blk.nonce || if (unlikely(bitforce->nonce_range && (nonce >= work->blk.nonce ||
(work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) { (work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) {
applog(LOG_WARNING, "%s%i: Disabling broken nonce range support", applog(LOG_WARNING, "%s%i: Disabling broken nonce range support",
bitforce->api->name, bitforce->device_id); bitforce->drv->name, bitforce->device_id);
bitforce->nonce_range = false; bitforce->nonce_range = false;
work->blk.nonce = 0xffffffff; work->blk.nonce = 0xffffffff;
bitforce->sleep_ms *= 5; bitforce->sleep_ms *= 5;
@ -643,7 +643,7 @@ static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_
if (ret == -1) { if (ret == -1) {
ret = 0; ret = 0;
applog(LOG_ERR, "%s%i: Comms error", bitforce->api->name, bitforce->device_id); applog(LOG_ERR, "%s%i: Comms error", bitforce->drv->name, bitforce->device_id);
dev_error(bitforce, REASON_DEV_COMMS_ERROR); dev_error(bitforce, REASON_DEV_COMMS_ERROR);
bitforce->hw_errors++; bitforce->hw_errors++;
/* empty read buffer */ /* empty read buffer */
@ -671,7 +671,7 @@ static bool bitforce_thread_init(struct thr_info *thr)
* so the devices aren't making calls all at the same time. */ * so the devices aren't making calls all at the same time. */
wait = thr->id * MAX_START_DELAY_MS; wait = thr->id * MAX_START_DELAY_MS;
applog(LOG_DEBUG, "%s%d: Delaying start by %dms", applog(LOG_DEBUG, "%s%d: Delaying start by %dms",
bitforce->api->name, bitforce->device_id, wait / 1000); bitforce->drv->name, bitforce->device_id, wait / 1000);
nmsleep(wait); nmsleep(wait);
return true; return true;
@ -691,10 +691,11 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
return root; return root;
} }
struct device_api bitforce_api = { struct device_drv bitforce_drv = {
.drv = DRIVER_BITFORCE,
.dname = "bitforce", .dname = "bitforce",
.name = "BFL", .name = "BFL",
.api_detect = bitforce_detect, .drv_detect = bitforce_detect,
.get_api_stats = bitforce_api_stats, .get_api_stats = bitforce_api_stats,
.get_statline_before = get_bitforce_statline_before, .get_statline_before = get_bitforce_statline_before,
.get_stats = bitforce_get_stats, .get_stats = bitforce_get_stats,

6
driver-cpu.c

@ -758,7 +758,7 @@ static void cpu_detect()
struct cgpu_info *cgpu; struct cgpu_info *cgpu;
cgpu = &cpus[i]; cgpu = &cpus[i];
cgpu->api = &cpu_api; cgpu->drv = &cpu_drv;
cgpu->deven = DEV_ENABLED; cgpu->deven = DEV_ENABLED;
cgpu->threads = 1; cgpu->threads = 1;
cgpu->kname = algo_names[opt_algo]; cgpu->kname = algo_names[opt_algo];
@ -843,10 +843,10 @@ CPUSearch:
return last_nonce - first_nonce + 1; return last_nonce - first_nonce + 1;
} }
struct device_api cpu_api = { struct device_drv cpu_drv = {
.dname = "cpu", .dname = "cpu",
.name = "CPU", .name = "CPU",
.api_detect = cpu_detect, .drv_detect = cpu_detect,
.reinit_device = reinit_cpu_device, .reinit_device = reinit_cpu_device,
.thread_prepare = cpu_thread_prepare, .thread_prepare = cpu_thread_prepare,
.can_limit_work = cpu_can_limit_work, .can_limit_work = cpu_can_limit_work,

2
driver-cpu.h

@ -53,7 +53,7 @@ enum sha256_algos {
extern const char *algo_names[]; extern const char *algo_names[];
extern bool opt_usecpu; extern bool opt_usecpu;
extern struct device_api cpu_api; extern struct device_drv cpu_drv;
extern char *set_algo(const char *arg, enum sha256_algos *algo); extern char *set_algo(const char *arg, enum sha256_algos *algo);
extern void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo); extern void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo);

11
driver-icarus.c

@ -208,7 +208,7 @@ static struct ICARUS_INFO **icarus_info;
// //
static int option_offset = -1; static int option_offset = -1;
struct device_api icarus_api; struct device_drv icarus_drv;
static void rev(unsigned char *s, size_t l) static void rev(unsigned char *s, size_t l)
{ {
@ -571,7 +571,7 @@ static bool icarus_detect_one(const char *devpath)
/* We have a real Icarus! */ /* We have a real Icarus! */
struct cgpu_info *icarus; struct cgpu_info *icarus;
icarus = calloc(1, sizeof(struct cgpu_info)); icarus = calloc(1, sizeof(struct cgpu_info));
icarus->api = &icarus_api; icarus->drv = &icarus_drv;
icarus->device_path = strdup(devpath); icarus->device_path = strdup(devpath);
icarus->device_fd = -1; icarus->device_fd = -1;
icarus->threads = 1; icarus->threads = 1;
@ -609,7 +609,7 @@ static bool icarus_detect_one(const char *devpath)
static void icarus_detect() static void icarus_detect()
{ {
serial_detect(&icarus_api, icarus_detect_one); serial_detect(&icarus_drv, icarus_detect_one);
} }
static bool icarus_prepare(struct thr_info *thr) static bool icarus_prepare(struct thr_info *thr)
@ -900,10 +900,11 @@ static void icarus_shutdown(struct thr_info *thr)
do_icarus_close(thr); do_icarus_close(thr);
} }
struct device_api icarus_api = { struct device_drv icarus_drv = {
.drv = DRIVER_ICARUS,
.dname = "icarus", .dname = "icarus",
.name = "ICA", .name = "ICA",
.api_detect = icarus_detect, .drv_detect = icarus_detect,
.get_api_stats = icarus_api_stats, .get_api_stats = icarus_api_stats,
.thread_prepare = icarus_prepare, .thread_prepare = icarus_prepare,
.scanhash = icarus_scanhash, .scanhash = icarus_scanhash,

93
driver-modminer.c

@ -87,7 +87,7 @@
// Limit when reducing shares_to_good // Limit when reducing shares_to_good
#define MODMINER_MIN_BACK 12 #define MODMINER_MIN_BACK 12
struct device_api modminer_api; struct device_drv modminer_drv;
// 45 noops sent when detecting, in case the device was left in "start job" reading // 45 noops sent when detecting, in case the device was left in "start job" reading
static const char NOOP[] = MODMINER_PING "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"; static const char NOOP[] = MODMINER_PING "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff";
@ -100,15 +100,15 @@ static void do_ping(struct cgpu_info *modminer)
// Don't care if it fails // Don't care if it fails
err = usb_write(modminer, (char *)NOOP, sizeof(NOOP)-1, &amount, C_PING); err = usb_write(modminer, (char *)NOOP, sizeof(NOOP)-1, &amount, C_PING);
applog(LOG_DEBUG, "%s%u: flush noop got %d err %d", applog(LOG_DEBUG, "%s%u: flush noop got %d err %d",
modminer->api->name, modminer->fpgaid, amount, err); modminer->drv->name, modminer->fpgaid, amount, err);
// Clear any outstanding data // Clear any outstanding data
while ((err = usb_read(modminer, buf, sizeof(buf)-1, &amount, C_CLEAR)) == 0 && amount > 0) while ((err = usb_read(modminer, buf, sizeof(buf)-1, &amount, C_CLEAR)) == 0 && amount > 0)
applog(LOG_DEBUG, "%s%u: clear got %d", applog(LOG_DEBUG, "%s%u: clear got %d",
modminer->api->name, modminer->fpgaid, amount); modminer->drv->name, modminer->fpgaid, amount);
applog(LOG_DEBUG, "%s%u: final clear got %d err %d", applog(LOG_DEBUG, "%s%u: final clear got %d err %d",
modminer->api->name, modminer->fpgaid, amount, err); modminer->drv->name, modminer->fpgaid, amount, err);
} }
static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found) static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
@ -121,7 +121,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
struct cgpu_info *modminer = NULL; struct cgpu_info *modminer = NULL;
modminer = calloc(1, sizeof(*modminer)); modminer = calloc(1, sizeof(*modminer));
modminer->api = &modminer_api; modminer->drv = &modminer_drv;
modminer->modminer_mutex = calloc(1, sizeof(*(modminer->modminer_mutex))); modminer->modminer_mutex = calloc(1, sizeof(*(modminer->modminer_mutex)));
mutex_init(modminer->modminer_mutex); mutex_init(modminer->modminer_mutex);
modminer->fpgaid = (char)0; modminer->fpgaid = (char)0;
@ -182,7 +182,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic
for (i = 0; i < buf[0]; i++) { for (i = 0; i < buf[0]; i++) {
struct cgpu_info *tmp = calloc(1, sizeof(*tmp)); struct cgpu_info *tmp = calloc(1, sizeof(*tmp));
tmp->api = modminer->api; tmp->drv = modminer->drv;
tmp->name = devname; tmp->name = devname;
sprintf(devpath, "%d:%d:%d", sprintf(devpath, "%d:%d:%d",
@ -233,7 +233,7 @@ shin:
static void modminer_detect() static void modminer_detect()
{ {
usb_detect(&modminer_api, modminer_detect_one); usb_detect(&modminer_drv, modminer_detect_one);
} }
static bool get_expect(struct cgpu_info *modminer, FILE *f, char c) static bool get_expect(struct cgpu_info *modminer, FILE *f, char c)
@ -242,13 +242,13 @@ static bool get_expect(struct cgpu_info *modminer, FILE *f, char c)
if (fread(&buf, 1, 1, f) != 1) { if (fread(&buf, 1, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream (%c)", applog(LOG_ERR, "%s%u: Error (%d) reading bitstream (%c)",
modminer->api->name, modminer->device_id, errno, c); modminer->drv->name, modminer->device_id, errno, c);
return false; return false;
} }
if (buf != c) { if (buf != c) {
applog(LOG_ERR, "%s%u: firmware code mismatch (%c)", applog(LOG_ERR, "%s%u: firmware code mismatch (%c)",
modminer->api->name, modminer->device_id, c); modminer->drv->name, modminer->device_id, c);
return false; return false;
} }
@ -262,7 +262,7 @@ static bool get_info(struct cgpu_info *modminer, FILE *f, char *buf, int bufsiz,
if (fread(siz, 2, 1, f) != 1) { if (fread(siz, 2, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s' len", applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s' len",
modminer->api->name, modminer->device_id, errno, name); modminer->drv->name, modminer->device_id, errno, name);
return false; return false;
} }
@ -270,13 +270,13 @@ static bool get_info(struct cgpu_info *modminer, FILE *f, char *buf, int bufsiz,
if (len >= bufsiz) { if (len >= bufsiz) {
applog(LOG_ERR, "%s%u: Bitstream '%s' len too large (%d)", applog(LOG_ERR, "%s%u: Bitstream '%s' len too large (%d)",
modminer->api->name, modminer->device_id, name, len); modminer->drv->name, modminer->device_id, name, len);
return false; return false;
} }
if (fread(buf, len, 1, f) != 1) { if (fread(buf, len, 1, f) != 1) {
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s'", errno, applog(LOG_ERR, "%s%u: Error (%d) reading bitstream '%s'", errno,
modminer->api->name, modminer->device_id, errno, name); modminer->drv->name, modminer->device_id, errno, name);
return false; return false;
} }
@ -302,7 +302,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d:%d) getting %s reply", applog(LOG_ERR, "%s%u: Error (%d:%d) getting %s reply",
modminer->api->name, modminer->device_id, amount, err, msg); modminer->drv->name, modminer->device_id, amount, err, msg);
return false; return false;
} }
@ -311,7 +311,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error, invalid %s reply (was %d should be 1)", applog(LOG_ERR, "%s%u: Error, invalid %s reply (was %d should be 1)",
modminer->api->name, modminer->device_id, msg, buf[0]); modminer->drv->name, modminer->device_id, msg, buf[0]);
return false; return false;
} }
@ -343,7 +343,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) opening bitstream file %s", applog(LOG_ERR, "%s%u: Error (%d) opening bitstream file %s",
modminer->api->name, modminer->device_id, errno, bsfile); modminer->drv->name, modminer->device_id, errno, bsfile);
return false; return false;
} }
@ -352,7 +352,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream magic", applog(LOG_ERR, "%s%u: Error (%d) reading bitstream magic",
modminer->api->name, modminer->device_id, errno); modminer->drv->name, modminer->device_id, errno);
goto dame; goto dame;
} }
@ -361,7 +361,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream has incorrect magic (%u,%u) instead of (%u,%u)", applog(LOG_ERR, "%s%u: bitstream has incorrect magic (%u,%u) instead of (%u,%u)",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
buf[0], buf[1], buf[0], buf[1],
BITSTREAM_MAGIC_0, BITSTREAM_MAGIC_1); BITSTREAM_MAGIC_0, BITSTREAM_MAGIC_1);
@ -372,7 +372,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) bitstream seek failed", applog(LOG_ERR, "%s%u: Error (%d) bitstream seek failed",
modminer->api->name, modminer->device_id, errno); modminer->drv->name, modminer->device_id, errno);
goto dame; goto dame;
} }
@ -384,7 +384,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
goto undame; goto undame;
applog(LOG_DEBUG, "%s%u: bitstream file '%s' info:", applog(LOG_DEBUG, "%s%u: bitstream file '%s' info:",
modminer->api->name, modminer->device_id, bsfile); modminer->drv->name, modminer->device_id, bsfile);
applog(LOG_DEBUG, " Design name: '%s'", buf); applog(LOG_DEBUG, " Design name: '%s'", buf);
@ -399,7 +399,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Bad usercode in bitstream file", applog(LOG_ERR, "%s%u: Bad usercode in bitstream file",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
goto dame; goto dame;
} }
@ -408,7 +408,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream doesn't support user code", applog(LOG_ERR, "%s%u: bitstream doesn't support user code",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
goto dame; goto dame;
} }
@ -446,7 +446,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error (%d) reading bitstream data len", applog(LOG_ERR, "%s%u: Error (%d) reading bitstream data len",
modminer->api->name, modminer->device_id, errno); modminer->drv->name, modminer->device_id, errno);
goto dame; goto dame;
} }
@ -460,7 +460,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
*ptr = '\0'; *ptr = '\0';
applog(LOG_WARNING, "%s%u: Programming all FPGA on %s ... Mining will not start until complete", applog(LOG_WARNING, "%s%u: Programming all FPGA on %s ... Mining will not start until complete",
modminer->api->name, modminer->device_id, devmsg); modminer->drv->name, modminer->device_id, devmsg);
buf[0] = MODMINER_PROGRAM; buf[0] = MODMINER_PROGRAM;
buf[1] = fpgaid; buf[1] = fpgaid;
@ -473,7 +473,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Program init failed (%d:%d)", applog(LOG_ERR, "%s%u: Program init failed (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
goto dame; goto dame;
} }
@ -492,7 +492,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: bitstream file read error %d (%d bytes left)", applog(LOG_ERR, "%s%u: bitstream file read error %d (%d bytes left)",
modminer->api->name, modminer->device_id, errno, len); modminer->drv->name, modminer->device_id, errno, len);
goto dame; goto dame;
} }
@ -507,7 +507,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "%s%u: Program timeout (%d:%d) sent %d tries %d", applog(LOG_DEBUG, "%s%u: Program timeout (%d:%d) sent %d tries %d",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
amount, err, remaining, tries); amount, err, remaining, tries);
if (!get_status(modminer, "write status", C_PROGRAMSTATUS2)) if (!get_status(modminer, "write status", C_PROGRAMSTATUS2))
@ -517,7 +517,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Program failed (%d:%d) sent %d", applog(LOG_ERR, "%s%u: Program failed (%d:%d) sent %d",
modminer->api->name, modminer->device_id, amount, err, remaining); modminer->drv->name, modminer->device_id, amount, err, remaining);
goto dame; goto dame;
} }
@ -532,7 +532,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
if (upto >= nextmsg) { if (upto >= nextmsg) {
applog(LOG_WARNING, applog(LOG_WARNING,
"%s%u: Programming %.1f%% (%d out of %d)", "%s%u: Programming %.1f%% (%d out of %d)",
modminer->api->name, modminer->device_id, upto*100, (totlen - len), totlen); modminer->drv->name, modminer->device_id, upto*100, (totlen - len), totlen);
nextmsg += 0.1; nextmsg += 0.1;
} }
@ -542,7 +542,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer)
goto undame; goto undame;
applog(LOG_WARNING, "%s%u: Programming completed for all FPGA on %s", applog(LOG_WARNING, "%s%u: Programming completed for all FPGA on %s",
modminer->api->name, modminer->device_id, devmsg); modminer->drv->name, modminer->device_id, devmsg);
// Give it a 2/3s delay after programming // Give it a 2/3s delay after programming
nmsleep(666); nmsleep(666);
@ -653,7 +653,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error writing set clock speed (%d:%d)", applog(LOG_ERR, "%s%u: Error writing set clock speed (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return clocksetfail; return clocksetfail;
} }
@ -662,7 +662,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error reading set clock speed (%d:%d)", applog(LOG_ERR, "%s%u: Error reading set clock speed (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return clockreplyfail; return clockreplyfail;
} }
@ -670,7 +670,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_WARNING, "%s%u: Set clock speed %sto %u", applog(LOG_WARNING, "%s%u: Set clock speed %sto %u",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
(delta < 0) ? "down " : (delta > 0 ? "up " : ""), (delta < 0) ? "down " : (delta > 0 ? "up " : ""),
modminer->clock); modminer->clock);
@ -691,7 +691,7 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error requesting USER code (%d:%d)", applog(LOG_ERR, "%s%u: Error requesting USER code (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return false; return false;
} }
@ -700,14 +700,14 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Error reading USER code (%d:%d)", applog(LOG_ERR, "%s%u: Error reading USER code (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return false; return false;
} }
if (memcmp(buf, BISTREAM_USER_ID, 4)) { if (memcmp(buf, BISTREAM_USER_ID, 4)) {
applog(LOG_ERR, "%s%u: FPGA not programmed", applog(LOG_ERR, "%s%u: FPGA not programmed",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
if (!modminer_fpga_upload_bitstream(modminer)) if (!modminer_fpga_upload_bitstream(modminer))
return false; return false;
@ -717,7 +717,7 @@ static bool modminer_fpga_init(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_DEBUG, "%s%u: FPGA is already programmed :)", applog(LOG_DEBUG, "%s%u: FPGA is already programmed :)",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
} }
modminer->clock = MODMINER_DEF_CLOCK; modminer->clock = MODMINER_DEF_CLOCK;
@ -773,7 +773,7 @@ static bool modminer_start_work(struct thr_info *thr)
mutex_unlock(modminer->modminer_mutex); mutex_unlock(modminer->modminer_mutex);
applog(LOG_ERR, "%s%u: Start work failed (%d:%d)", applog(LOG_ERR, "%s%u: Start work failed (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return false; return false;
} }
@ -827,14 +827,14 @@ static void check_temperature(struct thr_info *thr)
if (modminer->temp < MODMINER_RECOVER_TEMP) { if (modminer->temp < MODMINER_RECOVER_TEMP) {
state->overheated = false; state->overheated = false;
applog(LOG_WARNING, "%s%u: Recovered, temp less than (%.1f) now %.3f", applog(LOG_WARNING, "%s%u: Recovered, temp less than (%.1f) now %.3f",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
MODMINER_RECOVER_TEMP, modminer->temp); MODMINER_RECOVER_TEMP, modminer->temp);
} }
} }
else if (modminer->temp >= MODMINER_OVERHEAT_TEMP) { else if (modminer->temp >= MODMINER_OVERHEAT_TEMP) {
if (modminer->temp >= MODMINER_CUTOFF_TEMP) { if (modminer->temp >= MODMINER_CUTOFF_TEMP) {
applog(LOG_WARNING, "%s%u: Hit thermal cutoff limit! (%.1f) at %.3f", applog(LOG_WARNING, "%s%u: Hit thermal cutoff limit! (%.1f) at %.3f",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
MODMINER_CUTOFF_TEMP, modminer->temp); MODMINER_CUTOFF_TEMP, modminer->temp);
modminer_delta_clock(thr, MODMINER_CLOCK_CUTOFF, true, false); modminer_delta_clock(thr, MODMINER_CLOCK_CUTOFF, true, false);
@ -842,7 +842,7 @@ static void check_temperature(struct thr_info *thr)
dev_error(modminer, REASON_DEV_THERMAL_CUTOFF); dev_error(modminer, REASON_DEV_THERMAL_CUTOFF);
} else { } else {
applog(LOG_WARNING, "%s%u: Overheat limit (%.1f) reached %.3f", applog(LOG_WARNING, "%s%u: Overheat limit (%.1f) reached %.3f",
modminer->api->name, modminer->device_id, modminer->drv->name, modminer->device_id,
MODMINER_OVERHEAT_TEMP, modminer->temp); MODMINER_OVERHEAT_TEMP, modminer->temp);
// If it's defined to be 0 then don't call modminer_delta_clock() // If it's defined to be 0 then don't call modminer_delta_clock()
@ -909,7 +909,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
} }
applog(LOG_ERR, "%s%u: Error sending (get nonce) (%d:%d)", applog(LOG_ERR, "%s%u: Error sending (get nonce) (%d:%d)",
modminer->api->name, modminer->device_id, amount, err); modminer->drv->name, modminer->device_id, amount, err);
return -1; return -1;
} }
@ -936,7 +936,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
} }
applog(LOG_ERR, "%s%u: Error reading (get nonce) (%d:%d)", applog(LOG_ERR, "%s%u: Error reading (get nonce) (%d:%d)",
modminer->api->name, modminer->device_id, amount+amount2, err); modminer->drv->name, modminer->device_id, amount+amount2, err);
} }
if (memcmp(&nonce, "\xff\xff\xff\xff", 4)) { if (memcmp(&nonce, "\xff\xff\xff\xff", 4)) {
@ -975,7 +975,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
if (state->death_stage_one) { if (state->death_stage_one) {
modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true); modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true);
applog(LOG_ERR, "%s%u: DEATH clock down", applog(LOG_ERR, "%s%u: DEATH clock down",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
// reset the death info and DISABLE it // reset the death info and DISABLE it
state->last_nonce.tv_sec = 0; state->last_nonce.tv_sec = 0;
@ -985,7 +985,7 @@ static uint64_t modminer_process_results(struct thr_info *thr)
} else { } else {
modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true); modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true);
applog(LOG_ERR, "%s%u: death clock down", applog(LOG_ERR, "%s%u: death clock down",
modminer->api->name, modminer->device_id); modminer->drv->name, modminer->device_id);
state->death_stage_one = true; state->death_stage_one = true;
} }
@ -1141,10 +1141,11 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char
return replybuf; return replybuf;
} }
struct device_api modminer_api = { struct device_drv modminer_drv = {
.drv = DRIVER_MODMINER,
.dname = "modminer", .dname = "modminer",
.name = "MMQ", .name = "MMQ",
.api_detect = modminer_detect, .drv_detect = modminer_detect,
.get_statline_before = get_modminer_statline_before, .get_statline_before = get_modminer_statline_before,
.set_device = modminer_set_device, .set_device = modminer_set_device,
.thread_prepare = modminer_fpga_prepare, .thread_prepare = modminer_fpga_prepare,

38
driver-opencl.c

@ -50,24 +50,24 @@ extern int gpur_thr_id;
extern bool opt_noadl; extern bool opt_noadl;
extern bool have_opencl; extern bool have_opencl;
extern void *miner_thread(void *userdata); extern void *miner_thread(void *userdata);
extern int dev_from_id(int thr_id); extern int dev_from_id(int thr_id);
extern void tailsprintf(char *f, const char *fmt, ...); extern void tailsprintf(char *f, const char *fmt, ...);
extern void wlog(const char *f, ...); extern void wlog(const char *f, ...);
extern void decay_time(double *f, double fadd); extern void decay_time(double *f, double fadd);
/**********************************************/ /**********************************************/
#ifdef HAVE_OPENCL
struct device_drv opencl_drv;
#endif
#ifdef HAVE_ADL #ifdef HAVE_ADL
extern float gpu_temp(int gpu); extern float gpu_temp(int gpu);
extern int gpu_fanspeed(int gpu); extern int gpu_fanspeed(int gpu);
extern int gpu_fanpercent(int gpu); extern int gpu_fanpercent(int gpu);
#endif #endif
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
char *set_vector(char *arg) char *set_vector(char *arg)
{ {
@ -591,28 +591,20 @@ char *set_intensity(char *arg)
return NULL; return NULL;
} }
#endif
#ifdef HAVE_OPENCL
struct device_api opencl_api;
char *print_ndevs_and_exit(int *ndevs) char *print_ndevs_and_exit(int *ndevs)
{ {
opt_log_output = true; opt_log_output = true;
opencl_api.api_detect(); opencl_drv.drv_detect();
clear_adl(*ndevs); clear_adl(*ndevs);
applog(LOG_INFO, "%i GPU devices max detected", *ndevs); applog(LOG_INFO, "%i GPU devices max detected", *ndevs);
exit(*ndevs); exit(*ndevs);
} }
#endif #endif
struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */ struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
struct cgpu_info *cpus; struct cgpu_info *cpus;
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
/* In dynamic mode, only the first thread of each device will be in use. /* In dynamic mode, only the first thread of each device will be in use.
@ -637,9 +629,6 @@ void pause_dynamic_threads(int gpu)
} }
} }
struct device_api opencl_api;
#endif /* HAVE_OPENCL */ #endif /* HAVE_OPENCL */
#if defined(HAVE_OPENCL) && defined(HAVE_CURSES) #if defined(HAVE_OPENCL) && defined(HAVE_CURSES)
@ -773,7 +762,7 @@ retry:
for (i = 0; i < mining_threads; ++i) { for (i = 0; i < mining_threads; ++i) {
thr = &thr_info[i]; thr = &thr_info[i];
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->api != &opencl_api) if (cgpu->drv->drv != DRIVER_OPENCL)
continue; continue;
if (dev_from_id(i) != selected) if (dev_from_id(i) != selected)
continue; continue;
@ -1160,7 +1149,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) { for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = &thr_info[thr_id]; thr = &thr_info[thr_id];
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->api != &opencl_api) if (cgpu->drv->drv != DRIVER_OPENCL)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1185,7 +1174,7 @@ select_cgpu:
thr = &thr_info[thr_id]; thr = &thr_info[thr_id];
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->api != &opencl_api) if (cgpu->drv->drv != DRIVER_OPENCL)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1222,7 +1211,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) { for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = &thr_info[thr_id]; thr = &thr_info[thr_id];
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->api != &opencl_api) if (cgpu->drv->drv != DRIVER_OPENCL)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1243,8 +1232,6 @@ void *reinit_gpu(__maybe_unused void *userdata)
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
struct device_api opencl_api;
static void opencl_detect() static void opencl_detect()
{ {
int i; int i;
@ -1263,7 +1250,7 @@ static void opencl_detect()
cgpu = &gpus[i]; cgpu = &gpus[i];
cgpu->deven = DEV_ENABLED; cgpu->deven = DEV_ENABLED;
cgpu->api = &opencl_api; cgpu->drv = &opencl_drv;
cgpu->device_id = i; cgpu->device_id = i;
cgpu->threads = opt_g_threads; cgpu->threads = opt_g_threads;
cgpu->virtual_gpu = i; cgpu->virtual_gpu = i;
@ -1570,10 +1557,11 @@ static void opencl_thread_shutdown(struct thr_info *thr)
clReleaseContext(clState->context); clReleaseContext(clState->context);
} }
struct device_api opencl_api = { struct device_drv opencl_drv = {
.drv = DRIVER_OPENCL,
.dname = "opencl", .dname = "opencl",
.name = "GPU", .name = "GPU",
.api_detect = opencl_detect, .drv_detect = opencl_detect,
.reinit_device = reinit_opencl_device, .reinit_device = reinit_opencl_device,
#ifdef HAVE_ADL #ifdef HAVE_ADL
.get_statline_before = get_opencl_statline_before, .get_statline_before = get_opencl_statline_before,

2
driver-opencl.h

@ -30,6 +30,6 @@ extern void pause_dynamic_threads(int gpu);
extern bool have_opencl; extern bool have_opencl;
extern int opt_platform_id; extern int opt_platform_id;
extern struct device_api opencl_api; extern struct device_drv opencl_drv;
#endif /* __DEVICE_GPU_H__ */ #endif /* __DEVICE_GPU_H__ */

10
driver-ztex.c

@ -30,7 +30,7 @@
#define GOLDEN_BACKLOG 5 #define GOLDEN_BACKLOG 5
struct device_api ztex_api; struct device_drv ztex_drv;
// Forward declarations // Forward declarations
static void ztex_disable(struct thr_info* thr); static void ztex_disable(struct thr_info* thr);
@ -68,7 +68,7 @@ static void ztex_detect(void)
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
ztex = calloc(1, sizeof(struct cgpu_info)); ztex = calloc(1, sizeof(struct cgpu_info));
ztex->api = &ztex_api; ztex->drv = &ztex_drv;
ztex->device_ztex = ztex_devices[i]->dev; ztex->device_ztex = ztex_devices[i]->dev;
ztex->threads = 1; ztex->threads = 1;
ztex->device_ztex->fpgaNum = 0; ztex->device_ztex->fpgaNum = 0;
@ -82,7 +82,7 @@ static void ztex_detect(void)
for (j = 1; j < fpgacount; j++) { for (j = 1; j < fpgacount; j++) {
ztex = calloc(1, sizeof(struct cgpu_info)); ztex = calloc(1, sizeof(struct cgpu_info));
ztex->api = &ztex_api; ztex->drv = &ztex_drv;
ztex_slave = calloc(1, sizeof(struct libztex_device)); ztex_slave = calloc(1, sizeof(struct libztex_device));
memcpy(ztex_slave, ztex_devices[i]->dev, sizeof(struct libztex_device)); memcpy(ztex_slave, ztex_devices[i]->dev, sizeof(struct libztex_device));
ztex->device_ztex = ztex_slave; ztex->device_ztex = ztex_slave;
@ -394,10 +394,10 @@ static void ztex_disable(struct thr_info *thr)
ztex_shutdown(thr); ztex_shutdown(thr);
} }
struct device_api ztex_api = { struct device_drv ztex_drv = {
.dname = "ztex", .dname = "ztex",
.name = "ZTX", .name = "ZTX",
.api_detect = ztex_detect, .drv_detect = ztex_detect,
.get_statline_before = ztex_statline_before, .get_statline_before = ztex_statline_before,
.thread_prepare = ztex_prepare, .thread_prepare = ztex_prepare,
.scanhash = ztex_scanhash, .scanhash = ztex_scanhash,

2
findnonce.c

@ -204,7 +204,7 @@ static void *postcalc_hash(void *userdata)
* end of the res[] array */ * end of the res[] array */
if (unlikely(pcd->res[FOUND] & ~FOUND)) { if (unlikely(pcd->res[FOUND] & ~FOUND)) {
applog(LOG_WARNING, "%s%d: invalid nonce count - HW error", applog(LOG_WARNING, "%s%d: invalid nonce count - HW error",
thr->cgpu->api->name, thr->cgpu->device_id); thr->cgpu->drv->name, thr->cgpu->device_id);
hw_errors++; hw_errors++;
thr->cgpu->hw_errors++; thr->cgpu->hw_errors++;
pcd->res[FOUND] &= FOUND; pcd->res[FOUND] &= FOUND;

10
fpgautils.c

@ -104,14 +104,14 @@ int serial_autodetect_devserial(__maybe_unused detectone_func_t detectone, __may
#endif #endif
} }
int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto) int _serial_detect(struct device_drv *drv, detectone_func_t detectone, autoscan_func_t autoscan, bool forceauto)
{ {
struct string_elist *iter, *tmp; struct string_elist *iter, *tmp;
const char *dev, *colon; const char *dev, *colon;
bool inhibitauto = false; bool inhibitauto = false;
char found = 0; char found = 0;
size_t namel = strlen(api->name); size_t namel = strlen(drv->name);
size_t dnamel = strlen(api->dname); size_t dnamel = strlen(drv->dname);
list_for_each_entry_safe(iter, tmp, &scan_devices, list) { list_for_each_entry_safe(iter, tmp, &scan_devices, list) {
dev = iter->string; dev = iter->string;
@ -119,8 +119,8 @@ int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_
size_t idlen = colon - dev; size_t idlen = colon - dev;
// allow either name:device or dname:device // allow either name:device or dname:device
if ((idlen != namel || strncasecmp(dev, api->name, idlen)) if ((idlen != namel || strncasecmp(dev, drv->name, idlen))
&& (idlen != dnamel || strncasecmp(dev, api->dname, idlen))) && (idlen != dnamel || strncasecmp(dev, drv->dname, idlen)))
continue; continue;
dev = colon + 1; dev = colon + 1;

14
fpgautils.h

@ -16,13 +16,13 @@
typedef bool(*detectone_func_t)(const char*); typedef bool(*detectone_func_t)(const char*);
typedef int(*autoscan_func_t)(); typedef int(*autoscan_func_t)();
extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, bool force_autoscan); extern int _serial_detect(struct device_drv *drv, detectone_func_t, autoscan_func_t, bool force_autoscan);
#define serial_detect_fauto(api, detectone, autoscan) \ #define serial_detect_fauto(drv, detectone, autoscan) \
_serial_detect(api, detectone, autoscan, true) _serial_detect(drv, detectone, autoscan, true)
#define serial_detect_auto(api, detectone, autoscan) \ #define serial_detect_auto(drv, detectone, autoscan) \
_serial_detect(api, detectone, autoscan, false) _serial_detect(drv, detectone, autoscan, false)
#define serial_detect(api, detectone) \ #define serial_detect(drv, detectone) \
_serial_detect(api, detectone, NULL, false) _serial_detect(drv, detectone, NULL, false)
extern int serial_autodetect_devserial(detectone_func_t, const char *prodname); extern int serial_autodetect_devserial(detectone_func_t, const char *prodname);
extern int serial_autodetect_udev(detectone_func_t, const char *prodname); extern int serial_autodetect_udev(detectone_func_t, const char *prodname);

19
miner.h

@ -196,6 +196,15 @@ static inline int fsync (int fd)
#endif #endif
#endif #endif
enum drv_driver {
DRIVER_OPENCL,
DRIVER_ICARUS,
DRIVER_BITFORCE,
DRIVER_MODMINER,
DRIVER_ZTEX,
DRIVER_CPU,
};
enum alive { enum alive {
LIFE_WELL, LIFE_WELL,
LIFE_SICK, LIFE_SICK,
@ -263,12 +272,14 @@ struct api_data;
struct thr_info; struct thr_info;
struct work; struct work;
struct device_api { struct device_drv {
enum drv_driver drv;
char *dname; char *dname;
char *name; char *name;
// API-global functions // DRV-global functions
void (*api_detect)(); void (*drv_detect)();
// Device-specific functions // Device-specific functions
void (*reinit_device)(struct cgpu_info *); void (*reinit_device)(struct cgpu_info *);
@ -365,7 +376,7 @@ struct cgminer_pool_stats {
struct cgpu_info { struct cgpu_info {
int cgminer_id; int cgminer_id;
struct device_api *api; struct device_drv *drv;
int device_id; int device_id;
char *name; char *name;
char *device_path; char *device_path;

38
usbutils.c

@ -99,15 +99,15 @@ static struct usb_find_devices find_dev[] = {
}; };
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
extern struct device_api bitforce_api; extern struct device_drv bitforce_drv;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
extern struct device_api icarus_api; extern struct device_drv icarus_drv;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
extern struct device_api modminer_api; extern struct device_drv modminer_drv;
#endif #endif
/* /*
@ -907,7 +907,7 @@ dame:
return false; return false;
} }
static bool usb_check_device(struct device_api *api, struct libusb_device *dev, struct usb_find_devices *look) static bool usb_check_device(struct device_drv *drv, struct libusb_device *dev, struct usb_find_devices *look)
{ {
struct libusb_device_descriptor desc; struct libusb_device_descriptor desc;
int err; int err;
@ -920,25 +920,25 @@ static bool usb_check_device(struct device_api *api, struct libusb_device *dev,
if (desc.idVendor != look->idVendor || desc.idProduct != look->idProduct) { if (desc.idVendor != look->idVendor || desc.idProduct != look->idProduct) {
applog(LOG_DEBUG, "%s looking for %04x:%04x but found %04x:%04x instead", applog(LOG_DEBUG, "%s looking for %04x:%04x but found %04x:%04x instead",
api->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct); drv->name, look->idVendor, look->idProduct, desc.idVendor, desc.idProduct);
return false; return false;
} }
applog(LOG_DEBUG, "%s looking for and found %04x:%04x", applog(LOG_DEBUG, "%s looking for and found %04x:%04x",
api->name, look->idVendor, look->idProduct); drv->name, look->idVendor, look->idProduct);
return true; return true;
} }
static struct usb_find_devices *usb_check_each(int drv, struct device_api *api, struct libusb_device *dev) static struct usb_find_devices *usb_check_each(int drvnum, struct device_drv *drv, struct libusb_device *dev)
{ {
struct usb_find_devices *found; struct usb_find_devices *found;
int i; int i;
for (i = 0; find_dev[i].drv != DRV_LAST; i++) for (i = 0; find_dev[i].drv != DRV_LAST; i++)
if (find_dev[i].drv == drv) { if (find_dev[i].drv == drvnum) {
if (usb_check_device(api, dev, &(find_dev[i]))) { if (usb_check_device(drv, dev, &(find_dev[i]))) {
found = malloc(sizeof(*found)); found = malloc(sizeof(*found));
memcpy(found, &(find_dev[i]), sizeof(*found)); memcpy(found, &(find_dev[i]), sizeof(*found));
return found; return found;
@ -948,27 +948,27 @@ static struct usb_find_devices *usb_check_each(int drv, struct device_api *api,
return NULL; return NULL;
} }
static struct usb_find_devices *usb_check(__maybe_unused struct device_api *api, __maybe_unused struct libusb_device *dev) static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv, __maybe_unused struct libusb_device *dev)
{ {
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (api == &bitforce_api) if (drv->drv == DRIVER_BITFORCE)
return usb_check_each(DRV_BITFORCE, api, dev); return usb_check_each(DRV_BITFORCE, drv, dev);
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (api == &icarus_api) if (drv->drv == DRIVER_ICARUS)
return usb_check_each(DRV_ICARUS, api, dev); return usb_check_each(DRV_ICARUS, drv, dev);
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (api == &modminer_api) if (drv->drv == DRIVER_MODMINER)
return usb_check_each(DRV_MODMINER, api, dev); return usb_check_each(DRV_MODMINER, drv, dev);
#endif #endif
return NULL; return NULL;
} }
void usb_detect(struct device_api *api, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *)) void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *))
{ {
libusb_device **list; libusb_device **list;
ssize_t count, i; ssize_t count, i;
@ -995,7 +995,7 @@ void usb_detect(struct device_api *api, bool (*device_detect)(struct libusb_devi
mutex_unlock(list_lock); mutex_unlock(list_lock);
found = usb_check(api, list[i]); found = usb_check(drv, list[i]);
if (!found) if (!found)
release_dev(list[i], true); release_dev(list[i], true);
else else
@ -1106,7 +1106,7 @@ static void newstats(struct cgpu_info *cgpu)
cgpu->usbstat = ++next_stat; cgpu->usbstat = ++next_stat;
usb_stats = realloc(usb_stats, sizeof(*usb_stats) * next_stat); usb_stats = realloc(usb_stats, sizeof(*usb_stats) * next_stat);
usb_stats[next_stat-1].name = cgpu->api->name; usb_stats[next_stat-1].name = cgpu->drv->name;
usb_stats[next_stat-1].device_id = -1; usb_stats[next_stat-1].device_id = -1;
usb_stats[next_stat-1].details = calloc(1, sizeof(struct cg_usb_stats_details) * C_MAX * 2); usb_stats[next_stat-1].details = calloc(1, sizeof(struct cg_usb_stats_details) * C_MAX * 2);
for (i = 1; i < C_MAX * 2; i += 2) for (i = 1; i < C_MAX * 2; i += 2)

4
usbutils.h

@ -116,12 +116,12 @@ enum usb_cmds {
C_MAX C_MAX
}; };
struct device_api; struct device_drv;
struct cgpu_info; struct cgpu_info;
void usb_uninit(struct cgpu_info *cgpu); void usb_uninit(struct cgpu_info *cgpu);
bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found); bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find_devices *found);
void usb_detect(struct device_api *api, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *)); void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *));
struct api_data *api_usb_stats(int *count); struct api_data *api_usb_stats(int *count);
void update_usb_stats(struct cgpu_info *cgpu); void update_usb_stats(struct cgpu_info *cgpu);
int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, int eol, enum usb_cmds, bool ftdi); int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, int eol, enum usb_cmds, bool ftdi);

Loading…
Cancel
Save