summaryrefslogtreecommitdiffstats
path: root/firmware/usbstack
AgeCommit message (Collapse)AuthorFilesLines
2022-10-15move buflib_free invalid handle check to the functionWilliam Wilgus1-2/+1
allow buflib_free to check for invalid or already freed handles within the function -- remove all the invalid handle guards thru core_free Change-Id: Ibdcbc82760fc93b674c42283fca420d94907df8e
2022-02-12buflib: add a common dummy callbacks struct & use itAidan MacDonald1-4/+3
There are various allocations that can't be moved or shrunk. Provide a global callback struct for this use case instead of making each caller declare its own dummy struct. Also fixed ROLO and x1000 installer code which incorrectly used movable allocations. Change-Id: I00088396b9826e02e69a4a33477fe1a7816374f1
2021-11-14usb_core: don't buffer control request unnecessarilyAidan MacDonald1-3/+1
Due to how the old control request API worked, the request pointer (and the pointed-to contents) passed by the driver must remain valid for the lifetime of the request. The buffered copy wasn't used consistently anyway, so it should be safe to just get rid of it. (This only affects the old API compatibility layer.) Change-Id: I00294c718a7515a91b84f7c7cae5220c73aa5960
2021-11-13usb_core: More legacy control API fixesAidan MacDonald1-8/+11
In the old API, usb_core_transfer_complete() would ignore any completions on EP0. The legacy control API will also ignore most completions on EP0, but it only did so after filling in the completion event. If the driver submits a spurious completion on EP0, then this could clobber a previously queued completion event. Fix this by deciding whether to ignore the completion *before* modifying the event data. Change-Id: I68526898a96efa594ada4e94bb6851aaaf12e92a
2021-11-09usb: Fix possible SET ADDRESS data corruptionAidan MacDonald1-2/+5
The address from the packet needs to be saved before sending the response -- after the response the request being pointed to could get overwritten. This used to be done correctly but I unintentionally broke it when updating the handler to the new control request API. Change-Id: I9b11548baf20dce44a82301731405dc8e8f1cef3
2021-11-08usb: Attempt to fix race condition in compatibility layerAidan MacDonald1-10/+14
Because usb_core_legacy_control_request() is called by an interrupt handler the global variables used to track the current control request at the very least need to be volatile. It might also be necessary to disable IRQs but I'm not sure of that. Change-Id: I0f0bb86d0ad63734e8d3c73cb1c52fedf5a98120
2021-10-16usb: ensure RX buffers are a multiple of the packet sizeAidan MacDonald3-12/+25
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-16usb: remove dead code in usb_storage driverAidan MacDonald1-11/+0
Change-Id: Id6fc3520dad1adace33fd1014288ccb4cf5818af
2021-10-16usb: port usb_storage control request handling to new APIAidan MacDonald1-3/+2
Change-Id: I1a19e09fdc0f05473d53c39bab0761d5cb8f6ff0
2021-10-16usb: port usb_hid control request handling to new APIAidan MacDonald1-30/+19
Change-Id: I9028cf06e91c9fcbe271f6ad81d6b252cb4e7cec
2021-10-16usb: port usb_serial control requests handling to new APIAidan MacDonald1-5/+6
Change-Id: I1405c9279e0e8e490e2bb2d03ff192b36db2634b
2021-10-16usb: port usb_core control request handling to new APIAidan MacDonald1-56/+52
Change-Id: I3850c9cfcb87831e56884c83e31f728590b76f83
2021-10-16usb: implement new API with legacy emulation layerAidan MacDonald1-21/+127
All existing USB drivers now define USB_LEGACY_CONTROL_API to enable the emulation layer. Control request handlers will be ported in follow-up commits. Change-Id: I4be1ce7c372f2f6fee5978a4858c841b72e77405
2021-10-16usb: add request data argument to all control request handlersAidan MacDonald8-32/+38
Change-Id: I237143fa0d95c914b8e25ed22f8acde96ec00551
2021-10-16usb: give USB transfer completion events two data pointersAidan MacDonald1-4/+6
Change-Id: I036cc7f02c2f86a364d2dba59493a6aa893f2c16
2021-10-16usb: introduce new control request APIAidan MacDonald1-1/+1
Change-Id: I6545d8985ab683c026f28f6a7c0e23b40d0a6506
2021-10-06usbstack: Revise usb string descriptor table to use enum values for indicesJames Buren1-10/+9
This makes it possible for macros of conditionally included string descriptors to get a correct index no matter what other usb drivers are enabled or disabled due to the nature behavior of enums. Change-Id: I8ccebbd316605bed0f5d90b6b73fab4a333c02fa
2021-10-06Fix includes in usb_class_driver.hAidan MacDonald1-0/+5
Change-Id: I602ec80d02b5f4f586386026a6312d048fa7dac3
2021-10-02x1000: fix hang that may occur in USB modeAidan MacDonald1-0/+6
Upon getting a USB reset, the USB core will update charging current by calling usb_charging_maxcurrent_change(). On all current X1000 targets this may cause a hang, since changing the charge current involves a blocking I2C transaction. Eg. if the host issues a reset when we're already configured as part of error recovery, the change from 500 mA -> 100 mA will cause a hang. Change-Id: I5b45272c01fa16b179ae3d16bbc50c7fab9a416b
2021-09-20usb: rename usb_drv_recv() to usb_recv_recv_nonblocking()Aidan MacDonald4-18/+18
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-20usb_hid: fix accidental fallthroughAidan MacDonald1-15/+27
Successful SET REPORT requests would spuriously fail because of the fall through to GET REPORT. Change-Id: I8e7d1a1120afc6975d07d47b11c12c9e9ca51dd2
2021-07-23usb_storage: Fix a memset in SCSI_INQUIRY that overflowed its bufferSolomon Peachy1-1/+1
The funny thing is that the memset() for the field in question was redundant, as the overall inquiry structure was memset(0) already. Change-Id: I8bec0c93c9317823ff39cf7133535e3bf58fb987
2021-07-10Sansa Connect: Use deviceid in USB Serial NumberTomasz Moń1-0/+20
Atmel AT88SC6416C CryptoMemory is almost I2C compatible. The device is connected to bitbanged I2C bus shared with compliant I2C devices. Change-Id: Iec54702db1bdfb93c01291eef18ec60391c63b16
2021-06-12USB Serial: Implement Abstract Control ManagementTomasz Moń1-15/+207
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-04-26Nuke all TCC77x targets: iAudio 7, Sansa C100, M200(v1-3), Logik DAXSolomon Peachy1-2/+2
They were never finished, never saw any release ever, and haven't compiled for the better part of a decade. Given their HW capabilities [1], they are not worth trying to fix. [1] 1-2MB RAM, ~256MB onboard flash, no expandability Change-Id: I7b2a5806d687114c22156bb0458d4a10a9734190
2021-03-25usb: implement macro for initializing USB stringsJames Buren1-25/+4
This uses the new unicode string literal feature that is available now to greatly simplify the initialization of these special string types. This makes them much more readable at a quick glance. Change-Id: Iad8b49aa763486608e3bb7e83fb8abfb48ce0a7b
2021-03-10usb_hid: switch Battery Strength to use feature reportsJames Buren1-23/+63
This means we will no longer send them routinely and instead rely on the HID driver to send them when the host requests it. This also moves the reporting out of the power management code where it probably did not belong in the first place. Change-Id: I9c8420e81897f1f6caaa55ffacc7525589f1ef75
2021-03-06usb_hid: add support for Battery StrengthJames Buren2-1/+58
This allows rockbox to report its battery status through the HID Battery Strength method that is available through the Device Controls usage page. Change-Id: Ia7a7dd9b9d476dd9df5a5f5becabc5ae823e9a89
2018-07-30Workaround for usb_storage_init_connection() panicCástor Muñoz1-0/+1
For s5l8701, s5l8702 and as3525v2 targets. The crash occurs when USB is inserted or extracted while the playlist is being loaded or updated (it could take a few seconds for huge playlists), at this point all buflib memory is allocated and not freed before usb_starage_init_connection() is executed. This workaround mitigates this panic by using static memory for USB buffers, so this memory cannot be used for other tasks, in addition the problem still persist when playlist load is 'paused' by USB insertion and then updated after USB extraction. Change-Id: Iff1db5a949361fd543e0b494924d1f2906c84b5e
2017-03-12Do some housekeeping with fat.h and SECTOR_SIZEMichael Sevakis1-5/+1
Many includes of fat.h are pointless. Some includes are just for SECTOR_SIZE. Add a file 'firmware/include/fs_defines.h' for that and to define tuneable values that were scattered amongst various headers. Remove some local definitions of SECTOR_SIZE since they have to be in agreement with the rest of the fs code anyway. (We'll see what's in fact pointless in a moment ;) Change-Id: I9ba183bf58bd87f5c45eba7bd675c7e2c1c18ed5
2016-08-04usb_serial: fix send buffer alignmentCástor Muñoz1-16/+11
Change-Id: Ib2635c905462cd34befa3ca61e5d55c869686b48
2016-08-02Introduce new USB driver for Synopsys DesignWare USB OTG core.Cástor Muñoz1-0/+11
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
2015-02-16Revert "usb_storage: make it a bit more correct"Amaury Pouly1-1/+0
Clearly this was a stupid commit, no idea why I did that. This reverts commit 074e911859a0d3464fde9b701b3cff712c5826e0.
2014-08-30Rewrite filesystem code (WIP)Michael Sevakis1-4/+1
This patch redoes the filesystem code from the FAT driver up to the clipboard code in onplay.c. Not every aspect of this is finished therefore it is still "WIP". I don't wish to do too much at once (haha!). What is left to do is get dircache back in the sim and find an implementation for the dircache indicies in the tagcache and playlist code or do something else that has the same benefit. Leaving these out for now does not make anything unusable. All the basics are done. Phone app code should probably get vetted (and app path handling just plain rewritten as environment expansions); the SDL app and Android run well. Main things addressed: 1) Thread safety: There is none right now in the trunk code. Most of what currently works is luck when multiple threads are involved or multiple descriptors to the same file are open. 2) POSIX compliance: Many of the functions behave nothing like their counterparts on a host system. This leads to inconsistent code or very different behavior from native to hosted. One huge offender was rename(). Going point by point would fill a book. 3) Actual running RAM usage: Many targets will use less RAM and less stack space (some more RAM because I upped the number of cache buffers for large memory). There's very little memory lying fallow in rarely-used areas (see 'Key core changes' below). Also, all targets may open the same number of directory streams whereas before those with less than 8MB RAM were limited to 8, not 12 implying those targets will save slightly less. 4) Performance: The test_disk plugin shows markedly improved performance, particularly in the area of (uncached) directory scanning, due partly to more optimal directory reading and to a better sector cache algorithm. Uncached times tend to be better while there is a bit of a slowdown in dircache due to it being a bit heavier of an implementation. It's not noticeable by a human as far as I can say. Key core changes: 1) Files and directories share core code and data structures. 2) The filesystem code knows which descriptors refer to same file. This ensures that changes from one stream are appropriately reflected in every open descriptor for that file (fileobj_mgr.c). 3) File and directory cache buffers are borrowed from the main sector cache. This means that when they are not in use by a file, they are not wasted, but used for the cache. Most of the time, only a few of them are needed. It also means that adding more file and directory handles is less expensive. All one must do in ensure a large enough cache to borrow from. 4) Relative path components are supported and the namespace is unified. It does not support full relative paths to an implied current directory; what is does support is use of "." and "..". Adding the former would not be very difficult. The namespace is unified in the sense that volumes may be specified several times along with relative parts, e.g.: "/<0>/foo/../../<1>/bar" :<=> "/<1>/bar". 5) Stack usage is down due to sharing of data, static allocation and less duplication of strings on the stack. This requires more serialization than I would like but since the number of threads is limited to a low number, the tradoff in favor of the stack seems reasonable. 6) Separates and heirarchicalizes (sic) the SIM and APP filesystem code. SIM path and volume handling is just like the target. Some aspects of the APP file code get more straightforward (e.g. no path hashing is needed). Dircache: Deserves its own section. Dircache is new but pays homage to the old. The old one was not compatible and so it, since it got redone, does all the stuff it always should have done such as: 1) It may be update and used at any time during the build process. No longer has one to wait for it to finish building to do basic file management (create, remove, rename, etc.). 2) It does not need to be either fully scanned or completely disabled; it can be incomplete (i.e. overfilled, missing paths), still be of benefit and be correct. 3) Handles mounting and dismounting of individual volumes which means a full rebuild is not needed just because you pop a new SD card in the slot. Now, because it reuses its freed entry data, may rebuild only that volume. 4) Much more fundamental to the file code. When it is built, it is the keeper of the master file list whether enabled or not ("disabled" is just a state of the cache). Its must always to ready to be started and bind all streams opened prior to being enabled. 5) Maintains any short filenames in OEM format which means that it does not need to be rebuilt when changing the default codepage. Miscellaneous Compatibility: 1) Update any other code that would otherwise not work such as the hotswap mounting code in various card drivers. 2) File management: Clipboard needed updating because of the behavioral changes. Still needs a little more work on some finer points. 3) Remove now-obsolete functionality such as the mutex's "no preempt" flag (which was only for the prior FAT driver). 4) struct dirinfo uses time_t rather than raw FAT directory entry time fields. I plan to follow up on genericizing everything there (i.e. no FAT attributes). 5) unicode.c needed some redoing so that the file code does not try try to load codepages during a scan, which is actually a problem with the current code. The default codepage, if any is required, is now kept in RAM separarately (bufalloced) from codepages specified to iso_decode() (which must not be bufalloced because the conversion may be done by playback threads). Brings with it some additional reusable core code: 1) Revised file functions: Reusable code that does things such as safe path concatenation and parsing without buffer limitations or data duplication. Variants that copy or alter the input path may be based off these. To do: 1) Put dircache functionality back in the sim. Treating it internally as a different kind of file system seems the best approach at this time. 2) Restore use of dircache indexes in the playlist and database or something effectively the same. Since the cache doesn't have to be complete in order to be used, not getting a hit on the cache doesn't unambiguously say if the path exists or not. Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8 Reviewed-on: http://gerrit.rockbox.org/566 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested: Michael Sevakis <jethead71@rockbox.org>
2014-02-10Coding style fix for bde5394Marcin Bukat1-3/+4
Change-Id: I6e9ba6a2570915191cf5b66f58ed9ddb1959b6cc
2014-02-09Return a valid USB string descriptor for index 0xEE.Frank Gevaerts1-0/+7
Windows will try to retrieve such a descriptor on first connect. If the device returns STALL or a regular string descriptor (i.e. not one that follows the Microsoft OS Descriptor spec), things will continue normally. Unfortunately some of our low-level USB drivers have issues with STALL so any other valid descriptor is the next best solution. Change-Id: I59eb09eea157e4e14bec0197a898be378a5559f2 Reviewed-on: http://gerrit.rockbox.org/680 Reviewed-by: Frank Gevaerts <frank@gevaerts.be> Tested: Frank Gevaerts <frank@gevaerts.be>
2014-01-11Don't use core_alloc_maximum() in usb_storage.Frank Gevaerts1-6/+5
usb_storage needs a fairly reasonable amount of memory. Allocating what we need and no more allows other (future) USB drivers to get something too, and is much cleaner in general. Change-Id: Iec9573c0f251f02400f92d92727cbf2969785de0
2014-01-05Make sure usb class driver disconnect() functions are called properly.Frank Gevaerts1-8/+20
disconnect() needs to be called exactly once per call to init_connection(). In case of bus resets, disconnect() was not called, which led to leaking alloc_maximum() allocated buflib handles, which led to buflib running out of memory to allocate. Change-Id: I03025da578dc54e48b6de6bd3e3f40feae7220a6
2014-01-05Check that core_alloc_maximum() returned something useful, and panic if notFrank Gevaerts1-0/+5
Change-Id: I7ae40db0f81d1d51742501936b13b387f94a25e5
2013-12-23playback,talk: Share audiobuffer via core_alloc_maximum().Thomas Martitz1-5/+12
This fixes the radioart crash that was the result of buffering.c working on a freed buffer at the same time as buflib (radioart uses buffering.c for the images). With this change the buffer is owned by buflib exclusively so this cannot happen. As a result, audio_get_buffer() doesn't exist anymore. Callers should call core_alloc_maximum() directly. This buffer needs to be protected as usual against movement if necessary (previously it was not protected at all which cased the radioart crash), To get most of it they can adjust the willingness of the talk engine to give its buffer away (at the expense of disabling voice interface) with the new talk_buffer_set_policy() function. Change-Id: I52123012208d04967876a304451d634e2bef3a33
2013-08-17Cleanup MV/MD macros a little.Michael Sevakis1-4/+4
When using variadic macros there's no need for IF_MD2/IF_MV2 to deal with function parameters. IF_MD/IF_MV are enough. Throw in IF_MD_DRV/ID_MV_VOL that return the parameter if MD/MV, or 0 if not. Change-Id: I7605e6039f3be19cb47110c84dcb3c5516f2c3eb
2013-08-12Fix response length calculation for SCSI_REPORT_LUNSBertrik Sikken1-1/+2
Change-Id: I1167851bae20d9275eb2f441ce9dc73c8b2f09b1 Reviewed-on: http://gerrit.rockbox.org/488 Reviewed-by: Frank Gevaerts <frank@gevaerts.be> Reviewed-by: Bertrik Sikken <bertrik@sikken.nl> Tested-by: Bertrik Sikken <bertrik@sikken.nl>
2013-07-24usb stack: add more verbose debug logf()sMarcin Bukat2-2/+7
Change-Id: I087aefd2854978813c7e4ed7ef7da400f3692e39
2013-07-24usb_storage: make it a bit more correctAmaury Pouly1-0/+1
Add stall when unknown SCSI command is hit Change-Id: Icbeea905cd262ab296fb34470e54c665b8bab488
2013-07-24usb_core: rework handling of clear featureAmaury Pouly1-3/+13
Change-Id: Icb1e973aa5fd8520eff0796aa8164e0a988d9107
2013-06-24imx233: fix ocotop/debug and usb-core for stmp3600Amaury Pouly1-1/+2
Currently we don't know where the serial number is stored on the stmp3600. It is probably using the laser fuses but this needs to be investigated Change-Id: I1ac25e38b8f65635abb68788ceb65df0a740dabd
2013-06-16imx233: rewrite ocotp using new register headersAmaury Pouly1-1/+1
Change-Id: I3c622119a1e296ec6b3f35f27e81b5118ab7f6cc
2013-05-17FS#12854 - ipod-time-sync sets wrong dayrbutil/mkamsboot/mkamsboot.cBoris Gjenero1-1/+1
Change-Id: I8ac7561119e51774b9aee377e7373a7e830a5780
2012-12-07usb: add support for hardware handled SET ADDR/CONFIGAmaury Pouly1-17/+53
Some USB controllers like the one of the Rockchip 27xx handle some requests in pure hardware. This is especially a problem for two of them: - SET ADDR which is used by our core to track the DEFAULT/ADDRESS state and is required for the drivers to work properly - SET CONFIG which is used by our core to initialise the drivers by calling init_connection() In these cases we need a way to notify the core that such requests happened. We do this by exporting two functions which directly notify the core about these requests and perform the necessary init steps required without doing the actual USB transfers. Special care is needed because these functions could be called from an interrupt handler. For this reason we still use the usb_queue and introduce new IDs so that they are processed in order and safely. No functional change is intended, both in the usbstack and on targets without such quirks. Change-Id: Ie42feffd4584e88bf37cff018b627f333dca1140
2012-05-31Fill USB serial number descriptor on imx233 targets.Amaury Pouly1-0/+27
Compute a serial number using the ocotp OPS bits like the OF. Also add a comment about the first character of serial number being a indicator of the enabled interfaces. Change-Id: I9b90aed4e3b803f12fec003c9bc8ee8a046f4e42