Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (148 commits)
USB: serial: fix stalled writes
USB: remove fake "address-of" expressions
USB: fix thread-unsafe anchor utiliy routines
USB: usbtest: support test device with only one iso-in or iso-out endpoint
USB: usbtest: avoid to free coherent buffer in atomic context
USB: xhci: Set DMA mask for host.
USB: xhci: Don't flush doorbell writes.
USB: xhci: Reduce reads and writes of interrupter registers.
USB: xhci: Make xhci_set_hc_event_deq() static.
USB: xhci: Minimize HW event ring dequeue pointer writes.
USB: xhci: Make xhci_handle_event() static.
USB: xhci: Remove unnecessary reads of IRQ_PENDING register.
USB: xhci: Performance - move xhci_work() into xhci_irq()
USB: xhci: Performance - move interrupt handlers into xhci-ring.c
USB: xhci: Performance - move functions that find ep ring.
USB:: fix linux/usb.h kernel-doc warnings
USB: add USB serial ssu100 driver
USB: usb-storage: implement autosuspend
USB: ehci: fix remove of ehci debugfs dir
USB: Add USB 2.0 to ssb ohci driver
...

+5024 -2131
+12
Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
··· 7 7 0 -> resumed 8 8 9 9 (_UDC_ is the name of the USB Device Controller driver) 10 + 11 + What: /sys/devices/platform/_UDC_/gadget/gadget-lunX/nofua 12 + Date: July 2010 13 + Contact: Andy Shevchenko <andy.shevchenko@gmail.com> 14 + Description: 15 + Show or set the reaction on the FUA (Force Unit Access) bit in 16 + the SCSI WRITE(10,12) commands when a gadget in USB Mass 17 + Storage mode. 18 + 19 + Possible values are: 20 + 1 -> ignore the FUA flag 21 + 0 -> obey the FUA flag
+1 -1
Documentation/usb/ehci.txt
··· 9 9 - "Low Speed" 1.5 Mbit/sec 10 10 11 11 USB 1.1 only addressed full speed and low speed. High speed devices 12 - can be used on USB 1.1 systems, but they slow down to USB 1.1 speeds. 12 + can be used on USB 1.1 systems, but they slow down to USB 1.1 speeds. 13 13 14 14 USB 1.1 devices may also be used on USB 2.0 systems. When plugged 15 15 into an EHCI controller, they are given to a USB 1.1 "companion"
+150
Documentation/usb/gadget_multi.txt
··· 1 + -*- org -*- 2 + 3 + * Overview 4 + 5 + The Multifunction Composite Gadget (or g_multi) is a composite gadget 6 + that makes extensive use of the composite framework to provide 7 + a... multifunction gadget. 8 + 9 + In it's standard configuration it provides a single USB configuration 10 + with RNDIS[1] (that is Ethernet), USB CDC[2] ACM (that is serial) and 11 + USB Mass Storage functions. 12 + 13 + A CDC ECM (Ethernet) function may be turned on via a Kconfig option 14 + and RNDIS can be turned off. If they are both enabled the gadget will 15 + have two configurations -- one with RNDIS and another with CDC ECM[3]. 16 + 17 + Please not that if you use non-standard configuration (that is enable 18 + CDC ECM) you may need to change vendor and/or product ID. 19 + 20 + * Host drivers 21 + 22 + To make use of the gadget one needs to make it work on host side -- 23 + without that there's no hope of achieving anything with the gadget. 24 + As one might expect, things one need to do very from system to system. 25 + 26 + ** Linux host drivers 27 + 28 + Since the gadget uses standard composite framework and appears as such 29 + to Linux host it does not need any additional drivers on Linux host 30 + side. All the functions are handled by respective drivers developed 31 + for them. 32 + 33 + This is also true for two configuration set-up with RNDIS 34 + configuration being the first one. Linux host will use the second 35 + configuration with CDC ECM which should work better under Linux. 36 + 37 + ** Windows host drivers 38 + 39 + For the gadget two work under Windows two conditions have to be met: 40 + 41 + *** Detecting as composite gadget 42 + 43 + First of all, Windows need to detect the gadget as an USB composite 44 + gadget which on its own have some conditions[4]. If they are met, 45 + Windows lets USB Generic Parent Driver[5] handle the device which then 46 + tries to much drivers for each individual interface (sort of, don't 47 + get into too many details). 48 + 49 + The good news is: you do not have to worry about most of the 50 + conditions! 51 + 52 + The only thing to worry is that the gadget has to have a single 53 + configuration so a dual RNDIS and CDC ECM gadget won't work unless you 54 + create a proper INF -- and of course, if you do submit it! 55 + 56 + *** Installing drivers for each function 57 + 58 + The other, trickier thing is making Windows install drivers for each 59 + individual function. 60 + 61 + For mass storage it is trivial since Windows detect it's an interface 62 + implementing USB Mass Storage class and selects appropriate driver. 63 + 64 + Things are harder with RDNIS and CDC ACM. 65 + 66 + **** RNDIS 67 + 68 + To make Windows select RNDIS drivers for the first function in the 69 + gadget, one needs to use the [[file:linux.inf]] file provided with this 70 + document. It "attaches" Window's RNDIS driver to the first interface 71 + of the gadget. 72 + 73 + Please note, that while testing we encountered some issues[6] when 74 + RNDIS was not the first interface. You do not need to worry abut it 75 + unless you are trying to develop your own gadget in which case watch 76 + out for this bug. 77 + 78 + **** CDC ACM 79 + 80 + Similarly, [[file:linux-cdc-acm.inf]] is provided for CDC ACM. 81 + 82 + **** Customising the gadget 83 + 84 + If you intend to hack the g_multi gadget be advised that rearranging 85 + functions will obviously change interface numbers for each of the 86 + functionality. As an effect provided INFs won't work since they have 87 + interface numbers hard-coded in them (it's not hard to change those 88 + though[7]). 89 + 90 + This also means, that after experimenting with g_multi and changing 91 + provided functions one should change gadget's vendor and/or product ID 92 + so there will be no collision with other customised gadgets or the 93 + original gadget. 94 + 95 + Failing to comply may cause brain damage after wondering for hours why 96 + things don't work as intended before realising Windows have cached 97 + some drivers information (changing USB port may sometimes help plus 98 + you might try using USBDeview[8] to remove the phantom device). 99 + 100 + **** INF testing 101 + 102 + Provided INF files have been tested on Windows XP SP3, Windows Vista 103 + and Windows 7, all 32-bit versions. It should work on 64-bit versions 104 + as well. It most likely won't work on Windows prior to Windows XP 105 + SP2. 106 + 107 + ** Other systems 108 + 109 + At this moment, drivers for any other systems have not been tested. 110 + Knowing how MacOS is based on BSD and BSD is an Open Source it is 111 + believed that it should (read: "I have no idea whether it will") work 112 + out-of-the-box. 113 + 114 + For more exotic systems I have even less to say... 115 + 116 + Any testing and drivers *are* *welcome*! 117 + 118 + * Authors 119 + 120 + This document has been written by Michal Nazarewicz 121 + ([[mailto:mina86@mina86.com]]). INF files have been hacked with 122 + support of Marek Szyprowski ([[mailto:m.szyprowski@samsung.com]]) and 123 + Xiaofan Chen ([[mailto:xiaofanc@gmail.com]]) basing on the MS RNDIS 124 + template[9], Microchip's CDC ACM INF file and David Brownell's 125 + ([[mailto:dbrownell@users.sourceforge.net]]) original INF files. 126 + 127 + * Footnotes 128 + 129 + [1] Remote Network Driver Interface Specification, 130 + [[http://msdn.microsoft.com/en-us/library/ee484414.aspx]]. 131 + 132 + [2] Communications Device Class Abstract Control Model, spec for this 133 + and other USB classes can be found at 134 + [[http://www.usb.org/developers/devclass_docs/]]. 135 + 136 + [3] CDC Ethernet Control Model. 137 + 138 + [4] [[http://msdn.microsoft.com/en-us/library/ff537109(v=VS.85).aspx]] 139 + 140 + [5] [[http://msdn.microsoft.com/en-us/library/ff539234(v=VS.85).aspx]] 141 + 142 + [6] To put it in some other nice words, Windows failed to respond to 143 + any user input. 144 + 145 + [7] You may find [[http://www.cygnal.org/ubb/Forum9/HTML/001050.html]] 146 + useful. 147 + 148 + [8] http://www.nirsoft.net/utils/usb_devices_view.html 149 + 150 + [9] [[http://msdn.microsoft.com/en-us/library/ff570620.aspx]]
+10 -77
Documentation/usb/gadget_serial.txt
··· 151 151 152 152 Installing the Windows Host ACM Driver 153 153 -------------------------------------- 154 - To use the Windows ACM driver you must have the files "gserial.inf" 155 - and "usbser.sys" together in a folder on the Windows machine. 156 - 157 - The "gserial.inf" file is given here. 158 - 159 - -------------------- CUT HERE -------------------- 160 - [Version] 161 - Signature="$Windows NT$" 162 - Class=Ports 163 - ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 164 - Provider=%LINUX% 165 - DriverVer=08/17/2004,0.0.2.0 166 - ; Copyright (C) 2004 Al Borchers (alborchers@steinerpoint.com) 167 - 168 - [Manufacturer] 169 - %LINUX%=GSerialDeviceList 170 - 171 - [GSerialDeviceList] 172 - %GSERIAL%=GSerialInstall, USB\VID_0525&PID_A4A7 173 - 174 - [DestinationDirs] 175 - DefaultDestDir=10,System32\Drivers 176 - 177 - [GSerialInstall] 178 - CopyFiles=GSerialCopyFiles 179 - AddReg=GSerialAddReg 180 - 181 - [GSerialCopyFiles] 182 - usbser.sys 183 - 184 - [GSerialAddReg] 185 - HKR,,DevLoader,,*ntkern 186 - HKR,,NTMPDriver,,usbser.sys 187 - HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 188 - 189 - [GSerialInstall.Services] 190 - AddService = usbser,0x0002,GSerialService 191 - 192 - [GSerialService] 193 - DisplayName = %GSERIAL_DISPLAY_NAME% 194 - ServiceType = 1 ; SERVICE_KERNEL_DRIVER 195 - StartType = 3 ; SERVICE_DEMAND_START 196 - ErrorControl = 1 ; SERVICE_ERROR_NORMAL 197 - ServiceBinary = %10%\System32\Drivers\usbser.sys 198 - LoadOrderGroup = Base 199 - 200 - [Strings] 201 - LINUX = "Linux" 202 - GSERIAL = "Gadget Serial" 203 - GSERIAL_DISPLAY_NAME = "USB Gadget Serial Driver" 204 - -------------------- CUT HERE -------------------- 205 - 206 - The "usbser.sys" file comes with various versions of Windows. 207 - For example, it can be found on Windows XP typically in 208 - 209 - C:\WINDOWS\Driver Cache\i386\driver.cab 210 - 211 - Or it can be found on the Windows 98SE CD in the "win98" folder 212 - in the "DRIVER11.CAB" through "DRIVER20.CAB" cab files. You will 213 - need the DOS "expand" program, the Cygwin "cabextract" program, or 214 - a similar program to unpack these cab files and extract "usbser.sys". 215 - 216 - For example, to extract "usbser.sys" into the current directory 217 - on Windows XP, open a DOS window and run a command like 218 - 219 - expand C:\WINDOWS\Driver~1\i386\driver.cab -F:usbser.sys . 220 - 221 - (Thanks to Nishant Kamat for pointing out this DOS command.) 154 + To use the Windows ACM driver you must have the "linux-cdc-acm.inf" 155 + file (provided along this document) which supports all recent versions 156 + of Windows. 222 157 223 158 When the gadget serial driver is loaded and the USB device connected 224 159 to the Windows host with a USB cable, Windows should recognize the 225 160 gadget serial device and ask for a driver. Tell Windows to find the 226 - driver in the folder that contains "gserial.inf" and "usbser.sys". 161 + driver in the folder that contains the "linux-cdc-acm.inf" file. 227 162 228 163 For example, on Windows XP, when the gadget serial device is first 229 164 plugged in, the "Found New Hardware Wizard" starts up. Select 230 - "Install from a list or specific location (Advanced)", then on 231 - the next screen select "Include this location in the search" and 232 - enter the path or browse to the folder containing "gserial.inf" and 233 - "usbser.sys". Windows will complain that the Gadget Serial driver 234 - has not passed Windows Logo testing, but select "Continue anyway" 235 - and finish the driver installation. 165 + "Install from a list or specific location (Advanced)", then on the 166 + next screen select "Include this location in the search" and enter the 167 + path or browse to the folder containing the "linux-cdc-acm.inf" file. 168 + Windows will complain that the Gadget Serial driver has not passed 169 + Windows Logo testing, but select "Continue anyway" and finish the 170 + driver installation. 236 171 237 172 On Windows XP, in the "Device Manager" (under "Control Panel", 238 173 "System", "Hardware") expand the "Ports (COM & LPT)" entry and you ··· 280 345 side and host side systems. Anything you type on the terminal 281 346 window on the gadget side should appear in the terminal window on 282 347 the host side and vice versa. 283 - 284 -
+2 -2
Documentation/usb/hotplug.txt
··· 10 10 11 11 - Bind a driver to that device. Bus frameworks do that using a 12 12 device driver's probe() routine. 13 - 13 + 14 14 - Tell other subsystems to configure the new device. Print 15 15 queues may need to be enabled, networks brought up, disk 16 16 partitions mounted, and so on. In some cases these will ··· 84 84 Current versions of module-init-tools will create a "modules.usbmap" file 85 85 which contains the entries from each driver's MODULE_DEVICE_TABLE. Such 86 86 files can be used by various user mode policy agents to make sure all the 87 - right driver modules get loaded, either at boot time or later. 87 + right driver modules get loaded, either at boot time or later. 88 88 89 89 See <linux/usb.h> for full information about such table entries; or look 90 90 at existing drivers. Each table entry describes one or more criteria to
+107
Documentation/usb/linux-cdc-acm.inf
··· 1 + ; Windows USB CDC ACM Setup File 2 + 3 + ; Based on INF template which was: 4 + ; Copyright (c) 2000 Microsoft Corporation 5 + ; Copyright (c) 2007 Microchip Technology Inc. 6 + ; likely to be covered by the MLPL as found at: 7 + ; <http://msdn.microsoft.com/en-us/cc300389.aspx#MLPL>. 8 + ; For use only on Windows operating systems. 9 + 10 + [Version] 11 + Signature="$Windows NT$" 12 + Class=Ports 13 + ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 14 + Provider=%Linux% 15 + DriverVer=11/15/2007,5.1.2600.0 16 + 17 + [Manufacturer] 18 + %Linux%=DeviceList, NTamd64 19 + 20 + [DestinationDirs] 21 + DefaultDestDir=12 22 + 23 + 24 + ;------------------------------------------------------------------------------ 25 + ; Windows 2000/XP/Vista-32bit Sections 26 + ;------------------------------------------------------------------------------ 27 + 28 + [DriverInstall.nt] 29 + include=mdmcpq.inf 30 + CopyFiles=DriverCopyFiles.nt 31 + AddReg=DriverInstall.nt.AddReg 32 + 33 + [DriverCopyFiles.nt] 34 + usbser.sys,,,0x20 35 + 36 + [DriverInstall.nt.AddReg] 37 + HKR,,DevLoader,,*ntkern 38 + HKR,,NTMPDriver,,USBSER.sys 39 + HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 40 + 41 + [DriverInstall.nt.Services] 42 + AddService=usbser, 0x00000002, DriverService.nt 43 + 44 + [DriverService.nt] 45 + DisplayName=%SERVICE% 46 + ServiceType=1 47 + StartType=3 48 + ErrorControl=1 49 + ServiceBinary=%12%\USBSER.sys 50 + 51 + ;------------------------------------------------------------------------------ 52 + ; Vista-64bit Sections 53 + ;------------------------------------------------------------------------------ 54 + 55 + [DriverInstall.NTamd64] 56 + include=mdmcpq.inf 57 + CopyFiles=DriverCopyFiles.NTamd64 58 + AddReg=DriverInstall.NTamd64.AddReg 59 + 60 + [DriverCopyFiles.NTamd64] 61 + USBSER.sys,,,0x20 62 + 63 + [DriverInstall.NTamd64.AddReg] 64 + HKR,,DevLoader,,*ntkern 65 + HKR,,NTMPDriver,,USBSER.sys 66 + HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 67 + 68 + [DriverInstall.NTamd64.Services] 69 + AddService=usbser, 0x00000002, DriverService.NTamd64 70 + 71 + [DriverService.NTamd64] 72 + DisplayName=%SERVICE% 73 + ServiceType=1 74 + StartType=3 75 + ErrorControl=1 76 + ServiceBinary=%12%\USBSER.sys 77 + 78 + 79 + ;------------------------------------------------------------------------------ 80 + ; Vendor and Product ID Definitions 81 + ;------------------------------------------------------------------------------ 82 + ; When developing your USB device, the VID and PID used in the PC side 83 + ; application program and the firmware on the microcontroller must match. 84 + ; Modify the below line to use your VID and PID. Use the format as shown 85 + ; below. 86 + ; Note: One INF file can be used for multiple devices with different 87 + ; VID and PIDs. For each supported device, append 88 + ; ",USB\VID_xxxx&PID_yyyy" to the end of the line. 89 + ;------------------------------------------------------------------------------ 90 + [SourceDisksFiles] 91 + [SourceDisksNames] 92 + [DeviceList] 93 + %DESCRIPTION%=DriverInstall, USB\VID_0525&PID_A4A7, USB\VID_0525&PID_A4AB&MI_02 94 + 95 + [DeviceList.NTamd64] 96 + %DESCRIPTION%=DriverInstall, USB\VID_0525&PID_A4A7, USB\VID_0525&PID_A4AB&MI_02 97 + 98 + 99 + ;------------------------------------------------------------------------------ 100 + ; String Definitions 101 + ;------------------------------------------------------------------------------ 102 + ;Modify these strings to customize your device 103 + ;------------------------------------------------------------------------------ 104 + [Strings] 105 + Linux = "Linux Developer Community" 106 + DESCRIPTION = "Gadget Serial" 107 + SERVICE = "USB RS-232 Emulation Driver"
+44 -178
Documentation/usb/linux.inf
··· 1 - ; MS-Windows driver config matching some basic modes of the 2 - ; Linux-USB Ethernet/RNDIS gadget firmware: 3 - ; 4 - ; - RNDIS plus CDC Ethernet ... this may be familiar as a DOCSIS 5 - ; cable modem profile, and supports most non-Microsoft USB hosts 6 - ; 7 - ; - RNDIS plus CDC Subset ... used by hardware that incapable of 8 - ; full CDC Ethernet support. 9 - ; 10 - ; Microsoft only directly supports RNDIS drivers, and bundled them into XP. 11 - ; The Microsoft "Remote NDIS USB Driver Kit" is currently found at: 12 - ; http://www.microsoft.com/whdc/device/network/ndis/rmndis.mspx 13 - 1 + ; Based on template INF file found at 2 + ; <http://msdn.microsoft.com/en-us/library/ff570620.aspx> 3 + ; which was: 4 + ; Copyright (c) Microsoft Corporation 5 + ; and released under the MLPL as found at: 6 + ; <http://msdn.microsoft.com/en-us/cc300389.aspx#MLPL>. 7 + ; For use only on Windows operating systems. 14 8 15 9 [Version] 16 - Signature = "$CHICAGO$" 10 + Signature = "$Windows NT$" 17 11 Class = Net 18 12 ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318} 19 13 Provider = %Linux% 20 - Compatible = 1 21 - MillenniumPreferred = .ME 22 - DriverVer = 03/30/2004,0.0.0.0 23 - ; catalog file would be used by WHQL 24 - ;CatalogFile = Linux.cat 14 + DriverVer = 06/21/2006,6.0.6000.16384 25 15 26 16 [Manufacturer] 27 - %Linux% = LinuxDevices,NT.5.1 17 + %Linux% = LinuxDevices,NTx86,NTamd64,NTia64 28 18 29 - [LinuxDevices] 30 - ; NetChip IDs, used by both firmware modes 31 - %LinuxDevice% = RNDIS, USB\VID_0525&PID_a4a2 19 + ; Decoration for x86 architecture 20 + [LinuxDevices.NTx86] 21 + %LinuxDevice% = RNDIS.NT.5.1, USB\VID_0525&PID_a4a2, USB\VID_0525&PID_a4ab&MI_00 32 22 33 - [LinuxDevices.NT.5.1] 34 - %LinuxDevice% = RNDIS.NT.5.1, USB\VID_0525&PID_a4a2 23 + ; Decoration for x64 architecture 24 + [LinuxDevices.NTamd64] 25 + %LinuxDevice% = RNDIS.NT.5.1, USB\VID_0525&PID_a4a2, USB\VID_0525&PID_a4ab&MI_00 35 26 27 + ; Decoration for ia64 architecture 28 + [LinuxDevices.NTia64] 29 + %LinuxDevice% = RNDIS.NT.5.1, USB\VID_0525&PID_a4a2, USB\VID_0525&PID_a4ab&MI_00 30 + 31 + ;@@@ This is the common setting for setup 36 32 [ControlFlags] 37 33 ExcludeFromSelect=* 38 34 39 - ; Windows 98, Windows 98 Second Edition specific sections -------- 40 - 41 - [RNDIS] 42 - DeviceID = usb8023 43 - MaxInstance = 512 44 - DriverVer = 03/30/2004,0.0.0.0 45 - AddReg = RNDIS_AddReg_98, RNDIS_AddReg_Common 46 - 47 - [RNDIS_AddReg_98] 48 - HKR, , DevLoader, 0, *ndis 49 - HKR, , DeviceVxDs, 0, usb8023.sys 50 - HKR, NDIS, LogDriverName, 0, "usb8023" 51 - HKR, NDIS, MajorNdisVersion, 1, 5 52 - HKR, NDIS, MinorNdisVersion, 1, 0 53 - HKR, Ndi\Interfaces, DefUpper, 0, "ndis3,ndis4,ndis5" 54 - HKR, Ndi\Interfaces, DefLower, 0, "ethernet" 55 - HKR, Ndi\Interfaces, UpperRange, 0, "ndis3,ndis4,ndis5" 56 - HKR, Ndi\Interfaces, LowerRange, 0, "ethernet" 57 - HKR, Ndi\Install, ndis3, 0, "RNDIS_Install_98" 58 - HKR, Ndi\Install, ndis4, 0, "RNDIS_Install_98" 59 - HKR, Ndi\Install, ndis5, 0, "RNDIS_Install_98" 60 - HKR, Ndi, DeviceId, 0, "USB\VID_0525&PID_a4a2" 61 - 62 - [RNDIS_Install_98] 63 - CopyFiles=RNDIS_CopyFiles_98 64 - 65 - [RNDIS_CopyFiles_98] 66 - usb8023.sys, usb8023w.sys, , 0 67 - rndismp.sys, rndismpw.sys, , 0 68 - 69 - ; Windows Millennium Edition specific sections -------------------- 70 - 71 - [RNDIS.ME] 72 - DeviceID = usb8023 73 - MaxInstance = 512 74 - DriverVer = 03/30/2004,0.0.0.0 75 - AddReg = RNDIS_AddReg_ME, RNDIS_AddReg_Common 76 - Characteristics = 0x84 ; NCF_PHYSICAL + NCF_HAS_UI 77 - BusType = 15 78 - 79 - [RNDIS_AddReg_ME] 80 - HKR, , DevLoader, 0, *ndis 81 - HKR, , DeviceVxDs, 0, usb8023.sys 82 - HKR, NDIS, LogDriverName, 0, "usb8023" 83 - HKR, NDIS, MajorNdisVersion, 1, 5 84 - HKR, NDIS, MinorNdisVersion, 1, 0 85 - HKR, Ndi\Interfaces, DefUpper, 0, "ndis3,ndis4,ndis5" 86 - HKR, Ndi\Interfaces, DefLower, 0, "ethernet" 87 - HKR, Ndi\Interfaces, UpperRange, 0, "ndis3,ndis4,ndis5" 88 - HKR, Ndi\Interfaces, LowerRange, 0, "ethernet" 89 - HKR, Ndi\Install, ndis3, 0, "RNDIS_Install_ME" 90 - HKR, Ndi\Install, ndis4, 0, "RNDIS_Install_ME" 91 - HKR, Ndi\Install, ndis5, 0, "RNDIS_Install_ME" 92 - HKR, Ndi, DeviceId, 0, "USB\VID_0525&PID_a4a2" 93 - 94 - [RNDIS_Install_ME] 95 - CopyFiles=RNDIS_CopyFiles_ME 96 - 97 - [RNDIS_CopyFiles_ME] 98 - usb8023.sys, usb8023m.sys, , 0 99 - rndismp.sys, rndismpm.sys, , 0 100 - 101 - ; Windows 2000 specific sections --------------------------------- 102 - 103 - [RNDIS.NT] 104 - Characteristics = 0x84 ; NCF_PHYSICAL + NCF_HAS_UI 105 - BusType = 15 106 - DriverVer = 03/30/2004,0.0.0.0 107 - AddReg = RNDIS_AddReg_NT, RNDIS_AddReg_Common 108 - CopyFiles = RNDIS_CopyFiles_NT 109 - 110 - [RNDIS.NT.Services] 111 - AddService = USB_RNDIS, 2, RNDIS_ServiceInst_NT, RNDIS_EventLog 112 - 113 - [RNDIS_CopyFiles_NT] 114 - ; no rename of files on Windows 2000, use the 'k' names as is 115 - usb8023k.sys, , , 0 116 - rndismpk.sys, , , 0 117 - 118 - [RNDIS_ServiceInst_NT] 119 - DisplayName = %ServiceDisplayName% 120 - ServiceType = 1 121 - StartType = 3 122 - ErrorControl = 1 123 - ServiceBinary = %12%\usb8023k.sys 124 - LoadOrderGroup = NDIS 125 - AddReg = RNDIS_WMI_AddReg_NT 126 - 127 - [RNDIS_WMI_AddReg_NT] 128 - HKR, , MofImagePath, 0x00020000, "System32\drivers\rndismpk.sys" 129 - 130 - ; Windows XP specific sections ----------------------------------- 131 - 35 + ; DDInstall section 36 + ; References the in-build Netrndis.inf 132 37 [RNDIS.NT.5.1] 133 - Characteristics = 0x84 ; NCF_PHYSICAL + NCF_HAS_UI 134 - BusType = 15 135 - DriverVer = 03/30/2004,0.0.0.0 136 - AddReg = RNDIS_AddReg_NT, RNDIS_AddReg_Common 137 - ; no copyfiles - the files are already in place 38 + Characteristics = 0x84 ; NCF_PHYSICAL + NCF_HAS_UI 39 + BusType = 15 40 + ; NEVER REMOVE THE FOLLOWING REFERENCE FOR NETRNDIS.INF 41 + include = netrndis.inf 42 + needs = Usb_Rndis.ndi 43 + AddReg = Rndis_AddReg_Vista 138 44 45 + ; DDInstal.Services section 139 46 [RNDIS.NT.5.1.Services] 140 - AddService = USB_RNDIS, 2, RNDIS_ServiceInst_51, RNDIS_EventLog 47 + include = netrndis.inf 48 + needs = Usb_Rndis.ndi.Services 141 49 142 - [RNDIS_ServiceInst_51] 143 - DisplayName = %ServiceDisplayName% 144 - ServiceType = 1 145 - StartType = 3 146 - ErrorControl = 1 147 - ServiceBinary = %12%\usb8023.sys 148 - LoadOrderGroup = NDIS 149 - AddReg = RNDIS_WMI_AddReg_51 50 + ; Optional registry settings. You can modify as needed. 51 + [RNDIS_AddReg_Vista] 52 + HKR, NDI\params\VistaProperty, ParamDesc, 0, %Vista_Property% 53 + HKR, NDI\params\VistaProperty, type, 0, "edit" 54 + HKR, NDI\params\VistaProperty, LimitText, 0, "12" 55 + HKR, NDI\params\VistaProperty, UpperCase, 0, "1" 56 + HKR, NDI\params\VistaProperty, default, 0, " " 57 + HKR, NDI\params\VistaProperty, optional, 0, "1" 150 58 151 - [RNDIS_WMI_AddReg_51] 152 - HKR, , MofImagePath, 0x00020000, "System32\drivers\rndismp.sys" 153 - 154 - ; Windows 2000 and Windows XP common sections -------------------- 155 - 156 - [RNDIS_AddReg_NT] 157 - HKR, Ndi, Service, 0, "USB_RNDIS" 158 - HKR, Ndi\Interfaces, UpperRange, 0, "ndis5" 159 - HKR, Ndi\Interfaces, LowerRange, 0, "ethernet" 160 - 161 - [RNDIS_EventLog] 162 - AddReg = RNDIS_EventLog_AddReg 163 - 164 - [RNDIS_EventLog_AddReg] 165 - HKR, , EventMessageFile, 0x00020000, "%%SystemRoot%%\System32\netevent.dll" 166 - HKR, , TypesSupported, 0x00010001, 7 167 - 168 - ; Common Sections ------------------------------------------------- 169 - 170 - [RNDIS_AddReg_Common] 171 - HKR, NDI\params\NetworkAddress, ParamDesc, 0, %NetworkAddress% 172 - HKR, NDI\params\NetworkAddress, type, 0, "edit" 173 - HKR, NDI\params\NetworkAddress, LimitText, 0, "12" 174 - HKR, NDI\params\NetworkAddress, UpperCase, 0, "1" 175 - HKR, NDI\params\NetworkAddress, default, 0, " " 176 - HKR, NDI\params\NetworkAddress, optional, 0, "1" 177 - 178 - [SourceDisksNames] 179 - 1=%SourceDisk%,,1 180 - 181 - [SourceDisksFiles] 182 - usb8023m.sys=1 183 - rndismpm.sys=1 184 - usb8023w.sys=1 185 - rndismpw.sys=1 186 - usb8023k.sys=1 187 - rndismpk.sys=1 188 - 189 - [DestinationDirs] 190 - RNDIS_CopyFiles_98 = 10, system32/drivers 191 - RNDIS_CopyFiles_ME = 10, system32/drivers 192 - RNDIS_CopyFiles_NT = 12 59 + ; No sys copyfiles - the sys files are already in-build 60 + ; (part of the operating system). 61 + ; We do not support XP SP1-, 2003 SP1-, ME, 9x. 193 62 194 63 [Strings] 195 - ServiceDisplayName = "USB Remote NDIS Network Device Driver" 196 - NetworkAddress = "Network Address" 197 64 Linux = "Linux Developer Community" 198 65 LinuxDevice = "Linux USB Ethernet/RNDIS Gadget" 199 - SourceDisk = "Ethernet/RNDIS Gadget Driver Install Disk" 200 - 66 + Vista_Property = "Optional Vista Property"
+2 -2
arch/arm/mach-mx3/mach-armadillo5x0.c
··· 551 551 /* USB */ 552 552 #if defined(CONFIG_USB_ULPI) 553 553 usbotg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 554 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 554 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 555 555 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 556 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 556 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 557 557 558 558 mxc_register_device(&mxc_otg_host, &usbotg_pdata); 559 559 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
+2 -2
arch/arm/mach-mx3/mach-mx31lilly.c
··· 245 245 static void lilly1131_usb_init(void) 246 246 { 247 247 usbotg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 248 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 248 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 249 249 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 250 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 250 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 251 251 252 252 mxc_register_device(&mxc_usbh1, &usbh1_pdata); 253 253 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
+1 -1
arch/arm/mach-mx3/mach-mx31lite.c
··· 256 256 #if defined(CONFIG_USB_ULPI) 257 257 /* USB */ 258 258 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 259 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 259 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 260 260 261 261 mxc_register_device(&mxc_usbh2, &usbh2_pdata); 262 262 #endif
+1 -1
arch/arm/mach-mx3/mach-mx31moboard.c
··· 412 412 static int __init moboard_usbh2_init(void) 413 413 { 414 414 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 415 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 415 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 416 416 417 417 return mxc_register_device(&mxc_usbh2, &usbh2_pdata); 418 418 }
+2 -2
arch/arm/mach-mx3/mach-pcm037.c
··· 654 654 #if defined(CONFIG_USB_ULPI) 655 655 if (otg_mode_host) { 656 656 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 657 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 657 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 658 658 659 659 mxc_register_device(&mxc_otg_host, &otg_pdata); 660 660 } 661 661 662 662 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 663 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 663 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 664 664 665 665 mxc_register_device(&mxc_usbh2, &usbh2_pdata); 666 666 #endif
+1 -1
arch/arm/mach-mx3/mach-pcm043.c
··· 378 378 #if defined(CONFIG_USB_ULPI) 379 379 if (otg_mode_host) { 380 380 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 381 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 381 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 382 382 383 383 mxc_register_device(&mxc_otg_host, &otg_pdata); 384 384 }
+1 -1
arch/arm/mach-mx3/mx31moboard-smartbot.c
··· 134 134 static int __init smartbot_otg_host_init(void) 135 135 { 136 136 otg_host_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops, 137 - USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT); 137 + ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); 138 138 139 139 return mxc_register_device(&mxc_otg_host, &otg_host_pdata); 140 140 }
+2
arch/arm/plat-samsung/include/plat/regs-usb-hsotg.h
··· 226 226 227 227 #define S3C_DIEPMSK S3C_HSOTG_REG(0x810) 228 228 229 + #define S3C_DIEPMSK_TxFIFOEmpty (1 << 7) 229 230 #define S3C_DIEPMSK_INEPNakEffMsk (1 << 6) 230 231 #define S3C_DIEPMSK_INTknEPMisMsk (1 << 5) 231 232 #define S3C_DIEPMSK_INTknTXFEmpMsk (1 << 4) ··· 372 371 373 372 #define S3C_DIEPDMA(_a) S3C_HSOTG_REG(0x914 + ((_a) * 0x20)) 374 373 #define S3C_DOEPDMA(_a) S3C_HSOTG_REG(0xB14 + ((_a) * 0x20)) 374 + #define S3C_DTXFSTS(_a) S3C_HSOTG_REG(0x918 + ((_a) * 0x20)) 375 375 376 376 #define S3C_EPFIFO(_a) S3C_HSOTG_REG(0x1000 + ((_a) * 0x1000)) 377 377
+3 -3
drivers/staging/usbip/vhci_hcd.c
··· 215 215 vhci = hcd_to_vhci(hcd); 216 216 217 217 spin_lock_irqsave(&vhci->lock, flags); 218 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 218 + if (!HCD_HW_ACCESSIBLE(hcd)) { 219 219 usbip_dbg_vhci_rh("hw accessible flag in on?\n"); 220 220 goto done; 221 221 } ··· 269 269 270 270 u32 prev_port_status[VHCI_NPORTS]; 271 271 272 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 272 + if (!HCD_HW_ACCESSIBLE(hcd)) 273 273 return -ETIMEDOUT; 274 274 275 275 /* ··· 1041 1041 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); 1042 1042 1043 1043 spin_lock_irq(&vhci->lock); 1044 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1044 + if (!HCD_HW_ACCESSIBLE(hcd)) { 1045 1045 rc = -ESHUTDOWN; 1046 1046 } else { 1047 1047 /* vhci->rh_state = DUMMY_RH_RUNNING;
+1 -1
drivers/usb/Makefile
··· 41 41 obj-$(CONFIG_USB_SERIAL) += serial/ 42 42 43 43 obj-$(CONFIG_USB) += misc/ 44 - obj-y += early/ 44 + obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ 45 45 46 46 obj-$(CONFIG_USB_ATM) += atm/ 47 47 obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
+5 -6
drivers/usb/atm/cxacru.c
··· 564 564 } 565 565 566 566 static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, 567 - int* actual_length) 567 + int *actual_length) 568 568 { 569 569 struct timer_list timer; 570 570 ··· 952 952 put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb)); 953 953 offb += 4; 954 954 addr += l; 955 - if(l) 955 + if (l) 956 956 memcpy(buf + offb, data + offd, l); 957 957 if (l < stride) 958 958 memset(buf + offb + l, 0, stride - l); ··· 967 967 } 968 968 offb = 0; 969 969 } 970 - } while(offd < size); 970 + } while (offd < size); 971 971 dbg("sent fw %#x", fw); 972 972 973 973 ret = 0; ··· 1043 1043 if (instance->modem_type->boot_rom_patch) { 1044 1044 val = cpu_to_le32(BR_ADDR); 1045 1045 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4); 1046 - } 1047 - else { 1046 + } else { 1048 1047 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0); 1049 1048 } 1050 1049 if (ret) { ··· 1067 1068 } 1068 1069 1069 1070 static int cxacru_find_firmware(struct cxacru_data *instance, 1070 - char* phase, const struct firmware **fw_p) 1071 + char *phase, const struct firmware **fw_p) 1071 1072 { 1072 1073 struct usbatm_data *usbatm = instance->usbatm; 1073 1074 struct device *dev = &usbatm->usb_intf->dev;
+6 -4
drivers/usb/atm/speedtch.c
··· 753 753 .id_table = speedtch_usb_ids 754 754 }; 755 755 756 - static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { 756 + static void speedtch_release_interfaces(struct usb_device *usb_dev, 757 + int num_interfaces) 758 + { 757 759 struct usb_interface *cur_intf; 758 760 int i; 759 761 760 - for(i = 0; i < num_interfaces; i++) 762 + for (i = 0; i < num_interfaces; i++) 761 763 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { 762 764 usb_set_intfdata(cur_intf, NULL); 763 765 usb_driver_release_interface(&speedtch_usb_driver, cur_intf); ··· 794 792 795 793 /* claim all interfaces */ 796 794 797 - for (i=0; i < num_interfaces; i++) { 795 + for (i = 0; i < num_interfaces; i++) { 798 796 cur_intf = usb_ifnum_to_if(usb_dev, i); 799 797 800 798 if ((i != ifnum) && cur_intf) { ··· 844 842 845 843 use_isoc = 0; /* fall back to bulk if endpoint not found */ 846 844 847 - for (i=0; i<desc->desc.bNumEndpoints; i++) { 845 + for (i = 0; i < desc->desc.bNumEndpoints; i++) { 848 846 const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc; 849 847 850 848 if ((endpoint_desc->bEndpointAddress == target_address)) {
+3 -2
drivers/usb/atm/ueagle-atm.c
··· 67 67 #include <linux/mutex.h> 68 68 #include <linux/freezer.h> 69 69 #include <linux/slab.h> 70 + #include <linux/kernel.h> 70 71 71 72 #include <asm/unaligned.h> 72 73 ··· 2437 2436 2438 2437 /* Retrieve the device End System Identifier (MAC) */ 2439 2438 2440 - #define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10) 2441 2439 static int uea_getesi(struct uea_softc *sc, u_char * esi) 2442 2440 { 2443 2441 unsigned char mac_str[2 * ETH_ALEN + 1]; ··· 2447 2447 return 1; 2448 2448 2449 2449 for (i = 0; i < ETH_ALEN; i++) 2450 - esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]); 2450 + esi[i] = hex_to_bin(mac_str[2 * i]) * 16 + 2451 + hex_to_bin(mac_str[2 * i + 1]); 2451 2452 2452 2453 return 0; 2453 2454 }
+10 -13
drivers/usb/atm/usbatm.c
··· 84 84 85 85 #ifdef VERBOSE_DEBUG 86 86 static int usbatm_print_packet(const unsigned char *data, int len); 87 - #define PACKETDEBUG(arg...) usbatm_print_packet (arg) 88 - #define vdbg(arg...) dbg (arg) 87 + #define PACKETDEBUG(arg...) usbatm_print_packet(arg) 88 + #define vdbg(arg...) dbg(arg) 89 89 #else 90 90 #define PACKETDEBUG(arg...) 91 91 #define vdbg(arg...) ··· 273 273 274 274 if (unlikely(status) && 275 275 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || 276 - status != -EILSEQ )) 277 - { 276 + status != -EILSEQ)) { 278 277 if (status == -ESHUTDOWN) 279 278 return; 280 279 ··· 493 494 ptr += data_len; 494 495 __skb_pull(skb, data_len); 495 496 496 - if(!left) 497 + if (!left) 497 498 continue; 498 499 499 500 memset(ptr, 0, left); ··· 505 506 trailer[2] = ctrl->len >> 8; 506 507 trailer[3] = ctrl->len; 507 508 508 - ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4); 509 + ctrl->crc = ~crc32_be(ctrl->crc, ptr, left - 4); 509 510 510 511 trailer[4] = ctrl->crc >> 24; 511 512 trailer[5] = ctrl->crc >> 16; ··· 515 516 target[3] |= 0x2; /* adjust PTI */ 516 517 517 518 ctrl->len = 0; /* tag this skb finished */ 518 - } 519 - else 519 + } else 520 520 ctrl->crc = crc32_be(ctrl->crc, ptr, left); 521 521 } 522 522 ··· 1144 1146 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out); 1145 1147 1146 1148 /* tx buffer size must be a positive multiple of the stride */ 1147 - instance->tx_channel.buf_size = max (instance->tx_channel.stride, 1149 + instance->tx_channel.buf_size = max(instance->tx_channel.stride, 1148 1150 snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride)); 1149 1151 1150 1152 /* rx buffer size must be a positive multiple of the endpoint maxpacket */ ··· 1157 1159 goto fail_unbind; 1158 1160 } 1159 1161 1160 - num_packets = max (1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */ 1162 + num_packets = max(1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */ 1161 1163 1162 1164 if (num_packets * maxpacket > UDSL_MAX_BUF_SIZE) 1163 1165 num_packets--; ··· 1260 1262 usb_free_urb(instance->urbs[i]); 1261 1263 } 1262 1264 1263 - kfree (instance); 1265 + kfree(instance); 1264 1266 1265 1267 return error; 1266 1268 } ··· 1388 1390 for (i = 0; i < len;) { 1389 1391 buffer[0] = '\0'; 1390 1392 sprintf(buffer, "%.3d :", i); 1391 - for (j = 0; (j < 16) && (i < len); j++, i++) { 1393 + for (j = 0; (j < 16) && (i < len); j++, i++) 1392 1394 sprintf(buffer, "%s %2.2x", buffer, data[i]); 1393 - } 1394 1395 dbg("%s", buffer); 1395 1396 } 1396 1397 return i;
+11 -11
drivers/usb/atm/usbatm.h
··· 48 48 dev_warn(&(instance)->usb_intf->dev, \ 49 49 "failed assertion '%s' at line %d", \ 50 50 __stringify(x), __LINE__); \ 51 - } while(0) 51 + } while (0) 52 52 #endif 53 53 54 54 #define usb_err(instance, format, arg...) \ ··· 59 59 dev_warn(&(instance)->usb_intf->dev , format , ## arg) 60 60 #ifdef DEBUG 61 61 #define usb_dbg(instance, format, arg...) \ 62 - dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg) 62 + dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg) 63 63 #else 64 64 #define usb_dbg(instance, format, arg...) \ 65 65 do {} while (0) ··· 104 104 /* 105 105 * Assuming all methods exist and succeed, they are called in this order: 106 106 * 107 - * bind, heavy_init, atm_start, ..., atm_stop, unbind 107 + * bind, heavy_init, atm_start, ..., atm_stop, unbind 108 108 */ 109 109 110 110 struct usbatm_driver { 111 111 const char *driver_name; 112 112 113 113 /* init device ... can sleep, or cause probe() failure */ 114 - int (*bind) (struct usbatm_data *, struct usb_interface *, 114 + int (*bind) (struct usbatm_data *, struct usb_interface *, 115 115 const struct usb_device_id *id); 116 116 117 117 /* additional device initialization that is too slow to be done in probe() */ 118 - int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 118 + int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 119 119 120 120 /* cleanup device ... can sleep, but can't fail */ 121 - void (*unbind) (struct usbatm_data *, struct usb_interface *); 121 + void (*unbind) (struct usbatm_data *, struct usb_interface *); 122 122 123 123 /* init ATM device ... can sleep, or cause ATM initialization failure */ 124 124 int (*atm_start) (struct usbatm_data *, struct atm_dev *); ··· 126 126 /* cleanup ATM device ... can sleep, but can't fail */ 127 127 void (*atm_stop) (struct usbatm_data *, struct atm_dev *); 128 128 129 - int bulk_in; /* bulk rx endpoint */ 130 - int isoc_in; /* isochronous rx endpoint */ 131 - int bulk_out; /* bulk tx endpoint */ 129 + int bulk_in; /* bulk rx endpoint */ 130 + int isoc_in; /* isochronous rx endpoint */ 131 + int bulk_out; /* bulk tx endpoint */ 132 132 133 133 unsigned rx_padding; 134 134 unsigned tx_padding; ··· 156 156 struct usbatm_data { 157 157 /****************** 158 158 * public fields * 159 - ******************/ 159 + ******************/ 160 160 161 161 /* mini driver */ 162 162 struct usbatm_driver *driver; ··· 174 174 175 175 /******************************** 176 176 * private fields - do not use * 177 - ********************************/ 177 + ********************************/ 178 178 179 179 struct kref refcount; 180 180 struct mutex serialize;
+5 -5
drivers/usb/atm/xusbatm.c
··· 49 49 static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1]; 50 50 static struct usb_driver xusbatm_usb_driver; 51 51 52 - static struct usb_interface *xusbatm_find_intf (struct usb_device *usb_dev, int altsetting, u8 ep) 52 + static struct usb_interface *xusbatm_find_intf(struct usb_device *usb_dev, int altsetting, u8 ep) 53 53 { 54 54 struct usb_host_interface *alt; 55 55 struct usb_interface *intf; 56 56 int i, j; 57 57 58 - for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) 58 + for (i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) 59 59 if ((intf = usb_dev->actconfig->interface[i]) && (alt = usb_altnum_to_altsetting(intf, altsetting))) 60 60 for (j = 0; j < alt->desc.bNumEndpoints; j++) 61 61 if (alt->endpoint[j].desc.bEndpointAddress == ep) ··· 63 63 return NULL; 64 64 } 65 65 66 - static int xusbatm_capture_intf (struct usbatm_data *usbatm, struct usb_device *usb_dev, 66 + static int xusbatm_capture_intf(struct usbatm_data *usbatm, struct usb_device *usb_dev, 67 67 struct usb_interface *intf, int altsetting, int claim) 68 68 { 69 69 int ifnum = intf->altsetting->desc.bInterfaceNumber; ··· 80 80 return 0; 81 81 } 82 82 83 - static void xusbatm_release_intf (struct usb_device *usb_dev, struct usb_interface *intf, int claimed) 83 + static void xusbatm_release_intf(struct usb_device *usb_dev, struct usb_interface *intf, int claimed) 84 84 { 85 85 if (claimed) { 86 86 usb_set_intfdata(intf, NULL); ··· 147 147 148 148 usb_dbg(usbatm, "%s entered\n", __func__); 149 149 150 - for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 150 + for (i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 151 151 struct usb_interface *cur_intf = usb_dev->actconfig->interface[i]; 152 152 153 153 if (cur_intf && (usb_get_intfdata(cur_intf) == usbatm)) {
+2 -2
drivers/usb/c67x00/c67x00-hcd.c
··· 264 264 if (unlikely(hcd->state == HC_STATE_HALT)) 265 265 return; 266 266 267 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 267 + if (!HCD_HW_ACCESSIBLE(hcd)) 268 268 return; 269 269 270 270 /* Handle Start of frame events */ ··· 282 282 { 283 283 hcd->uses_new_polling = 1; 284 284 hcd->state = HC_STATE_RUNNING; 285 - hcd->poll_rh = 1; 285 + set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 286 286 287 287 return 0; 288 288 }
+184 -185
drivers/usb/class/usblp.c
··· 135 135 * ->lock locks what interrupt accesses. 136 136 */ 137 137 struct usblp { 138 - struct usb_device *dev; /* USB device */ 138 + struct usb_device *dev; /* USB device */ 139 139 struct mutex wmut; 140 140 struct mutex mut; 141 141 spinlock_t lock; /* locks rcomplete, wcomplete */ ··· 169 169 }; 170 170 171 171 #ifdef DEBUG 172 - static void usblp_dump(struct usblp *usblp) { 172 + static void usblp_dump(struct usblp *usblp) 173 + { 173 174 int p; 174 175 175 176 dbg("usblp=0x%p", usblp); ··· 217 216 { 0x03f0, 0x0304, USBLP_QUIRK_BIDIR }, /* HP DeskJet 810C/812C */ 218 217 { 0x03f0, 0x0404, USBLP_QUIRK_BIDIR }, /* HP DeskJet 830C */ 219 218 { 0x03f0, 0x0504, USBLP_QUIRK_BIDIR }, /* HP DeskJet 885C */ 220 - { 0x03f0, 0x0604, USBLP_QUIRK_BIDIR }, /* HP DeskJet 840C */ 221 - { 0x03f0, 0x0804, USBLP_QUIRK_BIDIR }, /* HP DeskJet 816C */ 219 + { 0x03f0, 0x0604, USBLP_QUIRK_BIDIR }, /* HP DeskJet 840C */ 220 + { 0x03f0, 0x0804, USBLP_QUIRK_BIDIR }, /* HP DeskJet 816C */ 222 221 { 0x03f0, 0x1104, USBLP_QUIRK_BIDIR }, /* HP Deskjet 959C */ 223 222 { 0x0409, 0xefbe, USBLP_QUIRK_BIDIR }, /* NEC Picty900 (HP OEM) */ 224 223 { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */ ··· 255 254 /* High byte has the interface index. 256 255 Low byte has the alternate setting. 257 256 */ 258 - if ((request == USBLP_REQ_GET_ID) && (type == USB_TYPE_CLASS)) { 259 - index = (usblp->ifnum<<8)|usblp->protocol[usblp->current_protocol].alt_setting; 260 - } 257 + if ((request == USBLP_REQ_GET_ID) && (type == USB_TYPE_CLASS)) 258 + index = (usblp->ifnum<<8)|usblp->protocol[usblp->current_protocol].alt_setting; 261 259 262 260 retval = usb_control_msg(usblp->dev, 263 261 dir ? usb_rcvctrlpipe(usblp->dev, 0) : usb_sndctrlpipe(usblp->dev, 0), ··· 372 372 return newerr; 373 373 } 374 374 375 - static int handle_bidir (struct usblp *usblp) 375 + static int handle_bidir(struct usblp *usblp) 376 376 { 377 377 if (usblp->bidir && usblp->used) { 378 378 if (usblp_submit_read(usblp) < 0) ··· 395 395 if (minor < 0) 396 396 return -ENODEV; 397 397 398 - mutex_lock (&usblp_mutex); 398 + mutex_lock(&usblp_mutex); 399 399 400 400 retval = -ENODEV; 401 401 intf = usb_find_interface(&usblp_driver, minor); 402 - if (!intf) { 402 + if (!intf) 403 403 goto out; 404 - } 405 - usblp = usb_get_intfdata (intf); 404 + usblp = usb_get_intfdata(intf); 406 405 if (!usblp || !usblp->dev || !usblp->present) 407 406 goto out; 408 407 ··· 432 433 retval = -EIO; 433 434 } 434 435 out: 435 - mutex_unlock (&usblp_mutex); 436 + mutex_unlock(&usblp_mutex); 436 437 return retval; 437 438 } 438 439 439 - static void usblp_cleanup (struct usblp *usblp) 440 + static void usblp_cleanup(struct usblp *usblp) 440 441 { 441 442 printk(KERN_INFO "usblp%d: removed\n", usblp->minor); 442 443 443 444 kfree(usblp->readbuf); 444 - kfree (usblp->device_id_string); 445 - kfree (usblp->statusbuf); 446 - kfree (usblp); 445 + kfree(usblp->device_id_string); 446 + kfree(usblp->statusbuf); 447 + kfree(usblp); 447 448 } 448 449 449 450 static void usblp_unlink_urbs(struct usblp *usblp) ··· 457 458 458 459 usblp->flags &= ~LP_ABORT; 459 460 460 - mutex_lock (&usblp_mutex); 461 + mutex_lock(&usblp_mutex); 461 462 usblp->used = 0; 462 463 if (usblp->present) { 463 464 usblp_unlink_urbs(usblp); 464 465 usb_autopm_put_interface(usblp->intf); 465 - } else /* finish cleanup from disconnect */ 466 - usblp_cleanup (usblp); 467 - mutex_unlock (&usblp_mutex); 466 + } else /* finish cleanup from disconnect */ 467 + usblp_cleanup(usblp); 468 + mutex_unlock(&usblp_mutex); 468 469 return 0; 469 470 } 470 471 ··· 494 495 int twoints[2]; 495 496 int retval = 0; 496 497 497 - mutex_lock (&usblp->mut); 498 + mutex_lock(&usblp->mut); 498 499 if (!usblp->present) { 499 500 retval = -ENODEV; 500 501 goto done; 501 502 } 502 503 503 504 dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd), 504 - _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd) ); 505 + _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd)); 505 506 506 507 if (_IOC_TYPE(cmd) == 'P') /* new-style ioctl number */ 507 508 508 509 switch (_IOC_NR(cmd)) { 509 510 510 - case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */ 511 - if (_IOC_DIR(cmd) != _IOC_READ) { 512 - retval = -EINVAL; 513 - goto done; 514 - } 511 + case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */ 512 + if (_IOC_DIR(cmd) != _IOC_READ) { 513 + retval = -EINVAL; 514 + goto done; 515 + } 515 516 516 - length = usblp_cache_device_id_string(usblp); 517 - if (length < 0) { 518 - retval = length; 519 - goto done; 520 - } 521 - if (length > _IOC_SIZE(cmd)) 522 - length = _IOC_SIZE(cmd); /* truncate */ 517 + length = usblp_cache_device_id_string(usblp); 518 + if (length < 0) { 519 + retval = length; 520 + goto done; 521 + } 522 + if (length > _IOC_SIZE(cmd)) 523 + length = _IOC_SIZE(cmd); /* truncate */ 523 524 524 - if (copy_to_user((void __user *) arg, 525 - usblp->device_id_string, 526 - (unsigned long) length)) { 527 - retval = -EFAULT; 528 - goto done; 529 - } 525 + if (copy_to_user((void __user *) arg, 526 + usblp->device_id_string, 527 + (unsigned long) length)) { 528 + retval = -EFAULT; 529 + goto done; 530 + } 530 531 531 - break; 532 + break; 532 533 533 - case IOCNR_GET_PROTOCOLS: 534 - if (_IOC_DIR(cmd) != _IOC_READ || 535 - _IOC_SIZE(cmd) < sizeof(twoints)) { 536 - retval = -EINVAL; 537 - goto done; 538 - } 534 + case IOCNR_GET_PROTOCOLS: 535 + if (_IOC_DIR(cmd) != _IOC_READ || 536 + _IOC_SIZE(cmd) < sizeof(twoints)) { 537 + retval = -EINVAL; 538 + goto done; 539 + } 539 540 540 - twoints[0] = usblp->current_protocol; 541 - twoints[1] = 0; 542 - for (i = USBLP_FIRST_PROTOCOL; 543 - i <= USBLP_LAST_PROTOCOL; i++) { 544 - if (usblp->protocol[i].alt_setting >= 0) 545 - twoints[1] |= (1<<i); 546 - } 541 + twoints[0] = usblp->current_protocol; 542 + twoints[1] = 0; 543 + for (i = USBLP_FIRST_PROTOCOL; 544 + i <= USBLP_LAST_PROTOCOL; i++) { 545 + if (usblp->protocol[i].alt_setting >= 0) 546 + twoints[1] |= (1<<i); 547 + } 547 548 548 - if (copy_to_user((void __user *)arg, 549 - (unsigned char *)twoints, 550 - sizeof(twoints))) { 551 - retval = -EFAULT; 552 - goto done; 553 - } 549 + if (copy_to_user((void __user *)arg, 550 + (unsigned char *)twoints, 551 + sizeof(twoints))) { 552 + retval = -EFAULT; 553 + goto done; 554 + } 554 555 555 - break; 556 + break; 556 557 557 - case IOCNR_SET_PROTOCOL: 558 - if (_IOC_DIR(cmd) != _IOC_WRITE) { 559 - retval = -EINVAL; 560 - goto done; 561 - } 558 + case IOCNR_SET_PROTOCOL: 559 + if (_IOC_DIR(cmd) != _IOC_WRITE) { 560 + retval = -EINVAL; 561 + goto done; 562 + } 562 563 563 564 #ifdef DEBUG 564 - if (arg == -10) { 565 - usblp_dump(usblp); 566 - break; 567 - } 565 + if (arg == -10) { 566 + usblp_dump(usblp); 567 + break; 568 + } 568 569 #endif 569 570 570 - usblp_unlink_urbs(usblp); 571 - retval = usblp_set_protocol(usblp, arg); 572 - if (retval < 0) { 573 - usblp_set_protocol(usblp, 574 - usblp->current_protocol); 575 - } 576 - break; 571 + usblp_unlink_urbs(usblp); 572 + retval = usblp_set_protocol(usblp, arg); 573 + if (retval < 0) { 574 + usblp_set_protocol(usblp, 575 + usblp->current_protocol); 576 + } 577 + break; 577 578 578 - case IOCNR_HP_SET_CHANNEL: 579 - if (_IOC_DIR(cmd) != _IOC_WRITE || 580 - le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 || 581 - usblp->quirks & USBLP_QUIRK_BIDIR) { 582 - retval = -EINVAL; 583 - goto done; 584 - } 579 + case IOCNR_HP_SET_CHANNEL: 580 + if (_IOC_DIR(cmd) != _IOC_WRITE || 581 + le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 || 582 + usblp->quirks & USBLP_QUIRK_BIDIR) { 583 + retval = -EINVAL; 584 + goto done; 585 + } 585 586 586 - err = usblp_hp_channel_change_request(usblp, 587 - arg, &newChannel); 588 - if (err < 0) { 589 - dev_err(&usblp->dev->dev, 590 - "usblp%d: error = %d setting " 591 - "HP channel\n", 592 - usblp->minor, err); 593 - retval = -EIO; 594 - goto done; 595 - } 587 + err = usblp_hp_channel_change_request(usblp, 588 + arg, &newChannel); 589 + if (err < 0) { 590 + dev_err(&usblp->dev->dev, 591 + "usblp%d: error = %d setting " 592 + "HP channel\n", 593 + usblp->minor, err); 594 + retval = -EIO; 595 + goto done; 596 + } 596 597 597 - dbg("usblp%d requested/got HP channel %ld/%d", 598 - usblp->minor, arg, newChannel); 599 - break; 598 + dbg("usblp%d requested/got HP channel %ld/%d", 599 + usblp->minor, arg, newChannel); 600 + break; 600 601 601 - case IOCNR_GET_BUS_ADDRESS: 602 - if (_IOC_DIR(cmd) != _IOC_READ || 603 - _IOC_SIZE(cmd) < sizeof(twoints)) { 604 - retval = -EINVAL; 605 - goto done; 606 - } 602 + case IOCNR_GET_BUS_ADDRESS: 603 + if (_IOC_DIR(cmd) != _IOC_READ || 604 + _IOC_SIZE(cmd) < sizeof(twoints)) { 605 + retval = -EINVAL; 606 + goto done; 607 + } 607 608 608 - twoints[0] = usblp->dev->bus->busnum; 609 - twoints[1] = usblp->dev->devnum; 610 - if (copy_to_user((void __user *)arg, 611 - (unsigned char *)twoints, 612 - sizeof(twoints))) { 613 - retval = -EFAULT; 614 - goto done; 615 - } 609 + twoints[0] = usblp->dev->bus->busnum; 610 + twoints[1] = usblp->dev->devnum; 611 + if (copy_to_user((void __user *)arg, 612 + (unsigned char *)twoints, 613 + sizeof(twoints))) { 614 + retval = -EFAULT; 615 + goto done; 616 + } 616 617 617 - dbg("usblp%d is bus=%d, device=%d", 618 - usblp->minor, twoints[0], twoints[1]); 619 - break; 618 + dbg("usblp%d is bus=%d, device=%d", 619 + usblp->minor, twoints[0], twoints[1]); 620 + break; 620 621 621 - case IOCNR_GET_VID_PID: 622 - if (_IOC_DIR(cmd) != _IOC_READ || 623 - _IOC_SIZE(cmd) < sizeof(twoints)) { 624 - retval = -EINVAL; 625 - goto done; 626 - } 622 + case IOCNR_GET_VID_PID: 623 + if (_IOC_DIR(cmd) != _IOC_READ || 624 + _IOC_SIZE(cmd) < sizeof(twoints)) { 625 + retval = -EINVAL; 626 + goto done; 627 + } 627 628 628 - twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor); 629 - twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct); 630 - if (copy_to_user((void __user *)arg, 631 - (unsigned char *)twoints, 632 - sizeof(twoints))) { 633 - retval = -EFAULT; 634 - goto done; 635 - } 629 + twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor); 630 + twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct); 631 + if (copy_to_user((void __user *)arg, 632 + (unsigned char *)twoints, 633 + sizeof(twoints))) { 634 + retval = -EFAULT; 635 + goto done; 636 + } 636 637 637 - dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X", 638 - usblp->minor, twoints[0], twoints[1]); 639 - break; 638 + dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X", 639 + usblp->minor, twoints[0], twoints[1]); 640 + break; 640 641 641 - case IOCNR_SOFT_RESET: 642 - if (_IOC_DIR(cmd) != _IOC_NONE) { 643 - retval = -EINVAL; 644 - goto done; 645 - } 646 - retval = usblp_reset(usblp); 647 - break; 648 - default: 649 - retval = -ENOTTY; 642 + case IOCNR_SOFT_RESET: 643 + if (_IOC_DIR(cmd) != _IOC_NONE) { 644 + retval = -EINVAL; 645 + goto done; 646 + } 647 + retval = usblp_reset(usblp); 648 + break; 649 + default: 650 + retval = -ENOTTY; 650 651 } 651 652 else /* old-style ioctl value */ 652 653 switch (cmd) { 653 654 654 - case LPGETSTATUS: 655 - if ((retval = usblp_read_status(usblp, usblp->statusbuf))) { 656 - if (printk_ratelimit()) 657 - printk(KERN_ERR "usblp%d:" 658 - "failed reading printer status (%d)\n", 659 - usblp->minor, retval); 660 - retval = -EIO; 661 - goto done; 662 - } 663 - status = *usblp->statusbuf; 664 - if (copy_to_user ((void __user *)arg, &status, sizeof(int))) 665 - retval = -EFAULT; 666 - break; 655 + case LPGETSTATUS: 656 + if ((retval = usblp_read_status(usblp, usblp->statusbuf))) { 657 + if (printk_ratelimit()) 658 + printk(KERN_ERR "usblp%d:" 659 + "failed reading printer status (%d)\n", 660 + usblp->minor, retval); 661 + retval = -EIO; 662 + goto done; 663 + } 664 + status = *usblp->statusbuf; 665 + if (copy_to_user((void __user *)arg, &status, sizeof(int))) 666 + retval = -EFAULT; 667 + break; 667 668 668 - case LPABORT: 669 - if (arg) 670 - usblp->flags |= LP_ABORT; 671 - else 672 - usblp->flags &= ~LP_ABORT; 673 - break; 669 + case LPABORT: 670 + if (arg) 671 + usblp->flags |= LP_ABORT; 672 + else 673 + usblp->flags &= ~LP_ABORT; 674 + break; 674 675 675 - default: 676 - retval = -ENOTTY; 676 + default: 677 + retval = -ENOTTY; 677 678 } 678 679 679 680 done: 680 - mutex_unlock (&usblp->mut); 681 + mutex_unlock(&usblp->mut); 681 682 return retval; 682 683 } 683 684 ··· 839 840 } 840 841 841 842 done: 842 - mutex_unlock (&usblp->mut); 843 + mutex_unlock(&usblp->mut); 843 844 return count; 844 845 } 845 846 ··· 1022 1023 * while you are sending print data, and you don't try to query the 1023 1024 * printer status every couple of milliseconds, you will probably be OK. 1024 1025 */ 1025 - static unsigned int usblp_quirks (__u16 vendor, __u16 product) 1026 + static unsigned int usblp_quirks(__u16 vendor, __u16 product) 1026 1027 { 1027 1028 int i; 1028 1029 ··· 1030 1031 if (vendor == quirk_printers[i].vendorId && 1031 1032 product == quirk_printers[i].productId) 1032 1033 return quirk_printers[i].quirks; 1033 - } 1034 + } 1034 1035 return 0; 1035 1036 } 1036 1037 ··· 1060 1061 static ssize_t usblp_show_ieee1284_id(struct device *dev, struct device_attribute *attr, char *buf) 1061 1062 { 1062 1063 struct usb_interface *intf = to_usb_interface(dev); 1063 - struct usblp *usblp = usb_get_intfdata (intf); 1064 + struct usblp *usblp = usb_get_intfdata(intf); 1064 1065 1065 1066 if (usblp->device_id_string[0] == 0 && 1066 1067 usblp->device_id_string[1] == 0) ··· 1074 1075 static int usblp_probe(struct usb_interface *intf, 1075 1076 const struct usb_device_id *id) 1076 1077 { 1077 - struct usb_device *dev = interface_to_usbdev (intf); 1078 + struct usb_device *dev = interface_to_usbdev(intf); 1078 1079 struct usblp *usblp; 1079 1080 int protocol; 1080 1081 int retval; ··· 1088 1089 } 1089 1090 usblp->dev = dev; 1090 1091 mutex_init(&usblp->wmut); 1091 - mutex_init (&usblp->mut); 1092 + mutex_init(&usblp->mut); 1092 1093 spin_lock_init(&usblp->lock); 1093 1094 init_waitqueue_head(&usblp->rwait); 1094 1095 init_waitqueue_head(&usblp->wwait); ··· 1152 1153 usblp_check_status(usblp, 0); 1153 1154 #endif 1154 1155 1155 - usb_set_intfdata (intf, usblp); 1156 + usb_set_intfdata(intf, usblp); 1156 1157 1157 1158 usblp->present = 1; 1158 1159 ··· 1176 1177 return 0; 1177 1178 1178 1179 abort_intfdata: 1179 - usb_set_intfdata (intf, NULL); 1180 + usb_set_intfdata(intf, NULL); 1180 1181 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1181 1182 abort: 1182 1183 kfree(usblp->readbuf); ··· 1339 1340 1340 1341 static void usblp_disconnect(struct usb_interface *intf) 1341 1342 { 1342 - struct usblp *usblp = usb_get_intfdata (intf); 1343 + struct usblp *usblp = usb_get_intfdata(intf); 1343 1344 1344 1345 usb_deregister_dev(intf, &usblp_class); 1345 1346 1346 1347 if (!usblp || !usblp->dev) { 1347 1348 dev_err(&intf->dev, "bogus disconnect\n"); 1348 - BUG (); 1349 + BUG(); 1349 1350 } 1350 1351 1351 1352 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1352 1353 1353 - mutex_lock (&usblp_mutex); 1354 - mutex_lock (&usblp->mut); 1354 + mutex_lock(&usblp_mutex); 1355 + mutex_lock(&usblp->mut); 1355 1356 usblp->present = 0; 1356 1357 wake_up(&usblp->wwait); 1357 1358 wake_up(&usblp->rwait); 1358 - usb_set_intfdata (intf, NULL); 1359 + usb_set_intfdata(intf, NULL); 1359 1360 1360 1361 usblp_unlink_urbs(usblp); 1361 - mutex_unlock (&usblp->mut); 1362 + mutex_unlock(&usblp->mut); 1362 1363 1363 1364 if (!usblp->used) 1364 - usblp_cleanup (usblp); 1365 - mutex_unlock (&usblp_mutex); 1365 + usblp_cleanup(usblp); 1366 + mutex_unlock(&usblp_mutex); 1366 1367 } 1367 1368 1368 1369 static int usblp_suspend(struct usb_interface *intf, pm_message_t message) 1369 1370 { 1370 - struct usblp *usblp = usb_get_intfdata (intf); 1371 + struct usblp *usblp = usb_get_intfdata(intf); 1371 1372 1372 1373 usblp_unlink_urbs(usblp); 1373 1374 #if 0 /* XXX Do we want this? What if someone is reading, should we fail? */ ··· 1381 1382 1382 1383 static int usblp_resume(struct usb_interface *intf) 1383 1384 { 1384 - struct usblp *usblp = usb_get_intfdata (intf); 1385 + struct usblp *usblp = usb_get_intfdata(intf); 1385 1386 int r; 1386 1387 1387 - r = handle_bidir (usblp); 1388 + r = handle_bidir(usblp); 1388 1389 1389 1390 return r; 1390 1391 } ··· 1400 1401 { } /* Terminating entry */ 1401 1402 }; 1402 1403 1403 - MODULE_DEVICE_TABLE (usb, usblp_ids); 1404 + MODULE_DEVICE_TABLE(usb, usblp_ids); 1404 1405 1405 1406 static struct usb_driver usblp_driver = { 1406 1407 .name = "usblp", ··· 1425 1426 module_init(usblp_init); 1426 1427 module_exit(usblp_exit); 1427 1428 1428 - MODULE_AUTHOR( DRIVER_AUTHOR ); 1429 - MODULE_DESCRIPTION( DRIVER_DESC ); 1429 + MODULE_AUTHOR(DRIVER_AUTHOR); 1430 + MODULE_DESCRIPTION(DRIVER_DESC); 1430 1431 module_param(proto_bias, int, S_IRUGO | S_IWUSR); 1431 1432 MODULE_PARM_DESC(proto_bias, "Favourite protocol number"); 1432 1433 MODULE_LICENSE("GPL");
+2 -5
drivers/usb/core/devio.c
··· 1668 1668 default: 1669 1669 if (intf->dev.driver) 1670 1670 driver = to_usb_driver(intf->dev.driver); 1671 - if (driver == NULL || driver->ioctl == NULL) { 1671 + if (driver == NULL || driver->unlocked_ioctl == NULL) { 1672 1672 retval = -ENOTTY; 1673 1673 } else { 1674 - /* keep API that guarantees BKL */ 1675 - lock_kernel(); 1676 - retval = driver->ioctl(intf, ctl->ioctl_code, buf); 1677 - unlock_kernel(); 1674 + retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf); 1678 1675 if (retval == -ENOIOCTLCMD) 1679 1676 retval = -ENOTTY; 1680 1677 }
+4 -7
drivers/usb/core/driver.c
··· 1742 1742 } 1743 1743 1744 1744 /* Prevent the parent from suspending immediately after */ 1745 - else if (udev->parent) { 1745 + else if (udev->parent) 1746 1746 udev->parent->last_busy = jiffies; 1747 - } 1748 1747 } 1749 1748 1750 1749 /* Runtime suspend for a USB interface doesn't mean anything. */ ··· 1785 1786 return 0; 1786 1787 } 1787 1788 1788 - static struct dev_pm_ops usb_bus_pm_ops = { 1789 + static const struct dev_pm_ops usb_bus_pm_ops = { 1789 1790 .runtime_suspend = usb_runtime_suspend, 1790 1791 .runtime_resume = usb_runtime_resume, 1791 1792 .runtime_idle = usb_runtime_idle, 1792 1793 }; 1793 - 1794 - #else 1795 - 1796 - #define usb_bus_pm_ops (*(struct dev_pm_ops *) NULL) 1797 1794 1798 1795 #endif /* CONFIG_USB_SUSPEND */ 1799 1796 ··· 1797 1802 .name = "usb", 1798 1803 .match = usb_device_match, 1799 1804 .uevent = usb_uevent, 1805 + #ifdef CONFIG_USB_SUSPEND 1800 1806 .pm = &usb_bus_pm_ops, 1807 + #endif 1801 1808 };
+7 -2
drivers/usb/core/endpoint.c
··· 96 96 97 97 switch (usb_endpoint_type(ep->desc)) { 98 98 case USB_ENDPOINT_XFER_CONTROL: 99 - if (ep->udev->speed == USB_SPEED_HIGH) /* uframes per NAK */ 99 + if (ep->udev->speed == USB_SPEED_HIGH) 100 + /* uframes per NAK */ 100 101 interval = ep->desc->bInterval; 101 102 break; 103 + 102 104 case USB_ENDPOINT_XFER_ISOC: 103 105 interval = 1 << (ep->desc->bInterval - 1); 104 106 break; 107 + 105 108 case USB_ENDPOINT_XFER_BULK: 106 - if (ep->udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */ 109 + if (ep->udev->speed == USB_SPEED_HIGH && !in) 110 + /* uframes per NAK */ 107 111 interval = ep->desc->bInterval; 108 112 break; 113 + 109 114 case USB_ENDPOINT_XFER_INT: 110 115 if (ep->udev->speed == USB_SPEED_HIGH) 111 116 interval = 1 << (ep->desc->bInterval - 1);
+3 -1
drivers/usb/core/generic.c
··· 105 105 /* When the first config's first interface is one of Microsoft's 106 106 * pet nonstandard Ethernet-over-USB protocols, ignore it unless 107 107 * this kernel has enabled the necessary host side driver. 108 + * But: Don't ignore it if it's the only config. 108 109 */ 109 - if (i == 0 && desc && (is_rndis(desc) || is_activesync(desc))) { 110 + if (i == 0 && num_configs > 1 && desc && 111 + (is_rndis(desc) || is_activesync(desc))) { 110 112 #if !defined(CONFIG_USB_NET_RNDIS_HOST) && !defined(CONFIG_USB_NET_RNDIS_HOST_MODULE) 111 113 continue; 112 114 #else
+142 -72
drivers/usb/core/hcd-pci.c
··· 66 66 * vice versa. 67 67 */ 68 68 companion = NULL; 69 - for (;;) { 70 - companion = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, companion); 71 - if (!companion) 72 - break; 69 + for_each_pci_dev(companion) { 73 70 if (companion->bus != pdev->bus || 74 71 PCI_SLOT(companion->devfn) != slot) 75 72 continue; ··· 247 250 if (retval != 0) 248 251 goto err4; 249 252 set_hs_companion(dev, hcd); 253 + 254 + if (pci_dev_run_wake(dev)) 255 + pm_runtime_put_noidle(&dev->dev); 250 256 return retval; 251 257 252 258 err4: ··· 292 292 if (!hcd) 293 293 return; 294 294 295 + if (pci_dev_run_wake(dev)) 296 + pm_runtime_get_noresume(&dev->dev); 297 + 298 + /* Fake an interrupt request in order to give the driver a chance 299 + * to test whether the controller hardware has been removed (e.g., 300 + * cardbus physical eject). 301 + */ 302 + local_irq_disable(); 303 + usb_hcd_irq(0, hcd); 304 + local_irq_enable(); 305 + 295 306 usb_remove_hcd(hcd); 296 307 if (hcd->driver->flags & HCD_MEMORY) { 297 308 iounmap(hcd->regs); ··· 328 317 if (!hcd) 329 318 return; 330 319 331 - if (hcd->driver->shutdown) 320 + if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && 321 + hcd->driver->shutdown) 332 322 hcd->driver->shutdown(hcd); 333 323 } 334 324 EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); 335 325 336 - #ifdef CONFIG_PM_SLEEP 326 + #ifdef CONFIG_PM_OPS 327 + 328 + #ifdef CONFIG_PPC_PMAC 329 + static void powermac_set_asic(struct pci_dev *pci_dev, int enable) 330 + { 331 + /* Enanble or disable ASIC clocks for USB */ 332 + if (machine_is(powermac)) { 333 + struct device_node *of_node; 334 + 335 + of_node = pci_device_to_OF_node(pci_dev); 336 + if (of_node) 337 + pmac_call_feature(PMAC_FTR_USB_ENABLE, 338 + of_node, 0, enable); 339 + } 340 + } 341 + 342 + #else 343 + 344 + static inline void powermac_set_asic(struct pci_dev *pci_dev, int enable) 345 + {} 346 + 347 + #endif /* CONFIG_PPC_PMAC */ 337 348 338 349 static int check_root_hub_suspended(struct device *dev) 339 350 { ··· 370 337 return 0; 371 338 } 372 339 373 - static int hcd_pci_suspend(struct device *dev) 340 + static int suspend_common(struct device *dev, bool do_wakeup) 374 341 { 375 342 struct pci_dev *pci_dev = to_pci_dev(dev); 376 343 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); ··· 385 352 if (retval) 386 353 return retval; 387 354 388 - /* We might already be suspended (runtime PM -- not yet written) */ 389 - if (pci_dev->current_state != PCI_D0) 390 - return retval; 391 - 392 355 if (hcd->driver->pci_suspend) { 393 - retval = hcd->driver->pci_suspend(hcd); 356 + /* Optimization: Don't suspend if a root-hub wakeup is 357 + * pending and it would cause the HCD to wake up anyway. 358 + */ 359 + if (do_wakeup && HCD_WAKEUP_PENDING(hcd)) 360 + return -EBUSY; 361 + retval = hcd->driver->pci_suspend(hcd, do_wakeup); 394 362 suspend_report_result(hcd->driver->pci_suspend, retval); 363 + 364 + /* Check again in case wakeup raced with pci_suspend */ 365 + if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) { 366 + if (hcd->driver->pci_resume) 367 + hcd->driver->pci_resume(hcd, false); 368 + retval = -EBUSY; 369 + } 395 370 if (retval) 396 371 return retval; 397 372 } ··· 413 372 */ 414 373 pci_disable_device(pci_dev); 415 374 return retval; 375 + } 376 + 377 + static int resume_common(struct device *dev, int event) 378 + { 379 + struct pci_dev *pci_dev = to_pci_dev(dev); 380 + struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 381 + int retval; 382 + 383 + if (hcd->state != HC_STATE_SUSPENDED) { 384 + dev_dbg(dev, "can't resume, not suspended!\n"); 385 + return 0; 386 + } 387 + 388 + retval = pci_enable_device(pci_dev); 389 + if (retval < 0) { 390 + dev_err(dev, "can't re-enable after resume, %d!\n", retval); 391 + return retval; 392 + } 393 + 394 + pci_set_master(pci_dev); 395 + 396 + clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 397 + 398 + if (hcd->driver->pci_resume) { 399 + if (event != PM_EVENT_AUTO_RESUME) 400 + wait_for_companions(pci_dev, hcd); 401 + 402 + retval = hcd->driver->pci_resume(hcd, 403 + event == PM_EVENT_RESTORE); 404 + if (retval) { 405 + dev_err(dev, "PCI post-resume error %d!\n", retval); 406 + usb_hc_died(hcd); 407 + } 408 + } 409 + return retval; 410 + } 411 + 412 + #ifdef CONFIG_PM_SLEEP 413 + 414 + static int hcd_pci_suspend(struct device *dev) 415 + { 416 + return suspend_common(dev, device_may_wakeup(dev)); 416 417 } 417 418 418 419 static int hcd_pci_suspend_noirq(struct device *dev) ··· 491 408 return retval; 492 409 } 493 410 494 - #ifdef CONFIG_PPC_PMAC 495 - /* Disable ASIC clocks for USB */ 496 - if (machine_is(powermac)) { 497 - struct device_node *of_node; 498 - 499 - of_node = pci_device_to_OF_node(pci_dev); 500 - if (of_node) 501 - pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0); 502 - } 503 - #endif 411 + powermac_set_asic(pci_dev, 0); 504 412 return retval; 505 413 } 506 414 ··· 499 425 { 500 426 struct pci_dev *pci_dev = to_pci_dev(dev); 501 427 502 - #ifdef CONFIG_PPC_PMAC 503 - /* Reenable ASIC clocks for USB */ 504 - if (machine_is(powermac)) { 505 - struct device_node *of_node; 506 - 507 - of_node = pci_device_to_OF_node(pci_dev); 508 - if (of_node) 509 - pmac_call_feature(PMAC_FTR_USB_ENABLE, 510 - of_node, 0, 1); 511 - } 512 - #endif 428 + powermac_set_asic(pci_dev, 1); 513 429 514 430 /* Go back to D0 and disable remote wakeup */ 515 431 pci_back_from_sleep(pci_dev); 516 432 return 0; 517 433 } 518 434 519 - static int resume_common(struct device *dev, bool hibernated) 520 - { 521 - struct pci_dev *pci_dev = to_pci_dev(dev); 522 - struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 523 - int retval; 524 - 525 - if (hcd->state != HC_STATE_SUSPENDED) { 526 - dev_dbg(dev, "can't resume, not suspended!\n"); 527 - return 0; 528 - } 529 - 530 - retval = pci_enable_device(pci_dev); 531 - if (retval < 0) { 532 - dev_err(dev, "can't re-enable after resume, %d!\n", retval); 533 - return retval; 534 - } 535 - 536 - pci_set_master(pci_dev); 537 - 538 - clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 539 - 540 - if (hcd->driver->pci_resume) { 541 - /* This call should be made only during system resume, 542 - * not during runtime resume. 543 - */ 544 - wait_for_companions(pci_dev, hcd); 545 - 546 - retval = hcd->driver->pci_resume(hcd, hibernated); 547 - if (retval) { 548 - dev_err(dev, "PCI post-resume error %d!\n", retval); 549 - usb_hc_died(hcd); 550 - } 551 - } 552 - return retval; 553 - } 554 - 555 435 static int hcd_pci_resume(struct device *dev) 556 436 { 557 - return resume_common(dev, false); 437 + return resume_common(dev, PM_EVENT_RESUME); 558 438 } 559 439 560 440 static int hcd_pci_restore(struct device *dev) 561 441 { 562 - return resume_common(dev, true); 442 + return resume_common(dev, PM_EVENT_RESTORE); 563 443 } 444 + 445 + #else 446 + 447 + #define hcd_pci_suspend NULL 448 + #define hcd_pci_suspend_noirq NULL 449 + #define hcd_pci_resume_noirq NULL 450 + #define hcd_pci_resume NULL 451 + #define hcd_pci_restore NULL 452 + 453 + #endif /* CONFIG_PM_SLEEP */ 454 + 455 + #ifdef CONFIG_PM_RUNTIME 456 + 457 + static int hcd_pci_runtime_suspend(struct device *dev) 458 + { 459 + int retval; 460 + 461 + retval = suspend_common(dev, true); 462 + if (retval == 0) 463 + powermac_set_asic(to_pci_dev(dev), 0); 464 + dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval); 465 + return retval; 466 + } 467 + 468 + static int hcd_pci_runtime_resume(struct device *dev) 469 + { 470 + int retval; 471 + 472 + powermac_set_asic(to_pci_dev(dev), 1); 473 + retval = resume_common(dev, PM_EVENT_AUTO_RESUME); 474 + dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval); 475 + return retval; 476 + } 477 + 478 + #else 479 + 480 + #define hcd_pci_runtime_suspend NULL 481 + #define hcd_pci_runtime_resume NULL 482 + 483 + #endif /* CONFIG_PM_RUNTIME */ 564 484 565 485 const struct dev_pm_ops usb_hcd_pci_pm_ops = { 566 486 .suspend = hcd_pci_suspend, ··· 569 501 .poweroff_noirq = hcd_pci_suspend_noirq, 570 502 .restore_noirq = hcd_pci_resume_noirq, 571 503 .restore = hcd_pci_restore, 504 + .runtime_suspend = hcd_pci_runtime_suspend, 505 + .runtime_resume = hcd_pci_runtime_resume, 572 506 }; 573 507 EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); 574 508 575 - #endif /* CONFIG_PM_SLEEP */ 509 + #endif /* CONFIG_PM_OPS */
+59 -20
drivers/usb/core/hcd.c
··· 667 667 unsigned long flags; 668 668 char buffer[6]; /* Any root hubs with > 31 ports? */ 669 669 670 - if (unlikely(!hcd->rh_registered)) 670 + if (unlikely(!hcd->rh_pollable)) 671 671 return; 672 672 if (!hcd->uses_new_polling && !hcd->status_urb) 673 673 return; ··· 679 679 spin_lock_irqsave(&hcd_root_hub_lock, flags); 680 680 urb = hcd->status_urb; 681 681 if (urb) { 682 - hcd->poll_pending = 0; 682 + clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); 683 683 hcd->status_urb = NULL; 684 684 urb->actual_length = length; 685 685 memcpy(urb->transfer_buffer, buffer, length); ··· 690 690 spin_lock(&hcd_root_hub_lock); 691 691 } else { 692 692 length = 0; 693 - hcd->poll_pending = 1; 693 + set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags); 694 694 } 695 695 spin_unlock_irqrestore(&hcd_root_hub_lock, flags); 696 696 } ··· 699 699 * exceed that limit if HZ is 100. The math is more clunky than 700 700 * maybe expected, this is to make sure that all timers for USB devices 701 701 * fire at the same time to give the CPU a break inbetween */ 702 - if (hcd->uses_new_polling ? hcd->poll_rh : 702 + if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) : 703 703 (length == 0 && hcd->status_urb != NULL)) 704 704 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); 705 705 } ··· 736 736 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); 737 737 738 738 /* If a status change has already occurred, report it ASAP */ 739 - else if (hcd->poll_pending) 739 + else if (HCD_POLL_PENDING(hcd)) 740 740 mod_timer(&hcd->rh_timer, jiffies); 741 741 retval = 0; 742 742 done: ··· 1150 1150 * finish unlinking the initial failed usb_set_address() 1151 1151 * or device descriptor fetch. 1152 1152 */ 1153 - if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) && 1154 - !is_root_hub(urb->dev)) { 1153 + if (!HCD_SAW_IRQ(hcd) && !is_root_hub(urb->dev)) { 1155 1154 dev_warn(hcd->self.controller, "Unlink after no-IRQ? " 1156 1155 "Controller is probably using the wrong IRQ.\n"); 1157 1156 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); ··· 1217 1218 enum dma_data_direction dir) 1218 1219 { 1219 1220 unsigned char *vaddr; 1221 + 1222 + if (*vaddr_handle == NULL) { 1223 + WARN_ON_ONCE(1); 1224 + return -EFAULT; 1225 + } 1220 1226 1221 1227 vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), 1222 1228 mem_flags, dma_handle); ··· 1945 1941 1946 1942 dev_dbg(&rhdev->dev, "usb %s%s\n", 1947 1943 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); 1944 + clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); 1948 1945 if (!hcd->driver->bus_resume) 1949 1946 return -ENOENT; 1950 1947 if (hcd->state == HC_STATE_RUNNING) ··· 1999 1994 unsigned long flags; 2000 1995 2001 1996 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2002 - if (hcd->rh_registered) 1997 + if (hcd->rh_registered) { 1998 + set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags); 2003 1999 queue_work(pm_wq, &hcd->wakeup_work); 2000 + } 2004 2001 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 2005 2002 } 2006 2003 EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); ··· 2070 2063 */ 2071 2064 local_irq_save(flags); 2072 2065 2073 - if (unlikely(hcd->state == HC_STATE_HALT || 2074 - !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) { 2066 + if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) { 2075 2067 rc = IRQ_NONE; 2076 2068 } else if (hcd->driver->irq(hcd) == IRQ_NONE) { 2077 2069 rc = IRQ_NONE; ··· 2085 2079 local_irq_restore(flags); 2086 2080 return rc; 2087 2081 } 2082 + EXPORT_SYMBOL_GPL(usb_hcd_irq); 2088 2083 2089 2084 /*-------------------------------------------------------------------------*/ 2090 2085 ··· 2105 2098 2106 2099 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2107 2100 if (hcd->rh_registered) { 2108 - hcd->poll_rh = 0; 2101 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2109 2102 2110 2103 /* make khubd clean up old urbs and devices */ 2111 2104 usb_set_device_state (hcd->self.root_hub, ··· 2224 2217 retval = -ENOMEM; 2225 2218 goto err_allocate_root_hub; 2226 2219 } 2220 + hcd->self.root_hub = rhdev; 2227 2221 2228 2222 switch (hcd->driver->flags & HCD_MASK) { 2229 2223 case HCD_USB11: ··· 2237 2229 rhdev->speed = USB_SPEED_SUPER; 2238 2230 break; 2239 2231 default: 2240 - goto err_allocate_root_hub; 2232 + goto err_set_rh_speed; 2241 2233 } 2242 - hcd->self.root_hub = rhdev; 2243 2234 2244 2235 /* wakeup flag init defaults to "everything works" for root hubs, 2245 2236 * but drivers can override it in reset() if needed, along with ··· 2253 2246 dev_err(hcd->self.controller, "can't setup\n"); 2254 2247 goto err_hcd_driver_setup; 2255 2248 } 2249 + hcd->rh_pollable = 1; 2256 2250 2257 2251 /* NOTE: root hub and controller capabilities may not be the same */ 2258 2252 if (device_can_wakeup(hcd->self.controller) ··· 2308 2300 retval); 2309 2301 goto error_create_attr_group; 2310 2302 } 2311 - if (hcd->uses_new_polling && hcd->poll_rh) 2303 + if (hcd->uses_new_polling && HCD_POLL_RH(hcd)) 2312 2304 usb_hcd_poll_rh_status(hcd); 2313 2305 return retval; 2314 2306 2315 2307 error_create_attr_group: 2308 + if (HC_IS_RUNNING(hcd->state)) 2309 + hcd->state = HC_STATE_QUIESCING; 2310 + spin_lock_irq(&hcd_root_hub_lock); 2311 + hcd->rh_registered = 0; 2312 + spin_unlock_irq(&hcd_root_hub_lock); 2313 + 2314 + #ifdef CONFIG_USB_SUSPEND 2315 + cancel_work_sync(&hcd->wakeup_work); 2316 + #endif 2316 2317 mutex_lock(&usb_bus_list_lock); 2317 - usb_disconnect(&hcd->self.root_hub); 2318 + usb_disconnect(&rhdev); /* Sets rhdev to NULL */ 2318 2319 mutex_unlock(&usb_bus_list_lock); 2319 2320 err_register_root_hub: 2321 + hcd->rh_pollable = 0; 2322 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2323 + del_timer_sync(&hcd->rh_timer); 2320 2324 hcd->driver->stop(hcd); 2325 + hcd->state = HC_STATE_HALT; 2326 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2327 + del_timer_sync(&hcd->rh_timer); 2321 2328 err_hcd_driver_start: 2322 2329 if (hcd->irq >= 0) 2323 2330 free_irq(irqnum, hcd); 2324 2331 err_request_irq: 2325 2332 err_hcd_driver_setup: 2326 - hcd->self.root_hub = NULL; 2327 - usb_put_dev(rhdev); 2333 + err_set_rh_speed: 2334 + usb_put_dev(hcd->self.root_hub); 2328 2335 err_allocate_root_hub: 2329 2336 usb_deregister_bus(&hcd->self); 2330 2337 err_register_bus: ··· 2358 2335 */ 2359 2336 void usb_remove_hcd(struct usb_hcd *hcd) 2360 2337 { 2338 + struct usb_device *rhdev = hcd->self.root_hub; 2339 + 2361 2340 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); 2341 + 2342 + usb_get_dev(rhdev); 2343 + sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group); 2362 2344 2363 2345 if (HC_IS_RUNNING (hcd->state)) 2364 2346 hcd->state = HC_STATE_QUIESCING; ··· 2377 2349 cancel_work_sync(&hcd->wakeup_work); 2378 2350 #endif 2379 2351 2380 - sysfs_remove_group(&hcd->self.root_hub->dev.kobj, &usb_bus_attr_group); 2381 2352 mutex_lock(&usb_bus_list_lock); 2382 - usb_disconnect(&hcd->self.root_hub); 2353 + usb_disconnect(&rhdev); /* Sets rhdev to NULL */ 2383 2354 mutex_unlock(&usb_bus_list_lock); 2355 + 2356 + /* Prevent any more root-hub status calls from the timer. 2357 + * The HCD might still restart the timer (if a port status change 2358 + * interrupt occurs), but usb_hcd_poll_rh_status() won't invoke 2359 + * the hub_status_data() callback. 2360 + */ 2361 + hcd->rh_pollable = 0; 2362 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2363 + del_timer_sync(&hcd->rh_timer); 2384 2364 2385 2365 hcd->driver->stop(hcd); 2386 2366 hcd->state = HC_STATE_HALT; 2387 2367 2388 - hcd->poll_rh = 0; 2368 + /* In case the HCD restarted the timer, stop it again. */ 2369 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 2389 2370 del_timer_sync(&hcd->rh_timer); 2390 2371 2391 2372 if (hcd->irq >= 0) 2392 2373 free_irq(hcd->irq, hcd); 2374 + 2375 + usb_put_dev(hcd->self.root_hub); 2393 2376 usb_deregister_bus(&hcd->self); 2394 2377 hcd_buffer_destroy(hcd); 2395 2378 }
+10 -3
drivers/usb/core/hub.c
··· 20 20 #include <linux/usb.h> 21 21 #include <linux/usbdevice_fs.h> 22 22 #include <linux/usb/hcd.h> 23 + #include <linux/usb/quirks.h> 23 24 #include <linux/kthread.h> 24 25 #include <linux/mutex.h> 25 26 #include <linux/freezer.h> ··· 1295 1294 return -ENODEV; 1296 1295 } 1297 1296 1297 + /* No BKL needed */ 1298 1298 static int 1299 1299 hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data) 1300 1300 { ··· 1803 1801 pm_runtime_set_active(&udev->dev); 1804 1802 pm_runtime_enable(&udev->dev); 1805 1803 1806 - usb_detect_quirks(udev); 1807 1804 err = usb_enumerate_device(udev); /* Read descriptors */ 1808 1805 if (err < 0) 1809 1806 goto fail; ··· 2881 2880 } 2882 2881 2883 2882 retval = 0; 2884 - 2883 + /* notify HCD that we have a device connected and addressed */ 2884 + if (hcd->driver->update_device) 2885 + hcd->driver->update_device(hcd, udev); 2885 2886 fail: 2886 2887 if (retval) { 2887 2888 hub_port_disable(hub, port1, 0); ··· 3113 3110 status = hub_port_init(hub, udev, port1, i); 3114 3111 if (status < 0) 3115 3112 goto loop; 3113 + 3114 + usb_detect_quirks(udev); 3115 + if (udev->quirks & USB_QUIRK_DELAY_INIT) 3116 + msleep(1000); 3116 3117 3117 3118 /* consecutive bus-powered hubs aren't reliable; they can 3118 3119 * violate the voltage drop budget. if the new child has ··· 3470 3463 .reset_resume = hub_reset_resume, 3471 3464 .pre_reset = hub_pre_reset, 3472 3465 .post_reset = hub_post_reset, 3473 - .ioctl = hub_ioctl, 3466 + .unlocked_ioctl = hub_ioctl, 3474 3467 .id_table = hub_id_table, 3475 3468 .supports_autosuspend = 1, 3476 3469 };
-4
drivers/usb/core/inode.c
··· 265 265 return -EINVAL; 266 266 } 267 267 268 - lock_kernel(); 269 - 270 268 if (usbfs_mount && usbfs_mount->mnt_sb) 271 269 update_sb(usbfs_mount->mnt_sb); 272 - 273 - unlock_kernel(); 274 270 275 271 return 0; 276 272 }
+3
drivers/usb/core/quirks.c
··· 38 38 /* Creative SB Audigy 2 NX */ 39 39 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME }, 40 40 41 + /* Logitech Harmony 700-series */ 42 + { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT }, 43 + 41 44 /* Philips PSC805 audio device */ 42 45 { USB_DEVICE(0x0471, 0x0155), .driver_info = USB_QUIRK_RESET_RESUME }, 43 46
+21 -29
drivers/usb/core/urb.c
··· 137 137 } 138 138 EXPORT_SYMBOL_GPL(usb_anchor_urb); 139 139 140 + /* Callers must hold anchor->lock */ 141 + static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) 142 + { 143 + urb->anchor = NULL; 144 + list_del(&urb->anchor_list); 145 + usb_put_urb(urb); 146 + if (list_empty(&anchor->urb_list)) 147 + wake_up(&anchor->wait); 148 + } 149 + 140 150 /** 141 151 * usb_unanchor_urb - unanchors an URB 142 152 * @urb: pointer to the urb to anchor ··· 166 156 return; 167 157 168 158 spin_lock_irqsave(&anchor->lock, flags); 169 - if (unlikely(anchor != urb->anchor)) { 170 - /* we've lost the race to another thread */ 171 - spin_unlock_irqrestore(&anchor->lock, flags); 172 - return; 173 - } 174 - urb->anchor = NULL; 175 - list_del(&urb->anchor_list); 159 + /* 160 + * At this point, we could be competing with another thread which 161 + * has the same intention. To protect the urb from being unanchored 162 + * twice, only the winner of the race gets the job. 163 + */ 164 + if (likely(anchor == urb->anchor)) 165 + __usb_unanchor_urb(urb, anchor); 176 166 spin_unlock_irqrestore(&anchor->lock, flags); 177 - usb_put_urb(urb); 178 - if (list_empty(&anchor->urb_list)) 179 - wake_up(&anchor->wait); 180 167 } 181 168 EXPORT_SYMBOL_GPL(usb_unanchor_urb); 182 169 ··· 756 749 void usb_unlink_anchored_urbs(struct usb_anchor *anchor) 757 750 { 758 751 struct urb *victim; 759 - unsigned long flags; 760 752 761 - spin_lock_irqsave(&anchor->lock, flags); 762 - while (!list_empty(&anchor->urb_list)) { 763 - victim = list_entry(anchor->urb_list.prev, struct urb, 764 - anchor_list); 765 - usb_get_urb(victim); 766 - spin_unlock_irqrestore(&anchor->lock, flags); 767 - /* this will unanchor the URB */ 753 + while ((victim = usb_get_from_anchor(anchor)) != NULL) { 768 754 usb_unlink_urb(victim); 769 755 usb_put_urb(victim); 770 - spin_lock_irqsave(&anchor->lock, flags); 771 756 } 772 - spin_unlock_irqrestore(&anchor->lock, flags); 773 757 } 774 758 EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); 775 759 ··· 797 799 victim = list_entry(anchor->urb_list.next, struct urb, 798 800 anchor_list); 799 801 usb_get_urb(victim); 800 - spin_unlock_irqrestore(&anchor->lock, flags); 801 - usb_unanchor_urb(victim); 802 + __usb_unanchor_urb(victim, anchor); 802 803 } else { 803 - spin_unlock_irqrestore(&anchor->lock, flags); 804 804 victim = NULL; 805 805 } 806 + spin_unlock_irqrestore(&anchor->lock, flags); 806 807 807 808 return victim; 808 809 } ··· 823 826 while (!list_empty(&anchor->urb_list)) { 824 827 victim = list_entry(anchor->urb_list.prev, struct urb, 825 828 anchor_list); 826 - usb_get_urb(victim); 827 - spin_unlock_irqrestore(&anchor->lock, flags); 828 - /* this may free the URB */ 829 - usb_unanchor_urb(victim); 830 - usb_put_urb(victim); 831 - spin_lock_irqsave(&anchor->lock, flags); 829 + __usb_unanchor_urb(victim, anchor); 832 830 } 833 831 spin_unlock_irqrestore(&anchor->lock, flags); 834 832 }
+2 -4
drivers/usb/core/usb.c
··· 317 317 .restore = usb_dev_restore, 318 318 }; 319 319 320 - #else 321 - 322 - #define usb_device_pm_ops (*(struct dev_pm_ops *) NULL) 323 - 324 320 #endif /* CONFIG_PM */ 325 321 326 322 ··· 334 338 .release = usb_release_dev, 335 339 .uevent = usb_dev_uevent, 336 340 .devnode = usb_devnode, 341 + #ifdef CONFIG_PM 337 342 .pm = &usb_device_pm_ops, 343 + #endif 338 344 }; 339 345 340 346
+41 -11
drivers/usb/gadget/Kconfig
··· 714 714 config USB_FUNCTIONFS 715 715 tristate "Function Filesystem (EXPERIMENTAL)" 716 716 depends on EXPERIMENTAL 717 + select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 717 718 help 718 719 The Function Filesystem (FunctioFS) lets one create USB 719 720 composite functions in user space in the same way as GadgetFS ··· 723 722 implemented in kernel space (for instance Ethernet, serial or 724 723 mass storage) and other are implemented in user space. 725 724 725 + If you say "y" or "m" here you will be able what kind of 726 + configurations the gadget will provide. 727 + 726 728 Say "y" to link the driver statically, or "m" to build 727 729 a dynamically linked module called "g_ffs". 728 730 729 731 config USB_FUNCTIONFS_ETH 730 - bool "Include CDC ECM (Ethernet) function" 732 + bool "Include configuration with CDC ECM (Ethernet)" 731 733 depends on USB_FUNCTIONFS && NET 732 734 help 733 - Include an CDC ECM (Ethernet) funcion in the CDC ECM (Funcion) 734 - Filesystem. If you also say "y" to the RNDIS query below the 735 - gadget will have two configurations. 735 + Include a configuration with CDC ECM funcion (Ethernet) and the 736 + Funcion Filesystem. 736 737 737 738 config USB_FUNCTIONFS_RNDIS 738 - bool "Include RNDIS (Ethernet) function" 739 + bool "Include configuration with RNDIS (Ethernet)" 739 740 depends on USB_FUNCTIONFS && NET 740 741 help 741 - Include an RNDIS (Ethernet) funcion in the Funcion Filesystem. 742 - If you also say "y" to the CDC ECM query above the gadget will 743 - have two configurations. 742 + Include a configuration with RNDIS funcion (Ethernet) and the Filesystem. 744 743 745 744 config USB_FUNCTIONFS_GENERIC 746 745 bool "Include 'pure' configuration" 747 - depends on USB_FUNCTIONFS && (USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 746 + depends on USB_FUNCTIONFS 748 747 help 749 - Include a configuration with FunctionFS and no Ethernet 750 - configuration. 748 + Include a configuration with the Function Filesystem alone with 749 + no Ethernet interface. 751 750 752 751 config USB_FILE_STORAGE 753 752 tristate "File-backed Storage Gadget" ··· 864 863 config USB_G_MULTI 865 864 tristate "Multifunction Composite Gadget (EXPERIMENTAL)" 866 865 depends on BLOCK && NET 866 + select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS 867 867 help 868 868 The Multifunction Composite Gadget provides Ethernet (RNDIS 869 869 and/or CDC Ethernet), mass storage and ACM serial link ··· 914 912 915 913 Say "y" to link the driver statically, or "m" to build a 916 914 dynamically linked module called "g_hid". 915 + 916 + config USB_G_DBGP 917 + tristate "EHCI Debug Device Gadget" 918 + help 919 + This gadget emulates an EHCI Debug device. This is useful when you want 920 + to interact with an EHCI Debug Port. 921 + 922 + Say "y" to link the driver statically, or "m" to build a 923 + dynamically linked module called "g_dbgp". 924 + 925 + if USB_G_DBGP 926 + choice 927 + prompt "EHCI Debug Device mode" 928 + default USB_G_DBGP_SERIAL 929 + 930 + config USB_G_DBGP_PRINTK 931 + depends on USB_G_DBGP 932 + bool "printk" 933 + help 934 + Directly printk() received data. No interaction. 935 + 936 + config USB_G_DBGP_SERIAL 937 + depends on USB_G_DBGP 938 + bool "serial" 939 + help 940 + Userland can interact using /dev/ttyGSxxx. 941 + endchoice 942 + endif 917 943 918 944 # put drivers that need isochronous transfer support (for audio 919 945 # or video class gadget drivers), or specific hardware, here.
+2 -1
drivers/usb/gadget/Makefile
··· 44 44 g_cdc-objs := cdc2.o 45 45 g_multi-objs := multi.o 46 46 g_hid-objs := hid.o 47 + g_dbgp-objs := dbgp.o 47 48 g_nokia-objs := nokia.o 48 49 g_webcam-objs := webcam.o 49 50 ··· 53 52 obj-$(CONFIG_USB_ETH) += g_ether.o 54 53 obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 55 54 obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o 56 - obj-$(CONFIG_USB_ETH_FUNCTIONFS) += g_eth_ffs.o 57 55 obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 58 56 obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o 59 57 obj-$(CONFIG_USB_G_SERIAL) += g_serial.o ··· 60 60 obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 61 61 obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o 62 62 obj-$(CONFIG_USB_G_HID) += g_hid.o 63 + obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o 63 64 obj-$(CONFIG_USB_G_MULTI) += g_multi.o 64 65 obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o 65 66 obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
+2 -2
drivers/usb/gadget/audio.c
··· 89 89 90 90 /*-------------------------------------------------------------------------*/ 91 91 92 - static int __init audio_do_config(struct usb_configuration *c) 92 + static int __ref audio_do_config(struct usb_configuration *c) 93 93 { 94 94 /* FIXME alloc iConfiguration string, set it in c->strings */ 95 95 ··· 113 113 114 114 /*-------------------------------------------------------------------------*/ 115 115 116 - static int __init audio_bind(struct usb_composite_dev *cdev) 116 + static int __ref audio_bind(struct usb_composite_dev *cdev) 117 117 { 118 118 int gcnum; 119 119 int status;
+2 -2
drivers/usb/gadget/cdc2.c
··· 129 129 /* 130 130 * We _always_ have both CDC ECM and CDC ACM functions. 131 131 */ 132 - static int __init cdc_do_config(struct usb_configuration *c) 132 + static int __ref cdc_do_config(struct usb_configuration *c) 133 133 { 134 134 int status; 135 135 ··· 159 159 160 160 /*-------------------------------------------------------------------------*/ 161 161 162 - static int __init cdc_bind(struct usb_composite_dev *cdev) 162 + static int __ref cdc_bind(struct usb_composite_dev *cdev) 163 163 { 164 164 int gcnum; 165 165 struct usb_gadget *gadget = cdev->gadget;
+69 -4
drivers/usb/gadget/composite.c
··· 673 673 * string IDs. Drivers for functions, configurations, or gadgets will 674 674 * then store that ID in the appropriate descriptors and string table. 675 675 * 676 - * All string identifier should be allocated using this routine, to 677 - * ensure that for example different functions don't wrongly assign 678 - * different meanings to the same identifier. 676 + * All string identifier should be allocated using this, 677 + * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure 678 + * that for example different functions don't wrongly assign different 679 + * meanings to the same identifier. 679 680 */ 680 681 int usb_string_id(struct usb_composite_dev *cdev) 681 682 { 682 683 if (cdev->next_string_id < 254) { 683 - /* string id 0 is reserved */ 684 + /* string id 0 is reserved by USB spec for list of 685 + * supported languages */ 686 + /* 255 reserved as well? -- mina86 */ 684 687 cdev->next_string_id++; 685 688 return cdev->next_string_id; 686 689 } 687 690 return -ENODEV; 688 691 } 692 + 693 + /** 694 + * usb_string_ids() - allocate unused string IDs in batch 695 + * @cdev: the device whose string descriptor IDs are being allocated 696 + * @str: an array of usb_string objects to assign numbers to 697 + * Context: single threaded during gadget setup 698 + * 699 + * @usb_string_ids() is called from bind() callbacks to allocate 700 + * string IDs. Drivers for functions, configurations, or gadgets will 701 + * then copy IDs from the string table to the appropriate descriptors 702 + * and string table for other languages. 703 + * 704 + * All string identifier should be allocated using this, 705 + * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for 706 + * example different functions don't wrongly assign different meanings 707 + * to the same identifier. 708 + */ 709 + int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str) 710 + { 711 + int next = cdev->next_string_id; 712 + 713 + for (; str->s; ++str) { 714 + if (unlikely(next >= 254)) 715 + return -ENODEV; 716 + str->id = ++next; 717 + } 718 + 719 + cdev->next_string_id = next; 720 + 721 + return 0; 722 + } 723 + 724 + /** 725 + * usb_string_ids_n() - allocate unused string IDs in batch 726 + * @cdev: the device whose string descriptor IDs are being allocated 727 + * @n: number of string IDs to allocate 728 + * Context: single threaded during gadget setup 729 + * 730 + * Returns the first requested ID. This ID and next @n-1 IDs are now 731 + * valid IDs. At least providind that @n is non zore because if it 732 + * is, returns last requested ID which is now very useful information. 733 + * 734 + * @usb_string_ids_n() is called from bind() callbacks to allocate 735 + * string IDs. Drivers for functions, configurations, or gadgets will 736 + * then store that ID in the appropriate descriptors and string table. 737 + * 738 + * All string identifier should be allocated using this, 739 + * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for 740 + * example different functions don't wrongly assign different meanings 741 + * to the same identifier. 742 + */ 743 + int usb_string_ids_n(struct usb_composite_dev *c, unsigned n) 744 + { 745 + unsigned next = c->next_string_id; 746 + if (unlikely(n > 254 || (unsigned)next + n > 254)) 747 + return -ENODEV; 748 + c->next_string_id += n; 749 + return next + 1; 750 + } 751 + 689 752 690 753 /*-------------------------------------------------------------------------*/ 691 754 ··· 956 893 spin_lock_irqsave(&cdev->lock, flags); 957 894 if (cdev->config) 958 895 reset_config(cdev); 896 + if (composite->disconnect) 897 + composite->disconnect(cdev); 959 898 spin_unlock_irqrestore(&cdev->lock, flags); 960 899 } 961 900
+434
drivers/usb/gadget/dbgp.c
··· 1 + /* 2 + * dbgp.c -- EHCI Debug Port device gadget 3 + * 4 + * Copyright (C) 2010 Stephane Duverger 5 + * 6 + * Released under the GPLv2. 7 + * 8 + */ 9 + 10 + /* verbose messages */ 11 + #include <linux/kernel.h> 12 + #include <linux/device.h> 13 + #include <linux/usb/ch9.h> 14 + #include <linux/usb/gadget.h> 15 + 16 + /* See comments in "zero.c" */ 17 + #include "epautoconf.c" 18 + 19 + #ifdef CONFIG_USB_G_DBGP_SERIAL 20 + #include "u_serial.c" 21 + #endif 22 + 23 + #define DRIVER_VENDOR_ID 0x0525 /* NetChip */ 24 + #define DRIVER_PRODUCT_ID 0xc0de /* undefined */ 25 + 26 + #define USB_DEBUG_MAX_PACKET_SIZE 8 27 + #define DBGP_REQ_EP0_LEN 128 28 + #define DBGP_REQ_LEN 512 29 + 30 + static struct dbgp { 31 + struct usb_gadget *gadget; 32 + struct usb_request *req; 33 + struct usb_ep *i_ep; 34 + struct usb_ep *o_ep; 35 + #ifdef CONFIG_USB_G_DBGP_SERIAL 36 + struct gserial *serial; 37 + #endif 38 + } dbgp; 39 + 40 + static struct usb_device_descriptor device_desc = { 41 + .bLength = sizeof device_desc, 42 + .bDescriptorType = USB_DT_DEVICE, 43 + .bcdUSB = __constant_cpu_to_le16(0x0200), 44 + .bDeviceClass = USB_CLASS_VENDOR_SPEC, 45 + .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID), 46 + .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID), 47 + .bNumConfigurations = 1, 48 + }; 49 + 50 + static struct usb_debug_descriptor dbg_desc = { 51 + .bLength = sizeof dbg_desc, 52 + .bDescriptorType = USB_DT_DEBUG, 53 + }; 54 + 55 + static struct usb_endpoint_descriptor i_desc = { 56 + .bLength = USB_DT_ENDPOINT_SIZE, 57 + .bDescriptorType = USB_DT_ENDPOINT, 58 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 59 + .bEndpointAddress = USB_DIR_IN, 60 + }; 61 + 62 + static struct usb_endpoint_descriptor o_desc = { 63 + .bLength = USB_DT_ENDPOINT_SIZE, 64 + .bDescriptorType = USB_DT_ENDPOINT, 65 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 66 + .bEndpointAddress = USB_DIR_OUT, 67 + }; 68 + 69 + #ifdef CONFIG_USB_G_DBGP_PRINTK 70 + static int dbgp_consume(char *buf, unsigned len) 71 + { 72 + char c; 73 + 74 + if (!len) 75 + return 0; 76 + 77 + c = buf[len-1]; 78 + if (c != 0) 79 + buf[len-1] = 0; 80 + 81 + printk(KERN_NOTICE "%s%c", buf, c); 82 + return 0; 83 + } 84 + 85 + static void __disable_ep(struct usb_ep *ep) 86 + { 87 + if (ep && ep->driver_data == dbgp.gadget) { 88 + usb_ep_disable(ep); 89 + ep->driver_data = NULL; 90 + } 91 + } 92 + 93 + static void dbgp_disable_ep(void) 94 + { 95 + __disable_ep(dbgp.i_ep); 96 + __disable_ep(dbgp.o_ep); 97 + } 98 + 99 + static void dbgp_complete(struct usb_ep *ep, struct usb_request *req) 100 + { 101 + int stp; 102 + int err = 0; 103 + int status = req->status; 104 + 105 + if (ep == dbgp.i_ep) { 106 + stp = 1; 107 + goto fail; 108 + } 109 + 110 + if (status != 0) { 111 + stp = 2; 112 + goto release_req; 113 + } 114 + 115 + dbgp_consume(req->buf, req->actual); 116 + 117 + req->length = DBGP_REQ_LEN; 118 + err = usb_ep_queue(ep, req, GFP_ATOMIC); 119 + if (err < 0) { 120 + stp = 3; 121 + goto release_req; 122 + } 123 + 124 + return; 125 + 126 + release_req: 127 + kfree(req->buf); 128 + usb_ep_free_request(dbgp.o_ep, req); 129 + dbgp_disable_ep(); 130 + fail: 131 + dev_dbg(&dbgp.gadget->dev, 132 + "complete: failure (%d:%d) ==> %d\n", stp, err, status); 133 + } 134 + 135 + static int dbgp_enable_ep_req(struct usb_ep *ep) 136 + { 137 + int err, stp; 138 + struct usb_request *req; 139 + 140 + req = usb_ep_alloc_request(ep, GFP_KERNEL); 141 + if (!req) { 142 + err = -ENOMEM; 143 + stp = 1; 144 + goto fail_1; 145 + } 146 + 147 + req->buf = kmalloc(DBGP_REQ_LEN, GFP_KERNEL); 148 + if (!req->buf) { 149 + err = -ENOMEM; 150 + stp = 2; 151 + goto fail_2; 152 + } 153 + 154 + req->complete = dbgp_complete; 155 + req->length = DBGP_REQ_LEN; 156 + err = usb_ep_queue(ep, req, GFP_ATOMIC); 157 + if (err < 0) { 158 + stp = 3; 159 + goto fail_3; 160 + } 161 + 162 + return 0; 163 + 164 + fail_3: 165 + kfree(req->buf); 166 + fail_2: 167 + usb_ep_free_request(dbgp.o_ep, req); 168 + fail_1: 169 + dev_dbg(&dbgp.gadget->dev, 170 + "enable ep req: failure (%d:%d)\n", stp, err); 171 + return err; 172 + } 173 + 174 + static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc) 175 + { 176 + int err = usb_ep_enable(ep, desc); 177 + ep->driver_data = dbgp.gadget; 178 + return err; 179 + } 180 + 181 + static int dbgp_enable_ep(void) 182 + { 183 + int err, stp; 184 + 185 + err = __enable_ep(dbgp.i_ep, &i_desc); 186 + if (err < 0) { 187 + stp = 1; 188 + goto fail_1; 189 + } 190 + 191 + err = __enable_ep(dbgp.o_ep, &o_desc); 192 + if (err < 0) { 193 + stp = 2; 194 + goto fail_2; 195 + } 196 + 197 + err = dbgp_enable_ep_req(dbgp.o_ep); 198 + if (err < 0) { 199 + stp = 3; 200 + goto fail_3; 201 + } 202 + 203 + return 0; 204 + 205 + fail_3: 206 + __disable_ep(dbgp.o_ep); 207 + fail_2: 208 + __disable_ep(dbgp.i_ep); 209 + fail_1: 210 + dev_dbg(&dbgp.gadget->dev, "enable ep: failure (%d:%d)\n", stp, err); 211 + return err; 212 + } 213 + #endif 214 + 215 + static void dbgp_disconnect(struct usb_gadget *gadget) 216 + { 217 + #ifdef CONFIG_USB_G_DBGP_PRINTK 218 + dbgp_disable_ep(); 219 + #else 220 + gserial_disconnect(dbgp.serial); 221 + #endif 222 + } 223 + 224 + static void dbgp_unbind(struct usb_gadget *gadget) 225 + { 226 + #ifdef CONFIG_USB_G_DBGP_SERIAL 227 + kfree(dbgp.serial); 228 + #endif 229 + if (dbgp.req) { 230 + kfree(dbgp.req->buf); 231 + usb_ep_free_request(gadget->ep0, dbgp.req); 232 + } 233 + 234 + gadget->ep0->driver_data = NULL; 235 + } 236 + 237 + static int __init dbgp_configure_endpoints(struct usb_gadget *gadget) 238 + { 239 + int stp; 240 + 241 + usb_ep_autoconfig_reset(gadget); 242 + 243 + dbgp.i_ep = usb_ep_autoconfig(gadget, &i_desc); 244 + if (!dbgp.i_ep) { 245 + stp = 1; 246 + goto fail_1; 247 + } 248 + 249 + dbgp.i_ep->driver_data = gadget; 250 + i_desc.wMaxPacketSize = 251 + __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE); 252 + 253 + dbgp.o_ep = usb_ep_autoconfig(gadget, &o_desc); 254 + if (!dbgp.o_ep) { 255 + dbgp.i_ep->driver_data = NULL; 256 + stp = 2; 257 + goto fail_2; 258 + } 259 + 260 + dbgp.o_ep->driver_data = gadget; 261 + o_desc.wMaxPacketSize = 262 + __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE); 263 + 264 + dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress & 0x7f; 265 + dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress & 0x7f; 266 + 267 + #ifdef CONFIG_USB_G_DBGP_SERIAL 268 + dbgp.serial->in = dbgp.i_ep; 269 + dbgp.serial->out = dbgp.o_ep; 270 + 271 + dbgp.serial->in_desc = &i_desc; 272 + dbgp.serial->out_desc = &o_desc; 273 + 274 + if (gserial_setup(gadget, 1) < 0) { 275 + stp = 3; 276 + goto fail_3; 277 + } 278 + 279 + return 0; 280 + 281 + fail_3: 282 + dbgp.o_ep->driver_data = NULL; 283 + #else 284 + return 0; 285 + #endif 286 + fail_2: 287 + dbgp.i_ep->driver_data = NULL; 288 + fail_1: 289 + dev_dbg(&dbgp.gadget->dev, "ep config: failure (%d)\n", stp); 290 + return -ENODEV; 291 + } 292 + 293 + static int __init dbgp_bind(struct usb_gadget *gadget) 294 + { 295 + int err, stp; 296 + 297 + dbgp.gadget = gadget; 298 + 299 + dbgp.req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); 300 + if (!dbgp.req) { 301 + err = -ENOMEM; 302 + stp = 1; 303 + goto fail; 304 + } 305 + 306 + dbgp.req->buf = kmalloc(DBGP_REQ_EP0_LEN, GFP_KERNEL); 307 + if (!dbgp.req->buf) { 308 + err = -ENOMEM; 309 + stp = 2; 310 + goto fail; 311 + } 312 + 313 + dbgp.req->length = DBGP_REQ_EP0_LEN; 314 + gadget->ep0->driver_data = gadget; 315 + 316 + #ifdef CONFIG_USB_G_DBGP_SERIAL 317 + dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL); 318 + if (!dbgp.serial) { 319 + stp = 3; 320 + err = -ENOMEM; 321 + goto fail; 322 + } 323 + #endif 324 + err = dbgp_configure_endpoints(gadget); 325 + if (err < 0) { 326 + stp = 4; 327 + goto fail; 328 + } 329 + 330 + dev_dbg(&dbgp.gadget->dev, "bind: success\n"); 331 + return 0; 332 + 333 + fail: 334 + dev_dbg(&gadget->dev, "bind: failure (%d:%d)\n", stp, err); 335 + dbgp_unbind(gadget); 336 + return err; 337 + } 338 + 339 + static void dbgp_setup_complete(struct usb_ep *ep, 340 + struct usb_request *req) 341 + { 342 + dev_dbg(&dbgp.gadget->dev, "setup complete: %d, %d/%d\n", 343 + req->status, req->actual, req->length); 344 + } 345 + 346 + static int dbgp_setup(struct usb_gadget *gadget, 347 + const struct usb_ctrlrequest *ctrl) 348 + { 349 + struct usb_request *req = dbgp.req; 350 + u8 request = ctrl->bRequest; 351 + u16 value = le16_to_cpu(ctrl->wValue); 352 + u16 length = le16_to_cpu(ctrl->wLength); 353 + int err = 0; 354 + void *data; 355 + u16 len; 356 + 357 + gadget->ep0->driver_data = gadget; 358 + 359 + if (request == USB_REQ_GET_DESCRIPTOR) { 360 + switch (value>>8) { 361 + case USB_DT_DEVICE: 362 + dev_dbg(&dbgp.gadget->dev, "setup: desc device\n"); 363 + len = sizeof device_desc; 364 + data = &device_desc; 365 + break; 366 + case USB_DT_DEBUG: 367 + dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n"); 368 + len = sizeof dbg_desc; 369 + data = &dbg_desc; 370 + break; 371 + default: 372 + goto fail; 373 + } 374 + } else if (request == USB_REQ_SET_FEATURE && 375 + value == USB_DEVICE_DEBUG_MODE) { 376 + len = 0; 377 + data = NULL; 378 + dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n"); 379 + #ifdef CONFIG_USB_G_DBGP_PRINTK 380 + err = dbgp_enable_ep(); 381 + #else 382 + err = gserial_connect(dbgp.serial, 0); 383 + #endif 384 + if (err < 0) 385 + goto fail; 386 + } else 387 + goto fail; 388 + 389 + if (len >= 0) { 390 + req->length = min(length, len); 391 + req->zero = len < req->length; 392 + if (data && req->length) 393 + memcpy(req->buf, data, req->length); 394 + 395 + req->complete = dbgp_setup_complete; 396 + return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 397 + } 398 + 399 + fail: 400 + dev_dbg(&dbgp.gadget->dev, 401 + "setup: failure req %x v %x\n", request, value); 402 + return err; 403 + } 404 + 405 + static struct usb_gadget_driver dbgp_driver = { 406 + .function = "dbgp", 407 + .speed = USB_SPEED_HIGH, 408 + .bind = dbgp_bind, 409 + .unbind = dbgp_unbind, 410 + .setup = dbgp_setup, 411 + .disconnect = dbgp_disconnect, 412 + .driver = { 413 + .owner = THIS_MODULE, 414 + .name = "dbgp" 415 + }, 416 + }; 417 + 418 + static int __init dbgp_init(void) 419 + { 420 + return usb_gadget_register_driver(&dbgp_driver); 421 + } 422 + 423 + static void __exit dbgp_exit(void) 424 + { 425 + usb_gadget_unregister_driver(&dbgp_driver); 426 + #ifdef CONFIG_USB_G_DBGP_SERIAL 427 + gserial_cleanup(); 428 + #endif 429 + } 430 + 431 + MODULE_AUTHOR("Stephane Duverger"); 432 + MODULE_LICENSE("GPL"); 433 + module_init(dbgp_init); 434 + module_exit(dbgp_exit);
+3 -3
drivers/usb/gadget/dummy_hcd.c
··· 1542 1542 dum = hcd_to_dummy (hcd); 1543 1543 1544 1544 spin_lock_irqsave (&dum->lock, flags); 1545 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 1545 + if (!HCD_HW_ACCESSIBLE(hcd)) 1546 1546 goto done; 1547 1547 1548 1548 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { ··· 1588 1588 int retval = 0; 1589 1589 unsigned long flags; 1590 1590 1591 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 1591 + if (!HCD_HW_ACCESSIBLE(hcd)) 1592 1592 return -ETIMEDOUT; 1593 1593 1594 1594 dum = hcd_to_dummy (hcd); ··· 1739 1739 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 1740 1740 1741 1741 spin_lock_irq (&dum->lock); 1742 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1742 + if (!HCD_HW_ACCESSIBLE(hcd)) { 1743 1743 rc = -ESHUTDOWN; 1744 1744 } else { 1745 1745 dum->rh_state = DUMMY_RH_RUNNING;
+3 -3
drivers/usb/gadget/ether.c
··· 237 237 * the first one present. That's to make Microsoft's drivers happy, 238 238 * and to follow DOCSIS 1.0 (cable modem standard). 239 239 */ 240 - static int __init rndis_do_config(struct usb_configuration *c) 240 + static int __ref rndis_do_config(struct usb_configuration *c) 241 241 { 242 242 /* FIXME alloc iConfiguration string, set it in c->strings */ 243 243 ··· 270 270 /* 271 271 * We _always_ have an ECM, CDC Subset, or EEM configuration. 272 272 */ 273 - static int __init eth_do_config(struct usb_configuration *c) 273 + static int __ref eth_do_config(struct usb_configuration *c) 274 274 { 275 275 /* FIXME alloc iConfiguration string, set it in c->strings */ 276 276 ··· 297 297 298 298 /*-------------------------------------------------------------------------*/ 299 299 300 - static int __init eth_bind(struct usb_composite_dev *cdev) 300 + static int __ref eth_bind(struct usb_composite_dev *cdev) 301 301 { 302 302 int gcnum; 303 303 struct usb_gadget *gadget = cdev->gadget;
+15 -23
drivers/usb/gadget/f_fs.c
··· 714 714 struct ffs_function *func = ffs->func; 715 715 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; 716 716 } else if (gadget->ops->ioctl) { 717 - lock_kernel(); 718 717 ret = gadget->ops->ioctl(gadget, code, value); 719 - unlock_kernel(); 720 718 } else { 721 719 ret = -ENOTTY; 722 720 } ··· 1375 1377 1376 1378 static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) 1377 1379 { 1378 - unsigned i, count; 1380 + struct usb_gadget_strings **lang; 1381 + int first_id; 1379 1382 1380 1383 ENTER(); 1381 1384 ··· 1384 1385 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) 1385 1386 return -EBADFD; 1386 1387 1387 - ffs_data_get(ffs); 1388 + first_id = usb_string_ids_n(cdev, ffs->strings_count); 1389 + if (unlikely(first_id < 0)) 1390 + return first_id; 1388 1391 1389 1392 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); 1390 1393 if (unlikely(!ffs->ep0req)) ··· 1394 1393 ffs->ep0req->complete = ffs_ep0_complete; 1395 1394 ffs->ep0req->context = ffs; 1396 1395 1397 - /* Get strings identifiers */ 1398 - for (count = ffs->strings_count, i = 0; i < count; ++i) { 1399 - struct usb_gadget_strings **lang; 1400 - 1401 - int id = usb_string_id(cdev); 1402 - if (unlikely(id < 0)) { 1403 - usb_ep_free_request(cdev->gadget->ep0, ffs->ep0req); 1404 - ffs->ep0req = NULL; 1405 - return id; 1406 - } 1407 - 1408 - lang = ffs->stringtabs; 1409 - do { 1410 - (*lang)->strings[i].id = id; 1411 - ++lang; 1412 - } while (*lang); 1396 + lang = ffs->stringtabs; 1397 + for (lang = ffs->stringtabs; *lang; ++lang) { 1398 + struct usb_string *str = (*lang)->strings; 1399 + int id = first_id; 1400 + for (; str->s; ++id, ++str) 1401 + str->id = id; 1413 1402 } 1414 1403 1415 1404 ffs->gadget = cdev->gadget; 1405 + ffs_data_get(ffs); 1416 1406 return 0; 1417 1407 } 1418 1408 ··· 1472 1480 } 1473 1481 1474 1482 1475 - static int functionfs_add(struct usb_composite_dev *cdev, 1476 - struct usb_configuration *c, 1477 - struct ffs_data *ffs) 1483 + static int functionfs_bind_config(struct usb_composite_dev *cdev, 1484 + struct usb_configuration *c, 1485 + struct ffs_data *ffs) 1478 1486 { 1479 1487 struct ffs_function *func; 1480 1488 int ret;
+3 -3
drivers/usb/gadget/f_hid.c
··· 142 142 static ssize_t f_hidg_read(struct file *file, char __user *buffer, 143 143 size_t count, loff_t *ptr) 144 144 { 145 - struct f_hidg *hidg = (struct f_hidg *)file->private_data; 145 + struct f_hidg *hidg = file->private_data; 146 146 char *tmp_buff = NULL; 147 147 unsigned long flags; 148 148 ··· 200 200 static ssize_t f_hidg_write(struct file *file, const char __user *buffer, 201 201 size_t count, loff_t *offp) 202 202 { 203 - struct f_hidg *hidg = (struct f_hidg *)file->private_data; 203 + struct f_hidg *hidg = file->private_data; 204 204 ssize_t status = -ENOMEM; 205 205 206 206 if (!access_ok(VERIFY_READ, buffer, count)) ··· 257 257 258 258 static unsigned int f_hidg_poll(struct file *file, poll_table *wait) 259 259 { 260 - struct f_hidg *hidg = (struct f_hidg *)file->private_data; 260 + struct f_hidg *hidg = file->private_data; 261 261 unsigned int ret = 0; 262 262 263 263 poll_wait(file, &hidg->read_queue, wait);
+2 -2
drivers/usb/gadget/f_loopback.c
··· 324 324 325 325 /*-------------------------------------------------------------------------*/ 326 326 327 - static int __init loopback_bind_config(struct usb_configuration *c) 327 + static int __ref loopback_bind_config(struct usb_configuration *c) 328 328 { 329 329 struct f_loopback *loop; 330 330 int status; ··· 346 346 return status; 347 347 } 348 348 349 - static struct usb_configuration loopback_driver = { 349 + static struct usb_configuration loopback_driver = { 350 350 .label = "loopback", 351 351 .strings = loopback_strings, 352 352 .bind = loopback_bind_config,
+80 -45
drivers/usb/gadget/f_mass_storage.c
··· 316 316 /*-------------------------------------------------------------------------*/ 317 317 318 318 struct fsg_dev; 319 + struct fsg_common; 320 + 321 + /* FSF callback functions */ 322 + struct fsg_operations { 323 + /* Callback function to call when thread exits. If no 324 + * callback is set or it returns value lower then zero MSF 325 + * will force eject all LUNs it operates on (including those 326 + * marked as non-removable or with prevent_medium_removal flag 327 + * set). */ 328 + int (*thread_exits)(struct fsg_common *common); 329 + 330 + /* Called prior to ejection. Negative return means error, 331 + * zero means to continue with ejection, positive means not to 332 + * eject. */ 333 + int (*pre_eject)(struct fsg_common *common, 334 + struct fsg_lun *lun, int num); 335 + /* Called after ejection. Negative return means error, zero 336 + * or positive is just a success. */ 337 + int (*post_eject)(struct fsg_common *common, 338 + struct fsg_lun *lun, int num); 339 + }; 319 340 320 341 321 342 /* Data shared by all the FSG instances. */ ··· 354 333 struct usb_ep *ep0; /* Copy of gadget->ep0 */ 355 334 struct usb_request *ep0req; /* Copy of cdev->req */ 356 335 unsigned int ep0_req_tag; 357 - const char *ep0req_name; 358 336 359 337 struct fsg_buffhd *next_buffhd_to_fill; 360 338 struct fsg_buffhd *next_buffhd_to_drain; ··· 389 369 struct completion thread_notifier; 390 370 struct task_struct *thread_task; 391 371 392 - /* Callback function to call when thread exits. */ 393 - int (*thread_exits)(struct fsg_common *common); 372 + /* Callback functions. */ 373 + const struct fsg_operations *ops; 394 374 /* Gadget's private data. */ 395 375 void *private_data; 396 376 ··· 414 394 const char *lun_name_format; 415 395 const char *thread_name; 416 396 417 - /* Callback function to call when thread exits. If no 418 - * callback is set or it returns value lower then zero MSF 419 - * will force eject all LUNs it operates on (including those 420 - * marked as non-removable or with prevent_medium_removal flag 421 - * set). */ 422 - int (*thread_exits)(struct fsg_common *common); 397 + /* Callback functions. */ 398 + const struct fsg_operations *ops; 423 399 /* Gadget's private data. */ 424 400 void *private_data; 425 401 ··· 451 435 if (common->fsg) 452 436 return 1; 453 437 ERROR(common, "common->fsg is NULL in %s at %u\n", func, line); 438 + WARN_ON(1); 454 439 return 0; 455 440 } 456 441 ··· 640 623 641 624 /* Respond with data/status */ 642 625 req->length = min((u16)1, w_length); 643 - fsg->common->ep0req_name = 644 - ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out"; 645 626 return ep0_queue(fsg->common); 646 627 } 647 628 ··· 1410 1395 } else if (!curlun->removable) { 1411 1396 curlun->sense_data = SS_INVALID_COMMAND; 1412 1397 return -EINVAL; 1413 - } 1414 - 1415 - loej = common->cmnd[4] & 0x02; 1416 - start = common->cmnd[4] & 0x01; 1417 - 1418 - /* eject code from file_storage.c:do_start_stop() */ 1419 - 1420 - if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */ 1421 - (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */ 1398 + } else if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */ 1399 + (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */ 1422 1400 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1423 1401 return -EINVAL; 1424 1402 } 1425 1403 1426 - if (!start) { 1427 - /* Are we allowed to unload the media? */ 1428 - if (curlun->prevent_medium_removal) { 1429 - LDBG(curlun, "unload attempt prevented\n"); 1430 - curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED; 1431 - return -EINVAL; 1432 - } 1433 - if (loej) { /* Simulate an unload/eject */ 1434 - up_read(&common->filesem); 1435 - down_write(&common->filesem); 1436 - fsg_lun_close(curlun); 1437 - up_write(&common->filesem); 1438 - down_read(&common->filesem); 1439 - } 1440 - } else { 1404 + loej = common->cmnd[4] & 0x02; 1405 + start = common->cmnd[4] & 0x01; 1441 1406 1442 - /* Our emulation doesn't support mounting; the medium is 1443 - * available for use as soon as it is loaded. */ 1407 + /* Our emulation doesn't support mounting; the medium is 1408 + * available for use as soon as it is loaded. */ 1409 + if (start) { 1444 1410 if (!fsg_lun_is_open(curlun)) { 1445 1411 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 1446 1412 return -EINVAL; 1447 1413 } 1414 + return 0; 1448 1415 } 1449 - return 0; 1416 + 1417 + /* Are we allowed to unload the media? */ 1418 + if (curlun->prevent_medium_removal) { 1419 + LDBG(curlun, "unload attempt prevented\n"); 1420 + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED; 1421 + return -EINVAL; 1422 + } 1423 + 1424 + if (!loej) 1425 + return 0; 1426 + 1427 + /* Simulate an unload/eject */ 1428 + if (common->ops && common->ops->pre_eject) { 1429 + int r = common->ops->pre_eject(common, curlun, 1430 + curlun - common->luns); 1431 + if (unlikely(r < 0)) 1432 + return r; 1433 + else if (r) 1434 + return 0; 1435 + } 1436 + 1437 + up_read(&common->filesem); 1438 + down_write(&common->filesem); 1439 + fsg_lun_close(curlun); 1440 + up_write(&common->filesem); 1441 + down_read(&common->filesem); 1442 + 1443 + return common->ops && common->ops->post_eject 1444 + ? min(0, common->ops->post_eject(common, curlun, 1445 + curlun - common->luns)) 1446 + : 0; 1450 1447 } 1451 1448 1452 1449 ··· 2637 2610 common->thread_task = NULL; 2638 2611 spin_unlock_irq(&common->lock); 2639 2612 2640 - if (!common->thread_exits || common->thread_exits(common) < 0) { 2613 + if (!common->ops || !common->ops->thread_exits 2614 + || common->ops->thread_exits(common) < 0) { 2641 2615 struct fsg_lun *curlun = common->luns; 2642 2616 unsigned i = common->nluns; 2643 2617 ··· 2714 2686 common->free_storage_on_release = 0; 2715 2687 } 2716 2688 2689 + common->ops = cfg->ops; 2717 2690 common->private_data = cfg->private_data; 2718 2691 2719 2692 common->gadget = gadget; ··· 2836 2807 2837 2808 2838 2809 /* Tell the thread to start working */ 2839 - common->thread_exits = cfg->thread_exits; 2840 2810 common->thread_task = 2841 2811 kthread_create(fsg_main_thread, common, 2842 2812 OR(cfg->thread_name, "file-storage")); ··· 3018 2990 NULL, 3019 2991 }; 3020 2992 3021 - static int fsg_add(struct usb_composite_dev *cdev, 3022 - struct usb_configuration *c, 3023 - struct fsg_common *common) 2993 + static int fsg_bind_config(struct usb_composite_dev *cdev, 2994 + struct usb_configuration *c, 2995 + struct fsg_common *common) 3024 2996 { 3025 2997 struct fsg_dev *fsg; 3026 2998 int rc; ··· 3052 3024 return rc; 3053 3025 } 3054 3026 3027 + static inline int __deprecated __maybe_unused 3028 + fsg_add(struct usb_composite_dev *cdev, 3029 + struct usb_configuration *c, 3030 + struct fsg_common *common) 3031 + { 3032 + return fsg_bind_config(cdev, c, common); 3033 + } 3055 3034 3056 3035 3057 3036 /************************* Module parameters *************************/ ··· 3131 3096 cfg->product_name = 0; 3132 3097 cfg->release = 0xffff; 3133 3098 3134 - cfg->thread_exits = 0; 3135 - cfg->private_data = 0; 3099 + cfg->ops = NULL; 3100 + cfg->private_data = NULL; 3136 3101 3137 3102 /* Finalise */ 3138 3103 cfg->can_stall = params->stall;
+1 -1
drivers/usb/gadget/f_sourcesink.c
··· 404 404 405 405 /*-------------------------------------------------------------------------*/ 406 406 407 - static int __init sourcesink_bind_config(struct usb_configuration *c) 407 + static int __ref sourcesink_bind_config(struct usb_configuration *c) 408 408 { 409 409 struct f_sourcesink *ss; 410 410 int status;
+85 -19
drivers/usb/gadget/file_storage.c
··· 56 56 * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03), 57 57 * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by 58 58 * the optional "protocol" module parameter. In addition, the default 59 - * Vendor ID, Product ID, and release number can be overridden. 59 + * Vendor ID, Product ID, release number and serial number can be overridden. 60 60 * 61 61 * There is support for multiple logical units (LUNs), each of which has 62 62 * its own backing file. The number of LUNs can be set using the optional ··· 93 93 * removable Default false, boolean for removable media 94 94 * luns=N Default N = number of filenames, number of 95 95 * LUNs to support 96 + * nofua=b[,b...] Default false, booleans for ignore FUA flag 97 + * in SCSI WRITE(10,12) commands 96 98 * stall Default determined according to the type of 97 99 * USB device controller (usually true), 98 100 * boolean to permit the driver to halt ··· 108 106 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID 109 107 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID 110 108 * release=0xRRRR Override the USB release number (bcdDevice) 109 + * serial=HHHH... Override serial number (string of hex chars) 111 110 * buflen=N Default N=16384, buffer size used (will be 112 111 * rounded down to a multiple of 113 112 * PAGE_CACHE_SIZE) 114 113 * 115 114 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 116 - * "removable", "luns", "stall", and "cdrom" options are available; default 117 - * values are used for everything else. 115 + * "removable", "luns", "nofua", "stall", and "cdrom" options are available; 116 + * default values are used for everything else. 118 117 * 119 118 * The pathnames of the backing files and the ro settings are available in 120 - * the attribute files "file" and "ro" in the lun<n> subdirectory of the 121 - * gadget's sysfs directory. If the "removable" option is set, writing to 119 + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of 120 + * the gadget's sysfs directory. If the "removable" option is set, writing to 122 121 * these files will simulate ejecting/loading the medium (writing an empty 123 122 * line means eject) and adjusting a write-enable tab. Changes to the ro 124 123 * setting are not allowed when the medium is loaded or if CD-ROM emulation ··· 273 270 274 271 #define DRIVER_DESC "File-backed Storage Gadget" 275 272 #define DRIVER_NAME "g_file_storage" 273 + /* DRIVER_VERSION must be at least 6 characters long, as it is used 274 + * to generate a fallback serial number. */ 276 275 #define DRIVER_VERSION "20 November 2008" 277 276 278 277 static char fsg_string_manufacturer[64]; ··· 306 301 static struct { 307 302 char *file[FSG_MAX_LUNS]; 308 303 int ro[FSG_MAX_LUNS]; 304 + int nofua[FSG_MAX_LUNS]; 309 305 unsigned int num_filenames; 310 306 unsigned int num_ros; 307 + unsigned int num_nofuas; 311 308 unsigned int nluns; 312 309 313 310 int removable; ··· 321 314 unsigned short vendor; 322 315 unsigned short product; 323 316 unsigned short release; 317 + char *serial; 324 318 unsigned int buflen; 325 319 326 320 int transport_type; ··· 349 341 module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); 350 342 MODULE_PARM_DESC(ro, "true to force read-only"); 351 343 344 + module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas, 345 + S_IRUGO); 346 + MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit"); 347 + 352 348 module_param_named(luns, mod_data.nluns, uint, S_IRUGO); 353 349 MODULE_PARM_DESC(luns, "number of LUNs"); 354 350 ··· 365 353 module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); 366 354 MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); 367 355 356 + module_param_named(serial, mod_data.serial, charp, S_IRUGO); 357 + MODULE_PARM_DESC(serial, "USB serial number"); 368 358 369 359 /* In the non-TEST version, only the module parameters listed above 370 360 * are available. */ ··· 1286 1272 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1287 1273 return -EINVAL; 1288 1274 } 1289 - if (fsg->cmnd[1] & 0x08) { // FUA 1275 + /* FUA */ 1276 + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) { 1290 1277 spin_lock(&curlun->filp->f_lock); 1291 1278 curlun->filp->f_flags |= O_DSYNC; 1292 1279 spin_unlock(&curlun->filp->f_lock); ··· 3141 3126 3142 3127 /* The write permissions and store_xxx pointers are set in fsg_bind() */ 3143 3128 static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL); 3129 + static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL); 3144 3130 static DEVICE_ATTR(file, 0444, fsg_show_file, NULL); 3145 3131 3146 3132 ··· 3213 3197 { 3214 3198 int prot; 3215 3199 int gcnum; 3200 + int i; 3216 3201 3217 3202 /* Store the default values */ 3218 3203 mod_data.transport_type = USB_PR_BULK; ··· 3289 3272 ERROR(fsg, "invalid buflen\n"); 3290 3273 return -ETOOSMALL; 3291 3274 } 3275 + 3292 3276 #endif /* CONFIG_USB_FILE_STORAGE_TEST */ 3277 + 3278 + /* Serial string handling. 3279 + * On a real device, the serial string would be loaded 3280 + * from permanent storage. */ 3281 + if (mod_data.serial) { 3282 + const char *ch; 3283 + unsigned len = 0; 3284 + 3285 + /* Sanity check : 3286 + * The CB[I] specification limits the serial string to 3287 + * 12 uppercase hexadecimal characters. 3288 + * BBB need at least 12 uppercase hexadecimal characters, 3289 + * with a maximum of 126. */ 3290 + for (ch = mod_data.serial; *ch; ++ch) { 3291 + ++len; 3292 + if ((*ch < '0' || *ch > '9') && 3293 + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */ 3294 + WARNING(fsg, 3295 + "Invalid serial string character: %c; " 3296 + "Failing back to default\n", 3297 + *ch); 3298 + goto fill_serial; 3299 + } 3300 + } 3301 + if (len > 126 || 3302 + (mod_data.transport_type == USB_PR_BULK && len < 12) || 3303 + (mod_data.transport_type != USB_PR_BULK && len > 12)) { 3304 + WARNING(fsg, 3305 + "Invalid serial string length; " 3306 + "Failing back to default\n"); 3307 + goto fill_serial; 3308 + } 3309 + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial; 3310 + } else { 3311 + WARNING(fsg, 3312 + "Userspace failed to provide serial number; " 3313 + "Failing back to default\n"); 3314 + fill_serial: 3315 + /* Serial number not specified or invalid, make our own. 3316 + * We just encode it from the driver version string, 3317 + * 12 characters to comply with both CB[I] and BBB spec. 3318 + * Warning : Two devices running the same kernel will have 3319 + * the same fallback serial number. */ 3320 + for (i = 0; i < 12; i += 2) { 3321 + unsigned char c = DRIVER_VERSION[i / 2]; 3322 + 3323 + if (!c) 3324 + break; 3325 + sprintf(&fsg_string_serial[i], "%02X", c); 3326 + } 3327 + } 3293 3328 3294 3329 return 0; 3295 3330 } 3296 3331 3297 3332 3298 - static int __init fsg_bind(struct usb_gadget *gadget) 3333 + static int __ref fsg_bind(struct usb_gadget *gadget) 3299 3334 { 3300 3335 struct fsg_dev *fsg = the_fsg; 3301 3336 int rc; ··· 3374 3305 } 3375 3306 } 3376 3307 3308 + /* Only for removable media? */ 3309 + dev_attr_nofua.attr.mode = 0644; 3310 + dev_attr_nofua.store = fsg_store_nofua; 3311 + 3377 3312 /* Find out how many LUNs there should be */ 3378 3313 i = mod_data.nluns; 3379 3314 if (i == 0) ··· 3403 3330 curlun->ro = mod_data.cdrom || mod_data.ro[i]; 3404 3331 curlun->initially_ro = curlun->ro; 3405 3332 curlun->removable = mod_data.removable; 3333 + curlun->nofua = mod_data.nofua[i]; 3406 3334 curlun->dev.release = lun_release; 3407 3335 curlun->dev.parent = &gadget->dev; 3408 3336 curlun->dev.driver = &fsg_driver.driver; ··· 3417 3343 } 3418 3344 if ((rc = device_create_file(&curlun->dev, 3419 3345 &dev_attr_ro)) != 0 || 3346 + (rc = device_create_file(&curlun->dev, 3347 + &dev_attr_nofua)) != 0 || 3420 3348 (rc = device_create_file(&curlun->dev, 3421 3349 &dev_attr_file)) != 0) { 3422 3350 device_unregister(&curlun->dev); ··· 3523 3447 init_utsname()->sysname, init_utsname()->release, 3524 3448 gadget->name); 3525 3449 3526 - /* On a real device, serial[] would be loaded from permanent 3527 - * storage. We just encode it from the driver version string. */ 3528 - for (i = 0; i < sizeof fsg_string_serial - 2; i += 2) { 3529 - unsigned char c = DRIVER_VERSION[i / 2]; 3530 - 3531 - if (!c) 3532 - break; 3533 - sprintf(&fsg_string_serial[i], "%02X", c); 3534 - } 3535 - 3536 3450 fsg->thread_task = kthread_create(fsg_main_thread, fsg, 3537 3451 "file-storage-gadget"); 3538 3452 if (IS_ERR(fsg->thread_task)) { ··· 3544 3478 if (IS_ERR(p)) 3545 3479 p = NULL; 3546 3480 } 3547 - LINFO(curlun, "ro=%d, file: %s\n", 3548 - curlun->ro, (p ? p : "(error)")); 3481 + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n", 3482 + curlun->ro, curlun->nofua, (p ? p : "(error)")); 3549 3483 } 3550 3484 } 3551 3485 kfree(pathbuf);
+49 -127
drivers/usb/gadget/g_ffs.c
··· 32 32 # include "u_ether.c" 33 33 34 34 static u8 gfs_hostaddr[ETH_ALEN]; 35 - #else 36 - # if !defined CONFIG_USB_FUNCTIONFS_GENERIC 37 - # define CONFIG_USB_FUNCTIONFS_GENERIC 35 + # ifdef CONFIG_USB_FUNCTIONFS_ETH 36 + static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 38 37 # endif 38 + #else 39 39 # define gether_cleanup() do { } while (0) 40 40 # define gether_setup(gadget, hostaddr) ((int)0) 41 + # define gfs_hostaddr NULL 41 42 #endif 42 43 43 44 #include "f_fs.c" ··· 108 107 enum { 109 108 GFS_STRING_MANUFACTURER_IDX, 110 109 GFS_STRING_PRODUCT_IDX, 111 - #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 112 - GFS_STRING_RNDIS_CONFIG_IDX, 113 - #endif 114 - #ifdef CONFIG_USB_FUNCTIONFS_ETH 115 - GFS_STRING_ECM_CONFIG_IDX, 116 - #endif 117 - #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 118 - GFS_STRING_GENERIC_CONFIG_IDX, 119 - #endif 110 + GFS_STRING_FIRST_CONFIG_IDX, 120 111 }; 121 112 122 113 static char gfs_manufacturer[50]; ··· 119 126 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, 120 127 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, 121 128 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 122 - [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS", 129 + { .s = "FunctionFS + RNDIS" }, 123 130 #endif 124 131 #ifdef CONFIG_USB_FUNCTIONFS_ETH 125 - [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM", 132 + { .s = "FunctionFS + ECM" }, 126 133 #endif 127 134 #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 128 - [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS", 135 + { .s = "FunctionFS" }, 129 136 #endif 130 137 { } /* end of list */ 131 138 }; ··· 139 146 }; 140 147 141 148 149 + 150 + struct gfs_configuration { 151 + struct usb_configuration c; 152 + int (*eth)(struct usb_configuration *c, u8 *ethaddr); 153 + } gfs_configurations[] = { 142 154 #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 143 - static int gfs_do_rndis_config(struct usb_configuration *c); 144 - 145 - static struct usb_configuration gfs_rndis_config_driver = { 146 - .label = "FunctionFS + RNDIS", 147 - .bind = gfs_do_rndis_config, 148 - .bConfigurationValue = 1, 149 - /* .iConfiguration = DYNAMIC */ 150 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 151 - }; 152 - # define gfs_add_rndis_config(cdev) \ 153 - usb_add_config(cdev, &gfs_rndis_config_driver) 154 - #else 155 - # define gfs_add_rndis_config(cdev) 0 155 + { 156 + .eth = rndis_bind_config, 157 + }, 156 158 #endif 157 - 158 159 159 160 #ifdef CONFIG_USB_FUNCTIONFS_ETH 160 - static int gfs_do_ecm_config(struct usb_configuration *c); 161 - 162 - static struct usb_configuration gfs_ecm_config_driver = { 163 - .label = "FunctionFS + ECM", 164 - .bind = gfs_do_ecm_config, 165 - .bConfigurationValue = 1, 166 - /* .iConfiguration = DYNAMIC */ 167 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 168 - }; 169 - # define gfs_add_ecm_config(cdev) \ 170 - usb_add_config(cdev, &gfs_ecm_config_driver) 171 - #else 172 - # define gfs_add_ecm_config(cdev) 0 161 + { 162 + .eth = eth_bind_config, 163 + }, 173 164 #endif 174 - 175 165 176 166 #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 177 - static int gfs_do_generic_config(struct usb_configuration *c); 178 - 179 - static struct usb_configuration gfs_generic_config_driver = { 180 - .label = "FunctionFS", 181 - .bind = gfs_do_generic_config, 182 - .bConfigurationValue = 2, 183 - /* .iConfiguration = DYNAMIC */ 184 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 185 - }; 186 - # define gfs_add_generic_config(cdev) \ 187 - usb_add_config(cdev, &gfs_generic_config_driver) 188 - #else 189 - # define gfs_add_generic_config(cdev) 0 167 + { 168 + }, 190 169 #endif 170 + }; 191 171 192 172 193 173 static int gfs_bind(struct usb_composite_dev *cdev); 194 174 static int gfs_unbind(struct usb_composite_dev *cdev); 175 + static int gfs_do_config(struct usb_configuration *c); 195 176 196 177 static struct usb_composite_driver gfs_driver = { 197 178 .name = gfs_short_name, ··· 234 267 235 268 static int gfs_bind(struct usb_composite_dev *cdev) 236 269 { 237 - int ret; 270 + int ret, i; 238 271 239 272 ENTER(); 240 273 ··· 251 284 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", 252 285 init_utsname()->sysname, init_utsname()->release, 253 286 cdev->gadget->name); 254 - ret = usb_string_id(cdev); 255 - if (unlikely(ret < 0)) 256 - goto error; 257 - gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret; 258 - gfs_dev_desc.iManufacturer = ret; 259 287 260 - ret = usb_string_id(cdev); 288 + ret = usb_string_ids_tab(cdev, gfs_strings); 261 289 if (unlikely(ret < 0)) 262 290 goto error; 263 - gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret; 264 - gfs_dev_desc.iProduct = ret; 265 291 266 - #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 267 - ret = usb_string_id(cdev); 268 - if (unlikely(ret < 0)) 269 - goto error; 270 - gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret; 271 - gfs_rndis_config_driver.iConfiguration = ret; 272 - #endif 273 - 274 - #ifdef CONFIG_USB_FUNCTIONFS_ETH 275 - ret = usb_string_id(cdev); 276 - if (unlikely(ret < 0)) 277 - goto error; 278 - gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret; 279 - gfs_ecm_config_driver.iConfiguration = ret; 280 - #endif 281 - 282 - #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 283 - ret = usb_string_id(cdev); 284 - if (unlikely(ret < 0)) 285 - goto error; 286 - gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret; 287 - gfs_generic_config_driver.iConfiguration = ret; 288 - #endif 292 + gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id; 293 + gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id; 289 294 290 295 ret = functionfs_bind(gfs_ffs_data, cdev); 291 296 if (unlikely(ret < 0)) 292 297 goto error; 293 298 294 - ret = gfs_add_rndis_config(cdev); 295 - if (unlikely(ret < 0)) 296 - goto error_unbind; 299 + for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) { 300 + struct gfs_configuration *c = gfs_configurations + i; 297 301 298 - ret = gfs_add_ecm_config(cdev); 299 - if (unlikely(ret < 0)) 300 - goto error_unbind; 302 + ret = GFS_STRING_FIRST_CONFIG_IDX + i; 303 + c->c.label = gfs_strings[ret].s; 304 + c->c.iConfiguration = gfs_strings[ret].id; 305 + c->c.bind = gfs_do_config; 306 + c->c.bConfigurationValue = 1 + i; 307 + c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER; 301 308 302 - ret = gfs_add_generic_config(cdev); 303 - if (unlikely(ret < 0)) 304 - goto error_unbind; 309 + ret = usb_add_config(cdev, &c->c); 310 + if (unlikely(ret < 0)) 311 + goto error_unbind; 312 + } 305 313 306 314 return 0; 307 315 ··· 310 368 } 311 369 312 370 313 - static int __gfs_do_config(struct usb_configuration *c, 314 - int (*eth)(struct usb_configuration *c, u8 *ethaddr), 315 - u8 *ethaddr) 371 + static int gfs_do_config(struct usb_configuration *c) 316 372 { 373 + struct gfs_configuration *gc = 374 + container_of(c, struct gfs_configuration, c); 317 375 int ret; 318 376 319 377 if (WARN_ON(!gfs_ffs_data)) ··· 324 382 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 325 383 } 326 384 327 - if (eth) { 328 - ret = eth(c, ethaddr); 385 + if (gc->eth) { 386 + ret = gc->eth(c, gfs_hostaddr); 329 387 if (unlikely(ret < 0)) 330 388 return ret; 331 389 } 332 390 333 - ret = functionfs_add(c->cdev, c, gfs_ffs_data); 391 + ret = functionfs_bind_config(c->cdev, c, gfs_ffs_data); 334 392 if (unlikely(ret < 0)) 335 393 return ret; 336 394 ··· 348 406 return 0; 349 407 } 350 408 351 - #ifdef CONFIG_USB_FUNCTIONFS_RNDIS 352 - static int gfs_do_rndis_config(struct usb_configuration *c) 353 - { 354 - ENTER(); 355 - 356 - return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr); 357 - } 358 - #endif 359 409 360 410 #ifdef CONFIG_USB_FUNCTIONFS_ETH 361 - static int gfs_do_ecm_config(struct usb_configuration *c) 411 + static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 362 412 { 363 - ENTER(); 364 - 365 - return __gfs_do_config(c, 366 - can_support_ecm(c->cdev->gadget) 367 - ? ecm_bind_config : geth_bind_config, 368 - gfs_hostaddr); 369 - } 370 - #endif 371 - 372 - #ifdef CONFIG_USB_FUNCTIONFS_GENERIC 373 - static int gfs_do_generic_config(struct usb_configuration *c) 374 - { 375 - ENTER(); 376 - 377 - return __gfs_do_config(c, NULL, NULL); 413 + return can_support_ecm(c->cdev->gadget) 414 + ? ecm_bind_config(c, ethaddr) 415 + : geth_bind_config(c, ethaddr); 378 416 } 379 417 #endif
+1 -1
drivers/usb/gadget/gmidi.c
··· 1157 1157 /* 1158 1158 * Creates an output endpoint, and initializes output ports. 1159 1159 */ 1160 - static int __init gmidi_bind(struct usb_gadget *gadget) 1160 + static int __ref gmidi_bind(struct usb_gadget *gadget) 1161 1161 { 1162 1162 struct gmidi_device *dev; 1163 1163 struct usb_ep *in_ep, *out_ep;
+2 -2
drivers/usb/gadget/hid.c
··· 127 127 128 128 /****************************** Configurations ******************************/ 129 129 130 - static int __init do_config(struct usb_configuration *c) 130 + static int __ref do_config(struct usb_configuration *c) 131 131 { 132 132 struct hidg_func_node *e; 133 133 int func = 0, status = 0; ··· 156 156 157 157 /****************************** Gadget Bind ******************************/ 158 158 159 - static int __init hid_bind(struct usb_composite_dev *cdev) 159 + static int __ref hid_bind(struct usb_composite_dev *cdev) 160 160 { 161 161 struct usb_gadget *gadget = cdev->gadget; 162 162 struct list_head *tmp;
+5 -11
drivers/usb/gadget/inode.c
··· 1299 1299 struct usb_gadget *gadget = dev->gadget; 1300 1300 long ret = -ENOTTY; 1301 1301 1302 - if (gadget->ops->ioctl) { 1303 - lock_kernel(); 1302 + if (gadget->ops->ioctl) 1304 1303 ret = gadget->ops->ioctl (gadget, code, value); 1305 - unlock_kernel(); 1306 - } 1304 + 1307 1305 return ret; 1308 1306 } 1309 1307 ··· 1865 1867 buf += 4; 1866 1868 length -= 4; 1867 1869 1868 - kbuf = kmalloc (length, GFP_KERNEL); 1869 - if (!kbuf) 1870 - return -ENOMEM; 1871 - if (copy_from_user (kbuf, buf, length)) { 1872 - kfree (kbuf); 1873 - return -EFAULT; 1874 - } 1870 + kbuf = memdup_user(buf, length); 1871 + if (IS_ERR(kbuf)) 1872 + return PTR_ERR(kbuf); 1875 1873 1876 1874 spin_lock_irq (&dev->lock); 1877 1875 value = -EINVAL;
+3 -3
drivers/usb/gadget/langwell_udc.c
··· 842 842 VDBG(dev, "req->mapped = 0\n"); 843 843 } 844 844 845 - DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08x\n", 846 - _ep->name, 847 - _req, _req->length, _req->buf, _req->dma); 845 + DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n", 846 + _ep->name, 847 + _req, _req->length, _req->buf, (unsigned long long)_req->dma); 848 848 849 849 _req->status = -EINPROGRESS; 850 850 _req->actual = 0;
+15 -9
drivers/usb/gadget/mass_storage.c
··· 141 141 return 0; 142 142 } 143 143 144 - static int __init msg_do_config(struct usb_configuration *c) 144 + static int __ref msg_do_config(struct usb_configuration *c) 145 145 { 146 - struct fsg_common *common; 146 + static const struct fsg_operations ops = { 147 + .thread_exits = msg_thread_exits, 148 + }; 149 + static struct fsg_common common; 150 + 151 + struct fsg_common *retp; 147 152 struct fsg_config config; 148 153 int ret; 149 154 ··· 158 153 } 159 154 160 155 fsg_config_from_params(&config, &mod_data); 161 - config.thread_exits = msg_thread_exits; 162 - common = fsg_common_init(0, c->cdev, &config); 163 - if (IS_ERR(common)) 164 - return PTR_ERR(common); 156 + config.ops = &ops; 165 157 166 - ret = fsg_add(c->cdev, c, common); 167 - fsg_common_put(common); 158 + retp = fsg_common_init(&common, c->cdev, &config); 159 + if (IS_ERR(retp)) 160 + return PTR_ERR(retp); 161 + 162 + ret = fsg_bind_config(c->cdev, c, &common); 163 + fsg_common_put(&common); 168 164 return ret; 169 165 } 170 166 ··· 182 176 /****************************** Gadget Bind ******************************/ 183 177 184 178 185 - static int __init msg_bind(struct usb_composite_dev *cdev) 179 + static int __ref msg_bind(struct usb_composite_dev *cdev) 186 180 { 187 181 struct usb_gadget *gadget = cdev->gadget; 188 182 int status;
+146 -116
drivers/usb/gadget/multi.c
··· 24 24 25 25 #include <linux/kernel.h> 26 26 #include <linux/utsname.h> 27 + #include <linux/module.h> 27 28 28 29 29 30 #if defined USB_ETH_RNDIS ··· 36 35 37 36 38 37 #define DRIVER_DESC "Multifunction Composite Gadget" 39 - #define DRIVER_VERSION "2009/07/21" 40 38 41 - /*-------------------------------------------------------------------------*/ 39 + MODULE_DESCRIPTION(DRIVER_DESC); 40 + MODULE_AUTHOR("Michal Nazarewicz"); 41 + MODULE_LICENSE("GPL"); 42 42 43 - #define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ 44 - #define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ 45 43 46 - /*-------------------------------------------------------------------------*/ 44 + /***************************** All the files... *****************************/ 47 45 48 46 /* 49 47 * kbuild is not very cooperative with respect to linking separately ··· 57 57 #include "config.c" 58 58 #include "epautoconf.c" 59 59 60 + #include "f_mass_storage.c" 61 + 60 62 #include "u_serial.c" 61 63 #include "f_acm.c" 62 64 ··· 70 68 #endif 71 69 #include "u_ether.c" 72 70 73 - #undef DBG /* u_ether.c has broken idea about macros */ 74 - #undef VDBG /* so clean up after it */ 75 - #undef ERROR 76 - #undef INFO 77 - #include "f_mass_storage.c" 78 71 79 - /*-------------------------------------------------------------------------*/ 72 + 73 + /***************************** Device Descriptor ****************************/ 74 + 75 + #define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */ 76 + #define MULTI_PRODUCT_NUM 0xa4ab /* XXX */ 77 + 78 + 79 + enum { 80 + __MULTI_NO_CONFIG, 81 + #ifdef CONFIG_USB_G_MULTI_RNDIS 82 + MULTI_RNDIS_CONFIG_NUM, 83 + #endif 84 + #ifdef CONFIG_USB_G_MULTI_CDC 85 + MULTI_CDC_CONFIG_NUM, 86 + #endif 87 + }; 88 + 80 89 81 90 static struct usb_device_descriptor device_desc = { 82 91 .bLength = sizeof device_desc, ··· 95 82 96 83 .bcdUSB = cpu_to_le16(0x0200), 97 84 98 - /* .bDeviceClass = USB_CLASS_COMM, */ 99 - /* .bDeviceSubClass = 0, */ 100 - /* .bDeviceProtocol = 0, */ 101 - .bDeviceClass = 0xEF, 85 + .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 102 86 .bDeviceSubClass = 2, 103 87 .bDeviceProtocol = 1, 104 - /* .bMaxPacketSize0 = f(hardware) */ 105 88 106 89 /* Vendor and product id can be overridden by module parameters. */ 107 90 .idVendor = cpu_to_le16(MULTI_VENDOR_NUM), 108 91 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM), 109 - /* .bcdDevice = f(hardware) */ 110 - /* .iManufacturer = DYNAMIC */ 111 - /* .iProduct = DYNAMIC */ 112 - /* NO SERIAL NUMBER */ 113 - .bNumConfigurations = 1, 114 92 }; 115 93 116 - static struct usb_otg_descriptor otg_descriptor = { 117 - .bLength = sizeof otg_descriptor, 118 - .bDescriptorType = USB_DT_OTG, 119 - 120 - /* REVISIT SRP-only hardware is possible, although 121 - * it would not be called "OTG" ... 122 - */ 123 - .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 124 - }; 125 94 126 95 static const struct usb_descriptor_header *otg_desc[] = { 127 - (struct usb_descriptor_header *) &otg_descriptor, 96 + (struct usb_descriptor_header *) &(struct usb_otg_descriptor){ 97 + .bLength = sizeof(struct usb_otg_descriptor), 98 + .bDescriptorType = USB_DT_OTG, 99 + 100 + /* 101 + * REVISIT SRP-only hardware is possible, although 102 + * it would not be called "OTG" ... 103 + */ 104 + .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, 105 + }, 128 106 NULL, 129 107 }; 130 108 131 109 132 - /* string IDs are assigned dynamically */ 133 - 134 - #define STRING_MANUFACTURER_IDX 0 135 - #define STRING_PRODUCT_IDX 1 110 + enum { 111 + MULTI_STRING_MANUFACTURER_IDX, 112 + MULTI_STRING_PRODUCT_IDX, 113 + #ifdef CONFIG_USB_G_MULTI_RNDIS 114 + MULTI_STRING_RNDIS_CONFIG_IDX, 115 + #endif 116 + #ifdef CONFIG_USB_G_MULTI_CDC 117 + MULTI_STRING_CDC_CONFIG_IDX, 118 + #endif 119 + }; 136 120 137 121 static char manufacturer[50]; 138 122 139 123 static struct usb_string strings_dev[] = { 140 - [STRING_MANUFACTURER_IDX].s = manufacturer, 141 - [STRING_PRODUCT_IDX].s = DRIVER_DESC, 124 + [MULTI_STRING_MANUFACTURER_IDX].s = manufacturer, 125 + [MULTI_STRING_PRODUCT_IDX].s = DRIVER_DESC, 126 + #ifdef CONFIG_USB_G_MULTI_RNDIS 127 + [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS", 128 + #endif 129 + #ifdef CONFIG_USB_G_MULTI_CDC 130 + [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM", 131 + #endif 142 132 { } /* end of list */ 143 133 }; 144 134 145 - static struct usb_gadget_strings stringtab_dev = { 146 - .language = 0x0409, /* en-us */ 147 - .strings = strings_dev, 148 - }; 149 - 150 135 static struct usb_gadget_strings *dev_strings[] = { 151 - &stringtab_dev, 136 + &(struct usb_gadget_strings){ 137 + .language = 0x0409, /* en-us */ 138 + .strings = strings_dev, 139 + }, 152 140 NULL, 153 141 }; 154 142 155 - static u8 hostaddr[ETH_ALEN]; 156 143 157 144 158 145 159 146 /****************************** Configurations ******************************/ 160 147 161 - static struct fsg_module_parameters mod_data = { 162 - .stall = 1 163 - }; 164 - FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 148 + static struct fsg_module_parameters fsg_mod_data = { .stall = 1 }; 149 + FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); 165 150 166 - static struct fsg_common *fsg_common; 151 + static struct fsg_common fsg_common; 167 152 153 + static u8 hostaddr[ETH_ALEN]; 154 + 155 + 156 + /********** RNDIS **********/ 168 157 169 158 #ifdef USB_ETH_RNDIS 170 159 171 - static int __init rndis_do_config(struct usb_configuration *c) 160 + static __ref int rndis_do_config(struct usb_configuration *c) 172 161 { 173 162 int ret; 174 163 ··· 187 172 if (ret < 0) 188 173 return ret; 189 174 190 - ret = fsg_add(c->cdev, c, fsg_common); 175 + ret = fsg_bind_config(c->cdev, c, &fsg_common); 191 176 if (ret < 0) 192 177 return ret; 193 178 194 179 return 0; 195 180 } 196 181 197 - static struct usb_configuration rndis_config_driver = { 198 - .label = "Multifunction Composite (RNDIS + MS + ACM)", 199 - .bind = rndis_do_config, 200 - .bConfigurationValue = 2, 201 - /* .iConfiguration = DYNAMIC */ 202 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 203 - }; 182 + static int rndis_config_register(struct usb_composite_dev *cdev) 183 + { 184 + static struct usb_configuration config = { 185 + .bind = rndis_do_config, 186 + .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM, 187 + .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 188 + }; 189 + 190 + config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s; 191 + config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id; 192 + 193 + return usb_add_config(cdev, &config); 194 + } 195 + 196 + #else 197 + 198 + static int rndis_config_register(struct usb_composite_dev *cdev) 199 + { 200 + return 0; 201 + } 204 202 205 203 #endif 206 204 205 + 206 + /********** CDC ECM **********/ 207 + 207 208 #ifdef CONFIG_USB_G_MULTI_CDC 208 209 209 - static int __init cdc_do_config(struct usb_configuration *c) 210 + static __ref int cdc_do_config(struct usb_configuration *c) 210 211 { 211 212 int ret; 212 213 ··· 239 208 if (ret < 0) 240 209 return ret; 241 210 242 - ret = fsg_add(c->cdev, c, fsg_common); 211 + ret = fsg_bind_config(c->cdev, c, &fsg_common); 243 212 if (ret < 0) 244 213 return ret; 245 214 246 215 return 0; 247 216 } 248 217 249 - static struct usb_configuration cdc_config_driver = { 250 - .label = "Multifunction Composite (CDC + MS + ACM)", 251 - .bind = cdc_do_config, 252 - .bConfigurationValue = 1, 253 - /* .iConfiguration = DYNAMIC */ 254 - .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 255 - }; 218 + static int cdc_config_register(struct usb_composite_dev *cdev) 219 + { 220 + static struct usb_configuration config = { 221 + .bind = cdc_do_config, 222 + .bConfigurationValue = MULTI_CDC_CONFIG_NUM, 223 + .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 224 + }; 225 + 226 + config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s; 227 + config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id; 228 + 229 + return usb_add_config(cdev, &config); 230 + } 231 + 232 + #else 233 + 234 + static int cdc_config_register(struct usb_composite_dev *cdev) 235 + { 236 + return 0; 237 + } 256 238 257 239 #endif 258 240 ··· 274 230 /****************************** Gadget Bind ******************************/ 275 231 276 232 277 - static int __init multi_bind(struct usb_composite_dev *cdev) 233 + static int __ref multi_bind(struct usb_composite_dev *cdev) 278 234 { 279 235 struct usb_gadget *gadget = cdev->gadget; 280 236 int status, gcnum; ··· 296 252 goto fail0; 297 253 298 254 /* set up mass storage function */ 299 - fsg_common = fsg_common_from_params(0, cdev, &mod_data); 300 - if (IS_ERR(fsg_common)) { 301 - status = PTR_ERR(fsg_common); 302 - goto fail1; 255 + { 256 + void *retp; 257 + retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 258 + if (IS_ERR(retp)) { 259 + status = PTR_ERR(retp); 260 + goto fail1; 261 + } 303 262 } 304 263 305 - 264 + /* set bcdDevice */ 306 265 gcnum = usb_gadget_controller_number(gadget); 307 - if (gcnum >= 0) 266 + if (gcnum >= 0) { 308 267 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); 309 - else { 310 - /* We assume that can_support_ecm() tells the truth; 311 - * but if the controller isn't recognized at all then 312 - * that assumption is a bit more likely to be wrong. 313 - */ 314 - WARNING(cdev, "controller '%s' not recognized\n", 315 - gadget->name); 268 + } else { 269 + WARNING(cdev, "controller '%s' not recognized\n", gadget->name); 316 270 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); 317 271 } 318 272 319 - 320 - /* Allocate string descriptor numbers ... note that string 321 - * contents can be overridden by the composite_dev glue. 322 - */ 323 - 324 - /* device descriptor strings: manufacturer, product */ 273 + /* allocate string descriptor numbers */ 325 274 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 326 275 init_utsname()->sysname, init_utsname()->release, 327 276 gadget->name); 328 - status = usb_string_id(cdev); 329 - if (status < 0) 330 - goto fail2; 331 - strings_dev[STRING_MANUFACTURER_IDX].id = status; 332 - device_desc.iManufacturer = status; 333 277 334 - status = usb_string_id(cdev); 335 - if (status < 0) 278 + status = usb_string_ids_tab(cdev, strings_dev); 279 + if (unlikely(status < 0)) 336 280 goto fail2; 337 - strings_dev[STRING_PRODUCT_IDX].id = status; 338 - device_desc.iProduct = status; 339 281 340 - #ifdef USB_ETH_RNDIS 341 - /* register our first configuration */ 342 - status = usb_add_config(cdev, &rndis_config_driver); 343 - if (status < 0) 282 + device_desc.iManufacturer = 283 + strings_dev[MULTI_STRING_MANUFACTURER_IDX].id; 284 + device_desc.iProduct = 285 + strings_dev[MULTI_STRING_PRODUCT_IDX].id; 286 + 287 + /* register configurations */ 288 + status = rndis_config_register(cdev); 289 + if (unlikely(status < 0)) 344 290 goto fail2; 345 - #endif 346 291 347 - #ifdef CONFIG_USB_G_MULTI_CDC 348 - /* register our second configuration */ 349 - status = usb_add_config(cdev, &cdc_config_driver); 350 - if (status < 0) 292 + status = cdc_config_register(cdev); 293 + if (unlikely(status < 0)) 351 294 goto fail2; 352 - #endif 353 295 354 - dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 355 - fsg_common_put(fsg_common); 296 + /* we're done */ 297 + dev_info(&gadget->dev, DRIVER_DESC "\n"); 298 + fsg_common_put(&fsg_common); 356 299 return 0; 357 300 301 + 302 + /* error recovery */ 358 303 fail2: 359 - fsg_common_put(fsg_common); 304 + fsg_common_put(&fsg_common); 360 305 fail1: 361 306 gserial_cleanup(); 362 307 fail0: ··· 372 339 .unbind = __exit_p(multi_unbind), 373 340 }; 374 341 375 - MODULE_DESCRIPTION(DRIVER_DESC); 376 - MODULE_AUTHOR("Michal Nazarewicz"); 377 - MODULE_LICENSE("GPL"); 378 342 379 - static int __init g_multi_init(void) 343 + static int __init multi_init(void) 380 344 { 381 345 return usb_composite_register(&multi_driver); 382 346 } 383 - module_init(g_multi_init); 347 + module_init(multi_init); 384 348 385 - static void __exit g_multi_cleanup(void) 349 + static void __exit multi_exit(void) 386 350 { 387 351 usb_composite_unregister(&multi_driver); 388 352 } 389 - module_exit(g_multi_cleanup); 353 + module_exit(multi_exit);
+5 -4
drivers/usb/gadget/printer.c
··· 25 25 #include <linux/ioport.h> 26 26 #include <linux/sched.h> 27 27 #include <linux/slab.h> 28 - #include <linux/smp_lock.h> 28 + #include <linux/mutex.h> 29 29 #include <linux/errno.h> 30 30 #include <linux/init.h> 31 31 #include <linux/timer.h> ··· 70 70 #define DRIVER_DESC "Printer Gadget" 71 71 #define DRIVER_VERSION "2007 OCT 06" 72 72 73 + static DEFINE_MUTEX(printer_mutex); 73 74 static const char shortname [] = "printer"; 74 75 static const char driver_desc [] = DRIVER_DESC; 75 76 ··· 477 476 unsigned long flags; 478 477 int ret = -EBUSY; 479 478 480 - lock_kernel(); 479 + mutex_lock(&printer_mutex); 481 480 dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); 482 481 483 482 spin_lock_irqsave(&dev->lock, flags); ··· 493 492 spin_unlock_irqrestore(&dev->lock, flags); 494 493 495 494 DBG(dev, "printer_open returned %x\n", ret); 496 - unlock_kernel(); 495 + mutex_unlock(&printer_mutex); 497 496 return ret; 498 497 } 499 498 ··· 1347 1346 set_gadget_data(gadget, NULL); 1348 1347 } 1349 1348 1350 - static int __init 1349 + static int __ref 1351 1350 printer_bind(struct usb_gadget *gadget) 1352 1351 { 1353 1352 struct printer_dev *dev;
+122 -31
drivers/usb/gadget/s3c-hsotg.c
··· 12 12 * published by the Free Software Foundation. 13 13 */ 14 14 15 + #define DEBUG 16 + 15 17 #include <linux/kernel.h> 16 18 #include <linux/module.h> 17 19 #include <linux/spinlock.h> ··· 25 23 #include <linux/delay.h> 26 24 #include <linux/io.h> 27 25 #include <linux/slab.h> 26 + #include <linux/clk.h> 28 27 29 28 #include <linux/usb/ch9.h> 30 29 #include <linux/usb/gadget.h> ··· 36 33 #include <plat/regs-usb-hsotg.h> 37 34 #include <mach/regs-sys.h> 38 35 #include <plat/udc-hs.h> 36 + #include <plat/cpu.h> 39 37 40 38 #define DMA_ADDR_INVALID (~((dma_addr_t)0)) 41 39 ··· 95 91 * For periodic IN endpoints, we have fifo_size and fifo_load to try 96 92 * and keep track of the amount of data in the periodic FIFO for each 97 93 * of these as we don't have a status register that tells us how much 98 - * is in each of them. 94 + * is in each of them. (note, this may actually be useless information 95 + * as in shared-fifo mode periodic in acts like a single-frame packet 96 + * buffer than a fifo) 99 97 */ 100 98 struct s3c_hsotg_ep { 101 99 struct usb_ep ep; ··· 134 128 * @regs: The memory area mapped for accessing registers. 135 129 * @regs_res: The resource that was allocated when claiming register space. 136 130 * @irq: The IRQ number we are using 131 + * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. 137 132 * @debug_root: root directrory for debugfs. 138 133 * @debug_file: main status file for debugfs. 139 134 * @debug_fifo: FIFO status file for debugfs. ··· 152 145 void __iomem *regs; 153 146 struct resource *regs_res; 154 147 int irq; 148 + struct clk *clk; 149 + 150 + unsigned int dedicated_fifos:1; 155 151 156 152 struct dentry *debug_root; 157 153 struct dentry *debug_file; ··· 320 310 hsotg->regs + S3C_GNPTXFSIZ); 321 311 */ 322 312 323 - /* set FIFO sizes to 2048/0x1C0 */ 313 + /* set FIFO sizes to 2048/1024 */ 324 314 325 315 writel(2048, hsotg->regs + S3C_GRXFSIZ); 326 316 writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) | 327 - S3C_GNPTXFSIZ_NPTxFDep(0x1C0), 317 + S3C_GNPTXFSIZ_NPTxFDep(1024), 328 318 hsotg->regs + S3C_GNPTXFSIZ); 329 319 330 320 /* arange all the rest of the TX FIFOs, as some versions of this ··· 474 464 if (to_write == 0) 475 465 return 0; 476 466 477 - if (periodic) { 467 + if (periodic && !hsotg->dedicated_fifos) { 478 468 u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); 479 469 int size_left; 480 470 int size_done; ··· 483 473 * how much data is left in the fifo. */ 484 474 485 475 size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); 476 + 477 + /* if shared fifo, we cannot write anything until the 478 + * previous data has been completely sent. 479 + */ 480 + if (hs_ep->fifo_load != 0) { 481 + s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); 482 + return -ENOSPC; 483 + } 486 484 487 485 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", 488 486 __func__, size_left, ··· 512 494 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); 513 495 return -ENOSPC; 514 496 } 497 + } else if (hsotg->dedicated_fifos && hs_ep->index != 0) { 498 + can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index)); 499 + 500 + can_write &= 0xffff; 501 + can_write *= 4; 515 502 } else { 516 503 if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { 517 504 dev_dbg(hsotg->dev, ··· 528 505 } 529 506 530 507 can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); 508 + can_write *= 4; /* fifo size is in 32bit quantities. */ 531 509 } 532 510 533 511 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", ··· 540 516 */ 541 517 if (can_write > 512) 542 518 can_write = 512; 519 + 520 + /* limit the write to one max-packet size worth of data, but allow 521 + * the transfer to return that it did not run out of fifo space 522 + * doing it. */ 523 + if (to_write > hs_ep->ep.maxpacket) { 524 + to_write = hs_ep->ep.maxpacket; 525 + 526 + s3c_hsotg_en_gsint(hsotg, 527 + periodic ? S3C_GINTSTS_PTxFEmp : 528 + S3C_GINTSTS_NPTxFEmp); 529 + } 543 530 544 531 /* see if we can write data */ 545 532 ··· 614 579 maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1; 615 580 maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; 616 581 } else { 582 + maxsize = 64+64; 617 583 if (hs_ep->dir_in) { 618 - /* maxsize = S3C_DIEPTSIZ0_XferSize_LIMIT + 1; */ 619 - maxsize = 64+64+1; 620 584 maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; 621 585 } else { 622 - maxsize = 0x3f; 623 586 maxpkt = 2; 624 587 } 625 588 } ··· 1386 1353 read_ptr = hs_req->req.actual; 1387 1354 max_req = hs_req->req.length - read_ptr; 1388 1355 1356 + dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", 1357 + __func__, to_read, max_req, read_ptr, hs_req->req.length); 1358 + 1389 1359 if (to_read > max_req) { 1390 1360 /* more data appeared than we where willing 1391 1361 * to deal with in this request. ··· 1397 1361 /* currently we don't deal this */ 1398 1362 WARN_ON_ONCE(1); 1399 1363 } 1400 - 1401 - dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n", 1402 - __func__, to_read, max_req, read_ptr, hs_req->req.length); 1403 1364 1404 1365 hs_ep->total_data += to_read; 1405 1366 hs_req->req.actual += to_read; ··· 1466 1433 static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, 1467 1434 int epnum, bool was_setup) 1468 1435 { 1436 + u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum)); 1469 1437 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; 1470 1438 struct s3c_hsotg_req *hs_req = hs_ep->req; 1471 1439 struct usb_request *req = &hs_req->req; 1440 + unsigned size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); 1472 1441 int result = 0; 1473 1442 1474 1443 if (!hs_req) { ··· 1479 1444 } 1480 1445 1481 1446 if (using_dma(hsotg)) { 1482 - u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum)); 1483 1447 unsigned size_done; 1484 - unsigned size_left; 1485 1448 1486 1449 /* Calculate the size of the transfer by checking how much 1487 1450 * is left in the endpoint size register and then working it ··· 1489 1456 * so may overshoot/undershoot the transfer. 1490 1457 */ 1491 1458 1492 - size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); 1493 - 1494 1459 size_done = hs_ep->size_loaded - size_left; 1495 1460 size_done += hs_ep->last_load; 1496 1461 1497 1462 req->actual = size_done; 1463 + } 1464 + 1465 + /* if there is more request to do, schedule new transfer */ 1466 + if (req->actual < req->length && size_left == 0) { 1467 + s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true); 1468 + return; 1498 1469 } 1499 1470 1500 1471 if (req->actual < req->length && req->short_not_ok) { ··· 1795 1758 if (dir_in) { 1796 1759 s3c_hsotg_complete_in(hsotg, hs_ep); 1797 1760 1798 - if (idx == 0) 1761 + if (idx == 0 && !hs_ep->req) 1799 1762 s3c_hsotg_enqueue_setup(hsotg); 1800 1763 } else if (using_dma(hsotg)) { 1801 1764 /* We're using DMA, we need to fire an OutDone here ··· 1854 1817 dev_warn(hsotg->dev, "%s: ep%d: INTknEP\n", 1855 1818 __func__, idx); 1856 1819 clear |= S3C_DIEPMSK_INTknEPMisMsk; 1820 + } 1821 + 1822 + /* FIFO has space or is empty (see GAHBCFG) */ 1823 + if (hsotg->dedicated_fifos && 1824 + ints & S3C_DIEPMSK_TxFIFOEmpty) { 1825 + dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n", 1826 + __func__, idx); 1827 + s3c_hsotg_trytx(hsotg, hs_ep); 1828 + clear |= S3C_DIEPMSK_TxFIFOEmpty; 1857 1829 } 1858 1830 } 1859 1831 ··· 2117 2071 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); 2118 2072 2119 2073 /* it seems after a reset we can end up with a situation 2120 - * where the TXFIFO still has data in it... try flushing 2121 - * it to remove anything that may still be in it. 2074 + * where the TXFIFO still has data in it... the docs 2075 + * suggest resetting all the fifos, so use the init_fifo 2076 + * code to relayout and flush the fifos. 2122 2077 */ 2123 2078 2124 - if (1) { 2125 - writel(S3C_GRSTCTL_TxFNum(0) | S3C_GRSTCTL_TxFFlsh, 2126 - hsotg->regs + S3C_GRSTCTL); 2127 - 2128 - dev_info(hsotg->dev, "GNPTXSTS=%08x\n", 2129 - readl(hsotg->regs + S3C_GNPTXSTS)); 2130 - } 2079 + s3c_hsotg_init_fifo(hsotg); 2131 2080 2132 2081 s3c_hsotg_enqueue_setup(hsotg); 2133 2082 ··· 2314 2273 epctrl |= S3C_DxEPCTL_EPType_Control; 2315 2274 break; 2316 2275 } 2276 + 2277 + /* if the hardware has dedicated fifos, we must give each IN EP 2278 + * a unique tx-fifo even if it is non-periodic. 2279 + */ 2280 + if (dir_in && hsotg->dedicated_fifos) 2281 + epctrl |= S3C_DxEPCTL_TxFNum(index); 2317 2282 2318 2283 /* for non control endpoints, set PID to D0 */ 2319 2284 if (index) ··· 2610 2563 2611 2564 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | 2612 2565 S3C_DIEPMSK_INTknEPMisMsk | 2613 - S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk, 2566 + S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk | 2567 + ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0), 2614 2568 hsotg->regs + S3C_DIEPMSK); 2615 2569 2616 2570 /* don't need XferCompl, we get that from RXFIFO in slave mode. In ··· 2780 2732 */ 2781 2733 2782 2734 ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); 2783 - hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo); 2735 + hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4; 2784 2736 2785 2737 /* if we're using dma, we need to set the next-endpoint pointer 2786 2738 * to be something valid. ··· 2801 2753 */ 2802 2754 static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) 2803 2755 { 2804 - u32 osc; 2756 + struct clk *xusbxti; 2757 + u32 pwr, osc; 2805 2758 2806 - writel(0, S3C_PHYPWR); 2759 + pwr = readl(S3C_PHYPWR); 2760 + pwr &= ~0x19; 2761 + writel(pwr, S3C_PHYPWR); 2807 2762 mdelay(1); 2808 2763 2809 2764 osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0; 2765 + 2766 + xusbxti = clk_get(hsotg->dev, "xusbxti"); 2767 + if (xusbxti && !IS_ERR(xusbxti)) { 2768 + switch (clk_get_rate(xusbxti)) { 2769 + case 12*MHZ: 2770 + osc |= S3C_PHYCLK_CLKSEL_12M; 2771 + break; 2772 + case 24*MHZ: 2773 + osc |= S3C_PHYCLK_CLKSEL_24M; 2774 + break; 2775 + default: 2776 + case 48*MHZ: 2777 + /* default reference clock */ 2778 + break; 2779 + } 2780 + clk_put(xusbxti); 2781 + } 2810 2782 2811 2783 writel(osc | 0x10, S3C_PHYCLK); 2812 2784 ··· 2840 2772 2841 2773 static void s3c_hsotg_init(struct s3c_hsotg *hsotg) 2842 2774 { 2775 + u32 cfg4; 2776 + 2843 2777 /* unmask subset of endpoint interrupts */ 2844 2778 2845 2779 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | ··· 2877 2807 2878 2808 writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0, 2879 2809 hsotg->regs + S3C_GAHBCFG); 2810 + 2811 + /* check hardware configuration */ 2812 + 2813 + cfg4 = readl(hsotg->regs + 0x50); 2814 + hsotg->dedicated_fifos = (cfg4 >> 25) & 1; 2815 + 2816 + dev_info(hsotg->dev, "%s fifos\n", 2817 + hsotg->dedicated_fifos ? "dedicated" : "shared"); 2880 2818 } 2881 2819 2882 2820 static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) ··· 3259 3181 hsotg->dev = dev; 3260 3182 hsotg->plat = plat; 3261 3183 3184 + hsotg->clk = clk_get(&pdev->dev, "otg"); 3185 + if (IS_ERR(hsotg->clk)) { 3186 + dev_err(dev, "cannot get otg clock\n"); 3187 + ret = -EINVAL; 3188 + goto err_mem; 3189 + } 3190 + 3262 3191 platform_set_drvdata(pdev, hsotg); 3263 3192 3264 3193 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3265 3194 if (!res) { 3266 3195 dev_err(dev, "cannot find register resource 0\n"); 3267 3196 ret = -EINVAL; 3268 - goto err_mem; 3197 + goto err_clk; 3269 3198 } 3270 3199 3271 3200 hsotg->regs_res = request_mem_region(res->start, resource_size(res), ··· 3280 3195 if (!hsotg->regs_res) { 3281 3196 dev_err(dev, "cannot reserve registers\n"); 3282 3197 ret = -ENOENT; 3283 - goto err_mem; 3198 + goto err_clk; 3284 3199 } 3285 3200 3286 3201 hsotg->regs = ioremap(res->start, resource_size(res)); ··· 3333 3248 3334 3249 /* reset the system */ 3335 3250 3251 + clk_enable(hsotg->clk); 3252 + 3336 3253 s3c_hsotg_gate(pdev, true); 3337 3254 3338 3255 s3c_hsotg_otgreset(hsotg); ··· 3358 3271 err_regs_res: 3359 3272 release_resource(hsotg->regs_res); 3360 3273 kfree(hsotg->regs_res); 3361 - 3274 + err_clk: 3275 + clk_put(hsotg->clk); 3362 3276 err_mem: 3363 3277 kfree(hsotg); 3364 3278 return ret; ··· 3380 3292 kfree(hsotg->regs_res); 3381 3293 3382 3294 s3c_hsotg_gate(pdev, false); 3295 + 3296 + clk_disable(hsotg->clk); 3297 + clk_put(hsotg->clk); 3383 3298 3384 3299 kfree(hsotg); 3385 3300 return 0;
+2 -2
drivers/usb/gadget/serial.c
··· 137 137 138 138 /*-------------------------------------------------------------------------*/ 139 139 140 - static int __init serial_bind_config(struct usb_configuration *c) 140 + static int __ref serial_bind_config(struct usb_configuration *c) 141 141 { 142 142 unsigned i; 143 143 int status = 0; ··· 161 161 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 162 162 }; 163 163 164 - static int __init gs_bind(struct usb_composite_dev *cdev) 164 + static int __ref gs_bind(struct usb_composite_dev *cdev) 165 165 { 166 166 int gcnum; 167 167 struct usb_gadget *gadget = cdev->gadget;
+80 -25
drivers/usb/gadget/storage_common.c
··· 57 57 #include <asm/unaligned.h> 58 58 59 59 60 - /* Thanks to NetChip Technologies for donating this product ID. 60 + /* 61 + * Thanks to NetChip Technologies for donating this product ID. 61 62 * 62 63 * DO NOT REUSE THESE IDs with any other driver!! Ever!! 63 - * Instead: allocate your own, using normal USB-IF procedures. */ 64 + * Instead: allocate your own, using normal USB-IF procedures. 65 + */ 64 66 #define FSG_VENDOR_ID 0x0525 /* NetChip */ 65 67 #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ 66 68 ··· 86 84 #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) 87 85 #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) 88 86 89 - /* Keep those macros in sync with thos in 90 - * include/linux/ubs/composite.h or else GCC will complain. If they 87 + /* 88 + * Keep those macros in sync with those in 89 + * include/linux/usb/composite.h or else GCC will complain. If they 91 90 * are identical (the same names of arguments, white spaces in the 92 91 * same places) GCC will allow redefinition otherwise (even if some 93 - * white space is removed or added) warning will be issued. No 94 - * checking if those symbols is defined is performed because warning 95 - * is desired when those macros were defined by someone else to mean 96 - * something else. */ 92 + * white space is removed or added) warning will be issued. 93 + * 94 + * Those macros are needed here because File Storage Gadget does not 95 + * include the composite.h header. For composite gadgets those macros 96 + * are redundant since composite.h is included any way. 97 + * 98 + * One could check whether those macros are already defined (which 99 + * would indicate composite.h had been included) or not (which would 100 + * indicate we were in FSG) but this is not done because a warning is 101 + * desired if definitions here differ from the ones in composite.h. 102 + * 103 + * We want the definitions to match and be the same in File Storage 104 + * Gadget as well as Mass Storage Function (and so composite gadgets 105 + * using MSF). If someone changes them in composite.h it will produce 106 + * a warning in this file when building MSF. 107 + */ 97 108 #define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args) 98 109 #define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args) 99 110 #define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args) ··· 284 269 unsigned int prevent_medium_removal:1; 285 270 unsigned int registered:1; 286 271 unsigned int info_valid:1; 272 + unsigned int nofua:1; 287 273 288 274 u32 sense_data; 289 275 u32 sense_data_info; ··· 329 313 enum fsg_buffer_state state; 330 314 struct fsg_buffhd *next; 331 315 332 - /* The NetChip 2280 is faster, and handles some protocol faults 316 + /* 317 + * The NetChip 2280 is faster, and handles some protocol faults 333 318 * better, if we don't submit any short bulk-out read requests. 334 - * So we will record the intended request length here. */ 319 + * So we will record the intended request length here. 320 + */ 335 321 unsigned int bulk_out_intended_length; 336 322 337 323 struct usb_request *inreq; ··· 413 395 .iInterface = FSG_STRING_INTERFACE, 414 396 }; 415 397 416 - /* Three full-speed endpoint descriptors: bulk-in, bulk-out, 417 - * and interrupt-in. */ 398 + /* 399 + * Three full-speed endpoint descriptors: bulk-in, bulk-out, and 400 + * interrupt-in. 401 + */ 418 402 419 403 static struct usb_endpoint_descriptor 420 404 fsg_fs_bulk_in_desc = { ··· 479 459 * 480 460 * That means alternate endpoint descriptors (bigger packets) 481 461 * and a "device qualifier" ... plus more construction options 482 - * for the config descriptor. 462 + * for the configuration descriptor. 483 463 */ 484 464 static struct usb_endpoint_descriptor 485 465 fsg_hs_bulk_in_desc = { ··· 567 547 568 548 /*-------------------------------------------------------------------------*/ 569 549 570 - /* If the next two routines are called while the gadget is registered, 571 - * the caller must own fsg->filesem for writing. */ 550 + /* 551 + * If the next two routines are called while the gadget is registered, 552 + * the caller must own fsg->filesem for writing. 553 + */ 572 554 573 555 static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 574 556 { ··· 609 587 goto out; 610 588 } 611 589 612 - /* If we can't read the file, it's no good. 613 - * If we can't write the file, use it read-only. */ 590 + /* 591 + * If we can't read the file, it's no good. 592 + * If we can't write the file, use it read-only. 593 + */ 614 594 if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) { 615 595 LINFO(curlun, "file not readable: %s\n", filename); 616 596 goto out; ··· 670 646 671 647 /*-------------------------------------------------------------------------*/ 672 648 673 - /* Sync the file data, don't bother with the metadata. 674 - * This code was copied from fs/buffer.c:sys_fdatasync(). */ 649 + /* 650 + * Sync the file data, don't bother with the metadata. 651 + * This code was copied from fs/buffer.c:sys_fdatasync(). 652 + */ 675 653 static int fsg_lun_fsync_sub(struct fsg_lun *curlun) 676 654 { 677 655 struct file *filp = curlun->filp; ··· 715 689 : curlun->initially_ro); 716 690 } 717 691 692 + static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr, 693 + char *buf) 694 + { 695 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 696 + 697 + return sprintf(buf, "%u\n", curlun->nofua); 698 + } 699 + 718 700 static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr, 719 701 char *buf) 720 702 { ··· 757 723 ssize_t rc = count; 758 724 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 759 725 struct rw_semaphore *filesem = dev_get_drvdata(dev); 760 - int i; 726 + unsigned long ro; 761 727 762 - if (sscanf(buf, "%d", &i) != 1) 728 + if (strict_strtoul(buf, 2, &ro)) 763 729 return -EINVAL; 764 730 765 - /* Allow the write-enable status to change only while the backing file 766 - * is closed. */ 731 + /* 732 + * Allow the write-enable status to change only while the 733 + * backing file is closed. 734 + */ 767 735 down_read(filesem); 768 736 if (fsg_lun_is_open(curlun)) { 769 737 LDBG(curlun, "read-only status change prevented\n"); 770 738 rc = -EBUSY; 771 739 } else { 772 - curlun->ro = !!i; 773 - curlun->initially_ro = !!i; 740 + curlun->ro = ro; 741 + curlun->initially_ro = ro; 774 742 LDBG(curlun, "read-only status set to %d\n", curlun->ro); 775 743 } 776 744 up_read(filesem); 777 745 return rc; 746 + } 747 + 748 + static ssize_t fsg_store_nofua(struct device *dev, 749 + struct device_attribute *attr, 750 + const char *buf, size_t count) 751 + { 752 + struct fsg_lun *curlun = fsg_lun_from_dev(dev); 753 + unsigned long nofua; 754 + 755 + if (strict_strtoul(buf, 2, &nofua)) 756 + return -EINVAL; 757 + 758 + /* Sync data when switching from async mode to sync */ 759 + if (!nofua && curlun->nofua) 760 + fsg_lun_fsync_sub(curlun); 761 + 762 + curlun->nofua = nofua; 763 + 764 + return count; 778 765 } 779 766 780 767 static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
+2 -13
drivers/usb/gadget/u_ether.c
··· 704 704 module_param(host_addr, charp, S_IRUGO); 705 705 MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); 706 706 707 - 708 - static u8 __init nibble(unsigned char c) 709 - { 710 - if (isdigit(c)) 711 - return c - '0'; 712 - c = toupper(c); 713 - if (isxdigit(c)) 714 - return 10 + c - 'A'; 715 - return 0; 716 - } 717 - 718 707 static int get_ether_addr(const char *str, u8 *dev_addr) 719 708 { 720 709 if (str) { ··· 714 725 715 726 if ((*str == '.') || (*str == ':')) 716 727 str++; 717 - num = nibble(*str++) << 4; 718 - num |= (nibble(*str++)); 728 + num = hex_to_bin(*str++) << 4; 729 + num |= hex_to_bin(*str++); 719 730 dev_addr [i] = num; 720 731 } 721 732 if (is_valid_ether_addr(dev_addr))
+1
drivers/usb/gadget/u_serial.c
··· 18 18 /* #define VERBOSE_DEBUG */ 19 19 20 20 #include <linux/kernel.h> 21 + #include <linux/sched.h> 21 22 #include <linux/interrupt.h> 22 23 #include <linux/device.h> 23 24 #include <linux/delay.h>
+2 -2
drivers/usb/gadget/webcam.c
··· 308 308 * USB configuration 309 309 */ 310 310 311 - static int __init 311 + static int __ref 312 312 webcam_config_bind(struct usb_configuration *c) 313 313 { 314 314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, ··· 330 330 return 0; 331 331 } 332 332 333 - static int __init 333 + static int __ref 334 334 webcam_bind(struct usb_composite_dev *cdev) 335 335 { 336 336 int ret;
+1 -1
drivers/usb/gadget/zero.c
··· 264 264 265 265 /*-------------------------------------------------------------------------*/ 266 266 267 - static int __init zero_bind(struct usb_composite_dev *cdev) 267 + static int __ref zero_bind(struct usb_composite_dev *cdev) 268 268 { 269 269 int gcnum; 270 270 struct usb_gadget *gadget = cdev->gadget;
+7 -4
drivers/usb/host/Kconfig
··· 72 72 from ARC, and has since changed hands a few times. 73 73 74 74 config USB_EHCI_TT_NEWSCHED 75 - bool "Improved Transaction Translator scheduling (EXPERIMENTAL)" 76 - depends on USB_EHCI_HCD && EXPERIMENTAL 75 + bool "Improved Transaction Translator scheduling" 76 + depends on USB_EHCI_HCD 77 + default y 77 78 ---help--- 78 79 This changes the periodic scheduling code to fill more of the low 79 80 and full speed bandwidth available from the Transaction Translator ··· 85 84 If you have multiple periodic low/fullspeed devices connected to a 86 85 highspeed USB hub which is connected to a highspeed USB Host 87 86 Controller, and some of those devices will not work correctly 88 - (possibly due to "ENOSPC" or "-28" errors), say Y. 87 + (possibly due to "ENOSPC" or "-28" errors), say Y. Conversely, if 88 + you have only one such device and it doesn't work, you could try 89 + saying N. 89 90 90 - If unsure, say N. 91 + If unsure, say Y. 91 92 92 93 config USB_EHCI_BIG_ENDIAN_MMIO 93 94 bool
+1 -1
drivers/usb/host/ehci-au1xxx.c
··· 228 228 * the root hub is either suspended or stopped. 229 229 */ 230 230 spin_lock_irqsave(&ehci->lock, flags); 231 - ehci_prepare_ports_for_controller_suspend(ehci); 231 + ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev)); 232 232 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 233 233 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 234 234
+152 -38
drivers/usb/host/ehci-dbg.c
··· 98 98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 99 99 } else { 100 100 ehci_dbg (ehci, 101 - "%s hcc_params %04x thresh %d uframes %s%s%s\n", 101 + "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n", 102 102 label, 103 103 params, 104 104 HCC_ISOC_THRES(params), 105 105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", 106 106 HCC_CANPARK(params) ? " park" : "", 107 - HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 107 + HCC_64BIT_ADDR(params) ? " 64 bit addr" : "", 108 + HCC_LPM(params) ? " LPM" : "", 109 + HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "", 110 + HCC_HW_PREFETCH(params) ? " hw prefetch" : "", 111 + HCC_32FRAME_PERIODIC_LIST(params) ? 112 + " 32 peridic list" : ""); 108 113 } 109 114 } 110 115 #else ··· 196 191 dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) 197 192 { 198 193 return scnprintf (buf, len, 199 - "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s", 194 + "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s", 200 195 label, label [0] ? " " : "", status, 196 + (status & STS_PPCE_MASK) ? " PPCE" : "", 201 197 (status & STS_ASS) ? " Async" : "", 202 198 (status & STS_PSS) ? " Periodic" : "", 203 199 (status & STS_RECL) ? " Recl" : "", ··· 216 210 dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) 217 211 { 218 212 return scnprintf (buf, len, 219 - "%s%sintrenable %02x%s%s%s%s%s%s", 213 + "%s%sintrenable %02x%s%s%s%s%s%s%s", 220 214 label, label [0] ? " " : "", enable, 215 + (enable & STS_PPCE_MASK) ? " PPCE" : "", 221 216 (enable & STS_IAA) ? " IAA" : "", 222 217 (enable & STS_FATAL) ? " FATAL" : "", 223 218 (enable & STS_FLR) ? " FLR" : "", ··· 235 228 dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) 236 229 { 237 230 return scnprintf (buf, len, 238 - "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", 231 + "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s " 232 + "period=%s%s %s", 239 233 label, label [0] ? " " : "", command, 240 - (command & CMD_PARK) ? "park" : "(park)", 234 + (command & CMD_HIRD) ? " HIRD" : "", 235 + (command & CMD_PPCEE) ? " PPCEE" : "", 236 + (command & CMD_FSP) ? " FSP" : "", 237 + (command & CMD_ASPE) ? " ASPE" : "", 238 + (command & CMD_PSPE) ? " PSPE" : "", 239 + (command & CMD_PARK) ? " park" : "(park)", 241 240 CMD_PARK_CNT (command), 242 241 (command >> 16) & 0x3f, 243 242 (command & CMD_LRESET) ? " LReset" : "", ··· 270 257 } 271 258 272 259 return scnprintf (buf, len, 273 - "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", 260 + "%s%sport:%d status %06x %d %s%s%s%s%s%s " 261 + "sig=%s%s%s%s%s%s%s%s%s%s%s", 274 262 label, label [0] ? " " : "", port, status, 263 + status>>25,/*device address */ 264 + (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ? 265 + " ACK" : "", 266 + (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ? 267 + " NYET" : "", 268 + (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ? 269 + " STALL" : "", 270 + (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ? 271 + " ERR" : "", 275 272 (status & PORT_POWER) ? " POWER" : "", 276 273 (status & PORT_OWNER) ? " OWNER" : "", 277 274 sig, 275 + (status & PORT_LPM) ? " LPM" : "", 278 276 (status & PORT_RESET) ? " RESET" : "", 279 277 (status & PORT_SUSPEND) ? " SUSPEND" : "", 280 278 (status & PORT_RESUME) ? " RESUME" : "", ··· 354 330 static int debug_periodic_open(struct inode *, struct file *); 355 331 static int debug_registers_open(struct inode *, struct file *); 356 332 static int debug_async_open(struct inode *, struct file *); 333 + static int debug_lpm_open(struct inode *, struct file *); 334 + static ssize_t debug_lpm_read(struct file *file, char __user *user_buf, 335 + size_t count, loff_t *ppos); 336 + static ssize_t debug_lpm_write(struct file *file, const char __user *buffer, 337 + size_t count, loff_t *ppos); 338 + static int debug_lpm_close(struct inode *inode, struct file *file); 339 + 357 340 static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); 358 341 static int debug_close(struct inode *, struct file *); 359 342 ··· 381 350 .open = debug_registers_open, 382 351 .read = debug_output, 383 352 .release = debug_close, 353 + }; 354 + static const struct file_operations debug_lpm_fops = { 355 + .owner = THIS_MODULE, 356 + .open = debug_lpm_open, 357 + .read = debug_lpm_read, 358 + .write = debug_lpm_write, 359 + .release = debug_lpm_close, 384 360 }; 385 361 386 362 static struct dentry *ehci_debug_root; ··· 712 674 713 675 spin_lock_irqsave (&ehci->lock, flags); 714 676 715 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 677 + if (!HCD_HW_ACCESSIBLE(hcd)) { 716 678 size = scnprintf (next, size, 717 679 "bus %s, device %s\n" 718 680 "%s\n" ··· 955 917 return file->private_data ? 0 : -ENOMEM; 956 918 } 957 919 920 + static int debug_lpm_open(struct inode *inode, struct file *file) 921 + { 922 + file->private_data = inode->i_private; 923 + return 0; 924 + } 925 + 926 + static int debug_lpm_close(struct inode *inode, struct file *file) 927 + { 928 + return 0; 929 + } 930 + 931 + static ssize_t debug_lpm_read(struct file *file, char __user *user_buf, 932 + size_t count, loff_t *ppos) 933 + { 934 + /* TODO: show lpm stats */ 935 + return 0; 936 + } 937 + 938 + static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf, 939 + size_t count, loff_t *ppos) 940 + { 941 + struct usb_hcd *hcd; 942 + struct ehci_hcd *ehci; 943 + char buf[50]; 944 + size_t len; 945 + u32 temp; 946 + unsigned long port; 947 + u32 __iomem *portsc ; 948 + u32 params; 949 + 950 + hcd = bus_to_hcd(file->private_data); 951 + ehci = hcd_to_ehci(hcd); 952 + 953 + len = min(count, sizeof(buf) - 1); 954 + if (copy_from_user(buf, user_buf, len)) 955 + return -EFAULT; 956 + buf[len] = '\0'; 957 + if (len > 0 && buf[len - 1] == '\n') 958 + buf[len - 1] = '\0'; 959 + 960 + if (strncmp(buf, "enable", 5) == 0) { 961 + if (strict_strtoul(buf + 7, 10, &port)) 962 + return -EINVAL; 963 + params = ehci_readl(ehci, &ehci->caps->hcs_params); 964 + if (port > HCS_N_PORTS(params)) { 965 + ehci_dbg(ehci, "ERR: LPM on bad port %lu\n", port); 966 + return -ENODEV; 967 + } 968 + portsc = &ehci->regs->port_status[port-1]; 969 + temp = ehci_readl(ehci, portsc); 970 + if (!(temp & PORT_DEV_ADDR)) { 971 + ehci_dbg(ehci, "LPM: no device attached\n"); 972 + return -ENODEV; 973 + } 974 + temp |= PORT_LPM; 975 + ehci_writel(ehci, temp, portsc); 976 + printk(KERN_INFO "force enable LPM for port %lu\n", port); 977 + } else if (strncmp(buf, "hird=", 5) == 0) { 978 + unsigned long hird; 979 + if (strict_strtoul(buf + 5, 16, &hird)) 980 + return -EINVAL; 981 + printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird); 982 + temp = ehci_readl(ehci, &ehci->regs->command); 983 + temp &= ~CMD_HIRD; 984 + temp |= hird << 24; 985 + ehci_writel(ehci, temp, &ehci->regs->command); 986 + } else if (strncmp(buf, "disable", 7) == 0) { 987 + if (strict_strtoul(buf + 8, 10, &port)) 988 + return -EINVAL; 989 + params = ehci_readl(ehci, &ehci->caps->hcs_params); 990 + if (port > HCS_N_PORTS(params)) { 991 + ehci_dbg(ehci, "ERR: LPM off bad port %lu\n", port); 992 + return -ENODEV; 993 + } 994 + portsc = &ehci->regs->port_status[port-1]; 995 + temp = ehci_readl(ehci, portsc); 996 + if (!(temp & PORT_DEV_ADDR)) { 997 + ehci_dbg(ehci, "ERR: no device attached\n"); 998 + return -ENODEV; 999 + } 1000 + temp &= ~PORT_LPM; 1001 + ehci_writel(ehci, temp, portsc); 1002 + printk(KERN_INFO "disabled LPM for port %lu\n", port); 1003 + } else 1004 + return -EOPNOTSUPP; 1005 + return count; 1006 + } 1007 + 958 1008 static inline void create_debug_files (struct ehci_hcd *ehci) 959 1009 { 960 1010 struct usb_bus *bus = &ehci_to_hcd(ehci)->self; 961 1011 962 1012 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); 963 1013 if (!ehci->debug_dir) 964 - goto dir_error; 1014 + return; 965 1015 966 - ehci->debug_async = debugfs_create_file("async", S_IRUGO, 967 - ehci->debug_dir, bus, 968 - &debug_async_fops); 969 - if (!ehci->debug_async) 970 - goto async_error; 1016 + if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus, 1017 + &debug_async_fops)) 1018 + goto file_error; 971 1019 972 - ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, 973 - ehci->debug_dir, bus, 974 - &debug_periodic_fops); 975 - if (!ehci->debug_periodic) 976 - goto periodic_error; 1020 + if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus, 1021 + &debug_periodic_fops)) 1022 + goto file_error; 977 1023 978 - ehci->debug_registers = debugfs_create_file("registers", S_IRUGO, 979 - ehci->debug_dir, bus, 980 - &debug_registers_fops); 981 - if (!ehci->debug_registers) 982 - goto registers_error; 1024 + if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus, 1025 + &debug_registers_fops)) 1026 + goto file_error; 1027 + 1028 + if (!debugfs_create_file("lpm", S_IRUGO|S_IWUGO, ehci->debug_dir, bus, 1029 + &debug_lpm_fops)) 1030 + goto file_error; 1031 + 983 1032 return; 984 1033 985 - registers_error: 986 - debugfs_remove(ehci->debug_periodic); 987 - periodic_error: 988 - debugfs_remove(ehci->debug_async); 989 - async_error: 990 - debugfs_remove(ehci->debug_dir); 991 - dir_error: 992 - ehci->debug_periodic = NULL; 993 - ehci->debug_async = NULL; 994 - ehci->debug_dir = NULL; 1034 + file_error: 1035 + debugfs_remove_recursive(ehci->debug_dir); 995 1036 } 996 1037 997 1038 static inline void remove_debug_files (struct ehci_hcd *ehci) 998 1039 { 999 - debugfs_remove(ehci->debug_registers); 1000 - debugfs_remove(ehci->debug_periodic); 1001 - debugfs_remove(ehci->debug_async); 1002 - debugfs_remove(ehci->debug_dir); 1040 + debugfs_remove_recursive(ehci->debug_dir); 1003 1041 } 1004 1042 1005 1043 #endif /* STUB_DEBUG_FILES */
+2 -1
drivers/usb/host/ehci-fsl.c
··· 313 313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 314 314 void __iomem *non_ehci = hcd->regs; 315 315 316 - ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd)); 316 + ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), 317 + device_may_wakeup(dev)); 317 318 if (!fsl_deep_sleep()) 318 319 return 0; 319 320
+44 -5
drivers/usb/host/ehci-hcd.c
··· 36 36 #include <linux/dma-mapping.h> 37 37 #include <linux/debugfs.h> 38 38 #include <linux/slab.h> 39 + #include <linux/uaccess.h> 39 40 40 41 #include <asm/byteorder.h> 41 42 #include <asm/io.h> ··· 79 78 #define EHCI_TUNE_RL_TT 0 80 79 #define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 81 80 #define EHCI_TUNE_MULT_TT 1 82 - #define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 81 + /* 82 + * Some drivers think it's safe to schedule isochronous transfers more than 83 + * 256 ms into the future (partly as a result of an old bug in the scheduling 84 + * code). In an attempt to avoid trouble, we will use a minimum scheduling 85 + * length of 512 frames instead of 256. 86 + */ 87 + #define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */ 83 88 84 89 #define EHCI_IAA_MSECS 10 /* arbitrary */ 85 90 #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ ··· 106 99 static int ignore_oc = 0; 107 100 module_param (ignore_oc, bool, S_IRUGO); 108 101 MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 102 + 103 + /* for link power management(LPM) feature */ 104 + static unsigned int hird; 105 + module_param(hird, int, S_IRUGO); 106 + MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n"); 109 107 110 108 #define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 111 109 ··· 316 304 static void ehci_work(struct ehci_hcd *ehci); 317 305 318 306 #include "ehci-hub.c" 307 + #include "ehci-lpm.c" 319 308 #include "ehci-mem.c" 320 309 #include "ehci-q.c" 321 310 #include "ehci-sched.c" ··· 590 577 if (log2_irq_thresh < 0 || log2_irq_thresh > 6) 591 578 log2_irq_thresh = 0; 592 579 temp = 1 << (16 + log2_irq_thresh); 580 + if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) { 581 + ehci->has_ppcd = 1; 582 + ehci_dbg(ehci, "enable per-port change event\n"); 583 + temp |= CMD_PPCEE; 584 + } 593 585 if (HCC_CANPARK(hcc_params)) { 594 586 /* HW default park == 3, on hardware that supports it (like 595 587 * NVidia and ALI silicon), maximizes throughput on the async ··· 621 603 default: BUG(); 622 604 } 623 605 } 606 + if (HCC_LPM(hcc_params)) { 607 + /* support link power management EHCI 1.1 addendum */ 608 + ehci_dbg(ehci, "support lpm\n"); 609 + ehci->has_lpm = 1; 610 + if (hird > 0xf) { 611 + ehci_dbg(ehci, "hird %d invalid, use default 0", 612 + hird); 613 + hird = 0; 614 + } 615 + temp |= hird << 24; 616 + } 624 617 ehci->command = temp; 625 618 626 619 /* Accept arbitrarily long scatter-gather lists */ 627 - hcd->self.sg_tablesize = ~0; 620 + if (!(hcd->driver->flags & HCD_LOCAL_MEM)) 621 + hcd->self.sg_tablesize = ~0; 628 622 return 0; 629 623 } 630 624 ··· 649 619 u32 hcc_params; 650 620 651 621 hcd->uses_new_polling = 1; 652 - hcd->poll_rh = 0; 653 622 654 623 /* EHCI spec section 4.1 */ 655 624 if ((retval = ehci_reset(ehci)) != 0) { ··· 793 764 /* remote wakeup [4.3.1] */ 794 765 if (status & STS_PCD) { 795 766 unsigned i = HCS_N_PORTS (ehci->hcs_params); 767 + u32 ppcd = 0; 796 768 797 769 /* kick root hub later */ 798 770 pcd_status = status; ··· 802 772 if (!(cmd & CMD_RUN)) 803 773 usb_hcd_resume_root_hub(hcd); 804 774 775 + /* get per-port change detect bits */ 776 + if (ehci->has_ppcd) 777 + ppcd = status >> 16; 778 + 805 779 while (i--) { 806 - int pstatus = ehci_readl(ehci, 807 - &ehci->regs->port_status [i]); 780 + int pstatus; 781 + 782 + /* leverage per-port change bits feature */ 783 + if (ehci->has_ppcd && !(ppcd & (1 << i))) 784 + continue; 785 + pstatus = ehci_readl(ehci, 786 + &ehci->regs->port_status[i]); 808 787 809 788 if (pstatus & PORT_OWNER) 810 789 continue;
+21 -4
drivers/usb/host/ehci-hub.c
··· 107 107 } 108 108 109 109 static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 110 - bool suspending) 110 + bool suspending, bool do_wakeup) 111 111 { 112 112 int port; 113 113 u32 temp; ··· 117 117 * when the controller is suspended or resumed. In all other 118 118 * cases they don't need to be changed. 119 119 */ 120 - if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || 121 - device_may_wakeup(ehci_to_hcd(ehci)->self.controller)) 120 + if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup) 122 121 return; 123 122 124 123 /* clear phy low-power mode before changing wakeup flags */ ··· 166 167 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 167 168 } 168 169 } 170 + 171 + /* Does the root hub have a port wakeup pending? */ 172 + if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD)) 173 + usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); 169 174 } 170 175 171 176 static int ehci_bus_suspend (struct usb_hcd *hcd) ··· 319 316 if (time_before (jiffies, ehci->next_statechange)) 320 317 msleep(5); 321 318 spin_lock_irq (&ehci->lock); 322 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 319 + if (!HCD_HW_ACCESSIBLE(hcd)) { 323 320 spin_unlock_irq(&ehci->lock); 324 321 return -ESHUTDOWN; 325 322 } ··· 606 603 u32 mask; 607 604 int ports, i, retval = 1; 608 605 unsigned long flags; 606 + u32 ppcd = 0; 609 607 610 608 /* if !USB_SUSPEND, root hub timers won't get shut down ... */ 611 609 if (!HC_IS_RUNNING(hcd->state)) ··· 636 632 637 633 /* port N changes (bit N)? */ 638 634 spin_lock_irqsave (&ehci->lock, flags); 635 + 636 + /* get per-port change detect bits */ 637 + if (ehci->has_ppcd) 638 + ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16; 639 + 639 640 for (i = 0; i < ports; i++) { 641 + /* leverage per-port change bits feature */ 642 + if (ehci->has_ppcd && !(ppcd & (1 << i))) 643 + continue; 640 644 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 641 645 642 646 /* ··· 802 790 status_reg); 803 791 break; 804 792 case USB_PORT_FEAT_C_CONNECTION: 793 + if (ehci->has_lpm) { 794 + /* clear PORTSC bits on disconnect */ 795 + temp &= ~PORT_LPM; 796 + temp &= ~PORT_DEV_ADDR; 797 + } 805 798 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, 806 799 status_reg); 807 800 break;
+83
drivers/usb/host/ehci-lpm.c
··· 1 + /* ehci-lpm.c EHCI HCD LPM support code 2 + * Copyright (c) 2008 - 2010, Intel Corporation. 3 + * Author: Jacob Pan <jacob.jun.pan@intel.com> 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License version 2 as 7 + * published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program; if not, write to the Free Software 16 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 + */ 18 + 19 + /* this file is part of ehci-hcd.c */ 20 + static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num) 21 + { 22 + u32 __iomem portsc; 23 + 24 + ehci_dbg(ehci, "set dev address %d for port %d\n", dev_addr, port_num); 25 + if (port_num > HCS_N_PORTS(ehci->hcs_params)) { 26 + ehci_dbg(ehci, "invalid port number %d\n", port_num); 27 + return -ENODEV; 28 + } 29 + portsc = ehci_readl(ehci, &ehci->regs->port_status[port_num-1]); 30 + portsc &= ~PORT_DEV_ADDR; 31 + portsc |= dev_addr<<25; 32 + ehci_writel(ehci, portsc, &ehci->regs->port_status[port_num-1]); 33 + return 0; 34 + } 35 + 36 + /* 37 + * this function is used to check if the device support LPM 38 + * if yes, mark the PORTSC register with PORT_LPM bit 39 + */ 40 + static int ehci_lpm_check(struct ehci_hcd *ehci, int port) 41 + { 42 + u32 __iomem *portsc ; 43 + u32 val32; 44 + int retval; 45 + 46 + portsc = &ehci->regs->port_status[port-1]; 47 + val32 = ehci_readl(ehci, portsc); 48 + if (!(val32 & PORT_DEV_ADDR)) { 49 + ehci_dbg(ehci, "LPM: no device attached\n"); 50 + return -ENODEV; 51 + } 52 + val32 |= PORT_LPM; 53 + ehci_writel(ehci, val32, portsc); 54 + msleep(5); 55 + val32 |= PORT_SUSPEND; 56 + ehci_dbg(ehci, "Sending LPM 0x%08x to port %d\n", val32, port); 57 + ehci_writel(ehci, val32, portsc); 58 + /* wait for ACK */ 59 + msleep(10); 60 + retval = handshake(ehci, &ehci->regs->port_status[port-1], PORT_SSTS, 61 + PORTSC_SUSPEND_STS_ACK, 125); 62 + dbg_port(ehci, "LPM", port, val32); 63 + if (retval != -ETIMEDOUT) { 64 + ehci_dbg(ehci, "LPM: device ACK for LPM\n"); 65 + val32 |= PORT_LPM; 66 + /* 67 + * now device should be in L1 sleep, let's wake up the device 68 + * so that we can complete enumeration. 69 + */ 70 + ehci_writel(ehci, val32, portsc); 71 + msleep(10); 72 + val32 |= PORT_RESUME; 73 + ehci_writel(ehci, val32, portsc); 74 + } else { 75 + ehci_dbg(ehci, "LPM: device does not ACK, disable LPM %d\n", 76 + retval); 77 + val32 &= ~PORT_LPM; 78 + retval = -ETIMEDOUT; 79 + ehci_writel(ehci, val32, portsc); 80 + } 81 + 82 + return retval; 83 + }
+36
drivers/usb/host/ehci-omap.c
··· 38 38 #include <linux/gpio.h> 39 39 #include <linux/regulator/consumer.h> 40 40 #include <linux/slab.h> 41 + #include <linux/usb/ulpi.h> 41 42 #include <plat/usb.h> 42 43 43 44 /* ··· 237 236 238 237 /*-------------------------------------------------------------------------*/ 239 238 239 + static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port) 240 + { 241 + unsigned long timeout = jiffies + msecs_to_jiffies(1000); 242 + unsigned reg = 0; 243 + 244 + reg = ULPI_FUNC_CTRL_RESET 245 + /* FUNCTION_CTRL_SET register */ 246 + | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) 247 + /* Write */ 248 + | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) 249 + /* PORTn */ 250 + | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) 251 + /* start ULPI access*/ 252 + | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); 253 + 254 + ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg); 255 + 256 + /* Wait for ULPI access completion */ 257 + while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI) 258 + & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { 259 + cpu_relax(); 260 + 261 + if (time_after(jiffies, timeout)) { 262 + dev_dbg(omap->dev, "phy reset operation timed out\n"); 263 + break; 264 + } 265 + } 266 + } 267 + 240 268 /* omap_start_ehc 241 269 * - Start the TI USBHOST controller 242 270 */ ··· 454 424 if (gpio_is_valid(omap->reset_gpio_port[1])) 455 425 gpio_set_value(omap->reset_gpio_port[1], 1); 456 426 } 427 + 428 + /* Soft reset the PHY using PHY reset command over ULPI */ 429 + if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) 430 + omap_ehci_soft_phy_reset(omap, 0); 431 + if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) 432 + omap_ehci_soft_phy_reset(omap, 1); 457 433 458 434 return 0; 459 435
+24 -2
drivers/usb/host/ehci-pci.c
··· 114 114 break; 115 115 case PCI_VENDOR_ID_INTEL: 116 116 ehci->need_io_watchdog = 0; 117 + ehci->fs_i_thresh = 1; 117 118 if (pdev->device == 0x27cc) { 118 119 ehci->broken_periodic = 1; 119 120 ehci_info(ehci, "using broken periodic workaround\n"); ··· 278 277 * Also they depend on separate root hub suspend/resume. 279 278 */ 280 279 281 - static int ehci_pci_suspend(struct usb_hcd *hcd) 280 + static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 282 281 { 283 282 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 284 283 unsigned long flags; ··· 292 291 * the root hub is either suspended or stopped. 293 292 */ 294 293 spin_lock_irqsave (&ehci->lock, flags); 295 - ehci_prepare_ports_for_controller_suspend(ehci); 294 + ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup); 296 295 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 297 296 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 298 297 ··· 362 361 } 363 362 #endif 364 363 364 + static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev) 365 + { 366 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 367 + int rc = 0; 368 + 369 + if (!udev->parent) /* udev is root hub itself, impossible */ 370 + rc = -1; 371 + /* we only support lpm device connected to root hub yet */ 372 + if (ehci->has_lpm && !udev->parent->parent) { 373 + rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum); 374 + if (!rc) 375 + rc = ehci_lpm_check(ehci, udev->portnum); 376 + } 377 + return rc; 378 + } 379 + 365 380 static const struct hc_driver ehci_pci_hc_driver = { 366 381 .description = hcd_name, 367 382 .product_desc = "EHCI Host Controller", ··· 423 406 .bus_resume = ehci_bus_resume, 424 407 .relinquish_port = ehci_relinquish_port, 425 408 .port_handed_over = ehci_port_handed_over, 409 + 410 + /* 411 + * call back when device connected and addressed 412 + */ 413 + .update_device = ehci_update_device, 426 414 427 415 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 428 416 };
+1 -2
drivers/usb/host/ehci-q.c
··· 1126 1126 #endif 1127 1127 1128 1128 spin_lock_irqsave (&ehci->lock, flags); 1129 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1130 - &ehci_to_hcd(ehci)->flags))) { 1129 + if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) { 1131 1130 rc = -ESHUTDOWN; 1132 1131 goto done; 1133 1132 }
+83 -95
drivers/usb/host/ehci-sched.c
··· 880 880 881 881 spin_lock_irqsave (&ehci->lock, flags); 882 882 883 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 884 - &ehci_to_hcd(ehci)->flags))) { 883 + if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) { 885 884 status = -ESHUTDOWN; 886 885 goto done_not_linked; 887 886 } ··· 1073 1074 stream->bEndpointAddress &= 0x0f; 1074 1075 if (stream->ep) 1075 1076 stream->ep->hcpriv = NULL; 1076 - 1077 - if (stream->rescheduled) { 1078 - ehci_info (ehci, "ep%d%s-iso rescheduled " 1079 - "%lu times in %lu seconds\n", 1080 - stream->bEndpointAddress, is_in ? "in" : "out", 1081 - stream->rescheduled, 1082 - ((jiffies - stream->start)/HZ) 1083 - ); 1084 - } 1085 1077 1086 1078 kfree(stream); 1087 1079 } ··· 1386 1396 struct ehci_iso_stream *stream 1387 1397 ) 1388 1398 { 1389 - u32 now, next, start, period; 1399 + u32 now, next, start, period, span; 1390 1400 int status; 1391 1401 unsigned mod = ehci->periodic_size << 3; 1392 1402 struct ehci_iso_sched *sched = urb->hcpriv; 1393 - struct pci_dev *pdev; 1394 1403 1395 - if (sched->span > (mod - SCHEDULE_SLOP)) { 1404 + period = urb->interval; 1405 + span = sched->span; 1406 + if (!stream->highspeed) { 1407 + period <<= 3; 1408 + span <<= 3; 1409 + } 1410 + 1411 + if (span > mod - SCHEDULE_SLOP) { 1396 1412 ehci_dbg (ehci, "iso request %p too long\n", urb); 1397 1413 status = -EFBIG; 1398 1414 goto fail; 1399 1415 } 1400 1416 1401 - if ((stream->depth + sched->span) > mod) { 1402 - ehci_dbg (ehci, "request %p would overflow (%d+%d>%d)\n", 1403 - urb, stream->depth, sched->span, mod); 1404 - status = -EFBIG; 1405 - goto fail; 1406 - } 1407 - 1408 - period = urb->interval; 1409 - if (!stream->highspeed) 1410 - period <<= 3; 1411 - 1412 - now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 1417 + now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1); 1413 1418 1414 1419 /* Typical case: reuse current schedule, stream is still active. 1415 1420 * Hopefully there are no gaps from the host falling behind ··· 1412 1427 * slot in the schedule, implicitly assuming URB_ISO_ASAP. 1413 1428 */ 1414 1429 if (likely (!list_empty (&stream->td_list))) { 1415 - pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 1416 - start = stream->next_uframe; 1430 + u32 excess; 1417 1431 1418 1432 /* For high speed devices, allow scheduling within the 1419 - * isochronous scheduling threshold. For full speed devices, 1420 - * don't. (Work around for Intel ICH9 bug.) 1433 + * isochronous scheduling threshold. For full speed devices 1434 + * and Intel PCI-based controllers, don't (work around for 1435 + * Intel ICH9 bug). 1421 1436 */ 1422 - if (!stream->highspeed && 1423 - pdev->vendor == PCI_VENDOR_ID_INTEL) 1437 + if (!stream->highspeed && ehci->fs_i_thresh) 1424 1438 next = now + ehci->i_thresh; 1425 1439 else 1426 1440 next = now; 1427 1441 1428 - /* Fell behind (by up to twice the slop amount)? */ 1429 - if (((start - next) & (mod - 1)) >= 1430 - mod - 2 * SCHEDULE_SLOP) 1431 - start += period * DIV_ROUND_UP( 1432 - (next - start) & (mod - 1), 1433 - period); 1434 - 1435 - /* Tried to schedule too far into the future? */ 1436 - if (unlikely(((start - now) & (mod - 1)) + sched->span 1437 - >= mod - 2 * SCHEDULE_SLOP)) { 1442 + /* Fell behind (by up to twice the slop amount)? 1443 + * We decide based on the time of the last currently-scheduled 1444 + * slot, not the time of the next available slot. 1445 + */ 1446 + excess = (stream->next_uframe - period - next) & (mod - 1); 1447 + if (excess >= mod - 2 * SCHEDULE_SLOP) 1448 + start = next + excess - mod + period * 1449 + DIV_ROUND_UP(mod - excess, period); 1450 + else 1451 + start = next + excess + period; 1452 + if (start - now >= mod) { 1453 + ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n", 1454 + urb, start - now - period, period, 1455 + mod); 1438 1456 status = -EFBIG; 1439 1457 goto fail; 1440 1458 } 1441 - stream->next_uframe = start; 1442 - goto ready; 1443 1459 } 1444 1460 1445 1461 /* need to schedule; when's the next (u)frame we could start? ··· 1449 1463 * can also help high bandwidth if the dma and irq loads don't 1450 1464 * jump until after the queue is primed. 1451 1465 */ 1452 - start = SCHEDULE_SLOP + (now & ~0x07); 1453 - start %= mod; 1454 - stream->next_uframe = start; 1466 + else { 1467 + start = SCHEDULE_SLOP + (now & ~0x07); 1455 1468 1456 - /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1469 + /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1457 1470 1458 - /* find a uframe slot with enough bandwidth */ 1459 - for (; start < (stream->next_uframe + period); start++) { 1460 - int enough_space; 1471 + /* find a uframe slot with enough bandwidth */ 1472 + next = start + period; 1473 + for (; start < next; start++) { 1461 1474 1462 - /* check schedule: enough space? */ 1463 - if (stream->highspeed) 1464 - enough_space = itd_slot_ok (ehci, mod, start, 1465 - stream->usecs, period); 1466 - else { 1467 - if ((start % 8) >= 6) 1468 - continue; 1469 - enough_space = sitd_slot_ok (ehci, mod, stream, 1470 - start, sched, period); 1475 + /* check schedule: enough space? */ 1476 + if (stream->highspeed) { 1477 + if (itd_slot_ok(ehci, mod, start, 1478 + stream->usecs, period)) 1479 + break; 1480 + } else { 1481 + if ((start % 8) >= 6) 1482 + continue; 1483 + if (sitd_slot_ok(ehci, mod, stream, 1484 + start, sched, period)) 1485 + break; 1486 + } 1471 1487 } 1472 1488 1473 - /* schedule it here if there's enough bandwidth */ 1474 - if (enough_space) { 1475 - stream->next_uframe = start % mod; 1476 - goto ready; 1489 + /* no room in the schedule */ 1490 + if (start == next) { 1491 + ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n", 1492 + urb, now, now + mod); 1493 + status = -ENOSPC; 1494 + goto fail; 1477 1495 } 1478 1496 } 1479 1497 1480 - /* no room in the schedule */ 1481 - ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n", 1482 - list_empty (&stream->td_list) ? "" : "re", 1483 - urb, now, now + mod); 1484 - status = -ENOSPC; 1498 + /* Tried to schedule too far into the future? */ 1499 + if (unlikely(start - now + span - period 1500 + >= mod - 2 * SCHEDULE_SLOP)) { 1501 + ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n", 1502 + urb, start - now, span - period, 1503 + mod - 2 * SCHEDULE_SLOP); 1504 + status = -EFBIG; 1505 + goto fail; 1506 + } 1485 1507 1486 - fail: 1487 - iso_sched_free (stream, sched); 1488 - urb->hcpriv = NULL; 1489 - return status; 1508 + stream->next_uframe = start & (mod - 1); 1490 1509 1491 - ready: 1492 1510 /* report high speed start in uframes; full speed, in frames */ 1493 1511 urb->start_frame = stream->next_uframe; 1494 1512 if (!stream->highspeed) 1495 1513 urb->start_frame >>= 3; 1496 1514 return 0; 1515 + 1516 + fail: 1517 + iso_sched_free(stream, sched); 1518 + urb->hcpriv = NULL; 1519 + return status; 1497 1520 } 1498 1521 1499 1522 /*-------------------------------------------------------------------------*/ ··· 1597 1602 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1598 1603 struct ehci_itd *itd; 1599 1604 1600 - next_uframe = stream->next_uframe % mod; 1605 + next_uframe = stream->next_uframe & (mod - 1); 1601 1606 1602 1607 if (unlikely (list_empty(&stream->td_list))) { 1603 1608 ehci_to_hcd(ehci)->self.bandwidth_allocated ··· 1608 1613 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 1609 1614 urb->interval, 1610 1615 next_uframe >> 3, next_uframe & 0x7); 1611 - stream->start = jiffies; 1612 1616 } 1613 1617 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1614 1618 ··· 1633 1639 itd_patch(ehci, itd, iso_sched, packet, uframe); 1634 1640 1635 1641 next_uframe += stream->interval; 1636 - stream->depth += stream->interval; 1637 - next_uframe %= mod; 1642 + next_uframe &= mod - 1; 1638 1643 packet++; 1639 1644 1640 1645 /* link completed itds into the schedule */ 1641 1646 if (((next_uframe >> 3) != frame) 1642 1647 || packet == urb->number_of_packets) { 1643 - itd_link (ehci, frame % ehci->periodic_size, itd); 1648 + itd_link(ehci, frame & (ehci->periodic_size - 1), itd); 1644 1649 itd = NULL; 1645 1650 } 1646 1651 } ··· 1688 1695 1689 1696 t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]); 1690 1697 itd->hw_transaction [uframe] = 0; 1691 - stream->depth -= stream->interval; 1692 1698 1693 1699 /* report transfer status */ 1694 1700 if (unlikely (t & ISO_ERRS)) { ··· 1807 1815 1808 1816 /* schedule ... need to lock */ 1809 1817 spin_lock_irqsave (&ehci->lock, flags); 1810 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1811 - &ehci_to_hcd(ehci)->flags))) { 1818 + if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) { 1812 1819 status = -ESHUTDOWN; 1813 1820 goto done_not_linked; 1814 1821 } ··· 2015 2024 "sched devp %s ep%d%s-iso [%d] %dms/%04x\n", 2016 2025 urb->dev->devpath, stream->bEndpointAddress & 0x0f, 2017 2026 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 2018 - (next_uframe >> 3) % ehci->periodic_size, 2027 + (next_uframe >> 3) & (ehci->periodic_size - 1), 2019 2028 stream->interval, hc32_to_cpu(ehci, stream->splits)); 2020 - stream->start = jiffies; 2021 2029 } 2022 2030 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2023 2031 ··· 2037 2047 sitd->urb = urb; 2038 2048 2039 2049 sitd_patch(ehci, stream, sitd, sched, packet); 2040 - sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, 2050 + sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), 2041 2051 sitd); 2042 2052 2043 2053 next_uframe += stream->interval << 3; 2044 - stream->depth += stream->interval << 3; 2045 2054 } 2046 - stream->next_uframe = next_uframe % mod; 2055 + stream->next_uframe = next_uframe & (mod - 1); 2047 2056 2048 2057 /* don't need that schedule data any more */ 2049 2058 iso_sched_free (stream, sched); ··· 2100 2111 desc->actual_length = desc->length - SITD_LENGTH(t); 2101 2112 urb->actual_length += desc->actual_length; 2102 2113 } 2103 - stream->depth -= stream->interval << 3; 2104 2114 2105 2115 /* handle completion now? */ 2106 2116 if ((urb_index + 1) != urb->number_of_packets) ··· 2189 2201 2190 2202 /* schedule ... need to lock */ 2191 2203 spin_lock_irqsave (&ehci->lock, flags); 2192 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2193 - &ehci_to_hcd(ehci)->flags))) { 2204 + if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) { 2194 2205 status = -ESHUTDOWN; 2195 2206 goto done_not_linked; 2196 2207 } ··· 2250 2263 now_uframe = ehci->next_uframe; 2251 2264 if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 2252 2265 clock = ehci_readl(ehci, &ehci->regs->frame_index); 2253 - clock_frame = (clock >> 3) % ehci->periodic_size; 2266 + clock_frame = (clock >> 3) & (ehci->periodic_size - 1); 2254 2267 } else { 2255 2268 clock = now_uframe + mod - 1; 2256 2269 clock_frame = -1; ··· 2259 2272 free_cached_lists(ehci); 2260 2273 ehci->clock_frame = clock_frame; 2261 2274 } 2262 - clock %= mod; 2275 + clock &= mod - 1; 2263 2276 clock_frame = clock >> 3; 2264 2277 2265 2278 for (;;) { ··· 2348 2361 * frame is current. 2349 2362 */ 2350 2363 if (((frame == clock_frame) || 2351 - (((frame + 1) % ehci->periodic_size) 2364 + (((frame + 1) & (ehci->periodic_size - 1)) 2352 2365 == clock_frame)) 2353 2366 && live 2354 2367 && (q.sitd->hw_results & ··· 2415 2428 || ehci->periodic_sched == 0) 2416 2429 break; 2417 2430 ehci->next_uframe = now_uframe; 2418 - now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 2431 + now = ehci_readl(ehci, &ehci->regs->frame_index) & 2432 + (mod - 1); 2419 2433 if (now_uframe == now) 2420 2434 break; 2421 2435 ··· 2429 2441 } 2430 2442 } else { 2431 2443 now_uframe++; 2432 - now_uframe %= mod; 2444 + now_uframe &= mod - 1; 2433 2445 } 2434 2446 } 2435 2447 }
+7 -11
drivers/usb/host/ehci.h
··· 130 130 unsigned has_amcc_usb23:1; 131 131 unsigned need_io_watchdog:1; 132 132 unsigned broken_periodic:1; 133 + unsigned fs_i_thresh:1; /* Intel iso scheduling */ 133 134 134 135 /* required for usb32 quirk */ 135 136 #define OHCI_CTRL_HCFS (3 << 6) ··· 141 140 #define OHCI_HCCTRL_LEN 0x4 142 141 __hc32 *ohci_hcctrl_reg; 143 142 unsigned has_hostpc:1; 144 - 143 + unsigned has_lpm:1; /* support link power management */ 144 + unsigned has_ppcd:1; /* support per-port change bits */ 145 145 u8 sbrn; /* packed release number */ 146 146 147 147 /* irq statistics */ ··· 156 154 /* debug files */ 157 155 #ifdef DEBUG 158 156 struct dentry *debug_dir; 159 - struct dentry *debug_async; 160 - struct dentry *debug_periodic; 161 - struct dentry *debug_registers; 162 157 #endif 163 158 }; 164 159 ··· 400 401 u32 refcount; 401 402 u8 bEndpointAddress; 402 403 u8 highspeed; 403 - u16 depth; /* depth in uframes */ 404 404 struct list_head td_list; /* queued itds/sitds */ 405 405 struct list_head free_list; /* list of unused itds/sitds */ 406 406 struct usb_device *udev; 407 407 struct usb_host_endpoint *ep; 408 408 409 409 /* output of (re)scheduling */ 410 - unsigned long start; /* jiffies */ 411 - unsigned long rescheduled; 412 410 int next_uframe; 413 411 __hc32 splits; 414 412 ··· 534 538 535 539 /* Prepare the PORTSC wakeup flags during controller suspend/resume */ 536 540 537 - #define ehci_prepare_ports_for_controller_suspend(ehci) \ 538 - ehci_adjust_port_wakeup_flags(ehci, true); 541 + #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \ 542 + ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup); 539 543 540 - #define ehci_prepare_ports_for_controller_resume(ehci) \ 541 - ehci_adjust_port_wakeup_flags(ehci, false); 544 + #define ehci_prepare_ports_for_controller_resume(ehci) \ 545 + ehci_adjust_port_wakeup_flags(ehci, false, false); 542 546 543 547 /*-------------------------------------------------------------------------*/ 544 548
+2 -2
drivers/usb/host/hwa-hc.c
··· 159 159 goto error_set_cluster_id; 160 160 161 161 usb_hcd->uses_new_polling = 1; 162 - usb_hcd->poll_rh = 1; 162 + set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags); 163 163 usb_hcd->state = HC_STATE_RUNNING; 164 164 result = 0; 165 165 out: ··· 776 776 goto error_alloc; 777 777 } 778 778 usb_hcd->wireless = 1; 779 - usb_hcd->flags |= HCD_FLAG_SAW_IRQ; 779 + set_bit(HCD_FLAG_SAW_IRQ, &usb_hcd->flags); 780 780 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 781 781 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 782 782 hwahc_init(hwahc);
+1 -1
drivers/usb/host/imx21-hcd.c
··· 1521 1521 return -ETIMEDOUT; 1522 1522 } 1523 1523 spin_unlock_irq(&imx21->lock); 1524 - schedule_timeout(1); 1524 + schedule_timeout_uninterruptible(1); 1525 1525 spin_lock_irq(&imx21->lock); 1526 1526 } 1527 1527 spin_unlock_irqrestore(&imx21->lock, flags);
+1 -23
drivers/usb/host/isp1362.h
··· 8 8 /* 9 9 * Platform specific compile time options 10 10 */ 11 - #if defined(CONFIG_ARCH_KARO) 12 - #include <asm/arch/hardware.h> 13 - #include <asm/arch/pxa-regs.h> 14 - #include <asm/arch/karo.h> 15 - 16 - #define USE_32BIT 1 17 - 18 - 19 - /* These options are mutually eclusive */ 20 - #define USE_PLATFORM_DELAY 1 21 - #define USE_NDELAY 0 22 - /* 23 - * MAX_ROOT_PORTS: Number of downstream ports 24 - * 25 - * The chip has two USB ports, one of which can be configured as 26 - * an USB device port, so the value of this constant is implementation 27 - * specific. 28 - */ 29 - #define MAX_ROOT_PORTS 2 30 - #define DUMMY_DELAY_ACCESS do {} while (0) 31 - 32 - /* insert platform specific definitions for other machines here */ 33 - #elif defined(CONFIG_BLACKFIN) 11 + #if defined(CONFIG_BLACKFIN) 34 12 35 13 #include <linux/io.h> 36 14 #define USE_32BIT 0
+1 -2
drivers/usb/host/isp1760-hcd.c
··· 482 482 u32 chipid; 483 483 484 484 hcd->uses_new_polling = 1; 485 - hcd->poll_rh = 0; 486 485 487 486 hcd->state = HC_STATE_RUNNING; 488 487 isp1760_enable_interrupts(hcd); ··· 1449 1450 epnum = urb->ep->desc.bEndpointAddress; 1450 1451 1451 1452 spin_lock_irqsave(&priv->lock, flags); 1452 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &priv_to_hcd(priv)->flags)) { 1453 + if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) { 1453 1454 rc = -ESHUTDOWN; 1454 1455 goto done; 1455 1456 }
+2 -2
drivers/usb/host/ohci-dbg.c
··· 645 645 hcd->product_desc, 646 646 hcd_name); 647 647 648 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 648 + if (!HCD_HW_ACCESSIBLE(hcd)) { 649 649 size -= scnprintf (next, size, 650 650 "SUSPENDED (no register access)\n"); 651 651 goto done; ··· 687 687 next += temp; 688 688 689 689 temp = scnprintf (next, size, "hub poll timer %s\n", 690 - ohci_to_hcd(ohci)->poll_rh ? "ON" : "off"); 690 + HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off"); 691 691 size -= temp; 692 692 next += temp; 693 693
+3 -3
drivers/usb/host/ohci-hcd.c
··· 212 212 spin_lock_irqsave (&ohci->lock, flags); 213 213 214 214 /* don't submit to a dead HC */ 215 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 215 + if (!HCD_HW_ACCESSIBLE(hcd)) { 216 216 retval = -ENODEV; 217 217 goto fail; 218 218 } ··· 685 685 } 686 686 687 687 /* use rhsc irqs after khubd is fully initialized */ 688 - hcd->poll_rh = 1; 688 + set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 689 689 hcd->uses_new_polling = 1; 690 690 691 691 /* start controller operations */ ··· 822 822 else if (ints & OHCI_INTR_RD) { 823 823 ohci_vdbg(ohci, "resume detect\n"); 824 824 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus); 825 - hcd->poll_rh = 1; 825 + set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 826 826 if (ohci->autostop) { 827 827 spin_lock (&ohci->lock); 828 828 ohci_rh_resume (ohci);
+16 -7
drivers/usb/host/ohci-hub.c
··· 284 284 285 285 spin_lock_irq (&ohci->lock); 286 286 287 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 287 + if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 288 288 rc = -ESHUTDOWN; 289 289 else 290 290 rc = ohci_rh_suspend (ohci, 0); ··· 302 302 303 303 spin_lock_irq (&ohci->lock); 304 304 305 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 305 + if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 306 306 rc = -ESHUTDOWN; 307 307 else 308 308 rc = ohci_rh_resume (ohci); ··· 355 355 ohci_readl(ohci, &ohci->regs->intrenable); 356 356 msleep(20); 357 357 } 358 + 359 + /* Does the root hub have a port wakeup pending? */ 360 + if (ohci_readl(ohci, &ohci->regs->intrstatus) & 361 + (OHCI_INTR_RD | OHCI_INTR_RHSC)) 362 + usb_hcd_resume_root_hub(hcd); 358 363 } 359 364 360 365 /* Carry out polling-, autostop-, and autoresume-related state changes */ ··· 369 364 int poll_rh = 1; 370 365 int rhsc_enable; 371 366 372 - /* Some broken controllers never turn off RHCS in the interrupt 367 + /* Some broken controllers never turn off RHSC in the interrupt 373 368 * status register. For their sake we won't re-enable RHSC 374 369 * interrupts if the interrupt bit is already active. 375 370 */ ··· 494 489 unsigned long flags; 495 490 496 491 spin_lock_irqsave (&ohci->lock, flags); 497 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 492 + if (!HCD_HW_ACCESSIBLE(hcd)) 498 493 goto done; 499 494 500 495 /* undocumented erratum seen on at least rev D */ ··· 538 533 } 539 534 } 540 535 541 - hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, 542 - any_connected, rhsc_status); 536 + if (ohci_root_hub_state_changes(ohci, changed, 537 + any_connected, rhsc_status)) 538 + set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 539 + else 540 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 541 + 543 542 544 543 done: 545 544 spin_unlock_irqrestore (&ohci->lock, flags); ··· 710 701 u32 temp; 711 702 int retval = 0; 712 703 713 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 704 + if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) 714 705 return -ESHUTDOWN; 715 706 716 707 switch (typeReq) {
+1 -1
drivers/usb/host/ohci-pci.c
··· 392 392 393 393 #ifdef CONFIG_PM 394 394 395 - static int ohci_pci_suspend(struct usb_hcd *hcd) 395 + static int ohci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 396 396 { 397 397 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 398 398 unsigned long flags;
+49 -3
drivers/usb/host/ohci-ssb.c
··· 93 93 { 94 94 struct usb_hcd *hcd = ssb_get_drvdata(dev); 95 95 96 + if (hcd->driver->shutdown) 97 + hcd->driver->shutdown(hcd); 96 98 usb_remove_hcd(hcd); 97 99 iounmap(hcd->regs); 100 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 98 101 usb_put_hcd(hcd); 99 102 ssb_device_disable(dev, 0); 100 103 } ··· 109 106 int err = -ENOMEM; 110 107 u32 tmp, flags = 0; 111 108 112 - if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) 113 - flags |= SSB_OHCI_TMSLOW_HOSTMODE; 109 + if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) || 110 + dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32))) 111 + return -EOPNOTSUPP; 114 112 115 - ssb_device_enable(dev, flags); 113 + if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) { 114 + /* Put the device into host-mode. */ 115 + flags |= SSB_OHCI_TMSLOW_HOSTMODE; 116 + ssb_device_enable(dev, flags); 117 + } else if (dev->id.coreid == SSB_DEV_USB20_HOST) { 118 + /* 119 + * USB 2.0 special considerations: 120 + * 121 + * In addition to the standard SSB reset sequence, the Host 122 + * Control Register must be programmed to bring the USB core 123 + * and various phy components out of reset. 124 + */ 125 + ssb_device_enable(dev, 0); 126 + ssb_write32(dev, 0x200, 0x7ff); 127 + 128 + /* Change Flush control reg */ 129 + tmp = ssb_read32(dev, 0x400); 130 + tmp &= ~8; 131 + ssb_write32(dev, 0x400, tmp); 132 + tmp = ssb_read32(dev, 0x400); 133 + 134 + /* Change Shim control reg */ 135 + tmp = ssb_read32(dev, 0x304); 136 + tmp &= ~0x100; 137 + ssb_write32(dev, 0x304, tmp); 138 + tmp = ssb_read32(dev, 0x304); 139 + 140 + udelay(1); 141 + 142 + /* Work around for 5354 failures */ 143 + if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) { 144 + /* Change syn01 reg */ 145 + tmp = 0x00fe00fe; 146 + ssb_write32(dev, 0x894, tmp); 147 + 148 + /* Change syn03 reg */ 149 + tmp = ssb_read32(dev, 0x89c); 150 + tmp |= 0x1; 151 + ssb_write32(dev, 0x89c, tmp); 152 + } 153 + } else 154 + ssb_device_enable(dev, 0); 116 155 117 156 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev, 118 157 dev_name(dev->dev)); ··· 245 200 static const struct ssb_device_id ssb_ohci_table[] = { 246 201 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV), 247 202 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV), 203 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV), 248 204 SSB_DEVTABLE_END 249 205 }; 250 206 MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
+2 -5
drivers/usb/host/oxu210hp-hcd.c
··· 1641 1641 #endif 1642 1642 1643 1643 spin_lock_irqsave(&oxu->lock, flags); 1644 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1645 - &oxu_to_hcd(oxu)->flags))) { 1644 + if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) { 1646 1645 rc = -ESHUTDOWN; 1647 1646 goto done; 1648 1647 } ··· 2208 2209 2209 2210 spin_lock_irqsave(&oxu->lock, flags); 2210 2211 2211 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2212 - &oxu_to_hcd(oxu)->flags))) { 2212 + if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) { 2213 2213 status = -ESHUTDOWN; 2214 2214 goto done; 2215 2215 } ··· 2713 2715 u32 temp, hcc_params; 2714 2716 2715 2717 hcd->uses_new_polling = 1; 2716 - hcd->poll_rh = 0; 2717 2718 2718 2719 /* EHCI spec section 4.1 */ 2719 2720 retval = ehci_reset(oxu);
+4 -1
drivers/usb/host/sl811-hcd.c
··· 813 813 #endif 814 814 815 815 /* avoid all allocations within spinlocks */ 816 - if (!hep->hcpriv) 816 + if (!hep->hcpriv) { 817 817 ep = kzalloc(sizeof *ep, mem_flags); 818 + if (ep == NULL) 819 + return -ENOMEM; 820 + } 818 821 819 822 spin_lock_irqsave(&sl811->lock, flags); 820 823
+8 -15
drivers/usb/host/uhci-debug.c
··· 17 17 18 18 #include "uhci-hcd.h" 19 19 20 - #define uhci_debug_operations (* (const struct file_operations *) NULL) 21 20 static struct dentry *uhci_debugfs_root; 22 21 23 22 #ifdef DEBUG ··· 494 495 { 495 496 struct uhci_hcd *uhci = inode->i_private; 496 497 struct uhci_debug *up; 497 - int ret = -ENOMEM; 498 498 unsigned long flags; 499 499 500 - lock_kernel(); 501 500 up = kmalloc(sizeof(*up), GFP_KERNEL); 502 501 if (!up) 503 - goto out; 502 + return -ENOMEM; 504 503 505 504 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); 506 505 if (!up->data) { 507 506 kfree(up); 508 - goto out; 507 + return -ENOMEM; 509 508 } 510 509 511 510 up->size = 0; ··· 514 517 515 518 file->private_data = up; 516 519 517 - ret = 0; 518 - out: 519 - unlock_kernel(); 520 - return ret; 520 + return 0; 521 521 } 522 522 523 523 static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence) ··· 522 528 struct uhci_debug *up; 523 529 loff_t new = -1; 524 530 525 - lock_kernel(); 526 531 up = file->private_data; 527 532 533 + /* XXX: atomic 64bit seek access, but that needs to be fixed in the VFS */ 528 534 switch (whence) { 529 535 case 0: 530 536 new = off; ··· 533 539 new = file->f_pos + off; 534 540 break; 535 541 } 536 - if (new < 0 || new > up->size) { 537 - unlock_kernel(); 542 + 543 + if (new < 0 || new > up->size) 538 544 return -EINVAL; 539 - } 540 - unlock_kernel(); 545 + 541 546 return (file->f_pos = new); 542 547 } 543 548 ··· 557 564 return 0; 558 565 } 559 566 560 - #undef uhci_debug_operations 561 567 static const struct file_operations uhci_debug_operations = { 562 568 .owner = THIS_MODULE, 563 569 .open = uhci_debug_open, ··· 564 572 .read = uhci_debug_read, 565 573 .release = uhci_debug_release, 566 574 }; 575 + #define UHCI_DEBUG_OPS 567 576 568 577 #endif /* CONFIG_DEBUG_FS */ 569 578
+46 -39
drivers/usb/host/uhci-hcd.c
··· 140 140 uhci->rh_state = UHCI_RH_RESET; 141 141 uhci->is_stopped = UHCI_IS_STOPPED; 142 142 uhci_to_hcd(uhci)->state = HC_STATE_HALT; 143 - uhci_to_hcd(uhci)->poll_rh = 0; 143 + clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 144 144 145 145 uhci->dead = 0; /* Full reset resurrects the controller */ 146 146 } ··· 176 176 */ 177 177 static void configure_hc(struct uhci_hcd *uhci) 178 178 { 179 + struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci)); 180 + 179 181 /* Set the frame length to the default: 1 ms exactly */ 180 182 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 181 183 ··· 193 191 mb(); 194 192 195 193 /* Enable PIRQ */ 196 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 197 - USBLEGSUP_DEFAULT); 194 + pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT); 195 + 196 + /* Disable platform-specific non-PME# wakeup */ 197 + if (pdev->vendor == PCI_VENDOR_ID_INTEL) 198 + pci_write_config_byte(pdev, USBRES_INTEL, 0); 198 199 } 199 200 200 201 ··· 349 344 /* If interrupts don't work and remote wakeup is enabled then 350 345 * the suspended root hub needs to be polled. 351 346 */ 352 - uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable); 347 + if (!int_enable && wakeup_enable) 348 + set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 349 + else 350 + clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 353 351 354 352 uhci_scan_schedule(uhci); 355 353 uhci_fsbr_off(uhci); ··· 371 363 uhci->io_addr + USBINTR); 372 364 mb(); 373 365 uhci->rh_state = UHCI_RH_RUNNING; 374 - uhci_to_hcd(uhci)->poll_rh = 1; 366 + set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); 375 367 } 376 368 377 369 static void wakeup_rh(struct uhci_hcd *uhci) ··· 597 589 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 598 590 int retval = -EBUSY; 599 591 int i; 600 - struct dentry *dentry; 592 + struct dentry __maybe_unused *dentry; 601 593 602 594 hcd->uses_new_polling = 1; 603 595 ··· 607 599 INIT_LIST_HEAD(&uhci->idle_qh_list); 608 600 init_waitqueue_head(&uhci->waitqh); 609 601 610 - if (DEBUG_CONFIGURED) { 611 - dentry = debugfs_create_file(hcd->self.bus_name, 612 - S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, 613 - uhci, &uhci_debug_operations); 614 - if (!dentry) { 615 - dev_err(uhci_dev(uhci), "couldn't create uhci " 616 - "debugfs entry\n"); 617 - retval = -ENOMEM; 618 - goto err_create_debug_entry; 619 - } 620 - uhci->dentry = dentry; 602 + #ifdef UHCI_DEBUG_OPS 603 + dentry = debugfs_create_file(hcd->self.bus_name, 604 + S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, 605 + uhci, &uhci_debug_operations); 606 + if (!dentry) { 607 + dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n"); 608 + return -ENOMEM; 621 609 } 610 + uhci->dentry = dentry; 611 + #endif 622 612 623 613 uhci->frame = dma_alloc_coherent(uhci_dev(uhci), 624 614 UHCI_NUMFRAMES * sizeof(*uhci->frame), ··· 697 691 698 692 configure_hc(uhci); 699 693 uhci->is_initialized = 1; 694 + spin_lock_irq(&uhci->lock); 700 695 start_rh(uhci); 696 + spin_unlock_irq(&uhci->lock); 701 697 return 0; 702 698 703 699 /* ··· 730 722 err_alloc_frame: 731 723 debugfs_remove(uhci->dentry); 732 724 733 - err_create_debug_entry: 734 725 return retval; 735 726 } 736 727 ··· 738 731 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 739 732 740 733 spin_lock_irq(&uhci->lock); 741 - if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead) 734 + if (HCD_HW_ACCESSIBLE(hcd) && !uhci->dead) 742 735 uhci_hc_died(uhci); 743 736 uhci_scan_schedule(uhci); 744 737 spin_unlock_irq(&uhci->lock); ··· 755 748 int rc = 0; 756 749 757 750 spin_lock_irq(&uhci->lock); 758 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 751 + if (!HCD_HW_ACCESSIBLE(hcd)) 759 752 rc = -ESHUTDOWN; 760 753 else if (uhci->dead) 761 754 ; /* Dead controllers tell no tales */ ··· 782 775 int rc = 0; 783 776 784 777 spin_lock_irq(&uhci->lock); 785 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 778 + if (!HCD_HW_ACCESSIBLE(hcd)) 786 779 rc = -ESHUTDOWN; 787 780 else if (!uhci->dead) 788 781 wakeup_rh(uhci); ··· 790 783 return rc; 791 784 } 792 785 793 - static int uhci_pci_suspend(struct usb_hcd *hcd) 786 + static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 794 787 { 795 788 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 789 + struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci)); 796 790 int rc = 0; 797 791 798 792 dev_dbg(uhci_dev(uhci), "%s\n", __func__); 799 793 800 794 spin_lock_irq(&uhci->lock); 801 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 795 + if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) 802 796 goto done_okay; /* Already suspended or dead */ 803 797 804 798 if (uhci->rh_state > UHCI_RH_SUSPENDED) { ··· 811 803 /* All PCI host controllers are required to disable IRQ generation 812 804 * at the source, so we must turn off PIRQ. 813 805 */ 814 - pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 815 - mb(); 816 - hcd->poll_rh = 0; 806 + pci_write_config_word(pdev, USBLEGSUP, 0); 807 + clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 817 808 818 - /* FIXME: Enable non-PME# remote wakeup? */ 809 + /* Enable platform-specific non-PME# wakeup */ 810 + if (do_wakeup) { 811 + if (pdev->vendor == PCI_VENDOR_ID_INTEL) 812 + pci_write_config_byte(pdev, USBRES_INTEL, 813 + USBPORT1EN | USBPORT2EN); 814 + } 819 815 820 816 done_okay: 821 817 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); ··· 838 826 * even if the controller was dead. 839 827 */ 840 828 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 841 - mb(); 842 829 843 830 spin_lock_irq(&uhci->lock); 844 831 845 832 /* Make sure resume from hibernation re-enumerates everything */ 846 833 if (hibernated) 847 834 uhci_hc_died(uhci); 848 - 849 - /* FIXME: Disable non-PME# remote wakeup? */ 850 835 851 836 /* The firmware or a boot kernel may have changed the controller 852 837 * settings during a system wakeup. Check it and reconfigure ··· 854 845 /* If the controller was dead before, it's back alive now */ 855 846 configure_hc(uhci); 856 847 857 - if (uhci->rh_state == UHCI_RH_RESET) { 858 - 859 - /* The controller had to be reset */ 848 + /* Tell the core if the controller had to be reset */ 849 + if (uhci->rh_state == UHCI_RH_RESET) 860 850 usb_root_hub_lost_power(hcd->self.root_hub); 861 - suspend_rh(uhci, UHCI_RH_SUSPENDED); 862 - } 863 851 864 852 spin_unlock_irq(&uhci->lock); 865 853 866 854 /* If interrupts don't work and remote wakeup is enabled then 867 855 * the suspended root hub needs to be polled. 868 856 */ 869 - if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) { 870 - hcd->poll_rh = 1; 871 - usb_hcd_poll_rh_status(hcd); 872 - } 857 + if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) 858 + set_bit(HCD_FLAG_POLL_RH, &hcd->flags); 859 + 860 + /* Does the root hub have a port wakeup pending? */ 861 + usb_hcd_poll_rh_status(hcd); 873 862 return 0; 874 863 } 875 864 #endif
+6 -1
drivers/usb/host/uhci-hcd.h
··· 67 67 #define USBPORTSC_RES3 0x4000 /* reserved, write zeroes */ 68 68 #define USBPORTSC_RES4 0x8000 /* reserved, write zeroes */ 69 69 70 - /* Legacy support register */ 70 + /* PCI legacy support register */ 71 71 #define USBLEGSUP 0xc0 72 72 #define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 73 73 #define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 74 74 #define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 75 + 76 + /* PCI Intel-specific resume-enable register */ 77 + #define USBRES_INTEL 0xc4 78 + #define USBPORT1EN 0x01 79 + #define USBPORT2EN 0x02 75 80 76 81 #define UHCI_PTR_BITS cpu_to_le32(0x000F) 77 82 #define UHCI_PTR_TERM cpu_to_le32(0x0001)
+3 -3
drivers/usb/host/uhci-hub.c
··· 190 190 spin_lock_irqsave(&uhci->lock, flags); 191 191 192 192 uhci_scan_schedule(uhci); 193 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 193 + if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) 194 194 goto done; 195 195 uhci_check_ports(uhci); 196 196 ··· 200 200 case UHCI_RH_SUSPENDING: 201 201 case UHCI_RH_SUSPENDED: 202 202 /* if port change, ask to be resumed */ 203 - if (status) 203 + if (status || uhci->resuming_ports) 204 204 usb_hcd_resume_root_hub(hcd); 205 205 break; 206 206 ··· 246 246 u16 wPortChange, wPortStatus; 247 247 unsigned long flags; 248 248 249 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 249 + if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead) 250 250 return -ETIMEDOUT; 251 251 252 252 spin_lock_irqsave(&uhci->lock, flags);
+2 -2
drivers/usb/host/uhci-q.c
··· 565 565 qh->unlink_frame = uhci->frame_number; 566 566 567 567 /* Force an interrupt so we know when the QH is fully unlinked */ 568 - if (list_empty(&uhci->skel_unlink_qh->node)) 568 + if (list_empty(&uhci->skel_unlink_qh->node) || uhci->is_stopped) 569 569 uhci_set_next_interrupt(uhci); 570 570 571 571 /* Move the QH from its old list to the end of the unlinking list */ ··· 1667 1667 qh->advance_jiffies = jiffies; 1668 1668 goto done; 1669 1669 } 1670 - ret = 0; 1670 + ret = uhci->is_stopped; 1671 1671 } 1672 1672 1673 1673 /* The queue hasn't advanced; check for timeout */
+1 -1
drivers/usb/host/whci/hcd.c
··· 68 68 whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN); 69 69 70 70 usb_hcd->uses_new_polling = 1; 71 - usb_hcd->poll_rh = 1; 71 + set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags); 72 72 usb_hcd->state = HC_STATE_RUNNING; 73 73 74 74 out:
+1 -1
drivers/usb/host/whci/qset.c
··· 475 475 || (prev_end & (WHCI_PAGE_SIZE-1)) 476 476 || (dma_addr & (WHCI_PAGE_SIZE-1)) 477 477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) { 478 - if (std->len % qset->max_packet != 0) 478 + if (std && std->len % qset->max_packet != 0) 479 479 return -EINVAL; 480 480 std = qset_new_std(whc, qset, urb, mem_flags); 481 481 if (std == NULL) {
+54 -47
drivers/usb/host/xhci-mem.c
··· 391 391 return ep->stream_info->stream_rings[stream_id]; 392 392 } 393 393 394 - struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, 395 - unsigned int slot_id, unsigned int ep_index, 396 - unsigned int stream_id) 397 - { 398 - struct xhci_virt_ep *ep; 399 - 400 - ep = &xhci->devs[slot_id]->eps[ep_index]; 401 - /* Common case: no streams */ 402 - if (!(ep->ep_state & EP_HAS_STREAMS)) 403 - return ep->ring; 404 - 405 - if (stream_id == 0) { 406 - xhci_warn(xhci, 407 - "WARN: Slot ID %u, ep index %u has streams, " 408 - "but URB has no stream ID.\n", 409 - slot_id, ep_index); 410 - return NULL; 411 - } 412 - 413 - if (stream_id < ep->stream_info->num_streams) 414 - return ep->stream_info->stream_rings[stream_id]; 415 - 416 - xhci_warn(xhci, 417 - "WARN: Slot ID %u, ep index %u has " 418 - "stream IDs 1 to %u allocated, " 419 - "but stream ID %u is requested.\n", 420 - slot_id, ep_index, 421 - ep->stream_info->num_streams - 1, 422 - stream_id); 423 - return NULL; 424 - } 425 - 426 - /* Get the right ring for the given URB. 427 - * If the endpoint supports streams, boundary check the URB's stream ID. 428 - * If the endpoint doesn't support streams, return the singular endpoint ring. 429 - */ 430 - struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, 431 - struct urb *urb) 432 - { 433 - return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id, 434 - xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id); 435 - } 436 - 437 394 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 438 395 static int xhci_test_radix_tree(struct xhci_hcd *xhci, 439 396 unsigned int num_streams, ··· 1069 1112 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 1070 1113 1071 1114 /* Set up the endpoint ring */ 1072 - virt_dev->eps[ep_index].new_ring = 1073 - xhci_ring_alloc(xhci, 1, true, mem_flags); 1115 + /* 1116 + * Isochronous endpoint ring needs bigger size because one isoc URB 1117 + * carries multiple packets and it will insert multiple tds to the 1118 + * ring. 1119 + * This should be replaced with dynamic ring resizing in the future. 1120 + */ 1121 + if (usb_endpoint_xfer_isoc(&ep->desc)) 1122 + virt_dev->eps[ep_index].new_ring = 1123 + xhci_ring_alloc(xhci, 8, true, mem_flags); 1124 + else 1125 + virt_dev->eps[ep_index].new_ring = 1126 + xhci_ring_alloc(xhci, 1, true, mem_flags); 1074 1127 if (!virt_dev->eps[ep_index].new_ring) { 1075 1128 /* Attempt to use the ring cache */ 1076 1129 if (virt_dev->num_rings_cached == 0) ··· 1091 1124 virt_dev->num_rings_cached--; 1092 1125 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring); 1093 1126 } 1127 + virt_dev->eps[ep_index].skip = false; 1094 1128 ep_ring = virt_dev->eps[ep_index].new_ring; 1095 1129 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 1096 1130 ··· 1357 1389 return command; 1358 1390 } 1359 1391 1392 + void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv) 1393 + { 1394 + int last; 1395 + 1396 + if (!urb_priv) 1397 + return; 1398 + 1399 + last = urb_priv->length - 1; 1400 + if (last >= 0) { 1401 + int i; 1402 + for (i = 0; i <= last; i++) 1403 + kfree(urb_priv->td[i]); 1404 + } 1405 + kfree(urb_priv); 1406 + } 1407 + 1360 1408 void xhci_free_command(struct xhci_hcd *xhci, 1361 1409 struct xhci_command *command) 1362 1410 { ··· 1572 1588 unsigned int num_tests; 1573 1589 int i, ret; 1574 1590 1575 - num_tests = sizeof(simple_test_vector) / sizeof(simple_test_vector[0]); 1591 + num_tests = ARRAY_SIZE(simple_test_vector); 1576 1592 for (i = 0; i < num_tests; i++) { 1577 1593 ret = xhci_test_trb_in_td(xhci, 1578 1594 xhci->event_ring->first_seg, ··· 1585 1601 return ret; 1586 1602 } 1587 1603 1588 - num_tests = sizeof(complex_test_vector) / sizeof(complex_test_vector[0]); 1604 + num_tests = ARRAY_SIZE(complex_test_vector); 1589 1605 for (i = 0; i < num_tests; i++) { 1590 1606 ret = xhci_test_trb_in_td(xhci, 1591 1607 complex_test_vector[i].input_seg, ··· 1599 1615 } 1600 1616 xhci_dbg(xhci, "TRB math tests passed.\n"); 1601 1617 return 0; 1618 + } 1619 + 1620 + static void xhci_set_hc_event_deq(struct xhci_hcd *xhci) 1621 + { 1622 + u64 temp; 1623 + dma_addr_t deq; 1624 + 1625 + deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, 1626 + xhci->event_ring->dequeue); 1627 + if (deq == 0 && !in_interrupt()) 1628 + xhci_warn(xhci, "WARN something wrong with SW event ring " 1629 + "dequeue ptr.\n"); 1630 + /* Update HC event ring dequeue pointer */ 1631 + temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 1632 + temp &= ERST_PTR_MASK; 1633 + /* Don't clear the EHB bit (which is RW1C) because 1634 + * there might be more events to service. 1635 + */ 1636 + temp &= ~ERST_EHB; 1637 + xhci_dbg(xhci, "// Write event ring dequeue pointer, " 1638 + "preserving EHB bit\n"); 1639 + xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, 1640 + &xhci->ir_set->erst_dequeue); 1602 1641 } 1603 1642 1604 1643
+9
drivers/usb/host/xhci-pci.c
··· 53 53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 54 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 55 55 int retval; 56 + u32 temp; 56 57 57 58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 58 59 ··· 93 92 if (retval) 94 93 return retval; 95 94 xhci_dbg(xhci, "Reset complete\n"); 95 + 96 + temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 97 + if (HCC_64BIT_ADDR(temp)) { 98 + xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); 99 + dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); 100 + } else { 101 + dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); 102 + } 96 103 97 104 xhci_dbg(xhci, "Calling HCD init\n"); 98 105 /* Initialize HCD and host controller data structures. */
+989 -353
drivers/usb/host/xhci-ring.c
··· 301 301 return 1; 302 302 } 303 303 304 - void xhci_set_hc_event_deq(struct xhci_hcd *xhci) 305 - { 306 - u64 temp; 307 - dma_addr_t deq; 308 - 309 - deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, 310 - xhci->event_ring->dequeue); 311 - if (deq == 0 && !in_interrupt()) 312 - xhci_warn(xhci, "WARN something wrong with SW event ring " 313 - "dequeue ptr.\n"); 314 - /* Update HC event ring dequeue pointer */ 315 - temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 316 - temp &= ERST_PTR_MASK; 317 - /* Don't clear the EHB bit (which is RW1C) because 318 - * there might be more events to service. 319 - */ 320 - temp &= ~ERST_EHB; 321 - xhci_dbg(xhci, "// Write event ring dequeue pointer, preserving EHB bit\n"); 322 - xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp, 323 - &xhci->ir_set->erst_dequeue); 324 - } 325 - 326 304 /* Ring the host controller doorbell after placing a command on the ring */ 327 305 void xhci_ring_cmd_db(struct xhci_hcd *xhci) 328 306 { ··· 337 359 field = xhci_readl(xhci, db_addr) & DB_MASK; 338 360 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id); 339 361 xhci_writel(xhci, field, db_addr); 340 - /* Flush PCI posted writes - FIXME Matthew Wilcox says this 341 - * isn't time-critical and we shouldn't make the CPU wait for 342 - * the flush. 343 - */ 344 - xhci_readl(xhci, db_addr); 345 362 } 346 363 } 347 364 ··· 390 417 return NULL; 391 418 } 392 419 return cur_seg; 420 + } 421 + 422 + 423 + static struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, 424 + unsigned int slot_id, unsigned int ep_index, 425 + unsigned int stream_id) 426 + { 427 + struct xhci_virt_ep *ep; 428 + 429 + ep = &xhci->devs[slot_id]->eps[ep_index]; 430 + /* Common case: no streams */ 431 + if (!(ep->ep_state & EP_HAS_STREAMS)) 432 + return ep->ring; 433 + 434 + if (stream_id == 0) { 435 + xhci_warn(xhci, 436 + "WARN: Slot ID %u, ep index %u has streams, " 437 + "but URB has no stream ID.\n", 438 + slot_id, ep_index); 439 + return NULL; 440 + } 441 + 442 + if (stream_id < ep->stream_info->num_streams) 443 + return ep->stream_info->stream_rings[stream_id]; 444 + 445 + xhci_warn(xhci, 446 + "WARN: Slot ID %u, ep index %u has " 447 + "stream IDs 1 to %u allocated, " 448 + "but stream ID %u is requested.\n", 449 + slot_id, ep_index, 450 + ep->stream_info->num_streams - 1, 451 + stream_id); 452 + return NULL; 453 + } 454 + 455 + /* Get the right ring for the given URB. 456 + * If the endpoint supports streams, boundary check the URB's stream ID. 457 + * If the endpoint doesn't support streams, return the singular endpoint ring. 458 + */ 459 + static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, 460 + struct urb *urb) 461 + { 462 + return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id, 463 + xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id); 393 464 } 394 465 395 466 /* ··· 595 578 struct xhci_td *cur_td, int status, char *adjective) 596 579 { 597 580 struct usb_hcd *hcd = xhci_to_hcd(xhci); 581 + struct urb *urb; 582 + struct urb_priv *urb_priv; 598 583 599 - cur_td->urb->hcpriv = NULL; 600 - usb_hcd_unlink_urb_from_ep(hcd, cur_td->urb); 601 - xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, cur_td->urb); 584 + urb = cur_td->urb; 585 + urb_priv = urb->hcpriv; 586 + urb_priv->td_cnt++; 602 587 603 - spin_unlock(&xhci->lock); 604 - usb_hcd_giveback_urb(hcd, cur_td->urb, status); 605 - kfree(cur_td); 606 - spin_lock(&xhci->lock); 607 - xhci_dbg(xhci, "%s URB given back\n", adjective); 588 + /* Only giveback urb when this is the last td in urb */ 589 + if (urb_priv->td_cnt == urb_priv->length) { 590 + usb_hcd_unlink_urb_from_ep(hcd, urb); 591 + xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb); 592 + 593 + spin_unlock(&xhci->lock); 594 + usb_hcd_giveback_urb(hcd, urb, status); 595 + xhci_urb_free_priv(xhci, urb_priv); 596 + spin_lock(&xhci->lock); 597 + xhci_dbg(xhci, "%s URB given back\n", adjective); 598 + } 608 599 } 609 600 610 601 /* ··· 1157 1132 1158 1133 /* Update event ring dequeue pointer before dropping the lock */ 1159 1134 inc_deq(xhci, xhci->event_ring, true); 1160 - xhci_set_hc_event_deq(xhci); 1161 1135 1162 1136 spin_unlock(&xhci->lock); 1163 1137 /* Pass this up to the core */ ··· 1282 1258 } 1283 1259 1284 1260 /* 1261 + * Finish the td processing, remove the td from td list; 1262 + * Return 1 if the urb can be given back. 1263 + */ 1264 + static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, 1265 + union xhci_trb *event_trb, struct xhci_transfer_event *event, 1266 + struct xhci_virt_ep *ep, int *status, bool skip) 1267 + { 1268 + struct xhci_virt_device *xdev; 1269 + struct xhci_ring *ep_ring; 1270 + unsigned int slot_id; 1271 + int ep_index; 1272 + struct urb *urb = NULL; 1273 + struct xhci_ep_ctx *ep_ctx; 1274 + int ret = 0; 1275 + struct urb_priv *urb_priv; 1276 + u32 trb_comp_code; 1277 + 1278 + slot_id = TRB_TO_SLOT_ID(event->flags); 1279 + xdev = xhci->devs[slot_id]; 1280 + ep_index = TRB_TO_EP_ID(event->flags) - 1; 1281 + ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1282 + ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1283 + trb_comp_code = GET_COMP_CODE(event->transfer_len); 1284 + 1285 + if (skip) 1286 + goto td_cleanup; 1287 + 1288 + if (trb_comp_code == COMP_STOP_INVAL || 1289 + trb_comp_code == COMP_STOP) { 1290 + /* The Endpoint Stop Command completion will take care of any 1291 + * stopped TDs. A stopped TD may be restarted, so don't update 1292 + * the ring dequeue pointer or take this TD off any lists yet. 1293 + */ 1294 + ep->stopped_td = td; 1295 + ep->stopped_trb = event_trb; 1296 + return 0; 1297 + } else { 1298 + if (trb_comp_code == COMP_STALL) { 1299 + /* The transfer is completed from the driver's 1300 + * perspective, but we need to issue a set dequeue 1301 + * command for this stalled endpoint to move the dequeue 1302 + * pointer past the TD. We can't do that here because 1303 + * the halt condition must be cleared first. Let the 1304 + * USB class driver clear the stall later. 1305 + */ 1306 + ep->stopped_td = td; 1307 + ep->stopped_trb = event_trb; 1308 + ep->stopped_stream = ep_ring->stream_id; 1309 + } else if (xhci_requires_manual_halt_cleanup(xhci, 1310 + ep_ctx, trb_comp_code)) { 1311 + /* Other types of errors halt the endpoint, but the 1312 + * class driver doesn't call usb_reset_endpoint() unless 1313 + * the error is -EPIPE. Clear the halted status in the 1314 + * xHCI hardware manually. 1315 + */ 1316 + xhci_cleanup_halted_endpoint(xhci, 1317 + slot_id, ep_index, ep_ring->stream_id, 1318 + td, event_trb); 1319 + } else { 1320 + /* Update ring dequeue pointer */ 1321 + while (ep_ring->dequeue != td->last_trb) 1322 + inc_deq(xhci, ep_ring, false); 1323 + inc_deq(xhci, ep_ring, false); 1324 + } 1325 + 1326 + td_cleanup: 1327 + /* Clean up the endpoint's TD list */ 1328 + urb = td->urb; 1329 + urb_priv = urb->hcpriv; 1330 + 1331 + /* Do one last check of the actual transfer length. 1332 + * If the host controller said we transferred more data than 1333 + * the buffer length, urb->actual_length will be a very big 1334 + * number (since it's unsigned). Play it safe and say we didn't 1335 + * transfer anything. 1336 + */ 1337 + if (urb->actual_length > urb->transfer_buffer_length) { 1338 + xhci_warn(xhci, "URB transfer length is wrong, " 1339 + "xHC issue? req. len = %u, " 1340 + "act. len = %u\n", 1341 + urb->transfer_buffer_length, 1342 + urb->actual_length); 1343 + urb->actual_length = 0; 1344 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1345 + *status = -EREMOTEIO; 1346 + else 1347 + *status = 0; 1348 + } 1349 + list_del(&td->td_list); 1350 + /* Was this TD slated to be cancelled but completed anyway? */ 1351 + if (!list_empty(&td->cancelled_td_list)) 1352 + list_del(&td->cancelled_td_list); 1353 + 1354 + urb_priv->td_cnt++; 1355 + /* Giveback the urb when all the tds are completed */ 1356 + if (urb_priv->td_cnt == urb_priv->length) 1357 + ret = 1; 1358 + } 1359 + 1360 + return ret; 1361 + } 1362 + 1363 + /* 1364 + * Process control tds, update urb status and actual_length. 1365 + */ 1366 + static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td, 1367 + union xhci_trb *event_trb, struct xhci_transfer_event *event, 1368 + struct xhci_virt_ep *ep, int *status) 1369 + { 1370 + struct xhci_virt_device *xdev; 1371 + struct xhci_ring *ep_ring; 1372 + unsigned int slot_id; 1373 + int ep_index; 1374 + struct xhci_ep_ctx *ep_ctx; 1375 + u32 trb_comp_code; 1376 + 1377 + slot_id = TRB_TO_SLOT_ID(event->flags); 1378 + xdev = xhci->devs[slot_id]; 1379 + ep_index = TRB_TO_EP_ID(event->flags) - 1; 1380 + ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1381 + ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1382 + trb_comp_code = GET_COMP_CODE(event->transfer_len); 1383 + 1384 + xhci_debug_trb(xhci, xhci->event_ring->dequeue); 1385 + switch (trb_comp_code) { 1386 + case COMP_SUCCESS: 1387 + if (event_trb == ep_ring->dequeue) { 1388 + xhci_warn(xhci, "WARN: Success on ctrl setup TRB " 1389 + "without IOC set??\n"); 1390 + *status = -ESHUTDOWN; 1391 + } else if (event_trb != td->last_trb) { 1392 + xhci_warn(xhci, "WARN: Success on ctrl data TRB " 1393 + "without IOC set??\n"); 1394 + *status = -ESHUTDOWN; 1395 + } else { 1396 + xhci_dbg(xhci, "Successful control transfer!\n"); 1397 + *status = 0; 1398 + } 1399 + break; 1400 + case COMP_SHORT_TX: 1401 + xhci_warn(xhci, "WARN: short transfer on control ep\n"); 1402 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1403 + *status = -EREMOTEIO; 1404 + else 1405 + *status = 0; 1406 + break; 1407 + default: 1408 + if (!xhci_requires_manual_halt_cleanup(xhci, 1409 + ep_ctx, trb_comp_code)) 1410 + break; 1411 + xhci_dbg(xhci, "TRB error code %u, " 1412 + "halted endpoint index = %u\n", 1413 + trb_comp_code, ep_index); 1414 + /* else fall through */ 1415 + case COMP_STALL: 1416 + /* Did we transfer part of the data (middle) phase? */ 1417 + if (event_trb != ep_ring->dequeue && 1418 + event_trb != td->last_trb) 1419 + td->urb->actual_length = 1420 + td->urb->transfer_buffer_length 1421 + - TRB_LEN(event->transfer_len); 1422 + else 1423 + td->urb->actual_length = 0; 1424 + 1425 + xhci_cleanup_halted_endpoint(xhci, 1426 + slot_id, ep_index, 0, td, event_trb); 1427 + return finish_td(xhci, td, event_trb, event, ep, status, true); 1428 + } 1429 + /* 1430 + * Did we transfer any data, despite the errors that might have 1431 + * happened? I.e. did we get past the setup stage? 1432 + */ 1433 + if (event_trb != ep_ring->dequeue) { 1434 + /* The event was for the status stage */ 1435 + if (event_trb == td->last_trb) { 1436 + if (td->urb->actual_length != 0) { 1437 + /* Don't overwrite a previously set error code 1438 + */ 1439 + if ((*status == -EINPROGRESS || *status == 0) && 1440 + (td->urb->transfer_flags 1441 + & URB_SHORT_NOT_OK)) 1442 + /* Did we already see a short data 1443 + * stage? */ 1444 + *status = -EREMOTEIO; 1445 + } else { 1446 + td->urb->actual_length = 1447 + td->urb->transfer_buffer_length; 1448 + } 1449 + } else { 1450 + /* Maybe the event was for the data stage? */ 1451 + if (trb_comp_code != COMP_STOP_INVAL) { 1452 + /* We didn't stop on a link TRB in the middle */ 1453 + td->urb->actual_length = 1454 + td->urb->transfer_buffer_length - 1455 + TRB_LEN(event->transfer_len); 1456 + xhci_dbg(xhci, "Waiting for status " 1457 + "stage event\n"); 1458 + return 0; 1459 + } 1460 + } 1461 + } 1462 + 1463 + return finish_td(xhci, td, event_trb, event, ep, status, false); 1464 + } 1465 + 1466 + /* 1467 + * Process isochronous tds, update urb packet status and actual_length. 1468 + */ 1469 + static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, 1470 + union xhci_trb *event_trb, struct xhci_transfer_event *event, 1471 + struct xhci_virt_ep *ep, int *status) 1472 + { 1473 + struct xhci_ring *ep_ring; 1474 + struct urb_priv *urb_priv; 1475 + int idx; 1476 + int len = 0; 1477 + int skip_td = 0; 1478 + union xhci_trb *cur_trb; 1479 + struct xhci_segment *cur_seg; 1480 + u32 trb_comp_code; 1481 + 1482 + ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1483 + trb_comp_code = GET_COMP_CODE(event->transfer_len); 1484 + urb_priv = td->urb->hcpriv; 1485 + idx = urb_priv->td_cnt; 1486 + 1487 + if (ep->skip) { 1488 + /* The transfer is partly done */ 1489 + *status = -EXDEV; 1490 + td->urb->iso_frame_desc[idx].status = -EXDEV; 1491 + } else { 1492 + /* handle completion code */ 1493 + switch (trb_comp_code) { 1494 + case COMP_SUCCESS: 1495 + td->urb->iso_frame_desc[idx].status = 0; 1496 + xhci_dbg(xhci, "Successful isoc transfer!\n"); 1497 + break; 1498 + case COMP_SHORT_TX: 1499 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1500 + td->urb->iso_frame_desc[idx].status = 1501 + -EREMOTEIO; 1502 + else 1503 + td->urb->iso_frame_desc[idx].status = 0; 1504 + break; 1505 + case COMP_BW_OVER: 1506 + td->urb->iso_frame_desc[idx].status = -ECOMM; 1507 + skip_td = 1; 1508 + break; 1509 + case COMP_BUFF_OVER: 1510 + case COMP_BABBLE: 1511 + td->urb->iso_frame_desc[idx].status = -EOVERFLOW; 1512 + skip_td = 1; 1513 + break; 1514 + case COMP_STALL: 1515 + td->urb->iso_frame_desc[idx].status = -EPROTO; 1516 + skip_td = 1; 1517 + break; 1518 + case COMP_STOP: 1519 + case COMP_STOP_INVAL: 1520 + break; 1521 + default: 1522 + td->urb->iso_frame_desc[idx].status = -1; 1523 + break; 1524 + } 1525 + } 1526 + 1527 + /* calc actual length */ 1528 + if (ep->skip) { 1529 + td->urb->iso_frame_desc[idx].actual_length = 0; 1530 + return finish_td(xhci, td, event_trb, event, ep, status, true); 1531 + } 1532 + 1533 + if (trb_comp_code == COMP_SUCCESS || skip_td == 1) { 1534 + td->urb->iso_frame_desc[idx].actual_length = 1535 + td->urb->iso_frame_desc[idx].length; 1536 + td->urb->actual_length += 1537 + td->urb->iso_frame_desc[idx].length; 1538 + } else { 1539 + for (cur_trb = ep_ring->dequeue, 1540 + cur_seg = ep_ring->deq_seg; cur_trb != event_trb; 1541 + next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1542 + if ((cur_trb->generic.field[3] & 1543 + TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1544 + (cur_trb->generic.field[3] & 1545 + TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1546 + len += 1547 + TRB_LEN(cur_trb->generic.field[2]); 1548 + } 1549 + len += TRB_LEN(cur_trb->generic.field[2]) - 1550 + TRB_LEN(event->transfer_len); 1551 + 1552 + if (trb_comp_code != COMP_STOP_INVAL) { 1553 + td->urb->iso_frame_desc[idx].actual_length = len; 1554 + td->urb->actual_length += len; 1555 + } 1556 + } 1557 + 1558 + if ((idx == urb_priv->length - 1) && *status == -EINPROGRESS) 1559 + *status = 0; 1560 + 1561 + return finish_td(xhci, td, event_trb, event, ep, status, false); 1562 + } 1563 + 1564 + /* 1565 + * Process bulk and interrupt tds, update urb status and actual_length. 1566 + */ 1567 + static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td, 1568 + union xhci_trb *event_trb, struct xhci_transfer_event *event, 1569 + struct xhci_virt_ep *ep, int *status) 1570 + { 1571 + struct xhci_ring *ep_ring; 1572 + union xhci_trb *cur_trb; 1573 + struct xhci_segment *cur_seg; 1574 + u32 trb_comp_code; 1575 + 1576 + ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1577 + trb_comp_code = GET_COMP_CODE(event->transfer_len); 1578 + 1579 + switch (trb_comp_code) { 1580 + case COMP_SUCCESS: 1581 + /* Double check that the HW transferred everything. */ 1582 + if (event_trb != td->last_trb) { 1583 + xhci_warn(xhci, "WARN Successful completion " 1584 + "on short TX\n"); 1585 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1586 + *status = -EREMOTEIO; 1587 + else 1588 + *status = 0; 1589 + } else { 1590 + if (usb_endpoint_xfer_bulk(&td->urb->ep->desc)) 1591 + xhci_dbg(xhci, "Successful bulk " 1592 + "transfer!\n"); 1593 + else 1594 + xhci_dbg(xhci, "Successful interrupt " 1595 + "transfer!\n"); 1596 + *status = 0; 1597 + } 1598 + break; 1599 + case COMP_SHORT_TX: 1600 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1601 + *status = -EREMOTEIO; 1602 + else 1603 + *status = 0; 1604 + break; 1605 + default: 1606 + /* Others already handled above */ 1607 + break; 1608 + } 1609 + dev_dbg(&td->urb->dev->dev, 1610 + "ep %#x - asked for %d bytes, " 1611 + "%d bytes untransferred\n", 1612 + td->urb->ep->desc.bEndpointAddress, 1613 + td->urb->transfer_buffer_length, 1614 + TRB_LEN(event->transfer_len)); 1615 + /* Fast path - was this the last TRB in the TD for this URB? */ 1616 + if (event_trb == td->last_trb) { 1617 + if (TRB_LEN(event->transfer_len) != 0) { 1618 + td->urb->actual_length = 1619 + td->urb->transfer_buffer_length - 1620 + TRB_LEN(event->transfer_len); 1621 + if (td->urb->transfer_buffer_length < 1622 + td->urb->actual_length) { 1623 + xhci_warn(xhci, "HC gave bad length " 1624 + "of %d bytes left\n", 1625 + TRB_LEN(event->transfer_len)); 1626 + td->urb->actual_length = 0; 1627 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1628 + *status = -EREMOTEIO; 1629 + else 1630 + *status = 0; 1631 + } 1632 + /* Don't overwrite a previously set error code */ 1633 + if (*status == -EINPROGRESS) { 1634 + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1635 + *status = -EREMOTEIO; 1636 + else 1637 + *status = 0; 1638 + } 1639 + } else { 1640 + td->urb->actual_length = 1641 + td->urb->transfer_buffer_length; 1642 + /* Ignore a short packet completion if the 1643 + * untransferred length was zero. 1644 + */ 1645 + if (*status == -EREMOTEIO) 1646 + *status = 0; 1647 + } 1648 + } else { 1649 + /* Slow path - walk the list, starting from the dequeue 1650 + * pointer, to get the actual length transferred. 1651 + */ 1652 + td->urb->actual_length = 0; 1653 + for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1654 + cur_trb != event_trb; 1655 + next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1656 + if ((cur_trb->generic.field[3] & 1657 + TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1658 + (cur_trb->generic.field[3] & 1659 + TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1660 + td->urb->actual_length += 1661 + TRB_LEN(cur_trb->generic.field[2]); 1662 + } 1663 + /* If the ring didn't stop on a Link or No-op TRB, add 1664 + * in the actual bytes transferred from the Normal TRB 1665 + */ 1666 + if (trb_comp_code != COMP_STOP_INVAL) 1667 + td->urb->actual_length += 1668 + TRB_LEN(cur_trb->generic.field[2]) - 1669 + TRB_LEN(event->transfer_len); 1670 + } 1671 + 1672 + return finish_td(xhci, td, event_trb, event, ep, status, false); 1673 + } 1674 + 1675 + /* 1285 1676 * If this function returns an error condition, it means it got a Transfer 1286 1677 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. 1287 1678 * At this point, the host controller is probably hosed and should be reset. ··· 1715 1276 union xhci_trb *event_trb; 1716 1277 struct urb *urb = NULL; 1717 1278 int status = -EINPROGRESS; 1279 + struct urb_priv *urb_priv; 1718 1280 struct xhci_ep_ctx *ep_ctx; 1719 1281 u32 trb_comp_code; 1282 + int ret = 0; 1720 1283 1721 - xhci_dbg(xhci, "In %s\n", __func__); 1722 1284 slot_id = TRB_TO_SLOT_ID(event->flags); 1723 1285 xdev = xhci->devs[slot_id]; 1724 1286 if (!xdev) { ··· 1733 1293 ep = &xdev->eps[ep_index]; 1734 1294 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1735 1295 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1736 - if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1296 + if (!ep_ring || 1297 + (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1737 1298 xhci_err(xhci, "ERROR Transfer event for disabled endpoint " 1738 1299 "or incorrect stream ring\n"); 1739 1300 return -ENODEV; 1740 1301 } 1741 1302 1742 1303 event_dma = event->buffer; 1743 - /* This TRB should be in the TD at the head of this ring's TD list */ 1744 - xhci_dbg(xhci, "%s - checking for list empty\n", __func__); 1745 - if (list_empty(&ep_ring->td_list)) { 1746 - xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n", 1747 - TRB_TO_SLOT_ID(event->flags), ep_index); 1748 - xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 1749 - (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10); 1750 - xhci_print_trb_offsets(xhci, (union xhci_trb *) event); 1751 - urb = NULL; 1752 - goto cleanup; 1753 - } 1754 - xhci_dbg(xhci, "%s - getting list entry\n", __func__); 1755 - td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); 1756 - 1757 - /* Is this a TRB in the currently executing TD? */ 1758 - xhci_dbg(xhci, "%s - looking for TD\n", __func__); 1759 - event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, 1760 - td->last_trb, event_dma); 1761 - xhci_dbg(xhci, "%s - found event_seg = %p\n", __func__, event_seg); 1762 - if (!event_seg) { 1763 - /* HC is busted, give up! */ 1764 - xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not part of current TD\n"); 1765 - return -ESHUTDOWN; 1766 - } 1767 - event_trb = &event_seg->trbs[(event_dma - event_seg->dma) / sizeof(*event_trb)]; 1768 - xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 1769 - (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10); 1770 - xhci_dbg(xhci, "Offset 0x00 (buffer lo) = 0x%x\n", 1771 - lower_32_bits(event->buffer)); 1772 - xhci_dbg(xhci, "Offset 0x04 (buffer hi) = 0x%x\n", 1773 - upper_32_bits(event->buffer)); 1774 - xhci_dbg(xhci, "Offset 0x08 (transfer length) = 0x%x\n", 1775 - (unsigned int) event->transfer_len); 1776 - xhci_dbg(xhci, "Offset 0x0C (flags) = 0x%x\n", 1777 - (unsigned int) event->flags); 1778 - 1779 - /* Look for common error cases */ 1780 1304 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1305 + /* Look for common error cases */ 1781 1306 switch (trb_comp_code) { 1782 1307 /* Skip codes that require special handling depending on 1783 1308 * transfer type ··· 1778 1373 xhci_warn(xhci, "WARN: HC couldn't access mem fast enough\n"); 1779 1374 status = -ENOSR; 1780 1375 break; 1376 + case COMP_BW_OVER: 1377 + xhci_warn(xhci, "WARN: bandwidth overrun event on endpoint\n"); 1378 + break; 1379 + case COMP_BUFF_OVER: 1380 + xhci_warn(xhci, "WARN: buffer overrun event on endpoint\n"); 1381 + break; 1382 + case COMP_UNDERRUN: 1383 + /* 1384 + * When the Isoch ring is empty, the xHC will generate 1385 + * a Ring Overrun Event for IN Isoch endpoint or Ring 1386 + * Underrun Event for OUT Isoch endpoint. 1387 + */ 1388 + xhci_dbg(xhci, "underrun event on endpoint\n"); 1389 + if (!list_empty(&ep_ring->td_list)) 1390 + xhci_dbg(xhci, "Underrun Event for slot %d ep %d " 1391 + "still with TDs queued?\n", 1392 + TRB_TO_SLOT_ID(event->flags), ep_index); 1393 + goto cleanup; 1394 + case COMP_OVERRUN: 1395 + xhci_dbg(xhci, "overrun event on endpoint\n"); 1396 + if (!list_empty(&ep_ring->td_list)) 1397 + xhci_dbg(xhci, "Overrun Event for slot %d ep %d " 1398 + "still with TDs queued?\n", 1399 + TRB_TO_SLOT_ID(event->flags), ep_index); 1400 + goto cleanup; 1401 + case COMP_MISSED_INT: 1402 + /* 1403 + * When encounter missed service error, one or more isoc tds 1404 + * may be missed by xHC. 1405 + * Set skip flag of the ep_ring; Complete the missed tds as 1406 + * short transfer when process the ep_ring next time. 1407 + */ 1408 + ep->skip = true; 1409 + xhci_dbg(xhci, "Miss service interval error, set skip flag\n"); 1410 + goto cleanup; 1781 1411 default: 1782 1412 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { 1783 1413 status = 0; 1784 1414 break; 1785 1415 } 1786 - xhci_warn(xhci, "ERROR Unknown event condition, HC probably busted\n"); 1787 - urb = NULL; 1416 + xhci_warn(xhci, "ERROR Unknown event condition, HC probably " 1417 + "busted\n"); 1788 1418 goto cleanup; 1789 1419 } 1790 - /* Now update the urb's actual_length and give back to the core */ 1791 - /* Was this a control transfer? */ 1792 - if (usb_endpoint_xfer_control(&td->urb->ep->desc)) { 1793 - xhci_debug_trb(xhci, xhci->event_ring->dequeue); 1794 - switch (trb_comp_code) { 1795 - case COMP_SUCCESS: 1796 - if (event_trb == ep_ring->dequeue) { 1797 - xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n"); 1798 - status = -ESHUTDOWN; 1799 - } else if (event_trb != td->last_trb) { 1800 - xhci_warn(xhci, "WARN: Success on ctrl data TRB without IOC set??\n"); 1801 - status = -ESHUTDOWN; 1802 - } else { 1803 - xhci_dbg(xhci, "Successful control transfer!\n"); 1804 - status = 0; 1805 - } 1806 - break; 1807 - case COMP_SHORT_TX: 1808 - xhci_warn(xhci, "WARN: short transfer on control ep\n"); 1809 - if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1810 - status = -EREMOTEIO; 1811 - else 1812 - status = 0; 1813 - break; 1814 1420 1815 - default: 1816 - if (!xhci_requires_manual_halt_cleanup(xhci, 1817 - ep_ctx, trb_comp_code)) 1818 - break; 1819 - xhci_dbg(xhci, "TRB error code %u, " 1820 - "halted endpoint index = %u\n", 1821 - trb_comp_code, ep_index); 1822 - /* else fall through */ 1823 - case COMP_STALL: 1824 - /* Did we transfer part of the data (middle) phase? */ 1825 - if (event_trb != ep_ring->dequeue && 1826 - event_trb != td->last_trb) 1827 - td->urb->actual_length = 1828 - td->urb->transfer_buffer_length 1829 - - TRB_LEN(event->transfer_len); 1830 - else 1831 - td->urb->actual_length = 0; 1832 - 1833 - xhci_cleanup_halted_endpoint(xhci, 1834 - slot_id, ep_index, 0, td, event_trb); 1835 - goto td_cleanup; 1836 - } 1837 - /* 1838 - * Did we transfer any data, despite the errors that might have 1839 - * happened? I.e. did we get past the setup stage? 1421 + do { 1422 + /* This TRB should be in the TD at the head of this ring's 1423 + * TD list. 1840 1424 */ 1841 - if (event_trb != ep_ring->dequeue) { 1842 - /* The event was for the status stage */ 1843 - if (event_trb == td->last_trb) { 1844 - if (td->urb->actual_length != 0) { 1845 - /* Don't overwrite a previously set error code */ 1846 - if ((status == -EINPROGRESS || 1847 - status == 0) && 1848 - (td->urb->transfer_flags 1849 - & URB_SHORT_NOT_OK)) 1850 - /* Did we already see a short data stage? */ 1851 - status = -EREMOTEIO; 1852 - } else { 1853 - td->urb->actual_length = 1854 - td->urb->transfer_buffer_length; 1855 - } 1856 - } else { 1857 - /* Maybe the event was for the data stage? */ 1858 - if (trb_comp_code != COMP_STOP_INVAL) { 1859 - /* We didn't stop on a link TRB in the middle */ 1860 - td->urb->actual_length = 1861 - td->urb->transfer_buffer_length - 1862 - TRB_LEN(event->transfer_len); 1863 - xhci_dbg(xhci, "Waiting for status stage event\n"); 1864 - urb = NULL; 1865 - goto cleanup; 1866 - } 1425 + if (list_empty(&ep_ring->td_list)) { 1426 + xhci_warn(xhci, "WARN Event TRB for slot %d ep %d " 1427 + "with no TDs queued?\n", 1428 + TRB_TO_SLOT_ID(event->flags), ep_index); 1429 + xhci_dbg(xhci, "Event TRB with TRB type ID %u\n", 1430 + (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10); 1431 + xhci_print_trb_offsets(xhci, (union xhci_trb *) event); 1432 + if (ep->skip) { 1433 + ep->skip = false; 1434 + xhci_dbg(xhci, "td_list is empty while skip " 1435 + "flag set. Clear skip flag.\n"); 1867 1436 } 1868 - } 1869 - } else { 1870 - switch (trb_comp_code) { 1871 - case COMP_SUCCESS: 1872 - /* Double check that the HW transferred everything. */ 1873 - if (event_trb != td->last_trb) { 1874 - xhci_warn(xhci, "WARN Successful completion " 1875 - "on short TX\n"); 1876 - if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1877 - status = -EREMOTEIO; 1878 - else 1879 - status = 0; 1880 - } else { 1881 - if (usb_endpoint_xfer_bulk(&td->urb->ep->desc)) 1882 - xhci_dbg(xhci, "Successful bulk " 1883 - "transfer!\n"); 1884 - else 1885 - xhci_dbg(xhci, "Successful interrupt " 1886 - "transfer!\n"); 1887 - status = 0; 1888 - } 1889 - break; 1890 - case COMP_SHORT_TX: 1891 - if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1892 - status = -EREMOTEIO; 1893 - else 1894 - status = 0; 1895 - break; 1896 - default: 1897 - /* Others already handled above */ 1898 - break; 1899 - } 1900 - dev_dbg(&td->urb->dev->dev, 1901 - "ep %#x - asked for %d bytes, " 1902 - "%d bytes untransferred\n", 1903 - td->urb->ep->desc.bEndpointAddress, 1904 - td->urb->transfer_buffer_length, 1905 - TRB_LEN(event->transfer_len)); 1906 - /* Fast path - was this the last TRB in the TD for this URB? */ 1907 - if (event_trb == td->last_trb) { 1908 - if (TRB_LEN(event->transfer_len) != 0) { 1909 - td->urb->actual_length = 1910 - td->urb->transfer_buffer_length - 1911 - TRB_LEN(event->transfer_len); 1912 - if (td->urb->transfer_buffer_length < 1913 - td->urb->actual_length) { 1914 - xhci_warn(xhci, "HC gave bad length " 1915 - "of %d bytes left\n", 1916 - TRB_LEN(event->transfer_len)); 1917 - td->urb->actual_length = 0; 1918 - if (td->urb->transfer_flags & 1919 - URB_SHORT_NOT_OK) 1920 - status = -EREMOTEIO; 1921 - else 1922 - status = 0; 1923 - } 1924 - /* Don't overwrite a previously set error code */ 1925 - if (status == -EINPROGRESS) { 1926 - if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1927 - status = -EREMOTEIO; 1928 - else 1929 - status = 0; 1930 - } 1931 - } else { 1932 - td->urb->actual_length = td->urb->transfer_buffer_length; 1933 - /* Ignore a short packet completion if the 1934 - * untransferred length was zero. 1935 - */ 1936 - if (status == -EREMOTEIO) 1937 - status = 0; 1938 - } 1939 - } else { 1940 - /* Slow path - walk the list, starting from the dequeue 1941 - * pointer, to get the actual length transferred. 1942 - */ 1943 - union xhci_trb *cur_trb; 1944 - struct xhci_segment *cur_seg; 1945 - 1946 - td->urb->actual_length = 0; 1947 - for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1948 - cur_trb != event_trb; 1949 - next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1950 - if ((cur_trb->generic.field[3] & 1951 - TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1952 - (cur_trb->generic.field[3] & 1953 - TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1954 - td->urb->actual_length += 1955 - TRB_LEN(cur_trb->generic.field[2]); 1956 - } 1957 - /* If the ring didn't stop on a Link or No-op TRB, add 1958 - * in the actual bytes transferred from the Normal TRB 1959 - */ 1960 - if (trb_comp_code != COMP_STOP_INVAL) 1961 - td->urb->actual_length += 1962 - TRB_LEN(cur_trb->generic.field[2]) - 1963 - TRB_LEN(event->transfer_len); 1964 - } 1965 - } 1966 - if (trb_comp_code == COMP_STOP_INVAL || 1967 - trb_comp_code == COMP_STOP) { 1968 - /* The Endpoint Stop Command completion will take care of any 1969 - * stopped TDs. A stopped TD may be restarted, so don't update 1970 - * the ring dequeue pointer or take this TD off any lists yet. 1971 - */ 1972 - ep->stopped_td = td; 1973 - ep->stopped_trb = event_trb; 1974 - } else { 1975 - if (trb_comp_code == COMP_STALL) { 1976 - /* The transfer is completed from the driver's 1977 - * perspective, but we need to issue a set dequeue 1978 - * command for this stalled endpoint to move the dequeue 1979 - * pointer past the TD. We can't do that here because 1980 - * the halt condition must be cleared first. Let the 1981 - * USB class driver clear the stall later. 1982 - */ 1983 - ep->stopped_td = td; 1984 - ep->stopped_trb = event_trb; 1985 - ep->stopped_stream = ep_ring->stream_id; 1986 - } else if (xhci_requires_manual_halt_cleanup(xhci, 1987 - ep_ctx, trb_comp_code)) { 1988 - /* Other types of errors halt the endpoint, but the 1989 - * class driver doesn't call usb_reset_endpoint() unless 1990 - * the error is -EPIPE. Clear the halted status in the 1991 - * xHCI hardware manually. 1992 - */ 1993 - xhci_cleanup_halted_endpoint(xhci, 1994 - slot_id, ep_index, ep_ring->stream_id, td, event_trb); 1995 - } else { 1996 - /* Update ring dequeue pointer */ 1997 - while (ep_ring->dequeue != td->last_trb) 1998 - inc_deq(xhci, ep_ring, false); 1999 - inc_deq(xhci, ep_ring, false); 1437 + ret = 0; 1438 + goto cleanup; 2000 1439 } 2001 1440 2002 - td_cleanup: 2003 - /* Clean up the endpoint's TD list */ 2004 - urb = td->urb; 2005 - /* Do one last check of the actual transfer length. 2006 - * If the host controller said we transferred more data than 2007 - * the buffer length, urb->actual_length will be a very big 2008 - * number (since it's unsigned). Play it safe and say we didn't 2009 - * transfer anything. 2010 - */ 2011 - if (urb->actual_length > urb->transfer_buffer_length) { 2012 - xhci_warn(xhci, "URB transfer length is wrong, " 2013 - "xHC issue? req. len = %u, " 2014 - "act. len = %u\n", 2015 - urb->transfer_buffer_length, 2016 - urb->actual_length); 2017 - urb->actual_length = 0; 2018 - if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 2019 - status = -EREMOTEIO; 2020 - else 2021 - status = 0; 1441 + td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); 1442 + /* Is this a TRB in the currently executing TD? */ 1443 + event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, 1444 + td->last_trb, event_dma); 1445 + if (event_seg && ep->skip) { 1446 + xhci_dbg(xhci, "Found td. Clear skip flag.\n"); 1447 + ep->skip = false; 2022 1448 } 2023 - list_del(&td->td_list); 2024 - /* Was this TD slated to be cancelled but completed anyway? */ 2025 - if (!list_empty(&td->cancelled_td_list)) 2026 - list_del(&td->cancelled_td_list); 1449 + if (!event_seg && 1450 + (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) { 1451 + /* HC is busted, give up! */ 1452 + xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not " 1453 + "part of current TD\n"); 1454 + return -ESHUTDOWN; 1455 + } 2027 1456 2028 - /* Leave the TD around for the reset endpoint function to use 2029 - * (but only if it's not a control endpoint, since we already 2030 - * queued the Set TR dequeue pointer command for stalled 2031 - * control endpoints). 2032 - */ 2033 - if (usb_endpoint_xfer_control(&urb->ep->desc) || 2034 - (trb_comp_code != COMP_STALL && 2035 - trb_comp_code != COMP_BABBLE)) { 2036 - kfree(td); 1457 + if (event_seg) { 1458 + event_trb = &event_seg->trbs[(event_dma - 1459 + event_seg->dma) / sizeof(*event_trb)]; 1460 + /* 1461 + * No-op TRB should not trigger interrupts. 1462 + * If event_trb is a no-op TRB, it means the 1463 + * corresponding TD has been cancelled. Just ignore 1464 + * the TD. 1465 + */ 1466 + if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK) 1467 + == TRB_TYPE(TRB_TR_NOOP)) { 1468 + xhci_dbg(xhci, "event_trb is a no-op TRB. " 1469 + "Skip it\n"); 1470 + goto cleanup; 1471 + } 2037 1472 } 2038 - urb->hcpriv = NULL; 2039 - } 1473 + 1474 + /* Now update the urb's actual_length and give back to 1475 + * the core 1476 + */ 1477 + if (usb_endpoint_xfer_control(&td->urb->ep->desc)) 1478 + ret = process_ctrl_td(xhci, td, event_trb, event, ep, 1479 + &status); 1480 + else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc)) 1481 + ret = process_isoc_td(xhci, td, event_trb, event, ep, 1482 + &status); 1483 + else 1484 + ret = process_bulk_intr_td(xhci, td, event_trb, event, 1485 + ep, &status); 1486 + 2040 1487 cleanup: 2041 - inc_deq(xhci, xhci->event_ring, true); 2042 - xhci_set_hc_event_deq(xhci); 1488 + /* 1489 + * Do not update event ring dequeue pointer if ep->skip is set. 1490 + * Will roll back to continue process missed tds. 1491 + */ 1492 + if (trb_comp_code == COMP_MISSED_INT || !ep->skip) { 1493 + inc_deq(xhci, xhci->event_ring, true); 1494 + } 2043 1495 2044 - /* FIXME for multi-TD URBs (who have buffers bigger than 64MB) */ 2045 - if (urb) { 2046 - usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 2047 - xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", 2048 - urb, urb->actual_length, status); 2049 - spin_unlock(&xhci->lock); 2050 - usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 2051 - spin_lock(&xhci->lock); 2052 - } 1496 + if (ret) { 1497 + urb = td->urb; 1498 + urb_priv = urb->hcpriv; 1499 + /* Leave the TD around for the reset endpoint function 1500 + * to use(but only if it's not a control endpoint, 1501 + * since we already queued the Set TR dequeue pointer 1502 + * command for stalled control endpoints). 1503 + */ 1504 + if (usb_endpoint_xfer_control(&urb->ep->desc) || 1505 + (trb_comp_code != COMP_STALL && 1506 + trb_comp_code != COMP_BABBLE)) 1507 + xhci_urb_free_priv(xhci, urb_priv); 1508 + 1509 + usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 1510 + xhci_dbg(xhci, "Giveback URB %p, len = %d, " 1511 + "status = %d\n", 1512 + urb, urb->actual_length, status); 1513 + spin_unlock(&xhci->lock); 1514 + usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 1515 + spin_lock(&xhci->lock); 1516 + } 1517 + 1518 + /* 1519 + * If ep->skip is set, it means there are missed tds on the 1520 + * endpoint ring need to take care of. 1521 + * Process them as short transfer until reach the td pointed by 1522 + * the event. 1523 + */ 1524 + } while (ep->skip && trb_comp_code != COMP_MISSED_INT); 1525 + 2053 1526 return 0; 2054 1527 } 2055 1528 ··· 1935 1652 * This function handles all OS-owned events on the event ring. It may drop 1936 1653 * xhci->lock between event processing (e.g. to pass up port status changes). 1937 1654 */ 1938 - void xhci_handle_event(struct xhci_hcd *xhci) 1655 + static void xhci_handle_event(struct xhci_hcd *xhci) 1939 1656 { 1940 1657 union xhci_trb *event; 1941 1658 int update_ptrs = 1; ··· 1993 1710 return; 1994 1711 } 1995 1712 1996 - if (update_ptrs) { 1997 - /* Update SW and HC event ring dequeue pointer */ 1713 + if (update_ptrs) 1714 + /* Update SW event ring dequeue pointer */ 1998 1715 inc_deq(xhci, xhci->event_ring, true); 1999 - xhci_set_hc_event_deq(xhci); 2000 - } 1716 + 2001 1717 /* Are there more items on the event ring? */ 2002 1718 xhci_handle_event(xhci); 1719 + } 1720 + 1721 + /* 1722 + * xHCI spec says we can get an interrupt, and if the HC has an error condition, 1723 + * we might get bad data out of the event ring. Section 4.10.2.7 has a list of 1724 + * indicators of an event TRB error, but we check the status *first* to be safe. 1725 + */ 1726 + irqreturn_t xhci_irq(struct usb_hcd *hcd) 1727 + { 1728 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1729 + u32 status; 1730 + union xhci_trb *trb; 1731 + u64 temp_64; 1732 + union xhci_trb *event_ring_deq; 1733 + dma_addr_t deq; 1734 + 1735 + spin_lock(&xhci->lock); 1736 + trb = xhci->event_ring->dequeue; 1737 + /* Check if the xHC generated the interrupt, or the irq is shared */ 1738 + status = xhci_readl(xhci, &xhci->op_regs->status); 1739 + if (status == 0xffffffff) 1740 + goto hw_died; 1741 + 1742 + if (!(status & STS_EINT)) { 1743 + spin_unlock(&xhci->lock); 1744 + xhci_warn(xhci, "Spurious interrupt.\n"); 1745 + return IRQ_NONE; 1746 + } 1747 + xhci_dbg(xhci, "op reg status = %08x\n", status); 1748 + xhci_dbg(xhci, "Event ring dequeue ptr:\n"); 1749 + xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n", 1750 + (unsigned long long) 1751 + xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb), 1752 + lower_32_bits(trb->link.segment_ptr), 1753 + upper_32_bits(trb->link.segment_ptr), 1754 + (unsigned int) trb->link.intr_target, 1755 + (unsigned int) trb->link.control); 1756 + 1757 + if (status & STS_FATAL) { 1758 + xhci_warn(xhci, "WARNING: Host System Error\n"); 1759 + xhci_halt(xhci); 1760 + hw_died: 1761 + xhci_to_hcd(xhci)->state = HC_STATE_HALT; 1762 + spin_unlock(&xhci->lock); 1763 + return -ESHUTDOWN; 1764 + } 1765 + 1766 + /* 1767 + * Clear the op reg interrupt status first, 1768 + * so we can receive interrupts from other MSI-X interrupters. 1769 + * Write 1 to clear the interrupt status. 1770 + */ 1771 + status |= STS_EINT; 1772 + xhci_writel(xhci, status, &xhci->op_regs->status); 1773 + /* FIXME when MSI-X is supported and there are multiple vectors */ 1774 + /* Clear the MSI-X event interrupt status */ 1775 + 1776 + if (hcd->irq != -1) { 1777 + u32 irq_pending; 1778 + /* Acknowledge the PCI interrupt */ 1779 + irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending); 1780 + irq_pending |= 0x3; 1781 + xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending); 1782 + } 1783 + 1784 + if (xhci->xhc_state & XHCI_STATE_DYING) { 1785 + xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " 1786 + "Shouldn't IRQs be disabled?\n"); 1787 + /* Clear the event handler busy flag (RW1C); 1788 + * the event ring should be empty. 1789 + */ 1790 + temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 1791 + xhci_write_64(xhci, temp_64 | ERST_EHB, 1792 + &xhci->ir_set->erst_dequeue); 1793 + spin_unlock(&xhci->lock); 1794 + 1795 + return IRQ_HANDLED; 1796 + } 1797 + 1798 + event_ring_deq = xhci->event_ring->dequeue; 1799 + /* FIXME this should be a delayed service routine 1800 + * that clears the EHB. 1801 + */ 1802 + xhci_handle_event(xhci); 1803 + 1804 + temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 1805 + /* If necessary, update the HW's version of the event ring deq ptr. */ 1806 + if (event_ring_deq != xhci->event_ring->dequeue) { 1807 + deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, 1808 + xhci->event_ring->dequeue); 1809 + if (deq == 0) 1810 + xhci_warn(xhci, "WARN something wrong with SW event " 1811 + "ring dequeue ptr.\n"); 1812 + /* Update HC event ring dequeue pointer */ 1813 + temp_64 &= ERST_PTR_MASK; 1814 + temp_64 |= ((u64) deq & (u64) ~ERST_PTR_MASK); 1815 + } 1816 + 1817 + /* Clear the event handler busy flag (RW1C); event ring is empty. */ 1818 + temp_64 |= ERST_EHB; 1819 + xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue); 1820 + 1821 + spin_unlock(&xhci->lock); 1822 + 1823 + return IRQ_HANDLED; 1824 + } 1825 + 1826 + irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) 1827 + { 1828 + irqreturn_t ret; 1829 + 1830 + set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1831 + 1832 + ret = xhci_irq(hcd); 1833 + 1834 + return ret; 2003 1835 } 2004 1836 2005 1837 /**** Endpoint Ring Operations ****/ ··· 2225 1827 unsigned int stream_id, 2226 1828 unsigned int num_trbs, 2227 1829 struct urb *urb, 2228 - struct xhci_td **td, 1830 + unsigned int td_index, 2229 1831 gfp_t mem_flags) 2230 1832 { 2231 1833 int ret; 1834 + struct urb_priv *urb_priv; 1835 + struct xhci_td *td; 2232 1836 struct xhci_ring *ep_ring; 2233 1837 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 2234 1838 ··· 2246 1846 num_trbs, mem_flags); 2247 1847 if (ret) 2248 1848 return ret; 2249 - *td = kzalloc(sizeof(struct xhci_td), mem_flags); 2250 - if (!*td) 2251 - return -ENOMEM; 2252 - INIT_LIST_HEAD(&(*td)->td_list); 2253 - INIT_LIST_HEAD(&(*td)->cancelled_td_list); 2254 1849 2255 - ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 2256 - if (unlikely(ret)) { 2257 - kfree(*td); 2258 - return ret; 1850 + urb_priv = urb->hcpriv; 1851 + td = urb_priv->td[td_index]; 1852 + 1853 + INIT_LIST_HEAD(&td->td_list); 1854 + INIT_LIST_HEAD(&td->cancelled_td_list); 1855 + 1856 + if (td_index == 0) { 1857 + ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 1858 + if (unlikely(ret)) { 1859 + xhci_urb_free_priv(xhci, urb_priv); 1860 + urb->hcpriv = NULL; 1861 + return ret; 1862 + } 2259 1863 } 2260 1864 2261 - (*td)->urb = urb; 2262 - urb->hcpriv = (void *) (*td); 1865 + td->urb = urb; 2263 1866 /* Add this TD to the tail of the endpoint ring's TD list */ 2264 - list_add_tail(&(*td)->td_list, &ep_ring->td_list); 2265 - (*td)->start_seg = ep_ring->enq_seg; 2266 - (*td)->first_trb = ep_ring->enqueue; 1867 + list_add_tail(&td->td_list, &ep_ring->td_list); 1868 + td->start_seg = ep_ring->enq_seg; 1869 + td->first_trb = ep_ring->enqueue; 1870 + 1871 + urb_priv->td[td_index] = td; 2267 1872 2268 1873 return 0; 2269 1874 } ··· 2407 2002 { 2408 2003 struct xhci_ring *ep_ring; 2409 2004 unsigned int num_trbs; 2005 + struct urb_priv *urb_priv; 2410 2006 struct xhci_td *td; 2411 2007 struct scatterlist *sg; 2412 2008 int num_sgs; ··· 2428 2022 2429 2023 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 2430 2024 ep_index, urb->stream_id, 2431 - num_trbs, urb, &td, mem_flags); 2025 + num_trbs, urb, 0, mem_flags); 2432 2026 if (trb_buff_len < 0) 2433 2027 return trb_buff_len; 2028 + 2029 + urb_priv = urb->hcpriv; 2030 + td = urb_priv->td[0]; 2031 + 2434 2032 /* 2435 2033 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2436 2034 * until we've finished creating all the other TRBs. The ring's cycle ··· 2555 2145 struct urb *urb, int slot_id, unsigned int ep_index) 2556 2146 { 2557 2147 struct xhci_ring *ep_ring; 2148 + struct urb_priv *urb_priv; 2558 2149 struct xhci_td *td; 2559 2150 int num_trbs; 2560 2151 struct xhci_generic_trb *start_trb; ··· 2601 2190 2602 2191 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2603 2192 ep_index, urb->stream_id, 2604 - num_trbs, urb, &td, mem_flags); 2193 + num_trbs, urb, 0, mem_flags); 2605 2194 if (ret < 0) 2606 2195 return ret; 2196 + 2197 + urb_priv = urb->hcpriv; 2198 + td = urb_priv->td[0]; 2607 2199 2608 2200 /* 2609 2201 * Don't give the first TRB to the hardware (by toggling the cycle bit) ··· 2693 2279 struct xhci_generic_trb *start_trb; 2694 2280 int start_cycle; 2695 2281 u32 field, length_field; 2282 + struct urb_priv *urb_priv; 2696 2283 struct xhci_td *td; 2697 2284 2698 2285 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); ··· 2721 2306 num_trbs++; 2722 2307 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2723 2308 ep_index, urb->stream_id, 2724 - num_trbs, urb, &td, mem_flags); 2309 + num_trbs, urb, 0, mem_flags); 2725 2310 if (ret < 0) 2726 2311 return ret; 2312 + 2313 + urb_priv = urb->hcpriv; 2314 + td = urb_priv->td[0]; 2727 2315 2728 2316 /* 2729 2317 * Don't give the first TRB to the hardware (by toggling the cycle bit) ··· 2782 2364 giveback_first_trb(xhci, slot_id, ep_index, 0, 2783 2365 start_cycle, start_trb, td); 2784 2366 return 0; 2367 + } 2368 + 2369 + static int count_isoc_trbs_needed(struct xhci_hcd *xhci, 2370 + struct urb *urb, int i) 2371 + { 2372 + int num_trbs = 0; 2373 + u64 addr, td_len, running_total; 2374 + 2375 + addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset); 2376 + td_len = urb->iso_frame_desc[i].length; 2377 + 2378 + running_total = TRB_MAX_BUFF_SIZE - 2379 + (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2380 + if (running_total != 0) 2381 + num_trbs++; 2382 + 2383 + while (running_total < td_len) { 2384 + num_trbs++; 2385 + running_total += TRB_MAX_BUFF_SIZE; 2386 + } 2387 + 2388 + return num_trbs; 2389 + } 2390 + 2391 + /* This is for isoc transfer */ 2392 + static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 2393 + struct urb *urb, int slot_id, unsigned int ep_index) 2394 + { 2395 + struct xhci_ring *ep_ring; 2396 + struct urb_priv *urb_priv; 2397 + struct xhci_td *td; 2398 + int num_tds, trbs_per_td; 2399 + struct xhci_generic_trb *start_trb; 2400 + bool first_trb; 2401 + int start_cycle; 2402 + u32 field, length_field; 2403 + int running_total, trb_buff_len, td_len, td_remain_len, ret; 2404 + u64 start_addr, addr; 2405 + int i, j; 2406 + 2407 + ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 2408 + 2409 + num_tds = urb->number_of_packets; 2410 + if (num_tds < 1) { 2411 + xhci_dbg(xhci, "Isoc URB with zero packets?\n"); 2412 + return -EINVAL; 2413 + } 2414 + 2415 + if (!in_interrupt()) 2416 + dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d)," 2417 + " addr = %#llx, num_tds = %d\n", 2418 + urb->ep->desc.bEndpointAddress, 2419 + urb->transfer_buffer_length, 2420 + urb->transfer_buffer_length, 2421 + (unsigned long long)urb->transfer_dma, 2422 + num_tds); 2423 + 2424 + start_addr = (u64) urb->transfer_dma; 2425 + start_trb = &ep_ring->enqueue->generic; 2426 + start_cycle = ep_ring->cycle_state; 2427 + 2428 + /* Queue the first TRB, even if it's zero-length */ 2429 + for (i = 0; i < num_tds; i++) { 2430 + first_trb = true; 2431 + 2432 + running_total = 0; 2433 + addr = start_addr + urb->iso_frame_desc[i].offset; 2434 + td_len = urb->iso_frame_desc[i].length; 2435 + td_remain_len = td_len; 2436 + 2437 + trbs_per_td = count_isoc_trbs_needed(xhci, urb, i); 2438 + 2439 + ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, 2440 + urb->stream_id, trbs_per_td, urb, i, mem_flags); 2441 + if (ret < 0) 2442 + return ret; 2443 + 2444 + urb_priv = urb->hcpriv; 2445 + td = urb_priv->td[i]; 2446 + 2447 + for (j = 0; j < trbs_per_td; j++) { 2448 + u32 remainder = 0; 2449 + field = 0; 2450 + 2451 + if (first_trb) { 2452 + /* Queue the isoc TRB */ 2453 + field |= TRB_TYPE(TRB_ISOC); 2454 + /* Assume URB_ISO_ASAP is set */ 2455 + field |= TRB_SIA; 2456 + if (i > 0) 2457 + field |= ep_ring->cycle_state; 2458 + first_trb = false; 2459 + } else { 2460 + /* Queue other normal TRBs */ 2461 + field |= TRB_TYPE(TRB_NORMAL); 2462 + field |= ep_ring->cycle_state; 2463 + } 2464 + 2465 + /* Chain all the TRBs together; clear the chain bit in 2466 + * the last TRB to indicate it's the last TRB in the 2467 + * chain. 2468 + */ 2469 + if (j < trbs_per_td - 1) { 2470 + field |= TRB_CHAIN; 2471 + } else { 2472 + td->last_trb = ep_ring->enqueue; 2473 + field |= TRB_IOC; 2474 + } 2475 + 2476 + /* Calculate TRB length */ 2477 + trb_buff_len = TRB_MAX_BUFF_SIZE - 2478 + (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1)); 2479 + if (trb_buff_len > td_remain_len) 2480 + trb_buff_len = td_remain_len; 2481 + 2482 + remainder = xhci_td_remainder(td_len - running_total); 2483 + length_field = TRB_LEN(trb_buff_len) | 2484 + remainder | 2485 + TRB_INTR_TARGET(0); 2486 + queue_trb(xhci, ep_ring, false, false, 2487 + lower_32_bits(addr), 2488 + upper_32_bits(addr), 2489 + length_field, 2490 + /* We always want to know if the TRB was short, 2491 + * or we won't get an event when it completes. 2492 + * (Unless we use event data TRBs, which are a 2493 + * waste of space and HC resources.) 2494 + */ 2495 + field | TRB_ISP); 2496 + running_total += trb_buff_len; 2497 + 2498 + addr += trb_buff_len; 2499 + td_remain_len -= trb_buff_len; 2500 + } 2501 + 2502 + /* Check TD length */ 2503 + if (running_total != td_len) { 2504 + xhci_err(xhci, "ISOC TD length unmatch\n"); 2505 + return -EINVAL; 2506 + } 2507 + } 2508 + 2509 + wmb(); 2510 + start_trb->field[3] |= start_cycle; 2511 + 2512 + ring_ep_doorbell(xhci, slot_id, ep_index, urb->stream_id); 2513 + return 0; 2514 + } 2515 + 2516 + /* 2517 + * Check transfer ring to guarantee there is enough room for the urb. 2518 + * Update ISO URB start_frame and interval. 2519 + * Update interval as xhci_queue_intr_tx does. Just use xhci frame_index to 2520 + * update the urb->start_frame by now. 2521 + * Always assume URB_ISO_ASAP set, and NEVER use urb->start_frame as input. 2522 + */ 2523 + int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, 2524 + struct urb *urb, int slot_id, unsigned int ep_index) 2525 + { 2526 + struct xhci_virt_device *xdev; 2527 + struct xhci_ring *ep_ring; 2528 + struct xhci_ep_ctx *ep_ctx; 2529 + int start_frame; 2530 + int xhci_interval; 2531 + int ep_interval; 2532 + int num_tds, num_trbs, i; 2533 + int ret; 2534 + 2535 + xdev = xhci->devs[slot_id]; 2536 + ep_ring = xdev->eps[ep_index].ring; 2537 + ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 2538 + 2539 + num_trbs = 0; 2540 + num_tds = urb->number_of_packets; 2541 + for (i = 0; i < num_tds; i++) 2542 + num_trbs += count_isoc_trbs_needed(xhci, urb, i); 2543 + 2544 + /* Check the ring to guarantee there is enough room for the whole urb. 2545 + * Do not insert any td of the urb to the ring if the check failed. 2546 + */ 2547 + ret = prepare_ring(xhci, ep_ring, ep_ctx->ep_info & EP_STATE_MASK, 2548 + num_trbs, mem_flags); 2549 + if (ret) 2550 + return ret; 2551 + 2552 + start_frame = xhci_readl(xhci, &xhci->run_regs->microframe_index); 2553 + start_frame &= 0x3fff; 2554 + 2555 + urb->start_frame = start_frame; 2556 + if (urb->dev->speed == USB_SPEED_LOW || 2557 + urb->dev->speed == USB_SPEED_FULL) 2558 + urb->start_frame >>= 3; 2559 + 2560 + xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info); 2561 + ep_interval = urb->interval; 2562 + /* Convert to microframes */ 2563 + if (urb->dev->speed == USB_SPEED_LOW || 2564 + urb->dev->speed == USB_SPEED_FULL) 2565 + ep_interval *= 8; 2566 + /* FIXME change this to a warning and a suggestion to use the new API 2567 + * to set the polling interval (once the API is added). 2568 + */ 2569 + if (xhci_interval != ep_interval) { 2570 + if (!printk_ratelimit()) 2571 + dev_dbg(&urb->dev->dev, "Driver uses different interval" 2572 + " (%d microframe%s) than xHCI " 2573 + "(%d microframe%s)\n", 2574 + ep_interval, 2575 + ep_interval == 1 ? "" : "s", 2576 + xhci_interval, 2577 + xhci_interval == 1 ? "" : "s"); 2578 + urb->interval = xhci_interval; 2579 + /* Convert back to frames for LS/FS devices */ 2580 + if (urb->dev->speed == USB_SPEED_LOW || 2581 + urb->dev->speed == USB_SPEED_FULL) 2582 + urb->interval /= 8; 2583 + } 2584 + return xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); 2785 2585 } 2786 2586 2787 2587 /**** Command Ring Operations ****/
+205 -145
drivers/usb/host/xhci.c
··· 20 20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 21 */ 22 22 23 + #include <linux/pci.h> 23 24 #include <linux/irq.h> 24 25 #include <linux/log2.h> 25 26 #include <linux/module.h> ··· 172 171 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); 173 172 } 174 173 175 - 176 - #if 0 177 - /* Set up MSI-X table for entry 0 (may claim other entries later) */ 178 - static int xhci_setup_msix(struct xhci_hcd *xhci) 174 + /* 175 + * Free IRQs 176 + * free all IRQs request 177 + */ 178 + static void xhci_free_irq(struct xhci_hcd *xhci) 179 179 { 180 - int ret; 180 + int i; 181 181 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 182 182 183 - xhci->msix_count = 0; 184 - /* XXX: did I do this right? ixgbe does kcalloc for more than one */ 185 - xhci->msix_entries = kmalloc(sizeof(struct msix_entry), GFP_KERNEL); 183 + /* return if using legacy interrupt */ 184 + if (xhci_to_hcd(xhci)->irq >= 0) 185 + return; 186 + 187 + if (xhci->msix_entries) { 188 + for (i = 0; i < xhci->msix_count; i++) 189 + if (xhci->msix_entries[i].vector) 190 + free_irq(xhci->msix_entries[i].vector, 191 + xhci_to_hcd(xhci)); 192 + } else if (pdev->irq >= 0) 193 + free_irq(pdev->irq, xhci_to_hcd(xhci)); 194 + 195 + return; 196 + } 197 + 198 + /* 199 + * Set up MSI 200 + */ 201 + static int xhci_setup_msi(struct xhci_hcd *xhci) 202 + { 203 + int ret; 204 + struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 205 + 206 + ret = pci_enable_msi(pdev); 207 + if (ret) { 208 + xhci_err(xhci, "failed to allocate MSI entry\n"); 209 + return ret; 210 + } 211 + 212 + ret = request_irq(pdev->irq, (irq_handler_t)xhci_msi_irq, 213 + 0, "xhci_hcd", xhci_to_hcd(xhci)); 214 + if (ret) { 215 + xhci_err(xhci, "disable MSI interrupt\n"); 216 + pci_disable_msi(pdev); 217 + } 218 + 219 + return ret; 220 + } 221 + 222 + /* 223 + * Set up MSI-X 224 + */ 225 + static int xhci_setup_msix(struct xhci_hcd *xhci) 226 + { 227 + int i, ret = 0; 228 + struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 229 + 230 + /* 231 + * calculate number of msi-x vectors supported. 232 + * - HCS_MAX_INTRS: the max number of interrupts the host can handle, 233 + * with max number of interrupters based on the xhci HCSPARAMS1. 234 + * - num_online_cpus: maximum msi-x vectors per CPUs core. 235 + * Add additional 1 vector to ensure always available interrupt. 236 + */ 237 + xhci->msix_count = min(num_online_cpus() + 1, 238 + HCS_MAX_INTRS(xhci->hcs_params1)); 239 + 240 + xhci->msix_entries = 241 + kmalloc((sizeof(struct msix_entry))*xhci->msix_count, 242 + GFP_KERNEL); 186 243 if (!xhci->msix_entries) { 187 244 xhci_err(xhci, "Failed to allocate MSI-X entries\n"); 188 245 return -ENOMEM; 189 246 } 190 - xhci->msix_entries[0].entry = 0; 247 + 248 + for (i = 0; i < xhci->msix_count; i++) { 249 + xhci->msix_entries[i].entry = i; 250 + xhci->msix_entries[i].vector = 0; 251 + } 191 252 192 253 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); 193 254 if (ret) { ··· 257 194 goto free_entries; 258 195 } 259 196 260 - /* 261 - * Pass the xhci pointer value as the request_irq "cookie". 262 - * If more irqs are added, this will need to be unique for each one. 263 - */ 264 - ret = request_irq(xhci->msix_entries[0].vector, &xhci_irq, 0, 265 - "xHCI", xhci_to_hcd(xhci)); 266 - if (ret) { 267 - xhci_err(xhci, "Failed to allocate MSI-X interrupt\n"); 268 - goto disable_msix; 197 + for (i = 0; i < xhci->msix_count; i++) { 198 + ret = request_irq(xhci->msix_entries[i].vector, 199 + (irq_handler_t)xhci_msi_irq, 200 + 0, "xhci_hcd", xhci_to_hcd(xhci)); 201 + if (ret) 202 + goto disable_msix; 269 203 } 270 - xhci_dbg(xhci, "Finished setting up MSI-X\n"); 271 - return 0; 204 + 205 + return ret; 272 206 273 207 disable_msix: 208 + xhci_err(xhci, "disable MSI-X interrupt\n"); 209 + xhci_free_irq(xhci); 274 210 pci_disable_msix(pdev); 275 211 free_entries: 276 212 kfree(xhci->msix_entries); ··· 277 215 return ret; 278 216 } 279 217 280 - /* XXX: code duplication; can xhci_setup_msix call this? */ 281 218 /* Free any IRQs and disable MSI-X */ 282 219 static void xhci_cleanup_msix(struct xhci_hcd *xhci) 283 220 { 284 221 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 285 - if (!xhci->msix_entries) 286 - return; 287 222 288 - free_irq(xhci->msix_entries[0].vector, xhci); 289 - pci_disable_msix(pdev); 290 - kfree(xhci->msix_entries); 291 - xhci->msix_entries = NULL; 292 - xhci_dbg(xhci, "Finished cleaning up MSI-X\n"); 223 + xhci_free_irq(xhci); 224 + 225 + if (xhci->msix_entries) { 226 + pci_disable_msix(pdev); 227 + kfree(xhci->msix_entries); 228 + xhci->msix_entries = NULL; 229 + } else { 230 + pci_disable_msi(pdev); 231 + } 232 + 233 + return; 293 234 } 294 - #endif 295 235 296 236 /* 297 237 * Initialize memory for HCD and xHC (one-time init). ··· 321 257 return retval; 322 258 } 323 259 324 - /* 325 - * Called in interrupt context when there might be work 326 - * queued on the event ring 327 - * 328 - * xhci->lock must be held by caller. 329 - */ 330 - static void xhci_work(struct xhci_hcd *xhci) 331 - { 332 - u32 temp; 333 - u64 temp_64; 334 - 335 - /* 336 - * Clear the op reg interrupt status first, 337 - * so we can receive interrupts from other MSI-X interrupters. 338 - * Write 1 to clear the interrupt status. 339 - */ 340 - temp = xhci_readl(xhci, &xhci->op_regs->status); 341 - temp |= STS_EINT; 342 - xhci_writel(xhci, temp, &xhci->op_regs->status); 343 - /* FIXME when MSI-X is supported and there are multiple vectors */ 344 - /* Clear the MSI-X event interrupt status */ 345 - 346 - /* Acknowledge the interrupt */ 347 - temp = xhci_readl(xhci, &xhci->ir_set->irq_pending); 348 - temp |= 0x3; 349 - xhci_writel(xhci, temp, &xhci->ir_set->irq_pending); 350 - /* Flush posted writes */ 351 - xhci_readl(xhci, &xhci->ir_set->irq_pending); 352 - 353 - if (xhci->xhc_state & XHCI_STATE_DYING) 354 - xhci_dbg(xhci, "xHCI dying, ignoring interrupt. " 355 - "Shouldn't IRQs be disabled?\n"); 356 - else 357 - /* FIXME this should be a delayed service routine 358 - * that clears the EHB. 359 - */ 360 - xhci_handle_event(xhci); 361 - 362 - /* Clear the event handler busy flag (RW1C); the event ring should be empty. */ 363 - temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 364 - xhci_write_64(xhci, temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue); 365 - /* Flush posted writes -- FIXME is this necessary? */ 366 - xhci_readl(xhci, &xhci->ir_set->irq_pending); 367 - } 368 - 369 260 /*-------------------------------------------------------------------------*/ 370 261 371 - /* 372 - * xHCI spec says we can get an interrupt, and if the HC has an error condition, 373 - * we might get bad data out of the event ring. Section 4.10.2.7 has a list of 374 - * indicators of an event TRB error, but we check the status *first* to be safe. 375 - */ 376 - irqreturn_t xhci_irq(struct usb_hcd *hcd) 377 - { 378 - struct xhci_hcd *xhci = hcd_to_xhci(hcd); 379 - u32 temp, temp2; 380 - union xhci_trb *trb; 381 - 382 - spin_lock(&xhci->lock); 383 - trb = xhci->event_ring->dequeue; 384 - /* Check if the xHC generated the interrupt, or the irq is shared */ 385 - temp = xhci_readl(xhci, &xhci->op_regs->status); 386 - temp2 = xhci_readl(xhci, &xhci->ir_set->irq_pending); 387 - if (temp == 0xffffffff && temp2 == 0xffffffff) 388 - goto hw_died; 389 - 390 - if (!(temp & STS_EINT) && !ER_IRQ_PENDING(temp2)) { 391 - spin_unlock(&xhci->lock); 392 - return IRQ_NONE; 393 - } 394 - xhci_dbg(xhci, "op reg status = %08x\n", temp); 395 - xhci_dbg(xhci, "ir set irq_pending = %08x\n", temp2); 396 - xhci_dbg(xhci, "Event ring dequeue ptr:\n"); 397 - xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n", 398 - (unsigned long long)xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb), 399 - lower_32_bits(trb->link.segment_ptr), 400 - upper_32_bits(trb->link.segment_ptr), 401 - (unsigned int) trb->link.intr_target, 402 - (unsigned int) trb->link.control); 403 - 404 - if (temp & STS_FATAL) { 405 - xhci_warn(xhci, "WARNING: Host System Error\n"); 406 - xhci_halt(xhci); 407 - hw_died: 408 - xhci_to_hcd(xhci)->state = HC_STATE_HALT; 409 - spin_unlock(&xhci->lock); 410 - return -ESHUTDOWN; 411 - } 412 - 413 - xhci_work(xhci); 414 - spin_unlock(&xhci->lock); 415 - 416 - return IRQ_HANDLED; 417 - } 418 262 419 263 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 420 264 void xhci_event_ring_work(unsigned long arg) ··· 395 423 { 396 424 u32 temp; 397 425 u64 temp_64; 426 + u32 ret; 398 427 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 428 + struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 399 429 void (*doorbell)(struct xhci_hcd *) = NULL; 400 430 401 431 hcd->uses_new_polling = 1; 402 - hcd->poll_rh = 0; 403 432 404 433 xhci_dbg(xhci, "xhci_run\n"); 405 - #if 0 /* FIXME: MSI not setup yet */ 406 - /* Do this at the very last minute */ 407 - ret = xhci_setup_msix(xhci); 408 - if (!ret) 409 - return ret; 434 + /* unregister the legacy interrupt */ 435 + if (hcd->irq) 436 + free_irq(hcd->irq, hcd); 437 + hcd->irq = -1; 410 438 411 - return -ENOSYS; 412 - #endif 439 + ret = xhci_setup_msix(xhci); 440 + if (ret) 441 + /* fall back to msi*/ 442 + ret = xhci_setup_msi(xhci); 443 + 444 + if (ret) { 445 + /* fall back to legacy interrupt*/ 446 + ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 447 + hcd->irq_descr, hcd); 448 + if (ret) { 449 + xhci_err(xhci, "request interrupt %d failed\n", 450 + pdev->irq); 451 + return ret; 452 + } 453 + hcd->irq = pdev->irq; 454 + } 455 + 413 456 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 414 457 init_timer(&xhci->event_ring_timer); 415 458 xhci->event_ring_timer.data = (unsigned long) xhci; ··· 482 495 return -ENODEV; 483 496 } 484 497 485 - xhci_dbg(xhci, "// @%p = 0x%x\n", &xhci->op_regs->command, temp); 486 498 if (doorbell) 487 499 (*doorbell)(xhci); 488 500 if (xhci->quirks & XHCI_NEC_HOST) ··· 508 522 spin_lock_irq(&xhci->lock); 509 523 xhci_halt(xhci); 510 524 xhci_reset(xhci); 525 + xhci_cleanup_msix(xhci); 511 526 spin_unlock_irq(&xhci->lock); 512 527 513 - #if 0 /* No MSI yet */ 514 - xhci_cleanup_msix(xhci); 515 - #endif 516 528 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 517 529 /* Tell the event ring poll function not to reschedule */ 518 530 xhci->zombie = 1; ··· 544 560 545 561 spin_lock_irq(&xhci->lock); 546 562 xhci_halt(xhci); 547 - spin_unlock_irq(&xhci->lock); 548 - 549 - #if 0 550 563 xhci_cleanup_msix(xhci); 551 - #endif 564 + spin_unlock_irq(&xhci->lock); 552 565 553 566 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 554 567 xhci_readl(xhci, &xhci->op_regs->status)); ··· 701 720 unsigned long flags; 702 721 int ret = 0; 703 722 unsigned int slot_id, ep_index; 704 - 723 + struct urb_priv *urb_priv; 724 + int size, i; 705 725 706 726 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) 707 727 return -EINVAL; ··· 716 734 ret = -EINVAL; 717 735 goto exit; 718 736 } 719 - if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 737 + if (!HCD_HW_ACCESSIBLE(hcd)) { 720 738 if (!in_interrupt()) 721 739 xhci_dbg(xhci, "urb submitted during PCI suspend\n"); 722 740 ret = -ESHUTDOWN; 723 741 goto exit; 724 742 } 743 + 744 + if (usb_endpoint_xfer_isoc(&urb->ep->desc)) 745 + size = urb->number_of_packets; 746 + else 747 + size = 1; 748 + 749 + urb_priv = kzalloc(sizeof(struct urb_priv) + 750 + size * sizeof(struct xhci_td *), mem_flags); 751 + if (!urb_priv) 752 + return -ENOMEM; 753 + 754 + for (i = 0; i < size; i++) { 755 + urb_priv->td[i] = kzalloc(sizeof(struct xhci_td), mem_flags); 756 + if (!urb_priv->td[i]) { 757 + urb_priv->length = i; 758 + xhci_urb_free_priv(xhci, urb_priv); 759 + return -ENOMEM; 760 + } 761 + } 762 + 763 + urb_priv->length = size; 764 + urb_priv->td_cnt = 0; 765 + urb->hcpriv = urb_priv; 766 + 725 767 if (usb_endpoint_xfer_control(&urb->ep->desc)) { 726 768 /* Check to see if the max packet size for the default control 727 769 * endpoint changed during FS device enumeration ··· 794 788 slot_id, ep_index); 795 789 spin_unlock_irqrestore(&xhci->lock, flags); 796 790 } else { 797 - ret = -EINVAL; 791 + spin_lock_irqsave(&xhci->lock, flags); 792 + if (xhci->xhc_state & XHCI_STATE_DYING) 793 + goto dying; 794 + ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb, 795 + slot_id, ep_index); 796 + spin_unlock_irqrestore(&xhci->lock, flags); 798 797 } 799 798 exit: 800 799 return ret; 801 800 dying: 801 + xhci_urb_free_priv(xhci, urb_priv); 802 + urb->hcpriv = NULL; 802 803 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " 803 804 "non-responsive xHCI host.\n", 804 805 urb->ep->desc.bEndpointAddress, urb); 805 806 spin_unlock_irqrestore(&xhci->lock, flags); 806 807 return -ESHUTDOWN; 808 + } 809 + 810 + /* Get the right ring for the given URB. 811 + * If the endpoint supports streams, boundary check the URB's stream ID. 812 + * If the endpoint doesn't support streams, return the singular endpoint ring. 813 + */ 814 + static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, 815 + struct urb *urb) 816 + { 817 + unsigned int slot_id; 818 + unsigned int ep_index; 819 + unsigned int stream_id; 820 + struct xhci_virt_ep *ep; 821 + 822 + slot_id = urb->dev->slot_id; 823 + ep_index = xhci_get_endpoint_index(&urb->ep->desc); 824 + stream_id = urb->stream_id; 825 + ep = &xhci->devs[slot_id]->eps[ep_index]; 826 + /* Common case: no streams */ 827 + if (!(ep->ep_state & EP_HAS_STREAMS)) 828 + return ep->ring; 829 + 830 + if (stream_id == 0) { 831 + xhci_warn(xhci, 832 + "WARN: Slot ID %u, ep index %u has streams, " 833 + "but URB has no stream ID.\n", 834 + slot_id, ep_index); 835 + return NULL; 836 + } 837 + 838 + if (stream_id < ep->stream_info->num_streams) 839 + return ep->stream_info->stream_rings[stream_id]; 840 + 841 + xhci_warn(xhci, 842 + "WARN: Slot ID %u, ep index %u has " 843 + "stream IDs 1 to %u allocated, " 844 + "but stream ID %u is requested.\n", 845 + slot_id, ep_index, 846 + ep->stream_info->num_streams - 1, 847 + stream_id); 848 + return NULL; 807 849 } 808 850 809 851 /* ··· 888 834 int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 889 835 { 890 836 unsigned long flags; 891 - int ret; 837 + int ret, i; 892 838 u32 temp; 893 839 struct xhci_hcd *xhci; 840 + struct urb_priv *urb_priv; 894 841 struct xhci_td *td; 895 842 unsigned int ep_index; 896 843 struct xhci_ring *ep_ring; ··· 906 851 temp = xhci_readl(xhci, &xhci->op_regs->status); 907 852 if (temp == 0xffffffff) { 908 853 xhci_dbg(xhci, "HW died, freeing TD.\n"); 909 - td = (struct xhci_td *) urb->hcpriv; 854 + urb_priv = urb->hcpriv; 910 855 911 856 usb_hcd_unlink_urb_from_ep(hcd, urb); 912 857 spin_unlock_irqrestore(&xhci->lock, flags); 913 858 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 914 - kfree(td); 859 + xhci_urb_free_priv(xhci, urb_priv); 915 860 return ret; 916 861 } 917 862 if (xhci->xhc_state & XHCI_STATE_DYING) { ··· 939 884 940 885 xhci_dbg(xhci, "Endpoint ring:\n"); 941 886 xhci_debug_ring(xhci, ep_ring); 942 - td = (struct xhci_td *) urb->hcpriv; 943 887 944 - list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 888 + urb_priv = urb->hcpriv; 889 + 890 + for (i = urb_priv->td_cnt; i < urb_priv->length; i++) { 891 + td = urb_priv->td[i]; 892 + list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 893 + } 894 + 945 895 /* Queue a stop endpoint command, but only if this is 946 896 * the first cancellation to be handled. 947 897 */
+22 -8
drivers/usb/host/xhci.h
··· 720 720 struct timer_list stop_cmd_timer; 721 721 int stop_cmds_pending; 722 722 struct xhci_hcd *xhci; 723 + /* 724 + * Sometimes the xHC can not process isochronous endpoint ring quickly 725 + * enough, and it will miss some isoc tds on the ring and generate 726 + * a Missed Service Error Event. 727 + * Set skip flag when receive a Missed Service Error Event and 728 + * process the missed tds on the endpoint ring. 729 + */ 730 + bool skip; 723 731 }; 724 732 725 733 struct xhci_virt_device { ··· 919 911 /* Control transfer TRB specific fields */ 920 912 #define TRB_DIR_IN (1<<16) 921 913 914 + /* Isochronous TRB specific fields */ 915 + #define TRB_SIA (1<<31) 916 + 922 917 struct xhci_generic_trb { 923 918 u32 field[4]; 924 919 }; ··· 1093 1082 dma_addr_t *sp_dma_buffers; 1094 1083 }; 1095 1084 1085 + struct urb_priv { 1086 + int length; 1087 + int td_cnt; 1088 + struct xhci_td *td[0]; 1089 + }; 1090 + 1096 1091 /* 1097 1092 * Each segment table entry is 4*32bits long. 1K seems like an ok size: 1098 1093 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table, ··· 1147 1130 int page_size; 1148 1131 /* Valid values are 12 to 20, inclusive */ 1149 1132 int page_shift; 1150 - /* only one MSI vector for now, but might need more later */ 1133 + /* msi-x vectors */ 1151 1134 int msix_count; 1152 1135 struct msix_entry *msix_entries; 1153 1136 /* data structures */ ··· 1344 1327 struct xhci_ring *xhci_dma_to_transfer_ring( 1345 1328 struct xhci_virt_ep *ep, 1346 1329 u64 address); 1347 - struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci, 1348 - struct urb *urb); 1349 - struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci, 1350 - unsigned int slot_id, unsigned int ep_index, 1351 - unsigned int stream_id); 1352 1330 struct xhci_ring *xhci_stream_id_to_ring( 1353 1331 struct xhci_virt_device *dev, 1354 1332 unsigned int ep_index, ··· 1351 1339 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 1352 1340 bool allocate_in_ctx, bool allocate_completion, 1353 1341 gfp_t mem_flags); 1342 + void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv); 1354 1343 void xhci_free_command(struct xhci_hcd *xhci, 1355 1344 struct xhci_command *command); 1356 1345 ··· 1371 1358 void xhci_shutdown(struct usb_hcd *hcd); 1372 1359 int xhci_get_frame(struct usb_hcd *hcd); 1373 1360 irqreturn_t xhci_irq(struct usb_hcd *hcd); 1361 + irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd); 1374 1362 int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1375 1363 void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1376 1364 int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, ··· 1400 1386 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1401 1387 void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1402 1388 void *xhci_setup_one_noop(struct xhci_hcd *xhci); 1403 - void xhci_handle_event(struct xhci_hcd *xhci); 1404 - void xhci_set_hc_event_deq(struct xhci_hcd *xhci); 1405 1389 int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); 1406 1390 int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1407 1391 u32 slot_id); ··· 1413 1401 int slot_id, unsigned int ep_index); 1414 1402 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1415 1403 int slot_id, unsigned int ep_index); 1404 + int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, 1405 + struct urb *urb, int slot_id, unsigned int ep_index); 1416 1406 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1417 1407 u32 slot_id, bool command_must_succeed); 1418 1408 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
+2 -2
drivers/usb/misc/ftdi-elan.c
··· 650 650 651 651 static int ftdi_elan_release(struct inode *inode, struct file *file) 652 652 { 653 - struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data; 653 + struct usb_ftdi *ftdi = file->private_data; 654 654 if (ftdi == NULL) 655 655 return -ENODEV; 656 656 up(&ftdi->sw_lock); /* decrement the count on our device */ ··· 673 673 int bytes_read = 0; 674 674 int retry_on_empty = 10; 675 675 int retry_on_timeout = 5; 676 - struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data; 676 + struct usb_ftdi *ftdi = file->private_data; 677 677 if (ftdi->disconnected > 0) { 678 678 return -ENODEV; 679 679 }
+12 -11
drivers/usb/misc/iowarrior.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/slab.h> 20 20 #include <linux/sched.h> 21 - #include <linux/smp_lock.h> 21 + #include <linux/mutex.h> 22 22 #include <linux/poll.h> 23 23 #include <linux/usb/iowarrior.h> 24 24 ··· 61 61 MODULE_LICENSE("GPL"); 62 62 63 63 /* Module parameters */ 64 + static DEFINE_MUTEX(iowarrior_mutex); 64 65 static int debug = 0; 65 66 module_param(debug, bool, 0644); 66 67 MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); ··· 283 282 int read_idx; 284 283 int offset; 285 284 286 - dev = (struct iowarrior *)file->private_data; 285 + dev = file->private_data; 287 286 288 287 /* verify that the device wasn't unplugged */ 289 288 if (dev == NULL || !dev->present) ··· 349 348 char *buf = NULL; /* for IOW24 and IOW56 we need a buffer */ 350 349 struct urb *int_out_urb = NULL; 351 350 352 - dev = (struct iowarrior *)file->private_data; 351 + dev = file->private_data; 353 352 354 353 mutex_lock(&dev->mutex); 355 354 /* verify that the device wasn't unplugged */ ··· 484 483 int retval; 485 484 int io_res; /* checks for bytes read/written and copy_to/from_user results */ 486 485 487 - dev = (struct iowarrior *)file->private_data; 486 + dev = file->private_data; 488 487 if (dev == NULL) { 489 488 return -ENODEV; 490 489 } ··· 494 493 return -ENOMEM; 495 494 496 495 /* lock this object */ 497 - lock_kernel(); 496 + mutex_lock(&iowarrior_mutex); 498 497 mutex_lock(&dev->mutex); 499 498 500 499 /* verify that the device wasn't unplugged */ ··· 586 585 error_out: 587 586 /* unlock the device */ 588 587 mutex_unlock(&dev->mutex); 589 - unlock_kernel(); 588 + mutex_unlock(&iowarrior_mutex); 590 589 kfree(buffer); 591 590 return retval; 592 591 } ··· 603 602 604 603 dbg("%s", __func__); 605 604 606 - lock_kernel(); 605 + mutex_lock(&iowarrior_mutex); 607 606 subminor = iminor(inode); 608 607 609 608 interface = usb_find_interface(&iowarrior_driver, subminor); 610 609 if (!interface) { 611 - unlock_kernel(); 610 + mutex_unlock(&iowarrior_mutex); 612 611 err("%s - error, can't find device for minor %d", __func__, 613 612 subminor); 614 613 return -ENODEV; ··· 618 617 dev = usb_get_intfdata(interface); 619 618 if (!dev) { 620 619 mutex_unlock(&iowarrior_open_disc_lock); 621 - unlock_kernel(); 620 + mutex_unlock(&iowarrior_mutex); 622 621 return -ENODEV; 623 622 } 624 623 ··· 645 644 646 645 out: 647 646 mutex_unlock(&dev->mutex); 648 - unlock_kernel(); 647 + mutex_unlock(&iowarrior_mutex); 649 648 return retval; 650 649 } 651 650 ··· 657 656 struct iowarrior *dev; 658 657 int retval = 0; 659 658 660 - dev = (struct iowarrior *)file->private_data; 659 + dev = file->private_data; 661 660 if (dev == NULL) { 662 661 return -ENODEV; 663 662 }
+3 -3
drivers/usb/misc/legousbtower.c
··· 448 448 449 449 dbg(2, "%s: enter", __func__); 450 450 451 - dev = (struct lego_usb_tower *)file->private_data; 451 + dev = file->private_data; 452 452 453 453 if (dev == NULL) { 454 454 dbg(1, "%s: object is NULL", __func__); ··· 597 597 598 598 dbg(2, "%s: enter, count = %Zd", __func__, count); 599 599 600 - dev = (struct lego_usb_tower *)file->private_data; 600 + dev = file->private_data; 601 601 602 602 /* lock this object */ 603 603 if (mutex_lock_interruptible(&dev->lock)) { ··· 686 686 687 687 dbg(2, "%s: enter, count = %Zd", __func__, count); 688 688 689 - dev = (struct lego_usb_tower *)file->private_data; 689 + dev = file->private_data; 690 690 691 691 /* lock this object */ 692 692 if (mutex_lock_interruptible(&dev->lock)) {
+8 -7
drivers/usb/misc/rio500.c
··· 32 32 #include <linux/kernel.h> 33 33 #include <linux/signal.h> 34 34 #include <linux/sched.h> 35 - #include <linux/smp_lock.h> 35 + #include <linux/mutex.h> 36 36 #include <linux/errno.h> 37 37 #include <linux/random.h> 38 38 #include <linux/poll.h> ··· 72 72 struct mutex lock; /* general race avoidance */ 73 73 }; 74 74 75 + static DEFINE_MUTEX(rio500_mutex); 75 76 static struct rio_usb_data rio_instance; 76 77 77 78 static int open_rio(struct inode *inode, struct file *file) ··· 80 79 struct rio_usb_data *rio = &rio_instance; 81 80 82 81 /* against disconnect() */ 83 - lock_kernel(); 82 + mutex_lock(&rio500_mutex); 84 83 mutex_lock(&(rio->lock)); 85 84 86 85 if (rio->isopen || !rio->present) { 87 86 mutex_unlock(&(rio->lock)); 88 - unlock_kernel(); 87 + mutex_unlock(&rio500_mutex); 89 88 return -EBUSY; 90 89 } 91 90 rio->isopen = 1; ··· 95 94 mutex_unlock(&(rio->lock)); 96 95 97 96 dev_info(&rio->rio_dev->dev, "Rio opened.\n"); 98 - unlock_kernel(); 97 + mutex_unlock(&rio500_mutex); 99 98 100 99 return 0; 101 100 } ··· 492 491 struct rio_usb_data *rio = usb_get_intfdata (intf); 493 492 494 493 usb_set_intfdata (intf, NULL); 495 - lock_kernel(); 494 + mutex_lock(&rio500_mutex); 496 495 if (rio) { 497 496 usb_deregister_dev(intf, &usb_rio_class); 498 497 ··· 502 501 /* better let it finish - the release will do whats needed */ 503 502 rio->rio_dev = NULL; 504 503 mutex_unlock(&(rio->lock)); 505 - unlock_kernel(); 504 + mutex_unlock(&rio500_mutex); 506 505 return; 507 506 } 508 507 kfree(rio->ibuf); ··· 513 512 rio->present = 0; 514 513 mutex_unlock(&(rio->lock)); 515 514 } 516 - unlock_kernel(); 515 + mutex_unlock(&rio500_mutex); 517 516 } 518 517 519 518 static const struct usb_device_id rio_table[] = {
+5 -5
drivers/usb/misc/sisusbvga/sisusb.c
··· 2487 2487 { 2488 2488 struct sisusb_usb_data *sisusb; 2489 2489 2490 - if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2490 + if (!(sisusb = file->private_data)) 2491 2491 return -ENODEV; 2492 2492 2493 2493 mutex_lock(&sisusb->lock); ··· 2519 2519 u16 buf16; 2520 2520 u32 buf32, address; 2521 2521 2522 - if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2522 + if (!(sisusb = file->private_data)) 2523 2523 return -ENODEV; 2524 2524 2525 2525 mutex_lock(&sisusb->lock); ··· 2661 2661 u16 buf16; 2662 2662 u32 buf32, address; 2663 2663 2664 - if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2664 + if (!(sisusb = file->private_data)) 2665 2665 return -ENODEV; 2666 2666 2667 2667 mutex_lock(&sisusb->lock); ··· 2804 2804 struct sisusb_usb_data *sisusb; 2805 2805 loff_t ret; 2806 2806 2807 - if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2807 + if (!(sisusb = file->private_data)) 2808 2808 return -ENODEV; 2809 2809 2810 2810 mutex_lock(&sisusb->lock); ··· 2969 2969 long retval = 0; 2970 2970 u32 __user *argp = (u32 __user *)arg; 2971 2971 2972 - if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2972 + if (!(sisusb = file->private_data)) 2973 2973 return -ENODEV; 2974 2974 2975 2975 mutex_lock(&sisusb->lock);
+12 -12
drivers/usb/misc/usblcd.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/init.h> 18 18 #include <linux/slab.h> 19 - #include <linux/smp_lock.h> 20 19 #include <linux/errno.h> 21 20 #include <linux/mutex.h> 22 21 #include <asm/uaccess.h> ··· 29 30 #define IOCTL_GET_DRV_VERSION 2 30 31 31 32 33 + static DEFINE_MUTEX(lcd_mutex); 32 34 static const struct usb_device_id id_table[] = { 33 35 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, 34 36 { }, ··· 74 74 struct usb_interface *interface; 75 75 int subminor, r; 76 76 77 - lock_kernel(); 77 + mutex_lock(&lcd_mutex); 78 78 subminor = iminor(inode); 79 79 80 80 interface = usb_find_interface(&lcd_driver, subminor); 81 81 if (!interface) { 82 - unlock_kernel(); 82 + mutex_unlock(&lcd_mutex); 83 83 err ("USBLCD: %s - error, can't find device for minor %d", 84 84 __func__, subminor); 85 85 return -ENODEV; ··· 89 89 dev = usb_get_intfdata(interface); 90 90 if (!dev) { 91 91 mutex_unlock(&open_disc_mutex); 92 - unlock_kernel(); 92 + mutex_unlock(&lcd_mutex); 93 93 return -ENODEV; 94 94 } 95 95 ··· 101 101 r = usb_autopm_get_interface(interface); 102 102 if (r < 0) { 103 103 kref_put(&dev->kref, lcd_delete); 104 - unlock_kernel(); 104 + mutex_unlock(&lcd_mutex); 105 105 return r; 106 106 } 107 107 108 108 /* save our object in the file's private structure */ 109 109 file->private_data = dev; 110 - unlock_kernel(); 110 + mutex_unlock(&lcd_mutex); 111 111 112 112 return 0; 113 113 } ··· 116 116 { 117 117 struct usb_lcd *dev; 118 118 119 - dev = (struct usb_lcd *)file->private_data; 119 + dev = file->private_data; 120 120 if (dev == NULL) 121 121 return -ENODEV; 122 122 ··· 132 132 int retval = 0; 133 133 int bytes_read; 134 134 135 - dev = (struct usb_lcd *)file->private_data; 135 + dev = file->private_data; 136 136 137 137 /* do a blocking bulk read to get data from the device */ 138 138 retval = usb_bulk_msg(dev->udev, ··· 158 158 u16 bcdDevice; 159 159 char buf[30]; 160 160 161 - dev = (struct usb_lcd *)file->private_data; 161 + dev = file->private_data; 162 162 if (dev == NULL) 163 163 return -ENODEV; 164 164 165 165 switch (cmd) { 166 166 case IOCTL_GET_HARD_VERSION: 167 - lock_kernel(); 167 + mutex_lock(&lcd_mutex); 168 168 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); 169 169 sprintf(buf,"%1d%1d.%1d%1d", 170 170 (bcdDevice & 0xF000)>>12, 171 171 (bcdDevice & 0xF00)>>8, 172 172 (bcdDevice & 0xF0)>>4, 173 173 (bcdDevice & 0xF)); 174 - unlock_kernel(); 174 + mutex_unlock(&lcd_mutex); 175 175 if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) 176 176 return -EFAULT; 177 177 break; ··· 217 217 struct urb *urb = NULL; 218 218 char *buf = NULL; 219 219 220 - dev = (struct usb_lcd *)file->private_data; 220 + dev = file->private_data; 221 221 222 222 /* verify that we actually have some data to write */ 223 223 if (count == 0)
+11 -3
drivers/usb/misc/usbtest.c
··· 136 136 iso_out = e; 137 137 } 138 138 } 139 - if ((in && out) || (iso_in && iso_out)) 139 + if ((in && out) || iso_in || iso_out) 140 140 goto found; 141 141 } 142 142 return -EINVAL; ··· 162 162 dev->in_iso_pipe = usb_rcvisocpipe (udev, 163 163 iso_in->desc.bEndpointAddress 164 164 & USB_ENDPOINT_NUMBER_MASK); 165 + } 166 + 167 + if (iso_out) { 165 168 dev->iso_out = &iso_out->desc; 166 169 dev->out_iso_pipe = usb_sndisocpipe (udev, 167 170 iso_out->desc.bEndpointAddress ··· 1381 1378 break; 1382 1379 } 1383 1380 } 1384 - simple_free_urb (urb); 1385 1381 1386 1382 ctx->pending--; 1387 1383 if (ctx->pending == 0) { ··· 1497 1495 } 1498 1496 1499 1497 simple_free_urb (urbs [i]); 1498 + urbs[i] = NULL; 1500 1499 context.pending--; 1501 1500 context.submit_error = 1; 1502 1501 break; ··· 1507 1504 1508 1505 wait_for_completion (&context.done); 1509 1506 1507 + for (i = 0; i < param->sglen; i++) { 1508 + if (urbs[i]) 1509 + simple_free_urb(urbs[i]); 1510 + } 1510 1511 /* 1511 1512 * Isochronous transfers are expected to fail sometimes. As an 1512 1513 * arbitrary limit, we will report an error if any submissions ··· 1555 1548 * off just killing the userspace task and waiting for it to exit. 1556 1549 */ 1557 1550 1551 + /* No BKL needed */ 1558 1552 static int 1559 1553 usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) 1560 1554 { ··· 2178 2170 .name = "usbtest", 2179 2171 .id_table = id_table, 2180 2172 .probe = usbtest_probe, 2181 - .ioctl = usbtest_ioctl, 2173 + .unlocked_ioctl = usbtest_ioctl, 2182 2174 .disconnect = usbtest_disconnect, 2183 2175 .suspend = usbtest_suspend, 2184 2176 .resume = usbtest_resume,
+3 -21
drivers/usb/mon/mon_bin.c
··· 646 646 size_t size; 647 647 int rc; 648 648 649 - lock_kernel(); 650 649 mutex_lock(&mon_lock); 651 650 if ((mbus = mon_bus_lookup(iminor(inode))) == NULL) { 652 651 mutex_unlock(&mon_lock); 653 - unlock_kernel(); 654 652 return -ENODEV; 655 653 } 656 654 if (mbus != &mon_bus0 && mbus->u_bus == NULL) { 657 655 printk(KERN_ERR TAG ": consistency error on open\n"); 658 656 mutex_unlock(&mon_lock); 659 - unlock_kernel(); 660 657 return -ENODEV; 661 658 } 662 659 ··· 686 689 687 690 file->private_data = rp; 688 691 mutex_unlock(&mon_lock); 689 - unlock_kernel(); 690 692 return 0; 691 693 692 694 err_allocbuff: ··· 694 698 kfree(rp); 695 699 err_alloc: 696 700 mutex_unlock(&mon_lock); 697 - unlock_kernel(); 698 701 return rc; 699 702 } 700 703 ··· 949 954 950 955 /* 951 956 */ 952 - static int mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 957 + static long mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 953 958 { 954 959 struct mon_reader_bin *rp = file->private_data; 955 960 // struct mon_bus* mbus = rp->r.m_bus; ··· 1004 1009 1005 1010 mutex_lock(&rp->fetch_lock); 1006 1011 spin_lock_irqsave(&rp->b_lock, flags); 1007 - mon_free_buff(rp->b_vec, size/CHUNK_SIZE); 1012 + mon_free_buff(rp->b_vec, rp->b_size/CHUNK_SIZE); 1008 1013 kfree(rp->b_vec); 1009 1014 rp->b_vec = vec; 1010 1015 rp->b_size = size; ··· 1088 1093 1089 1094 return ret; 1090 1095 } 1091 - 1092 - static long mon_bin_unlocked_ioctl(struct file *file, unsigned int cmd, 1093 - unsigned long arg) 1094 - { 1095 - int ret; 1096 - 1097 - lock_kernel(); 1098 - ret = mon_bin_ioctl(file, cmd, arg); 1099 - unlock_kernel(); 1100 - 1101 - return ret; 1102 - } 1103 - 1104 1096 1105 1097 #ifdef CONFIG_COMPAT 1106 1098 static long mon_bin_compat_ioctl(struct file *file, ··· 1232 1250 .read = mon_bin_read, 1233 1251 /* .write = mon_text_write, */ 1234 1252 .poll = mon_bin_poll, 1235 - .unlocked_ioctl = mon_bin_unlocked_ioctl, 1253 + .unlocked_ioctl = mon_bin_ioctl, 1236 1254 #ifdef CONFIG_COMPAT 1237 1255 .compat_ioctl = mon_bin_compat_ioctl, 1238 1256 #endif
+3 -4
drivers/usb/musb/musb_core.c
··· 704 704 #ifdef CONFIG_USB_MUSB_HDRC_HCD 705 705 if (int_usb & MUSB_INTR_CONNECT) { 706 706 struct usb_hcd *hcd = musb_to_hcd(musb); 707 - void __iomem *mbase = musb->mregs; 708 707 709 708 handled = IRQ_HANDLED; 710 709 musb->is_active = 1; ··· 716 717 if (is_peripheral_active(musb)) { 717 718 /* REVISIT HNP; just force disconnect */ 718 719 } 719 - musb_writew(mbase, MUSB_INTRTXE, musb->epmask); 720 - musb_writew(mbase, MUSB_INTRRXE, musb->epmask & 0xfffe); 721 - musb_writeb(mbase, MUSB_INTRUSBE, 0xf7); 720 + musb_writew(musb->mregs, MUSB_INTRTXE, musb->epmask); 721 + musb_writew(musb->mregs, MUSB_INTRRXE, musb->epmask & 0xfffe); 722 + musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7); 722 723 #endif 723 724 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED 724 725 |USB_PORT_STAT_HIGH_SPEED
+16 -16
drivers/usb/musb/musb_debugfs.c
··· 92 92 { "LS_EOF1", 0x7E, 8 }, 93 93 { "SOFT_RST", 0x7F, 8 }, 94 94 { "DMA_CNTLch0", 0x204, 16 }, 95 - { "DMA_ADDRch0", 0x208, 16 }, 96 - { "DMA_COUNTch0", 0x20C, 16 }, 95 + { "DMA_ADDRch0", 0x208, 32 }, 96 + { "DMA_COUNTch0", 0x20C, 32 }, 97 97 { "DMA_CNTLch1", 0x214, 16 }, 98 - { "DMA_ADDRch1", 0x218, 16 }, 99 - { "DMA_COUNTch1", 0x21C, 16 }, 98 + { "DMA_ADDRch1", 0x218, 32 }, 99 + { "DMA_COUNTch1", 0x21C, 32 }, 100 100 { "DMA_CNTLch2", 0x224, 16 }, 101 - { "DMA_ADDRch2", 0x228, 16 }, 102 - { "DMA_COUNTch2", 0x22C, 16 }, 101 + { "DMA_ADDRch2", 0x228, 32 }, 102 + { "DMA_COUNTch2", 0x22C, 32 }, 103 103 { "DMA_CNTLch3", 0x234, 16 }, 104 - { "DMA_ADDRch3", 0x238, 16 }, 105 - { "DMA_COUNTch3", 0x23C, 16 }, 104 + { "DMA_ADDRch3", 0x238, 32 }, 105 + { "DMA_COUNTch3", 0x23C, 32 }, 106 106 { "DMA_CNTLch4", 0x244, 16 }, 107 - { "DMA_ADDRch4", 0x248, 16 }, 108 - { "DMA_COUNTch4", 0x24C, 16 }, 107 + { "DMA_ADDRch4", 0x248, 32 }, 108 + { "DMA_COUNTch4", 0x24C, 32 }, 109 109 { "DMA_CNTLch5", 0x254, 16 }, 110 - { "DMA_ADDRch5", 0x258, 16 }, 111 - { "DMA_COUNTch5", 0x25C, 16 }, 110 + { "DMA_ADDRch5", 0x258, 32 }, 111 + { "DMA_COUNTch5", 0x25C, 32 }, 112 112 { "DMA_CNTLch6", 0x264, 16 }, 113 - { "DMA_ADDRch6", 0x268, 16 }, 114 - { "DMA_COUNTch6", 0x26C, 16 }, 113 + { "DMA_ADDRch6", 0x268, 32 }, 114 + { "DMA_COUNTch6", 0x26C, 32 }, 115 115 { "DMA_CNTLch7", 0x274, 16 }, 116 - { "DMA_ADDRch7", 0x278, 16 }, 117 - { "DMA_COUNTch7", 0x27C, 16 }, 116 + { "DMA_ADDRch7", 0x278, 32 }, 117 + { "DMA_COUNTch7", 0x27C, 32 }, 118 118 { } /* Terminating Entry */ 119 119 }; 120 120
+3
drivers/usb/musb/musb_gadget_ep0.c
··· 402 402 musb->g.a_alt_hnp_support = 1; 403 403 break; 404 404 #endif 405 + case USB_DEVICE_DEBUG_MODE: 406 + handled = 0; 407 + break; 405 408 stall: 406 409 default: 407 410 handled = -EINVAL;
+1 -1
drivers/usb/musb/musb_virthub.c
··· 244 244 245 245 spin_lock_irqsave(&musb->lock, flags); 246 246 247 - if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) { 247 + if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) { 248 248 spin_unlock_irqrestore(&musb->lock, flags); 249 249 return -ESHUTDOWN; 250 250 }
+1 -4
drivers/usb/musb/musbhsdma.c
··· 173 173 musb_channel->max_packet_sz = packet_sz; 174 174 channel->status = MUSB_DMA_STATUS_BUSY; 175 175 176 - if ((mode == 1) && (len >= packet_sz)) 177 - configure_channel(channel, packet_sz, 1, dma_addr, len); 178 - else 179 - configure_channel(channel, packet_sz, 0, dma_addr, len); 176 + configure_channel(channel, packet_sz, mode, dma_addr, len); 180 177 181 178 return true; 182 179 }
-6
drivers/usb/musb/omap2430.c
··· 32 32 #include <linux/clk.h> 33 33 #include <linux/io.h> 34 34 35 - #include <plat/mux.h> 36 - 37 35 #include "musb_core.h" 38 36 #include "omap2430.h" 39 37 ··· 191 193 { 192 194 u32 l; 193 195 struct omap_musb_board_data *data = board_data; 194 - 195 - #if defined(CONFIG_ARCH_OMAP2430) 196 - omap_cfg_reg(AE5_2430_USB0HS_STP); 197 - #endif 198 196 199 197 /* We require some kind of external transceiver, hooked 200 198 * up through ULPI. TWL4030-family PMICs include one,
-2
drivers/usb/otg/Kconfig
··· 49 49 Enable this to support ULPI connected USB OTG transceivers which 50 50 are likely found on embedded boards. 51 51 52 - The only chip currently supported is NXP's ISP1504 53 - 54 52 config TWL4030_USB 55 53 tristate "TWL4030 USB Transceiver Driver" 56 54 depends on TWL4030_CORE && REGULATOR_TWL4030
+121 -15
drivers/usb/otg/ulpi.c
··· 31 31 32 32 #define ULPI_ID(vendor, product) (((vendor) << 16) | (product)) 33 33 34 - #define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0) 35 - 36 34 /* ULPI hardcoded IDs, used for probing */ 37 35 static unsigned int ulpi_ids[] = { 38 36 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */ 37 + ULPI_ID(0x0424, 0x0006), /* SMSC USB3319 */ 39 38 }; 40 39 41 - static int ulpi_set_flags(struct otg_transceiver *otg) 40 + static int ulpi_set_otg_flags(struct otg_transceiver *otg) 41 + { 42 + unsigned int flags = ULPI_OTG_CTRL_DP_PULLDOWN | 43 + ULPI_OTG_CTRL_DM_PULLDOWN; 44 + 45 + if (otg->flags & ULPI_OTG_ID_PULLUP) 46 + flags |= ULPI_OTG_CTRL_ID_PULLUP; 47 + 48 + /* 49 + * ULPI Specification rev.1.1 default 50 + * for Dp/DmPulldown is enabled. 51 + */ 52 + if (otg->flags & ULPI_OTG_DP_PULLDOWN_DIS) 53 + flags &= ~ULPI_OTG_CTRL_DP_PULLDOWN; 54 + 55 + if (otg->flags & ULPI_OTG_DM_PULLDOWN_DIS) 56 + flags &= ~ULPI_OTG_CTRL_DM_PULLDOWN; 57 + 58 + if (otg->flags & ULPI_OTG_EXTVBUSIND) 59 + flags |= ULPI_OTG_CTRL_EXTVBUSIND; 60 + 61 + return otg_io_write(otg, flags, ULPI_OTG_CTRL); 62 + } 63 + 64 + static int ulpi_set_fc_flags(struct otg_transceiver *otg) 42 65 { 43 66 unsigned int flags = 0; 44 67 45 - if (otg->flags & USB_OTG_PULLUP_ID) 46 - flags |= ULPI_OTG_CTRL_ID_PULLUP; 68 + /* 69 + * ULPI Specification rev.1.1 default 70 + * for XcvrSelect is Full Speed. 71 + */ 72 + if (otg->flags & ULPI_FC_HS) 73 + flags |= ULPI_FUNC_CTRL_HIGH_SPEED; 74 + else if (otg->flags & ULPI_FC_LS) 75 + flags |= ULPI_FUNC_CTRL_LOW_SPEED; 76 + else if (otg->flags & ULPI_FC_FS4LS) 77 + flags |= ULPI_FUNC_CTRL_FS4LS; 78 + else 79 + flags |= ULPI_FUNC_CTRL_FULL_SPEED; 47 80 48 - if (otg->flags & USB_OTG_PULLDOWN_DM) 49 - flags |= ULPI_OTG_CTRL_DM_PULLDOWN; 81 + if (otg->flags & ULPI_FC_TERMSEL) 82 + flags |= ULPI_FUNC_CTRL_TERMSELECT; 50 83 51 - if (otg->flags & USB_OTG_PULLDOWN_DP) 52 - flags |= ULPI_OTG_CTRL_DP_PULLDOWN; 84 + /* 85 + * ULPI Specification rev.1.1 default 86 + * for OpMode is Normal Operation. 87 + */ 88 + if (otg->flags & ULPI_FC_OP_NODRV) 89 + flags |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; 90 + else if (otg->flags & ULPI_FC_OP_DIS_NRZI) 91 + flags |= ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI; 92 + else if (otg->flags & ULPI_FC_OP_NSYNC_NEOP) 93 + flags |= ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP; 94 + else 95 + flags |= ULPI_FUNC_CTRL_OPMODE_NORMAL; 53 96 54 - if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR) 55 - flags |= ULPI_OTG_CTRL_EXTVBUSIND; 97 + /* 98 + * ULPI Specification rev.1.1 default 99 + * for SuspendM is Powered. 100 + */ 101 + flags |= ULPI_FUNC_CTRL_SUSPENDM; 56 102 57 - return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL)); 103 + return otg_io_write(otg, flags, ULPI_FUNC_CTRL); 104 + } 105 + 106 + static int ulpi_set_ic_flags(struct otg_transceiver *otg) 107 + { 108 + unsigned int flags = 0; 109 + 110 + if (otg->flags & ULPI_IC_AUTORESUME) 111 + flags |= ULPI_IFC_CTRL_AUTORESUME; 112 + 113 + if (otg->flags & ULPI_IC_EXTVBUS_INDINV) 114 + flags |= ULPI_IFC_CTRL_EXTERNAL_VBUS; 115 + 116 + if (otg->flags & ULPI_IC_IND_PASSTHRU) 117 + flags |= ULPI_IFC_CTRL_PASSTHRU; 118 + 119 + if (otg->flags & ULPI_IC_PROTECT_DIS) 120 + flags |= ULPI_IFC_CTRL_PROTECT_IFC_DISABLE; 121 + 122 + return otg_io_write(otg, flags, ULPI_IFC_CTRL); 123 + } 124 + 125 + static int ulpi_set_flags(struct otg_transceiver *otg) 126 + { 127 + int ret; 128 + 129 + ret = ulpi_set_otg_flags(otg); 130 + if (ret) 131 + return ret; 132 + 133 + ret = ulpi_set_ic_flags(otg); 134 + if (ret) 135 + return ret; 136 + 137 + return ulpi_set_fc_flags(otg); 58 138 } 59 139 60 140 static int ulpi_init(struct otg_transceiver *otg) ··· 161 81 return -ENODEV; 162 82 } 163 83 84 + static int ulpi_set_host(struct otg_transceiver *otg, struct usb_bus *host) 85 + { 86 + unsigned int flags = otg_io_read(otg, ULPI_IFC_CTRL); 87 + 88 + if (!host) { 89 + otg->host = NULL; 90 + return 0; 91 + } 92 + 93 + otg->host = host; 94 + 95 + flags &= ~(ULPI_IFC_CTRL_6_PIN_SERIAL_MODE | 96 + ULPI_IFC_CTRL_3_PIN_SERIAL_MODE | 97 + ULPI_IFC_CTRL_CARKITMODE); 98 + 99 + if (otg->flags & ULPI_IC_6PIN_SERIAL) 100 + flags |= ULPI_IFC_CTRL_6_PIN_SERIAL_MODE; 101 + else if (otg->flags & ULPI_IC_3PIN_SERIAL) 102 + flags |= ULPI_IFC_CTRL_3_PIN_SERIAL_MODE; 103 + else if (otg->flags & ULPI_IC_CARKIT) 104 + flags |= ULPI_IFC_CTRL_CARKITMODE; 105 + 106 + return otg_io_write(otg, flags, ULPI_IFC_CTRL); 107 + } 108 + 164 109 static int ulpi_set_vbus(struct otg_transceiver *otg, bool on) 165 110 { 166 111 unsigned int flags = otg_io_read(otg, ULPI_OTG_CTRL); ··· 193 88 flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT); 194 89 195 90 if (on) { 196 - if (otg->flags & USB_OTG_DRV_VBUS) 91 + if (otg->flags & ULPI_OTG_DRVVBUS) 197 92 flags |= ULPI_OTG_CTRL_DRVVBUS; 198 93 199 - if (otg->flags & USB_OTG_DRV_VBUS_EXT) 94 + if (otg->flags & ULPI_OTG_DRVVBUS_EXT) 200 95 flags |= ULPI_OTG_CTRL_DRVVBUS_EXT; 201 96 } 202 97 203 - return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL)); 98 + return otg_io_write(otg, flags, ULPI_OTG_CTRL); 204 99 } 205 100 206 101 struct otg_transceiver * ··· 217 112 otg->flags = flags; 218 113 otg->io_ops = ops; 219 114 otg->init = ulpi_init; 115 + otg->set_host = ulpi_set_host; 220 116 otg->set_vbus = ulpi_set_vbus; 221 117 222 118 return otg;
+9
drivers/usb/serial/Kconfig
··· 642 642 To compile this driver as a module, choose M here: the 643 643 module will be called zio. 644 644 645 + config USB_SERIAL_SSU100 646 + tristate "USB Quatech SSU-100 Single Port Serial Driver" 647 + help 648 + Say Y here if you want to use the Quatech SSU-100 single 649 + port usb to serial adapter. 650 + 651 + To compile this driver as a module, choose M here: the 652 + module will be called ssu100. 653 + 645 654 config USB_SERIAL_DEBUG 646 655 tristate "USB Debugging Device" 647 656 help
+1
drivers/usb/serial/Makefile
··· 51 51 obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o 52 52 obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 53 53 obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o 54 + obj-$(CONFIG_USB_SERIAL_SSU100) += ssu100.o 54 55 obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o 55 56 obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o 56 57 obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
+4
drivers/usb/serial/cp210x.c
··· 126 126 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ 127 127 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 128 128 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 129 + { USB_DEVICE(0x16DC, 0x0010) }, /* W-IE-NE-R Plein & Baus GmbH PL512 Power Supply */ 130 + { USB_DEVICE(0x16DC, 0x0011) }, /* W-IE-NE-R Plein & Baus GmbH RCM Remote Control for MARATON Power Supply */ 131 + { USB_DEVICE(0x16DC, 0x0012) }, /* W-IE-NE-R Plein & Baus GmbH MPOD Multi Channel Power Supply */ 132 + { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */ 129 133 { } /* Terminating Entry */ 130 134 }; 131 135
+4
drivers/usb/serial/ftdi_sio.c
··· 157 157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) }, 158 158 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) }, 159 159 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) }, 160 + { USB_DEVICE(FTDI_VID, FTDI_USINT_CAT_PID) }, 161 + { USB_DEVICE(FTDI_VID, FTDI_USINT_WKEY_PID) }, 162 + { USB_DEVICE(FTDI_VID, FTDI_USINT_RS232_PID) }, 160 163 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, 161 164 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 162 165 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, ··· 749 746 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 750 747 { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID), 751 748 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 749 + { USB_DEVICE(FTDI_VID, SEGWAY_RMP200_PID) }, 752 750 { }, /* Optional parameter entry */ 753 751 { } /* Terminating entry */ 754 752 };
+10
drivers/usb/serial/ftdi_sio_ids.h
··· 40 40 41 41 #define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */ 42 42 43 + /* US Interface Navigator (http://www.usinterface.com/) */ 44 + #define FTDI_USINT_CAT_PID 0xb810 /* Navigator CAT and 2nd PTT lines */ 45 + #define FTDI_USINT_WKEY_PID 0xb811 /* Navigator WKEY and FSK lines */ 46 + #define FTDI_USINT_RS232_PID 0xb812 /* Navigator RS232 and CONFIG lines */ 47 + 43 48 /* OOCDlink by Joern Kaipf <joernk@web.de> 44 49 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */ 45 50 #define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */ ··· 1037 1032 #define XVERVE_SIGNALYZER_SH2_PID 0xBCA2 1038 1033 #define XVERVE_SIGNALYZER_SH4_PID 0xBCA4 1039 1034 1035 + /* 1036 + * Segway Robotic Mobility Platform USB interface (using VID 0x0403) 1037 + * Submitted by John G. Rogers 1038 + */ 1039 + #define SEGWAY_RMP200_PID 0xe729
+10 -5
drivers/usb/serial/generic.c
··· 208 208 urb->transfer_buffer_length = count; 209 209 usb_serial_debug_data(debug, &port->dev, __func__, count, 210 210 urb->transfer_buffer); 211 + spin_lock_irqsave(&port->lock, flags); 212 + port->tx_bytes += count; 213 + spin_unlock_irqrestore(&port->lock, flags); 214 + 215 + clear_bit(i, &port->write_urbs_free); 211 216 result = usb_submit_urb(urb, GFP_ATOMIC); 212 217 if (result) { 213 218 dev_err(&port->dev, "%s - error submitting urb: %d\n", 214 219 __func__, result); 220 + set_bit(i, &port->write_urbs_free); 221 + spin_lock_irqsave(&port->lock, flags); 222 + port->tx_bytes -= count; 223 + spin_unlock_irqrestore(&port->lock, flags); 224 + 215 225 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 216 226 return result; 217 227 } 218 - clear_bit(i, &port->write_urbs_free); 219 - 220 - spin_lock_irqsave(&port->lock, flags); 221 - port->tx_bytes += count; 222 - spin_unlock_irqrestore(&port->lock, flags); 223 228 224 229 /* Try sending off another urb, unless in irq context (in which case 225 230 * there will be no free urb). */
+2 -2
drivers/usb/serial/io_ti.c
··· 1298 1298 kfree(header); 1299 1299 kfree(rom_desc); 1300 1300 kfree(ti_manuf_desc); 1301 - return status; 1301 + return -EINVAL; 1302 1302 } 1303 1303 1304 1304 /* verify the write -- must do this in order for ··· 1321 1321 kfree(header); 1322 1322 kfree(rom_desc); 1323 1323 kfree(ti_manuf_desc); 1324 - return status; 1324 + return -EINVAL; 1325 1325 } 1326 1326 1327 1327 kfree(vheader);
-1
drivers/usb/serial/ipaq.c
··· 534 534 { USB_DEVICE(0x413C, 0x4009) }, /* Dell Axim USB Sync */ 535 535 { USB_DEVICE(0x4505, 0x0010) }, /* Smartphone */ 536 536 { USB_DEVICE(0x5E04, 0xCE00) }, /* SAGEM Wireless Assistant */ 537 - { USB_DEVICE(0x0BB4, 0x00CF) }, /* HTC smartphone modems */ 538 537 { } /* Terminating entry */ 539 538 }; 540 539
+41 -13
drivers/usb/serial/iuu_phoenix.c
··· 1 1 /* 2 2 * Infinity Unlimited USB Phoenix driver 3 3 * 4 + * Copyright (C) 2010 James Courtier-Dutton (James@superbug.co.uk) 5 + 4 6 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com) 5 7 * 6 8 * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás) ··· 42 40 /* 43 41 * Version Information 44 42 */ 45 - #define DRIVER_VERSION "v0.11" 43 + #define DRIVER_VERSION "v0.12" 46 44 #define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" 47 45 48 46 static const struct usb_device_id id_table[] = { ··· 83 81 u8 *dbgbuf; /* debug buffer */ 84 82 u8 len; 85 83 int vcc; /* vcc (either 3 or 5 V) */ 84 + u32 baud; 85 + u32 boost; 86 + u32 clk; 86 87 }; 87 88 88 89 ··· 162 157 port->number, set, clear); 163 158 164 159 spin_lock_irqsave(&priv->lock, flags); 165 - if (set & TIOCM_RTS) 166 - priv->tiostatus = TIOCM_RTS; 167 160 168 - if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) { 161 + if ((set & TIOCM_RTS) && !(priv->tiostatus == TIOCM_RTS)) { 169 162 dbg("%s TIOCMSET RESET called !!!", __func__); 170 163 priv->reset = 1; 171 164 } 165 + if (set & TIOCM_RTS) 166 + priv->tiostatus = TIOCM_RTS; 167 + 172 168 spin_unlock_irqrestore(&priv->lock, flags); 173 169 return 0; 174 170 } ··· 857 851 return status; 858 852 } 859 853 860 - static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, 854 + static int iuu_uart_baud(struct usb_serial_port *port, u32 baud_base, 861 855 u32 *actual, u8 parity) 862 856 { 863 857 int status; 858 + u32 baud; 864 859 u8 *dataout; 865 860 u8 DataCount = 0; 866 861 u8 T1Frekvens = 0; 867 862 u8 T1reload = 0; 868 863 unsigned int T1FrekvensHZ = 0; 869 864 865 + dbg("%s - enter baud_base=%d", __func__, baud_base); 870 866 dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL); 871 867 872 868 if (!dataout) 873 869 return -ENOMEM; 870 + /*baud = (((priv->clk / 35) * baud_base) / 100000); */ 871 + baud = baud_base; 874 872 875 873 if (baud < 1200 || baud > 230400) { 876 874 kfree(dataout); ··· 958 948 struct usb_serial_port *port, struct ktermios *old_termios) 959 949 { 960 950 const u32 supported_mask = CMSPAR|PARENB|PARODD; 961 - 951 + struct iuu_private *priv = usb_get_serial_port_data(port); 962 952 unsigned int cflag = tty->termios->c_cflag; 963 953 int status; 964 954 u32 actual; 965 955 u32 parity; 966 956 int csize = CS7; 967 - int baud = 9600; /* Fixed for the moment */ 957 + int baud; 968 958 u32 newval = cflag & supported_mask; 959 + 960 + /* Just use the ospeed. ispeed should be the same. */ 961 + baud = tty->termios->c_ospeed; 962 + 963 + dbg("%s - enter c_ospeed or baud=%d", __func__, baud); 969 964 970 965 /* compute the parity parameter */ 971 966 parity = 0; ··· 991 976 992 977 /* set it */ 993 978 status = iuu_uart_baud(port, 994 - (clockmode == 2) ? 16457 : 9600 * boost / 100, 979 + baud * priv->boost / 100, 995 980 &actual, parity); 996 981 997 982 /* set the termios value to the real one, so the user now what has 998 983 * changed. We support few fields so its easies to copy the old hw 999 984 * settings back over and then adjust them 1000 985 */ 1001 - if (old_termios) 1002 - tty_termios_copy_hw(tty->termios, old_termios); 986 + if (old_termios) 987 + tty_termios_copy_hw(tty->termios, old_termios); 1003 988 if (status != 0) /* Set failed - return old bits */ 1004 989 return; 1005 990 /* Re-encode speed, parity and csize */ ··· 1033 1018 1034 1019 static void iuu_init_termios(struct tty_struct *tty) 1035 1020 { 1021 + dbg("%s - enter", __func__); 1036 1022 *(tty->termios) = tty_std_termios; 1037 1023 tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 1038 1024 | TIOCM_CTS | CSTOPB | PARENB; ··· 1049 1033 struct usb_serial *serial = port->serial; 1050 1034 u8 *buf; 1051 1035 int result; 1036 + int baud; 1052 1037 u32 actual; 1053 1038 struct iuu_private *priv = usb_get_serial_port_data(port); 1054 1039 1055 - dbg("%s - port %d", __func__, port->number); 1040 + baud = tty->termios->c_ospeed; 1041 + tty->termios->c_ispeed = baud; 1042 + /* Re-encode speed */ 1043 + tty_encode_baud_rate(tty, baud, baud); 1044 + 1045 + dbg("%s - port %d, baud %d", __func__, port->number, baud); 1056 1046 usb_clear_halt(serial->dev, port->write_urb->pipe); 1057 1047 usb_clear_halt(serial->dev, port->read_urb->pipe); 1058 1048 ··· 1093 1071 iuu_uart_on(port); 1094 1072 if (boost < 100) 1095 1073 boost = 100; 1074 + priv->boost = boost; 1075 + priv->baud = baud; 1096 1076 switch (clockmode) { 1097 1077 case 2: /* 3.680 Mhz */ 1078 + priv->clk = IUU_CLK_3680000; 1098 1079 iuu_clk(port, IUU_CLK_3680000 * boost / 100); 1099 1080 result = 1100 - iuu_uart_baud(port, 9600 * boost / 100, &actual, 1081 + iuu_uart_baud(port, baud * boost / 100, &actual, 1101 1082 IUU_PARITY_EVEN); 1102 1083 break; 1103 1084 case 3: /* 6.00 Mhz */ 1104 1085 iuu_clk(port, IUU_CLK_6000000 * boost / 100); 1086 + priv->clk = IUU_CLK_6000000; 1087 + /* Ratio of 6000000 to 3500000 for baud 9600 */ 1105 1088 result = 1106 1089 iuu_uart_baud(port, 16457 * boost / 100, &actual, 1107 1090 IUU_PARITY_EVEN); 1108 1091 break; 1109 1092 default: /* 3.579 Mhz */ 1110 1093 iuu_clk(port, IUU_CLK_3579000 * boost / 100); 1094 + priv->clk = IUU_CLK_3579000; 1111 1095 result = 1112 - iuu_uart_baud(port, 9600 * boost / 100, &actual, 1096 + iuu_uart_baud(port, baud * boost / 100, &actual, 1113 1097 IUU_PARITY_EVEN); 1114 1098 } 1115 1099
+13 -4
drivers/usb/serial/option.c
··· 145 145 #define HUAWEI_PRODUCT_E143D 0x143D 146 146 #define HUAWEI_PRODUCT_E143E 0x143E 147 147 #define HUAWEI_PRODUCT_E143F 0x143F 148 + #define HUAWEI_PRODUCT_K4505 0x1464 149 + #define HUAWEI_PRODUCT_K3765 0x1465 148 150 #define HUAWEI_PRODUCT_E14AC 0x14AC 151 + #define HUAWEI_PRODUCT_ETS1220 0x1803 149 152 150 153 #define QUANTA_VENDOR_ID 0x0408 151 154 #define QUANTA_PRODUCT_Q101 0xEA02 ··· 266 263 #define BANDRICH_PRODUCT_1010 0x1010 267 264 #define BANDRICH_PRODUCT_1011 0x1011 268 265 #define BANDRICH_PRODUCT_1012 0x1012 269 - 270 - #define AMOI_VENDOR_ID 0x1614 271 - #define AMOI_PRODUCT_9508 0x0800 272 266 273 267 #define QUALCOMM_VENDOR_ID 0x05C6 274 268 ··· 482 482 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) }, 483 483 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) }, 484 484 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) }, 485 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) }, 486 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) }, 487 + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) }, 485 488 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) }, 486 - { USB_DEVICE(AMOI_VENDOR_ID, AMOI_PRODUCT_9508) }, 487 489 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, /* Novatel Merlin V640/XV620 */ 488 490 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, /* Novatel Merlin V620/S620 */ 489 491 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, /* Novatel Merlin EX720/V740/X720 */ ··· 1017 1015 if ((serial->dev->descriptor.idVendor == BANDRICH_VENDOR_ID || 1018 1016 serial->dev->descriptor.idVendor == PIRELLI_VENDOR_ID) && 1019 1017 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) 1018 + return -ENODEV; 1019 + 1020 + /* Don't bind network interfaces on Huawei K3765 & K4505 */ 1021 + if (serial->dev->descriptor.idVendor == HUAWEI_VENDOR_ID && 1022 + (serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K3765 || 1023 + serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505) && 1024 + serial->interface->cur_altsetting->desc.bInterfaceNumber == 1) 1020 1025 return -ENODEV; 1021 1026 1022 1027 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
+698
drivers/usb/serial/ssu100.c
··· 1 + /* 2 + * usb-serial driver for Quatech SSU-100 3 + * 4 + * based on ftdi_sio.c and the original serqt_usb.c from Quatech 5 + * 6 + */ 7 + 8 + #include <linux/errno.h> 9 + #include <linux/init.h> 10 + #include <linux/slab.h> 11 + #include <linux/tty.h> 12 + #include <linux/tty_driver.h> 13 + #include <linux/tty_flip.h> 14 + #include <linux/module.h> 15 + #include <linux/serial.h> 16 + #include <linux/usb.h> 17 + #include <linux/usb/serial.h> 18 + #include <linux/uaccess.h> 19 + 20 + #define QT_OPEN_CLOSE_CHANNEL 0xca 21 + #define QT_SET_GET_DEVICE 0xc2 22 + #define QT_SET_GET_REGISTER 0xc0 23 + #define QT_GET_SET_PREBUF_TRIG_LVL 0xcc 24 + #define QT_SET_ATF 0xcd 25 + #define QT_GET_SET_UART 0xc1 26 + #define QT_TRANSFER_IN 0xc0 27 + #define QT_HW_FLOW_CONTROL_MASK 0xc5 28 + #define QT_SW_FLOW_CONTROL_MASK 0xc6 29 + 30 + #define MODEM_CTL_REGISTER 0x04 31 + #define MODEM_STATUS_REGISTER 0x06 32 + 33 + 34 + #define SERIAL_LSR_OE 0x02 35 + #define SERIAL_LSR_PE 0x04 36 + #define SERIAL_LSR_FE 0x08 37 + #define SERIAL_LSR_BI 0x10 38 + 39 + #define SERIAL_LSR_TEMT 0x40 40 + 41 + #define SERIAL_MCR_DTR 0x01 42 + #define SERIAL_MCR_RTS 0x02 43 + #define SERIAL_MCR_LOOP 0x10 44 + 45 + #define SERIAL_MSR_CTS 0x10 46 + #define SERIAL_MSR_CD 0x80 47 + #define SERIAL_MSR_RI 0x40 48 + #define SERIAL_MSR_DSR 0x20 49 + #define SERIAL_MSR_MASK 0xf0 50 + 51 + #define SERIAL_CRTSCTS ((SERIAL_MCR_RTS << 8) | SERIAL_MSR_CTS) 52 + 53 + #define SERIAL_8_DATA 0x03 54 + #define SERIAL_7_DATA 0x02 55 + #define SERIAL_6_DATA 0x01 56 + #define SERIAL_5_DATA 0x00 57 + 58 + #define SERIAL_ODD_PARITY 0X08 59 + #define SERIAL_EVEN_PARITY 0X18 60 + 61 + #define MAX_BAUD_RATE 460800 62 + 63 + #define ATC_DISABLED 0x00 64 + #define DUPMODE_BITS 0xc0 65 + #define RR_BITS 0x03 66 + #define LOOPMODE_BITS 0x41 67 + #define RS232_MODE 0x00 68 + #define RTSCTS_TO_CONNECTOR 0x40 69 + #define CLKS_X4 0x02 70 + #define FULLPWRBIT 0x00000080 71 + #define NEXT_BOARD_POWER_BIT 0x00000004 72 + 73 + static int debug = 1; 74 + 75 + /* Version Information */ 76 + #define DRIVER_VERSION "v0.1" 77 + #define DRIVER_DESC "Quatech SSU-100 USB to Serial Driver" 78 + 79 + #define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */ 80 + #define QUATECH_SSU100 0xC020 /* SSU100 */ 81 + 82 + static const struct usb_device_id id_table[] = { 83 + {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU100)}, 84 + {} /* Terminating entry */ 85 + }; 86 + 87 + MODULE_DEVICE_TABLE(usb, id_table); 88 + 89 + 90 + static struct usb_driver ssu100_driver = { 91 + .name = "ssu100", 92 + .probe = usb_serial_probe, 93 + .disconnect = usb_serial_disconnect, 94 + .id_table = id_table, 95 + .suspend = usb_serial_suspend, 96 + .resume = usb_serial_resume, 97 + .no_dynamic_id = 1, 98 + .supports_autosuspend = 1, 99 + }; 100 + 101 + struct ssu100_port_private { 102 + u8 shadowLSR; 103 + u8 shadowMSR; 104 + wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 105 + unsigned short max_packet_size; 106 + }; 107 + 108 + static void ssu100_release(struct usb_serial *serial) 109 + { 110 + struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port); 111 + 112 + dbg("%s", __func__); 113 + kfree(priv); 114 + } 115 + 116 + static inline int ssu100_control_msg(struct usb_device *dev, 117 + u8 request, u16 data, u16 index) 118 + { 119 + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 120 + request, 0x40, data, index, 121 + NULL, 0, 300); 122 + } 123 + 124 + static inline int ssu100_setdevice(struct usb_device *dev, u8 *data) 125 + { 126 + u16 x = ((u16)(data[1] << 8) | (u16)(data[0])); 127 + 128 + return ssu100_control_msg(dev, QT_SET_GET_DEVICE, x, 0); 129 + } 130 + 131 + 132 + static inline int ssu100_getdevice(struct usb_device *dev, u8 *data) 133 + { 134 + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 135 + QT_SET_GET_DEVICE, 0xc0, 0, 0, 136 + data, 3, 300); 137 + } 138 + 139 + static inline int ssu100_getregister(struct usb_device *dev, 140 + unsigned short uart, 141 + unsigned short reg, 142 + u8 *data) 143 + { 144 + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 145 + QT_SET_GET_REGISTER, 0xc0, reg, 146 + uart, data, sizeof(*data), 300); 147 + 148 + } 149 + 150 + 151 + static inline int ssu100_setregister(struct usb_device *dev, 152 + unsigned short uart, 153 + u16 data) 154 + { 155 + u16 value = (data << 8) | MODEM_CTL_REGISTER; 156 + 157 + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 158 + QT_SET_GET_REGISTER, 0x40, value, uart, 159 + NULL, 0, 300); 160 + 161 + } 162 + 163 + #define set_mctrl(dev, set) update_mctrl((dev), (set), 0) 164 + #define clear_mctrl(dev, clear) update_mctrl((dev), 0, (clear)) 165 + 166 + /* these do not deal with device that have more than 1 port */ 167 + static inline int update_mctrl(struct usb_device *dev, unsigned int set, 168 + unsigned int clear) 169 + { 170 + unsigned urb_value; 171 + int result; 172 + 173 + if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) { 174 + dbg("%s - DTR|RTS not being set|cleared", __func__); 175 + return 0; /* no change */ 176 + } 177 + 178 + clear &= ~set; /* 'set' takes precedence over 'clear' */ 179 + urb_value = 0; 180 + if (set & TIOCM_DTR) 181 + urb_value |= SERIAL_MCR_DTR; 182 + if (set & TIOCM_RTS) 183 + urb_value |= SERIAL_MCR_RTS; 184 + 185 + result = ssu100_setregister(dev, 0, urb_value); 186 + if (result < 0) 187 + dbg("%s Error from MODEM_CTRL urb", __func__); 188 + 189 + return result; 190 + } 191 + 192 + static int ssu100_initdevice(struct usb_device *dev) 193 + { 194 + u8 *data; 195 + int result = 0; 196 + 197 + dbg("%s", __func__); 198 + 199 + data = kzalloc(3, GFP_KERNEL); 200 + if (!data) 201 + return -ENOMEM; 202 + 203 + result = ssu100_getdevice(dev, data); 204 + if (result < 0) { 205 + dbg("%s - get_device failed %i", __func__, result); 206 + goto out; 207 + } 208 + 209 + data[1] &= ~FULLPWRBIT; 210 + 211 + result = ssu100_setdevice(dev, data); 212 + if (result < 0) { 213 + dbg("%s - setdevice failed %i", __func__, result); 214 + goto out; 215 + } 216 + 217 + result = ssu100_control_msg(dev, QT_GET_SET_PREBUF_TRIG_LVL, 128, 0); 218 + if (result < 0) { 219 + dbg("%s - set prebuffer level failed %i", __func__, result); 220 + goto out; 221 + } 222 + 223 + result = ssu100_control_msg(dev, QT_SET_ATF, ATC_DISABLED, 0); 224 + if (result < 0) { 225 + dbg("%s - set ATFprebuffer level failed %i", __func__, result); 226 + goto out; 227 + } 228 + 229 + result = ssu100_getdevice(dev, data); 230 + if (result < 0) { 231 + dbg("%s - get_device failed %i", __func__, result); 232 + goto out; 233 + } 234 + 235 + data[0] &= ~(RR_BITS | DUPMODE_BITS); 236 + data[0] |= CLKS_X4; 237 + data[1] &= ~(LOOPMODE_BITS); 238 + data[1] |= RS232_MODE; 239 + 240 + result = ssu100_setdevice(dev, data); 241 + if (result < 0) { 242 + dbg("%s - setdevice failed %i", __func__, result); 243 + goto out; 244 + } 245 + 246 + out: kfree(data); 247 + return result; 248 + 249 + } 250 + 251 + 252 + static void ssu100_set_termios(struct tty_struct *tty, 253 + struct usb_serial_port *port, 254 + struct ktermios *old_termios) 255 + { 256 + struct usb_device *dev = port->serial->dev; 257 + struct ktermios *termios = tty->termios; 258 + u16 baud, divisor, remainder; 259 + unsigned int cflag = termios->c_cflag; 260 + u16 urb_value = 0; /* will hold the new flags */ 261 + int result; 262 + 263 + dbg("%s", __func__); 264 + 265 + if (cflag & PARENB) { 266 + if (cflag & PARODD) 267 + urb_value |= SERIAL_ODD_PARITY; 268 + else 269 + urb_value |= SERIAL_EVEN_PARITY; 270 + } 271 + 272 + switch (cflag & CSIZE) { 273 + case CS5: 274 + urb_value |= SERIAL_5_DATA; 275 + break; 276 + case CS6: 277 + urb_value |= SERIAL_6_DATA; 278 + break; 279 + case CS7: 280 + urb_value |= SERIAL_7_DATA; 281 + break; 282 + default: 283 + case CS8: 284 + urb_value |= SERIAL_8_DATA; 285 + break; 286 + } 287 + 288 + baud = tty_get_baud_rate(tty); 289 + if (!baud) 290 + baud = 9600; 291 + 292 + dbg("%s - got baud = %d\n", __func__, baud); 293 + 294 + 295 + divisor = MAX_BAUD_RATE / baud; 296 + remainder = MAX_BAUD_RATE % baud; 297 + if (((remainder * 2) >= baud) && (baud != 110)) 298 + divisor++; 299 + 300 + urb_value = urb_value << 8; 301 + 302 + result = ssu100_control_msg(dev, QT_GET_SET_UART, divisor, urb_value); 303 + if (result < 0) 304 + dbg("%s - set uart failed", __func__); 305 + 306 + if (cflag & CRTSCTS) 307 + result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK, 308 + SERIAL_CRTSCTS, 0); 309 + else 310 + result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK, 311 + 0, 0); 312 + if (result < 0) 313 + dbg("%s - set HW flow control failed", __func__); 314 + 315 + if (I_IXOFF(tty) || I_IXON(tty)) { 316 + u16 x = ((u16)(START_CHAR(tty) << 8) | (u16)(STOP_CHAR(tty))); 317 + 318 + result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK, 319 + x, 0); 320 + } else 321 + result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK, 322 + 0, 0); 323 + 324 + if (result < 0) 325 + dbg("%s - set SW flow control failed", __func__); 326 + 327 + } 328 + 329 + 330 + static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port) 331 + { 332 + struct usb_device *dev = port->serial->dev; 333 + struct ssu100_port_private *priv = usb_get_serial_port_data(port); 334 + u8 *data; 335 + int result; 336 + 337 + dbg("%s - port %d", __func__, port->number); 338 + 339 + data = kzalloc(2, GFP_KERNEL); 340 + if (!data) 341 + return -ENOMEM; 342 + 343 + result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 344 + QT_OPEN_CLOSE_CHANNEL, 345 + QT_TRANSFER_IN, 0x01, 346 + 0, data, 2, 300); 347 + if (result < 0) { 348 + dbg("%s - open failed %i", __func__, result); 349 + kfree(data); 350 + return result; 351 + } 352 + 353 + priv->shadowLSR = data[0] & (SERIAL_LSR_OE | SERIAL_LSR_PE | 354 + SERIAL_LSR_FE | SERIAL_LSR_BI); 355 + 356 + priv->shadowMSR = data[1] & (SERIAL_MSR_CTS | SERIAL_MSR_DSR | 357 + SERIAL_MSR_RI | SERIAL_MSR_CD); 358 + 359 + kfree(data); 360 + 361 + /* set to 9600 */ 362 + result = ssu100_control_msg(dev, QT_GET_SET_UART, 0x30, 0x0300); 363 + if (result < 0) 364 + dbg("%s - set uart failed", __func__); 365 + 366 + if (tty) 367 + ssu100_set_termios(tty, port, tty->termios); 368 + 369 + return usb_serial_generic_open(tty, port); 370 + } 371 + 372 + static void ssu100_close(struct usb_serial_port *port) 373 + { 374 + dbg("%s", __func__); 375 + usb_serial_generic_close(port); 376 + } 377 + 378 + static int get_serial_info(struct usb_serial_port *port, 379 + struct serial_struct __user *retinfo) 380 + { 381 + struct serial_struct tmp; 382 + 383 + if (!retinfo) 384 + return -EFAULT; 385 + 386 + memset(&tmp, 0, sizeof(tmp)); 387 + tmp.line = port->serial->minor; 388 + tmp.port = 0; 389 + tmp.irq = 0; 390 + tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ; 391 + tmp.xmit_fifo_size = port->bulk_out_size; 392 + tmp.baud_base = 9600; 393 + tmp.close_delay = 5*HZ; 394 + tmp.closing_wait = 30*HZ; 395 + 396 + if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 397 + return -EFAULT; 398 + return 0; 399 + } 400 + 401 + static int ssu100_ioctl(struct tty_struct *tty, struct file *file, 402 + unsigned int cmd, unsigned long arg) 403 + { 404 + struct usb_serial_port *port = tty->driver_data; 405 + struct ssu100_port_private *priv = usb_get_serial_port_data(port); 406 + 407 + dbg("%s cmd 0x%04x", __func__, cmd); 408 + 409 + switch (cmd) { 410 + case TIOCGSERIAL: 411 + return get_serial_info(port, 412 + (struct serial_struct __user *) arg); 413 + 414 + case TIOCMIWAIT: 415 + while (priv != NULL) { 416 + u8 prevMSR = priv->shadowMSR & SERIAL_MSR_MASK; 417 + interruptible_sleep_on(&priv->delta_msr_wait); 418 + /* see if a signal did it */ 419 + if (signal_pending(current)) 420 + return -ERESTARTSYS; 421 + else { 422 + u8 diff = (priv->shadowMSR & SERIAL_MSR_MASK) ^ prevMSR; 423 + if (!diff) 424 + return -EIO; /* no change => error */ 425 + 426 + /* Return 0 if caller wanted to know about 427 + these bits */ 428 + 429 + if (((arg & TIOCM_RNG) && (diff & SERIAL_MSR_RI)) || 430 + ((arg & TIOCM_DSR) && (diff & SERIAL_MSR_DSR)) || 431 + ((arg & TIOCM_CD) && (diff & SERIAL_MSR_CD)) || 432 + ((arg & TIOCM_CTS) && (diff & SERIAL_MSR_CTS))) 433 + return 0; 434 + } 435 + } 436 + return 0; 437 + 438 + default: 439 + break; 440 + } 441 + 442 + dbg("%s arg not supported", __func__); 443 + 444 + return -ENOIOCTLCMD; 445 + } 446 + 447 + static void ssu100_set_max_packet_size(struct usb_serial_port *port) 448 + { 449 + struct ssu100_port_private *priv = usb_get_serial_port_data(port); 450 + struct usb_serial *serial = port->serial; 451 + struct usb_device *udev = serial->dev; 452 + 453 + struct usb_interface *interface = serial->interface; 454 + struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc; 455 + 456 + unsigned num_endpoints; 457 + int i; 458 + 459 + num_endpoints = interface->cur_altsetting->desc.bNumEndpoints; 460 + dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints); 461 + 462 + for (i = 0; i < num_endpoints; i++) { 463 + dev_info(&udev->dev, "Endpoint %d MaxPacketSize %d\n", i+1, 464 + interface->cur_altsetting->endpoint[i].desc.wMaxPacketSize); 465 + ep_desc = &interface->cur_altsetting->endpoint[i].desc; 466 + } 467 + 468 + /* set max packet size based on descriptor */ 469 + priv->max_packet_size = ep_desc->wMaxPacketSize; 470 + 471 + dev_info(&udev->dev, "Setting MaxPacketSize %d\n", priv->max_packet_size); 472 + } 473 + 474 + static int ssu100_attach(struct usb_serial *serial) 475 + { 476 + struct ssu100_port_private *priv; 477 + struct usb_serial_port *port = *serial->port; 478 + 479 + dbg("%s", __func__); 480 + 481 + priv = kzalloc(sizeof(*priv), GFP_KERNEL); 482 + if (!priv) { 483 + dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__, 484 + sizeof(*priv)); 485 + return -ENOMEM; 486 + } 487 + 488 + init_waitqueue_head(&priv->delta_msr_wait); 489 + usb_set_serial_port_data(port, priv); 490 + 491 + ssu100_set_max_packet_size(port); 492 + 493 + return ssu100_initdevice(serial->dev); 494 + } 495 + 496 + static int ssu100_tiocmget(struct tty_struct *tty, struct file *file) 497 + { 498 + struct usb_serial_port *port = tty->driver_data; 499 + struct usb_device *dev = port->serial->dev; 500 + u8 *d; 501 + int r; 502 + 503 + dbg("%s\n", __func__); 504 + 505 + d = kzalloc(2, GFP_KERNEL); 506 + if (!d) 507 + return -ENOMEM; 508 + 509 + r = ssu100_getregister(dev, 0, MODEM_CTL_REGISTER, d); 510 + if (r < 0) 511 + goto mget_out; 512 + 513 + r = ssu100_getregister(dev, 0, MODEM_STATUS_REGISTER, d+1); 514 + if (r < 0) 515 + goto mget_out; 516 + 517 + r = (d[0] & SERIAL_MCR_DTR ? TIOCM_DTR : 0) | 518 + (d[0] & SERIAL_MCR_RTS ? TIOCM_RTS : 0) | 519 + (d[1] & SERIAL_MSR_CTS ? TIOCM_CTS : 0) | 520 + (d[1] & SERIAL_MSR_CD ? TIOCM_CAR : 0) | 521 + (d[1] & SERIAL_MSR_RI ? TIOCM_RI : 0) | 522 + (d[1] & SERIAL_MSR_DSR ? TIOCM_DSR : 0); 523 + 524 + mget_out: 525 + kfree(d); 526 + return r; 527 + } 528 + 529 + static int ssu100_tiocmset(struct tty_struct *tty, struct file *file, 530 + unsigned int set, unsigned int clear) 531 + { 532 + struct usb_serial_port *port = tty->driver_data; 533 + struct usb_device *dev = port->serial->dev; 534 + 535 + dbg("%s\n", __func__); 536 + return update_mctrl(dev, set, clear); 537 + } 538 + 539 + static void ssu100_dtr_rts(struct usb_serial_port *port, int on) 540 + { 541 + struct usb_device *dev = port->serial->dev; 542 + 543 + dbg("%s\n", __func__); 544 + 545 + mutex_lock(&port->serial->disc_mutex); 546 + if (!port->serial->disconnected) { 547 + /* Disable flow control */ 548 + if (!on && 549 + ssu100_setregister(dev, 0, 0) < 0) 550 + dev_err(&port->dev, "error from flowcontrol urb\n"); 551 + /* drop RTS and DTR */ 552 + if (on) 553 + set_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 554 + else 555 + clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS); 556 + } 557 + mutex_unlock(&port->serial->disc_mutex); 558 + } 559 + 560 + static int ssu100_process_packet(struct tty_struct *tty, 561 + struct usb_serial_port *port, 562 + struct ssu100_port_private *priv, 563 + char *packet, int len) 564 + { 565 + int i; 566 + char flag; 567 + char *ch; 568 + 569 + dbg("%s - port %d", __func__, port->number); 570 + 571 + if (len < 4) { 572 + dbg("%s - malformed packet", __func__); 573 + return 0; 574 + } 575 + 576 + if ((packet[0] == 0x1b) && (packet[1] == 0x1b) && 577 + ((packet[2] == 0x00) || (packet[2] == 0x01))) { 578 + if (packet[2] == 0x00) 579 + priv->shadowLSR = packet[3] & (SERIAL_LSR_OE | 580 + SERIAL_LSR_PE | 581 + SERIAL_LSR_FE | 582 + SERIAL_LSR_BI); 583 + 584 + if (packet[2] == 0x01) { 585 + priv->shadowMSR = packet[3]; 586 + wake_up_interruptible(&priv->delta_msr_wait); 587 + } 588 + 589 + len -= 4; 590 + ch = packet + 4; 591 + } else 592 + ch = packet; 593 + 594 + if (!len) 595 + return 0; /* status only */ 596 + 597 + if (port->port.console && port->sysrq) { 598 + for (i = 0; i < len; i++, ch++) { 599 + if (!usb_serial_handle_sysrq_char(tty, port, *ch)) 600 + tty_insert_flip_char(tty, *ch, flag); 601 + } 602 + } else 603 + tty_insert_flip_string_fixed_flag(tty, ch, flag, len); 604 + 605 + return len; 606 + } 607 + 608 + static void ssu100_process_read_urb(struct urb *urb) 609 + { 610 + struct usb_serial_port *port = urb->context; 611 + struct ssu100_port_private *priv = usb_get_serial_port_data(port); 612 + char *data = (char *)urb->transfer_buffer; 613 + struct tty_struct *tty; 614 + int count = 0; 615 + int i; 616 + int len; 617 + 618 + dbg("%s", __func__); 619 + 620 + tty = tty_port_tty_get(&port->port); 621 + if (!tty) 622 + return; 623 + 624 + for (i = 0; i < urb->actual_length; i += priv->max_packet_size) { 625 + len = min_t(int, urb->actual_length - i, priv->max_packet_size); 626 + count += ssu100_process_packet(tty, port, priv, &data[i], len); 627 + } 628 + 629 + if (count) 630 + tty_flip_buffer_push(tty); 631 + tty_kref_put(tty); 632 + } 633 + 634 + 635 + static struct usb_serial_driver ssu100_device = { 636 + .driver = { 637 + .owner = THIS_MODULE, 638 + .name = "ssu100", 639 + }, 640 + .description = DRIVER_DESC, 641 + .id_table = id_table, 642 + .usb_driver = &ssu100_driver, 643 + .num_ports = 1, 644 + .bulk_in_size = 256, 645 + .bulk_out_size = 256, 646 + .open = ssu100_open, 647 + .close = ssu100_close, 648 + .attach = ssu100_attach, 649 + .release = ssu100_release, 650 + .dtr_rts = ssu100_dtr_rts, 651 + .process_read_urb = ssu100_process_read_urb, 652 + .tiocmget = ssu100_tiocmget, 653 + .tiocmset = ssu100_tiocmset, 654 + .ioctl = ssu100_ioctl, 655 + .set_termios = ssu100_set_termios, 656 + }; 657 + 658 + static int __init ssu100_init(void) 659 + { 660 + int retval; 661 + 662 + dbg("%s", __func__); 663 + 664 + /* register with usb-serial */ 665 + retval = usb_serial_register(&ssu100_device); 666 + 667 + if (retval) 668 + goto failed_usb_sio_register; 669 + 670 + retval = usb_register(&ssu100_driver); 671 + if (retval) 672 + goto failed_usb_register; 673 + 674 + printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 675 + DRIVER_DESC "\n"); 676 + 677 + return 0; 678 + 679 + failed_usb_register: 680 + usb_serial_deregister(&ssu100_device); 681 + failed_usb_sio_register: 682 + return retval; 683 + } 684 + 685 + static void __exit ssu100_exit(void) 686 + { 687 + usb_deregister(&ssu100_driver); 688 + usb_serial_deregister(&ssu100_device); 689 + } 690 + 691 + module_init(ssu100_init); 692 + module_exit(ssu100_exit); 693 + 694 + MODULE_DESCRIPTION(DRIVER_DESC); 695 + MODULE_LICENSE("GPL"); 696 + 697 + module_param(debug, bool, S_IRUGO | S_IWUSR); 698 + MODULE_PARM_DESC(debug, "Debug enabled or not");
+16 -16
drivers/usb/serial/usb-serial.c
··· 653 653 return id; 654 654 } 655 655 656 + /* Caller must hold table_lock */ 656 657 static struct usb_serial_driver *search_serial_device( 657 658 struct usb_interface *iface) 658 659 { ··· 719 718 int num_ports = 0; 720 719 int max_endpoints; 721 720 722 - lock_kernel(); /* guard against unloading a serial driver module */ 721 + mutex_lock(&table_lock); 723 722 type = search_serial_device(interface); 724 723 if (!type) { 725 - unlock_kernel(); 724 + mutex_unlock(&table_lock); 726 725 dbg("none matched"); 727 726 return -ENODEV; 728 727 } 729 728 729 + if (!try_module_get(type->driver.owner)) { 730 + mutex_unlock(&table_lock); 731 + dev_err(&interface->dev, "module get failed, exiting\n"); 732 + return -EIO; 733 + } 734 + mutex_unlock(&table_lock); 735 + 730 736 serial = create_serial(dev, interface, type); 731 737 if (!serial) { 732 - unlock_kernel(); 733 738 dev_err(&interface->dev, "%s - out of memory\n", __func__); 734 739 return -ENOMEM; 735 740 } ··· 744 737 if (type->probe) { 745 738 const struct usb_device_id *id; 746 739 747 - if (!try_module_get(type->driver.owner)) { 748 - unlock_kernel(); 749 - dev_err(&interface->dev, 750 - "module get failed, exiting\n"); 751 - kfree(serial); 752 - return -EIO; 753 - } 754 - 755 740 id = get_iface_id(type, interface); 756 741 retval = type->probe(serial, id); 757 742 module_put(type->driver.owner); 758 743 759 744 if (retval) { 760 - unlock_kernel(); 761 745 dbg("sub driver rejected device"); 762 746 kfree(serial); 763 747 return retval; ··· 820 822 * properly during a later invocation of usb_serial_probe 821 823 */ 822 824 if (num_bulk_in == 0 || num_bulk_out == 0) { 823 - unlock_kernel(); 824 825 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 825 826 kfree(serial); 826 827 return -ENODEV; ··· 832 835 if (type == &usb_serial_generic_device) { 833 836 num_ports = num_bulk_out; 834 837 if (num_ports == 0) { 835 - unlock_kernel(); 836 838 dev_err(&interface->dev, 837 839 "Generic device with no bulk out, not allowed.\n"); 838 840 kfree(serial); ··· 843 847 /* if this device type has a calc_num_ports function, call it */ 844 848 if (type->calc_num_ports) { 845 849 if (!try_module_get(type->driver.owner)) { 846 - unlock_kernel(); 847 850 dev_err(&interface->dev, 848 851 "module get failed, exiting\n"); 849 852 kfree(serial); ··· 873 878 max_endpoints = max(max_endpoints, num_interrupt_out); 874 879 max_endpoints = max(max_endpoints, (int)serial->num_ports); 875 880 serial->num_port_pointers = max_endpoints; 876 - unlock_kernel(); 877 881 878 882 dbg("%s - setting up %d port structures for this device", 879 883 __func__, max_endpoints); ··· 1071 1077 dev_set_name(&port->dev, "ttyUSB%d", port->number); 1072 1078 dbg ("%s - registering %s", __func__, dev_name(&port->dev)); 1073 1079 port->dev_state = PORT_REGISTERING; 1080 + device_enable_async_suspend(&port->dev); 1081 + 1074 1082 retval = device_add(&port->dev); 1075 1083 if (retval) { 1076 1084 dev_err(&port->dev, "Error registering port device, " ··· 1345 1349 driver->description = driver->driver.name; 1346 1350 1347 1351 /* Add this device to our list of devices */ 1352 + mutex_lock(&table_lock); 1348 1353 list_add(&driver->driver_list, &usb_serial_driver_list); 1349 1354 1350 1355 retval = usb_serial_bus_register(driver); ··· 1357 1360 printk(KERN_INFO "USB Serial support registered for %s\n", 1358 1361 driver->description); 1359 1362 1363 + mutex_unlock(&table_lock); 1360 1364 return retval; 1361 1365 } 1362 1366 EXPORT_SYMBOL_GPL(usb_serial_register); ··· 1368 1370 /* must be called with BKL held */ 1369 1371 printk(KERN_INFO "USB Serial deregistering driver %s\n", 1370 1372 device->description); 1373 + mutex_lock(&table_lock); 1371 1374 list_del(&device->driver_list); 1372 1375 usb_serial_bus_deregister(device); 1376 + mutex_unlock(&table_lock); 1373 1377 } 1374 1378 EXPORT_SYMBOL_GPL(usb_serial_deregister); 1375 1379
+11 -12
drivers/usb/storage/freecom.c
··· 269 269 /* The firmware will time-out commands after 20 seconds. Some commands 270 270 * can legitimately take longer than this, so we use a different 271 271 * command that only waits for the interrupt and then sends status, 272 - * without having to send a new ATAPI command to the device. 272 + * without having to send a new ATAPI command to the device. 273 273 * 274 274 * NOTE: There is some indication that a data transfer after a timeout 275 275 * may not work, but that is a condition that should never happen. ··· 324 324 325 325 /* Find the length we desire to read. */ 326 326 switch (srb->cmnd[0]) { 327 - case INQUIRY: 328 - case REQUEST_SENSE: /* 16 or 18 bytes? spec says 18, lots of devices only have 16 */ 329 - case MODE_SENSE: 330 - case MODE_SENSE_10: 331 - length = le16_to_cpu(fst->Count); 332 - break; 333 - default: 334 - length = scsi_bufflen(srb); 327 + case INQUIRY: 328 + case REQUEST_SENSE: /* 16 or 18 bytes? spec says 18, lots of devices only have 16 */ 329 + case MODE_SENSE: 330 + case MODE_SENSE_10: 331 + length = le16_to_cpu(fst->Count); 332 + break; 333 + default: 334 + length = scsi_bufflen(srb); 335 335 } 336 336 337 337 /* verify that this amount is legal */ ··· 414 414 /* should never hit here -- filtered in usb.c */ 415 415 US_DEBUGP ("freecom unimplemented direction: %d\n", 416 416 us->srb->sc_data_direction); 417 - // Return fail, SCSI seems to handle this better. 417 + /* Return fail, SCSI seems to handle this better. */ 418 418 return USB_STOR_TRANSPORT_FAILED; 419 419 break; 420 420 } ··· 494 494 offset = 0; 495 495 } 496 496 offset += sprintf (line+offset, "%08x:", i); 497 - } 498 - else if ((i & 7) == 0) { 497 + } else if ((i & 7) == 0) { 499 498 offset += sprintf (line+offset, " -"); 500 499 } 501 500 offset += sprintf (line+offset, " %02x", buffer[i] & 0xff);
+1 -2
drivers/usb/storage/isd200.c
··· 1456 1456 int retStatus = ISD200_GOOD; 1457 1457 struct isd200_info *info; 1458 1458 1459 - info = (struct isd200_info *) 1460 - kzalloc(sizeof(struct isd200_info), GFP_KERNEL); 1459 + info = kzalloc(sizeof(struct isd200_info), GFP_KERNEL); 1461 1460 if (!info) 1462 1461 retStatus = ISD200_ERROR; 1463 1462 else {
+4
drivers/usb/storage/usb.c
··· 336 336 else { 337 337 US_DEBUG(usb_stor_show_command(us->srb)); 338 338 us->proto_handler(us->srb, us); 339 + usb_mark_last_busy(us->pusb_dev); 339 340 } 340 341 341 342 /* lock access to the state */ ··· 846 845 /* Should we unbind if no devices were detected? */ 847 846 } 848 847 848 + usb_autopm_put_interface(us->pusb_intf); 849 849 complete_and_exit(&us->scanning_done, 0); 850 850 } 851 851 ··· 970 968 goto BadDevice; 971 969 } 972 970 971 + usb_autopm_get_interface_no_resume(us->pusb_intf); 973 972 wake_up_process(th); 974 973 975 974 return 0; ··· 1043 1040 .pre_reset = usb_stor_pre_reset, 1044 1041 .post_reset = usb_stor_post_reset, 1045 1042 .id_table = usb_storage_usb_ids, 1043 + .supports_autosuspend = 1, 1046 1044 .soft_unbind = 1, 1047 1045 }; 1048 1046
+4 -4
drivers/usb/usb-skeleton.c
··· 142 142 { 143 143 struct usb_skel *dev; 144 144 145 - dev = (struct usb_skel *)file->private_data; 145 + dev = file->private_data; 146 146 if (dev == NULL) 147 147 return -ENODEV; 148 148 ··· 162 162 struct usb_skel *dev; 163 163 int res; 164 164 165 - dev = (struct usb_skel *)file->private_data; 165 + dev = file->private_data; 166 166 if (dev == NULL) 167 167 return -ENODEV; 168 168 ··· 246 246 int rv; 247 247 bool ongoing_io; 248 248 249 - dev = (struct usb_skel *)file->private_data; 249 + dev = file->private_data; 250 250 251 251 /* if we cannot read at all, return EOF */ 252 252 if (!dev->bulk_in_urb || !count) ··· 401 401 char *buf = NULL; 402 402 size_t writesize = min(count, (size_t)MAX_TRANSFER); 403 403 404 - dev = (struct usb_skel *)file->private_data; 404 + dev = file->private_data; 405 405 406 406 /* verify that we actually have some data to write */ 407 407 if (count == 0)
+4 -1
include/linux/usb.h
··· 127 127 * queued reset so that usb_cancel_queued_reset() doesn't try to 128 128 * remove from the workqueue when running inside the worker 129 129 * thread. See __usb_queue_reset_device(). 130 + * @resetting_device: USB core reset the device, so use alt setting 0 as 131 + * current; needs bandwidth alloc after reset. 130 132 * 131 133 * USB device drivers attach to interfaces on a physical device. Each 132 134 * interface encapsulates a single high level function, such as feeding ··· 845 843 846 844 void (*disconnect) (struct usb_interface *intf); 847 845 848 - int (*ioctl) (struct usb_interface *intf, unsigned int code, 846 + int (*unlocked_ioctl) (struct usb_interface *intf, unsigned int code, 849 847 void *buf); 850 848 851 849 int (*suspend) (struct usb_interface *intf, pm_message_t message); ··· 1017 1015 * is a different endpoint (and pipe) from "out" endpoint two. 1018 1016 * The current configuration controls the existence, type, and 1019 1017 * maximum packet size of any given endpoint. 1018 + * @stream_id: the endpoint's stream ID for bulk streams 1020 1019 * @dev: Identifies the USB device to perform the request. 1021 1020 * @status: This is read in non-iso completion functions to get the 1022 1021 * status of the particular request. ISO requests only use it
+6
include/linux/usb/composite.h
··· 276 276 int (*bind)(struct usb_composite_dev *); 277 277 int (*unbind)(struct usb_composite_dev *); 278 278 279 + void (*disconnect)(struct usb_composite_dev *); 280 + 279 281 /* global suspend hooks */ 280 282 void (*suspend)(struct usb_composite_dev *); 281 283 void (*resume)(struct usb_composite_dev *); ··· 344 342 }; 345 343 346 344 extern int usb_string_id(struct usb_composite_dev *c); 345 + extern int usb_string_ids_tab(struct usb_composite_dev *c, 346 + struct usb_string *str); 347 + extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n); 348 + 347 349 348 350 /* messaging utils */ 349 351 #define DBG(d, fmt, args...) \
+23
include/linux/usb/ehci_def.h
··· 39 39 #define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */ 40 40 41 41 u32 hcc_params; /* HCCPARAMS - offset 0x8 */ 42 + /* EHCI 1.1 addendum */ 43 + #define HCC_32FRAME_PERIODIC_LIST(p) ((p)&(1 << 19)) 44 + #define HCC_PER_PORT_CHANGE_EVENT(p) ((p)&(1 << 18)) 45 + #define HCC_LPM(p) ((p)&(1 << 17)) 46 + #define HCC_HW_PREFETCH(p) ((p)&(1 << 16)) 47 + 42 48 #define HCC_EXT_CAPS(p) (((p)>>8)&0xff) /* for pci extended caps */ 43 49 #define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */ 44 50 #define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */ ··· 60 54 61 55 /* USBCMD: offset 0x00 */ 62 56 u32 command; 57 + 58 + /* EHCI 1.1 addendum */ 59 + #define CMD_HIRD (0xf<<24) /* host initiated resume duration */ 60 + #define CMD_PPCEE (1<<15) /* per port change event enable */ 61 + #define CMD_FSP (1<<14) /* fully synchronized prefetch */ 62 + #define CMD_ASPE (1<<13) /* async schedule prefetch enable */ 63 + #define CMD_PSPE (1<<12) /* periodic schedule prefetch enable */ 63 64 /* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */ 64 65 #define CMD_PARK (1<<11) /* enable "park" on async qh */ 65 66 #define CMD_PARK_CNT(c) (((c)>>8)&3) /* how many transfers to park for */ ··· 80 67 81 68 /* USBSTS: offset 0x04 */ 82 69 u32 status; 70 + #define STS_PPCE_MASK (0xff<<16) /* Per-Port change event 1-16 */ 83 71 #define STS_ASS (1<<15) /* Async Schedule Status */ 84 72 #define STS_PSS (1<<14) /* Periodic Schedule Status */ 85 73 #define STS_RECL (1<<13) /* Reclamation */ ··· 114 100 115 101 /* PORTSC: offset 0x44 */ 116 102 u32 port_status[0]; /* up to N_PORTS */ 103 + /* EHCI 1.1 addendum */ 104 + #define PORTSC_SUSPEND_STS_ACK 0 105 + #define PORTSC_SUSPEND_STS_NYET 1 106 + #define PORTSC_SUSPEND_STS_STALL 2 107 + #define PORTSC_SUSPEND_STS_ERR 3 108 + 109 + #define PORT_DEV_ADDR (0x7f<<25) /* device address */ 110 + #define PORT_SSTS (0x3<<23) /* suspend status */ 117 111 /* 31:23 reserved */ 118 112 #define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */ 119 113 #define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ ··· 137 115 #define PORT_USB11(x) (((x)&(3<<10)) == (1<<10)) /* USB 1.1 device */ 138 116 /* 11:10 for detecting lowspeed devices (reset vs release ownership) */ 139 117 /* 9 reserved */ 118 + #define PORT_LPM (1<<9) /* LPM transaction */ 140 119 #define PORT_RESET (1<<8) /* reset port */ 141 120 #define PORT_SUSPEND (1<<7) /* suspend port */ 142 121 #define PORT_RESUME (1<<6) /* resume it */
+3 -3
include/linux/usb/functionfs.h
··· 180 180 static void functionfs_unbind(struct ffs_data *ffs) 181 181 __attribute__((nonnull)); 182 182 183 - static int functionfs_add(struct usb_composite_dev *cdev, 184 - struct usb_configuration *c, 185 - struct ffs_data *ffs) 183 + static int functionfs_bind_config(struct usb_composite_dev *cdev, 184 + struct usb_configuration *c, 185 + struct ffs_data *ffs) 186 186 __attribute__((warn_unused_result, nonnull)); 187 187 188 188
+25 -6
include/linux/usb/hcd.h
··· 89 89 */ 90 90 const struct hc_driver *driver; /* hw-specific hooks */ 91 91 92 - /* Flags that need to be manipulated atomically */ 92 + /* Flags that need to be manipulated atomically because they can 93 + * change while the host controller is running. Always use 94 + * set_bit() or clear_bit() to change their values. 95 + */ 93 96 unsigned long flags; 94 - #define HCD_FLAG_HW_ACCESSIBLE 0x00000001 95 - #define HCD_FLAG_SAW_IRQ 0x00000002 97 + #define HCD_FLAG_HW_ACCESSIBLE 0 /* at full power */ 98 + #define HCD_FLAG_SAW_IRQ 1 99 + #define HCD_FLAG_POLL_RH 2 /* poll for rh status? */ 100 + #define HCD_FLAG_POLL_PENDING 3 /* status has changed? */ 101 + #define HCD_FLAG_WAKEUP_PENDING 4 /* root hub is resuming? */ 96 102 103 + /* The flags can be tested using these macros; they are likely to 104 + * be slightly faster than test_bit(). 105 + */ 106 + #define HCD_HW_ACCESSIBLE(hcd) ((hcd)->flags & (1U << HCD_FLAG_HW_ACCESSIBLE)) 107 + #define HCD_SAW_IRQ(hcd) ((hcd)->flags & (1U << HCD_FLAG_SAW_IRQ)) 108 + #define HCD_POLL_RH(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_RH)) 109 + #define HCD_POLL_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING)) 110 + #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) 111 + 112 + /* Flags that get set only during HCD registration or removal. */ 97 113 unsigned rh_registered:1;/* is root hub registered? */ 114 + unsigned rh_pollable:1; /* may we poll the root hub? */ 98 115 99 116 /* The next flag is a stopgap, to be removed when all the HCDs 100 117 * support the new root-hub polling mechanism. */ 101 118 unsigned uses_new_polling:1; 102 - unsigned poll_rh:1; /* poll for rh status? */ 103 - unsigned poll_pending:1; /* status has changed? */ 104 119 unsigned wireless:1; /* Wireless USB HCD */ 105 120 unsigned authorized_default:1; 106 121 unsigned has_tt:1; /* Integrated TT in root hub */ ··· 213 198 * a whole, not just the root hub; they're for PCI bus glue. 214 199 */ 215 200 /* called after suspending the hub, before entering D3 etc */ 216 - int (*pci_suspend)(struct usb_hcd *hcd); 201 + int (*pci_suspend)(struct usb_hcd *hcd, bool do_wakeup); 217 202 218 203 /* called after entering D0 (etc), before resuming the hub */ 219 204 int (*pci_resume)(struct usb_hcd *hcd, bool hibernated); ··· 314 299 int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev, 315 300 struct usb_tt *tt, gfp_t mem_flags); 316 301 int (*reset_device)(struct usb_hcd *, struct usb_device *); 302 + /* Notifies the HCD after a device is connected and its 303 + * address is set 304 + */ 305 + int (*update_device)(struct usb_hcd *, struct usb_device *); 317 306 }; 318 307 319 308 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
+2 -9
include/linux/usb/otg.h
··· 43 43 USB_EVENT_ENUMERATED, /* gadget driver enumerated */ 44 44 }; 45 45 46 - #define USB_OTG_PULLUP_ID (1 << 0) 47 - #define USB_OTG_PULLDOWN_DP (1 << 1) 48 - #define USB_OTG_PULLDOWN_DM (1 << 2) 49 - #define USB_OTG_EXT_VBUS_INDICATOR (1 << 3) 50 - #define USB_OTG_DRV_VBUS (1 << 4) 51 - #define USB_OTG_DRV_VBUS_EXT (1 << 5) 52 - 53 46 struct otg_transceiver; 54 47 55 48 /* for transceivers connected thru an ULPI interface, the user must ··· 139 146 return -EINVAL; 140 147 } 141 148 142 - static inline int otg_io_write(struct otg_transceiver *otg, u32 reg, u32 val) 149 + static inline int otg_io_write(struct otg_transceiver *otg, u32 val, u32 reg) 143 150 { 144 151 if (otg->io_ops && otg->io_ops->write) 145 - return otg->io_ops->write(otg, reg, val); 152 + return otg->io_ops->write(otg, val, reg); 146 153 147 154 return -EINVAL; 148 155 }
+4
include/linux/usb/quirks.h
··· 26 26 and can't handle talking to these interfaces */ 27 27 #define USB_QUIRK_HONOR_BNUMINTERFACES 0x00000020 28 28 29 + /* device needs a pause during initialization, after we read the device 30 + descriptor */ 31 + #define USB_QUIRK_DELAY_INIT 0x00000040 32 + 29 33 #endif /* __LINUX_USB_QUIRKS_H */
+40
include/linux/usb/ulpi.h
··· 11 11 #ifndef __LINUX_USB_ULPI_H 12 12 #define __LINUX_USB_ULPI_H 13 13 14 + #include <linux/usb/otg.h> 15 + /*-------------------------------------------------------------------------*/ 16 + 17 + /* 18 + * ULPI Flags 19 + */ 20 + #define ULPI_OTG_ID_PULLUP (1 << 0) 21 + #define ULPI_OTG_DP_PULLDOWN_DIS (1 << 1) 22 + #define ULPI_OTG_DM_PULLDOWN_DIS (1 << 2) 23 + #define ULPI_OTG_DISCHRGVBUS (1 << 3) 24 + #define ULPI_OTG_CHRGVBUS (1 << 4) 25 + #define ULPI_OTG_DRVVBUS (1 << 5) 26 + #define ULPI_OTG_DRVVBUS_EXT (1 << 6) 27 + #define ULPI_OTG_EXTVBUSIND (1 << 7) 28 + 29 + #define ULPI_IC_6PIN_SERIAL (1 << 8) 30 + #define ULPI_IC_3PIN_SERIAL (1 << 9) 31 + #define ULPI_IC_CARKIT (1 << 10) 32 + #define ULPI_IC_CLKSUSPM (1 << 11) 33 + #define ULPI_IC_AUTORESUME (1 << 12) 34 + #define ULPI_IC_EXTVBUS_INDINV (1 << 13) 35 + #define ULPI_IC_IND_PASSTHRU (1 << 14) 36 + #define ULPI_IC_PROTECT_DIS (1 << 15) 37 + 38 + #define ULPI_FC_HS (1 << 16) 39 + #define ULPI_FC_FS (1 << 17) 40 + #define ULPI_FC_LS (1 << 18) 41 + #define ULPI_FC_FS4LS (1 << 19) 42 + #define ULPI_FC_TERMSEL (1 << 20) 43 + #define ULPI_FC_OP_NORM (1 << 21) 44 + #define ULPI_FC_OP_NODRV (1 << 22) 45 + #define ULPI_FC_OP_DIS_NRZI (1 << 23) 46 + #define ULPI_FC_OP_NSYNC_NEOP (1 << 24) 47 + #define ULPI_FC_RST (1 << 25) 48 + #define ULPI_FC_SUSPM (1 << 26) 49 + 14 50 /*-------------------------------------------------------------------------*/ 15 51 16 52 /* ··· 93 57 #define ULPI_EXT_VENDOR_SPECIFIC 0x80 94 58 95 59 /*-------------------------------------------------------------------------*/ 60 + 61 + /* 62 + * Register Bits 63 + */ 96 64 97 65 /* Function Control */ 98 66 #define ULPI_FUNC_CTRL_XCVRSEL (1 << 0)