miner.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include "config.h"
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <sys/time.h>
  7. #include <pthread.h>
  8. #include <jansson.h>
  9. #include <curl/curl.h>
  10. #include "elist.h"
  11. #include "uthash.h"
  12. #include "logging.h"
  13. #ifdef HAVE_OPENCL
  14. #include "CL/cl.h"
  15. #endif /* HAVE_OPENCL */
  16. #ifdef STDC_HEADERS
  17. # include <stdlib.h>
  18. # include <stddef.h>
  19. #else
  20. # ifdef HAVE_STDLIB_H
  21. # include <stdlib.h>
  22. # endif
  23. #endif
  24. #ifdef HAVE_ALLOCA_H
  25. # include <alloca.h>
  26. #elif defined __GNUC__
  27. # ifndef WIN32
  28. # define alloca __builtin_alloca
  29. # else
  30. # include <malloc.h>
  31. # endif
  32. #elif defined _AIX
  33. # define alloca __alloca
  34. #elif defined _MSC_VER
  35. # include <malloc.h>
  36. # define alloca _alloca
  37. #else
  38. # ifndef HAVE_ALLOCA
  39. # ifdef __cplusplus
  40. extern "C"
  41. # endif
  42. void *alloca (size_t);
  43. # endif
  44. #endif
  45. #if defined (__linux)
  46. #ifndef LINUX
  47. #define LINUX
  48. #endif
  49. #endif
  50. #ifdef WIN32
  51. #ifndef timersub
  52. #define timersub(a, b, result) \
  53. do { \
  54. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  55. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  56. if ((result)->tv_usec < 0) { \
  57. --(result)->tv_sec; \
  58. (result)->tv_usec += 1000000; \
  59. } \
  60. } while (0)
  61. #endif
  62. #ifndef timeradd
  63. # define timeradd(a, b, result) \
  64. do { \
  65. (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
  66. (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
  67. if ((result)->tv_usec >= 1000000) \
  68. { \
  69. ++(result)->tv_sec; \
  70. (result)->tv_usec -= 1000000; \
  71. } \
  72. } while (0)
  73. #endif
  74. #endif
  75. #ifdef HAVE_ADL
  76. #include "ADL_SDK/adl_sdk.h"
  77. #endif
  78. #ifdef HAVE_LIBUSB
  79. #include <libusb-1.0/libusb.h>
  80. #endif
  81. #ifdef USE_ZTEX
  82. #include "libztex.h"
  83. #endif
  84. #if !defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  85. #define bswap_16 __builtin_bswap16
  86. #define bswap_32 __builtin_bswap32
  87. #define bswap_64 __builtin_bswap64
  88. #else
  89. #if HAVE_BYTESWAP_H
  90. #include <byteswap.h>
  91. #elif defined(USE_SYS_ENDIAN_H)
  92. #include <sys/endian.h>
  93. #elif defined(__APPLE__)
  94. #include <libkern/OSByteOrder.h>
  95. #define bswap_16 OSSwapInt16
  96. #define bswap_32 OSSwapInt32
  97. #define bswap_64 OSSwapInt64
  98. #else
  99. #define bswap_16(value) \
  100. ((((value) & 0xff) << 8) | ((value) >> 8))
  101. #define bswap_32(value) \
  102. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  103. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  104. #define bswap_64(value) \
  105. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  106. << 32) | \
  107. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  108. #endif
  109. #endif /* !defined(__GLXBYTEORDER_H__) */
  110. /* This assumes htobe32 is a macro in endian.h */
  111. #ifndef htobe32
  112. # if __BYTE_ORDER == __LITTLE_ENDIAN
  113. # define be32toh(x) bswap_32(x)
  114. # define htobe32(x) bswap_32(x)
  115. # elif __BYTE_ORDER == __BIG_ENDIAN
  116. # define be32toh(x) (x)
  117. # define htobe32(x) (x)
  118. #else
  119. #error UNKNOWN BYTE ORDER
  120. #endif
  121. #endif
  122. #undef unlikely
  123. #undef likely
  124. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  125. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  126. #define likely(expr) (__builtin_expect(!!(expr), 1))
  127. #else
  128. #define unlikely(expr) (expr)
  129. #define likely(expr) (expr)
  130. #endif
  131. #define __maybe_unused __attribute__((unused))
  132. #define uninitialised_var(x) x = x
  133. #if defined(__i386__)
  134. #define WANT_CRYPTOPP_ASM32
  135. #endif
  136. #ifndef ARRAY_SIZE
  137. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  138. #endif
  139. enum alive {
  140. LIFE_WELL,
  141. LIFE_SICK,
  142. LIFE_DEAD,
  143. LIFE_NOSTART,
  144. LIFE_INIT,
  145. LIFE_WAIT,
  146. };
  147. enum pool_strategy {
  148. POOL_FAILOVER,
  149. POOL_ROUNDROBIN,
  150. POOL_ROTATE,
  151. POOL_LOADBALANCE,
  152. };
  153. #define TOP_STRATEGY (POOL_LOADBALANCE)
  154. struct strategies {
  155. const char *s;
  156. };
  157. struct cgpu_info;
  158. #ifdef HAVE_ADL
  159. struct gpu_adl {
  160. ADLTemperature lpTemperature;
  161. int iAdapterIndex;
  162. int lpAdapterID;
  163. int iBusNumber;
  164. char strAdapterName[256];
  165. ADLPMActivity lpActivity;
  166. ADLODParameters lpOdParameters;
  167. ADLODPerformanceLevels *DefPerfLev;
  168. ADLFanSpeedInfo lpFanSpeedInfo;
  169. ADLFanSpeedValue lpFanSpeedValue;
  170. ADLFanSpeedValue DefFanSpeedValue;
  171. int iEngineClock;
  172. int iMemoryClock;
  173. int iVddc;
  174. int iPercentage;
  175. bool autofan;
  176. bool autoengine;
  177. bool managed; /* Were the values ever changed on this card */
  178. int lastengine;
  179. int lasttemp;
  180. int targetfan;
  181. int targettemp;
  182. int overtemp;
  183. int minspeed;
  184. int maxspeed;
  185. int gpu;
  186. bool has_fanspeed;
  187. struct gpu_adl *twin;
  188. };
  189. #endif
  190. struct api_data;
  191. struct thr_info;
  192. struct work;
  193. struct device_api {
  194. const char*dname;
  195. const char*name;
  196. // API-global functions
  197. void (*api_detect)();
  198. // Device-specific functions
  199. void (*reinit_device)(struct cgpu_info*);
  200. void (*get_statline_before)(char*, struct cgpu_info*);
  201. void (*get_statline)(char*, struct cgpu_info*);
  202. struct api_data* (*get_api_extra_device_detail)(struct cgpu_info*);
  203. struct api_data* (*get_api_extra_device_status)(struct cgpu_info*);
  204. struct api_data *(*get_api_stats)(struct cgpu_info*);
  205. bool (*get_stats)(struct cgpu_info*);
  206. // Thread-specific functions
  207. bool (*thread_prepare)(struct thr_info*);
  208. uint64_t (*can_limit_work)(struct thr_info*);
  209. bool (*thread_init)(struct thr_info*);
  210. void (*free_work)(struct thr_info*, struct work*);
  211. bool (*prepare_work)(struct thr_info*, struct work*);
  212. int64_t (*scanhash)(struct thr_info*, struct work*, int64_t);
  213. void (*thread_shutdown)(struct thr_info*);
  214. void (*thread_enable)(struct thr_info*);
  215. };
  216. enum dev_enable {
  217. DEV_ENABLED,
  218. DEV_DISABLED,
  219. DEV_RECOVER,
  220. };
  221. enum cl_kernels {
  222. KL_NONE,
  223. KL_POCLBM,
  224. KL_PHATK,
  225. KL_DIAKGCN,
  226. KL_DIABLO,
  227. KL_SCRYPT,
  228. };
  229. enum dev_reason {
  230. REASON_THREAD_FAIL_INIT,
  231. REASON_THREAD_ZERO_HASH,
  232. REASON_THREAD_FAIL_QUEUE,
  233. REASON_DEV_SICK_IDLE_60,
  234. REASON_DEV_DEAD_IDLE_600,
  235. REASON_DEV_NOSTART,
  236. REASON_DEV_OVER_HEAT,
  237. REASON_DEV_THERMAL_CUTOFF,
  238. REASON_DEV_COMMS_ERROR,
  239. };
  240. #define REASON_NONE "None"
  241. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  242. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  243. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  244. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  245. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  246. #define REASON_DEV_NOSTART_STR "Device failed to start"
  247. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  248. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  249. #define REASON_DEV_COMMS_ERROR_STR "Device comms error"
  250. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  251. #define MIN_SEC_UNSET 99999999
  252. struct cgminer_stats {
  253. uint32_t getwork_calls;
  254. struct timeval getwork_wait;
  255. struct timeval getwork_wait_max;
  256. struct timeval getwork_wait_min;
  257. };
  258. // Just the actual network getworks to the pool
  259. struct cgminer_pool_stats {
  260. uint32_t getwork_calls;
  261. uint32_t getwork_attempts;
  262. struct timeval getwork_wait;
  263. struct timeval getwork_wait_max;
  264. struct timeval getwork_wait_min;
  265. double getwork_wait_rolling;
  266. };
  267. struct cgpu_info {
  268. int cgminer_id;
  269. const struct device_api *api;
  270. const char *devtype;
  271. int device_id;
  272. const char *name;
  273. const char *device_path;
  274. FILE *device_file;
  275. union {
  276. #ifdef USE_ZTEX
  277. struct libztex_device *device_ztex;
  278. #endif
  279. int device_fd;
  280. };
  281. #ifdef USE_BITFORCE
  282. struct timeval work_start_tv;
  283. unsigned int wait_ms;
  284. unsigned int sleep_ms;
  285. double avg_wait_f;
  286. unsigned int avg_wait_d;
  287. uint32_t nonces;
  288. bool nonce_range;
  289. #endif
  290. pthread_mutex_t device_mutex;
  291. enum dev_enable deven;
  292. int accepted;
  293. double accepted_weighed;
  294. int rejected;
  295. int hw_errors;
  296. unsigned int low_count;
  297. double rolling;
  298. double total_mhashes;
  299. double utility;
  300. double utility_diff1;
  301. enum alive status;
  302. char init[40];
  303. struct timeval last_message_tv;
  304. int threads;
  305. struct thr_info **thr;
  306. unsigned int max_hashes;
  307. const char *kname;
  308. #ifdef HAVE_OPENCL
  309. bool mapped;
  310. int virtual_gpu;
  311. int virtual_adl;
  312. int intensity;
  313. bool dynamic;
  314. cl_uint vwidth;
  315. size_t work_size;
  316. enum cl_kernels kernel;
  317. struct timeval tv_gpustart;;
  318. struct timeval tv_gpuend;
  319. double gpu_us_average;
  320. #endif
  321. float temp;
  322. int cutofftemp;
  323. #ifdef HAVE_ADL
  324. bool has_adl;
  325. struct gpu_adl adl;
  326. int gpu_engine;
  327. int min_engine;
  328. int gpu_fan;
  329. int min_fan;
  330. int gpu_memclock;
  331. int gpu_memdiff;
  332. int gpu_powertune;
  333. float gpu_vddc;
  334. #endif
  335. int last_share_pool;
  336. time_t last_share_pool_time;
  337. time_t device_last_well;
  338. time_t device_last_not_well;
  339. enum dev_reason device_not_well_reason;
  340. int thread_fail_init_count;
  341. int thread_zero_hash_count;
  342. int thread_fail_queue_count;
  343. int dev_sick_idle_60_count;
  344. int dev_dead_idle_600_count;
  345. int dev_nostart_count;
  346. int dev_over_heat_count; // It's a warning but worth knowing
  347. int dev_thermal_cutoff_count;
  348. int dev_comms_error_count;
  349. struct cgminer_stats cgminer_stats;
  350. };
  351. extern bool add_cgpu(struct cgpu_info*);
  352. struct thread_q {
  353. struct list_head q;
  354. bool frozen;
  355. pthread_mutex_t mutex;
  356. pthread_cond_t cond;
  357. };
  358. struct thr_info {
  359. int id;
  360. int device_thread;
  361. bool primary_thread;
  362. pthread_t pth;
  363. struct thread_q *q;
  364. struct cgpu_info *cgpu;
  365. void *cgpu_data;
  366. struct timeval last;
  367. struct timeval sick;
  368. bool pause;
  369. time_t getwork;
  370. double rolling;
  371. bool work_restart;
  372. int work_restart_fd;
  373. int _work_restart_fd_w;
  374. };
  375. extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  376. extern void thr_info_cancel(struct thr_info *thr);
  377. extern void thr_info_freeze(struct thr_info *thr);
  378. extern void nmsleep(unsigned int msecs);
  379. struct string_elist {
  380. char *string;
  381. bool free_me;
  382. struct list_head list;
  383. };
  384. static inline void string_elist_add(const char *s, struct list_head *head)
  385. {
  386. struct string_elist *n;
  387. n = calloc(1, sizeof(*n));
  388. n->string = strdup(s);
  389. n->free_me = true;
  390. list_add_tail(&n->list, head);
  391. }
  392. static inline void string_elist_del(struct string_elist *item)
  393. {
  394. if (item->free_me)
  395. free(item->string);
  396. list_del(&item->list);
  397. }
  398. static inline uint32_t swab32(uint32_t v)
  399. {
  400. return bswap_32(v);
  401. }
  402. static inline void swap256(void *dest_p, const void *src_p)
  403. {
  404. uint32_t *dest = dest_p;
  405. const uint32_t *src = src_p;
  406. dest[0] = src[7];
  407. dest[1] = src[6];
  408. dest[2] = src[5];
  409. dest[3] = src[4];
  410. dest[4] = src[3];
  411. dest[5] = src[2];
  412. dest[6] = src[1];
  413. dest[7] = src[0];
  414. }
  415. extern void quit(int status, const char *format, ...);
  416. static inline void mutex_lock(pthread_mutex_t *lock)
  417. {
  418. if (unlikely(pthread_mutex_lock(lock)))
  419. quit(1, "WTF MUTEX ERROR ON LOCK!");
  420. }
  421. static inline void mutex_unlock(pthread_mutex_t *lock)
  422. {
  423. if (unlikely(pthread_mutex_unlock(lock)))
  424. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  425. }
  426. static inline void wr_lock(pthread_rwlock_t *lock)
  427. {
  428. if (unlikely(pthread_rwlock_wrlock(lock)))
  429. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  430. }
  431. static inline void rd_lock(pthread_rwlock_t *lock)
  432. {
  433. if (unlikely(pthread_rwlock_rdlock(lock)))
  434. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  435. }
  436. static inline void rw_unlock(pthread_rwlock_t *lock)
  437. {
  438. if (unlikely(pthread_rwlock_unlock(lock)))
  439. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  440. }
  441. static inline void rd_unlock(pthread_rwlock_t *lock)
  442. {
  443. rw_unlock(lock);
  444. }
  445. static inline void wr_unlock(pthread_rwlock_t *lock)
  446. {
  447. rw_unlock(lock);
  448. }
  449. static inline void mutex_init(pthread_mutex_t *lock)
  450. {
  451. if (unlikely(pthread_mutex_init(lock, NULL)))
  452. quit(1, "Failed to pthread_mutex_init");
  453. }
  454. static inline void rwlock_init(pthread_rwlock_t *lock)
  455. {
  456. if (unlikely(pthread_rwlock_init(lock, NULL)))
  457. quit(1, "Failed to pthread_rwlock_init");
  458. }
  459. struct pool;
  460. extern bool opt_protocol;
  461. extern char *opt_kernel_path;
  462. extern char *opt_socks_proxy;
  463. extern char *cgminer_path;
  464. extern bool opt_autofan;
  465. extern bool opt_autoengine;
  466. extern bool use_curses;
  467. extern char *opt_api_allow;
  468. extern char *opt_api_groups;
  469. extern char *opt_api_description;
  470. extern int opt_api_port;
  471. extern bool opt_api_listen;
  472. extern bool opt_api_network;
  473. extern bool opt_delaynet;
  474. extern bool opt_restart;
  475. extern char *opt_icarus_timing;
  476. #ifdef USE_BITFORCE
  477. extern bool opt_bfl_noncerange;
  478. #endif
  479. extern pthread_rwlock_t netacc_lock;
  480. extern const uint32_t sha256_init_state[];
  481. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  482. const char *rpc_req, bool, bool, int *,
  483. struct pool *pool, bool);
  484. extern char *bin2hex(const unsigned char *p, size_t len);
  485. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  486. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  487. unsigned char *pdata,
  488. unsigned char *phash1, unsigned char *phash,
  489. const unsigned char *ptarget,
  490. uint32_t max_nonce,
  491. uint32_t *last_nonce,
  492. uint32_t nonce);
  493. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  494. extern int opt_scantime;
  495. extern pthread_mutex_t console_lock;
  496. extern pthread_mutex_t restart_lock;
  497. extern pthread_cond_t restart_cond;
  498. extern void thread_reportin(struct thr_info *thr);
  499. extern bool queue_request(struct thr_info *thr, bool needed);
  500. extern int restart_wait(unsigned int mstime);
  501. extern int stale_wait(unsigned int mstime, struct work*, bool checkend);
  502. extern void kill_work(void);
  503. extern void reinit_device(struct cgpu_info *cgpu);
  504. #ifdef HAVE_ADL
  505. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  506. extern int set_fanspeed(int gpu, int iFanSpeed);
  507. extern int set_vddc(int gpu, float fVddc);
  508. extern int set_engineclock(int gpu, int iEngineClock);
  509. extern int set_memoryclock(int gpu, int iMemoryClock);
  510. #endif
  511. extern void api(int thr_id);
  512. extern struct pool *current_pool(void);
  513. extern int enabled_pools;
  514. extern void add_pool_details(bool live, char *url, char *user, char *pass);
  515. #define MAX_GPUDEVICES 16
  516. #define MIN_INTENSITY -10
  517. #define _MIN_INTENSITY_STR "-10"
  518. #define MAX_INTENSITY 14
  519. #define _MAX_INTENSITY_STR "14"
  520. extern struct list_head scan_devices;
  521. extern int nDevs;
  522. extern int opt_n_threads;
  523. extern int num_processors;
  524. extern int hw_errors;
  525. extern bool use_syslog;
  526. extern bool opt_quiet;
  527. extern struct thr_info *thr_info;
  528. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  529. extern int gpu_threads;
  530. #ifdef USE_SCRYPT
  531. extern bool opt_scrypt;
  532. #else
  533. #define opt_scrypt (0)
  534. #endif
  535. extern double total_secs;
  536. extern int mining_threads;
  537. extern struct cgpu_info *cpus;
  538. extern int total_devices;
  539. extern struct cgpu_info **devices;
  540. extern int total_pools;
  541. extern struct pool **pools;
  542. extern const char *algo_names[];
  543. extern enum sha256_algos opt_algo;
  544. extern struct strategies strategies[];
  545. extern enum pool_strategy pool_strategy;
  546. extern int opt_rotate_period;
  547. extern double total_mhashes_done;
  548. extern unsigned int new_blocks;
  549. extern unsigned int found_blocks;
  550. extern int total_accepted, total_rejected;
  551. extern int total_getworks, total_stale, total_discarded;
  552. extern unsigned int local_work;
  553. extern unsigned int total_go, total_ro;
  554. extern const int opt_cutofftemp;
  555. extern int opt_log_interval;
  556. extern unsigned long long global_hashrate;
  557. #ifdef HAVE_OPENCL
  558. typedef struct {
  559. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  560. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  561. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  562. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  563. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  564. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  565. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  566. cl_uint W16; cl_uint W17; cl_uint W2;
  567. cl_uint PreVal4; cl_uint T1;
  568. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  569. cl_uint PreVal4addT1; cl_uint T1substate0;
  570. cl_uint PreVal4_2;
  571. cl_uint PreVal0;
  572. cl_uint PreW18;
  573. cl_uint PreW19;
  574. cl_uint PreW31;
  575. cl_uint PreW32;
  576. /* For diakgcn */
  577. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  578. cl_uint zeroA, zeroB;
  579. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  580. #ifdef USE_SCRYPT
  581. struct work *work;
  582. #endif
  583. } dev_blk_ctx;
  584. #else
  585. typedef struct {
  586. uint32_t nonce;
  587. } dev_blk_ctx;
  588. #endif
  589. struct curl_ent {
  590. CURL *curl;
  591. struct list_head node;
  592. struct timeval tv;
  593. };
  594. enum pool_enable {
  595. POOL_ENABLED,
  596. POOL_DISABLED,
  597. POOL_REJECTING,
  598. };
  599. struct pool {
  600. int pool_no;
  601. int prio;
  602. int accepted, rejected;
  603. int seq_rejects;
  604. int solved;
  605. bool submit_fail;
  606. bool idle;
  607. bool lagging;
  608. bool probed;
  609. enum pool_enable enabled;
  610. bool submit_old;
  611. bool removed;
  612. bool lp_started;
  613. unsigned char work_restart_id;
  614. uint32_t block_id;
  615. char *hdr_path;
  616. char *lp_url;
  617. unsigned int getwork_requested;
  618. unsigned int stale_shares;
  619. unsigned int discarded_work;
  620. unsigned int getfail_occasions;
  621. unsigned int remotefail_occasions;
  622. struct timeval tv_idle;
  623. char *rpc_url;
  624. char *rpc_userpass;
  625. char *rpc_user, *rpc_pass;
  626. pthread_mutex_t pool_lock;
  627. struct thread_q *submit_q;
  628. struct thread_q *getwork_q;
  629. pthread_t longpoll_thread;
  630. pthread_t submit_thread;
  631. pthread_t getwork_thread;
  632. int curls;
  633. pthread_cond_t cr_cond;
  634. struct list_head curlring;
  635. time_t last_share_time;
  636. struct cgminer_stats cgminer_stats;
  637. struct cgminer_pool_stats cgminer_pool_stats;
  638. };
  639. struct work {
  640. unsigned char data[128];
  641. unsigned char hash1[64];
  642. unsigned char midstate[32];
  643. unsigned char target[32];
  644. unsigned char hash[32];
  645. int rolls;
  646. uint32_t output[1];
  647. uint32_t valid;
  648. dev_blk_ctx blk;
  649. struct thr_info *thr;
  650. int thr_id;
  651. struct pool *pool;
  652. struct timeval tv_staged;
  653. bool mined;
  654. bool clone;
  655. bool cloned;
  656. int rolltime;
  657. bool longpoll;
  658. bool stale;
  659. bool mandatory;
  660. bool block;
  661. unsigned char work_restart_id;
  662. int id;
  663. UT_hash_handle hh;
  664. float difficulty;
  665. time_t share_found_time;
  666. };
  667. extern void get_datestamp(char *, struct timeval *);
  668. extern bool test_nonce(struct work *work, uint32_t nonce, bool checktarget);
  669. bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  670. extern void tailsprintf(char *f, const char *fmt, ...);
  671. extern void wlogprint(const char *f, ...);
  672. extern int curses_int(const char *query);
  673. extern char *curses_input(const char *query);
  674. extern void kill_work(void);
  675. extern void switch_pools(struct pool *selected);
  676. extern void remove_pool(struct pool *pool);
  677. extern void write_config(FILE *fcfg);
  678. extern void default_save_file(char *filename);
  679. extern bool log_curses_only(int prio, const char *f, va_list ap);
  680. extern void clear_logwin(void);
  681. extern bool pool_tclear(struct pool *pool, bool *var);
  682. extern struct thread_q *tq_new(void);
  683. extern void tq_free(struct thread_q *tq);
  684. extern bool tq_push(struct thread_q *tq, void *data);
  685. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  686. extern void tq_freeze(struct thread_q *tq);
  687. extern void tq_thaw(struct thread_q *tq);
  688. extern bool successful_connect;
  689. extern void adl(void);
  690. extern void app_restart(void);
  691. enum api_data_type {
  692. API_ESCAPE,
  693. API_STRING,
  694. API_CONST,
  695. API_INT,
  696. API_UINT,
  697. API_UINT32,
  698. API_UINT64,
  699. API_DOUBLE,
  700. API_ELAPSED,
  701. API_BOOL,
  702. API_TIMEVAL,
  703. API_TIME,
  704. API_MHS,
  705. API_MHTOTAL,
  706. API_TEMP,
  707. API_UTILITY,
  708. API_FREQ,
  709. API_VOLTS,
  710. API_HS,
  711. API_JSON,
  712. };
  713. struct api_data {
  714. enum api_data_type type;
  715. char *name;
  716. void *data;
  717. bool data_was_malloc;
  718. struct api_data *prev;
  719. struct api_data *next;
  720. };
  721. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  722. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  723. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  724. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  725. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  726. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  727. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  728. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  729. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  730. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  731. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  732. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  733. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  734. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  735. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  736. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  737. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  738. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  739. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  740. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  741. #endif /* __MINER_H__ */