Perfect function of BitMain Multi Chain
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
diff --git a/driver-bitmain.c b/driver-bitmain.c
index 45c3576..184d5f1 100644
--- a/driver-bitmain.c
+++ b/driver-bitmain.c
@@ -1,6 +1,5 @@
/*
- * Copyright 2013 BitMain <xlc1985@126.com>
- * Copyright 2012-2013 LingchaoXu <xlc1985@126.com>
+ * Copyright 2012-2013 Lingchao Xu <lingchao.xu@bitmaintech.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
@@ -50,7 +49,6 @@ int opt_bitmain_freq_max = BITMAIN_MAX_FREQUENCY;
bool opt_bitmain_auto;
static int option_offset = -1;
-struct device_drv bitmain_drv;
// --------------------------------------------------------------
// CRC16 check table
@@ -911,17 +909,21 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info
applog(LOG_ERR, "work %d data2: %s", work->id, ob_hex);
free(ob_hex);*/
- if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) {
- applog(LOG_DEBUG, "bitmain_decode_nonce info->qlock start");
- mutex_lock(&info->qlock);
- info->nonces++;
- info->auto_nonces++;
- mutex_unlock(&info->qlock);
- applog(LOG_DEBUG, "bitmain_decode_nonce info->qlock stop");
- } else {
- //bitmain_inc_nvw(info, thr);
- applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id);
- }
+ if(work->work_block < info->last_work_block) {
+ applog(LOG_ERR, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id);
+ } else {
+ if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) {
+ applog(LOG_DEBUG, "bitmain_decode_nonce info->qlock start");
+ mutex_lock(&info->qlock);
+ info->nonces++;
+ info->auto_nonces++;
+ mutex_unlock(&info->qlock);
+ applog(LOG_DEBUG, "bitmain_decode_nonce info->qlock stop");
+ } else {
+ //bitmain_inc_nvw(info, thr);
+ applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id);
+ }
+ }
free_work(work);
} else {
//bitmain_inc_nvw(info, thr);
@@ -973,13 +975,11 @@ static void *bitmain_get_results(void *userdata)
const int rsize = BITMAIN_FTDI_READSIZE;
char readbuf[BITMAIN_READBUF_SIZE];
struct thr_info *thr = info->thr;
- cgtimer_t ts_start;
char threadname[24];
int errorcount = 0;
snprintf(threadname, 24, "btm_recv/%d", bitmain->device_id);
RenameThread(threadname);
- cgsleep_prepare_r(&ts_start);
while (likely(!bitmain->shutdown)) {
unsigned char buf[rsize];
@@ -1020,12 +1020,9 @@ static void *bitmain_get_results(void *userdata)
errorcount++;
if(errorcount > 100) {
applog(LOG_ERR, "bitmain_read errorcount ret=%d", ret);
- cgsleep_prepare_r(&ts_start);
- cgsleep_ms_r(&ts_start, 20);
+ cgsleep_ms(20);
errorcount = 0;
}
- //cgsleep_prepare_r(&ts_start);
- //cgsleep_ms_r(&ts_start, 200);
continue;
}
@@ -1230,10 +1227,15 @@ static void bitmain_usb_init(struct cgpu_info *bitmain)
{
int err, interface;
+#ifndef WIN32
+ return;
+#endif
+
if (bitmain->usbinfo.nodev)
return;
- interface = bitmain->usbdev->found->interface;
+ interface = usb_interface(bitmain);
+
// Reset
err = usb_transfer(bitmain, FTDI_TYPE_OUT, FTDI_REQUEST_RESET,
FTDI_VALUE_RESET, interface, C_RESET);
@@ -1314,7 +1316,7 @@ static void bitmain_usb_init(struct cgpu_info *bitmain)
bitmain->drv->name, bitmain->device_id, err);
}
-static bool bitmain_usb_detect_one(libusb_device *dev, struct usb_find_devices *found)
+static struct cgpu_info * bitmain_usb_detect_one(libusb_device *dev, struct usb_find_devices *found)
{
int baud, chain_num, asic_num, timeout, frequency = 0;
uint8_t reg_data[4] = {0};
@@ -1325,20 +1327,25 @@ static bool bitmain_usb_detect_one(libusb_device *dev, struct usb_find_devices *
int ret;
if (opt_bitmain_options == NULL)
- return false;
+ return NULL;
bitmain = usb_alloc_cgpu(&bitmain_drv, BITMAIN_MINER_THREADS);
- configured = get_options(this_option_offset, &baud, &chain_num,
- &asic_num, &timeout, &frequency, reg_data);
+ baud = BITMAIN_IO_SPEED;
+ chain_num = BITMAIN_DEFAULT_CHAIN_NUM;
+ asic_num = BITMAIN_DEFAULT_ASIC_NUM;
+ timeout = BITMAIN_DEFAULT_TIMEOUT;
+ frequency = BITMAIN_DEFAULT_FREQUENCY;
if (!usb_init(bitmain, dev, found))
goto shin;
+ configured = get_options(this_option_offset, &baud, &chain_num,
+ &asic_num, &timeout, &frequency, reg_data);
+
/* Even though this is an FTDI type chip, we want to do the parsing
* all ourselves so set it to std usb type */
bitmain->usbdev->usb_type = USB_TYPE_STD;
- bitmain->usbdev->PrefPacketSize = BITMAIN_USB_PACKETSIZE;
/* We have a real BitMain! */
bitmain_usb_init(bitmain);
@@ -1393,7 +1400,7 @@ static bool bitmain_usb_detect_one(libusb_device *dev, struct usb_find_devices *
bitmain->device_path, info->chain_num, info->asic_num, info->timeout,
info->frequency);
- return true;
+ return bitmain;
unshin:
@@ -1406,7 +1413,7 @@ shin:
bitmain = usb_free_cgpu(bitmain);
- return false;
+ return NULL;
}
static bool bitmain_detect_one(const char * devpath)
@@ -1493,7 +1500,7 @@ shin:
return false;
}
-static void bitmain_detect(void)
+static void bitmain_detect(bool __maybe_unused hotplug)
{
applog(LOG_DEBUG, "BTM detect dev: %s", opt_bitmain_dev);
if(strlen(opt_bitmain_dev) <= 0) {
@@ -1872,8 +1879,8 @@ char *set_bitmain_freq(char *arg)
}
struct device_drv bitmain_drv = {
- .drv_id = DRIVER_BITMAIN,
- .dname = "bitmain",
+ .drv_id = DRIVER_bitmain,
+ .dname = "Bitmain",
.name = "BTM",
.drv_detect = bitmain_detect,
.thread_prepare = bitmain_prepare,