API V1.23 - new pgaset command, to be used soon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
diff --git a/API-README b/API-README
index 1a686f5..1bd5fc6 100644
--- a/API-README
+++ b/API-README
@@ -330,9 +330,20 @@ The list of requests - a (*) means it requires privileged access - and replies a
queue, scantime, expiry
N is an integer in the range 0 to 9999
- substats USBSTATS Stats of all LIBUSB mining devices except ztex
+ usbstats USBSTATS Stats of all LIBUSB mining devices except ztex
e.g. Name=MMQ,ID=0,Stat=SendWork,Count=99,...|
+ 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 cgminer status window
@@ -386,7 +397,14 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
-API V1.22
+API V1.23
+
+Added API commands:
+ 'pgaset'
+
+----------
+
+API V1.22 (cgminer v2.10.1)
Enforced output limitation:
all extra records beyond the output limit of the API (~64k) are ignored
diff --git a/api.c b/api.c
index 4cec476..659d934 100644
--- a/api.c
+++ b/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";
#if defined(HAVE_OPENCL) || defined(HAVE_AN_FPGA)
static const char *SICK = "Sick";
@@ -379,6 +379,14 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_USBSTA 87
#define MSG_NOUSTA 88
+#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,
@@ -544,6 +552,13 @@ struct CODES {
{ SEVERITY_ERR, MSG_CONVAL, PARAM_STR, "Missing config value N for '%s,N'" },
{ SEVERITY_SUCC, MSG_USBSTA, PARAM_NONE, "USB Statistics" },
{ SEVERITY_INFO, MSG_NOUSTA, PARAM_NONE, "No USB Statistics" },
+#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 }
};
@@ -3142,6 +3157,64 @@ static void usbstats(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
#endif
}
+#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];
+ 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 {
@@ -3198,6 +3271,9 @@ struct CMDS {
{ "debug", debugstate, true },
{ "setconfig", setconfig, true },
{ "usbstats", usbstats, false },
+#ifdef HAVE_AN_FPGA
+ { "pgaset", pgaset, true },
+#endif
{ NULL, NULL, false }
};
diff --git a/miner.h b/miner.h
index b0659d9..2b5897a 100644
--- a/miner.h
+++ b/miner.h
@@ -277,6 +277,7 @@ struct device_api {
struct api_data *(*get_api_stats)(struct cgpu_info *);
bool (*get_stats)(struct cgpu_info *);
void (*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 *);