Merge branch 'master' into hashfast Conflicts: usbutils.c usbutils.h
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
diff --git a/driver-hashfast.c b/driver-hashfast.c
index bd6319a..49d4a98 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -101,6 +101,7 @@ struct hf_cmd {
enum usb_cmds usb_cmd;
};
+#define C_NULL C_MAX
static const struct hf_cmd hf_cmds[] = {
{OP_NULL, "OP_NULL", C_NULL},
{OP_ROOT, "OP_ROOT", C_NULL},
diff --git a/usbutils.c b/usbutils.c
index 534b903..867389a 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -542,83 +542,13 @@ static int next_stat = USB_NOSTAT;
#endif // DO_USB_STATS
-static const char **usb_commands;
-
-static const char *C_NULL_S = "Null";
-static const char *C_REJECTED_S = "RejectedNoDevice";
-static const char *C_PING_S = "Ping";
-static const char *C_CLEAR_S = "Clear";
-static const char *C_REQUESTVERSION_S = "RequestVersion";
-static const char *C_GETVERSION_S = "GetVersion";
-static const char *C_REQUESTFPGACOUNT_S = "RequestFPGACount";
-static const char *C_GETFPGACOUNT_S = "GetFPGACount";
-static const char *C_STARTPROGRAM_S = "StartProgram";
-static const char *C_STARTPROGRAMSTATUS_S = "StartProgramStatus";
-static const char *C_PROGRAM_S = "Program";
-static const char *C_PROGRAMSTATUS_S = "ProgramStatus";
-static const char *C_PROGRAMSTATUS2_S = "ProgramStatus2";
-static const char *C_FINALPROGRAMSTATUS_S = "FinalProgramStatus";
-static const char *C_SETCLOCK_S = "SetClock";
-static const char *C_REPLYSETCLOCK_S = "ReplySetClock";
-static const char *C_REQUESTUSERCODE_S = "RequestUserCode";
-static const char *C_GETUSERCODE_S = "GetUserCode";
-static const char *C_REQUESTTEMPERATURE_S = "RequestTemperature";
-static const char *C_GETTEMPERATURE_S = "GetTemperature";
-static const char *C_SENDWORK_S = "SendWork";
-static const char *C_SENDWORKSTATUS_S = "SendWorkStatus";
-static const char *C_REQUESTWORKSTATUS_S = "RequestWorkStatus";
-static const char *C_GETWORKSTATUS_S = "GetWorkStatus";
-static const char *C_REQUESTIDENTIFY_S = "RequestIdentify";
-static const char *C_GETIDENTIFY_S = "GetIdentify";
-static const char *C_REQUESTFLASH_S = "RequestFlash";
-static const char *C_REQUESTSENDWORK_S = "RequestSendWork";
-static const char *C_REQUESTSENDWORKSTATUS_S = "RequestSendWorkStatus";
-static const char *C_RESET_S = "Reset";
-static const char *C_SETBAUD_S = "SetBaud";
-static const char *C_SETDATA_S = "SetDataCtrl";
-static const char *C_SETFLOW_S = "SetFlowCtrl";
-static const char *C_SETMODEM_S = "SetModemCtrl";
-static const char *C_PURGERX_S = "PurgeRx";
-static const char *C_PURGETX_S = "PurgeTx";
-static const char *C_FLASHREPLY_S = "FlashReply";
-static const char *C_REQUESTDETAILS_S = "RequestDetails";
-static const char *C_GETDETAILS_S = "GetDetails";
-static const char *C_REQUESTRESULTS_S = "RequestResults";
-static const char *C_GETRESULTS_S = "GetResults";
-static const char *C_REQUESTQUEJOB_S = "RequestQueJob";
-static const char *C_REQUESTQUEJOBSTATUS_S = "RequestQueJobStatus";
-static const char *C_QUEJOB_S = "QueJob";
-static const char *C_QUEJOBSTATUS_S = "QueJobStatus";
-static const char *C_QUEFLUSH_S = "QueFlush";
-static const char *C_QUEFLUSHREPLY_S = "QueFlushReply";
-static const char *C_REQUESTVOLTS_S = "RequestVolts";
-static const char *C_GETVOLTS_S = "GetVolts";
-static const char *C_SENDTESTWORK_S = "SendTestWork";
-static const char *C_LATENCY_S = "SetLatency";
-static const char *C_SETLINE_S = "SetLine";
-static const char *C_VENDOR_S = "Vendor";
-static const char *C_SETFAN_S = "SetFan";
-static const char *C_FANREPLY_S = "GetFan";
-static const char *C_AVALON_TASK_S = "AvalonTask";
-static const char *C_AVALON_READ_S = "AvalonRead";
-static const char *C_GET_AVALON_READY_S = "AvalonReady";
-static const char *C_AVALON_RESET_S = "AvalonReset";
-static const char *C_GET_AVALON_RESET_S = "GetAvalonReset";
-static const char *C_FTDI_STATUS_S = "FTDIStatus";
-static const char *C_ENABLE_UART_S = "EnableUART";
-static const char *C_BB_SET_VOLTAGE_S = "SetCoreVoltage";
-static const char *C_BB_GET_VOLTAGE_S = "GetCoreVoltage";
-static const char *C_HF_RESET_S = "HFReset";
-static const char *C_HF_PLL_CONFIG_S = "HFPLLConfig";
-static const char *C_HF_ADDRESS_S = "HFAddress";
-static const char *C_HF_BAUD_S = "HFBaud";
-static const char *C_HF_HASH_S = "HFHash";
-static const char *C_HF_NONCE_S = "HFNonce";
-static const char *C_HF_ABORT_S = "HFAbort";
-static const char *C_HF_STATUS_S = "HFStatus";
-static const char *C_HF_CONFIG_S = "HFConfig";
-static const char *C_HF_STATISTICS_S = "HFStatistics";
-static const char *C_HF_CLOCKGATE_S = "HFClockGate";
+/* Create usb_commands array from USB_PARSE_COMMANDS macro in usbutils.h */
+#define USB_ADD_COMMAND(X, Y) Y,
+char *usb_commands[] = {
+ USB_PARSE_COMMANDS
+ "Null"
+};
+#undef USB_ADD_COMMAND
#ifdef EOL
#undef EOL
@@ -1038,90 +968,6 @@ static void cgusb_check_init()
libusb_set_debug(NULL, opt_usbdump);
usb_all(opt_usbdump);
}
-
- usb_commands = malloc(sizeof(*usb_commands) * C_MAX);
- if (unlikely(!usb_commands))
- quit(1, "USB failed to malloc usb_commands");
-
- // use constants so the stat generation is very quick
- // and the association between number and name can't
- // be missalined easily
- usb_commands[C_NULL] = C_NULL_S;
- usb_commands[C_REJECTED] = C_REJECTED_S;
- usb_commands[C_PING] = C_PING_S;
- usb_commands[C_CLEAR] = C_CLEAR_S;
- usb_commands[C_REQUESTVERSION] = C_REQUESTVERSION_S;
- usb_commands[C_GETVERSION] = C_GETVERSION_S;
- usb_commands[C_REQUESTFPGACOUNT] = C_REQUESTFPGACOUNT_S;
- usb_commands[C_GETFPGACOUNT] = C_GETFPGACOUNT_S;
- usb_commands[C_STARTPROGRAM] = C_STARTPROGRAM_S;
- usb_commands[C_STARTPROGRAMSTATUS] = C_STARTPROGRAMSTATUS_S;
- usb_commands[C_PROGRAM] = C_PROGRAM_S;
- usb_commands[C_PROGRAMSTATUS] = C_PROGRAMSTATUS_S;
- usb_commands[C_PROGRAMSTATUS2] = C_PROGRAMSTATUS2_S;
- usb_commands[C_FINALPROGRAMSTATUS] = C_FINALPROGRAMSTATUS_S;
- usb_commands[C_SETCLOCK] = C_SETCLOCK_S;
- usb_commands[C_REPLYSETCLOCK] = C_REPLYSETCLOCK_S;
- usb_commands[C_REQUESTUSERCODE] = C_REQUESTUSERCODE_S;
- usb_commands[C_GETUSERCODE] = C_GETUSERCODE_S;
- usb_commands[C_REQUESTTEMPERATURE] = C_REQUESTTEMPERATURE_S;
- usb_commands[C_GETTEMPERATURE] = C_GETTEMPERATURE_S;
- usb_commands[C_SENDWORK] = C_SENDWORK_S;
- usb_commands[C_SENDWORKSTATUS] = C_SENDWORKSTATUS_S;
- usb_commands[C_REQUESTWORKSTATUS] = C_REQUESTWORKSTATUS_S;
- usb_commands[C_GETWORKSTATUS] = C_GETWORKSTATUS_S;
- usb_commands[C_REQUESTIDENTIFY] = C_REQUESTIDENTIFY_S;
- usb_commands[C_GETIDENTIFY] = C_GETIDENTIFY_S;
- usb_commands[C_REQUESTFLASH] = C_REQUESTFLASH_S;
- usb_commands[C_REQUESTSENDWORK] = C_REQUESTSENDWORK_S;
- usb_commands[C_REQUESTSENDWORKSTATUS] = C_REQUESTSENDWORKSTATUS_S;
- usb_commands[C_RESET] = C_RESET_S;
- usb_commands[C_SETBAUD] = C_SETBAUD_S;
- usb_commands[C_SETDATA] = C_SETDATA_S;
- usb_commands[C_SETFLOW] = C_SETFLOW_S;
- usb_commands[C_SETMODEM] = C_SETMODEM_S;
- usb_commands[C_PURGERX] = C_PURGERX_S;
- usb_commands[C_PURGETX] = C_PURGETX_S;
- usb_commands[C_FLASHREPLY] = C_FLASHREPLY_S;
- usb_commands[C_REQUESTDETAILS] = C_REQUESTDETAILS_S;
- usb_commands[C_GETDETAILS] = C_GETDETAILS_S;
- usb_commands[C_REQUESTRESULTS] = C_REQUESTRESULTS_S;
- usb_commands[C_GETRESULTS] = C_GETRESULTS_S;
- usb_commands[C_REQUESTQUEJOB] = C_REQUESTQUEJOB_S;
- usb_commands[C_REQUESTQUEJOBSTATUS] = C_REQUESTQUEJOBSTATUS_S;
- usb_commands[C_QUEJOB] = C_QUEJOB_S;
- usb_commands[C_QUEJOBSTATUS] = C_QUEJOBSTATUS_S;
- usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S;
- usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S;
- usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S;
- usb_commands[C_GETVOLTS] = C_GETVOLTS_S;
- usb_commands[C_SENDTESTWORK] = C_SENDTESTWORK_S;
- usb_commands[C_LATENCY] = C_LATENCY_S;
- usb_commands[C_SETLINE] = C_SETLINE_S;
- usb_commands[C_VENDOR] = C_VENDOR_S;
- usb_commands[C_SETFAN] = C_SETFAN_S;
- usb_commands[C_FANREPLY] = C_FANREPLY_S;
- usb_commands[C_AVALON_TASK] = C_AVALON_TASK_S;
- usb_commands[C_AVALON_READ] = C_AVALON_READ_S;
- usb_commands[C_GET_AVALON_READY] = C_GET_AVALON_READY_S;
- usb_commands[C_AVALON_RESET] = C_AVALON_RESET_S;
- usb_commands[C_GET_AVALON_RESET] = C_GET_AVALON_RESET_S;
- usb_commands[C_FTDI_STATUS] = C_FTDI_STATUS_S;
- usb_commands[C_ENABLE_UART] = C_ENABLE_UART_S;
- usb_commands[C_BB_SET_VOLTAGE] = C_BB_SET_VOLTAGE_S;
- usb_commands[C_BB_GET_VOLTAGE] = C_BB_GET_VOLTAGE_S;
- usb_commands[C_HF_RESET] = C_HF_RESET_S;
- usb_commands[C_HF_PLL_CONFIG] = C_HF_PLL_CONFIG_S;
- usb_commands[C_HF_ADDRESS] = C_HF_ADDRESS_S;
- usb_commands[C_HF_BAUD] = C_HF_BAUD_S;
- usb_commands[C_HF_HASH] = C_HF_HASH_S;
- usb_commands[C_HF_NONCE] = C_HF_NONCE_S;
- usb_commands[C_HF_ABORT] = C_HF_ABORT_S;
- usb_commands[C_HF_STATUS] = C_HF_STATUS_S;
- usb_commands[C_HF_CONFIG] = C_HF_CONFIG_S;
- usb_commands[C_HF_STATISTICS] = C_HF_STATISTICS_S;
- usb_commands[C_HF_CLOCKGATE] = C_HF_CLOCKGATE_S;
-
stats_initialised = true;
}
diff --git a/usbutils.h b/usbutils.h
index 742930e..e0aea5a 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -258,84 +258,89 @@ struct cg_usb_info {
struct cg_usb_tmo usb_tmo[USB_TMOS];
};
+#define USB_PARSE_COMMANDS \
+ USB_ADD_COMMAND(C_REJECTED, "RejectedNoDevice") \
+ USB_ADD_COMMAND(C_PING, "Ping") \
+ USB_ADD_COMMAND(C_CLEAR, "Clear") \
+ USB_ADD_COMMAND(C_REQUESTVERSION, "RequestVersion") \
+ USB_ADD_COMMAND(C_GETVERSION, "GetVersion") \
+ USB_ADD_COMMAND(C_REQUESTFPGACOUNT, "RequestFPGACount") \
+ USB_ADD_COMMAND(C_GETFPGACOUNT, "GetFPGACount") \
+ USB_ADD_COMMAND(C_STARTPROGRAM, "StartProgram") \
+ USB_ADD_COMMAND(C_STARTPROGRAMSTATUS, "StartProgramStatus") \
+ USB_ADD_COMMAND(C_PROGRAM, "Program") \
+ USB_ADD_COMMAND(C_PROGRAMSTATUS, "ProgramStatus") \
+ USB_ADD_COMMAND(C_PROGRAMSTATUS2, "ProgramStatus2") \
+ USB_ADD_COMMAND(C_FINALPROGRAMSTATUS, "FinalProgramStatus") \
+ USB_ADD_COMMAND(C_SETCLOCK, "SetClock") \
+ USB_ADD_COMMAND(C_REPLYSETCLOCK, "ReplySetClock") \
+ USB_ADD_COMMAND(C_REQUESTUSERCODE, "RequestUserCode") \
+ USB_ADD_COMMAND(C_GETUSERCODE, "GetUserCode") \
+ USB_ADD_COMMAND(C_REQUESTTEMPERATURE, "RequestTemperature") \
+ USB_ADD_COMMAND(C_GETTEMPERATURE, "GetTemperature") \
+ USB_ADD_COMMAND(C_SENDWORK, "SendWork") \
+ USB_ADD_COMMAND(C_SENDWORKSTATUS, "SendWorkStatus") \
+ USB_ADD_COMMAND(C_REQUESTWORKSTATUS, "RequestWorkStatus") \
+ USB_ADD_COMMAND(C_GETWORKSTATUS, "GetWorkStatus") \
+ USB_ADD_COMMAND(C_REQUESTIDENTIFY, "RequestIdentify") \
+ USB_ADD_COMMAND(C_GETIDENTIFY, "GetIdentify") \
+ USB_ADD_COMMAND(C_REQUESTFLASH, "RequestFlash") \
+ USB_ADD_COMMAND(C_REQUESTSENDWORK, "RequestSendWork") \
+ USB_ADD_COMMAND(C_REQUESTSENDWORKSTATUS, "RequestSendWorkStatus") \
+ USB_ADD_COMMAND(C_RESET, "Reset") \
+ USB_ADD_COMMAND(C_SETBAUD, "SetBaud") \
+ USB_ADD_COMMAND(C_SETDATA, "SetDataCtrl") \
+ USB_ADD_COMMAND(C_SETFLOW, "SetFlowCtrl") \
+ USB_ADD_COMMAND(C_SETMODEM, "SetModemCtrl") \
+ USB_ADD_COMMAND(C_PURGERX, "PurgeRx") \
+ USB_ADD_COMMAND(C_PURGETX, "PurgeTx") \
+ USB_ADD_COMMAND(C_FLASHREPLY, "FlashReply") \
+ USB_ADD_COMMAND(C_REQUESTDETAILS, "RequestDetails") \
+ USB_ADD_COMMAND(C_GETDETAILS, "GetDetails") \
+ USB_ADD_COMMAND(C_REQUESTRESULTS, "RequestResults") \
+ USB_ADD_COMMAND(C_GETRESULTS, "GetResults") \
+ USB_ADD_COMMAND(C_REQUESTQUEJOB, "RequestQueJob") \
+ USB_ADD_COMMAND(C_REQUESTQUEJOBSTATUS, "RequestQueJobStatus") \
+ USB_ADD_COMMAND(C_QUEJOB, "QueJob") \
+ USB_ADD_COMMAND(C_QUEJOBSTATUS, "QueJobStatus") \
+ USB_ADD_COMMAND(C_QUEFLUSH, "QueFlush") \
+ USB_ADD_COMMAND(C_QUEFLUSHREPLY, "QueFlushReply") \
+ USB_ADD_COMMAND(C_REQUESTVOLTS, "RequestVolts") \
+ USB_ADD_COMMAND(C_GETVOLTS, "GetVolts") \
+ USB_ADD_COMMAND(C_SENDTESTWORK, "SendTestWork") \
+ USB_ADD_COMMAND(C_LATENCY, "SetLatency") \
+ USB_ADD_COMMAND(C_SETLINE, "SetLine") \
+ USB_ADD_COMMAND(C_VENDOR, "Vendor") \
+ USB_ADD_COMMAND(C_SETFAN, "SetFan") \
+ USB_ADD_COMMAND(C_FANREPLY, "GetFan") \
+ USB_ADD_COMMAND(C_AVALON_TASK, "AvalonTask") \
+ USB_ADD_COMMAND(C_AVALON_READ, "AvalonRead") \
+ USB_ADD_COMMAND(C_GET_AVALON_READY, "AvalonReady") \
+ USB_ADD_COMMAND(C_AVALON_RESET, "AvalonReset") \
+ USB_ADD_COMMAND(C_GET_AVALON_RESET, "GetAvalonReset") \
+ USB_ADD_COMMAND(C_FTDI_STATUS, "FTDIStatus") \
+ USB_ADD_COMMAND(C_ENABLE_UART, "EnableUART") \
+ USB_ADD_COMMAND(C_BB_SET_VOLTAGE, "SetCoreVoltage") \
+ USB_ADD_COMMAND(C_BB_GET_VOLTAGE, "GetCoreVoltage") \
+ USB_ADD_COMMAND(C_HF_RESET, "HFReset") \
+ USB_ADD_COMMAND(C_HF_PLL_CONFIG, "HFPLLConfig") \
+ USB_ADD_COMMAND(C_HF_ADDRESS, "HFAddress") \
+ USB_ADD_COMMAND(C_HF_BAUD, "HFBaud") \
+ USB_ADD_COMMAND(C_HF_HASH, "HFHash") \
+ USB_ADD_COMMAND(C_HF_NONCE, "HFNonce") \
+ USB_ADD_COMMAND(C_HF_ABORT, "HFAbort") \
+ USB_ADD_COMMAND(C_HF_STATUS, "HFStatus") \
+ USB_ADD_COMMAND(C_HF_CONFIG, "HFConfig") \
+ USB_ADD_COMMAND(C_HF_STATISTICS, "HFStatistics") \
+ USB_ADD_COMMAND(C_HF_CLOCKGATE, "HFClockGate")
+
+/* Create usb_cmds enum from USB_PARSE_COMMANDS macro */
+#define USB_ADD_COMMAND(X, Y) X,
enum usb_cmds {
- C_NULL = 0,
- C_REJECTED,
- C_PING,
- C_CLEAR,
- C_REQUESTVERSION,
- C_GETVERSION,
- C_REQUESTFPGACOUNT,
- C_GETFPGACOUNT,
- C_STARTPROGRAM,
- C_STARTPROGRAMSTATUS,
- C_PROGRAM,
- C_PROGRAMSTATUS,
- C_PROGRAMSTATUS2,
- C_FINALPROGRAMSTATUS,
- C_SETCLOCK,
- C_REPLYSETCLOCK,
- C_REQUESTUSERCODE,
- C_GETUSERCODE,
- C_REQUESTTEMPERATURE,
- C_GETTEMPERATURE,
- C_SENDWORK,
- C_SENDWORKSTATUS,
- C_REQUESTWORKSTATUS,
- C_GETWORKSTATUS,
- C_REQUESTIDENTIFY,
- C_GETIDENTIFY,
- C_REQUESTFLASH,
- C_REQUESTSENDWORK,
- C_REQUESTSENDWORKSTATUS,
- C_RESET,
- C_SETBAUD,
- C_SETDATA,
- C_SETFLOW,
- C_SETMODEM,
- C_PURGERX,
- C_PURGETX,
- C_FLASHREPLY,
- C_REQUESTDETAILS,
- C_GETDETAILS,
- C_REQUESTRESULTS,
- C_GETRESULTS,
- C_REQUESTQUEJOB,
- C_REQUESTQUEJOBSTATUS,
- C_QUEJOB,
- C_QUEJOBSTATUS,
- C_QUEFLUSH,
- C_QUEFLUSHREPLY,
- C_REQUESTVOLTS,
- C_GETVOLTS,
- C_SENDTESTWORK,
- C_LATENCY,
- C_SETLINE,
- C_VENDOR,
- C_SETFAN,
- C_FANREPLY,
- C_AVALON_TASK,
- C_AVALON_READ,
- C_GET_AVALON_READY,
- C_AVALON_RESET,
- C_GET_AVALON_RESET,
- C_FTDI_STATUS,
- C_ENABLE_UART,
- C_BB_SET_VOLTAGE,
- C_BB_GET_VOLTAGE,
- C_HF_RESET,
- C_HF_PLL_CONFIG,
- C_HF_ADDRESS,
- C_HF_BAUD,
- C_HF_HASH,
- C_HF_NONCE,
- C_HF_ABORT,
- C_HF_STATUS,
- C_HF_CONFIG,
- C_HF_STATISTICS,
- C_HF_CLOCKGATE,
+ USB_PARSE_COMMANDS
C_MAX
};
+#undef USB_ADD_COMMAND
struct device_drv;
struct cgpu_info;