usb add transfer_read and commented out in icarus
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
diff --git a/driver-icarus.c b/driver-icarus.c
index 000abf7..fb5c9da 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -215,6 +215,21 @@ static int option_offset = -1;
struct device_drv icarus_drv;
+/*
+#define ICA_BUFSIZ (0x200)
+
+static void transfer_read(struct cgpu_info *icarus, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, enum usb_cmds cmd)
+{
+ int err;
+
+ err = usb_transfer_read(icarus, request_type, bRequest, wValue, wIndex, buf, bufsiz, amount, cmd);
+
+ applog(LOG_DEBUG, "%s: cgid %d %s got err %d",
+ icarus->drv->name, icarus->cgminer_id,
+ usb_cmdname(cmd), err);
+}
+*/
+
static void _transfer(struct cgpu_info *icarus, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t *data, int siz, enum usb_cmds cmd)
{
int err;
diff --git a/usbutils.c b/usbutils.c
index 33e8dad..ebad706 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -49,9 +49,6 @@
#define USB_CONFIG 1
-#define EPI(x) (LIBUSB_ENDPOINT_IN | (unsigned char)(x))
-#define EPO(x) (LIBUSB_ENDPOINT_OUT | (unsigned char)(x))
-
#ifdef WIN32
#define BFLSC_TIMEOUT_MS 500
#define BITFORCE_TIMEOUT_MS 999
@@ -2216,6 +2213,44 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest
return err;
}
+int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd)
+{
+ struct cg_usb_device *usbdev = cgpu->usbdev;
+#if DO_USB_STATS
+ struct timeval tv_start, tv_finish;
+#endif
+ int err;
+
+ USBDEBUG("USB debug: _usb_transfer_read(%s (nodev=%s),type=%"PRIu8",req=%"PRIu8",value=%"PRIu16",index=%"PRIu16",bufsiz=%d,timeout=%u,cmd=%s)", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), request_type, bRequest, wValue, wIndex, bufsiz, timeout, usb_cmdname(cmd));
+
+ if (cgpu->usbinfo.nodev) {
+#if DO_USB_STATS
+ rejected_inc(cgpu);
+#endif
+ return LIBUSB_ERROR_NO_DEVICE;
+ }
+
+ *amount = 0;
+
+ STATS_TIMEVAL(&tv_start);
+ err = libusb_control_transfer(usbdev->handle, request_type,
+ bRequest, htole16(wValue), htole16(wIndex),
+ (unsigned char *)buf, (uint16_t)bufsiz,
+ timeout == DEVTIMEOUT ? usbdev->found->timeout : timeout);
+ STATS_TIMEVAL(&tv_finish);
+ USB_STATS(cgpu, &tv_start, &tv_finish, err, cmd, SEQ0);
+
+ USBDEBUG("USB debug: @_usb_transfer_read(%s (nodev=%s)) amt/err=%d%s%s%s", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), err, isnodev(err), err > 0 ? " = " : BLANK, err > 0 ? bin2hex((unsigned char *)buf, (size_t)err) : BLANK);
+
+ if (err > 0) {
+ *amount = err;
+ err = 0;
+ } else if (NODEV(err))
+ release_cgpu(cgpu);
+
+ return err;
+}
+
void usb_cleanup()
{
struct cgpu_info *cgpu;
diff --git a/usbutils.h b/usbutils.h
index 14fc17a..862a208 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -12,6 +12,9 @@
#include <libusb.h>
+#define EPI(x) (LIBUSB_ENDPOINT_IN | (unsigned char)(x))
+#define EPO(x) (LIBUSB_ENDPOINT_OUT | (unsigned char)(x))
+
// For 0x0403:0x6014/0x6001 FT232H (and possibly others?) - BFL, BAS, BLT, LLT, AVA
#define FTDI_TYPE_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT)
@@ -68,6 +71,8 @@
#define PL2303_REQUEST_LINE 0x20
#define PL2303_REQUEST_VENDOR 0x01
+#define PL2303_REPLY_CTRL 0x21
+
#define PL2303_VALUE_CTRL (PL2303_CTRL_DTR | PL2303_CTRL_RTS)
#define PL2303_VALUE_LINE 0
#define PL2303_VALUE_LINE0 0x0001c200
@@ -222,6 +227,7 @@ 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 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, uint32_t *data, int siz, unsigned int timeout, enum usb_cmds cmd);
+int _usb_transfer_read(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, char *buf, int bufsiz, int *amount, unsigned int timeout, enum usb_cmds cmd);
void usb_cleanup();
void usb_initialise();
@@ -264,4 +270,7 @@ void usb_initialise();
#define usb_transfer_data(cgpu, typ, req, val, idx, data, len, cmd) \
_usb_transfer(cgpu, typ, req, val, idx, data, len, DEVTIMEOUT, cmd)
+#define usb_transfer_read(cgpu, typ, req, val, idx, buf, bufsiz, read, cmd) \
+ _usb_transfer_read(cgpu, typ, req, val, idx, buf, bufsiz, read, DEVTIMEOUT, cmd)
+
#endif