summaryrefslogtreecommitdiffstats
path: root/include/usb
Commit message (Collapse)AuthorAgeFilesLines
* usb: gadget: mass-storage: reference count allocations used in bthreadAhmad Fatoum2022-03-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Since 997cca0f15dc ("bthread: replace blocking bthread_stop with nonblocking bthread_cancel"), the bthread may survive longer than the multigadget unbind. This didn't cause issues so far, because the multi gadget unbind didn't call usb_put_function[_instance] for mass-storage (but did so for other functions), so we just leaked the memory. In preparation for fixing the memory leak, we will need to straighten out the mass storage cleanup. We do so by reference counting the two shared structures: If bthread runs before usb_put_function[_instance], it will not free them yet (avoiding a double free) and if bthread runs after usb_put_function[_instance], it will still be able to access them (avoiding a use-after-free). A cleaner way would've been to wait for bthread completion, but we can't do that here, because gadget could be unbound in a poller and bthreads are only scheduled in command context. Fixes: 997cca0f15dc ("bthread: replace blocking bthread_stop with nonblocking bthread_cancel") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220319110246.2850396-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: add SPDX-License-IdentifierAhmad Fatoum2022-01-0512-0/+24
| | | | | | | | | All these files lack a license statement, so add the default GPL-2.0-only. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220103120539.1730644-7-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: dfu: Rework dfu command to use usbgadgetJules Maselbas2021-10-051-1/+1
| | | | | | | | | | | | | | | | | | The dfu command now uses the composite multi gadget to register the usb functionality. This allows the removal of the usb composite driver from dfu.c As the dfu command is blocking the command slice must be released while the dfu gadget is running in order to do operations on the file system. The usb_dfu_register() function is replaced with usb_dfu_detached() for the dfu command to return a different value depending on if it has been interrupted with CTRL-C or if the gadget has been detached. Tested-by: Anže Lešnik <anze.lesnik@norik.com> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Link: https://lore.barebox.org/20210910102931.26078-1-jmaselbas@kalray.eu Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: add support for USB mass storage gadgetAhmad Fatoum2021-06-253-0/+119
| | | | | | | | | | | | | | | | | | | This driver is based on the f_mass_storage drivers in Linux v5.11 and U-Boot v2021.01. Unlike the U-Boot version, it runs asynchronously without blocking the bootloader from doing other tasks, like exporting other USB gadgets at the same time or enabling shell access. With pollers and workqueues, enabling this would need a large rework of the code to be completely callback based, whenever the original Linux code sleeps waiting for events. With the new bthread support, we can actually sleep and handover control to other bthreads until there is actual work to do. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: refactor usbgadget_register to accept arrayAhmad Fatoum2021-06-251-4/+13
| | | | | | | | | | usbgadget_register currently takes 6 arguments. Instead of increasing them to 8 to support the new usb mass storage gadget, rewrite it to accept a pointer to a struct with all the options instead. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210622082617.18011-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* drivers: drop unused usb_gadget_{map,unmap}_request()Antony Pavlov2021-06-151-10/+0
| | | | | | | | | There is no code that is dependent on usb_gadget_{map,unmap}_request(). Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Link: https://lore.barebox.org/20210614142833.86544-1-antonynpavlov@gmail.com Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fastboot/dfu: use system partitions as fall backAhmad Fatoum2021-05-121-0/+1
| | | | | | | | | | | | | Use the new system partitions infrastructure to have fastboot and DFU fall back to using the same partitions if the global.usbgadget.dfu_function and global.fastboot_partitions are not set, respectively. No functional change intended for configurations that have SYSTEM_PARTITIONS disabled. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: host: ehci: remove duplicated usb_host_detect() callsAhmad Fatoum2021-02-011-6/+0
| | | | | | | | With the last patch adding a fallback detect, we no longer need the duplication in the host controller drivers. Drop them. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net' into masterSascha Hauer2020-09-251-1/+7
|\
| * usb: Add a slice to usb host controllersSascha Hauer2020-08-191-1/+7
| | | | | | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | USB: gadget: Add serialnumber device parameterJules Maselbas2020-08-031-0/+1
|/ | | | | | | This add the device parameter usbgadget.serialnumber Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fastboot: split generic code from USB gadgetEdmund Henniges2020-05-202-32/+4
| | | | | | | | | | | | | The fastboot specification describes other protocols beyond USB. Allow these to reuse the generic parts of the existing fastboot code when they are implemented. Most of the changes in common/fastboot.c are due to the renaming of struct f_fastboot *f_fb to struct fastboot *fb. Signed-off-by: Edmund Henniges <eh@emlix.com> Signed-off-by: Daniel Glöckner <dg@emlix.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/mxs'Sascha Hauer2020-05-141-0/+13
|\
| * usb: i.MX: Add i.MX28 supportSascha Hauer2020-05-071-0/+13
| | | | | | | | | | | | | | | | The existing i.MX chipidea support can be used for i.MX28 as well. The main difference is that the i.MX28 doesn't have a usbmisc unit, so the bulk of this patch makes this unit optional in the driver. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | treewide: remove references to CREDITSUwe Kleine-König2020-04-272-6/+0
|/ | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb'Sascha Hauer2020-04-165-7/+58
|\
| * usb: Add U-Boot xhci driverSascha Hauer2020-03-261-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the xhci driver from U-Boot-2020.04-rc2. The usual things like adjusting to the barebox driver model and using dev_* instead of printf/puts/debug messages are made. The previously existing PCI support is not present in this driver currently. XHCI PCI support was not enabled in any defconfig, so we boldly assume it was unused. It shouldn't be much effort though to add it again. The memory handling has been changed for barebox. The various descriptor rings and descriptors are allocated with dma_alloc_coherent() which makes the cache flushing/invalidating unnecessary. They are left in the driver in case we want to change that. The XHCI has a nasty limitation in that the TRBs may not cross a 64KiB boundary. This limitation has been handled in the U-Boot driver, but the handling seems to be broken. We help ourselves with using a bounce buffer which is sufficiently aligned, but this limits the maximum bulk transfer size to 64KiB. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: Add super speed supportSascha Hauer2020-03-263-0/+39
| | | | | | | | | | | | | | This adds the missing bits and pieces to add super speed support to the USB stack. It is based on the corresponding U-Boot code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: hub: Translate USB 3.0 hub port status into old versionSascha Hauer2020-03-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adoption of U-Boot commit: | 1commit 74ffc7cbb1d2d1f218b1bd67d1bd3cc1cba8aa79 | Author: Bin Meng <bmeng.cn@gmail.com> | Date: Wed Jul 19 21:51:12 2017 +0800 | | usb: hub: Translate USB 3.0 hub port status into old version | | USB 3.0 hub port status field has different bit positions from 2.0 | hubs. Since U-Boot only understands the old version, translate the | new one into the old one. | | Since we are going to add USB 3.0 hub support, this feature is only | available with driver model USB. | | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: net: Allocate tx buffer dynamicallySascha Hauer2020-03-261-0/+1
| | | | | | | | | | | | It's cleaner to have a tx buffer per device and not one for all. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: net: Allocate rx buffer dynamicallySascha Hauer2020-03-261-0/+1
| | | | | | | | | | | | | | Allocate an individual rx buffer per device in the size we need it instead of using one global buffer for all devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: support set hub depth request for USB 3.0 hubsSascha Hauer2020-03-201-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an adoption of U-Boot commit bbc6f06c0031249bf1983b875e54cb7549bafe60: | commit bbc6f06c0031249bf1983b875e54cb7549bafe60 | Author: Bin Meng <bmeng.cn@gmail.com> | Date: Wed Jul 19 21:51:13 2017 +0800 | | usb: hub: Support 'set hub depth' request for USB 3.0 hubs | | USB 3.0 hub uses a hub depth value multiplied by four as an offset | into the 'route string' to locate the bits it uses to determine the | downstream port number. We shall set the hub depth value of a USB | 3.0 hub after it is configured. | | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | Reviewed-by: Simon Glass <sjg@chromium.org> In this patch we also support recording the depth of a hub in struct usb_device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: hub: Parse and save TT details from device descriptorSascha Hauer2020-03-201-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adoption of U-Boot commit 5624dfd5aa91c244519ec60b40b4a42b4d9a43ca: | commit 5624dfd5aa91c244519ec60b40b4a42b4d9a43ca | Author: Bin Meng <bmeng.cn@gmail.com> | Date: Wed Jul 19 21:51:16 2017 +0800 | | usb: hub: Parse and save TT details from device descriptor | | A high speed hub has a special responsibility to handle full speed/ | low speed devices connected on downstream ports. In this case, the | hub must isolate the high speed signaling environment from the full | speed/low speed signaling environment with the help of Transaction | Translator (TT). TT details are provided by hub descriptors and we | parse and save it to hub uclass_priv for later use. | | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * usb: Make driver_info constSascha Hauer2020-03-201-1/+1
| | | | | | | | | | | | driver_info shouldn't be changed, make it const. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | usb: rename "struct usb_configuration" to "struct usb_config"Christian Eggers2020-02-251-2/+2
|/ | | | | | | | | | | struct usb_configuration in usb.h conflicts with struct usb_configuration in usb/composite.h The version in usb/composite.h is also defined in Linux, so rename the other one. Signed-off-by: Christian Eggers <ceggers@arri.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Add usbroothubdes.hSascha Hauer2019-12-201-0/+128
| | | | | | Taken from U-Boot, needed for the upcoming dwc2 driver. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Make timeout unit clearSascha Hauer2019-12-201-4/+4
| | | | | | | The usb_*_msg() functions take a timeout parameter. Make clear which unit is expected by adding a _ms suffix to the variable name. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: i.MX: Use usb_register_otg_device()Sascha Hauer2019-11-211-7/+1
| | | | | | | We now have usb_register_otg_device() to register an "otg" device. Use it and drop the custom code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Add function to register otg devSascha Hauer2019-11-211-0/+3
| | | | | | | | We have two drivers in the tree which register an "otg" device to configure the host/peripheral switching. Before introducing a third driver create a common function for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/usb'Sascha Hauer2019-10-171-0/+3
|\
| * usb: Change power-on / scanning timeout handlingPrimoz Fiser2019-10-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change USB port scanning procedure and timeout handling in the following ways: 1) The power-on delay in usb_hub_power_on() is now reduced to a value of max(100ms, "hub->desc.bPwrOn2PwrGood * 2"). The code does not wait using mdelay, instead usb_hub_power_on() will wait before querying the device in the scanning loop later. The total connection timeout for this hub, which is (1 second + hub->desc.bPwrOn2PwrGood * 2) is calculated and will be used in the following per-port scanning loop as the timeout to detect active USB devices on this hub. 2) Don't delay the minimum delay (for power to stabilize) in usb_hub_power_on(). Instead skip querying these devices in the scanning loop usb_scan_port() until the delay time is reached. 3) The ports are now scanned in a quasi parallel way. The current code did wait for each (unconnected) port to reach its timeout and only then continue with the next port. This patch now changes this to scan all ports of all USB hubs quasi simultaneously. For this, all ports are added to a scanning list in usb_hub_configure_ports(). The list is later scanned in usb_device_list_scan() until all ports are ready by either a) reaching the connection timeout (calculated earlier), or by b) detecting a USB device. This results in a faster USB scan time as the recursive scanning of USB hubs connected to the hub that's currently being scanned will start earlier. 4) Ports with overcurrent detection will get scanned multiple times if OC condition is detected (PORT_OVERCURRENT_MAX_SCAN_COUNT). Without patch: $ time usb usb: USB: scanning bus for devices... usb: 17 USB Device(s) found time: 10344ms With patch: $ time usb usb: USB: scanning bus for devices... usb: 17 USB Device(s) found time: 4529ms Delta: ~6 seconds Signed-off-by: Primoz Fiser <primoz.fiser@norik.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/layerscape'Sascha Hauer2019-10-173-0/+9
|\ \
| * | usb: gadget: composite: conditionally dequeue setup requestsSascha Hauer2019-09-171-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is an adoption of Kernel commit a7c12eaf2 ("usb: gadget: composite: conditionally dequeue os_desc and setup requests"). Basically we only want to dequeue ep0 requests when they are actually queued. Drivers like dwc3 warn when unqueued requests are being tried to unqueued. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | usb/ch9.h: add USB 3.1 isoc endpoint defineSteffen Trumtrar2019-09-171-0/+2
| | | | | | | | | | | | | | | | | | | | | Add a new define for USB 3.1 endpoints Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | usb: gadget: add usb_gadget_udc_reset functionSteffen Trumtrar2019-09-171-0/+4
| |/ | | | | | | | | | | | | Add a function to notify the udc core, that a bus reset occured. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / USB: remove blackfin supportSascha Hauer2019-09-121-8/+0
|/ | | | | | | The blackfin architecture has been removed from barebox. Remove the blackfin specifics in the USB drivers as well. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Drop usb_disable_asynch()Andrey Smirnov2019-03-111-1/+0
| | | | | | | | | | There are no users of usb_control_msg() in the codebase that pass timeout of 0, so it doesn't look like usb_disable_asynch() has any effect on USB operation. Drop that function and remove all of its uses to simplify things. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include/usb: Import USB_SPEED_SUPER_PLUS from LinuxAndrey Smirnov2019-02-221-0/+1
| | | | | | | | Import USB_SPEED_SUPER_PLUS constant from Linux to support porting kernel code that uses it. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: fastboot: pass message type as enumSascha Hauer2018-12-071-1/+9
| | | | | | | | We used to pass the message type ("INFO", "FAIL", "OKAY") as strings to fastboot_tx_print(). Change this to a enum type. This allows fastboot_tx_print() to react on the message type in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: autostart: add DFU supportLadislav Michl2018-10-291-0/+4
| | | | | | | | | | | Use global variable dfu_function to autostart DFU. As similar code is used to start multifunction gadget using command, move common code to common/usbgadget.c and consolidate it. It turned out that '-s' option of usbgadget command does nothing, so remove its help text and make it function as '-a'. Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: fsl_udc: pass controller instance to unregisterSascha Hauer2018-10-291-2/+4
| | | | | | | | | | | | | ci_udc_unregister() used to unregister "the controller". Since we may register multiple chipidea devices we called ci_udc_unregister() for each of them. This led to messages like: ERROR: imx-usb 53f80000.usb: gadget not registered. Fix this by returning the registered controller. This allows us to call ci_udc_unregister() only when we actually registered one before. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: host: ehci: do not use dev->privSascha Hauer2018-10-291-0/+6
| | | | | | | | | | | | | | An ehci can be registered with ehci_register which is passed a struct device_d *. In that case the priv pointer may already be used by the caller, so we must not use it in the ehci code. At least for the Atmel ehci driver this fixes a bug, here dev->priv is set two times to different values. Since we need dev->priv in the ehci code to get the controller in ehci_detect() we can no longer implement that without the help of the caller, hence we eport ehci_detect() and epect it to be called by the code which registers a ehci host. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: host: ehci: add ehci_unregister()Sascha Hauer2018-10-291-3/+11
| | | | | | | | | ehci_register() allocates data and registers a ehci host. Add ehci_unregister() to properly halt the controller and to free the memory again.. To do so, change ehci_register() to return the ehci host rather than an error code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: Add usb_unregister_host()Sascha Hauer2018-10-261-0/+1
| | | | | | | | We have usb_register_host() which puts a new host on the list of hosts we should also have the opposite which removes the host from the list again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: imx: implement support for limiting host to full speedNikita Yushchenko2018-06-263-0/+10
| | | | | | | | | | | | | | | | | | This is needed when host is known to not work properly in high speed mode. In linux, chipidea driver supports 'maximum-speed' device tree property. When that is set to "full-speed", driver sets PFSC bit in PORTSC register, which disallows use of high speed mode. This patch implements same support for barebox. Important technical detail is that PFSC bit is cleared by port reset, thus setting it has to be done in ehci->init() callback which is called after ehci_reset(). Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: fastboot: Add external command execution supportSascha Hauer2018-02-091-0/+17
| | | | | | | | | | | | | | | | Custom projects may need vendor specific expansions to the fastboot command execution. Allow these to be implemented without messing in the fastboot code directly. We have a hook for all commands and also one for the "flash" command. Each hook can decide if the generic command parser is executed afterwards (return value FASTBOOT_CMD_FALLTHROUGH) or if the generic parser shall be skipped (return value 0 or negative error code). This allows board code to implement vendor specific "oem" commands or to handle the downloaded image in a special way (i.e. do signature checks on them) Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usbgadget: fastboot: Allow to automatically export the bbu handlersSascha Hauer2017-09-271-0/+7
| | | | | | | | | | We have a list of registered handlers which take a barebox update. Do the next step and allow to automatically export them via fastboot so that barebox can be updated via fastboot without manually exporting the partition. Since this may not be desirable in all cases this behaviour is configurable. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: gadget: properly release f_multi_optsSascha Hauer2017-03-091-0/+2
| | | | | | | | | | | | | | | | The usbgadget commands uses statically allocated f_multi_opts and passes this to usb_multi_register(). These f_multi_opts are of course no longer valid when we leave the usbgadget command. Luckily we do not use the data after we left the usbgadget command, so this never has been a problem. However, f_multi_opts has some allocated members which we can not free anymore on gadget unregistration because we no longer have the pointer to them. Fix this by adding a release function to struct f_multi_opts. This way we can allocate all memory dynamically and properly free it when not used anymore. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: imx: Make usb-misc multi instance safeSascha Hauer2017-01-191-2/+2
| | | | | | | i.MX7 has two usbmisc devices, so we cannot use global instance variables anymore. Create a driver private data struct for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* usb: ehci: forward phy given in registration data to hostSascha Hauer2016-09-291-0/+1
| | | | | | | Allow to pass a phy in the registration data and forward it to the usb_host structure. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>