Initial import and conversion of hashratio driver to direct USB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
diff --git a/Makefile.am b/Makefile.am
index b68b76a..4152c18 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -80,6 +80,10 @@ if HAS_HASHFAST
cgminer_SOURCES += driver-hashfast.c driver-hashfast.h hf_protocol.h hf_protocol_be.h
endif
+if HAS_HASHRATIO
+cgminer_SOURCES += driver-hashratio.c driver-hashratio.h crc16.c crc.h
+endif
+
if HAS_BITFURY
cgminer_SOURCES += driver-bitfury.c driver-bitfury.h
endif
diff --git a/api.c b/api.c
index bf539f9..73e1b4c 100644
--- a/api.c
+++ b/api.c
@@ -31,7 +31,7 @@
defined(USE_KNC) || defined(USE_BAB) || defined(USE_DRILLBIT) || \
defined(USE_MINION) || defined(USE_COINTERRA) || defined(USE_BITMINE_A1) || \
defined(USE_ANT_S1) || defined(USE_ANT_S2) || defined(USE_SP10) || defined(USE_SP30) || \
- defined(USE_ICARUS)
+ defined(USE_ICARUS) || defined(USE_HASHRATIO)
#define HAVE_AN_ASIC 1
#endif
@@ -182,6 +182,9 @@ static const char *DEVICECODE = ""
#ifdef USE_HASHFAST
"HFA "
#endif
+#ifdef USE_HASHRATIO
+ "HRO "
+#endif
#ifdef USE_BITMINE_A1
"BA1 "
#endif
diff --git a/cgminer.c b/cgminer.c
index 0ada951..4b5653a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6840,7 +6840,7 @@ void set_target(unsigned char *dest_target, double diff)
memcpy(dest_target, target, 32);
}
-#ifdef USE_AVALON2
+#if defined (USE_AVALON2) || defined (USE_HASHRATIO)
void submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *real_pool,
uint32_t nonce2, uint32_t nonce)
{
diff --git a/configure.ac b/configure.ac
index f455f79..657984c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -244,6 +244,17 @@ if test "x$hashfast" = xyes; then
fi
AM_CONDITIONAL([HAS_HASHFAST], [test x$hashfast = xyes])
+hashratio="no"
+
+AC_ARG_ENABLE([hashratio],
+ [AC_HELP_STRING([--enable-hashratio],[Compile support for Hashratio (default disabled)])],
+ [hashratio=$enableval]
+ )
+if test "x$hashratio" = xyes; then
+ AC_DEFINE([USE_HASHRATIO], [1], [Defined to 1 if Hashratiosupport is wanted])
+fi
+AM_CONDITIONAL([HAS_HASHRATIO], [test x$hashratio = xyes])
+
icarus="no"
AC_ARG_ENABLE([icarus],
@@ -363,7 +374,7 @@ else
])
fi
-if test x$avalon$bitforce$bitfury$modminer$bflsc$icarus$hashfast$klondike$drillbit$cointerra$ants1$ants2 != xnononononononononononono; then
+if test x$avalon$bitforce$bitfury$modminer$bflsc$icarus$hashfast$hashratio$klondike$drillbit$cointerra$ants1$ants2 != xnonononononononononononono; then
want_usbutils=true
else
want_usbutils=false
@@ -635,6 +646,12 @@ else
echo " Hashfast.ASICs.......: Disabled"
fi
+if test "x$hashratio" = xyes; then
+ echo " Hashratio.ASICs......: Enabled"
+else
+ echo " Hashratio.ASICs......: Disabled"
+fi
+
if test "x$icarus" = xyes; then
echo " Icarus.ASICs/FPGAs...: Enabled"
else
@@ -659,7 +676,7 @@ else
echo " ModMiner.FPGAs.......: Disabled"
fi
-if test "x$avalon$avalon2$bab$bflsc$bitforce$bitfury$hashfast$icarus$klondike$knc$modminer$drillbit$minion$cointerra$bitmine_A1$ants1$ants2$sp10$sp30" = xnonononononononononononononononononono; then
+if test "x$avalon$avalon2$bab$bflsc$bitforce$bitfury$hashfast$hashratio$icarus$klondike$knc$modminer$drillbit$minion$cointerra$bitmine_A1$ants1$ants2$sp10$sp30" = xnononononononononononononononononononono; then
AC_MSG_ERROR([No mining configured in])
fi
diff --git a/driver-hashratio.c b/driver-hashratio.c
new file mode 100644
index 0000000..c830d93
--- /dev/null
+++ b/driver-hashratio.c
@@ -0,0 +1,826 @@
+/*
+ * Copyright 2013-2014 Con Kolivas <kernel@kolivas.org>
+ * Copyright 2012-2014 Xiangfu <xiangfu@openmobilefree.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version. See COPYING for more details.
+ */
+
+#include "config.h"
+
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <dirent.h>
+#include <unistd.h>
+#ifndef WIN32
+ #include <termios.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #ifndef O_CLOEXEC
+ #define O_CLOEXEC 0
+ #endif
+#else
+ #include <windows.h>
+ #include <io.h>
+#endif
+
+#include "elist.h"
+#include "miner.h"
+#include "driver-hashratio.h"
+#include "crc.h"
+#include "usbutils.h"
+
+int opt_hashratio_fan_min = HRTO_DEFAULT_FAN_MIN;
+int opt_hashratio_fan_max = HRTO_DEFAULT_FAN_MAX;
+
+int opt_hashratio_freq = HRTO_DEFAULT_FREQUENCY;
+
+
+//static int get_fan_pwm(int temp) {
+// int pwm;
+// uint8_t fan_pwm_arr[] = {30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
+// 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
+// 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
+// 30, 37, 49, 61, 73, 85, 88, 91, 94, 97, 100, 100, 100, 100, 100, 100,
+// 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
+// 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
+// 100, 100, 100, 100, 100, 100, 100};
+// if (temp < 0 || temp >= sizeof(fan_pwm_arr)/sizeof(fan_pwm_arr[0]) ||
+// fan_pwm_arr[temp] > opt_hashratio_fan_max) {
+// return opt_hashratio_fan_max;
+// }
+// pwm = HRTO_PWM_MAX - fan_pwm_arr[temp] * HRTO_PWM_MAX / 100;
+//
+// if (pwm < opt_hashratio_fan_min) {
+// return opt_hashratio_fan_min;
+// }
+// if (pwm > opt_hashratio_fan_max) {
+// return opt_hashratio_fan_max;
+// }
+// return pwm;
+//}
+
+char *set_hashratio_freq(char *arg)
+{
+ int val, ret;
+
+ ret = sscanf(arg, "%d", &val);
+ if (ret != 1)
+ return "No values passed to hashratio-freq";
+
+ if (val < HRTO_DEFAULT_FREQUENCY_MIN || val > HRTO_DEFAULT_FREQUENCY_MAX)
+ return "Invalid value passed to hashratio-freq";
+
+ opt_hashratio_freq = val;
+
+ return NULL;
+}
+
+static inline uint8_t rev8(uint8_t d)
+{
+ int i;
+ uint8_t out = 0;
+
+ /* (from left to right) */
+ for (i = 0; i < 8; i++)
+ if (d & (1 << i))
+ out |= (1 << (7 - i));
+
+ return out;
+}
+
+char *set_hashratio_fan(char *arg)
+{
+ int val1, val2, ret;
+
+ ret = sscanf(arg, "%d-%d", &val1, &val2);
+ if (ret < 1)
+ return "No values passed to hashratio-fan";
+ if (ret == 1)
+ val2 = val1;
+
+ if (val1 < 0 || val1 > 100 || val2 < 0 || val2 > 100 || val2 < val1)
+ return "Invalid value passed to hashratio-fan";
+
+ opt_hashratio_fan_min = val1 * HRTO_PWM_MAX / 100;
+ opt_hashratio_fan_max = val2 * HRTO_PWM_MAX / 100;
+
+ return NULL;
+}
+
+static int hashratio_init_pkg(struct hashratio_pkg *pkg, uint8_t type,
+ uint8_t idx, uint8_t cnt)
+{
+ unsigned short crc;
+
+ pkg->head[0] = HRTO_H1;
+ pkg->head[1] = HRTO_H2;
+
+ pkg->type = type;
+ pkg->idx = idx;
+ pkg->cnt = cnt;
+
+ crc = crc16(pkg->data, HRTO_P_DATA_LEN);
+
+ pkg->crc[0] = (crc & 0xff00) >> 8;
+ pkg->crc[1] = crc & 0x00ff;
+ return 0;
+}
+
+#if 0
+static int job_idcmp(uint8_t *job_id, char *pool_job_id)
+{
+ int job_id_len;
+ unsigned short crc, crc_expect;
+
+ if (!pool_job_id)
+ return 1;
+
+ job_id_len = strlen(pool_job_id);
+ crc_expect = crc16(pool_job_id, job_id_len);
+
+ crc = job_id[0] << 8 | job_id[1];
+
+ if (crc_expect == crc)
+ return 0;
+
+ applog(LOG_DEBUG, "Hashratio: job_id not match! [%04x:%04x (%s)]",
+ crc, crc_expect, pool_job_id);
+
+ return 1;
+}
+#endif
+
+static int decode_pkg(struct thr_info *thr, struct hashratio_ret *ar, uint8_t *pkg)
+{
+ struct cgpu_info *hashratio = thr->cgpu;
+ struct hashratio_info *info = hashratio->device_data;
+ struct pool *pool;
+
+ unsigned int expected_crc;
+ unsigned int actual_crc;
+ uint32_t nonce, nonce2, miner;
+ int pool_no;
+ uint8_t job_id[5];
+ int tmp;
+
+ int type = HRTO_GETS_ERROR;
+
+ memcpy((uint8_t *)ar, pkg, HRTO_READ_SIZE);
+
+// applog(LOG_DEBUG, "pkg.type, hex: %02x, dec: %d", ar->type, ar->type);
+
+ if (ar->head[0] == HRTO_H1 && ar->head[1] == HRTO_H2) {
+ expected_crc = crc16(ar->data, HRTO_P_DATA_LEN);
+ actual_crc = (ar->crc[0] & 0xff) |
+ ((ar->crc[1] & 0xff) << 8);
+
+ type = ar->type;
+ applog(LOG_DEBUG, "hashratio: %d: expected crc(%04x), actural_crc(%04x)", type, expected_crc, actual_crc);
+ if (expected_crc != actual_crc)
+ goto out;
+
+ switch(type) {
+ case HRTO_P_NONCE:
+ memcpy(&miner, ar->data + 0, 4);
+ memcpy(&pool_no, ar->data + 4, 4);
+ memcpy(&nonce2, ar->data + 8, 4);
+ /* Calc time ar->data + 12 */
+ memcpy(&nonce, ar->data + 12, 4);
+ memset(job_id, 0, 5);
+ memcpy(job_id, ar->data + 16, 4);
+
+ miner = be32toh(miner);
+ pool_no = be32toh(pool_no);
+ if (miner >= HRTO_DEFAULT_MINERS || pool_no >= total_pools || pool_no < 0) {
+ applog(LOG_DEBUG, "hashratio: Wrong miner/pool/id no %d,%d", miner, pool_no);
+ break;
+ } else
+ info->matching_work[miner]++;
+ nonce2 = be32toh(nonce2);
+ nonce = be32toh(nonce);
+
+ applog(LOG_DEBUG, "hashratio: Found! [%s] %d:(%08x) (%08x)",
+ job_id, pool_no, nonce2, nonce);
+
+ pool = pools[pool_no];
+ if (!info->new_stratum)
+ submit_nonce2_nonce(thr, pool, pool, nonce2, nonce);
+ break;
+ case HRTO_P_STATUS:
+ memcpy(&tmp, ar->data, 4);
+ tmp = be32toh(tmp);
+ info->temp = (tmp & 0x00f0) >> 8;
+ if (info->temp_max < info->temp) {
+ info->temp_max = info->temp;
+ }
+// info->temp[1] = tmp & 0xffff;
+
+ memcpy(&tmp, ar->data + 4, 4);
+ tmp = be32toh(tmp);
+ info->fan[0] = tmp >> 16;
+ info->fan[1] = tmp & 0xffff;
+
+ // local_work
+ memcpy(&tmp, ar->data + 8, 4);
+ tmp = be32toh(tmp);
+ info->local_work = tmp;
+ info->local_works += tmp;
+
+ // hw_work
+ memcpy(&tmp, ar->data + 12, 4);
+ tmp = be32toh(tmp);
+ info->hw_works += tmp;
+
+ hashratio->temp = info->temp;
+ break;
+ case HRTO_P_ACKDETECT:
+ break;
+ case HRTO_P_ACK:
+ break;
+ case HRTO_P_NAK:
+ break;
+ default:
+ type = HRTO_GETS_ERROR;
+ break;
+ }
+ }
+
+out:
+ return type;
+}
+
+static inline int hashratio_gets(struct cgpu_info *hashratio, uint8_t *buf)
+{
+ int i;
+ int read_amount = HRTO_READ_SIZE;
+ uint8_t buf_tmp[HRTO_READ_SIZE];
+ uint8_t buf_copy[2 * HRTO_READ_SIZE];
+ uint8_t *buf_back = buf;
+ int ret = 0;
+
+ while (true) {
+ int err;
+
+ do {
+ memset(buf, 0, read_amount);
+ err = usb_read(hashratio, (char *)buf, read_amount, &ret, C_HRO_READ);
+ if (unlikely(err < 0 || ret != read_amount)) {
+ applog(LOG_ERR, "hashratio: Error on read in hashratio_gets got %d", ret);
+ return HRTO_GETS_ERROR;
+ }
+ if (likely(ret >= read_amount)) {
+ for (i = 1; i < read_amount; i++) {
+ if (buf_back[i - 1] == HRTO_H1 && buf_back[i] == HRTO_H2)
+ break;
+ }
+ i -= 1;
+ if (i) {
+ err = usb_read(hashratio, (char *)buf, read_amount, &ret, C_HRO_READ);
+ if (unlikely(err < 0 || ret != i)) {
+ applog(LOG_ERR, "hashratio: Error on 2nd read in hashratio_gets got %d", ret);
+ return HRTO_GETS_ERROR;
+ }
+ memcpy(buf_copy, buf_back + i, HRTO_READ_SIZE - i);
+ memcpy(buf_copy + HRTO_READ_SIZE - i, buf_tmp, i);
+ memcpy(buf_back, buf_copy, HRTO_READ_SIZE);
+ }
+ return HRTO_GETS_OK;
+ }
+ buf += ret;
+ read_amount -= ret;
+ continue;
+ } while (ret > 0);
+
+ return HRTO_GETS_TIMEOUT;
+ }
+}
+
+static int hashratio_send_pkg(struct cgpu_info *hashratio, const struct hashratio_pkg *pkg)
+{
+ int err, amount;
+ uint8_t buf[HRTO_WRITE_SIZE];
+ int nr_len = HRTO_WRITE_SIZE;
+
+ memcpy(buf, pkg, HRTO_WRITE_SIZE);
+// if (opt_debug) {
+// applog(LOG_DEBUG, "hashratio: Sent(%d):", nr_len);
+// hexdump((uint8_t *)buf, nr_len);
+// }
+
+ err = usb_write(hashratio, (char *)buf, nr_len, &amount, C_HRO_WRITE);
+ if (err || amount != nr_len) {
+ applog(LOG_DEBUG, "hashratio: Send(%d)!", amount);
+ return HRTO_SEND_ERROR;
+ }
+
+#if 0
+ cgsleep_ms(20);
+ ret = hashratio_gets(fd, result);
+ if (ret != HRTO_GETS_OK) {
+ applog(LOG_DEBUG, "hashratio: Get(%d)!", ret);
+ return HRTO_SEND_ERROR;
+ }
+
+ ret = decode_pkg(thr, &ar, result);
+ if (ret != HRTO_P_ACK) {
+ applog(LOG_DEBUG, "hashratio: PKG(%d)!", ret);
+ hexdump((uint8_t *)result, HRTO_READ_SIZE);
+ return HRTO_SEND_ERROR;
+ }
+#endif
+
+ return HRTO_SEND_OK;
+}
+
+static int hashratio_stratum_pkgs(struct cgpu_info *hashratio, struct pool *pool)
+{
+ const int merkle_offset = 36;
+ struct hashratio_pkg pkg;
+ int i, a, b, tmp;
+ unsigned char target[32];
+ int job_id_len;
+
+ /* Send out the first stratum message STATIC */
+ applog(LOG_DEBUG, "hashratio: Pool stratum message STATIC: %d, %d, %d, %d, %d, %d",
+ pool->coinbase_len,
+ pool->nonce2_offset,
+ pool->n2size,
+ merkle_offset,
+ pool->merkles,
+ pool->pool_no);
+ memset(pkg.data, 0, HRTO_P_DATA_LEN);
+ tmp = be32toh(pool->coinbase_len);
+ memcpy(pkg.data, &tmp, 4);
+
+ tmp = be32toh(pool->nonce2_offset);
+ memcpy(pkg.data + 4, &tmp, 4);
+
+ tmp = be32toh(pool->n2size);
+ memcpy(pkg.data + 8, &tmp, 4);
+
+ tmp = be32toh(merkle_offset);
+ memcpy(pkg.data + 12, &tmp, 4);
+
+ tmp = be32toh(pool->merkles);
+ memcpy(pkg.data + 16, &tmp, 4);
+
+ tmp = be32toh((int)pool->sdiff);
+ memcpy(pkg.data + 20, &tmp, 4);
+
+ tmp = be32toh((int)pool->pool_no);
+ memcpy(pkg.data + 24, &tmp, 4);
+
+ hashratio_init_pkg(&pkg, HRTO_P_STATIC, 1, 1);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+
+ set_target(target, pool->sdiff);
+ memcpy(pkg.data, target, 32);
+ if (opt_debug) {
+ char *target_str;
+ target_str = bin2hex(target, 32);
+ applog(LOG_DEBUG, "hashratio: Pool stratum target: %s", target_str);
+ free(target_str);
+ }
+ hashratio_init_pkg(&pkg, HRTO_P_TARGET, 1, 1);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+
+
+ applog(LOG_DEBUG, "hashratio: Pool stratum message JOBS_ID: %s",
+ pool->swork.job_id);
+ memset(pkg.data, 0, HRTO_P_DATA_LEN);
+
+ job_id_len = strlen(pool->swork.job_id);
+ job_id_len = job_id_len >= 4 ? 4 : job_id_len;
+ for (i = 0; i < job_id_len; i++) {
+ pkg.data[i] = *(pool->swork.job_id + strlen(pool->swork.job_id) - 4 + i);
+ }
+ hashratio_init_pkg(&pkg, HRTO_P_JOB_ID, 1, 1);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+
+ a = pool->coinbase_len / HRTO_P_DATA_LEN;
+ b = pool->coinbase_len % HRTO_P_DATA_LEN;
+ applog(LOG_DEBUG, "pool->coinbase_len: %d", pool->coinbase_len);
+ applog(LOG_DEBUG, "hashratio: Pool stratum message COINBASE: %d %d", a, b);
+ for (i = 0; i < a; i++) {
+ memcpy(pkg.data, pool->coinbase + i * 32, 32);
+ hashratio_init_pkg(&pkg, HRTO_P_COINBASE, i + 1, a + (b ? 1 : 0));
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+ if (i % 25 == 0) {
+ cgsleep_ms(2);
+ }
+ }
+ if (b) {
+ memset(pkg.data, 0, HRTO_P_DATA_LEN);
+ memcpy(pkg.data, pool->coinbase + i * 32, b);
+ hashratio_init_pkg(&pkg, HRTO_P_COINBASE, i + 1, i + 1);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+ }
+
+ b = pool->merkles;
+ applog(LOG_DEBUG, "hashratio: Pool stratum message MERKLES: %d", b);
+ for (i = 0; i < b; i++) {
+ memset(pkg.data, 0, HRTO_P_DATA_LEN);
+ memcpy(pkg.data, pool->swork.merkle_bin[i], 32);
+ hashratio_init_pkg(&pkg, HRTO_P_MERKLES, i + 1, b);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+ }
+
+ applog(LOG_DEBUG, "hashratio: Pool stratum message HEADER: 4");
+ for (i = 0; i < 4; i++) {
+ memset(pkg.data, 0, HRTO_P_HEADER);
+ memcpy(pkg.data, pool->header_bin + i * 32, 32);
+ hashratio_init_pkg(&pkg, HRTO_P_HEADER, i + 1, 4);
+ while (hashratio_send_pkg(hashratio, &pkg) != HRTO_SEND_OK)
+ ;
+
+ }
+ return 0;
+}
+
+static int hashratio_get_result(struct thr_info *thr, struct hashratio_ret *ar)
+{
+ struct cgpu_info *hashratio = thr->cgpu;
+ uint8_t result[HRTO_READ_SIZE];
+ int ret;
+
+ memset(result, 0, HRTO_READ_SIZE);
+
+ ret = hashratio_gets(hashratio, result);
+ if (ret != HRTO_GETS_OK)
+ return ret;
+
+// if (opt_debug) {
+// applog(LOG_DEBUG, "hashratio: Get(ret = %d):", ret);
+// hexdump((uint8_t *)result, HRTO_READ_SIZE);
+// }
+
+ return decode_pkg(thr, ar, result);
+}
+
+#define HASHRATIO_LATENCY 5
+
+static void hashratio_initialise(struct cgpu_info *hashratio)
+{
+ int err, interface;
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ interface = usb_interface(hashratio);
+ // Reset
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
+ FTDI_VALUE_RESET, interface, C_RESET);
+
+ applog(LOG_DEBUG, "%s%i: reset got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set latency
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
+ HASHRATIO_LATENCY, interface, C_LATENCY);
+
+ applog(LOG_DEBUG, "%s%i: latency got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set data
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_DATA,
+ FTDI_VALUE_DATA_AVA, interface, C_SETDATA);
+
+ applog(LOG_DEBUG, "%s%i: data got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set the baud
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_BAUD, FTDI_VALUE_BAUD_AVA,
+ (FTDI_INDEX_BAUD_AVA & 0xff00) | interface,
+ C_SETBAUD);
+
+ applog(LOG_DEBUG, "%s%i: setbaud got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set Modem Control
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
+ FTDI_VALUE_MODEM, interface, C_SETMODEM);
+
+ applog(LOG_DEBUG, "%s%i: setmodemctrl got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set Flow Control
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
+ FTDI_VALUE_FLOW, interface, C_SETFLOW);
+
+ applog(LOG_DEBUG, "%s%i: setflowctrl got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ /* hashratio repeats the following */
+ // Set Modem Control
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_MODEM,
+ FTDI_VALUE_MODEM, interface, C_SETMODEM);
+
+ applog(LOG_DEBUG, "%s%i: setmodemctrl 2 got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+
+ if (hashratio->usbinfo.nodev)
+ return;
+
+ // Set Flow Control
+ err = usb_transfer(hashratio, FTDI_TYPE_OUT, FTDI_REQUEST_FLOW,
+ FTDI_VALUE_FLOW, interface, C_SETFLOW);
+
+ applog(LOG_DEBUG, "%s%i: setflowctrl 2 got err %d",
+ hashratio->drv->name, hashratio->device_id, err);
+}
+
+static struct cgpu_info *hashratio_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
+{
+ struct hashratio_info *info;
+ int err, amount;
+ int ackdetect;
+ char mm_version[16];
+
+ struct cgpu_info *hashratio = usb_alloc_cgpu(&hashratio_drv, 1);
+ struct hashratio_pkg detect_pkg;
+ struct hashratio_ret ret_pkg;
+
+ if (!usb_init(hashratio, dev, found)) {
+ applog(LOG_ERR, "Hashratio failed usb_init");
+ hashratio = usb_free_cgpu(hashratio);
+ return NULL;
+ }
+
+ hashratio_initialise(hashratio);
+
+ strcpy(mm_version, "NONE");
+ /* Send out detect pkg */
+ memset(detect_pkg.data, 0, HRTO_P_DATA_LEN);
+
+ hashratio_init_pkg(&detect_pkg, HRTO_P_DETECT, 1, 1);
+ hashratio_send_pkg(hashratio, &detect_pkg);
+ cgsleep_ms(20);
+ err = usb_read(hashratio, (char *)&ret_pkg, HRTO_READ_SIZE, &amount, C_HRO_READ);
+ if (err || amount != HRTO_READ_SIZE) {
+ applog(LOG_ERR, "%s %d: Hashratio failed usb_read with err %d amount %d",
+ hashratio->drv->name, hashratio->device_id, err, amount);
+ usb_uninit(hashratio);
+ usb_free_cgpu(hashratio);
+ return NULL;
+ }
+
+ ackdetect = ret_pkg.type;
+ applog(LOG_DEBUG, "hashratio Detect ID: %d", ackdetect);
+
+ if (ackdetect != HRTO_P_ACKDETECT) {
+ applog(LOG_DEBUG, "Not a hashratio device");
+ usb_uninit(hashratio);
+ usb_free_cgpu(hashratio);
+ return NULL;
+ }
+
+ memcpy(mm_version, ret_pkg.data, 15);
+ mm_version[15] = '\0';
+
+ /* We have a real Hashratio! */
+ hashratio->threads = HRTO_MINER_THREADS;
+ add_cgpu(hashratio);
+
+ update_usb_stats(hashratio);
+
+ applog(LOG_INFO, "%s%d: Found at %s", hashratio->drv->name, hashratio->device_id,
+ hashratio->device_path);
+
+ hashratio->device_data = calloc(sizeof(struct hashratio_info), 1);
+ if (unlikely(!(hashratio->device_data)))
+ quit(1, "Failed to malloc hashratio_info");
+
+ info = hashratio->device_data;
+
+ strcpy(info->mm_version, mm_version);
+
+ info->fan_pwm = HRTO_DEFAULT_FAN / 100 * HRTO_PWM_MAX;
+ info->temp_max = 0;
+ info->temp_history_index = 0;
+ info->temp_sum = 0;
+ info->temp_old = 0;
+ info->default_freq = opt_hashratio_freq;
+
+ return hashratio;
+}
+
+static inline void hashratio_detect(bool __maybe_unused hotplug)
+{
+ usb_detect(&hashratio_drv, hashratio_detect_one);
+}
+
+static bool hashratio_prepare(struct thr_info *thr)
+{
+ struct cgpu_info *hashratio = thr->cgpu;
+ struct hashratio_info *info = hashratio->device_data;
+
+ info->first = true;
+
+ return true;
+}
+
+static int polling(struct thr_info *thr)
+{
+ struct hashratio_pkg send_pkg;
+ struct hashratio_ret ar;
+ struct cgpu_info *hashratio = thr->cgpu;
+
+ memset(send_pkg.data, 0, HRTO_P_DATA_LEN);
+ hashratio_init_pkg(&send_pkg, HRTO_P_POLLING, 1, 1);
+
+ while (hashratio_send_pkg(hashratio, &send_pkg) != HRTO_SEND_OK)
+ ;
+ hashratio_get_result(thr, &ar);
+
+ return 0;
+}
+
+static int64_t hashratio_scanhash(struct thr_info *thr)
+{
+ struct hashratio_pkg send_pkg;
+ struct pool *pool;
+ struct cgpu_info *hashratio = thr->cgpu;
+ struct hashratio_info *info = hashratio->device_data;
+
+ uint32_t tmp, range, start;
+
+
+ if (thr->work_restart || thr->work_update || info->first) {
+ info->new_stratum = true;
+ applog(LOG_DEBUG, "hashratio: New stratum: restart: %d, update: %d, first: %d",
+ thr->work_restart, thr->work_update, info->first);
+ thr->work_update = false;
+ thr->work_restart = false;
+ if (unlikely(info->first))
+ info->first = false;
+
+ get_work(thr, thr->id); /* Make sure pool is ready */
+
+ pool = current_pool();
+ if (!pool->has_stratum)
+ quit(1, "hashratio: Miner Manager have to use stratum pool");
+ if (pool->coinbase_len > HRTO_P_COINBASE_SIZE)
+ quit(1, "hashratio: Miner Manager pool coinbase length have to less then %d", HRTO_P_COINBASE_SIZE);
+ if (pool->merkles > HRTO_P_MERKLES_COUNT)
+ quit(1, "hashratio: Miner Manager merkles have to less then %d", HRTO_P_MERKLES_COUNT);
+
+ info->diff = (int)pool->sdiff - 1;
+ info->pool_no = pool->pool_no;
+
+ cg_wlock(&pool->data_lock);
+ hashratio_stratum_pkgs(hashratio, pool);
+ cg_wunlock(&pool->data_lock);
+
+ /* Configuer the parameter from outside */
+ memset(send_pkg.data, 0, HRTO_P_DATA_LEN);
+
+ // fan
+ info->fan_pwm = HRTO_PWM_MAX;
+ tmp = be32toh(info->fan_pwm);
+ memcpy(send_pkg.data, &tmp, 4);
+
+ // freq
+ tmp = be32toh(info->default_freq);
+ memcpy(send_pkg.data + 4, &tmp, 4);
+ applog(LOG_DEBUG, "set freq: %d", info->default_freq);
+
+ /* Configure the nonce2 offset and range */
+ range = 0xffffffff / total_devices;
+ start = range * hashratio->device_id;
+
+ tmp = be32toh(start);
+ memcpy(send_pkg.data + 8, &tmp, 4);
+
+ tmp = be32toh(range);
+ memcpy(send_pkg.data + 12, &tmp, 4);
+
+ /* Package the data */
+ hashratio_init_pkg(&send_pkg, HRTO_P_SET, 1, 1);
+ while (hashratio_send_pkg(hashratio, &send_pkg) != HRTO_SEND_OK)
+ ;
+
+ info->new_stratum = false;
+ }
+
+ polling(thr);
+
+ return (int64_t)info->local_work * 64 * 0xffffffff;
+}
+
+static struct api_data *hashratio_api_stats(struct cgpu_info *cgpu)
+{
+ struct api_data *root = NULL;
+ struct hashratio_info *info = cgpu->device_data;
+ char buf[24];
+ char buf2[256];
+ double hwp;
+ int i;
+
+ // mm version
+ sprintf(buf, "MM Version");
+ root = api_add_string(root, buf, info->mm_version, false);
+
+ // asic freq
+ sprintf(buf, "Asic Freq (MHz)");
+ root = api_add_int(root, buf, &(info->default_freq), false);
+
+ // match work count
+ for (i = 0; i < HRTO_DEFAULT_MODULARS; i++) {
+ sprintf(buf, "Match work Modular %02d", i + 1);
+ memset(buf2, 0, sizeof(buf2));
+ snprintf(buf2, sizeof(buf2),
+ "%02d:%08d %02d:%08d %02d:%08d %02d:%08d "
+ "%02d:%08d %02d:%08d %02d:%08d %02d:%08d "
+ "%02d:%08d %02d:%08d %02d:%08d %02d:%08d "
+ "%02d:%08d %02d:%08d %02d:%08d %02d:%08d",
+ i*16 + 1, info->matching_work[i*16 + 0],
+ i*16 + 2, info->matching_work[i*16 + 1],
+ i*16 + 3, info->matching_work[i*16 + 2],
+ i*16 + 4, info->matching_work[i*16 + 3],
+ i*16 + 5, info->matching_work[i*16 + 4],
+ i*16 + 6, info->matching_work[i*16 + 5],
+ i*16 + 7, info->matching_work[i*16 + 6],
+ i*16 + 8, info->matching_work[i*16 + 7],
+ i*16 + 9, info->matching_work[i*16 + 8],
+ i*16 + 10, info->matching_work[i*16 + 9],
+ i*16 + 11, info->matching_work[i*16 + 10],
+ i*16 + 12, info->matching_work[i*16 + 11],
+ i*16 + 13, info->matching_work[i*16 + 12],
+ i*16 + 14, info->matching_work[i*16 + 13],
+ i*16 + 15, info->matching_work[i*16 + 14],
+ i*16 + 16, info->matching_work[i*16 + 15]);
+ root = api_add_string(root, buf, buf2, true);
+ }
+
+ // local works
+ sprintf(buf, "Local works");
+ root = api_add_int(root, buf, &(info->local_works), false);
+
+ // hardware error works
+ sprintf(buf, "Hardware error works");
+ root = api_add_int(root, buf, &(info->hw_works), false);
+
+ // device hardware error %
+ hwp = info->local_works ? ((double)info->hw_works / (double)info->local_works) : 0;
+ sprintf(buf, "Device hardware error%%");
+ root = api_add_percent(root, buf, &hwp, true);
+
+ // Temperature
+ sprintf(buf, "Temperature");
+ root = api_add_int(root, buf, &(info->temp), false);
+
+ // Fan
+ for (i = 0; i < HRTO_FAN_COUNT; i++) {
+ sprintf(buf, "Fan%d", i+1);
+ root = api_add_int(root, buf, &(info->fan[i]), false);
+ }
+
+ return root;
+}
+
+static void hashratio_shutdown(struct thr_info __maybe_unused *thr)
+{
+}
+
+struct device_drv hashratio_drv = {
+ .drv_id = DRIVER_hashratio,
+ .dname = "hashratio",
+ .name = "HRTO",
+ .get_api_stats = hashratio_api_stats,
+ .drv_detect = hashratio_detect,
+ .thread_prepare = hashratio_prepare,
+ .hash_work = hash_driver_work,
+ .scanwork = hashratio_scanhash,
+ .thread_shutdown = hashratio_shutdown,
+};
diff --git a/driver-hashratio.h b/driver-hashratio.h
new file mode 100644
index 0000000..50e3452
--- /dev/null
+++ b/driver-hashratio.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2013 Con Kolivas <kernel@kolivas.org>
+ * Copyright 2012-2014 Xiangfu <xiangfu@openmobilefree.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version. See COPYING for more details.
+ */
+
+#ifndef _HASHRATIO_H_
+#define _HASHRATIO_H_
+
+#include "util.h"
+#include "fpgautils.h"
+
+#ifdef USE_HASHRATIO
+
+#define HRTO_MINER_THREADS 1
+
+#define HRTO_RESET_FAULT_DECISECONDS 10
+#define HRTO_IO_SPEED 115200
+
+#define HRTO_DEFAULT_MODULARS 5
+#define HRTO_DEFAULT_MINERS_PER_MODULAR 16
+/* total chips number */
+#define HRTO_DEFAULT_MINERS (HRTO_DEFAULT_MODULARS * 16)
+
+#define HRTO_PWM_MAX 0x3FF
+#define HRTO_DEFAULT_FAN 20 /* N% */
+#define HRTO_DEFAULT_FAN_MIN 50 /* N% */
+#define HRTO_DEFAULT_FAN_MAX 100 /* N% */
+
+#define HRTO_DEFAULT_FREQUENCY 280 /* MHz */
+#define HRTO_DEFAULT_FREQUENCY_MIN 100
+#define HRTO_DEFAULT_FREQUENCY_MAX 750
+
+#define HRTO_FAN_COUNT 2
+//#define HRTO_TEMP_COUNT 1
+
+/* Hashratio protocol package type */
+#define HRTO_H1 'H'
+#define HRTO_H2 'R'
+
+#define HRTO_P_COINBASE_SIZE (6 * 1024)
+#define HRTO_P_MERKLES_COUNT 20
+
+#define HRTO_P_COUNT 39
+#define HRTO_P_DATA_LEN (HRTO_P_COUNT - 7)
+
+#define HRTO_P_DETECT 10 // 0x0a
+#define HRTO_P_STATIC 11 // 0x0b
+#define HRTO_P_JOB_ID 12 // 0x0c
+#define HRTO_P_COINBASE 13 // 0x0d
+#define HRTO_P_MERKLES 14 // 0x0e
+#define HRTO_P_HEADER 15 // 0x0f
+#define HRTO_P_POLLING 16 // 0x10
+#define HRTO_P_TARGET 17 // 0x11
+#define HRTO_P_REQUIRE 18 // 0x12
+#define HRTO_P_SET 19 // 0x13
+#define HRTO_P_TEST 20 // 0x14
+
+#define HRTO_P_ACK 51 // 0x33
+#define HRTO_P_NAK 52 // 0x34
+#define HRTO_P_NONCE 53 // 0x35
+#define HRTO_P_STATUS 54 // 0x36
+#define HRTO_P_ACKDETECT 55 // 0x37
+#define HRTO_P_TEST_RET 56 // 0x38
+/* Hashratio protocol package type */
+
+struct hashratio_pkg {
+ uint8_t head[2];
+ uint8_t type;
+ uint8_t idx;
+ uint8_t cnt;
+ uint8_t data[32];
+ uint8_t crc[2];
+};
+#define hashratio_ret hashratio_pkg
+
+struct hashratio_info {
+ int default_freq;
+
+ int fan_pwm;
+
+ int temp;
+ int fan[HRTO_FAN_COUNT];
+// uint8_t freq[HRTO_DEFAULT_MINERS];
+ uint8_t target_freq[HRTO_DEFAULT_MINERS];
+
+ int temp_max;
+ int temp_history_count;
+ int temp_history_index;
+ int temp_sum;
+ int temp_old;
+
+ bool first;
+ bool new_stratum;
+
+ int pool_no;
+ int diff;
+
+ int local_works;
+ int hw_works;
+ int matching_work[HRTO_DEFAULT_MINERS];
+ int local_work;
+ int hw_work;
+
+// uint32_t get_result_counter;
+
+ char mm_version[16];
+};
+
+#define HRTO_WRITE_SIZE (sizeof(struct hashratio_pkg))
+#define HRTO_READ_SIZE HRTO_WRITE_SIZE
+
+#define HRTO_GETS_OK 0
+#define HRTO_GETS_TIMEOUT -1
+#define HRTO_GETS_RESTART -2
+#define HRTO_GETS_ERROR -3
+
+#define HRTO_SEND_OK 0
+#define HRTO_SEND_ERROR -1
+
+#define hashratio_open(devpath, baud, purge) serial_open(devpath, baud, HRTO_RESET_FAULT_DECISECONDS, purge)
+#define hashratio_close(fd) close(fd)
+
+extern char *set_hashratio_fan(char *arg);
+extern char *set_hashratio_freq(char *arg);
+
+#endif /* USE_HASHRATIO */
+#endif /* _HASHRATIO_H_ */
diff --git a/miner.h b/miner.h
index 7a43fed..f8db614 100644
--- a/miner.h
+++ b/miner.h
@@ -237,6 +237,7 @@ static inline int fsync (int fd)
DRIVER_ADD_COMMAND(bitfury) \
DRIVER_ADD_COMMAND(cointerra) \
DRIVER_ADD_COMMAND(hashfast) \
+ DRIVER_ADD_COMMAND(hashratio) \
DRIVER_ADD_COMMAND(icarus) \
DRIVER_ADD_COMMAND(klondike) \
DRIVER_ADD_COMMAND(knc) \
@@ -1092,6 +1093,10 @@ extern pthread_cond_t restart_cond;
extern void clear_stratum_shares(struct pool *pool);
extern void clear_pool_work(struct pool *pool);
extern void set_target(unsigned char *dest_target, double diff);
+#if defined (USE_AVALON2) || defined (USE_HASHRATIO)
+void submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *real_pool,
+ uint32_t nonce2, uint32_t nonce);
+#endif
extern int restart_wait(struct thr_info *thr, unsigned int mstime);
extern void kill_work(void);
diff --git a/usbutils.c b/usbutils.c
index 595ed05..b09a84f 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -72,6 +72,7 @@ static cgtimer_t usb11_cgt;
#define KLONDIKE_TIMEOUT_MS 999
#define COINTERRA_TIMEOUT_MS 999
#define HASHFAST_TIMEOUT_MS 999
+#define HASHRATIO_TIMEOUT_MS 999
/* The safety timeout we use, cancelling async transfers on windows that fail
* to timeout on their own. */
@@ -85,6 +86,7 @@ static cgtimer_t usb11_cgt;
#define KLONDIKE_TIMEOUT_MS 200
#define COINTERRA_TIMEOUT_MS 200
#define HASHFAST_TIMEOUT_MS 500
+#define HASHRATIO_TIMEOUT_MS 200
#endif
#define USB_EPS(_intx, _epinfosx) { \
@@ -216,6 +218,17 @@ static struct usb_intinfo hfa_ints[] = {
};
#endif
+#ifdef USE_HASHRATIO
+static struct usb_epinfo hro_epinfos[] = {
+ { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0, 0 },
+ { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0, 0 }
+};
+
+static struct usb_intinfo hro_ints[] = {
+ USB_EPS(0, hro_epinfos)
+};
+#endif
+
#ifdef USE_MODMINER
static struct usb_epinfo mmq_epinfos[] = {
{ LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(3), 0, 0 },
@@ -538,6 +551,18 @@ static struct usb_find_devices find_dev[] = {
.latency = LATENCY_UNUSED,
INTINFO(hfa_ints) },
#endif
+#ifdef USE_HASHRATIO
+ {
+ .drv = DRIVER_hashratio,
+ .name = "HRO",
+ .ident = IDENT_HRO,
+ .idVendor = IDVENDOR_FTDI,
+ .idProduct = 0x6001,
+ .config = 1,
+ .timeout = HASHRATIO_TIMEOUT_MS,
+ .latency = LATENCY_UNUSED,
+ INTINFO(hro_ints) },
+#endif
#ifdef USE_KLONDIKE
{
.drv = DRIVER_klondike,
diff --git a/usbutils.h b/usbutils.h
index 8e9f949..31255da 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -155,6 +155,7 @@ enum sub_ident {
IDENT_CTA,
IDENT_DRB,
IDENT_HFA,
+ IDENT_HRO,
IDENT_ICA,
IDENT_KLN,
IDENT_LIN,
@@ -419,6 +420,8 @@ struct cg_usb_info {
USB_ADD_COMMAND(C_HF_NOTICE, "HFNotice") \
USB_ADD_COMMAND(C_HF_PING, "HFPing") \
USB_ADD_COMMAND(C_HF_FAN, "HFFan") \
+ USB_ADD_COMMAND(C_HRO_WRITE, "HROWrite") \
+ USB_ADD_COMMAND(C_HRO_READ, "HRORead") \
USB_ADD_COMMAND(C_OP_NAME, "HFName") \
USB_ADD_COMMAND(C_HF_GETHEADER, "HFGetHeader") \
USB_ADD_COMMAND(C_HF_GETDATA, "HFGetData") \