1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-02-02 10:04:33 +00:00

Create a macro list of drivers to enable easier addition of further drivers.

This commit is contained in:
ckolivas 2013-09-28 10:25:48 +10:00
parent c50b13a602
commit 8875197466
12 changed files with 55 additions and 49 deletions

32
api.c
View File

@ -1220,15 +1220,15 @@ static int numascs()
rd_lock(&devices_lock); rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_AVALON #ifdef USE_AVALON
if (devices[i]->drv->drv_id == DRIVER_AVALON) if (devices[i]->drv->drv_id == DRIVER_avalon)
count++; count++;
#endif #endif
#ifdef USE_BFLSC #ifdef USE_BFLSC
if (devices[i]->drv->drv_id == DRIVER_BFLSC) if (devices[i]->drv->drv_id == DRIVER_bflsc)
count++; count++;
#endif #endif
#ifdef USE_BITFURY #ifdef USE_BITFURY
if (devices[i]->drv->drv_id == DRIVER_BITFURY) if (devices[i]->drv->drv_id == DRIVER_bitfury)
count++; count++;
#endif #endif
} }
@ -1244,15 +1244,15 @@ static int ascdevice(int ascid)
rd_lock(&devices_lock); rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_AVALON #ifdef USE_AVALON
if (devices[i]->drv->drv_id == DRIVER_AVALON) if (devices[i]->drv->drv_id == DRIVER_avalon)
count++; count++;
#endif #endif
#ifdef USE_BFLSC #ifdef USE_BFLSC
if (devices[i]->drv->drv_id == DRIVER_BFLSC) if (devices[i]->drv->drv_id == DRIVER_bflsc)
count++; count++;
#endif #endif
#ifdef USE_BITFURY #ifdef USE_BITFURY
if (devices[i]->drv->drv_id == DRIVER_BITFURY) if (devices[i]->drv->drv_id == DRIVER_bitfury)
count++; count++;
#endif #endif
if (count == (ascid + 1)) if (count == (ascid + 1))
@ -1278,19 +1278,19 @@ static int numpgas()
rd_lock(&devices_lock); rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (devices[i]->drv->drv_id == DRIVER_BITFORCE) if (devices[i]->drv->drv_id == DRIVER_bitforce)
count++; count++;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (devices[i]->drv->drv_id == DRIVER_ICARUS) if (devices[i]->drv->drv_id == DRIVER_icarus)
count++; count++;
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (devices[i]->drv->drv_id == DRIVER_ZTEX) if (devices[i]->drv->drv_id == DRIVER_ztex)
count++; count++;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (devices[i]->drv->drv_id == DRIVER_MODMINER) if (devices[i]->drv->drv_id == DRIVER_modminer)
count++; count++;
#endif #endif
} }
@ -1306,19 +1306,19 @@ static int pgadevice(int pgaid)
rd_lock(&devices_lock); rd_lock(&devices_lock);
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (devices[i]->drv->drv_id == DRIVER_BITFORCE) if (devices[i]->drv->drv_id == DRIVER_bitforce)
count++; count++;
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (devices[i]->drv->drv_id == DRIVER_ICARUS) if (devices[i]->drv->drv_id == DRIVER_icarus)
count++; count++;
#endif #endif
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (devices[i]->drv->drv_id == DRIVER_ZTEX) if (devices[i]->drv->drv_id == DRIVER_ztex)
count++; count++;
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (devices[i]->drv->drv_id == DRIVER_MODMINER) if (devices[i]->drv->drv_id == DRIVER_modminer)
count++; count++;
#endif #endif
if (count == (pgaid + 1)) if (count == (pgaid + 1))
@ -1770,11 +1770,11 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
dev_runtime = 1.0; dev_runtime = 1.0;
#ifdef USE_ZTEX #ifdef USE_ZTEX
if (cgpu->drv->drv_id == DRIVER_ZTEX && cgpu->device_ztex) if (cgpu->drv->drv_id == 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->drv->drv_id == DRIVER_MODMINER) if (cgpu->drv->drv_id == DRIVER_modminer)
frequency = cgpu->clock; frequency = cgpu->clock;
#endif #endif

View File

@ -7496,7 +7496,7 @@ void enable_device(struct cgpu_info *cgpu)
#endif #endif
} }
#ifdef HAVE_OPENCL #ifdef HAVE_OPENCL
if (cgpu->drv->drv_id == DRIVER_OPENCL) { if (cgpu->drv->drv_id == DRIVER_opencl) {
gpu_threads += cgpu->threads; gpu_threads += cgpu->threads;
} }
#endif #endif

View File

