driver-klondike.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. /*
  2. * Copyright 2013 Andrew Smith
  3. * Copyright 2013 Con Kolivas
  4. * Copyright 2013 Chris Savery
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 3 of the License, or (at your option)
  9. * any later version. See COPYING for more details.
  10. */
  11. #include "config.h"
  12. #include <float.h>
  13. #include <limits.h>
  14. #include <pthread.h>
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <strings.h>
  19. #include <sys/time.h>
  20. #include <unistd.h>
  21. #include <math.h>
  22. #ifdef WIN32
  23. #include <windows.h>
  24. #endif
  25. #include "compat.h"
  26. #include "deviceapi.h"
  27. #include "lowlevel.h"
  28. #include "lowl-usb.h"
  29. #include "miner.h"
  30. #define K1 "K1"
  31. #define K16 "K16"
  32. #define K64 "K64"
  33. static const char *msg_detect_send = "DSend";
  34. static const char *msg_detect_reply = "DReply";
  35. static const char *msg_send = "Send";
  36. static const char *msg_reply = "Reply";
  37. #define KLN_CMD_ABORT 'A'
  38. #define KLN_CMD_CONFIG 'C'
  39. #define KLN_CMD_ENABLE 'E'
  40. #define KLN_CMD_IDENT 'I'
  41. #define KLN_CMD_NONCE '='
  42. #define KLN_CMD_STATUS 'S'
  43. #define KLN_CMD_WORK 'W'
  44. #define KLN_CMD_ENABLE_OFF '0'
  45. #define KLN_CMD_ENABLE_ON '1'
  46. #define MIDSTATE_BYTES 32
  47. #define MERKLE_OFFSET 64
  48. #define MERKLE_BYTES 12
  49. #define REPLY_SIZE 15 // adequate for all types of replies
  50. #define MAX_KLINES 1024 // unhandled reply limit
  51. #define REPLY_WAIT_TIME 100 // poll interval for a cmd waiting it's reply
  52. #define CMD_REPLY_RETRIES 8 // how many retries for cmds
  53. #define TACH_FACTOR 87890 // fan rpm divisor
  54. #define KLN_KILLWORK_TEMP 53.5
  55. #define KLN_COOLED_DOWN 45.5
  56. /*
  57. * How many incorrect slave counts to ignore in a row
  58. * 2 means it allows random grabage returned twice
  59. * Until slaves are implemented, this should never occur
  60. * so allowing 2 in a row should ignore random errros
  61. */
  62. #define KLN_ISS_IGNORE 2
  63. /*
  64. * If the queue status hasn't been updated for this long then do it now
  65. * 5GH/s = 859ms per full nonce range
  66. */
  67. #define LATE_UPDATE_MS ((int)(2.5 * 1000))
  68. // If 5 late updates in a row, try to reset the device
  69. #define LATE_UPDATE_LIMIT 5
  70. // If the reset fails sleep for 1s
  71. #define LATE_UPDATE_SLEEP_MS 1000
  72. // However give up after 8s
  73. #define LATE_UPDATE_NODEV_MS ((int)(8.0 * 1000))
  74. BFG_REGISTER_DRIVER(klondike_drv)
  75. typedef struct klondike_header {
  76. uint8_t cmd;
  77. uint8_t dev;
  78. uint8_t buf[REPLY_SIZE-2];
  79. } HEADER;
  80. #define K_2(_bytes) ((int)(_bytes[0]) + \
  81. ((int)(_bytes[1]) << 8))
  82. #define K_4(_bytes) ((uint64_t)(_bytes[0]) + \
  83. ((uint64_t)(_bytes[1]) << 8) + \
  84. ((uint64_t)(_bytes[2]) << 16) + \
  85. ((uint64_t)(_bytes[3]) << 24))
  86. #define K_SERIAL(_serial) K_4(_serial)
  87. #define K_HASHCOUNT(_hashcount) K_2(_hashcount)
  88. #define K_MAXCOUNT(_maxcount) K_2(_maxcount)
  89. #define K_NONCE(_nonce) K_4(_nonce)
  90. #define K_HASHCLOCK(_hashclock) K_2(_hashclock)
  91. #define SET_HASHCLOCK(_hashclock, _value) do { \
  92. (_hashclock)[0] = (uint8_t)((_value) & 0xff); \
  93. (_hashclock)[1] = (uint8_t)(((_value) >> 8) & 0xff); \
  94. } while(0)
  95. #define KSENDHD(_add) (sizeof(uint8_t) + sizeof(uint8_t) + _add)
  96. typedef struct klondike_id {
  97. uint8_t cmd;
  98. uint8_t dev;
  99. uint8_t version;
  100. uint8_t product[7];
  101. uint8_t serial[4];
  102. } IDENTITY;
  103. typedef struct klondike_status {
  104. uint8_t cmd;
  105. uint8_t dev;
  106. uint8_t state;
  107. uint8_t chipcount;
  108. uint8_t slavecount;
  109. uint8_t workqc;
  110. uint8_t workid;
  111. uint8_t temp;
  112. uint8_t fanspeed;
  113. uint8_t errorcount;
  114. uint8_t hashcount[2];
  115. uint8_t maxcount[2];
  116. uint8_t noise;
  117. } WORKSTATUS;
  118. typedef struct _worktask {
  119. uint8_t cmd;
  120. uint8_t dev;
  121. uint8_t workid;
  122. uint8_t midstate[32];
  123. uint8_t merkle[12];
  124. } WORKTASK;
  125. typedef struct _workresult {
  126. uint8_t cmd;
  127. uint8_t dev;
  128. uint8_t workid;
  129. uint8_t nonce[4];
  130. } WORKRESULT;
  131. typedef struct klondike_cfg {
  132. uint8_t cmd;
  133. uint8_t dev;
  134. uint8_t hashclock[2];
  135. uint8_t temptarget;
  136. uint8_t tempcritical;
  137. uint8_t fantarget;
  138. uint8_t pad2;
  139. } WORKCFG;
  140. typedef struct kline {
  141. union {
  142. HEADER hd;
  143. IDENTITY id;
  144. WORKSTATUS ws;
  145. WORKTASK wt;
  146. WORKRESULT wr;
  147. WORKCFG cfg;
  148. };
  149. } KLINE;
  150. #define zero_kline(_kline) memset((void *)(_kline), 0, sizeof(KLINE));
  151. typedef struct device_info {
  152. uint32_t noncecount;
  153. uint32_t nextworkid;
  154. uint16_t lasthashcount;
  155. uint64_t totalhashcount;
  156. uint32_t rangesize;
  157. uint32_t *chipstats;
  158. } DEVINFO;
  159. typedef struct klist {
  160. struct klist *prev;
  161. struct klist *next;
  162. KLINE kline;
  163. struct timeval tv_when;
  164. int block_seq;
  165. bool ready;
  166. bool working;
  167. } KLIST;
  168. typedef struct jobque {
  169. int workqc;
  170. struct timeval last_update;
  171. bool overheat;
  172. bool flushed;
  173. int late_update_count;
  174. int late_update_sequential;
  175. } JOBQUE;
  176. struct klondike_info {
  177. pthread_rwlock_t stat_lock;
  178. struct thr_info replies_thr;
  179. cglock_t klist_lock;
  180. KLIST *used;
  181. KLIST *free;
  182. int kline_count;
  183. int used_count;
  184. int block_seq;
  185. KLIST *status;
  186. DEVINFO *devinfo;
  187. KLIST *cfg;
  188. JOBQUE *jobque;
  189. int noncecount;
  190. uint64_t hashcount;
  191. uint64_t errorcount;
  192. uint64_t noisecount;
  193. int incorrect_slave_sequential;
  194. int16_t nonce_offset;
  195. // us Delay from USB reply to being processed
  196. double delay_count;
  197. double delay_total;
  198. double delay_min;
  199. double delay_max;
  200. struct timeval tv_last_nonce_received;
  201. // Time from recieving one nonce to the next
  202. double nonce_count;
  203. double nonce_total;
  204. double nonce_min;
  205. double nonce_max;
  206. int wque_size;
  207. int wque_cleared;
  208. int clock;
  209. bool initialised;
  210. struct libusb_device_handle *usbdev_handle;
  211. // TODO:
  212. bool usbinfo_nodev;
  213. int max_work_count;
  214. int old_work_ms;
  215. };
  216. static KLIST *new_klist_set(struct cgpu_info *klncgpu)
  217. {
  218. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  219. KLIST *klist = NULL;
  220. int i;
  221. klist = calloc(MAX_KLINES, sizeof(*klist));
  222. if (!klist)
  223. quit(1, "Failed to calloc klist - when old count=%d", klninfo->kline_count);
  224. klninfo->kline_count += MAX_KLINES;
  225. klist[0].prev = NULL;
  226. klist[0].next = &(klist[1]);
  227. for (i = 1; i < MAX_KLINES-1; i++) {
  228. klist[i].prev = &klist[i-1];
  229. klist[i].next = &klist[i+1];
  230. }
  231. klist[MAX_KLINES-1].prev = &(klist[MAX_KLINES-2]);
  232. klist[MAX_KLINES-1].next = NULL;
  233. return klist;
  234. }
  235. static KLIST *allocate_kitem(struct cgpu_info *klncgpu)
  236. {
  237. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  238. KLIST *kitem = NULL;
  239. int ran_out = 0;
  240. char errbuf[1024];
  241. cg_wlock(&klninfo->klist_lock);
  242. if (klninfo->free == NULL) {
  243. ran_out = klninfo->kline_count;
  244. klninfo->free = new_klist_set(klncgpu);
  245. snprintf(errbuf, sizeof(errbuf),
  246. "%s%i: KLINE count exceeded %d, now %d",
  247. klncgpu->drv->name, klncgpu->device_id,
  248. ran_out, klninfo->kline_count);
  249. }
  250. kitem = klninfo->free;
  251. klninfo->free = klninfo->free->next;
  252. if (klninfo->free)
  253. klninfo->free->prev = NULL;
  254. kitem->next = klninfo->used;
  255. kitem->prev = NULL;
  256. if (kitem->next)
  257. kitem->next->prev = kitem;
  258. klninfo->used = kitem;
  259. kitem->ready = false;
  260. kitem->working = false;
  261. memset((void *)&(kitem->kline), 0, sizeof(kitem->kline));
  262. klninfo->used_count++;
  263. cg_wunlock(&klninfo->klist_lock);
  264. if (ran_out > 0)
  265. applog(LOG_WARNING, "%s", errbuf);
  266. return kitem;
  267. }
  268. static KLIST *release_kitem(struct cgpu_info *klncgpu, KLIST *kitem)
  269. {
  270. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  271. cg_wlock(&klninfo->klist_lock);
  272. if (kitem == klninfo->used)
  273. klninfo->used = kitem->next;
  274. if (kitem->next)
  275. kitem->next->prev = kitem->prev;
  276. if (kitem->prev)
  277. kitem->prev->next = kitem->next;
  278. kitem->next = klninfo->free;
  279. if (klninfo->free)
  280. klninfo->free->prev = kitem;
  281. kitem->prev = NULL;
  282. klninfo->free = kitem;
  283. klninfo->used_count--;
  284. cg_wunlock(&klninfo->klist_lock);
  285. return NULL;
  286. }
  287. static
  288. int usb_init(struct cgpu_info * const klncgpu, struct libusb_device * const dev)
  289. {
  290. struct klondike_info * const klninfo = klncgpu->device_data;
  291. int e;
  292. if (libusb_open(dev, &klninfo->usbdev_handle) != LIBUSB_SUCCESS)
  293. return 0;
  294. if (LIBUSB_SUCCESS != (e = libusb_set_configuration(klninfo->usbdev_handle, 1)))
  295. {
  296. applog(LOG_DEBUG, "%s: Failed to set configuration 1: %s",
  297. klondike_drv.dname, bfg_strerror(e, BST_LIBUSB));
  298. fail:
  299. libusb_close(klninfo->usbdev_handle);
  300. return 0;
  301. }
  302. if (LIBUSB_SUCCESS != (e = libusb_claim_interface(klninfo->usbdev_handle, 0)))
  303. {
  304. applog(LOG_DEBUG, "%s: Failed to claim interface 0: %s",
  305. klondike_drv.dname, bfg_strerror(e, BST_LIBUSB));
  306. goto fail;
  307. }
  308. return 1;
  309. }
  310. static
  311. int _usb_rw(struct cgpu_info * const klncgpu, void * const buf, const size_t bufsiz, int * const processed, int ep)
  312. {
  313. struct klondike_info * const klninfo = klncgpu->device_data;
  314. const unsigned int timeout = 999;
  315. unsigned char *cbuf = buf;
  316. int err, sent;
  317. *processed = 0;
  318. while (*processed < bufsiz)
  319. {
  320. err = libusb_bulk_transfer(klninfo->usbdev_handle, ep, cbuf, bufsiz, &sent, timeout);
  321. if (unlikely(err))
  322. return err;
  323. *processed += sent;
  324. }
  325. return LIBUSB_SUCCESS;
  326. }
  327. #define usb_read( klncgpu, buf, bufsiz, processed) _usb_rw(klncgpu, buf, bufsiz, processed, 1 | LIBUSB_ENDPOINT_IN)
  328. #define usb_write(klncgpu, buf, bufsiz, processed) _usb_rw(klncgpu, buf, bufsiz, processed, 1 | LIBUSB_ENDPOINT_OUT)
  329. static
  330. void usb_nodev(__maybe_unused struct cgpu_info * const klncgpu)
  331. {
  332. // TODO
  333. }
  334. static
  335. void usb_uninit(struct cgpu_info * const klncgpu)
  336. {
  337. struct klondike_info * const klninfo = klncgpu->device_data;
  338. libusb_release_interface(klninfo->usbdev_handle, 0);
  339. libusb_close(klninfo->usbdev_handle);
  340. }
  341. static double cvtKlnToC(uint8_t temp)
  342. {
  343. double Rt, stein, celsius;
  344. if (temp == 0)
  345. return 0.0;
  346. Rt = 1000.0 * 255.0 / (double)temp - 1000.0;
  347. stein = log(Rt / 2200.0) / 3987.0;
  348. stein += 1.0 / (double)(25.0 + 273.15);
  349. celsius = (1.0 / stein) - 273.15;
  350. // For display of bad data
  351. if (celsius < 0.0)
  352. celsius = 0.0;
  353. if (celsius > 200.0)
  354. celsius = 200.0;
  355. return celsius;
  356. }
  357. static int cvtCToKln(double deg)
  358. {
  359. double Rt, stein, temp;
  360. if (deg < 0.0)
  361. deg = 0.0;
  362. stein = 1.0 / (deg + 273.15);
  363. stein -= 1.0 / (double)(25.0 + 273.15);
  364. Rt = exp(stein * 3987.0) * 2200.0;
  365. if (Rt == -1000.0)
  366. Rt++;
  367. temp = 1000.0 * 256.0 / (Rt + 1000.0);
  368. if (temp > 255)
  369. temp = 255;
  370. if (temp < 0)
  371. temp = 0;
  372. return (int)temp;
  373. }
  374. // Change this to LOG_WARNING if you wish to always see the replies
  375. #define READ_DEBUG LOG_DEBUG
  376. static void display_kline(struct cgpu_info *klncgpu, KLINE *kline, const char *msg)
  377. {
  378. const struct klondike_info * const klninfo = klncgpu->device_data;
  379. switch (kline->hd.cmd) {
  380. case KLN_CMD_NONCE:
  381. applog(READ_DEBUG,
  382. "%s%i:%d %s work [%c] dev=%d workid=%d"
  383. " nonce=0x%08x",
  384. klncgpu->drv->name, klncgpu->device_id,
  385. (int)(kline->wr.dev), msg, kline->wr.cmd,
  386. (int)(kline->wr.dev),
  387. (int)(kline->wr.workid),
  388. (unsigned int)K_NONCE(kline->wr.nonce) + klninfo->nonce_offset);
  389. break;
  390. case KLN_CMD_STATUS:
  391. case KLN_CMD_WORK:
  392. case KLN_CMD_ENABLE:
  393. case KLN_CMD_ABORT:
  394. applog(READ_DEBUG,
  395. "%s%i:%d %s status [%c] dev=%d chips=%d"
  396. " slaves=%d workcq=%d workid=%d temp=%d fan=%d"
  397. " errors=%d hashes=%d max=%d noise=%d",
  398. klncgpu->drv->name, klncgpu->device_id,
  399. (int)(kline->ws.dev), msg, kline->ws.cmd,
  400. (int)(kline->ws.dev),
  401. (int)(kline->ws.chipcount),
  402. (int)(kline->ws.slavecount),
  403. (int)(kline->ws.workqc),
  404. (int)(kline->ws.workid),
  405. (int)(kline->ws.temp),
  406. (int)(kline->ws.fanspeed),
  407. (int)(kline->ws.errorcount),
  408. K_HASHCOUNT(kline->ws.hashcount),
  409. K_MAXCOUNT(kline->ws.maxcount),
  410. (int)(kline->ws.noise));
  411. break;
  412. case KLN_CMD_CONFIG:
  413. applog(READ_DEBUG,
  414. "%s%i:%d %s config [%c] dev=%d clock=%d"
  415. " temptarget=%d tempcrit=%d fan=%d",
  416. klncgpu->drv->name, klncgpu->device_id,
  417. (int)(kline->cfg.dev), msg, kline->cfg.cmd,
  418. (int)(kline->cfg.dev),
  419. K_HASHCLOCK(kline->cfg.hashclock),
  420. (int)(kline->cfg.temptarget),
  421. (int)(kline->cfg.tempcritical),
  422. (int)(kline->cfg.fantarget));
  423. break;
  424. case KLN_CMD_IDENT:
  425. applog(READ_DEBUG,
  426. "%s%i:%d %s info [%c] version=0x%02x prod=%.7s"
  427. " serial=0x%08x",
  428. klncgpu->drv->name, klncgpu->device_id,
  429. (int)(kline->hd.dev), msg, kline->hd.cmd,
  430. (int)(kline->id.version),
  431. kline->id.product,
  432. (unsigned int)K_SERIAL(kline->id.serial));
  433. break;
  434. default:
  435. {
  436. char hexdata[REPLY_SIZE * 2];
  437. bin2hex(hexdata, &kline->hd.dev, REPLY_SIZE - 1);
  438. applog(LOG_ERR,
  439. "%s%i:%d %s [%c:%s] unknown and ignored",
  440. klncgpu->drv->name, klncgpu->device_id,
  441. (int)(kline->hd.dev), msg, kline->hd.cmd,
  442. hexdata);
  443. break;
  444. }
  445. }
  446. }
  447. static void display_send_kline(struct cgpu_info *klncgpu, KLINE *kline, const char *msg)
  448. {
  449. switch (kline->hd.cmd) {
  450. case KLN_CMD_WORK:
  451. applog(READ_DEBUG,
  452. "%s%i:%d %s work [%c] dev=%d workid=0x%02x ...",
  453. klncgpu->drv->name, klncgpu->device_id,
  454. (int)(kline->wt.dev), msg, kline->ws.cmd,
  455. (int)(kline->wt.dev),
  456. (int)(kline->wt.workid));
  457. break;
  458. case KLN_CMD_CONFIG:
  459. applog(READ_DEBUG,
  460. "%s%i:%d %s config [%c] dev=%d clock=%d"
  461. " temptarget=%d tempcrit=%d fan=%d",
  462. klncgpu->drv->name, klncgpu->device_id,
  463. (int)(kline->cfg.dev), msg, kline->cfg.cmd,
  464. (int)(kline->cfg.dev),
  465. K_HASHCLOCK(kline->cfg.hashclock),
  466. (int)(kline->cfg.temptarget),
  467. (int)(kline->cfg.tempcritical),
  468. (int)(kline->cfg.fantarget));
  469. break;
  470. case KLN_CMD_IDENT:
  471. case KLN_CMD_STATUS:
  472. case KLN_CMD_ABORT:
  473. applog(READ_DEBUG,
  474. "%s%i:%d %s cmd [%c]",
  475. klncgpu->drv->name, klncgpu->device_id,
  476. (int)(kline->hd.dev), msg, kline->hd.cmd);
  477. break;
  478. case KLN_CMD_ENABLE:
  479. applog(READ_DEBUG,
  480. "%s%i:%d %s enable [%c] enable=%c",
  481. klncgpu->drv->name, klncgpu->device_id,
  482. (int)(kline->hd.dev), msg, kline->hd.cmd,
  483. (char)(kline->hd.buf[0]));
  484. break;
  485. case KLN_CMD_NONCE:
  486. default:
  487. {
  488. char hexdata[REPLY_SIZE * 2];
  489. bin2hex(hexdata, (unsigned char *)&(kline->hd.dev), REPLY_SIZE - 1);
  490. applog(LOG_ERR,
  491. "%s%i:%d %s [%c:%s] unknown/unexpected and ignored",
  492. klncgpu->drv->name, klncgpu->device_id,
  493. (int)(kline->hd.dev), msg, kline->hd.cmd,
  494. hexdata);
  495. break;
  496. }
  497. }
  498. }
  499. static bool SendCmd(struct cgpu_info *klncgpu, KLINE *kline, int datalen)
  500. {
  501. struct klondike_info * const klninfo = klncgpu->device_data;
  502. int err, amt, writ;
  503. if (klninfo->usbinfo_nodev)
  504. return false;
  505. display_send_kline(klncgpu, kline, msg_send);
  506. writ = KSENDHD(datalen);
  507. err = usb_write(klncgpu, kline, writ, &amt);
  508. if (err < 0 || amt != writ) {
  509. applog(LOG_ERR, "%s%i:%d Cmd:%c Dev:%d, write failed (%d:%d:%d)",
  510. klncgpu->drv->name, klncgpu->device_id,
  511. (int)(kline->hd.dev),
  512. kline->hd.cmd, (int)(kline->hd.dev),
  513. writ, amt, err);
  514. return false;
  515. }
  516. return true;
  517. }
  518. static KLIST *GetReply(struct cgpu_info *klncgpu, uint8_t cmd, uint8_t dev)
  519. {
  520. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  521. KLIST *kitem;
  522. int retries = CMD_REPLY_RETRIES;
  523. while (retries-- > 0 && klncgpu->shutdown == false) {
  524. cgsleep_ms(REPLY_WAIT_TIME);
  525. cg_rlock(&klninfo->klist_lock);
  526. kitem = klninfo->used;
  527. while (kitem) {
  528. if (kitem->kline.hd.cmd == cmd &&
  529. kitem->kline.hd.dev == dev &&
  530. kitem->ready == true && kitem->working == false) {
  531. kitem->working = true;
  532. cg_runlock(&klninfo->klist_lock);
  533. return kitem;
  534. }
  535. kitem = kitem->next;
  536. }
  537. cg_runlock(&klninfo->klist_lock);
  538. }
  539. return NULL;
  540. }
  541. static KLIST *SendCmdGetReply(struct cgpu_info *klncgpu, KLINE *kline, int datalen)
  542. {
  543. if (!SendCmd(klncgpu, kline, datalen))
  544. return NULL;
  545. return GetReply(klncgpu, kline->hd.cmd, kline->hd.dev);
  546. }
  547. static bool klondike_get_stats(struct cgpu_info *klncgpu)
  548. {
  549. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  550. KLIST *kitem;
  551. KLINE kline;
  552. int slaves, dev;
  553. uint8_t temp = 0xFF;
  554. if (klninfo->usbinfo_nodev || klninfo->status == NULL)
  555. return false;
  556. applog(LOG_DEBUG, "%s%i: getting status",
  557. klncgpu->drv->name, klncgpu->device_id);
  558. rd_lock(&(klninfo->stat_lock));
  559. slaves = klninfo->status[0].kline.ws.slavecount;
  560. rd_unlock(&(klninfo->stat_lock));
  561. // loop thru devices and get status for each
  562. for (dev = 0; dev <= slaves; dev++) {
  563. zero_kline(&kline);
  564. kline.hd.cmd = KLN_CMD_STATUS;
  565. kline.hd.dev = dev;
  566. kitem = SendCmdGetReply(klncgpu, &kline, 0);
  567. if (kitem != NULL) {
  568. wr_lock(&(klninfo->stat_lock));
  569. memcpy((void *)(&(klninfo->status[dev])),
  570. (void *)kitem,
  571. sizeof(klninfo->status[dev]));
  572. wr_unlock(&(klninfo->stat_lock));
  573. kitem = release_kitem(klncgpu, kitem);
  574. } else {
  575. applog(LOG_ERR, "%s%i:%d failed to update stats",
  576. klncgpu->drv->name, klncgpu->device_id, dev);
  577. }
  578. if (klninfo->status[dev].kline.ws.temp < temp)
  579. temp = klninfo->status[dev].kline.ws.temp;
  580. }
  581. klncgpu->temp = cvtKlnToC(temp);
  582. return true;
  583. }
  584. // TODO: this only enables the master (no slaves)
  585. static bool kln_enable(struct cgpu_info *klncgpu)
  586. {
  587. KLIST *kitem;
  588. KLINE kline;
  589. int tries = 2;
  590. bool ok = false;
  591. zero_kline(&kline);
  592. kline.hd.cmd = KLN_CMD_ENABLE;
  593. kline.hd.dev = 0;
  594. kline.hd.buf[0] = KLN_CMD_ENABLE_ON;
  595. while (tries-- > 0) {
  596. kitem = SendCmdGetReply(klncgpu, &kline, 1);
  597. if (kitem) {
  598. kitem = release_kitem(klncgpu, kitem);
  599. ok = true;
  600. break;
  601. }
  602. cgsleep_ms(50);
  603. }
  604. if (ok)
  605. cgsleep_ms(50);
  606. return ok;
  607. }
  608. static void kln_disable(struct cgpu_info *klncgpu, int dev, bool all)
  609. {
  610. KLINE kline;
  611. int i;
  612. zero_kline(&kline);
  613. kline.hd.cmd = KLN_CMD_ENABLE;
  614. kline.hd.buf[0] = KLN_CMD_ENABLE_OFF;
  615. for (i = (all ? 0 : dev); i <= dev; i++) {
  616. kline.hd.dev = i;
  617. SendCmd(klncgpu, &kline, KSENDHD(1));
  618. }
  619. }
  620. static bool klondike_init(struct cgpu_info *klncgpu)
  621. {
  622. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  623. KLIST *kitem;
  624. KLINE kline;
  625. int slaves, dev;
  626. klninfo->initialised = false;
  627. cgpu_set_defaults(klncgpu);
  628. zero_kline(&kline);
  629. kline.hd.cmd = KLN_CMD_STATUS;
  630. kline.hd.dev = 0;
  631. kitem = SendCmdGetReply(klncgpu, &kline, 0);
  632. if (kitem == NULL)
  633. return false;
  634. slaves = kitem->kline.ws.slavecount;
  635. if (klninfo->status == NULL) {
  636. applog(LOG_DEBUG, "%s%i: initializing data",
  637. klncgpu->drv->name, klncgpu->device_id);
  638. // alloc space for status, devinfo, cfg and jobque for master and slaves
  639. klninfo->status = calloc(slaves+1, sizeof(*(klninfo->status)));
  640. if (unlikely(!klninfo->status))
  641. quit(1, "Failed to calloc status array in klondke_get_stats");
  642. klninfo->devinfo = calloc(slaves+1, sizeof(*(klninfo->devinfo)));
  643. if (unlikely(!klninfo->devinfo))
  644. quit(1, "Failed to calloc devinfo array in klondke_get_stats");
  645. klninfo->cfg = calloc(slaves+1, sizeof(*(klninfo->cfg)));
  646. if (unlikely(!klninfo->cfg))
  647. quit(1, "Failed to calloc cfg array in klondke_get_stats");
  648. klninfo->jobque = calloc(slaves+1, sizeof(*(klninfo->jobque)));
  649. if (unlikely(!klninfo->jobque))
  650. quit(1, "Failed to calloc jobque array in klondke_get_stats");
  651. }
  652. memcpy((void *)(&(klninfo->status[0])), (void *)kitem, sizeof(klninfo->status[0]));
  653. kitem = release_kitem(klncgpu, kitem);
  654. // zero init triggers read back only
  655. zero_kline(&kline);
  656. kline.cfg.cmd = KLN_CMD_CONFIG;
  657. int size = 2;
  658. // boundaries are checked by device, with valid values returned
  659. {
  660. SET_HASHCLOCK(kline.cfg.hashclock, klninfo->clock);
  661. kline.cfg.temptarget = cvtCToKln(klncgpu->targettemp);
  662. kline.cfg.tempcritical = 0; // hard code for old firmware
  663. kline.cfg.fantarget = 0xff; // hard code for old firmware
  664. size = sizeof(kline.cfg) - 2;
  665. }
  666. for (dev = 0; dev <= slaves; dev++) {
  667. kline.cfg.dev = dev;
  668. kitem = SendCmdGetReply(klncgpu, &kline, size);
  669. if (kitem != NULL) {
  670. memcpy((void *)&(klninfo->cfg[dev]), kitem, sizeof(klninfo->cfg[dev]));
  671. applog(LOG_WARNING, "%s%i:%d config (%d: Clk: %d, T:%.0lf, C:%.0lf, F:%d)",
  672. klncgpu->drv->name, klncgpu->device_id, dev,
  673. dev, K_HASHCLOCK(klninfo->cfg[dev].kline.cfg.hashclock),
  674. cvtKlnToC(klninfo->cfg[dev].kline.cfg.temptarget),
  675. cvtKlnToC(klninfo->cfg[dev].kline.cfg.tempcritical),
  676. (int)100*klninfo->cfg[dev].kline.cfg.fantarget/256);
  677. kitem = release_kitem(klncgpu, kitem);
  678. }
  679. }
  680. klondike_get_stats(klncgpu);
  681. klninfo->initialised = true;
  682. for (dev = 0; dev <= slaves; dev++) {
  683. klninfo->devinfo[dev].rangesize = ((uint64_t)1<<32) / klninfo->status[dev].kline.ws.chipcount;
  684. klninfo->devinfo[dev].chipstats = calloc(klninfo->status[dev].kline.ws.chipcount*2 , sizeof(uint32_t));
  685. }
  686. bool ok = kln_enable(klncgpu);
  687. if (!ok)
  688. applog(LOG_ERR, "%s%i: failed to enable", klncgpu->drv->name, klncgpu->device_id);
  689. return ok;
  690. }
  691. static void control_init(struct cgpu_info *klncgpu)
  692. {
  693. struct klondike_info * const klninfo = klncgpu->device_data;
  694. int err, interface;
  695. if (klninfo->usbinfo_nodev)
  696. return;
  697. interface = 0;
  698. err = libusb_control_transfer(klninfo->usbdev_handle, 0, 9, 1, interface, NULL, 0, 999);
  699. applog(LOG_DEBUG, "%s%i: reset got err %d",
  700. klncgpu->drv->name, klncgpu->device_id, err);
  701. }
  702. static
  703. const char *klondike_set_clock(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  704. {
  705. struct klondike_info * const klninfo = proc->device_data;
  706. if (klninfo->initialised)
  707. return "Cannot change clock after initialisation";
  708. klninfo->clock = atoi(newvalue);
  709. return NULL;
  710. }
  711. static
  712. const char *klondike_set_max_work_count(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  713. {
  714. struct klondike_info * const klninfo = proc->device_data;
  715. klninfo->max_work_count = atoi(newvalue);
  716. return NULL;
  717. }
  718. static
  719. const char *klondike_set_old_work_time(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
  720. {
  721. struct klondike_info * const klninfo = proc->device_data;
  722. klninfo->old_work_ms = atof(newvalue) * 1000.0;
  723. return NULL;
  724. }
  725. static const struct bfg_set_device_definition klondike_set_device_funcs[] = {
  726. {"clock", klondike_set_clock, "clock frequency (can only be set at startup, with --set-device)"},
  727. {"max_work_count", klondike_set_max_work_count, "number of work items to queue on each bus"},
  728. {"old_work_time", klondike_set_old_work_time, "number of seconds to retain work"},
  729. {NULL}
  730. };
  731. static
  732. bool klondike_lowl_match(const struct lowlevel_device_info * const info)
  733. {
  734. if (!lowlevel_match_id(info, &lowl_usb, 0x04d8, 0xf60a))
  735. return false;
  736. return (info->manufacturer && strstr(info->manufacturer, "Klondike"));
  737. }
  738. static
  739. bool klondike_lowl_probe(const struct lowlevel_device_info * const info)
  740. {
  741. if (unlikely(info->lowl != &lowl_usb))
  742. {
  743. applog(LOG_DEBUG, "%s: Matched \"%s\" serial \"%s\", but lowlevel driver is not usb!",
  744. __func__, info->product, info->serial);
  745. return false;
  746. }
  747. struct libusb_device * const dev = info->lowl_data;
  748. if (bfg_claim_libusb(&klondike_drv, true, dev))
  749. return false;
  750. // static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  751. struct cgpu_info * const klncgpu = malloc(sizeof(*klncgpu));
  752. struct klondike_info *klninfo = NULL;
  753. KLINE kline;
  754. if (unlikely(!klncgpu))
  755. quit(1, "Failed to calloc klncgpu in klondike_detect_one");
  756. *klncgpu = (struct cgpu_info){
  757. .drv = &klondike_drv,
  758. .deven = DEV_ENABLED,
  759. .threads = 1,
  760. .targettemp = 50,
  761. .cutofftemp = (int)KLN_KILLWORK_TEMP,
  762. .set_device_funcs = klondike_set_device_funcs,
  763. };
  764. klninfo = calloc(1, sizeof(*klninfo));
  765. if (unlikely(!klninfo))
  766. quit(1, "Failed to calloc klninfo in klondke_detect_one");
  767. klninfo->clock = 282;
  768. klninfo->max_work_count = 4;
  769. klninfo->old_work_ms = 5000;
  770. klncgpu->device_data = (void *)klninfo;
  771. klninfo->free = new_klist_set(klncgpu);
  772. if (usb_init(klncgpu, dev)) {
  773. int sent, recd, err;
  774. KLIST kitem;
  775. int attempts = 0;
  776. klncgpu->device_path = strdup(info->devid);
  777. control_init(klncgpu);
  778. while (attempts++ < 3) {
  779. kline.hd.cmd = KLN_CMD_IDENT;
  780. kline.hd.dev = 0;
  781. display_send_kline(klncgpu, &kline, msg_detect_send);
  782. err = usb_write(klncgpu, (char *)&(kline.hd), 2, &sent);
  783. if (err < 0 || sent != 2) {
  784. applog(LOG_ERR, "%s (%s) detect write failed (%d:%d)",
  785. klncgpu->drv->dname,
  786. klncgpu->device_path,
  787. sent, err);
  788. }
  789. cgsleep_ms(REPLY_WAIT_TIME*10);
  790. err = usb_read(klncgpu, &kitem.kline, REPLY_SIZE, &recd);
  791. if (err < 0) {
  792. applog(LOG_ERR, "%s (%s) detect read failed (%d:%d)",
  793. klncgpu->drv->dname,
  794. klncgpu->device_path,
  795. recd, err);
  796. } else if (recd < 1) {
  797. applog(LOG_ERR, "%s (%s) detect empty reply (%d)",
  798. klncgpu->drv->dname,
  799. klncgpu->device_path,
  800. recd);
  801. } else if (kitem.kline.hd.cmd == KLN_CMD_IDENT && kitem.kline.hd.dev == 0) {
  802. display_kline(klncgpu, &kitem.kline, msg_detect_reply);
  803. applog(LOG_DEBUG, "%s (%s) detect successful (%d attempt%s)",
  804. klncgpu->drv->dname,
  805. klncgpu->device_path,
  806. attempts, attempts == 1 ? "" : "s");
  807. if (!add_cgpu(klncgpu))
  808. break;
  809. applog(LOG_DEBUG, "Klondike cgpu added");
  810. rwlock_init(&klninfo->stat_lock);
  811. cglock_init(&klninfo->klist_lock);
  812. return true;
  813. }
  814. }
  815. usb_uninit(klncgpu);
  816. }
  817. free(klninfo->free);
  818. free(klninfo);
  819. free(klncgpu);
  820. return false;
  821. }
  822. static void klondike_check_nonce(struct cgpu_info *klncgpu, KLIST *kitem)
  823. {
  824. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  825. struct work *work, *look, *tmp;
  826. KLINE *kline = &(kitem->kline);
  827. struct timeval tv_now;
  828. double us_diff;
  829. uint32_t nonce = K_NONCE(kline->wr.nonce) + klninfo->nonce_offset;
  830. applog(LOG_DEBUG, "%s%i:%d FOUND NONCE (%02x:%08x)",
  831. klncgpu->drv->name, klncgpu->device_id, (int)(kline->wr.dev),
  832. kline->wr.workid, (unsigned int)nonce);
  833. work = NULL;
  834. cgtime(&tv_now);
  835. rd_lock(&(klncgpu->qlock));
  836. HASH_ITER(hh, klncgpu->queued_work, look, tmp) {
  837. if (ms_tdiff(&tv_now, &(look->tv_stamp)) < klninfo->old_work_ms &&
  838. (look->subid == (kline->wr.dev*256 + kline->wr.workid))) {
  839. work = look;
  840. break;
  841. }
  842. }
  843. rd_unlock(&(klncgpu->qlock));
  844. if (work) {
  845. if (unlikely(!klninfo->nonce_offset))
  846. {
  847. bool test_c0 = test_nonce(work, nonce - 0xc0, false);
  848. bool test_180 = test_nonce(work, nonce - 0x180, false);
  849. if (test_c0)
  850. {
  851. if (unlikely(test_180))
  852. {
  853. applog(LOG_DEBUG, "%s: Matched both c0 and 180 offsets (%02x:%08lx)",
  854. klncgpu->dev_repr, kline->wr.workid, (unsigned long)nonce);
  855. submit_nonce(klncgpu->thr[0], work, nonce - 0x180);
  856. nonce -= 0xc0;
  857. }
  858. else
  859. {
  860. applog(LOG_DEBUG, "%s: Matched c0 offset (%02x:%08lx)",
  861. klncgpu->dev_repr, kline->wr.workid, (unsigned long)nonce);
  862. nonce += (klninfo->nonce_offset = -0xc0);
  863. }
  864. }
  865. else
  866. if (test_180)
  867. {
  868. applog(LOG_DEBUG, "%s: Matched 180 offset (%02x:%08lx)",
  869. klncgpu->dev_repr, kline->wr.workid, (unsigned long)nonce);
  870. nonce += (klninfo->nonce_offset = -0x180);
  871. }
  872. else
  873. applog(LOG_DEBUG, "%s: Matched neither c0 nor 180 offset (%02x:%08lx)",
  874. klncgpu->dev_repr, kline->wr.workid, (unsigned long)nonce);
  875. }
  876. wr_lock(&(klninfo->stat_lock));
  877. klninfo->devinfo[kline->wr.dev].noncecount++;
  878. klninfo->noncecount++;
  879. wr_unlock(&(klninfo->stat_lock));
  880. applog(LOG_DEBUG, "%s%i:%d SUBMIT NONCE (%02x:%08x)",
  881. klncgpu->drv->name, klncgpu->device_id, (int)(kline->wr.dev),
  882. kline->wr.workid, (unsigned int)nonce);
  883. cgtime(&tv_now);
  884. bool ok = submit_nonce(klncgpu->thr[0], work, nonce);
  885. applog(LOG_DEBUG, "%s%i:%d chip stats %d, %08x, %d, %d",
  886. klncgpu->drv->name, klncgpu->device_id, (int)(kline->wr.dev),
  887. kline->wr.dev, (unsigned int)nonce,
  888. klninfo->devinfo[kline->wr.dev].rangesize,
  889. klninfo->status[kline->wr.dev].kline.ws.chipcount);
  890. klninfo->devinfo[kline->wr.dev].chipstats[(nonce / klninfo->devinfo[kline->wr.dev].rangesize) + (ok ? 0 : klninfo->status[kline->wr.dev].kline.ws.chipcount)]++;
  891. us_diff = us_tdiff(&tv_now, &(kitem->tv_when));
  892. if (klninfo->delay_count == 0) {
  893. klninfo->delay_min = us_diff;
  894. klninfo->delay_max = us_diff;
  895. } else {
  896. if (klninfo->delay_min > us_diff)
  897. klninfo->delay_min = us_diff;
  898. if (klninfo->delay_max < us_diff)
  899. klninfo->delay_max = us_diff;
  900. }
  901. klninfo->delay_count++;
  902. klninfo->delay_total += us_diff;
  903. if (klninfo->nonce_count > 0) {
  904. us_diff = us_tdiff(&(kitem->tv_when), &(klninfo->tv_last_nonce_received));
  905. if (klninfo->nonce_count == 1) {
  906. klninfo->nonce_min = us_diff;
  907. klninfo->nonce_max = us_diff;
  908. } else {
  909. if (klninfo->nonce_min > us_diff)
  910. klninfo->nonce_min = us_diff;
  911. if (klninfo->nonce_max < us_diff)
  912. klninfo->nonce_max = us_diff;
  913. }
  914. klninfo->nonce_total += us_diff;
  915. }
  916. klninfo->nonce_count++;
  917. memcpy(&(klninfo->tv_last_nonce_received), &(kitem->tv_when),
  918. sizeof(klninfo->tv_last_nonce_received));
  919. return;
  920. }
  921. applog(LOG_ERR, "%s%i:%d unknown work (%02x:%08x) - ignored",
  922. klncgpu->drv->name, klncgpu->device_id, (int)(kline->wr.dev),
  923. kline->wr.workid, (unsigned int)nonce);
  924. inc_hw_errors2(klncgpu->thr[0], NULL, &nonce);
  925. }
  926. // thread to keep looking for replies
  927. static void *klondike_get_replies(void *userdata)
  928. {
  929. struct cgpu_info *klncgpu = (struct cgpu_info *)userdata;
  930. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  931. KLIST *kitem = NULL;
  932. int err, recd, slaves, dev, isc;
  933. bool overheat, sent;
  934. applog(LOG_DEBUG, "%s%i: listening for replies",
  935. klncgpu->drv->name, klncgpu->device_id);
  936. while (klncgpu->shutdown == false) {
  937. if (klninfo->usbinfo_nodev)
  938. return NULL;
  939. if (kitem == NULL)
  940. kitem = allocate_kitem(klncgpu);
  941. else
  942. memset((void *)&(kitem->kline), 0, sizeof(kitem->kline));
  943. err = usb_read(klncgpu, &kitem->kline, REPLY_SIZE, &recd);
  944. if (err || recd != REPLY_SIZE) {
  945. if (err != -7)
  946. applog(LOG_ERR, "%s%i: reply err=%d amt=%d",
  947. klncgpu->drv->name, klncgpu->device_id,
  948. err, recd);
  949. }
  950. if (!err && recd == REPLY_SIZE) {
  951. cgtime(&(kitem->tv_when));
  952. rd_lock(&(klninfo->stat_lock));
  953. kitem->block_seq = klninfo->block_seq;
  954. rd_unlock(&(klninfo->stat_lock));
  955. if (opt_log_level <= READ_DEBUG) {
  956. char hexdata[recd * 2];
  957. bin2hex(hexdata, &kitem->kline.hd.dev, recd-1);
  958. applog(READ_DEBUG, "%s%i:%d reply [%c:%s]",
  959. klncgpu->drv->name, klncgpu->device_id,
  960. (int)(kitem->kline.hd.dev),
  961. kitem->kline.hd.cmd, hexdata);
  962. }
  963. // We can't check this until it's initialised
  964. if (klninfo->initialised) {
  965. rd_lock(&(klninfo->stat_lock));
  966. slaves = klninfo->status[0].kline.ws.slavecount;
  967. rd_unlock(&(klninfo->stat_lock));
  968. if (kitem->kline.hd.dev > slaves) {
  969. applog(LOG_ERR, "%s%i: reply [%c] has invalid dev=%d (max=%d) using 0",
  970. klncgpu->drv->name, klncgpu->device_id,
  971. (char)(kitem->kline.hd.cmd),
  972. (int)(kitem->kline.hd.dev),
  973. slaves);
  974. /* TODO: this is rather problematic if there are slaves
  975. * however without slaves - it should always be zero */
  976. kitem->kline.hd.dev = 0;
  977. } else {
  978. wr_lock(&(klninfo->stat_lock));
  979. klninfo->jobque[kitem->kline.hd.dev].late_update_sequential = 0;
  980. wr_unlock(&(klninfo->stat_lock));
  981. }
  982. }
  983. switch (kitem->kline.hd.cmd) {
  984. case KLN_CMD_NONCE:
  985. klondike_check_nonce(klncgpu, kitem);
  986. display_kline(klncgpu, &kitem->kline, msg_reply);
  987. break;
  988. case KLN_CMD_WORK:
  989. // We can't do/check this until it's initialised
  990. if (klninfo->initialised) {
  991. dev = kitem->kline.ws.dev;
  992. if (kitem->kline.ws.workqc == 0) {
  993. bool idle = false;
  994. rd_lock(&(klninfo->stat_lock));
  995. if (klninfo->jobque[dev].flushed == false)
  996. idle = true;
  997. slaves = klninfo->status[0].kline.ws.slavecount;
  998. rd_unlock(&(klninfo->stat_lock));
  999. if (idle)
  1000. applog(LOG_WARNING, "%s%i:%d went idle before work was sent",
  1001. klncgpu->drv->name,
  1002. klncgpu->device_id,
  1003. dev);
  1004. }
  1005. wr_lock(&(klninfo->stat_lock));
  1006. klninfo->jobque[dev].flushed = false;
  1007. wr_unlock(&(klninfo->stat_lock));
  1008. }
  1009. case KLN_CMD_STATUS:
  1010. case KLN_CMD_ABORT:
  1011. // We can't do/check this until it's initialised
  1012. if (klninfo->initialised) {
  1013. isc = 0;
  1014. dev = kitem->kline.ws.dev;
  1015. wr_lock(&(klninfo->stat_lock));
  1016. klninfo->jobque[dev].workqc = (int)(kitem->kline.ws.workqc);
  1017. cgtime(&(klninfo->jobque[dev].last_update));
  1018. slaves = klninfo->status[0].kline.ws.slavecount;
  1019. overheat = klninfo->jobque[dev].overheat;
  1020. if (dev == 0) {
  1021. if (kitem->kline.ws.slavecount != slaves)
  1022. isc = ++klninfo->incorrect_slave_sequential;
  1023. else
  1024. isc = klninfo->incorrect_slave_sequential = 0;
  1025. }
  1026. wr_unlock(&(klninfo->stat_lock));
  1027. if (isc) {
  1028. applog(LOG_ERR, "%s%i:%d reply [%c] has a diff"
  1029. " # of slaves=%d (curr=%d)%s",
  1030. klncgpu->drv->name,
  1031. klncgpu->device_id,
  1032. dev,
  1033. (char)(kitem->kline.ws.cmd),
  1034. (int)(kitem->kline.ws.slavecount),
  1035. slaves,
  1036. isc <= KLN_ISS_IGNORE ? "" :
  1037. " disabling device");
  1038. if (isc > KLN_ISS_IGNORE)
  1039. usb_nodev(klncgpu);
  1040. break;
  1041. }
  1042. if (!overheat) {
  1043. double temp = cvtKlnToC(kitem->kline.ws.temp);
  1044. if (temp >= KLN_KILLWORK_TEMP) {
  1045. KLINE kline;
  1046. wr_lock(&(klninfo->stat_lock));
  1047. klninfo->jobque[dev].overheat = true;
  1048. wr_unlock(&(klninfo->stat_lock));
  1049. applog(LOG_WARNING, "%s%i:%d Critical overheat (%.0fC)",
  1050. klncgpu->drv->name,
  1051. klncgpu->device_id,
  1052. dev, temp);
  1053. zero_kline(&kline);
  1054. kline.hd.cmd = KLN_CMD_ABORT;
  1055. kline.hd.dev = dev;
  1056. sent = SendCmd(klncgpu, &kline, KSENDHD(0));
  1057. kln_disable(klncgpu, dev, false);
  1058. if (!sent) {
  1059. applog(LOG_ERR, "%s%i:%d overheat failed to"
  1060. " abort work - disabling device",
  1061. klncgpu->drv->name,
  1062. klncgpu->device_id,
  1063. dev);
  1064. usb_nodev(klncgpu);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. case KLN_CMD_ENABLE:
  1070. wr_lock(&(klninfo->stat_lock));
  1071. klninfo->errorcount += kitem->kline.ws.errorcount;
  1072. klninfo->noisecount += kitem->kline.ws.noise;
  1073. wr_unlock(&(klninfo->stat_lock));
  1074. display_kline(klncgpu, &kitem->kline, msg_reply);
  1075. kitem->ready = true;
  1076. kitem = NULL;
  1077. break;
  1078. case KLN_CMD_CONFIG:
  1079. display_kline(klncgpu, &kitem->kline, msg_reply);
  1080. kitem->ready = true;
  1081. kitem = NULL;
  1082. break;
  1083. case KLN_CMD_IDENT:
  1084. display_kline(klncgpu, &kitem->kline, msg_reply);
  1085. kitem->ready = true;
  1086. kitem = NULL;
  1087. break;
  1088. default:
  1089. display_kline(klncgpu, &kitem->kline, msg_reply);
  1090. break;
  1091. }
  1092. }
  1093. }
  1094. return NULL;
  1095. }
  1096. static void klondike_flush_work(struct cgpu_info *klncgpu)
  1097. {
  1098. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1099. KLIST *kitem;
  1100. KLINE kline;
  1101. int slaves, dev;
  1102. if (klninfo->initialised) {
  1103. wr_lock(&(klninfo->stat_lock));
  1104. klninfo->block_seq++;
  1105. slaves = klninfo->status[0].kline.ws.slavecount;
  1106. wr_unlock(&(klninfo->stat_lock));
  1107. applog(LOG_DEBUG, "%s%i: flushing work",
  1108. klncgpu->drv->name, klncgpu->device_id);
  1109. zero_kline(&kline);
  1110. kline.hd.cmd = KLN_CMD_ABORT;
  1111. for (dev = 0; dev <= slaves; dev++) {
  1112. kline.hd.dev = dev;
  1113. kitem = SendCmdGetReply(klncgpu, &kline, KSENDHD(0));
  1114. if (kitem != NULL) {
  1115. wr_lock(&(klninfo->stat_lock));
  1116. memcpy((void *)&(klninfo->status[dev]),
  1117. kitem,
  1118. sizeof(klninfo->status[dev]));
  1119. klninfo->jobque[dev].flushed = true;
  1120. wr_unlock(&(klninfo->stat_lock));
  1121. kitem = release_kitem(klncgpu, kitem);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. static bool klondike_thread_prepare(struct thr_info *thr)
  1127. {
  1128. struct cgpu_info *klncgpu = thr->cgpu;
  1129. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1130. if (thr_info_create(&(klninfo->replies_thr), NULL, klondike_get_replies, (void *)klncgpu)) {
  1131. applog(LOG_ERR, "%s%i: thread create failed", klncgpu->drv->name, klncgpu->device_id);
  1132. return false;
  1133. }
  1134. pthread_detach(klninfo->replies_thr.pth);
  1135. // let the listening get started
  1136. cgsleep_ms(100);
  1137. return klondike_init(klncgpu);
  1138. }
  1139. static bool klondike_thread_init(struct thr_info *thr)
  1140. {
  1141. struct cgpu_info *klncgpu = thr->cgpu;
  1142. struct klondike_info * const klninfo = klncgpu->device_data;
  1143. notifier_init(thr->work_restart_notifier);
  1144. if (klninfo->usbinfo_nodev)
  1145. return false;
  1146. klondike_flush_work(klncgpu);
  1147. return true;
  1148. }
  1149. static void klondike_shutdown(struct thr_info *thr)
  1150. {
  1151. struct cgpu_info *klncgpu = thr->cgpu;
  1152. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1153. applog(LOG_DEBUG, "%s%i: shutting down work",
  1154. klncgpu->drv->name, klncgpu->device_id);
  1155. kln_disable(klncgpu, klninfo->status[0].kline.ws.slavecount, true);
  1156. klncgpu->shutdown = true;
  1157. }
  1158. static void klondike_thread_enable(struct thr_info *thr)
  1159. {
  1160. struct cgpu_info *klncgpu = thr->cgpu;
  1161. struct klondike_info * const klninfo = klncgpu->device_data;
  1162. if (klninfo->usbinfo_nodev)
  1163. return;
  1164. /*
  1165. KLINE kline;
  1166. zero_kline(&kline);
  1167. kline.hd.cmd = KLN_CMD_ENABLE;
  1168. kline.hd.dev = dev;
  1169. kline.hd.buf[0] = KLN_CMD_ENABLE_OFF;
  1170. kitem = SendCmdGetReply(klncgpu, &kline, KSENDHD(1));
  1171. */
  1172. }
  1173. static bool klondike_send_work(struct cgpu_info *klncgpu, int dev, struct work *work)
  1174. {
  1175. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1176. struct work *look, *tmp;
  1177. KLINE kline;
  1178. struct timeval tv_old;
  1179. int wque_size, wque_cleared;
  1180. if (klninfo->usbinfo_nodev)
  1181. return false;
  1182. zero_kline(&kline);
  1183. kline.wt.cmd = KLN_CMD_WORK;
  1184. kline.wt.dev = dev;
  1185. memcpy(kline.wt.midstate, work->midstate, MIDSTATE_BYTES);
  1186. memcpy(kline.wt.merkle, work->data + MERKLE_OFFSET, MERKLE_BYTES);
  1187. kline.wt.workid = (uint8_t)(klninfo->devinfo[dev].nextworkid++ & 0xFF);
  1188. work->subid = dev*256 + kline.wt.workid;
  1189. cgtime(&work->tv_stamp);
  1190. if (opt_log_level <= LOG_DEBUG) {
  1191. char hexdata[(sizeof(kline.wt) * 2) + 1];
  1192. bin2hex(hexdata, &kline.wt, sizeof(kline.wt));
  1193. applog(LOG_DEBUG, "WORKDATA: %s", hexdata);
  1194. }
  1195. applog(LOG_DEBUG, "%s%i:%d sending work (%d:%02x)",
  1196. klncgpu->drv->name, klncgpu->device_id, dev,
  1197. dev, kline.wt.workid);
  1198. KLIST *kitem = SendCmdGetReply(klncgpu, &kline, sizeof(kline.wt));
  1199. if (kitem != NULL) {
  1200. wr_lock(&(klninfo->stat_lock));
  1201. memcpy((void *)&(klninfo->status[dev]), kitem, sizeof(klninfo->status[dev]));
  1202. wr_unlock(&(klninfo->stat_lock));
  1203. kitem = release_kitem(klncgpu, kitem);
  1204. // remove old work
  1205. wque_size = 0;
  1206. wque_cleared = 0;
  1207. cgtime(&tv_old);
  1208. wr_lock(&klncgpu->qlock);
  1209. HASH_ITER(hh, klncgpu->queued_work, look, tmp) {
  1210. if (ms_tdiff(&tv_old, &(look->tv_stamp)) > klninfo->old_work_ms) {
  1211. __work_completed(klncgpu, look);
  1212. free_work(look);
  1213. wque_cleared++;
  1214. } else
  1215. wque_size++;
  1216. }
  1217. wr_unlock(&klncgpu->qlock);
  1218. wr_lock(&(klninfo->stat_lock));
  1219. klninfo->wque_size = wque_size;
  1220. klninfo->wque_cleared = wque_cleared;
  1221. wr_unlock(&(klninfo->stat_lock));
  1222. return true;
  1223. }
  1224. return false;
  1225. }
  1226. static bool klondike_queue_full(struct cgpu_info *klncgpu)
  1227. {
  1228. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1229. struct work *work = NULL;
  1230. int dev, queued, slaves, seq, howlong;
  1231. struct timeval now;
  1232. bool nowork;
  1233. if (klncgpu->shutdown == true)
  1234. return true;
  1235. cgtime(&now);
  1236. rd_lock(&(klninfo->stat_lock));
  1237. slaves = klninfo->status[0].kline.ws.slavecount;
  1238. for (dev = 0; dev <= slaves; dev++)
  1239. if (ms_tdiff(&now, &(klninfo->jobque[dev].last_update)) > LATE_UPDATE_MS) {
  1240. klninfo->jobque[dev].late_update_count++;
  1241. seq = ++klninfo->jobque[dev].late_update_sequential;
  1242. rd_unlock(&(klninfo->stat_lock));
  1243. if (seq < LATE_UPDATE_LIMIT) {
  1244. applog(LOG_DEBUG, "%s%i:%d late update",
  1245. klncgpu->drv->name, klncgpu->device_id, dev);
  1246. klondike_get_stats(klncgpu);
  1247. goto que;
  1248. } else {
  1249. applog(LOG_WARNING, "%s%i:%d late update (%d) reached - attempting reset",
  1250. klncgpu->drv->name, klncgpu->device_id,
  1251. dev, LATE_UPDATE_LIMIT);
  1252. control_init(klncgpu);
  1253. kln_enable(klncgpu);
  1254. klondike_get_stats(klncgpu);
  1255. rd_lock(&(klninfo->stat_lock));
  1256. howlong = ms_tdiff(&now, &(klninfo->jobque[dev].last_update));
  1257. if (howlong > LATE_UPDATE_MS) {
  1258. rd_unlock(&(klninfo->stat_lock));
  1259. if (howlong > LATE_UPDATE_NODEV_MS) {
  1260. applog(LOG_ERR, "%s%i:%d reset failed - dropping device",
  1261. klncgpu->drv->name, klncgpu->device_id, dev);
  1262. usb_nodev(klncgpu);
  1263. } else
  1264. cgsleep_ms(LATE_UPDATE_SLEEP_MS);
  1265. return true;
  1266. }
  1267. break;
  1268. }
  1269. }
  1270. rd_unlock(&(klninfo->stat_lock));
  1271. que:
  1272. nowork = true;
  1273. for (queued = 0; queued < klninfo->max_work_count - 1; ++queued)
  1274. for (dev = 0; dev <= slaves; dev++) {
  1275. tryagain:
  1276. rd_lock(&(klninfo->stat_lock));
  1277. if (klninfo->jobque[dev].overheat) {
  1278. double temp = cvtKlnToC(klninfo->status[0].kline.ws.temp);
  1279. if ((queued == klninfo->max_work_count - 2) &&
  1280. ms_tdiff(&now, &(klninfo->jobque[dev].last_update)) > (LATE_UPDATE_MS/2)) {
  1281. rd_unlock(&(klninfo->stat_lock));
  1282. klondike_get_stats(klncgpu);
  1283. goto tryagain;
  1284. }
  1285. if (temp <= KLN_COOLED_DOWN) {
  1286. klninfo->jobque[dev].overheat = false;
  1287. rd_unlock(&(klninfo->stat_lock));
  1288. applog(LOG_WARNING, "%s%i:%d Overheat recovered (%.0fC)",
  1289. klncgpu->drv->name, klncgpu->device_id,
  1290. dev, temp);
  1291. kln_enable(klncgpu);
  1292. goto tryagain;
  1293. } else {
  1294. rd_unlock(&(klninfo->stat_lock));
  1295. continue;
  1296. }
  1297. }
  1298. if (klninfo->jobque[dev].workqc <= queued) {
  1299. rd_unlock(&(klninfo->stat_lock));
  1300. if (!work)
  1301. work = get_queued(klncgpu);
  1302. if (unlikely(!work))
  1303. return false;
  1304. nowork = false;
  1305. if (klondike_send_work(klncgpu, dev, work))
  1306. return false;
  1307. } else
  1308. rd_unlock(&(klninfo->stat_lock));
  1309. }
  1310. if (nowork)
  1311. cgsleep_ms(10); // avoid a hard loop in case we have nothing to do
  1312. return true;
  1313. }
  1314. static int64_t klondike_scanwork(struct thr_info *thr)
  1315. {
  1316. struct cgpu_info *klncgpu = thr->cgpu;
  1317. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1318. int64_t newhashcount = 0;
  1319. int dev, slaves;
  1320. if (klninfo->usbinfo_nodev)
  1321. return -1;
  1322. restart_wait(thr, 200);
  1323. if (klninfo->status != NULL) {
  1324. rd_lock(&(klninfo->stat_lock));
  1325. slaves = klninfo->status[0].kline.ws.slavecount;
  1326. for (dev = 0; dev <= slaves; dev++) {
  1327. uint64_t newhashdev = 0, hashcount;
  1328. int maxcount;
  1329. hashcount = K_HASHCOUNT(klninfo->status[dev].kline.ws.hashcount);
  1330. maxcount = K_MAXCOUNT(klninfo->status[dev].kline.ws.maxcount);
  1331. // todo: chg this to check workid for wrapped instead
  1332. if (klninfo->devinfo[dev].lasthashcount > hashcount)
  1333. newhashdev += maxcount; // hash counter wrapped
  1334. newhashdev += hashcount - klninfo->devinfo[dev].lasthashcount;
  1335. klninfo->devinfo[dev].lasthashcount = hashcount;
  1336. if (maxcount != 0)
  1337. klninfo->hashcount += (newhashdev << 32) / maxcount;
  1338. }
  1339. newhashcount += 0xffffffffull * (uint64_t)klninfo->noncecount;
  1340. klninfo->noncecount = 0;
  1341. rd_unlock(&(klninfo->stat_lock));
  1342. }
  1343. return newhashcount;
  1344. }
  1345. #ifdef HAVE_CURSES
  1346. static
  1347. void klondike_wlogprint_status(struct cgpu_info *klncgpu)
  1348. {
  1349. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1350. uint16_t fan = 0;
  1351. uint16_t clock = 0;
  1352. int dev, slaves;
  1353. if (klninfo->status == NULL) {
  1354. return;
  1355. }
  1356. rd_lock(&(klninfo->stat_lock));
  1357. slaves = klninfo->status[0].kline.ws.slavecount;
  1358. for (dev = 0; dev <= slaves; dev++) {
  1359. fan += klninfo->cfg[dev].kline.cfg.fantarget;
  1360. clock += (uint16_t)K_HASHCLOCK(klninfo->cfg[dev].kline.cfg.hashclock);
  1361. }
  1362. rd_unlock(&(klninfo->stat_lock));
  1363. fan /= slaves + 1;
  1364. fan = 100 * fan / 255;
  1365. clock /= slaves + 1;
  1366. wlogprint("Frequency: %d MHz\n", (int)clock);
  1367. if (fan && fan <= 100)
  1368. wlogprint("Fan speed: %d%%\n", fan);
  1369. }
  1370. #endif
  1371. static struct api_data *klondike_api_stats(struct cgpu_info *klncgpu)
  1372. {
  1373. struct klondike_info *klninfo = (struct klondike_info *)(klncgpu->device_data);
  1374. struct api_data *root = NULL;
  1375. char buf[32];
  1376. int dev, slaves;
  1377. if (klninfo->status == NULL)
  1378. return NULL;
  1379. rd_lock(&(klninfo->stat_lock));
  1380. slaves = klninfo->status[0].kline.ws.slavecount;
  1381. for (dev = 0; dev <= slaves; dev++) {
  1382. float fTemp = cvtKlnToC(klninfo->status[dev].kline.ws.temp);
  1383. sprintf(buf, "Temp %d", dev);
  1384. root = api_add_temp(root, buf, &fTemp, true);
  1385. double dClk = (double)K_HASHCLOCK(klninfo->cfg[dev].kline.cfg.hashclock);
  1386. sprintf(buf, "Clock %d", dev);
  1387. root = api_add_freq(root, buf, &dClk, true);
  1388. unsigned int iFan = (unsigned int)100 * klninfo->cfg[dev].kline.cfg.fantarget / 255;
  1389. sprintf(buf, "Fan Percent %d", dev);
  1390. root = api_add_int(root, buf, (int *)(&iFan), true);
  1391. iFan = 0;
  1392. if (klninfo->status[dev].kline.ws.fanspeed > 0)
  1393. iFan = (unsigned int)TACH_FACTOR / klninfo->status[dev].kline.ws.fanspeed;
  1394. sprintf(buf, "Fan RPM %d", dev);
  1395. root = api_add_int(root, buf, (int *)(&iFan), true);
  1396. if (klninfo->devinfo[dev].chipstats != NULL) {
  1397. char data[2048];
  1398. char one[32];
  1399. int n;
  1400. sprintf(buf, "Nonces / Chip %d", dev);
  1401. data[0] = '\0';
  1402. for (n = 0; n < klninfo->status[dev].kline.ws.chipcount; n++) {
  1403. snprintf(one, sizeof(one), "%07d ", klninfo->devinfo[dev].chipstats[n]);
  1404. strcat(data, one);
  1405. }
  1406. root = api_add_string(root, buf, data, true);
  1407. sprintf(buf, "Errors / Chip %d", dev);
  1408. data[0] = '\0';
  1409. for (n = 0; n < klninfo->status[dev].kline.ws.chipcount; n++) {
  1410. snprintf(one, sizeof(one), "%07d ", klninfo->devinfo[dev].chipstats[n + klninfo->status[dev].kline.ws.chipcount]);
  1411. strcat(data, one);
  1412. }
  1413. root = api_add_string(root, buf, data, true);
  1414. }
  1415. }
  1416. root = api_add_uint64(root, "Hash Count", &(klninfo->hashcount), true);
  1417. root = api_add_uint64(root, "Error Count", &(klninfo->errorcount), true);
  1418. root = api_add_uint64(root, "Noise Count", &(klninfo->noisecount), true);
  1419. root = api_add_int(root, "KLine Limit", &(klninfo->kline_count), true);
  1420. root = api_add_int(root, "KLine Used", &(klninfo->used_count), true);
  1421. root = api_add_elapsed(root, "KQue Delay Count", &(klninfo->delay_count), true);
  1422. root = api_add_elapsed(root, "KQue Delay Total", &(klninfo->delay_total), true);
  1423. root = api_add_elapsed(root, "KQue Delay Min", &(klninfo->delay_min), true);
  1424. root = api_add_elapsed(root, "KQue Delay Max", &(klninfo->delay_max), true);
  1425. double avg;
  1426. if (klninfo->delay_count == 0)
  1427. avg = 0;
  1428. else
  1429. avg = klninfo->delay_total / klninfo->delay_count;
  1430. root = api_add_diff(root, "KQue Delay Avg", &avg, true);
  1431. root = api_add_elapsed(root, "KQue Nonce Count", &(klninfo->nonce_count), true);
  1432. root = api_add_elapsed(root, "KQue Nonce Total", &(klninfo->nonce_total), true);
  1433. root = api_add_elapsed(root, "KQue Nonce Min", &(klninfo->nonce_min), true);
  1434. root = api_add_elapsed(root, "KQue Nonce Max", &(klninfo->nonce_max), true);
  1435. if (klninfo->nonce_count == 0)
  1436. avg = 0;
  1437. else
  1438. avg = klninfo->nonce_total / klninfo->nonce_count;
  1439. root = api_add_diff(root, "KQue Nonce Avg", &avg, true);
  1440. root = api_add_int(root, "WQue Size", &(klninfo->wque_size), true);
  1441. root = api_add_int(root, "WQue Cleared", &(klninfo->wque_cleared), true);
  1442. rd_unlock(&(klninfo->stat_lock));
  1443. return root;
  1444. }
  1445. struct device_drv klondike_drv = {
  1446. .dname = "Klondike",
  1447. .name = "KLN",
  1448. .lowl_match = klondike_lowl_match,
  1449. .lowl_probe = klondike_lowl_probe,
  1450. .get_api_stats = klondike_api_stats,
  1451. .get_stats = klondike_get_stats,
  1452. .thread_prepare = klondike_thread_prepare,
  1453. .thread_init = klondike_thread_init,
  1454. .minerloop = hash_queued_work,
  1455. .scanwork = klondike_scanwork,
  1456. .queue_full = klondike_queue_full,
  1457. .flush_work = klondike_flush_work,
  1458. .thread_shutdown = klondike_shutdown,
  1459. .thread_enable = klondike_thread_enable,
  1460. #ifdef HAVE_CURSES
  1461. .proc_wlogprint_status = klondike_wlogprint_status,
  1462. #endif
  1463. };