Commit 8875197466ac8b144d177b954ad396bf73c2b007

ckolivas 2013-09-28T10:25:48

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

diff --git a/api.c b/api.c
index e86ac7b..e145543 100644
--- a/api.c
+++ b/api.c
@@ -1220,15 +1220,15 @@ static int numascs()
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 #ifdef USE_AVALON
-		if (devices[i]->drv->drv_id == DRIVER_AVALON)
+		if (devices[i]->drv->drv_id == DRIVER_avalon)
 			count++;
 #endif
 #ifdef USE_BFLSC
-		if (devices[i]->drv->drv_id == DRIVER_BFLSC)
+		if (devices[i]->drv->drv_id == DRIVER_bflsc)
 			count++;
 #endif
 #ifdef USE_BITFURY
-		if (devices[i]->drv->drv_id == DRIVER_BITFURY)
+		if (devices[i]->drv->drv_id == DRIVER_bitfury)
 			count++;
 #endif
 	}
@@ -1244,15 +1244,15 @@ static int ascdevice(int ascid)
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 #ifdef USE_AVALON
-		if (devices[i]->drv->drv_id == DRIVER_AVALON)
+		if (devices[i]->drv->drv_id == DRIVER_avalon)
 			count++;
 #endif
 #ifdef USE_BFLSC
-		if (devices[i]->drv->drv_id == DRIVER_BFLSC)
+		if (devices[i]->drv->drv_id == DRIVER_bflsc)
 			count++;
 #endif
 #ifdef USE_BITFURY
-		if (devices[i]->drv->drv_id == DRIVER_BITFURY)
+		if (devices[i]->drv->drv_id == DRIVER_bitfury)
 			count++;
 #endif
 		if (count == (ascid + 1))
@@ -1278,19 +1278,19 @@ static int numpgas()
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 #ifdef USE_BITFORCE
-		if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
+		if (devices[i]->drv->drv_id == DRIVER_bitforce)
 			count++;
 #endif
 #ifdef USE_ICARUS
-		if (devices[i]->drv->drv_id == DRIVER_ICARUS)
+		if (devices[i]->drv->drv_id == DRIVER_icarus)
 			count++;
 #endif
 #ifdef USE_ZTEX
-		if (devices[i]->drv->drv_id == DRIVER_ZTEX)
+		if (devices[i]->drv->drv_id == DRIVER_ztex)
 			count++;
 #endif
 #ifdef USE_MODMINER
-		if (devices[i]->drv->drv_id == DRIVER_MODMINER)
+		if (devices[i]->drv->drv_id == DRIVER_modminer)
 			count++;
 #endif
 	}
@@ -1306,19 +1306,19 @@ static int pgadevice(int pgaid)
 	rd_lock(&devices_lock);
 	for (i = 0; i < total_devices; i++) {
 #ifdef USE_BITFORCE
-		if (devices[i]->drv->drv_id == DRIVER_BITFORCE)
+		if (devices[i]->drv->drv_id == DRIVER_bitforce)
 			count++;
 #endif
 #ifdef USE_ICARUS
-		if (devices[i]->drv->drv_id == DRIVER_ICARUS)
+		if (devices[i]->drv->drv_id == DRIVER_icarus)
 			count++;
 #endif
 #ifdef USE_ZTEX
-		if (devices[i]->drv->drv_id == DRIVER_ZTEX)
+		if (devices[i]->drv->drv_id == DRIVER_ztex)
 			count++;
 #endif
 #ifdef USE_MODMINER
-		if (devices[i]->drv->drv_id == DRIVER_MODMINER)
+		if (devices[i]->drv->drv_id == DRIVER_modminer)
 			count++;
 #endif
 		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;
 
 #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);
 #endif
 #ifdef USE_MODMINER
-		if (cgpu->drv->drv_id == DRIVER_MODMINER)
+		if (cgpu->drv->drv_id == DRIVER_modminer)
 			frequency = cgpu->clock;
 #endif
 
diff --git a/cgminer.c b/cgminer.c
index 953ab02..4021990 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -7496,7 +7496,7 @@ void enable_device(struct cgpu_info *cgpu)
 #endif
 	}
 #ifdef HAVE_OPENCL
