miner.h 21 KB

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