gc3355.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * Copyright 2014 Nate Woolls
  3. * Copyright 2013 Luke Dashjr
  4. * Copyright 2014 GridSeed Team
  5. * Copyright 2014 Dualminer Team
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 3 of the License, or (at your option)
  10. * any later version. See COPYING for more details.
  11. */
  12. #include "config.h"
  13. #include "gc3355.h"
  14. #include <stdint.h>
  15. #include <string.h>
  16. #include "miner.h"
  17. #include "driver-icarus.h"
  18. #include "logging.h"
  19. #include "lowl-vcom.h"
  20. #ifndef WIN32
  21. #include <sys/ioctl.h>
  22. #else
  23. #include <io.h>
  24. #endif
  25. // options configurable by the end-user
  26. int opt_sha2_units = -1;
  27. int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
  28. #define GC3355_CHIP_NAME "gc3355"
  29. // General GC3355 commands
  30. static
  31. const char *firmware_request_cmd[] =
  32. {
  33. "55AAC000909090900000000001000000", // get firmware version of GC3355
  34. NULL
  35. };
  36. // SHA-2 commands
  37. static
  38. const char *sha2_gating_cmd[] =
  39. {
  40. "55AAEF0200000000", // Chip 1 - power down SHA-2 (unless masked w/PLL)
  41. "55AAEF0300000000", // Chip 2
  42. "55AAEF0400000000", // Chip 3
  43. "55AAEF0500000000", // Chip 4
  44. "55AAEF0600000000", // Chip 5
  45. NULL
  46. };
  47. // maps the above SHA chip gating with SHA-2 units
  48. static
  49. const char *sha2_open_cmd[] =
  50. {
  51. "55AAEF0200000001",
  52. "55AAEF0200000003",
  53. "55AAEF0200000007",
  54. "55AAEF020000000F",
  55. "55AAEF020000001F",
  56. "55AAEF020000003F",
  57. "55AAEF020000007F",
  58. "55AAEF02000000FF",
  59. "55AAEF02000001FF",
  60. "55AAEF02000003FF",
  61. "55AAEF02000007FF",
  62. "55AAEF0200000FFF",
  63. "55AAEF0200001FFF",
  64. "55AAEF0200003FFF",
  65. "55AAEF0200007FFF",
  66. "55AAEF020000FFFF",
  67. "55AAEF020001FFFF",
  68. "55AAEF020003FFFF",
  69. "55AAEF020007FFFF",
  70. "55AAEF02000FFFFF",
  71. "55AAEF02001FFFFF",
  72. "55AAEF02003FFFFF",
  73. "55AAEF02007FFFFF",
  74. "55AAEF0200FFFFFF",
  75. "55AAEF0201FFFFFF",
  76. "55AAEF0203FFFFFF",
  77. "55AAEF0207FFFFFF",
  78. "55AAEF020FFFFFFF",
  79. "55AAEF021FFFFFFF",
  80. "55AAEF023FFFFFFF",
  81. "55AAEF027FFFFFFF",
  82. "55AAEF02FFFFFFFF",
  83. "55AAEF0300000001",
  84. "55AAEF0300000003",
  85. "55AAEF0300000007",
  86. "55AAEF030000000F",
  87. "55AAEF030000001F",
  88. "55AAEF030000003F",
  89. "55AAEF030000007F",
  90. "55AAEF03000000FF",
  91. "55AAEF03000001FF",
  92. "55AAEF03000003FF",
  93. "55AAEF03000007FF",
  94. "55AAEF0300000FFF",
  95. "55AAEF0300001FFF",
  96. "55AAEF0300003FFF",
  97. "55AAEF0300007FFF",
  98. "55AAEF030000FFFF",
  99. "55AAEF030001FFFF",
  100. "55AAEF030003FFFF",
  101. "55AAEF030007FFFF",
  102. "55AAEF03000FFFFF",
  103. "55AAEF03001FFFFF",
  104. "55AAEF03003FFFFF",
  105. "55AAEF03007FFFFF",
  106. "55AAEF0300FFFFFF",
  107. "55AAEF0301FFFFFF",
  108. "55AAEF0303FFFFFF",
  109. "55AAEF0307FFFFFF",
  110. "55AAEF030FFFFFFF",
  111. "55AAEF031FFFFFFF",
  112. "55AAEF033FFFFFFF",
  113. "55AAEF037FFFFFFF",
  114. "55AAEF03FFFFFFFF",
  115. "55AAEF0400000001",
  116. "55AAEF0400000003",
  117. "55AAEF0400000007",
  118. "55AAEF040000000F",
  119. "55AAEF040000001F",
  120. "55AAEF040000003F",
  121. "55AAEF040000007F",
  122. "55AAEF04000000FF",
  123. "55AAEF04000001FF",
  124. "55AAEF04000003FF",
  125. "55AAEF04000007FF",
  126. "55AAEF0400000FFF",
  127. "55AAEF0400001FFF",
  128. "55AAEF0400003FFF",
  129. "55AAEF0400007FFF",
  130. "55AAEF040000FFFF",
  131. "55AAEF040001FFFF",
  132. "55AAEF040003FFFF",
  133. "55AAEF040007FFFF",
  134. "55AAEF04000FFFFF",
  135. "55AAEF04001FFFFF",
  136. "55AAEF04003FFFFF",
  137. "55AAEF04007FFFFF",
  138. "55AAEF0400FFFFFF",
  139. "55AAEF0401FFFFFF",
  140. "55AAEF0403FFFFFF",
  141. "55AAEF0407FFFFFF",
  142. "55AAEF040FFFFFFF",
  143. "55AAEF041FFFFFFF",
  144. "55AAEF043FFFFFFF",
  145. "55AAEF047FFFFFFF",
  146. "55AAEF04FFFFFFFF",
  147. "55AAEF0500000001",
  148. "55AAEF0500000003",
  149. "55AAEF0500000007",
  150. "55AAEF050000000F",
  151. "55AAEF050000001F",
  152. "55AAEF050000003F",
  153. "55AAEF050000007F",
  154. "55AAEF05000000FF",
  155. "55AAEF05000001FF",
  156. "55AAEF05000003FF",
  157. "55AAEF05000007FF",
  158. "55AAEF0500000FFF",
  159. "55AAEF0500001FFF",
  160. "55AAEF0500003FFF",
  161. "55AAEF0500007FFF",
  162. "55AAEF050000FFFF",
  163. "55AAEF050001FFFF",
  164. "55AAEF050003FFFF",
  165. "55AAEF050007FFFF",
  166. "55AAEF05000FFFFF",
  167. "55AAEF05001FFFFF",
  168. "55AAEF05003FFFFF",
  169. "55AAEF05007FFFFF",
  170. "55AAEF0500FFFFFF",
  171. "55AAEF0501FFFFFF",
  172. "55AAEF0503FFFFFF",
  173. "55AAEF0507FFFFFF",
  174. "55AAEF050FFFFFFF",
  175. "55AAEF051FFFFFFF",
  176. "55AAEF053FFFFFFF",
  177. "55AAEF057FFFFFFF",
  178. "55AAEF05FFFFFFFF",
  179. "55AAEF0600000001",
  180. "55AAEF0600000003",
  181. "55AAEF0600000007",
  182. "55AAEF060000000F",
  183. "55AAEF060000001F",
  184. "55AAEF060000003F",
  185. "55AAEF060000007F",
  186. "55AAEF06000000FF",
  187. "55AAEF06000001FF",
  188. "55AAEF06000003FF",
  189. "55AAEF06000007FF",
  190. "55AAEF0600000FFF",
  191. "55AAEF0600001FFF",
  192. "55AAEF0600003FFF",
  193. "55AAEF0600007FFF",
  194. "55AAEF060000FFFF",
  195. "55AAEF060001FFFF",
  196. "55AAEF060003FFFF",
  197. "55AAEF060007FFFF",
  198. "55AAEF06000FFFFF",
  199. "55AAEF06001FFFFF",
  200. "55AAEF06003FFFFF",
  201. "55AAEF06007FFFFF",
  202. "55AAEF0600FFFFFF",
  203. "55AAEF0601FFFFFF",
  204. "55AAEF0603FFFFFF",
  205. "55AAEF0607FFFFFF",
  206. "55AAEF060FFFFFFF",
  207. "55AAEF061FFFFFFF",
  208. "55AAEF063FFFFFFF",
  209. "55AAEF067FFFFFFF",
  210. "55AAEF06FFFFFFFF",
  211. NULL
  212. };
  213. static
  214. const char *multichip_init_cmd[] =
  215. {
  216. "55AAC000C0C0C0C00500000001000000", // set number of sub-chips (05 in this case)
  217. "55AAEF020000000000000000000000000000000000000000", // power down all SHA-2 modules
  218. "55AAEF3020000000", // Enable SHA-2 OR NOT - NO SCRYPT ACCEPTS WITHOUT THIS???
  219. NULL
  220. };
  221. static
  222. const char *sha2_init_cmd[] =
  223. {
  224. "55AAEF3020000000", // Enable SHA-2
  225. "55AA1F2817000000", // Enable GCP
  226. NULL
  227. };
  228. // called when initializing GridSeed device
  229. // called while initializing DualMiner when mining in scrypt+sha (dual-mode)
  230. static
  231. const char *scrypt_init_cmd[] =
  232. {
  233. "55AA1F2814000000", // Enable Scrypt
  234. "55AA1F2817000000", // Enable GCP
  235. NULL
  236. };
  237. // called before job start by GridSeed when mining scrypt
  238. // called before job start by DualMiner when mining scrypt in scrypt+sha (dual-mode)
  239. static
  240. const char *scrypt_reset_cmd[] =
  241. {
  242. // faster, for start of each job:
  243. "55AA1F2816000000", // Reset Scrypt(?)
  244. "55AA1F2817000000", // Enable GCP(?)
  245. NULL
  246. };
  247. // called while initializing DualMiner when mining scrypt in scrypt-only (not dual-mode)
  248. static
  249. const char *scrypt_only_init_cmd[] =
  250. {
  251. "55AAEF0200000000",
  252. "55AAEF0300000000",
  253. "55AAEF0400000000",
  254. "55AAEF0500000000",
  255. "55AAEF0600000000",
  256. "55AAEF3040000000",
  257. "55AA1F2810000000",
  258. "55AA1F2813000000",
  259. NULL
  260. };
  261. // called before job start by DualMiner when mining scrypt in scrypt-only (not dual-mode)
  262. // called while initializing DualMiner when mining scrypt in scrypt-only (not dual-mode)
  263. static
  264. const char *scrypt_only_reset_cmd[] =
  265. {
  266. "55AA1F2810000000", // Close Scrypt(?)
  267. "55AA1F2813000000", // Open Scrypt(?)
  268. NULL
  269. };
  270. static
  271. const char *gcp_chip_reset_cmd[] =
  272. {
  273. "55AAC000808080800000000001000000", // GCP (GridChip) reset
  274. NULL
  275. };
  276. static
  277. const char *sha2_chip_reset_cmd[] =
  278. {
  279. "55AAC000E0E0E0E00000000001000000", // SHA2 reset
  280. NULL
  281. };
  282. void gc3355_reset_dtr(int fd)
  283. {
  284. // set data terminal ready (DTR) status
  285. set_serial_dtr(fd, BGV_HIGH);
  286. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  287. set_serial_dtr(fd, BGV_LOW);
  288. }
  289. static
  290. void gc3355_set_register(uint8_t * const buf, const uint8_t clusaddr, const uint8_t chipaddr, const uint8_t regaddr, const uint32_t val)
  291. {
  292. buf[0] = 0x55;
  293. buf[1] = 0xaa;
  294. buf[2] = (clusaddr << 4) | chipaddr;
  295. buf[3] = regaddr;
  296. buf[4] = (val >> 0) & 0xff;
  297. buf[5] = (val >> 8) & 0xff;
  298. buf[6] = (val >> 0x10) & 0xff;
  299. buf[7] = (val >> 0x18) & 0xff;
  300. }
  301. static
  302. void gc3355_config_cpm(uint8_t * const buf, const uint8_t chipaddr, const float mhz)
  303. {
  304. // See https://github.com/gridseed/gc3355-doc/blob/master/GC3355_Register_Spec.pdf
  305. const uint8_t pll_bypass = 1;
  306. const uint8_t pll_bandselect = 0;
  307. const uint8_t pll_outdiv = 0;
  308. uint8_t freq_div, freq_mult, last_freq_mult = 0; // mhz = (25 / freq_div * freq_mult)
  309. float actual_mhz, last_actual_mhz = -1;
  310. for (freq_div = 1; freq_div <= 32; ++freq_div)
  311. {
  312. freq_mult = mhz * freq_div / 25;
  313. if (freq_mult > 0x80)
  314. freq_mult = 0x80;
  315. actual_mhz = 25. / freq_div * freq_mult;
  316. if (last_actual_mhz > actual_mhz)
  317. {
  318. --freq_div;
  319. freq_mult = last_freq_mult;
  320. if (opt_debug)
  321. actual_mhz = 25. / freq_div * freq_mult;
  322. break;
  323. }
  324. if (actual_mhz > mhz - .5)
  325. break;
  326. last_actual_mhz = actual_mhz;
  327. last_freq_mult = freq_mult;
  328. }
  329. const uint8_t pll_F = freq_mult - 1;
  330. const uint8_t pll_R = freq_div - 1;
  331. const uint8_t core_clk_out1_diven = 0;
  332. const uint8_t core_clk_sel1 = 0;
  333. const uint8_t core_clk_sel0 = 0;
  334. const uint8_t pll_clk_gate = 0;
  335. const uint8_t pll_recfg = 1;
  336. const uint8_t cfg_cpm = 1;
  337. const uint32_t cfg = (pll_bypass << 31) | (pll_bandselect << 30) | (pll_outdiv << 28) | (pll_F << 21) | (pll_R << 16) | (core_clk_out1_diven << 6) | (core_clk_sel1 << 5) | (core_clk_sel0 << 4) | (pll_clk_gate << 3) | (pll_recfg << 2) | (cfg_cpm << 0);
  338. gc3355_set_register(buf, 0xe, chipaddr, 0, cfg);
  339. }
  340. // NOTE: MHz must match CPM config
  341. static
  342. void gc3355_config_sha256d(uint8_t * const buf, const uint8_t chipaddr, const float mhz, const uint32_t baud)
  343. {
  344. // See https://github.com/gridseed/gc3355-doc/blob/master/GC3355_Register_Spec.pdf
  345. const uint8_t force_start = 1;
  346. const uint8_t uart_enable = 1;
  347. const uint8_t uart_debug = 0;
  348. const uint8_t byte_order = 0;
  349. const uint16_t rpt_cycle = (mhz * 1000000 / baud);
  350. const uint32_t cfg = (force_start << 31) | (uart_enable << 30) | (uart_debug << 29) | (byte_order << 28) | rpt_cycle;
  351. gc3355_set_register(buf, 0, chipaddr, 0xff, cfg);
  352. }
  353. static
  354. void gc3355_log_protocol(int fd, const char *buf, size_t size, const char *prefix)
  355. {
  356. char hex[(size * 2) + 1];
  357. bin2hex(hex, buf, size);
  358. applog(LOG_DEBUG, "%s fd=%d: DEVPROTO: %s(%3lu) %s",
  359. GC3355_CHIP_NAME, fd, prefix, (unsigned long)size, hex);
  360. }
  361. int gc3355_read(int fd, char *buf, size_t size)
  362. {
  363. size_t read;
  364. int tries = 20;
  365. while (tries > 0)
  366. {
  367. read = serial_read(fd, buf, size);
  368. if (read > 0)
  369. break;
  370. tries--;
  371. }
  372. if (unlikely(tries == 0))
  373. return -1;
  374. if ((read > 0) && opt_dev_protocol)
  375. gc3355_log_protocol(fd, buf, read, "RECV");
  376. return read;
  377. }
  378. ssize_t gc3355_write(int fd, const void * const buf, const size_t size)
  379. {
  380. if (opt_dev_protocol)
  381. gc3355_log_protocol(fd, buf, size, "SEND");
  382. return write(fd, buf, size);
  383. }
  384. static
  385. void _gc3355_send_cmds_bin(int fd, const char *cmds[], bool is_bin, int size)
  386. {
  387. int i = 0;
  388. unsigned char ob_bin[512];
  389. for (i = 0; ; i++)
  390. {
  391. const char *cmd = cmds[i];
  392. if (cmd == NULL)
  393. break;
  394. if (is_bin)
  395. gc3355_write(fd, cmd, size);
  396. else
  397. {
  398. int bin_size = strlen(cmd) / 2;
  399. hex2bin(ob_bin, cmd, bin_size);
  400. gc3355_write(fd, ob_bin, bin_size);
  401. }
  402. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  403. }
  404. }
  405. #define gc3355_send_cmds_bin(fd, cmds, size) _gc3355_send_cmds_bin(fd, cmds, true, size)
  406. #define gc3355_send_cmds(fd, cmds) _gc3355_send_cmds_bin(fd, cmds, false, -1)
  407. void gc3355_scrypt_only_reset(int fd)
  408. {
  409. gc3355_send_cmds(fd, scrypt_only_reset_cmd);
  410. }
  411. void gc3355_set_pll_freq(int fd, int pll_freq)
  412. {
  413. const uint8_t chipaddr = 0xf;
  414. const uint32_t baud = 115200; // FIXME: Make this configurable
  415. uint8_t buf[8];
  416. gc3355_config_cpm(buf, chipaddr, pll_freq);
  417. gc3355_write(fd, buf, sizeof(buf));
  418. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  419. gc3355_config_sha256d(buf, chipaddr, pll_freq, baud);
  420. gc3355_write(fd, buf, sizeof(buf));
  421. }
  422. static
  423. void gc3355_open_sha2_units(int fd, int sha2_units)
  424. {
  425. int unit_count = 0;
  426. unsigned char ob_bin[8];
  427. int i;
  428. // should be 0 - 160
  429. unit_count = sha2_units < 0 ? 0 : sha2_units > 160 ? 160 : sha2_units;
  430. if (unit_count > 0)
  431. {
  432. for(i = 0; i <= unit_count; i++)
  433. {
  434. hex2bin(ob_bin, sha2_open_cmd[i], sizeof(ob_bin));
  435. gc3355_write(fd, ob_bin, 8);
  436. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  437. }
  438. }
  439. else if (unit_count == 0)
  440. gc3355_send_cmds(fd, sha2_gating_cmd);
  441. }
  442. void gc3355_scrypt_init(int fd)
  443. {
  444. gc3355_send_cmds(fd, scrypt_init_cmd);
  445. }
  446. static
  447. void gc3355_scrypt_only_init(int fd)
  448. {
  449. gc3355_send_cmds(fd, sha2_gating_cmd);
  450. gc3355_send_cmds(fd, scrypt_only_init_cmd);
  451. gc3355_scrypt_only_reset(fd);
  452. }
  453. void gc3355_sha2_init(int fd)
  454. {
  455. gc3355_send_cmds(fd, sha2_gating_cmd);
  456. gc3355_send_cmds(fd, sha2_init_cmd);
  457. }
  458. void gc3355_init_miner(int fd, int pll_freq)
  459. {
  460. gc3355_send_cmds(fd, gcp_chip_reset_cmd);
  461. // zzz
  462. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  463. // initialize units
  464. gc3355_send_cmds(fd, multichip_init_cmd);
  465. gc3355_scrypt_init(fd);
  466. //set freq
  467. gc3355_set_pll_freq(fd, pll_freq);
  468. }
  469. void gc3355_init_dualminer(int fd, int pll_freq, bool scrypt_only, bool detect_only)
  470. {
  471. gc3355_send_cmds(fd, gcp_chip_reset_cmd);
  472. // zzz
  473. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  474. gc3355_send_cmds(fd, sha2_chip_reset_cmd);
  475. // initialize units
  476. gc3355_reset_dtr(fd);
  477. if (opt_scrypt && scrypt_only)
  478. gc3355_scrypt_only_init(fd);
  479. else
  480. {
  481. gc3355_sha2_init(fd);
  482. gc3355_scrypt_init(fd);
  483. }
  484. //set freq
  485. gc3355_set_pll_freq(fd, pll_freq);
  486. // zzz
  487. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  488. if (!detect_only)
  489. {
  490. if (!opt_scrypt)
  491. // open sha2 units
  492. gc3355_open_sha2_units(fd, opt_sha2_units);
  493. // set request to send (RTS) status
  494. set_serial_rts(fd, BGV_HIGH);
  495. }
  496. }
  497. void gc3355_scrypt_reset(int fd)
  498. {
  499. gc3355_send_cmds(fd, scrypt_reset_cmd);
  500. }
  501. void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *work)
  502. {
  503. // command header
  504. cmd[0] = 0x55;
  505. cmd[1] = 0xaa;
  506. cmd[2] = 0x1f;
  507. cmd[3] = 0x00;
  508. // task data
  509. memcpy(cmd + 4, work->target, 32);
  510. memcpy(cmd + 36, work->midstate, 32);
  511. memcpy(cmd + 68, work->data, 80);
  512. // nonce_max
  513. cmd[148] = 0xff;
  514. cmd[149] = 0xff;
  515. cmd[150] = 0xff;
  516. cmd[151] = 0xff;
  517. // taskid
  518. int workid = work->id;
  519. memcpy(cmd + 152, &(workid), 4);
  520. }
  521. void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *work)
  522. {
  523. // command header
  524. cmd[0] = 0x55;
  525. cmd[1] = 0xaa;
  526. cmd[2] = 0x0f;
  527. cmd[3] = 0x00; // Scrypt header sig - used by DualMiner in Dual Mode
  528. uint8_t temp_bin[64];
  529. memset(temp_bin, 0, 64);
  530. memcpy(temp_bin, work->midstate, 32);
  531. memcpy(temp_bin + 52, work->data + 64, 12);
  532. memcpy(cmd + 8, work->midstate, 32);
  533. memcpy(cmd + 40, temp_bin + 52, 12);
  534. }
  535. int64_t gc3355_get_firmware_version(int fd)
  536. {
  537. gc3355_send_cmds(fd, firmware_request_cmd);
  538. char buf[GC3355_READ_SIZE];
  539. int read = gc3355_read(fd, buf, GC3355_READ_SIZE);
  540. if (read != GC3355_READ_SIZE)
  541. {
  542. applog(LOG_DEBUG, "%s: Failed reading work from %d", GC3355_CHIP_NAME, fd);
  543. return -1;
  544. }
  545. // firmware response begins with 55aac000 90909090
  546. if (memcmp(buf, "\x55\xaa\xc0\x00\x90\x90\x90\x90", GC3355_READ_SIZE - 4) != 0)
  547. {
  548. return -1;
  549. }
  550. uint32_t fw_version = be32toh(*(uint32_t *)(buf + 8));
  551. return fw_version;
  552. }