titan-asic.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 2014 Vitalii Demianets
  3. * Copyright 2014 KnCMiner
  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 "miner.h"
  11. #include "logging.h"
  12. #include "titan-asic.h"
  13. bool knc_titan_get_info(const char *repr, void * const ctx, int channel, int die, struct knc_die_info *die_info)
  14. {
  15. int rc;
  16. rc = knc_detect_die(ctx, channel, die, die_info);
  17. return (0 == rc);
  18. }
  19. bool knc_titan_set_work(const char *repr, void * const ctx, int channel, int die, int core, int slot, struct work *work, bool urgent, bool *work_accepted, struct knc_report *report)
  20. {
  21. int request_length = 4 + 1 + BLOCK_HEADER_BYTES_WITHOUT_NONCE;
  22. uint8_t request[request_length];
  23. int response_length = 1 + 1 + (1 + 4) * 5;
  24. uint8_t response[response_length];
  25. int status;
  26. request_length = knc_prepare_titan_setwork(request, die, core, slot, work, urgent);
  27. status = knc_syncronous_transfer(ctx, channel, request_length, request, response_length, response);
  28. if (status == KNC_ACCEPTED) {
  29. *work_accepted = true;
  30. } else {
  31. *work_accepted = false;
  32. if (response[0] == 0x7f) {
  33. applog(LOG_DEBUG, "%s[%d:%d:%d]: Core disabled", repr, channel, die, core);
  34. return false;
  35. }
  36. if (status & KNC_ERR_MASK) {
  37. applog(LOG_INFO, "%s[%d:%d:%d]: Failed to set work state (%x)", repr, channel, die, core, status);
  38. return false;
  39. }
  40. if (!(status & KNC_ERR_MASK)) {
  41. /* !KNC_ERRMASK */
  42. applog(LOG_DEBUG, "%s[%d:%d:%d]: Core busy (%x)", repr, channel, die, core, status);
  43. }
  44. }
  45. knc_decode_report(response, report, KNC_VERSION_TITAN);
  46. return true;
  47. }
  48. bool knc_titan_set_work_multi(const char *repr, void * const ctx, int channel, int die, int core_start, int slot, struct work *work, bool urgent, bool *work_accepted, struct knc_report *reports, int num)
  49. {
  50. int REQUEST_BUFSIZE = 4 + 1 + BLOCK_HEADER_BYTES_WITHOUT_NONCE;
  51. int RESPONSE_BUFSIZE = 1 + 1 + (1 + 4) * 5;
  52. int i, core;
  53. uint8_t *requests = NULL;
  54. uint8_t *responses = NULL;
  55. int *request_lengths = NULL;
  56. int *response_lengths = NULL;
  57. int *statuses = NULL;
  58. requests = malloc(REQUEST_BUFSIZE * num);
  59. if (NULL == requests)
  60. goto exit_err;
  61. responses = malloc(RESPONSE_BUFSIZE * num);
  62. if (NULL == responses)
  63. goto exit_err;
  64. request_lengths = malloc(num * sizeof(int));
  65. if (NULL == request_lengths)
  66. goto exit_err;
  67. response_lengths = malloc(num * sizeof(int));
  68. if (NULL == response_lengths)
  69. goto exit_err;
  70. statuses = malloc(num * sizeof(int));
  71. if (NULL == statuses)
  72. goto exit_err;
  73. for (i = 0, core = core_start; i < num; ++i, ++core) {
  74. request_lengths[i] = knc_prepare_titan_setwork(&requests[REQUEST_BUFSIZE * i], die, core, slot, work, urgent);
  75. response_lengths[i] = RESPONSE_BUFSIZE;
  76. statuses[i] = KNC_ERR_UNAVAIL;
  77. }
  78. knc_syncronous_transfer_multi(ctx, channel, request_lengths, REQUEST_BUFSIZE, requests, response_lengths, RESPONSE_BUFSIZE, responses, statuses, num);
  79. for (i = 0, core = core_start; i < num; ++i, ++core) {
  80. uint8_t *response = &responses[RESPONSE_BUFSIZE * i];
  81. if (statuses[i] == KNC_ACCEPTED) {
  82. work_accepted[i] = true;
  83. } else {
  84. work_accepted[i] = false;
  85. if (response[0] == 0x7f) {
  86. applog(LOG_DEBUG, "%s[%d:%d:%d]: Core disabled", repr, channel, die, core);
  87. continue;
  88. }
  89. if (statuses[i] & KNC_ERR_MASK) {
  90. applog(LOG_INFO, "%s[%d:%d:%d]: Failed to set work state (%x)", repr, channel, die, core, statuses[i]);
  91. continue;
  92. }
  93. if (!(statuses[i] & KNC_ERR_MASK)) {
  94. applog(LOG_DEBUG, "%s[%d:%d:%d]: Core busy (%x)", repr, channel, die, core, statuses[i]);
  95. }
  96. }
  97. knc_decode_report(response, &reports[i], KNC_VERSION_TITAN);
  98. }
  99. free(response_lengths);
  100. free(request_lengths);
  101. free(statuses);
  102. free(responses);
  103. free(requests);
  104. return true;
  105. exit_err:
  106. if (NULL != response_lengths)
  107. free(response_lengths);
  108. if (NULL != request_lengths)
  109. free(request_lengths);
  110. if (NULL != statuses)
  111. free(statuses);
  112. if (NULL != responses)
  113. free(responses);
  114. if (NULL != requests)
  115. free(requests);
  116. return false;
  117. }
  118. bool knc_titan_get_report(const char *repr, void * const ctx, int channel, int die, int core, struct knc_report *report)
  119. {
  120. uint8_t request[4];
  121. int request_length;
  122. int response_length = 1 + 1 + (1 + 4) * 5;
  123. uint8_t response[response_length];
  124. int status;
  125. request_length = knc_prepare_report(request, die, core);
  126. status = knc_syncronous_transfer(ctx, channel, request_length, request, response_length, response);
  127. if (status) {
  128. applog(LOG_INFO, "%s[%d:%d:%d]: get_report failed (%x)", repr, channel, die, core, status);
  129. return false;
  130. }
  131. knc_decode_report(response, report, KNC_VERSION_TITAN);
  132. return true;
  133. }
  134. /* Use bare function without extra checks */
  135. extern bool knc_titan_setup_core_(void * const ctx, int channel, int die, int core, struct titan_setup_core_params *params);
  136. /* This fails if core is hashing!
  137. * Stop it before setting up.
  138. */
  139. bool knc_titan_setup_core_local(const char *repr, void * const ctx, int channel, int die, int core, struct titan_setup_core_params *params)
  140. {
  141. return knc_titan_setup_core_(ctx, channel, die, core, params);
  142. }