@ -1600,7 +1600,7 @@ static char *avalon_set_device(struct cgpu_info *avalon, char *option, char *set
} }
struct device_drv avalon_drv = { struct device_drv avalon_drv = {
.drv_id = DRIVER_AVALON, .drv_id = DRIVER_avalon,
.dname = "avalon", .dname = "avalon",
.name = "AVA", .name = "AVA",
.drv_detect = avalon_detect, .drv_detect = avalon_detect,

View File

@ -1915,7 +1915,7 @@ else a whole lot of something like these ... etc
} }
struct device_drv bflsc_drv = { struct device_drv bflsc_drv = {
.drv_id = DRIVER_BFLSC, .drv_id = DRIVER_bflsc,
.dname = "BitForceSC", .dname = "BitForceSC",
.name = BFLSC_SINGLE, .name = BFLSC_SINGLE,
.drv_detect = bflsc_detect, .drv_detect = bflsc_detect,

View File

@ -742,7 +742,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
} }
struct device_drv bitforce_drv = { struct device_drv bitforce_drv = {
.drv_id = DRIVER_BITFORCE, .drv_id = DRIVER_bitforce,
.dname = "BitForce", .dname = "BitForce",
.name = "BFL", .name = "BFL",
.drv_detect = bitforce_detect, .drv_detect = bitforce_detect,

View File

@ -310,7 +310,7 @@ static void bitfury_shutdown(struct thr_info *thr)
/* Currently hardcoded to BF1 devices */ /* Currently hardcoded to BF1 devices */
struct device_drv bitfury_drv = { struct device_drv bitfury_drv = {
.drv_id = DRIVER_BITFURY, .drv_id = DRIVER_bitfury,
.dname = "bitfury", .dname = "bitfury",
.name = "BF1", .name = "BF1",
.drv_detect = bitfury_detect, .drv_detect = bitfury_detect,

View File

@ -1210,7 +1210,7 @@ static void icarus_shutdown(__maybe_unused struct thr_info *thr)
} }
struct device_drv icarus_drv = { struct device_drv icarus_drv = {
.drv_id = DRIVER_ICARUS, .drv_id = DRIVER_icarus,
.dname = "Icarus", .dname = "Icarus",
.name = "ICA", .name = "ICA",
.drv_detect = icarus_detect, .drv_detect = icarus_detect,

View File

@ -1132,7 +1132,7 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char
} }
struct device_drv modminer_drv = { struct device_drv modminer_drv = {
.drv_id = DRIVER_MODMINER, .drv_id = DRIVER_modminer,
.dname = "ModMiner", .dname = "ModMiner",
.name = "MMQ", .name = "MMQ",
.drv_detect = modminer_detect, .drv_detect = modminer_detect,

View File

@ -753,7 +753,7 @@ retry:
for (i = 0; i < mining_threads; ++i) { for (i = 0; i < mining_threads; ++i) {
thr = get_thread(i); thr = get_thread(i);
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL) if (cgpu->drv->drv_id != DRIVER_opencl)
continue; continue;
if (dev_from_id(i) != selected) if (dev_from_id(i) != selected)
continue; continue;
@ -1148,7 +1148,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) { for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = get_thread(thr_id); thr = get_thread(thr_id);
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL) if (cgpu->drv->drv_id != DRIVER_opencl)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1173,7 +1173,7 @@ select_cgpu:
thr = get_thread(thr_id); thr = get_thread(thr_id);
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL) if (cgpu->drv->drv_id != DRIVER_opencl)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1210,7 +1210,7 @@ select_cgpu:
for (thr_id = 0; thr_id < mining_threads; ++thr_id) { for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = get_thread(thr_id); thr = get_thread(thr_id);
cgpu = thr->cgpu; cgpu = thr->cgpu;
if (cgpu->drv->drv_id != DRIVER_OPENCL) if (cgpu->drv->drv_id != DRIVER_opencl)
continue; continue;
if (dev_from_id(thr_id) != gpu) if (dev_from_id(thr_id) != gpu)
continue; continue;
@ -1575,7 +1575,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
} }
struct device_drv opencl_drv = { struct device_drv opencl_drv = {
.drv_id = DRIVER_OPENCL, .drv_id = DRIVER_opencl,
.dname = "opencl", .dname = "opencl",
.name = "GPU", .name = "GPU",
.drv_detect = opencl_detect, .drv_detect = opencl_detect,

View File

@ -413,7 +413,7 @@ static void ztex_disable(struct thr_info *thr)
} }
struct device_drv ztex_drv = { struct device_drv ztex_drv = {
.drv_id = DRIVER_ZTEX, .drv_id = DRIVER_ztex,
.dname = "ztex", .dname = "ztex",
.name = "ZTX", .name = "ZTX",
.drv_detect = ztex_detect, .drv_detect = ztex_detect,

22
miner.h
View File

@ -230,17 +230,23 @@ static inline int fsync (int fd)
#define MIN(x, y) ((x) > (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x))
#define MAX(x, y) ((x) > (y) ? (x) : (y)) #define MAX(x, y) ((x) > (y) ? (x) : (y))
#define DRIVER_PARSE_COMMANDS \
DRIVER_ADD_COMMAND(avalon) \
DRIVER_ADD_COMMAND(bflsc) \
DRIVER_ADD_COMMAND(bitforce) \
DRIVER_ADD_COMMAND(bitfury) \
DRIVER_ADD_COMMAND(icarus) \
DRIVER_ADD_COMMAND(modminer) \
DRIVER_ADD_COMMAND(opencl) \
DRIVER_ADD_COMMAND(ztex)
/* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
#define DRIVER_ADD_COMMAND(X) DRIVER_##X,
enum drv_driver { enum drv_driver {
DRIVER_OPENCL = 0, DRIVER_PARSE_COMMANDS
DRIVER_ICARUS,
DRIVER_BITFORCE,
DRIVER_BITFURY,
DRIVER_MODMINER,
DRIVER_ZTEX,
DRIVER_BFLSC,
DRIVER_AVALON,
DRIVER_MAX DRIVER_MAX
}; };
#undef DRIVER_ADD_COMMAND
enum alive { enum alive {
LIFE_WELL, LIFE_WELL,

View File

@ -1899,32 +1899,32 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
} }
#ifdef USE_BFLSC #ifdef USE_BFLSC
if (drv->drv_id == DRIVER_BFLSC) if (drv->drv_id == DRIVER_bflsc)
return usb_check_each(DRV_BFLSC, drv, dev); return usb_check_each(DRV_BFLSC, drv, dev);
#endif #endif
#ifdef USE_BITFORCE #ifdef USE_BITFORCE
if (drv->drv_id == DRIVER_BITFORCE) if (drv->drv_id == DRIVER_bitforce)
return usb_check_each(DRV_BITFORCE, drv, dev); return usb_check_each(DRV_BITFORCE, drv, dev);
#endif #endif
#ifdef USE_BITFURY #ifdef USE_BITFURY
if (drv->drv_id == DRIVER_BITFURY) if (drv->drv_id == DRIVER_bitfury)
return usb_check_each(DRV_BITFURY, drv, dev); return usb_check_each(DRV_BITFURY, drv, dev);
#endif #endif
#ifdef USE_MODMINER #ifdef USE_MODMINER
if (drv->drv_id == DRIVER_MODMINER) if (drv->drv_id == DRIVER_modminer)
return usb_check_each(DRV_MODMINER, drv, dev); return usb_check_each(DRV_MODMINER, drv, dev);
#endif #endif
#ifdef USE_ICARUS #ifdef USE_ICARUS
if (drv->drv_id == DRIVER_ICARUS) if (drv->drv_id == DRIVER_icarus)
return usb_check_each(DRV_ICARUS, drv, dev); return usb_check_each(DRV_ICARUS, drv, dev);
#endif #endif
#ifdef USE_AVALON #ifdef USE_AVALON
if (drv->drv_id == DRIVER_AVALON) if (drv->drv_id == DRIVER_avalon)
return usb_check_each(DRV_AVALON, drv, dev); return usb_check_each(DRV_AVALON, drv, dev);
#endif #endif
@ -3151,12 +3151,12 @@ void usb_cleanup()
for (i = 0; i < total_devices; i++) { for (i = 0; i < total_devices; i++) {
cgpu = devices[i]; cgpu = devices[i];
switch (cgpu->drv->drv_id) { switch (cgpu->drv->drv_id) {
case DRIVER_BFLSC: case DRIVER_bflsc:
case DRIVER_BITFORCE: case DRIVER_bitforce:
case DRIVER_BITFURY: case DRIVER_bitfury:
case DRIVER_MODMINER: case DRIVER_modminer:
case DRIVER_ICARUS: case DRIVER_icarus:
case DRIVER_AVALON: case DRIVER_avalon:
wr_lock(cgpu->usbinfo.devlock); wr_lock(cgpu->usbinfo.devlock);
release_cgpu(cgpu); release_cgpu(cgpu);
wr_unlock(cgpu->usbinfo.devlock); wr_unlock(cgpu->usbinfo.devlock);