driver-avalon.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright 2013 Avalon project
  3. * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org>
  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 AVALON_H
  11. #define AVALON_H
  12. #ifdef USE_AVALON
  13. #include "util.h"
  14. #define AVALON_RESET_FAULT_DECISECONDS 1
  15. #define AVALON_MINER_THREADS 1
  16. #define AVALON_IO_SPEED 115200
  17. #define AVALON_HASH_TIME_FACTOR ((float)1.67/0x32)
  18. #define AVALON_RESET_PITCH (300*1000*1000)
  19. #define AVALON_A3256 110
  20. #define AVALON_A3255 55
  21. #define AVALON_FAN_FACTOR 120
  22. #define AVALON_PWM_MAX 0xA0
  23. #define AVALON_DEFAULT_FAN_MIN 20
  24. #define AVALON_DEFAULT_FAN_MAX 100
  25. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  26. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  27. #define AVALON_TEMP_TARGET 50
  28. #define AVALON_TEMP_HYSTERESIS 3
  29. #define AVALON_TEMP_OVERHEAT 60
  30. /* Avalon-based BitBurner. */
  31. #define BITBURNER_DEFAULT_CORE_VOLTAGE 1200 /* in millivolts */
  32. #define BITBURNER_MIN_COREMV 1000
  33. /* change here if you want to risk killing it :) */
  34. #define BITBURNER_MAX_COREMV 1400
  35. /* BitFury-based BitBurner. */
  36. #define BITBURNER_FURY_DEFAULT_CORE_VOLTAGE 900 /* in millivolts */
  37. #define BITBURNER_FURY_MIN_COREMV 700
  38. /* change here if you want to risk killing it :) */
  39. #define BITBURNER_FURY_MAX_COREMV 1100
  40. #define AVALON_DEFAULT_TIMEOUT 0x2D
  41. #define AVALON_MIN_FREQUENCY 256
  42. #define AVALON_MAX_FREQUENCY 2000
  43. #define AVALON_TIMEOUT_FACTOR 12690
  44. #define AVALON_DEFAULT_FREQUENCY 282
  45. #define AVALON_DEFAULT_MINER_NUM 0x20
  46. #define AVALON_MAX_MINER_NUM 0x100
  47. #define AVALON_DEFAULT_ASIC_NUM 0xA
  48. /* Default number of miners for Bitburner Fury is for a stack of 8 boards,
  49. but it will work acceptably for smaller stacks, too */
  50. #define BITBURNER_FURY_DEFAULT_MINER_NUM 128
  51. #define BITBURNER_FURY_DEFAULT_FREQUENCY 256
  52. #define BITBURNER_FURY_DEFAULT_TIMEOUT 50
  53. #define AVALON_AUTO_CYCLE 1024
  54. #define AVALON_FTDI_READSIZE 510
  55. #define AVALON_READBUF_SIZE 8192
  56. /* Set latency to just less than full 64 byte packet size at 115200 baud */
  57. #define AVALON_LATENCY 4
  58. struct avalon_task {
  59. uint8_t reset :1;
  60. uint8_t flush_fifo :1;
  61. uint8_t fan_eft :1;
  62. uint8_t timer_eft :1;
  63. uint8_t asic_num :4;
  64. uint8_t fan_pwm_data;
  65. uint8_t timeout_data;
  66. uint8_t miner_num;
  67. uint8_t nonce_elf :1;
  68. uint8_t gate_miner_elf :1;
  69. uint8_t asic_pll :1;
  70. uint8_t gate_miner :1;
  71. uint8_t _pad0 :4;
  72. uint8_t _pad1[3];
  73. uint32_t _pad2;
  74. uint8_t midstate[32];
  75. uint8_t data[12];
  76. } __attribute__((packed, aligned(4)));
  77. struct avalon_result {
  78. uint32_t nonce;
  79. uint8_t data[12];
  80. uint8_t midstate[32];
  81. uint8_t fan0;
  82. uint8_t fan1;
  83. uint8_t fan2;
  84. uint8_t temp0;
  85. uint8_t temp1;
  86. uint8_t temp2;
  87. uint8_t _pad0[2];
  88. uint16_t fifo_wp;
  89. uint16_t fifo_rp;
  90. uint8_t chip_num;
  91. uint8_t pwm_data;
  92. uint8_t timeout;
  93. uint8_t miner_num;
  94. } __attribute__((packed, aligned(4)));
  95. struct avalon_info {
  96. int baud;
  97. int miner_count;
  98. int asic_count;
  99. int timeout;
  100. int fan0;
  101. int fan1;
  102. int fan2;
  103. int temp0;
  104. int temp1;
  105. int temp2;
  106. int temp_history_count;
  107. int temp_history_index;
  108. int temp_sum;
  109. int temp_old;
  110. int fan_pwm;
  111. int core_voltage;
  112. int no_matching_work;
  113. int matching_work[AVALON_MAX_MINER_NUM];
  114. int frequency;
  115. uint32_t asic;
  116. uint32_t ctlr_ver;
  117. struct thr_info *thr;
  118. pthread_t read_thr;
  119. pthread_t write_thr;
  120. pthread_mutex_t lock;
  121. pthread_mutex_t qlock;
  122. cgsem_t qsem;
  123. cgtimer_t cgsent;
  124. int send_delay;
  125. int nonces;
  126. int auto_queued;
  127. int auto_nonces;
  128. int auto_hw;
  129. int increment;
  130. int decrement;
  131. int idle;
  132. bool reset;
  133. bool overheat;
  134. bool optimal;
  135. uint8_t version1;
  136. uint8_t version2;
  137. uint8_t version3;
  138. };
  139. #define BITBURNER_VERSION1 1
  140. #define BITBURNER_VERSION2 0
  141. #define BITBURNER_VERSION3 0
  142. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  143. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  144. #define AVALON_ARRAY_SIZE 3
  145. #define BITBURNER_ARRAY_SIZE 4
  146. #define AVA_GETS_ERROR -1
  147. #define AVA_GETS_OK 0
  148. #define AVA_SEND_ERROR -1
  149. #define AVA_SEND_OK 0
  150. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  151. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  152. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  153. ASSERT1(sizeof(uint32_t) == 4);
  154. extern struct avalon_info **avalon_info;
  155. extern int opt_avalon_temp;
  156. extern int opt_avalon_overheat;
  157. extern int opt_avalon_fan_min;
  158. extern int opt_avalon_fan_max;
  159. extern int opt_avalon_freq_min;
  160. extern int opt_avalon_freq_max;
  161. extern bool opt_avalon_auto;
  162. extern int opt_bitburner_core_voltage;
  163. extern int opt_bitburner_fury_core_voltage;
  164. extern char *set_avalon_fan(char *arg);
  165. extern char *set_avalon_freq(char *arg);
  166. #endif /* USE_AVALON */
  167. #endif /* AVALON_H */