Merge branch 'master' into bxf
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
diff --git a/api.c b/api.c
index 07f6c39..302196d 100644
--- a/api.c
+++ b/api.c
@@ -1625,10 +1625,14 @@ uint64_t api_trylock(void *lock, const char *file, const char *func, const int l
LOCKINFO *info;
uint64_t id;
+ locklock();
+
info = findlock(lock, CGLOCK_UNKNOWN, file, func, linenum);
id = lock_id++;
addgettry(info, id, file, func, linenum, false);
+ lockunlock();
+
return id;
}
diff --git a/compat/libusb-1.0/libusb/os/windows_usb.c b/compat/libusb-1.0/libusb/os/windows_usb.c
index afc4dfc..ac359c4 100644
--- a/compat/libusb-1.0/libusb/os/windows_usb.c
+++ b/compat/libusb-1.0/libusb/os/windows_usb.c
@@ -1822,9 +1822,6 @@ static int windows_submit_transfer(struct usbi_transfer *itransfer)
return submit_control_transfer(itransfer);
case LIBUSB_TRANSFER_TYPE_BULK:
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
- if (IS_XFEROUT(transfer) &&
- transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET)
- return LIBUSB_ERROR_NOT_SUPPORTED;
return submit_bulk_transfer(itransfer);
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
return submit_iso_transfer(itransfer);
@@ -2391,20 +2388,8 @@ static int winusb_configure_endpoints(struct libusb_device_handle *dev_handle, i
PIPE_TRANSFER_TIMEOUT, sizeof(ULONG), &timeout)) {
usbi_dbg("failed to set PIPE_TRANSFER_TIMEOUT for control endpoint %02X", endpoint_address);
}
- if (i == -1) continue; // Other policies don't apply to control endpoint
- policy = false;
- if (!WinUsb_SetPipePolicy(winusb_handle, endpoint_address,
- SHORT_PACKET_TERMINATE, sizeof(UCHAR), &policy)) {
- usbi_dbg("failed to disable SHORT_PACKET_TERMINATE for endpoint %02X", endpoint_address);
- }
- if (!WinUsb_SetPipePolicy(winusb_handle, endpoint_address,
- IGNORE_SHORT_PACKETS, sizeof(UCHAR), &policy)) {
- usbi_dbg("failed to disable IGNORE_SHORT_PACKETS for endpoint %02X", endpoint_address);
- }
- if (!WinUsb_SetPipePolicy(winusb_handle, endpoint_address,
- ALLOW_PARTIAL_READS, sizeof(UCHAR), &policy)) {
- usbi_dbg("failed to disable ALLOW_PARTIAL_READS for endpoint %02X", endpoint_address);
- }
+ if (i == -1)
+ continue; // Other policies don't apply to control endpoint
policy = true;
if (!WinUsb_SetPipePolicy(winusb_handle, endpoint_address,
AUTO_CLEAR_STALL, sizeof(UCHAR), &policy)) {
@@ -2649,6 +2634,8 @@ static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer)
bool ret;
int current_interface;
struct winfd wfd;
+ ULONG ppolicy = sizeof(UCHAR);
+ UCHAR policy;
CHECK_WINUSB_AVAILABLE;
@@ -2671,9 +2658,20 @@ static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer)
}
if (IS_XFERIN(transfer)) {
- usbi_dbg("reading %d bytes", transfer->length);
+ WinUsb_GetPipePolicy(wfd.handle, transfer->endpoint, AUTO_CLEAR_STALL, &ppolicy, &policy);
+ if (!policy) {
+ policy = TRUE;
+ WinUsb_SetPipePolicy(wfd.handle, transfer->endpoint, AUTO_CLEAR_STALL, ppolicy, &policy);
+ }
ret = WinUsb_ReadPipe(wfd.handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped);
} else {
+ if (transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET) {
+ WinUsb_GetPipePolicy(wfd.handle, transfer->endpoint, SHORT_PACKET_TERMINATE, &ppolicy, &policy);
+ if (!policy) {
+ policy = TRUE;
+ WinUsb_SetPipePolicy(wfd.handle, transfer->endpoint, SHORT_PACKET_TERMINATE, ppolicy, &policy);
+ }
+ }
usbi_dbg("writing %d bytes", transfer->length);
ret = WinUsb_WritePipe(wfd.handle, transfer->endpoint, transfer->buffer, transfer->length, NULL, wfd.overlapped);
}
diff --git a/driver-bab.c b/driver-bab.c
index 545e8bb..7db3df1 100644
--- a/driver-bab.c
+++ b/driver-bab.c
@@ -17,7 +17,8 @@
#include "sha2.h"
/*
- * Tested on RPi running Raspbian with BlackArrow BitFury V1 16 chip GPIO board
+ * Tested on RPi running both Raspbian and Arch
+ * with BlackArrow BitFury V1 16 chip GPIO board
*/
#ifndef LINUX
diff --git a/driver-klondike.c b/driver-klondike.c
index 2446202..3a740ec 100644
--- a/driver-klondike.c
+++ b/driver-klondike.c
@@ -1129,26 +1129,28 @@ static void klondike_flush_work(struct cgpu_info *klncgpu)
KLINE kline;
int slaves, dev;
- wr_lock(&(klninfo->stat_lock));
- klninfo->block_seq++;
- slaves = klninfo->status[0].kline.ws.slavecount;
- wr_unlock(&(klninfo->stat_lock));
+ if (klninfo->initialised) {
+ wr_lock(&(klninfo->stat_lock));
+ klninfo->block_seq++;
+ slaves = klninfo->status[0].kline.ws.slavecount;
+ wr_unlock(&(klninfo->stat_lock));
- applog(LOG_DEBUG, "%s%i: flushing work",
- klncgpu->drv->name, klncgpu->device_id);
- zero_kline(&kline);
- kline.hd.cmd = KLN_CMD_ABORT;
- for (dev = 0; dev <= slaves; dev++) {
- kline.hd.dev = dev;
- kitem = SendCmdGetReply(klncgpu, &kline, KSENDHD(0));
- if (kitem != NULL) {
- wr_lock(&(klninfo->stat_lock));
- memcpy((void *)&(klninfo->status[dev]),
- kitem,
- sizeof(klninfo->status[dev]));
- klninfo->jobque[dev].flushed = true;
- wr_unlock(&(klninfo->stat_lock));
- kitem = release_kitem(klncgpu, kitem);
+ applog(LOG_DEBUG, "%s%i: flushing work",
+ klncgpu->drv->name, klncgpu->device_id);
+ zero_kline(&kline);
+ kline.hd.cmd = KLN_CMD_ABORT;
+ for (dev = 0; dev <= slaves; dev++) {
+ kline.hd.dev = dev;
+ kitem = SendCmdGetReply(klncgpu, &kline, KSENDHD(0));
+ if (kitem != NULL) {
+ wr_lock(&(klninfo->stat_lock));
+ memcpy((void *)&(klninfo->status[dev]),
+ kitem,
+ sizeof(klninfo->status[dev]));
+ klninfo->jobque[dev].flushed = true;
+ wr_unlock(&(klninfo->stat_lock));
+ kitem = release_kitem(klncgpu, kitem);
+ }
}
}
}
diff --git a/usbutils.c b/usbutils.c
index 16e383f..1984c2e 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2456,15 +2456,11 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
struct usb_transfer ut;
unsigned char endpoint;
int err, errn;
- /* Zero length packet required */
- bool zlp = false;
#if DO_USB_STATS
struct timeval tv_start, tv_finish;
#endif
unsigned char buf[512];
#ifdef WIN32
- int dummy;
-
/* On windows the callback_timeout is a safety mechanism only. */
bulk_timeout = timeout;
callback_timeout += WIN_CALLBACK_EXTRA;
@@ -2486,17 +2482,9 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
memcpy(buf, data, length);
- /* If this is the last packet in a transfer and is the length
- * of the wMaxPacketSize then we need to send a zero length
- * packet to let the device know it's the end of the message.*/
if (length > usb_epinfo->wMaxPacketSize)
length = usb_epinfo->wMaxPacketSize;
- else if (length == usb_epinfo->wMaxPacketSize)
- zlp = true;
-#ifndef WIN32
- /* Windows doesn't support this flag so we emulate it below */
ut.transfer->flags |= LIBUSB_TRANSFER_ADD_ZERO_PACKET;
-#endif
}
USBDEBUG("USB debug: @usb_bulk_transfer(%s (nodev=%s),intinfo=%d,epinfo=%d,data=%p,length=%d,timeout=%u,mode=%d,cmd=%s,seq=%d) endpoint=%d", cgpu->drv->name, bool_str(cgpu->usbinfo.nodev), intinfo, epinfo, data, length, timeout, mode, usb_cmdname(cmd), seq, (int)endpoint);
@@ -2539,12 +2527,6 @@ usb_bulk_transfer(struct libusb_device_handle *dev_handle, int intinfo,
}
if ((endpoint & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
memcpy(data, buf, *transferred);
- else if (zlp) {
-#ifdef WIN32
- /* Send a zero length packet */
- libusb_bulk_transfer(dev_handle, endpoint, NULL, 0, &dummy, 100);
-#endif
- }
return err;
}