From a344deb6ac8605a57c96eb03cb7ec9b17c4575b7 Mon Sep 17 00:00:00 2001 From: Kano Date: Sat, 5 Jan 2013 23:47:26 +1100 Subject: [PATCH] rename device_api -> device_drv and all related api -> drv and add a device_drv->drv enum for identifying which driver each is --- api.c | 64 ++++++++++--------------- cgminer.c | 119 +++++++++++++++++++++++----------------------- driver-bitforce.c | 87 ++++++++++++++++----------------- driver-cpu.c | 6 +-- driver-cpu.h | 2 +- driver-icarus.c | 11 +++-- driver-modminer.c | 93 ++++++++++++++++++------------------ driver-opencl.c | 38 +++++---------- driver-opencl.h | 2 +- driver-ztex.c | 10 ++-- findnonce.c | 2 +- fpgautils.c | 10 ++-- fpgautils.h | 14 +++--- miner.h | 19 ++++++-- usbutils.c | 38 +++++++-------- usbutils.h | 4 +- 16 files changed, 253 insertions(+), 266 deletions(-) diff --git a/api.c b/api.c index 3561c7ab..2e013ff4 100644 --- a/api.c +++ b/api.c @@ -599,22 +599,6 @@ struct APIGROUPS { static struct IP4ACCESS *ipaccess = NULL; 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 { size_t siz; char *ptr; @@ -1153,19 +1137,19 @@ static int numpgas() for (i = 0; i < total_devices; i++) { #ifdef USE_BITFORCE - if (devices[i]->api == &bitforce_api) + if (devices[i]->drv->drv == DRIVER_BITFORCE) count++; #endif #ifdef USE_ICARUS - if (devices[i]->api == &icarus_api) + if (devices[i]->drv->drv == DRIVER_ICARUS) count++; #endif #ifdef USE_ZTEX - if (devices[i]->api == &ztex_api) + if (devices[i]->drv->drv == DRIVER_ZTEX) count++; #endif #ifdef USE_MODMINER - if (devices[i]->api == &modminer_api) + if (devices[i]->drv->drv == DRIVER_MODMINER) count++; #endif } @@ -1179,19 +1163,19 @@ static int pgadevice(int pgaid) for (i = 0; i < total_devices; i++) { #ifdef USE_BITFORCE - if (devices[i]->api == &bitforce_api) + if (devices[i]->drv->drv == DRIVER_BITFORCE) count++; #endif #ifdef USE_ICARUS - if (devices[i]->api == &icarus_api) + if (devices[i]->drv->drv == DRIVER_ICARUS) count++; #endif #ifdef USE_ZTEX - if (devices[i]->api == &ztex_api) + if (devices[i]->drv->drv == DRIVER_ZTEX) count++; #endif #ifdef USE_MODMINER - if (devices[i]->api == &modminer_api) + if (devices[i]->drv->drv == DRIVER_MODMINER) count++; #endif 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; #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); #endif #ifdef USE_MODMINER - if (cgpu->api == &modminer_api) + if (cgpu->drv->drv == DRIVER_MODMINER) frequency = cgpu->clock; #endif @@ -1553,7 +1537,7 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom status = (char *)status2str(cgpu->status); 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_string(root, "Enabled", enabled, 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 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); else { - api->identify_device(cgpu); + drv->identify_device(cgpu); 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 '*' // Simplifies future external support for identifying new counters 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_time(root, "Last Well", &(cgpu->device_last_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]; 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_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, "Model", cgpu->name ? : 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++) { struct cgpu_info *cgpu = devices[j]; - if (cgpu && cgpu->api) { - if (cgpu->api->get_api_stats) - extra = cgpu->api->get_api_stats(cgpu); + if (cgpu && cgpu->drv) { + if (cgpu->drv->get_api_stats) + extra = cgpu->drv->get_api_stats(cgpu); else 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); } } @@ -3195,16 +3179,16 @@ static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe } struct cgpu_info *cgpu = devices[dev]; - struct device_api *api = cgpu->api; + struct device_drv *drv = cgpu->drv; char *set = strchr(opt, ','); if (set) *(set++) = '\0'; - if (!api->set_device) + if (!drv->set_device) message(io_data, MSG_PGANOSET, id, NULL, isjson); else { - char *ret = api->set_device(cgpu, opt, set, buf); + char *ret = drv->set_device(cgpu, opt, set, buf); if (ret) { if (strcasecmp(opt, "help") == 0) message(io_data, MSG_PGAHELP, id, ret, isjson); diff --git a/cgminer.c b/cgminer.c index 19ffcb98..adf7db45 100644 --- a/cgminer.c +++ b/cgminer.c @@ -385,7 +385,7 @@ static void sharelog(const char*disposition, const struct work*work) data = bin2hex(work->data, sizeof(work->data)); // 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(hash); free(data); @@ -1875,9 +1875,9 @@ static void get_statline(char *buf, struct cgpu_info *cgpu) suffix_string(dh64, displayed_hashes, 4); suffix_string(dr64, displayed_rolling, 4); - sprintf(buf, "%s%d ", cgpu->api->name, cgpu->device_id); - if (cgpu->api->get_statline_before) - cgpu->api->get_statline_before(buf, cgpu); + sprintf(buf, "%s%d ", cgpu->drv->name, cgpu->device_id); + if (cgpu->drv->get_statline_before) + cgpu->drv->get_statline_before(buf, cgpu); else tailsprintf(buf, " | "); 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->hw_errors, cgpu->utility); - if (cgpu->api->get_statline) - cgpu->api->get_statline(buf, cgpu); + if (cgpu->drv->get_statline) + cgpu->drv->get_statline(buf, cgpu); } 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; wmove(statuswin,devcursor + cgpu->cgminer_id, 0); - wprintw(statuswin, " %s %*d: ", cgpu->api->name, dev_width, cgpu->device_id); - if (cgpu->api->get_statline_before) { + wprintw(statuswin, " %s %*d: ", cgpu->drv->name, dev_width, cgpu->device_id); + if (cgpu->drv->get_statline_before) { logline[0] = '\0'; - cgpu->api->get_statline_before(logline, cgpu); + cgpu->drv->get_statline_before(logline, cgpu); wprintw(statuswin, "%s", logline); } else @@ -2007,9 +2007,9 @@ static void curses_print_devstatus(int thr_id) hwwidth, cgpu->hw_errors, uwidth + 3, cgpu->utility); - if (cgpu->api->get_statline) { + if (cgpu->drv->get_statline) { logline[0] = '\0'; - cgpu->api->get_statline(logline, cgpu); + cgpu->drv->get_statline(logline, cgpu); 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 (total_pools > 1) 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 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); 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", - 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); } @@ -5238,15 +5238,15 @@ static bool hashtest(struct thr_info *thr, struct work *work) if (hash2_32[7] != 0) { 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); hw_errors++; thr->cgpu->hw_errors++; mutex_unlock(&stats_lock); - if (thr->cgpu->api->hw_error) - thr->cgpu->api->hw_error(thr); + if (thr->cgpu->drv->hw_error) + thr->cgpu->drv->hw_error(thr); 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, - struct device_api *api) + struct device_drv *drv) { applog(LOG_WARNING, "Thread %d being disabled", thr_id); 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); thread_reportin(mythr); applog(LOG_WARNING, "Thread %d being re-enabled", thr_id); - if (api->thread_enable) - api->thread_enable(mythr); + if (drv->thread_enable) + drv->thread_enable(mythr); } void *miner_thread(void *userdata) @@ -5314,7 +5314,7 @@ void *miner_thread(void *userdata) struct thr_info *mythr = userdata; const int thr_id = mythr->id; 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 *pool_stats; struct timeval getwork_start; @@ -5323,7 +5323,7 @@ void *miner_thread(void *userdata) const long cycle = opt_log_interval / 5 ? : 1; struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate; 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; struct work *work; @@ -5337,7 +5337,7 @@ void *miner_thread(void *userdata) 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); goto out; } @@ -5357,7 +5357,7 @@ void *miner_thread(void *userdata) gettimeofday(&tv_workstart, NULL); work->blk.nonce = 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 " "mining thread %d", thr_id); break; @@ -5399,16 +5399,16 @@ void *miner_thread(void *userdata) gettimeofday(&(work->tv_work_start), NULL); 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); gettimeofday(&getwork_start, NULL); 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; dev_error(cgpu, REASON_THREAD_ZERO_HASH); - mt_disable(mythr, thr_id, api); + mt_disable(mythr, thr_id, drv); } hashes_done += hashes; @@ -5429,7 +5429,7 @@ void *miner_thread(void *userdata) if (unlikely((long)sdiff.tv_sec < cycle)) { int mult; - if (likely(!api->can_limit_work || max_nonce == 0xffffffff)) + if (likely(!drv->can_limit_work || max_nonce == 0xffffffff)) continue; mult = 1000000 / ((sdiff.tv_usec + 0x400) / 0x400) + 0x10; @@ -5438,9 +5438,9 @@ void *miner_thread(void *userdata) max_nonce = 0xffffffff; else 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; - 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)); timersub(&tv_end, &tv_lastupdate, &diff); @@ -5466,7 +5466,7 @@ void *miner_thread(void *userdata) } 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; } while (!abandon_work(work, &wdiff, cgpu->max_hashes)); @@ -5474,8 +5474,8 @@ void *miner_thread(void *userdata) } out: - if (api->thread_shutdown) - api->thread_shutdown(mythr); + if (drv->thread_shutdown) + drv->thread_shutdown(mythr); thread_reportin(mythr); applog(LOG_ERR, "Thread %d failure, exiting", thr_id); @@ -5703,8 +5703,8 @@ out: void reinit_device(struct cgpu_info *cgpu) { - if (cgpu->api->reinit_device) - cgpu->api->reinit_device(cgpu); + if (cgpu->drv->reinit_device) + cgpu->drv->reinit_device(cgpu); } static struct timeval rotate_tv; @@ -5879,12 +5879,12 @@ static void *watchdog_thread(void __maybe_unused *userdata) char dev_str[8]; int gpu; - if (cgpu->api->get_stats) - cgpu->api->get_stats(cgpu); + if (cgpu->drv->get_stats) + cgpu->drv->get_stats(cgpu); gpu = cgpu->device_id; denable = &cgpu->deven; - sprintf(dev_str, "%s%d", cgpu->api->name, gpu); + sprintf(dev_str, "%s%d", cgpu->drv->name, gpu); #ifdef HAVE_ADL if (adl_active && cgpu->has_adl) @@ -5904,7 +5904,7 @@ static void *watchdog_thread(void __maybe_unused *userdata) continue; #ifdef WANT_CPUMINE - if (!strcmp(cgpu->api->dname, "cpu")) + if (cgpu->drv->drv != DRIVER_CPU) continue; #endif 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 */ #ifndef WANT_CPUMINE -struct device_api cpu_api; -struct device_api cpu_api = { +struct device_drv cpu_drv; +struct device_drv cpu_drv = { + .drv = DRIVER_CPU, .name = "CPU", }; #endif #ifdef USE_BITFORCE -extern struct device_api bitforce_api; +extern struct device_drv bitforce_drv; #endif #ifdef USE_ICARUS -extern struct device_api icarus_api; +extern struct device_drv icarus_drv; #endif #ifdef USE_MODMINER -extern struct device_api modminer_api; +extern struct device_drv modminer_drv; #endif #ifdef USE_ZTEX -extern struct device_api ztex_api; +extern struct device_drv ztex_drv; #endif @@ -6328,7 +6329,7 @@ void enable_device(struct cgpu_info *cgpu) adj_width(mining_threads, &dev_width); #endif #ifdef HAVE_OPENCL - if (cgpu->api == &opencl_api) { + if (cgpu->drv->drv == DRIVER_OPENCL) { gpu_threads += cgpu->threads; } #endif @@ -6345,12 +6346,12 @@ bool add_cgpu(struct cgpu_info*cgpu) static struct _cgpu_devid_counter *devids = NULL; struct _cgpu_devid_counter *d; - HASH_FIND_STR(devids, cgpu->api->name, d); + HASH_FIND_STR(devids, cgpu->drv->name, d); if (d) cgpu->device_id = ++d->lastid; else { 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; HASH_ADD_STR(devids, name, d); } @@ -6568,32 +6569,32 @@ int main(int argc, char *argv[]) #ifdef HAVE_OPENCL if (!opt_nogpu) - opencl_api.api_detect(); + opencl_drv.drv_detect(); gpu_threads = 0; #endif #ifdef USE_ICARUS if (!opt_scrypt) - icarus_api.api_detect(); + icarus_drv.drv_detect(); #endif #ifdef USE_BITFORCE if (!opt_scrypt) - bitforce_api.api_detect(); + bitforce_drv.drv_detect(); #endif #ifdef USE_MODMINER if (!opt_scrypt) - modminer_api.api_detect(); + modminer_drv.drv_detect(); #endif #ifdef USE_ZTEX if (!opt_scrypt) - ztex_api.api_detect(); + ztex_drv.drv_detect(); #endif #ifdef WANT_CPUMINE - cpu_api.api_detect(); + cpu_drv.drv_detect(); #endif if (devices_enabled == -1) { @@ -6601,9 +6602,9 @@ int main(int argc, char *argv[]) for (i = 0; i < total_devices; ++i) { struct cgpu_info *cgpu = devices[i]; 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 - 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); } @@ -6617,7 +6618,7 @@ int main(int argc, char *argv[]) enable_device(devices[i]); } else if (i < total_devices) { if (opt_removedisabled) { - if (devices[i]->api == &cpu_api) + if (devices[i]->drv->drv == DRIVER_CPU) --opt_n_threads; } else { enable_device(devices[i]); @@ -6789,7 +6790,7 @@ begin_bench: thr->q = tq_new(); 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 * their queue in case we wish to enable them later */ @@ -6799,7 +6800,7 @@ begin_bench: 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; thread_reportout(thr); diff --git a/driver-bitforce.c b/driver-bitforce.c index 4a06b597..f1196322 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -64,7 +64,7 @@ static const char *blank = ""; -struct device_api bitforce_api; +struct device_drv bitforce_drv; 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); if (opt_debug) 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 err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_DATA, FTDI_VALUE_DATA, bitforce->usbdev->found->interface, C_SETDATA); if (opt_debug) 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 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); if (opt_debug) 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 err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW, FTDI_VALUE_FLOW, bitforce->usbdev->found->interface, C_SETFLOW); if (opt_debug) 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 err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM, FTDI_VALUE_MODEM, bitforce->usbdev->found->interface, C_SETMODEM); if (opt_debug) 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 err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_TX, bitforce->usbdev->found->interface, C_PURGETX); if (opt_debug) 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 err = usb_transfer(bitforce, FTDI_TYPE_OUT, FTDI_REQUEST_RESET, FTDI_VALUE_PURGE_RX, bitforce->usbdev->found->interface, C_PURGERX); if (opt_debug) 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) 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; bitforce = calloc(1, sizeof(*bitforce)); - bitforce->api = &bitforce_api; + bitforce->drv = &bitforce_drv; bitforce->deven = DEV_ENABLED; bitforce->threads = 1; if (!usb_init(bitforce, dev, found)) { 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_device_address(dev)); 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) { 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; } @@ -168,7 +168,7 @@ reinit: if (++init_count <= REINIT_COUNT) { if (init_count < 2) { 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); goto reinit; @@ -176,14 +176,14 @@ reinit: if (init_count > 0) 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) { applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)", - bitforce->api->dname, devpath, amount, err); + bitforce->drv->dname, devpath, amount, err); } else { applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)", - bitforce->api->dname, devpath, amount); + bitforce->drv->dname, devpath, amount); } goto unshin; @@ -192,7 +192,7 @@ reinit: if (unlikely(!strstr(buf, "SHA256"))) { applog(LOG_ERR, "%s detect (%s) didn't recognise '%s'", - bitforce->api->dname, devpath, buf); + bitforce->drv->dname, devpath, buf); goto unshin; } @@ -205,7 +205,7 @@ reinit: // We have a real BitForce! 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 * fails */ @@ -247,7 +247,7 @@ shin: 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) @@ -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) { 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 { /* However, this stops anything else getting a reply * 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) { mutex_unlock(&bitforce->device_mutex); 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++; return false; } @@ -337,10 +337,10 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) mutex_unlock(&bitforce->device_mutex); if (err < 0) { 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 { 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++; return false; @@ -360,7 +360,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) bitforce->temp = temp; if (unlikely(bitforce->cutofftemp > 0 && temp > bitforce->cutofftemp)) { 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; 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 * hopefully recover */ 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); /* Count throttling episodes as hardware errors */ bitforce->hw_errors++; @@ -404,14 +404,14 @@ re_send: if ((err = usb_write(bitforce, cmd, len, &amount, C_REQUESTSENDWORK)) < 0 || amount != len) { mutex_unlock(&bitforce->device_mutex); 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; } if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) { mutex_unlock(&bitforce->device_mutex); 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; } @@ -423,14 +423,14 @@ re_send: mutex_unlock(&bitforce->device_mutex); if (bitforce->nonce_range) { 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->sleep_ms *= 5; bitforce->kname = KNAME_WORK; goto re_send; } 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; } @@ -458,14 +458,14 @@ re_send: if ((err = usb_write(bitforce, (char *)ob, len, &amount, C_SENDWORK)) < 0 || amount != len) { mutex_unlock(&bitforce->device_mutex); 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; } if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) { mutex_unlock(&bitforce->device_mutex); 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; } @@ -474,19 +474,19 @@ re_send: if (opt_debug) { s = bin2hex(ob + 8, 44); applog(LOG_DEBUG, "%s%i: block data: %s", - bitforce->api->name, bitforce->device_id, s); + bitforce->drv->name, bitforce->device_id, s); free(s); } if (amount == 0 || !buf[0]) { 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; } if (unlikely(strncasecmp(buf, "OK", 2))) { 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; } @@ -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) { 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); 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) { 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); 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) 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); /* 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", - bitforce->api->name, bitforce->device_id, + bitforce->drv->name, bitforce->device_id, bitforce->wait_ms, buf); if (!strncasecmp(&buf[2], "-", 1)) 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)) { bitforce->hw_errors++; 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); 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 || (work->blk.nonce > 0 && nonce < work->blk.nonce - bitforce->nonces - 1)))) { 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; work->blk.nonce = 0xffffffff; bitforce->sleep_ms *= 5; @@ -643,7 +643,7 @@ static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_ if (ret == -1) { 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); bitforce->hw_errors++; /* 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. */ wait = thr->id * MAX_START_DELAY_MS; 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); return true; @@ -691,10 +691,11 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu) return root; } -struct device_api bitforce_api = { +struct device_drv bitforce_drv = { + .drv = DRIVER_BITFORCE, .dname = "bitforce", .name = "BFL", - .api_detect = bitforce_detect, + .drv_detect = bitforce_detect, .get_api_stats = bitforce_api_stats, .get_statline_before = get_bitforce_statline_before, .get_stats = bitforce_get_stats, diff --git a/driver-cpu.c b/driver-cpu.c index 75d9a5a4..99c5a3fa 100644 --- a/driver-cpu.c +++ b/driver-cpu.c @@ -758,7 +758,7 @@ static void cpu_detect() struct cgpu_info *cgpu; cgpu = &cpus[i]; - cgpu->api = &cpu_api; + cgpu->drv = &cpu_drv; cgpu->deven = DEV_ENABLED; cgpu->threads = 1; cgpu->kname = algo_names[opt_algo]; @@ -843,10 +843,10 @@ CPUSearch: return last_nonce - first_nonce + 1; } -struct device_api cpu_api = { +struct device_drv cpu_drv = { .dname = "cpu", .name = "CPU", - .api_detect = cpu_detect, + .drv_detect = cpu_detect, .reinit_device = reinit_cpu_device, .thread_prepare = cpu_thread_prepare, .can_limit_work = cpu_can_limit_work, diff --git a/driver-cpu.h b/driver-cpu.h index e4b44527..361ae5d8 100644 --- a/driver-cpu.h +++ b/driver-cpu.h @@ -53,7 +53,7 @@ enum sha256_algos { extern const char *algo_names[]; 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 void show_algo(char buf[OPT_SHOW_LEN], const enum sha256_algos *algo); diff --git a/driver-icarus.c b/driver-icarus.c index c979a681..f42e7214 100644 --- a/driver-icarus.c +++ b/driver-icarus.c @@ -208,7 +208,7 @@ static struct ICARUS_INFO **icarus_info; // static int option_offset = -1; -struct device_api icarus_api; +struct device_drv icarus_drv; 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! */ struct cgpu_info *icarus; icarus = calloc(1, sizeof(struct cgpu_info)); - icarus->api = &icarus_api; + icarus->drv = &icarus_drv; icarus->device_path = strdup(devpath); icarus->device_fd = -1; icarus->threads = 1; @@ -609,7 +609,7 @@ static bool icarus_detect_one(const char *devpath) 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) @@ -900,10 +900,11 @@ static void icarus_shutdown(struct thr_info *thr) do_icarus_close(thr); } -struct device_api icarus_api = { +struct device_drv icarus_drv = { + .drv = DRIVER_ICARUS, .dname = "icarus", .name = "ICA", - .api_detect = icarus_detect, + .drv_detect = icarus_detect, .get_api_stats = icarus_api_stats, .thread_prepare = icarus_prepare, .scanhash = icarus_scanhash, diff --git a/driver-modminer.c b/driver-modminer.c index c48a51bc..0868e85e 100644 --- a/driver-modminer.c +++ b/driver-modminer.c @@ -87,7 +87,7 @@ // Limit when reducing shares_to_good #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 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 err = usb_write(modminer, (char *)NOOP, sizeof(NOOP)-1, &amount, C_PING); 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 while ((err = usb_read(modminer, buf, sizeof(buf)-1, &amount, C_CLEAR)) == 0 && amount > 0) 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", - 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) @@ -121,7 +121,7 @@ static bool modminer_detect_one(struct libusb_device *dev, struct usb_find_devic struct cgpu_info *modminer = NULL; modminer = calloc(1, sizeof(*modminer)); - modminer->api = &modminer_api; + modminer->drv = &modminer_drv; modminer->modminer_mutex = calloc(1, sizeof(*(modminer->modminer_mutex))); mutex_init(modminer->modminer_mutex); 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++) { struct cgpu_info *tmp = calloc(1, sizeof(*tmp)); - tmp->api = modminer->api; + tmp->drv = modminer->drv; tmp->name = devname; sprintf(devpath, "%d:%d:%d", @@ -233,7 +233,7 @@ shin: 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) @@ -242,13 +242,13 @@ static bool get_expect(struct cgpu_info *modminer, FILE *f, char c) if (fread(&buf, 1, 1, f) != 1) { 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; } if (buf != 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; } @@ -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) { 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; } @@ -270,13 +270,13 @@ static bool get_info(struct cgpu_info *modminer, FILE *f, char *buf, int bufsiz, if (len >= bufsiz) { 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; } if (fread(buf, len, 1, f) != 1) { 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; } @@ -302,7 +302,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i mutex_unlock(modminer->modminer_mutex); 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; } @@ -311,7 +311,7 @@ static bool get_status_timeout(struct cgpu_info *modminer, char *msg, unsigned i mutex_unlock(modminer->modminer_mutex); 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; } @@ -343,7 +343,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -352,7 +352,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -361,7 +361,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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], 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); 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; } @@ -384,7 +384,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) goto undame; 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); @@ -399,7 +399,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); applog(LOG_ERR, "%s%u: Bad usercode in bitstream file", - modminer->api->name, modminer->device_id); + modminer->drv->name, modminer->device_id); goto dame; } @@ -408,7 +408,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -446,7 +446,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -460,7 +460,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) *ptr = '\0'; 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[1] = fpgaid; @@ -473,7 +473,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -492,7 +492,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) mutex_unlock(modminer->modminer_mutex); 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; } @@ -507,7 +507,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) if (opt_debug) 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); 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); 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; } @@ -532,7 +532,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) if (upto >= nextmsg) { applog(LOG_WARNING, "%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; } @@ -542,7 +542,7 @@ static bool modminer_fpga_upload_bitstream(struct cgpu_info *modminer) goto undame; 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 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); 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; } @@ -662,7 +662,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te mutex_unlock(modminer->modminer_mutex); 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; } @@ -670,7 +670,7 @@ static const char *modminer_delta_clock(struct thr_info *thr, int delta, bool te mutex_unlock(modminer->modminer_mutex); 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 " : ""), modminer->clock); @@ -691,7 +691,7 @@ static bool modminer_fpga_init(struct thr_info *thr) mutex_unlock(modminer->modminer_mutex); 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; } @@ -700,14 +700,14 @@ static bool modminer_fpga_init(struct thr_info *thr) mutex_unlock(modminer->modminer_mutex); 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; } if (memcmp(buf, BISTREAM_USER_ID, 4)) { 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)) return false; @@ -717,7 +717,7 @@ static bool modminer_fpga_init(struct thr_info *thr) mutex_unlock(modminer->modminer_mutex); 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; @@ -773,7 +773,7 @@ static bool modminer_start_work(struct thr_info *thr) mutex_unlock(modminer->modminer_mutex); 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; } @@ -827,14 +827,14 @@ static void check_temperature(struct thr_info *thr) if (modminer->temp < MODMINER_RECOVER_TEMP) { state->overheated = false; 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); } } else if (modminer->temp >= MODMINER_OVERHEAT_TEMP) { if (modminer->temp >= MODMINER_CUTOFF_TEMP) { 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_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); } else { 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); // 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)", - modminer->api->name, modminer->device_id, amount, err); + modminer->drv->name, modminer->device_id, amount, err); 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)", - 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)) { @@ -975,7 +975,7 @@ static uint64_t modminer_process_results(struct thr_info *thr) if (state->death_stage_one) { modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true); 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 state->last_nonce.tv_sec = 0; @@ -985,7 +985,7 @@ static uint64_t modminer_process_results(struct thr_info *thr) } else { modminer_delta_clock(thr, MODMINER_CLOCK_DEAD, false, true); 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; } @@ -1141,10 +1141,11 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char return replybuf; } -struct device_api modminer_api = { +struct device_drv modminer_drv = { + .drv = DRIVER_MODMINER, .dname = "modminer", .name = "MMQ", - .api_detect = modminer_detect, + .drv_detect = modminer_detect, .get_statline_before = get_modminer_statline_before, .set_device = modminer_set_device, .thread_prepare = modminer_fpga_prepare, diff --git a/driver-opencl.c b/driver-opencl.c index 01e70198..966d8cd0 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -50,24 +50,24 @@ extern int gpur_thr_id; extern bool opt_noadl; extern bool have_opencl; - - extern void *miner_thread(void *userdata); extern int dev_from_id(int thr_id); extern void tailsprintf(char *f, const char *fmt, ...); extern void wlog(const char *f, ...); extern void decay_time(double *f, double fadd); - /**********************************************/ +#ifdef HAVE_OPENCL +struct device_drv opencl_drv; +#endif + #ifdef HAVE_ADL extern float gpu_temp(int gpu); extern int gpu_fanspeed(int gpu); extern int gpu_fanpercent(int gpu); #endif - #ifdef HAVE_OPENCL char *set_vector(char *arg) { @@ -591,28 +591,20 @@ char *set_intensity(char *arg) return NULL; } -#endif - - -#ifdef HAVE_OPENCL -struct device_api opencl_api; char *print_ndevs_and_exit(int *ndevs) { opt_log_output = true; - opencl_api.api_detect(); + opencl_drv.drv_detect(); clear_adl(*ndevs); applog(LOG_INFO, "%i GPU devices max detected", *ndevs); exit(*ndevs); } #endif - struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */ struct cgpu_info *cpus; - - #ifdef HAVE_OPENCL /* 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 */ #if defined(HAVE_OPENCL) && defined(HAVE_CURSES) @@ -773,7 +762,7 @@ retry: for (i = 0; i < mining_threads; ++i) { thr = &thr_info[i]; cgpu = thr->cgpu; - if (cgpu->api != &opencl_api) + if (cgpu->drv->drv != DRIVER_OPENCL) continue; if (dev_from_id(i) != selected) continue; @@ -1160,7 +1149,7 @@ select_cgpu: for (thr_id = 0; thr_id < mining_threads; ++thr_id) { thr = &thr_info[thr_id]; cgpu = thr->cgpu; - if (cgpu->api != &opencl_api) + if (cgpu->drv->drv != DRIVER_OPENCL) continue; if (dev_from_id(thr_id) != gpu) continue; @@ -1185,7 +1174,7 @@ select_cgpu: thr = &thr_info[thr_id]; cgpu = thr->cgpu; - if (cgpu->api != &opencl_api) + if (cgpu->drv->drv != DRIVER_OPENCL) continue; if (dev_from_id(thr_id) != gpu) continue; @@ -1222,7 +1211,7 @@ select_cgpu: for (thr_id = 0; thr_id < mining_threads; ++thr_id) { thr = &thr_info[thr_id]; cgpu = thr->cgpu; - if (cgpu->api != &opencl_api) + if (cgpu->drv->drv != DRIVER_OPENCL) continue; if (dev_from_id(thr_id) != gpu) continue; @@ -1243,8 +1232,6 @@ void *reinit_gpu(__maybe_unused void *userdata) #ifdef HAVE_OPENCL -struct device_api opencl_api; - static void opencl_detect() { int i; @@ -1263,7 +1250,7 @@ static void opencl_detect() cgpu = &gpus[i]; cgpu->deven = DEV_ENABLED; - cgpu->api = &opencl_api; + cgpu->drv = &opencl_drv; cgpu->device_id = i; cgpu->threads = opt_g_threads; cgpu->virtual_gpu = i; @@ -1570,10 +1557,11 @@ static void opencl_thread_shutdown(struct thr_info *thr) clReleaseContext(clState->context); } -struct device_api opencl_api = { +struct device_drv opencl_drv = { + .drv = DRIVER_OPENCL, .dname = "opencl", .name = "GPU", - .api_detect = opencl_detect, + .drv_detect = opencl_detect, .reinit_device = reinit_opencl_device, #ifdef HAVE_ADL .get_statline_before = get_opencl_statline_before, diff --git a/driver-opencl.h b/driver-opencl.h index c1d61822..22bd9ec2 100644 --- a/driver-opencl.h +++ b/driver-opencl.h @@ -30,6 +30,6 @@ extern void pause_dynamic_threads(int gpu); extern bool have_opencl; extern int opt_platform_id; -extern struct device_api opencl_api; +extern struct device_drv opencl_drv; #endif /* __DEVICE_GPU_H__ */ diff --git a/driver-ztex.c b/driver-ztex.c index 23aa97e4..4a61a5c5 100644 --- a/driver-ztex.c +++ b/driver-ztex.c @@ -30,7 +30,7 @@ #define GOLDEN_BACKLOG 5 -struct device_api ztex_api; +struct device_drv ztex_drv; // Forward declarations static void ztex_disable(struct thr_info* thr); @@ -68,7 +68,7 @@ static void ztex_detect(void) for (i = 0; i < cnt; i++) { ztex = calloc(1, sizeof(struct cgpu_info)); - ztex->api = &ztex_api; + ztex->drv = &ztex_drv; ztex->device_ztex = ztex_devices[i]->dev; ztex->threads = 1; ztex->device_ztex->fpgaNum = 0; @@ -82,7 +82,7 @@ static void ztex_detect(void) for (j = 1; j < fpgacount; j++) { ztex = calloc(1, sizeof(struct cgpu_info)); - ztex->api = &ztex_api; + ztex->drv = &ztex_drv; ztex_slave = calloc(1, sizeof(struct libztex_device)); memcpy(ztex_slave, ztex_devices[i]->dev, sizeof(struct libztex_device)); ztex->device_ztex = ztex_slave; @@ -394,10 +394,10 @@ static void ztex_disable(struct thr_info *thr) ztex_shutdown(thr); } -struct device_api ztex_api = { +struct device_drv ztex_drv = { .dname = "ztex", .name = "ZTX", - .api_detect = ztex_detect, + .drv_detect = ztex_detect, .get_statline_before = ztex_statline_before, .thread_prepare = ztex_prepare, .scanhash = ztex_scanhash, diff --git a/findnonce.c b/findnonce.c index bf39a122..fcf75f23 100644 --- a/findnonce.c +++ b/findnonce.c @@ -204,7 +204,7 @@ static void *postcalc_hash(void *userdata) * end of the res[] array */ if (unlikely(pcd->res[FOUND] & ~FOUND)) { 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++; thr->cgpu->hw_errors++; pcd->res[FOUND] &= FOUND; diff --git a/fpgautils.c b/fpgautils.c index 487395cc..307bec49 100644 --- a/fpgautils.c +++ b/fpgautils.c @@ -104,14 +104,14 @@ int serial_autodetect_devserial(__maybe_unused detectone_func_t detectone, __may #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; const char *dev, *colon; bool inhibitauto = false; char found = 0; - size_t namel = strlen(api->name); - size_t dnamel = strlen(api->dname); + size_t namel = strlen(drv->name); + size_t dnamel = strlen(drv->dname); list_for_each_entry_safe(iter, tmp, &scan_devices, list) { dev = iter->string; @@ -119,8 +119,8 @@ int _serial_detect(struct device_api *api, detectone_func_t detectone, autoscan_ size_t idlen = colon - dev; // allow either name:device or dname:device - if ((idlen != namel || strncasecmp(dev, api->name, idlen)) - && (idlen != dnamel || strncasecmp(dev, api->dname, idlen))) + if ((idlen != namel || strncasecmp(dev, drv->name, idlen)) + && (idlen != dnamel || strncasecmp(dev, drv->dname, idlen))) continue; dev = colon + 1; diff --git a/fpgautils.h b/fpgautils.h index 18025488..b979b6c6 100644 --- a/fpgautils.h +++ b/fpgautils.h @@ -16,13 +16,13 @@ typedef bool(*detectone_func_t)(const char*); typedef int(*autoscan_func_t)(); -extern int _serial_detect(struct device_api *api, detectone_func_t, autoscan_func_t, bool force_autoscan); -#define serial_detect_fauto(api, detectone, autoscan) \ - _serial_detect(api, detectone, autoscan, true) -#define serial_detect_auto(api, detectone, autoscan) \ - _serial_detect(api, detectone, autoscan, false) -#define serial_detect(api, detectone) \ - _serial_detect(api, detectone, NULL, false) +extern int _serial_detect(struct device_drv *drv, detectone_func_t, autoscan_func_t, bool force_autoscan); +#define serial_detect_fauto(drv, detectone, autoscan) \ + _serial_detect(drv, detectone, autoscan, true) +#define serial_detect_auto(drv, detectone, autoscan) \ + _serial_detect(drv, detectone, autoscan, false) +#define serial_detect(drv, detectone) \ + _serial_detect(drv, detectone, NULL, false) extern int serial_autodetect_devserial(detectone_func_t, const char *prodname); extern int serial_autodetect_udev(detectone_func_t, const char *prodname); diff --git a/miner.h b/miner.h index d892ed03..4e888f32 100644 --- a/miner.h +++ b/miner.h @@ -196,6 +196,15 @@ static inline int fsync (int fd) #endif #endif +enum drv_driver { + DRIVER_OPENCL, + DRIVER_ICARUS, + DRIVER_BITFORCE, + DRIVER_MODMINER, + DRIVER_ZTEX, + DRIVER_CPU, +}; + enum alive { LIFE_WELL, LIFE_SICK, @@ -263,12 +272,14 @@ struct api_data; struct thr_info; struct work; -struct device_api { +struct device_drv { + enum drv_driver drv; + char *dname; char *name; - // API-global functions - void (*api_detect)(); + // DRV-global functions + void (*drv_detect)(); // Device-specific functions void (*reinit_device)(struct cgpu_info *); @@ -365,7 +376,7 @@ struct cgminer_pool_stats { struct cgpu_info { int cgminer_id; - struct device_api *api; + struct device_drv *drv; int device_id; char *name; char *device_path; diff --git a/usbutils.c b/usbutils.c index 0d9e79aa..bebd722d 100644 --- a/usbutils.c +++ b/usbutils.c @@ -99,15 +99,15 @@ static struct usb_find_devices find_dev[] = { }; #ifdef USE_BITFORCE -extern struct device_api bitforce_api; +extern struct device_drv bitforce_drv; #endif #ifdef USE_ICARUS -extern struct device_api icarus_api; +extern struct device_drv icarus_drv; #endif #ifdef USE_MODMINER -extern struct device_api modminer_api; +extern struct device_drv modminer_drv; #endif /* @@ -907,7 +907,7 @@ dame: 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; 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) { 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; } applog(LOG_DEBUG, "%s looking for and found %04x:%04x", - api->name, look->idVendor, look->idProduct); + drv->name, look->idVendor, look->idProduct); 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; int i; for (i = 0; find_dev[i].drv != DRV_LAST; i++) - if (find_dev[i].drv == drv) { - if (usb_check_device(api, dev, &(find_dev[i]))) { + if (find_dev[i].drv == drvnum) { + if (usb_check_device(drv, dev, &(find_dev[i]))) { found = malloc(sizeof(*found)); memcpy(found, &(find_dev[i]), sizeof(*found)); return found; @@ -948,27 +948,27 @@ static struct usb_find_devices *usb_check_each(int drv, struct device_api *api, 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 - if (api == &bitforce_api) - return usb_check_each(DRV_BITFORCE, api, dev); + if (drv->drv == DRIVER_BITFORCE) + return usb_check_each(DRV_BITFORCE, drv, dev); #endif #ifdef USE_ICARUS - if (api == &icarus_api) - return usb_check_each(DRV_ICARUS, api, dev); + if (drv->drv == DRIVER_ICARUS) + return usb_check_each(DRV_ICARUS, drv, dev); #endif #ifdef USE_MODMINER - if (api == &modminer_api) - return usb_check_each(DRV_MODMINER, api, dev); + if (drv->drv == DRIVER_MODMINER) + return usb_check_each(DRV_MODMINER, drv, dev); #endif 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; 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); - found = usb_check(api, list[i]); + found = usb_check(drv, list[i]); if (!found) release_dev(list[i], true); else @@ -1106,7 +1106,7 @@ static void newstats(struct cgpu_info *cgpu) cgpu->usbstat = ++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].details = calloc(1, sizeof(struct cg_usb_stats_details) * C_MAX * 2); for (i = 1; i < C_MAX * 2; i += 2) diff --git a/usbutils.h b/usbutils.h index 156e2a2d..2ee86150 100644 --- a/usbutils.h +++ b/usbutils.h @@ -116,12 +116,12 @@ enum usb_cmds { C_MAX }; -struct device_api; +struct device_drv; struct cgpu_info; void usb_uninit(struct cgpu_info *cgpu); 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); 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);