Browse Source

bitfury: Migrate all drivers to set_device_funcs interface

Luke Dashjr 12 years ago
parent
commit
e058930aa1
8 changed files with 76 additions and 88 deletions
  1. 1 1
      driver-bfsb.c
  2. 24 41
      driver-bitfury.c
  3. 6 1
      driver-bitfury.h
  4. 1 1
      driver-hashbuster.c
  5. 41 41
      driver-hashbusterusb.c
  6. 1 1
      driver-littlefury.c
  7. 1 1
      driver-metabank.c
  8. 1 1
      driver-nanofury.c

+ 1 - 1
driver-bfsb.c

@@ -96,6 +96,7 @@ int bfsb_autodetect()
 				cgpu = malloc(sizeof(*cgpu));
 				*cgpu = (struct cgpu_info){
 					.drv = &bfsb_drv,
+					.set_device_funcs = bitfury_set_device_funcs,
 					.procs = chip_n,
 					.device_data = devicelist,
 				};
@@ -176,7 +177,6 @@ struct device_drv bfsb_drv = {
 	.job_process_results = bitfury_job_process_results,
 	.get_api_extra_device_detail = bfsb_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,
-	.set_device = bitfury_set_device,
 	.thread_disable = bitfury_disable,
 	.thread_enable = bitfury_enable,
 	.thread_shutdown = bfsb_shutdown,

+ 24 - 41
driver-bitfury.c

@@ -38,8 +38,7 @@
 #include "spidevc.h"
 
 BFG_REGISTER_DRIVER(bitfury_drv)
-
-static char *bitfury_spi_port_config(struct cgpu_info *, char *, char *, char *);
+const struct bfg_set_device_definition bitfury_set_device_funcs[];
 
 static
 int bitfury_autodetect()
@@ -62,7 +61,7 @@ int bitfury_autodetect()
 		struct bitfury_device dummy_bitfury = {
 			.spi = sys_spi,
 		};
-		drv_set_defaults(&bitfury_drv, bitfury_spi_port_config, &dummy_bitfury, NULL, NULL, 0);
+		drv_set_defaults(&bitfury_drv, bitfury_set_device_funcs_probe, &dummy_bitfury, NULL, NULL, 1);
 	}
 	
 	chip_n = libbitfury_detectChips1(sys_spi);
@@ -74,6 +73,7 @@ int bitfury_autodetect()
 	}
 
 	bitfury_info->procs = chip_n;
+	bitfury_info->set_device_funcs = bitfury_set_device_funcs;
 	add_cgpu(bitfury_info);
 	
 	return 1;
@@ -671,7 +671,7 @@ struct api_data *bitfury_api_device_status(struct cgpu_info * const cgpu)
 }
 
 static
