driver-avalon.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_DEFAULT_FAN_MAX_PWM 0xA0 /* 100% */
  21. #define AVALON_DEFAULT_FAN_MIN_PWM 0x20 /* 20% */
  22. #define AVALON_DEFAULT_TIMEOUT 0x2D
  23. #define AVALON_DEFAULT_FREQUENCY 282
  24. #define AVALON_DEFAULT_MINER_NUM 0x20
  25. #define AVALON_DEFAULT_ASIC_NUM 0xA
  26. #define AVALON_FTDI_READSIZE 510
  27. #define AVALON_USB_PACKETSIZE 512
  28. #define AVALON_READBUF_SIZE 8192
  29. #define AVALON_RESET_TIMEOUT 100
  30. #define AVALON_READ_TIMEOUT 18 /* Enough to only half fill the buffer */
  31. #define AVALON_LATENCY 1
  32. struct avalon_task {
  33. uint8_t reset :1;
  34. uint8_t flush_fifo :1;
  35. uint8_t fan_eft :1;
  36. uint8_t timer_eft :1;
  37. uint8_t asic_num :4;
  38. uint8_t fan_pwm_data;
  39. uint8_t timeout_data;
  40. uint8_t miner_num;
  41. uint8_t nonce_elf :1;
  42. uint8_t gate_miner_elf :1;
  43. uint8_t asic_pll :1;
  44. uint8_t gate_miner :1;
  45. uint8_t _pad0 :4;
  46. uint8_t _pad1[3];
  47. uint32_t _pad2;
  48. uint8_t midstate[32];
  49. uint8_t data[12];
  50. } __attribute__((packed, aligned(4)));
  51. struct avalon_result {
  52. uint32_t nonce;
  53. uint8_t data[12];
  54. uint8_t midstate[32];
  55. uint8_t fan0;
  56. uint8_t fan1;
  57. uint8_t fan2;
  58. uint8_t temp0;
  59. uint8_t temp1;
  60. uint8_t temp2;
  61. uint8_t _pad0[2];
  62. uint16_t fifo_wp;
  63. uint16_t fifo_rp;
  64. uint8_t chip_num;
  65. uint8_t pwm_data;
  66. uint8_t timeout;
  67. uint8_t miner_num;
  68. } __attribute__((packed, aligned(4)));
  69. struct avalon_info {
  70. int baud;
  71. int miner_count;
  72. int asic_count;
  73. int timeout;
  74. int fan0;
  75. int fan1;
  76. int fan2;
  77. int temp0;
  78. int temp1;
  79. int temp2;
  80. int temp_max;
  81. int temp_history_count;
  82. int temp_history_index;
  83. int temp_sum;
  84. int temp_old;
  85. int fan_pwm;
  86. int no_matching_work;
  87. int matching_work[AVALON_DEFAULT_MINER_NUM];
  88. int frequency;
  89. struct thr_info *thr;
  90. pthread_t read_thr;
  91. pthread_t write_thr;
  92. pthread_mutex_t lock;
  93. pthread_mutex_t qlock;
  94. pthread_cond_t qcond;
  95. cgsem_t write_sem;
  96. int nonces;
  97. bool idle;
  98. bool reset;
  99. };
  100. #define AVALON_WRITE_SIZE (sizeof(struct avalon_task))
  101. #define AVALON_READ_SIZE (sizeof(struct avalon_result))
  102. #define AVALON_ARRAY_SIZE 3
  103. #define AVA_GETS_ERROR -1
  104. #define AVA_GETS_OK 0
  105. #define AVA_SEND_ERROR -1
  106. #define AVA_SEND_OK 0
  107. #define avalon_buffer_full(avalon) !usb_ftdi_cts(avalon)
  108. #define AVALON_READ_TIME(baud) ((double)AVALON_READ_SIZE * (double)8.0 / (double)(baud))
  109. #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1]
  110. ASSERT1(sizeof(uint32_t) == 4);
  111. extern struct avalon_info **avalon_info;
  112. #endif /* USE_AVALON */
  113. #endif /* AVALON_H */