driver-bflsc.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  1. /*
  2. * Copyright 2013 Andrew Smith
  3. * Copyright 2013 Con Kolivas
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #include <float.h>
  11. #include <limits.h>
  12. #include <pthread.h>
  13. #include <stdint.h>
  14. #include <stdio.h>
  15. #include <strings.h>
  16. #include <sys/time.h>
  17. #include <unistd.h>
  18. #include "config.h"
  19. #ifdef WIN32
  20. #include <windows.h>
  21. #endif
  22. #include "compat.h"
  23. #include "miner.h"
  24. #include "usbutils.h"
  25. #define BLANK ""
  26. #define LFSTR "<LF>"
  27. #define BFLSC_DI_FIRMWARE "FIRMWARE"
  28. #define BFLSC_DI_ENGINES "ENGINES"
  29. #define BFLSC_DI_JOBSINQUE "JOBS IN QUEUE"
  30. #define BFLSC_DI_XLINKMODE "XLINK MODE"
  31. #define BFLSC_DI_XLINKPRESENT "XLINK PRESENT"
  32. #define BFLSC_DI_DEVICESINCHAIN "DEVICES IN CHAIN"
  33. #define BFLSC_DI_CHAINPRESENCE "CHAIN PRESENCE MASK"
  34. #define FULLNONCE 0x100000000
  35. struct bflsc_dev {
  36. // Work
  37. unsigned int ms_work;
  38. int work_queued;
  39. int work_complete;
  40. int nonces_hw; // TODO: this - need to add a paramter to submit_nonce()
  41. // so can pass 'dev' to hw_error
  42. uint64_t hashes_unsent;
  43. uint64_t hashes_sent;
  44. uint64_t nonces_found;
  45. struct timeval last_check_result;
  46. struct timeval last_dev_result; // array > 0
  47. struct timeval last_nonce_result; // > 0 nonce
  48. // Info
  49. char *firmware;
  50. int engines; // does a faulty engine only hash 'x/16 * FULLNONCE' ?
  51. char *xlink_mode;
  52. char *xlink_present;
  53. // Status
  54. bool dead; // TODO: handle seperate x-link devices failing?
  55. bool overheat;
  56. // Stats
  57. float temp1;
  58. float temp2;
  59. float vcc1; // TODO? get V also
  60. float vcc2;
  61. float vmain;
  62. float temp1_max;
  63. float temp2_max;
  64. time_t temp1_max_time;
  65. time_t temp2_max_time;
  66. float temp1_sum;
  67. float temp2_sum;
  68. uint64_t temp_count;
  69. time_t temp_time;
  70. float temp1_5min_av; // TODO:
  71. float temp2_5min_av; // TODO:
  72. // To handle the fact that flushing the queue may not remove all work
  73. // (normally one item is still being processed)
  74. // and also that once the queue is flushed, results may still be in
  75. // the output queue - but we don't want to process them at the time of doing an LP
  76. // when result_id > flush_id+1, flushed work can be discarded since it
  77. // is no longer in the device
  78. uint64_t flush_id; // counter when results were last flushed
  79. uint64_t result_id; // counter when results were last checked
  80. bool flushed; // are any flushed?
  81. };
  82. // TODO: I stole cgpu_info.device_file
  83. // ... need to update miner.h to instead have a generic void *device_info = NULL;
  84. // ... and these structure definitions need to be in miner.h if API needs to see them
  85. // ... but then again maybe not - maybe another devinfo that the driver provides
  86. // However, clean up all that for all devices in miner.h ... miner.h is a mess at the moment
  87. struct bflsc_info {
  88. pthread_rwlock_t stat_lock;
  89. struct thr_info results_thr;
  90. uint64_t hashes_sent;
  91. uint32_t update_count;
  92. struct timeval last_update;
  93. int sc_count;
  94. struct bflsc_dev *sc_devs;
  95. unsigned int scan_sleep_time;
  96. unsigned int results_sleep_time;
  97. unsigned int default_ms_work;
  98. bool shutdown;
  99. bool flash_led;
  100. };
  101. #define BFLSC_XLINKHDR '@'
  102. #define BFLSC_MAXPAYLOAD 255
  103. struct DataForwardToChain {
  104. uint8_t header;
  105. uint8_t deviceAddress;
  106. uint8_t payloadSize;
  107. uint8_t payloadData[BFLSC_MAXPAYLOAD];
  108. };
  109. #define DATAFORWARDSIZE(data) (1 + 1 + 1 + data.payloadSize)
  110. #define MIDSTATE_BYTES 32
  111. #define MERKLE_OFFSET 64
  112. #define MERKLE_BYTES 12
  113. #define BFLSC_QJOBSIZ (MIDSTATE_BYTES+MERKLE_BYTES+1)
  114. #define BFLSC_EOB 0xaa
  115. struct QueueJobStructure {
  116. uint8_t payloadSize;
  117. uint8_t midState[MIDSTATE_BYTES];
  118. uint8_t blockData[MERKLE_BYTES];
  119. uint8_t endOfBlock;
  120. };
  121. #define QUE_RES_LINES_MIN 3
  122. #define QUE_MIDSTATE 0
  123. #define QUE_BLOCKDATA 1
  124. #define QUE_NONCECOUNT 2
  125. #define QUE_FLD_MIN 3
  126. #define QUE_FLD_MAX 11
  127. #define BFLSC_SIGNATURE 0xc1
  128. #define BFLSC_EOW 0xfe
  129. // N.B. this will only work with 5 jobs
  130. // requires a different jobs[N] for each job count
  131. // but really only need to handle 5 anyway
  132. struct QueueJobPackStructure {
  133. uint8_t payloadSize;
  134. uint8_t signature;
  135. uint8_t jobsInArray;
  136. struct QueueJobStructure jobs[5];
  137. uint8_t endOfWrapper;
  138. };
  139. // TODO: Implement in API and also in usb device selection
  140. struct SaveString {
  141. uint8_t payloadSize;
  142. uint8_t payloadData[BFLSC_MAXPAYLOAD];
  143. };
  144. // Commands
  145. #define BFLSC_IDENTIFY "ZGX"
  146. #define BFLSC_IDENTIFY_LEN (sizeof(BFLSC_IDENTIFY)-1)
  147. #define BFLSC_DETAILS "ZCX"
  148. #define BFLSC_DETAILS_LEN (sizeof(BFLSC_DETAILS)-1)
  149. #define BFLSC_FIRMWARE "ZJX"
  150. #define BFLSC_FIRMWARE_LEN (sizeof(BFLSC_FIRMWARE)-1)
  151. #define BFLSC_FLASH "ZMX"
  152. #define BFLSC_FLASH_LEN (sizeof(BFLSC_FLASH)-1)
  153. #define BFLSC_VOLTAGE "ZTX"
  154. #define BFLSC_VOLTAGE_LEN (sizeof(BFLSC_VOLTAGE)-1)
  155. #define BFLSC_TEMPERATURE "ZLX"
  156. #define BFLSC_TEMPERATURE_LEN (sizeof(BFLSC_TEMPERATURE)-1)
  157. #define BFLSC_QJOB "ZNX"
  158. #define BFLSC_QJOB_LEN (sizeof(BFLSC_QJOB)-1)
  159. #define BFLSC_QJOBS "ZWX"
  160. #define BFLSC_QJOBS_LEN (sizeof(BFLSC_QJOBS)-1)
  161. #define BFLSC_QRES "ZOX"
  162. #define BFLSC_QRES_LEN (sizeof(BFLSC_QRES)-1)
  163. #define BFLSC_QFLUSH "ZQX"
  164. #define BFLSC_QFLUSH_LEN (sizeof(BFLSC_QFLUSH)-1)
  165. #define BFLSC_FANAUTO "Z5X"
  166. #define BFLSC_FANOUT_LEN (sizeof(BFLSC_FANAUTO)-1)
  167. #define BFLSC_FAN0 "Z0X"
  168. #define BFLSC_FAN0_LEN (sizeof(BFLSC_FAN0)-1)
  169. #define BFLSC_FAN1 "Z1X"
  170. #define BFLSC_FAN1_LEN (sizeof(BFLSC_FAN1)-1)
  171. #define BFLSC_FAN2 "Z2X"
  172. #define BFLSC_FAN2_LEN (sizeof(BFLSC_FAN2)-1)
  173. #define BFLSC_FAN3 "Z3X"
  174. #define BFLSC_FAN3_LEN (sizeof(BFLSC_FAN3)-1)
  175. #define BFLSC_FAN4 "Z4X"
  176. #define BFLSC_FAN4_LEN (sizeof(BFLSC_FAN4)-1)
  177. #define BFLSC_SAVESTR "ZSX"
  178. #define BFLSC_SAVESTR_LEN (sizeof(BFLSC_SAVESTR)-1)
  179. #define BFLSC_LOADSTR "ZUX"
  180. #define BFLSC_LOADSTR_LEN (sizeof(BFLSC_LOADSTR)-1)
  181. // Replies
  182. #define BFLSC_IDENTITY "BitFORCE SC"
  183. #define BFLSC_BFLSC "SHA256 SC"
  184. #define BFLSC_OK "OK\n"
  185. #define BFLSC_OK_LEN (sizeof(BFLSC_OK)-1)
  186. #define BFLSC_SUCCESS "SUCCESS\n"
  187. #define BFLSC_SUCCESS_LEN (sizeof(BFLSC_SUCCESS)-1)
  188. #define BFLSC_RESULT "COUNT:"
  189. #define BFLSC_RESULT_LEN (sizeof(BFLSC_RESULT)-1)
  190. #define BFLSC_ANERR "ERR:"
  191. #define BFLSC_ANERR_LEN (sizeof(BFLSC_ANERR)-1)
  192. #define BFLSC_TIMEOUT BFLSC_ANERR "TIMEOUT"
  193. #define BFLSC_TIMEOUT_LEN (sizeof(BFLSC_TIMEOUT)-1)
  194. #define BFLSC_INVALID BFLSC_ANERR "INVALID DATA"
  195. #define BFLSC_INVALID_LEN (sizeof(BFLSC_INVALID)-1)
  196. #define BFLSC_ERRSIG BFLSC_ANERR "SIGNATURE"
  197. #define BFLSC_ERRSIG_LEN (sizeof(BFLSC_ERRSIG)-1)
  198. #define BFLSC_OKQ "OK:QUEUED"
  199. #define BFLSC_OKQ_LEN (sizeof(BFLSC_OKQ)-1)
  200. // Followed by N=1..5
  201. #define BFLSC_OKQN "OK:QUEUED "
  202. #define BFLSC_OKQN_LEN (sizeof(BFLSC_OKQN)-1)
  203. #define BFLSC_QFULL "QUEUE FULL"
  204. #define BFLSC_QFULL_LEN (sizeof(BFLSC_QFULL)-1)
  205. #define BFLSC_HITEMP "HIGH TEMPERATURE RECOVERY"
  206. #define BFLSC_HITEMP_LEN (sizeof(BFLSC_HITEMP)-1)
  207. #define BFLSC_EMPTYSTR "MEMORY EMPTY"
  208. #define BFLSC_EMPTYSTR_LEN (sizeof(BFLSC_EMPTYSTR)-1)
  209. // Queued and non-queued are the same
  210. #define FullNonceRangeJob QueueJobStructure
  211. #define BFLSC_JOBSIZ BFLSC_QJOBSIZ
  212. // Non queued commands
  213. #define BFLSC_SENDWORK "ZDX"
  214. #define BFLSC_SENDWORK_LEN (sizeof(BFLSC_SENDWORK)-1)
  215. // Non queued commands (not used)
  216. #define BFLSC_WORKSTATUS "ZFX"
  217. #define BFLSC_WORKSTATUS_LEN (sizeof(BFLSC_WORKSTATUS)-1)
  218. #define BFLSC_SENDRANGE "ZPX"
  219. #define BFLSC_SENDRANGE_LEN (sizeof(BFLSC_SENDRANGE)-1)
  220. // Non queued work replies (not used)
  221. #define BFLSC_NONCE "NONCE-FOUND:"
  222. #define BFLSC_NONCE_LEN (sizeof(BFLSC_NONCE)-1)
  223. #define BFLSC_NO_NONCE "NO-NONCE"
  224. #define BFLSC_NO_NONCE_LEN (sizeof(BFLSC_NO_NONCE)-1)
  225. #define BFLSC_IDLE "IDLE"
  226. #define BFLSC_IDLE_LEN (sizeof(BFLSC_IDLE)-1)
  227. #define BFLSC_BUSY "BUSY"
  228. #define BFLSC_BUSY_LEN (sizeof(BFLSC_BUSY)-1)
  229. #define BFLSC_MINIRIG "BAM"
  230. #define BFLSC_SINGLE "BAS"
  231. #define BFLSC_LITTLESINGLE "BAL"
  232. #define BFLSC_JALAPENO "BAJ"
  233. // Default expected time for a nonce range
  234. // - thus no need to check until this + last time work was found
  235. // 60GH/s MiniRig (1 board) or Single
  236. #define BAM_WORK_TIME 71.58
  237. #define BAS_WORK_TIME 71.58
  238. // 30GH/s Little Single
  239. #define BAL_WORK_TIME 143.17
  240. // 4.5GH/s Jalapeno
  241. #define BAJ_WORK_TIME 954.44
  242. // Defaults (slightly over half the work time) but ensure none are above 100
  243. // SCAN_TIME - delay after sending work
  244. // RES_TIME - delay between checking for results
  245. // TODO: make dynamic? (for all but MiniRig)
  246. #define BAM_SCAN_TIME 2
  247. #define BAM_RES_TIME 2
  248. #define BAS_SCAN_TIME 36
  249. #define BAS_RES_TIME 36
  250. #define BAL_SCAN_TIME 72
  251. #define BAL_RES_TIME 72
  252. #define BAJ_SCAN_TIME 100
  253. #define BAJ_RES_TIME 100
  254. #define BFLSC_TEMP_SLEEPMS 5
  255. #define BFLSC_QUE_SIZE 20
  256. #define BFLSC_QUE_FULL_ENOUGH 13
  257. #define BFLSC_BUFSIZ (0x200)
  258. // Must drop this far below cutoff before resuming work
  259. #define BFLSC_TEMP_RECOVER 5
  260. // If initialisation fails the first time,
  261. // sleep this amount (ms) and try again
  262. #define REINIT_TIME_FIRST_MS 100
  263. // Max ms per sleep
  264. #define REINIT_TIME_MAX_MS 800
  265. // Keep trying up to this many us
  266. #define REINIT_TIME_MAX 3000000
  267. static const char *blank = "";
  268. struct device_drv bflsc_drv;
  269. static void bflsc_applog(struct cgpu_info *bflsc, int dev, enum usb_cmds cmd, int amount, int err)
  270. {
  271. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  272. char xlink[17];
  273. if (dev > 0)
  274. sprintf(xlink, "x-%d", dev);
  275. else {
  276. if (sc_info->sc_count > 0)
  277. strcpy(xlink, " master");
  278. else
  279. xlink[0] = '\0';
  280. }
  281. usb_applog(bflsc, cmd, xlink, amount, err);
  282. }
  283. // Break an input up into lines with LFs removed
  284. // false means an error, but if *lines > 0 then data was also found
  285. // error would be no data or missing LF at the end
  286. static bool tolines(struct cgpu_info *bflsc, int dev, char *buf, int *lines, char ***items, enum usb_cmds cmd)
  287. {
  288. bool ok = true;
  289. char *ptr;
  290. #define p_lines (*lines)
  291. #define p_items (*items)
  292. p_lines = 0;
  293. p_items = NULL;
  294. if (!buf || !(*buf)) {
  295. applog(LOG_DEBUG, "USB: %s%i: (%d) empty %s",
  296. bflsc->drv->name, bflsc->device_id, dev, usb_cmdname(cmd));
  297. return false;
  298. }
  299. ptr = strdup(buf);
  300. while (ptr && *ptr) {
  301. p_items = realloc(p_items, ++p_lines * sizeof(*p_items));
  302. if (unlikely(!p_items))
  303. quit(1, "Failed to realloc p_items in tolines");
  304. p_items[p_lines-1] = ptr;
  305. ptr = strchr(ptr, '\n');
  306. if (ptr)
  307. *(ptr++) = '\0';
  308. else {
  309. if (ok) {
  310. applog(LOG_DEBUG, "USB: %s%i: (%d) missing lf(s) in %s",
  311. bflsc->drv->name, bflsc->device_id, dev, usb_cmdname(cmd));
  312. }
  313. ok = false;
  314. }
  315. }
  316. return ok;
  317. }
  318. static void freetolines(int *lines, char ***items)
  319. {
  320. if (*lines > 0) {
  321. free(**items);
  322. free(*items);
  323. }
  324. *lines = 0;
  325. *items = NULL;
  326. }
  327. enum breakmode {
  328. NOCOLON,
  329. ONECOLON,
  330. ALLCOLON // Temperature uses this
  331. };
  332. // Break down a single line into 'fields'
  333. // 'lf' will be a pointer to the final LF if it is there (or NULL)
  334. // firstname will be the allocated buf copy pointer which is also
  335. // the string before ':' for ONECOLON and ALLCOLON
  336. // If any string is missing the ':' when it was expected, false is returned
  337. static bool breakdown(enum breakmode mode, char *buf, int *count, char **firstname, char ***fields, char **lf)
  338. {
  339. char *ptr, *colon, *comma;
  340. bool ok;
  341. #define p_count (*count)
  342. #define p_firstname (*firstname)
  343. #define p_fields (*fields)
  344. #define p_lf (*lf)
  345. p_count = 0;
  346. p_firstname = NULL;
  347. p_fields = NULL;
  348. p_lf = NULL;
  349. if (!buf || !(*buf))
  350. return false;
  351. ptr = p_firstname = strdup(buf);
  352. p_lf = strchr(p_firstname, '\n');
  353. if (mode == ONECOLON) {
  354. colon = strchr(ptr, ':');
  355. if (colon) {
  356. ptr = colon;
  357. *(ptr++) = '\0';
  358. } else
  359. ok = false;
  360. }
  361. while (*ptr == ' ')
  362. ptr++;
  363. ok = true;
  364. while (ptr && *ptr) {
  365. if (mode == ALLCOLON) {
  366. colon = strchr(ptr, ':');
  367. if (colon)
  368. ptr = colon + 1;
  369. else
  370. ok = false;
  371. }
  372. while (*ptr == ' ')
  373. ptr++;
  374. comma = strchr(ptr, ',');
  375. if (comma)
  376. *(comma++) = '\0';
  377. p_fields = realloc(p_fields, ++p_count * sizeof(*p_fields));
  378. if (unlikely(!p_fields))
  379. quit(1, "Failed to realloc p_fields in breakdown");
  380. p_fields[p_count-1] = ptr;
  381. ptr = comma;
  382. }
  383. return ok;
  384. }
  385. static void freebreakdown(int *count, char **firstname, char ***fields)
  386. {
  387. if (*firstname)
  388. free(*firstname);
  389. if (*count > 0)
  390. free(*fields);
  391. *count = 0;
  392. *firstname = NULL;
  393. *fields = NULL;
  394. }
  395. static void xlinkstr(char *xlink, int dev, struct bflsc_info *sc_info)
  396. {
  397. if (dev > 0)
  398. sprintf(xlink, " x-%d", dev);
  399. else {
  400. if (sc_info->sc_count > 0)
  401. strcpy(xlink, " mast");
  402. else
  403. *xlink = '\0';
  404. }
  405. }
  406. static void __bflsc_initialise(struct cgpu_info *bflsc)
  407. {
  408. int err;
  409. // TODO: this is a standard BFL FPGA Initialisation
  410. // it probably will need changing ...
  411. // TODO: does x-link bypass the other device FTDI? (I think it does)
  412. // So no initialisation required except for the master device?
  413. if (bflsc->usbinfo.nodev)
  414. return;
  415. // Reset
  416. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  417. FTDI_VALUE_RESET, bflsc->usbdev->found->interface, C_RESET);
  418. applog(LOG_DEBUG, "%s%i: reset got err %d",
  419. bflsc->drv->name, bflsc->device_id, err);
  420. if (bflsc->usbinfo.nodev)
  421. return;
  422. // Set data control
  423. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
  424. FTDI_VALUE_DATA, bflsc->usbdev->found->interface, C_SETDATA);
  425. applog(LOG_DEBUG, "%s%i: setdata got err %d",
  426. bflsc->drv->name, bflsc->device_id, err);
  427. if (bflsc->usbinfo.nodev)
  428. return;
  429. // Set the baud
  430. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD,
  431. (FTDI_INDEX_BAUD & 0xff00) | bflsc->usbdev->found->interface,
  432. C_SETBAUD);
  433. applog(LOG_DEBUG, "%s%i: setbaud got err %d",
  434. bflsc->drv->name, bflsc->device_id, err);
  435. if (bflsc->usbinfo.nodev)
  436. return;
  437. // Set Flow Control
  438. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
  439. FTDI_VALUE_FLOW, bflsc->usbdev->found->interface, C_SETFLOW);
  440. applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
  441. bflsc->drv->name, bflsc->device_id, err);
  442. if (bflsc->usbinfo.nodev)
  443. return;
  444. // Set Modem Control
  445. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
  446. FTDI_VALUE_MODEM, bflsc->usbdev->found->interface, C_SETMODEM);
  447. applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
  448. bflsc->drv->name, bflsc->device_id, err);
  449. if (bflsc->usbinfo.nodev)
  450. return;
  451. // Clear any sent data
  452. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  453. FTDI_VALUE_PURGE_TX, bflsc->usbdev->found->interface, C_PURGETX);
  454. applog(LOG_DEBUG, "%s%i: purgetx got err %d",
  455. bflsc->drv->name, bflsc->device_id, err);
  456. if (bflsc->usbinfo.nodev)
  457. return;
  458. // Clear any received data
  459. err = usb_transfer(bflsc, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
  460. FTDI_VALUE_PURGE_RX, bflsc->usbdev->found->interface, C_PURGERX);
  461. applog(LOG_DEBUG, "%s%i: purgerx got err %d",
  462. bflsc->drv->name, bflsc->device_id, err);
  463. }
  464. static void bflsc_initialise(struct cgpu_info *bflsc)
  465. {
  466. mutex_lock(&(bflsc->device_mutex));
  467. __bflsc_initialise(bflsc);
  468. mutex_unlock(&(bflsc->device_mutex));
  469. }
  470. static int write_to_dev(struct cgpu_info *bflsc, int dev, char *buf, int buflen, int *amount, enum usb_cmds cmd)
  471. {
  472. struct DataForwardToChain data;
  473. int len;
  474. if (dev == 0)
  475. return usb_write(bflsc, buf, buflen, amount, cmd);
  476. data.header = BFLSC_XLINKHDR;
  477. data.deviceAddress = (uint8_t)dev;
  478. data.payloadSize = buflen;
  479. memcpy(data.payloadData, buf, buflen);
  480. len = DATAFORWARDSIZE(data);
  481. // TODO: handle xlink timeout message - here or at call?
  482. return usb_write(bflsc, (char *)&data, len, amount, cmd);
  483. }
  484. static bool getinfo(struct cgpu_info *bflsc, int dev)
  485. {
  486. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  487. struct bflsc_dev sc_dev;
  488. char buf[BFLSC_BUFSIZ+1];
  489. int err, amount;
  490. char **items, *firstname, **fields, *lf;
  491. int i, lines, count;
  492. bool res, ok;
  493. // TODO: if dev is ever > 0 must handle xlink timeout message
  494. err = write_to_dev(bflsc, dev, BFLSC_DETAILS, BFLSC_DETAILS_LEN, &amount, C_REQUESTDETAILS);
  495. if (err < 0 || amount != BFLSC_DETAILS_LEN) {
  496. applog(LOG_ERR, "%s detect (%s) send details request failed (%d:%d)",
  497. bflsc->drv->dname, bflsc->device_path, amount, err);
  498. return false;
  499. }
  500. err = usb_ftdi_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS);
  501. if (err < 0 || amount < 1) {
  502. if (err < 0) {
  503. applog(LOG_ERR, "%s detect (%s) get details return invalid/timed out (%d:%d)",
  504. bflsc->drv->dname, bflsc->device_path, amount, err);
  505. } else {
  506. applog(LOG_ERR, "%s detect (%s) get details returned nothing (%d:%d)",
  507. bflsc->drv->dname, bflsc->device_path, amount, err);
  508. }
  509. return false;
  510. }
  511. memset(&sc_dev, 0, sizeof(struct bflsc_dev));
  512. sc_info->sc_count = 1;
  513. res = tolines(bflsc, dev, &(buf[0]), &lines, &items, C_GETDETAILS);
  514. for (i = 0; i < lines-2; i++) {
  515. res = breakdown(ONECOLON, items[i], &count, &firstname, &fields, &lf);
  516. if (lf)
  517. *lf = '\0';
  518. if (!res || count != 1) {
  519. applog(LOG_WARNING, "%s detect (%s) invalid details line: '%s' %d",
  520. bflsc->drv->dname, bflsc->device_path, str_text(buf), count);
  521. dev_error(bflsc, REASON_DEV_COMMS_ERROR);
  522. goto mata;
  523. }
  524. if (strcmp(firstname, BFLSC_DI_FIRMWARE) == 0)
  525. sc_dev.firmware = strdup(fields[0]);
  526. else if (strcmp(firstname, BFLSC_DI_ENGINES) == 0) {
  527. sc_dev.engines = atoi(fields[0]);
  528. if (sc_dev.engines < 1) {
  529. applog(LOG_WARNING, "%s detect (%s) invalid engine count: '%s%s'",
  530. bflsc->drv->dname, bflsc->device_path, buf, lf ? LFSTR : BLANK);
  531. goto mata;
  532. }
  533. }
  534. else if (strcmp(firstname, BFLSC_DI_XLINKMODE) == 0)
  535. sc_dev.xlink_mode = strdup(fields[0]);
  536. else if (strcmp(firstname, BFLSC_DI_XLINKPRESENT) == 0)
  537. sc_dev.xlink_present = strdup(fields[0]);
  538. else if (strcmp(firstname, BFLSC_DI_DEVICESINCHAIN) == 0) {
  539. sc_info->sc_count = atoi(fields[0]) + 1;
  540. if (sc_info->sc_count < 1 || sc_info->sc_count > 30) {
  541. applog(LOG_WARNING, "%s detect (%s) invalid s-link count: '%s%s'",
  542. bflsc->drv->dname, bflsc->device_path, buf, lf ? LFSTR : BLANK);
  543. goto mata;
  544. }
  545. }
  546. freebreakdown(&count, &firstname, &fields);
  547. }
  548. sc_info->sc_devs = calloc(sc_info->sc_count, sizeof(struct bflsc_dev));
  549. if (unlikely(!sc_info->sc_devs))
  550. quit(1, "Failed to calloc in getinfo");
  551. memcpy(&(sc_info->sc_devs[0]), &sc_dev, sizeof(sc_dev));
  552. // TODO: do we care about getting this info for the rest if > 0 x-link
  553. ok = true;
  554. goto ne;
  555. mata:
  556. freebreakdown(&count, &firstname, &fields);
  557. ok = false;
  558. ne:
  559. freetolines(&lines, &items);
  560. return ok;
  561. }
  562. static bool bflsc_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  563. {
  564. struct bflsc_info *sc_info = NULL;
  565. char buf[BFLSC_BUFSIZ+1];
  566. char devpath[20];
  567. int i, err, amount;
  568. struct timeval init_start, init_now;
  569. int init_sleep, init_count;
  570. bool ident_first;
  571. char *newname;
  572. struct cgpu_info *bflsc = calloc(1, sizeof(*bflsc));
  573. if (unlikely(!bflsc))
  574. quit(1, "Failed to calloc bflsc in bflsc_detect_one");
  575. bflsc->drv = &bflsc_drv;
  576. bflsc->deven = DEV_ENABLED;
  577. bflsc->threads = 1;
  578. sc_info = calloc(1, sizeof(*sc_info));
  579. if (unlikely(!sc_info))
  580. quit(1, "Failed to calloc sc_info in bflsc_detect_one");
  581. // TODO: fix ... everywhere ...
  582. bflsc->device_file = (FILE *)sc_info;
  583. if (!usb_init(bflsc, dev, found)) {
  584. applog(LOG_ERR, "%s detect (%d:%d) failed to initialise (incorrect device?)",
  585. bflsc->drv->dname,
  586. (int)(bflsc->usbinfo.bus_number),
  587. (int)(bflsc->usbinfo.device_address));
  588. goto shin;
  589. }
  590. sprintf(devpath, "%d:%d",
  591. (int)(bflsc->usbinfo.bus_number),
  592. (int)(bflsc->usbinfo.device_address));
  593. // Allow 2 complete attempts if the 1st time returns an unrecognised reply
  594. ident_first = true;
  595. retry:
  596. init_count = 0;
  597. init_sleep = REINIT_TIME_FIRST_MS;
  598. cgtime(&init_start);
  599. reinit:
  600. __bflsc_initialise(bflsc);
  601. err = write_to_dev(bflsc, 0, BFLSC_IDENTIFY, BFLSC_IDENTIFY_LEN, &amount, C_REQUESTIDENTIFY);
  602. if (err < 0 || amount != BFLSC_IDENTIFY_LEN) {
  603. applog(LOG_ERR, "%s detect (%s) send identify request failed (%d:%d)",
  604. bflsc->drv->dname, devpath, amount, err);
  605. goto unshin;
  606. }
  607. err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY);
  608. if (err < 0 || amount < 1) {
  609. init_count++;
  610. cgtime(&init_now);
  611. if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) {
  612. if (init_count == 2) {
  613. applog(LOG_WARNING, "%s detect (%s) 2nd init failed (%d:%d) - retrying",
  614. bflsc->drv->dname, devpath, amount, err);
  615. }
  616. nmsleep(init_sleep);
  617. if ((init_sleep * 2) <= REINIT_TIME_MAX_MS)
  618. init_sleep *= 2;
  619. goto reinit;
  620. }
  621. if (init_count > 0)
  622. applog(LOG_WARNING, "%s detect (%s) init failed %d times %.2fs",
  623. bflsc->drv->dname, devpath, init_count, tdiff(&init_now, &init_start));
  624. if (err < 0) {
  625. applog(LOG_ERR, "%s detect (%s) error identify reply (%d:%d)",
  626. bflsc->drv->dname, devpath, amount, err);
  627. } else {
  628. applog(LOG_ERR, "%s detect (%s) empty identify reply (%d)",
  629. bflsc->drv->dname, devpath, amount);
  630. }
  631. goto unshin;
  632. }
  633. buf[amount] = '\0';
  634. if (unlikely(!strstr(buf, BFLSC_BFLSC))) {
  635. applog(LOG_DEBUG, "%s detect (%s) found an FPGA '%s' ignoring",
  636. bflsc->drv->dname, devpath, buf);
  637. goto unshin;
  638. }
  639. if (unlikely(strstr(buf, BFLSC_IDENTITY))) {
  640. if (ident_first) {
  641. applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' trying again ...",
  642. bflsc->drv->dname, devpath, buf);
  643. ident_first = false;
  644. goto retry;
  645. }
  646. applog(LOG_DEBUG, "%s detect (%s) didn't recognise '%s' on 2nd attempt",
  647. bflsc->drv->dname, devpath, buf);
  648. goto unshin;
  649. }
  650. bflsc->device_path = strdup(devpath);
  651. if (!getinfo(bflsc, 0))
  652. goto unshin;
  653. sc_info->scan_sleep_time = BAS_SCAN_TIME;
  654. sc_info->results_sleep_time = BAS_RES_TIME;
  655. sc_info->default_ms_work = BAS_WORK_TIME;
  656. newname = NULL;
  657. if (sc_info->sc_count > 1) {
  658. newname = BFLSC_MINIRIG;
  659. sc_info->scan_sleep_time = BAM_SCAN_TIME;
  660. sc_info->results_sleep_time = BAM_RES_TIME;
  661. sc_info->default_ms_work = BAM_WORK_TIME;
  662. } else {
  663. switch (sc_info->sc_devs[0].engines) {
  664. case 1:
  665. newname = BFLSC_JALAPENO;
  666. sc_info->scan_sleep_time = BAJ_SCAN_TIME;
  667. sc_info->results_sleep_time = BAJ_RES_TIME;
  668. sc_info->default_ms_work = BAJ_WORK_TIME;
  669. break;
  670. case 2:
  671. case 3:
  672. case 4:
  673. newname = BFLSC_LITTLESINGLE;
  674. sc_info->scan_sleep_time = BAL_SCAN_TIME;
  675. sc_info->results_sleep_time = BAL_RES_TIME;
  676. sc_info->default_ms_work = BAL_WORK_TIME;
  677. break;
  678. default:
  679. break;
  680. }
  681. }
  682. for (i = 0; i < sc_info->sc_count; i++)
  683. sc_info->sc_devs[i].ms_work = sc_info->default_ms_work;
  684. if (newname) {
  685. if (!bflsc->drv->copy)
  686. bflsc->drv = copy_drv(bflsc->drv);
  687. bflsc->drv->name = newname;
  688. }
  689. // Do a performance test of a nonce? (and set ms_work)
  690. // We have a real BFLSC!
  691. applog(LOG_DEBUG, "%s (%s) identified as: '%s'",
  692. bflsc->drv->dname, devpath, bflsc->drv->name);
  693. if (!add_cgpu(bflsc))
  694. goto unshin;
  695. update_usb_stats(bflsc);
  696. mutex_init(&bflsc->device_mutex);
  697. return true;
  698. unshin:
  699. usb_uninit(bflsc);
  700. shin:
  701. free(bflsc->device_path);
  702. free(bflsc->device_file);
  703. if (bflsc->name != blank)
  704. free(bflsc->name);
  705. if (bflsc->drv->copy)
  706. free(bflsc->drv);
  707. free(bflsc);
  708. return false;
  709. }
  710. static void bflsc_detect(void)
  711. {
  712. usb_detect(&bflsc_drv, bflsc_detect_one);
  713. }
  714. static void get_bflsc_statline_before(char *buf, struct cgpu_info *bflsc)
  715. {
  716. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  717. float temp = 0;
  718. float vcc1 = 0;
  719. int i;
  720. rd_lock(&(sc_info->stat_lock));
  721. for (i = 0; i < sc_info->sc_count; i++) {
  722. if (sc_info->sc_devs[i].temp1 > temp)
  723. temp = sc_info->sc_devs[i].temp1;
  724. if (sc_info->sc_devs[i].temp2 > temp)
  725. temp = sc_info->sc_devs[i].temp2;
  726. if (sc_info->sc_devs[i].vcc1 > vcc1)
  727. vcc1 = sc_info->sc_devs[i].vcc1;
  728. }
  729. rd_unlock(&(sc_info->stat_lock));
  730. tailsprintf(buf, "max%5.1fC%4.2fV | ", temp, vcc1);
  731. }
  732. static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount)
  733. {
  734. char buf[BFLSC_BUFSIZ+1];
  735. *err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd);
  736. if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
  737. return false;
  738. else
  739. return true;
  740. }
  741. static bool getokerr(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount, char *buf, size_t bufsiz)
  742. {
  743. *err = usb_ftdi_read_nl(bflsc, buf, bufsiz-1, amount, cmd);
  744. if (*err < 0 || *amount < (int)BFLSC_OK_LEN)
  745. return false;
  746. else {
  747. if (*amount > (int)BFLSC_ANERR_LEN && strncmp(buf, BFLSC_ANERR, BFLSC_ANERR_LEN) == 0)
  748. return false;
  749. else
  750. return true;
  751. }
  752. }
  753. static void bflsc_send_flush_work(struct cgpu_info *bflsc, int dev)
  754. {
  755. int err, amount;
  756. // Device is gone
  757. if (bflsc->usbinfo.nodev)
  758. return;
  759. mutex_lock(&bflsc->device_mutex);
  760. err = write_to_dev(bflsc, dev, BFLSC_QFLUSH, BFLSC_QFLUSH_LEN, &amount, C_QUEFLUSH);
  761. if (err < 0 || amount != BFLSC_QFLUSH_LEN) {
  762. mutex_unlock(&bflsc->device_mutex);
  763. bflsc_applog(bflsc, dev, C_QUEFLUSH, amount, err);
  764. } else {
  765. // TODO: do we care if we don't get 'OK'? (always will in normal processing)
  766. err = getok(bflsc, C_QUEFLUSHREPLY, &err, &amount);
  767. mutex_unlock(&bflsc->device_mutex);
  768. // TODO: report an error if not 'OK' ?
  769. }
  770. }
  771. static void flush_one_dev(struct cgpu_info *bflsc, int dev)
  772. {
  773. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  774. struct work *work, *tmp;
  775. bool did = false;
  776. bflsc_send_flush_work(bflsc, dev);
  777. rd_lock(&bflsc->qlock);
  778. HASH_ITER(hh, bflsc->queued_work, work, tmp) {
  779. if (work->queued && work->subid == dev) {
  780. // devflag is used to flag stale work
  781. work->devflag = true;
  782. did = true;
  783. }
  784. }
  785. rd_unlock(&bflsc->qlock);
  786. if (did) {
  787. wr_lock(&(sc_info->stat_lock));
  788. sc_info->sc_devs[dev].flushed = true;
  789. sc_info->sc_devs[dev].flush_id = sc_info->sc_devs[dev].result_id;
  790. sc_info->sc_devs[dev].work_queued = 0;
  791. wr_unlock(&(sc_info->stat_lock));
  792. }
  793. }
  794. static void bflsc_flush_work(struct cgpu_info *bflsc)
  795. {
  796. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  797. int dev;
  798. for (dev = 0; dev < sc_info->sc_count; dev++)
  799. flush_one_dev(bflsc, dev);
  800. }
  801. static void bflsc_flash_led(struct cgpu_info *bflsc, int dev)
  802. {
  803. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  804. int err, amount;
  805. // Device is gone
  806. if (bflsc->usbinfo.nodev)
  807. return;
  808. // It is not critical flashing the led so don't get stuck if we
  809. // can't grab the mutex now
  810. if (mutex_trylock(&bflsc->device_mutex))
  811. return;
  812. err = write_to_dev(bflsc, dev, BFLSC_FLASH, BFLSC_FLASH_LEN, &amount, C_REQUESTFLASH);
  813. if (err < 0 || amount != BFLSC_FLASH_LEN) {
  814. mutex_unlock(&(bflsc->device_mutex));
  815. bflsc_applog(bflsc, dev, C_REQUESTFLASH, amount, err);
  816. } else {
  817. getok(bflsc, C_FLASHREPLY, &err, &amount);
  818. mutex_unlock(&(bflsc->device_mutex));
  819. }
  820. // Once we've tried - don't do it until told to again
  821. // - even if it failed
  822. sc_info->flash_led = false;
  823. return;
  824. }
  825. static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev)
  826. {
  827. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  828. char buf[BFLSC_BUFSIZ+1];
  829. int err, amount;
  830. char *firstname, **fields, *lf;
  831. char xlink[17];
  832. int count;
  833. bool res;
  834. float temp, temp1, temp2;
  835. // Device is gone
  836. if (bflsc->usbinfo.nodev)
  837. return false;
  838. if (dev >= sc_info->sc_count) {
  839. applog(LOG_ERR, "%s%i: temp invalid xlink device %d - limit %d",
  840. bflsc->drv->name, bflsc->device_id, dev, sc_info->sc_count - 1);
  841. return false;
  842. }
  843. // Flash instead of Temp
  844. if (sc_info->flash_led) {
  845. bflsc_flash_led(bflsc, dev);
  846. return true;
  847. }
  848. /* It is not very critical getting temp so don't get stuck if we
  849. * can't grab the mutex here */
  850. if (mutex_trylock(&bflsc->device_mutex))
  851. return false;
  852. xlinkstr(&(xlink[0]), dev, sc_info);
  853. err = write_to_dev(bflsc, dev, BFLSC_TEMPERATURE, BFLSC_TEMPERATURE_LEN, &amount, C_REQUESTTEMPERATURE);
  854. if (err < 0 || amount != BFLSC_TEMPERATURE_LEN) {
  855. mutex_unlock(&(bflsc->device_mutex));
  856. applog(LOG_ERR, "%s%i: Error: Request%s temp invalid/timed out (%d:%d)",
  857. bflsc->drv->name, bflsc->device_id, xlink, amount, err);
  858. return false;
  859. }
  860. err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE);
  861. if (err < 0 || amount < 1) {
  862. mutex_unlock(&(bflsc->device_mutex));
  863. if (err < 0) {
  864. applog(LOG_ERR, "%s%i: Error: Get%s temp return invalid/timed out (%d:%d)",
  865. bflsc->drv->name, bflsc->device_id, xlink, amount, err);
  866. } else {
  867. applog(LOG_ERR, "%s%i: Error: Get%s temp returned nothing (%d:%d)",
  868. bflsc->drv->name, bflsc->device_id, xlink, amount, err);
  869. }
  870. return false;
  871. }
  872. mutex_unlock(&(bflsc->device_mutex));
  873. res = breakdown(ALLCOLON, buf, &count, &firstname, &fields, &lf);
  874. if (lf)
  875. *lf = '\0';
  876. if (!res || count != 2 || !lf) {
  877. applog(LOG_WARNING, "%s%i: Invalid%s temp reply: '%s%s'",
  878. bflsc->drv->name, bflsc->device_id, xlink, buf, lf ? LFSTR : BLANK);
  879. freebreakdown(&count, &firstname, &fields);
  880. dev_error(bflsc, REASON_DEV_COMMS_ERROR);
  881. return false;
  882. }
  883. temp = temp1 = (float)atoi(fields[0]);
  884. temp2 = (float)atoi(fields[1]);
  885. if (temp1 > 0 || temp2 > 0) {
  886. wr_lock(&(sc_info->stat_lock));
  887. sc_info->sc_devs[dev].temp1 = temp1;
  888. sc_info->sc_devs[dev].temp2 = temp2;
  889. if (temp1 > sc_info->sc_devs[dev].temp1_max) {
  890. sc_info->sc_devs[dev].temp1_max = temp1;
  891. sc_info->sc_devs[dev].temp1_max_time = time(NULL);
  892. }
  893. if (temp2 > sc_info->sc_devs[dev].temp2_max) {
  894. sc_info->sc_devs[dev].temp2_max = temp2;
  895. sc_info->sc_devs[dev].temp2_max_time = time(NULL);
  896. }
  897. sc_info->sc_devs[dev].temp1_sum += temp1;
  898. sc_info->sc_devs[dev].temp2_sum += temp2;
  899. sc_info->sc_devs[dev].temp_count++;
  900. sc_info->sc_devs[dev].temp_time = time(NULL);
  901. // TODO: 5min av
  902. // also will be useful for adjusting the fans by code
  903. wr_unlock(&(sc_info->stat_lock));
  904. if (temp < temp2)
  905. temp = temp2;
  906. bflsc->temp = temp;
  907. if (bflsc->cutofftemp > 0 && temp > bflsc->cutofftemp) {
  908. applog(LOG_WARNING, "%s%i:%s temp (%.1f) hit thermal cutoff limit %d, stopping work!",
  909. bflsc->drv->name, bflsc->device_id, xlink,
  910. temp, bflsc->cutofftemp);
  911. dev_error(bflsc, REASON_DEV_THERMAL_CUTOFF);
  912. sc_info->sc_devs[dev].overheat = true;
  913. flush_one_dev(bflsc, dev);
  914. return false;
  915. }
  916. if (bflsc->cutofftemp > 0 && temp < (bflsc->cutofftemp - BFLSC_TEMP_RECOVER))
  917. sc_info->sc_devs[dev].overheat = false;
  918. }
  919. freebreakdown(&count, &firstname, &fields);
  920. return true;
  921. }
  922. static void process_nonces(struct cgpu_info *bflsc, int dev, char *xlink, char *data, int count, char **fields, int *nonces)
  923. {
  924. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  925. char midstate[MIDSTATE_BYTES], blockdata[MERKLE_BYTES];
  926. struct work *work;
  927. uint32_t nonce;
  928. int i, num;
  929. bool res;
  930. char *tmp;
  931. if (count < QUE_FLD_MIN) {
  932. tmp = str_text(data);
  933. applog(LOG_ERR, "%s%i:%s work returned too small (%d,%s)",
  934. bflsc->drv->name, bflsc->device_id, xlink, count, tmp);
  935. free(tmp);
  936. return;
  937. }
  938. if (count > QUE_FLD_MAX) {
  939. applog(LOG_ERR, "%s%i:%s work returned too large (%d) processing %d anyway",
  940. bflsc->drv->name, bflsc->device_id, xlink, count, QUE_FLD_MAX);
  941. count = QUE_FLD_MAX;
  942. }
  943. num = atoi(fields[QUE_NONCECOUNT]);
  944. if (num != count - QUE_FLD_MIN) {
  945. applog(LOG_ERR, "%s%i:%s incorrect data count (%d) will use %d instead",
  946. bflsc->drv->name, bflsc->device_id, xlink, num, count - QUE_FLD_MAX);
  947. }
  948. memset(midstate, 0, MIDSTATE_BYTES);
  949. memset(blockdata, 0, MERKLE_BYTES);
  950. hex2bin((unsigned char *)midstate, fields[QUE_MIDSTATE], MIDSTATE_BYTES);
  951. hex2bin((unsigned char *)blockdata, fields[QUE_BLOCKDATA], MERKLE_BYTES);
  952. work = find_queued_work_bymidstate(bflsc, midstate, MIDSTATE_BYTES,
  953. blockdata, MERKLE_OFFSET, MERKLE_BYTES);
  954. if (!work) {
  955. applog(LOG_ERR, "%s%i:%s failed to find work - can't be processed - ignored",
  956. bflsc->drv->name, bflsc->device_id, xlink);
  957. return;
  958. }
  959. res = false;
  960. for (i = QUE_FLD_MIN; i < count; i++) {
  961. if (strlen(fields[i]) != 8) {
  962. tmp = str_text(data);
  963. applog(LOG_ERR, "%s%i:%s invalid nonce (%s) will try to process anyway",
  964. bflsc->drv->name, bflsc->device_id, xlink, tmp);
  965. free(tmp);
  966. }
  967. hex2bin((void*)&nonce, fields[i], 4);
  968. nonce = htobe32(nonce);
  969. wr_lock(&(sc_info->stat_lock));
  970. sc_info->sc_devs[dev].nonces_found++;
  971. wr_unlock(&(sc_info->stat_lock));
  972. submit_nonce(bflsc->thr[0], work, nonce);
  973. (*nonces)++;
  974. res = true;
  975. }
  976. wr_lock(&(sc_info->stat_lock));
  977. if (res)
  978. sc_info->sc_devs[dev].result_id++;
  979. sc_info->sc_devs[dev].work_complete++;
  980. sc_info->sc_devs[dev].hashes_unsent += FULLNONCE;
  981. // If not flushed (stale)
  982. if (!(work->devflag))
  983. sc_info->sc_devs[dev].work_queued -= 1;
  984. wr_unlock(&(sc_info->stat_lock));
  985. work_completed(bflsc, work);
  986. }
  987. static int process_results(struct cgpu_info *bflsc, int dev, char *buf, int *nonces)
  988. {
  989. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  990. char **items, *firstname, **fields, *lf;
  991. int que, i, lines, count;
  992. char xlink[17];
  993. bool res;
  994. char *tmp, *tmp2;
  995. *nonces = 0;
  996. xlinkstr(&(xlink[0]), dev, sc_info);
  997. res = tolines(bflsc, dev, buf, &lines, &items, C_GETRESULTS);
  998. if (lines < 1) {
  999. tmp = str_text(buf);
  1000. applog(LOG_ERR, "%s%i:%s empty result (%s) ignored",
  1001. bflsc->drv->name, bflsc->device_id, xlink, tmp);
  1002. free(tmp);
  1003. que = 0;
  1004. goto arigatou;
  1005. }
  1006. if (lines < QUE_RES_LINES_MIN) {
  1007. tmp = str_text(buf);
  1008. applog(LOG_ERR, "%s%i:%s result too small (%s) ignored",
  1009. bflsc->drv->name, bflsc->device_id, xlink, tmp);
  1010. free(tmp);
  1011. que = 0;
  1012. goto arigatou;
  1013. }
  1014. res = breakdown(ONECOLON, items[1], &count, &firstname, &fields, &lf);
  1015. if (count < 1) {
  1016. tmp = str_text(buf);
  1017. tmp2 = str_text(items[1]);
  1018. applog(LOG_ERR, "%s%i:%s empty result count (%s) in (%s) will try anyway",
  1019. bflsc->drv->name, bflsc->device_id, xlink, tmp2, tmp);
  1020. free(tmp2);
  1021. free(tmp);
  1022. } else if (count != 1) {
  1023. tmp = str_text(buf);
  1024. tmp2 = str_text(items[1]);
  1025. applog(LOG_ERR, "%s%i:%s incorrect result count (%s) in (%s) will try anyway",
  1026. bflsc->drv->name, bflsc->device_id, xlink, tmp2, tmp);
  1027. free(tmp2);
  1028. free(tmp);
  1029. }
  1030. que = atoi(fields[0]);
  1031. if (que != (lines - QUE_RES_LINES_MIN)) {
  1032. i = que;
  1033. // 1+ In case the last line isn't 'OK' - try to process it
  1034. que = 1 + lines - QUE_RES_LINES_MIN;
  1035. tmp = str_text(items[0]);
  1036. applog(LOG_ERR, "%s%i:%s incorrect result count (%s) %d but should be %d will try %d anyway",
  1037. bflsc->drv->name, bflsc->device_id, xlink, tmp, i, que, que);
  1038. free(tmp);
  1039. }
  1040. freebreakdown(&count, &firstname, &fields);
  1041. for (i = 0; i < que; i++) {
  1042. res = breakdown(NOCOLON, items[i + QUE_RES_LINES_MIN - 1], &count, &firstname, &fields, &lf);
  1043. process_nonces(bflsc, dev, &(xlink[0]), items[i], count, fields, nonces);
  1044. freebreakdown(&count, &firstname, &fields);
  1045. }
  1046. arigatou:
  1047. freetolines(&lines, &items);
  1048. return que;
  1049. }
  1050. #define TVF(tv) ((float)((tv)->tv_sec) + ((float)((tv)->tv_usec) / 1000000.0))
  1051. #define TVFMS(tv) (TVF(tv) * 1000.0)
  1052. // Thread to simply keep looking for results
  1053. static void *bflsc_get_results(void *userdata)
  1054. {
  1055. struct cgpu_info *bflsc = (struct cgpu_info *)userdata;
  1056. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1057. struct timeval elapsed, now;
  1058. float oldest, f;
  1059. char buf[BFLSC_BUFSIZ+1];
  1060. int err, amount;
  1061. int i, que, dev, nonces;
  1062. cgtime(&now);
  1063. for (i = 0; i < sc_info->sc_count; i++) {
  1064. copy_time(&(sc_info->sc_devs[i].last_check_result), &now);
  1065. copy_time(&(sc_info->sc_devs[i].last_dev_result), &now);
  1066. copy_time(&(sc_info->sc_devs[i].last_nonce_result), &now);
  1067. }
  1068. while (sc_info->shutdown == false) {
  1069. if (bflsc->usbinfo.nodev)
  1070. return NULL;
  1071. dev = -1;
  1072. oldest = FLT_MAX;
  1073. cgtime(&now);
  1074. // Find the first oldest ... that also needs checking
  1075. for (i = 0; i < sc_info->sc_count; i++) {
  1076. timersub(&now, &(sc_info->sc_devs[i].last_check_result), &elapsed);
  1077. f = TVFMS(&elapsed);
  1078. if (f < oldest && f >= sc_info->sc_devs[i].ms_work) {
  1079. f = oldest;
  1080. dev = i;
  1081. }
  1082. }
  1083. if (bflsc->usbinfo.nodev)
  1084. return NULL;
  1085. if (dev == -1)
  1086. goto utsura;
  1087. mutex_lock(&(bflsc->device_mutex));
  1088. cgtime(&(sc_info->sc_devs[dev].last_check_result));
  1089. err = write_to_dev(bflsc, dev, BFLSC_QRES, BFLSC_QRES_LEN, &amount, C_REQUESTRESULTS);
  1090. if (err < 0 || amount != BFLSC_QRES_LEN) {
  1091. mutex_unlock(&(bflsc->device_mutex));
  1092. bflsc_applog(bflsc, dev, C_REQUESTRESULTS, amount, err);
  1093. // TODO: do what? flag as dead device?
  1094. // count how many times it has happened and reset/fail it
  1095. // or even make sure it is all x-link and that means device
  1096. // has failed after some limit of this?
  1097. // of course all other I/O must also be failing ...
  1098. } else {
  1099. err = usb_ftdi_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETRESULTS);
  1100. mutex_unlock(&(bflsc->device_mutex));
  1101. if (err < 0 || amount < 1) {
  1102. bflsc_applog(bflsc, dev, C_GETRESULTS, amount, err);
  1103. // TODO: do what? ... see above
  1104. } else {
  1105. que = process_results(bflsc, dev, buf, &nonces);
  1106. if (que > 0)
  1107. cgtime(&(sc_info->sc_devs[dev].last_dev_result));
  1108. if (nonces > 0)
  1109. cgtime(&(sc_info->sc_devs[dev].last_nonce_result));
  1110. // TODO: if not getting results ...
  1111. }
  1112. // TODO: re-estimate the wait times (results_sleep_time and ms_work) based on ?
  1113. }
  1114. utsura:
  1115. nmsleep(sc_info->results_sleep_time);
  1116. }
  1117. return NULL;
  1118. }
  1119. static bool bflsc_thread_prepare(struct thr_info *thr)
  1120. {
  1121. struct cgpu_info *bflsc = thr->cgpu;
  1122. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1123. struct timeval now;
  1124. if (thr_info_create(&(sc_info->results_thr), NULL, bflsc_get_results, (void *)bflsc)) {
  1125. applog(LOG_ERR, "%s%i: thread create failed", bflsc->drv->name, bflsc->device_id);
  1126. return false;
  1127. }
  1128. pthread_detach(sc_info->results_thr.pth);
  1129. cgtime(&now);
  1130. get_datestamp(bflsc->init, &now);
  1131. return true;
  1132. }
  1133. static void bflsc_shutdown(struct thr_info *thr)
  1134. {
  1135. struct cgpu_info *bflsc = thr->cgpu;
  1136. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1137. sc_info->shutdown = true;
  1138. }
  1139. static void bflsc_thread_enable(struct thr_info *thr)
  1140. {
  1141. struct cgpu_info *bflsc = thr->cgpu;
  1142. if (bflsc->usbinfo.nodev)
  1143. return;
  1144. bflsc_initialise(bflsc);
  1145. }
  1146. static bool bflsc_send_work(struct cgpu_info *bflsc, int dev, struct work *work)
  1147. {
  1148. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1149. struct FullNonceRangeJob data;
  1150. char buf[BFLSC_BUFSIZ+1];
  1151. int err, amount;
  1152. int len;
  1153. int try;
  1154. // Device is gone
  1155. if (bflsc->usbinfo.nodev)
  1156. return false;
  1157. // TODO: handle this everywhere
  1158. if (sc_info->sc_devs[dev].overheat == true)
  1159. return false;
  1160. // Initially code only deals with sending one work item
  1161. data.payloadSize = BFLSC_JOBSIZ;
  1162. memcpy(data.midState, work->midstate, MIDSTATE_BYTES);
  1163. memcpy(data.blockData, work->data + MERKLE_OFFSET, MERKLE_BYTES);
  1164. data.endOfBlock = BFLSC_EOB;
  1165. try = 0;
  1166. mutex_lock(&(bflsc->device_mutex));
  1167. re_send:
  1168. err = write_to_dev(bflsc, dev, BFLSC_QJOB, BFLSC_QJOB_LEN, &amount, C_REQUESTQUEJOB);
  1169. if (err < 0 || amount != BFLSC_QJOB_LEN) {
  1170. mutex_unlock(&(bflsc->device_mutex));
  1171. bflsc_applog(bflsc, dev, C_REQUESTQUEJOB, amount, err);
  1172. return false;
  1173. }
  1174. if (!getok(bflsc, C_REQUESTQUEJOBSTATUS, &err, &amount)) {
  1175. mutex_unlock(&(bflsc->device_mutex));
  1176. bflsc_applog(bflsc, dev, C_REQUESTQUEJOBSTATUS, amount, err);
  1177. return false;
  1178. }
  1179. len = sizeof(struct FullNonceRangeJob);
  1180. err = write_to_dev(bflsc, dev, (char *)&data, len, &amount, C_QUEJOB);
  1181. if (err < 0 || amount != len) {
  1182. mutex_unlock(&(bflsc->device_mutex));
  1183. bflsc_applog(bflsc, dev, C_QUEJOB, amount, err);
  1184. return false;
  1185. }
  1186. if (!getokerr(bflsc, C_QUEJOBSTATUS, &err, &amount, buf, sizeof(buf))) {
  1187. // TODO: check for QUEUE FULL and set work_queued to BFLSC_QUE_SIZE
  1188. // and report a code bug LOG_ERR - coz it should never happen
  1189. // Try twice
  1190. if (try++ < 1 && amount > 1 &&
  1191. strncasecmp(buf, BFLSC_TIMEOUT, BFLSC_TIMEOUT_LEN) == 0)
  1192. goto re_send;
  1193. mutex_unlock(&(bflsc->device_mutex));
  1194. bflsc_applog(bflsc, dev, C_QUEJOBSTATUS, amount, err);
  1195. return false;
  1196. }
  1197. mutex_unlock(&(bflsc->device_mutex));
  1198. wr_lock(&(sc_info->stat_lock));
  1199. sc_info->sc_devs[dev].work_queued++;
  1200. wr_unlock(&(sc_info->stat_lock));
  1201. work->subid = dev;
  1202. return true;
  1203. }
  1204. static bool bflsc_queue_full(struct cgpu_info *bflsc)
  1205. {
  1206. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1207. struct work *work = NULL;
  1208. int i, dev, tried, que;
  1209. bool ret = false;
  1210. int tries = 0;
  1211. tried = -1;
  1212. // if something is wrong with a device try the next one available
  1213. // TODO: try them all? Add an unavailable flag to sc_devs[i] init to 0 here first
  1214. while (++tries < 3) {
  1215. // Device is gone
  1216. if (bflsc->usbinfo.nodev)
  1217. return false;
  1218. dev = -1;
  1219. rd_lock(&(sc_info->stat_lock));
  1220. // Anything waiting - gets the work first
  1221. for (i = 0; i < sc_info->sc_count; i++) {
  1222. // TODO: and ignore x-link dead - once I work out how to decide it is dead
  1223. if (i != tried && sc_info->sc_devs[i].work_queued == 0 &&
  1224. !sc_info->sc_devs[i].overheat) {
  1225. dev = i;
  1226. break;
  1227. }
  1228. }
  1229. if (dev == -1) {
  1230. que = BFLSC_QUE_SIZE * 10; // 10x is certainly above the MAX it could be
  1231. // The first device with the smallest amount queued
  1232. for (i = 0; i < sc_info->sc_count; i++) {
  1233. if (i != tried && sc_info->sc_devs[i].work_queued < que &&
  1234. !sc_info->sc_devs[i].overheat) {
  1235. dev = i;
  1236. que = sc_info->sc_devs[i].work_queued;
  1237. }
  1238. }
  1239. if (que > BFLSC_QUE_FULL_ENOUGH)
  1240. dev = -1;
  1241. }
  1242. rd_unlock(&(sc_info->stat_lock));
  1243. // nothing needs work yet
  1244. if (dev == -1) {
  1245. ret = true;
  1246. break;
  1247. }
  1248. if (!work)
  1249. work = get_queued(bflsc);
  1250. if (unlikely(!work))
  1251. break;
  1252. if (bflsc_send_work(bflsc, dev, work)) {
  1253. work = NULL;
  1254. break;
  1255. } else
  1256. tried = dev;
  1257. }
  1258. if (unlikely(work))
  1259. work_completed(bflsc, work);
  1260. return ret;
  1261. }
  1262. static int64_t bflsc_scanwork(struct thr_info *thr)
  1263. {
  1264. struct cgpu_info *bflsc = thr->cgpu;
  1265. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1266. int64_t ret, unsent;
  1267. bool flushed, cleanup;
  1268. struct work *work, *tmp, *flush;
  1269. int dev;
  1270. // Device is gone
  1271. if (bflsc->usbinfo.nodev)
  1272. return -1;
  1273. flushed = false;
  1274. // Single lock check if any are flagged as flushed
  1275. rd_lock(&(sc_info->stat_lock));
  1276. for (dev = 0; dev < sc_info->sc_count; dev++)
  1277. flushed |= sc_info->sc_devs[dev].flushed;
  1278. rd_unlock(&(sc_info->stat_lock));
  1279. // > 0 flagged as flushed
  1280. if (flushed) {
  1281. // TODO: something like this ......
  1282. for (dev = 0; dev < sc_info->sc_count; dev++) {
  1283. cleanup = false;
  1284. // Is there any flushed work that can be removed?
  1285. wr_lock(&(sc_info->stat_lock));
  1286. if (sc_info->sc_devs[dev].flushed) {
  1287. if (sc_info->sc_devs[dev].result_id > (sc_info->sc_devs[dev].flush_id + 1))
  1288. cleanup = true;
  1289. }
  1290. // yes remove the flushed work that can be removed
  1291. if (cleanup) {
  1292. // one lock per item - TODO: need a better way to do this?
  1293. do {
  1294. flush = NULL;
  1295. rd_lock(&bflsc->qlock);
  1296. HASH_ITER(hh, bflsc->queued_work, work, tmp) {
  1297. if (work->devflag && work->subid == dev)
  1298. flush = work;
  1299. }
  1300. rd_unlock(&bflsc->qlock);
  1301. if (flush)
  1302. discard_work(flush);
  1303. } while (flush);
  1304. sc_info->sc_devs[dev].flushed = false;
  1305. }
  1306. wr_unlock(&(sc_info->stat_lock));
  1307. }
  1308. }
  1309. // avoid a hard loop
  1310. if (sc_info->scan_sleep_time > 0)
  1311. nmsleep(sc_info->scan_sleep_time);
  1312. // Count up the work done since we last were here
  1313. wr_lock(&(sc_info->stat_lock));
  1314. ret = 0;
  1315. for (dev = 0; dev < sc_info->sc_count; dev++) {
  1316. unsent = sc_info->sc_devs[dev].hashes_unsent;
  1317. sc_info->sc_devs[dev].hashes_unsent = 0;
  1318. sc_info->sc_devs[dev].hashes_sent += unsent;
  1319. sc_info->hashes_sent += unsent;
  1320. ret += unsent;
  1321. }
  1322. wr_unlock(&(sc_info->stat_lock));
  1323. return ret;
  1324. }
  1325. static bool bflsc_get_stats(struct cgpu_info *bflsc)
  1326. {
  1327. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1328. bool allok = true;
  1329. int i;
  1330. // Device is gone
  1331. if (bflsc->usbinfo.nodev)
  1332. return false;
  1333. for (i = 0; i < sc_info->sc_count; i++) {
  1334. if (!bflsc_get_temp(bflsc, i))
  1335. allok = false;
  1336. // Device is gone
  1337. if (bflsc->usbinfo.nodev)
  1338. return false;
  1339. if (i < (sc_info->sc_count - 1))
  1340. nmsleep(BFLSC_TEMP_SLEEPMS);
  1341. }
  1342. return allok;
  1343. }
  1344. static void bflsc_identify(struct cgpu_info *bflsc)
  1345. {
  1346. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1347. // TODO: handle x-link
  1348. sc_info->flash_led = true;
  1349. }
  1350. static bool bflsc_thread_init(struct thr_info *thr)
  1351. {
  1352. struct cgpu_info *bflsc = thr->cgpu;
  1353. if (bflsc->usbinfo.nodev)
  1354. return false;
  1355. bflsc_initialise(bflsc);
  1356. return true;
  1357. }
  1358. // there should be a new API function to return device info that isn't the standard stuff
  1359. // instead of bflsc_api_stats - since the stats should really just be internal code info
  1360. // and the new one should be UNusual device stats/extra details - like the stuff below
  1361. static struct api_data *bflsc_api_stats(struct cgpu_info *bflsc)
  1362. {
  1363. struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_file);
  1364. struct api_data *root = NULL;
  1365. //if no x-link ... etc
  1366. rd_lock(&(sc_info->stat_lock));
  1367. root = api_add_temp(root, "Temp1", &(sc_info->sc_devs[0].temp1), true);
  1368. root = api_add_temp(root, "Temp2", &(sc_info->sc_devs[0].temp2), true);
  1369. root = api_add_volts(root, "Vcc1", &(sc_info->sc_devs[0].vcc1), true);
  1370. root = api_add_volts(root, "Vcc2", &(sc_info->sc_devs[0].vcc2), true);
  1371. root = api_add_volts(root, "Vmain", &(sc_info->sc_devs[0].vmain), true);
  1372. root = api_add_temp(root, "Temp1 Max", &(sc_info->sc_devs[0].temp1_max), true);
  1373. root = api_add_temp(root, "Temp2 Max", &(sc_info->sc_devs[0].temp2_max), true);
  1374. root = api_add_time(root, "Temp1 Max Time", &(sc_info->sc_devs[0].temp1_max_time), true);
  1375. root = api_add_time(root, "Temp2 Max Time", &(sc_info->sc_devs[0].temp2_max_time), true);
  1376. rd_unlock(&(sc_info->stat_lock));
  1377. /*
  1378. else a whole lot of something like these ... etc
  1379. root = api_add_temp(root, "X-%d-Temp1", &(sc_info->temp1), false);
  1380. root = api_add_temp(root, "X-%d-Temp2", &(sc_info->temp2), false);
  1381. root = api_add_volts(root, "X-%d-Vcc1", &(sc_info->vcc1), false);
  1382. root = api_add_volts(root, "X-%d-Vcc2", &(sc_info->vcc2), false);
  1383. root = api_add_volts(root, "X-%d-Vmain", &(sc_info->vmain), false);
  1384. */
  1385. return root;
  1386. }
  1387. struct device_drv bflsc_drv = {
  1388. .drv_id = DRIVER_BFLSC,
  1389. .dname = "BitForceSC",
  1390. .name = BFLSC_SINGLE,
  1391. .drv_detect = bflsc_detect,
  1392. .get_api_stats = bflsc_api_stats,
  1393. .get_statline_before = get_bflsc_statline_before,
  1394. .get_stats = bflsc_get_stats,
  1395. .identify_device = bflsc_identify,
  1396. .thread_prepare = bflsc_thread_prepare,
  1397. .thread_init = bflsc_thread_init,
  1398. .hash_work = hash_queued_work,
  1399. .scanwork = bflsc_scanwork,
  1400. .queue_full = bflsc_queue_full,
  1401. .flush_work = bflsc_flush_work,
  1402. .thread_shutdown = bflsc_shutdown,
  1403. .thread_enable = bflsc_thread_enable
  1404. };