titan-asic.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 + 6*4 + 3*4 + 8*4;
  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]: Core disabled", repr, channel, die);
  34. return false;
  35. }
  36. if (status & KNC_ERR_MASK) {
  37. applog(LOG_INFO, "%s[%d:%d]: Failed to set work state (%x)", repr, channel, die, status);
  38. return false;
  39. }
  40. if (!(status & KNC_ERR_MASK)) {
  41. /* !KNC_ERRMASK */
  42. applog(LOG_DEBUG, "%s[%d:%d]: Core busy (%x)", repr, channel, die, status);
  43. }
  44. }
  45. knc_decode_report(response, report, KNC_VERSION_TITAN);
  46. return true;
  47. }
  48. bool knc_titan_get_report(const char *repr, void * const ctx, int channel, int die, int core, struct knc_report *report)
  49. {
  50. uint8_t request[4];
  51. int request_length;
  52. int response_length = 1 + 1 + (1 + 4) * 5;
  53. uint8_t response[response_length];
  54. int status;
  55. request_length = knc_prepare_report(request, die, core);
  56. status = knc_syncronous_transfer(ctx, channel, request_length, request, response_length, response);
  57. if (status) {
  58. applog(LOG_INFO, "%s[%d:%d]: get_report failed (%x)", repr, channel, die, status);
  59. return false;
  60. }
  61. knc_decode_report(response, report, KNC_VERSION_TITAN);
  62. return true;
  63. }
  64. /* Use bare function without extra checks */
  65. extern bool knc_titan_setup_core_(void * const ctx, int channel, int die, int core, struct titan_setup_core_params *params);
  66. /* This fails if core is hashing!
  67. * Stop it before setting up.
  68. */
  69. bool knc_titan_setup_core_local(const char *repr, void * const ctx, int channel, int die, int core, struct titan_setup_core_params *params)
  70. {
  71. return knc_titan_setup_core_(ctx, channel, die, core, params);
  72. }