From 28f4fc64fdaf75b9b1948cb9590a2a27d3469cf6 Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 16 May 2013 19:33:30 +1000 Subject: [PATCH 01/12] usbutils identify Icarus devices --- usbutils.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/usbutils.c b/usbutils.c index 79a46982..916c65a2 100644 --- a/usbutils.c +++ b/usbutils.c @@ -57,11 +57,13 @@ #define BITFORCE_TIMEOUT_MS 999 #define MODMINER_TIMEOUT_MS 200 #define AVALON_TIMEOUT_MS 500 +#define ICARUS_TIMEOUT_MS 500 #else #define BFLSC_TIMEOUT_MS 200 #define BITFORCE_TIMEOUT_MS 200 #define MODMINER_TIMEOUT_MS 100 #define AVALON_TIMEOUT_MS 200 +#define ICARUS_TIMEOUT_MS 200 #endif #ifdef USE_BFLSC @@ -94,15 +96,27 @@ static struct usb_endpoints ava_eps[] = { }; #endif -// TODO: Add support for (at least) Isochronous endpoints -static struct usb_find_devices find_dev[] = { -/* #ifdef USE_ICARUS - { DRV_ICARUS, "ICA", 0x067b, 0x0230, true, EPI(3), EPO(2), 1 }, - { DRV_ICARUS, "LOT", 0x0403, 0x6001, false, EPI(0), EPO(0), 1 }, - { DRV_ICARUS, "CM1", 0x067b, 0x0230, false, EPI(0), EPO(0), 1 }, +static struct usb_endpoints ica_eps[] = { + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(3), 0 }, + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 } +}; +static struct usb_endpoints amu_eps[] = { + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 }, + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(1), 0 } +}; +static struct usb_endpoints lot_eps[] = { + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 }, + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 } +}; +static struct usb_endpoints cmr_eps[] = { + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 }, + { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 } +}; #endif -*/ + +// TODO: Add support for (at least) Isochronous endpoints +static struct usb_find_devices find_dev[] = { #ifdef USE_BFLSC { .drv = DRV_BFLSC, @@ -159,6 +173,66 @@ static struct usb_find_devices find_dev[] = { .epcount = ARRAY_SIZE(ava_eps), .eps = ava_eps }, #endif +#ifdef USE_ICARUS + { + .drv = DRV_ICARUS, + .name = "ICA", + .idVendor = 0x067b, + .idProduct = 0x2303, + .kernel = 0, + .config = 1, + .interface = 0, + .timeout = ICARUS_TIMEOUT_MS, + .epcount = ARRAY_SIZE(ica_eps), + .eps = ica_eps }, + { + .drv = DRV_ICARUS, + .name = "AMU", + .idVendor = 0x10c4, + .idProduct = 0xea60, + .kernel = 0, + .config = 1, + .interface = 0, + .timeout = ICARUS_TIMEOUT_MS, + .epcount = ARRAY_SIZE(amu_eps), + .eps = amu_eps }, + { + .drv = DRV_ICARUS, + .name = "BAT", + .idVendor = 0x0403, + .idProduct = 0x6001, + .iProduct = "FT232R USB UART", + .kernel = 0, + .config = 1, + .interface = 0, + .timeout = ICARUS_TIMEOUT_MS, + .epcount = ARRAY_SIZE(lot_eps), + .eps = lot_eps }, + // For any that don't match the above "BAT" + { + .drv = DRV_ICARUS, + .name = "LLT", + .idVendor = 0x0403, + .idProduct = 0x6001, + .kernel = 0, + .config = 1, + .interface = 0, + .timeout = ICARUS_TIMEOUT_MS, + .epcount = ARRAY_SIZE(lot_eps), + .eps = lot_eps }, + { + .drv = DRV_ICARUS, + .name = "CMR", + .idVendor = 0x067b, + .idProduct = 0x0230, + .iProduct = "Cairnsmore1", + .kernel = 0, + .config = 1, + .interface = 0, + .timeout = ICARUS_TIMEOUT_MS, + .epcount = ARRAY_SIZE(cmr_eps), + .eps = cmr_eps }, +#endif #ifdef USE_ZTEX // This is here so cgminer -n shows them // the ztex driver (as at 201303) doesn't use usbutils From 2a0b712ed5ea91debead706b622015a3435400d4 Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 16 May 2013 19:39:40 +1000 Subject: [PATCH 02/12] usbutils set Black Arrow Lancelot's as BAL and match the lot->llt name --- usbutils.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/usbutils.c b/usbutils.c index 916c65a2..b5981f72 100644 --- a/usbutils.c +++ b/usbutils.c @@ -105,7 +105,7 @@ static struct usb_endpoints amu_eps[] = { { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 }, { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(1), 0 } }; -static struct usb_endpoints lot_eps[] = { +static struct usb_endpoints llt_eps[] = { { LIBUSB_TRANSFER_TYPE_BULK, 64, EPI(1), 0 }, { LIBUSB_TRANSFER_TYPE_BULK, 64, EPO(2), 0 } }; @@ -198,7 +198,7 @@ static struct usb_find_devices find_dev[] = { .eps = amu_eps }, { .drv = DRV_ICARUS, - .name = "BAT", + .name = "BAL", .idVendor = 0x0403, .idProduct = 0x6001, .iProduct = "FT232R USB UART", @@ -206,9 +206,9 @@ static struct usb_find_devices find_dev[] = { .config = 1, .interface = 0, .timeout = ICARUS_TIMEOUT_MS, - .epcount = ARRAY_SIZE(lot_eps), - .eps = lot_eps }, - // For any that don't match the above "BAT" + .epcount = ARRAY_SIZE(llt_eps), + .eps = llt_eps }, + // For any that don't match the above "BAL" { .drv = DRV_ICARUS, .name = "LLT", @@ -218,8 +218,8 @@ static struct usb_find_devices find_dev[] = { .config = 1, .interface = 0, .timeout = ICARUS_TIMEOUT_MS, - .epcount = ARRAY_SIZE(lot_eps), - .eps = lot_eps }, + .epcount = ARRAY_SIZE(llt_eps), + .eps = llt_eps }, { .drv = DRV_ICARUS, .name = "CMR", From 92e5ee9d66e925fb9d02450efed0cf258af94eea Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 16 May 2013 19:41:53 +1000 Subject: [PATCH 03/12] fix duplicate name --- usbutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usbutils.c b/usbutils.c index b5981f72..f0109609 100644 --- a/usbutils.c +++ b/usbutils.c @@ -198,7 +198,7 @@ static struct usb_find_devices find_dev[] = { .eps = amu_eps }, { .drv = DRV_ICARUS, - .name = "BAL", + .name = "BLT", .idVendor = 0x0403, .idProduct = 0x6001, .iProduct = "FT232R USB UART", @@ -208,7 +208,7 @@ static struct usb_find_devices find_dev[] = { .timeout = ICARUS_TIMEOUT_MS, .epcount = ARRAY_SIZE(llt_eps), .eps = llt_eps }, - // For any that don't match the above "BAL" + // For any that don't match the above "BLT" { .drv = DRV_ICARUS, .name = "LLT", From 2631b55ee2683c3a849d812dd8d30779f032e863 Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 16 May 2013 21:38:55 +1000 Subject: [PATCH 04/12] usbutils - make FTDI handling automatic --- driver-bflsc.c | 16 ++++++++-------- driver-bitforce.c | 10 +++++----- usbutils.c | 18 ++++++++++++------ usbutils.h | 32 ++++++++++++++++---------------- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/driver-bflsc.c b/driver-bflsc.c index 0e8c57d9..a532e0dd 100644 --- a/driver-bflsc.c +++ b/driver-bflsc.c @@ -487,7 +487,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo { char buf[BFLSC_BUFSIZ+1]; - *err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd); + *err = usb_read_nl(bflsc, buf, sizeof(buf)-1, amount, cmd); if (*err < 0 || *amount < (int)BFLSC_OK_LEN) return false; else @@ -496,7 +496,7 @@ static bool getok(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amo static bool getokerr(struct cgpu_info *bflsc, enum usb_cmds cmd, int *err, int *amount, char *buf, size_t bufsiz) { - *err = usb_ftdi_read_nl(bflsc, buf, bufsiz-1, amount, cmd); + *err = usb_read_nl(bflsc, buf, bufsiz-1, amount, cmd); if (*err < 0 || *amount < (int)BFLSC_OK_LEN) return false; else { @@ -529,7 +529,7 @@ static void bflsc_send_flush_work(struct cgpu_info *bflsc, int dev) } } -/* return True = attempted usb_ftdi_read_ok() +/* return True = attempted usb_read_ok() * set ignore to true means no applog/ignore errors */ static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int dev, int *err, int *amount, bool ignore) { @@ -550,7 +550,7 @@ static bool bflsc_qres(struct cgpu_info *bflsc, char *buf, size_t bufsiz, int de // of course all other I/O must also be failing ... } else { readok = true; - *err = usb_ftdi_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS); + *err = usb_read_ok(bflsc, buf, bufsiz-1, amount, C_GETRESULTS); mutex_unlock(&(bflsc->device_mutex)); if (*err < 0 || *amount < 1) { @@ -695,7 +695,7 @@ static bool getinfo(struct cgpu_info *bflsc, int dev) return false; } - err = usb_ftdi_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS); + err = usb_read_ok(bflsc, buf, sizeof(buf)-1, &amount, C_GETDETAILS); if (err < 0 || amount < 1) { if (err < 0) { applog(LOG_ERR, "%s detect (%s) get details return invalid/timed out (%d:%d)", @@ -830,7 +830,7 @@ reinit: goto unshin; } - err = usb_ftdi_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY); + err = usb_read_nl(bflsc, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY); if (err < 0 || amount < 1) { init_count++; cgtime(&init_now); @@ -1095,7 +1095,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev) return false; } - err = usb_ftdi_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE); + err = usb_read_nl(bflsc, temp_buf, sizeof(temp_buf)-1, &amount, C_GETTEMPERATURE); if (err < 0 || amount < 1) { mutex_unlock(&(bflsc->device_mutex)); if (err < 0) { @@ -1117,7 +1117,7 @@ static bool bflsc_get_temp(struct cgpu_info *bflsc, int dev) return false; } - err = usb_ftdi_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE); + err = usb_read_nl(bflsc, volt_buf, sizeof(volt_buf)-1, &amount, C_GETTEMPERATURE); if (err < 0 || amount < 1) { mutex_unlock(&(bflsc->device_mutex)); if (err < 0) { diff --git a/driver-bitforce.c b/driver-bitforce.c index f703edcc..7b4361bb 100644 --- a/driver-bitforce.c +++ b/driver-bitforce.c @@ -200,7 +200,7 @@ reinit: goto unshin; } - if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) { + if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETIDENTIFY)) < 0 || amount < 1) { init_count++; cgtime(&init_now); if (us_tdiff(&init_now, &init_start) <= REINIT_TIME_MAX) { @@ -395,7 +395,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce) return false; } - if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) { + if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETTEMPERATURE)) < 0 || amount < 1) { mutex_unlock(&bitforce->device_mutex); if (err < 0) { applog(LOG_ERR, "%s%i: Error: Get temp return invalid/timed out (%d:%d)", @@ -470,7 +470,7 @@ re_send: return false; } - if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) { + if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_REQUESTSENDWORKSTATUS)) < 0) { mutex_unlock(&bitforce->device_mutex); applog(LOG_ERR, "%s%d: read request send work status failed (%d:%d)", bitforce->drv->name, bitforce->device_id, amount, err); @@ -524,7 +524,7 @@ re_send: return false; } - if ((err = usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) { + if ((err = usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_SENDWORKSTATUS)) < 0) { mutex_unlock(&bitforce->device_mutex); applog(LOG_ERR, "%s%d: read send work status failed (%d:%d)", bitforce->drv->name, bitforce->device_id, amount, err); @@ -573,7 +573,7 @@ static int64_t bitforce_get_result(struct thr_info *thr, struct work *work) mutex_lock(&bitforce->device_mutex); usb_write(bitforce, BITFORCE_WORKSTATUS, BITFORCE_WORKSTATUS_LEN, &amount, C_REQUESTWORKSTATUS); - usb_ftdi_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS); + usb_read_nl(bitforce, buf, sizeof(buf)-1, &amount, C_GETWORKSTATUS); mutex_unlock(&bitforce->device_mutex); cgtime(&now); diff --git a/usbutils.c b/usbutils.c index f0109609..2d286d15 100644 --- a/usbutils.c +++ b/usbutils.c @@ -115,13 +115,15 @@ static struct usb_endpoints cmr_eps[] = { }; #endif +#define IDVENDOR_FTDI 0x0403 + // TODO: Add support for (at least) Isochronous endpoints static struct usb_find_devices find_dev[] = { #ifdef USE_BFLSC { .drv = DRV_BFLSC, .name = "BAS", - .idVendor = 0x0403, + .idVendor = IDVENDOR_FTDI, .idProduct = 0x6014, .iManufacturer = "Butterfly Labs", .iProduct = "BitFORCE SHA256 SC", @@ -136,7 +138,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_BITFORCE, .name = "BFL", - .idVendor = 0x0403, + .idVendor = IDVENDOR_FTDI, .idProduct = 0x6014, .iManufacturer = "Butterfly Labs Inc.", .iProduct = "BitFORCE SHA256", @@ -164,7 +166,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_AVALON, .name = "AVA", - .idVendor = 0x0403, + .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .kernel = 0, .config = 1, @@ -199,7 +201,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "BLT", - .idVendor = 0x0403, + .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .iProduct = "FT232R USB UART", .kernel = 0, @@ -212,7 +214,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "LLT", - .idVendor = 0x0403, + .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .kernel = 0, .config = 1, @@ -1330,6 +1332,9 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u cgusb = calloc(1, sizeof(*cgusb)); cgusb->found = found; + if (found->idVendor == IDVENDOR_FTDI) + cgusb->usb_type = USB_TYPE_FTDI; + cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor))); err = libusb_get_device_descriptor(dev, cgusb->descriptor); @@ -1911,9 +1916,10 @@ static void rejected_inc(struct cgpu_info *cgpu) #define USB_MAX_READ 8192 -int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce) +int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce) { struct cg_usb_device *usbdev = cgpu->usbdev; + bool ftdi = (usbdev->usb_type == USB_TYPE_FTDI); #if DO_USB_STATS struct timeval tv_start; #endif diff --git a/usbutils.h b/usbutils.h index 2c4f6424..64a4546f 100644 --- a/usbutils.h +++ b/usbutils.h @@ -65,12 +65,18 @@ struct usb_find_devices { struct usb_endpoints *eps; }; +enum usb_types { + USB_TYPE_STD = 0, + USB_TYPE_FTDI +}; + struct cg_usb_device { struct usb_find_devices *found; libusb_device_handle *handle; pthread_mutex_t *mutex; struct libusb_device_descriptor *descriptor; uint16_t usbver; + enum usb_types usb_type; int speed; char *prod_string; char *manuf_string; @@ -150,29 +156,32 @@ bool usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct usb_find void usb_detect(struct device_drv *drv, bool (*device_detect)(struct libusb_device *, struct usb_find_devices *)); struct api_data *api_usb_stats(int *count); void update_usb_stats(struct cgpu_info *cgpu); -int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool ftdi, bool readonce); +int _usb_read(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, const char *end, enum usb_cmds cmd, bool readonce); int _usb_write(struct cgpu_info *cgpu, int ep, char *buf, size_t bufsiz, int *processed, unsigned int timeout, enum usb_cmds); int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned int timeout, enum usb_cmds cmd); void usb_cleanup(); void usb_initialise(); #define usb_read(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false) + _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false) #define usb_read_once(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, true) + _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true) #define usb_read_nl(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false, false) + _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, false) + +#define usb_read_ok(cgpu, buf, bufsiz, read, cmd) \ + _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, false) #define usb_read_ep(cgpu, ep, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false, false) + _usb_read(cgpu, ep, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, false) #define usb_read_timeout(cgpu, buf, bufsiz, read, timeout, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false, false) + _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, timeout, NULL, cmd, false) #define usb_read_ep_timeout(cgpu, ep, buf, bufsiz, read, timeout, cmd) \ - _usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false, false) + _usb_read(cgpu, ep, buf, bufsiz, read, timeout, NULL, cmd, false) #define usb_write(cgpu, buf, bufsiz, wrote, cmd) \ _usb_write(cgpu, DEFAULT_EP_OUT, buf, bufsiz, wrote, DEVTIMEOUT, cmd) @@ -186,15 +195,6 @@ void usb_initialise(); #define usb_write_ep_timeout(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) \ _usb_write(cgpu, ep, buf, bufsiz, wrote, timeout, cmd) -#define usb_ftdi_read(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, NULL, cmd, true, false) - -#define usb_ftdi_read_nl(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "\n", cmd, true, false) - -#define usb_ftdi_read_ok(cgpu, buf, bufsiz, read, cmd) \ - _usb_read(cgpu, DEFAULT_EP_IN, buf, bufsiz, read, DEVTIMEOUT, "OK\n", cmd, true, false) - #define usb_transfer(cgpu, typ, req, val, idx, cmd) \ _usb_transfer(cgpu, typ, req, val, idx, DEVTIMEOUT, cmd) From e89c921ab09e5d2fa0e33e8e7d24bdc49f54baf8 Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 16 May 2013 22:16:15 +1000 Subject: [PATCH 05/12] usb add a numeric sub-indentity for each name --- driver-bflsc.c | 3 +++ usbutils.c | 14 +++++++++++++- usbutils.h | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/driver-bflsc.c b/driver-bflsc.c index a532e0dd..9c1528ca 100644 --- a/driver-bflsc.c +++ b/driver-bflsc.c @@ -897,17 +897,20 @@ reinit: sc_info->scan_sleep_time = BAM_SCAN_TIME; sc_info->results_sleep_time = BAM_RES_TIME; sc_info->default_ms_work = BAM_WORK_TIME; + bflsc->usbdev->ident = IDENT_BAM; } else { if (sc_info->sc_devs[0].engines < 34) { // 16 * 2 + 2 newname = BFLSC_JALAPENO; sc_info->scan_sleep_time = BAJ_SCAN_TIME; sc_info->results_sleep_time = BAJ_RES_TIME; sc_info->default_ms_work = BAJ_WORK_TIME; + bflsc->usbdev->ident = IDENT_BAJ; } else if (sc_info->sc_devs[0].engines < 130) { // 16 * 8 + 2 newname = BFLSC_LITTLESINGLE; sc_info->scan_sleep_time = BAL_SCAN_TIME; sc_info->results_sleep_time = BAL_RES_TIME; sc_info->default_ms_work = BAL_WORK_TIME; + bflsc->usbdev->ident = IDENT_BAL; } } diff --git a/usbutils.c b/usbutils.c index 2d286d15..4d51dcf8 100644 --- a/usbutils.c +++ b/usbutils.c @@ -123,6 +123,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_BFLSC, .name = "BAS", + .ident = IDENT_BAS, .idVendor = IDVENDOR_FTDI, .idProduct = 0x6014, .iManufacturer = "Butterfly Labs", @@ -138,6 +139,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_BITFORCE, .name = "BFL", + .ident = IDENT_BFL, .idVendor = IDVENDOR_FTDI, .idProduct = 0x6014, .iManufacturer = "Butterfly Labs Inc.", @@ -153,6 +155,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_MODMINER, .name = "MMQ", + .ident = IDENT_MMQ, .idVendor = 0x1fc9, .idProduct = 0x0003, .kernel = 0, @@ -166,6 +169,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_AVALON, .name = "AVA", + .ident = IDENT_AVA, .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .kernel = 0, @@ -179,6 +183,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "ICA", + .ident = IDENT_ICA, .idVendor = 0x067b, .idProduct = 0x2303, .kernel = 0, @@ -190,6 +195,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "AMU", + .ident = IDENT_AMU, .idVendor = 0x10c4, .idProduct = 0xea60, .kernel = 0, @@ -201,6 +207,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "BLT", + .ident = IDENT_BLT, .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .iProduct = "FT232R USB UART", @@ -214,6 +221,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "LLT", + .ident = IDENT_LLT, .idVendor = IDVENDOR_FTDI, .idProduct = 0x6001, .kernel = 0, @@ -225,6 +233,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ICARUS, .name = "CMR", + .ident = IDENT_CMR, .idVendor = 0x067b, .idProduct = 0x0230, .iProduct = "Cairnsmore1", @@ -241,6 +250,7 @@ static struct usb_find_devices find_dev[] = { { .drv = DRV_ZTEX, .name = "ZTX", + .ident = IDENT_ZTX, .idVendor = 0x221a, .idProduct = 0x0100, .kernel = 0, @@ -250,7 +260,7 @@ static struct usb_find_devices find_dev[] = { .epcount = 0, .eps = NULL }, #endif - { DRV_LAST, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL } + { DRV_LAST, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, NULL } }; #ifdef USE_BFLSC @@ -1335,6 +1345,8 @@ static int _usb_init(struct cgpu_info *cgpu, struct libusb_device *dev, struct u if (found->idVendor == IDVENDOR_FTDI) cgusb->usb_type = USB_TYPE_FTDI; + cgusb->ident = found->ident; + cgusb->descriptor = calloc(1, sizeof(*(cgusb->descriptor))); err = libusb_get_device_descriptor(dev, cgusb->descriptor); diff --git a/usbutils.h b/usbutils.h index 64a4546f..ed82ac62 100644 --- a/usbutils.h +++ b/usbutils.h @@ -50,9 +50,26 @@ struct usb_endpoints { bool found; }; +enum sub_ident { + IDENT_BAJ, + IDENT_BAL, + IDENT_BAS, + IDENT_BAM, + IDENT_BFL, + IDENT_MMQ, + IDENT_AVA, + IDENT_ICA, + IDENT_AMU, + IDENT_BLT, + IDENT_LLT, + IDENT_CMR, + IDENT_ZTX +}; + struct usb_find_devices { int drv; const char *name; + enum sub_ident ident; uint16_t idVendor; uint16_t idProduct; char *iManufacturer; @@ -75,8 +92,9 @@ struct cg_usb_device { libusb_device_handle *handle; pthread_mutex_t *mutex; struct libusb_device_descriptor *descriptor; - uint16_t usbver; enum usb_types usb_type; + enum sub_ident ident; + uint16_t usbver; int speed; char *prod_string; char *manuf_string; From 05a385ccfcdc36c7aa1085a684084a55222d7051 Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 13:49:41 +1000 Subject: [PATCH 06/12] usbutils new command for icarus --- usbutils.c | 2 ++ usbutils.h | 1 + 2 files changed, 3 insertions(+) diff --git a/usbutils.c b/usbutils.c index 4d51dcf8..a2663d4c 100644 --- a/usbutils.c +++ b/usbutils.c @@ -407,6 +407,7 @@ static const char *C_QUEJOBSTATUS_S = "QueJobStatus"; static const char *C_QUEFLUSH_S = "QueFlush"; static const char *C_QUEFLUSHREPLY_S = "QueFlushReply"; static const char *C_REQUESTVOLTS_S = "RequestVolts"; +static const char *C_SENDTESTWORK_S = "SendTestWork"; #ifdef EOL #undef EOL @@ -875,6 +876,7 @@ static void cgusb_check_init() usb_commands[C_QUEFLUSH] = C_QUEFLUSH_S; usb_commands[C_QUEFLUSHREPLY] = C_QUEFLUSHREPLY_S; usb_commands[C_REQUESTVOLTS] = C_REQUESTVOLTS_S; + usb_commands[C_SENDTESTWORK] = C_SENDTESTWORK_S; stats_initialised = true; } diff --git a/usbutils.h b/usbutils.h index ed82ac62..74c166e3 100644 --- a/usbutils.h +++ b/usbutils.h @@ -160,6 +160,7 @@ enum usb_cmds { C_QUEFLUSH, C_QUEFLUSHREPLY, C_REQUESTVOLTS, + C_SENDTESTWORK, C_MAX }; From 6219f977f67202ad9435528f95165ad3414c4370 Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 14:10:58 +1000 Subject: [PATCH 07/12] switch icarus configuration to usb --- Makefile.am | 2 +- cgminer.c | 2 +- configure.ac | 35 +++++------------------------------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/Makefile.am b/Makefile.am index ccd4e6b6..b9487ee4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,7 +25,7 @@ bin_SCRIPTS = $(top_srcdir)/*.cl cgminer_LDFLAGS = $(PTHREAD_FLAGS) cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \ @OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \ - @UDEV_LIBS@ @LIBUSB_LIBS@ @MM_LIBS@ \ + @LIBUSB_LIBS@ @MM_LIBS@ \ @MATH_LIBS@ lib/libgnu.a ccan/libccan.a if HAVE_WINDOWS diff --git a/cgminer.c b/cgminer.c index 3b7a387e..974496cf 100644 --- a/cgminer.c +++ b/cgminer.c @@ -60,7 +60,7 @@ #if defined(USE_BITFORCE) || defined(USE_ICARUS) || defined(USE_AVALON) || defined(USE_MODMINER) # define USE_FPGA -#if defined(USE_ICARUS) || defined(USE_AVALON) +#if defined(USE_AVALON) # define USE_FPGA_SERIAL #endif #elif defined(USE_ZTEX) diff --git a/configure.ac b/configure.ac index 804cd218..4af4fb41 100644 --- a/configure.ac +++ b/configure.ac @@ -303,14 +303,14 @@ else ]) fi -AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$icarus$bitforce$modminer$ztex != xnonononono]) -AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc != xnonono]) +AM_CONDITIONAL([NEED_FPGAUTILS], [test x$avalon$modminer$ztex != xnonono]) +AM_CONDITIONAL([NEED_USBUTILS_C], [test x$bitforce$modminer$bflsc$icarus != xnononono]) AM_CONDITIONAL([HAVE_CURSES], [test x$curses = xyes]) AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) AM_CONDITIONAL([HAVE_x86_64], [test x$have_x86_64 = xtrue]) -if test "x$bitforce$modminer$bflsc" != xnonono; then +if test "x$bitforce$modminer$bflsc$icarus" != xnononono; then AC_DEFINE([USE_USBUTILS], [1], [Defined to 1 if usbutils support required]) fi @@ -321,26 +321,6 @@ else JANSSON_LIBS=-ljansson fi -if test "x$icarus" != xno; then - AC_ARG_WITH([libudev], [AC_HELP_STRING([--without-libudev], [Autodetect FPGAs using libudev (default enabled)])], - [libudev=$withval], - [libudev=auto] - ) - if test "x$libudev" != "xno"; then - AC_CHECK_HEADER([libudev.h],[ - libudev=yes - UDEV_LIBS=-ludev - AC_DEFINE([HAVE_LIBUDEV], [1], [Defined to 1 if libudev is wanted]) - ], [ - if test "x$libudev" = "xyes"; then - AC_MSG_ERROR([libudev not found]) - fi - libudev=no - ]) - fi -fi -AM_CONDITIONAL([HAVE_LIBUDEV], [test x$libudev != xno]) - PKG_PROG_PKG_CONFIG() if test "x$have_cgminer_sdk" = "xtrue"; then @@ -353,7 +333,7 @@ if test "x$have_cgminer_sdk" = "xtrue"; then PKG_CONFIG_PATH="$CGMINER_SDK/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" fi -if test "x$ztex$modminer$bitforce$bflsc" != xnononono; then +if test "x$ztex$modminer$bitforce$bflsc$icarus" != xnonononono; then case $target in *-*-freebsd*) LIBUSB_LIBS="-lusb" @@ -441,7 +421,6 @@ AC_SUBST(PDCURSES_LIBS) AC_SUBST(WS2_LIBS) AC_SUBST(MM_LIBS) AC_SUBST(MATH_LIBS) -AC_SUBST(UDEV_LIBS) AC_SUBST(ADL_CPPFLAGS) AC_CONFIG_FILES([ @@ -538,16 +517,12 @@ else echo " Ztex.FPGAs...........: Disabled" fi -if test "x$icarus" != xno; then - echo " libudev.detection....: $libudev" -fi - echo echo "Compilation............: make (or gmake)" echo " CPPFLAGS.............: $CPPFLAGS" echo " CFLAGS...............: $CFLAGS $LIBUSB_CFLAGS" echo " LDFLAGS..............: $LDFLAGS $PTHREAD_FLAGS" -echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $UDEV_LIBS $LIBUSB_LIBS" +echo " LDADD................: $DLOPEN_FLAGS $LIBCURL_LIBS $JANSSON_LIBS $PTHREAD_LIBS $OPENCL_LIBS $NCURSES_LIBS $PDCURSES_LIBS $WS2_LIBS $MATH_LIBS $LIBUSB_LIBS" echo echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')" echo " prefix...............: $prefix" From 079b488a5b5a272b2bfcab9fa5ad1ea80929a05a Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 14:21:43 +1000 Subject: [PATCH 08/12] Add USB rules for supported USB devices --- 01-cgminer.rules | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/01-cgminer.rules b/01-cgminer.rules index 010dba81..f3a488a1 100644 --- a/01-cgminer.rules +++ b/01-cgminer.rules @@ -1,3 +1,20 @@ # Butterfly Labs FPGA and ASIC devices ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# ModMinerQuad ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# Lancelot and Avalon +ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# Icarus +ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# AsicminerUSB +ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# Cairnsmore1 +ATTRS{idVendor}=="067b", ATTRS{idProduct}=="0230", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + +# Ztex +ATTRS{idVendor}=="221a", ATTRS{idProduct}=="0100", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" From 9f4a3a798df6ac963b144073da2e342d948d05dc Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 15:05:51 +1000 Subject: [PATCH 09/12] Update documentation for icarus switch to USB --- ASIC-README | 7 +----- FPGA-README | 29 +++++++++++------------- README | 61 ++++++++++----------------------------------------- cgminer.c | 2 +- driver-ztex.c | 2 +- 5 files changed, 27 insertions(+), 74 deletions(-) diff --git a/ASIC-README b/ASIC-README index 8796a792..6341617d 100644 --- a/ASIC-README +++ b/ASIC-README @@ -44,17 +44,12 @@ If your distribution does not have the plugdev group you can create it with: sudo groupadd plugdev In order for the BFL devices to instantly be owned by the plugdev group and -accessible by anyone from the plugdev group you can either copy the file +accessible by anyone from the plugdev group you can copy the file "01-cgminer.rules" from the cgminer archive into the /etc/udev/rules.d directory with the following command: sudo cp 01-cgminer.rules /etc/udev/rules.d/ -Or you can manually create a file/add to a rules.d file with following rules -(most users won't want to do this manually): -ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" -ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" - After this you can either manually restart udev and re-login, or more easily just reboot. diff --git a/FPGA-README b/FPGA-README index 4dfed2ab..98730b08 100644 --- a/FPGA-README +++ b/FPGA-README @@ -2,16 +2,14 @@ This README contains extended details about FPGA mining with cgminer -For ModMinerQuad (MMQ) and BitForce (BFL) ------------------------------------------ +For ModMinerQuad (MMQ) BitForce (BFL) and Icarus (ICA, BLT, LLT, AMU, CMR) +-------------------------------------------------------------------------- When mining on windows, the driver being used will determine if mining will work. If the driver doesn't allow mining, you will get a "USB init," error message i.e. one of: open device failed, err %d, you need to install a Windows USB driver for the device -or - kernel detach failed :( or claim interface %d failed, err %d @@ -32,19 +30,16 @@ with cgminer (not the libusbx version) When mining on linux, but not using 'sudo' and not logged into 'root' you may get a USB priviledge error (-3), so you may also need to do the following: -Create /etc/udev/rules.d/01-cgminer.rules -With: - ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" - ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="0003", SUBSYSTEMS=="usb", ACTION=="add", MODE="0666", GROUP="plugdev" + sudo cp 01-cgminer.rules /etc/udev/rules.d/ And also: sudo usermod -G plugdev -a `whoami` -Then reboot ... - If your linux distro doesn't have the 'plugdev' group, you can create it like: sudo groupadd plugdev +Then reboot ... + - There is a hidden option in cgminer to dump out a lot of information @@ -53,8 +48,7 @@ problems: --usb-dump 0 -It will only help if you have a working MMQ or BFL device attached to the -computer +It will only help if you have a working FPGA device listed above ModMinerQuad (MMQ) @@ -190,8 +184,8 @@ the MH/s value reported with the changed firmware - and the MH/s reported will be less than the firmware speed since you lose work on every block change. -Icarus (ICA) ------------- +Icarus (ICA, BLT, LLT, AMU, CMR) +-------------------------------- There are two hidden options in cgminer when Icarus support is compiled in: @@ -245,8 +239,8 @@ scan hash time, for the first 5 nonce's or one minute (whichever is longer) In 'default' or 'value' mode the 'constants' are calculated once at the start, based on the default value or the value specified -The optional additional =N specifies to set the default abort at N 1/10ths of a second, not the -calculated value, which is 112 for 2.6316ns +The optional additional =N specifies to set the default abort at N * 100ms, not the calculated +value, which is ~112 for 2.6316ns To determine the hash time value for a non Icarus Rev3 device or an Icarus Rev3 with a different bitstream to the default one, use 'long' mode and give it at least a few hundred shares, or use @@ -258,6 +252,9 @@ Icarus Rev3 requires and also is less than ~840MH/s and greater than 2MH/s If an FPGA device does hash faster than ~840MH/s it should work correctly if you supply the correct hash time nanoseconds value +The Icarus code will automatically detect Icarus, Lancelot, AsicminerUSB and Cairnsmore1 +FPGA devices and set default settings to match those devices if you don't specify them + The timing code itself will affect the Icarus performance since it increases the delay after work is completed or aborted until it starts again The increase is, however, extremely small and the actual increase is reported with the diff --git a/README b/README index bda7fd86..84ca072e 100644 --- a/README +++ b/README @@ -111,7 +111,7 @@ CGMiner specific configuration options: --disable-adl Override detection and disable building with adl --enable-bflsc Compile support for BFL ASICs (default disabled) --enable-bitforce Compile support for BitForce FPGAs(default disabled) - --enable-icarus Compile support for Icarus Board(default disabled) + --enable-icarus Compile support for Icarus bitstream FPGAs(default disabled) --enable-modminer Compile support for ModMiner FPGAs(default disabled) --enable-ztex Compile support for Ztex Board(default disabled) --enable-avalon Compile support for Avalon (default disabled) @@ -235,13 +235,14 @@ ASIC and FPGA mining boards (BFL ASIC, BitForce, Icarus, ModMiner, Ztex) only options: Cgminer will automatically find all of your BFL ASIC, BitForce FPGAs, -ModMiner FPGAs or Ztex FPGAs -The --usb option can restrict how many BFL ASIC, BitForce FPGAs or -ModMiner FPGAs it finds: +ModMiner FPGAs, Icarus bitstream FPGAs or Ztex FPGAs + +The --usb option can restrict how many BFL ASIC, BitForce FPGAs, +ModMiner FPGAs or Icarus bitstream FPGAs it finds: --usb 1:2,1:3,1:4,1:* or - --usb BAS:1,BFL:1,MMQ:0 + --usb BAS:1,BFL:1,MMQ:0,ICA:0 or --usb :10 @@ -260,15 +261,16 @@ This is useful if you unplug a device then plug it back in the same port, it usually reappears with the same bus_number but a different device_address You can see the list of all USB devices on linux with 'sudo lsusb' -Cgminer will list the recognised USB devices with the '--usb-dump 0' option +Cgminer will list the recognised USB devices with the '-n' option or the +'--usb-dump 0' option The '--usb-dump N' option with a value of N greater than 0 will dump a lot of details about each recognised USB device If you wish to see all USB devices, include the --usb-list-all option The second version - --usb BAS:1,BFL:1,MMQ:0 + --usb BAS:1,BFL:1,MMQ:0,ICA:0 allows you to specify how many devices to choose based on each device -driver cgminer has - there are currently 3 USB drivers: BAS, BFL & MMQ +driver cgminer has - there are currently 4 USB drivers: BAS, BFL, MMQ & ICA N.B. you can only specify which device driver to limit, not the type of each device, e.g. with BAS:n you can limit how many BFL ASIC devices will be checked, but you cannot limit the number of each type of BFL ASIC @@ -283,28 +285,8 @@ not scan for any more If one of the 10 devices stops working, hotplug - if enabled, as is default - will scan normally again until it has 10 devices + --usb :0 will disable all USB I/O other than to initialse libusb ---scan-serial|-S Serial port to probe for Icarus mining device - -This option is only for Icarus bitstream FPGAs - -By default, cgminer will scan for autodetected Icarus unless at least one --S is specified for that driver. If you specify -S and still want cgminer -to scan, you must also use "-S auto". If you want to prevent cgminer from -scanning without specifying a device, you can use "-S noauto". Note that -presently, autodetection only works on Linux, and might only detect one -device depending on the version of udev being used. - -On linux is usually of the format /dev/ttyUSBn -On windows is usually of the format \\.\COMn -(where n = the correct device number for the Icarus device) - -The official supplied binaries are compiled with support for all FPGAs. -To force the code to only attempt detection with a specific driver, -prepend the argument with the driver name followed by a colon. -For example, "icarus:/dev/ttyUSB0" or using the short name: "ica:/dev/ttyUSB0" -This option not longer matters since Icarus is the only serial-USB -device that uses it For other FPGA details see the FPGA-README @@ -657,27 +639,6 @@ A: Cgminer currently supports 2 ASICs: Avalon and BitForce SC devices. They are Application Specify Integrated Circuit devices and provide the highest performance per unit power due to being dedicated to only one purpose. -Q: How do I get my Icarus/Lancelot/Cairnsmore device to auto-recognise? -A: On linux, if the /dev/ttyUSB* devices don't automatically appear, the only -thing that needs to be done is to load the driver for them: -Icarus: sudo modprobe pl2303 vendor=0x067b product=0x230 -Lancelot: sudo modprobe ftdi_sio vendor=0x0403 product=0x6001 -Cairnsmore: sudo modprobe ftdi_sio product=0x8350 vendor=0x0403 -On windows you must install the pl2303 or ftdi driver required for the device -pl2303: http://prolificusa.com/pl-2303hx-drivers/ -ftdi: http://www.ftdichip.com/Drivers/VCP.htm - -Q: On linux I can see the /dev/ttyUSB* devices for my Icarus FPGAs, but -cgminer can't mine on them -A: Make sure you have the required priviledges to access the /dev/ttyUSB* devices: - sudo ls -las /dev/ttyUSB* -will give output like: - 0 crw-rw---- 1 root dialout 188, 0 2012-09-11 13:49 /dev/ttyUSB0 -This means your account must have the group 'dialout' or root priviledges -To permanently give your account the 'dialout' group: - sudo usermod -G dialout -a `whoami` -Then logout and back in again - Q: Can I mine scrypt with FPGAs or ASICs? A: No. diff --git a/cgminer.c b/cgminer.c index 974496cf..086b0d94 100644 --- a/cgminer.c +++ b/cgminer.c @@ -1089,7 +1089,7 @@ static struct opt_table opt_config_table[] = { #ifdef USE_FPGA_SERIAL OPT_WITH_ARG("--scan-serial|-S", add_serial, NULL, NULL, - "Serial port to probe for Icarus FPGA Mining device"), + "Serial port to probe for Avalon Mining device"), #endif OPT_WITH_ARG("--scan-time|-s", set_int_0_to_9999, opt_show_intval, &opt_scantime, diff --git a/driver-ztex.c b/driver-ztex.c index 2ab4a4dd..09387267 100644 --- a/driver-ztex.c +++ b/driver-ztex.c @@ -7,7 +7,7 @@ * Copyright (C) 2009-2011 ZTEX GmbH. * http://www.ztex.de * - * This work is based upon the icarus.c worker which is + * This work is based upon the icarus.c worker which was * Copyright 2012 Luke Dashjr * Copyright 2012 Xiangfu * From dad308701b9bcdd3ea55cde6c874afb83aa86e4e Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 15:08:48 +1000 Subject: [PATCH 10/12] README spelling --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 84ca072e..8a54bd5b 100644 --- a/README +++ b/README @@ -285,7 +285,7 @@ not scan for any more If one of the 10 devices stops working, hotplug - if enabled, as is default - will scan normally again until it has 10 devices - --usb :0 will disable all USB I/O other than to initialse libusb + --usb :0 will disable all USB I/O other than to initialise libusb For other FPGA details see the FPGA-README From 9f46aa901285f2b177bbf0bede6b37829bcf6311 Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 15:14:48 +1000 Subject: [PATCH 11/12] icarus->USB v0.1 incomplete - missing initialise() --- driver-icarus.c | 361 ++++++++++++++++++++++++------------------------ 1 file changed, 178 insertions(+), 183 deletions(-) diff --git a/driver-icarus.c b/driver-icarus.c index 5d1d91c4..a4b26c6a 100644 --- a/driver-icarus.c +++ b/driver-icarus.c @@ -1,7 +1,6 @@ /* - * Copyright 2012 Luke Dashjr + * Copyright 2012-2013 Andrew Smith * Copyright 2012 Xiangfu - * Copyright 2012 Andrew Smith * * 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 @@ -29,30 +28,25 @@ * nonce range is completely calculated. */ -#include "config.h" -#include "miner.h" +#include #include #include +#include #include +#include #include -#include -#include #include -#ifndef WIN32 - #include - #include - #include - #ifndef O_CLOEXEC - #define O_CLOEXEC 0 - #endif -#else - #include - #include + +#include "config.h" + +#ifdef WIN32 +#include #endif -#include "elist.h" -#include "fpgautils.h" +#include "compat.h" +#include "miner.h" +#include "usbutils.h" // The serial I/O speed - Linux uses a define 'B115200' in bits/termios.h #define ICARUS_IO_SPEED 115200 @@ -67,41 +61,51 @@ #define ASSERT1(condition) __maybe_unused static char sizeof_uint32_t_must_be_4[(condition)?1:-1] ASSERT1(sizeof(uint32_t) == 4); -#define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud)) +// TODO: USB? Different calculation? - see usbstats to work it out e.g. 1/2 of normal send time +// or even use that number? 1/2 +// #define ICARUS_READ_TIME(baud) ((double)ICARUS_READ_SIZE * (double)8.0 / (double)(baud)) +// maybe 1ms? +#define ICARUS_READ_TIME(baud) (0.001) -// Fraction of a second, USB timeout is measured in -// i.e. 10 means 1/10 of a second -#define TIME_FACTOR 10 -// It's 10 per second, thus value = 10/TIME_FACTOR = -#define ICARUS_READ_FAULT_DECISECONDS 1 +// USB ms timeout to wait +#define ICARUS_WAIT_TIMEOUT 100 // In timing mode: Default starting value until an estimate can be obtained -// 5 seconds allows for up to a ~840MH/s device -#define ICARUS_READ_COUNT_TIMING (5 * TIME_FACTOR) +// 5000 ms allows for up to a ~840MH/s device +#define ICARUS_READ_COUNT_TIMING 5000 +#define ICARUS_READ_COUNT_MIN ICARUS_WAIT_TIMEOUT +#define SECTOMS(s) ((int)((s) * 1000)) +// How many ms below the expected completion time to abort work +// extra in case the last read is delayed +#define ICARUS_READ_REDUCE ((int)(ICARUS_WAIT_TIMEOUT * 1.5)) // For a standard Icarus REV3 (to 5 places) // Since this rounds up a the last digit - it is a slight overestimate // Thus the hash rate will be a VERY slight underestimate // (by a lot less than the displayed accuracy) +// Minor inaccuracy of these numbers doesn't affect the work done, +// only the displayed MH/s #define ICARUS_REV3_HASH_TIME 0.0000000026316 +#define LANCELOT_HASH_TIME 0.0000000025000 +#define ASICMINERUSB_HASH_TIME 0.0000000029761 #define NANOSEC 1000000000.0 // Icarus Rev3 doesn't send a completion message when it finishes // the full nonce range, so to avoid being idle we must abort the -// work (by starting a new work) shortly before it finishes +// work (by starting a new work item) shortly before it finishes // // Thus we need to estimate 2 things: // 1) How many hashes were done if the work was aborted // 2) How high can the timeout be before the Icarus is idle, -// to minimise the number of work started -// We set 2) to 'the calculated estimate' - 1 +// to minimise the number of work items started +// We set 2) to 'the calculated estimate' - ICARUS_READ_REDUCE // to ensure the estimate ends before idle // // The simple calculation used is: // Tn = Total time in seconds to calculate n hashes // Hs = seconds per hash // Xn = number of hashes -// W = code overhead per work +// W = code/usb overhead per work // // Rough but reasonable estimate: // Tn = Hs * Xn + W (of the form y = mx + b) @@ -123,7 +127,7 @@ ASSERT1(sizeof(uint32_t) == 4); #define HISTORY_SEC 60 // Minimum how many points a single ICARUS_HISTORY should have #define MIN_DATA_COUNT 5 -// The value above used is doubled each history until it exceeds: +// The value MIN_DATA_COUNT used is doubled each history until it exceeds: #define MAX_MIN_DATA_COUNT 100 static struct timeval history_sec = { HISTORY_SEC, 0 }; @@ -163,7 +167,8 @@ struct ICARUS_INFO { // seconds per Hash double Hs; - int read_count; + // ms til we abort + int read_time; enum timing_mode timing_mode; bool do_icarus_timing; @@ -195,7 +200,8 @@ static struct ICARUS_INFO **icarus_info; // // Code increments this each time we start to look at a device // However, this means that if other devices are checked by -// the Icarus code (e.g. BFL) they will count in the option offset +// the Icarus code (e.g. Avalon only as at 20130517) +// they will count in the option offset // // This, however, is deterministic so that's OK // @@ -203,13 +209,21 @@ static struct ICARUS_INFO **icarus_info; // that would be random since an Icarus may fail and thus we'd // not be able to predict the option order // -// This also assumes that serial_detect() checks them sequentially -// and in the order specified on the command line +// Devices are checked in the order libusb finds them which is ? // static int option_offset = -1; struct device_drv icarus_drv; +static void icarus_initialise(struct cgpu_info *icarus, int baud) +{ + if (icarus->usbinfo.nodev) + return; + + if (baud) { + } +} + static void rev(unsigned char *s, size_t l) { size_t i, j; @@ -222,81 +236,63 @@ static void rev(unsigned char *s, size_t l) } } -#define icarus_open2(devpath, baud, purge) serial_open(devpath, baud, ICARUS_READ_FAULT_DECISECONDS, purge) -#define icarus_open(devpath, baud) icarus_open2(devpath, baud, false) +#define ICA_NONCE_ERROR -1 +#define ICA_NONCE_OK 0 +#define ICA_NONCE_RESTART 1 +#define ICA_NONCE_TIMEOUT 2 -#define ICA_GETS_ERROR -1 -#define ICA_GETS_OK 0 -#define ICA_GETS_RESTART 1 -#define ICA_GETS_TIMEOUT 2 - -static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info *thr, int read_count) +static int icarus_get_nonce(struct cgpu_info *icarus, unsigned char *buf, struct timeval *tv_start, struct timeval *tv_finish, struct thr_info *thr, int read_time) { - ssize_t ret = 0; + struct timeval read_start, read_finish; + int err, amt; int rc = 0; int read_amount = ICARUS_READ_SIZE; bool first = true; - // Read reply 1 byte at a time to get earliest tv_finish + cgtime(tv_start); while (true) { - ret = read(fd, buf, 1); - if (ret < 0) - return ICA_GETS_ERROR; + cgtime(&read_start); + err = usb_read_timeout(icarus, (char *)buf, read_amount, &amt, ICARUS_WAIT_TIMEOUT, C_GETRESULTS); + cgtime(&read_finish); + if (err < 0 && err != LIBUSB_ERROR_TIMEOUT) { + applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); + dev_error(icarus, REASON_DEV_COMMS_ERROR); + return ICA_NONCE_ERROR; + } if (first) - cgtime(tv_finish); + copy_time(tv_finish, &read_finish); - if (ret >= read_amount) - return ICA_GETS_OK; + // TODO: test if there is more data? to read a 2nd nonce? + if (amt >= ICARUS_READ_SIZE) + return ICA_NONCE_OK; - if (ret > 0) { - buf += ret; - read_amount -= ret; + if (amt > 0) { + buf += amt; + read_amount -= amt; first = false; continue; } - rc++; - if (rc >= read_count) { + rc += SECTOMS(tdiff(&read_finish, &read_start)); + if (rc >= read_time) { if (opt_debug) { applog(LOG_DEBUG, - "Icarus Read: No data in %.2f seconds", - (float)rc/(float)TIME_FACTOR); + "Icarus Read: No data in %d ms", rc); } - return ICA_GETS_TIMEOUT; + return ICA_NONCE_TIMEOUT; } if (thr && thr->work_restart) { if (opt_debug) { applog(LOG_DEBUG, - "Icarus Read: Work restart at %.2f seconds", - (float)(rc)/(float)TIME_FACTOR); + "Icarus Read: Work restart at %d ms", rc); } - return ICA_GETS_RESTART; + return ICA_NONCE_RESTART; } } } -static int icarus_write(int fd, const void *buf, size_t bufLen) -{ - size_t ret; - - ret = write(fd, buf, bufLen); - if (unlikely(ret != bufLen)) - return 1; - - return 0; -} - -#define icarus_close(fd) close(fd) - -static void do_icarus_close(struct thr_info *thr) -{ - struct cgpu_info *icarus = thr->cgpu; - icarus_close(icarus->device_fd); - icarus->device_fd = -1; -} - static const char *timing_mode_str(enum timing_mode timing_mode) { switch(timing_mode) { @@ -346,17 +342,17 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus) } info->Hs = 0; - info->read_count = 0; + info->read_time = 0; if (strcasecmp(buf, MODE_SHORT_STR) == 0) { info->Hs = ICARUS_REV3_HASH_TIME; - info->read_count = ICARUS_READ_COUNT_TIMING; + info->read_time = ICARUS_READ_COUNT_TIMING; info->timing_mode = MODE_SHORT; info->do_icarus_timing = true; } else if (strcasecmp(buf, MODE_LONG_STR) == 0) { info->Hs = ICARUS_REV3_HASH_TIME; - info->read_count = ICARUS_READ_COUNT_TIMING; + info->read_time = ICARUS_READ_COUNT_TIMING; info->timing_mode = MODE_LONG; info->do_icarus_timing = true; @@ -365,13 +361,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus) info->fullnonce = info->Hs * (((double)0xffffffff) + 1); if ((eq = strchr(buf, '=')) != NULL) - info->read_count = atoi(eq+1); + info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT; - if (info->read_count < 1) - info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1; + if (info->read_time < ICARUS_READ_COUNT_MIN) + info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE; - if (unlikely(info->read_count < 1)) - info->read_count = 1; + if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN)) + info->read_time = ICARUS_READ_COUNT_MIN; info->timing_mode = MODE_VALUE; info->do_icarus_timing = false; @@ -382,10 +378,13 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus) info->fullnonce = info->Hs * (((double)0xffffffff) + 1); if ((eq = strchr(buf, '=')) != NULL) - info->read_count = atoi(eq+1); + info->read_time = atoi(eq+1) * ICARUS_WAIT_TIMEOUT; + + if (info->read_time < ICARUS_READ_COUNT_MIN) + info->read_time = SECTOMS(info->fullnonce) - ICARUS_READ_REDUCE; - if (info->read_count < 1) - info->read_count = (int)(info->fullnonce * TIME_FACTOR) - 1; + if (unlikely(info->read_time < ICARUS_READ_COUNT_MIN)) + info->read_time = ICARUS_READ_COUNT_MIN; info->timing_mode = MODE_DEFAULT; info->do_icarus_timing = false; @@ -393,8 +392,8 @@ static void set_timing_mode(int this_option_offset, struct cgpu_info *icarus) info->min_data_count = MIN_DATA_COUNT; - applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_count=%d Hs=%e", - icarus->device_id, timing_mode_str(info->timing_mode), info->read_count, info->Hs); + applog(LOG_DEBUG, "Icarus: Init: %d mode=%s read_time=%dms Hs=%e", + icarus->device_id, timing_mode_str(info->timing_mode), info->read_time, info->Hs); } static uint32_t mask(int work_division) @@ -508,13 +507,12 @@ static void get_options(int this_option_offset, int *baud, int *work_division, i } } -static bool icarus_detect_one(const char *devpath) +static bool icarus_detect_one(struct libusb_device *dev, struct usb_find_devices *found) { int this_option_offset = ++option_offset; - + char devpath[20]; struct ICARUS_INFO *info; struct timeval tv_start, tv_finish; - int fd; // Block 171874 nonce = (0xa2870100) = 0x000187a2 // N.B. golden_ob MUST take less time to calculate @@ -528,30 +526,52 @@ static bool icarus_detect_one(const char *devpath) const char golden_nonce[] = "000187a2"; const uint32_t golden_nonce_val = 0x000187a2; - unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE]; char *nonce_hex; - int baud, work_division, fpga_count; + struct cgpu_info *icarus; + int ret, err, amount, tries; get_options(this_option_offset, &baud, &work_division, &fpga_count); - applog(LOG_DEBUG, "Icarus Detect: Attempting to open %s", devpath); + icarus = calloc(1, sizeof(struct cgpu_info)); + if (unlikely(!icarus)) + quit(1, "Failed to calloc icarus in icarus_detect_one"); + icarus->drv = &icarus_drv; + icarus->deven = DEV_ENABLED; + icarus->threads = 1; - fd = icarus_open2(devpath, baud, true); - if (unlikely(fd == -1)) { - applog(LOG_ERR, "Icarus Detect: Failed to open %s", devpath); - return false; - } + if (!usb_init(icarus, dev, found)) + goto shin; + + // TODO: set options based on ident if options not supplied + // add a flag to say options were set by parameters + + sprintf(devpath, "%d:%d", + (int)(icarus->usbinfo.bus_number), + (int)(icarus->usbinfo.device_address)); + + icarus->device_path = strdup(devpath); hex2bin(ob_bin, golden_ob, sizeof(ob_bin)); - icarus_write(fd, ob_bin, sizeof(ob_bin)); - cgtime(&tv_start); - memset(nonce_bin, 0, sizeof(nonce_bin)); - icarus_gets(nonce_bin, fd, &tv_finish, NULL, 1); + tries = 0; + while (++tries) { + icarus_initialise(icarus, baud); + + err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDTESTWORK); - icarus_close(fd); + if (err == LIBUSB_SUCCESS && amount == sizeof(ob_bin)) + break; + + if (tries > 2) + goto unshin; + } + + memset(nonce_bin, 0, sizeof(nonce_bin)); + ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, NULL, 1); + if (ret != ICA_NONCE_OK) + goto unshin; nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin)); if (strncmp(nonce_hex, golden_nonce, 8)) { @@ -560,7 +580,7 @@ static bool icarus_detect_one(const char *devpath) "Test failed at %s: get %s, should: %s", devpath, nonce_hex, golden_nonce); free(nonce_hex); - return false; + goto unshin; } applog(LOG_DEBUG, "Icarus Detect: " @@ -569,14 +589,14 @@ static bool icarus_detect_one(const char *devpath) free(nonce_hex); /* We have a real Icarus! */ - struct cgpu_info *icarus; - icarus = calloc(1, sizeof(struct cgpu_info)); - icarus->drv = &icarus_drv; - icarus->device_path = strdup(devpath); - icarus->device_fd = -1; - icarus->threads = 1; - add_cgpu(icarus); + if (!add_cgpu(icarus)) + goto unshin; + + update_usb_stats(icarus); + icarus_info = realloc(icarus_info, sizeof(struct ICARUS_INFO *) * (total_devices + 1)); + if (unlikely(!icarus_info)) + quit(1, "Failed to realloc ICARUS_INFO"); applog(LOG_INFO, "Found Icarus at %s, mark as %d", devpath, icarus->device_id); @@ -605,11 +625,23 @@ static bool icarus_detect_one(const char *devpath) set_timing_mode(this_option_offset, icarus); return true; + +unshin: + + usb_uninit(icarus); + + free(icarus->device_path); + +shin: + + free(icarus); + + return false; } static void icarus_detect() { - serial_detect(&icarus_drv, icarus_detect_one); + usb_detect(&icarus_drv, icarus_detect_one); } static bool icarus_prepare(struct thr_info *thr) @@ -618,18 +650,6 @@ static bool icarus_prepare(struct thr_info *thr) struct timeval now; - icarus->device_fd = -1; - - int fd = icarus_open(icarus->device_path, icarus_info[icarus->device_id]->baud); - if (unlikely(-1 == fd)) { - applog(LOG_ERR, "Failed to open Icarus on %s", - icarus->device_path); - return false; - } - - icarus->device_fd = fd; - - applog(LOG_INFO, "Opened Icarus on %s", icarus->device_path); cgtime(&now); get_datestamp(icarus->init, &now); @@ -639,9 +659,8 @@ static bool icarus_prepare(struct thr_info *thr) static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, __maybe_unused int64_t max_nonce) { - struct cgpu_info *icarus; - int fd; - int ret; + struct cgpu_info *icarus = thr->cgpu; + int ret, err, amount; struct ICARUS_INFO *info; @@ -658,43 +677,32 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, struct ICARUS_HISTORY *history0, *history; int count; double Hs, W, fullnonce; - int read_count; + int read_time; int64_t estimate_hashes; uint32_t values; int64_t hash_count_range; - elapsed.tv_sec = elapsed.tv_usec = 0; - - icarus = thr->cgpu; - if (icarus->device_fd == -1) - if (!icarus_prepare(thr)) { - applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); - dev_error(icarus, REASON_DEV_COMMS_ERROR); - - // fail the device if the reopen attempt fails - return -1; - } + // Device is gone + if (icarus->usbinfo.nodev) + return -1; - fd = icarus->device_fd; + info = icarus_info[icarus->device_id]; + elapsed.tv_sec = elapsed.tv_usec = 0; memset(ob_bin, 0, sizeof(ob_bin)); memcpy(ob_bin, work->midstate, 32); memcpy(ob_bin + 52, work->data + 64, 12); rev(ob_bin, 32); rev(ob_bin + 52, 12); -#ifndef WIN32 - tcflush(fd, TCOFLUSH); -#endif - ret = icarus_write(fd, ob_bin, sizeof(ob_bin)); - if (ret) { - do_icarus_close(thr); + + err = usb_write(icarus, (char *)ob_bin, sizeof(ob_bin), &amount, C_SENDWORK); + if (err < 0 || amount != sizeof(ob_bin)) { applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); dev_error(icarus, REASON_DEV_COMMS_ERROR); - return 0; /* This should never happen */ + icarus_initialise(icarus, info->baud); + return 0; } - cgtime(&tv_start); - if (opt_debug) { ob_hex = bin2hex(ob_bin, sizeof(ob_bin)); applog(LOG_DEBUG, "Icarus %d sent: %s", @@ -704,19 +712,14 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, /* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */ memset(nonce_bin, 0, sizeof(nonce_bin)); - info = icarus_info[icarus->device_id]; - ret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count); - if (ret == ICA_GETS_ERROR) { - do_icarus_close(thr); - applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); - dev_error(icarus, REASON_DEV_COMMS_ERROR); + ret = icarus_get_nonce(icarus, nonce_bin, &tv_start, &tv_finish, thr, info->read_time); + if (ret == ICA_NONCE_ERROR) return 0; - } work->blk.nonce = 0xffffffff; // aborted before becoming idle, get new work - if (ret == ICA_GETS_TIMEOUT || ret == ICA_GETS_RESTART) { + if (ret == ICA_NONCE_TIMEOUT || ret == ICA_NONCE_RESTART) { timersub(&tv_finish, &tv_start, &elapsed); // ONLY up to just when it aborted @@ -739,19 +742,11 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, } memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin)); - -#if !defined (__BIG_ENDIAN__) && !defined(MIPSEB) - nonce = swab32(nonce); -#endif - + nonce = htobe32(nonce); curr_hw_errors = icarus->hw_errors; submit_nonce(thr, work, nonce); was_hw_error = (curr_hw_errors > icarus->hw_errors); - // Force a USB close/reopen on any hw error - if (was_hw_error) - do_icarus_close(thr); - hash_count = (nonce & info->nonce_mask); hash_count++; hash_count *= info->fpga_count; @@ -804,7 +799,7 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, memset(history0, 0, sizeof(struct ICARUS_HISTORY)); // We just completed a history data set - // So now recalc read_count based on the whole history thus we will + // So now recalc read_time based on the whole history thus we will // initially get more accurate until it completes INFO_HISTORY // total data sets count = 0; @@ -837,10 +832,10 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, memset(history0, 0, sizeof(struct ICARUS_HISTORY)); fullnonce = W + Hs * (((double)0xffffffff) + 1); - read_count = (int)(fullnonce * TIME_FACTOR) - 1; + read_time = SECTOMS(fullnonce) - ICARUS_READ_REDUCE; info->Hs = Hs; - info->read_count = read_count; + info->read_time = read_time; info->fullnonce = fullnonce; info->count = count; @@ -853,9 +848,9 @@ static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, else if (info->timing_mode == MODE_SHORT) info->do_icarus_timing = false; -// applog(LOG_WARNING, "Icarus %d Re-estimate: read_count=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_count, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count); - applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_count=%d fullnonce=%.3fs", - icarus->device_id, Hs, W, read_count, fullnonce); +// applog(LOG_WARNING, "Icarus %d Re-estimate: read_time=%d fullnonce=%fs history count=%d Hs=%e W=%e values=%d hash range=0x%08lx min data count=%u", icarus->device_id, read_time, fullnonce, count, Hs, W, values, hash_count_range, info->min_data_count); + applog(LOG_WARNING, "Icarus %d Re-estimate: Hs=%e W=%e read_time=%dms fullnonce=%.3fs", + icarus->device_id, Hs, W, read_time, fullnonce); } info->history_count++; cgtime(&tv_history_finish); @@ -876,7 +871,7 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu) // care since hashing performance is way more important than // locking access to displaying API debug 'stats' // If locking becomes an issue for any of them, use copy_data=true also - root = api_add_int(root, "read_count", &(info->read_count), false); + root = api_add_int(root, "read_time", &(info->read_time), false); root = api_add_double(root, "fullnonce", &(info->fullnonce), false); root = api_add_int(root, "count", &(info->count), false); root = api_add_hs(root, "Hs", &(info->Hs), false); @@ -896,9 +891,9 @@ static struct api_data *icarus_api_stats(struct cgpu_info *cgpu) return root; } -static void icarus_shutdown(struct thr_info *thr) +static void icarus_shutdown(__maybe_unused struct thr_info *thr) { - do_icarus_close(thr); + // TODO: ? } struct device_drv icarus_drv = { From 288f5e3b4391853c5b86af7e93a89852558b7655 Mon Sep 17 00:00:00 2001 From: Kano Date: Fri, 17 May 2013 19:12:31 +1000 Subject: [PATCH 12/12] simple serial-USB python test script --- usbtest.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100755 usbtest.py diff --git a/usbtest.py b/usbtest.py new file mode 100755 index 00000000..79f79cbe --- /dev/null +++ b/usbtest.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python2.7 +# +# Original version supplied to me (Kano/kanoi) by xiangfu +# +# Modified to allow supplying the data to send +# +# Linux usAge: ./ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus +# OR python ubstest.py /dev/ttyUSB0 0xhexcodes|string|icarus +# +# Windows usAge: ./ubstest.py COM1 0xhexcodes|string|icarus +# +# sends the data sepcified to the USB device and waits +# for a reply then displays it +# +# the data can be: +# 0xhexcodes: e.g. 0x68656c6c6f20776f726c640a +# would send "hello world\n" +# +# string: e.g. sendsometext +# +# icarus: sends 2 known block payloads for an icarus device +# and shows the expected and actual answers if it's +# a working V3 icarus + +import sys +import serial +import binascii + +if len(sys.argv) < 2: + sys.stderr.write("usAge: " + sys.argv[0] + " device strings...\n") + sys.stderr.write(" where device is either like /dev/ttyUSB0 or COM1\n") + sys.stderr.write(" and strings are either '0xXXXX' or 'text'\n") + sys.stderr.write(" if the first string is 'icarus' the rest are ignored\n") + sys.stderr.write(" and 2 valid icarus test payloads are sent with results displayed\n") + sys.stderr.write("\nAfter any command is sent it waits up to 30 seconds for a reply\n"); + sys.exit("Aborting") + +# Open with a 10 second timeout - just to be sure +ser = serial.Serial(sys.argv[1], 115200, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 10, False, False, 5, False, None) + +if sys.argv[2] == "icarus": + + # This show how Icarus use the block and midstate data + # This will produce nonce 063c5e01 + block = "0000000120c8222d0497a7ab44a1a2c7bf39de941c9970b1dc7cdc400000079700000000e88aabe1f353238c668d8a4df9318e614c10c474f8cdf8bc5f6397b946c33d7c4e7242c31a098ea500000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000" + midstate = "33c5bf5751ec7f7e056443b5aee3800331432c83f404d9de38b94ecbf907b92d" + + rdata2 = block.decode('hex')[95:63:-1] + rmid = midstate.decode('hex')[::-1] + payload = rmid + rdata2 + + print("Push payload to icarus: " + binascii.hexlify(payload)) + ser.write(payload) + + b=ser.read(4) + print("Result:(should be: 063c5e01): " + binascii.hexlify(b)) + + # Just another test + payload2 = "ce92099c5a80bb81c52990d5c0924c625fd25a535640607d5a4bdf8174e2c8d500000000000000000000000080000000000000000b290c1a42313b4f21b5bcb8" + print("Push payload to icarus: " + payload2) + ser.write(payload2.decode('hex')) + + b=ser.read(4) + print("Result:(should be: 8e0b31c5): " + binascii.hexlify(b)) +else: + data = "" + for arg in sys.argv[2::]: + if arg[0:2:] == '0x': + data += arg[2::].decode('hex') + else: + data += arg + + print("Sending: 0x" + binascii.hexlify(data)) + ser.write(data) + + # If you're expecting more than one linefeed terminated reply, + # you'll only see the first one + # AND with no linefeed, this will wait the 10 seconds before returning + print("Waiting up to 10 seconds ...") + b=ser.readline() + print("Result: hex 0x" + binascii.hexlify(b)) + + # This could mess up the display - do it last + print("Result: asc '" + b + "'") + +ser.close()