* [PATCH] usb bulk transfer: 1024 byte packets
@ 2007-04-13 16:56 Jeremy C. Andrus
2007-04-13 18:47 ` Jeremy C. Andrus
2007-04-14 2:16 ` Pete Zaitcev
0 siblings, 2 replies; 5+ messages in thread
From: Jeremy C. Andrus @ 2007-04-13 16:56 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 738 bytes --]
Hello,
I recently ran into a couple of USB devices which insisted on using 1024
byte packets in bulk transfer mode (despite the hard limit of 512
established in the spec). I really wanted to use these devices, so I
created a kernel patch which allows the use of 1024 byte URBs, but does
not interfere with normal (512 byte) operation. I did this through a
bit in the transfer_flags bitfield.
I found this patch useful and un-obtrusive, so I figured that I would
post it here to see if anyone else thinks it interesting enough to
patch in.
I am not subscribed to the list, and would appreciate a personal CC on
reply :-).
-Jeremy
--
-----------------------
Jeremy C. Andrus
http://www.jeremya.com/
-----------------------
[-- Attachment #2: linux-2.6.20.6-usb_1024byte_packets.patch --]
[-- Type: text/x-diff, Size: 3531 bytes --]
diff -Naur linux-2.6.20.6/Documentation/usb/bulk_tx_hacks.txt linux-2.6.20.6_jca/Documentation/usb/bulk_tx_hacks.txt
--- linux-2.6.20.6/Documentation/usb/bulk_tx_hacks.txt 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.20.6_jca/Documentation/usb/bulk_tx_hacks.txt 2007-04-13 09:59:19.000000000 -0400
@@ -0,0 +1,28 @@
+bulk_tx_hacks.txt
+Copyright (C) 2007 Jeremy C. Andrus <jeremy@jeremya.com>
+Started: 2007-April-13
+
+
+How to use a 1024-byte bulk transfer packet
+
+There are some devices/companies which have decided to use
+a bulk transfer packet size which is larger than the maximum
+specified in the USB spec. Because I was interested in using
+such a device, I found it necessary to devise a way to allow
+this functionality in the linux kernel.
+
+It is reasonably simple to create a 1024-byte bulk transfer
+URB. Simply OR the 'URB_1024_BYTE_PKT' value into the URB's
+transfer_flags field before submitting it to the system:
+
+ urb = usb_alloc_urb(0, GFP_KERNEL);
+
+ usb_fill_bulk_urb( urb, ... );
+
+ /* this allows the URB's buffer to be 1024 bytes */
+ urb->transfer_flags |= URB_1024_BYTE_PKT;
+
+ retval = usb_submit_urb( urb, GFP_KERNEL );
+
+ usb_free_urb( urb );
+
diff -Naur linux-2.6.20.6/drivers/usb/host/Kconfig linux-2.6.20.6_jca/drivers/usb/host/Kconfig
--- linux-2.6.20.6/drivers/usb/host/Kconfig 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/drivers/usb/host/Kconfig 2007-04-13 10:00:36.000000000 -0400
@@ -67,6 +67,20 @@
If unsure, say N.
+config USB_EHCI_1024BYTE_BULK_PKTS
+ bool "Allow 1024-byte packets in Bulk Transfer mode"
+ depends on USB_EHCI_HCD && EXPERIMENTAL
+ ---help---
+ The USB specification allows a maximum bulk transfer packet size
+ of 512 bytes. There are a few devices which have decided to break
+ this specification and use 1024 byte packets. This option allows
+ the use of the larger packet size with a very specific flag set
+ in the URB.
+
+ See the Documentation/usb/bulk_tx_hacks.txt file for details.
+
+ If unsure, say N.
+
config USB_ISP116X_HCD
tristate "ISP116X HCD support"
depends on USB
diff -Naur linux-2.6.20.6/drivers/usb/host/ehci-q.c linux-2.6.20.6_jca/drivers/usb/host/ehci-q.c
--- linux-2.6.20.6/drivers/usb/host/ehci-q.c 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/drivers/usb/host/ehci-q.c 2007-04-13 09:47:09.000000000 -0400
@@ -751,7 +751,12 @@
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else if (type == PIPE_BULK) {
info1 |= (EHCI_TUNE_RL_HS << 28);
- info1 |= 512 << 16; /* usb2 fixed maxpacket */
+#ifdef USB_EHCI_1024BYTE_BULK_PKTS
+ if ( urb->transfer_flags & URB_1024_BYTE_PKT )
+ info1 |= 1024 << 16; /* HACK for Micron Dev Kits requiring 1024 byte packets... */
+ else
+#endif
+ info1 |= 512 << 16; /* usb2 fixed maxpacket */
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else { /* PIPE_INTERRUPT */
info1 |= max_packet (maxp) << 16;
diff -Naur linux-2.6.20.6/include/linux/usb.h linux-2.6.20.6_jca/include/linux/usb.h
--- linux-2.6.20.6/include/linux/usb.h 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/include/linux/usb.h 2007-04-13 09:47:09.000000000 -0400
@@ -904,6 +904,9 @@
#define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt
* needed */
+#ifdef USB_EHCI_1024BYTE_BULK_PKTS
+#define URB_1024_BYTE_PKT 0x8000 /* Use a max packet length of 1024 bytes instead of 512 */
+#endif
struct usb_iso_packet_descriptor {
unsigned int offset;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb bulk transfer: 1024 byte packets
2007-04-13 16:56 [PATCH] usb bulk transfer: 1024 byte packets Jeremy C. Andrus
@ 2007-04-13 18:47 ` Jeremy C. Andrus
2007-04-14 2:16 ` Pete Zaitcev
1 sibling, 0 replies; 5+ messages in thread
From: Jeremy C. Andrus @ 2007-04-13 18:47 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
On Friday April 13 2007 12:56, I wrote:
[snip]
> I found this patch useful and un-obtrusive, so I figured that I would
> post it here to see if anyone else thinks it interesting enough to
> patch in.
>
Sorry about this, but there was a small error in my patch...
-Jeremy
--
-----------------------
Jeremy C. Andrus
http://www.jeremya.com/
-----------------------
[-- Attachment #2: linux-2.6.20.6-usb_1024byte_packets.patch --]
[-- Type: text/x-diff, Size: 3545 bytes --]
diff -Naur linux-2.6.20.6/Documentation/usb/bulk_tx_hacks.txt linux-2.6.20.6_jca/Documentation/usb/bulk_tx_hacks.txt
--- linux-2.6.20.6/Documentation/usb/bulk_tx_hacks.txt 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.20.6_jca/Documentation/usb/bulk_tx_hacks.txt 2007-04-13 09:59:19.000000000 -0400
@@ -0,0 +1,28 @@
+bulk_tx_hacks.txt
+Copyright (C) 2007 Jeremy C. Andrus <jeremy@jeremya.com>
+Started: 2007-April-13
+
+
+How to use a 1024-byte bulk transfer packet
+
+There are some devices/companies which have decided to use
+a bulk transfer packet size which is larger than the maximum
+specified in the USB spec. Because I was interested in using
+such a device, I found it necessary to devise a way to allow
+this functionality in the linux kernel.
+
+It is reasonably simple to create a 1024-byte bulk transfer
+URB. Simply OR the 'URB_1024_BYTE_PKT' value into the URB's
+transfer_flags field before submitting it to the system:
+
+ urb = usb_alloc_urb(0, GFP_KERNEL);
+
+ usb_fill_bulk_urb( urb, ... );
+
+ /* this allows the URB's buffer to be 1024 bytes */
+ urb->transfer_flags |= URB_1024_BYTE_PKT;
+
+ retval = usb_submit_urb( urb, GFP_KERNEL );
+
+ usb_free_urb( urb );
+
diff -Naur linux-2.6.20.6/drivers/usb/host/Kconfig linux-2.6.20.6_jca/drivers/usb/host/Kconfig
--- linux-2.6.20.6/drivers/usb/host/Kconfig 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/drivers/usb/host/Kconfig 2007-04-13 10:00:36.000000000 -0400
@@ -67,6 +67,20 @@
If unsure, say N.
+config USB_EHCI_1024BYTE_BULK_PKTS
+ bool "Allow 1024-byte packets in Bulk Transfer mode"
+ depends on USB_EHCI_HCD && EXPERIMENTAL
+ ---help---
+ The USB specification allows a maximum bulk transfer packet size
+ of 512 bytes. There are a few devices which have decided to break
+ this specification and use 1024 byte packets. This option allows
+ the use of the larger packet size with a very specific flag set
+ in the URB.
+
+ See the Documentation/usb/bulk_tx_hacks.txt file for details.
+
+ If unsure, say N.
+
config USB_ISP116X_HCD
tristate "ISP116X HCD support"
depends on USB
diff -Naur linux-2.6.20.6/drivers/usb/host/ehci-q.c linux-2.6.20.6_jca/drivers/usb/host/ehci-q.c
--- linux-2.6.20.6/drivers/usb/host/ehci-q.c 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/drivers/usb/host/ehci-q.c 2007-04-13 09:47:09.000000000 -0400
@@ -751,7 +751,12 @@
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else if (type == PIPE_BULK) {
info1 |= (EHCI_TUNE_RL_HS << 28);
- info1 |= 512 << 16; /* usb2 fixed maxpacket */
+#ifdef CONFIG_USB_EHCI_1024BYTE_BULK_PKTS
+ if ( urb->transfer_flags & URB_1024_BYTE_PKT )
+ info1 |= 1024 << 16; /* HACK for Micron Dev Kits requiring 1024 byte packets... */
+ else
+#endif
+ info1 |= 512 << 16; /* usb2 fixed maxpacket */
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else { /* PIPE_INTERRUPT */
info1 |= max_packet (maxp) << 16;
diff -Naur linux-2.6.20.6/include/linux/usb.h linux-2.6.20.6_jca/include/linux/usb.h
--- linux-2.6.20.6/include/linux/usb.h 2007-04-06 16:02:48.000000000 -0400
+++ linux-2.6.20.6_jca/include/linux/usb.h 2007-04-13 09:47:09.000000000 -0400
@@ -904,6 +904,9 @@
#define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt
* needed */
+#ifdef CONFIG_USB_EHCI_1024BYTE_BULK_PKTS
+#define URB_1024_BYTE_PKT 0x8000 /* Use a max packet length of 1024 bytes instead of 512 */
+#endif
struct usb_iso_packet_descriptor {
unsigned int offset;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb bulk transfer: 1024 byte packets
2007-04-13 16:56 [PATCH] usb bulk transfer: 1024 byte packets Jeremy C. Andrus
2007-04-13 18:47 ` Jeremy C. Andrus
@ 2007-04-14 2:16 ` Pete Zaitcev
2007-04-14 13:14 ` Jeremy C. Andrus
1 sibling, 1 reply; 5+ messages in thread
From: Pete Zaitcev @ 2007-04-14 2:16 UTC (permalink / raw)
To: Jeremy C. Andrus; +Cc: linux-kernel
On Fri, 13 Apr 2007 12:56:47 -0400, "Jeremy C. Andrus" <jeremy@jeremya.com> wrote:
> I recently ran into a couple of USB devices which insisted on using 1024
> byte packets in bulk transfer mode (despite the hard limit of 512
> established in the spec). I really wanted to use these devices, so I
> created a kernel patch which allows the use of 1024 byte URBs, but does
> not interfere with normal (512 byte) operation. I did this through a
> bit in the transfer_flags bitfield.
The transfer size in the URB is not limited by the maximum packet size.
The HC driver splits up the transfer as specified by URB into the required
number of packets.
I think you might want to write to linux-usb-devel@lists.sourceforge.net
to discuss the specifics of what it mean "devices insisted on 1024".
I presume the devices didn't show up on your doorstep with baseball
bats to have a little chat. So there must be a specific failure symptom.
Until you share it, I don't see this patch going anywhere.
-- Pete
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb bulk transfer: 1024 byte packets
2007-04-14 2:16 ` Pete Zaitcev
@ 2007-04-14 13:14 ` Jeremy C. Andrus
2007-04-14 16:58 ` Pete Zaitcev
0 siblings, 1 reply; 5+ messages in thread
From: Jeremy C. Andrus @ 2007-04-14 13:14 UTC (permalink / raw)
To: linux-kernel; +Cc: Pete Zaitcev
On Fri, April 13, 2007 22:16, Pete Zaitcev wrote:
>
> The transfer size in the URB is not limited by the maximum packet
> size. The HC driver splits up the transfer as specified by URB into
> the required number of packets.
The problem was not in the transfer from PC -> Device, but from Device
-> PC. If I remember correctly, the 512 limit (in the
urb->transfer_flags) is used to setup the DMA. When the device sent
packets which were 1024 bytes in size, the urb came back with a status
set to -EOVERFLOW.
The only place this could happen (in the EHCI) is in qtd_copy_status()
where the hardware has reported a "can't proceed" error (via
QTD_STS_HALT) and then the QTD_STS_BABBLE bit is set (which I interpret
to mean that the device on the other end is "babbling").
[snip]
> I presume the devices didn't show up on your doorstep with baseball
> bats to have a little chat.
In a sense they did when there was no way for me to do BULK transfers
without slamming me with 1024 byte packets :-).
-Jeremy
--
-----------------------
Jeremy C. Andrus
http://www.jeremya.com/
-----------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb bulk transfer: 1024 byte packets
2007-04-14 13:14 ` Jeremy C. Andrus
@ 2007-04-14 16:58 ` Pete Zaitcev
0 siblings, 0 replies; 5+ messages in thread
From: Pete Zaitcev @ 2007-04-14 16:58 UTC (permalink / raw)
To: jeremy; +Cc: linux-kernel, zaitcev
On Sat, 14 Apr 2007 09:14:25 -0400 (EDT), "Jeremy C. Andrus" <jeremy@jeremya.com> wrote:
> On Fri, April 13, 2007 22:16, Pete Zaitcev wrote:
> > The transfer size in the URB is not limited by the maximum packet
> > size. The HC driver splits up the transfer as specified by URB into
> > the required number of packets.
>
> The problem was not in the transfer from PC -> Device, but from Device
> -> PC. If I remember correctly, the 512 limit (in the
> urb->transfer_flags) is used to setup the DMA. When the device sent
> packets which were 1024 bytes in size, the urb came back with a status
> set to -EOVERFLOW.
It's a bug in your driver. Supply the correct size with the URB and
all will be fine. Like I said, HC splits up the transfer transparently,
no matter what direction.
-- Pete
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-14 16:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-13 16:56 [PATCH] usb bulk transfer: 1024 byte packets Jeremy C. Andrus
2007-04-13 18:47 ` Jeremy C. Andrus
2007-04-14 2:16 ` Pete Zaitcev
2007-04-14 13:14 ` Jeremy C. Andrus
2007-04-14 16:58 ` Pete Zaitcev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®