driver-bitfury.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 2013 bitfury
  3. * Copyright 2013 legkodymov
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #include "miner.h"
  24. #include <unistd.h>
  25. #include <sha2.h>
  26. #include "libbitfury.h"
  27. #include "util.h"
  28. #define GOLDEN_BACKLOG 5
  29. struct device_drv bitfury_drv;
  30. // Forward declarations
  31. static void bitfury_disable(struct thr_info* thr);
  32. static bool bitfury_prepare(struct thr_info *thr);
  33. static void bitfury_detect(void)
  34. {
  35. int chip_n;
  36. struct cgpu_info *bitfury_info;
  37. applog(LOG_INFO, "INFO: bitfury_detect");
  38. chip_n = libbitfury_detectChips();
  39. if (!chip_n) {
  40. applog(LOG_WARNING, "No Bitfury chips detected!");
  41. return;
  42. } else {
  43. applog(LOG_WARNING, "BITFURY: %d chips detected!", chip_n);
  44. }
  45. bitfury_info = calloc(1, sizeof(struct cgpu_info));
  46. bitfury_info->drv = &bitfury_drv;
  47. bitfury_info->threads = 1;
  48. bitfury_info->chip_n = chip_n;
  49. add_cgpu(bitfury_info);
  50. }
  51. static uint32_t bitfury_checkNonce(struct work *work, uint32_t nonce)
  52. {
  53. applog(LOG_INFO, "INFO: bitfury_checkNonce");
  54. }
  55. static int64_t bitfury_scanHash(struct thr_info *thr)
  56. {
  57. static struct bitfury_device devices[100];
  58. int chip_n;
  59. int chip;
  60. uint64_t hashes = 0;
  61. chip_n = thr->cgpu->chip_n;
  62. for (chip = 0; chip < chip_n; chip++) {
  63. if(!devices[chip].work) {
  64. devices[chip].work = get_queued(thr->cgpu);
  65. if (devices[chip].work == NULL) {
  66. return 0;
  67. }
  68. work_to_payload(&(devices[chip].payload), devices[chip].work);
  69. }
  70. }
  71. libbitfury_sendHashData(devices, chip_n);
  72. for (chip = 0; chip < chip_n; chip++) {
  73. if (devices[chip].job_switched) {
  74. int i,j;
  75. int *res = devices[chip].results;
  76. struct work *owork = devices[chip].owork;
  77. i = devices[chip].results_n;
  78. for (j = i - 1; j >= 0; j--) {
  79. if (owork) {
  80. submit_nonce(thr, owork, bswap_32(res[j]));
  81. }
  82. }
  83. if (owork)
  84. work_completed(thr->cgpu, owork);
  85. devices[chip].owork = devices[chip].work;
  86. devices[chip].work = NULL;
  87. hashes += 0xffffffffull * i;
  88. }
  89. }
  90. return hashes;
  91. }
  92. static bool bitfury_prepare(struct thr_info *thr)
  93. {
  94. struct cgpu_info *cgpu = thr->cgpu;
  95. get_now_datestamp(cgpu->init, sizeof(cgpu->init));
  96. applog(LOG_INFO, "INFO bitfury_prepare");
  97. return true;
  98. }
  99. static void bitfury_shutdown(struct thr_info *thr)
  100. {
  101. applog(LOG_INFO, "INFO bitfury_shutdown");
  102. }
  103. static void bitfury_disable(struct thr_info *thr)
  104. {
  105. applog(LOG_INFO, "INFO bitfury_disable");
  106. }
  107. struct device_drv bitfury_drv = {
  108. .dname = "bitfury",
  109. .name = "BITFURY",
  110. .drv_detect = bitfury_detect,
  111. .thread_prepare = bitfury_prepare,
  112. .scanwork = bitfury_scanHash,
  113. .thread_shutdown = bitfury_shutdown,
  114. .minerloop = hash_queued_work,
  115. };