Commit Graph

35 Commits

Author SHA1 Message Date
Aidan MacDonald 24294bda15 usb: ensure RX buffers are a multiple of the packet size
When performing an OUT transfer which is not a multiple of the
max packet size, the last packet of the OUT transfer should be
a short packet. However, there's no guarantee the host sends
the expected amount of data in the final packet.

The DWC2 USB controller handles this case by accepting any size
packet and copying it out to memory. So if the packet is bigger
than expected, it'll overrun the caller's buffer and Bad Things
will happen.

The USB 2.0 spec seems to endorse this behavior. Section 8.5.1
says "an ACK handshake indicates the endpoint has space for a
wMaxPacketSize data payload." So it is possible that other USB
controllers share the DWC2's behavior.

The simplest solution is to force all USB RX buffers to be big
enough to hold the transfer size, rounded up to a multiple of
the max packet size. For example, a transfer of 700 bytes would
require a 1024-byte buffer if the MPS = 512 bytes.

Change-Id: Ibb84d2b2d53aec8800a3a7c2449f7a17480acbcf
2021-10-16 21:14:42 +01:00
Aidan MacDonald 3318ba4795 usb: port usb_serial control requests handling to new API
Change-Id: I1405c9279e0e8e490e2bb2d03ff192b36db2634b
2021-10-16 21:14:42 +01:00
Aidan MacDonald dff8320a5d usb: add request data argument to all control request handlers
Change-Id: I237143fa0d95c914b8e25ed22f8acde96ec00551
2021-10-16 21:14:42 +01:00
Aidan MacDonald 672bbe434b usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()
IMHO the current name is somewhat misleading:

- usb_drv_send() is blocking and we have usb_drv_send_nonblocking()
  for the non-blocking case. This inconsistent naming can only
  promote confusion. (And what would we call a blocking receive?)

- Other hardware abstraction APIs in Rockbox are usually blocking:
  storage, LCD, backlight, audio... in other words, blocking is the
  default expected behavior, with non-blocking calls being a rarity.

Change-Id: I05b41088d09eab582697674f4f06fdca0c8950af
2021-09-20 22:41:29 +01:00
Tomasz Moń f3f9d1fb95 USB Serial: Implement Abstract Control Management
On devices that can assign interrupt IN, bulk IN and bulk OUT endpoints
this change results in the serial interface working out of the box on
Linux and Windows. On Linux it is registered as ttyACM device and on
Windows it is assigned a COM port number.

On devices that cannot assign the interrupt IN this change won't have
any effect.

Implement minimum required interface control requests. Respond with
whatever line coding was set to make terminal programs happy.

Change-Id: Id7d3899d8546e45d7cb4ecc3fe464908cb59e810
2021-06-12 14:47:15 +00:00
Cástor Muñoz e3c51e09d1 usb_serial: fix send buffer alignment
Change-Id: Ib2635c905462cd34befa3ca61e5d55c869686b48
2016-08-04 17:57:04 +02:00
Cástor Muñoz 5e305d35c9 Introduce new USB driver for Synopsys DesignWare USB OTG core.
Based on g#844 and g#949, it is intended as a replacement for the
current s3c6400x USB driver.

The DesignWare USB OTG core is integrated into many SoC's, however
HW core version and capabilities (mainly DMA mode, Tx FIFO mode,
FIFO size and number of available IN/OUT endpoins) may differ:

CPU       targets        HW ver  DMA  NPTX FIFO  FIFO sz  #IN/OUT
--------  -------------  ------  ---  ---------  -------  -------
as3525v2  sansaclipplus  2.60a   Yes  Dedicated  0x535    4/4
          sansaclipv2
          sansaclipzip
          sansafuzev2
s5l8701   ipodnano2g     2.20a   Yes  Shared     0x500    4/5
s5l8702   ipod6g         2.60a   Yes  Dedicated  0x820    7/7
          ipodnano3g
s5l8720   ipodnano4g     ?       ?    ?          ?        ?

Functionality supported by this driver:
- Device mode, compatible with USB 1.1/2.0 hosts.
- Shared FIFO (USB_DW_SHARED_FIFO) or dedicated FIFOs.
- No DMA (USB_DW_ARCH_SLAVE) or internal DMA mode.
- Concurrent transfers: control, bulk (usb_storage, usb_serial) and
  interrupt (usb_hid).