-	if (cgpu->drv->drv_id == DRIVER_OPENCL) {
+	if (cgpu->drv->drv_id == DRIVER_opencl) {
 		gpu_threads += cgpu->threads;
 	}
 #endif
diff --git a/driver-avalon.c b/driver-avalon.c
index 333add9..0223c62 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -1600,7 +1600,7 @@ static char *avalon_set_device(struct cgpu_info *avalon, char *option, char *set
 }
 
 struct device_drv avalon_drv = {
-	.drv_id = DRIVER_AVALON,
+	.drv_id = DRIVER_avalon,
 	.dname = "avalon",
 	.name = "AVA",
 	.drv_detect = avalon_detect,
diff --git a/driver-bflsc.c b/driver-bflsc.c
index 48cadf2..26cf0c6 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -1915,7 +1915,7 @@ else a whole lot of something like these ... etc
 }
 
 struct device_drv bflsc_drv = {
-	.drv_id = DRIVER_BFLSC,
+	.drv_id = DRIVER_bflsc,
 	.dname = "BitForceSC",
 	.name = BFLSC_SINGLE,
 	.drv_detect = bflsc_detect,
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 30a6b2d..2132427 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -742,7 +742,7 @@ static struct api_data *bitforce_api_stats(struct cgpu_info *cgpu)
 }
 
 struct device_drv bitforce_drv = {
-	.drv_id = DRIVER_BITFORCE,
+	.drv_id = DRIVER_bitforce,
 	.dname = "BitForce",
 	.name = "BFL",
 	.drv_detect = bitforce_detect,
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 7152443..d26ae62 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -310,7 +310,7 @@ static void bitfury_shutdown(struct thr_info *thr)
 
 /* Currently hardcoded to BF1 devices */
 struct device_drv bitfury_drv = {
-	.drv_id = DRIVER_BITFURY,
+	.drv_id = DRIVER_bitfury,
 	.dname = "bitfury",
 	.name = "BF1",
 	.drv_detect = bitfury_detect,
diff --git a/driver-icarus.c b/driver-icarus.c
index 59fd554..0dbcbb4 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -1210,7 +1210,7 @@ static void icarus_shutdown(__maybe_unused struct thr_info *thr)
 }
 
 struct device_drv icarus_drv = {
-	.drv_id = DRIVER_ICARUS,
+	.drv_id = DRIVER_icarus,
 	.dname = "Icarus",
 	.name = "ICA",
 	.drv_detect = icarus_detect,
diff --git a/driver-modminer.c b/driver-modminer.c
index 8f85855..8e7f651 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -1132,7 +1132,7 @@ static char *modminer_set_device(struct cgpu_info *modminer, char *option, char 
 }
 
 struct device_drv modminer_drv = {
-	.drv_id = DRIVER_MODMINER,
+	.drv_id = DRIVER_modminer,
 	.dname = "ModMiner",
 	.name = "MMQ",
 	.drv_detect = modminer_detect,
diff --git a/driver-opencl.c b/driver-opencl.c
index 57df2dc..0e2aba2 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -753,7 +753,7 @@ retry:
 		for (i = 0; i < mining_threads; ++i) {
 			thr = get_thread(i);
 			cgpu = thr->cgpu;
-			if (cgpu->drv->drv_id != DRIVER_OPENCL)
+			if (cgpu->drv->drv_id != DRIVER_opencl)
 				continue;
 			if (dev_from_id(i) != selected)
 				continue;
@@ -1148,7 +1148,7 @@ select_cgpu:
 	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1173,7 +1173,7 @@ select_cgpu:
 
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1210,7 +1210,7 @@ select_cgpu:
 	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
 		thr = get_thread(thr_id);
 		cgpu = thr->cgpu;
-		if (cgpu->drv->drv_id != DRIVER_OPENCL)
+		if (cgpu->drv->drv_id != DRIVER_opencl)
 			continue;
 		if (dev_from_id(thr_id) != gpu)
 			continue;
@@ -1575,7 +1575,7 @@ static void opencl_thread_shutdown(struct thr_info *thr)
 }
 
 struct device_drv opencl_drv = {
-	.drv_id = DRIVER_OPENCL,
+	.drv_id = DRIVER_opencl,
 	.dname = "opencl",
 	.name = "GPU",
 	.drv_detect = opencl_detect,
diff --git a/driver-ztex.c b/driver-ztex.c
index 2525471..38c6490 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -413,7 +413,7 @@ static void ztex_disable(struct thr_info *thr)
 }
 
 struct device_drv ztex_drv = {
-	.drv_id = DRIVER_ZTEX,
+	.drv_id = DRIVER_ztex,
 	.dname = "ztex",
 	.name = "ZTX",
 	.drv_detect = ztex_detect,
diff --git a/miner.h b/miner.h
index 867ca0e..780b36b 100644
--- a/miner.h
+++ b/miner.h
@@ -230,17 +230,23 @@ static inline int fsync (int fd)
 #define MIN(x, y)	((x) > (y) ? (y) : (x))
 #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 {
-	DRIVER_OPENCL = 0,
-	DRIVER_ICARUS,
-	DRIVER_BITFORCE,
-	DRIVER_BITFURY,
-	DRIVER_MODMINER,
-	DRIVER_ZTEX,
-	DRIVER_BFLSC,
-	DRIVER_AVALON,
+	DRIVER_PARSE_COMMANDS
 	DRIVER_MAX
 };
+#undef DRIVER_ADD_COMMAND
 
 enum alive {
 	LIFE_WELL,
diff --git a/usbutils.c b/usbutils.c
index 136e93e..28933ef 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -1899,32 +1899,32 @@ static struct usb_find_devices *usb_check(__maybe_unused struct device_drv *drv,
 	}
 
 #ifdef USE_BFLSC
-	if (drv->drv_id == DRIVER_BFLSC)
+	if (drv->drv_id == DRIVER_bflsc)
 		return usb_check_each(DRV_BFLSC, drv, dev);
 #endif
 
 #ifdef USE_BITFORCE
-	if (drv->drv_id == DRIVER_BITFORCE)
+	if (drv->drv_id == DRIVER_bitforce)
 		return usb_check_each(DRV_BITFORCE, drv, dev);
 #endif
 
 #ifdef USE_BITFURY
-	if (drv->drv_id == DRIVER_BITFURY)
+	if (drv->drv_id == DRIVER_bitfury)
 		return usb_check_each(DRV_BITFURY, drv, dev);
 #endif
 
 #ifdef USE_MODMINER
-	if (drv->drv_id == DRIVER_MODMINER)
+	if (drv->drv_id == DRIVER_modminer)
 		return usb_check_each(DRV_MODMINER, drv, dev);
 #endif
 
 #ifdef USE_ICARUS
-	if (drv->drv_id == DRIVER_ICARUS)
+	if (drv->drv_id == DRIVER_icarus)
 		return usb_check_each(DRV_ICARUS, drv, dev);
 #endif
 
 #ifdef USE_AVALON
-	if (drv->drv_id == DRIVER_AVALON)
+	if (drv->drv_id == DRIVER_avalon)
 		return usb_check_each(DRV_AVALON, drv, dev);
 #endif
 
@@ -3151,12 +3151,12 @@ void usb_cleanup()
 	for (i = 0; i < total_devices; i++) {
 		cgpu = devices[i];
 		switch (cgpu->drv->drv_id) {
-			case DRIVER_BFLSC:
-			case DRIVER_BITFORCE:
-			case DRIVER_BITFURY:
-			case DRIVER_MODMINER:
-			case DRIVER_ICARUS:
-			case DRIVER_AVALON:
+			case DRIVER_bflsc:
+			case DRIVER_bitforce:
+			case DRIVER_bitfury:
+			case DRIVER_modminer:
+			case DRIVER_icarus:
+			case DRIVER_avalon:
 				wr_lock(cgpu->usbinfo.devlock);
 				release_cgpu(cgpu);
 				wr_unlock(cgpu->usbinfo.devlock);