dragonmint_t1.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef _DRAGONMINT_T1_
  2. #define _DRAGONMINT_T1_
  3. #include "stdint.h"
  4. #include "stdbool.h"
  5. #include "util.h"
  6. #include "elist.h"
  7. #include "dm_compat.h"
  8. #define MAX_CHIP_NUM (68)
  9. #define MAX_CHAIN_NUM (3)
  10. #define MAX_CORE_NUM (32)
  11. #define MAX_CORES (MAX_CHIP_NUM * MAX_CORE_NUM)
  12. #define MAX_CMD_LENGTH (JOB_LENGTH + MAX_CHIP_NUM * 2 * 2)
  13. #define CMD_TYPE_T1 (0x0)
  14. #define JOB_LENGTH (162)
  15. #define NONCE_LEN (6)
  16. #define T1_PLL_LV_NUM (324)
  17. #define T1_PLL_SETSPI (310)
  18. #define T1_PLL_SETVID (1000)
  19. #define T1_SPI_SPEED_DEF SPI_SPEED_390K
  20. #define STARTUP_VID (0)
  21. #define DEFAULT_PLL (1332)
  22. #define MIN_PLL (1200)
  23. #define MAX_PLL (1392)
  24. #define DEFAULT_VOLT (404)
  25. #define TUNE_VOLT_START_EFF (410)
  26. #define TUNE_VOLT_START_BAL (415)
  27. #define TUNE_VOLT_START_PER (420)
  28. #define TUNE_VOLT_STOP (390)
  29. #define CHIP_VOLT_MAX (445)
  30. #define CHIP_VOLT_MIN (380)
  31. #define USE_BISTMASK
  32. //#define USE_AUTONONCE
  33. #define USE_AUTOCMD0A
  34. #define WEAK_CHIP_THRESHOLD 5
  35. #define BROKEN_CHIP_THRESHOLD 5
  36. #define DRAGONMINT_MINER_TYPE_FILE "/tmp/type"
  37. #define DRAGONMINT_HARDWARE_VERSION_FILE "/tmp/hwver"
  38. #define DRAGONMINT_CHIP_NUM_FILE "/tmp/chip_nums"
  39. #define MINER_AGEING_STATUS_FILE "/tmp/ageingStatus"
  40. #define T1_PLL(prediv,fbdiv,postdiv) ((prediv<<(89-64))|fbdiv<<(80-64)|0b010<<(77-64)|postdiv<<(70-64))
  41. #define T1_PLL_MIN (0) // 120 MHz
  42. #define T1_PLL_TUNE_MIN (290) // 1200 MHz
  43. #define T1_PLL_TUNE_MAX (323) // 1596 MHz
  44. #define T1_PLL_MAX (323) // 1596 MHz
  45. #define T1_PLL_TUNE_RANGE (T1_PLL_TUNE_MAX - T1_PLL_TUNE_MIN + 1)
  46. /* Low iVid corresponds with high voltage */
  47. #define T1_VID_MIN (0)
  48. #define T1_VID_MAX (31)
  49. #define T1_VID_TUNE_RANGE (T1_VID_MAX - T1_VID_MIN + 1)
  50. #define T1_CYCLES_CHAIN (666)
  51. typedef enum {
  52. HARDWARE_VERSION_NONE = 0x00,
  53. HARDWARE_VERSION_G9 = 0x09,
  54. HARDWARE_VERSION_G19 = 0x13,
  55. } hardware_version_e;
  56. typedef enum {
  57. AGEING_BIST_START_FAILED = 1,
  58. AGEING_BIST_FIX_FAILED,
  59. AGEING_CONFIG_PLL_FAILED,
  60. AGEING_PLUG_STATUS_ERROR,
  61. AGEING_SPI_STATUS_ERROR,
  62. AGEING_RUNNING_CONNECT_POOL_FAILED,
  63. AGEING_INIT_CONNECT_POOL_FAILED,
  64. AGEING_ALL_SPI_STATUS_ERROR,
  65. AGEING_HW_VERSION_ERROR,
  66. AGEING_TEMP_IS_OVERHEAT,
  67. AGEING_STATUS_MAX,
  68. } MINER_AGEING_STATUS;
  69. typedef struct {
  70. double highest_vol[MAX_CHAIN_NUM]; /* chip temp bits */;
  71. double lowest_vol[MAX_CHAIN_NUM]; /* chip temp bits */;
  72. double average_vol[MAX_CHAIN_NUM]; /* chip temp bits */;
  73. int stat_val[MAX_CHAIN_NUM][MAX_CHIP_NUM];
  74. int stat_cnt[MAX_CHAIN_NUM][MAX_CHIP_NUM];
  75. } dragonmint_reg_ctrl_t;
  76. struct work_ent {
  77. struct work *work;
  78. struct list_head head;
  79. };
  80. struct work_queue {
  81. int num_elems;
  82. struct list_head head;
  83. };
  84. struct T1_chip {
  85. uint8_t reg[REG_LENGTH];
  86. int num_cores;
  87. int last_queued_id;
  88. struct work *work[4];
  89. /* stats */
  90. int hw_errors;
  91. int stales;
  92. int dupes;
  93. int nonces_found;
  94. int nonce_ranges_done;
  95. /* systime in ms when chip was disabled */
  96. int cooldown_begin;
  97. /* number of consecutive failures to access the chip */
  98. int fail_count;
  99. int fail_reset;
  100. /* mark chip disabled, do not try to re-enable it */
  101. bool disabled;
  102. int temp;
  103. int nVol;
  104. uint32_t last_nonce;
  105. };
  106. struct T1_chain {
  107. int chain_id;
  108. struct cgpu_info *cgpu;
  109. int num_chips;
  110. int num_cores;
  111. int num_active_chips;
  112. int chain_skew;
  113. struct spi_ctx *spi_ctx;
  114. struct T1_chip *chips;
  115. pthread_mutex_t lock;
  116. pthread_cond_t cond;
  117. struct work_queue active_wq;
  118. /* mark chain disabled, do not try to re-enable it */
  119. bool disabled;
  120. bool throttle; /* Needs throttling */
  121. struct timeval cycle_start;
  122. int cycles; /* Cycles used for iVid tuning */
  123. int hw_errors;
  124. int pll; /* Current chain speed */
  125. int base_pll; /* Initial chain speed */
  126. int iVid; /* Current actual iVid */
  127. int base_iVid; /* Initial iVid */
  128. int optimalVid; /* Vid after last tune */
  129. int optimal_vol; /* Optimal voltage found after VID tuning */
  130. double vidproduct[T1_VID_TUNE_RANGE]; // Hashrate product vs vid level
  131. double vidhwerr[T1_VID_TUNE_RANGE]; // hwerr vs vid level
  132. /* Double may give more precision than int since it's an average voltage */
  133. double vidvol[T1_VID_TUNE_RANGE]; // What the voltage is per vid level
  134. double pllproduct[T1_PLL_TUNE_RANGE]; // Hashrate product vs pll level
  135. double pllhwerr[T1_PLL_TUNE_RANGE]; // hwerr vs pll level
  136. int pllvid[T1_PLL_TUNE_RANGE]; // Associated VID per pll
  137. bool VidOptimal; // We've stopped tuning voltage
  138. bool pllOptimal; // We've stopped tuning frequency
  139. bool sampling; // Results are valid for tuning
  140. time_t throttled; // Currently throttled time for heat
  141. time_t lastshare;
  142. cgtimer_t cgt; /* Main work loop reentrant timer */
  143. };
  144. struct PLL_Clock {
  145. uint32_t num; // divider 1000
  146. uint32_t speedMHz; // unit MHz
  147. uint32_t pll_reg;
  148. };
  149. struct T1_config_options {
  150. int ref_clk_khz;
  151. int sys_clk_khz;
  152. int spi_clk_khz;
  153. /* limit chip chain to this number of chips (testing only) */
  154. int override_chip_num;
  155. int wiper;
  156. };
  157. unsigned short CRC16_2(unsigned char* pchMsg, unsigned short wDataLen);
  158. void hexdump_error(char *prefix, uint8_t *buff, int len);
  159. void hexdump(char *prefix, uint8_t *buff, int len);
  160. bool dm_cmd_resetall(uint8_t chain_id, uint8_t chip_id, uint8_t *result);
  161. bool dm_cmd_resetjob(uint8_t chain_id, uint8_t chip_id, uint8_t *result);
  162. bool dm_cmd_resetbist(uint8_t chain_id, uint8_t chip_id, uint8_t *result);
  163. bool dragonmint_check_voltage(struct T1_chain *t1, int chip_id, dragonmint_reg_ctrl_t *s_reg_ctrl);
  164. bool check_chip(struct T1_chain *t1, int i);
  165. bool abort_work(struct T1_chain *t1);
  166. int get_current_ms(void);
  167. bool is_chip_disabled(struct T1_chain *t1, uint8_t chip_id);
  168. void disable_chip(struct T1_chain *t1, uint8_t chip_id);
  169. bool get_nonce(struct T1_chain *t1, uint8_t *nonce, uint8_t *chip_id, uint8_t *job_id, uint8_t *micro_job_id);
  170. bool set_work(struct T1_chain *t1, uint8_t chip_id, struct work *work, uint8_t queue_states);
  171. uint8_t *create_job(uint8_t chip_id, uint8_t job_id, struct work *work);
  172. void test_bench_pll_config(struct T1_chain *t1,uint32_t uiPll);
  173. hardware_version_e dragonmint_get_hwver(void);
  174. //dragonmint_type_e dragonmint_get_miner_type(void);
  175. uint32_t dragonmint_get_chipnum(void);
  176. void chain_all_exit(void);
  177. void power_down_all_chain(void);
  178. void write_miner_ageing_status(uint32_t statusCode);
  179. int dragonmint_get_voltage_stats(struct T1_chain *t1, dragonmint_reg_ctrl_t *s_reg_ctrl);
  180. bool t1_set_pll(struct T1_chain *t1, int chip_id, int target_pll);
  181. bool T1_SetT1PLLClock(struct T1_chain *t1,int pllClkIdx, int chip_id);
  182. int T1_ConfigT1PLLClock(uint32_t optPll);
  183. extern const struct PLL_Clock PLL_Clk_12Mhz[T1_PLL_LV_NUM];
  184. extern const uint8_t default_reg[T1_PLL_LV_NUM][REG_LENGTH];
  185. #endif