driver-hashfast.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2013 Hashfast Inc.
  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. #include "config.h"
  11. #include <stdbool.h>
  12. #include "usbutils.h"
  13. #include "fpgautils.h"
  14. #include "driver-hashfast.h"
  15. static hf_info_t **hashfast_infos;
  16. struct device_drv hashfast_drv;
  17. static int hashfast_reset(struct cgpu_info __maybe_unused *hashfast)
  18. {
  19. return 0;
  20. }
  21. static bool hashfast_detect_common(struct cgpu_info *hashfast, int baud)
  22. {
  23. hf_core_t **c, *core;
  24. hf_info_t *info;
  25. hf_job_t *j;
  26. int i, k, ret;
  27. hashfast_infos = realloc(hashfast_infos, sizeof(hf_info_t *) * (total_devices + 1));
  28. if (unlikely(!hashfast_infos))
  29. quit(1, "Failed to realloc hashfast_infos in hashfast_detect_common");
  30. // Assume success, allocate info ahead of reset, so reset can fill fields in
  31. info = calloc(sizeof(hf_info_t), 1);
  32. if (unlikely(!info))
  33. quit(1, "Failed to calloc info in hashfast_detect_common");
  34. hashfast_infos[hashfast->device_id] = info;
  35. info->tacho_enable = 1;
  36. info->miner_count = 1;
  37. info->max_search_difficulty = 12;
  38. info->baud_rate = baud;
  39. ret = hashfast_reset(hashfast);
  40. if (unlikely(ret)) {
  41. free(info);
  42. hashfast_infos[hashfast->device_id] = NULL;
  43. return false;
  44. }
  45. /* 1 Pending, 1 active for each */
  46. info->inflight_target = info->asic_count * info->core_count *2;
  47. switch (info->device_type) {
  48. default:
  49. case HFD_G1:
  50. /* Implies hash_loops = 0 for full nonce range */
  51. break;
  52. case HFD_ExpressAGX:
  53. /* ExpressAGX */
  54. info->hash_loops = 1 << 26;
  55. break;
  56. case HFD_VC709:
  57. /* Virtex 7
  58. * Adjust according to fast or slow configuration */
  59. if (info->core_count > 5)
  60. info->hash_loops = 1 << 26;
  61. else
  62. info->hash_loops = 1 << 30;
  63. break;
  64. }
  65. applog(LOG_INFO, "Hashfast Detect: chips %d cores %d inflight_target %d entries",
  66. info->asic_count, info->core_count, info->inflight_target);
  67. /* Initialize list heads */
  68. info->active.next = &info->active;
  69. info->active.prev = &info->active;
  70. info->inactive.next = &info->inactive;
  71. info->inactive.prev = &info->inactive;
  72. /* Allocate core data structures */
  73. info->cores = calloc(info->asic_count, sizeof(hf_core_t *));
  74. if (unlikely(!info->cores))
  75. quit(1, "Failed to calloc info cores in hashfast_detect_common");
  76. c = info->cores;
  77. for (i = 0; i < info->asic_count; i++) {
  78. *c = calloc(info->core_count, sizeof(hf_core_t));
  79. if (unlikely(!*c))
  80. quit(1, "Failed to calloc hf_core_t in hashfast_detect_common");
  81. for (k = 0, core = *c; k < info->core_count; k++, core++)
  82. core->enabled = 1;
  83. c++;
  84. }
  85. /* Now allocate enough structures to hold all the in-flight work
  86. * 2 per core - one active and one pending. These go on the inactive
  87. * queue, and get used/recycled as required. */
  88. for (i = 0; i < info->asic_count * info->core_count * 2; i++) {
  89. j = calloc(sizeof(hf_job_t), 1);
  90. if (unlikely(!j))
  91. quit(1, "Failed to calloc hf_job_t in hashfast_detect_common");
  92. list_add(&info->inactive, &j->l);
  93. }
  94. info->inactive_count = info->asic_count * info->core_count * 2;
  95. applog(LOG_INFO, "Hashfast Detect: Allocated %d job entries",
  96. info->inflight_target);
  97. // Finally, allocate enough space to hold the work array.
  98. info->max_work = info->inflight_target;
  99. info->num_sequence = 1024;
  100. info->work = calloc(info->max_work, sizeof(hf_work_t));
  101. if (unlikely(!info->work))
  102. quit(1, "Failed to calloc info work in hashfast_detect_common");
  103. applog(LOG_INFO, "Hashfast Detect: Allocated space for %d work entries", info->inflight_target);
  104. return true;
  105. }
  106. static void hashfast_usb_initialise(struct cgpu_info *hashfast)
  107. {
  108. if (hashfast->usbinfo.nodev)
  109. return;
  110. // FIXME Do necessary initialising here
  111. }
  112. static bool hashfast_detect_one_usb(libusb_device *dev, struct usb_find_devices *found)
  113. {
  114. struct cgpu_info *hashfast;
  115. int baud = DEFAULT_BAUD_RATE;
  116. hashfast = usb_alloc_cgpu(&hashfast_drv, HASHFAST_MINER_THREADS);
  117. if (!hashfast)
  118. return false;
  119. if (!usb_init(hashfast, dev, found)) {
  120. free(hashfast->device_data);
  121. hashfast->device_data = NULL;
  122. hashfast = usb_free_cgpu(hashfast);
  123. return false;
  124. }
  125. hashfast->usbdev->usb_type = USB_TYPE_STD;
  126. hashfast->usbdev->PrefPacketSize = HASHFAST_USB_PACKETSIZE;
  127. hashfast_usb_initialise(hashfast);
  128. add_cgpu(hashfast);
  129. return hashfast_detect_common(hashfast, baud);
  130. }
  131. static void hashfast_detect(void)
  132. {
  133. usb_detect(&hashfast_drv, hashfast_detect_one_usb);
  134. }
  135. static bool hashfast_prepare(struct thr_info __maybe_unused *thr)
  136. {
  137. return true;
  138. }
  139. static bool hashfast_fill(struct cgpu_info __maybe_unused *hashfast)
  140. {
  141. return true;
  142. }
  143. static int64_t hashfast_scanhash(struct thr_info __maybe_unused *thr)
  144. {
  145. return 0;
  146. }
  147. static struct api_data *hashfast_api_stats(struct cgpu_info __maybe_unused *cgpu)
  148. {
  149. return NULL;
  150. }
  151. static void hashfast_init(struct cgpu_info __maybe_unused *hashfast)
  152. {
  153. }
  154. static void hashfast_shutdown(struct thr_info __maybe_unused *thr)
  155. {
  156. }
  157. struct device_drv hashfast_drv = {
  158. .drv_id = DRIVER_HASHFAST,
  159. .dname = "Hashfast",
  160. .name = "HFA",
  161. .drv_detect = hashfast_detect,
  162. .thread_prepare = hashfast_prepare,
  163. .hash_work = hash_queued_work,
  164. .queue_full = hashfast_fill,
  165. .scanwork = hashfast_scanhash,
  166. .get_api_stats = hashfast_api_stats,
  167. .reinit_device = hashfast_init,
  168. .thread_shutdown = hashfast_shutdown,
  169. };