mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-08 19:09:57 +00:00
Signed-off-by: popcornmix <popcornmix@gmail.com> usb: dwc: fix lockdep false positive Signed-off-by: Kari Suvanto <karis79@gmail.com> usb: dwc: fix inconsistent lock state Signed-off-by: Kari Suvanto <karis79@gmail.com> Add FIQ patch to dwc_otg driver. Enable with dwc_otg.fiq_fix_enable=1. Should give about 10% more ARM performance. Thanks to Gordon and Costas Avoid dynamic memory allocation for channel lock in USB driver. Thanks ddv2005. Add NAK holdoff scheme. Enabled by default, disable with dwc_otg.nak_holdoff_enable=0. Thanks gsh Make sure we wait for the reset to finish dwc_otg: fix bug in dwc_otg_hcd.c resulting in silent kernel memory corruption, escalating to OOPS under high USB load. dwc_otg: Fix unsafe access of QTD during URB enqueue In dwc_otg_hcd_urb_enqueue during qtd creation, it was possible that the transaction could complete almost immediately after the qtd was assigned to a host channel during URB enqueue, which meant the qtd pointer was no longer valid having been completed and removed. Usually, this resulted in an OOPS during URB submission. By predetermining whether transactions need to be queued or not, this unsafe pointer access is avoided. This bug was only evident on the Pi model A where a device was attached that had no periodic endpoints (e.g. USB pendrive or some wlan devices). dwc_otg: Fix incorrect URB allocation error handling If the memory allocation for a dwc_otg_urb failed, the kernel would OOPS because for some reason a member of the *unallocated* struct was set to zero. Error handling changed to fail correctly. dwc_otg: fix potential use-after-free case in interrupt handler If a transaction had previously aborted, certain interrupts are enabled to track error counts and reset where necessary. On IN endpoints the host generates an ACK interrupt near-simultaneously with completion of transfer. In the case where this transfer had previously had an error, this results in a use-after-free on the QTD memory space with a 1-byte length being overwritten to 0x00. dwc_otg: add handling of SPLIT transaction data toggle errors Previously a data toggle error on packets from a USB1.1 device behind a TT would result in the Pi locking up as the driver never handled the associated interrupt. Patch adds basic retry mechanism and interrupt acknowledgement to cater for either a chance toggle error or for devices that have a broken initial toggle state (FT8U232/FT232BM). dwc_otg: implement tasklet for returning URBs to usbcore hcd layer The dwc_otg driver interrupt handler for transfer completion will spend a very long time with interrupts disabled when a URB is completed - this is because usb_hcd_giveback_urb is called from within the handler which for a USB device driver with complicated processing (e.g. webcam) will take an exorbitant amount of time to complete. This results in missed completion interrupts for other USB packets which lead to them being dropped due to microframe overruns. This patch splits returning the URB to the usb hcd layer into a high-priority tasklet. This will have most benefit for isochronous IN transfers but will also have incidental benefit where multiple periodic devices are active at once. dwc_otg: fix NAK holdoff and allow on split transactions only This corrects a bug where if a single active non-periodic endpoint had at least one transaction in its qh, on frnum == MAX_FRNUM the qh would get skipped and never get queued again. This would result in a silent device until error detection (automatic or otherwise) would either reset the device or flush and requeue the URBs. Additionally the NAK holdoff was enabled for all transactions - this would potentially stall a HS endpoint for 1ms if a previous error state enabled this interrupt and the next response was a NAK. Fix so that only split transactions get held off. dwc_otg: Call usb_hcd_unlink_urb_from_ep with lock held in completion handler usb_hcd_unlink_urb_from_ep must be called with the HCD lock held. Calling it asynchronously in the tasklet was not safe (regression inc4564d4a1a). This change unlinks it from the endpoint prior to queueing it for handling in the tasklet, and also adds a check to ensure the urb is OK to be unlinked before doing so. NULL pointer dereference kernel oopses had been observed in usb_hcd_giveback_urb when a USB device was unplugged/replugged during data transfer. This effect was reproduced using automated USB port power control, hundreds of replug events were performed during active transfers to confirm that the problem was eliminated. USB fix using a FIQ to implement split transactions This commit adds a FIQ implementaion that schedules the split transactions using a FIQ so we don't get held off by the interrupt latency of Linux dwc_otg: fix device attributes and avoid kernel warnings on boot dcw_otg: avoid logging function that can cause panics See: https://github.com/raspberrypi/firmware/issues/21 Thanks to cleverca22 for fix dwc_otg: mask correct interrupts after transaction error recovery The dwc_otg driver will unmask certain interrupts on a transaction that previously halted in the error state in order to reset the QTD error count. The various fine-grained interrupt handlers do not consider that other interrupts besides themselves were unmasked. By disabling the two other interrupts only ever enabled in DMA mode for this purpose, we can avoid unnecessary function calls in the IRQ handler. This will also prevent an unneccesary FIQ interrupt from being generated if the FIQ is enabled. dwc_otg: fiq: prevent FIQ thrash and incorrect state passing to IRQ In the case of a transaction to a device that had previously aborted due to an error, several interrupts are enabled to reset the error count when a device responds. This has the side-effect of making the FIQ thrash because the hardware will generate multiple instances of a NAK on an IN bulk/interrupt endpoint and multiple instances of ACK on an OUT bulk/interrupt endpoint. Make the FIQ mask and clear the associated interrupts. Additionally, on non-split transactions make sure that only unmasked interrupts are cleared. This caused a hard-to-trigger but serious race condition when you had the combination of an endpoint awaiting error recovery and a transaction completed on an endpoint - due to the sequencing and timing of interrupts generated by the dwc_otg core, it was possible to confuse the IRQ handler. Fix function tracing dwc_otg: whitespace cleanup in dwc_otg_urb_enqueue dwc_otg: prevent OOPSes during device disconnects The dwc_otg_urb_enqueue function is thread-unsafe. In particular the access of urb->hcpriv, usb_hcd_link_urb_to_ep, dwc_otg_urb->qtd and friends does not occur within a critical section and so if a device was unplugged during activity there was a high chance that the usbcore hub_thread would try to disable the endpoint with partially- formed entries in the URB queue. This would result in BUG() or null pointer dereferences. Fix so that access of urb->hcpriv, enqueuing to the hardware and adding to usbcore endpoint URB lists is contained within a single critical section. dwc_otg: prevent BUG() in TT allocation if hub address is > 16 A fixed-size array is used to track TT allocation. This was previously set to 16 which caused a crash because dwc_otg_hcd_allocate_port would read past the end of the array. This was hit if a hub was plugged in which enumerated as addr > 16, due to previous device resets or unplugs. Also add #ifdef FIQ_DEBUG around hcd->hub_port_alloc[], which grows to a large size if 128 hub addresses are supported. This field is for debug only for tracking which frame an allocate happened in. dwc_otg: make channel halts with unknown state less damaging If the IRQ received a channel halt interrupt through the FIQ with no other bits set, the IRQ would not release the host channel and never complete the URB. Add catchall handling to treat as a transaction error and retry. dwc_otg: fiq_split: use TTs with more granularity This fixes certain issues with split transaction scheduling. - Isochronous multi-packet OUT transactions now hog the TT until they are completed - this prevents hubs aborting transactions if they get a periodic start-split out-of-order - Don't perform TT allocation on non-periodic endpoints - this allows simultaneous use of the TT's bulk/control and periodic transaction buffers This commit will mainly affect USB audio playback. dwc_otg: fix potential sleep while atomic during urb enqueue Fixes a regression introduced witheb1b482a. Kmalloc called from dwc_otg_hcd_qtd_add / dwc_otg_hcd_qtd_create did not always have the GPF_ATOMIC flag set. Force this flag when inside the larger critical section. dwc_otg: make fiq_split_enable imply fiq_fix_enable Failing to set up the FIQ correctly would result in "IRQ 32: nobody cared" errors in dmesg. dwc_otg: prevent crashes on host port disconnects Fix several issues resulting in crashes or inconsistent state if a Model A root port was disconnected. - Clean up queue heads properly in kill_urbs_in_qh_list by removing the empty QHs from the schedule lists - Set the halt status properly to prevent IRQ handlers from using freed memory - Add fiq_split related cleanup for saved registers - Make microframe scheduling reclaim host channels if active during a disconnect - Abort URBs with -ESHUTDOWN status response, informing device drivers so they respond in a more correct fashion and don't try to resubmit URBs - Prevent IRQ handlers from attempting to handle channel interrupts if the associated URB was dequeued (and the driver state was cleared) dwc_otg: prevent leaking URBs during enqueue A dwc_otg_urb would get leaked if the HCD enqueue function failed for any reason. Free the URB at the appropriate points. dwc_otg: Enable NAK holdoff for control split transactions Certain low-speed devices take a very long time to complete a data or status stage of a control transaction, producing NAK responses until they complete internal processing - the USB2.0 spec limit is up to 500mS. This causes the same type of interrupt storm as seen with USB-serial dongles prior toc8edb238. In certain circumstances, usually while booting, this interrupt storm could cause SD card timeouts. dwc_otg: Fix for occasional lockup on boot when doing a USB reset dwc_otg: Don't issue traffic to LS devices in FS mode Issuing low-speed packets when the root port is in full-speed mode causes the root port to stop responding. Explicitly fail when enqueuing URBs to a LS endpoint on a FS bus. Fix ARM architecture issue with local_irq_restore() If local_fiq_enable() is called before a local_irq_restore(flags) where the flags variable has the F bit set, the FIQ will be erroneously disabled. Fixup arch_local_irq_restore to avoid trampling the F bit in CPSR. Also fix some of the hacks previously implemented for previous dwc_otg incarnations. dwc_otg: fiq_fsm: Base commit for driver rewrite This commit removes the previous FIQ fixes entirely and adds fiq_fsm. This rewrite features much more complete support for split transactions and takes into account several OTG hardware bugs. High-speed isochronous transactions are also capable of being performed by fiq_fsm. All driver options have been removed and replaced with: - dwc_otg.fiq_enable (bool) - dwc_otg.fiq_fsm_enable (bool) - dwc_otg.fiq_fsm_mask (bitmask) - dwc_otg.nak_holdoff (unsigned int) Defaults are specified such that fiq_fsm behaves similarly to the previously implemented FIQ fixes. fiq_fsm: Push error recovery into the FIQ when fiq_fsm is used If the transfer associated with a QTD failed due to a bus error, the HCD would retry the transfer up to 3 times (implementing the USB2.0 three-strikes retry in software). Due to the masking mechanism used by fiq_fsm, it is only possible to pass a single interrupt through to the HCD per-transfer. In this instance host channels would fall off the radar because the error reset would function, but the subsequent channel halt would be lost. Push the error count reset into the FIQ handler. fiq_fsm: Implement timeout mechanism For full-speed endpoints with a large packet size, interrupt latency runs the risk of the FIQ starting a transaction too late in a full-speed frame. If the device is still transmitting data when EOF2 for the downstream frame occurs, the hub will disable the port. This change is not reflected in the hub status endpoint and the device becomes unresponsive. Prevent high-bandwidth transactions from being started too late in a frame. The mechanism is not guaranteed: a combination of bit stuffing and hub latency may still result in a device overrunning. fiq_fsm: fix bounce buffer utilisation for Isochronous OUT Multi-packet isochronous OUT transactions were subject to a few bounday bugs. Fix them. Audio playback is now much more robust: however, an issue stands with devices that have adaptive sinks - ALSA plays samples too fast. dwc_otg: Return full-speed frame numbers in HS mode The frame counter increments on every *microframe* in high-speed mode. Most device drivers expect this number to be in full-speed frames - this caused considerable confusion to e.g. snd_usb_audio which uses the frame counter to estimate the number of samples played. fiq_fsm: save PID on completion of interrupt OUT transfers Also add edge case handling for interrupt transports. Note that for periodic split IN, data toggles are unimplemented in the OTG host hardware - it unconditionally accepts any PID. fiq_fsm: add missing case for fiq_fsm_tt_in_use() Certain combinations of bitrate and endpoint activity could result in a periodic transaction erroneously getting started while the previous Isochronous OUT was still active. fiq_fsm: clear hcintmsk for aborted transactions Prevents the FIQ from erroneously handling interrupts on a timed out channel. fiq_fsm: enable by default fiq_fsm: fix dequeues for non-periodic split transactions If a dequeue happened between the SSPLIT and CSPLIT phases of the transaction, the HCD would never receive an interrupt. fiq_fsm: Disable by default fiq_fsm: Handle HC babble errors The HCTSIZ transfer size field raises a babble interrupt if the counter wraps. Handle the resulting interrupt in this case. dwc_otg: fix interrupt registration for fiq_enable=0 Additionally make the module parameter conditional for wherever hcd->fiq_state is touched. fiq_fsm: Enable by default dwc_otg: Fix various issues with root port and transaction errors Process the host port interrupts correctly (and don't trample them). Root port hotplug now functional again. Fix a few thinkos with the transaction error passthrough for fiq_fsm. fiq_fsm: Implement hack for Split Interrupt transactions Hubs aren't too picky about which endpoint we send Control type split transactions to. By treating Interrupt transfers as Control, it is possible to use the non-periodic queue in the OTG core as well as the non-periodic FIFOs in the hub itself. This massively reduces the microframe exclusivity/contention that periodic split transactions otherwise have to enforce. It goes without saying that this is a fairly egregious USB specification violation, but it works. Original idea by Hans Petter Selasky @ FreeBSD.org. dwc_otg: FIQ support on SMP. Set up FIQ stack and handler on Core 0 only. dwc_otg: introduce fiq_fsm_spin(un|)lock() SMP safety for the FIQ relies on register read-modify write cycles being completed in the correct order. Several places in the DWC code modify registers also touched by the FIQ. Protect these by a bare-bones lock mechanism. This also makes it possible to run the FIQ and IRQ handlers on different cores. fiq_fsm: fix build on bcm2708 and bcm2709 platforms dwc_otg: put some barriers back where they should be for UP bcm2709/dwc_otg: Setup FIQ on core 1 if >1 core active dwc_otg: fixup read-modify-write in critical paths Be more careful about read-modify-write on registers that the FIQ also touches. Guard fiq_fsm_spin_lock with fiq_enable check fiq_fsm: Falling out of the state machine isn't fatal This edge case can be hit if the port is disabled while the FIQ is in the middle of a transaction. Make the effects less severe. Also get rid of the useless return value. squash: dwc_otg: Allow to build without SMP usb: core: make overcurrent messages more prominent Hub overcurrent messages are more serious than "debug". Increase loglevel. usb: dwc_otg: Don't use dma_to_virt() Commit6ce0d20changes dma_to_virt() which breaks this driver. Open code the old dma_to_virt() implementation to work around this. Limit the use of __bus_to_virt() to cases where transfer_buffer_length is set and transfer_buffer is not set. This is done to increase the chance that this driver will also work on ARCH_BCM2835. transfer_buffer should not be NULL if the length is set, but the comment in the code indicates that there are situations where this might happen. drivers/usb/isp1760/isp1760-hcd.c also has a similar comment pointing to a possible: 'usb storage / SCSI bug'. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> dwc_otg: Fix crash when fiq_enable=0 dwc_otg: fiq_fsm: Make high-speed isochronous strided transfers work properly Certain low-bandwidth high-speed USB devices (specialist audio devices, compressed-frame webcams) have packet intervals > 1 microframe. Stride these transfers in the FIQ by using the start-of-frame interrupt to restart the channel at the right time. dwc_otg: Force host mode to fix incorrect compute module boards dwc_otg: Add ARCH_BCM2835 support Signed-off-by: Noralf Trønnes <noralf@tronnes.org> dwc_otg: Simplify FIQ irq number code Dropping ATAGS means we can simplify the FIQ irq number code. Also add error checking on the returned irq number. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> dwc_otg: Remove duplicate gadget probe/unregister function dwc_otg: Properly set the HFIR Douglas Anderson reported: According to the most up to date version of the dwc2 databook, the FRINT field of the HFIR register should be programmed to: * 125 us * (PHY clock freq for HS) - 1 * 1000 us * (PHY clock freq for FS/LS) - 1 This is opposed to older versions of the doc that claimed it should be: * 125 us * (PHY clock freq for HS) * 1000 us * (PHY clock freq for FS/LS) and reported lower timing jitter on a USB analyser dcw_otg: trim xfer length when buffer larger than allocated size is received dwc_otg: Don't free qh align buffers in atomic context dwc_otg: Enable the hack for Split Interrupt transactions by default dwc_otg.fiq_fsm_mask=0xF has long been a suggestion for users with audio stutters or other USB bandwidth issues. So far we are aware of many success stories but no failure caused by this setting. Make it a default to learn more. See: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=70437 Signed-off-by: popcornmix <popcornmix@gmail.com> dwc_otg: Use kzalloc when suitable dwc_otg: Pass struct device to dma_alloc*() This makes it possible to get the bus address from Device Tree. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> dwc_otg: fix summarize urb->actual_length for isochronous transfers Kernel does not copy input data of ISO transfers to userspace if actual_length is set only in ISO transfers and not summarized in urb->actual_length. Fixes raspberrypi/linux#903 fiq_fsm: Use correct states when starting isoc OUT transfers In fiq_fsm_start_next_periodic() if an isochronous OUT transfer was selected, no regard was given as to whether this was a single-packet transfer or a multi-packet staged transfer. For single-packet transfers, this had the effect of repeatedly sending OUT packets with bogus data and lengths. Eventually if the channel was repeatedly enabled enough times, this would lock up the OTG core and no further bus transfers would happen. Set the FSM state up properly if we select a single-packet transfer. Fixes https://github.com/raspberrypi/linux/issues/1842 dwc_otg: make nak_holdoff work as intended with empty queues If URBs reading from non-periodic split endpoints were dequeued and the last transfer from the endpoint was a NAK handshake, the resulting qh->nak_frame value was stale which would result in unnecessarily long polling intervals for the first subsequent transfer with a fresh URB. Fixup qh->nak_frame in dwc_otg_hcd_urb_dequeue and also guard against a case where a single URB is submitted to the endpoint, a NAK was received on the transfer immediately prior to receiving data and the device subsequently resubmits another URB past the qh->nak_frame interval. Fixes https://github.com/raspberrypi/linux/issues/1709 dwc_otg: fix split transaction data toggle handling around dequeues See https://github.com/raspberrypi/linux/issues/1709 Fix several issues regarding endpoint state when URBs are dequeued - If the HCD is disconnected, flush FIQ-enabled channels properly - Save the data toggle state for bulk endpoints if the last transfer from an endpoint where URBs were dequeued returned a data packet - Reset hc->start_pkt_count properly in assign_and_init_hc() dwc_otg: fix several potential crash sources On root port disconnect events, the host driver state is cleared and in-progress host channels are forcibly stopped. This doesn't play well with the FIQ running in the background, so: - Guard the disconnect callback with both the host spinlock and FIQ spinlock - Move qtd dereference in dwc_otg_handle_hc_fsm() after the early-out so we don't dereference a qtd that has gone away - Turn catch-all BUG()s in dwc_otg_handle_hc_fsm() into warnings. dwc_otg: delete hcd->channel_lock The lock serves no purpose as it is only held while the HCD spinlock is already being held. dwc_otg: remove unnecessary dma-mode channel halts on disconnect interrupt Host channels are already halted in kill_urbs_in_qh_list() with the subsequent interrupt processing behaving as if the URB was dequeued via HCD callback. There's no need to clobber the host channel registers a second time as this exposes races between the driver and host channel resulting in hcd->free_hc_list becoming corrupted. dwcotg: Allow to build without FIQ on ARM64 Signed-off-by: popcornmix <popcornmix@gmail.com> dwc_otg: make periodic scheduling behave properly for FS buses If the root port is in full-speed mode, transfer times at 12mbit/s would be calculated but matched against high-speed quotas. Reinitialise hcd->frame_usecs[i] on each port enable event so that full-speed bandwidth can be tracked sensibly. Also, don't bother using the FIQ for transfers when in full-speed mode - at the slower bus speed, interrupt frequency is reduced by an order of magnitude. Related issue: https://github.com/raspberrypi/linux/issues/2020 dwc_otg: fiq_fsm: Make isochronous compatibility checks work properly Get rid of the spammy printk and local pointer mangling. Also, there is a nominal benefit for using fiq_fsm for isochronous transfers in FS mode (~1.1k IRQs per second vs 2.1k IRQs per second) so remove the root port speed check. dwc_otg: add module parameter int_ep_interval_min Add a module parameter (defaulting to ignored) that clamps the polling rate of high-speed Interrupt endpoints to a minimum microframe interval. The parameter is modifiable at runtime as it is used when activating new endpoints (such as on device connect). dwc_otg: fiq_fsm: Add non-periodic TT exclusivity constraints Certain hub types do not discriminate between pipe direction (IN or OUT) when considering non-periodic transfers. Therefore these hubs get confused if multiple transfers are issued in different directions with the same device address and endpoint number. Constrain queuing non-periodic split transactions so they are performed serially in such cases. Related: https://github.com/raspberrypi/linux/issues/2024 dwc_otg: Fixup change to DRIVER_ATTR interface dwc_otg: Fix compilation warnings Signed-off-by: Phil Elwell <phil@raspberrypi.org> USB_DWCOTG: Disable building dwc_otg as a module (#2265) When dwc_otg is built as a module, build will fail with the following error: ERROR: "DWC_TASK_HI_SCHEDULE" [drivers/usb/host/dwc_otg/dwc_otg.ko] undefined! scripts/Makefile.modpost:91: recipe for target '__modpost' failed make[1]: *** [__modpost] Error 1 Makefile:1199: recipe for target 'modules' failed make: *** [modules] Error 2 Even if the error is solved by including the missing DWC_TASK_HI_SCHEDULE function, the kernel will panic when loading dwc_otg. As a workaround, simply prevent user from building dwc_otg as a module as the current kernel does not support it. See: https://github.com/raspberrypi/linux/issues/2258 Signed-off-by: Malik Olivier Boussejra <malik@boussejra.com> dwc_otg: New timer API dwc_otg: Fix removed ACCESS_ONCE->READ_ONCE dwc_otg: don't unconditionally force host mode in dwc_otg_cil_init() Add the ability to disable force_host_mode for those that want to use dwc_otg in both device and host modes. dwc_otg: Fix a regression when dequeueing isochronous transfers In282bed95(dwc_otg: make nak_holdoff work as intended with empty queues) the dequeue mechanism was changed to leave FIQ-enabled transfers to run to completion - to avoid leaving hub TT buffers with stale packets lying around. This broke FIQ-accelerated isochronous transfers, as this then meant that dozens of transfers were performed after the dequeue function returned. Restore the state machine fence for isochronous transfers. fiq_fsm: rewind DMA pointer for OUT transactions that fail (#2288) See: https://github.com/raspberrypi/linux/issues/2140 dwc_otg: add smp_mb() to prevent driver state corruption on boot Occasional crashes have been seen where the FIQ code dereferences invalid/random pointers immediately after being set up, leading to panic on boot. The crash occurs as the FIQ code races against hcd_init_fiq() and the hcd_init_fiq() code races against the outstanding memory stores from dwc_otg_hcd_init(). Use explicit barriers after touching driver state. usb: dwc_otg: fix memory corruption in dwc_otg driver [Upstream commit51b1b64917] The move from the staging tree to the main tree exposed a longstanding memory corruption bug in the dwc2 driver. The reordering of the driver initialization caused the dwc2 driver to corrupt the initialization data of the sdhci driver on the Raspberry Pi platform, which made the bug show up. The error is in calling to_usb_device(hsotg->dev), since ->dev is not a member of struct usb_device. The easiest fix is to just remove the offending code, since it is not really needed. Thanks to Stephen Warren for tracking down the cause of this. Reported-by: Andre Heider <a.heider@gmail.com> Tested-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [lukas: port from upstream dwc2 to out-of-tree dwc_otg driver] Signed-off-by: Lukas Wunner <lukas@wunner.de> usb: dwb_otg: Fix unreachable switch statement warning This warning appears with GCC 7.3.0 from toolchains.bootlin.com: ../drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c: In function ‘fiq_fsm_update_hs_isoc’: ../drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c:595:61: warning: statement will never be executed [-Wswitch-unreachable] st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps; ~~~~~~~~~~~~~~~~~^~~~ Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> dwc_otg: fiq_fsm: fix incorrect DMA register offset calculation Rationalise the offset and update all call sites. Fixes https://github.com/raspberrypi/linux/issues/2408
2348 lines
70 KiB
C
2348 lines
70 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* message.c - synchronous message handling
|
|
*
|
|
* Released under the GPLv2 only.
|
|
*/
|
|
|
|
#include <linux/pci.h> /* for scatterlist macros */
|
|
#include <linux/usb.h>
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/nls.h>
|
|
#include <linux/device.h>
|
|
#include <linux/scatterlist.h>
|
|
#include <linux/usb/cdc.h>
|
|
#include <linux/usb/quirks.h>
|
|
#include <linux/usb/hcd.h> /* for usbcore internals */
|
|
#include <linux/usb/of.h>
|
|
#include <asm/byteorder.h>
|
|
|
|
#include "usb.h"
|
|
|
|
static void cancel_async_set_config(struct usb_device *udev);
|
|
|
|
struct api_context {
|
|
struct completion done;
|
|
int status;
|
|
};
|
|
|
|
static void usb_api_blocking_completion(struct urb *urb)
|
|
{
|
|
struct api_context *ctx = urb->context;
|
|
|
|
ctx->status = urb->status;
|
|
complete(&ctx->done);
|
|
}
|
|
|
|
|
|
/*
|
|
* Starts urb and waits for completion or timeout. Note that this call
|
|
* is NOT interruptible. Many device driver i/o requests should be
|
|
* interruptible and therefore these drivers should implement their
|
|
* own interruptible routines.
|
|
*/
|
|
static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
|
|
{
|
|
struct api_context ctx;
|
|
unsigned long expire;
|
|
int retval;
|
|
|
|
init_completion(&ctx.done);
|
|
urb->context = &ctx;
|
|
urb->actual_length = 0;
|
|
retval = usb_submit_urb(urb, GFP_NOIO);
|
|
if (unlikely(retval))
|
|
goto out;
|
|
|
|
expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT;
|
|
if (!wait_for_completion_timeout(&ctx.done, expire)) {
|
|
usb_kill_urb(urb);
|
|
retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status);
|
|
|
|
dev_dbg(&urb->dev->dev,
|
|
"%s timed out on ep%d%s len=%u/%u\n",
|
|
current->comm,
|
|
usb_endpoint_num(&urb->ep->desc),
|
|
usb_urb_dir_in(urb) ? "in" : "out",
|
|
urb->actual_length,
|
|
urb->transfer_buffer_length);
|
|
} else
|
|
retval = ctx.status;
|
|
out:
|
|
if (actual_length)
|
|
*actual_length = urb->actual_length;
|
|
|
|
usb_free_urb(urb);
|
|
return retval;
|
|
}
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
/* returns status (negative) or length (positive) */
|
|
static int usb_internal_control_msg(struct usb_device *usb_dev,
|
|
unsigned int pipe,
|
|
struct usb_ctrlrequest *cmd,
|
|
void *data, int len, int timeout)
|
|
{
|
|
struct urb *urb;
|
|
int retv;
|
|
int length;
|
|
|
|
urb = usb_alloc_urb(0, GFP_NOIO);
|
|
if (!urb)
|
|
return -ENOMEM;
|
|
|
|
usb_fill_control_urb(urb, usb_dev, pipe, (unsigned char *)cmd, data,
|
|
len, usb_api_blocking_completion, NULL);
|
|
|
|
retv = usb_start_wait_urb(urb, timeout, &length);
|
|
if (retv < 0)
|
|
return retv;
|
|
else
|
|
return length;
|
|
}
|
|
|
|
/**
|
|
* usb_control_msg - Builds a control urb, sends it off and waits for completion
|
|
* @dev: pointer to the usb device to send the message to
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
* @request: USB message request value
|
|
* @requesttype: USB message request type value
|
|
* @value: USB message value
|
|
* @index: USB message index value
|
|
* @data: pointer to the data to send
|
|
* @size: length in bytes of the data to send
|
|
* @timeout: time in msecs to wait for the message to complete before timing
|
|
* out (if 0 the wait is forever)
|
|
*
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This function sends a simple control message to a specified endpoint and
|
|
* waits for the message to complete, or timeout.
|
|
*
|
|
* Don't use this function from within an interrupt context. If you need
|
|
* an asynchronous message, or need to send a message from within interrupt
|
|
* context, use usb_submit_urb(). If a thread in your driver uses this call,
|
|
* make sure your disconnect() method can wait for it to complete. Since you
|
|
* don't have a handle on the URB used, you can't cancel the request.
|
|
*
|
|
* Return: If successful, the number of bytes transferred. Otherwise, a negative
|
|
* error number.
|
|
*/
|
|
int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
|
|
__u8 requesttype, __u16 value, __u16 index, void *data,
|
|
__u16 size, int timeout)
|
|
{
|
|
struct usb_ctrlrequest *dr;
|
|
int ret;
|
|
|
|
dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO);
|
|
if (!dr)
|
|
return -ENOMEM;
|
|
|
|
dr->bRequestType = requesttype;
|
|
dr->bRequest = request;
|
|
dr->wValue = cpu_to_le16(value);
|
|
dr->wIndex = cpu_to_le16(index);
|
|
dr->wLength = cpu_to_le16(size);
|
|
|
|
ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
|
|
|
|
/* Linger a bit, prior to the next control message. */
|
|
if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
|
|
msleep(200);
|
|
|
|
kfree(dr);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_control_msg);
|
|
|
|
/**
|
|
* usb_interrupt_msg - Builds an interrupt urb, sends it off and waits for completion
|
|
* @usb_dev: pointer to the usb device to send the message to
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
* @data: pointer to the data to send
|
|
* @len: length in bytes of the data to send
|
|
* @actual_length: pointer to a location to put the actual length transferred
|
|
* in bytes
|
|
* @timeout: time in msecs to wait for the message to complete before
|
|
* timing out (if 0 the wait is forever)
|
|
*
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This function sends a simple interrupt message to a specified endpoint and
|
|
* waits for the message to complete, or timeout.
|
|
*
|
|
* Don't use this function from within an interrupt context. If you need
|
|
* an asynchronous message, or need to send a message from within interrupt
|
|
* context, use usb_submit_urb() If a thread in your driver uses this call,
|
|
* make sure your disconnect() method can wait for it to complete. Since you
|
|
* don't have a handle on the URB used, you can't cancel the request.
|
|
*
|
|
* Return:
|
|
* If successful, 0. Otherwise a negative error number. The number of actual
|
|
* bytes transferred will be stored in the @actual_length parameter.
|
|
*/
|
|
int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
|
|
void *data, int len, int *actual_length, int timeout)
|
|
{
|
|
return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_interrupt_msg);
|
|
|
|
/**
|
|
* usb_bulk_msg - Builds a bulk urb, sends it off and waits for completion
|
|
* @usb_dev: pointer to the usb device to send the message to
|
|
* @pipe: endpoint "pipe" to send the message to
|
|
* @data: pointer to the data to send
|
|
* @len: length in bytes of the data to send
|
|
* @actual_length: pointer to a location to put the actual length transferred
|
|
* in bytes
|
|
* @timeout: time in msecs to wait for the message to complete before
|
|
* timing out (if 0 the wait is forever)
|
|
*
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This function sends a simple bulk message to a specified endpoint
|
|
* and waits for the message to complete, or timeout.
|
|
*
|
|
* Don't use this function from within an interrupt context. If you need
|
|
* an asynchronous message, or need to send a message from within interrupt
|
|
* context, use usb_submit_urb() If a thread in your driver uses this call,
|
|
* make sure your disconnect() method can wait for it to complete. Since you
|
|
* don't have a handle on the URB used, you can't cancel the request.
|
|
*
|
|
* Because there is no usb_interrupt_msg() and no USBDEVFS_INTERRUPT ioctl,
|
|
* users are forced to abuse this routine by using it to submit URBs for
|
|
* interrupt endpoints. We will take the liberty of creating an interrupt URB
|
|
* (with the default interval) if the target is an interrupt endpoint.
|
|
*
|
|
* Return:
|
|
* If successful, 0. Otherwise a negative error number. The number of actual
|
|
* bytes transferred will be stored in the @actual_length parameter.
|
|
*
|
|
*/
|
|
int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
|
|
void *data, int len, int *actual_length, int timeout)
|
|
{
|
|
struct urb *urb;
|
|
struct usb_host_endpoint *ep;
|
|
|
|
ep = usb_pipe_endpoint(usb_dev, pipe);
|
|
if (!ep || len < 0)
|
|
return -EINVAL;
|
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
if (!urb)
|
|
return -ENOMEM;
|
|
|
|
if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
|
|
USB_ENDPOINT_XFER_INT) {
|
|
pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30);
|
|
usb_fill_int_urb(urb, usb_dev, pipe, data, len,
|
|
usb_api_blocking_completion, NULL,
|
|
ep->desc.bInterval);
|
|
} else
|
|
usb_fill_bulk_urb(urb, usb_dev, pipe, data, len,
|
|
usb_api_blocking_completion, NULL);
|
|
|
|
return usb_start_wait_urb(urb, timeout, actual_length);
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_bulk_msg);
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
static void sg_clean(struct usb_sg_request *io)
|
|
{
|
|
if (io->urbs) {
|
|
while (io->entries--)
|
|
usb_free_urb(io->urbs[io->entries]);
|
|
kfree(io->urbs);
|
|
io->urbs = NULL;
|
|
}
|
|
io->dev = NULL;
|
|
}
|
|
|
|
static void sg_complete(struct urb *urb)
|
|
{
|
|
unsigned long flags;
|
|
struct usb_sg_request *io = urb->context;
|
|
int status = urb->status;
|
|
|
|
spin_lock_irqsave(&io->lock, flags);
|
|
|
|
/* In 2.5 we require hcds' endpoint queues not to progress after fault
|
|
* reports, until the completion callback (this!) returns. That lets
|
|
* device driver code (like this routine) unlink queued urbs first,
|
|
* if it needs to, since the HC won't work on them at all. So it's
|
|
* not possible for page N+1 to overwrite page N, and so on.
|
|
*
|
|
* That's only for "hard" faults; "soft" faults (unlinks) sometimes
|
|
* complete before the HCD can get requests away from hardware,
|
|
* though never during cleanup after a hard fault.
|
|
*/
|
|
if (io->status
|
|
&& (io->status != -ECONNRESET
|
|
|| status != -ECONNRESET)
|
|
&& urb->actual_length) {
|
|
dev_err(io->dev->bus->controller,
|
|
"dev %s ep%d%s scatterlist error %d/%d\n",
|
|
io->dev->devpath,
|
|
usb_endpoint_num(&urb->ep->desc),
|
|
usb_urb_dir_in(urb) ? "in" : "out",
|
|
status, io->status);
|
|
/* BUG (); */
|
|
}
|
|
|
|
if (io->status == 0 && status && status != -ECONNRESET) {
|
|
int i, found, retval;
|
|
|
|
io->status = status;
|
|
|
|
/* the previous urbs, and this one, completed already.
|
|
* unlink pending urbs so they won't rx/tx bad data.
|
|
* careful: unlink can sometimes be synchronous...
|
|
*/
|
|
spin_unlock_irqrestore(&io->lock, flags);
|
|
for (i = 0, found = 0; i < io->entries; i++) {
|
|
if (!io->urbs[i])
|
|
continue;
|
|
if (found) {
|
|
usb_block_urb(io->urbs[i]);
|
|
retval = usb_unlink_urb(io->urbs[i]);
|
|
if (retval != -EINPROGRESS &&
|
|
retval != -ENODEV &&
|
|
retval != -EBUSY &&
|
|
retval != -EIDRM)
|
|
dev_err(&io->dev->dev,
|
|
"%s, unlink --> %d\n",
|
|
__func__, retval);
|
|
} else if (urb == io->urbs[i])
|
|
found = 1;
|
|
}
|
|
spin_lock_irqsave(&io->lock, flags);
|
|
}
|
|
|
|
/* on the last completion, signal usb_sg_wait() */
|
|
io->bytes += urb->actual_length;
|
|
io->count--;
|
|
if (!io->count)
|
|
complete(&io->complete);
|
|
|
|
spin_unlock_irqrestore(&io->lock, flags);
|
|
}
|
|
|
|
|
|
/**
|
|
* usb_sg_init - initializes scatterlist-based bulk/interrupt I/O request
|
|
* @io: request block being initialized. until usb_sg_wait() returns,
|
|
* treat this as a pointer to an opaque block of memory,
|
|
* @dev: the usb device that will send or receive the data
|
|
* @pipe: endpoint "pipe" used to transfer the data
|
|
* @period: polling rate for interrupt endpoints, in frames or
|
|
* (for high speed endpoints) microframes; ignored for bulk
|
|
* @sg: scatterlist entries
|
|
* @nents: how many entries in the scatterlist
|
|
* @length: how many bytes to send from the scatterlist, or zero to
|
|
* send every byte identified in the list.
|
|
* @mem_flags: SLAB_* flags affecting memory allocations in this call
|
|
*
|
|
* This initializes a scatter/gather request, allocating resources such as
|
|
* I/O mappings and urb memory (except maybe memory used by USB controller
|
|
* drivers).
|
|
*
|
|
* The request must be issued using usb_sg_wait(), which waits for the I/O to
|
|
* complete (or to be canceled) and then cleans up all resources allocated by
|
|
* usb_sg_init().
|
|
*
|
|
* The request may be canceled with usb_sg_cancel(), either before or after
|
|
* usb_sg_wait() is called.
|
|
*
|
|
* Return: Zero for success, else a negative errno value.
|
|
*/
|
|
int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
|
|
unsigned pipe, unsigned period, struct scatterlist *sg,
|
|
int nents, size_t length, gfp_t mem_flags)
|
|
{
|
|
int i;
|
|
int urb_flags;
|
|
int use_sg;
|
|
|
|
if (!io || !dev || !sg
|
|
|| usb_pipecontrol(pipe)
|
|
|| usb_pipeisoc(pipe)
|
|
|| nents <= 0)
|
|
return -EINVAL;
|
|
|
|
spin_lock_init(&io->lock);
|
|
io->dev = dev;
|
|
io->pipe = pipe;
|
|
|
|
if (dev->bus->sg_tablesize > 0) {
|
|
use_sg = true;
|
|
io->entries = 1;
|
|
} else {
|
|
use_sg = false;
|
|
io->entries = nents;
|
|
}
|
|
|
|
/* initialize all the urbs we'll use */
|
|
io->urbs = kmalloc_array(io->entries, sizeof(*io->urbs), mem_flags);
|
|
if (!io->urbs)
|
|
goto nomem;
|
|
|
|
urb_flags = URB_NO_INTERRUPT;
|
|
if (usb_pipein(pipe))
|
|
urb_flags |= URB_SHORT_NOT_OK;
|
|
|
|
for_each_sg(sg, sg, io->entries, i) {
|
|
struct urb *urb;
|
|
unsigned len;
|
|
|
|
urb = usb_alloc_urb(0, mem_flags);
|
|
if (!urb) {
|
|
io->entries = i;
|
|
goto nomem;
|
|
}
|
|
io->urbs[i] = urb;
|
|
|
|
urb->dev = NULL;
|
|
urb->pipe = pipe;
|
|
urb->interval = period;
|
|
urb->transfer_flags = urb_flags;
|
|
urb->complete = sg_complete;
|
|
urb->context = io;
|
|
urb->sg = sg;
|
|
|
|
if (use_sg) {
|
|
/* There is no single transfer buffer */
|
|
urb->transfer_buffer = NULL;
|
|
urb->num_sgs = nents;
|
|
|
|
/* A length of zero means transfer the whole sg list */
|
|
len = length;
|
|
if (len == 0) {
|
|
struct scatterlist *sg2;
|
|
int j;
|
|
|
|
for_each_sg(sg, sg2, nents, j)
|
|
len += sg2->length;
|
|
}
|
|
} else {
|
|
/*
|
|
* Some systems can't use DMA; they use PIO instead.
|
|
* For their sakes, transfer_buffer is set whenever
|
|
* possible.
|
|
*/
|
|
if (!PageHighMem(sg_page(sg)))
|
|
urb->transfer_buffer = sg_virt(sg);
|
|
else
|
|
urb->transfer_buffer = NULL;
|
|
|
|
len = sg->length;
|
|
if (length) {
|
|
len = min_t(size_t, len, length);
|
|
length -= len;
|
|
if (length == 0)
|
|
io->entries = i + 1;
|
|
}
|
|
}
|
|
urb->transfer_buffer_length = len;
|
|
}
|
|
io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
|
|
|
|
/* transaction state */
|
|
io->count = io->entries;
|
|
io->status = 0;
|
|
io->bytes = 0;
|
|
init_completion(&io->complete);
|
|
return 0;
|
|
|
|
nomem:
|
|
sg_clean(io);
|
|
return -ENOMEM;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_sg_init);
|
|
|
|
/**
|
|
* usb_sg_wait - synchronously execute scatter/gather request
|
|
* @io: request block handle, as initialized with usb_sg_init().
|
|
* some fields become accessible when this call returns.
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This function blocks until the specified I/O operation completes. It
|
|
* leverages the grouping of the related I/O requests to get good transfer
|
|
* rates, by queueing the requests. At higher speeds, such queuing can
|
|
* significantly improve USB throughput.
|
|
*
|
|
* There are three kinds of completion for this function.
|
|
*
|
|
* (1) success, where io->status is zero. The number of io->bytes
|
|
* transferred is as requested.
|
|
* (2) error, where io->status is a negative errno value. The number
|
|
* of io->bytes transferred before the error is usually less
|
|
* than requested, and can be nonzero.
|
|
* (3) cancellation, a type of error with status -ECONNRESET that
|
|
* is initiated by usb_sg_cancel().
|
|
*
|
|
* When this function returns, all memory allocated through usb_sg_init() or
|
|
* this call will have been freed. The request block parameter may still be
|
|
* passed to usb_sg_cancel(), or it may be freed. It could also be
|
|
* reinitialized and then reused.
|
|
*
|
|
* Data Transfer Rates:
|
|
*
|
|
* Bulk transfers are valid for full or high speed endpoints.
|
|
* The best full speed data rate is 19 packets of 64 bytes each
|
|
* per frame, or 1216 bytes per millisecond.
|
|
* The best high speed data rate is 13 packets of 512 bytes each
|
|
* per microframe, or 52 KBytes per millisecond.
|
|
*
|
|
* The reason to use interrupt transfers through this API would most likely
|
|
* be to reserve high speed bandwidth, where up to 24 KBytes per millisecond
|
|
* could be transferred. That capability is less useful for low or full
|
|
* speed interrupt endpoints, which allow at most one packet per millisecond,
|
|
* of at most 8 or 64 bytes (respectively).
|
|
*
|
|
* It is not necessary to call this function to reserve bandwidth for devices
|
|
* under an xHCI host controller, as the bandwidth is reserved when the
|
|
* configuration or interface alt setting is selected.
|
|
*/
|
|
void usb_sg_wait(struct usb_sg_request *io)
|
|
{
|
|
int i;
|
|
int entries = io->entries;
|
|
|
|
/* queue the urbs. */
|
|
spin_lock_irq(&io->lock);
|
|
i = 0;
|
|
while (i < entries && !io->status) {
|
|
int retval;
|
|
|
|
io->urbs[i]->dev = io->dev;
|
|
spin_unlock_irq(&io->lock);
|
|
|
|
retval = usb_submit_urb(io->urbs[i], GFP_NOIO);
|
|
|
|
switch (retval) {
|
|
/* maybe we retrying will recover */
|
|
case -ENXIO: /* hc didn't queue this one */
|
|
case -EAGAIN:
|
|
case -ENOMEM:
|
|
retval = 0;
|
|
yield();
|
|
break;
|
|
|
|
/* no error? continue immediately.
|
|
*
|
|
* NOTE: to work better with UHCI (4K I/O buffer may
|
|
* need 3K of TDs) it may be good to limit how many
|
|
* URBs are queued at once; N milliseconds?
|
|
*/
|
|
case 0:
|
|
++i;
|
|
cpu_relax();
|
|
break;
|
|
|
|
/* fail any uncompleted urbs */
|
|
default:
|
|
io->urbs[i]->status = retval;
|
|
dev_dbg(&io->dev->dev, "%s, submit --> %d\n",
|
|
__func__, retval);
|
|
usb_sg_cancel(io);
|
|
}
|
|
spin_lock_irq(&io->lock);
|
|
if (retval && (io->status == 0 || io->status == -ECONNRESET))
|
|
io->status = retval;
|
|
}
|
|
io->count -= entries - i;
|
|
if (io->count == 0)
|
|
complete(&io->complete);
|
|
spin_unlock_irq(&io->lock);
|
|
|
|
/* OK, yes, this could be packaged as non-blocking.
|
|
* So could the submit loop above ... but it's easier to
|
|
* solve neither problem than to solve both!
|
|
*/
|
|
wait_for_completion(&io->complete);
|
|
|
|
sg_clean(io);
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_sg_wait);
|
|
|
|
/**
|
|
* usb_sg_cancel - stop scatter/gather i/o issued by usb_sg_wait()
|
|
* @io: request block, initialized with usb_sg_init()
|
|
*
|
|
* This stops a request after it has been started by usb_sg_wait().
|
|
* It can also prevents one initialized by usb_sg_init() from starting,
|
|
* so that call just frees resources allocated to the request.
|
|
*/
|
|
void usb_sg_cancel(struct usb_sg_request *io)
|
|
{
|
|
unsigned long flags;
|
|
int i, retval;
|
|
|
|
spin_lock_irqsave(&io->lock, flags);
|
|
if (io->status) {
|
|
spin_unlock_irqrestore(&io->lock, flags);
|
|
return;
|
|
}
|
|
/* shut everything down */
|
|
io->status = -ECONNRESET;
|
|
spin_unlock_irqrestore(&io->lock, flags);
|
|
|
|
for (i = io->entries - 1; i >= 0; --i) {
|
|
usb_block_urb(io->urbs[i]);
|
|
|
|
retval = usb_unlink_urb(io->urbs[i]);
|
|
if (retval != -EINPROGRESS
|
|
&& retval != -ENODEV
|
|
&& retval != -EBUSY
|
|
&& retval != -EIDRM)
|
|
dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
|
|
__func__, retval);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_sg_cancel);
|
|
|
|
/*-------------------------------------------------------------------*/
|
|
|
|
/**
|
|
* usb_get_descriptor - issues a generic GET_DESCRIPTOR request
|
|
* @dev: the device whose descriptor is being retrieved
|
|
* @type: the descriptor type (USB_DT_*)
|
|
* @index: the number of the descriptor
|
|
* @buf: where to put the descriptor
|
|
* @size: how big is "buf"?
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* Gets a USB descriptor. Convenience functions exist to simplify
|
|
* getting some types of descriptors. Use
|
|
* usb_get_string() or usb_string() for USB_DT_STRING.
|
|
* Device (USB_DT_DEVICE) and configuration descriptors (USB_DT_CONFIG)
|
|
* are part of the device structure.
|
|
* In addition to a number of USB-standard descriptors, some
|
|
* devices also use class-specific or vendor-specific descriptors.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Return: The number of bytes received on success, or else the status code
|
|
* returned by the underlying usb_control_msg() call.
|
|
*/
|
|
int usb_get_descriptor(struct usb_device *dev, unsigned char type,
|
|
unsigned char index, void *buf, int size)
|
|
{
|
|
int i;
|
|
int result;
|
|
|
|
memset(buf, 0, size); /* Make sure we parse really received data */
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
/* retry on length 0 or error; some devices are flakey */
|
|
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
|
|
(type << 8) + index, 0, buf, size,
|
|
USB_CTRL_GET_TIMEOUT);
|
|
if (result <= 0 && result != -ETIMEDOUT)
|
|
continue;
|
|
if (result > 1 && ((u8 *)buf)[1] != type) {
|
|
result = -ENODATA;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_get_descriptor);
|
|
|
|
/**
|
|
* usb_get_string - gets a string descriptor
|
|
* @dev: the device whose string descriptor is being retrieved
|
|
* @langid: code for language chosen (from string descriptor zero)
|
|
* @index: the number of the descriptor
|
|
* @buf: where to put the string
|
|
* @size: how big is "buf"?
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* Retrieves a string, encoded using UTF-16LE (Unicode, 16 bits per character,
|
|
* in little-endian byte order).
|
|
* The usb_string() function will often be a convenient way to turn
|
|
* these strings into kernel-printable form.
|
|
*
|
|
* Strings may be referenced in device, configuration, interface, or other
|
|
* descriptors, and could also be used in vendor-specific ways.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Return: The number of bytes received on success, or else the status code
|
|
* returned by the underlying usb_control_msg() call.
|
|
*/
|
|
static int usb_get_string(struct usb_device *dev, unsigned short langid,
|
|
unsigned char index, void *buf, int size)
|
|
{
|
|
int i;
|
|
int result;
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
/* retry on length 0 or stall; some devices are flakey */
|
|
result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
|
|
(USB_DT_STRING << 8) + index, langid, buf, size,
|
|
USB_CTRL_GET_TIMEOUT);
|
|
if (result == 0 || result == -EPIPE)
|
|
continue;
|
|
if (result > 1 && ((u8 *) buf)[1] != USB_DT_STRING) {
|
|
result = -ENODATA;
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static void usb_try_string_workarounds(unsigned char *buf, int *length)
|
|
{
|
|
int newlength, oldlength = *length;
|
|
|
|
for (newlength = 2; newlength + 1 < oldlength; newlength += 2)
|
|
if (!isprint(buf[newlength]) || buf[newlength + 1])
|
|
break;
|
|
|
|
if (newlength > 2) {
|
|
buf[0] = newlength;
|
|
*length = newlength;
|
|
}
|
|
}
|
|
|
|
static int usb_string_sub(struct usb_device *dev, unsigned int langid,
|
|
unsigned int index, unsigned char *buf)
|
|
{
|
|
int rc;
|
|
|
|
/* Try to read the string descriptor by asking for the maximum
|
|
* possible number of bytes */
|
|
if (dev->quirks & USB_QUIRK_STRING_FETCH_255)
|
|
rc = -EIO;
|
|
else
|
|
rc = usb_get_string(dev, langid, index, buf, 255);
|
|
|
|
/* If that failed try to read the descriptor length, then
|
|
* ask for just that many bytes */
|
|
if (rc < 2) {
|
|
rc = usb_get_string(dev, langid, index, buf, 2);
|
|
if (rc == 2)
|
|
rc = usb_get_string(dev, langid, index, buf, buf[0]);
|
|
}
|
|
|
|
if (rc >= 2) {
|
|
if (!buf[0] && !buf[1])
|
|
usb_try_string_workarounds(buf, &rc);
|
|
|
|
/* There might be extra junk at the end of the descriptor */
|
|
if (buf[0] < rc)
|
|
rc = buf[0];
|
|
|
|
rc = rc - (rc & 1); /* force a multiple of two */
|
|
}
|
|
|
|
if (rc < 2)
|
|
rc = (rc < 0 ? rc : -EINVAL);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int usb_get_langid(struct usb_device *dev, unsigned char *tbuf)
|
|
{
|
|
int err;
|
|
|
|
if (dev->have_langid)
|
|
return 0;
|
|
|
|
if (dev->string_langid < 0)
|
|
return -EPIPE;
|
|
|
|
err = usb_string_sub(dev, 0, 0, tbuf);
|
|
|
|
/* If the string was reported but is malformed, default to english
|
|
* (0x0409) */
|
|
if (err == -ENODATA || (err > 0 && err < 4)) {
|
|
dev->string_langid = 0x0409;
|
|
dev->have_langid = 1;
|
|
dev_err(&dev->dev,
|
|
"language id specifier not provided by device, defaulting to English\n");
|
|
return 0;
|
|
}
|
|
|
|
/* In case of all other errors, we assume the device is not able to
|
|
* deal with strings at all. Set string_langid to -1 in order to
|
|
* prevent any string to be retrieved from the device */
|
|
if (err < 0) {
|
|
dev_info(&dev->dev, "string descriptor 0 read error: %d\n",
|
|
err);
|
|
dev->string_langid = -1;
|
|
return -EPIPE;
|
|
}
|
|
|
|
/* always use the first langid listed */
|
|
dev->string_langid = tbuf[2] | (tbuf[3] << 8);
|
|
dev->have_langid = 1;
|
|
dev_dbg(&dev->dev, "default language 0x%04x\n",
|
|
dev->string_langid);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* usb_string - returns UTF-8 version of a string descriptor
|
|
* @dev: the device whose string descriptor is being retrieved
|
|
* @index: the number of the descriptor
|
|
* @buf: where to put the string
|
|
* @size: how big is "buf"?
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This converts the UTF-16LE encoded strings returned by devices, from
|
|
* usb_get_string_descriptor(), to null-terminated UTF-8 encoded ones
|
|
* that are more usable in most kernel contexts. Note that this function
|
|
* chooses strings in the first language supported by the device.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Return: length of the string (>= 0) or usb_control_msg status (< 0).
|
|
*/
|
|
int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
|
|
{
|
|
unsigned char *tbuf;
|
|
int err;
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
return -EHOSTUNREACH;
|
|
if (size <= 0 || !buf || !index)
|
|
return -EINVAL;
|
|
buf[0] = 0;
|
|
tbuf = kmalloc(256, GFP_NOIO);
|
|
if (!tbuf)
|
|
return -ENOMEM;
|
|
|
|
err = usb_get_langid(dev, tbuf);
|
|
if (err < 0)
|
|
goto errout;
|
|
|
|
err = usb_string_sub(dev, dev->string_langid, index, tbuf);
|
|
if (err < 0)
|
|
goto errout;
|
|
|
|
size--; /* leave room for trailing NULL char in output buffer */
|
|
err = utf16s_to_utf8s((wchar_t *) &tbuf[2], (err - 2) / 2,
|
|
UTF16_LITTLE_ENDIAN, buf, size);
|
|
buf[err] = 0;
|
|
|
|
if (tbuf[1] != USB_DT_STRING)
|
|
dev_dbg(&dev->dev,
|
|
"wrong descriptor type %02x for string %d (\"%s\")\n",
|
|
tbuf[1], index, buf);
|
|
|
|
errout:
|
|
kfree(tbuf);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_string);
|
|
|
|
/* one UTF-8-encoded 16-bit character has at most three bytes */
|
|
#define MAX_USB_STRING_SIZE (127 * 3 + 1)
|
|
|
|
/**
|
|
* usb_cache_string - read a string descriptor and cache it for later use
|
|
* @udev: the device whose string descriptor is being read
|
|
* @index: the descriptor index
|
|
*
|
|
* Return: A pointer to a kmalloc'ed buffer containing the descriptor string,
|
|
* or %NULL if the index is 0 or the string could not be read.
|
|
*/
|
|
char *usb_cache_string(struct usb_device *udev, int index)
|
|
{
|
|
char *buf;
|
|
char *smallbuf = NULL;
|
|
int len;
|
|
|
|
if (index <= 0)
|
|
return NULL;
|
|
|
|
buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
|
|
if (buf) {
|
|
len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
|
|
if (len > 0) {
|
|
smallbuf = kmalloc(++len, GFP_NOIO);
|
|
if (!smallbuf)
|
|
return buf;
|
|
memcpy(smallbuf, buf, len);
|
|
}
|
|
kfree(buf);
|
|
}
|
|
return smallbuf;
|
|
}
|
|
|
|
/*
|
|
* usb_get_device_descriptor - (re)reads the device descriptor (usbcore)
|
|
* @dev: the device whose device descriptor is being updated
|
|
* @size: how much of the descriptor to read
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* Updates the copy of the device descriptor stored in the device structure,
|
|
* which dedicates space for this purpose.
|
|
*
|
|
* Not exported, only for use by the core. If drivers really want to read
|
|
* the device descriptor directly, they can call usb_get_descriptor() with
|
|
* type = USB_DT_DEVICE and index = 0.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Return: The number of bytes received on success, or else the status code
|
|
* returned by the underlying usb_control_msg() call.
|
|
*/
|
|
int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
|
|
{
|
|
struct usb_device_descriptor *desc;
|
|
int ret;
|
|
|
|
if (size > sizeof(*desc))
|
|
return -EINVAL;
|
|
desc = kmalloc(sizeof(*desc), GFP_NOIO);
|
|
if (!desc)
|
|
return -ENOMEM;
|
|
|
|
ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);
|
|
if (ret >= 0)
|
|
memcpy(&dev->descriptor, desc, size);
|
|
kfree(desc);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* usb_set_isoch_delay - informs the device of the packet transmit delay
|
|
* @dev: the device whose delay is to be informed
|
|
* Context: !in_interrupt()
|
|
*
|
|
* Since this is an optional request, we don't bother if it fails.
|
|
*/
|
|
int usb_set_isoch_delay(struct usb_device *dev)
|
|
{
|
|
/* skip hub devices */
|
|
if (dev->descriptor.bDeviceClass == USB_CLASS_HUB)
|
|
return 0;
|
|
|
|
/* skip non-SS/non-SSP devices */
|
|
if (dev->speed < USB_SPEED_SUPER)
|
|
return 0;
|
|
|
|
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
USB_REQ_SET_ISOCH_DELAY,
|
|
USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
|
|
dev->hub_delay, 0, NULL, 0,
|
|
USB_CTRL_SET_TIMEOUT);
|
|
}
|
|
|
|
/**
|
|
* usb_get_status - issues a GET_STATUS call
|
|
* @dev: the device whose status is being checked
|
|
* @recip: USB_RECIP_*; for device, interface, or endpoint
|
|
* @type: USB_STATUS_TYPE_*; for standard or PTM status types
|
|
* @target: zero (for device), else interface or endpoint number
|
|
* @data: pointer to two bytes of bitmap data
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* Returns device, interface, or endpoint status. Normally only of
|
|
* interest to see if the device is self powered, or has enabled the
|
|
* remote wakeup facility; or whether a bulk or interrupt endpoint
|
|
* is halted ("stalled").
|
|
*
|
|
* Bits in these status bitmaps are set using the SET_FEATURE request,
|
|
* and cleared using the CLEAR_FEATURE request. The usb_clear_halt()
|
|
* function should be used to clear halt ("stall") status.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Returns 0 and the status value in *@data (in host byte order) on success,
|
|
* or else the status code from the underlying usb_control_msg() call.
|
|
*/
|
|
int usb_get_status(struct usb_device *dev, int recip, int type, int target,
|
|
void *data)
|
|
{
|
|
int ret;
|
|
void *status;
|
|
int length;
|
|
|
|
switch (type) {
|
|
case USB_STATUS_TYPE_STANDARD:
|
|
length = 2;
|
|
break;
|
|
case USB_STATUS_TYPE_PTM:
|
|
if (recip != USB_RECIP_DEVICE)
|
|
return -EINVAL;
|
|
|
|
length = 4;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
status = kmalloc(length, GFP_KERNEL);
|
|
if (!status)
|
|
return -ENOMEM;
|
|
|
|
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
|
USB_REQ_GET_STATUS, USB_DIR_IN | recip, USB_STATUS_TYPE_STANDARD,
|
|
target, status, length, USB_CTRL_GET_TIMEOUT);
|
|
|
|
switch (ret) {
|
|
case 4:
|
|
if (type != USB_STATUS_TYPE_PTM) {
|
|
ret = -EIO;
|
|
break;
|
|
}
|
|
|
|
*(u32 *) data = le32_to_cpu(*(__le32 *) status);
|
|
ret = 0;
|
|
break;
|
|
case 2:
|
|
if (type != USB_STATUS_TYPE_STANDARD) {
|
|
ret = -EIO;
|
|
break;
|
|
}
|
|
|
|
*(u16 *) data = le16_to_cpu(*(__le16 *) status);
|
|
ret = 0;
|
|
break;
|
|
default:
|
|
ret = -EIO;
|
|
}
|
|
|
|
kfree(status);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_get_status);
|
|
|
|
/**
|
|
* usb_clear_halt - tells device to clear endpoint halt/stall condition
|
|
* @dev: device whose endpoint is halted
|
|
* @pipe: endpoint "pipe" being cleared
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This is used to clear halt conditions for bulk and interrupt endpoints,
|
|
* as reported by URB completion status. Endpoints that are halted are
|
|
* sometimes referred to as being "stalled". Such endpoints are unable
|
|
* to transmit or receive data until the halt status is cleared. Any URBs
|
|
* queued for such an endpoint should normally be unlinked by the driver
|
|
* before clearing the halt condition, as described in sections 5.7.5
|
|
* and 5.8.5 of the USB 2.0 spec.
|
|
*
|
|
* Note that control and isochronous endpoints don't halt, although control
|
|
* endpoints report "protocol stall" (for unsupported requests) using the
|
|
* same status code used to report a true stall.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
*
|
|
* Return: Zero on success, or else the status code returned by the
|
|
* underlying usb_control_msg() call.
|
|
*/
|
|
int usb_clear_halt(struct usb_device *dev, int pipe)
|
|
{
|
|
int result;
|
|
int endp = usb_pipeendpoint(pipe);
|
|
|
|
if (usb_pipein(pipe))
|
|
endp |= USB_DIR_IN;
|
|
|
|
/* we don't care if it wasn't halted first. in fact some devices
|
|
* (like some ibmcam model 1 units) seem to expect hosts to make
|
|
* this request for iso endpoints, which can't halt!
|
|
*/
|
|
result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT,
|
|
USB_ENDPOINT_HALT, endp, NULL, 0,
|
|
USB_CTRL_SET_TIMEOUT);
|
|
|
|
/* don't un-halt or force to DATA0 except on success */
|
|
if (result < 0)
|
|
return result;
|
|
|
|
/* NOTE: seems like Microsoft and Apple don't bother verifying
|
|
* the clear "took", so some devices could lock up if you check...
|
|
* such as the Hagiwara FlashGate DUAL. So we won't bother.
|
|
*
|
|
* NOTE: make sure the logic here doesn't diverge much from
|
|
* the copy in usb-storage, for as long as we need two copies.
|
|
*/
|
|
|
|
usb_reset_endpoint(dev, endp);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_clear_halt);
|
|
|
|
static int create_intf_ep_devs(struct usb_interface *intf)
|
|
{
|
|
struct usb_device *udev = interface_to_usbdev(intf);
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
int i;
|
|
|
|
if (intf->ep_devs_created || intf->unregistering)
|
|
return 0;
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
|
(void) usb_create_ep_devs(&intf->dev, &alt->endpoint[i], udev);
|
|
intf->ep_devs_created = 1;
|
|
return 0;
|
|
}
|
|
|
|
static void remove_intf_ep_devs(struct usb_interface *intf)
|
|
{
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
int i;
|
|
|
|
if (!intf->ep_devs_created)
|
|
return;
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
|
usb_remove_ep_devs(&alt->endpoint[i]);
|
|
intf->ep_devs_created = 0;
|
|
}
|
|
|
|
/**
|
|
* usb_disable_endpoint -- Disable an endpoint by address
|
|
* @dev: the device whose endpoint is being disabled
|
|
* @epaddr: the endpoint's address. Endpoint number for output,
|
|
* endpoint number + USB_DIR_IN for input
|
|
* @reset_hardware: flag to erase any endpoint state stored in the
|
|
* controller hardware
|
|
*
|
|
* Disables the endpoint for URB submission and nukes all pending URBs.
|
|
* If @reset_hardware is set then also deallocates hcd/hardware state
|
|
* for the endpoint.
|
|
*/
|
|
void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr,
|
|
bool reset_hardware)
|
|
{
|
|
unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
|
|
struct usb_host_endpoint *ep;
|
|
|
|
if (!dev)
|
|
return;
|
|
|
|
if (usb_endpoint_out(epaddr)) {
|
|
ep = dev->ep_out[epnum];
|
|
if (reset_hardware)
|
|
dev->ep_out[epnum] = NULL;
|
|
} else {
|
|
ep = dev->ep_in[epnum];
|
|
if (reset_hardware)
|
|
dev->ep_in[epnum] = NULL;
|
|
}
|
|
if (ep) {
|
|
ep->enabled = 0;
|
|
usb_hcd_flush_endpoint(dev, ep);
|
|
if (reset_hardware)
|
|
usb_hcd_disable_endpoint(dev, ep);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* usb_reset_endpoint - Reset an endpoint's state.
|
|
* @dev: the device whose endpoint is to be reset
|
|
* @epaddr: the endpoint's address. Endpoint number for output,
|
|
* endpoint number + USB_DIR_IN for input
|
|
*
|
|
* Resets any host-side endpoint state such as the toggle bit,
|
|
* sequence number or current window.
|
|
*/
|
|
void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr)
|
|
{
|
|
unsigned int epnum = epaddr & USB_ENDPOINT_NUMBER_MASK;
|
|
struct usb_host_endpoint *ep;
|
|
|
|
if (usb_endpoint_out(epaddr))
|
|
ep = dev->ep_out[epnum];
|
|
else
|
|
ep = dev->ep_in[epnum];
|
|
if (ep)
|
|
usb_hcd_reset_endpoint(dev, ep);
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_reset_endpoint);
|
|
|
|
|
|
/**
|
|
* usb_disable_interface -- Disable all endpoints for an interface
|
|
* @dev: the device whose interface is being disabled
|
|
* @intf: pointer to the interface descriptor
|
|
* @reset_hardware: flag to erase any endpoint state stored in the
|
|
* controller hardware
|
|
*
|
|
* Disables all the endpoints for the interface's current altsetting.
|
|
*/
|
|
void usb_disable_interface(struct usb_device *dev, struct usb_interface *intf,
|
|
bool reset_hardware)
|
|
{
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
int i;
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i) {
|
|
usb_disable_endpoint(dev,
|
|
alt->endpoint[i].desc.bEndpointAddress,
|
|
reset_hardware);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* usb_disable_device - Disable all the endpoints for a USB device
|
|
* @dev: the device whose endpoints are being disabled
|
|
* @skip_ep0: 0 to disable endpoint 0, 1 to skip it.
|
|
*
|
|
* Disables all the device's endpoints, potentially including endpoint 0.
|
|
* Deallocates hcd/hardware state for the endpoints (nuking all or most
|
|
* pending urbs) and usbcore state for the interfaces, so that usbcore
|
|
* must usb_set_configuration() before any interfaces could be used.
|
|
*/
|
|
void usb_disable_device(struct usb_device *dev, int skip_ep0)
|
|
{
|
|
int i;
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
|
|
|
/* getting rid of interfaces will disconnect
|
|
* any drivers bound to them (a key side effect)
|
|
*/
|
|
if (dev->actconfig) {
|
|
/*
|
|
* FIXME: In order to avoid self-deadlock involving the
|
|
* bandwidth_mutex, we have to mark all the interfaces
|
|
* before unregistering any of them.
|
|
*/
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
|
|
dev->actconfig->interface[i]->unregistering = 1;
|
|
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
|
|
struct usb_interface *interface;
|
|
|
|
/* remove this interface if it has been registered */
|
|
interface = dev->actconfig->interface[i];
|
|
if (!device_is_registered(&interface->dev))
|
|
continue;
|
|
dev_dbg(&dev->dev, "unregistering interface %s\n",
|
|
dev_name(&interface->dev));
|
|
remove_intf_ep_devs(interface);
|
|
device_del(&interface->dev);
|
|
}
|
|
|
|
/* Now that the interfaces are unbound, nobody should
|
|
* try to access them.
|
|
*/
|
|
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
|
|
put_device(&dev->actconfig->interface[i]->dev);
|
|
dev->actconfig->interface[i] = NULL;
|
|
}
|
|
|
|
if (dev->usb2_hw_lpm_enabled == 1)
|
|
usb_set_usb2_hardware_lpm(dev, 0);
|
|
usb_unlocked_disable_lpm(dev);
|
|
usb_disable_ltm(dev);
|
|
|
|
dev->actconfig = NULL;
|
|
if (dev->state == USB_STATE_CONFIGURED)
|
|
usb_set_device_state(dev, USB_STATE_ADDRESS);
|
|
}
|
|
|
|
dev_dbg(&dev->dev, "%s nuking %s URBs\n", __func__,
|
|
skip_ep0 ? "non-ep0" : "all");
|
|
if (hcd->driver->check_bandwidth) {
|
|
/* First pass: Cancel URBs, leave endpoint pointers intact. */
|
|
for (i = skip_ep0; i < 16; ++i) {
|
|
usb_disable_endpoint(dev, i, false);
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, false);
|
|
}
|
|
/* Remove endpoints from the host controller internal state */
|
|
mutex_lock(hcd->bandwidth_mutex);
|
|
usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
/* Second pass: remove endpoint pointers */
|
|
}
|
|
for (i = skip_ep0; i < 16; ++i) {
|
|
usb_disable_endpoint(dev, i, true);
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, true);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* usb_enable_endpoint - Enable an endpoint for USB communications
|
|
* @dev: the device whose interface is being enabled
|
|
* @ep: the endpoint
|
|
* @reset_ep: flag to reset the endpoint state
|
|
*
|
|
* Resets the endpoint state if asked, and sets dev->ep_{in,out} pointers.
|
|
* For control endpoints, both the input and output sides are handled.
|
|
*/
|
|
void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep,
|
|
bool reset_ep)
|
|
{
|
|
int epnum = usb_endpoint_num(&ep->desc);
|
|
int is_out = usb_endpoint_dir_out(&ep->desc);
|
|
int is_control = usb_endpoint_xfer_control(&ep->desc);
|
|
|
|
if (reset_ep)
|
|
usb_hcd_reset_endpoint(dev, ep);
|
|
if (is_out || is_control)
|
|
dev->ep_out[epnum] = ep;
|
|
if (!is_out || is_control)
|
|
dev->ep_in[epnum] = ep;
|
|
ep->enabled = 1;
|
|
}
|
|
|
|
/**
|
|
* usb_enable_interface - Enable all the endpoints for an interface
|
|
* @dev: the device whose interface is being enabled
|
|
* @intf: pointer to the interface descriptor
|
|
* @reset_eps: flag to reset the endpoints' state
|
|
*
|
|
* Enables all the endpoints for the interface's current altsetting.
|
|
*/
|
|
void usb_enable_interface(struct usb_device *dev,
|
|
struct usb_interface *intf, bool reset_eps)
|
|
{
|
|
struct usb_host_interface *alt = intf->cur_altsetting;
|
|
int i;
|
|
|
|
for (i = 0; i < alt->desc.bNumEndpoints; ++i)
|
|
usb_enable_endpoint(dev, &alt->endpoint[i], reset_eps);
|
|
}
|
|
|
|
/**
|
|
* usb_set_interface - Makes a particular alternate setting be current
|
|
* @dev: the device whose interface is being updated
|
|
* @interface: the interface being updated
|
|
* @alternate: the setting being chosen.
|
|
* Context: !in_interrupt ()
|
|
*
|
|
* This is used to enable data transfers on interfaces that may not
|
|
* be enabled by default. Not all devices support such configurability.
|
|
* Only the driver bound to an interface may change its setting.
|
|
*
|
|
* Within any given configuration, each interface may have several
|
|
* alternative settings. These are often used to control levels of
|
|
* bandwidth consumption. For example, the default setting for a high
|
|
* speed interrupt endpoint may not send more than 64 bytes per microframe,
|
|
* while interrupt transfers of up to 3KBytes per microframe are legal.
|
|
* Also, isochronous endpoints may never be part of an
|
|
* interface's default setting. To access such bandwidth, alternate
|
|
* interface settings must be made current.
|
|
*
|
|
* Note that in the Linux USB subsystem, bandwidth associated with
|
|
* an endpoint in a given alternate setting is not reserved until an URB
|
|
* is submitted that needs that bandwidth. Some other operating systems
|
|
* allocate bandwidth early, when a configuration is chosen.
|
|
*
|
|
* xHCI reserves bandwidth and configures the alternate setting in
|
|
* usb_hcd_alloc_bandwidth(). If it fails the original interface altsetting
|
|
* may be disabled. Drivers cannot rely on any particular alternate
|
|
* setting being in effect after a failure.
|
|
*
|
|
* This call is synchronous, and may not be used in an interrupt context.
|
|
* Also, drivers must not change altsettings while urbs are scheduled for
|
|
* endpoints in that interface; all such urbs must first be completed
|
|
* (perhaps forced by unlinking).
|
|
*
|
|
* Return: Zero on success, or else the status code returned by the
|
|
* underlying usb_control_msg() call.
|
|
*/
|
|
int usb_set_interface(struct usb_device *dev, int interface, int alternate)
|
|
{
|
|
struct usb_interface *iface;
|
|
struct usb_host_interface *alt;
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
|
int i, ret, manual = 0;
|
|
unsigned int epaddr;
|
|
unsigned int pipe;
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
return -EHOSTUNREACH;
|
|
|
|
iface = usb_ifnum_to_if(dev, interface);
|
|
if (!iface) {
|
|
dev_dbg(&dev->dev, "selecting invalid interface %d\n",
|
|
interface);
|
|
return -EINVAL;
|
|
}
|
|
if (iface->unregistering)
|
|
return -ENODEV;
|
|
|
|
alt = usb_altnum_to_altsetting(iface, alternate);
|
|
if (!alt) {
|
|
dev_warn(&dev->dev, "selecting invalid altsetting %d\n",
|
|
alternate);
|
|
return -EINVAL;
|
|
}
|
|
/*
|
|
* usb3 hosts configure the interface in usb_hcd_alloc_bandwidth,
|
|
* including freeing dropped endpoint ring buffers.
|
|
* Make sure the interface endpoints are flushed before that
|
|
*/
|
|
usb_disable_interface(dev, iface, false);
|
|
|
|
/* Make sure we have enough bandwidth for this alternate interface.
|
|
* Remove the current alt setting and add the new alt setting.
|
|
*/
|
|
mutex_lock(hcd->bandwidth_mutex);
|
|
/* Disable LPM, and re-enable it once the new alt setting is installed,
|
|
* so that the xHCI driver can recalculate the U1/U2 timeouts.
|
|
*/
|
|
if (usb_disable_lpm(dev)) {
|
|
dev_err(&iface->dev, "%s Failed to disable LPM\n", __func__);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
return -ENOMEM;
|
|
}
|
|
/* Changing alt-setting also frees any allocated streams */
|
|
for (i = 0; i < iface->cur_altsetting->desc.bNumEndpoints; i++)
|
|
iface->cur_altsetting->endpoint[i].streams = 0;
|
|
|
|
ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
|
|
if (ret < 0) {
|
|
dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
|
|
alternate);
|
|
usb_enable_lpm(dev);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
return ret;
|
|
}
|
|
|
|
if (dev->quirks & USB_QUIRK_NO_SET_INTF)
|
|
ret = -EPIPE;
|
|
else
|
|
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
|
|
alternate, interface, NULL, 0, 5000);
|
|
|
|
/* 9.4.10 says devices don't need this and are free to STALL the
|
|
* request if the interface only has one alternate setting.
|
|
*/
|
|
if (ret == -EPIPE && iface->num_altsetting == 1) {
|
|
dev_dbg(&dev->dev,
|
|
"manual set_interface for iface %d, alt %d\n",
|
|
interface, alternate);
|
|
manual = 1;
|
|
} else if (ret < 0) {
|
|
/* Re-instate the old alt setting */
|
|
usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
|
|
usb_enable_lpm(dev);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
return ret;
|
|
}
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
/* FIXME drivers shouldn't need to replicate/bugfix the logic here
|
|
* when they implement async or easily-killable versions of this or
|
|
* other "should-be-internal" functions (like clear_halt).
|
|
* should hcd+usbcore postprocess control requests?
|
|
*/
|
|
|
|
/* prevent submissions using previous endpoint settings */
|
|
if (iface->cur_altsetting != alt) {
|
|
remove_intf_ep_devs(iface);
|
|
usb_remove_sysfs_intf_files(iface);
|
|
}
|
|
usb_disable_interface(dev, iface, true);
|
|
|
|
iface->cur_altsetting = alt;
|
|
|
|
/* Now that the interface is installed, re-enable LPM. */
|
|
usb_unlocked_enable_lpm(dev);
|
|
|
|
/* If the interface only has one altsetting and the device didn't
|
|
* accept the request, we attempt to carry out the equivalent action
|
|
* by manually clearing the HALT feature for each endpoint in the
|
|
* new altsetting.
|
|
*/
|
|
if (manual) {
|
|
for (i = 0; i < alt->desc.bNumEndpoints; i++) {
|
|
epaddr = alt->endpoint[i].desc.bEndpointAddress;
|
|
pipe = __create_pipe(dev,
|
|
USB_ENDPOINT_NUMBER_MASK & epaddr) |
|
|
(usb_endpoint_out(epaddr) ?
|
|
USB_DIR_OUT : USB_DIR_IN);
|
|
|
|
usb_clear_halt(dev, pipe);
|
|
}
|
|
}
|
|
|
|
/* 9.1.1.5: reset toggles for all endpoints in the new altsetting
|
|
*
|
|
* Note:
|
|
* Despite EP0 is always present in all interfaces/AS, the list of
|
|
* endpoints from the descriptor does not contain EP0. Due to its
|
|
* omnipresence one might expect EP0 being considered "affected" by
|
|
* any SetInterface request and hence assume toggles need to be reset.
|
|
* However, EP0 toggles are re-synced for every individual transfer
|
|
* during the SETUP stage - hence EP0 toggles are "don't care" here.
|
|
* (Likewise, EP0 never "halts" on well designed devices.)
|
|
*/
|
|
usb_enable_interface(dev, iface, true);
|
|
if (device_is_registered(&iface->dev)) {
|
|
usb_create_sysfs_intf_files(iface);
|
|
create_intf_ep_devs(iface);
|
|
}
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_set_interface);
|
|
|
|
/**
|
|
* usb_reset_configuration - lightweight device reset
|
|
* @dev: the device whose configuration is being reset
|
|
*
|
|
* This issues a standard SET_CONFIGURATION request to the device using
|
|
* the current configuration. The effect is to reset most USB-related
|
|
* state in the device, including interface altsettings (reset to zero),
|
|
* endpoint halts (cleared), and endpoint state (only for bulk and interrupt
|
|
* endpoints). Other usbcore state is unchanged, including bindings of
|
|
* usb device drivers to interfaces.
|
|
*
|
|
* Because this affects multiple interfaces, avoid using this with composite
|
|
* (multi-interface) devices. Instead, the driver for each interface may
|
|
* use usb_set_interface() on the interfaces it claims. Be careful though;
|
|
* some devices don't support the SET_INTERFACE request, and others won't
|
|
* reset all the interface state (notably endpoint state). Resetting the whole
|
|
* configuration would affect other drivers' interfaces.
|
|
*
|
|
* The caller must own the device lock.
|
|
*
|
|
* Return: Zero on success, else a negative error code.
|
|
*/
|
|
int usb_reset_configuration(struct usb_device *dev)
|
|
{
|
|
int i, retval;
|
|
struct usb_host_config *config;
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
|
|
|
if (dev->state == USB_STATE_SUSPENDED)
|
|
return -EHOSTUNREACH;
|
|
|
|
/* caller must have locked the device and must own
|
|
* the usb bus readlock (so driver bindings are stable);
|
|
* calls during probe() are fine
|
|
*/
|
|
|
|
for (i = 1; i < 16; ++i) {
|
|
usb_disable_endpoint(dev, i, true);
|
|
usb_disable_endpoint(dev, i + USB_DIR_IN, true);
|
|
}
|
|
|
|
config = dev->actconfig;
|
|
retval = 0;
|
|
mutex_lock(hcd->bandwidth_mutex);
|
|
/* Disable LPM, and re-enable it once the configuration is reset, so
|
|
* that the xHCI driver can recalculate the U1/U2 timeouts.
|
|
*/
|
|
if (usb_disable_lpm(dev)) {
|
|
dev_err(&dev->dev, "%s Failed to disable LPM\n", __func__);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
return -ENOMEM;
|
|
}
|
|
/* Make sure we have enough bandwidth for each alternate setting 0 */
|
|
for (i = 0; i < config->desc.bNumInterfaces; i++) {
|
|
struct usb_interface *intf = config->interface[i];
|
|
struct usb_host_interface *alt;
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
if (!alt)
|
|
alt = &intf->altsetting[0];
|
|
if (alt != intf->cur_altsetting)
|
|
retval = usb_hcd_alloc_bandwidth(dev, NULL,
|
|
intf->cur_altsetting, alt);
|
|
if (retval < 0)
|
|
break;
|
|
}
|
|
/* If not, reinstate the old alternate settings */
|
|
if (retval < 0) {
|
|
reset_old_alts:
|
|
for (i--; i >= 0; i--) {
|
|
struct usb_interface *intf = config->interface[i];
|
|
struct usb_host_interface *alt;
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
if (!alt)
|
|
alt = &intf->altsetting[0];
|
|
if (alt != intf->cur_altsetting)
|
|
usb_hcd_alloc_bandwidth(dev, NULL,
|
|
alt, intf->cur_altsetting);
|
|
}
|
|
usb_enable_lpm(dev);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
return retval;
|
|
}
|
|
retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
USB_REQ_SET_CONFIGURATION, 0,
|
|
config->desc.bConfigurationValue, 0,
|
|
NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
if (retval < 0)
|
|
goto reset_old_alts;
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
/* re-init hc/hcd interface/endpoint state */
|
|
for (i = 0; i < config->desc.bNumInterfaces; i++) {
|
|
struct usb_interface *intf = config->interface[i];
|
|
struct usb_host_interface *alt;
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
/* No altsetting 0? We'll assume the first altsetting.
|
|
* We could use a GetInterface call, but if a device is
|
|
* so non-compliant that it doesn't have altsetting 0
|
|
* then I wouldn't trust its reply anyway.
|
|
*/
|
|
if (!alt)
|
|
alt = &intf->altsetting[0];
|
|
|
|
if (alt != intf->cur_altsetting) {
|
|
remove_intf_ep_devs(intf);
|
|
usb_remove_sysfs_intf_files(intf);
|
|
}
|
|
intf->cur_altsetting = alt;
|
|
usb_enable_interface(dev, intf, true);
|
|
if (device_is_registered(&intf->dev)) {
|
|
usb_create_sysfs_intf_files(intf);
|
|
create_intf_ep_devs(intf);
|
|
}
|
|
}
|
|
/* Now that the interfaces are installed, re-enable LPM. */
|
|
usb_unlocked_enable_lpm(dev);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_reset_configuration);
|
|
|
|
static void usb_release_interface(struct device *dev)
|
|
{
|
|
struct usb_interface *intf = to_usb_interface(dev);
|
|
struct usb_interface_cache *intfc =
|
|
altsetting_to_usb_interface_cache(intf->altsetting);
|
|
|
|
kref_put(&intfc->ref, usb_release_interface_cache);
|
|
usb_put_dev(interface_to_usbdev(intf));
|
|
of_node_put(dev->of_node);
|
|
kfree(intf);
|
|
}
|
|
|
|
/*
|
|
* usb_deauthorize_interface - deauthorize an USB interface
|
|
*
|
|
* @intf: USB interface structure
|
|
*/
|
|
void usb_deauthorize_interface(struct usb_interface *intf)
|
|
{
|
|
struct device *dev = &intf->dev;
|
|
|
|
device_lock(dev->parent);
|
|
|
|
if (intf->authorized) {
|
|
device_lock(dev);
|
|
intf->authorized = 0;
|
|
device_unlock(dev);
|
|
|
|
usb_forced_unbind_intf(intf);
|
|
}
|
|
|
|
device_unlock(dev->parent);
|
|
}
|
|
|
|
/*
|
|
* usb_authorize_interface - authorize an USB interface
|
|
*
|
|
* @intf: USB interface structure
|
|
*/
|
|
void usb_authorize_interface(struct usb_interface *intf)
|
|
{
|
|
struct device *dev = &intf->dev;
|
|
|
|
if (!intf->authorized) {
|
|
device_lock(dev);
|
|
intf->authorized = 1; /* authorize interface */
|
|
device_unlock(dev);
|
|
}
|
|
}
|
|
|
|
static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
|
|
{
|
|
struct usb_device *usb_dev;
|
|
struct usb_interface *intf;
|
|
struct usb_host_interface *alt;
|
|
|
|
intf = to_usb_interface(dev);
|
|
usb_dev = interface_to_usbdev(intf);
|
|
alt = intf->cur_altsetting;
|
|
|
|
if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
|
|
alt->desc.bInterfaceClass,
|
|
alt->desc.bInterfaceSubClass,
|
|
alt->desc.bInterfaceProtocol))
|
|
return -ENOMEM;
|
|
|
|
if (add_uevent_var(env,
|
|
"MODALIAS=usb:"
|
|
"v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02Xin%02X",
|
|
le16_to_cpu(usb_dev->descriptor.idVendor),
|
|
le16_to_cpu(usb_dev->descriptor.idProduct),
|
|
le16_to_cpu(usb_dev->descriptor.bcdDevice),
|
|
usb_dev->descriptor.bDeviceClass,
|
|
usb_dev->descriptor.bDeviceSubClass,
|
|
usb_dev->descriptor.bDeviceProtocol,
|
|
alt->desc.bInterfaceClass,
|
|
alt->desc.bInterfaceSubClass,
|
|
alt->desc.bInterfaceProtocol,
|
|
alt->desc.bInterfaceNumber))
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct device_type usb_if_device_type = {
|
|
.name = "usb_interface",
|
|
.release = usb_release_interface,
|
|
.uevent = usb_if_uevent,
|
|
};
|
|
|
|
static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
|
|
struct usb_host_config *config,
|
|
u8 inum)
|
|
{
|
|
struct usb_interface_assoc_descriptor *retval = NULL;
|
|
struct usb_interface_assoc_descriptor *intf_assoc;
|
|
int first_intf;
|
|
int last_intf;
|
|
int i;
|
|
|
|
for (i = 0; (i < USB_MAXIADS && config->intf_assoc[i]); i++) {
|
|
intf_assoc = config->intf_assoc[i];
|
|
if (intf_assoc->bInterfaceCount == 0)
|
|
continue;
|
|
|
|
first_intf = intf_assoc->bFirstInterface;
|
|
last_intf = first_intf + (intf_assoc->bInterfaceCount - 1);
|
|
if (inum >= first_intf && inum <= last_intf) {
|
|
if (!retval)
|
|
retval = intf_assoc;
|
|
else
|
|
dev_err(&dev->dev, "Interface #%d referenced"
|
|
" by multiple IADs\n", inum);
|
|
}
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
|
|
/*
|
|
* Internal function to queue a device reset
|
|
* See usb_queue_reset_device() for more details
|
|
*/
|
|
static void __usb_queue_reset_device(struct work_struct *ws)
|
|
{
|
|
int rc;
|
|
struct usb_interface *iface =
|
|
container_of(ws, struct usb_interface, reset_ws);
|
|
struct usb_device *udev = interface_to_usbdev(iface);
|
|
|
|
rc = usb_lock_device_for_reset(udev, iface);
|
|
if (rc >= 0) {
|
|
usb_reset_device(udev);
|
|
usb_unlock_device(udev);
|
|
}
|
|
usb_put_intf(iface); /* Undo _get_ in usb_queue_reset_device() */
|
|
}
|
|
|
|
|
|
/*
|
|
* usb_set_configuration - Makes a particular device setting be current
|
|
* @dev: the device whose configuration is being updated
|
|
* @configuration: the configuration being chosen.
|
|
* Context: !in_interrupt(), caller owns the device lock
|
|
*
|
|
* This is used to enable non-default device modes. Not all devices
|
|
* use this kind of configurability; many devices only have one
|
|
* configuration.
|
|
*
|
|
* @configuration is the value of the configuration to be installed.
|
|
* According to the USB spec (e.g. section 9.1.1.5), configuration values
|
|
* must be non-zero; a value of zero indicates that the device in
|
|
* unconfigured. However some devices erroneously use 0 as one of their
|
|
* configuration values. To help manage such devices, this routine will
|
|
* accept @configuration = -1 as indicating the device should be put in
|
|
* an unconfigured state.
|
|
*
|
|
* USB device configurations may affect Linux interoperability,
|
|
* power consumption and the functionality available. For example,
|
|
* the default configuration is limited to using 100mA of bus power,
|
|
* so that when certain device functionality requires more power,
|
|
* and the device is bus powered, that functionality should be in some
|
|
* non-default device configuration. Other device modes may also be
|
|
* reflected as configuration options, such as whether two ISDN
|
|
* channels are available independently; and choosing between open
|
|
* standard device protocols (like CDC) or proprietary ones.
|
|
*
|
|
* Note that a non-authorized device (dev->authorized == 0) will only
|
|
* be put in unconfigured mode.
|
|
*
|
|
* Note that USB has an additional level of device configurability,
|
|
* associated with interfaces. That configurability is accessed using
|
|
* usb_set_interface().
|
|
*
|
|
* This call is synchronous. The calling context must be able to sleep,
|
|
* must own the device lock, and must not hold the driver model's USB
|
|
* bus mutex; usb interface driver probe() methods cannot use this routine.
|
|
*
|
|
* Returns zero on success, or else the status code returned by the
|
|
* underlying call that failed. On successful completion, each interface
|
|
* in the original device configuration has been destroyed, and each one
|
|
* in the new configuration has been probed by all relevant usb device
|
|
* drivers currently known to the kernel.
|
|
*/
|
|
int usb_set_configuration(struct usb_device *dev, int configuration)
|
|
{
|
|
int i, ret;
|
|
struct usb_host_config *cp = NULL;
|
|
struct usb_interface **new_interfaces = NULL;
|
|
struct usb_hcd *hcd = bus_to_hcd(dev->bus);
|
|
int n, nintf;
|
|
|
|
if (dev->authorized == 0 || configuration == -1)
|
|
configuration = 0;
|
|
else {
|
|
for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
|
|
if (dev->config[i].desc.bConfigurationValue ==
|
|
configuration) {
|
|
cp = &dev->config[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ((!cp && configuration != 0))
|
|
return -EINVAL;
|
|
|
|
/* The USB spec says configuration 0 means unconfigured.
|
|
* But if a device includes a configuration numbered 0,
|
|
* we will accept it as a correctly configured state.
|
|
* Use -1 if you really want to unconfigure the device.
|
|
*/
|
|
if (cp && configuration == 0)
|
|
dev_warn(&dev->dev, "config 0 descriptor??\n");
|
|
|
|
/* Allocate memory for new interfaces before doing anything else,
|
|
* so that if we run out then nothing will have changed. */
|
|
n = nintf = 0;
|
|
if (cp) {
|
|
nintf = cp->desc.bNumInterfaces;
|
|
new_interfaces = kmalloc_array(nintf, sizeof(*new_interfaces),
|
|
GFP_NOIO);
|
|
if (!new_interfaces)
|
|
return -ENOMEM;
|
|
|
|
for (; n < nintf; ++n) {
|
|
new_interfaces[n] = kzalloc(
|
|
sizeof(struct usb_interface),
|
|
GFP_NOIO);
|
|
if (!new_interfaces[n]) {
|
|
ret = -ENOMEM;
|
|
free_interfaces:
|
|
while (--n >= 0)
|
|
kfree(new_interfaces[n]);
|
|
kfree(new_interfaces);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
i = dev->bus_mA - usb_get_max_power(dev, cp);
|
|
if (i < 0)
|
|
dev_warn(&dev->dev, "new config #%d exceeds power "
|
|
"limit by %dmA\n",
|
|
configuration, -i);
|
|
}
|
|
|
|
/* Wake up the device so we can send it the Set-Config request */
|
|
ret = usb_autoresume_device(dev);
|
|
if (ret)
|
|
goto free_interfaces;
|
|
|
|
/* if it's already configured, clear out old state first.
|
|
* getting rid of old interfaces means unbinding their drivers.
|
|
*/
|
|
if (dev->state != USB_STATE_ADDRESS)
|
|
usb_disable_device(dev, 1); /* Skip ep0 */
|
|
|
|
/* Get rid of pending async Set-Config requests for this device */
|
|
cancel_async_set_config(dev);
|
|
|
|
/* Make sure we have bandwidth (and available HCD resources) for this
|
|
* configuration. Remove endpoints from the schedule if we're dropping
|
|
* this configuration to set configuration 0. After this point, the
|
|
* host controller will not allow submissions to dropped endpoints. If
|
|
* this call fails, the device state is unchanged.
|
|
*/
|
|
mutex_lock(hcd->bandwidth_mutex);
|
|
/* Disable LPM, and re-enable it once the new configuration is
|
|
* installed, so that the xHCI driver can recalculate the U1/U2
|
|
* timeouts.
|
|
*/
|
|
if (dev->actconfig && usb_disable_lpm(dev)) {
|
|
dev_err(&dev->dev, "%s Failed to disable LPM\n", __func__);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
ret = -ENOMEM;
|
|
goto free_interfaces;
|
|
}
|
|
ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
|
|
if (ret < 0) {
|
|
if (dev->actconfig)
|
|
usb_enable_lpm(dev);
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
usb_autosuspend_device(dev);
|
|
goto free_interfaces;
|
|
}
|
|
|
|
/*
|
|
* Initialize the new interface structures and the
|
|
* hc/hcd/usbcore interface/endpoint state.
|
|
*/
|
|
for (i = 0; i < nintf; ++i) {
|
|
struct usb_interface_cache *intfc;
|
|
struct usb_interface *intf;
|
|
struct usb_host_interface *alt;
|
|
u8 ifnum;
|
|
|
|
cp->interface[i] = intf = new_interfaces[i];
|
|
intfc = cp->intf_cache[i];
|
|
intf->altsetting = intfc->altsetting;
|
|
intf->num_altsetting = intfc->num_altsetting;
|
|
intf->authorized = !!HCD_INTF_AUTHORIZED(hcd);
|
|
kref_get(&intfc->ref);
|
|
|
|
alt = usb_altnum_to_altsetting(intf, 0);
|
|
|
|
/* No altsetting 0? We'll assume the first altsetting.
|
|
* We could use a GetInterface call, but if a device is
|
|
* so non-compliant that it doesn't have altsetting 0
|
|
* then I wouldn't trust its reply anyway.
|
|
*/
|
|
if (!alt)
|
|
alt = &intf->altsetting[0];
|
|
|
|
ifnum = alt->desc.bInterfaceNumber;
|
|
intf->intf_assoc = find_iad(dev, cp, ifnum);
|
|
intf->cur_altsetting = alt;
|
|
usb_enable_interface(dev, intf, true);
|
|
intf->dev.parent = &dev->dev;
|
|
if (usb_of_has_combined_node(dev)) {
|
|
device_set_of_node_from_dev(&intf->dev, &dev->dev);
|
|
} else {
|
|
intf->dev.of_node = usb_of_get_interface_node(dev,
|
|
configuration, ifnum);
|
|
}
|
|
intf->dev.driver = NULL;
|
|
intf->dev.bus = &usb_bus_type;
|
|
intf->dev.type = &usb_if_device_type;
|
|
intf->dev.groups = usb_interface_groups;
|
|
/*
|
|
* Please refer to usb_alloc_dev() to see why we set
|
|
* dma_mask and dma_pfn_offset.
|
|
*/
|
|
intf->dev.dma_mask = dev->dev.dma_mask;
|
|
intf->dev.dma_pfn_offset = dev->dev.dma_pfn_offset;
|
|
INIT_WORK(&intf->reset_ws, __usb_queue_reset_device);
|
|
intf->minor = -1;
|
|
device_initialize(&intf->dev);
|
|
pm_runtime_no_callbacks(&intf->dev);
|
|
dev_set_name(&intf->dev, "%d-%s:%d.%d", dev->bus->busnum,
|
|
dev->devpath, configuration, ifnum);
|
|
usb_get_dev(dev);
|
|
}
|
|
kfree(new_interfaces);
|
|
|
|
ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
|
|
USB_REQ_SET_CONFIGURATION, 0, configuration, 0,
|
|
NULL, 0, USB_CTRL_SET_TIMEOUT);
|
|
if (ret < 0 && cp) {
|
|
/*
|
|
* All the old state is gone, so what else can we do?
|
|
* The device is probably useless now anyway.
|
|
*/
|
|
usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
|
|
for (i = 0; i < nintf; ++i) {
|
|
usb_disable_interface(dev, cp->interface[i], true);
|
|
put_device(&cp->interface[i]->dev);
|
|
cp->interface[i] = NULL;
|
|
}
|
|
cp = NULL;
|
|
}
|
|
|
|
dev->actconfig = cp;
|
|
mutex_unlock(hcd->bandwidth_mutex);
|
|
|
|
if (!cp) {
|
|
usb_set_device_state(dev, USB_STATE_ADDRESS);
|
|
|
|
/* Leave LPM disabled while the device is unconfigured. */
|
|
usb_autosuspend_device(dev);
|
|
return ret;
|
|
}
|
|
usb_set_device_state(dev, USB_STATE_CONFIGURED);
|
|
|
|
if (cp->string == NULL &&
|
|
!(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
|
|
cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
|
|
/* Uncomment this define to enable the HS Electrical Test support */
|
|
#define DWC_HS_ELECT_TST 1
|
|
#ifdef DWC_HS_ELECT_TST
|
|
/* Here we implement the HS Electrical Test support. The
|
|
* tester uses a vendor ID of 0x1A0A to indicate we should
|
|
* run a special test sequence. The product ID tells us
|
|
* which sequence to run. We invoke the test sequence by
|
|
* sending a non-standard SetFeature command to our root
|
|
* hub port. Our dwc_otg_hcd_hub_control() routine will
|
|
* recognize the command and perform the desired test
|
|
* sequence.
|
|
*/
|
|
if (dev->descriptor.idVendor == 0x1A0A) {
|
|
/* HSOTG Electrical Test */
|
|
dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
|
|
|
|
if (dev->bus && dev->bus->root_hub) {
|
|
struct usb_device *hdev = dev->bus->root_hub;
|
|
dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
|
|
|
|
switch (dev->descriptor.idProduct) {
|
|
case 0x0101: /* TEST_SE0_NAK */
|
|
dev_warn(&dev->dev, "TEST_SE0_NAK\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
|
|
break;
|
|
|
|
case 0x0102: /* TEST_J */
|
|
dev_warn(&dev->dev, "TEST_J\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
|
|
break;
|
|
|
|
case 0x0103: /* TEST_K */
|
|
dev_warn(&dev->dev, "TEST_K\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
|
|
break;
|
|
|
|
case 0x0104: /* TEST_PACKET */
|
|
dev_warn(&dev->dev, "TEST_PACKET\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
|
|
break;
|
|
|
|
case 0x0105: /* TEST_FORCE_ENABLE */
|
|
dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
|
|
break;
|
|
|
|
case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
|
|
dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
|
|
break;
|
|
|
|
case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
|
|
dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
|
|
break;
|
|
|
|
case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
|
|
dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
|
|
usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
|
|
USB_REQ_SET_FEATURE, USB_RT_PORT,
|
|
USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
|
|
}
|
|
}
|
|
}
|
|
#endif /* DWC_HS_ELECT_TST */
|
|
|
|
/* Now that the interfaces are installed, re-enable LPM. */
|
|
usb_unlocked_enable_lpm(dev);
|
|
/* Enable LTM if it was turned off by usb_disable_device. */
|
|
usb_enable_ltm(dev);
|
|
|
|
/* Now that all the interfaces are set up, register them
|
|
* to trigger binding of drivers to interfaces. probe()
|
|
* routines may install different altsettings and may
|
|
* claim() any interfaces not yet bound. Many class drivers
|
|
* need that: CDC, audio, video, etc.
|
|
*/
|
|
for (i = 0; i < nintf; ++i) {
|
|
struct usb_interface *intf = cp->interface[i];
|
|
|
|
dev_dbg(&dev->dev,
|
|
"adding %s (config #%d, interface %d)\n",
|
|
dev_name(&intf->dev), configuration,
|
|
intf->cur_altsetting->desc.bInterfaceNumber);
|
|
device_enable_async_suspend(&intf->dev);
|
|
ret = device_add(&intf->dev);
|
|
if (ret != 0) {
|
|
dev_err(&dev->dev, "device_add(%s) --> %d\n",
|
|
dev_name(&intf->dev), ret);
|
|
continue;
|
|
}
|
|
create_intf_ep_devs(intf);
|
|
}
|
|
|
|
usb_autosuspend_device(dev);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_set_configuration);
|
|
|
|
static LIST_HEAD(set_config_list);
|
|
static DEFINE_SPINLOCK(set_config_lock);
|
|
|
|
struct set_config_request {
|
|
struct usb_device *udev;
|
|
int config;
|
|
struct work_struct work;
|
|
struct list_head node;
|
|
};
|
|
|
|
/* Worker routine for usb_driver_set_configuration() */
|
|
static void driver_set_config_work(struct work_struct *work)
|
|
{
|
|
struct set_config_request *req =
|
|
container_of(work, struct set_config_request, work);
|
|
struct usb_device *udev = req->udev;
|
|
|
|
usb_lock_device(udev);
|
|
spin_lock(&set_config_lock);
|
|
list_del(&req->node);
|
|
spin_unlock(&set_config_lock);
|
|
|
|
if (req->config >= -1) /* Is req still valid? */
|
|
usb_set_configuration(udev, req->config);
|
|
usb_unlock_device(udev);
|
|
usb_put_dev(udev);
|
|
kfree(req);
|
|
}
|
|
|
|
/* Cancel pending Set-Config requests for a device whose configuration
|
|
* was just changed
|
|
*/
|
|
static void cancel_async_set_config(struct usb_device *udev)
|
|
{
|
|
struct set_config_request *req;
|
|
|
|
spin_lock(&set_config_lock);
|
|
list_for_each_entry(req, &set_config_list, node) {
|
|
if (req->udev == udev)
|
|
req->config = -999; /* Mark as cancelled */
|
|
}
|
|
spin_unlock(&set_config_lock);
|
|
}
|
|
|
|
/**
|
|
* usb_driver_set_configuration - Provide a way for drivers to change device configurations
|
|
* @udev: the device whose configuration is being updated
|
|
* @config: the configuration being chosen.
|
|
* Context: In process context, must be able to sleep
|
|
*
|
|
* Device interface drivers are not allowed to change device configurations.
|
|
* This is because changing configurations will destroy the interface the
|
|
* driver is bound to and create new ones; it would be like a floppy-disk
|
|
* driver telling the computer to replace the floppy-disk drive with a
|
|
* tape drive!
|
|
*
|
|
* Still, in certain specialized circumstances the need may arise. This
|
|
* routine gets around the normal restrictions by using a work thread to
|
|
* submit the change-config request.
|
|
*
|
|
* Return: 0 if the request was successfully queued, error code otherwise.
|
|
* The caller has no way to know whether the queued request will eventually
|
|
* succeed.
|
|
*/
|
|
int usb_driver_set_configuration(struct usb_device *udev, int config)
|
|
{
|
|
struct set_config_request *req;
|
|
|
|
req = kmalloc(sizeof(*req), GFP_KERNEL);
|
|
if (!req)
|
|
return -ENOMEM;
|
|
req->udev = udev;
|
|
req->config = config;
|
|
INIT_WORK(&req->work, driver_set_config_work);
|
|
|
|
spin_lock(&set_config_lock);
|
|
list_add(&req->node, &set_config_list);
|
|
spin_unlock(&set_config_lock);
|
|
|
|
usb_get_dev(udev);
|
|
schedule_work(&req->work);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(usb_driver_set_configuration);
|
|
|
|
/**
|
|
* cdc_parse_cdc_header - parse the extra headers present in CDC devices
|
|
* @hdr: the place to put the results of the parsing
|
|
* @intf: the interface for which parsing is requested
|
|
* @buffer: pointer to the extra headers to be parsed
|
|
* @buflen: length of the extra headers
|
|
*
|
|
* This evaluates the extra headers present in CDC devices which
|
|
* bind the interfaces for data and control and provide details
|
|
* about the capabilities of the device.
|
|
*
|
|
* Return: number of descriptors parsed or -EINVAL
|
|
* if the header is contradictory beyond salvage
|
|
*/
|
|
|
|
int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr,
|
|
struct usb_interface *intf,
|
|
u8 *buffer,
|
|
int buflen)
|
|
{
|
|
/* duplicates are ignored */
|
|
struct usb_cdc_union_desc *union_header = NULL;
|
|
|
|
/* duplicates are not tolerated */
|
|
struct usb_cdc_header_desc *header = NULL;
|
|
struct usb_cdc_ether_desc *ether = NULL;
|
|
struct usb_cdc_mdlm_detail_desc *detail = NULL;
|
|
struct usb_cdc_mdlm_desc *desc = NULL;
|
|
|
|
unsigned int elength;
|
|
int cnt = 0;
|
|
|
|
memset(hdr, 0x00, sizeof(struct usb_cdc_parsed_header));
|
|
hdr->phonet_magic_present = false;
|
|
while (buflen > 0) {
|
|
elength = buffer[0];
|
|
if (!elength) {
|
|
dev_err(&intf->dev, "skipping garbage byte\n");
|
|
elength = 1;
|
|
goto next_desc;
|
|
}
|
|
if ((buflen < elength) || (elength < 3)) {
|
|
dev_err(&intf->dev, "invalid descriptor buffer length\n");
|
|
break;
|
|
}
|
|
if (buffer[1] != USB_DT_CS_INTERFACE) {
|
|
dev_err(&intf->dev, "skipping garbage\n");
|
|
goto next_desc;
|
|
}
|
|
|
|
switch (buffer[2]) {
|
|
case USB_CDC_UNION_TYPE: /* we've found it */
|
|
if (elength < sizeof(struct usb_cdc_union_desc))
|
|
goto next_desc;
|
|
if (union_header) {
|
|
dev_err(&intf->dev, "More than one union descriptor, skipping ...\n");
|
|
goto next_desc;
|
|
}
|
|
union_header = (struct usb_cdc_union_desc *)buffer;
|
|
break;
|
|
case USB_CDC_COUNTRY_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_country_functional_desc))
|
|
goto next_desc;
|
|
hdr->usb_cdc_country_functional_desc =
|
|
(struct usb_cdc_country_functional_desc *)buffer;
|
|
break;
|
|
case USB_CDC_HEADER_TYPE:
|
|
if (elength != sizeof(struct usb_cdc_header_desc))
|
|
goto next_desc;
|
|
if (header)
|
|
return -EINVAL;
|
|
header = (struct usb_cdc_header_desc *)buffer;
|
|
break;
|
|
case USB_CDC_ACM_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_acm_descriptor))
|
|
goto next_desc;
|
|
hdr->usb_cdc_acm_descriptor =
|
|
(struct usb_cdc_acm_descriptor *)buffer;
|
|
break;
|
|
case USB_CDC_ETHERNET_TYPE:
|
|
if (elength != sizeof(struct usb_cdc_ether_desc))
|
|
goto next_desc;
|
|
if (ether)
|
|
return -EINVAL;
|
|
ether = (struct usb_cdc_ether_desc *)buffer;
|
|
break;
|
|
case USB_CDC_CALL_MANAGEMENT_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_call_mgmt_descriptor))
|
|
goto next_desc;
|
|
hdr->usb_cdc_call_mgmt_descriptor =
|
|
(struct usb_cdc_call_mgmt_descriptor *)buffer;
|
|
break;
|
|
case USB_CDC_DMM_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_dmm_desc))
|
|
goto next_desc;
|
|
hdr->usb_cdc_dmm_desc =
|
|
(struct usb_cdc_dmm_desc *)buffer;
|
|
break;
|
|
case USB_CDC_MDLM_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_mdlm_desc *))
|
|
goto next_desc;
|
|
if (desc)
|
|
return -EINVAL;
|
|
desc = (struct usb_cdc_mdlm_desc *)buffer;
|
|
break;
|
|
case USB_CDC_MDLM_DETAIL_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_mdlm_detail_desc *))
|
|
goto next_desc;
|
|
if (detail)
|
|
return -EINVAL;
|
|
detail = (struct usb_cdc_mdlm_detail_desc *)buffer;
|
|
break;
|
|
case USB_CDC_NCM_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_ncm_desc))
|
|
goto next_desc;
|
|
hdr->usb_cdc_ncm_desc = (struct usb_cdc_ncm_desc *)buffer;
|
|
break;
|
|
case USB_CDC_MBIM_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_mbim_desc))
|
|
goto next_desc;
|
|
|
|
hdr->usb_cdc_mbim_desc = (struct usb_cdc_mbim_desc *)buffer;
|
|
break;
|
|
case USB_CDC_MBIM_EXTENDED_TYPE:
|
|
if (elength < sizeof(struct usb_cdc_mbim_extended_desc))
|
|
break;
|
|
hdr->usb_cdc_mbim_extended_desc =
|
|
(struct usb_cdc_mbim_extended_desc *)buffer;
|
|
break;
|
|
case CDC_PHONET_MAGIC_NUMBER:
|
|
hdr->phonet_magic_present = true;
|
|
break;
|
|
default:
|
|
/*
|
|
* there are LOTS more CDC descriptors that
|
|
* could legitimately be found here.
|
|
*/
|
|
dev_dbg(&intf->dev, "Ignoring descriptor: type %02x, length %ud\n",
|
|
buffer[2], elength);
|
|
goto next_desc;
|
|
}
|
|
cnt++;
|
|
next_desc:
|
|
buflen -= elength;
|
|
buffer += elength;
|
|
}
|
|
hdr->usb_cdc_union_desc = union_header;
|
|
hdr->usb_cdc_header_desc = header;
|
|
hdr->usb_cdc_mdlm_detail_desc = detail;
|
|
hdr->usb_cdc_mdlm_desc = desc;
|
|
hdr->usb_cdc_ether_desc = ether;
|
|
return cnt;
|
|
}
|
|
|
|
EXPORT_SYMBOL(cdc_parse_cdc_header);
|