aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/usb/controller/dwc_otg.c
Commit message (Collapse)AuthorAgeFilesLines
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-251-1/+1
| | | | Sponsored by: Netflix
* sys: Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-161-1/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* usb(4): Remove a double word in a source code commentGordon Bergling2022-04-091-1/+1
| | | | | | - s/for for/for/ MFC after: 3 days
* Fix undefined behaviour in the USB controllersAndrew Turner2022-01-121-2/+1
| | | | | | | | | | | | | | | | The USB controller drivers assume they can cast a NULL pointer to a struct and find the address of a member. KUBSan complains about this so replace with the __offsetof and __containerof macros that use either a builtin function where available, or the same NULL pointer on older compilers without the builtin. Reviewers: hselasky Subscribers: imp Reviewed by: hselasky Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33865
* Factor out repeated code in the USB controller drivers to avoid bugsHans Petter Selasky2021-07-101-43/+2
| | | | | | | | computing the same isochronous start frame number over and over again. PR: 257082 MFC after: 1 week Sponsored by: NVIDIA Networking
* usb: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-46/+1
| | | | Notes: svn path=/head/; revision=365084
* Add dwc_otg_acpiAndrew Turner2020-06-301-0/+29
| | | | | | | | | | | | | | Create an acpi attachment for the DWC USB OTG device. This is present in the Raspberry Pi 4 in the USB-C port normally used to power the board. Some firmware presents the kernel with ACPI tables rather than FDT so we need an ACPI attachment. Submitted by: Greg V <greg_unrelenting.technology> Approved by: hselasky (removal of All rights reserved) Differential Revision: https://reviews.freebsd.org/D25203 Notes: svn path=/head/; revision=362803
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (2 of many)Pawel Biernacki2020-02-151-1/+2
| | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Reviewed by: hselasky, kib Approved by: kib (mentor) Differential Revision: https://reviews.freebsd.org/D23632 Notes: svn path=/head/; revision=357972
* Sometimes the complete split packet may be queued too early and theHans Petter Selasky2018-11-071-0/+13
| | | | | | | | | | | transaction translator will return a NAK. Ignore this message and retry the complete split instead. MFC after: 3 days Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=340212
* Fix for reception of large full speed isochronous frames via the transactionHans Petter Selasky2018-10-161-7/+22
| | | | | | | | | | | | | | | translator, when using the DWC OTG USB controller driver. Make sure to re-try getting the complete split packets until a DATA0 packet is received. Larger isochronous frames may be split into multiple MDATA packets terminated by a single DATA0 packet. PR: 230434 MFC after: 3 days Approved by: re (gjb) Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=339388
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Allow operation with UTMI+ phy.Ruslan Bukin2016-11-171-8/+19
| | | | | | | | Submitted by: kan Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=308752
* Fix interrupt loop when switching from USB device to USB host mode byHans Petter Selasky2016-07-041-16/+18
| | | | | | | | | | | clearing all endpoint interrupt bits. PR: 210736 Approved by: re (glebius) MFC after: 1 week Notes: svn path=/head/; revision=302336
* Fix detection of USB device disconnects in USB host mode when the USBHans Petter Selasky2016-07-011-1/+4
| | | | | | | | | | | | device is connected directly to the USB port of the DWC OTG, in this case a RPI-zero. PR: 210695 Approved by: re (gjb) MFC after: 1 week Notes: svn path=/head/; revision=302306
* dev/usb: minor spelling fixes in comments.Pedro F. Giffuni2016-05-021-1/+1
| | | | | | | | | No functional change. Reviewed by: hselasky Notes: svn path=/head/; revision=298932
* Fix for directly connected FULL or LOW speed USB devices.Hans Petter Selasky2016-01-051-6/+21
| | | | | | | | Found by: Sebastian Huber <sebastian.huber@embedded-brains.de> MFC after: 1 week Notes: svn path=/head/; revision=293192
* Avoid using the bounce buffer when the source or destination buffer isHans Petter Selasky2015-11-081-37/+139
| | | | | | | | | | | 32-bits aligned. Merge the two bounce buffers into a single one. Some rough tests showed that the DWC OTG throughput on RPI2 increased by 10% after this patch. MFC after: 1 week Notes: svn path=/head/; revision=290542
* Reduce the DWC OTG interrupt load by not reading all the host channelHans Petter Selasky2015-10-301-6/+11
| | | | | | | | | | | | status registers for every interrupt. Check a common host channel status interrupt register first, then conditionally read the individual host channel status registers. Submitted by: Sebastian Huber <sebastian.huber@embedded-brains.de> MFC after: 1 week Notes: svn path=/head/; revision=290195
* Fixes for HIGH speed ISOCHRONOUS traffic. HS ISOCHRONOUS traffic atHans Petter Selasky2015-08-151-213/+234
| | | | | | | | | | | | intervals less than 250us was not handled properly. Add support for high-bandwidth ISOCHRONOUS packets. USB webcams, USB audio and USB DVB devices are expected to work better. High-bandwidth INTERRUPT endpoints is not yet supported. MFC after: 2 weeks Notes: svn path=/head/; revision=286802
* Handle NYET high speed tokens and predict NAK'ing is up next.Hans Petter Selasky2015-08-141-7/+13
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=286780
* Minor code refactor to avoid duplicating code.Hans Petter Selasky2015-08-141-18/+9
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=286778
* Limit the number of times we loop inside the DWC OTG poll handler toHans Petter Selasky2015-07-311-1/+7
| | | | | | | | | | avoid starving other fast interrupts. Fix a comment while at it. MFC after: 1 week Suggested by: Svatopluk Kraus <onwahe@gmail.com> Notes: svn path=/head/; revision=286118
* Optimise the DWC OTG host mode driver's receive path:Hans Petter Selasky2015-07-281-48/+29
| | | | | | | | | | | | Remove NAKing limit and pause IN and OUT transactions for 125us in case of NAK response for BULK and CONTROL endpoints. This gets the receive latency down and improves USB network throughput at the cost of some CPU usage. MFC after: 1 month Notes: svn path=/head/; revision=285935
* Optimise the DWC OTG host mode driver's transmit path:Hans Petter Selasky2015-07-161-107/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | 1) Use the TX FIFO empty interrupts to poll the transmit FIFO usage, instead of using own software counters and waiting for SOF interrupts. Assume that enough FIFO space is available to execute one USB OUT transfer of any kind when the TX FIFO is empty. 2) Use the host channel halted event to asynchronously wait for host channels to be disabled instead of waiting for SOF interrupts. This results in less turnaround time for re-using host channels and at the same time increases the performance. The network transmit performance measured by "iperf" for the "RPi-B v1 2011/12" board, increased from 45MBit/s to 65Mbit/s after applying the changes above. No regressions seen using: - High Speed (BULK, CONTROL, INTERRUPT) - Full Speed (All transfer types) - Low Speed (Control and Interrupt) MFC after: 1 month Submitted by: Daisuke Aoyama <aoyama@peach.ne.jp> Notes: svn path=/head/; revision=285638
* Fix for control endpoint handling in the DWC OTG driver. The dataHans Petter Selasky2015-06-021-56/+52
| | | | | | | | | | | stage processing is only allowed after the setup complete event has been received. Else a race may occur and the OUT data can be corrupted. While at it ensure resetting a FIFO has the required wait loop. MFC after: 3 days Notes: svn path=/head/; revision=283922
* Fix for DWC OTG device side isochronous transfers. The even or oddHans Petter Selasky2015-05-191-2/+31
| | | | | | | | | isochronous frame bit needs to be flipped. MFC after: 3 days Notes: svn path=/head/; revision=283103
* Make the FIFO configuration a bit more flexible for the DWC OTG inHans Petter Selasky2015-05-181-21/+18
| | | | | | | device side mode. Notes: svn path=/head/; revision=283067
* Disable multi process interrupts, because the current code doesn't useHans Petter Selasky2015-04-231-9/+7
| | | | | | | | | | them. Else we can end up in an infinite interrupt loop in USB device mode. MFC after: 3 days Notes: svn path=/head/; revision=281881
* Add support for the DWC OTG v2 chipset found in the STM32F4 series ofHans Petter Selasky2015-02-231-11/+40
| | | | | | | | | | processors. Make sure we pullup the data lines in device mode when we power on the port. MFC after: 1 week Notes: svn path=/head/; revision=279210
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-3/+2
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-2/+3
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Fix for USB specification compliance. We need to accept both DATA0 andHans Petter Selasky2014-06-071-0/+16
| | | | | | | | | DATA1 for INTERRUPT endpoints. MFC after: 3 days Notes: svn path=/head/; revision=267211
* Some further DWC OTG improvements for full speed and low speed devices:Hans Petter Selasky2014-06-071-80/+58
| | | | | | | | | | | | | | | | | | - Revert r265427. It appears we are halting the DWC OTG host controller schedule if we process events only at every SOF. When doing split transactions we rely on that events are processed quickly and waiting too long might cause data loss. - We are not always able to meet the timing requirements of interrupt endpoint split transactions. Switch from INTERRUPT to CONTROL endpoint type for interrupt endpoint events until further, hence CONTROL endpoint events are more relaxed, reducing the chance of data loss. See comment in code for more in-depth explanation. - Simplify TT scheduling. MFC after: 3 days Notes: svn path=/head/; revision=267210
* Try to fix DWC OTG regression issues with full and low speed devices:Hans Petter Selasky2014-06-051-225/+281
| | | | | | | | | | | | | | | | | | | | | | | | | | - Remove double buffering interrupt and isochronous traffic via the transaction translator. It can be avoided because the DWC OTG will always delay the start split transactions for interrupt and isochronous traffic, but will not delay the complete split transactions, if we set the odd frame bit correctly. - Need to check the transfer cache field in the device done function to be sure all allocated channels are freed and not the transfer first one. This seems to resolve the control endpoint transfer type quirk which is now removed. - Make sure any received data upon TX is dumped else RX path will stop. - Transmit isochronous data before receiving isochronous data as a means to optimise the TT schedule. - Implement a simple TT bandwidth scheduler. - Cleanup use of old "td->error" variable. - On interrupt IN traffic via the transaction translator we simply ignore missed transfer opportunities and silently retry the transaction upon next available time slot. MFC after: 3 days Notes: svn path=/head/; revision=267120
* The external USB HUB in the RPI-B rejects control endpoint trafficHans Petter Selasky2014-06-041-3/+12
| | | | | | | | | | using the BULK endpoint type, while other USB HUBs do not. Disable endpoint type workaround for TT traffic. MFC after: 3 days Notes: svn path=/head/; revision=267044
* Add some more spinlocks to protect the state of the USB transferHans Petter Selasky2014-05-291-27/+38
| | | | | | | | | queue. Rename some functions to indicate locking requirements. MFC after: 1 week Notes: svn path=/head/; revision=266833
* - Add softc pointer argument to FIFO functions as an optimisation.Hans Petter Selasky2014-05-181-112/+164
| | | | | | | | | | | - Implement support for interrupt filters in the DWC OTG driver, to reduce the amount of CPU task switching when only feeding the FIFOs. - Add common spinlock to the USB bus structure. MFC after: 2 weeks Notes: svn path=/head/; revision=266394
* Disable configuration of the host frame interval register untilHans Petter Selasky2014-05-141-0/+7
| | | | | | | further, hence it breaks USB support on some non-RPI platforms. Notes: svn path=/head/; revision=266012
* Optimise host mode data roundtrip time. When BULK data is submitted toHans Petter Selasky2014-05-111-25/+69
| | | | | | | | | | | | | the main processing queue, clear the NAK counter for any associated BULK or CONTROL transfers and poll the endpoint(s) for 1 millisecond at 125us rate interval, before going into slow, 10ms, NAK polling mode again. This has the effect that typical ping-ping protocols respond quicker when initiated from the USB host. MFC after: 2 weeks Notes: svn path=/head/; revision=265872
* Optimise host channel disabling:Hans Petter Selasky2014-05-101-38/+67
| | | | | | | | | | | | | | - For non-periodic traffic we only need to wait two SOFs before disabling the channel. - Make sure we release the TX FIFO tracking level after the host channel is disabled. - Make sure the host channel state gets reset/disabled initially. - Two minor code style changes. MFC after: 2 weeks Notes: svn path=/head/; revision=265806
* Fix a regression issue:Hans Petter Selasky2014-05-091-7/+7
| | | | | | | | | | | - ACK can be received before data arrives in RX FIFO. Handle this. - Remove obsolete comment. - Some minor code styling. MFC after: 2 weeks Notes: svn path=/head/; revision=265783
* Multiple DWC OTG host mode related fixes and improvements:Hans Petter Selasky2014-05-091-711/+580
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Rework how we allocate and free USB host channels, so that we only allocate a channel if there is a real packet going out on the USB cable. - Use BULK type for control data and status, due to instabilities in the HW it appears. - Split FIFO TX levels into one for the periodic FIFO and one for the non-periodic FIFO. - Use correct HFNUM mask when scheduling host transactions. The HFNUM register does not count the full 16-bit range. - Correct START/COMPLETION slot for TT transactions. For INTERRUPT and ISOCHRONOUS type transactions the hardware always respects the ODDFRM bit, which means we need to allocate multiple host channels when processing such endpoints, to not miss any so-called complete split opportunities. - When doing ISOCHRONOUS OUT transfers through a TT send all data payload in a single ALL-burst. This deacreases the likelyhood for isochronous data underruns. - Fixed unbalanced unlock in case of "dwc_otg_init_fifo()" failure. - Increase interrupt priority. MFC after: 2 weeks Notes: svn path=/head/; revision=265777
* Reduce the number of interrupts in USB host mode for the DWC OTGHans Petter Selasky2014-05-061-83/+145
| | | | | | | | | | | | | | | | | controller driver by piggybacking the SOF interrupt when issuing new and checking old transfers. Number of interrupts was reduced by 30% when doing Isochronous transfers. Use correct GINTMSK_XXX macros when accessing the DWC OTG interrupt mask register. Add code to adjust the frame interval register which influences the SOF rate. MFC after: 2 weeks Notes: svn path=/head/; revision=265427
* Improve DWC OTG USB host side support for isochronous FULL and HIGHHans Petter Selasky2014-05-051-253/+736
| | | | | | | | | | | | speed data traffic going directly to a USB device or through a so-called USB transaction translator. Add checks that we are not overusing the TX FIFO. MFC after: 2 weeks Notes: svn path=/head/; revision=265358
* Add support for specifying USB controller mode via FDT.Hans Petter Selasky2014-04-181-2/+7
| | | | | | | | | | | Add FDT support to the DWC OTG kernel module. Submitted by: John Wehle <john@feith.com> PR: usb/188683 MFC after: 1 week Notes: svn path=/head/; revision=264642
* USB method structures for USB controllers and USB pipes should beHans Petter Selasky2013-12-111-6/+6
| | | | | | | | constant and does not need to be modified. This also saves a small amount of RAM. Notes: svn path=/head/; revision=259218
* Bugfix: The endpoint profile should only be checked in device mode whenHans Petter Selasky2013-08-251-8/+12
| | | | | | | | | allocating USB transfers and not in host mode. Reported by: George Mitchell <george+freebsd@m5p.com> Notes: svn path=/head/; revision=254828
* Use string literals in string descriptors for marginallyHans Petter Selasky2013-01-301-4/+2
| | | | | | | | | better readability. Submitted by: Christoph Mallon Notes: svn path=/head/; revision=246125