driver-hashfast.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2013 Hashfast
  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 HASHFAST_H
  11. #define HASHFAST_H
  12. #ifdef USE_HASHFAST
  13. #include "miner.h"
  14. #include "elist.h"
  15. #include "hf_protocol.h"
  16. extern int opt_hfa_ntime_roll;
  17. extern int opt_hfa_hash_clock;
  18. extern int opt_hfa_overheat;
  19. extern int opt_hfa_target;
  20. extern bool opt_hfa_pll_bypass;
  21. extern bool opt_hfa_dfu_boot;
  22. extern int opt_hfa_fan_default;
  23. extern int opt_hfa_fan_max;
  24. extern int opt_hfa_fan_min;
  25. extern int opt_hfa_fail_drop;
  26. extern bool opt_hfa_noshed;
  27. extern char *set_hfa_fan(char *arg);
  28. extern char *opt_hfa_name;
  29. extern char *opt_hfa_options;
  30. #define HASHFAST_MINER_THREADS 1
  31. #define HFA_CLOCK_DEFAULT 550
  32. #define HFA_CLOCK_MIN 125
  33. #define HFA_CLOCK_MAX 1000
  34. #define HFA_CLOCK_MAXDIFF 100
  35. #define HFA_TEMP_OVERHEAT 95
  36. #define HFA_TEMP_TARGET 88
  37. #define HFA_TEMP_HYSTERESIS 3
  38. #define HFA_FAN_DEFAULT 33
  39. #define HFA_FAN_MAX 85
  40. #define HFA_FAN_MIN 5
  41. #define HFA_VOLTAGE_MAX 1000
  42. #define HFA_VOLTAGE_MIN 500
  43. #define HFA_MAGIC_SETTINGS_VALUE 0x42AA
  44. // # Factory Operation Codes
  45. #define OP_SETTINGS 55 // Read or write settings
  46. #define OP_POWER 57
  47. // Matching fields for hf_statistics, but large #s for local accumulation, per-die
  48. struct hf_long_statistics {
  49. uint64_t rx_header_crc; // Header CRCs
  50. uint64_t rx_body_crc; // Data CRCs
  51. uint64_t rx_header_timeouts; // Header timeouts
  52. uint64_t rx_body_timeouts; // Data timeouts
  53. uint64_t core_nonce_fifo_full; // Core nonce Q overrun events
  54. uint64_t array_nonce_fifo_full; // System nonce Q overrun events
  55. uint64_t stats_overrun; // Overrun in statistics reporting
  56. };
  57. // Matching fields for hf_usb_stats1, but large #s for local accumulation, per device
  58. struct hf_long_usb_stats1 {
  59. // USB incoming
  60. uint64_t usb_rx_preambles;
  61. uint64_t usb_rx_receive_byte_errors;
  62. uint64_t usb_rx_bad_hcrc;
  63. // USB outgoing
  64. uint64_t usb_tx_attempts;
  65. uint64_t usb_tx_packets;
  66. uint64_t usb_tx_timeouts;
  67. uint64_t usb_tx_incompletes;
  68. uint64_t usb_tx_endpointstalled;
  69. uint64_t usb_tx_disconnected;
  70. uint64_t usb_tx_suspended;
  71. #if 0
  72. /* We don't care about UART stats */
  73. // UART transmit
  74. uint64_t uart_tx_queue_dma;
  75. uint64_t uart_tx_interrupts;
  76. // UART receive
  77. uint64_t uart_rx_preamble_ints;
  78. uint64_t uart_rx_missed_preamble_ints;
  79. uint64_t uart_rx_header_done;
  80. uint64_t uart_rx_data_done;
  81. uint64_t uart_rx_bad_hcrc;
  82. uint64_t uart_rx_bad_dma;
  83. uint64_t uart_rx_short_dma;
  84. uint64_t uart_rx_buffers_full;
  85. #endif
  86. uint8_t max_tx_buffers;
  87. uint8_t max_rx_buffers;
  88. };
  89. /* Private per die data for dynamic clocking */
  90. struct hf_die_data {
  91. int hash_clock;
  92. double temp;
  93. double board_temp;
  94. time_t last_restart;
  95. };
  96. struct hashfast_info {
  97. struct cgpu_info *cgpu; // Points back to parent structure
  98. struct cgpu_info *old_cgpu ; // Points to old structure if hotplugged same device
  99. int asic_count; // # of chips in the chain
  100. int core_count; // # of cores per chip
  101. int device_type; // What sort of device this is
  102. int num_sequence; // A power of 2. What the sequence number range is.
  103. int ref_frequency; // Reference clock rate
  104. struct hf_g1_die_data *die_status; // Array of per-die voltage, current, temperature sensor data
  105. struct hf_long_statistics *die_statistics; // Array of per-die error counters
  106. struct hf_long_usb_stats1 stats1;
  107. struct hf_die_data *die_data;
  108. double firmware_version;
  109. double hardware_version;
  110. int hash_clock_rate; // Hash clock rate to use, in Mhz
  111. int base_clock; // Clock rate we actually got
  112. struct hf_usb_init_base usb_init_base; // USB Base information from USB_INIT
  113. struct hf_config_data config_data; // Configuration data used from USB_INIT
  114. int core_bitmap_size; // in bytes
  115. uint32_t *core_bitmap; // Core OK bitmap test results, run with PLL Bypassed
  116. int group_ntime_roll; // Total ntime roll amount per group
  117. int core_ntime_roll; // Total core ntime roll amount
  118. uint32_t serial_number; // db->serial_number if it exists
  119. char op_name[36];
  120. bool has_opname;
  121. bool opname_valid;
  122. pthread_mutex_t lock;
  123. pthread_mutex_t rlock;
  124. struct work **works;
  125. uint16_t hash_sequence_head; // HOST: The next hash sequence # to be sent
  126. uint16_t hash_sequence_tail; // HOST: Follows device_sequence_tail around to free work
  127. uint16_t device_sequence_head; // DEVICE: The most recent sequence number the device dispatched
  128. uint16_t device_sequence_tail; // DEVICE: The most recently completed job in the device
  129. int64_t hash_count;
  130. uint64_t raw_hashes;
  131. uint64_t calc_hashes;
  132. uint16_t shed_count; // Dynamic copy of #cores device has shed for thermal control
  133. int no_matching_work;
  134. int resets;
  135. int overheat;
  136. int last_max_temp;
  137. int temp_updates;
  138. int fanspeed; // Fanspeed in percent
  139. int last_die_adjusted;
  140. int clock_offset;
  141. int hash_voltage; // Hash voltage to use, in mV
  142. pthread_t read_thr;
  143. time_t last_restart;
  144. time_t last_send;
  145. };
  146. #endif /* USE_HASHFAST */
  147. #endif /* HASHFAST_H */