driver-gridseed.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef INCLUDE_DRIVER_GRIDSEED_H
  2. #define INCLUDE_DRIVER_GRIDSEED_H
  3. #ifdef USE_GRIDSEED
  4. #include "util.h"
  5. #define GRIDSEED_MINER_THREADS 1
  6. #define GRIDSEED_LATENCY 4
  7. #define GRIDSEED_DEFAULT_BAUD 115200
  8. #define GRIDSEED_DEFAULT_FREQUENCY 600
  9. #define GRIDSEED_DEFAULT_CHIPS 5
  10. #define GRIDSEED_MAX_CHIPS 256
  11. #define GRIDSEED_DEFAULT_MODULES 1
  12. #define GRIDSEED_DEFAULT_USEFIFO 0
  13. #define GRIDSEED_DEFAULT_BTCORE 16
  14. #define GRIDSEED_COMMAND_DELAY 20
  15. #define GRIDSEED_READ_SIZE 12
  16. #define GRIDSEED_MCU_QUEUE_LEN 8
  17. #define GRIDSEED_SOFT_QUEUE_LEN (GRIDSEED_MCU_QUEUE_LEN+2)
  18. #define GRIDSEED_READBUF_SIZE 8192
  19. #define GRIDSEED_HASH_SPEED ((double)0.0851128926) // in ms
  20. #define GRIDSEED_F_IN 25 // input frequency
  21. #define GRIDSEED_MIN_FREQUENCY 13
  22. #define GRIDSEED_MAX_FREQUENCY 1600
  23. #define GRIDSEED_PROXY_PORT 3350
  24. #define GRIDSEED_PERIPH_BASE ((uint32_t)0x40000000)
  25. #define GRIDSEED_APB2PERIPH_BASE (GRIDSEED_PERIPH_BASE + 0x10000)
  26. #define GRIDSEED_GPIOA_BASE (GRIDSEED_APB2PERIPH_BASE + 0x0800)
  27. #define GRIDSEED_GPIOB_BASE (GRIDSEED_APB2PERIPH_BASE + 0x0c00)
  28. #define GRIDSEED_CRL_OFFSET 0x00
  29. #define GRIDSEED_ODR_OFFSET 0x0c
  30. #define GRIDSEED_USB_ID_MODEL_STR "STM32_Virtual_COM_Port"
  31. #define transfer(gridseed, request_type, bRequest, wValue, wIndex, cmd) \
  32. _transfer(gridseed, request_type, bRequest, wValue, wIndex, NULL, 0, cmd)
  33. enum gsd_mode {
  34. MODE_UNK = 0,
  35. MODE_SHA256, // Solo mining in sha256 mode, no proxy requests (yet)
  36. MODE_SHA256_DUAL, // Mining sha256 directly, providing proxy for scrypt mining
  37. MODE_SCRYPT, // Solo mining in scrypt mode
  38. MODE_SCRYPT_DUAL // Mining scrypt via proxy through a sha256 dual miner
  39. };
  40. #define MODE_UNK_STR "Unknown"
  41. #define MODE_SHA256_STR "sha256"
  42. #define MODE_SHA256_DUAL_STR "sha256 / scrypt"
  43. #define MODE_SCRYPT_STR "scrypt"
  44. #define MODE_SCRYPT_DUAL_STR "scrypt via proxy"
  45. #define SHA256_MODE(mode) ((mode) == MODE_SHA256 || (mode) == MODE_SHA256_DUAL)
  46. #define SCRYPT_MODE(mode) ((mode) == MODE_SCRYPT || (mode) == MODE_SCRYPT_DUAL)
  47. typedef struct s_gridseed_info {
  48. // device
  49. enum sub_ident ident;
  50. uint32_t fw_version;
  51. char id[24];
  52. int device_fd;
  53. int using_libusb;
  54. bool serial_reopen;
  55. // statistics
  56. int nonce_count[GRIDSEED_MAX_CHIPS]; // per chip
  57. int error_count[GRIDSEED_MAX_CHIPS]; // per chip
  58. struct timeval scanhash_time;
  59. // options
  60. int baud;
  61. int freq;
  62. unsigned char cmd_freq[8];
  63. unsigned char cmd_btc_baud[8];
  64. int chips; //chips per module
  65. int modules;
  66. int usefifo;
  67. int btcore;
  68. int voltage;
  69. int led;
  70. int per_chip_stats;
  71. // runtime
  72. struct thr_info *thr;
  73. pthread_t th_read;
  74. pthread_t th_send;
  75. pthread_t th_packet;
  76. pthread_mutex_t lock;
  77. pthread_mutex_t qlock;
  78. enum gsd_mode mode;
  79. // state
  80. // sha
  81. int queued;
  82. int dev_queue_len;
  83. int soft_queue_len;
  84. struct work *workqueue[GRIDSEED_SOFT_QUEUE_LEN];
  85. int needworks; /* how many works need to be queue for device */
  86. bool query_qlen; /* true when query device queue length and waiting response */
  87. cgtimer_t query_ts;
  88. // sha & scrypt
  89. int workdone;
  90. // scrypt
  91. struct work *ltc_work;
  92. struct timeval ltc_workstart;
  93. int hashes_per_ms;
  94. // proxy
  95. int sockltc;
  96. short ltc_port;
  97. struct sockaddr_in toaddr; /* remote address to send response */
  98. cgsem_t psem;
  99. } GRIDSEED_INFO;
  100. enum packet_type {
  101. PACKET_PING,
  102. PACKET_INFO,
  103. PACKET_WORK,
  104. PACKET_NONCE
  105. };
  106. typedef struct s_gridseed_packet {
  107. enum packet_type type;
  108. union {
  109. struct {
  110. char id[24];
  111. int freq;
  112. int chips;
  113. int modules;
  114. } info;
  115. struct {
  116. unsigned char target[32];
  117. unsigned char midstate[32];
  118. unsigned char data[128];
  119. int id;
  120. } work;
  121. struct {
  122. uint32_t nonce;
  123. int workid;
  124. } nonce;
  125. };
  126. } GRIDSEED_PACKET;
  127. extern struct device_drv gridseed_drv;
  128. #endif /* USE_GRIDSEED */
  129. #endif /* INCLUDE_DRIVER_GRIDSEED_H */