driver-btm-soc.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /*
  2. * Copyright 2016-2017 Fazio Bai <yang.bai@bitmain.com>
  3. * Copyright 2016-2017 Clement Duan <kai.duan@bitmain.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #ifndef __DRIVER_BTM_SOC_H__
  11. #define __DRIVER_BTM_SOC_H__
  12. #include "config.h"
  13. //FPGA rgister Address Map
  14. #define HARDWARE_VERSION (0x00000000/sizeof(int))
  15. #define FAN_SPEED (0x00000004/sizeof(int))
  16. #define HASH_ON_PLUG (0x00000008/sizeof(int))
  17. #define BUFFER_SPACE (0x0000000c/sizeof(int))
  18. #define RETURN_NONCE (0x00000010/sizeof(int))
  19. #define NONCE_NUMBER_IN_FIFO (0x00000018/sizeof(int))
  20. #define NONCE_FIFO_INTERRUPT (0x0000001c/sizeof(int))
  21. #define TEMPERATURE_0_3 (0x00000020/sizeof(int))
  22. #define TEMPERATURE_4_7 (0x00000024/sizeof(int))
  23. #define TEMPERATURE_8_11 (0x00000028/sizeof(int))
  24. #define TEMPERATURE_12_15 (0x0000002c/sizeof(int))
  25. #define IIC_COMMAND (0x00000030/sizeof(int))
  26. #define RESET_HASHBOARD_COMMAND (0x00000034/sizeof(int))
  27. #define BMC_CMD_COUNTER (0x00000038/sizeof(int))
  28. #define TW_WRITE_COMMAND (0x00000040/sizeof(int))
  29. #define QN_WRITE_DATA_COMMAND (0x00000080/sizeof(int))
  30. #define FAN_CONTROL (0x00000084/sizeof(int))
  31. #define TIME_OUT_CONTROL (0x00000088/sizeof(int))
  32. #define TICKET_MASK_FPGA (0x0000008c/sizeof(int))
  33. #define HASH_COUNTING_NUMBER_FPGA (0x00000090/sizeof(int))
  34. #define SNO (0x00000094/sizeof(int))
  35. #define BC_WRITE_COMMAND (0x000000c0/sizeof(int))
  36. #define BC_COMMAND_BUFFER (0x000000c4/sizeof(int))
  37. #define FPGA_CHIP_ID_ADDR (0x000000f0/sizeof(int))
  38. #define CRC_ERROR_CNT_ADDR (0x000000f8/sizeof(int))
  39. #define DHASH_ACC_CONTROL (0x00000100/sizeof(int))
  40. #define COINBASE_AND_NONCE2_LENGTH (0x00000104/sizeof(int))
  41. #define WORK_NONCE_2 (0x00000108/sizeof(int))
  42. #define NONCE2_AND_JOBID_STORE_ADDRESS (0x00000110/sizeof(int))
  43. #define MERKLE_BIN_NUMBER (0x00000114/sizeof(int))
  44. #define JOB_START_ADDRESS (0x00000118/sizeof(int))
  45. #define JOB_LENGTH (0x0000011c/sizeof(int))
  46. #define JOB_DATA_READY (0x00000120/sizeof(int))
  47. #define JOB_ID (0x00000124/sizeof(int))
  48. #define BLOCK_HEADER_VERSION (0x00000130/sizeof(int))
  49. #define TIME_STAMP (0x00000134/sizeof(int))
  50. #define TARGET_BITS (0x00000138/sizeof(int))
  51. #define PRE_HEADER_HASH (0x00000140/sizeof(int))
  52. //FPGA registers bit map
  53. //QN_WRITE_DATA_COMMAND
  54. #define RESET_HASH_BOARD (1 << 31)
  55. #define RESET_ALL (1 << 23)
  56. #define CHAIN_ID(id) (id << 16)
  57. #define RESET_FPGA (1 << 15)
  58. #define RESET_TIME(time) (time << 0)
  59. #define TIME_OUT_VALID (1 << 31)
  60. //RETURN_NONCE
  61. #define WORK_ID_OR_CRC (1 << 31)
  62. #define WORK_ID_OR_CRC_VALUE(value) ((value >> 16) & 0x7fff)
  63. #define NONCE_INDICATOR (1 << 7)
  64. #define CHAIN_NUMBER(value) (value & 0xf)
  65. #define REGISTER_DATA_CRC(value) ((value >> 24) & 0x7f)
  66. //BC_WRITE_COMMAND
  67. #define BC_COMMAND_BUFFER_READY (1 << 31)
  68. #define BC_COMMAND_EN_CHAIN_ID (1 << 23)
  69. #define BC_COMMAND_EN_NULL_WORK (1 << 22)
  70. //NONCE2_AND_JOBID_STORE_ADDRESS
  71. #define JOB_ID_OFFSET (0x0/sizeof(int))
  72. #define HEADER_VERSION_OFFSET (0x4/sizeof(int))
  73. #define NONCE2_L_OFFSET (0x8/sizeof(int))
  74. #define NONCE2_H_OFFSET (0xc/sizeof(int))
  75. #define MIDSTATE_OFFSET 0x20
  76. //DHASH_ACC_CONTROL
  77. #define VIL_MODE (1 << 15)
  78. #define VIL_MIDSTATE_NUMBER(value) ((value & 0x0f) << 8)
  79. #define NEW_BLOCK (1 << 7)
  80. #define RUN_BIT (1 << 6)
  81. #define OPERATION_MODE (1 << 5)
  82. //NONCE_FIFO_INTERRUPT
  83. #define FLUSH_NONCE3_FIFO (1 << 16)
  84. //ASIC macro define
  85. //ASIC register address
  86. #define SOC_VERSION 1
  87. #define CHIP_ADDRESS 0x0
  88. #define GOLDEN_NONCE_COUNTER 0x8
  89. #define PLL_PARAMETER 0xc
  90. #define START_NONCE_OFFSET 0x10
  91. #define HASH_COUNTING_NUMBER 0x14
  92. #define TICKET_MASK 0x18
  93. #define MISC_CONTROL 0x1c
  94. #define GENERAL_I2C_COMMAND 0X20
  95. //ASIC command
  96. #define SET_ADDRESS 0x1
  97. #define SET_PLL_DIVIDER2 0x2
  98. #define PATTERN_CONTROL 0x3
  99. #define GET_STATUS 0x4
  100. #define CHAIN_INACTIVE 0x5
  101. #define SET_BAUD_OPS 0x6
  102. #define SET_PLL_DIVIDER1 0x7
  103. #define SET_CONFIG 0x8
  104. #define COMMAND_FOR_ALL 0x80
  105. //other ASIC macro define
  106. #define MAX_BAUD_DIVIDER 26
  107. #define DEFAULT_BAUD_DIVIDER 26
  108. #define VIL_COMMAND_TYPE (0x02 << 5)
  109. #define VIL_ALL (0x01 << 4)
  110. #define PAT (0x01 << 7)
  111. #define GRAY (0x01 << 6)
  112. #define INV_CLKO (0x01 << 5)
  113. #define LPD (0x01 << 4)
  114. #define GATEBCLK (0x01 << 7)
  115. #define RFS (0x01 << 6)
  116. #define MMEN (0x01 << 7)
  117. #define TFS(x) ((x & 0x03) << 5)
  118. // Pic
  119. #define PIC_FLASH_POINTER_START_ADDRESS_H 0x03
  120. #define PIC_FLASH_POINTER_START_ADDRESS_L 0x00
  121. #define PIC_FLASH_POINTER_END_ADDRESS_H 0x0f
  122. #define PIC_FLASH_POINTER_END_ADDRESS_L 0x7f
  123. #define PIC_FLASH_LENGTH (((unsigned int)PIC_FLASH_POINTER_END_ADDRESS_H<<8 + PIC_FLASH_POINTER_END_ADDRESS_L) - ((unsigned int)PIC_FLASH_POINTER_START_ADDRESS_H<<8 + PIC_FLASH_POINTER_START_ADDRESS_L) + 1)
  124. #define PIC_FLASH_SECTOR_LENGTH 32
  125. #define PIC_SOFTWARE_VERSION_LENGTH 1
  126. #define PIC_VOLTAGE_TIME_LENGTH 6
  127. #define PIC_COMMAND_1 0x55
  128. #define PIC_COMMAND_2 0xaa
  129. #define SET_PIC_FLASH_POINTER 0x01
  130. #define SEND_DATA_TO_IIC 0x02 // just send data into pic's cache
  131. #define READ_DATA_FROM_IIC 0x03
  132. #define ERASE_IIC_FLASH 0x04 // erase 32 bytes one time
  133. #define WRITE_DATA_INTO_PIC 0x05 // tell pic write data into flash from cache
  134. #define JUMP_FROM_LOADER_TO_APP 0x06
  135. #define RESET_PIC 0x07
  136. #define GET_PIC_FLASH_POINTER 0x08
  137. #define ERASE_PIC_APP_PROGRAM 0x09
  138. #define SET_VOLTAGE 0x10
  139. #define SET_VOLTAGE_TIME 0x11
  140. #define SET_HASH_BOARD_ID 0x12
  141. #define GET_HASH_BOARD_ID 0x13
  142. #define SET_HOST_MAC_ADDRESS 0x14
  143. #define ENABLE_VOLTAGE 0x15
  144. #define SEND_HEART_BEAT 0x16
  145. #define GET_PIC_SOFTWARE_VERSION 0x17
  146. #define GET_VOLTAGE 0x18
  147. #define GET_DATE 0x19
  148. #define GET_WHICH_MAC 0x20
  149. #define GET_MAC 0x21
  150. #define WR_TEMP_OFFSET_VALUE 0x22
  151. #define RD_TEMP_OFFSET_VALUE 0x23
  152. //diff freq
  153. #define PIC_FLASH_POINTER_FREQ_START_ADDRESS_H 0x0F
  154. #define PIC_FLASH_POINTER_FREQ_START_ADDRESS_L 0xA0
  155. #define PIC_FLASH_POINTER_FREQ_END_ADDRESS_H 0x0f
  156. #define PIC_FLASH_POINTER_FREQ_END_ADDRESS_L 0xDF
  157. #define FREQ_MAGIC 0x7D
  158. // BAD CORE NUM
  159. #define PIC_FLASH_POINTER_BADCORE_START_ADDRESS_H 0x0F
  160. #define PIC_FLASH_POINTER_BADCORE_START_ADDRESS_L 0x80
  161. #define PIC_FLASH_POINTER_BADCORE_END_ADDRESS_H 0x0f
  162. #define PIC_FLASH_POINTER_BADCORE_END_ADDRESS_L 0x9F
  163. #define BADCORE_MAGIC 0x23 // magic number for bad core num
  164. #define HEART_BEAT_TIME_GAP 10 // 10s
  165. #define IIC_READ (1 << 25)
  166. #define IIC_WRITE (~IIC_READ)
  167. #define IIC_REG_ADDR_VALID (1 << 24)
  168. //#define IIC_ADDR_HIGH_4_BIT (0x0A << 20)
  169. #define IIC_CHAIN_NUMBER(x) ((x & 0x0f) << 16)
  170. #define IIC_REG_ADDR(x) ((x & 0xff) << 8)
  171. // AT24C02
  172. #define AT24C02_ADDRESS 0x50
  173. #define EEPROM_LENGTH 256
  174. #define HASH_ID_ADDR 0x80
  175. #define VOLTAGE_ADDR 0x90
  176. #define SENSOR_OFFSET_ADDR 0x98
  177. #define VOLTAGE_SET_TIME 0xA0
  178. #define VOLTAGE_SET_TIME 0xA0
  179. #define FREQ_BADCORE_ADDR 0x00 // 128 bytes 0 - 0x7F
  180. //other FPGA macro define
  181. #define TOTAL_LEN 0x160
  182. #define FPGA_MEM_TOTAL_LEN (16*1024*1024) // 16M bytes
  183. #define HARDWARE_VERSION_VALUE 0xC501
  184. #define NONCE2_AND_JOBID_STORE_SPACE (2*1024*1024) // 2M bytes
  185. #define NONCE2_AND_JOBID_STORE_SPACE_ORDER 9 // for 2M bytes space
  186. #define JOB_STORE_SPACE (1 << 16) // for 64K bytes space
  187. #define JOB_START_SPACE (1024*8) // 8K bytes
  188. #define JOB_START_ADDRESS_ALIGN 32 // JOB_START_ADDRESS need 32 bytes aligned
  189. #define NONCE2_AND_JOBID_ALIGN 64 // NONCE2_AND_JOBID_STORE_SPACE need 64 bytes aligned
  190. #define MAX_TIMEOUT_VALUE 0x1ffff // defined in TIME_OUT_CONTROL
  191. #define MAX_NONCE_NUMBER_IN_FIFO 0x1ff // 511 nonce
  192. #define NONCE_DATA_LENGTH 4 // 4 bytes
  193. #define REGISTER_DATA_LENGTH 4 // 4 bytes
  194. #define TW_WRITE_COMMAND_LEN 52
  195. #define TW_WRITE_COMMAND_LEN_VIL 52
  196. #define NEW_BLOCK_MARKER 0x11
  197. #define NORMAL_BLOCK_MARKER 0x01
  198. // ATTENTION: if MEM size is changed, must change this micro definition too!!! use MAX size (BYTE) - 16 MB as FPGA start memory address
  199. #define PHY_MEM_NONCE2_JOBID_ADDRESS_XILINX_1GB ((1024-16)*1024*1024)
  200. #define PHY_MEM_NONCE2_JOBID_ADDRESS_XILINX_512MB ((512-16)*1024*1024) // XILINX use 512MB memory
  201. #define PHY_MEM_NONCE2_JOBID_ADDRESS_XILINX_256MB ((256-16)*1024*1024) // XILINX use 256MB memory
  202. #define PHY_MEM_NONCE2_JOBID_ADDRESS_C5 ((1024-16)*1024*1024)
  203. extern unsigned int PHY_MEM_NONCE2_JOBID_ADDRESS;
  204. #define PHY_MEM_JOB_START_ADDRESS_1 (PHY_MEM_NONCE2_JOBID_ADDRESS + NONCE2_AND_JOBID_STORE_SPACE)
  205. #define PHY_MEM_JOB_START_ADDRESS_2 (PHY_MEM_JOB_START_ADDRESS_1 + JOB_STORE_SPACE)
  206. //#include "miner_type.h" // use setminertype to define miner type in this file instead of belows!!!
  207. //#define R4 // if defined , for R4 63 chips
  208. //#define S9_PLUS // if defined , for T9 57 chips
  209. //#define S9_63 // if defined , for S9 63 chips
  210. //#define T9_18 // if defined , for T9+ 18 chips
  211. #define RESET_KEEP_TIME 3 // keep reset signal for 1 secnods
  212. #undef USE_OPENCORE_ONEBYONE // if defined, we will use open core one by one, do 114 times on open core for each chain! but NOT WORKS!??
  213. #undef ENABLE_REGISTER_CRC_CHECK //if defined, will drop the register buffer with crc error!
  214. #define REBOOT_TEST_ONCE_1HOUR //if defined, will check hashrate after 1 hour, and reboot only once
  215. #define ENABLE_FINAL_TEST_WITHOUT_REBOOT // when REBOOT_TEST_ONCE_1HOUR enabeld and this defined, the miner will not reboot after test for 1 hours, then we can save time. test system will treat these miners as good with green color.
  216. #define DISABLE_FINAL_TEST //if defined, it will set rebootTestNum=0 and restartNum=2 to indicate the the miner fw is in normal user mode , not test mode
  217. #define DISABLE_SHOWX_ENABLE_XTIMES // if defined, will disable x show on web UI, but will enable x times counter in 1 mins
  218. #define FASTER_TESTPATTEN // will use 9% timeout to test patten
  219. #undef USE_OPENCORE_TWICE
  220. #define ENABLE_REINIT_WHEN_TESTFAILED //if defined, when test failed on patten, we set a flag in file, and will use highest voltage according to the limit rules of power and hashrate.
  221. #define RESET_HASHBOARD_TIME 15
  222. #define ENABLE_CHECK_PIC_FLASH_ADDR // if enabled, will check PIC FLASH ADDR value , set and read back to compare from PIC
  223. #define ENABLE_RESTORE_PIC_APP // if enabled, will restore PIC APP when the version is not correct!!!
  224. #ifdef R4
  225. #define USE_N_OFFSET_FIX_TEMP // if defined, we will use n and offset to fix temp value
  226. #define EXTEND_TEMP_MODE // if defined, we set temp value area from -64 to 191 as extended temp
  227. #define ENABLE_HIGH_VOLTAGE_OPENCORE
  228. #define PIC_VERSION 0x03
  229. #define CHAIN_ASIC_NUM 63
  230. #define R4_MAX_VOLTAGE_C5 890
  231. #define R4_MAX_VOLTAGE_XILINX 910
  232. #define FIX_BAUD_VALUE 1
  233. #define UPRATE_PERCENT 1 // means we need reserved more 1% rate
  234. #define HIGHEST_VOLTAGE_LIMITED_HW 940 //measn the largest voltage, hw can support
  235. #define USE_NEW_RESET_FPGA
  236. #undef USE_PREINIT_OPENCORE // if defined, we will open core at first ,then get asicnum and do other init process
  237. #endif
  238. #ifdef S9_PLUS
  239. #define ENABLE_HIGH_VOLTAGE_OPENCORE
  240. #define S9_PLUS_VOLTAGE2 //if defined, then it support S9+ new board with new voltage controller
  241. #define PIC_VERSION 0x03
  242. #define CHAIN_ASIC_NUM 57
  243. #define USE_N_OFFSET_FIX_TEMP // if defined, we will use n and offset to fix temp value
  244. #define EXTEND_TEMP_MODE // if defined, we set temp value area from -64 to 191 as extended temp
  245. #define HIGHEST_VOLTAGE_LIMITED_HW 970 //measn the largest voltage, hw can support
  246. #define FIX_BAUD_VALUE 1
  247. #define UPRATE_PERCENT 2 // means we need reserved more 2% rate
  248. #define USE_NEW_RESET_FPGA
  249. #undef USE_PREINIT_OPENCORE // if defined, we will open core at first ,then get asicnum and do other init process
  250. #endif
  251. #ifdef S9_63
  252. #define ENABLE_HIGH_VOLTAGE_OPENCORE
  253. #define PIC_VERSION 0x03
  254. #define CHAIN_ASIC_NUM 63
  255. #define USE_N_OFFSET_FIX_TEMP // if defined, we will use n and offset to fix temp value
  256. #define EXTEND_TEMP_MODE // if defined, we set temp value area from -64 to 191 as extended temp
  257. #define FIX_BAUD_VALUE 1
  258. #define UPRATE_PERCENT 1 // means we need reserved more 1% rate
  259. #define HIGHEST_VOLTAGE_LIMITED_HW 940 //measn the largest voltage, hw can support
  260. #define USE_NEW_RESET_FPGA
  261. #undef USE_PREINIT_OPENCORE // if defined, we will open core at first ,then get asicnum and do other init process
  262. #endif
  263. #ifdef T9_18
  264. #define ENABLE_HIGH_VOLTAGE_OPENCORE // T9+ use this , will cause error on chips, because the voltage changing need a long time to balance
  265. #define PIC_VERSION 0x03
  266. #define CHAIN_ASIC_NUM 18
  267. #define USE_N_OFFSET_FIX_TEMP // if defined, we will use n and offset to fix temp value
  268. #define EXTEND_TEMP_MODE // if defined, we set temp value area from -64 to 191 as extended temp
  269. #define FIX_BAUD_VALUE 1
  270. #define UPRATE_PERCENT 2 // means we need reserved more 2% rate
  271. #define HIGHEST_VOLTAGE_LIMITED_HW 930 //measn the largest voltage, hw can support
  272. #define USE_NEW_RESET_FPGA
  273. #undef USE_PREINIT_OPENCORE // if defined, we will open core at first ,then get asicnum and do other init process
  274. #endif
  275. #ifdef USE_PREINIT_OPENCORE
  276. #define ENABLE_SET_TICKETMASK_BEFORE_TESTPATTEN // a bug, do not know reason: asic ticket mask > 0 even after reset asic!!!
  277. #else
  278. #undef ENABLE_SET_TICKETMASK_BEFORE_TESTPATTEN // a bug, do not know reason: asic ticket mask > 0 even after reset asic!!!
  279. #endif
  280. #define ASIC_TYPE 1387 // 1385 or 1387
  281. #define CHIP_ADDR_INTERVAL 4 // fix chip address interval = 4
  282. #define DEFAULT_BAUD_VALUE 26
  283. #define ASIC_CORE_NUM 114
  284. #define BM1387_CORE_NUM ASIC_CORE_NUM
  285. // macro define about miner
  286. #define BITMAIN_MAX_CHAIN_NUM 16
  287. #define BITMAIN_MAX_FAN_NUM 8 // FPGA just can supports 8 fan
  288. #define BITMAIN_DEFAULT_ASIC_NUM 64 // max support 64 ASIC on 1 HASH board
  289. #define MIDSTATE_LEN 32
  290. #define DATA2_LEN 12
  291. #define MAX_RETURNED_NONCE_NUM 10
  292. #define PREV_HASH_LEN 32
  293. #define MERKLE_BIN_LEN 32
  294. #define INIT_CONFIG_TYPE 0x51
  295. #define STATUS_DATA_TYPE 0xa1
  296. #define SEND_JOB_TYPE 0x52
  297. #define READ_JOB_TYPE 0xa2
  298. #define CHECK_SYSTEM_TIME_GAP 10000 // 10s
  299. //fan
  300. // BELOW IS ALL FOR DEBUG !!! normally all must be undefined!!!
  301. #undef DEBUG_FORCE_REINIT //defined to force to reinit with higher voltage
  302. #undef DEBUG_KEEP_USE_PIC_VOLTAGE_WITHOUT_CHECKING_VOLTAGE_OF_SEARCHFREQ // if defined, will read pic voltage at first , and use this voltage in mining as working voltage, ignore the backup voltage of search freq
  303. #undef DEBUG_ENABLE_I2C_TIMEOUT_PROCESS // if defined, sw will process I2C timeout, but normally FPGA will process timeout, SW do not need this
  304. #undef DEBUG_PRINT_T9_PLUS_PIC_HEART_INFO // if defined, used to debug T9+ bug: pic heart cmd failed!
  305. #undef DEBUG_PIC_UPGRADE // if defined, we will force to write PIC program data once!
  306. #undef DEBUG_KEEP_REBOOT_EVERY_ONE_HOUR // if defined, keep reboot every one hour!!! this is for R4
  307. #undef DEBUG_NOT_CHECK_FAN_NUM // if defined, we will ignore fan number checking, will keep run even without any fan!!!
  308. #undef DEBUG_WITHOUT_FREQ_VOLTAGE_LIMIT // if defined, we will not limit freq according to voltage!
  309. #undef DEBUG_DOWN_VOLTAGE_TEST
  310. #ifdef DEBUG_DOWN_VOLTAGE_TEST
  311. #define DEBUG_DOWN_VOLTAGE_VALUE 10 // means down 0.1 V
  312. #endif
  313. #undef DEBUG_XILINX_NONCE_NOTENOUGH // will disable mutex lock on read temp and send work, but will disable one chain's read temp
  314. #ifdef DEBUG_XILINX_NONCE_NOTENOUGH
  315. #define DISABLE_REG_CHAIN_INDEX 5 //disable which chain's read register
  316. #endif
  317. #undef DEBUG_OPENCORE_TWICE
  318. #undef ENABLE_REINIT_MINING // if defined, will enable hashrate check in mining, and re-init if low hashrate.
  319. #undef DEBUG_REINIT // reinit per 2mins and will not do pre heat patten test
  320. #undef DEBUG_REBOOT // reboot every 30mins, for test
  321. #undef DEBUG_218_FAN_FULLSPEED //for debug on 218, full speed on fan
  322. #undef DISABLE_TEMP_PROTECT
  323. #undef TWO_CHIP_TEMP_S9
  324. #undef SHOW_BOTTOM_TEMP
  325. #undef KEEP_TEMPFAN_LOG // if defined, will not clear old temp fan log info
  326. #undef HIGH_TEMP_TEST_S9 //if defined, will use 120 degree as the high temp
  327. #undef CAPTURE_PATTEN
  328. #define CHECK_RT_IDEAL_RATE_PERCENT 85 // RT rate / ideal rate >= 85% will be OK, or need re init
  329. typedef enum
  330. {
  331. TEMP_POS_LOCAL=0,
  332. TEMP_POS_MIDDLE,
  333. TEMP_POS_BOTTOM,
  334. TEMP_POS_NUM=4, // always the last one, to identify the number of temp , must 4 bytes alignment
  335. } TEMP_POSITION;
  336. #ifdef R4
  337. #define PWM_T 0 // 0 local temp, 1 middle temp, 2 bottom, as above!!!
  338. #define MIN_FAN_NUM 1
  339. #define MAX_FAN_SPEED 3000
  340. #define TEMP_INTERVAL 2
  341. // below are used for R4 on using one app to support C5 and XILINX board
  342. extern int MIN_PWM_PERCENT;
  343. extern int MID_PWM_PERCENT;
  344. extern int MAX_PWM_PERCENT;
  345. extern int MAX_TEMP;
  346. extern int MAX_FAN_TEMP;
  347. extern int MID_FAN_TEMP;
  348. extern int MIN_FAN_TEMP;
  349. extern int MAX_PCB_TEMP;
  350. extern int MAX_FAN_PCB_TEMP;
  351. #if PWM_T == 1
  352. #define MIN_PWM_PERCENT_C5 20
  353. #define MID_PWM_PERCENT_C5 60
  354. #define MAX_PWM_PERCENT_C5 100
  355. #define MAX_TEMP_C5 125
  356. #define MAX_FAN_TEMP_C5 110
  357. #define MID_FAN_TEMP_C5 90
  358. #define MIN_FAN_TEMP_C5 60
  359. #define MAX_PCB_TEMP_C5 100 // use middle to control fan, but use pcb temp to check to stop or not!
  360. #define MAX_FAN_PCB_TEMP_C5 85 //90 use middle to control fan, but use pcb temp to check to stop or not!
  361. #define MIN_PWM_PERCENT_XILINX 20
  362. #define MID_PWM_PERCENT_XILINX 60
  363. #define MAX_PWM_PERCENT_XILINX 100
  364. #define MAX_TEMP_XILINX 125
  365. #define MAX_FAN_TEMP_XILINX 110
  366. #define MID_FAN_TEMP_XILINX 90
  367. #define MIN_FAN_TEMP_XILINX 60
  368. #define MAX_PCB_TEMP_XILINX 100 // use middle to control fan, but use pcb temp to check to stop or not!
  369. #define MAX_FAN_PCB_TEMP_XILINX 85 //90 use middle to control fan, but use pcb temp to check to stop or not!
  370. #else
  371. #define MIN_PWM_PERCENT_C5 50
  372. #define MID_PWM_PERCENT_C5 90
  373. #define MAX_PWM_PERCENT_C5 100
  374. #define MAX_TEMP_C5 90
  375. #define MAX_FAN_TEMP_C5 75
  376. #define MID_FAN_TEMP_C5 65
  377. #define MIN_FAN_TEMP_C5 25
  378. #define MAX_PCB_TEMP_C5 90 // use middle to control fan, but use pcb temp to check to stop or not!
  379. #define MAX_FAN_PCB_TEMP_C5 85 //90 use middle to control fan, but use pcb temp to check to stop or not!
  380. #define MIN_PWM_PERCENT_XILINX 30
  381. #define MID_PWM_PERCENT_XILINX 70
  382. #define MAX_PWM_PERCENT_XILINX 100
  383. #define MAX_TEMP_XILINX 90
  384. #define MAX_FAN_TEMP_XILINX 75
  385. #define MID_FAN_TEMP_XILINX 65
  386. #define MIN_FAN_TEMP_XILINX 25
  387. #define MAX_PCB_TEMP_XILINX 90 // use middle to control fan, but use pcb temp to check to stop or not!
  388. #define MAX_FAN_PCB_TEMP_XILINX 85 //90 use middle to control fan, but use pcb temp to check to stop or not!
  389. #endif
  390. #define TEMP_INTERVAL 2
  391. #define MID_PWM_ADJUST_FACTOR ((MAX_PWM_PERCENT-MID_PWM_PERCENT)/(MAX_FAN_TEMP-MID_FAN_TEMP))
  392. #define PWM_ADJUST_FACTOR ((MID_PWM_PERCENT-MIN_PWM_PERCENT)/(MID_FAN_TEMP-MIN_FAN_TEMP))
  393. #else
  394. // below is for S9
  395. #define PWM_T 1 // 0 local temp, 1 middle temp, 2 bottom, as above!!!
  396. #define MIN_FAN_NUM 2
  397. #define MAX_FAN_SPEED 6000
  398. #if PWM_T == 1
  399. #define MIN_PWM_PERCENT 0
  400. #define MAX_PWM_PERCENT 100
  401. #ifdef HIGH_TEMP_TEST_S9
  402. #define MAX_TEMP 135 //125 135 145 release:135
  403. #define MAX_FAN_TEMP 120 // 115 125 135 release:120
  404. #define MIN_FAN_TEMP 70 //65 75 85 release:70
  405. #define MAX_PCB_TEMP 105 //100 105 110 release:105
  406. #define MAX_FAN_PCB_TEMP 95 //95 100 105 release:95
  407. #define MIN_FAN_PCB_TEMP 45 // Attention: MAX_FAN_PCB_TEMP - MIN_FAN_PCB_TEMP = MAX_FAN_TEMP - MIN_FAN_TEMP
  408. #else
  409. #ifdef TWO_CHIP_TEMP_S9
  410. #define MAX_TEMP 135 //125 135 145 release:135
  411. #define MAX_FAN_TEMP 120 // 115 125 135 release:120
  412. #define MIN_FAN_TEMP 70 //65 75 85 release:70
  413. #define MAX_PCB_TEMP 105 //100 105 110 release:105
  414. #define MAX_FAN_PCB_TEMP 95 //95 100 105 release:95
  415. #define MIN_FAN_PCB_TEMP 45 // Attention: MAX_FAN_PCB_TEMP - MIN_FAN_PCB_TEMP = MAX_FAN_TEMP - MIN_FAN_TEMP
  416. #else
  417. #define MAX_TEMP 125 //125 135 145 release:125
  418. #define MAX_FAN_TEMP 90 // 115 125 135 release:115
  419. #define MIN_FAN_TEMP 40 //65 75 85 release:65
  420. #define MAX_PCB_TEMP 90 //100 105 110 release:95
  421. #define MAX_FAN_PCB_TEMP 75 //95 100 105 release:85
  422. #define MIN_FAN_PCB_TEMP 25 // Attention: MAX_FAN_PCB_TEMP - MIN_FAN_PCB_TEMP = MAX_FAN_TEMP - MIN_FAN_TEMP
  423. #endif
  424. #endif
  425. #else
  426. #define MIN_PWM_PERCENT 20
  427. #define MAX_PWM_PERCENT 100
  428. #define MAX_TEMP 90
  429. #define MAX_FAN_TEMP 75
  430. #define MIN_FAN_TEMP 35
  431. #define MAX_PCB_TEMP 90 // use middle to control fan, but use pcb temp to check to stop or not!
  432. #endif
  433. #define TEMP_INTERVAL 2
  434. #define PWM_ADJUST_FACTOR ((MAX_PWM_PERCENT-MIN_PWM_PERCENT)/(MAX_FAN_TEMP-MIN_FAN_TEMP))
  435. #endif
  436. #ifdef HIGH_TEMP_TEST_S9
  437. #define MIN_TEMP_CONTINUE_DOWN_FAN 110 // release: 90
  438. #define MAX_TEMP_NEED_UP_FANSTEP 120 // release: 100 if temp is higher than 100, then we need make fan much faster
  439. #else
  440. #define MIN_TEMP_CONTINUE_DOWN_FAN 80 // release: 90
  441. #define MAX_TEMP_NEED_UP_FANSTEP 85 // release: 100 if temp is higher than 100, then we need make fan much faster
  442. #endif
  443. #define PWM_SCALE 50 //50: 1M=1us, 20KHz??
  444. //25: 40KHz
  445. #define PWM_ADJ_SCALE 9/10
  446. //use for hash test
  447. #define TEST_DHASH 0
  448. #define DEVICE_DIFF 8
  449. //use for status check
  450. #define MAX_TEMPCHIP_NUM 8 // support 8 chip has temp
  451. #define MIN_FREQ 4 // 8:300M 6:250M 4:200M
  452. #define MAX_FREQ 100 //850M
  453. #define MAX_SW_TEMP_OFFSET -15
  454. #define BMMINER_VERSION 3 // 3 for auto freq, 1 or 2 for normal ( the old version is 0)
  455. // for c5, bmminer will detect board type and use it.
  456. #define RED_LED_DEV_C5 "/sys/class/leds/hps_led2/brightness"
  457. #define GREEN_LED_DEV_C5 "/sys/class/leds/hps_led0/brightness"
  458. // for xilinx, bmminer will detect board type and use it.
  459. #define RED_LED_DEV_XILINX "/sys/class/gpio/gpio943/value"
  460. #define GREEN_LED_DEV_XILINX "/sys/class/gpio/gpio944/value"
  461. // S9 , T9, R4 PIC PROGRAM
  462. #define PIC_PROGRAM "/etc/config/hash_s8_app.txt"
  463. // T9+ PIC PROGRAM
  464. #define DSPIC33EP16GS202_PIC_PROGRAM "/etc/config/dsPIC33EP16GS202_app.txt"
  465. #define TIMESLICE 60
  466. #ifdef T9_18
  467. #define IIC_ADDR_HIGH_4_BIT (0x04 << 20)
  468. #define EEPROM_ADDR_HIGH_4_BIT (0x0A << 20)
  469. #define IIC_SELECT(x) ((x & 0x03) << 26)
  470. unsigned int get_iic();
  471. unsigned char set_iic(unsigned int data);
  472. unsigned char T9_plus_write_pic_iic(bool read, bool reg_addr_valid, unsigned char reg_addr, unsigned char which_iic, unsigned char data);
  473. int dsPIC33EP16GS202_jump_to_app_from_loader(unsigned char which_iic);
  474. #else
  475. #define IIC_ADDR_HIGH_4_BIT (0x0A << 20)
  476. #endif
  477. struct init_config
  478. {
  479. uint8_t token_type;
  480. uint8_t version;
  481. uint16_t length;
  482. uint8_t reset :1;
  483. uint8_t fan_eft :1;
  484. uint8_t timeout_eft :1;
  485. uint8_t frequency_eft :1;
  486. uint8_t voltage_eft :1;
  487. uint8_t chain_check_time_eft :1;
  488. uint8_t chip_config_eft :1;
  489. uint8_t hw_error_eft :1;
  490. uint8_t beeper_ctrl :1;
  491. uint8_t temp_ctrl :1;
  492. uint8_t chain_freq_eft :1;
  493. uint8_t reserved1 :5;
  494. uint8_t reserved2[2];
  495. uint8_t chain_num;
  496. uint8_t asic_num;
  497. uint8_t fan_pwm_percent;
  498. uint8_t temperature;
  499. uint16_t frequency;
  500. uint8_t voltage[2];
  501. uint8_t chain_check_time_integer;
  502. uint8_t chain_check_time_fractions;
  503. uint8_t timeout_data_integer;
  504. uint8_t timeout_data_fractions;
  505. uint32_t reg_data;
  506. uint8_t chip_address;
  507. uint8_t reg_address;
  508. uint16_t chain_min_freq;
  509. uint16_t chain_max_freq;
  510. uint16_t crc;
  511. } __attribute__((packed, aligned(4)));
  512. struct bitmain_soc_info
  513. {
  514. cglock_t update_lock;
  515. uint8_t data_type;
  516. uint8_t version;
  517. uint16_t length;
  518. uint8_t chip_value_eft :1;
  519. uint8_t reserved1 :7;
  520. uint8_t chain_num;
  521. uint16_t reserved2;
  522. uint8_t fan_num;
  523. uint8_t temp_num;
  524. uint8_t reserved3[2];
  525. uint32_t fan_exist;
  526. uint32_t temp_exist;
  527. uint16_t diff;
  528. uint16_t reserved4;
  529. uint32_t reg_value;
  530. uint32_t chain_asic_exist[BITMAIN_MAX_CHAIN_NUM][BITMAIN_DEFAULT_ASIC_NUM/32];
  531. uint32_t chain_asic_status[BITMAIN_MAX_CHAIN_NUM][BITMAIN_DEFAULT_ASIC_NUM/32];
  532. uint8_t chain_asic_num[BITMAIN_MAX_CHAIN_NUM];
  533. uint8_t temp[BITMAIN_MAX_CHAIN_NUM];
  534. uint8_t fan_speed_value[BITMAIN_MAX_FAN_NUM];
  535. uint16_t freq[BITMAIN_MAX_CHAIN_NUM];
  536. struct thr_info *thr;
  537. pthread_t read_nonce_thr;
  538. pthread_mutex_t lock;
  539. struct init_config soc_config;
  540. int pool_no;
  541. struct pool pool0;
  542. struct pool pool1;
  543. struct pool pool2;
  544. uint32_t pool0_given_id;
  545. uint32_t pool1_given_id;
  546. uint32_t pool2_given_id;
  547. uint16_t crc;
  548. } __attribute__((packed, aligned(4)));
  549. struct part_of_job
  550. {
  551. uint8_t token_type; // buf[0]
  552. uint8_t version;
  553. uint16_t reserved;
  554. uint32_t length; // buf[1]
  555. uint8_t pool_nu; // buf[2]
  556. uint8_t new_block :1;
  557. uint8_t asic_diff_valid :1;
  558. uint8_t reserved1 :6;
  559. uint8_t asic_diff;
  560. uint8_t reserved2[1];
  561. uint32_t job_id; // buf[3]
  562. uint32_t bbversion; // buf[4]
  563. uint8_t prev_hash[32]; // buf[5] - buf[12]
  564. uint32_t ntime; // buf[13]
  565. uint32_t nbit; // buf[14]
  566. uint16_t coinbase_len; // buf[15]
  567. uint16_t nonce2_offset;
  568. uint16_t nonce2_bytes_num; // 4 or 8 bytes // buf[16]
  569. uint16_t merkles_num;
  570. uint64_t nonce2_start_value; //nonce2 start calculate value. // buf[17] - buf[18]
  571. };
  572. //uint8_t coinbase //this is variable
  573. //uint8_t merkle_bin[32] * merkles_num
  574. //uint16_t crc
  575. struct nonce_content
  576. {
  577. uint32_t job_id;
  578. uint32_t work_id;
  579. uint32_t header_version;
  580. uint64_t nonce2;
  581. uint32_t nonce3;
  582. uint32_t chain_num;
  583. uint8_t midstate[MIDSTATE_LEN];
  584. } __attribute__((packed, aligned(4)));
  585. struct nonce
  586. {
  587. uint8_t token_type;
  588. uint8_t version;
  589. uint16_t length;
  590. uint16_t valid_nonce_num;
  591. struct nonce_content nonce_cont[MAX_RETURNED_NONCE_NUM];
  592. uint16_t crc;
  593. } __attribute__((packed, aligned(4)));
  594. struct all_parameters
  595. {
  596. unsigned int *current_job_start_address;
  597. unsigned int pwm_value;
  598. unsigned int chain_exist[BITMAIN_MAX_CHAIN_NUM];
  599. unsigned int timeout;
  600. unsigned int fan_exist_map;
  601. unsigned int temp_sensor_map;
  602. unsigned int nonce_error;
  603. unsigned int chain_asic_exist[BITMAIN_MAX_CHAIN_NUM][8];
  604. unsigned int chain_asic_status[BITMAIN_MAX_CHAIN_NUM][8];
  605. signed char chain_asic_temp_num[BITMAIN_MAX_CHAIN_NUM]; // the real number of temp chip
  606. unsigned char TempChipType[BITMAIN_MAX_CHAIN_NUM][MAX_TEMPCHIP_NUM];
  607. unsigned char TempChipAddr[BITMAIN_MAX_CHAIN_NUM][MAX_TEMPCHIP_NUM]; // each temp chip's address: chip index*4, index start from 0
  608. int16_t chain_asic_temp[BITMAIN_MAX_CHAIN_NUM][MAX_TEMPCHIP_NUM][TEMP_POS_NUM]; // 4 kinds of temp
  609. int16_t chain_asic_maxtemp[BITMAIN_MAX_CHAIN_NUM][TEMP_POS_NUM]; // 4 kinds of temp
  610. int16_t chain_asic_mintemp[BITMAIN_MAX_CHAIN_NUM][TEMP_POS_NUM]; // 4 kinds of temp
  611. int8_t chain_asic_iic[CHAIN_ASIC_NUM];
  612. uint32_t chain_hw[BITMAIN_MAX_CHAIN_NUM];
  613. uint64_t chain_asic_nonce[BITMAIN_MAX_CHAIN_NUM][BITMAIN_DEFAULT_ASIC_NUM];
  614. char chain_asic_status_string[BITMAIN_MAX_CHAIN_NUM][BITMAIN_DEFAULT_ASIC_NUM+8];
  615. unsigned long long int total_nonce_num;
  616. unsigned char fan_exist[BITMAIN_MAX_FAN_NUM];
  617. unsigned int fan_speed_value[BITMAIN_MAX_FAN_NUM];
  618. int temp[BITMAIN_MAX_CHAIN_NUM];
  619. uint8_t chain_asic_num[BITMAIN_MAX_CHAIN_NUM];
  620. unsigned char check_bit;
  621. unsigned char pwm_percent;
  622. unsigned char chain_num;
  623. unsigned char fan_num;
  624. unsigned char temp_num;
  625. unsigned int fan_speed_top1;
  626. int temp_top1[TEMP_POS_NUM];
  627. int temp_low1[TEMP_POS_NUM];
  628. int temp_top1_last;
  629. unsigned char corenum;
  630. unsigned char addrInterval;
  631. unsigned char max_asic_num_in_one_chain;
  632. unsigned char baud;
  633. unsigned char diff;
  634. uint8_t fan_eft;
  635. uint8_t fan_pwm;
  636. unsigned short int frequency;
  637. char frequency_t[10];
  638. unsigned short int freq[BITMAIN_MAX_CHAIN_NUM];
  639. } __attribute__((packed, aligned(4)));
  640. struct nonce_buf
  641. {
  642. unsigned int p_wr;
  643. unsigned int p_rd;
  644. unsigned int nonce_num;
  645. struct nonce_content nonce_buffer[MAX_NONCE_NUMBER_IN_FIFO];
  646. } __attribute__((packed, aligned(4)));
  647. struct reg_content
  648. {
  649. unsigned int reg_value;
  650. unsigned char crc;
  651. unsigned char chain_number;
  652. } __attribute__((packed, aligned(4)));
  653. struct reg_buf
  654. {
  655. unsigned int p_wr;
  656. unsigned int p_rd;
  657. unsigned int reg_value_num;
  658. struct reg_content reg_buffer[MAX_NONCE_NUMBER_IN_FIFO];
  659. } __attribute__((packed, aligned(4)));
  660. struct freq_pll
  661. {
  662. const char *freq;
  663. unsigned int fildiv1;
  664. unsigned int fildiv2;
  665. unsigned int vilpll;
  666. };
  667. #define Swap32(l) (((l) >> 24) | (((l) & 0x00ff0000) >> 8) | (((l) & 0x0000ff00) << 8) | ((l) << 24))
  668. struct vil_work
  669. {
  670. uint8_t type; // Bit[7:5]: Type,fixed 0x01. Bit[4:0]:Reserved
  671. uint8_t length; // data length, from Byte0 to the end.
  672. uint8_t wc_base; // Bit[7]: Reserved. Bit[6:0]: Work count base, muti-Midstate, each Midstate corresponding work count increase one by one.
  673. uint8_t mid_num; // Bit[7:3]: Reserved Bit[2:0]: MSN, midstate num,now support 1,2,4.
  674. //uint32_t sno; // SPAT mode??Start Nonce Number Normal mode??Reserved.
  675. uint8_t midstate[32];
  676. uint8_t data2[12];
  677. };
  678. struct vil_work_1387
  679. {
  680. uint8_t work_type;
  681. uint8_t chain_id;
  682. uint8_t reserved1[2];
  683. uint32_t work_count;
  684. uint8_t data[12];
  685. uint8_t midstate[32];
  686. };
  687. static struct freq_pll freq_pll_1385[] =
  688. {
  689. {"100",0x020040, 0x0420, 0x200241},
  690. {"125",0x028040, 0x0420, 0x280241},
  691. {"150",0x030040, 0x0420, 0x300241},
  692. {"175",0x038040, 0x0420, 0x380241},
  693. {"200",0x040040, 0x0420, 0x400241},
  694. {"225",0x048040, 0x0420, 0x480241},
  695. {"250",0x050040, 0x0420, 0x500241},
  696. {"275",0x058040, 0x0420, 0x580241},
  697. {"300",0x060040, 0x0420, 0x600241},
  698. {"325",0x068040, 0x0420, 0x680241},
  699. {"350",0x070040, 0x0420, 0x700241},
  700. {"375",0x078040, 0x0420, 0x780241},
  701. {"400",0x080040, 0x0420, 0x800241},
  702. {"404",0x061040, 0x0320, 0x610231},
  703. {"406",0x041040, 0x0220, 0x410221},
  704. {"408",0x062040, 0x0320, 0x620231},
  705. {"412",0x042040, 0x0220, 0x420221},
  706. {"416",0x064040, 0x0320, 0x640231},
  707. {"418",0x043040, 0x0220, 0x430221},
  708. {"420",0x065040, 0x0320, 0x650231},
  709. {"425",0x044040, 0x0220, 0x440221},
  710. {"429",0x067040, 0x0320, 0x670231},
  711. {"431",0x045040, 0x0220, 0x450221},
  712. {"433",0x068040, 0x0320, 0x680231},
  713. {"437",0x046040, 0x0220, 0x460221},
  714. {"441",0x06a040, 0x0320, 0x6a0231},
  715. {"443",0x047040, 0x0220, 0x470221},
  716. {"445",0x06b040, 0x0320, 0x6b0231},
  717. {"450",0x048040, 0x0220, 0x480221},
  718. {"454",0x06d040, 0x0320, 0x6d0231},
  719. {"456",0x049040, 0x0220, 0x490221},
  720. {"458",0x06e040, 0x0320, 0x6e0231},
  721. {"462",0x04a040, 0x0220, 0x4a0221},
  722. {"466",0x070040, 0x0320, 0x700231},
  723. {"468",0x04b040, 0x0220, 0x4b0221},
  724. {"470",0x071040, 0x0320, 0x710231},
  725. {"475",0x04c040, 0x0220, 0x4c0221},
  726. {"479",0x073040, 0x0320, 0x730231},
  727. {"481",0x04d040, 0x0220, 0x4d0221},
  728. {"483",0x074040, 0x0320, 0x740231},
  729. {"487",0x04e040, 0x0220, 0x4e0221},
  730. {"491",0x076040, 0x0320, 0x760231},
  731. {"493",0x04f040, 0x0220, 0x4f0221},
  732. {"495",0x077040, 0x0320, 0x770231},
  733. {"500",0x050040, 0x0220, 0x500221},
  734. {"504",0x079040, 0x0320, 0x790231},
  735. {"506",0x051040, 0x0220, 0x510221},
  736. {"508",0x07a040, 0x0320, 0x7a0231},
  737. {"512",0x052040, 0x0220, 0x520221},
  738. {"516",0x07c040, 0x0320, 0x7c0231},
  739. {"518",0x053040, 0x0220, 0x530221},
  740. {"520",0x07d040, 0x0320, 0x7d0231},
  741. {"525",0x054040, 0x0220, 0x540221},
  742. {"529",0x07f040, 0x0320, 0x7f0231},
  743. {"531",0x055040, 0x0220, 0x550221},
  744. {"533",0x080040, 0x0320, 0x800231},
  745. {"537",0x056040, 0x0220, 0x560221},
  746. {"543",0x057040, 0x0220, 0x570221},
  747. {"550",0x058040, 0x0220, 0x580221},
  748. {"556",0x059040, 0x0220, 0x590221},
  749. {"562",0x05a040, 0x0220, 0x5a0221},
  750. {"568",0x05b040, 0x0220, 0x5b0221},
  751. {"575",0x05c040, 0x0220, 0x5c0221},
  752. {"581",0x05d040, 0x0220, 0x5d0221},
  753. {"587",0x05e040, 0x0220, 0x5e0221},
  754. {"593",0x05f040, 0x0220, 0x5f0221},
  755. {"600",0x060040, 0x0220, 0x600221},
  756. {"606",0x061040, 0x0220, 0x610221},
  757. {"612",0x062040, 0x0220, 0x620221},
  758. {"618",0x063040, 0x0220, 0x630221},
  759. {"625",0x064040, 0x0220, 0x640221},
  760. {"631",0x065040, 0x0220, 0x650221},
  761. {"637",0x066040, 0x0220, 0x660221},
  762. {"643",0x067040, 0x0220, 0x670221},
  763. {"650",0x068040, 0x0220, 0x680221},
  764. {"656",0x069040, 0x0220, 0x690221},
  765. {"662",0x06a040, 0x0220, 0x6a0221},
  766. {"668",0x06b040, 0x0220, 0x6b0221},
  767. {"675",0x06c040, 0x0220, 0x6c0221},
  768. {"681",0x06d040, 0x0220, 0x6d0221},
  769. {"687",0x06e040, 0x0220, 0x6e0221},
  770. {"693",0x06f040, 0x0220, 0x6f0221},
  771. {"700",0x070040, 0x0220, 0x700221},
  772. {"706",0x071040, 0x0220, 0x710221},
  773. {"712",0x072040, 0x0220, 0x720221},
  774. {"718",0x073040, 0x0220, 0x730221},
  775. {"725",0x074040, 0x0220, 0x740221},
  776. {"731",0x075040, 0x0220, 0x750221},
  777. {"737",0x076040, 0x0220, 0x760221},
  778. {"743",0x077040, 0x0220, 0x770221},
  779. {"750",0x078040, 0x0220, 0x780221},
  780. {"756",0x079040, 0x0220, 0x790221},
  781. {"762",0x07a040, 0x0220, 0x7a0221},
  782. {"768",0x07b040, 0x0220, 0x7b0221},
  783. {"775",0x07c040, 0x0220, 0x7c0221},
  784. {"781",0x07d040, 0x0220, 0x7d0221},
  785. {"787",0x07e040, 0x0220, 0x7e0221},
  786. {"793",0x07f040, 0x0220, 0x7f0221},
  787. {"800",0x080040, 0x0220, 0x800221},
  788. {"825",0x042040, 0x0120, 0x420211},
  789. {"850",0x044040, 0x0120, 0x440211},
  790. {"875",0x046040, 0x0120, 0x460211},
  791. {"900",0x048040, 0x0120, 0x480211},
  792. {"925",0x04a040, 0x0120, 0x4a0211},
  793. {"950",0x04c040, 0x0120, 0x4c0211},
  794. {"975",0x04e040, 0x0120, 0x4e0211},
  795. {"1000",0x050040, 0x0120, 0x500211},
  796. {"1025",0x052040, 0x0120, 0x520211},
  797. {"1050",0x054040, 0x0120, 0x540211},
  798. {"1075",0x056040, 0x0120, 0x560211},
  799. {"1100",0x058040, 0x0120, 0x580211},
  800. {"1125",0x05a040, 0x0120, 0x5a0211},
  801. {"1150",0x05c040, 0x0120, 0x5c0211},
  802. {"1175",0x05e040, 0x0120, 0x5e0211},
  803. };
  804. extern bool opt_bitmain_fan_ctrl;
  805. extern bool opt_bitmain_new_cmd_type_vil;
  806. extern bool opt_fixed_freq;
  807. extern bool opt_pre_heat;
  808. extern int opt_bitmain_fan_pwm;
  809. extern int opt_bitmain_soc_freq;
  810. extern int opt_bitmain_soc_voltage;
  811. extern int ADD_FREQ;
  812. extern int ADD_FREQ1;
  813. extern int fpga_version;
  814. extern int opt_multi_version;
  815. int getChainExistFlag(int chainIndex);
  816. unsigned char get_pic_voltage(unsigned char chain);
  817. int getVolValueFromPICvoltage(unsigned char vol_pic);
  818. unsigned char getPICvoltageFromValue(int vol_value);
  819. void set_pic_voltage(unsigned char chain, unsigned char voltage);
  820. int getChainAsicNum(int chainIndex);
  821. int readRebootTestNum();
  822. int send_job(unsigned char *buf);
  823. #endif