api.c new commands: pgaenable pgadisable
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
diff --git a/README b/README
index 7c411d9..0cb5720 100644
--- a/README
+++ b/README
@@ -749,8 +749,19 @@ The list of requests - a (*) means it requires privileged access - and replies a
to the API and success if you do have privilege
The command doesn't change anything in cgminer
-When you enable, disable or restart a GPU, you will also get Thread messages in
-the cgminer status window
+ pgaenable|N (*)
+ none There is no reply section just the STATUS section
+ stating the results of the enable request
+ You cannot enable a PGA if it's status is not WELL
+ This is only available if PGA mining is enabled
+
+ pgadisable|N (*)
+ none There is no reply section just the STATUS section
+ stating the results of the disable request
+ This is only available if PGA mining is enabled
+
+When you enable, disable or restart a GPU or PGA, you will also get Thread messages
+in the cgminer status window
When you switch to a different pool to the current one, you will get a
'Switching to URL' message in the cgminer status windows
diff --git a/api.c b/api.c
index 1879c38..953b193 100644
--- a/api.c
+++ b/api.c
@@ -329,6 +329,14 @@ static const char *JSON_PARAMETER = "parameter";
#define MSG_NUMPGA 59
#define MSG_NOTIFY 60
+#if defined(USE_BITFORCE) || defined(USE_ICARUS)
+#define MSG_PGALRENA 61
+#define MSG_PGALRDIS 62
+#define MSG_PGAENA 63
+#define MSG_PGADIS 64
+#define MSG_PGAUNW 65
+#endif
+
enum code_severity {
SEVERITY_ERR,
SEVERITY_WARN,
@@ -400,6 +408,11 @@ struct CODES {
{ SEVERITY_ERR, MSG_PGANON, PARAM_NONE, "No PGAs" },
{ SEVERITY_SUCC, MSG_PGADEV, PARAM_PGA, "PGA%d" },
{ SEVERITY_ERR, MSG_INVPGA, PARAM_PGAMAX, "Invalid PGA id %d - range is 0 - %d" },
+ { SEVERITY_INFO, MSG_PGALRENA,PARAM_PGA, "PGA %d already enabled" },
+ { SEVERITY_INFO, MSG_PGALRDIS,PARAM_PGA, "PGA %d already disabled" },
+ { SEVERITY_INFO, MSG_PGAENA, PARAM_PGA, "PGA %d sent enable message" },
+ { SEVERITY_INFO, MSG_PGADIS, PARAM_PGA, "PGA %d set disable flag" },
+ { SEVERITY_ERR, MSG_PGAUNW, PARAM_PGA, "PGA %d is not flagged WELL, cannot enable" },
#endif
#ifdef WANT_CPUMINE
{ SEVERITY_ERR, MSG_CPUNON, PARAM_NONE, "No CPUs" },
@@ -955,6 +968,99 @@ static void pgadev(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
if (isjson)
strcat(io_buffer, JSON_CLOSE);
}
+
+static void pgaenable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
+{
+ int numpga = numpgas();
+ struct thr_info *thr;
+ int pga;
+ int id;
+ int i;
+
+ if (numpga == 0) {
+ strcpy(io_buffer, message(MSG_PGANON, 0, NULL, isjson));
+ return;
+ }
+
+ if (param == NULL || *param == '\0') {
+ strcpy(io_buffer, message(MSG_MISID, 0, NULL, isjson));
+ return;
+ }
+
+ id = atoi(param);
+ if (id < 0 || id >= numpga) {
+ strcpy(io_buffer, message(MSG_INVPGA, id, NULL, isjson));
+ return;
+ }
+
+ int dev = pgadevice(id);
+ if (dev < 0) { // Should never happen
+ strcpy(io_buffer, message(MSG_INVPGA, id, NULL, isjson));
+ return;
+ }
+
+ struct cgpu_info *cgpu = devices[dev];
+
+ if (cgpu->deven != DEV_DISABLED) {
+ strcpy(io_buffer, message(MSG_PGALRENA, id, NULL, isjson));
+ return;
+ }
+
+ if (cgpu->status != LIFE_WELL) {
+ strcpy(io_buffer, message(MSG_PGAUNW, id, NULL, isjson));
+ return;
+ }
+
+ for (i = 0; i < mining_threads; i++) {
+ pga = thr_info[i].cgpu->device_id;
+ if (pga == dev) {
+ thr = &thr_info[i];
+ cgpu->deven = DEV_ENABLED;
+ tq_push(thr->q, &ping);
+ }
+ }
+
+ strcpy(io_buffer, message(MSG_PGAENA, id, NULL, isjson));
+}
+
+static void pgadisable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
+{
+ int numpga = numpgas();
+ int id;
+
+ if (numpga == 0) {
+ strcpy(io_buffer, message(MSG_PGANON, 0, NULL, isjson));
+ return;
+ }
+
+ if (param == NULL || *param == '\0') {
+ strcpy(io_buffer, message(MSG_MISID, 0, NULL, isjson));
+ return;
+ }
+
+ id = atoi(param);
+ if (id < 0 || id >= numpga) {
+ strcpy(io_buffer, message(MSG_INVPGA, id, NULL, isjson));
+ return;
+ }
+
+ int dev = pgadevice(id);
+ if (dev < 0) { // Should never happen
+ strcpy(io_buffer, message(MSG_INVPGA, id, NULL, isjson));
+ return;
+ }
+
+ struct cgpu_info *cgpu = devices[dev];
+
+ if (cgpu->deven == DEV_DISABLED) {
+ strcpy(io_buffer, message(MSG_PGALRDIS, id, NULL, isjson));
+ return;
+ }
+
+ cgpu->deven = DEV_DISABLED;
+
+ strcpy(io_buffer, message(MSG_PGADIS, id, NULL, isjson));
+}
#endif
#ifdef WANT_CPUMINE
@@ -1720,6 +1826,8 @@ struct CMDS {
{ "gpu", gpudev, false },
#if defined(USE_BITFORCE) || defined(USE_ICARUS)
{ "pga", pgadev, false },
+ { "pgaenable", pgaenable, true },
+ { "pgadisable", pgadisable, true },
#endif
#ifdef WANT_CPUMINE
{ "cpu", cpudev, false },