A1-common.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef A1_COMMON_H
  2. #define A1_COMMON_H
  3. #include <stddef.h>
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. /********** work queue */
  7. struct work_ent {
  8. struct work *work;
  9. struct list_head head;
  10. };
  11. struct work_queue {
  12. int num_elems;
  13. struct list_head head;
  14. };
  15. /********** chip and chain context structures */
  16. /* the WRITE_JOB command is the largest (2 bytes command, 56 bytes payload) */
  17. #define WRITE_JOB_LENGTH 58
  18. #define MAX_CHAIN_LENGTH 64
  19. /*
  20. * For commands to traverse the chain, we need to issue dummy writes to
  21. * keep SPI clock running. To reach the last chip in the chain, we need to
  22. * write the command, followed by chain-length words to pass it through the
  23. * chain and another chain-length words to get the ACK back to host
  24. */
  25. #define MAX_CMD_LENGTH (WRITE_JOB_LENGTH + MAX_CHAIN_LENGTH * 2 * 2)
  26. struct A1_chip {
  27. int num_cores;
  28. int last_queued_id;
  29. struct work *work[4];
  30. /* stats */
  31. int hw_errors;
  32. int stales;
  33. int nonces_found;
  34. int nonce_ranges_done;
  35. /* systime in ms when chip was disabled */
  36. int cooldown_begin;
  37. /* number of consecutive failures to access the chip */
  38. int fail_count;
  39. /* mark chip disabled, do not try to re-enable it */
  40. bool disabled;
  41. };
  42. struct A1_chain {
  43. int chain_id;
  44. struct cgpu_info *cgpu;
  45. struct mcp4x *trimpot;
  46. int num_chips;
  47. int num_cores;
  48. int num_active_chips;
  49. int chain_skew;
  50. uint8_t spi_tx[MAX_CMD_LENGTH];
  51. uint8_t spi_rx[MAX_CMD_LENGTH];
  52. struct spi_ctx *spi_ctx;
  53. struct A1_chip *chips;
  54. pthread_mutex_t lock;
  55. struct work_queue active_wq;
  56. /* mark chain disabled, do not try to re-enable it */
  57. bool disabled;
  58. uint8_t temp;
  59. int last_temp_time;
  60. };
  61. #define MAX_CHAINS_PER_BOARD 2
  62. struct A1_board {
  63. int board_id;
  64. int num_chains;
  65. struct A1_chain *chain[MAX_CHAINS_PER_BOARD];
  66. };
  67. /********** config paramters */
  68. struct A1_config_options {
  69. int ref_clk_khz;
  70. int sys_clk_khz;
  71. int spi_clk_khz;
  72. /* limit chip chain to this number of chips (testing only) */
  73. int override_chip_num;
  74. int wiper;
  75. };
  76. /* global configuration instance */
  77. extern struct A1_config_options A1_config_options;
  78. #endif /* A1_COMMON_H */