driver-bitfury.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * bitfury.c - cgminer worker for bitfury chip/board
  3. *
  4. * Copyright (c) 2013 bitfury
  5. * Copyright (c) 2013 legkodymov
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see http://www.gnu.org/licenses/.
  18. **/
  19. #include "miner.h"
  20. #include <unistd.h>
  21. #include <sha2.h>
  22. #include "libbitfury.h"
  23. #include "util.h"
  24. #define GOLDEN_BACKLOG 5
  25. struct device_drv bitfury_drv;
  26. // Forward declarations
  27. static void bitfury_disable(struct thr_info* thr);
  28. static bool bitfury_prepare(struct thr_info *thr);
  29. static void bitfury_detect(void)
  30. {
  31. struct cgpu_info *bitfury_info;
  32. applog(LOG_INFO, "INFO: bitfury_detect");
  33. libbitfury_detectChips();
  34. bitfury_info = calloc(1, sizeof(struct cgpu_info));
  35. bitfury_info->drv = &bitfury_drv;
  36. bitfury_info->threads = 1;
  37. add_cgpu(bitfury_info);
  38. }
  39. static uint32_t bitfury_checkNonce(struct work *work, uint32_t nonce)
  40. {
  41. applog(LOG_INFO, "INFO: bitfury_checkNonce");
  42. }
  43. static int64_t bitfury_scanHash(struct thr_info *thr)
  44. {
  45. int i;
  46. unsigned char sendbuf[44];
  47. unsigned int res[16];
  48. unsigned char flipped_data[81];
  49. unsigned char *work_hex;
  50. unsigned char *mid_hex;
  51. unsigned hashMerkleRoot7;
  52. unsigned ntime, nbits, nnonce;
  53. static struct work *owork; //old work
  54. struct work *work;
  55. int j;
  56. work = get_queued(thr->cgpu);
  57. if (work == NULL) {
  58. return 0;
  59. }
  60. flipped_data[80]= '\0';
  61. flip80(flipped_data, work->data);
  62. work_hex = bin2hex(flipped_data, 80);
  63. hashMerkleRoot7 = *(unsigned *)(flipped_data + 64);
  64. ntime = *(unsigned *)(flipped_data + 68);
  65. nbits = *(unsigned *)(flipped_data + 72);
  66. nnonce = *(unsigned *)(flipped_data + 76);
  67. applog(LOG_INFO, "INFO bitfury_scanHash MS0: %08x, ", ((unsigned int *)work->midstate)[0]);
  68. applog(LOG_INFO, "INFO merkle[7]: %08x, ntime: %08x, nbits: %08x, nnonce: %08x",
  69. hashMerkleRoot7, ntime, nbits, nnonce);
  70. libbitfury_sendHashData(work->midstate, hashMerkleRoot7, ntime, nbits, nnonce);
  71. i = libbitfury_readHashData(res);
  72. for (j = i - 1; j >= 0; j--) {
  73. if (owork) {
  74. submit_nonce(thr, owork, bswap_32(res[j]));
  75. }
  76. }
  77. if (owork)
  78. work_completed(thr->cgpu, owork);
  79. owork = work;
  80. return 0xffffffffull * i;
  81. }
  82. static void bitfury_statline_before(char *buf, struct cgpu_info *cgpu)
  83. {
  84. applog(LOG_INFO, "INFO bitfury_statline_before");
  85. }
  86. static bool bitfury_prepare(struct thr_info *thr)
  87. {
  88. struct timeval now;
  89. struct cgpu_info *cgpu = thr->cgpu;
  90. cgtime(&now);
  91. get_datestamp(cgpu->init, &now);
  92. applog(LOG_INFO, "INFO bitfury_prepare");
  93. return true;
  94. }
  95. static void bitfury_shutdown(struct thr_info *thr)
  96. {
  97. applog(LOG_INFO, "INFO bitfury_shutdown");
  98. }
  99. static void bitfury_disable(struct thr_info *thr)
  100. {
  101. applog(LOG_INFO, "INFO bitfury_disable");
  102. }
  103. struct device_drv bitfury_drv = {
  104. .drv_id = DRIVER_BITFURY,
  105. .dname = "bitfury",
  106. .name = "BITFURY",
  107. .drv_detect = bitfury_detect,
  108. .get_statline_before = bitfury_statline_before,
  109. .thread_prepare = bitfury_prepare,
  110. .scanwork = bitfury_scanHash,
  111. .thread_shutdown = bitfury_shutdown,
  112. .hash_work = hash_queued_work,
  113. };