driver-avalon.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2013 Avalon project
  3. * Copyright 2013 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_FAN_FACTOR 120
  20. #define AVALON_PWM_MAX 0xA0
  21. #define AVALON_DEFAULT_FAN_MIN 20
  22. #define AVALON_DEFAULT_FAN_MAX 100
  23. #define AVALON_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  24. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  25. #define AVALON_TEMP_TARGET 50
  26. #define AVALON_TEMP_HYSTERESIS 3
  27. #define AVALON_TEMP_OVERHEAT 60
  28. #define BITBURNER_DEFAULT_CORE_VOLTAGE 1200 /* in millivolts */
  29. #define AVALON_DEFAULT_TIMEOUT 0x2D
  30. #define AVALON_MIN_FREQUENCY 256
  31. #define AVALON_MAX_FREQUENCY 450
  32. #define AVALON_TIMEOUT_FACTOR 12690
  33. #define AVALON_DEFAULT_FREQUENCY 282
  34. #define AVALON_DEFAULT_MINER_NUM 0x20
  35. #define AVALON_DEFAULT_ASIC_NUM 0xA
  36. #define AVALON_AUTO_CYCLE 1024
  37. #define AVALON_FTDI_READSIZE 510
  38. #define AVALON_USB_PACKETSIZE 512
  39. #define AVALON_READBUF_SIZE 8192
  40. #define AVALON_RESET_TIMEOUT 100
  41. #define AVALON_READ_TIMEOUT 18 /* Enough to only half fill the buffer */
  42. #define AVALON_LATENCY 1
  43. struct avalon_task {
  44. uint8_t reset :1;
  45. uint8_t flush_fifo :1;
  46. uint8_t fan_eft :1;
  47. uint8_t timer_eft :1;
  48. uint8_t asic_num :4;
  49. uint8_t fan_pwm_data;
  50. uint8_t timeout_data;
  51. uint8_t miner_num;
  52. uint8_t nonce_elf :1;
  53. uint8_t gate_miner_elf :1;
  54. uint8_t asic_pll :1;
  55. uint8_t gate_miner :1;
  56. uint8_t _pad0 :4;
  57. uint8_t _pad1[3];
  58. uint32_t _pad2;
  59. uint8_t midstate[32];
  60. uint8_t data[12];
  61. } __attribute__((packed, aligned(4)));
  62. struct avalon_result {
  63. uint32_t nonce;
  64. uint8_t data[12];
  65. uint8_t midstate[32];
  66. uint8_t fan0;
  67. uint8_t fan1;
  68. uint8_t fan2;
  69. uint8_t temp0;
  70. uint8_t temp1;
  71. uint8_t temp2;
  72. uint8_t _pad0[2];
  73. uint16_t fifo_wp;
  74. uint16_t fifo_rp;
  75. uint8_t chip_num;
  76. uint8_t pwm_data;
  77. uint8_t timeout;
  78. uint8_t miner_num;
  79. } __attribute__((packed, aligned(4)));
  80. struct avalon_info {
  81. int baud;
  82. int miner_count;
  83. int asic_count;
  84. int timeout;
  85. int fan0;
  86. int fan1;
  87. int fan2;
  88. int temp0;
  89. int temp1;
  90. int temp2;
  91. int temp_max;
  92. int temp_history_count;
  93. int temp_history_index;
  94. int temp_sum;
  95. int temp_old;
  96. int fan_pwm;
  97. int core_voltage;
  98. int no_matching_work;
  99. int matching_work[AVALON_DEFAULT_MINER_NUM];
  100. int frequency;
  101. struct thr_info *thr;
  102. pthread_t read_thr;
  103. pthread_t write_thr;
  104. pthread_mutex_t lock;
  105. pthread_mutex_t qlock;
  106. pthread_cond_t qcond;
  107. cgsem_t write_sem;
  108. int nonces;
  109. int auto_queued;
  110. int auto_nonces;
  111. int auto_hw;
  112. int idle;
  113. bool reset;
  114. bool overheat;
  115. bool optimal;
  116. };
  117. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  118. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  119. #define AVALON_ARRAY_SIZE 3
  120. #define AVA_GETS_ERROR -1
  121. #define AVA_GETS_OK 0
  122. #define AVA_SEND_ERROR -1
  123. #define AVA_SEND_OK 0
  124. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  125. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  126. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  127. ASSERT1(sizeof(uint32_t) == 4);
  128. extern struct avalon_info **avalon_info;
  129. extern int opt_avalon_temp;
  130. extern int opt_avalon_overheat;
  131. extern int opt_avalon_fan_min;
  132. extern int opt_avalon_fan_max;
  133. extern int opt_avalon_freq_min;
  134. extern int opt_avalon_freq_max;
  135. extern bool opt_avalon_auto;
  136. extern int opt_bitburner_core_voltage;
  137. extern char *set_avalon_fan(char *arg);
  138. extern char *set_avalon_freq(char *arg);
  139. #endif /* USE_AVALON */
  140. #endif /* AVALON_H */