driver-icarus.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright 2012-2014 Luke Dashjr
  3. * Copyright 2014 Nate Woolls
  4. * Copyright 2012 Xiangfu
  5. * Copyright 2012 Andrew Smith
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 3 of the License, or (at your option)
  10. * any later version. See COPYING for more details.
  11. */
  12. #ifndef BFG_DRIVER_ICARUS_H
  13. #define BFG_DRIVER_ICARUS_H
  14. #include <stdbool.h>
  15. #include <stdint.h>
  16. #include <sys/time.h>
  17. #include "deviceapi.h"
  18. #include "dynclock.h"
  19. #include "miner.h"
  20. // Fraction of a second, USB timeout is measured in
  21. // i.e. 10 means 1/10 of a second
  22. // Right now, it MUST be 10 due to other assumptions.
  23. #define TIME_FACTOR 10
  24. // It's 10 per second, thus value = 10/TIME_FACTOR =
  25. #define ICARUS_READ_FAULT_DECISECONDS 1
  26. #define NANOSEC 1000000000.0
  27. // Default value for ICARUS_INFO->read_size
  28. #define ICARUS_DEFAULT_READ_SIZE 4
  29. #define ICA_GETS_ERROR -1
  30. #define ICA_GETS_OK 0
  31. #define ICA_GETS_RESTART 1
  32. #define ICA_GETS_TIMEOUT 2
  33. // Store the last INFO_HISTORY data sets
  34. // [0] = current data, not yet ready to be included as an estimate
  35. // Each new data set throws the last old set off the end thus
  36. // keeping a ongoing average of recent data
  37. #define INFO_HISTORY 10
  38. extern struct device_drv icarus_drv;
  39. struct ICARUS_HISTORY {
  40. struct timeval finish;
  41. double sumXiTi;
  42. double sumXi;
  43. double sumTi;
  44. double sumXi2;
  45. uint32_t values;
  46. uint32_t hash_count_min;
  47. uint32_t hash_count_max;
  48. };
  49. enum timing_mode { MODE_DEFAULT, MODE_SHORT, MODE_LONG, MODE_VALUE };
  50. enum icarus_reopen_mode {
  51. IRM_NEVER,
  52. IRM_TIMEOUT,
  53. IRM_CYCLE,
  54. };
  55. enum icarus_user_settings {
  56. IUS_WORK_DIVISION = 1,
  57. IUS_FPGA_COUNT = 2,
  58. };
  59. struct ICARUS_INFO {
  60. // time to calculate the golden_ob
  61. struct timeval golden_tv;
  62. // History structures for calculating read_count
  63. // when info->do_icarus_timing is true
  64. struct ICARUS_HISTORY history[INFO_HISTORY+1];
  65. uint32_t min_data_count;
  66. // Timeout scanning for a nonce (deciseconds)
  67. int read_count;
  68. // Timeout scanning for a golden nonce (deciseconds)
  69. int probe_read_count;
  70. // ds limit for (short=/long=) read_count
  71. int read_count_limit;
  72. enum timing_mode timing_mode;
  73. bool do_icarus_timing;
  74. int do_default_detection;
  75. double fullnonce;
  76. int count;
  77. double W;
  78. uint32_t values;
  79. uint64_t hash_count_range;
  80. // Determine the cost of history processing
  81. // (which will only affect W)
  82. uint64_t history_count;
  83. struct timeval history_time;
  84. // icarus-options
  85. int baud;
  86. // Used to calculate / display hash count when nonce is NOT found
  87. // seconds per Hash
  88. double Hs;
  89. // Used to calculate / display hash count when a nonce is found
  90. int work_division;
  91. int fpga_count;
  92. uint32_t nonce_mask;
  93. enum icarus_reopen_mode reopen_mode;
  94. bool reopen_now;
  95. uint8_t user_set;
  96. bool continue_search;
  97. dclk_change_clock_func_t dclk_change_clock_func;
  98. struct dclk_data dclk;
  99. // Bytes to read from Icarus for nonce
  100. int read_size;
  101. // Settings used when probing / detecting
  102. size_t ob_size;
  103. const char *golden_ob;
  104. const char *golden_nonce;
  105. bool nonce_littleendian;
  106. // Don't check the golden nonce returned when probing
  107. bool ignore_golden_nonce;
  108. // Custom driver functions
  109. bool (*detect_init_func)(const char *devpath, int fd, struct ICARUS_INFO *);
  110. bool (*job_start_func)(struct thr_info *);
  111. #ifdef USE_DUALMINER
  112. #ifdef USE_SCRYPT
  113. bool scrypt;
  114. #endif
  115. bool dual_mode;
  116. #endif
  117. #ifdef USE_ZEUSMINER
  118. // Hardware information, doesn't affect anything directly
  119. uint16_t freq;
  120. uint16_t chips;
  121. #endif
  122. };
  123. struct icarus_state {
  124. bool firstrun;
  125. struct timeval tv_workstart;
  126. struct timeval tv_workfinish;
  127. struct work *last_work;
  128. struct work *last2_work;
  129. bool changework;
  130. bool identify;
  131. uint8_t *ob_bin;
  132. };
  133. extern struct cgpu_info *icarus_detect_custom(const char *devpath, struct device_drv *, struct ICARUS_INFO *);
  134. extern int icarus_gets(const char *repr, unsigned char *, int fd, struct timeval *tv_finish, struct thr_info *, int read_count, int read_size);
  135. extern int icarus_write(const char *repr, int fd, const void *buf, size_t bufLen);
  136. extern bool icarus_init(struct thr_info *);
  137. extern void do_icarus_close(struct thr_info *thr);
  138. extern bool icarus_job_start(struct thr_info *);
  139. extern const char *icarus_set_baud(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  140. extern const char *icarus_set_work_division(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  141. extern const char *icarus_set_reopen(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  142. extern const char *icarus_set_timing(struct cgpu_info *proc, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *out_success);
  143. #endif