driver-bitfury.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. int chip_n;
  32. struct cgpu_info *bitfury_info;
  33. applog(LOG_INFO, "INFO: bitfury_detect");
  34. chip_n = libbitfury_detectChips();
  35. if (!chip_n) {
  36. applog(LOG_WARNING, "No Bitfury chips detected!");
  37. return;
  38. } else {
  39. applog(LOG_WARNING, "BITFURY: %d chips detected!", chip_n);
  40. }
  41. bitfury_info = calloc(1, sizeof(struct cgpu_info));
  42. bitfury_info->drv = &bitfury_drv;
  43. bitfury_info->threads = 1;
  44. bitfury_info->chip_n = chip_n;
  45. add_cgpu(bitfury_info);
  46. }
  47. static uint32_t bitfury_checkNonce(struct work *work, uint32_t nonce)
  48. {
  49. applog(LOG_INFO, "INFO: bitfury_checkNonce");
  50. }
  51. static int64_t bitfury_scanHash(struct thr_info *thr)
  52. {
  53. static struct bitfury_device devices[100];
  54. int chip_n;
  55. int chip;
  56. uint64_t hashes = 0;
  57. chip_n = thr->cgpu->chip_n;
  58. for (chip = 0; chip < chip_n; chip++) {
  59. if(!devices[chip].work) {
  60. devices[chip].work = get_queued(thr->cgpu);
  61. if (devices[chip].work == NULL) {
  62. return 0;
  63. }
  64. work_to_payload(&(devices[chip].payload), devices[chip].work);
  65. }
  66. }
  67. libbitfury_sendHashData(devices, chip_n);
  68. for (chip = 0; chip < chip_n; chip++) {
  69. if (devices[chip].job_switched) {
  70. int i,j;
  71. int *res = devices[chip].results;
  72. struct work *owork = devices[chip].owork;
  73. i = devices[chip].results_n;
  74. for (j = i - 1; j >= 0; j--) {
  75. if (owork) {
  76. submit_nonce(thr, owork, bswap_32(res[j]));
  77. }
  78. }
  79. if (owork)
  80. work_completed(thr->cgpu, owork);
  81. devices[chip].owork = devices[chip].work;
  82. devices[chip].work = NULL;
  83. hashes += 0xffffffffull * i;
  84. }
  85. }
  86. return hashes;
  87. }
  88. static void bitfury_statline_before(char *buf, struct cgpu_info *cgpu)
  89. {
  90. applog(LOG_INFO, "INFO bitfury_statline_before");
  91. }
  92. static bool bitfury_prepare(struct thr_info *thr)
  93. {
  94. struct timeval now;
  95. struct cgpu_info *cgpu = thr->cgpu;
  96. cgtime(&now);
  97. get_datestamp(cgpu->init, &now);
  98. applog(LOG_INFO, "INFO bitfury_prepare");
  99. return true;
  100. }
  101. static void bitfury_shutdown(struct thr_info *thr)
  102. {
  103. applog(LOG_INFO, "INFO bitfury_shutdown");
  104. }
  105. static void bitfury_disable(struct thr_info *thr)
  106. {
  107. applog(LOG_INFO, "INFO bitfury_disable");
  108. }
  109. struct device_drv bitfury_drv = {
  110. .drv_id = DRIVER_BITFURY,
  111. .dname = "bitfury",
  112. .name = "BITFURY",
  113. .drv_detect = bitfury_detect,
  114. .get_statline_before = bitfury_statline_before,
  115. .thread_prepare = bitfury_prepare,
  116. .scanwork = bitfury_scanHash,
  117. .thread_shutdown = bitfury_shutdown,
  118. .hash_work = hash_queued_work,
  119. };