Actually this driver is not used by any CPU, it will be enabled for
each individual CPU/target in next patches.

Change-Id: I74a1e836d18927a31f6977d71115fb442477dd5f
2016-08-02 04:57:49 +02:00
Rafaël Carré 4c2126b5a8 usb PACK_DATA: use a static inline to enable type checking
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31467 a1c6a512-1295-4272-9138-f99709370657
2011-12-29 21:58:34 +00:00
Amaury Pouly ca370f4b40 Fix a bug in usbserial that would allow to send messages on EP_CONTROL between usb init and endpoints allocation via logf.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24214 a1c6a512-1295-4272-9138-f99709370657
2010-01-11 21:03:48 +00:00
Jeffrey Goode 9d842683eb Comment out LOGF_ENABLE defines everywhere, replace evil comments
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23497 a1c6a512-1295-4272-9138-f99709370657
2009-11-03 16:25:03 +00:00
Frank Gevaerts 1eeab430a1 Add const to usb_serial_send() buffer.
Flyspray: FS#10519
Author: Amaury Pouly



git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22422 a1c6a512-1295-4272-9138-f99709370657
2009-08-19 05:30:40 +00:00
Frank Gevaerts f10a3c7bed Limit usb_serial packets to 32 bytes. It's unclear why this is needed, but usb serial packets larger than 96 bytes seem to never be sent.
Thanks to Amaury Pouly for investigating this


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22285 a1c6a512-1295-4272-9138-f99709370657
2009-08-12 20:35:01 +00:00
Frank Gevaerts c61a75173b Reorganise USB stack defines. Now config.h decides which class drivers get enabled instead of usb_core.h
Also enable HID, and use that as the dummy class instead of charging-only for controllers that have working interrupt transfers.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21053 a1c6a512-1295-4272-9138-f99709370657
2009-05-23 14:30:20 +00:00
Frank Gevaerts 69a4117c1d Add working USB HID driver, by Tomer Shalev (part of his GSoC work).
This needs support for usb interrupt transfers, so there are some changes in various USB drivers as well (only usb-drv-arc supports it at this point, others won't have working HID yet).

HID is disabled for now, as the apps/ part is not included yet.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20962 a1c6a512-1295-4272-9138-f99709370657
2009-05-16 15:30:09 +00:00
Frank Gevaerts 4bff30a77f simplify and cleanup usb_serial.c (FS#10149 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20746 a1c6a512-1295-4272-9138-f99709370657
2009-04-19 19:25:59 +00:00
Frank Gevaerts 00b407b04f USB related Cosmetics, whitespace and readability fixes (FS#10147 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20737 a1c6a512-1295-4272-9138-f99709370657
2009-04-18 21:32:41 +00:00
Frank Gevaerts 3314f389ba Allow class drivers to reuse the core data buffer for control transfers. This doesn't make much difference right now, but it should keep HID memory usage lower (once HID is ready) (FS#10146 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20735 a1c6a512-1295-4272-9138-f99709370657
2009-04-18 20:40:50 +00:00
Frank Gevaerts ab09322b7a Add a PACK_DESCRIPTOR macro to make the class drivers a bit more readable (FS#10145 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20733 a1c6a512-1295-4272-9138-f99709370657
2009-04-18 20:04:52 +00:00
Frank Gevaerts 3e7715d2f5 small usb serial fixes. This seems to work fine on imx31, but for some reason it sometimes stops sending data on portalplayer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20077 a1c6a512-1295-4272-9138-f99709370657
2009-02-21 16:36:54 +00:00
Frank Gevaerts 88eb592cf4 more fixes. There's still something wrong as it sometimes suddenly stops sending data. Disconnecting and reconnecting gets it going again
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20072 a1c6a512-1295-4272-9138-f99709370657
2009-02-21 00:28:40 +00:00
Frank Gevaerts 2c3517d67a Fix ringbuffer handling. This will hopefully fix the hang-on-fast-send issue
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20064 a1c6a512-1295-4272-9138-f99709370657
2009-02-20 15:20:31 +00:00
Frank Gevaerts 67a5c56103 usb serial on PP seems to have broken. Fix it
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20023 a1c6a512-1295-4272-9138-f99709370657
2009-02-16 21:45:40 +00:00
Frank Gevaerts 478fc5baed reorganise the USB stack a bit to allow for easier integration of non-ARC controller drivers
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18703 a1c6a512-1295-4272-9138-f99709370657
2008-10-03 22:43:16 +00:00
Daniel Stenberg 2acc0ac542 Updated our source code header to explicitly mention that we are GPL v2 or
later. We still need to hunt down snippets used that are not. 1324 modified
files...
http://www.rockbox.org/mail/archive/rockbox-dev-archive-2008-06/0060.shtml


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17847 a1c6a512-1295-4272-9138-f99709370657
2008-06-28 18:10:04 +00:00
Frank Gevaerts ee8ebc9160 typo fixes (; instead of , at the end of two assignments)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17398 a1c6a512-1295-4272-9138-f99709370657
2008-05-06 20:48:50 +00:00
Bertrik Sikken ba39a5c110 Added missing usb #includes to usb source files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17309 a1c6a512-1295-4272-9138-f99709370657
2008-05-03 07:10:21 +00:00
Frank Gevaerts bec6aa3176 - change the usb class driver framework to allow for device classes with more than one interface or more than one endpoint pair
- move the charging-only dummy driver out of usb_core



git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17252 a1c6a512-1295-4272-9138-f99709370657
2008-04-26 19:02:16 +00:00
Frank Gevaerts 02bfba6c61 Put USB controller structures in IRAM. This seems to make the connection much more stable on PP502x
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17191 a1c6a512-1295-4272-9138-f99709370657
2008-04-20 16:51:09 +00:00
Michael Sevakis 94f7d0f290 UMS for the Gigabeat S. Bootloader USB mode. Has a couple quirks 1) First plug has problems if cold. Replug if it doesn't connect or not at high speed 2) Linux doesn't like the odd bootable flag value used in the partitions so it won't mount but Windows works. Fix minor OTG driver bugs and clean up device memory handling. Generic name for ARC controller driver.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17154 a1c6a512-1295-4272-9138-f99709370657
2008-04-18 16:42:50 +00:00
Frank Gevaerts f0b4a32d6f reorganise the usb stack to provide a clean separation between core and class drivers
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16541 a1c6a512-1295-4272-9138-f99709370657
2008-03-06 21:25:09 +00:00
Frank Gevaerts 0b4299a82f extra input checking
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16493 a1c6a512-1295-4272-9138-f99709370657
2008-03-02 23:34:30 +00:00
Frank Gevaerts 8abe9cffe4 remove a reundant MIN(), and reduce the buffer. We really don't need 16k for this. It seems to work reliably at full speed.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16491 a1c6a512-1295-4272-9138-f99709370657
2008-03-02 22:12:51 +00:00
Frank Gevaerts 776d015cc4 implement logf over usb-serial. Needs USB_SERIAL defined in usb_core.h to work, and needs to be enabled in the debug menu.
It stops sending data after a while for unknown reasons.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16486 a1c6a512-1295-4272-9138-f99709370657
2008-03-02 20:45:33 +00:00
Frank Gevaerts 07427592a9 Major USB stack improvements. It now works at nearly the maximum speed for a full speed connection, and does seem stable.
Still not enabled by default, #define USE_ROCKBOX_USB is still required to enable it.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16360 a1c6a512-1295-4272-9138-f99709370657
2008-02-20 22:54:26 +00:00
Christian Gmeiner 94be71eab5 Add a working serial driver to usb stack. At the moment it simply echos back what it gets. You can test it on linux by
0) change relevant defines in usb_core.c
1) modprobe usbserial vendor=0x0781 product=0x7421 debug=1
2) picocom /dev/ttyUSB0
3) look at your logf screen if you build with logf support and enabled LOGF_ENABLE define in usb_serial.c
I also modified usb_core so that storage and serial both can make use the the 'usb_core'-thread. More will come :)


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15850 a1c6a512-1295-4272-9138-f99709370657
2007-11-30 00:13:00 +00:00