Attachments you submit will be routed for moderation. If you have an account, please
log in first.
Ticket #6: 0001-Linux-Correctly-terminate-bulk-packets-of-size-wMax.patch
| File 0001-Linux-Correctly-terminate-bulk-packets-of-size-wMax.patch,
2.4 KB
(added by nikias, 3 years ago) |
|
|
-
From 3a99da700874289ab4b000840cd8e0e0cbe8646e Mon Sep 17 00:00:00 2001
From: Nikias Bassen <nikias@gmx.li>
Date: Sat, 29 Aug 2009 16:40:31 +0200
Subject: [PATCH] Linux: Correctly terminate bulk packets of size wMaxPacketSize
... and multiples. This patch will automatically set the URB_ZERO_PACKET
flag if the packet size is a multiple of the endpoint's wMaxPacketSize
so that the kernel actually submits bulk packet. This is only for
outgoing transfers.
---
libusb/os/linux_usbfs.c | 18 ++++++++++++++++++
libusb/os/linux_usbfs.h | 1 +
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 1280188..ad1dc89 100644
|
a
|
b
|
static int submit_bulk_transfer(struct usbi_transfer *itransfer, |
| 1265 | 1265 | int r; |
| 1266 | 1266 | int i; |
| 1267 | 1267 | size_t alloc_size; |
| | 1268 | uint8_t is_read; /* 0 = we're reading, 1 = we're writing */ |
| | 1269 | uint8_t flag_zero_packet = 0; /* 0 = don't flag, 1 = flag */ |
| 1268 | 1270 | |
| 1269 | 1271 | if (tpriv->urbs) |
| 1270 | 1272 | return LIBUSB_ERROR_BUSY; |
| … |
… |
static int submit_bulk_transfer(struct usbi_transfer *itransfer, |
| 1294 | 1296 | tpriv->num_retired = 0; |
| 1295 | 1297 | tpriv->reap_action = NORMAL; |
| 1296 | 1298 | |
| | 1299 | /* are we reading or writing? */ |
| | 1300 | is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN; |
| | 1301 | if (!is_read) { |
| | 1302 | libusb_device *tdev = libusb_get_device(transfer->dev_handle); |
| | 1303 | int max_packet_size = libusb_get_max_packet_size(tdev, transfer->endpoint); |
| | 1304 | if ((max_packet_size > 0) && (transfer->length > 0) |
| | 1305 | && (transfer->length % max_packet_size == 0)) { |
| | 1306 | flag_zero_packet = 1; |
| | 1307 | } |
| | 1308 | } |
| | 1309 | |
| 1297 | 1310 | for (i = 0; i < num_urbs; i++) { |
| 1298 | 1311 | struct usbfs_urb *urb = &urbs[i]; |
| 1299 | 1312 | urb->usercontext = itransfer; |
| … |
… |
static int submit_bulk_transfer(struct usbi_transfer *itransfer, |
| 1307 | 1320 | else |
| 1308 | 1321 | urb->buffer_length = MAX_BULK_BUFFER_LENGTH; |
| 1309 | 1322 | |
| | 1323 | if ((i == num_urbs - 1) && (flag_zero_packet)) { |
| | 1324 | printf("flagging URB_ZERO_PACKET\n"); |
| | 1325 | urb->flags |= USBFS_URB_ZERO_PACKET; |
| | 1326 | } |
| | 1327 | |
| 1310 | 1328 | r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); |
| 1311 | 1329 | if (r < 0) { |
| 1312 | 1330 | int j; |
-
diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
index fdf5e9b..9ed0b4f 100644
|
a
|
b
|
struct usbfs_getdriver { |
| 63 | 63 | #define USBFS_URB_DISABLE_SPD 1 |
| 64 | 64 | #define USBFS_URB_ISO_ASAP 2 |
| 65 | 65 | #define USBFS_URB_QUEUE_BULK 0x10 |
| | 66 | #define USBFS_URB_ZERO_PACKET 0x40 |
| 66 | 67 | |
| 67 | 68 | enum usbfs_urb_type { |
| 68 | 69 | USBFS_URB_TYPE_ISO = 0, |
Download in other formats: