Browse Source

Merge commit 'e931b72' into cg_merges_20121218

Conflicts:
	API-README
	api.c
	miner.h
Luke Dashjr 13 years ago
parent
commit
64bb8f2927
3 changed files with 96 additions and 1 deletions
  1. 18 0
      API-README
  2. 77 1
      api.c
  3. 1 0
      miner.h

+ 18 - 0
API-README

@@ -332,6 +332,17 @@ The list of requests - a (*) means it requires privileged access - and replies a
                                                        0 to 9999)
                               coinbase-sig (string)
 
+ pgaset|N,opt[,val] (*)
+               none           There is no reply section just the STATUS section
+                              stating the results of setting PGA N with opt[,val]
+                              This is only available if PGA mining is enabled
+
+                              If the PGA does not support any set options, it will
+                              always return a WARN stating pgaset isn't supported
+
+                              If opt=help it will return an INFO status with a
+                              help message about the options available
+
 When you enable, disable or restart a GPU or PGA, you will also get Thread messages
 in the BFGMiner status window
 
@@ -384,6 +395,13 @@ miner.php - an example web page to access the API
 Feature Changelog for external applications using the API:
 
 
+API V1.23
+
+Added API commands:
+ 'pgaset'
+
+----------
+
 API V1.22
 
 Enforced output limitation:

+ 77 - 1
api.c

@@ -133,7 +133,7 @@ static const char SEPARATOR = '|';
 #define SEPSTR "|"
 static const char GPUSEP = ',';
 
-static const char *APIVERSION = "1.22";
+static const char *APIVERSION = "1.23";
 static const char *DEAD = "Dead";
 static const char *SICK = "Sick";
 static const char *NOSTART = "NoStart";
@@ -380,6 +380,14 @@ static const char *JSON_PARAMETER = "parameter";
 #define MSG_CONPAR 85
 #define MSG_CONVAL 86
 
+#ifdef HAVE_AN_FPGA
+#define MSG_MISPGAOPT 89
+#define MSG_PGANOSET 90
+#define MSG_PGAHELP 91
+#define MSG_PGASETOK 92
+#define MSG_PGASETERR 93
+#endif
+
 enum code_severity {
 	SEVERITY_ERR,
 	SEVERITY_WARN,
@@ -543,6 +551,13 @@ struct CODES {
  { SEVERITY_ERR,   MSG_INVNUM,	PARAM_BOTH,	"Invalid number (%d) for '%s' range is 0-9999" },
  { SEVERITY_ERR,   MSG_CONPAR,	PARAM_NONE,	"Missing config parameters 'name,N'" },
  { SEVERITY_ERR,   MSG_CONVAL,	PARAM_STR,	"Missing config value N for '%s,N'" },
+#ifdef HAVE_AN_FPGA
+ { SEVERITY_ERR,   MSG_MISPGAOPT, PARAM_NONE,	"Missing option after PGA number" },
+ { SEVERITY_WARN,  MSG_PGANOSET, PARAM_PGA,	"PGA %d does not support pgaset" },
+ { SEVERITY_INFO,  MSG_PGAHELP, PARAM_BOTH,	"PGA %d set help: %s" },
+ { SEVERITY_SUCC,  MSG_PGASETOK, PARAM_BOTH,	"PGA %d set OK" },
+ { SEVERITY_ERR,   MSG_PGASETERR, PARAM_BOTH,	"PGA %d set failed: %s" },
+#endif
  { SEVERITY_FAIL, 0, 0, NULL }
 };
 
@@ -2975,6 +2990,64 @@ static void setconfig(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 	message(io_data, MSG_SETCONFIG, value, param, isjson);
 }
 
+#ifdef HAVE_AN_FPGA
+static void pgaset(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __maybe_unused char *param, bool isjson, __maybe_unused char group)
+{
+	char buf[TMPBUFSIZ];
+	int numpga = numpgas();
+
+	if (numpga == 0) {
+		message(io_data, MSG_PGANON, 0, NULL, isjson);
+		return;
+	}
+
+	if (param == NULL || *param == '\0') {
+		message(io_data, MSG_MISID, 0, NULL, isjson);
+		return;
+	}
+
+	char *opt = strchr(param, ',');
+	if (opt)
+		*(opt++) = '\0';
+	if (!opt || !*opt) {
+		message(io_data, MSG_MISPGAOPT, 0, NULL, isjson);
+		return;
+	}
+
+	int id = atoi(param);
+	if (id < 0 || id >= numpga) {
+		message(io_data, MSG_INVPGA, id, NULL, isjson);
+		return;
+	}
+
+	int dev = pgadevice(id);
+	if (dev < 0) { // Should never happen
+		message(io_data, MSG_INVPGA, id, NULL, isjson);
+		return;
+	}
+
+	struct cgpu_info *cgpu = devices[dev];
+	const struct device_api *api = cgpu->api;
+
+	char *set = strchr(opt, ',');
+	if (set)
+		*(set++) = '\0';
+
+	if (!api->set_device)
+		message(io_data, MSG_PGANOSET, id, NULL, isjson);
+	else {
+		char *ret = api->set_device(cgpu, opt, set, buf);
+		if (ret) {
+			if (strcasecmp(opt, "help") == 0)
+				message(io_data, MSG_PGAHELP, id, ret, isjson);
+			else
+				message(io_data, MSG_PGASETERR, id, ret, isjson);
+		} else
+			message(io_data, MSG_PGASETOK, id, NULL, isjson);
+	}
+}
+#endif
+
 static void checkcommand(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, char group);
 
 struct CMDS {
@@ -3031,6 +3104,9 @@ struct CMDS {
 	{ "coin",		minecoin,	false },
 	{ "debug",		debugstate,	true },
 	{ "setconfig",		setconfig,	true },
+#ifdef HAVE_AN_FPGA
+	{ "pgaset",		pgaset,		true },
+#endif
 	{ NULL,			NULL,		false }
 };
 

+ 1 - 0
miner.h

@@ -299,6 +299,7 @@ struct device_api {
 	struct api_data *(*get_api_stats)(struct cgpu_info *);
 	bool (*get_stats)(struct cgpu_info *);
 	bool (*identify_device)(struct cgpu_info *);  // e.g. to flash a led
+	char *(*set_device)(struct cgpu_info *, char *option, char *setting, char *replybuf);
 
 	// Thread-specific functions
 	bool (*thread_prepare)(struct thr_info *);