Browse Source

Port antminer driver to use set_device_funcs

Luke Dashjr 11 years ago
parent
commit
61ee5f5054
3 changed files with 31 additions and 28 deletions
  1. 18 17
      driver-antminer.c
  2. 6 10
      driver-icarus.c
  3. 7 1
      driver-icarus.h

+ 18 - 17
driver-antminer.c

@@ -1,5 +1,5 @@
 /*
- * Copyright 2013-2014 Luke Dashjr
+ * Copyright 2013-2015 Luke Dashjr
  * Copyright 2013-2014 Nate Woolls
  * Copyright 2013 Lingchao Xu
  *
@@ -37,6 +37,8 @@
 #define ANTMINER_COMMAND_OFFSET 32
 
 BFG_REGISTER_DRIVER(antminer_drv)
+static
+const struct bfg_set_device_definition antminer_set_device_funcs[];
 
 static
 bool antminer_detect_one(const char *devpath)
@@ -54,12 +56,14 @@ bool antminer_detect_one(const char *devpath)
 		.read_size = 5,
 	};
 	
-	if (!icarus_detect_custom(devpath, drv, info))
+	struct cgpu_info * const dev = icarus_detect_custom(devpath, drv, info);
+	if (!dev)
 	{
 		free(info);
 		return false;
 	}
 	
+	dev->set_device_funcs = antminer_set_device_funcs;
 	info->read_count = 15;
 	
 	return true;
@@ -114,7 +118,7 @@ char *antminer_get_clock(struct cgpu_info *cgpu, char *replybuf)
 }
 
 static
-char *antminer_set_clock(struct cgpu_info *cgpu, char *setting, char *replybuf)
+const char *antminer_set_clock(struct cgpu_info * const cgpu, const char * const optname, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	if (!setting || !*setting)
 		return "missing clock setting";
@@ -129,7 +133,7 @@ char *antminer_set_clock(struct cgpu_info *cgpu, char *setting, char *replybuf)
 	}
 	
 	//remove leading character
-	char *hex_setting = setting + 1;
+	const char * const hex_setting = &setting[1];
 
 	uint8_t reg_data[4] = {0};
 	
@@ -165,18 +169,6 @@ char *antminer_set_clock(struct cgpu_info *cgpu, char *setting, char *replybuf)
 	return antminer_get_clock(cgpu, replybuf);
 }
 
-static
-char *antminer_set_device(struct cgpu_info *cgpu, char *option, char *setting, char *replybuf)
-{		
-	if (strcasecmp(option, "clock") == 0)
-	{
-		return antminer_set_clock(cgpu, setting, replybuf);
-	}
-
-	sprintf(replybuf, "Unknown option: %s", option);
-	return replybuf;
-}
-
 static
 void antminer_flash_led(const struct cgpu_info *antminer)
 {
@@ -206,6 +198,16 @@ bool antminer_identify(struct cgpu_info *antminer)
 	return true;
 }
 
+static
+const struct bfg_set_device_definition antminer_set_device_funcs[] = {
+	{"baud"         , icarus_set_baud         , "serial baud rate"},
+	{"work_division", icarus_set_work_division, "number of pieces work is split into"},
+	{"reopen"       , icarus_set_reopen       , "how often to reopen device: never, timeout, cycle, (or now for a one-shot reopen)"},
+	{"timing"       , icarus_set_timing       , "timing of device; see README.FPGA"},
+	{"clock", antminer_set_clock, "clock frequency"},
+	{NULL},
+};
+
 static
 void antminer_drv_init()
 {
@@ -213,7 +215,6 @@ void antminer_drv_init()
 	antminer_drv.dname = "antminer";
 	antminer_drv.name = "AMU";
 	antminer_drv.lowl_probe = antminer_lowl_probe;
-	antminer_drv.set_device = antminer_set_device,
 	antminer_drv.identify_device = antminer_identify;
 	++antminer_drv.probe_priority;
 }

+ 6 - 10
driver-icarus.c

@@ -412,7 +412,6 @@ const char *_icarus_set_timing(struct ICARUS_INFO * const info, const char * con
 	return NULL;
 }
 
-static
 const char *icarus_set_timing(struct cgpu_info * const proc, const char * const optname, const char * const buf, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	struct ICARUS_INFO * const info = proc->device_data;
@@ -495,7 +494,7 @@ int icarus_probe_work_division(const int fd, const char * const repr, struct ICA
 	return work_division;
 }
 
-bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct ICARUS_INFO *info)
+struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *api, struct ICARUS_INFO *info)
 {
 	struct timeval tv_start, tv_finish;
 	int fd;
@@ -514,7 +513,7 @@ bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct IC
 	fd = icarus_open2(devpath, baud, true);
 	if (unlikely(fd == -1)) {
 		applog(LOG_DEBUG, "%s: Failed to open %s", api->dname, devpath);
-		return false;
+		return NULL;
 	}
 	
 	// Set a default so that individual drivers need not specify
@@ -576,7 +575,7 @@ bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct IC
 				   "Test failed at %s: get %s, should: %s",
 				   api->dname,
 				   devpath, nonce_hex, info->golden_nonce);
-			return false;
+			return NULL;
 		}
 		
 		if (info->read_size - ICARUS_NONCE_SIZE != bytes_left)
@@ -586,7 +585,7 @@ bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct IC
 				   "Test failed at %s: expected %d bytes, got %d",
 				   api->dname,
 				   devpath, info->read_size, ICARUS_NONCE_SIZE + bytes_left);
-			return false;
+			return NULL;
 		}
 	}
 	else
@@ -599,7 +598,7 @@ bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct IC
 			devpath, nonce_hex);
 
 	if (serial_claim_v(devpath, api))
-		return false;
+		return NULL;
 
 	_icarus_set_timing(info, api->dname, api, "");
 	if (!info->fpga_count)
@@ -638,7 +637,7 @@ bool icarus_detect_custom(const char *devpath, struct device_drv *api, struct IC
 
 	timersub(&tv_finish, &tv_start, &(info->golden_tv));
 
-	return true;
+	return icarus;
 }
 
 static bool icarus_detect_one(const char *devpath)
@@ -1300,7 +1299,6 @@ static struct api_data *icarus_drv_stats(struct cgpu_info *cgpu)
 	return root;
 }
 
-static
 const char *icarus_set_baud(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	struct ICARUS_INFO * const info = proc->device_data;
@@ -1323,7 +1321,6 @@ const char *icarus_set_probe_timeout(struct cgpu_info * const proc, const char *
 	return NULL;
 }
 
-static
 const char *icarus_set_work_division(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	struct ICARUS_INFO * const info = proc->device_data;
@@ -1354,7 +1351,6 @@ const char *icarus_set_fpga_count(struct cgpu_info * const proc, const char * co
 	return NULL;
 }
 
-static
 const char *icarus_set_reopen(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	struct ICARUS_INFO * const info = proc->device_data;

+ 7 - 1
driver-icarus.h

@@ -17,6 +17,7 @@
 #include <stdint.h>
 #include <sys/time.h>
 
+#include "deviceapi.h"
 #include "dynclock.h"
 #include "miner.h"
 
@@ -160,11 +161,16 @@ struct icarus_state {
 	uint8_t *ob_bin;
 };
 
-bool icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
+extern struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
 extern int icarus_gets(unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
 extern int icarus_write(int fd, const void *buf, size_t bufLen);
 extern bool icarus_init(struct thr_info *);
 extern void do_icarus_close(struct thr_info *thr);
 extern bool icarus_job_start(struct thr_info *);
 
+extern const char *icarus_set_baud(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
+extern const char *icarus_set_work_division(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
+extern const char *icarus_set_reopen(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
+extern const char *icarus_set_timing(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
+
 #endif