-bool _bitfury_set_device_parse_setting(uint32_t * const rv, char * const setting, char * const replybuf, const int maxval)
+bool _bitfury_set_device_parse_setting(uint32_t * const rv, const char * const setting, char * const replybuf, const int maxval)
 {
 	char *p;
 	long int nv;
@@ -691,56 +691,40 @@ bool _bitfury_set_device_parse_setting(uint32_t * const rv, char * const setting
 	return true;
 }
 
-static
-char *bitfury_spi_port_config(struct cgpu_info * const proc, char *option, char *setting, char *replybuf)
+const char *bitfury_set_baud(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
 	struct bitfury_device * const bitfury = proc->device_data;
+	if (!_bitfury_set_device_parse_setting(&bitfury->spi->speed, setting, replybuf, INT_MAX))
+		return replybuf;
 	
-	if (!strcasecmp(option, "baud"))
-	{
-		if (!_bitfury_set_device_parse_setting(&bitfury->spi->speed, setting, replybuf, INT_MAX))
-			return replybuf;
-		
-		return NULL;
-	}
-	
-	return "";
+	return NULL;
 }
 
-char *bitfury_set_device(struct cgpu_info * const proc, char * const option, char * const setting, char * const replybuf)
+const char *bitfury_set_osc6_bits(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
 	struct bitfury_device * const bitfury = proc->device_data;
-	char *rv;
 	uint32_t newval;
+	struct freq_stat * const c = &bitfury->chip_stat;
 	
-	if (!strcasecmp(option, "help"))
-	{
-		sprintf(replybuf, "baud: SPI baud rate\nosc6_bits: range 1-%d (slow to fast)", BITFURY_MAX_OSC6_BITS);
+	newval = bitfury->osc6_bits;
+	if (!_bitfury_set_device_parse_setting(&newval, setting, replybuf, BITFURY_MAX_OSC6_BITS))
 		return replybuf;
-	}
 	
-	rv = bitfury_spi_port_config(proc, option, setting, replybuf);
-	if ((!rv) || rv[0])
-		return rv;
+	bitfury->osc6_bits = newval;
+	bitfury->force_reinit = true;
+	c->osc6_max = 0;
 	
-	if (!strcasecmp(option, "osc6_bits"))
-	{
-		struct freq_stat * const c = &bitfury->chip_stat;
-		newval = bitfury->osc6_bits;
-		if (!_bitfury_set_device_parse_setting(&newval, setting, replybuf, BITFURY_MAX_OSC6_BITS))
-			return replybuf;
-		
-		bitfury->osc6_bits = newval;
-		bitfury->force_reinit = true;
-		c->osc6_max = 0;
-		
-		return NULL;
-	}
-	
-	sprintf(replybuf, "Unknown option: %s", option);
-	return replybuf;
+	return NULL;
 }
 
+const struct bfg_set_device_definition bitfury_set_device_funcs[] = {
+	{"osc6_bits", bitfury_set_osc6_bits, "range 1-"BITFURY_MAX_OSC6_BITS_S" (slow to fast)"},
+	// NOTE: bitfury_set_device_funcs_probe should begin here:
+	{"baud", bitfury_set_baud, "SPI baud rate"},
+	{NULL},
+};
+const struct bfg_set_device_definition *bitfury_set_device_funcs_probe = &bitfury_set_device_funcs[1];
+
 #ifdef HAVE_CURSES
 void bitfury_tui_wlogprint_choices(struct cgpu_info *cgpu)
 {
@@ -804,7 +788,6 @@ struct device_drv bitfury_drv = {
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,
-	.set_device = bitfury_set_device,
 	
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = bitfury_wlogprint_status,

+ 6 - 1
driver-bitfury.h

@@ -7,6 +7,12 @@
 #include "miner.h"
 
 #define BITFURY_MAX_OSC6_BITS  60
+#define BITFURY_MAX_OSC6_BITS_S  "60"
+
+extern const struct bfg_set_device_definition bitfury_set_device_funcs[];
+extern const struct bfg_set_device_definition *bitfury_set_device_funcs_probe;
+extern const char *bitfury_set_baud(struct cgpu_info *, const char *, const char *, char *, enum bfg_set_device_replytype *);
+extern const char *bitfury_set_osc6_bits(struct cgpu_info *, const char *, const char *, char *, enum bfg_set_device_replytype *);
 
 extern bool bitfury_prepare(struct thr_info *);
 extern bool bitfury_init_chip(struct cgpu_info *);
@@ -19,7 +25,6 @@ extern void bitfury_do_io(struct thr_info *);
 extern int64_t bitfury_job_process_results(struct thr_info *, struct work *, bool stopping);
 extern struct api_data *bitfury_api_device_detail(struct cgpu_info *);
 extern struct api_data *bitfury_api_device_status(struct cgpu_info *);
-extern char *bitfury_set_device(struct cgpu_info *, char *, char *, char *);
 extern void bitfury_tui_wlogprint_choices(struct cgpu_info *);
 extern const char *bitfury_tui_handle_choice(struct cgpu_info *, int input);
 extern void bitfury_wlogprint_status(struct cgpu_info *);

+ 1 - 1
driver-hashbuster.c

@@ -201,6 +201,7 @@ bool hashbuster_lowl_probe(const struct lowlevel_device_info * const info)
 	cgpu = malloc(sizeof(*cgpu));
 	*cgpu = (struct cgpu_info){
 		.drv = &hashbuster_drv,
+		.set_device_funcs = bitfury_set_device_funcs,
 		.device_data = lowlevel_ref(info),
 		.threads = 1,
 		.procs = chip_n,
@@ -311,7 +312,6 @@ struct device_drv hashbuster_drv = {
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,
-	.set_device = bitfury_set_device,
 	
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = bitfury_wlogprint_status,

+ 41 - 41
driver-hashbusterusb.c

@@ -28,6 +28,7 @@
 #define HASHBUSTER_MAX_BYTES_PER_SPI_TRANSFER 61
 
 BFG_REGISTER_DRIVER(hashbusterusb_drv)
+static const struct bfg_set_device_definition hashbusterusb_set_device_funcs[];
 
 struct hashbusterusb_state {
 	uint16_t voltage;
@@ -248,6 +249,7 @@ fail:
 		cgpu = malloc(sizeof(*cgpu));
 		*cgpu = (struct cgpu_info){
 			.drv = &hashbusterusb_drv,
+			.set_device_funcs = hashbusterusb_set_device_funcs,
 			.procs = chip_n,
 			.device_data = devicelist,
 			.cutofftemp = 200,
@@ -460,51 +462,50 @@ struct api_data *hashbusterusb_api_extra_device_stats(struct cgpu_info * const c
 }
 
 static
-char *hashbusterusb_set_device(struct cgpu_info * const proc, char * const option, char * const setting, char * const replybuf)
+const char *hashbusterusb_rpcset_vrmlock(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
-	if (!strcasecmp(option, "help"))
-	{
-		bitfury_set_device(proc, option, setting, replybuf);
-		tailsprintf(replybuf, 1024, "\nvrmlock: Lock the VRM voltage to safe range\nvrmunlock: Allow setting potentially unsafe voltages (requires unlock code)\nvoltage: Set voltage");
-		return replybuf;
-	}
-	
-	if (!strcasecmp(option, "vrmlock"))
-	{
-		cgpu_request_control(proc->device);
-		hashbusterusb_vrm_lock(proc);
-		cgpu_release_control(proc->device);
-		return NULL;
-	}
-	
-	if (!strcasecmp(option, "vrmunlock"))
-	{
-		cgpu_request_control(proc->device);
-		const bool rv = hashbusterusb_vrm_unlock(proc, setting);
-		cgpu_release_control(proc->device);
-		if (!rv)
-			return "Unlock error";
-		return NULL;
-	}
+	cgpu_request_control(proc->device);
+	hashbusterusb_vrm_lock(proc);
+	cgpu_release_control(proc->device);
+	return NULL;
+}
+
+static
+const char *hashbusterusb_rpcset_vrmunlock(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
+{
+	cgpu_request_control(proc->device);
+	const bool rv = hashbusterusb_vrm_unlock(proc, setting);
+	cgpu_release_control(proc->device);
+	if (!rv)
+		return "Unlock error";
+	return NULL;
+}
+
+static
+const char *hashbusterusb_rpcset_voltage(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
+{
+	const int val = atof(setting) * 1000;
+	if (val < 600 || val > 1100)
+		return "Invalid PSU voltage value";
 	
-	if (!strcasecmp(option, "voltage"))
-	{
-		const int val = atof(setting) * 1000;
-		if (val < 600 || val > 1100)
-			return "Invalid PSU voltage value";
-		
-		cgpu_request_control(proc->device);
-		const bool rv = hashbusterusb_set_voltage(proc, val);
-		cgpu_release_control(proc->device);
-		
-		if (!rv)
-			return "Voltage change error";
-		return NULL;
-	}
+	cgpu_request_control(proc->device);
+	const bool rv = hashbusterusb_set_voltage(proc, val);
+	cgpu_release_control(proc->device);
 	
-	return bitfury_set_device(proc, option, setting, replybuf);
+	if (!rv)
+		return "Voltage change error";
+	return NULL;
 }
 
+static const struct bfg_set_device_definition hashbusterusb_set_device_funcs[] = {
+	{"baud"     , bitfury_set_baud              , "SPI baud rate"},
+	{"osc6_bits", bitfury_set_osc6_bits         , "range 1-"BITFURY_MAX_OSC6_BITS_S" (slow to fast)"},
+	{"vrmlock"  , hashbusterusb_rpcset_vrmlock  , "Lock the VRM voltage to safe range"},
+	{"vrmunlock", hashbusterusb_rpcset_vrmunlock, "Allow setting potentially unsafe voltages (requires unlock code)"},
+	{"voltage"  , hashbusterusb_rpcset_voltage  , "Set voltage"},
+	{NULL},
+};
+
 #ifdef HAVE_CURSES
 void hashbusterusb_tui_wlogprint_choices(struct cgpu_info * const proc)
 {
@@ -598,7 +599,6 @@ struct device_drv hashbusterusb_drv = {
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = hashbusterusb_api_extra_device_stats,
-	.set_device = hashbusterusb_set_device,
 	.identify_device = hashbusterusb_identify,
 	
 #ifdef HAVE_CURSES

+ 1 - 1
driver-littlefury.c

@@ -327,6 +327,7 @@ bool littlefury_detect_one(const char *devpath)
 	cgpu = malloc(sizeof(*cgpu));
 	*cgpu = (struct cgpu_info){
 		.drv = &littlefury_drv,
+		.set_device_funcs = bitfury_set_device_funcs,
 		.device_path = strdup(devpath),
 		.deven = DEV_ENABLED,
 		.procs = chips,
@@ -514,7 +515,6 @@ struct device_drv littlefury_drv = {
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,
-	.set_device = bitfury_set_device,
 	
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = bitfury_wlogprint_status,

+ 1 - 1
driver-metabank.c

@@ -118,6 +118,7 @@ int metabank_autodetect()
 				cgpu = malloc(sizeof(*cgpu));
 				*cgpu = (struct cgpu_info){
 					.drv = &metabank_drv,
+					.set_device_funcs = bitfury_set_device_funcs,
 					.procs = chip_n,
 					.device_data = devicelist,
 					.cutofftemp = 50,
@@ -241,7 +242,6 @@ struct device_drv metabank_drv = {
 	.get_api_extra_device_detail = metabank_api_extra_device_detail,
 	.get_api_extra_device_status = metabank_api_extra_device_status,
 	.get_stats = metabank_get_stats,
-	.set_device = bitfury_set_device,
 	
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = bitfury_wlogprint_status,

+ 1 - 1
driver-nanofury.c

@@ -223,6 +223,7 @@ bool nanofury_lowl_probe(const struct lowlevel_device_info * const info)
 	cgpu = malloc(sizeof(*cgpu));
 	*cgpu = (struct cgpu_info){
 		.drv = &nanofury_drv,
+		.set_device_funcs = bitfury_set_device_funcs,
 		.device_data = lowlevel_ref(info),
 		.threads = 1,
 		// TODO: .name
@@ -393,7 +394,6 @@ struct device_drv nanofury_drv = {
 	
 	.get_api_extra_device_detail = bitfury_api_device_detail,
 	.get_api_extra_device_status = bitfury_api_device_status,
-	.set_device = bitfury_set_device,
 	.identify_device = nanofury_identify,
 	
 #ifdef HAVE_CURSES