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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'usb-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB/Thunderbolt updates from Greg KH:
"Here is the large set of USB and Thunderbolt changes for 6.12-rc1.

Nothing "major" in here, except for a new 9p network gadget that has
been worked on for a long time (all of the needed acks are here)

Other than that, it's the usual set of:

- Thunderbolt / USB4 driver updates and additions for new hardware

- dwc3 driver updates and new features added

- xhci driver updates

- typec driver updates

- USB gadget updates and api additions to make some gadgets more
configurable by userspace

- dwc2 driver updates

- usb phy driver updates

- usbip feature additions

- other minor USB driver updates

All of these have been in linux-next for a long time with no reported
issues"

* tag 'usb-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (145 commits)
sub: cdns3: Use predefined PCI vendor ID constant
sub: cdns2: Use predefined PCI vendor ID constant
USB: misc: yurex: fix race between read and write
USB: misc: cypress_cy7c63: check for short transfer
USB: appledisplay: close race between probe and completion handler
USB: class: CDC-ACM: fix race between get_serial and set_serial
usb: r8a66597-hcd: make read-only const arrays static
usb: typec: ucsi: Fix busy loop on ASUS VivoBooks
usb: dwc3: rtk: Clean up error code in __get_dwc3_maximum_speed()
usb: storage: ene_ub6250: Fix right shift warnings
usb: roles: Improve the fix for a false positive recursive locking complaint
locking/mutex: Introduce mutex_init_with_key()
locking/mutex: Define mutex_init() once
net/9p/usbg: fix CONFIG_USB_GADGET dependency
usb: xhci: fix loss of data on Cadence xHC
usb: xHCI: add XHCI_RESET_ON_RESUME quirk for Phytium xHCI host
usb: dwc3: imx8mp: disable SS_CON and U3 wakeup for system sleep
usb: dwc3: imx8mp: add 2 software managed quirk properties for host mode
usb: host: xhci-plat: Parse xhci-missing_cas_quirk and apply quirk
usb: misc: onboard_usb_dev: add Microchip usb5744 SMBus programming support
...

+3860 -1248
+7
Documentation/ABI/testing/configfs-usb-gadget-acm
··· 6 6 This item contains just one readonly attribute: port_num. 7 7 It contains the port number of the /dev/ttyGS<n> device 8 8 associated with acm function's instance "name". 9 + 10 + What: /config/usb-gadget/gadget/functions/acm.name/protocol 11 + Date: Aug 2024 12 + KernelVersion: 6.13 13 + Description: 14 + Reported bInterfaceProtocol for the ACM device. For legacy 15 + reasons, this defaults to 1 (USB_CDC_ACM_PROTO_AT_V25TER).
+8
Documentation/ABI/testing/configfs-usb-gadget-uac1
··· 30 30 req_number the number of pre-allocated requests 31 31 for both capture and playback 32 32 function_name name of the interface 33 + p_it_name playback input terminal name 34 + p_it_ch_name playback channels name 35 + p_ot_name playback output terminal name 36 + p_fu_vol_name playback mute/volume functional unit name 37 + c_it_name capture input terminal name 38 + c_it_ch_name capture channels name 39 + c_ot_name capture output terminal name 40 + c_fu_vol_name capture mute/volume functional unit name 33 41 ===================== =======================================
+11
Documentation/ABI/testing/configfs-usb-gadget-uac2
··· 35 35 req_number the number of pre-allocated requests 36 36 for both capture and playback 37 37 function_name name of the interface 38 + if_ctrl_name topology control name 39 + clksrc_in_name input clock name 40 + clksrc_out_name output clock name 41 + p_it_name playback input terminal name 42 + p_it_ch_name playback input first channel name 43 + p_ot_name playback output terminal name 44 + p_fu_vol_name playback mute/volume function unit name 45 + c_it_name capture input terminal name 46 + c_it_ch_name capture input first channel name 47 + c_ot_name capture output terminal name 48 + c_fu_vol_name capture mute/volume functional unit name 38 49 c_terminal_type code of the capture terminal type 39 50 p_terminal_type code of the playback terminal type 40 51 ===================== =======================================
+17
Documentation/devicetree/bindings/phy/fsl,mxs-usbphy.yaml
··· 87 87 maximum: 119 88 88 default: 100 89 89 90 + nxp,sim: 91 + description: 92 + The system integration module (SIM) provides system control and chip 93 + configuration registers. 94 + $ref: /schemas/types.yaml#/definitions/phandle 95 + 90 96 required: 91 97 - compatible 92 98 - reg ··· 115 109 then: 116 110 required: 117 111 - fsl,anatop 112 + 113 + - if: 114 + properties: 115 + compatible: 116 + const: fsl,imx7ulp-usbphy 117 + then: 118 + required: 119 + - nxp,sim 120 + else: 121 + properties: 122 + nxp,sim: false 118 123 119 124 additionalProperties: false 120 125
+52
Documentation/devicetree/bindings/usb/fsl,ls1028a.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/fsl,ls1028a.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Freescale layerscape SuperSpeed DWC3 USB SoC controller 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + select: 13 + properties: 14 + compatible: 15 + contains: 16 + enum: 17 + - fsl,ls1028a-dwc3 18 + required: 19 + - compatible 20 + 21 + properties: 22 + compatible: 23 + items: 24 + - enum: 25 + - fsl,ls1028a-dwc3 26 + - const: snps,dwc3 27 + 28 + reg: 29 + maxItems: 1 30 + 31 + interrupts: 32 + maxItems: 1 33 + 34 + unevaluatedProperties: false 35 + 36 + required: 37 + - compatible 38 + - reg 39 + - interrupts 40 + 41 + allOf: 42 + - $ref: snps,dwc3.yaml# 43 + 44 + examples: 45 + - | 46 + #include <dt-bindings/interrupt-controller/arm-gic.h> 47 + 48 + usb@fe800000 { 49 + compatible = "fsl,ls1028a-dwc3", "snps,dwc3"; 50 + reg = <0xfe800000 0x100000>; 51 + interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>; 52 + };
-110
Documentation/devicetree/bindings/usb/msm-hsusb.txt
··· 1 - MSM SoC HSUSB controllers 2 - 3 - EHCI 4 - 5 - Required properties: 6 - - compatible: Should contain "qcom,ehci-host" 7 - - regs: offset and length of the register set in the memory map 8 - - usb-phy: phandle for the PHY device 9 - 10 - Example EHCI controller device node: 11 - 12 - ehci: ehci@f9a55000 { 13 - compatible = "qcom,ehci-host"; 14 - reg = <0xf9a55000 0x400>; 15 - usb-phy = <&usb_otg>; 16 - }; 17 - 18 - USB PHY with optional OTG: 19 - 20 - Required properties: 21 - - compatible: Should contain: 22 - "qcom,usb-otg-ci" for chipsets with ChipIdea 45nm PHY 23 - "qcom,usb-otg-snps" for chipsets with Synopsys 28nm PHY 24 - 25 - - regs: Offset and length of the register set in the memory map 26 - - interrupts: interrupt-specifier for the OTG interrupt. 27 - 28 - - clocks: A list of phandle + clock-specifier pairs for the 29 - clocks listed in clock-names 30 - - clock-names: Should contain the following: 31 - "phy" USB PHY reference clock 32 - "core" Protocol engine clock 33 - "iface" Interface bus clock 34 - "alt_core" Protocol engine clock for targets with asynchronous 35 - reset methodology. (optional) 36 - 37 - - vdccx-supply: phandle to the regulator for the vdd supply for 38 - digital circuit operation. 39 - - v1p8-supply: phandle to the regulator for the 1.8V supply 40 - - v3p3-supply: phandle to the regulator for the 3.3V supply 41 - 42 - - resets: A list of phandle + reset-specifier pairs for the 43 - resets listed in reset-names 44 - - reset-names: Should contain the following: 45 - "phy" USB PHY controller reset 46 - "link" USB LINK controller reset 47 - 48 - - qcom,otg-control: OTG control (VBUS and ID notifications) can be one of 49 - 1 - PHY control 50 - 2 - PMIC control 51 - 52 - Optional properties: 53 - - dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg" 54 - 55 - - switch-gpio: A phandle + gpio-specifier pair. Some boards are using Dual 56 - SPDT USB Switch, witch is controlled by GPIO to de/multiplex 57 - D+/D- USB lines between connectors. 58 - 59 - - qcom,phy-init-sequence: PHY configuration sequence values. This is related to Device 60 - Mode Eye Diagram test. Start address at which these values will be 61 - written is ULPI_EXT_VENDOR_SPECIFIC. Value of -1 is reserved as 62 - "do not overwrite default value at this address". 63 - For example: qcom,phy-init-sequence = < -1 0x63 >; 64 - Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1. 65 - 66 - - qcom,phy-num: Select number of pyco-phy to use, can be one of 67 - 0 - PHY one, default 68 - 1 - Second PHY 69 - Some platforms may have configuration to allow USB 70 - controller work with any of the two HSPHYs present. 71 - 72 - - qcom,vdd-levels: This property must be a list of three integer values 73 - (no, min, max) where each value represents either a voltage 74 - in microvolts or a value corresponding to voltage corner. 75 - 76 - - qcom,manual-pullup: If present, vbus is not routed to USB controller/phy 77 - and controller driver therefore enables pull-up explicitly 78 - before starting controller using usbcmd run/stop bit. 79 - 80 - - extcon: phandles to external connector devices. First phandle 81 - should point to external connector, which provide "USB" 82 - cable events, the second should point to external connector 83 - device, which provide "USB-HOST" cable events. If one of 84 - the external connector devices is not required empty <0> 85 - phandle should be specified. 86 - 87 - Example HSUSB OTG controller device node: 88 - 89 - usb@f9a55000 { 90 - compatible = "qcom,usb-otg-snps"; 91 - reg = <0xf9a55000 0x400>; 92 - interrupts = <0 134 0>; 93 - dr_mode = "peripheral"; 94 - 95 - clocks = <&gcc GCC_XO_CLK>, <&gcc GCC_USB_HS_SYSTEM_CLK>, 96 - <&gcc GCC_USB_HS_AHB_CLK>; 97 - 98 - clock-names = "phy", "core", "iface"; 99 - 100 - vddcx-supply = <&pm8841_s2_corner>; 101 - v1p8-supply = <&pm8941_l6>; 102 - v3p3-supply = <&pm8941_l24>; 103 - 104 - resets = <&gcc GCC_USB2A_PHY_BCR>, <&gcc GCC_USB_HS_BCR>; 105 - reset-names = "phy", "link"; 106 - 107 - qcom,otg-control = <1>; 108 - qcom,phy-init-sequence = < -1 0x63 >; 109 - qcom,vdd-levels = <1 5 7>; 110 - };
+18
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 52 52 - qcom,sm8550-dwc3 53 53 - qcom,sm8650-dwc3 54 54 - qcom,x1e80100-dwc3 55 + - qcom,x1e80100-dwc3-mp 55 56 - const: qcom,dwc3 56 57 57 58 reg: ··· 290 289 - qcom,sc8280xp-dwc3 291 290 - qcom,sc8280xp-dwc3-mp 292 291 - qcom,x1e80100-dwc3 292 + - qcom,x1e80100-dwc3-mp 293 293 then: 294 294 properties: 295 295 clocks: ··· 430 428 contains: 431 429 enum: 432 430 - qcom,ipq5332-dwc3 431 + then: 432 + properties: 433 + interrupts: 434 + maxItems: 3 435 + interrupt-names: 436 + items: 437 + - const: pwr_event 438 + - const: dp_hs_phy_irq 439 + - const: dm_hs_phy_irq 440 + 441 + - if: 442 + properties: 443 + compatible: 444 + contains: 445 + enum: 433 446 - qcom,x1e80100-dwc3 434 447 then: 435 448 properties: ··· 503 486 contains: 504 487 enum: 505 488 - qcom,sc8180x-dwc3-mp 489 + - qcom,x1e80100-dwc3-mp 506 490 then: 507 491 properties: 508 492 interrupts:
+1 -2
Documentation/devicetree/bindings/usb/ti,j721e-usb.yaml
··· 13 13 compatible: 14 14 oneOf: 15 15 - const: ti,j721e-usb 16 - - const: ti,am64-usb 17 16 - items: 18 - - const: ti,j721e-usb 19 17 - const: ti,am64-usb 18 + - const: ti,j721e-usb 20 19 21 20 reg: 22 21 maxItems: 1
+57 -1
Documentation/filesystems/9p.rst
··· 48 48 49 49 mount -t 9p -o trans=virtio <mount_tag> /mnt/9 50 50 51 - where mount_tag is the tag associated by the server to each of the exported 51 + where mount_tag is the tag generated by the server to each of the exported 52 52 mount points. Each 9P export is seen by the client as a virtio device with an 53 53 associated "mount_tag" property. Available mount tags can be 54 54 seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files. 55 + 56 + USBG Usage 57 + ========== 58 + 59 + To mount a 9p FS on a USB Host accessible via the gadget at runtime:: 60 + 61 + mount -t 9p -o trans=usbg,aname=/path/to/fs <device> /mnt/9 62 + 63 + To mount a 9p FS on a USB Host accessible via the gadget as root filesystem:: 64 + 65 + root=<device> rootfstype=9p rootflags=trans=usbg,cache=loose,uname=root,access=0,dfltuid=0,dfltgid=0,aname=/path/to/rootfs 66 + 67 + where <device> is the tag associated by the usb gadget transport. 68 + It is defined by the configfs instance name. 69 + 70 + USBG Example 71 + ============ 72 + 73 + The USB host exports a filesystem, while the gadget on the USB device 74 + side makes it mountable. 75 + 76 + Diod (9pfs server) and the forwarder are on the development host, where 77 + the root filesystem is actually stored. The gadget is initialized during 78 + boot (or later) on the embedded board. Then the forwarder will find it 79 + on the USB bus and start forwarding requests. 80 + 81 + In this case the 9p requests come from the device and are handled by the 82 + host. The reason is that USB device ports are normally not available on 83 + PCs, so a connection in the other direction would not work. 84 + 85 + When using the usbg transport, for now there is no native usb host 86 + service capable to handle the requests from the gadget driver. For 87 + this we have to use the extra python tool p9_fwd.py from tools/usb. 88 + 89 + Just start the 9pfs capable network server like diod/nfs-ganesha e.g.:: 90 + 91 + $ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD 92 + 93 + Optionaly scan your bus if there are more then one usbg gadgets to find their path:: 94 + 95 + $ python $kernel_dir/tools/usb/p9_fwd.py list 96 + 97 + Bus | Addr | Manufacturer | Product | ID | Path 98 + --- | ---- | ---------------- | ---------------- | --------- | ---- 99 + 2 | 67 | unknown | unknown | 1d6b:0109 | 2-1.1.2 100 + 2 | 68 | unknown | unknown | 1d6b:0109 | 2-1.1.3 101 + 102 + Then start the python transport:: 103 + 104 + $ python $kernel_dir/tools/usb/p9_fwd.py --path 2-1.1.2 connect -p 9999 105 + 106 + After that the gadget driver can be used as described above. 107 + 108 + One use-case is to use it as an alternative to NFS root booting during 109 + the development of embedded Linux devices. 55 110 56 111 Options 57 112 ======= ··· 123 68 virtio connect to the next virtio channel available 124 69 (from QEMU with trans_virtio module) 125 70 rdma connect to a specified RDMA channel 71 + usbg connect to a specified usb gadget channel 126 72 ======== ============================================ 127 73 128 74 uname=name user name to attempt mount as on the remote server. The
+39
Documentation/usb/functionfs-desc.rst
··· 1 + ====================== 2 + FunctionFS Descriptors 3 + ====================== 4 + 5 + Some of the descriptors that can be written to the FFS gadget are 6 + described below. Device and configuration descriptors are handled 7 + by the composite gadget and are not written by the user to the 8 + FFS gadget. 9 + 10 + Descriptors are written to the "ep0" file in the FFS gadget 11 + following the descriptor header. 12 + 13 + .. kernel-doc:: include/uapi/linux/usb/functionfs.h 14 + :doc: descriptors 15 + 16 + Interface Descriptors 17 + --------------------- 18 + 19 + Standard USB interface descriptors may be written. The class/subclass of the 20 + most recent interface descriptor determines what type of class-specific 21 + descriptors are accepted. 22 + 23 + Class-Specific Descriptors 24 + -------------------------- 25 + 26 + Class-specific descriptors are accepted only for the class/subclass of the 27 + most recent interface descriptor. The following are some of the 28 + class-specific descriptors that are supported. 29 + 30 + DFU Functional Descriptor 31 + ~~~~~~~~~~~~~~~~~~~~~~~~~ 32 + 33 + When the interface class is USB_CLASS_APP_SPEC and the interface subclass 34 + is USB_SUBCLASS_DFU, a DFU functional descriptor can be provided. 35 + The DFU functional descriptor is a described in the USB specification for 36 + Device Firmware Upgrade (DFU), version 1.1 as of this writing. 37 + 38 + .. kernel-doc:: include/uapi/linux/usb/functionfs.h 39 + :doc: usb_dfu_functional_descriptor
+2
Documentation/usb/functionfs.rst
··· 25 25 them as needed also handling situation when numbers differ in 26 26 different configurations. 27 27 28 + For more information about FunctionFS descriptors see :doc:`functionfs-desc` 29 + 28 30 When descriptors and strings are written "ep#" files appear 29 31 (one for each declared endpoint) which handle communication on 30 32 a single endpoint. Again, FunctionFS takes care of the real
+19
Documentation/usb/gadget-testing.rst
··· 765 765 req_number the number of pre-allocated request for both capture 766 766 and playback 767 767 function_name name of the interface 768 + if_ctrl_name topology control name 769 + clksrc_in_name input clock name 770 + clksrc_out_name output clock name 771 + p_it_name playback input terminal name 772 + p_it_ch_name playback input first channel name 773 + p_ot_name playback output terminal name 774 + p_fu_vol_name playback function unit name 775 + c_it_name capture input terminal name 776 + c_it_ch_name capture input first channel name 777 + c_ot_name capture output terminal name 778 + c_fu_vol_name capture functional unit name 768 779 c_terminal_type code of the capture terminal type 769 780 p_terminal_type code of the playback terminal type 770 781 ================ ==================================================== ··· 968 957 req_number the number of pre-allocated requests for both capture 969 958 and playback 970 959 function_name name of the interface 960 + p_it_name playback input terminal name 961 + p_it_ch_name playback channels name 962 + p_ot_name playback output terminal name 963 + p_fu_vol_name playback mute/volume functional unit name 964 + c_it_name capture input terminal name 965 + c_it_ch_name capture channels name 966 + c_ot_name capture output terminal name 967 + c_fu_vol_name capture mute/volume functional unit name 971 968 ================ ==================================================== 972 969 973 970 The attributes have sane default values.
+1
Documentation/usb/index.rst
··· 11 11 dwc3 12 12 ehci 13 13 functionfs 14 + functionfs-desc 14 15 gadget_configfs 15 16 gadget_hid 16 17 gadget_multi
+10 -30
drivers/thunderbolt/acpi.c
··· 32 32 goto out_put; 33 33 34 34 /* 35 - * Try to find physical device walking upwards to the hierarcy. 36 - * We need to do this because the xHCI driver might not yet be 37 - * bound so the USB3 SuperSpeed ports are not yet created. 35 + * Ignore USB3 ports here as USB core will set up device links between 36 + * tunneled USB3 devices and NHI host during USB device creation. 37 + * USB3 ports might not even have a physical device yet if xHCI driver 38 + * isn't bound yet. 38 39 */ 39 - do { 40 - dev = acpi_get_first_physical_node(adev); 41 - if (dev) 42 - break; 43 - 44 - adev = acpi_dev_parent(adev); 45 - } while (adev); 46 - 47 - /* 48 - * Check that the device is PCIe. This is because USB3 49 - * SuperSpeed ports have this property and they are not power 50 - * managed with the xHCI and the SuperSpeed hub so we create the 51 - * link from xHCI instead. 52 - */ 53 - while (dev && !dev_is_pci(dev)) 54 - dev = dev->parent; 55 - 56 - if (!dev) 40 + dev = acpi_get_first_physical_node(adev); 41 + if (!dev || !dev_is_pci(dev)) 57 42 goto out_put; 58 43 59 - /* 60 - * Check that this actually matches the type of device we 61 - * expect. It should either be xHCI or PCIe root/downstream 62 - * port. 63 - */ 44 + /* Check that this matches a PCIe root/downstream port. */ 64 45 pdev = to_pci_dev(dev); 65 - if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI || 66 - (pci_is_pcie(pdev) && 67 - (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || 68 - pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM))) { 46 + if (pci_is_pcie(pdev) && 47 + (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || 48 + pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM)) { 69 49 const struct device_link *link; 70 50 71 51 /*
+366 -16
drivers/thunderbolt/debugfs.c
··· 9 9 10 10 #include <linux/bitfield.h> 11 11 #include <linux/debugfs.h> 12 + #include <linux/delay.h> 12 13 #include <linux/pm_runtime.h> 13 14 #include <linux/uaccess.h> 14 15 ··· 34 33 #define PATH_LEN 2 35 34 36 35 #define COUNTER_SET_LEN 3 36 + 37 + /* 38 + * USB4 spec doesn't specify dwell range, the range of 100 ms to 500 ms 39 + * probed to give good results. 40 + */ 41 + #define MIN_DWELL_TIME 100 /* ms */ 42 + #define MAX_DWELL_TIME 500 /* ms */ 43 + #define DWELL_SAMPLE_INTERVAL 10 37 44 38 45 /* Sideband registers and their sizes as defined in the USB4 spec */ 39 46 struct sb_reg { ··· 403 394 * @ber_level: Current BER level contour value 404 395 * @voltage_steps: Number of mandatory voltage steps 405 396 * @max_voltage_offset: Maximum mandatory voltage offset (in mV) 397 + * @voltage_steps_optional_range: Number of voltage steps for optional range 398 + * @max_voltage_offset_optional_range: Maximum voltage offset for the optional 399 + * range (in mV). 406 400 * @time_steps: Number of time margin steps 407 401 * @max_time_offset: Maximum time margin offset (in mUI) 402 + * @voltage_time_offset: Offset for voltage / time for software margining 403 + * @dwell_time: Dwell time for software margining (in ms) 404 + * @error_counter: Error counter operation for software margining 405 + * @optional_voltage_offset_range: Enable optional extended voltage range 408 406 * @software: %true if software margining is used instead of hardware 409 407 * @time: %true if time margining is used instead of voltage 410 408 * @right_high: %false if left/low margin test is performed, %true if ··· 430 414 unsigned int ber_level; 431 415 unsigned int voltage_steps; 432 416 unsigned int max_voltage_offset; 417 + unsigned int voltage_steps_optional_range; 418 + unsigned int max_voltage_offset_optional_range; 433 419 unsigned int time_steps; 434 420 unsigned int max_time_offset; 421 + unsigned int voltage_time_offset; 422 + unsigned int dwell_time; 423 + enum usb4_margin_sw_error_counter error_counter; 424 + bool optional_voltage_offset_range; 435 425 bool software; 436 426 bool time; 437 427 bool right_high; 438 428 }; 429 + 430 + static int margining_modify_error_counter(struct tb_margining *margining, 431 + u32 lanes, enum usb4_margin_sw_error_counter error_counter) 432 + { 433 + struct usb4_port_margining_params params = { 0 }; 434 + struct tb_port *port = margining->port; 435 + u32 result; 436 + 437 + if (error_counter != USB4_MARGIN_SW_ERROR_COUNTER_CLEAR && 438 + error_counter != USB4_MARGIN_SW_ERROR_COUNTER_STOP) 439 + return -EOPNOTSUPP; 440 + 441 + params.error_counter = error_counter; 442 + params.lanes = lanes; 443 + 444 + return usb4_port_sw_margin(port, margining->target, margining->index, 445 + &params, &result); 446 + } 439 447 440 448 static bool supports_software(const struct tb_margining *margining) 441 449 { ··· 492 452 independent_time_margins(const struct tb_margining *margining) 493 453 { 494 454 return FIELD_GET(USB4_MARGIN_CAP_1_TIME_INDP_MASK, margining->caps[1]); 455 + } 456 + 457 + static bool 458 + supports_optional_voltage_offset_range(const struct tb_margining *margining) 459 + { 460 + return margining->caps[0] & USB4_MARGIN_CAP_0_OPT_VOLTAGE_SUPPORT; 495 461 } 496 462 497 463 static ssize_t ··· 599 553 margining->voltage_steps); 600 554 seq_printf(s, "# maximum voltage offset: %u mV\n", 601 555 margining->max_voltage_offset); 556 + seq_printf(s, "# optional voltage offset range support: %s\n", 557 + str_yes_no(supports_optional_voltage_offset_range(margining))); 558 + if (supports_optional_voltage_offset_range(margining)) { 559 + seq_printf(s, "# voltage margin steps, optional range: %u\n", 560 + margining->voltage_steps_optional_range); 561 + seq_printf(s, "# maximum voltage offset, optional range: %u mV\n", 562 + margining->max_voltage_offset_optional_range); 563 + } 602 564 603 565 switch (independent_voltage_margins(margining)) { 604 566 case USB4_MARGIN_CAP_0_VOLTAGE_MIN: ··· 721 667 } 722 668 DEBUGFS_ATTR_RW(margining_lanes); 723 669 670 + static ssize_t 671 + margining_voltage_time_offset_write(struct file *file, 672 + const char __user *user_buf, 673 + size_t count, loff_t *ppos) 674 + { 675 + struct seq_file *s = file->private_data; 676 + struct tb_margining *margining = s->private; 677 + struct tb *tb = margining->port->sw->tb; 678 + unsigned int max_margin; 679 + unsigned int val; 680 + int ret; 681 + 682 + ret = kstrtouint_from_user(user_buf, count, 10, &val); 683 + if (ret) 684 + return ret; 685 + 686 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 687 + if (!margining->software) 688 + return -EOPNOTSUPP; 689 + 690 + if (margining->time) 691 + max_margin = margining->time_steps; 692 + else 693 + if (margining->optional_voltage_offset_range) 694 + max_margin = margining->voltage_steps_optional_range; 695 + else 696 + max_margin = margining->voltage_steps; 697 + 698 + margining->voltage_time_offset = clamp(val, 0, max_margin); 699 + } 700 + 701 + return count; 702 + } 703 + 704 + static int margining_voltage_time_offset_show(struct seq_file *s, 705 + void *not_used) 706 + { 707 + const struct tb_margining *margining = s->private; 708 + struct tb *tb = margining->port->sw->tb; 709 + 710 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 711 + if (!margining->software) 712 + return -EOPNOTSUPP; 713 + 714 + seq_printf(s, "%d\n", margining->voltage_time_offset); 715 + } 716 + 717 + return 0; 718 + } 719 + DEBUGFS_ATTR_RW(margining_voltage_time_offset); 720 + 721 + static ssize_t 722 + margining_error_counter_write(struct file *file, const char __user *user_buf, 723 + size_t count, loff_t *ppos) 724 + { 725 + enum usb4_margin_sw_error_counter error_counter; 726 + struct seq_file *s = file->private_data; 727 + struct tb_margining *margining = s->private; 728 + struct tb *tb = margining->port->sw->tb; 729 + char *buf; 730 + 731 + buf = validate_and_copy_from_user(user_buf, &count); 732 + if (IS_ERR(buf)) 733 + return PTR_ERR(buf); 734 + 735 + buf[count - 1] = '\0'; 736 + 737 + if (!strcmp(buf, "nop")) 738 + error_counter = USB4_MARGIN_SW_ERROR_COUNTER_NOP; 739 + else if (!strcmp(buf, "clear")) 740 + error_counter = USB4_MARGIN_SW_ERROR_COUNTER_CLEAR; 741 + else if (!strcmp(buf, "start")) 742 + error_counter = USB4_MARGIN_SW_ERROR_COUNTER_START; 743 + else if (!strcmp(buf, "stop")) 744 + error_counter = USB4_MARGIN_SW_ERROR_COUNTER_STOP; 745 + else 746 + return -EINVAL; 747 + 748 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 749 + if (!margining->software) 750 + return -EOPNOTSUPP; 751 + 752 + margining->error_counter = error_counter; 753 + } 754 + 755 + return count; 756 + } 757 + 758 + static int margining_error_counter_show(struct seq_file *s, void *not_used) 759 + { 760 + const struct tb_margining *margining = s->private; 761 + struct tb *tb = margining->port->sw->tb; 762 + 763 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 764 + if (!margining->software) 765 + return -EOPNOTSUPP; 766 + 767 + switch (margining->error_counter) { 768 + case USB4_MARGIN_SW_ERROR_COUNTER_NOP: 769 + seq_puts(s, "[nop] clear start stop\n"); 770 + break; 771 + case USB4_MARGIN_SW_ERROR_COUNTER_CLEAR: 772 + seq_puts(s, "nop [clear] start stop\n"); 773 + break; 774 + case USB4_MARGIN_SW_ERROR_COUNTER_START: 775 + seq_puts(s, "nop clear [start] stop\n"); 776 + break; 777 + case USB4_MARGIN_SW_ERROR_COUNTER_STOP: 778 + seq_puts(s, "nop clear start [stop]\n"); 779 + break; 780 + } 781 + } 782 + 783 + return 0; 784 + } 785 + DEBUGFS_ATTR_RW(margining_error_counter); 786 + 787 + static ssize_t 788 + margining_dwell_time_write(struct file *file, const char __user *user_buf, 789 + size_t count, loff_t *ppos) 790 + { 791 + struct seq_file *s = file->private_data; 792 + struct tb_margining *margining = s->private; 793 + struct tb *tb = margining->port->sw->tb; 794 + unsigned int val; 795 + int ret; 796 + 797 + ret = kstrtouint_from_user(user_buf, count, 10, &val); 798 + if (ret) 799 + return ret; 800 + 801 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 802 + if (!margining->software) 803 + return -EOPNOTSUPP; 804 + 805 + margining->dwell_time = clamp(val, MIN_DWELL_TIME, MAX_DWELL_TIME); 806 + } 807 + 808 + return count; 809 + } 810 + 811 + static int margining_dwell_time_show(struct seq_file *s, void *not_used) 812 + { 813 + struct tb_margining *margining = s->private; 814 + struct tb *tb = margining->port->sw->tb; 815 + 816 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 817 + if (!margining->software) 818 + return -EOPNOTSUPP; 819 + 820 + seq_printf(s, "%d\n", margining->dwell_time); 821 + } 822 + 823 + return 0; 824 + } 825 + DEBUGFS_ATTR_RW(margining_dwell_time); 826 + 827 + static ssize_t 828 + margining_optional_voltage_offset_write(struct file *file, const char __user *user_buf, 829 + size_t count, loff_t *ppos) 830 + { 831 + struct seq_file *s = file->private_data; 832 + struct tb_margining *margining = s->private; 833 + struct tb *tb = margining->port->sw->tb; 834 + bool val; 835 + int ret; 836 + 837 + ret = kstrtobool_from_user(user_buf, count, &val); 838 + if (ret) 839 + return ret; 840 + 841 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 842 + margining->optional_voltage_offset_range = val; 843 + } 844 + 845 + return count; 846 + } 847 + 848 + static int margining_optional_voltage_offset_show(struct seq_file *s, 849 + void *not_used) 850 + { 851 + struct tb_margining *margining = s->private; 852 + struct tb *tb = margining->port->sw->tb; 853 + 854 + scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { 855 + seq_printf(s, "%u\n", margining->optional_voltage_offset_range); 856 + } 857 + 858 + return 0; 859 + } 860 + DEBUGFS_ATTR_RW(margining_optional_voltage_offset); 861 + 724 862 static ssize_t margining_mode_write(struct file *file, 725 863 const char __user *user_buf, 726 864 size_t count, loff_t *ppos) ··· 985 739 } 986 740 DEBUGFS_ATTR_RW(margining_mode); 987 741 742 + static int margining_run_sw(struct tb_margining *margining, 743 + struct usb4_port_margining_params *params) 744 + { 745 + u32 nsamples = margining->dwell_time / DWELL_SAMPLE_INTERVAL; 746 + int ret, i; 747 + 748 + ret = usb4_port_sw_margin(margining->port, margining->target, margining->index, 749 + params, margining->results); 750 + if (ret) 751 + goto out_stop; 752 + 753 + for (i = 0; i <= nsamples; i++) { 754 + u32 errors = 0; 755 + 756 + ret = usb4_port_sw_margin_errors(margining->port, margining->target, 757 + margining->index, &margining->results[1]); 758 + if (ret) 759 + break; 760 + 761 + if (margining->lanes == USB4_MARGIN_SW_LANE_0) 762 + errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_0_MASK, 763 + margining->results[1]); 764 + else if (margining->lanes == USB4_MARGIN_SW_LANE_1) 765 + errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_1_MASK, 766 + margining->results[1]); 767 + else if (margining->lanes == USB4_MARGIN_SW_ALL_LANES) 768 + errors = margining->results[1]; 769 + 770 + /* Any errors stop the test */ 771 + if (errors) 772 + break; 773 + 774 + fsleep(DWELL_SAMPLE_INTERVAL * USEC_PER_MSEC); 775 + } 776 + 777 + out_stop: 778 + /* 779 + * Stop the counters but don't clear them to allow the 780 + * different error counter configurations. 781 + */ 782 + margining_modify_error_counter(margining, margining->lanes, 783 + USB4_MARGIN_SW_ERROR_COUNTER_STOP); 784 + return ret; 785 + } 786 + 988 787 static int margining_run_write(void *data, u64 val) 989 788 { 990 789 struct tb_margining *margining = data; ··· 1070 779 clx = ret; 1071 780 } 1072 781 782 + /* Clear the results */ 783 + memset(margining->results, 0, sizeof(margining->results)); 784 + 1073 785 if (margining->software) { 786 + struct usb4_port_margining_params params = { 787 + .error_counter = USB4_MARGIN_SW_ERROR_COUNTER_CLEAR, 788 + .lanes = margining->lanes, 789 + .time = margining->time, 790 + .voltage_time_offset = margining->voltage_time_offset, 791 + .right_high = margining->right_high, 792 + .optional_voltage_offset_range = margining->optional_voltage_offset_range, 793 + }; 794 + 1074 795 tb_port_dbg(port, 1075 796 "running software %s lane margining for %s lanes %u\n", 1076 797 margining->time ? "time" : "voltage", dev_name(dev), 1077 798 margining->lanes); 1078 - ret = usb4_port_sw_margin(port, margining->target, margining->index, 1079 - margining->lanes, margining->time, 1080 - margining->right_high, 1081 - USB4_MARGIN_SW_COUNTER_CLEAR); 1082 - if (ret) 1083 - goto out_clx; 1084 799 1085 - ret = usb4_port_sw_margin_errors(port, margining->target, 1086 - margining->index, 1087 - &margining->results[0]); 800 + ret = margining_run_sw(margining, &params); 1088 801 } else { 802 + struct usb4_port_margining_params params = { 803 + .ber_level = margining->ber_level, 804 + .lanes = margining->lanes, 805 + .time = margining->time, 806 + .right_high = margining->right_high, 807 + .optional_voltage_offset_range = margining->optional_voltage_offset_range, 808 + }; 809 + 1089 810 tb_port_dbg(port, 1090 811 "running hardware %s lane margining for %s lanes %u\n", 1091 812 margining->time ? "time" : "voltage", dev_name(dev), 1092 813 margining->lanes); 1093 - /* Clear the results */ 1094 - margining->results[0] = 0; 1095 - margining->results[1] = 0; 1096 - ret = usb4_port_hw_margin(port, margining->target, margining->index, 1097 - margining->lanes, margining->ber_level, 1098 - margining->time, margining->right_high, 814 + 815 + ret = usb4_port_hw_margin(port, margining->target, margining->index, &params, 1099 816 margining->results); 1100 817 } 1101 818 1102 - out_clx: 1103 819 if (down_sw) 1104 820 tb_switch_clx_enable(down_sw, clx); 1105 821 out_unlock: ··· 1135 837 margining->results[0] = 0; 1136 838 margining->results[1] = 0; 1137 839 840 + if (margining->software) { 841 + /* Clear the error counters */ 842 + margining_modify_error_counter(margining, 843 + USB4_MARGIN_SW_ALL_LANES, 844 + USB4_MARGIN_SW_ERROR_COUNTER_CLEAR); 845 + } 846 + 1138 847 mutex_unlock(&tb->lock); 1139 848 return count; 1140 849 } ··· 1157 852 if (val & USB4_MARGIN_HW_RES_1_EXCEEDS) 1158 853 seq_puts(s, " exceeds maximum"); 1159 854 seq_puts(s, "\n"); 855 + if (margining->optional_voltage_offset_range) 856 + seq_puts(s, " optional voltage offset range enabled\n"); 1160 857 } 1161 858 1162 859 static void time_margin_show(struct seq_file *s, ··· 1230 923 seq_puts(s, "# lane 1 low voltage margin: "); 1231 924 voltage_margin_show(s, margining, val); 1232 925 } 926 + } 927 + } else { 928 + u32 lane_errors, result; 929 + 930 + seq_printf(s, "0x%08x\n", margining->results[1]); 931 + result = FIELD_GET(USB4_MARGIN_SW_LANES_MASK, margining->results[0]); 932 + 933 + if (result == USB4_MARGIN_SW_LANE_0 || 934 + result == USB4_MARGIN_SW_ALL_LANES) { 935 + lane_errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_0_MASK, 936 + margining->results[1]); 937 + seq_printf(s, "# lane 0 errors: %u\n", lane_errors); 938 + } 939 + if (result == USB4_MARGIN_SW_LANE_1 || 940 + result == USB4_MARGIN_SW_ALL_LANES) { 941 + lane_errors = FIELD_GET(USB4_MARGIN_SW_ERR_COUNTER_LANE_1_MASK, 942 + margining->results[1]); 943 + seq_printf(s, "# lane 1 errors: %u\n", lane_errors); 1233 944 } 1234 945 } 1235 946 ··· 1416 1091 val = FIELD_GET(USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK, margining->caps[0]); 1417 1092 margining->max_voltage_offset = 74 + val * 2; 1418 1093 1094 + if (supports_optional_voltage_offset_range(margining)) { 1095 + val = FIELD_GET(USB4_MARGIN_CAP_0_VOLT_STEPS_OPT_MASK, 1096 + margining->caps[0]); 1097 + margining->voltage_steps_optional_range = val; 1098 + val = FIELD_GET(USB4_MARGIN_CAP_1_MAX_VOLT_OFS_OPT_MASK, 1099 + margining->caps[1]); 1100 + margining->max_voltage_offset_optional_range = 74 + val * 2; 1101 + } 1102 + 1419 1103 if (supports_time(margining)) { 1420 1104 val = FIELD_GET(USB4_MARGIN_CAP_1_TIME_STEPS_MASK, margining->caps[1]); 1421 1105 margining->time_steps = val; ··· 1461 1127 independent_time_margins(margining) == USB4_MARGIN_CAP_1_TIME_LR)) 1462 1128 debugfs_create_file("margin", 0600, dir, margining, 1463 1129 &margining_margin_fops); 1130 + 1131 + margining->error_counter = USB4_MARGIN_SW_ERROR_COUNTER_CLEAR; 1132 + margining->dwell_time = MIN_DWELL_TIME; 1133 + 1134 + if (supports_optional_voltage_offset_range(margining)) 1135 + debugfs_create_file("optional_voltage_offset", DEBUGFS_MODE, dir, margining, 1136 + &margining_optional_voltage_offset_fops); 1137 + 1138 + if (supports_software(margining)) { 1139 + debugfs_create_file("voltage_time_offset", DEBUGFS_MODE, dir, margining, 1140 + &margining_voltage_time_offset_fops); 1141 + debugfs_create_file("error_counter", DEBUGFS_MODE, dir, margining, 1142 + &margining_error_counter_fops); 1143 + debugfs_create_file("dwell_time", DEBUGFS_MODE, dir, margining, 1144 + &margining_dwell_time_fops); 1145 + } 1464 1146 return margining; 1465 1147 } 1466 1148
+13 -5
drivers/thunderbolt/sb_regs.h
··· 57 57 #define USB4_MARGIN_CAP_0_TIME BIT(5) 58 58 #define USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK GENMASK(12, 6) 59 59 #define USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK GENMASK(18, 13) 60 + #define USB4_MARGIN_CAP_0_OPT_VOLTAGE_SUPPORT BIT(19) 61 + #define USB4_MARGIN_CAP_0_VOLT_STEPS_OPT_MASK GENMASK(26, 20) 62 + #define USB4_MARGIN_CAP_1_MAX_VOLT_OFS_OPT_MASK GENMASK(7, 0) 60 63 #define USB4_MARGIN_CAP_1_TIME_DESTR BIT(8) 61 64 #define USB4_MARGIN_CAP_1_TIME_INDP_MASK GENMASK(10, 9) 62 65 #define USB4_MARGIN_CAP_1_TIME_MIN 0x0 ··· 75 72 #define USB4_MARGIN_HW_RH BIT(4) 76 73 #define USB4_MARGIN_HW_BER_MASK GENMASK(9, 5) 77 74 #define USB4_MARGIN_HW_BER_SHIFT 5 75 + #define USB4_MARGIN_HW_OPT_VOLTAGE BIT(10) 78 76 79 77 /* Applicable to all margin values */ 80 78 #define USB4_MARGIN_HW_RES_1_MARGIN_MASK GENMASK(6, 0) ··· 86 82 #define USB4_MARGIN_HW_RES_1_L1_LL_MARGIN_SHIFT 24 87 83 88 84 /* USB4_SB_OPCODE_RUN_SW_LANE_MARGINING */ 85 + #define USB4_MARGIN_SW_LANES_MASK GENMASK(2, 0) 86 + #define USB4_MARGIN_SW_LANE_0 0x0 87 + #define USB4_MARGIN_SW_LANE_1 0x1 88 + #define USB4_MARGIN_SW_ALL_LANES 0x7 89 89 #define USB4_MARGIN_SW_TIME BIT(3) 90 90 #define USB4_MARGIN_SW_RH BIT(4) 91 + #define USB4_MARGIN_SW_OPT_VOLTAGE BIT(5) 92 + #define USB4_MARGIN_SW_VT_MASK GENMASK(12, 6) 91 93 #define USB4_MARGIN_SW_COUNTER_MASK GENMASK(14, 13) 92 - #define USB4_MARGIN_SW_COUNTER_SHIFT 13 93 - #define USB4_MARGIN_SW_COUNTER_NOP 0x0 94 - #define USB4_MARGIN_SW_COUNTER_CLEAR 0x1 95 - #define USB4_MARGIN_SW_COUNTER_START 0x2 96 - #define USB4_MARGIN_SW_COUNTER_STOP 0x3 94 + 95 + #define USB4_MARGIN_SW_ERR_COUNTER_LANE_0_MASK GENMASK(3, 0) 96 + #define USB4_MARGIN_SW_ERR_COUNTER_LANE_1_MASK GENMASK(7, 4) 97 97 98 98 #endif
+38 -4
drivers/thunderbolt/tb.h
··· 1353 1353 int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, 1354 1354 u8 index, u8 reg, const void *buf, u8 size); 1355 1355 1356 + /** 1357 + * enum usb4_margin_sw_error_counter - Software margining error counter operation 1358 + * @USB4_MARGIN_SW_ERROR_COUNTER_NOP: No change in counter setup 1359 + * @USB4_MARGIN_SW_ERROR_COUNTER_CLEAR: Set the error counter to 0, enable counter 1360 + * @USB4_MARGIN_SW_ERROR_COUNTER_START: Start counter, count from last value 1361 + * @USB4_MARGIN_SW_ERROR_COUNTER_STOP: Stop counter, do not clear value 1362 + */ 1363 + enum usb4_margin_sw_error_counter { 1364 + USB4_MARGIN_SW_ERROR_COUNTER_NOP, 1365 + USB4_MARGIN_SW_ERROR_COUNTER_CLEAR, 1366 + USB4_MARGIN_SW_ERROR_COUNTER_START, 1367 + USB4_MARGIN_SW_ERROR_COUNTER_STOP, 1368 + }; 1369 + 1370 + /** 1371 + * struct usb4_port_margining_params - USB4 margining parameters 1372 + * @error_counter: Error counter operation for software margining 1373 + * @ber_level: Current BER level contour value 1374 + * @lanes: %0, %1 or %7 (all) 1375 + * @voltage_time_offset: Offset for voltage / time for software margining 1376 + * @optional_voltage_offset_range: Enable optional extended voltage range 1377 + * @right_high: %false if left/low margin test is performed, %true if right/high 1378 + * @time: %true if time margining is used instead of voltage 1379 + */ 1380 + struct usb4_port_margining_params { 1381 + enum usb4_margin_sw_error_counter error_counter; 1382 + u32 ber_level; 1383 + u32 lanes; 1384 + u32 voltage_time_offset; 1385 + bool optional_voltage_offset_range; 1386 + bool right_high; 1387 + bool time; 1388 + }; 1389 + 1356 1390 int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, 1357 1391 u8 index, u32 *caps); 1358 1392 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, 1359 - u8 index, unsigned int lanes, unsigned int ber_level, 1360 - bool timing, bool right_high, u32 *results); 1393 + u8 index, const struct usb4_port_margining_params *params, 1394 + u32 *results); 1361 1395 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, 1362 - u8 index, unsigned int lanes, bool timing, 1363 - bool right_high, u32 counter); 1396 + u8 index, const struct usb4_port_margining_params *params, 1397 + u32 *results); 1364 1398 int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, 1365 1399 u8 index, u32 *errors); 1366 1400
+35 -27
drivers/thunderbolt/usb4.c
··· 1653 1653 * @port: USB4 port 1654 1654 * @target: Sideband target 1655 1655 * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1656 - * @lanes: Which lanes to run (must match the port capabilities). Can be 1657 - * %0, %1 or %7. 1658 - * @ber_level: BER level contour value 1659 - * @timing: Perform timing margining instead of voltage 1660 - * @right_high: Use Right/high margin instead of left/low 1656 + * @params: Parameters for USB4 hardware margining 1661 1657 * @results: Array with at least two elements to hold the results 1662 1658 * 1663 1659 * Runs hardware lane margining on USB4 port and returns the result in 1664 1660 * @results. 1665 1661 */ 1666 1662 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, 1667 - u8 index, unsigned int lanes, unsigned int ber_level, 1668 - bool timing, bool right_high, u32 *results) 1663 + u8 index, const struct usb4_port_margining_params *params, 1664 + u32 *results) 1669 1665 { 1670 1666 u32 val; 1671 1667 int ret; 1672 1668 1673 - val = lanes; 1674 - if (timing) 1669 + if (WARN_ON_ONCE(!params)) 1670 + return -EINVAL; 1671 + 1672 + val = params->lanes; 1673 + if (params->time) 1675 1674 val |= USB4_MARGIN_HW_TIME; 1676 - if (right_high) 1675 + if (params->right_high) 1677 1676 val |= USB4_MARGIN_HW_RH; 1678 - if (ber_level) 1679 - val |= (ber_level << USB4_MARGIN_HW_BER_SHIFT) & 1680 - USB4_MARGIN_HW_BER_MASK; 1677 + if (params->ber_level) 1678 + val |= FIELD_PREP(USB4_MARGIN_HW_BER_MASK, params->ber_level); 1679 + if (params->optional_voltage_offset_range) 1680 + val |= USB4_MARGIN_HW_OPT_VOLTAGE; 1681 1681 1682 1682 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, 1683 1683 sizeof(val)); ··· 1698 1698 * @port: USB4 port 1699 1699 * @target: Sideband target 1700 1700 * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER 1701 - * @lanes: Which lanes to run (must match the port capabilities). Can be 1702 - * %0, %1 or %7. 1703 - * @timing: Perform timing margining instead of voltage 1704 - * @right_high: Use Right/high margin instead of left/low 1705 - * @counter: What to do with the error counter 1701 + * @params: Parameters for USB4 software margining 1702 + * @results: Data word for the operation completion data 1706 1703 * 1707 1704 * Runs software lane margining on USB4 port. Read back the error 1708 1705 * counters by calling usb4_port_sw_margin_errors(). Returns %0 in 1709 1706 * success and negative errno otherwise. 1710 1707 */ 1711 1708 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, 1712 - u8 index, unsigned int lanes, bool timing, 1713 - bool right_high, u32 counter) 1709 + u8 index, const struct usb4_port_margining_params *params, 1710 + u32 *results) 1714 1711 { 1715 1712 u32 val; 1716 1713 int ret; 1717 1714 1718 - val = lanes; 1719 - if (timing) 1715 + if (WARN_ON_ONCE(!params)) 1716 + return -EINVAL; 1717 + 1718 + val = params->lanes; 1719 + if (params->time) 1720 1720 val |= USB4_MARGIN_SW_TIME; 1721 - if (right_high) 1721 + if (params->optional_voltage_offset_range) 1722 + val |= USB4_MARGIN_SW_OPT_VOLTAGE; 1723 + if (params->right_high) 1722 1724 val |= USB4_MARGIN_SW_RH; 1723 - val |= (counter << USB4_MARGIN_SW_COUNTER_SHIFT) & 1724 - USB4_MARGIN_SW_COUNTER_MASK; 1725 + val |= FIELD_PREP(USB4_MARGIN_SW_COUNTER_MASK, params->error_counter); 1726 + val |= FIELD_PREP(USB4_MARGIN_SW_VT_MASK, params->voltage_time_offset); 1725 1727 1726 1728 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, 1727 1729 sizeof(val)); 1728 1730 if (ret) 1729 1731 return ret; 1730 1732 1731 - return usb4_port_sb_op(port, target, index, 1732 - USB4_SB_OPCODE_RUN_SW_LANE_MARGINING, 2500); 1733 + ret = usb4_port_sb_op(port, target, index, 1734 + USB4_SB_OPCODE_RUN_SW_LANE_MARGINING, 2500); 1735 + if (ret) 1736 + return ret; 1737 + 1738 + return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, 1739 + sizeof(*results)); 1740 + 1733 1741 } 1734 1742 1735 1743 /**
+2 -3
drivers/usb/cdns3/cdns3-pci-wrap.c
··· 37 37 #define PCI_DRIVER_NAME "cdns3-pci-usbss" 38 38 #define PLAT_DRIVER_NAME "cdns-usb3" 39 39 40 - #define CDNS_VENDOR_ID 0x17cd 41 - #define CDNS_DEVICE_ID 0x0100 40 + #define PCI_DEVICE_ID_CDNS_USB3 0x0100 42 41 43 42 static struct pci_dev *cdns3_get_second_fun(struct pci_dev *pdev) 44 43 { ··· 189 190 } 190 191 191 192 static const struct pci_device_id cdns3_pci_ids[] = { 192 - { PCI_DEVICE(CDNS_VENDOR_ID, CDNS_DEVICE_ID), }, 193 + { PCI_VDEVICE(CDNS, PCI_DEVICE_ID_CDNS_USB3) }, 193 194 { 0, } 194 195 }; 195 196
+15 -14
drivers/usb/cdns3/cdnsp-pci.c
··· 28 28 #define PCI_DRIVER_NAME "cdns-pci-usbssp" 29 29 #define PLAT_DRIVER_NAME "cdns-usbssp" 30 30 31 - #define CDNS_VENDOR_ID 0x17cd 32 - #define CDNS_DEVICE_ID 0x0200 33 - #define CDNS_DRD_ID 0x0100 34 - #define CDNS_DRD_IF (PCI_CLASS_SERIAL_USB << 8 | 0x80) 31 + #define PCI_DEVICE_ID_CDNS_USB3 0x0100 32 + #define PCI_DEVICE_ID_CDNS_UDC 0x0200 33 + 34 + #define PCI_CLASS_SERIAL_USB_CDNS_USB3 (PCI_CLASS_SERIAL_USB << 8 | 0x80) 35 + #define PCI_CLASS_SERIAL_USB_CDNS_UDC PCI_CLASS_SERIAL_USB_DEVICE 35 36 36 37 static struct pci_dev *cdnsp_get_second_fun(struct pci_dev *pdev) 37 38 { ··· 41 40 * Platform has two function. The fist keeps resources for 42 41 * Host/Device while the secon keeps resources for DRD/OTG. 43 42 */ 44 - if (pdev->device == CDNS_DEVICE_ID) 45 - return pci_get_device(pdev->vendor, CDNS_DRD_ID, NULL); 46 - else if (pdev->device == CDNS_DRD_ID) 47 - return pci_get_device(pdev->vendor, CDNS_DEVICE_ID, NULL); 43 + if (pdev->device == PCI_DEVICE_ID_CDNS_UDC) 44 + return pci_get_device(pdev->vendor, PCI_DEVICE_ID_CDNS_USB3, NULL); 45 + if (pdev->device == PCI_DEVICE_ID_CDNS_USB3) 46 + return pci_get_device(pdev->vendor, PCI_DEVICE_ID_CDNS_UDC, NULL); 48 47 49 48 return NULL; 50 49 } ··· 221 220 }; 222 221 223 222 static const struct pci_device_id cdnsp_pci_ids[] = { 224 - { PCI_VENDOR_ID_CDNS, CDNS_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 225 - PCI_CLASS_SERIAL_USB_DEVICE, PCI_ANY_ID }, 226 - { PCI_VENDOR_ID_CDNS, CDNS_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 227 - CDNS_DRD_IF, PCI_ANY_ID }, 228 - { PCI_VENDOR_ID_CDNS, CDNS_DRD_ID, PCI_ANY_ID, PCI_ANY_ID, 229 - CDNS_DRD_IF, PCI_ANY_ID }, 223 + { PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_UDC), 224 + .class = PCI_CLASS_SERIAL_USB_CDNS_UDC }, 225 + { PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_UDC), 226 + .class = PCI_CLASS_SERIAL_USB_CDNS_USB3 }, 227 + { PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_USB3), 228 + .class = PCI_CLASS_SERIAL_USB_CDNS_USB3 }, 230 229 { 0, } 231 230 }; 232 231
+4 -2
drivers/usb/cdns3/cdnsp-ring.c
··· 718 718 seg = cdnsp_trb_in_td(pdev, cur_td->start_seg, cur_td->first_trb, 719 719 cur_td->last_trb, hw_deq); 720 720 721 - if (seg && (pep->ep_state & EP_ENABLED)) 721 + if (seg && (pep->ep_state & EP_ENABLED) && 722 + !(pep->ep_state & EP_DIS_IN_RROGRESS)) 722 723 cdnsp_find_new_dequeue_state(pdev, pep, preq->request.stream_id, 723 724 cur_td, &deq_state); 724 725 else ··· 737 736 * During disconnecting all endpoint will be disabled so we don't 738 737 * have to worry about updating dequeue pointer. 739 738 */ 740 - if (pdev->cdnsp_state & CDNSP_STATE_DISCONNECT_PENDING) { 739 + if (pdev->cdnsp_state & CDNSP_STATE_DISCONNECT_PENDING || 740 + pep->ep_state & EP_DIS_IN_RROGRESS) { 741 741 status = -ESHUTDOWN; 742 742 ret = cdnsp_cmd_set_deq(pdev, pep, &deq_state); 743 743 }
+3 -1
drivers/usb/cdns3/host.c
··· 62 62 .resume_quirk = xhci_cdns3_resume_quirk, 63 63 }; 64 64 65 - static const struct xhci_plat_priv xhci_plat_cdnsp_xhci; 65 + static const struct xhci_plat_priv xhci_plat_cdnsp_xhci = { 66 + .quirks = XHCI_CDNS_SCTX_QUIRK, 67 + }; 66 68 67 69 static int __cdns_host_init(struct cdns *cdns) 68 70 {
+1 -1
drivers/usb/chipidea/ci_hdrc_imx.c
··· 128 128 * In case the fsl,usbmisc property is not present this device doesn't 129 129 * need usbmisc. Return NULL (which is no error here) 130 130 */ 131 - if (!of_get_property(np, "fsl,usbmisc", NULL)) 131 + if (!of_property_present(np, "fsl,usbmisc")) 132 132 return NULL; 133 133 134 134 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+2 -2
drivers/usb/chipidea/ci_hdrc_npcm.c
··· 18 18 struct ci_hdrc_platform_data pdata; 19 19 }; 20 20 21 - static int npcm_udc_notify_event(struct ci_hdrc *ci, unsigned event) 21 + static int npcm_udc_notify_event(struct ci_hdrc *ci, unsigned int event) 22 22 { 23 23 struct device *dev = ci->dev->parent; 24 24 ··· 28 28 hw_write(ci, OP_USBMODE, 0xffffffff, 0x0); 29 29 break; 30 30 default: 31 - dev_dbg(dev, "unknown ci_hdrc event (%d)\n",event); 31 + dev_dbg(dev, "unknown ci_hdrc event (%d)\n", event); 32 32 break; 33 33 } 34 34
+7 -1
drivers/usb/chipidea/udc.c
··· 86 86 hw_write(ci, OP_ENDPTLISTADDR, ~0, dma); 87 87 /* interrupt, error, port change, reset, sleep/suspend */ 88 88 hw_write(ci, OP_USBINTR, ~0, 89 - USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI); 89 + USBi_UI|USBi_UEI|USBi_PCI|USBi_URI); 90 90 } else { 91 91 hw_write(ci, OP_USBINTR, ~0, 0); 92 92 } ··· 877 877 __acquires(ci->lock) 878 878 { 879 879 int retval; 880 + u32 intr; 880 881 881 882 spin_unlock(&ci->lock); 882 883 if (ci->gadget.speed != USB_SPEED_UNKNOWN) ··· 890 889 retval = hw_usb_reset(ci); 891 890 if (retval) 892 891 goto done; 892 + 893 + /* clear SLI */ 894 + hw_write(ci, OP_USBSTS, USBi_SLI, USBi_SLI); 895 + intr = hw_read(ci, OP_USBINTR, ~0); 896 + hw_write(ci, OP_USBINTR, ~0, intr | USBi_SLI); 893 897 894 898 ci->status = usb_ep_alloc_request(&ci->ep0in->ep, GFP_ATOMIC); 895 899 if (ci->status == NULL)
+2
drivers/usb/class/cdc-acm.c
··· 962 962 struct acm *acm = tty->driver_data; 963 963 964 964 ss->line = acm->minor; 965 + mutex_lock(&acm->port.mutex); 965 966 ss->close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; 966 967 ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? 967 968 ASYNC_CLOSING_WAIT_NONE : 968 969 jiffies_to_msecs(acm->port.closing_wait) / 10; 970 + mutex_unlock(&acm->port.mutex); 969 971 return 0; 970 972 } 971 973
+1 -1
drivers/usb/class/usbtmc.c
··· 754 754 if (!urb) 755 755 return NULL; 756 756 757 - dmabuf = kmalloc(bufsize, GFP_KERNEL); 757 + dmabuf = kzalloc(bufsize, GFP_KERNEL); 758 758 if (!dmabuf) { 759 759 usb_free_urb(urb); 760 760 return NULL;
+10 -12
drivers/usb/common/common.c
··· 107 107 */ 108 108 enum usb_device_speed usb_get_maximum_speed(struct device *dev) 109 109 { 110 - const char *maximum_speed; 110 + const char *p = "maximum-speed"; 111 111 int ret; 112 112 113 - ret = device_property_read_string(dev, "maximum-speed", &maximum_speed); 114 - if (ret < 0) 115 - return USB_SPEED_UNKNOWN; 116 - 117 - ret = match_string(ssp_rate, ARRAY_SIZE(ssp_rate), maximum_speed); 113 + ret = device_property_match_property_string(dev, p, ssp_rate, ARRAY_SIZE(ssp_rate)); 118 114 if (ret > 0) 119 115 return USB_SPEED_SUPER_PLUS; 120 116 121 - ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); 122 - return (ret < 0) ? USB_SPEED_UNKNOWN : ret; 117 + ret = device_property_match_property_string(dev, p, speed_names, ARRAY_SIZE(speed_names)); 118 + if (ret > 0) 119 + return ret; 120 + 121 + return USB_SPEED_UNKNOWN; 123 122 } 124 123 EXPORT_SYMBOL_GPL(usb_get_maximum_speed); 125 124 ··· 275 276 */ 276 277 enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) 277 278 { 278 - struct device_node *controller = NULL; 279 + struct device_node *controller; 279 280 struct of_phandle_args args; 280 281 const char *dr_mode; 281 282 int index; 282 283 int err; 283 284 284 - do { 285 - controller = of_find_node_with_property(controller, "phys"); 285 + for_each_node_with_property(controller, "phys") { 286 286 if (!of_device_is_available(controller)) 287 287 continue; 288 288 index = 0; ··· 304 306 goto finish; 305 307 index++; 306 308 } while (args.np); 307 - } while (controller); 309 + } 308 310 309 311 finish: 310 312 err = of_property_read_string(controller, "dr_mode", &dr_mode);
+53
drivers/usb/core/usb-acpi.c
··· 142 142 } 143 143 EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); 144 144 145 + /** 146 + * usb_acpi_add_usb4_devlink - add device link to USB4 Host Interface for tunneled USB3 devices 147 + * 148 + * @udev: Tunneled USB3 device connected to a roothub. 149 + * 150 + * Adds a device link between a tunneled USB3 device and the USB4 Host Interface 151 + * device to ensure correct runtime PM suspend and resume order. This function 152 + * should only be called for tunneled USB3 devices. 153 + * The USB4 Host Interface this tunneled device depends on is found from the roothub 154 + * port ACPI device specific data _DSD entry. 155 + * 156 + * Return: negative error code on failure, 0 otherwise 157 + */ 158 + static int usb_acpi_add_usb4_devlink(struct usb_device *udev) 159 + { 160 + const struct device_link *link; 161 + struct usb_port *port_dev; 162 + struct usb_hub *hub; 163 + 164 + if (!udev->parent || udev->parent->parent) 165 + return 0; 166 + 167 + hub = usb_hub_to_struct_hub(udev->parent); 168 + port_dev = hub->ports[udev->portnum - 1]; 169 + 170 + struct fwnode_handle *nhi_fwnode __free(fwnode_handle) = 171 + fwnode_find_reference(dev_fwnode(&port_dev->dev), "usb4-host-interface", 0); 172 + 173 + if (IS_ERR(nhi_fwnode)) 174 + return 0; 175 + 176 + link = device_link_add(&port_dev->child->dev, nhi_fwnode->dev, 177 + DL_FLAG_AUTOREMOVE_CONSUMER | 178 + DL_FLAG_RPM_ACTIVE | 179 + DL_FLAG_PM_RUNTIME); 180 + if (!link) { 181 + dev_err(&port_dev->dev, "Failed to created device link from %s to %s\n", 182 + dev_name(&port_dev->child->dev), dev_name(nhi_fwnode->dev)); 183 + return -EINVAL; 184 + } 185 + 186 + dev_dbg(&port_dev->dev, "Created device link from %s to %s\n", 187 + dev_name(&port_dev->child->dev), dev_name(nhi_fwnode->dev)); 188 + 189 + return 0; 190 + } 191 + 145 192 /* 146 193 * Private to usb-acpi, all the core needs to know is that 147 194 * port_dev->location is non-zero when it has been set by the firmware. ··· 308 261 hub = usb_hub_to_struct_hub(udev->parent); 309 262 if (!hub) 310 263 return NULL; 264 + 265 + 266 + /* Tunneled USB3 devices depend on USB4 Host Interface, set device link to it */ 267 + if (udev->speed >= USB_SPEED_SUPER && 268 + udev->tunnel_mode != USB_LINK_NATIVE) 269 + usb_acpi_add_usb4_devlink(udev); 311 270 312 271 /* 313 272 * This is an embedded USB device connected to a port and such
+1
drivers/usb/dwc2/debugfs.c
··· 702 702 print_param(seq, p, uframe_sched); 703 703 print_param(seq, p, external_id_pin_ctl); 704 704 print_param(seq, p, power_down); 705 + print_param(seq, p, no_clock_gating); 705 706 print_param(seq, p, lpm); 706 707 print_param(seq, p, lpm_clock_gating); 707 708 print_param(seq, p, besl);
+9
drivers/usb/dwc2/drd.c
··· 127 127 role = USB_ROLE_DEVICE; 128 128 } 129 129 130 + if ((IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || 131 + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)) && 132 + dwc2_is_device_mode(hsotg) && 133 + hsotg->lx_state == DWC2_L2 && 134 + hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE && 135 + hsotg->bus_suspended && 136 + !hsotg->params.no_clock_gating) 137 + dwc2_gadget_exit_clock_gating(hsotg, 0); 138 + 130 139 if (role == USB_ROLE_HOST) { 131 140 already = dwc2_ovr_avalid(hsotg, true); 132 141 } else if (role == USB_ROLE_DEVICE) {
+2
drivers/usb/dwc2/params.c
··· 23 23 p->max_transfer_size = 65535; 24 24 p->max_packet_count = 511; 25 25 p->ahbcfg = 0x10; 26 + p->no_clock_gating = true; 26 27 } 27 28 28 29 static void dwc2_set_his_params(struct dwc2_hsotg *hsotg) ··· 353 352 MODULE_DEVICE_TABLE(of, dwc2_of_match_table); 354 353 355 354 const struct acpi_device_id dwc2_acpi_match[] = { 355 + /* This ID refers to the same USB IP as of_device_id brcm,bcm2835-usb */ 356 356 { "BCM2848", (kernel_ulong_t)dwc2_set_bcm_params }, 357 357 { }, 358 358 };
+14 -12
drivers/usb/dwc2/platform.c
··· 469 469 470 470 spin_lock_init(&hsotg->lock); 471 471 472 - hsotg->irq = platform_get_irq(dev, 0); 473 - if (hsotg->irq < 0) 474 - return hsotg->irq; 475 - 476 - dev_dbg(hsotg->dev, "registering common handler for irq%d\n", 477 - hsotg->irq); 478 - retval = devm_request_irq(hsotg->dev, hsotg->irq, 479 - dwc2_handle_common_intr, IRQF_SHARED, 480 - dev_name(hsotg->dev), hsotg); 481 - if (retval) 482 - return retval; 483 - 484 472 hsotg->vbus_supply = devm_regulator_get_optional(hsotg->dev, "vbus"); 485 473 if (IS_ERR(hsotg->vbus_supply)) { 486 474 retval = PTR_ERR(hsotg->vbus_supply); ··· 509 521 510 522 /* Detect config values from hardware */ 511 523 retval = dwc2_get_hwparams(hsotg); 524 + if (retval) 525 + goto error; 526 + 527 + hsotg->irq = platform_get_irq(dev, 0); 528 + if (hsotg->irq < 0) { 529 + retval = hsotg->irq; 530 + goto error; 531 + } 532 + 533 + dev_dbg(hsotg->dev, "registering common handler for irq%d\n", 534 + hsotg->irq); 535 + retval = devm_request_irq(hsotg->dev, hsotg->irq, 536 + dwc2_handle_common_intr, IRQF_SHARED, 537 + dev_name(hsotg->dev), hsotg); 512 538 if (retval) 513 539 goto error; 514 540
+51 -62
drivers/usb/dwc3/dwc3-imx8mp.c
··· 5 5 * Copyright (c) 2020 NXP. 6 6 */ 7 7 8 + #include <linux/cleanup.h> 8 9 #include <linux/clk.h> 9 10 #include <linux/interrupt.h> 10 11 #include <linux/io.h> ··· 97 96 writel(value, dwc3_imx->glue_base + USB_CTRL1); 98 97 } 99 98 100 - static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx) 99 + static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx, 100 + pm_message_t msg) 101 101 { 102 102 struct dwc3 *dwc3 = platform_get_drvdata(dwc3_imx->dwc3); 103 103 u32 val; ··· 108 106 109 107 val = readl(dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 110 108 111 - if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci) 112 - val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN | 113 - USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN; 114 - else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE) 109 + if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci) { 110 + val |= USB_WAKEUP_EN | USB_WAKEUP_DPDM_EN; 111 + if (PMSG_IS_AUTO(msg)) 112 + val |= USB_WAKEUP_SS_CONN | USB_WAKEUP_U3_EN; 113 + } else { 115 114 val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN | 116 115 USB_WAKEUP_VBUS_SRC_SESS_VAL; 116 + } 117 117 118 118 writel(val, dwc3_imx->hsio_blk_base + USB_WAKEUP_CTRL); 119 119 } ··· 148 144 return IRQ_HANDLED; 149 145 } 150 146 147 + static int dwc3_imx8mp_set_software_node(struct device *dev) 148 + { 149 + struct property_entry props[3] = { 0 }; 150 + int prop_idx = 0; 151 + 152 + props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-missing-cas-quirk"); 153 + props[prop_idx++] = PROPERTY_ENTRY_BOOL("xhci-skip-phy-init-quirk"); 154 + 155 + return device_create_managed_software_node(dev, props, NULL); 156 + } 157 + 151 158 static int dwc3_imx8mp_probe(struct platform_device *pdev) 152 159 { 153 160 struct device *dev = &pdev->dev; 154 - struct device_node *dwc3_np, *node = dev->of_node; 161 + struct device_node *node = dev->of_node; 155 162 struct dwc3_imx8mp *dwc3_imx; 156 163 struct resource *res; 157 164 int err, irq; ··· 193 178 return PTR_ERR(dwc3_imx->glue_base); 194 179 } 195 180 196 - dwc3_imx->hsio_clk = devm_clk_get(dev, "hsio"); 197 - if (IS_ERR(dwc3_imx->hsio_clk)) { 198 - err = PTR_ERR(dwc3_imx->hsio_clk); 199 - dev_err(dev, "Failed to get hsio clk, err=%d\n", err); 200 - return err; 201 - } 181 + dwc3_imx->hsio_clk = devm_clk_get_enabled(dev, "hsio"); 182 + if (IS_ERR(dwc3_imx->hsio_clk)) 183 + return dev_err_probe(dev, PTR_ERR(dwc3_imx->hsio_clk), 184 + "Failed to get hsio clk\n"); 202 185 203 - err = clk_prepare_enable(dwc3_imx->hsio_clk); 204 - if (err) { 205 - dev_err(dev, "Failed to enable hsio clk, err=%d\n", err); 206 - return err; 207 - } 208 - 209 - dwc3_imx->suspend_clk = devm_clk_get(dev, "suspend"); 210 - if (IS_ERR(dwc3_imx->suspend_clk)) { 211 - err = PTR_ERR(dwc3_imx->suspend_clk); 212 - dev_err(dev, "Failed to get suspend clk, err=%d\n", err); 213 - goto disable_hsio_clk; 214 - } 215 - 216 - err = clk_prepare_enable(dwc3_imx->suspend_clk); 217 - if (err) { 218 - dev_err(dev, "Failed to enable suspend clk, err=%d\n", err); 219 - goto disable_hsio_clk; 220 - } 186 + dwc3_imx->suspend_clk = devm_clk_get_enabled(dev, "suspend"); 187 + if (IS_ERR(dwc3_imx->suspend_clk)) 188 + return dev_err_probe(dev, PTR_ERR(dwc3_imx->suspend_clk), 189 + "Failed to get suspend clk\n"); 221 190 222 191 irq = platform_get_irq(pdev, 0); 223 - if (irq < 0) { 224 - err = irq; 225 - goto disable_clks; 226 - } 192 + if (irq < 0) 193 + return irq; 227 194 dwc3_imx->irq = irq; 195 + 196 + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(node, 197 + "snps,dwc3"); 198 + if (!dwc3_np) 199 + return dev_err_probe(dev, -ENODEV, "failed to find dwc3 core child\n"); 228 200 229 201 imx8mp_configure_glue(dwc3_imx); 230 202 ··· 221 219 if (err < 0) 222 220 goto disable_rpm; 223 221 224 - dwc3_np = of_get_compatible_child(node, "snps,dwc3"); 225 - if (!dwc3_np) { 222 + err = dwc3_imx8mp_set_software_node(dev); 223 + if (err) { 226 224 err = -ENODEV; 227 - dev_err(dev, "failed to find dwc3 core child\n"); 225 + dev_err(dev, "failed to create software node\n"); 228 226 goto disable_rpm; 229 227 } 230 228 231 229 err = of_platform_populate(node, NULL, NULL, dev); 232 230 if (err) { 233 231 dev_err(&pdev->dev, "failed to create dwc3 core\n"); 234 - goto err_node_put; 232 + goto disable_rpm; 235 233 } 236 234 237 235 dwc3_imx->dwc3 = of_find_device_by_node(dwc3_np); ··· 240 238 err = -ENODEV; 241 239 goto depopulate; 242 240 } 243 - of_node_put(dwc3_np); 244 241 245 242 err = devm_request_threaded_irq(dev, irq, NULL, dwc3_imx8mp_interrupt, 246 243 IRQF_ONESHOT, dev_name(dev), dwc3_imx); ··· 255 254 256 255 depopulate: 257 256 of_platform_depopulate(dev); 258 - err_node_put: 259 - of_node_put(dwc3_np); 260 257 disable_rpm: 261 258 pm_runtime_disable(dev); 262 259 pm_runtime_put_noidle(dev); 263 - disable_clks: 264 - clk_disable_unprepare(dwc3_imx->suspend_clk); 265 - disable_hsio_clk: 266 - clk_disable_unprepare(dwc3_imx->hsio_clk); 267 260 268 261 return err; 269 262 } 270 263 271 264 static void dwc3_imx8mp_remove(struct platform_device *pdev) 272 265 { 273 - struct dwc3_imx8mp *dwc3_imx = platform_get_drvdata(pdev); 274 266 struct device *dev = &pdev->dev; 275 267 276 268 pm_runtime_get_sync(dev); 277 269 of_platform_depopulate(dev); 278 270 279 - clk_disable_unprepare(dwc3_imx->suspend_clk); 280 - clk_disable_unprepare(dwc3_imx->hsio_clk); 281 - 282 271 pm_runtime_disable(dev); 283 272 pm_runtime_put_noidle(dev); 284 273 } 285 274 286 - static int __maybe_unused dwc3_imx8mp_suspend(struct dwc3_imx8mp *dwc3_imx, 287 - pm_message_t msg) 275 + static int dwc3_imx8mp_suspend(struct dwc3_imx8mp *dwc3_imx, pm_message_t msg) 288 276 { 289 277 if (dwc3_imx->pm_suspended) 290 278 return 0; 291 279 292 280 /* Wakeup enable */ 293 281 if (PMSG_IS_AUTO(msg) || device_may_wakeup(dwc3_imx->dev)) 294 - dwc3_imx8mp_wakeup_enable(dwc3_imx); 282 + dwc3_imx8mp_wakeup_enable(dwc3_imx, msg); 295 283 296 284 dwc3_imx->pm_suspended = true; 297 285 298 286 return 0; 299 287 } 300 288 301 - static int __maybe_unused dwc3_imx8mp_resume(struct dwc3_imx8mp *dwc3_imx, 302 - pm_message_t msg) 289 + static int dwc3_imx8mp_resume(struct dwc3_imx8mp *dwc3_imx, pm_message_t msg) 303 290 { 304 291 struct dwc3 *dwc = platform_get_drvdata(dwc3_imx->dwc3); 305 292 int ret = 0; ··· 320 331 return ret; 321 332 } 322 333 323 - static int __maybe_unused dwc3_imx8mp_pm_suspend(struct device *dev) 334 + static int dwc3_imx8mp_pm_suspend(struct device *dev) 324 335 { 325 336 struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); 326 337 int ret; ··· 338 349 return ret; 339 350 } 340 351 341 - static int __maybe_unused dwc3_imx8mp_pm_resume(struct device *dev) 352 + static int dwc3_imx8mp_pm_resume(struct device *dev) 342 353 { 343 354 struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); 344 355 int ret; ··· 368 379 return ret; 369 380 } 370 381 371 - static int __maybe_unused dwc3_imx8mp_runtime_suspend(struct device *dev) 382 + static int dwc3_imx8mp_runtime_suspend(struct device *dev) 372 383 { 373 384 struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); 374 385 ··· 377 388 return dwc3_imx8mp_suspend(dwc3_imx, PMSG_AUTO_SUSPEND); 378 389 } 379 390 380 - static int __maybe_unused dwc3_imx8mp_runtime_resume(struct device *dev) 391 + static int dwc3_imx8mp_runtime_resume(struct device *dev) 381 392 { 382 393 struct dwc3_imx8mp *dwc3_imx = dev_get_drvdata(dev); 383 394 ··· 387 398 } 388 399 389 400 static const struct dev_pm_ops dwc3_imx8mp_dev_pm_ops = { 390 - SET_SYSTEM_SLEEP_PM_OPS(dwc3_imx8mp_pm_suspend, dwc3_imx8mp_pm_resume) 391 - SET_RUNTIME_PM_OPS(dwc3_imx8mp_runtime_suspend, 392 - dwc3_imx8mp_runtime_resume, NULL) 401 + SYSTEM_SLEEP_PM_OPS(dwc3_imx8mp_pm_suspend, dwc3_imx8mp_pm_resume) 402 + RUNTIME_PM_OPS(dwc3_imx8mp_runtime_suspend, dwc3_imx8mp_runtime_resume, 403 + NULL) 393 404 }; 394 405 395 406 static const struct of_device_id dwc3_imx8mp_of_match[] = { ··· 403 414 .remove_new = dwc3_imx8mp_remove, 404 415 .driver = { 405 416 .name = "imx8mp-dwc3", 406 - .pm = &dwc3_imx8mp_dev_pm_ops, 417 + .pm = pm_ptr(&dwc3_imx8mp_dev_pm_ops), 407 418 .of_match_table = dwc3_imx8mp_of_match, 408 419 }, 409 420 };
+4 -15
drivers/usb/dwc3/dwc3-octeon.c
··· 419 419 int ref_clk_sel, ref_clk_fsel, mpll_mul; 420 420 int power_active_low, power_gpio; 421 421 int err, len; 422 - u32 clock_rate; 422 + u32 clock_rate, gpio_pwr[3]; 423 423 424 424 if (of_property_read_u32(node, "refclk-frequency", &clock_rate)) { 425 425 dev_err(dev, "No UCTL \"refclk-frequency\"\n"); ··· 476 476 477 477 power_gpio = DWC3_GPIO_POWER_NONE; 478 478 power_active_low = 0; 479 - if (of_find_property(node, "power", &len)) { 480 - u32 gpio_pwr[3]; 481 - 482 - switch (len) { 483 - case 8: 484 - of_property_read_u32_array(node, "power", gpio_pwr, 2); 485 - break; 486 - case 12: 487 - of_property_read_u32_array(node, "power", gpio_pwr, 3); 479 + len = of_property_read_variable_u32_array(node, "power", gpio_pwr, 2, 3); 480 + if (len > 0) { 481 + if (len == 3) 488 482 power_active_low = gpio_pwr[2] & 0x01; 489 - break; 490 - default: 491 - dev_err(dev, "invalid power configuration\n"); 492 - return -EINVAL; 493 - } 494 483 power_gpio = gpio_pwr[1]; 495 484 } 496 485
+6 -10
drivers/usb/dwc3/dwc3-qcom.c
··· 4 4 * Inspired by dwc3-of-simple.c 5 5 */ 6 6 7 + #include <linux/cleanup.h> 7 8 #include <linux/io.h> 8 9 #include <linux/of.h> 9 10 #include <linux/clk.h> ··· 703 702 static int dwc3_qcom_of_register_core(struct platform_device *pdev) 704 703 { 705 704 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 706 - struct device_node *np = pdev->dev.of_node, *dwc3_np; 705 + struct device_node *np = pdev->dev.of_node; 707 706 struct device *dev = &pdev->dev; 708 707 int ret; 709 708 710 - dwc3_np = of_get_compatible_child(np, "snps,dwc3"); 709 + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, 710 + "snps,dwc3"); 711 711 if (!dwc3_np) { 712 712 dev_err(dev, "failed to find dwc3 core child\n"); 713 713 return -ENODEV; ··· 717 715 ret = of_platform_populate(np, NULL, NULL, dev); 718 716 if (ret) { 719 717 dev_err(dev, "failed to register dwc3 core - %d\n", ret); 720 - goto node_put; 718 + return ret; 721 719 } 722 720 723 721 qcom->dwc3 = of_find_device_by_node(dwc3_np); ··· 727 725 of_platform_depopulate(dev); 728 726 } 729 727 730 - node_put: 731 - of_node_put(dwc3_np); 732 - 733 728 return ret; 734 729 } 735 730 ··· 735 736 struct device_node *np = pdev->dev.of_node; 736 737 struct device *dev = &pdev->dev; 737 738 struct dwc3_qcom *qcom; 738 - struct resource *res; 739 739 int ret, i; 740 740 bool ignore_pipe_clk; 741 741 bool wakeup_source; ··· 772 774 goto reset_assert; 773 775 } 774 776 775 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 776 - 777 - qcom->qscratch_base = devm_ioremap_resource(dev, res); 777 + qcom->qscratch_base = devm_platform_ioremap_resource(pdev, 0); 778 778 if (IS_ERR(qcom->qscratch_base)) { 779 779 ret = PTR_ERR(qcom->qscratch_base); 780 780 goto clk_disable;
+15 -37
drivers/usb/dwc3/dwc3-rtk.c
··· 6 6 * 7 7 */ 8 8 9 + #include <linux/cleanup.h> 9 10 #include <linux/module.h> 10 11 #include <linux/kernel.h> 11 12 #include <linux/platform_device.h> ··· 174 173 175 174 static enum usb_device_speed __get_dwc3_maximum_speed(struct device_node *np) 176 175 { 177 - struct device_node *dwc3_np; 178 176 const char *maximum_speed; 179 177 int ret; 180 178 181 - dwc3_np = of_get_compatible_child(np, "snps,dwc3"); 179 + struct device_node *dwc3_np __free(device_node) = of_get_compatible_child(np, 180 + "snps,dwc3"); 182 181 if (!dwc3_np) 183 182 return USB_SPEED_UNKNOWN; 184 183 185 184 ret = of_property_read_string(dwc3_np, "maximum-speed", &maximum_speed); 186 185 if (ret < 0) 187 - goto out; 186 + return USB_SPEED_UNKNOWN; 188 187 189 188 ret = match_string(speed_names, ARRAY_SIZE(speed_names), maximum_speed); 190 - 191 - out: 192 - of_node_put(dwc3_np); 193 189 194 190 return (ret < 0) ? USB_SPEED_UNKNOWN : ret; 195 191 } ··· 274 276 struct device_node *node = dev->of_node; 275 277 struct platform_device *dwc3_pdev; 276 278 struct device *dwc3_dev; 277 - struct device_node *dwc3_node; 278 279 enum usb_dr_mode dr_mode; 279 280 int ret = 0; 280 281 ··· 287 290 return ret; 288 291 } 289 292 290 - dwc3_node = of_get_compatible_child(node, "snps,dwc3"); 293 + struct device_node *dwc3_node __free(device_node) = of_get_compatible_child(node, 294 + "snps,dwc3"); 291 295 if (!dwc3_node) { 292 296 dev_err(dev, "failed to find dwc3 core node\n"); 293 297 ret = -ENODEV; ··· 299 301 if (!dwc3_pdev) { 300 302 dev_err(dev, "failed to find dwc3 core platform_device\n"); 301 303 ret = -ENODEV; 302 - goto err_node_put; 304 + goto depopulate; 303 305 } 304 306 305 307 dwc3_dev = &dwc3_pdev->dev; ··· 341 343 switch_usb2_role(rtk, rtk->cur_role); 342 344 343 345 platform_device_put(dwc3_pdev); 344 - of_node_put(dwc3_node); 345 346 346 347 return 0; 347 348 348 349 err_pdev_put: 349 350 platform_device_put(dwc3_pdev); 350 - err_node_put: 351 - of_node_put(dwc3_node); 352 351 depopulate: 353 352 of_platform_depopulate(dev); 354 353 ··· 358 363 struct device *dev = &pdev->dev; 359 364 struct resource *res; 360 365 void __iomem *regs; 361 - int ret = 0; 362 366 363 367 rtk = devm_kzalloc(dev, sizeof(*rtk), GFP_KERNEL); 364 - if (!rtk) { 365 - ret = -ENOMEM; 366 - goto out; 367 - } 368 + if (!rtk) 369 + return -ENOMEM; 368 370 369 371 platform_set_drvdata(pdev, rtk); 370 372 371 373 rtk->dev = dev; 372 374 373 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 374 - if (!res) { 375 - dev_err(dev, "missing memory resource\n"); 376 - ret = -ENODEV; 377 - goto out; 378 - } 379 - 380 - regs = devm_ioremap_resource(dev, res); 381 - if (IS_ERR(regs)) { 382 - ret = PTR_ERR(regs); 383 - goto out; 384 - } 375 + regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 376 + if (IS_ERR(regs)) 377 + return PTR_ERR(regs); 385 378 386 379 rtk->regs = regs; 387 380 rtk->regs_size = resource_size(res); ··· 377 394 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 378 395 if (res) { 379 396 rtk->pm_base = devm_ioremap_resource(dev, res); 380 - if (IS_ERR(rtk->pm_base)) { 381 - ret = PTR_ERR(rtk->pm_base); 382 - goto out; 383 - } 397 + if (IS_ERR(rtk->pm_base)) 398 + return PTR_ERR(rtk->pm_base); 384 399 } 385 400 386 - ret = dwc3_rtk_probe_dwc3_core(rtk); 387 - 388 - out: 389 - return ret; 401 + return dwc3_rtk_probe_dwc3_core(rtk); 390 402 } 391 403 392 404 static void dwc3_rtk_remove(struct platform_device *pdev)
+17 -21
drivers/usb/dwc3/dwc3-st.c
··· 14 14 * Inspired by dwc3-omap.c and dwc3-exynos.c. 15 15 */ 16 16 17 + #include <linux/cleanup.h> 17 18 #include <linux/delay.h> 18 19 #include <linux/interrupt.h> 19 20 #include <linux/io.h> ··· 198 197 struct st_dwc3 *dwc3_data; 199 198 struct resource *res; 200 199 struct device *dev = &pdev->dev; 201 - struct device_node *node = dev->of_node, *child; 200 + struct device_node *node = dev->of_node; 202 201 struct platform_device *child_pdev; 203 202 struct regmap *regmap; 204 203 int ret; ··· 225 224 226 225 dwc3_data->syscfg_reg_off = res->start; 227 226 228 - dev_vdbg(&pdev->dev, "glue-logic addr 0x%pK, syscfg-reg offset 0x%x\n", 227 + dev_vdbg(dev, "glue-logic addr 0x%pK, syscfg-reg offset 0x%x\n", 229 228 dwc3_data->glue_base, dwc3_data->syscfg_reg_off); 229 + 230 + struct device_node *child __free(device_node) = of_get_compatible_child(node, 231 + "snps,dwc3"); 232 + if (!child) { 233 + dev_err(dev, "failed to find dwc3 core node\n"); 234 + return -ENODEV; 235 + } 230 236 231 237 dwc3_data->rstc_pwrdn = 232 238 devm_reset_control_get_exclusive(dev, "powerdown"); 233 - if (IS_ERR(dwc3_data->rstc_pwrdn)) { 234 - dev_err(&pdev->dev, "could not get power controller\n"); 235 - return PTR_ERR(dwc3_data->rstc_pwrdn); 236 - } 239 + if (IS_ERR(dwc3_data->rstc_pwrdn)) 240 + return dev_err_probe(dev, PTR_ERR(dwc3_data->rstc_pwrdn), 241 + "could not get power controller\n"); 237 242 238 243 /* Manage PowerDown */ 239 244 reset_control_deassert(dwc3_data->rstc_pwrdn); ··· 247 240 dwc3_data->rstc_rst = 248 241 devm_reset_control_get_shared(dev, "softreset"); 249 242 if (IS_ERR(dwc3_data->rstc_rst)) { 250 - dev_err(&pdev->dev, "could not get reset controller\n"); 251 - ret = PTR_ERR(dwc3_data->rstc_rst); 243 + ret = dev_err_probe(dev, PTR_ERR(dwc3_data->rstc_rst), 244 + "could not get reset controller\n"); 252 245 goto undo_powerdown; 253 246 } 254 247 255 248 /* Manage SoftReset */ 256 249 reset_control_deassert(dwc3_data->rstc_rst); 257 250 258 - child = of_get_compatible_child(node, "snps,dwc3"); 259 - if (!child) { 260 - dev_err(&pdev->dev, "failed to find dwc3 core node\n"); 261 - ret = -ENODEV; 262 - goto err_node_put; 263 - } 264 - 265 251 /* Allocate and initialize the core */ 266 252 ret = of_platform_populate(node, NULL, NULL, dev); 267 253 if (ret) { 268 254 dev_err(dev, "failed to add dwc3 core\n"); 269 - goto err_node_put; 255 + goto undo_softreset; 270 256 } 271 257 272 258 child_pdev = of_find_device_by_node(child); ··· 270 270 } 271 271 272 272 dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev); 273 - of_node_put(child); 274 273 platform_device_put(child_pdev); 275 274 276 275 /* ··· 281 282 ret = st_dwc3_drd_init(dwc3_data); 282 283 if (ret) { 283 284 dev_err(dev, "drd initialisation failed\n"); 284 - of_platform_depopulate(dev); 285 - goto undo_softreset; 285 + goto depopulate; 286 286 } 287 287 288 288 /* ST glue logic init */ ··· 292 294 293 295 depopulate: 294 296 of_platform_depopulate(dev); 295 - err_node_put: 296 - of_node_put(child); 297 297 undo_softreset: 298 298 reset_control_assert(dwc3_data->rstc_rst); 299 299 undo_powerdown:
+2 -5
drivers/usb/dwc3/dwc3-xilinx.c
··· 285 285 return -ENOMEM; 286 286 287 287 regs = devm_platform_ioremap_resource(pdev, 0); 288 - if (IS_ERR(regs)) { 289 - ret = PTR_ERR(regs); 290 - dev_err_probe(dev, ret, "failed to map registers\n"); 291 - return ret; 292 - } 288 + if (IS_ERR(regs)) 289 + return dev_err_probe(dev, PTR_ERR(regs), "failed to map registers\n"); 293 290 294 291 match = of_match_node(dwc3_xlnx_of_match, pdev->dev.of_node); 295 292
+6 -6
drivers/usb/gadget/configfs.c
··· 6 6 #include <linux/kstrtox.h> 7 7 #include <linux/nls.h> 8 8 #include <linux/usb/composite.h> 9 + #include <linux/usb/func_utils.h> 9 10 #include <linux/usb/gadget_configfs.h> 10 11 #include <linux/usb/webusb.h> 11 12 #include "configfs.h" 12 - #include "u_f.h" 13 13 #include "u_os_desc.h" 14 14 15 - int check_user_usb_string(const char *name, 15 + static int check_user_usb_string(const char *name, 16 16 struct usb_gadget_strings *stringtab_dev) 17 17 { 18 18 u16 num; ··· 902 902 .drop_item = gadget_language_string_drop, 903 903 }; 904 904 905 - static struct config_item_type gadget_language_type = { 905 + static const struct config_item_type gadget_language_type = { 906 906 .ct_item_ops = &gadget_language_langid_item_ops, 907 907 .ct_group_ops = &gadget_language_langid_group_ops, 908 908 .ct_attrs = gadget_language_langid_attrs, ··· 961 961 .drop_item = &gadget_language_drop, 962 962 }; 963 963 964 - static struct config_item_type gadget_language_strings_type = { 964 + static const struct config_item_type gadget_language_strings_type = { 965 965 .ct_group_ops = &gadget_language_group_ops, 966 966 .ct_owner = THIS_MODULE, 967 967 }; ··· 1106 1106 NULL, 1107 1107 }; 1108 1108 1109 - static struct config_item_type webusb_type = { 1109 + static const struct config_item_type webusb_type = { 1110 1110 .ct_attrs = webusb_attrs, 1111 1111 .ct_owner = THIS_MODULE, 1112 1112 }; ··· 1263 1263 .drop_link = os_desc_unlink, 1264 1264 }; 1265 1265 1266 - static struct config_item_type os_desc_type = { 1266 + static const struct config_item_type os_desc_type = { 1267 1267 .ct_item_ops = &os_desc_ops, 1268 1268 .ct_attrs = os_desc_attrs, 1269 1269 .ct_owner = THIS_MODULE,
+50 -2
drivers/usb/gadget/function/f_acm.c
··· 41 41 struct gserial port; 42 42 u8 ctrl_id, data_id; 43 43 u8 port_num; 44 + u8 bInterfaceProtocol; 44 45 45 46 u8 pending; 46 47 ··· 90 89 .bInterfaceCount = 2, // control + data 91 90 .bFunctionClass = USB_CLASS_COMM, 92 91 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, 93 - .bFunctionProtocol = USB_CDC_ACM_PROTO_AT_V25TER, 92 + /* .bFunctionProtocol = DYNAMIC */ 94 93 /* .iFunction = DYNAMIC */ 95 94 }; 96 95 ··· 102 101 .bNumEndpoints = 1, 103 102 .bInterfaceClass = USB_CLASS_COMM, 104 103 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, 105 - .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER, 104 + /* .bInterfaceProtocol = DYNAMIC */ 106 105 /* .iInterface = DYNAMIC */ 107 106 }; 108 107 ··· 664 663 goto fail; 665 664 acm->notify = ep; 666 665 666 + acm_iad_descriptor.bFunctionProtocol = acm->bInterfaceProtocol; 667 + acm_control_interface_desc.bInterfaceProtocol = acm->bInterfaceProtocol; 668 + 667 669 /* allocate notification */ 668 670 acm->notify_req = gs_alloc_req(ep, 669 671 sizeof(struct usb_cdc_notification) + 2, ··· 723 719 static void acm_free_func(struct usb_function *f) 724 720 { 725 721 struct f_acm *acm = func_to_acm(f); 722 + struct f_serial_opts *opts; 723 + 724 + opts = container_of(f->fi, struct f_serial_opts, func_inst); 726 725 727 726 kfree(acm); 727 + mutex_lock(&opts->lock); 728 + opts->instances--; 729 + mutex_unlock(&opts->lock); 728 730 } 729 731 730 732 static void acm_resume(struct usb_function *f) ··· 771 761 acm->port.func.disable = acm_disable; 772 762 773 763 opts = container_of(fi, struct f_serial_opts, func_inst); 764 + mutex_lock(&opts->lock); 774 765 acm->port_num = opts->port_num; 766 + acm->bInterfaceProtocol = opts->protocol; 767 + opts->instances++; 768 + mutex_unlock(&opts->lock); 775 769 acm->port.func.unbind = acm_unbind; 776 770 acm->port.func.free_func = acm_free_func; 777 771 acm->port.func.resume = acm_resume; ··· 826 812 827 813 CONFIGFS_ATTR_RO(f_acm_, port_num); 828 814 815 + static ssize_t f_acm_protocol_show(struct config_item *item, char *page) 816 + { 817 + return sprintf(page, "%u\n", to_f_serial_opts(item)->protocol); 818 + } 819 + 820 + static ssize_t f_acm_protocol_store(struct config_item *item, 821 + const char *page, size_t count) 822 + { 823 + struct f_serial_opts *opts = to_f_serial_opts(item); 824 + int ret; 825 + 826 + mutex_lock(&opts->lock); 827 + 828 + if (opts->instances) { 829 + ret = -EBUSY; 830 + goto out; 831 + } 832 + 833 + ret = kstrtou8(page, 0, &opts->protocol); 834 + if (ret) 835 + goto out; 836 + ret = count; 837 + 838 + out: 839 + mutex_unlock(&opts->lock); 840 + return ret; 841 + } 842 + 843 + CONFIGFS_ATTR(f_acm_, protocol); 844 + 829 845 static struct configfs_attribute *acm_attrs[] = { 830 846 #ifdef CONFIG_U_SERIAL_CONSOLE 831 847 &f_acm_attr_console, 832 848 #endif 833 849 &f_acm_attr_port_num, 850 + &f_acm_attr_protocol, 834 851 NULL, 835 852 }; 836 853 ··· 877 832 878 833 opts = container_of(fi, struct f_serial_opts, func_inst); 879 834 gserial_free_line(opts->port_num); 835 + mutex_destroy(&opts->lock); 880 836 kfree(opts); 881 837 } 882 838 ··· 889 843 opts = kzalloc(sizeof(*opts), GFP_KERNEL); 890 844 if (!opts) 891 845 return ERR_PTR(-ENOMEM); 846 + opts->protocol = USB_CDC_ACM_PROTO_AT_V25TER; 892 847 opts->func_inst.free_func_inst = acm_free_instance; 848 + mutex_init(&opts->lock); 893 849 ret = gserial_alloc_line(&opts->port_num); 894 850 if (ret) { 895 851 kfree(opts);
+11 -3
drivers/usb/gadget/function/f_fs.c
··· 33 33 #include <linux/usb/ccid.h> 34 34 #include <linux/usb/composite.h> 35 35 #include <linux/usb/functionfs.h> 36 + #include <linux/usb/func_utils.h> 36 37 37 38 #include <linux/aio.h> 38 39 #include <linux/kthread.h> ··· 41 40 #include <linux/eventfd.h> 42 41 43 42 #include "u_fs.h" 44 - #include "u_f.h" 45 43 #include "u_os_desc.h" 46 44 #include "configfs.h" 47 45 ··· 2478 2478 2479 2479 static int __must_check ffs_do_single_desc(char *data, unsigned len, 2480 2480 ffs_entity_callback entity, 2481 - void *priv, int *current_class) 2481 + void *priv, int *current_class, int *current_subclass) 2482 2482 { 2483 2483 struct usb_descriptor_header *_ds = (void *)data; 2484 2484 u8 length; ··· 2535 2535 if (ds->iInterface) 2536 2536 __entity(STRING, ds->iInterface); 2537 2537 *current_class = ds->bInterfaceClass; 2538 + *current_subclass = ds->bInterfaceSubClass; 2538 2539 } 2539 2540 break; 2540 2541 ··· 2558 2557 } else if (*current_class == USB_INTERFACE_CLASS_CCID) { 2559 2558 pr_vdebug("ccid descriptor\n"); 2560 2559 if (length != sizeof(struct ccid_descriptor)) 2560 + goto inv_length; 2561 + break; 2562 + } else if (*current_class == USB_CLASS_APP_SPEC && 2563 + *current_subclass == USB_SUBCLASS_DFU) { 2564 + pr_vdebug("dfu functional descriptor\n"); 2565 + if (length != sizeof(struct usb_dfu_functional_descriptor)) 2561 2566 goto inv_length; 2562 2567 break; 2563 2568 } else { ··· 2628 2621 const unsigned _len = len; 2629 2622 unsigned long num = 0; 2630 2623 int current_class = -1; 2624 + int current_subclass = -1; 2631 2625 2632 2626 for (;;) { 2633 2627 int ret; ··· 2648 2640 return _len - len; 2649 2641 2650 2642 ret = ffs_do_single_desc(data, len, entity, priv, 2651 - &current_class); 2643 + &current_class, &current_subclass); 2652 2644 if (ret < 0) { 2653 2645 pr_debug("%s returns %d\n", __func__, ret); 2654 2646 return ret;
+267 -8
drivers/usb/gadget/function/f_hid.c
··· 15 15 #include <linux/uaccess.h> 16 16 #include <linux/wait.h> 17 17 #include <linux/sched.h> 18 + #include <linux/workqueue.h> 19 + #include <linux/usb/func_utils.h> 18 20 #include <linux/usb/g_hid.h> 21 + #include <uapi/linux/usb/g_hid.h> 19 22 20 - #include "u_f.h" 21 23 #include "u_hid.h" 22 24 23 25 #define HIDG_MINORS 4 26 + 27 + /* 28 + * Most operating systems seem to allow for 5000ms timeout, we will allow 29 + * userspace half that time to respond before we return an empty report. 30 + */ 31 + #define GET_REPORT_TIMEOUT_MS 2500 24 32 25 33 static int major, minors; 26 34 ··· 38 30 39 31 static DEFINE_IDA(hidg_ida); 40 32 static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */ 33 + 34 + struct report_entry { 35 + struct usb_hidg_report report_data; 36 + struct list_head node; 37 + }; 41 38 42 39 /*-------------------------------------------------------------------------*/ 43 40 /* HID gadget struct */ ··· 87 74 bool write_pending; 88 75 wait_queue_head_t write_queue; 89 76 struct usb_request *req; 77 + 78 + /* get report */ 79 + struct usb_request *get_req; 80 + struct usb_hidg_report get_report; 81 + bool get_report_returned; 82 + int get_report_req_report_id; 83 + int get_report_req_report_length; 84 + spinlock_t get_report_spinlock; 85 + wait_queue_head_t get_queue; /* Waiting for userspace response */ 86 + wait_queue_head_t get_id_queue; /* Get ID came in */ 87 + struct work_struct work; 88 + struct workqueue_struct *workqueue; 89 + struct list_head report_list; 90 90 91 91 struct device dev; 92 92 struct cdev cdev; ··· 550 524 return status; 551 525 } 552 526 527 + static struct report_entry *f_hidg_search_for_report(struct f_hidg *hidg, u8 report_id) 528 + { 529 + struct list_head *ptr; 530 + struct report_entry *entry; 531 + 532 + list_for_each(ptr, &hidg->report_list) { 533 + entry = list_entry(ptr, struct report_entry, node); 534 + if (entry->report_data.report_id == report_id) 535 + return entry; 536 + } 537 + 538 + return NULL; 539 + } 540 + 541 + static void get_report_workqueue_handler(struct work_struct *work) 542 + { 543 + struct f_hidg *hidg = container_of(work, struct f_hidg, work); 544 + struct usb_composite_dev *cdev = hidg->func.config->cdev; 545 + struct usb_request *req; 546 + struct report_entry *ptr; 547 + unsigned long flags; 548 + 549 + int status = 0; 550 + 551 + spin_lock_irqsave(&hidg->get_report_spinlock, flags); 552 + req = hidg->get_req; 553 + if (!req) { 554 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 555 + return; 556 + } 557 + 558 + req->zero = 0; 559 + req->length = min_t(unsigned int, min_t(unsigned int, hidg->get_report_req_report_length, 560 + hidg->report_length), 561 + MAX_REPORT_LENGTH); 562 + 563 + /* Check if there is a response available for immediate response */ 564 + ptr = f_hidg_search_for_report(hidg, hidg->get_report_req_report_id); 565 + if (ptr && !ptr->report_data.userspace_req) { 566 + /* Report exists in list and it is to be used for immediate response */ 567 + req->buf = ptr->report_data.data; 568 + status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 569 + hidg->get_report_returned = true; 570 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 571 + } else { 572 + /* 573 + * Report does not exist in list or should not be immediately sent 574 + * i.e. give userspace time to respond 575 + */ 576 + hidg->get_report_returned = false; 577 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 578 + wake_up(&hidg->get_id_queue); 579 + #define GET_REPORT_COND (!hidg->get_report_returned) 580 + /* Wait until userspace has responded or timeout */ 581 + status = wait_event_interruptible_timeout(hidg->get_queue, !GET_REPORT_COND, 582 + msecs_to_jiffies(GET_REPORT_TIMEOUT_MS)); 583 + spin_lock_irqsave(&hidg->get_report_spinlock, flags); 584 + req = hidg->get_req; 585 + if (!req) { 586 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 587 + return; 588 + } 589 + if (status == 0 && !hidg->get_report_returned) { 590 + /* GET_REPORT request was not serviced by userspace within timeout period */ 591 + VDBG(cdev, "get_report : userspace timeout.\n"); 592 + hidg->get_report_returned = true; 593 + } 594 + 595 + /* Search again for report ID in list and respond to GET_REPORT request */ 596 + ptr = f_hidg_search_for_report(hidg, hidg->get_report_req_report_id); 597 + if (ptr) { 598 + /* 599 + * Either get an updated response just serviced by userspace 600 + * or send the latest response in the list 601 + */ 602 + req->buf = ptr->report_data.data; 603 + } else { 604 + /* If there are no prevoiusly sent reports send empty report */ 605 + req->buf = hidg->get_report.data; 606 + memset(req->buf, 0x0, req->length); 607 + } 608 + 609 + status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 610 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 611 + } 612 + 613 + if (status < 0) 614 + VDBG(cdev, "usb_ep_queue error on ep0 responding to GET_REPORT\n"); 615 + } 616 + 617 + static int f_hidg_get_report_id(struct file *file, __u8 __user *buffer) 618 + { 619 + struct f_hidg *hidg = file->private_data; 620 + int ret = 0; 621 + 622 + ret = put_user(hidg->get_report_req_report_id, buffer); 623 + 624 + return ret; 625 + } 626 + 627 + static int f_hidg_get_report(struct file *file, struct usb_hidg_report __user *buffer) 628 + { 629 + struct f_hidg *hidg = file->private_data; 630 + struct usb_composite_dev *cdev = hidg->func.config->cdev; 631 + unsigned long flags; 632 + struct report_entry *entry; 633 + struct report_entry *ptr; 634 + __u8 report_id; 635 + 636 + entry = kmalloc(sizeof(*entry), GFP_KERNEL); 637 + if (!entry) 638 + return -ENOMEM; 639 + 640 + if (copy_from_user(&entry->report_data, buffer, 641 + sizeof(struct usb_hidg_report))) { 642 + ERROR(cdev, "copy_from_user error\n"); 643 + kfree(entry); 644 + return -EINVAL; 645 + } 646 + 647 + report_id = entry->report_data.report_id; 648 + 649 + spin_lock_irqsave(&hidg->get_report_spinlock, flags); 650 + ptr = f_hidg_search_for_report(hidg, report_id); 651 + 652 + if (ptr) { 653 + /* Report already exists in list - update it */ 654 + if (copy_from_user(&ptr->report_data, buffer, 655 + sizeof(struct usb_hidg_report))) { 656 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 657 + ERROR(cdev, "copy_from_user error\n"); 658 + kfree(entry); 659 + return -EINVAL; 660 + } 661 + kfree(entry); 662 + } else { 663 + /* Report does not exist in list - add it */ 664 + list_add_tail(&entry->node, &hidg->report_list); 665 + } 666 + 667 + /* If there is no response pending then do nothing further */ 668 + if (hidg->get_report_returned) { 669 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 670 + return 0; 671 + } 672 + 673 + /* If this userspace response serves the current pending report */ 674 + if (hidg->get_report_req_report_id == report_id) { 675 + hidg->get_report_returned = true; 676 + wake_up(&hidg->get_queue); 677 + } 678 + 679 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 680 + return 0; 681 + } 682 + 683 + static long f_hidg_ioctl(struct file *file, unsigned int code, unsigned long arg) 684 + { 685 + switch (code) { 686 + case GADGET_HID_READ_GET_REPORT_ID: 687 + return f_hidg_get_report_id(file, (__u8 __user *)arg); 688 + case GADGET_HID_WRITE_GET_REPORT: 689 + return f_hidg_get_report(file, (struct usb_hidg_report __user *)arg); 690 + default: 691 + return -ENOTTY; 692 + } 693 + } 694 + 553 695 static __poll_t f_hidg_poll(struct file *file, poll_table *wait) 554 696 { 555 697 struct f_hidg *hidg = file->private_data; ··· 725 531 726 532 poll_wait(file, &hidg->read_queue, wait); 727 533 poll_wait(file, &hidg->write_queue, wait); 534 + poll_wait(file, &hidg->get_queue, wait); 535 + poll_wait(file, &hidg->get_id_queue, wait); 728 536 729 537 if (WRITE_COND) 730 538 ret |= EPOLLOUT | EPOLLWRNORM; ··· 739 543 ret |= EPOLLIN | EPOLLRDNORM; 740 544 } 741 545 546 + if (GET_REPORT_COND) 547 + ret |= EPOLLPRI; 548 + 742 549 return ret; 743 550 } 744 551 745 552 #undef WRITE_COND 746 553 #undef READ_COND_SSREPORT 747 554 #undef READ_COND_INTOUT 555 + #undef GET_REPORT_COND 748 556 749 557 static int f_hidg_release(struct inode *inode, struct file *fd) 750 558 { ··· 841 641 wake_up(&hidg->read_queue); 842 642 } 843 643 644 + static void hidg_get_report_complete(struct usb_ep *ep, struct usb_request *req) 645 + { 646 + } 647 + 844 648 static int hidg_setup(struct usb_function *f, 845 649 const struct usb_ctrlrequest *ctrl) 846 650 { ··· 853 649 struct usb_request *req = cdev->req; 854 650 int status = 0; 855 651 __u16 value, length; 652 + unsigned long flags; 856 653 857 654 value = __le16_to_cpu(ctrl->wValue); 858 655 length = __le16_to_cpu(ctrl->wLength); ··· 865 660 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) { 866 661 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 867 662 | HID_REQ_GET_REPORT): 868 - VDBG(cdev, "get_report\n"); 663 + VDBG(cdev, "get_report | wLength=%d\n", ctrl->wLength); 869 664 870 - /* send an empty report */ 871 - length = min_t(unsigned, length, hidg->report_length); 872 - memset(req->buf, 0x0, length); 665 + /* 666 + * Update GET_REPORT ID so that an ioctl can be used to determine what 667 + * GET_REPORT the request was actually for. 668 + */ 669 + spin_lock_irqsave(&hidg->get_report_spinlock, flags); 670 + hidg->get_report_req_report_id = value & 0xff; 671 + hidg->get_report_req_report_length = length; 672 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 873 673 874 - goto respond; 875 - break; 674 + queue_work(hidg->workqueue, &hidg->work); 675 + 676 + return status; 876 677 877 678 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8 878 679 | HID_REQ_GET_PROTOCOL): ··· 1004 793 spin_unlock_irqrestore(&hidg->read_spinlock, flags); 1005 794 } 1006 795 796 + spin_lock_irqsave(&hidg->get_report_spinlock, flags); 797 + if (!hidg->get_report_returned) { 798 + usb_ep_free_request(f->config->cdev->gadget->ep0, hidg->get_req); 799 + hidg->get_req = NULL; 800 + hidg->get_report_returned = true; 801 + } 802 + spin_unlock_irqrestore(&hidg->get_report_spinlock, flags); 803 + 1007 804 spin_lock_irqsave(&hidg->write_spinlock, flags); 1008 805 if (!hidg->write_pending) { 1009 806 free_ep_req(hidg->in_ep, hidg->req); ··· 1121 902 return status; 1122 903 } 1123 904 905 + #ifdef CONFIG_COMPAT 906 + static long f_hidg_compat_ioctl(struct file *file, unsigned int code, 907 + unsigned long value) 908 + { 909 + return f_hidg_ioctl(file, code, value); 910 + } 911 + #endif 912 + 1124 913 static const struct file_operations f_hidg_fops = { 1125 914 .owner = THIS_MODULE, 1126 915 .open = f_hidg_open, ··· 1136 909 .write = f_hidg_write, 1137 910 .read = f_hidg_read, 1138 911 .poll = f_hidg_poll, 912 + .unlocked_ioctl = f_hidg_ioctl, 913 + #ifdef CONFIG_COMPAT 914 + .compat_ioctl = f_hidg_compat_ioctl, 915 + #endif 1139 916 .llseek = noop_llseek, 1140 917 }; 1141 918 ··· 1149 918 struct f_hidg *hidg = func_to_hidg(f); 1150 919 struct usb_string *us; 1151 920 int status; 921 + 922 + hidg->get_req = usb_ep_alloc_request(c->cdev->gadget->ep0, GFP_ATOMIC); 923 + if (!hidg->get_req) 924 + return -ENOMEM; 925 + 926 + hidg->get_req->zero = 0; 927 + hidg->get_req->complete = hidg_get_report_complete; 928 + hidg->get_req->context = hidg; 929 + hidg->get_report_returned = true; 1152 930 1153 931 /* maybe allocate device-global string IDs, and patch descriptors */ 1154 932 us = usb_gstrings_attach(c->cdev, ct_func_strings, ··· 1244 1004 hidg->write_pending = 1; 1245 1005 hidg->req = NULL; 1246 1006 spin_lock_init(&hidg->read_spinlock); 1007 + spin_lock_init(&hidg->get_report_spinlock); 1247 1008 init_waitqueue_head(&hidg->write_queue); 1248 1009 init_waitqueue_head(&hidg->read_queue); 1010 + init_waitqueue_head(&hidg->get_queue); 1011 + init_waitqueue_head(&hidg->get_id_queue); 1249 1012 INIT_LIST_HEAD(&hidg->completed_out_req); 1013 + INIT_LIST_HEAD(&hidg->report_list); 1014 + 1015 + INIT_WORK(&hidg->work, get_report_workqueue_handler); 1016 + hidg->workqueue = alloc_workqueue("report_work", 1017 + WQ_FREEZABLE | 1018 + WQ_MEM_RECLAIM, 1019 + 1); 1020 + 1021 + if (!hidg->workqueue) { 1022 + status = -ENOMEM; 1023 + goto fail; 1024 + } 1250 1025 1251 1026 /* create char device */ 1252 1027 cdev_init(&hidg->cdev, &f_hidg_fops); ··· 1271 1016 1272 1017 return 0; 1273 1018 fail_free_descs: 1019 + destroy_workqueue(hidg->workqueue); 1274 1020 usb_free_all_descriptors(f); 1275 1021 fail: 1276 1022 ERROR(f->config->cdev, "hidg_bind FAILED\n"); 1277 1023 if (hidg->req != NULL) 1278 1024 free_ep_req(hidg->in_ep, hidg->req); 1025 + 1026 + usb_ep_free_request(c->cdev->gadget->ep0, hidg->get_req); 1027 + hidg->get_req = NULL; 1279 1028 1280 1029 return status; 1281 1030 } ··· 1515 1256 struct f_hidg *hidg = func_to_hidg(f); 1516 1257 1517 1258 cdev_device_del(&hidg->cdev, &hidg->dev); 1518 - 1259 + destroy_workqueue(hidg->workqueue); 1519 1260 usb_free_all_descriptors(f); 1520 1261 } 1521 1262
+1 -1
drivers/usb/gadget/function/f_loopback.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/err.h> 16 16 #include <linux/usb/composite.h> 17 + #include <linux/usb/func_utils.h> 17 18 18 19 #include "g_zero.h" 19 - #include "u_f.h" 20 20 21 21 /* 22 22 * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals,
+1 -2
drivers/usb/gadget/function/f_mass_storage.c
··· 3050 3050 if (!common->thread_task) { 3051 3051 common->state = FSG_STATE_NORMAL; 3052 3052 common->thread_task = 3053 - kthread_create(fsg_main_thread, common, "file-storage"); 3053 + kthread_run(fsg_main_thread, common, "file-storage"); 3054 3054 if (IS_ERR(common->thread_task)) { 3055 3055 ret = PTR_ERR(common->thread_task); 3056 3056 common->thread_task = NULL; ··· 3059 3059 } 3060 3060 DBG(common, "I/O thread pid: %d\n", 3061 3061 task_pid_nr(common->thread_task)); 3062 - wake_up_process(common->thread_task); 3063 3062 } 3064 3063 3065 3064 fsg->gadget = gadget;
+1 -1
drivers/usb/gadget/function/f_midi.c
··· 30 30 #include <sound/rawmidi.h> 31 31 32 32 #include <linux/usb/ch9.h> 33 + #include <linux/usb/func_utils.h> 33 34 #include <linux/usb/gadget.h> 34 35 #include <linux/usb/audio.h> 35 36 #include <linux/usb/midi.h> 36 37 37 - #include "u_f.h" 38 38 #include "u_midi.h" 39 39 40 40 MODULE_AUTHOR("Ben Williamson");
+1 -1
drivers/usb/gadget/function/f_midi2.c
··· 15 15 #include <sound/ump_convert.h> 16 16 17 17 #include <linux/usb/ch9.h> 18 + #include <linux/usb/func_utils.h> 18 19 #include <linux/usb/gadget.h> 19 20 #include <linux/usb/audio.h> 20 21 #include <linux/usb/midi-v2.h> 21 22 22 - #include "u_f.h" 23 23 #include "u_midi2.h" 24 24 25 25 struct f_midi2;
+1 -1
drivers/usb/gadget/function/f_sourcesink.c
··· 13 13 #include <linux/device.h> 14 14 #include <linux/module.h> 15 15 #include <linux/usb/composite.h> 16 + #include <linux/usb/func_utils.h> 16 17 #include <linux/err.h> 17 18 18 19 #include "g_zero.h" 19 - #include "u_f.h" 20 20 21 21 /* 22 22 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
+47 -16
drivers/usb/gadget/function/f_uac1.c
··· 377 377 STR_AS_OUT_IF_ALT1, 378 378 STR_AS_IN_IF_ALT0, 379 379 STR_AS_IN_IF_ALT1, 380 + NUM_STR_DESCRIPTORS, 380 381 }; 381 382 382 - static struct usb_string strings_uac1[] = { 383 - /* [STR_AC_IF].s = DYNAMIC, */ 384 - [STR_USB_OUT_IT].s = "Playback Input terminal", 385 - [STR_USB_OUT_IT_CH_NAMES].s = "Playback Channels", 386 - [STR_IO_OUT_OT].s = "Playback Output terminal", 387 - [STR_IO_IN_IT].s = "Capture Input terminal", 388 - [STR_IO_IN_IT_CH_NAMES].s = "Capture Channels", 389 - [STR_USB_IN_OT].s = "Capture Output terminal", 390 - [STR_FU_IN].s = "Capture Volume", 391 - [STR_FU_OUT].s = "Playback Volume", 392 - [STR_AS_OUT_IF_ALT0].s = "Playback Inactive", 393 - [STR_AS_OUT_IF_ALT1].s = "Playback Active", 394 - [STR_AS_IN_IF_ALT0].s = "Capture Inactive", 395 - [STR_AS_IN_IF_ALT1].s = "Capture Active", 396 - { }, 397 - }; 383 + static struct usb_string strings_uac1[NUM_STR_DESCRIPTORS + 1] = {}; 398 384 399 385 static struct usb_gadget_strings str_uac1 = { 400 386 .language = 0x0409, /* en-us */ ··· 1251 1265 1252 1266 strings_uac1[STR_AC_IF].s = audio_opts->function_name; 1253 1267 1268 + strings_uac1[STR_USB_OUT_IT].s = audio_opts->c_it_name; 1269 + strings_uac1[STR_USB_OUT_IT_CH_NAMES].s = audio_opts->c_it_ch_name; 1270 + strings_uac1[STR_IO_OUT_OT].s = audio_opts->c_ot_name; 1271 + strings_uac1[STR_FU_OUT].s = audio_opts->c_fu_vol_name; 1272 + strings_uac1[STR_AS_OUT_IF_ALT0].s = "Playback Inactive"; 1273 + strings_uac1[STR_AS_OUT_IF_ALT1].s = "Playback Active"; 1274 + 1275 + strings_uac1[STR_IO_IN_IT].s = audio_opts->p_it_name; 1276 + strings_uac1[STR_IO_IN_IT_CH_NAMES].s = audio_opts->p_it_ch_name; 1277 + strings_uac1[STR_USB_IN_OT].s = audio_opts->p_ot_name; 1278 + strings_uac1[STR_FU_IN].s = audio_opts->p_fu_vol_name; 1279 + strings_uac1[STR_AS_IN_IF_ALT0].s = "Capture Inactive"; 1280 + strings_uac1[STR_AS_IN_IF_ALT1].s = "Capture Active"; 1281 + 1254 1282 us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); 1255 1283 if (IS_ERR(us)) 1256 1284 return PTR_ERR(us); ··· 1681 1681 UAC1_ATTRIBUTE(s16, c_volume_min); 1682 1682 UAC1_ATTRIBUTE(s16, c_volume_max); 1683 1683 UAC1_ATTRIBUTE(s16, c_volume_res); 1684 + 1684 1685 UAC1_ATTRIBUTE_STRING(function_name); 1686 + 1687 + UAC1_ATTRIBUTE_STRING(p_it_name); 1688 + UAC1_ATTRIBUTE_STRING(p_it_ch_name); 1689 + UAC1_ATTRIBUTE_STRING(p_ot_name); 1690 + UAC1_ATTRIBUTE_STRING(p_fu_vol_name); 1691 + 1692 + UAC1_ATTRIBUTE_STRING(c_it_name); 1693 + UAC1_ATTRIBUTE_STRING(c_it_ch_name); 1694 + UAC1_ATTRIBUTE_STRING(c_ot_name); 1695 + UAC1_ATTRIBUTE_STRING(c_fu_vol_name); 1685 1696 1686 1697 static struct configfs_attribute *f_uac1_attrs[] = { 1687 1698 &f_uac1_opts_attr_c_chmask, ··· 1716 1705 &f_uac1_opts_attr_c_volume_res, 1717 1706 1718 1707 &f_uac1_opts_attr_function_name, 1708 + 1709 + &f_uac1_opts_attr_p_it_name, 1710 + &f_uac1_opts_attr_p_it_ch_name, 1711 + &f_uac1_opts_attr_p_ot_name, 1712 + &f_uac1_opts_attr_p_fu_vol_name, 1713 + 1714 + &f_uac1_opts_attr_c_it_name, 1715 + &f_uac1_opts_attr_c_it_ch_name, 1716 + &f_uac1_opts_attr_c_ot_name, 1717 + &f_uac1_opts_attr_c_fu_vol_name, 1719 1718 1720 1719 NULL, 1721 1720 }; ··· 1780 1759 opts->req_number = UAC1_DEF_REQ_NUM; 1781 1760 1782 1761 scnprintf(opts->function_name, sizeof(opts->function_name), "AC Interface"); 1762 + 1763 + scnprintf(opts->p_it_name, sizeof(opts->p_it_name), "Capture Input terminal"); 1764 + scnprintf(opts->p_it_ch_name, sizeof(opts->p_it_ch_name), "Capture Channels"); 1765 + scnprintf(opts->p_ot_name, sizeof(opts->p_ot_name), "Capture Output terminal"); 1766 + scnprintf(opts->p_fu_vol_name, sizeof(opts->p_fu_vol_name), "Capture Volume"); 1767 + 1768 + scnprintf(opts->c_it_name, sizeof(opts->c_it_name), "Playback Input terminal"); 1769 + scnprintf(opts->c_it_ch_name, sizeof(opts->c_it_ch_name), "Playback Channels"); 1770 + scnprintf(opts->c_ot_name, sizeof(opts->c_ot_name), "Playback Output terminal"); 1771 + scnprintf(opts->c_fu_vol_name, sizeof(opts->c_fu_vol_name), "Playback Volume"); 1783 1772 1784 1773 return &opts->func_inst; 1785 1774 }
+63 -17
drivers/usb/gadget/function/f_uac2.c
··· 95 95 STR_CLKSRC_IN, 96 96 STR_CLKSRC_OUT, 97 97 STR_USB_IT, 98 + STR_USB_IT_CH, 98 99 STR_IO_IT, 100 + STR_IO_IT_CH, 99 101 STR_USB_OT, 100 102 STR_IO_OT, 101 103 STR_FU_IN, ··· 106 104 STR_AS_OUT_ALT1, 107 105 STR_AS_IN_ALT0, 108 106 STR_AS_IN_ALT1, 107 + NUM_STR_DESCRIPTORS, 109 108 }; 110 109 111 - static struct usb_string strings_fn[] = { 112 - /* [STR_ASSOC].s = DYNAMIC, */ 113 - [STR_IF_CTRL].s = "Topology Control", 114 - [STR_CLKSRC_IN].s = "Input Clock", 115 - [STR_CLKSRC_OUT].s = "Output Clock", 116 - [STR_USB_IT].s = "USBH Out", 117 - [STR_IO_IT].s = "USBD Out", 118 - [STR_USB_OT].s = "USBH In", 119 - [STR_IO_OT].s = "USBD In", 120 - [STR_FU_IN].s = "Capture Volume", 121 - [STR_FU_OUT].s = "Playback Volume", 122 - [STR_AS_OUT_ALT0].s = "Playback Inactive", 123 - [STR_AS_OUT_ALT1].s = "Playback Active", 124 - [STR_AS_IN_ALT0].s = "Capture Inactive", 125 - [STR_AS_IN_ALT1].s = "Capture Active", 126 - { }, 127 - }; 110 + static struct usb_string strings_fn[NUM_STR_DESCRIPTORS + 1] = {}; 128 111 129 112 static const char *const speed_names[] = { 130 113 [USB_SPEED_UNKNOWN] = "UNKNOWN", ··· 1036 1049 return ret; 1037 1050 1038 1051 strings_fn[STR_ASSOC].s = uac2_opts->function_name; 1052 + strings_fn[STR_IF_CTRL].s = uac2_opts->if_ctrl_name; 1053 + strings_fn[STR_CLKSRC_IN].s = uac2_opts->clksrc_in_name; 1054 + strings_fn[STR_CLKSRC_OUT].s = uac2_opts->clksrc_out_name; 1055 + 1056 + strings_fn[STR_USB_IT].s = uac2_opts->c_it_name; 1057 + strings_fn[STR_USB_IT_CH].s = uac2_opts->c_it_ch_name; 1058 + strings_fn[STR_IO_OT].s = uac2_opts->c_ot_name; 1059 + strings_fn[STR_FU_OUT].s = uac2_opts->c_fu_vol_name; 1060 + strings_fn[STR_AS_OUT_ALT0].s = "Playback Inactive"; 1061 + strings_fn[STR_AS_OUT_ALT1].s = "Playback Active"; 1062 + 1063 + strings_fn[STR_IO_IT].s = uac2_opts->p_it_name; 1064 + strings_fn[STR_IO_IT_CH].s = uac2_opts->p_it_ch_name; 1065 + strings_fn[STR_USB_OT].s = uac2_opts->p_ot_name; 1066 + strings_fn[STR_FU_IN].s = uac2_opts->p_fu_vol_name; 1067 + strings_fn[STR_AS_IN_ALT0].s = "Capture Inactive"; 1068 + strings_fn[STR_AS_IN_ALT1].s = "Capture Active"; 1039 1069 1040 1070 us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); 1041 1071 if (IS_ERR(us)) ··· 1076 1072 in_clk_src_desc.iClockSource = us[STR_CLKSRC_IN].id; 1077 1073 out_clk_src_desc.iClockSource = us[STR_CLKSRC_OUT].id; 1078 1074 usb_out_it_desc.iTerminal = us[STR_USB_IT].id; 1075 + usb_out_it_desc.iChannelNames = us[STR_USB_IT_CH].id; 1079 1076 io_in_it_desc.iTerminal = us[STR_IO_IT].id; 1077 + io_in_it_desc.iChannelNames = us[STR_IO_IT_CH].id; 1080 1078 usb_in_ot_desc.iTerminal = us[STR_USB_OT].id; 1081 1079 io_out_ot_desc.iTerminal = us[STR_IO_OT].id; 1082 1080 std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id; ··· 2106 2100 UAC2_ATTRIBUTE(s16, c_volume_res); 2107 2101 UAC2_ATTRIBUTE(u32, fb_max); 2108 2102 UAC2_ATTRIBUTE_STRING(function_name); 2103 + UAC2_ATTRIBUTE_STRING(if_ctrl_name); 2104 + UAC2_ATTRIBUTE_STRING(clksrc_in_name); 2105 + UAC2_ATTRIBUTE_STRING(clksrc_out_name); 2106 + 2107 + UAC2_ATTRIBUTE_STRING(p_it_name); 2108 + UAC2_ATTRIBUTE_STRING(p_it_ch_name); 2109 + UAC2_ATTRIBUTE_STRING(p_ot_name); 2110 + UAC2_ATTRIBUTE_STRING(p_fu_vol_name); 2111 + 2112 + UAC2_ATTRIBUTE_STRING(c_it_name); 2113 + UAC2_ATTRIBUTE_STRING(c_it_ch_name); 2114 + UAC2_ATTRIBUTE_STRING(c_ot_name); 2115 + UAC2_ATTRIBUTE_STRING(c_fu_vol_name); 2109 2116 2110 2117 UAC2_ATTRIBUTE(s16, p_terminal_type); 2111 2118 UAC2_ATTRIBUTE(s16, c_terminal_type); 2119 + 2112 2120 2113 2121 static struct configfs_attribute *f_uac2_attrs[] = { 2114 2122 &f_uac2_opts_attr_p_chmask, ··· 2150 2130 &f_uac2_opts_attr_c_volume_res, 2151 2131 2152 2132 &f_uac2_opts_attr_function_name, 2133 + &f_uac2_opts_attr_if_ctrl_name, 2134 + &f_uac2_opts_attr_clksrc_in_name, 2135 + &f_uac2_opts_attr_clksrc_out_name, 2136 + 2137 + &f_uac2_opts_attr_p_it_name, 2138 + &f_uac2_opts_attr_p_it_ch_name, 2139 + &f_uac2_opts_attr_p_ot_name, 2140 + &f_uac2_opts_attr_p_fu_vol_name, 2141 + 2142 + &f_uac2_opts_attr_c_it_name, 2143 + &f_uac2_opts_attr_c_it_ch_name, 2144 + &f_uac2_opts_attr_c_ot_name, 2145 + &f_uac2_opts_attr_c_fu_vol_name, 2153 2146 2154 2147 &f_uac2_opts_attr_p_terminal_type, 2155 2148 &f_uac2_opts_attr_c_terminal_type, ··· 2224 2191 opts->fb_max = FBACK_FAST_MAX; 2225 2192 2226 2193 scnprintf(opts->function_name, sizeof(opts->function_name), "Source/Sink"); 2194 + scnprintf(opts->if_ctrl_name, sizeof(opts->if_ctrl_name), "Topology Control"); 2195 + scnprintf(opts->clksrc_in_name, sizeof(opts->clksrc_in_name), "Input Clock"); 2196 + scnprintf(opts->clksrc_out_name, sizeof(opts->clksrc_out_name), "Output Clock"); 2197 + 2198 + scnprintf(opts->p_it_name, sizeof(opts->p_it_name), "USBD Out"); 2199 + scnprintf(opts->p_it_ch_name, sizeof(opts->p_it_ch_name), "Capture Channels"); 2200 + scnprintf(opts->p_ot_name, sizeof(opts->p_ot_name), "USBH In"); 2201 + scnprintf(opts->p_fu_vol_name, sizeof(opts->p_fu_vol_name), "Capture Volume"); 2202 + 2203 + scnprintf(opts->c_it_name, sizeof(opts->c_it_name), "USBH Out"); 2204 + scnprintf(opts->c_it_ch_name, sizeof(opts->c_it_ch_name), "Playback Channels"); 2205 + scnprintf(opts->c_ot_name, sizeof(opts->c_ot_name), "USBD In"); 2206 + scnprintf(opts->c_fu_vol_name, sizeof(opts->c_fu_vol_name), "Playback Volume"); 2227 2207 2228 2208 opts->p_terminal_type = UAC2_DEF_P_TERM_TYPE; 2229 2209 opts->c_terminal_type = UAC2_DEF_C_TERM_TYPE;
+5 -5
drivers/usb/gadget/function/u_audio.c
··· 1140 1140 } 1141 1141 1142 1142 static struct snd_kcontrol_new u_audio_controls[] = { 1143 - [UAC_FBACK_CTRL] { 1143 + [UAC_FBACK_CTRL] = { 1144 1144 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1145 1145 .name = "Capture Pitch 1000000", 1146 1146 .info = u_audio_pitch_info, 1147 1147 .get = u_audio_pitch_get, 1148 1148 .put = u_audio_pitch_put, 1149 1149 }, 1150 - [UAC_P_PITCH_CTRL] { 1150 + [UAC_P_PITCH_CTRL] = { 1151 1151 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1152 1152 .name = "Playback Pitch 1000000", 1153 1153 .info = u_audio_pitch_info, 1154 1154 .get = u_audio_pitch_get, 1155 1155 .put = u_audio_pitch_put, 1156 1156 }, 1157 - [UAC_MUTE_CTRL] { 1157 + [UAC_MUTE_CTRL] = { 1158 1158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1159 1159 .name = "", /* will be filled later */ 1160 1160 .info = u_audio_mute_info, 1161 1161 .get = u_audio_mute_get, 1162 1162 .put = u_audio_mute_put, 1163 1163 }, 1164 - [UAC_VOLUME_CTRL] { 1164 + [UAC_VOLUME_CTRL] = { 1165 1165 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1166 1166 .name = "", /* will be filled later */ 1167 1167 .info = u_audio_volume_info, 1168 1168 .get = u_audio_volume_get, 1169 1169 .put = u_audio_volume_put, 1170 1170 }, 1171 - [UAC_RATE_CTRL] { 1171 + [UAC_RATE_CTRL] = { 1172 1172 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 1173 1173 .name = "", /* will be filled later */ 1174 1174 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
+22
drivers/usb/gadget/function/u_serial.c
··· 28 28 #include <linux/kthread.h> 29 29 #include <linux/workqueue.h> 30 30 #include <linux/kfifo.h> 31 + #include <linux/serial.h> 31 32 32 33 #include "u_serial.h" 33 34 ··· 127 126 wait_queue_head_t close_wait; 128 127 bool suspended; /* port suspended */ 129 128 bool start_delayed; /* delay start when suspended */ 129 + struct async_icount icount; 130 130 131 131 /* REVISIT this state ... */ 132 132 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */ ··· 259 257 break; 260 258 } 261 259 do_tty_wake = true; 260 + port->icount.tx += len; 262 261 263 262 req->length = len; 264 263 list_del(&req->list); ··· 411 408 size -= n; 412 409 } 413 410 411 + port->icount.rx += size; 414 412 count = tty_insert_flip_string(&port->port, packet, 415 413 size); 416 414 if (count) ··· 855 851 return status; 856 852 } 857 853 854 + static int gs_get_icount(struct tty_struct *tty, 855 + struct serial_icounter_struct *icount) 856 + { 857 + struct gs_port *port = tty->driver_data; 858 + struct async_icount cnow; 859 + unsigned long flags; 860 + 861 + spin_lock_irqsave(&port->port_lock, flags); 862 + cnow = port->icount; 863 + spin_unlock_irqrestore(&port->port_lock, flags); 864 + 865 + icount->rx = cnow.rx; 866 + icount->tx = cnow.tx; 867 + 868 + return 0; 869 + } 870 + 858 871 static const struct tty_operations gs_tty_ops = { 859 872 .open = gs_open, 860 873 .close = gs_close, ··· 882 861 .chars_in_buffer = gs_chars_in_buffer, 883 862 .unthrottle = gs_unthrottle, 884 863 .break_ctl = gs_break_ctl, 864 + .get_icount = gs_get_icount, 885 865 }; 886 866 887 867 /*-------------------------------------------------------------------------*/
+4
drivers/usb/gadget/function/u_serial.h
··· 17 17 struct f_serial_opts { 18 18 struct usb_function_instance func_inst; 19 19 u8 port_num; 20 + u8 protocol; 21 + 22 + struct mutex lock; /* protect instances */ 23 + int instances; 20 24 }; 21 25 22 26 /*
+11 -1
drivers/usb/gadget/function/u_uac1.h
··· 52 52 int req_number; 53 53 unsigned bound:1; 54 54 55 - char function_name[32]; 55 + char function_name[USB_MAX_STRING_LEN]; 56 + 57 + char p_it_name[USB_MAX_STRING_LEN]; 58 + char p_it_ch_name[USB_MAX_STRING_LEN]; 59 + char p_ot_name[USB_MAX_STRING_LEN]; 60 + char p_fu_vol_name[USB_MAX_STRING_LEN]; 61 + 62 + char c_it_name[USB_MAX_STRING_LEN]; 63 + char c_it_ch_name[USB_MAX_STRING_LEN]; 64 + char c_ot_name[USB_MAX_STRING_LEN]; 65 + char c_fu_vol_name[USB_MAX_STRING_LEN]; 56 66 57 67 struct mutex lock; 58 68 int refcnt;
+14 -1
drivers/usb/gadget/function/u_uac2.h
··· 68 68 int fb_max; 69 69 bool bound; 70 70 71 - char function_name[32]; 71 + char function_name[USB_MAX_STRING_LEN]; 72 + char if_ctrl_name[USB_MAX_STRING_LEN]; 73 + char clksrc_in_name[USB_MAX_STRING_LEN]; 74 + char clksrc_out_name[USB_MAX_STRING_LEN]; 75 + 76 + char p_it_name[USB_MAX_STRING_LEN]; 77 + char p_it_ch_name[USB_MAX_STRING_LEN]; 78 + char p_ot_name[USB_MAX_STRING_LEN]; 79 + char p_fu_vol_name[USB_MAX_STRING_LEN]; 80 + 81 + char c_it_name[USB_MAX_STRING_LEN]; 82 + char c_it_ch_name[USB_MAX_STRING_LEN]; 83 + char c_ot_name[USB_MAX_STRING_LEN]; 84 + char c_fu_vol_name[USB_MAX_STRING_LEN]; 72 85 73 86 s16 p_terminal_type; 74 87 s16 c_terminal_type;
+11 -1
drivers/usb/gadget/function/uvc_v4l2.c
··· 121 121 list_for_each_entry(format, &uvc->header->formats, entry) { 122 122 const struct uvc_format_desc *fmtdesc = to_uvc_format(format->fmt); 123 123 124 + if (IS_ERR(fmtdesc)) 125 + continue; 126 + 124 127 if (fmtdesc->fcc == pixelformat) { 125 128 uformat = format->fmt; 126 129 break; ··· 243 240 struct uvc_video *video = &uvc->video; 244 241 struct uvcg_format *uformat; 245 242 struct uvcg_frame *uframe; 243 + const struct uvc_format_desc *fmtdesc; 246 244 u8 *fcc; 247 245 248 246 if (fmt->type != video->queue.queue.type) ··· 281 277 fmt->fmt.pix.height = uframe->frame.w_height; 282 278 fmt->fmt.pix.bytesperline = uvc_v4l2_get_bytesperline(uformat, uframe); 283 279 fmt->fmt.pix.sizeimage = uvc_get_frame_size(uformat, uframe); 284 - fmt->fmt.pix.pixelformat = to_uvc_format(uformat)->fcc; 280 + fmtdesc = to_uvc_format(uformat); 281 + if (IS_ERR(fmtdesc)) 282 + return PTR_ERR(fmtdesc); 283 + fmt->fmt.pix.pixelformat = fmtdesc->fcc; 285 284 } 286 285 fmt->fmt.pix.field = V4L2_FIELD_NONE; 287 286 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB; ··· 396 389 return -EINVAL; 397 390 398 391 fmtdesc = to_uvc_format(uformat); 392 + if (IS_ERR(fmtdesc)) 393 + return PTR_ERR(fmtdesc); 394 + 399 395 f->pixelformat = fmtdesc->fcc; 400 396 401 397 return 0;
+1 -1
drivers/usb/gadget/u_f.c
··· 8 8 * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com> 9 9 */ 10 10 11 - #include "u_f.h" 12 11 #include <linux/usb/ch9.h> 12 + #include <linux/usb/func_utils.h> 13 13 14 14 struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len) 15 15 {
+4 -4
drivers/usb/gadget/u_f.h include/linux/usb/func_utils.h
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * u_f.h 3 + * func_utils.h 4 4 * 5 5 * Utility definitions for USB functions 6 6 * ··· 10 10 * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com> 11 11 */ 12 12 13 - #ifndef __U_F_H__ 14 - #define __U_F_H__ 13 + #ifndef _FUNC_UTILS_H_ 14 + #define _FUNC_UTILS_H_ 15 15 16 16 #include <linux/usb/gadget.h> 17 17 #include <linux/overflow.h> ··· 83 83 usb_ep_free_request(ep, req); 84 84 } 85 85 86 - #endif /* __U_F_H__ */ 86 + #endif /* _FUNC_UTILS_H_ */
+1
drivers/usb/gadget/udc/bdc/bdc_core.c
··· 639 639 { .compatible = "brcm,bdc" }, 640 640 { /* sentinel */ } 641 641 }; 642 + MODULE_DEVICE_TABLE(of, bdc_of_match); 642 643 643 644 static struct platform_driver bdc_driver = { 644 645 .driver = {
+2 -2
drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
··· 2033 2033 set_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_DISCON); 2034 2034 2035 2035 /* Disable interrupt. */ 2036 - writeb(0, &pdev->interrupt_regs->extien), 2037 - writeb(0, &pdev->interrupt_regs->usbien), 2036 + writeb(0, &pdev->interrupt_regs->extien); 2037 + writeb(0, &pdev->interrupt_regs->usbien); 2038 2038 writew(0, &pdev->adma_regs->ep_ien); 2039 2039 2040 2040 /* Clear interrupt line. */
+3 -4
drivers/usb/gadget/udc/cdns2/cdns2-pci.c
··· 15 15 #include "cdns2-gadget.h" 16 16 17 17 #define PCI_DRIVER_NAME "cdns-pci-usbhs" 18 - #define CDNS_VENDOR_ID 0x17cd 19 - #define CDNS_DEVICE_ID 0x0120 18 + #define PCI_DEVICE_ID_CDNS_USB2 0x0120 20 19 #define PCI_BAR_DEV 0 21 20 #define PCI_DEV_FN_DEVICE 0 22 21 ··· 113 114 }; 114 115 115 116 static const struct pci_device_id cdns2_pci_ids[] = { 116 - { PCI_VENDOR_ID_CDNS, CDNS_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 117 - PCI_CLASS_SERIAL_USB_DEVICE, PCI_ANY_ID }, 117 + { PCI_DEVICE(PCI_VENDOR_ID_CDNS, PCI_DEVICE_ID_CDNS_USB2), 118 + .class = PCI_CLASS_SERIAL_USB_DEVICE }, 118 119 { 0, } 119 120 }; 120 121
+8 -6
drivers/usb/gadget/udc/dummy_hcd.c
··· 1304 1304 1305 1305 /* kick the scheduler, it'll do the rest */ 1306 1306 if (!hrtimer_active(&dum_hcd->timer)) 1307 - hrtimer_start(&dum_hcd->timer, ns_to_ktime(DUMMY_TIMER_INT_NSECS), HRTIMER_MODE_REL); 1307 + hrtimer_start(&dum_hcd->timer, ns_to_ktime(DUMMY_TIMER_INT_NSECS), 1308 + HRTIMER_MODE_REL_SOFT); 1308 1309 1309 1310 done: 1310 1311 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); ··· 1326 1325 rc = usb_hcd_check_unlink_urb(hcd, urb, status); 1327 1326 if (!rc && dum_hcd->rh_state != DUMMY_RH_RUNNING && 1328 1327 !list_empty(&dum_hcd->urbp_list)) 1329 - hrtimer_start(&dum_hcd->timer, ns_to_ktime(0), HRTIMER_MODE_REL); 1328 + hrtimer_start(&dum_hcd->timer, ns_to_ktime(0), HRTIMER_MODE_REL_SOFT); 1330 1329 1331 1330 spin_unlock_irqrestore(&dum_hcd->dum->lock, flags); 1332 1331 return rc; ··· 1996 1995 dum_hcd->udev = NULL; 1997 1996 } else if (dum_hcd->rh_state == DUMMY_RH_RUNNING) { 1998 1997 /* want a 1 msec delay here */ 1999 - hrtimer_start(&dum_hcd->timer, ns_to_ktime(DUMMY_TIMER_INT_NSECS), HRTIMER_MODE_REL); 1998 + hrtimer_start(&dum_hcd->timer, ns_to_ktime(DUMMY_TIMER_INT_NSECS), 1999 + HRTIMER_MODE_REL_SOFT); 2000 2000 } 2001 2001 2002 2002 spin_unlock_irqrestore(&dum->lock, flags); ··· 2391 2389 dum_hcd->rh_state = DUMMY_RH_RUNNING; 2392 2390 set_link_state(dum_hcd); 2393 2391 if (!list_empty(&dum_hcd->urbp_list)) 2394 - hrtimer_start(&dum_hcd->timer, ns_to_ktime(0), HRTIMER_MODE_REL); 2392 + hrtimer_start(&dum_hcd->timer, ns_to_ktime(0), HRTIMER_MODE_REL_SOFT); 2395 2393 hcd->state = HC_STATE_RUNNING; 2396 2394 } 2397 2395 spin_unlock_irq(&dum_hcd->dum->lock); ··· 2469 2467 2470 2468 static int dummy_start_ss(struct dummy_hcd *dum_hcd) 2471 2469 { 2472 - hrtimer_init(&dum_hcd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 2470 + hrtimer_init(&dum_hcd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); 2473 2471 dum_hcd->timer.function = dummy_timer; 2474 2472 dum_hcd->rh_state = DUMMY_RH_RUNNING; 2475 2473 dum_hcd->stream_en_ep = 0; ··· 2499 2497 return dummy_start_ss(dum_hcd); 2500 2498 2501 2499 spin_lock_init(&dum_hcd->dum->lock); 2502 - hrtimer_init(&dum_hcd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 2500 + hrtimer_init(&dum_hcd->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); 2503 2501 dum_hcd->timer.function = dummy_timer; 2504 2502 dum_hcd->rh_state = DUMMY_RH_RUNNING; 2505 2503
+30 -37
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 1487 1487 req = list_entry(ep0->queue.next, struct lpc32xx_request, 1488 1488 queue); 1489 1489 1490 - if (req) { 1491 - if (req->req.length == 0) { 1492 - /* Just dequeue request */ 1493 - done(ep0, req, 0); 1494 - udc->ep0state = WAIT_FOR_SETUP; 1495 - return 1; 1496 - } 1490 + if (req->req.length == 0) { 1491 + /* Just dequeue request */ 1492 + done(ep0, req, 0); 1493 + udc->ep0state = WAIT_FOR_SETUP; 1494 + return 1; 1495 + } 1497 1496 1498 - /* Get data from FIFO */ 1499 - bufferspace = req->req.length - req->req.actual; 1500 - if (bufferspace > ep0->ep.maxpacket) 1501 - bufferspace = ep0->ep.maxpacket; 1497 + /* Get data from FIFO */ 1498 + bufferspace = req->req.length - req->req.actual; 1499 + if (bufferspace > ep0->ep.maxpacket) 1500 + bufferspace = ep0->ep.maxpacket; 1502 1501 1503 - /* Copy data to buffer */ 1504 - prefetchw(req->req.buf + req->req.actual); 1505 - tr = udc_read_hwep(udc, EP_OUT, req->req.buf + req->req.actual, 1506 - bufferspace); 1507 - req->req.actual += bufferspace; 1502 + /* Copy data to buffer */ 1503 + prefetchw(req->req.buf + req->req.actual); 1504 + tr = udc_read_hwep(udc, EP_OUT, req->req.buf + req->req.actual, 1505 + bufferspace); 1506 + req->req.actual += bufferspace; 1508 1507 1509 - if (tr < ep0->ep.maxpacket) { 1510 - /* This is the last packet */ 1511 - done(ep0, req, 0); 1512 - udc->ep0state = WAIT_FOR_SETUP; 1513 - return 1; 1514 - } 1508 + if (tr < ep0->ep.maxpacket) { 1509 + /* This is the last packet */ 1510 + done(ep0, req, 0); 1511 + udc->ep0state = WAIT_FOR_SETUP; 1512 + return 1; 1515 1513 } 1516 1514 1517 1515 return 0; ··· 1960 1962 1961 1963 /* If there isn't a request waiting, something went wrong */ 1962 1964 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); 1963 - if (req) { 1964 - done(ep, req, 0); 1965 1965 1966 - /* Start another request if ready */ 1967 - if (!list_empty(&ep->queue)) { 1968 - if (ep->is_in) 1969 - udc_ep_in_req_dma(udc, ep); 1970 - else 1971 - udc_ep_out_req_dma(udc, ep); 1972 - } else 1973 - ep->req_pending = 0; 1974 - } 1966 + done(ep, req, 0); 1967 + 1968 + /* Start another request if ready */ 1969 + if (!list_empty(&ep->queue)) { 1970 + if (ep->is_in) 1971 + udc_ep_in_req_dma(udc, ep); 1972 + else 1973 + udc_ep_out_req_dma(udc, ep); 1974 + } else 1975 + ep->req_pending = 0; 1975 1976 } 1976 1977 1977 1978 ··· 1986 1989 #endif 1987 1990 1988 1991 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); 1989 - if (!req) { 1990 - ep_err(ep, "DMA interrupt on no req!\n"); 1991 - return; 1992 - } 1993 1992 dd = req->dd_desc_ptr; 1994 1993 1995 1994 /* DMA descriptor should always be retired for this call */
+1 -1
drivers/usb/gadget/udc/udc-xilinx.c
··· 947 947 ep->desc = NULL; 948 948 ep->ep_usb.desc = NULL; 949 949 950 - dev_dbg(udc->dev, "USB Ep %d disable\n ", ep->epnumber); 950 + dev_dbg(udc->dev, "USB Ep %d disable\n", ep->epnumber); 951 951 /* Disable the endpoint.*/ 952 952 epcfg = udc->read_fn(udc->addr + ep->offset); 953 953 epcfg &= ~XUSB_EP_CFG_VALID_MASK;
+1 -1
drivers/usb/host/Kconfig
··· 40 40 config USB_XHCI_PCI 41 41 tristate 42 42 depends on USB_PCI 43 - depends on USB_XHCI_PCI_RENESAS || !USB_XHCI_PCI_RENESAS 44 43 default y 45 44 46 45 config USB_XHCI_PCI_RENESAS 47 46 tristate "Support for additional Renesas xHCI controller with firmware" 47 + depends on USB_XHCI_PCI 48 48 help 49 49 Say 'Y' to enable the support for the Renesas xHCI controller with 50 50 firmware. Make sure you have the firmware for the device and
+1
drivers/usb/host/ehci-brcm.c
··· 246 246 { .compatible = "brcm,bcm7445-ehci", }, 247 247 {} 248 248 }; 249 + MODULE_DEVICE_TABLE(of, brcm_ehci_of_match); 249 250 250 251 static struct platform_driver ehci_brcm_driver = { 251 252 .probe = ehci_brcm_probe,
+2 -7
drivers/usb/host/ehci-exynos.c
··· 48 48 static int exynos_ehci_get_phy(struct device *dev, 49 49 struct exynos_ehci_hcd *exynos_ehci) 50 50 { 51 - struct device_node *child; 52 51 struct phy *phy; 53 52 int phy_number, num_phys; 54 53 int ret; ··· 65 66 return 0; 66 67 67 68 /* Get PHYs using legacy bindings */ 68 - for_each_available_child_of_node(dev->of_node, child) { 69 + for_each_available_child_of_node_scoped(dev->of_node, child) { 69 70 ret = of_property_read_u32(child, "reg", &phy_number); 70 71 if (ret) { 71 72 dev_err(dev, "Failed to parse device tree\n"); 72 - of_node_put(child); 73 73 return ret; 74 74 } 75 75 76 76 if (phy_number >= PHY_NUMBER) { 77 77 dev_err(dev, "Invalid number of PHYs\n"); 78 - of_node_put(child); 79 78 return -EINVAL; 80 79 } 81 80 82 81 phy = devm_of_phy_optional_get(dev, child, NULL); 83 82 exynos_ehci->phy[phy_number] = phy; 84 - if (IS_ERR(phy)) { 85 - of_node_put(child); 83 + if (IS_ERR(phy)) 86 84 return PTR_ERR(phy); 87 - } 88 85 } 89 86 90 87 exynos_ehci->legacy_phy = true;
+2 -7
drivers/usb/host/ohci-exynos.c
··· 37 37 static int exynos_ohci_get_phy(struct device *dev, 38 38 struct exynos_ohci_hcd *exynos_ohci) 39 39 { 40 - struct device_node *child; 41 40 struct phy *phy; 42 41 int phy_number, num_phys; 43 42 int ret; ··· 54 55 return 0; 55 56 56 57 /* Get PHYs using legacy bindings */ 57 - for_each_available_child_of_node(dev->of_node, child) { 58 + for_each_available_child_of_node_scoped(dev->of_node, child) { 58 59 ret = of_property_read_u32(child, "reg", &phy_number); 59 60 if (ret) { 60 61 dev_err(dev, "Failed to parse device tree\n"); 61 - of_node_put(child); 62 62 return ret; 63 63 } 64 64 65 65 if (phy_number >= PHY_NUMBER) { 66 66 dev_err(dev, "Invalid number of PHYs\n"); 67 - of_node_put(child); 68 67 return -EINVAL; 69 68 } 70 69 71 70 phy = devm_of_phy_optional_get(dev, child, NULL); 72 71 exynos_ohci->phy[phy_number] = phy; 73 - if (IS_ERR(phy)) { 74 - of_node_put(child); 72 + if (IS_ERR(phy)) 75 73 return PTR_ERR(phy); 76 - } 77 74 } 78 75 79 76 exynos_ohci->legacy_phy = true;
+4 -14
drivers/usb/host/ohci-nxp.c
··· 51 51 52 52 static struct i2c_client *isp1301_i2c_client; 53 53 54 - static struct clk *usb_host_clk; 55 - 56 54 static void isp1301_configure_lpc32xx(void) 57 55 { 58 56 /* LPC32XX only supports DAT_SE0 USB mode */ ··· 153 155 struct resource *res; 154 156 int ret = 0, irq; 155 157 struct device_node *isp1301_node; 158 + struct clk *usb_host_clk; 156 159 157 160 if (pdev->dev.of_node) { 158 161 isp1301_node = of_parse_phandle(pdev->dev.of_node, ··· 179 180 } 180 181 181 182 /* Enable USB host clock */ 182 - usb_host_clk = devm_clk_get(&pdev->dev, NULL); 183 + usb_host_clk = devm_clk_get_enabled(&pdev->dev, NULL); 183 184 if (IS_ERR(usb_host_clk)) { 184 - dev_err(&pdev->dev, "failed to acquire USB OHCI clock\n"); 185 + dev_err(&pdev->dev, "failed to acquire and start USB OHCI clock\n"); 185 186 ret = PTR_ERR(usb_host_clk); 186 - goto fail_disable; 187 - } 188 - 189 - ret = clk_prepare_enable(usb_host_clk); 190 - if (ret < 0) { 191 - dev_err(&pdev->dev, "failed to start USB OHCI clock\n"); 192 187 goto fail_disable; 193 188 } 194 189 ··· 192 199 if (!hcd) { 193 200 dev_err(&pdev->dev, "Failed to allocate HC buffer\n"); 194 201 ret = -ENOMEM; 195 - goto fail_hcd; 202 + goto fail_disable; 196 203 } 197 204 198 205 hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); ··· 222 229 ohci_nxp_stop_hc(); 223 230 fail_resource: 224 231 usb_put_hcd(hcd); 225 - fail_hcd: 226 - clk_disable_unprepare(usb_host_clk); 227 232 fail_disable: 228 233 isp1301_i2c_client = NULL; 229 234 return ret; ··· 234 243 usb_remove_hcd(hcd); 235 244 ohci_nxp_stop_hc(); 236 245 usb_put_hcd(hcd); 237 - clk_disable_unprepare(usb_host_clk); 238 246 isp1301_i2c_client = NULL; 239 247 } 240 248
-4
drivers/usb/host/ohci-ppc-of.c
··· 204 204 #ifdef CONFIG_USB_OHCI_HCD_PPC_OF_LE 205 205 { 206 206 .name = "usb", 207 - .compatible = "ohci-littledian", 208 - }, 209 - { 210 - .name = "usb", 211 207 .compatible = "ohci-le", 212 208 }, 213 209 #endif
+3 -3
drivers/usb/host/r8a66597-hcd.c
··· 297 297 static void set_pipe_reg_addr(struct r8a66597_pipe *pipe, u8 dma_ch) 298 298 { 299 299 u16 pipenum = pipe->info.pipenum; 300 - const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO}; 301 - const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL}; 302 - const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR}; 300 + static const unsigned long fifoaddr[] = {D0FIFO, D1FIFO, CFIFO}; 301 + static const unsigned long fifosel[] = {D0FIFOSEL, D1FIFOSEL, CFIFOSEL}; 302 + static const unsigned long fifoctr[] = {D0FIFOCTR, D1FIFOCTR, CFIFOCTR}; 303 303 304 304 if (dma_ch > R8A66597_PIPE_NO_DMA) /* dma fifo not use? */ 305 305 dma_ch = R8A66597_PIPE_NO_DMA;
+82 -51
drivers/usb/host/xhci-dbgcap.c
··· 173 173 spin_lock(&dbc->lock); 174 174 } 175 175 176 - static void xhci_dbc_flush_single_request(struct dbc_request *req) 176 + static void trb_to_noop(union xhci_trb *trb) 177 177 { 178 - union xhci_trb *trb = req->trb; 179 - 180 178 trb->generic.field[0] = 0; 181 179 trb->generic.field[1] = 0; 182 180 trb->generic.field[2] = 0; 183 181 trb->generic.field[3] &= cpu_to_le32(TRB_CYCLE); 184 182 trb->generic.field[3] |= cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)); 183 + } 185 184 185 + static void xhci_dbc_flush_single_request(struct dbc_request *req) 186 + { 187 + trb_to_noop(req->trb); 186 188 xhci_dbc_giveback(req, -ESHUTDOWN); 187 189 } 188 190 ··· 651 649 case DS_DISABLED: 652 650 return; 653 651 case DS_CONFIGURED: 654 - case DS_STALLED: 655 652 if (dbc->driver->disconnect) 656 653 dbc->driver->disconnect(dbc); 657 654 break; ··· 668 667 669 668 xhci_dbc_mem_cleanup(dbc); 670 669 pm_runtime_put_sync(dbc->dev); /* note, was self.controller */ 670 + } 671 + 672 + static void 673 + handle_ep_halt_changes(struct xhci_dbc *dbc, struct dbc_ep *dep, bool halted) 674 + { 675 + if (halted) { 676 + dev_info(dbc->dev, "DbC Endpoint halted\n"); 677 + dep->halted = 1; 678 + 679 + } else if (dep->halted) { 680 + dev_info(dbc->dev, "DbC Endpoint halt cleared\n"); 681 + dep->halted = 0; 682 + 683 + if (!list_empty(&dep->list_pending)) 684 + writel(DBC_DOOR_BELL_TARGET(dep->direction), 685 + &dbc->regs->doorbell); 686 + } 671 687 } 672 688 673 689 static void ··· 715 697 struct xhci_ring *ring; 716 698 int ep_id; 717 699 int status; 700 + struct xhci_ep_ctx *ep_ctx; 718 701 u32 comp_code; 719 702 size_t remain_length; 720 703 struct dbc_request *req = NULL, *r; ··· 725 706 ep_id = TRB_TO_EP_ID(le32_to_cpu(event->generic.field[3])); 726 707 dep = (ep_id == EPID_OUT) ? 727 708 get_out_ep(dbc) : get_in_ep(dbc); 709 + ep_ctx = (ep_id == EPID_OUT) ? 710 + dbc_bulkout_ctx(dbc) : dbc_bulkin_ctx(dbc); 728 711 ring = dep->ring; 712 + 713 + /* Match the pending request: */ 714 + list_for_each_entry(r, &dep->list_pending, list_pending) { 715 + if (r->trb_dma == event->trans_event.buffer) { 716 + req = r; 717 + break; 718 + } 719 + if (r->status == -COMP_STALL_ERROR) { 720 + dev_warn(dbc->dev, "Give back stale stalled req\n"); 721 + ring->num_trbs_free++; 722 + xhci_dbc_giveback(r, 0); 723 + } 724 + } 725 + 726 + if (!req) { 727 + dev_warn(dbc->dev, "no matched request\n"); 728 + return; 729 + } 730 + 731 + trace_xhci_dbc_handle_transfer(ring, &req->trb->generic); 729 732 730 733 switch (comp_code) { 731 734 case COMP_SUCCESS: ··· 759 718 case COMP_TRB_ERROR: 760 719 case COMP_BABBLE_DETECTED_ERROR: 761 720 case COMP_USB_TRANSACTION_ERROR: 762 - case COMP_STALL_ERROR: 763 721 dev_warn(dbc->dev, "tx error %d detected\n", comp_code); 764 722 status = -comp_code; 765 723 break; 724 + case COMP_STALL_ERROR: 725 + dev_warn(dbc->dev, "Stall error at bulk TRB %llx, remaining %zu, ep deq %llx\n", 726 + event->trans_event.buffer, remain_length, ep_ctx->deq); 727 + status = 0; 728 + dep->halted = 1; 729 + 730 + /* 731 + * xHC DbC may trigger a STALL bulk xfer event when host sends a 732 + * ClearFeature(ENDPOINT_HALT) request even if there wasn't an 733 + * active bulk transfer. 734 + * 735 + * Don't give back this transfer request as hardware will later 736 + * start processing TRBs starting from this 'STALLED' TRB, 737 + * causing TRBs and requests to be out of sync. 738 + * 739 + * If STALL event shows some bytes were transferred then assume 740 + * it's an actual transfer issue and give back the request. 741 + * In this case mark the TRB as No-Op to avoid hw from using the 742 + * TRB again. 743 + */ 744 + 745 + if ((ep_ctx->deq & ~TRB_CYCLE) == event->trans_event.buffer) { 746 + dev_dbg(dbc->dev, "Ep stopped on Stalled TRB\n"); 747 + if (remain_length == req->length) { 748 + dev_dbg(dbc->dev, "Spurious stall event, keep req\n"); 749 + req->status = -COMP_STALL_ERROR; 750 + req->actual = 0; 751 + return; 752 + } 753 + dev_dbg(dbc->dev, "Give back stalled req, but turn TRB to No-op\n"); 754 + trb_to_noop(req->trb); 755 + } 756 + break; 757 + 766 758 default: 767 759 dev_err(dbc->dev, "unknown tx error %d\n", comp_code); 768 760 status = -comp_code; 769 761 break; 770 762 } 771 - 772 - /* Match the pending request: */ 773 - list_for_each_entry(r, &dep->list_pending, list_pending) { 774 - if (r->trb_dma == event->trans_event.buffer) { 775 - req = r; 776 - break; 777 - } 778 - } 779 - 780 - if (!req) { 781 - dev_warn(dbc->dev, "no matched request\n"); 782 - return; 783 - } 784 - 785 - trace_xhci_dbc_handle_transfer(ring, &req->trb->generic); 786 763 787 764 ring->num_trbs_free++; 788 765 req->actual = req->length - remain_length; ··· 821 762 static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc) 822 763 { 823 764 dma_addr_t deq; 824 - struct dbc_ep *dep; 825 765 union xhci_trb *evt; 826 766 u32 ctrl, portsc; 827 767 bool update_erdp = false; ··· 872 814 return EVT_DISC; 873 815 } 874 816 875 - /* Handle endpoint stall event: */ 817 + /* Check and handle changes in endpoint halt status */ 876 818 ctrl = readl(&dbc->regs->control); 877 - if ((ctrl & DBC_CTRL_HALT_IN_TR) || 878 - (ctrl & DBC_CTRL_HALT_OUT_TR)) { 879 - dev_info(dbc->dev, "DbC Endpoint stall\n"); 880 - dbc->state = DS_STALLED; 881 - 882 - if (ctrl & DBC_CTRL_HALT_IN_TR) { 883 - dep = get_in_ep(dbc); 884 - xhci_dbc_flush_endpoint_requests(dep); 885 - } 886 - 887 - if (ctrl & DBC_CTRL_HALT_OUT_TR) { 888 - dep = get_out_ep(dbc); 889 - xhci_dbc_flush_endpoint_requests(dep); 890 - } 891 - 892 - return EVT_DONE; 893 - } 819 + handle_ep_halt_changes(dbc, get_in_ep(dbc), ctrl & DBC_CTRL_HALT_IN_TR); 820 + handle_ep_halt_changes(dbc, get_out_ep(dbc), ctrl & DBC_CTRL_HALT_OUT_TR); 894 821 895 822 /* Clear DbC run change bit: */ 896 823 if (ctrl & DBC_CTRL_DBC_RUN_CHANGE) { 897 824 writel(ctrl, &dbc->regs->control); 898 825 ctrl = readl(&dbc->regs->control); 899 826 } 900 - 901 827 break; 902 - case DS_STALLED: 903 - ctrl = readl(&dbc->regs->control); 904 - if (!(ctrl & DBC_CTRL_HALT_IN_TR) && 905 - !(ctrl & DBC_CTRL_HALT_OUT_TR) && 906 - (ctrl & DBC_CTRL_DBC_RUN)) { 907 - dbc->state = DS_CONFIGURED; 908 - break; 909 - } 910 - 911 - return EVT_DONE; 912 828 default: 913 829 dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state); 914 830 break; ··· 971 939 [DS_ENABLED] = "enabled", 972 940 [DS_CONNECTED] = "connected", 973 941 [DS_CONFIGURED] = "configured", 974 - [DS_STALLED] = "stalled", 975 942 }; 976 943 977 944 static ssize_t dbc_show(struct device *dev,
+1 -1
drivers/usb/host/xhci-dbgcap.h
··· 81 81 DS_ENABLED, 82 82 DS_CONNECTED, 83 83 DS_CONFIGURED, 84 - DS_STALLED, 85 84 DS_MAX 86 85 }; 87 86 ··· 89 90 struct list_head list_pending; 90 91 struct xhci_ring *ring; 91 92 unsigned int direction:1; 93 + unsigned int halted:1; 92 94 }; 93 95 94 96 #define DBC_QUEUE_SIZE 16
+1 -1
drivers/usb/host/xhci-dbgtty.c
··· 346 346 port->n_read = 0; 347 347 } 348 348 349 - list_move(&req->list_pool, &port->read_pool); 349 + list_move_tail(&req->list_pool, &port->read_pool); 350 350 } 351 351 352 352 if (do_push)
+5
drivers/usb/host/xhci-ext-caps.h
··· 42 42 #define XHCI_EXT_CAPS_DEBUG 10 43 43 /* Vendor caps */ 44 44 #define XHCI_EXT_CAPS_VENDOR_INTEL 192 45 + #define XHCI_EXT_CAPS_INTEL_SPR_SHADOW 206 45 46 /* USB Legacy Support Capability - section 7.1.1 */ 46 47 #define XHCI_HC_BIOS_OWNED (1 << 16) 47 48 #define XHCI_HC_OS_OWNED (1 << 24) ··· 64 63 /* USB 2.0 xHCI 1.0 hardware LMP capability - section 7.2.2.1.3.2 */ 65 64 #define XHCI_HLC (1 << 19) 66 65 #define XHCI_BLC (1 << 20) 66 + 67 + /* Intel SPR shadow capability */ 68 + #define XHCI_INTEL_SPR_ESS_PORT_OFFSET 0x8ac4 /* SuperSpeed port control */ 69 + #define XHCI_INTEL_SPR_TUNEN BIT(4) /* Tunnel mode enabled */ 67 70 68 71 /* command register values to disable interrupts and halt the HC */ 69 72 /* start/stop HC execution - do not write unless HC is halted*/
+36
drivers/usb/host/xhci-hub.c
··· 752 752 return xhci_reset(xhci, XHCI_RESET_SHORT_USEC); 753 753 } 754 754 755 + /** 756 + * xhci_port_is_tunneled() - Check if USB3 connection is tunneled over USB4 757 + * @xhci: xhci host controller 758 + * @port: USB3 port to be checked. 759 + * 760 + * Some hosts can detect if a USB3 connection is native USB3 or tunneled over 761 + * USB4. Intel hosts expose this via vendor specific extended capability 206 762 + * eSS PORT registers TUNEN (tunnel enabled) bit. 763 + * 764 + * A USB3 device must be connected to the port to detect the tunnel. 765 + * 766 + * Return: link tunnel mode enum, USB_LINK_UNKNOWN if host is incapable of 767 + * detecting USB3 over USB4 tunnels. USB_LINK_NATIVE or USB_LINK_TUNNELED 768 + * otherwise. 769 + */ 770 + enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, 771 + struct xhci_port *port) 772 + { 773 + void __iomem *base; 774 + u32 offset; 775 + 776 + base = &xhci->cap_regs->hc_capbase; 777 + offset = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_INTEL_SPR_SHADOW); 778 + 779 + if (offset && offset <= XHCI_INTEL_SPR_ESS_PORT_OFFSET) { 780 + offset = XHCI_INTEL_SPR_ESS_PORT_OFFSET + port->hcd_portnum * 0x20; 781 + 782 + if (readl(base + offset) & XHCI_INTEL_SPR_TUNEN) 783 + return USB_LINK_TUNNELED; 784 + else 785 + return USB_LINK_NATIVE; 786 + } 787 + 788 + return USB_LINK_UNKNOWN; 789 + } 790 + 755 791 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, 756 792 u32 link_state) 757 793 {
+7 -1
drivers/usb/host/xhci-mem.c
··· 2332 2332 } 2333 2333 2334 2334 struct xhci_interrupter * 2335 - xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs) 2335 + xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, 2336 + u32 imod_interval) 2336 2337 { 2337 2338 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 2338 2339 struct xhci_interrupter *ir; ··· 2365 2364 xhci_free_interrupter(xhci, ir); 2366 2365 return NULL; 2367 2366 } 2367 + 2368 + err = xhci_set_interrupter_moderation(ir, imod_interval); 2369 + if (err) 2370 + xhci_warn(xhci, "Failed to set interrupter %d moderation to %uns\n", 2371 + i, imod_interval); 2368 2372 2369 2373 xhci_dbg(xhci, "Add secondary interrupter %d, max interrupters %d\n", 2370 2374 i, xhci->max_interrupters);
+41 -7
drivers/usb/host/xhci-pci-renesas.c
··· 50 50 #define RENESAS_RETRY 10000 51 51 #define RENESAS_DELAY 10 52 52 53 + #define RENESAS_FW_NAME "renesas_usb_fw.mem" 54 + 53 55 static int renesas_fw_download_image(struct pci_dev *dev, 54 56 const u32 *fw, size_t step, bool rom) 55 57 { ··· 575 573 return err; 576 574 } 577 575 578 - int renesas_xhci_check_request_fw(struct pci_dev *pdev, 579 - const struct pci_device_id *id) 576 + static int renesas_xhci_check_request_fw(struct pci_dev *pdev, 577 + const struct pci_device_id *id) 580 578 { 581 - struct xhci_driver_data *driver_data = 582 - (struct xhci_driver_data *)id->driver_data; 583 - const char *fw_name = driver_data->firmware; 579 + const char fw_name[] = RENESAS_FW_NAME; 584 580 const struct firmware *fw; 585 581 bool has_rom; 586 582 int err; ··· 625 625 release_firmware(fw); 626 626 return err; 627 627 } 628 - EXPORT_SYMBOL_GPL(renesas_xhci_check_request_fw); 629 628 630 - MODULE_DESCRIPTION("Support for Renesas xHCI controller with firmware"); 629 + static int 630 + xhci_pci_renesas_probe(struct pci_dev *dev, const struct pci_device_id *id) 631 + { 632 + int retval; 633 + 634 + retval = renesas_xhci_check_request_fw(dev, id); 635 + if (retval) 636 + return retval; 637 + 638 + return xhci_pci_common_probe(dev, id); 639 + } 640 + 641 + static const struct pci_device_id pci_ids[] = { 642 + { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0014) }, 643 + { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0015) }, 644 + { /* end: all zeroes */ } 645 + }; 646 + MODULE_DEVICE_TABLE(pci, pci_ids); 647 + 648 + static struct pci_driver xhci_renesas_pci_driver = { 649 + .name = "xhci-pci-renesas", 650 + .id_table = pci_ids, 651 + 652 + .probe = xhci_pci_renesas_probe, 653 + .remove = xhci_pci_remove, 654 + 655 + .shutdown = usb_hcd_pci_shutdown, 656 + .driver = { 657 + .pm = pm_ptr(&usb_hcd_pci_pm_ops), 658 + }, 659 + }; 660 + module_pci_driver(xhci_renesas_pci_driver); 661 + 662 + MODULE_DESCRIPTION("Renesas xHCI PCI Host Controller Driver"); 663 + MODULE_FIRMWARE(RENESAS_FW_NAME); 664 + MODULE_IMPORT_NS(xhci); 631 665 MODULE_LICENSE("GPL v2");
+48 -50
drivers/usb/host/xhci-pci.c
··· 55 55 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_PCH_XHCI 0x51ed 56 56 #define PCI_DEVICE_ID_INTEL_ALDER_LAKE_N_PCH_XHCI 0x54ed 57 57 58 + #define PCI_VENDOR_ID_PHYTIUM 0x1db7 59 + #define PCI_DEVICE_ID_PHYTIUM_XHCI 0xdc27 60 + 58 61 /* Thunderbolt */ 59 62 #define PCI_DEVICE_ID_INTEL_MAPLE_RIDGE_XHCI 0x1138 60 63 #define PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_XHCI 0x15b5 ··· 81 78 #define PCI_DEVICE_ID_ASMEDIA_2142_XHCI 0x2142 82 79 #define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242 83 80 81 + #define PCI_DEVICE_ID_CADENCE 0x17CD 82 + #define PCI_DEVICE_ID_CADENCE_SSP 0x0200 83 + 84 84 static const char hcd_name[] = "xhci_hcd"; 85 85 86 86 static struct hc_driver __read_mostly xhci_pci_hc_driver; ··· 99 93 .update_hub_device = xhci_pci_update_hub_device, 100 94 }; 101 95 96 + /* 97 + * Primary Legacy and MSI IRQ are synced in suspend_common(). 98 + * All MSI-X IRQs and secondary MSI IRQs should be synced here. 99 + */ 102 100 static void xhci_msix_sync_irqs(struct xhci_hcd *xhci) 103 101 { 104 102 struct usb_hcd *hcd = xhci_to_hcd(xhci); ··· 115 105 } 116 106 } 117 107 118 - /* Free any IRQs and disable MSI-X */ 108 + /* Legacy IRQ is freed by usb_remove_hcd() or usb_hcd_pci_shutdown() */ 119 109 static void xhci_cleanup_msix(struct xhci_hcd *xhci) 120 110 { 121 111 struct usb_hcd *hcd = xhci_to_hcd(xhci); 122 112 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 123 113 124 - /* return if using legacy interrupt */ 125 114 if (hcd->irq > 0) 126 115 return; 127 116 ··· 244 235 static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) 245 236 { 246 237 struct pci_dev *pdev = to_pci_dev(dev); 247 - struct xhci_driver_data *driver_data; 248 - const struct pci_device_id *id; 249 - 250 - id = pci_match_id(to_pci_driver(pdev->dev.driver)->id_table, pdev); 251 - 252 - if (id && id->driver_data) { 253 - driver_data = (struct xhci_driver_data *)id->driver_data; 254 - xhci->quirks |= driver_data->quirks; 255 - } 256 238 257 239 /* Look for vendor-specific quirks */ 258 240 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && ··· 416 416 if (pdev->vendor == PCI_VENDOR_ID_VIA) 417 417 xhci->quirks |= XHCI_RESET_ON_RESUME; 418 418 419 + if (pdev->vendor == PCI_VENDOR_ID_PHYTIUM && 420 + pdev->device == PCI_DEVICE_ID_PHYTIUM_XHCI) 421 + xhci->quirks |= XHCI_RESET_ON_RESUME; 422 + 419 423 /* See https://bugzilla.kernel.org/show_bug.cgi?id=79511 */ 420 424 if (pdev->vendor == PCI_VENDOR_ID_VIA && 421 425 pdev->device == 0x3432) ··· 476 472 if (pdev->device == 0x9203) 477 473 xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; 478 474 } 475 + 476 + if (pdev->vendor == PCI_DEVICE_ID_CADENCE && 477 + pdev->device == PCI_DEVICE_ID_CADENCE_SSP) 478 + xhci->quirks |= XHCI_CDNS_SCTX_QUIRK; 479 479 480 480 /* xHC spec requires PCI devices to support D3hot and D3cold */ 481 481 if (xhci->hci_version >= 0x120) ··· 542 534 struct xhci_hcd *xhci; 543 535 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 544 536 int retval; 537 + u8 sbrn; 545 538 546 539 xhci = hcd_to_xhci(hcd); 547 - if (!xhci->sbrn) 548 - pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); 549 540 550 541 /* imod_interval is the interrupt moderation value in nanoseconds. */ 551 542 xhci->imod_interval = 40000; ··· 559 552 if (xhci->quirks & XHCI_PME_STUCK_QUIRK) 560 553 xhci_pme_acpi_rtd3_enable(pdev); 561 554 562 - xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); 555 + pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &sbrn); 556 + xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int)sbrn); 563 557 564 558 /* Find any debug ports */ 565 559 return xhci_pci_reinit(xhci, pdev); ··· 580 572 * We need to register our own PCI probe function (instead of the USB core's 581 573 * function) in order to create a second roothub under xHCI. 582 574 */ 583 - static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 575 + int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id) 584 576 { 585 577 int retval; 586 578 struct xhci_hcd *xhci; 587 579 struct usb_hcd *hcd; 588 - struct xhci_driver_data *driver_data; 589 580 struct reset_control *reset; 590 - 591 - driver_data = (struct xhci_driver_data *)id->driver_data; 592 - if (driver_data && driver_data->quirks & XHCI_RENESAS_FW_QUIRK) { 593 - retval = renesas_xhci_check_request_fw(dev, id); 594 - if (retval) 595 - return retval; 596 - } 597 581 598 582 reset = devm_reset_control_get_optional_exclusive(&dev->dev, NULL); 599 583 if (IS_ERR(reset)) ··· 651 651 pm_runtime_put_noidle(&dev->dev); 652 652 return retval; 653 653 } 654 + EXPORT_SYMBOL_NS_GPL(xhci_pci_common_probe, xhci); 654 655 655 - static void xhci_pci_remove(struct pci_dev *dev) 656 + static const struct pci_device_id pci_ids_reject[] = { 657 + /* handled by xhci-pci-renesas */ 658 + { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0014) }, 659 + { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0015) }, 660 + { /* end: all zeroes */ } 661 + }; 662 + 663 + static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 664 + { 665 + if (pci_match_id(pci_ids_reject, dev)) 666 + return -ENODEV; 667 + 668 + return xhci_pci_common_probe(dev, id); 669 + } 670 + 671 + void xhci_pci_remove(struct pci_dev *dev) 656 672 { 657 673 struct xhci_hcd *xhci; 674 + bool set_power_d3; 658 675 659 676 xhci = hcd_to_xhci(pci_get_drvdata(dev)); 677 + set_power_d3 = xhci->quirks & XHCI_SPURIOUS_WAKEUP; 660 678 661 679 xhci->xhc_state |= XHCI_STATE_REMOVING; 662 680 ··· 687 669 xhci->shared_hcd = NULL; 688 670 } 689 671 690 - /* Workaround for spurious wakeups at shutdown with HSW */ 691 - if (xhci->quirks & XHCI_SPURIOUS_WAKEUP) 692 - pci_set_power_state(dev, PCI_D3hot); 693 - 694 672 usb_hcd_pci_remove(dev); 673 + 674 + /* Workaround for spurious wakeups at shutdown with HSW */ 675 + if (set_power_d3) 676 + pci_set_power_state(dev, PCI_D3hot); 695 677 } 678 + EXPORT_SYMBOL_NS_GPL(xhci_pci_remove, xhci); 696 679 697 680 /* 698 681 * In some Intel xHCI controllers, in order to get D3 working, ··· 802 783 { 803 784 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 804 785 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 805 - int retval = 0; 806 786 807 787 reset_control_reset(xhci->reset); 808 788 ··· 832 814 if (xhci->quirks & XHCI_PME_STUCK_QUIRK) 833 815 xhci_pme_quirk(hcd); 834 816 835 - retval = xhci_resume(xhci, msg); 836 - return retval; 817 + return xhci_resume(xhci, msg); 837 818 } 838 819 839 820 static int xhci_pci_poweroff_late(struct usb_hcd *hcd, bool do_wakeup) ··· 899 882 900 883 /*-------------------------------------------------------------------------*/ 901 884 902 - static const struct xhci_driver_data reneses_data = { 903 - .quirks = XHCI_RENESAS_FW_QUIRK, 904 - .firmware = "renesas_usb_fw.mem", 905 - }; 906 - 907 885 /* PCI driver selection metadata; PCI hotplugging uses this */ 908 886 static const struct pci_device_id pci_ids[] = { 909 - { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0014), 910 - .driver_data = (unsigned long)&reneses_data, 911 - }, 912 - { PCI_DEVICE(PCI_VENDOR_ID_RENESAS, 0x0015), 913 - .driver_data = (unsigned long)&reneses_data, 914 - }, 915 887 /* handle any USB 3.0 xHCI controller */ 916 888 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_XHCI, ~0), 917 889 }, 918 890 { /* end: all zeroes */ } 919 891 }; 920 892 MODULE_DEVICE_TABLE(pci, pci_ids); 921 - 922 - /* 923 - * Without CONFIG_USB_XHCI_PCI_RENESAS renesas_xhci_check_request_fw() won't 924 - * load firmware, so don't encumber the xhci-pci driver with it. 925 - */ 926 - #if IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS) 927 - MODULE_FIRMWARE("renesas_usb_fw.mem"); 928 - #endif 929 893 930 894 /* pci driver glue; this is a "new style" PCI driver module */ 931 895 static struct pci_driver xhci_pci_driver = {
+2 -17
drivers/usb/host/xhci-pci.h
··· 4 4 #ifndef XHCI_PCI_H 5 5 #define XHCI_PCI_H 6 6 7 - #if IS_ENABLED(CONFIG_USB_XHCI_PCI_RENESAS) 8 - int renesas_xhci_check_request_fw(struct pci_dev *dev, 9 - const struct pci_device_id *id); 10 - 11 - #else 12 - static int renesas_xhci_check_request_fw(struct pci_dev *dev, 13 - const struct pci_device_id *id) 14 - { 15 - return 0; 16 - } 17 - 18 - #endif 19 - 20 - struct xhci_driver_data { 21 - u64 quirks; 22 - const char *firmware; 23 - }; 7 + int xhci_pci_common_probe(struct pci_dev *dev, const struct pci_device_id *id); 8 + void xhci_pci_remove(struct pci_dev *dev); 24 9 25 10 #endif
+6
drivers/usb/host/xhci-plat.c
··· 259 259 if (device_property_read_bool(tmpdev, "write-64-hi-lo-quirk")) 260 260 xhci->quirks |= XHCI_WRITE_64_HI_LO; 261 261 262 + if (device_property_read_bool(tmpdev, "xhci-missing-cas-quirk")) 263 + xhci->quirks |= XHCI_MISSING_CAS; 264 + 265 + if (device_property_read_bool(tmpdev, "xhci-skip-phy-init-quirk")) 266 + xhci->quirks |= XHCI_SKIP_PHY_INIT; 267 + 262 268 device_property_read_u32(tmpdev, "imod-interval-ns", 263 269 &xhci->imod_interval); 264 270 }
+38 -34
drivers/usb/host/xhci-ring.c
··· 1399 1399 struct xhci_stream_ctx *ctx = 1400 1400 &ep->stream_info->stream_ctx_array[stream_id]; 1401 1401 deq = le64_to_cpu(ctx->stream_ring) & SCTX_DEQ_MASK; 1402 + 1403 + /* 1404 + * Cadence xHCI controllers store some endpoint state 1405 + * information within Rsvd0 fields of Stream Endpoint 1406 + * context. This field is not cleared during Set TR 1407 + * Dequeue Pointer command which causes XDMA to skip 1408 + * over transfer ring and leads to data loss on stream 1409 + * pipe. 1410 + * To fix this issue driver must clear Rsvd0 field. 1411 + */ 1412 + if (xhci->quirks & XHCI_CDNS_SCTX_QUIRK) { 1413 + ctx->reserved[0] = 0; 1414 + ctx->reserved[1] = 0; 1415 + } 1402 1416 } else { 1403 1417 deq = le64_to_cpu(ep_ctx->deq) & ~EP_CTX_CYCLE_MASK; 1404 1418 } ··· 2535 2521 td->status = 0; 2536 2522 break; 2537 2523 case COMP_SHORT_PACKET: 2538 - xhci_dbg(xhci, "ep %#x - asked for %d bytes, %d bytes untransferred\n", 2539 - td->urb->ep->desc.bEndpointAddress, 2540 - requested, remaining); 2541 2524 td->status = 0; 2542 2525 break; 2543 2526 case COMP_STOPPED_SHORT_PACKET: ··· 2775 2764 return 0; 2776 2765 } 2777 2766 2778 - do { 2779 - /* This TRB should be in the TD at the head of this ring's 2780 - * TD list. 2767 + if (list_empty(&ep_ring->td_list)) { 2768 + /* 2769 + * Don't print wanings if ring is empty due to a stopped endpoint generating an 2770 + * extra completion event if the device was suspended. Or, a event for the last TRB 2771 + * of a short TD we already got a short event for. The short TD is already removed 2772 + * from the TD list. 2781 2773 */ 2782 - if (list_empty(&ep_ring->td_list)) { 2783 - /* 2784 - * Don't print wanings if it's due to a stopped endpoint 2785 - * generating an extra completion event if the device 2786 - * was suspended. Or, a event for the last TRB of a 2787 - * short TD we already got a short event for. 2788 - * The short TD is already removed from the TD list. 2789 - */ 2790 - 2791 - if (!(trb_comp_code == COMP_STOPPED || 2792 - trb_comp_code == COMP_STOPPED_LENGTH_INVALID || 2793 - ep_ring->last_td_was_short)) { 2794 - xhci_warn(xhci, "WARN Event TRB for slot %u ep %d with no TDs queued?\n", 2795 - slot_id, ep_index); 2796 - } 2797 - if (ep->skip) { 2798 - ep->skip = false; 2799 - xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n", 2800 - slot_id, ep_index); 2801 - } 2802 - 2803 - td = NULL; 2804 - goto check_endpoint_halted; 2774 + if (trb_comp_code != COMP_STOPPED && 2775 + trb_comp_code != COMP_STOPPED_LENGTH_INVALID && 2776 + !ep_ring->last_td_was_short) { 2777 + xhci_warn(xhci, "Event TRB for slot %u ep %u with no TDs queued\n", 2778 + slot_id, ep_index); 2805 2779 } 2806 2780 2781 + ep->skip = false; 2782 + goto check_endpoint_halted; 2783 + } 2784 + 2785 + do { 2807 2786 td = list_first_entry(&ep_ring->td_list, struct xhci_td, 2808 2787 td_list); 2809 2788 ··· 2804 2803 2805 2804 if (ep->skip && usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { 2806 2805 skip_isoc_td(xhci, td, ep, status); 2807 - continue; 2806 + if (!list_empty(&ep_ring->td_list)) 2807 + continue; 2808 + 2809 + xhci_dbg(xhci, "All TDs skipped for slot %u ep %u. Clear skip flag.\n", 2810 + slot_id, ep_index); 2811 + ep->skip = false; 2812 + td = NULL; 2813 + goto check_endpoint_halted; 2808 2814 } 2809 2815 2810 2816 /* ··· 3948 3940 start_frame &= 0x7ff; 3949 3941 start_frame_id = (start_frame_id >> 3) & 0x7ff; 3950 3942 end_frame_id = (end_frame_id >> 3) & 0x7ff; 3951 - 3952 - xhci_dbg(xhci, "%s: index %d, reg 0x%x start_frame_id 0x%x, end_frame_id 0x%x, start_frame 0x%x\n", 3953 - __func__, index, readl(&xhci->run_regs->microframe_index), 3954 - start_frame_id, end_frame_id, start_frame); 3955 3943 3956 3944 if (start_frame_id < end_frame_id) { 3957 3945 if (start_frame > end_frame_id ||
+16 -2
drivers/usb/host/xhci.c
··· 347 347 } 348 348 349 349 /* interrupt moderation interval imod_interval in nanoseconds */ 350 - static int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, 351 - u32 imod_interval) 350 + int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, 351 + u32 imod_interval) 352 352 { 353 353 u32 imod; 354 354 ··· 4524 4524 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 4525 4525 struct xhci_port *port; 4526 4526 u32 capability; 4527 + 4528 + /* Check if USB3 device at root port is tunneled over USB4 */ 4529 + if (hcd->speed >= HCD_USB3 && !udev->parent->parent) { 4530 + port = xhci->usb3_rhub.ports[udev->portnum - 1]; 4531 + 4532 + udev->tunnel_mode = xhci_port_is_tunneled(xhci, port); 4533 + if (udev->tunnel_mode == USB_LINK_UNKNOWN) 4534 + dev_dbg(&udev->dev, "link tunnel state unknown\n"); 4535 + else if (udev->tunnel_mode == USB_LINK_TUNNELED) 4536 + dev_dbg(&udev->dev, "tunneled over USB4 link\n"); 4537 + else if (udev->tunnel_mode == USB_LINK_NATIVE) 4538 + dev_dbg(&udev->dev, "native USB 3.x link\n"); 4539 + return 0; 4540 + } 4527 4541 4528 4542 if (hcd->speed >= HCD_USB3 || !udev->lpm_capable || !xhci->hw_lpm_support) 4529 4543 return 0;
+8 -12
drivers/usb/host/xhci.h
··· 1498 1498 spinlock_t lock; 1499 1499 1500 1500 /* packed release number */ 1501 - u8 sbrn; 1502 1501 u16 hci_version; 1503 - u8 max_slots; 1504 1502 u16 max_interrupters; 1505 - u8 max_ports; 1506 - u8 isoc_threshold; 1507 1503 /* imod_interval in ns (I * 250ns) */ 1508 1504 u32 imod_interval; 1509 - int event_ring_max; 1510 1505 /* 4KB min, 128MB max */ 1511 1506 int page_size; 1512 1507 /* Valid values are 12 to 20, inclusive */ ··· 1611 1616 #define XHCI_DEFAULT_PM_RUNTIME_ALLOW BIT_ULL(33) 1612 1617 #define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34) 1613 1618 #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35) 1614 - #define XHCI_RENESAS_FW_QUIRK BIT_ULL(36) 1619 + /* Reserved. It was XHCI_RENESAS_FW_QUIRK */ 1615 1620 #define XHCI_SKIP_PHY_INIT BIT_ULL(37) 1616 1621 #define XHCI_DISABLE_SPARSE BIT_ULL(38) 1617 1622 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39) ··· 1623 1628 #define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(45) 1624 1629 #define XHCI_ZHAOXIN_HOST BIT_ULL(46) 1625 1630 #define XHCI_WRITE_64_HI_LO BIT_ULL(47) 1631 + #define XHCI_CDNS_SCTX_QUIRK BIT_ULL(48) 1626 1632 1627 1633 unsigned int num_active_eps; 1628 1634 unsigned int limit_active_eps; ··· 1827 1831 void xhci_free_container_ctx(struct xhci_hcd *xhci, 1828 1832 struct xhci_container_ctx *ctx); 1829 1833 struct xhci_interrupter * 1830 - xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs); 1834 + xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs, 1835 + u32 imod_interval); 1831 1836 void xhci_remove_secondary_interrupter(struct usb_hcd 1832 1837 *hcd, struct xhci_interrupter *ir); 1833 1838 ··· 1868 1871 struct xhci_virt_device *virt_dev, 1869 1872 struct usb_device *hdev, 1870 1873 struct usb_tt *tt, gfp_t mem_flags); 1874 + int xhci_set_interrupter_moderation(struct xhci_interrupter *ir, 1875 + u32 imod_interval); 1871 1876 1872 1877 /* xHCI ring, segment, TRB, and TD functions */ 1873 1878 dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); ··· 1903 1904 enum xhci_ep_reset_type reset_type); 1904 1905 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd, 1905 1906 u32 slot_id); 1906 - void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id, 1907 - unsigned int ep_index, unsigned int stream_id, 1908 - struct xhci_td *td); 1909 - void xhci_stop_endpoint_command_watchdog(struct timer_list *t); 1910 1907 void xhci_handle_command_timeout(struct work_struct *work); 1911 1908 1912 1909 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, ··· 1924 1929 int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); 1925 1930 int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1); 1926 1931 struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd); 1927 - 1932 + enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, 1933 + struct xhci_port *port); 1928 1934 void xhci_hc_died(struct xhci_hcd *xhci); 1929 1935 1930 1936 #ifdef CONFIG_PM
+11 -4
drivers/usb/misc/appledisplay.c
··· 107 107 case ACD_BTN_BRIGHT_UP: 108 108 case ACD_BTN_BRIGHT_DOWN: 109 109 pdata->button_pressed = 1; 110 - schedule_delayed_work(&pdata->work, 0); 110 + /* 111 + * there is a window during which no device 112 + * is registered 113 + */ 114 + if (pdata->bd ) 115 + schedule_delayed_work(&pdata->work, 0); 111 116 break; 112 117 case ACD_BTN_NONE: 113 118 default: ··· 207 202 const struct usb_device_id *id) 208 203 { 209 204 struct backlight_properties props; 205 + struct backlight_device *backlight; 210 206 struct appledisplay *pdata; 211 207 struct usb_device *udev = interface_to_usbdev(iface); 212 208 struct usb_endpoint_descriptor *endpoint; ··· 278 272 memset(&props, 0, sizeof(struct backlight_properties)); 279 273 props.type = BACKLIGHT_RAW; 280 274 props.max_brightness = 0xff; 281 - pdata->bd = backlight_device_register(bl_name, NULL, pdata, 275 + backlight = backlight_device_register(bl_name, NULL, pdata, 282 276 &appledisplay_bl_data, &props); 283 - if (IS_ERR(pdata->bd)) { 277 + if (IS_ERR(backlight)) { 284 278 dev_err(&iface->dev, "Backlight registration failed\n"); 285 - retval = PTR_ERR(pdata->bd); 279 + retval = PTR_ERR(backlight); 286 280 goto error; 287 281 } 282 + pdata->bd = backlight; 288 283 289 284 /* Try to get brightness */ 290 285 brightness = appledisplay_bl_get_brightness(pdata->bd);
+1
drivers/usb/misc/brcmstb-usb-pinmap.c
··· 335 335 { .compatible = "brcm,usb-pinmap" }, 336 336 { }, 337 337 }; 338 + MODULE_DEVICE_TABLE(of, brcmstb_usb_pinmap_of_match); 338 339 339 340 static struct platform_driver brcmstb_usb_pinmap_driver = { 340 341 .driver = {
+4
drivers/usb/misc/cypress_cy7c63.c
··· 88 88 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, 89 89 address, data, iobuf, CYPRESS_MAX_REQSIZE, 90 90 USB_CTRL_GET_TIMEOUT); 91 + /* we must not process garbage */ 92 + if (retval < 2) 93 + goto err_buf; 91 94 92 95 /* store returned data (more READs to be added) */ 93 96 switch (request) { ··· 110 107 break; 111 108 } 112 109 110 + err_buf: 113 111 kfree(iobuf); 114 112 error: 115 113 return retval;
+78
drivers/usb/misc/onboard_usb_dev.c
··· 11 11 #include <linux/err.h> 12 12 #include <linux/gpio/consumer.h> 13 13 #include <linux/init.h> 14 + #include <linux/i2c.h> 14 15 #include <linux/kernel.h> 15 16 #include <linux/list.h> 16 17 #include <linux/module.h> ··· 29 28 #include <linux/workqueue.h> 30 29 31 30 #include "onboard_usb_dev.h" 31 + 32 + /* USB5744 register offset and mask */ 33 + #define USB5744_CMD_ATTACH 0xAA 34 + #define USB5744_CMD_ATTACH_LSB 0x56 35 + #define USB5744_CMD_CREG_ACCESS 0x99 36 + #define USB5744_CMD_CREG_ACCESS_LSB 0x37 37 + #define USB5744_CREG_MEM_ADDR 0x00 38 + #define USB5744_CREG_WRITE 0x00 39 + #define USB5744_CREG_RUNTIMEFLAGS2 0x41 40 + #define USB5744_CREG_RUNTIMEFLAGS2_LSB 0x1D 41 + #define USB5744_CREG_BYPASS_UDC_SUSPEND BIT(3) 32 42 33 43 static void onboard_dev_attach_usb_driver(struct work_struct *work); 34 44 ··· 110 98 111 99 fsleep(onboard_dev->pdata->reset_us); 112 100 gpiod_set_value_cansleep(onboard_dev->reset_gpio, 0); 101 + fsleep(onboard_dev->pdata->power_on_delay_us); 113 102 114 103 onboard_dev->is_powered_on = true; 115 104 ··· 309 296 pr_err("Failed to attach USB driver: %pe\n", ERR_PTR(err)); 310 297 } 311 298 299 + static int onboard_dev_5744_i2c_init(struct i2c_client *client) 300 + { 301 + #if IS_ENABLED(CONFIG_I2C) 302 + struct device *dev = &client->dev; 303 + int ret; 304 + 305 + /* 306 + * Set BYPASS_UDC_SUSPEND bit to ensure MCU is always enabled 307 + * and ready to respond to SMBus runtime commands. 308 + * The command writes 5 bytes to memory and single data byte in 309 + * configuration register. 310 + */ 311 + char wr_buf[7] = {USB5744_CREG_MEM_ADDR, 5, 312 + USB5744_CREG_WRITE, 1, 313 + USB5744_CREG_RUNTIMEFLAGS2, 314 + USB5744_CREG_RUNTIMEFLAGS2_LSB, 315 + USB5744_CREG_BYPASS_UDC_SUSPEND}; 316 + 317 + ret = i2c_smbus_write_block_data(client, 0, sizeof(wr_buf), wr_buf); 318 + if (ret) 319 + return dev_err_probe(dev, ret, "BYPASS_UDC_SUSPEND bit configuration failed\n"); 320 + 321 + ret = i2c_smbus_write_word_data(client, USB5744_CMD_CREG_ACCESS, 322 + USB5744_CMD_CREG_ACCESS_LSB); 323 + if (ret) 324 + return dev_err_probe(dev, ret, "Configuration Register Access Command failed\n"); 325 + 326 + /* Send SMBus command to boot hub. */ 327 + ret = i2c_smbus_write_word_data(client, USB5744_CMD_ATTACH, 328 + USB5744_CMD_ATTACH_LSB); 329 + if (ret < 0) 330 + return dev_err_probe(dev, ret, "USB Attach with SMBus command failed\n"); 331 + 332 + return ret; 333 + #else 334 + return -ENODEV; 335 + #endif 336 + } 337 + 312 338 static int onboard_dev_probe(struct platform_device *pdev) 313 339 { 314 340 struct device *dev = &pdev->dev; 315 341 struct onboard_dev *onboard_dev; 342 + struct device_node *i2c_node; 316 343 int err; 317 344 318 345 onboard_dev = devm_kzalloc(dev, sizeof(*onboard_dev), GFP_KERNEL); ··· 392 339 if (err) 393 340 return err; 394 341 342 + i2c_node = of_parse_phandle(pdev->dev.of_node, "i2c-bus", 0); 343 + if (i2c_node) { 344 + struct i2c_client *client; 345 + 346 + client = of_find_i2c_device_by_node(i2c_node); 347 + of_node_put(i2c_node); 348 + 349 + if (!client) { 350 + err = -EPROBE_DEFER; 351 + goto err_power_off; 352 + } 353 + 354 + if (of_device_is_compatible(pdev->dev.of_node, "usb424,2744") || 355 + of_device_is_compatible(pdev->dev.of_node, "usb424,5744")) 356 + err = onboard_dev_5744_i2c_init(client); 357 + 358 + put_device(&client->dev); 359 + if (err < 0) 360 + goto err_power_off; 361 + } 362 + 395 363 /* 396 364 * The USB driver might have been detached from the USB devices by 397 365 * onboard_dev_remove() (e.g. through an 'unbind' by userspace), ··· 424 350 schedule_work(&attach_usb_driver_work); 425 351 426 352 return 0; 353 + 354 + err_power_off: 355 + onboard_dev_power_off(onboard_dev); 356 + return err; 427 357 } 428 358 429 359 static void onboard_dev_remove(struct platform_device *pdev)
+2
drivers/usb/misc/onboard_usb_dev.h
··· 10 10 11 11 struct onboard_dev_pdata { 12 12 unsigned long reset_us; /* reset pulse width in us */ 13 + unsigned long power_on_delay_us; /* power on delay in us */ 13 14 unsigned int num_supplies; /* number of supplies */ 14 15 const char * const supply_names[MAX_SUPPLIES]; 15 16 bool is_hub; ··· 25 24 26 25 static const struct onboard_dev_pdata microchip_usb5744_data = { 27 26 .reset_us = 0, 27 + .power_on_delay_us = 10000, 28 28 .num_supplies = 2, 29 29 .supply_names = { "vdd", "vdd2" }, 30 30 .is_hub = true,
+1 -1
drivers/usb/misc/qcom_eud.c
··· 232 232 } 233 233 234 234 static const struct of_device_id eud_dt_match[] = { 235 - { .compatible = "qcom,sc7280-eud" }, 235 + { .compatible = "qcom,eud" }, 236 236 { } 237 237 }; 238 238 MODULE_DEVICE_TABLE(of, eud_dt_match);
+6 -4
drivers/usb/misc/yurex.c
··· 404 404 struct usb_yurex *dev; 405 405 int len = 0; 406 406 char in_buffer[MAX_S64_STRLEN]; 407 - unsigned long flags; 408 407 409 408 dev = file->private_data; 410 409 ··· 418 419 return -EIO; 419 420 } 420 421 421 - spin_lock_irqsave(&dev->lock, flags); 422 + spin_lock_irq(&dev->lock); 422 423 scnprintf(in_buffer, MAX_S64_STRLEN, "%lld\n", dev->bbu); 423 - spin_unlock_irqrestore(&dev->lock, flags); 424 + spin_unlock_irq(&dev->lock); 424 425 mutex_unlock(&dev->io_mutex); 425 426 426 427 return simple_read_from_buffer(buffer, count, ppos, in_buffer, len); ··· 510 511 __func__, retval); 511 512 goto error; 512 513 } 513 - if (set && timeout) 514 + if (set && timeout) { 515 + spin_lock_irq(&dev->lock); 514 516 dev->bbu = c2; 517 + spin_unlock_irq(&dev->lock); 518 + } 515 519 return timeout ? count : -EIO; 516 520 517 521 error:
+11 -16
drivers/usb/musb/mediatek.c
··· 416 416 return -ENOMEM; 417 417 418 418 ret = of_platform_populate(np, NULL, NULL, dev); 419 - if (ret) { 420 - dev_err(dev, "failed to create child devices at %p\n", np); 421 - return ret; 422 - } 419 + if (ret) 420 + return dev_err_probe(dev, ret, 421 + "failed to create child devices at %p\n", np); 423 422 424 423 ret = mtk_musb_clks_get(glue); 425 424 if (ret) ··· 447 448 glue->role = USB_ROLE_NONE; 448 449 break; 449 450 default: 450 - dev_err(&pdev->dev, "Error 'dr_mode' property\n"); 451 - return -EINVAL; 451 + return dev_err_probe(&pdev->dev, -EINVAL, 452 + "Error 'dr_mode' property\n"); 452 453 } 453 454 454 455 glue->phy = devm_of_phy_get_by_index(dev, np, 0); 455 - if (IS_ERR(glue->phy)) { 456 - dev_err(dev, "fail to getting phy %ld\n", 457 - PTR_ERR(glue->phy)); 458 - return PTR_ERR(glue->phy); 459 - } 456 + if (IS_ERR(glue->phy)) 457 + return dev_err_probe(dev, PTR_ERR(glue->phy), 458 + "fail to getting phy\n"); 460 459 461 460 glue->usb_phy = usb_phy_generic_register(); 462 - if (IS_ERR(glue->usb_phy)) { 463 - dev_err(dev, "fail to registering usb-phy %ld\n", 464 - PTR_ERR(glue->usb_phy)); 465 - return PTR_ERR(glue->usb_phy); 466 - } 461 + if (IS_ERR(glue->usb_phy)) 462 + return dev_err_probe(dev, PTR_ERR(glue->usb_phy), 463 + "fail to registering usb-phy\n"); 467 464 468 465 glue->xceiv = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 469 466 if (IS_ERR(glue->xceiv)) {
+136 -24
drivers/usb/musb/mpfs.c
··· 49 49 .ram_bits = MPFS_MUSB_RAM_BITS, 50 50 }; 51 51 52 - static irqreturn_t mpfs_musb_interrupt(int irq, void *__hci) 53 - { 54 - unsigned long flags; 55 - irqreturn_t ret = IRQ_NONE; 56 - struct musb *musb = __hci; 57 - 58 - spin_lock_irqsave(&musb->lock, flags); 59 - 60 - musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 61 - musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 62 - musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 63 - 64 - if (musb->int_usb || musb->int_tx || musb->int_rx) { 65 - musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb); 66 - musb_writew(musb->mregs, MUSB_INTRTX, musb->int_tx); 67 - musb_writew(musb->mregs, MUSB_INTRRX, musb->int_rx); 68 - ret = musb_interrupt(musb); 69 - } 70 - 71 - spin_unlock_irqrestore(&musb->lock, flags); 72 - 73 - return ret; 74 - } 75 - 76 52 static void mpfs_musb_set_vbus(struct musb *musb, int is_on) 77 53 { 78 54 u8 devctl; ··· 87 111 musb_readb(musb->mregs, MUSB_DEVCTL)); 88 112 } 89 113 114 + #define POLL_SECONDS 2 115 + 116 + static void otg_timer(struct timer_list *t) 117 + { 118 + struct musb *musb = from_timer(musb, t, dev_timer); 119 + void __iomem *mregs = musb->mregs; 120 + u8 devctl; 121 + unsigned long flags; 122 + 123 + /* 124 + * We poll because PolarFire SoC won't expose several OTG-critical 125 + * status change events (from the transceiver) otherwise. 126 + */ 127 + devctl = musb_readb(mregs, MUSB_DEVCTL); 128 + dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 129 + usb_otg_state_string(musb->xceiv->otg->state)); 130 + 131 + spin_lock_irqsave(&musb->lock, flags); 132 + switch (musb->xceiv->otg->state) { 133 + case OTG_STATE_A_WAIT_BCON: 134 + devctl &= ~MUSB_DEVCTL_SESSION; 135 + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 136 + 137 + devctl = musb_readb(musb->mregs, MUSB_DEVCTL); 138 + if (devctl & MUSB_DEVCTL_BDEVICE) { 139 + musb->xceiv->otg->state = OTG_STATE_B_IDLE; 140 + MUSB_DEV_MODE(musb); 141 + mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 142 + } else { 143 + musb->xceiv->otg->state = OTG_STATE_A_IDLE; 144 + MUSB_HST_MODE(musb); 145 + } 146 + break; 147 + case OTG_STATE_A_WAIT_VFALL: 148 + if (devctl & MUSB_DEVCTL_VBUS) { 149 + mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 150 + break; 151 + } 152 + musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; 153 + break; 154 + case OTG_STATE_B_IDLE: 155 + /* 156 + * There's no ID-changed IRQ, so we have no good way to tell 157 + * when to switch to the A-Default state machine (by setting 158 + * the DEVCTL.Session bit). 159 + * 160 + * Workaround: whenever we're in B_IDLE, try setting the 161 + * session flag every few seconds. If it works, ID was 162 + * grounded and we're now in the A-Default state machine. 163 + * 164 + * NOTE: setting the session flag is _supposed_ to trigger 165 + * SRP but clearly it doesn't. 166 + */ 167 + musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION); 168 + devctl = musb_readb(mregs, MUSB_DEVCTL); 169 + if (devctl & MUSB_DEVCTL_BDEVICE) 170 + mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 171 + else 172 + musb->xceiv->otg->state = OTG_STATE_A_IDLE; 173 + break; 174 + default: 175 + break; 176 + } 177 + spin_unlock_irqrestore(&musb->lock, flags); 178 + } 179 + 180 + static void __maybe_unused mpfs_musb_try_idle(struct musb *musb, unsigned long timeout) 181 + { 182 + static unsigned long last_timer; 183 + 184 + if (timeout == 0) 185 + timeout = jiffies + msecs_to_jiffies(3); 186 + 187 + /* Never idle if active, or when VBUS timeout is not set as host */ 188 + if (musb->is_active || (musb->a_wait_bcon == 0 && 189 + musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { 190 + dev_dbg(musb->controller, "%s active, deleting timer\n", 191 + usb_otg_state_string(musb->xceiv->otg->state)); 192 + del_timer(&musb->dev_timer); 193 + last_timer = jiffies; 194 + return; 195 + } 196 + 197 + if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) { 198 + dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); 199 + return; 200 + } 201 + last_timer = timeout; 202 + 203 + dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 204 + usb_otg_state_string(musb->xceiv->otg->state), 205 + jiffies_to_msecs(timeout - jiffies)); 206 + mod_timer(&musb->dev_timer, timeout); 207 + } 208 + 209 + static irqreturn_t mpfs_musb_interrupt(int irq, void *__hci) 210 + { 211 + unsigned long flags; 212 + irqreturn_t ret = IRQ_NONE; 213 + struct musb *musb = __hci; 214 + 215 + spin_lock_irqsave(&musb->lock, flags); 216 + 217 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 218 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 219 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 220 + 221 + if (musb->int_usb || musb->int_tx || musb->int_rx) { 222 + musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb); 223 + musb_writew(musb->mregs, MUSB_INTRTX, musb->int_tx); 224 + musb_writew(musb->mregs, MUSB_INTRRX, musb->int_rx); 225 + ret = musb_interrupt(musb); 226 + } 227 + 228 + /* Poll for ID change */ 229 + if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) 230 + mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); 231 + 232 + spin_unlock_irqrestore(&musb->lock, flags); 233 + 234 + return ret; 235 + } 236 + 90 237 static int mpfs_musb_init(struct musb *musb) 91 238 { 92 239 struct device *dev = musb->controller; ··· 220 121 return PTR_ERR(musb->xceiv); 221 122 } 222 123 124 + timer_setup(&musb->dev_timer, otg_timer, 0); 125 + 223 126 musb->dyn_fifo = true; 224 127 musb->isr = mpfs_musb_interrupt; 225 128 ··· 230 129 return 0; 231 130 } 232 131 132 + static int mpfs_musb_exit(struct musb *musb) 133 + { 134 + del_timer_sync(&musb->dev_timer); 135 + 136 + return 0; 137 + } 138 + 233 139 static const struct musb_platform_ops mpfs_ops = { 234 140 .quirks = MUSB_DMA_INVENTRA, 235 141 .init = mpfs_musb_init, 142 + .exit = mpfs_musb_exit, 236 143 .fifo_mode = 2, 237 144 #ifdef CONFIG_USB_INVENTRA_DMA 238 145 .dma_init = musbhs_dma_controller_create, 239 146 .dma_exit = musbhs_dma_controller_destroy, 147 + #endif 148 + #ifndef CONFIG_USB_MUSB_HOST 149 + .try_idle = mpfs_musb_try_idle, 240 150 #endif 241 151 .set_vbus = mpfs_musb_set_vbus 242 152 };
+1
drivers/usb/phy/phy-gpio-vbus-usb.c
··· 374 374 }, 375 375 {}, 376 376 }; 377 + MODULE_DEVICE_TABLE(of, gpio_vbus_of_match); 377 378 378 379 static struct platform_driver gpio_vbus_driver = { 379 380 .driver = {
+119 -13
drivers/usb/phy/phy-mxs-usb.c
··· 18 18 #include <linux/regmap.h> 19 19 #include <linux/mfd/syscon.h> 20 20 #include <linux/iopoll.h> 21 + #include <linux/regulator/consumer.h> 21 22 22 23 #define DRIVER_NAME "mxs_phy" 23 24 ··· 71 70 #define BM_USBPHY_PLL_EN_USB_CLKS BIT(6) 72 71 73 72 /* Anatop Registers */ 73 + #define ANADIG_REG_1P1_SET 0x114 74 + #define ANADIG_REG_1P1_CLR 0x118 75 + 74 76 #define ANADIG_ANA_MISC0 0x150 75 77 #define ANADIG_ANA_MISC0_SET 0x154 76 78 #define ANADIG_ANA_MISC0_CLR 0x158 ··· 121 117 #define BM_ANADIG_USB2_MISC_RX_VPIN_FS BIT(29) 122 118 #define BM_ANADIG_USB2_MISC_RX_VMIN_FS BIT(28) 123 119 120 + /* System Integration Module (SIM) Registers */ 121 + #define SIM_GPR1 0x30 122 + 123 + #define USB_PHY_VLLS_WAKEUP_EN BIT(0) 124 + 125 + #define BM_ANADIG_REG_1P1_ENABLE_WEAK_LINREG BIT(18) 126 + #define BM_ANADIG_REG_1P1_TRACK_VDD_SOC_CAP BIT(19) 127 + 124 128 #define to_mxs_phy(p) container_of((p), struct mxs_phy, phy) 125 129 126 130 /* Do disconnection between PHY and controller without vbus */ ··· 161 149 #define MXS_PHY_TX_D_CAL_MIN 79 162 150 #define MXS_PHY_TX_D_CAL_MAX 119 163 151 152 + /* 153 + * At imx6q/6sl/6sx, the PHY2's clock is controlled by hardware directly, 154 + * eg, according to PHY's suspend status. In these PHYs, we only need to 155 + * open the clock at the initialization and close it at its shutdown routine. 156 + * These PHYs can send resume signal without software interfere if not 157 + * gate clock. 158 + */ 159 + #define MXS_PHY_HARDWARE_CONTROL_PHY2_CLK BIT(4) 160 + 164 161 struct mxs_phy_data { 165 162 unsigned int flags; 166 163 }; ··· 181 160 static const struct mxs_phy_data imx6q_phy_data = { 182 161 .flags = MXS_PHY_SENDING_SOF_TOO_FAST | 183 162 MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 184 - MXS_PHY_NEED_IP_FIX, 163 + MXS_PHY_NEED_IP_FIX | 164 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK, 185 165 }; 186 166 187 167 static const struct mxs_phy_data imx6sl_phy_data = { 188 168 .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 189 - MXS_PHY_NEED_IP_FIX, 169 + MXS_PHY_NEED_IP_FIX | 170 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK, 190 171 }; 191 172 192 173 static const struct mxs_phy_data vf610_phy_data = { ··· 197 174 }; 198 175 199 176 static const struct mxs_phy_data imx6sx_phy_data = { 200 - .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS, 177 + .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 178 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK, 201 179 }; 202 180 203 181 static const struct mxs_phy_data imx6ul_phy_data = { 204 - .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS, 182 + .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 183 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK, 205 184 }; 206 185 207 186 static const struct mxs_phy_data imx7ulp_phy_data = { ··· 226 201 struct clk *clk; 227 202 const struct mxs_phy_data *data; 228 203 struct regmap *regmap_anatop; 204 + struct regmap *regmap_sim; 229 205 int port_id; 230 206 u32 tx_reg_set; 231 207 u32 tx_reg_mask; 208 + struct regulator *phy_3p0; 232 209 }; 233 210 234 211 static inline bool is_imx6q_phy(struct mxs_phy *mxs_phy) ··· 246 219 static inline bool is_imx7ulp_phy(struct mxs_phy *mxs_phy) 247 220 { 248 221 return mxs_phy->data == &imx7ulp_phy_data; 222 + } 223 + 224 + static inline bool is_imx6ul_phy(struct mxs_phy *mxs_phy) 225 + { 226 + return mxs_phy->data == &imx6ul_phy_data; 249 227 } 250 228 251 229 /* ··· 319 287 ret = stmp_reset_block(base + HW_USBPHY_CTRL); 320 288 if (ret) 321 289 goto disable_pll; 290 + 291 + if (mxs_phy->phy_3p0) { 292 + ret = regulator_enable(mxs_phy->phy_3p0); 293 + if (ret) { 294 + dev_err(mxs_phy->phy.dev, 295 + "Failed to enable 3p0 regulator, ret=%d\n", 296 + ret); 297 + return ret; 298 + } 299 + } 322 300 323 301 /* Power up the PHY */ 324 302 writel(0, base + HW_USBPHY_PWD); ··· 490 448 if (is_imx7ulp_phy(mxs_phy)) 491 449 mxs_phy_pll_enable(phy->io_priv, false); 492 450 451 + if (mxs_phy->phy_3p0) 452 + regulator_disable(mxs_phy->phy_3p0); 453 + 493 454 clk_disable_unprepare(mxs_phy->clk); 494 455 } 495 456 ··· 548 503 } 549 504 writel(BM_USBPHY_CTRL_CLKGATE, 550 505 x->io_priv + HW_USBPHY_CTRL_SET); 551 - clk_disable_unprepare(mxs_phy->clk); 506 + if (!(mxs_phy->port_id == 1 && 507 + (mxs_phy->data->flags & 508 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK))) 509 + clk_disable_unprepare(mxs_phy->clk); 552 510 } else { 553 511 mxs_phy_clock_switch_delay(); 554 - ret = clk_prepare_enable(mxs_phy->clk); 555 - if (ret) 556 - return ret; 512 + if (!(mxs_phy->port_id == 1 && 513 + (mxs_phy->data->flags & 514 + MXS_PHY_HARDWARE_CONTROL_PHY2_CLK))) { 515 + ret = clk_prepare_enable(mxs_phy->clk); 516 + if (ret) 517 + return ret; 518 + } 557 519 writel(BM_USBPHY_CTRL_CLKGATE, 558 520 x->io_priv + HW_USBPHY_CTRL_CLR); 559 521 writel(0, x->io_priv + HW_USBPHY_PWD); ··· 790 738 } 791 739 } 792 740 741 + /* Currently, only imx7ulp has SIM module */ 742 + if (of_get_property(np, "nxp,sim", NULL)) { 743 + mxs_phy->regmap_sim = syscon_regmap_lookup_by_phandle 744 + (np, "nxp,sim"); 745 + if (IS_ERR(mxs_phy->regmap_sim)) { 746 + dev_dbg(&pdev->dev, 747 + "failed to find regmap for sim\n"); 748 + return PTR_ERR(mxs_phy->regmap_sim); 749 + } 750 + } 751 + 793 752 /* Precompute which bits of the TX register are to be updated, if any */ 794 753 if (!of_property_read_u32(np, "fsl,tx-cal-45-dn-ohms", &val) && 795 754 val >= MXS_PHY_TX_CAL45_MIN && val <= MXS_PHY_TX_CAL45_MAX) { ··· 852 789 mxs_phy->clk = clk; 853 790 mxs_phy->data = of_device_get_match_data(&pdev->dev); 854 791 792 + mxs_phy->phy_3p0 = devm_regulator_get(&pdev->dev, "phy-3p0"); 793 + if (PTR_ERR(mxs_phy->phy_3p0) == -ENODEV) 794 + /* not exist */ 795 + mxs_phy->phy_3p0 = NULL; 796 + else if (IS_ERR(mxs_phy->phy_3p0)) 797 + return dev_err_probe(&pdev->dev, PTR_ERR(mxs_phy->phy_3p0), 798 + "Getting regulator error\n"); 799 + 800 + if (mxs_phy->phy_3p0) 801 + regulator_set_voltage(mxs_phy->phy_3p0, 3200000, 3200000); 802 + 855 803 platform_set_drvdata(pdev, mxs_phy); 856 804 857 805 device_set_wakeup_capable(&pdev->dev, true); ··· 878 804 } 879 805 880 806 #ifdef CONFIG_PM_SLEEP 807 + static void mxs_phy_wakeup_enable(struct mxs_phy *mxs_phy, bool on) 808 + { 809 + u32 mask = USB_PHY_VLLS_WAKEUP_EN; 810 + 811 + /* If the SoCs don't have SIM, quit */ 812 + if (!mxs_phy->regmap_sim) 813 + return; 814 + 815 + if (on) { 816 + regmap_update_bits(mxs_phy->regmap_sim, SIM_GPR1, mask, mask); 817 + udelay(500); 818 + } else { 819 + regmap_update_bits(mxs_phy->regmap_sim, SIM_GPR1, mask, 0); 820 + } 821 + } 822 + 881 823 static void mxs_phy_enable_ldo_in_suspend(struct mxs_phy *mxs_phy, bool on) 882 824 { 883 - unsigned int reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR; 825 + unsigned int reg; 826 + u32 value; 884 827 885 828 /* If the SoCs don't have anatop, quit */ 886 829 if (!mxs_phy->regmap_anatop) 887 830 return; 888 831 889 - if (is_imx6q_phy(mxs_phy)) 832 + if (is_imx6q_phy(mxs_phy)) { 833 + reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR; 890 834 regmap_write(mxs_phy->regmap_anatop, reg, 891 835 BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG); 892 - else if (is_imx6sl_phy(mxs_phy)) 836 + } else if (is_imx6sl_phy(mxs_phy)) { 837 + reg = on ? ANADIG_ANA_MISC0_SET : ANADIG_ANA_MISC0_CLR; 893 838 regmap_write(mxs_phy->regmap_anatop, 894 839 reg, BM_ANADIG_ANA_MISC0_STOP_MODE_CONFIG_SL); 840 + } else if (is_imx6ul_phy(mxs_phy)) { 841 + reg = on ? ANADIG_REG_1P1_SET : ANADIG_REG_1P1_CLR; 842 + value = BM_ANADIG_REG_1P1_ENABLE_WEAK_LINREG | 843 + BM_ANADIG_REG_1P1_TRACK_VDD_SOC_CAP; 844 + if (mxs_phy_get_vbus_status(mxs_phy) && on) 845 + regmap_write(mxs_phy->regmap_anatop, reg, value); 846 + else if (!on) 847 + regmap_write(mxs_phy->regmap_anatop, reg, value); 848 + } 895 849 } 896 850 897 851 static int mxs_phy_system_suspend(struct device *dev) 898 852 { 899 853 struct mxs_phy *mxs_phy = dev_get_drvdata(dev); 900 854 901 - if (device_may_wakeup(dev)) 855 + if (device_may_wakeup(dev)) { 902 856 mxs_phy_enable_ldo_in_suspend(mxs_phy, true); 857 + mxs_phy_wakeup_enable(mxs_phy, true); 858 + } 903 859 904 860 return 0; 905 861 } ··· 938 834 { 939 835 struct mxs_phy *mxs_phy = dev_get_drvdata(dev); 940 836 941 - if (device_may_wakeup(dev)) 837 + if (device_may_wakeup(dev)) { 942 838 mxs_phy_enable_ldo_in_suspend(mxs_phy, false); 839 + mxs_phy_wakeup_enable(mxs_phy, false); 840 + } 943 841 944 842 return 0; 945 843 }
+6 -1
drivers/usb/roles/class.c
··· 11 11 #include <linux/usb/role.h> 12 12 #include <linux/property.h> 13 13 #include <linux/device.h> 14 + #include <linux/lockdep.h> 14 15 #include <linux/module.h> 15 16 #include <linux/mutex.h> 16 17 #include <linux/slab.h> ··· 22 21 23 22 struct usb_role_switch { 24 23 struct device dev; 24 + struct lock_class_key key; 25 25 struct mutex lock; /* device lock*/ 26 26 struct module *module; /* the module this device depends on */ 27 27 enum usb_role role; ··· 328 326 { 329 327 struct usb_role_switch *sw = to_role_switch(dev); 330 328 329 + mutex_destroy(&sw->lock); 330 + lockdep_unregister_key(&sw->key); 331 331 kfree(sw); 332 332 } 333 333 ··· 368 364 if (!sw) 369 365 return ERR_PTR(-ENOMEM); 370 366 371 - mutex_init(&sw->lock); 367 + lockdep_register_key(&sw->key); 368 + mutex_init_with_key(&sw->lock, &sw->key); 372 369 373 370 sw->allow_userspace_control = desc->allow_userspace_control; 374 371 sw->usb2_port = desc->usb2_port;
-1
drivers/usb/serial/aircable.c
··· 138 138 139 139 static struct usb_serial_driver aircable_device = { 140 140 .driver = { 141 - .owner = THIS_MODULE, 142 141 .name = "aircable", 143 142 }, 144 143 .id_table = id_table,
-1
drivers/usb/serial/ark3116.c
··· 599 599 600 600 static struct usb_serial_driver ark3116_device = { 601 601 .driver = { 602 - .owner = THIS_MODULE, 603 602 .name = "ark3116", 604 603 }, 605 604 .id_table = id_table,
-1
drivers/usb/serial/belkin_sa.c
··· 66 66 /* All of the device info needed for the serial converters */ 67 67 static struct usb_serial_driver belkin_device = { 68 68 .driver = { 69 - .owner = THIS_MODULE, 70 69 .name = "belkin", 71 70 }, 72 71 .description = "Belkin / Peracom / GoHubs USB Serial Adapter",
-1
drivers/usb/serial/ch341.c
··· 837 837 838 838 static struct usb_serial_driver ch341_device = { 839 839 .driver = { 840 - .owner = THIS_MODULE, 841 840 .name = "ch341-uart", 842 841 }, 843 842 .id_table = id_table,
-1
drivers/usb/serial/cp210x.c
··· 299 299 300 300 static struct usb_serial_driver cp210x_device = { 301 301 .driver = { 302 - .owner = THIS_MODULE, 303 302 .name = "cp210x", 304 303 }, 305 304 .id_table = id_table,
-1
drivers/usb/serial/cyberjack.c
··· 67 67 68 68 static struct usb_serial_driver cyberjack_device = { 69 69 .driver = { 70 - .owner = THIS_MODULE, 71 70 .name = "cyberjack", 72 71 }, 73 72 .description = "Reiner SCT Cyberjack USB card reader",
-3
drivers/usb/serial/cypress_m8.c
··· 139 139 140 140 static struct usb_serial_driver cypress_earthmate_device = { 141 141 .driver = { 142 - .owner = THIS_MODULE, 143 142 .name = "earthmate", 144 143 }, 145 144 .description = "DeLorme Earthmate USB", ··· 165 166 166 167 static struct usb_serial_driver cypress_hidcom_device = { 167 168 .driver = { 168 - .owner = THIS_MODULE, 169 169 .name = "cyphidcom", 170 170 }, 171 171 .description = "HID->COM RS232 Adapter", ··· 190 192 191 193 static struct usb_serial_driver cypress_ca42v2_device = { 192 194 .driver = { 193 - .owner = THIS_MODULE, 194 195 .name = "nokiaca42v2", 195 196 }, 196 197 .description = "Nokia CA-42 V2 Adapter",
-2
drivers/usb/serial/digi_acceleport.c
··· 262 262 263 263 static struct usb_serial_driver digi_acceleport_2_device = { 264 264 .driver = { 265 - .owner = THIS_MODULE, 266 265 .name = "digi_2", 267 266 }, 268 267 .description = "Digi 2 port USB adapter", ··· 292 293 293 294 static struct usb_serial_driver digi_acceleport_4_device = { 294 295 .driver = { 295 - .owner = THIS_MODULE, 296 296 .name = "digi_4", 297 297 }, 298 298 .description = "Digi 4 port USB adapter",
-1
drivers/usb/serial/empeg.c
··· 43 43 44 44 static struct usb_serial_driver empeg_device = { 45 45 .driver = { 46 - .owner = THIS_MODULE, 47 46 .name = "empeg", 48 47 }, 49 48 .id_table = id_table,
-2
drivers/usb/serial/f81232.c
··· 967 967 968 968 static struct usb_serial_driver f81232_device = { 969 969 .driver = { 970 - .owner = THIS_MODULE, 971 970 .name = "f81232", 972 971 }, 973 972 .id_table = f81232_id_table, ··· 993 994 994 995 static struct usb_serial_driver f81534a_device = { 995 996 .driver = { 996 - .owner = THIS_MODULE, 997 997 .name = "f81534a", 998 998 }, 999 999 .id_table = f81534a_id_table,
-1
drivers/usb/serial/f81534.c
··· 1538 1538 1539 1539 static struct usb_serial_driver f81534_device = { 1540 1540 .driver = { 1541 - .owner = THIS_MODULE, 1542 1541 .name = "f81534", 1543 1542 }, 1544 1543 .description = DRIVER_DESC,
-1
drivers/usb/serial/ftdi_sio.c
··· 2871 2871 2872 2872 static struct usb_serial_driver ftdi_device = { 2873 2873 .driver = { 2874 - .owner = THIS_MODULE, 2875 2874 .name = "ftdi_sio", 2876 2875 .dev_groups = ftdi_groups, 2877 2876 },
-1
drivers/usb/serial/garmin_gps.c
··· 1412 1412 /* All of the device info needed */ 1413 1413 static struct usb_serial_driver garmin_device = { 1414 1414 .driver = { 1415 - .owner = THIS_MODULE, 1416 1415 .name = "garmin_gps", 1417 1416 }, 1418 1417 .description = "Garmin GPS usb/tty",
-1
drivers/usb/serial/generic.c
··· 63 63 64 64 static struct usb_serial_driver usb_serial_generic_device = { 65 65 .driver = { 66 - .owner = THIS_MODULE, 67 66 .name = "generic", 68 67 }, 69 68 .id_table = generic_device_ids,
-4
drivers/usb/serial/io_edgeport.c
··· 2978 2978 2979 2979 static struct usb_serial_driver edgeport_2port_device = { 2980 2980 .driver = { 2981 - .owner = THIS_MODULE, 2982 2981 .name = "edgeport_2", 2983 2982 }, 2984 2983 .description = "Edgeport 2 port adapter", ··· 3012 3013 3013 3014 static struct usb_serial_driver edgeport_4port_device = { 3014 3015 .driver = { 3015 - .owner = THIS_MODULE, 3016 3016 .name = "edgeport_4", 3017 3017 }, 3018 3018 .description = "Edgeport 4 port adapter", ··· 3046 3048 3047 3049 static struct usb_serial_driver edgeport_8port_device = { 3048 3050 .driver = { 3049 - .owner = THIS_MODULE, 3050 3051 .name = "edgeport_8", 3051 3052 }, 3052 3053 .description = "Edgeport 8 port adapter", ··· 3080 3083 3081 3084 static struct usb_serial_driver epic_device = { 3082 3085 .driver = { 3083 - .owner = THIS_MODULE, 3084 3086 .name = "epic", 3085 3087 }, 3086 3088 .description = "EPiC device",
-2
drivers/usb/serial/io_ti.c
··· 2670 2670 2671 2671 static struct usb_serial_driver edgeport_1port_device = { 2672 2672 .driver = { 2673 - .owner = THIS_MODULE, 2674 2673 .name = "edgeport_ti_1", 2675 2674 }, 2676 2675 .description = "Edgeport TI 1 port adapter", ··· 2707 2708 2708 2709 static struct usb_serial_driver edgeport_2port_device = { 2709 2710 .driver = { 2710 - .owner = THIS_MODULE, 2711 2711 .name = "edgeport_ti_2", 2712 2712 }, 2713 2713 .description = "Edgeport TI 2 port adapter",
-1
drivers/usb/serial/ipaq.c
··· 496 496 /* All of the device info needed for the Compaq iPAQ */ 497 497 static struct usb_serial_driver ipaq_device = { 498 498 .driver = { 499 - .owner = THIS_MODULE, 500 499 .name = "ipaq", 501 500 }, 502 501 .description = "PocketPC PDA",
-1
drivers/usb/serial/ipw.c
··· 285 285 286 286 static struct usb_serial_driver ipw_device = { 287 287 .driver = { 288 - .owner = THIS_MODULE, 289 288 .name = "ipw", 290 289 }, 291 290 .description = "IPWireless converter",
-1
drivers/usb/serial/ir-usb.c
··· 71 71 72 72 static struct usb_serial_driver ir_device = { 73 73 .driver = { 74 - .owner = THIS_MODULE, 75 74 .name = "ir-usb", 76 75 }, 77 76 .description = "IR Dongle",
-1
drivers/usb/serial/iuu_phoenix.c
··· 1157 1157 1158 1158 static struct usb_serial_driver iuu_device = { 1159 1159 .driver = { 1160 - .owner = THIS_MODULE, 1161 1160 .name = "iuu_phoenix", 1162 1161 }, 1163 1162 .id_table = id_table,
-4
drivers/usb/serial/keyspan.c
··· 3001 3001 /* Structs for the devices, pre and post renumeration. */ 3002 3002 static struct usb_serial_driver keyspan_pre_device = { 3003 3003 .driver = { 3004 - .owner = THIS_MODULE, 3005 3004 .name = "keyspan_no_firm", 3006 3005 }, 3007 3006 .description = "Keyspan - (without firmware)", ··· 3011 3012 3012 3013 static struct usb_serial_driver keyspan_1port_device = { 3013 3014 .driver = { 3014 - .owner = THIS_MODULE, 3015 3015 .name = "keyspan_1", 3016 3016 }, 3017 3017 .description = "Keyspan 1 port adapter", ··· 3034 3036 3035 3037 static struct usb_serial_driver keyspan_2port_device = { 3036 3038 .driver = { 3037 - .owner = THIS_MODULE, 3038 3039 .name = "keyspan_2", 3039 3040 }, 3040 3041 .description = "Keyspan 2 port adapter", ··· 3057 3060 3058 3061 static struct usb_serial_driver keyspan_4port_device = { 3059 3062 .driver = { 3060 - .owner = THIS_MODULE, 3061 3063 .name = "keyspan_4", 3062 3064 }, 3063 3065 .description = "Keyspan 4 port adapter",
-2
drivers/usb/serial/keyspan_pda.c
··· 676 676 677 677 static struct usb_serial_driver keyspan_pda_fake_device = { 678 678 .driver = { 679 - .owner = THIS_MODULE, 680 679 .name = "keyspan_pda_pre", 681 680 }, 682 681 .description = "Keyspan PDA - (prerenumeration)", ··· 686 687 687 688 static struct usb_serial_driver keyspan_pda_device = { 688 689 .driver = { 689 - .owner = THIS_MODULE, 690 690 .name = "keyspan_pda", 691 691 }, 692 692 .description = "Keyspan PDA",
-1
drivers/usb/serial/kl5kusb105.c
··· 75 75 76 76 static struct usb_serial_driver kl5kusb105d_device = { 77 77 .driver = { 78 - .owner = THIS_MODULE, 79 78 .name = "kl5kusb105d", 80 79 }, 81 80 .description = "KL5KUSB105D / PalmConnect",
+1 -3
drivers/usb/serial/kobil_sct.c
··· 77 77 78 78 static struct usb_serial_driver kobil_device = { 79 79 .driver = { 80 - .owner = THIS_MODULE, 81 80 .name = "kobil", 82 81 }, 83 82 .description = "KOBIL USB smart card terminal", ··· 155 156 { 156 157 /* Default to echo off and other sane device settings */ 157 158 tty->termios.c_lflag = 0; 158 - tty->termios.c_iflag &= ~(ISIG | ICANON | ECHO | IEXTEN | XCASE); 159 - tty->termios.c_iflag |= IGNBRK | IGNPAR | IXOFF; 159 + tty->termios.c_iflag = IGNBRK | IGNPAR | IXOFF; 160 160 /* do NOT translate CR to CR-NL (0x0A -> 0x0A 0x0D) */ 161 161 tty->termios.c_oflag &= ~ONLCR; 162 162 }
-1
drivers/usb/serial/mct_u232.c
··· 69 69 70 70 static struct usb_serial_driver mct_u232_device = { 71 71 .driver = { 72 - .owner = THIS_MODULE, 73 72 .name = "mct_u232", 74 73 }, 75 74 .description = "MCT U232",
-1
drivers/usb/serial/metro-usb.c
··· 341 341 342 342 static struct usb_serial_driver metrousb_device = { 343 343 .driver = { 344 - .owner = THIS_MODULE, 345 344 .name = "metro-usb", 346 345 }, 347 346 .description = "Metrologic USB to Serial",
-1
drivers/usb/serial/mos7720.c
··· 1724 1724 1725 1725 static struct usb_serial_driver moschip7720_2port_driver = { 1726 1726 .driver = { 1727 - .owner = THIS_MODULE, 1728 1727 .name = "moschip7720", 1729 1728 }, 1730 1729 .description = "Moschip 2 port adapter",
-1
drivers/usb/serial/mos7840.c
··· 1782 1782 1783 1783 static struct usb_serial_driver moschip7840_4port_device = { 1784 1784 .driver = { 1785 - .owner = THIS_MODULE, 1786 1785 .name = "mos7840", 1787 1786 }, 1788 1787 .description = DRIVER_DESC,
-1
drivers/usb/serial/mxuport.c
··· 1278 1278 1279 1279 static struct usb_serial_driver mxuport_device = { 1280 1280 .driver = { 1281 - .owner = THIS_MODULE, 1282 1281 .name = "mxuport", 1283 1282 }, 1284 1283 .description = "MOXA UPort",
-1
drivers/usb/serial/navman.c
··· 95 95 96 96 static struct usb_serial_driver navman_device = { 97 97 .driver = { 98 - .owner = THIS_MODULE, 99 98 .name = "navman", 100 99 }, 101 100 .id_table = id_table,
-1
drivers/usb/serial/omninet.c
··· 49 49 50 50 static struct usb_serial_driver zyxel_omninet_device = { 51 51 .driver = { 52 - .owner = THIS_MODULE, 53 52 .name = "omninet", 54 53 }, 55 54 .description = "ZyXEL - omni.net usb",
-1
drivers/usb/serial/opticon.c
··· 375 375 376 376 static struct usb_serial_driver opticon_device = { 377 377 .driver = { 378 - .owner = THIS_MODULE, 379 378 .name = "opticon", 380 379 }, 381 380 .id_table = id_table,
-1
drivers/usb/serial/option.c
··· 2381 2381 2382 2382 static struct usb_serial_driver option_1port_device = { 2383 2383 .driver = { 2384 - .owner = THIS_MODULE, 2385 2384 .name = "option1", 2386 2385 }, 2387 2386 .description = "GSM modem (1-port)",
-1
drivers/usb/serial/oti6858.c
··· 138 138 /* device info */ 139 139 static struct usb_serial_driver oti6858_device = { 140 140 .driver = { 141 - .owner = THIS_MODULE, 142 141 .name = "oti6858", 143 142 }, 144 143 .id_table = id_table,
+1 -1
drivers/usb/serial/pl2303.c
··· 118 118 { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) }, 119 119 { USB_DEVICE(AT_VENDOR_ID, AT_VTKIT3_PRODUCT_ID) }, 120 120 { USB_DEVICE(IBM_VENDOR_ID, IBM_PRODUCT_ID) }, 121 + { USB_DEVICE(MACROSILICON_VENDOR_ID, MACROSILICON_MS3020_PRODUCT_ID) }, 121 122 { } /* Terminating entry */ 122 123 }; 123 124 ··· 1235 1234 1236 1235 static struct usb_serial_driver pl2303_device = { 1237 1236 .driver = { 1238 - .owner = THIS_MODULE, 1239 1237 .name = "pl2303", 1240 1238 }, 1241 1239 .id_table = id_table,
+4
drivers/usb/serial/pl2303.h
··· 171 171 /* Allied Telesis VT-Kit3 */ 172 172 #define AT_VENDOR_ID 0x0caa 173 173 #define AT_VTKIT3_PRODUCT_ID 0x3001 174 + 175 + /* Macrosilicon MS3020 */ 176 + #define MACROSILICON_VENDOR_ID 0x345f 177 + #define MACROSILICON_MS3020_PRODUCT_ID 0x3020
-1
drivers/usb/serial/qcaux.c
··· 72 72 73 73 static struct usb_serial_driver qcaux_device = { 74 74 .driver = { 75 - .owner = THIS_MODULE, 76 75 .name = "qcaux", 77 76 }, 78 77 .id_table = id_table,
-1
drivers/usb/serial/qcserial.c
··· 454 454 455 455 static struct usb_serial_driver qcdevice = { 456 456 .driver = { 457 - .owner = THIS_MODULE, 458 457 .name = "qcserial", 459 458 }, 460 459 .description = "Qualcomm USB modem",
-1
drivers/usb/serial/quatech2.c
··· 924 924 925 925 static struct usb_serial_driver qt2_device = { 926 926 .driver = { 927 - .owner = THIS_MODULE, 928 927 .name = "quatech-serial", 929 928 }, 930 929 .description = DRIVER_DESC,
-1
drivers/usb/serial/safe_serial.c
··· 284 284 285 285 static struct usb_serial_driver safe_device = { 286 286 .driver = { 287 - .owner = THIS_MODULE, 288 287 .name = "safe_serial", 289 288 }, 290 289 .id_table = id_table,
-1
drivers/usb/serial/sierra.c
··· 1021 1021 1022 1022 static struct usb_serial_driver sierra_device = { 1023 1023 .driver = { 1024 - .owner = THIS_MODULE, 1025 1024 .name = "sierra", 1026 1025 }, 1027 1026 .description = "Sierra USB modem",
-1
drivers/usb/serial/spcp8x5.c
··· 452 452 453 453 static struct usb_serial_driver spcp8x5_device = { 454 454 .driver = { 455 - .owner = THIS_MODULE, 456 455 .name = "SPCP8x5", 457 456 }, 458 457 .id_table = id_table,
-1
drivers/usb/serial/ssu100.c
··· 500 500 501 501 static struct usb_serial_driver ssu100_device = { 502 502 .driver = { 503 - .owner = THIS_MODULE, 504 503 .name = "ssu100", 505 504 }, 506 505 .description = DRIVER_DESC,
-1
drivers/usb/serial/symbolserial.c
··· 169 169 170 170 static struct usb_serial_driver symbol_device = { 171 171 .driver = { 172 - .owner = THIS_MODULE, 173 172 .name = "symbol", 174 173 }, 175 174 .id_table = id_table,
-2
drivers/usb/serial/ti_usb_3410_5052.c
··· 417 417 418 418 static struct usb_serial_driver ti_1port_device = { 419 419 .driver = { 420 - .owner = THIS_MODULE, 421 420 .name = "ti_usb_3410_5052_1", 422 421 }, 423 422 .description = "TI USB 3410 1 port adapter", ··· 449 450 450 451 static struct usb_serial_driver ti_2port_device = { 451 452 .driver = { 452 - .owner = THIS_MODULE, 453 453 .name = "ti_usb_3410_5052_2", 454 454 }, 455 455 .description = "TI USB 5052 2 port adapter",
-1
drivers/usb/serial/upd78f0730.c
··· 407 407 408 408 static struct usb_serial_driver upd78f0730_device = { 409 409 .driver = { 410 - .owner = THIS_MODULE, 411 410 .name = "upd78f0730", 412 411 }, 413 412 .id_table = id_table,
-1
drivers/usb/serial/usb-serial-simple.c
··· 24 24 }; \ 25 25 static struct usb_serial_driver vendor##_device = { \ 26 26 .driver = { \ 27 - .owner = THIS_MODULE, \ 28 27 .name = #vendor, \ 29 28 }, \ 30 29 .id_table = vendor##_id_table, \
+7 -5
drivers/usb/serial/usb-serial.c
··· 1459 1459 } 1460 1460 1461 1461 /** 1462 - * usb_serial_register_drivers - register drivers for a usb-serial module 1462 + * __usb_serial_register_drivers - register drivers for a usb-serial module 1463 1463 * @serial_drivers: NULL-terminated array of pointers to drivers to be registered 1464 + * @owner: owning module 1464 1465 * @name: name of the usb_driver for this set of @serial_drivers 1465 1466 * @id_table: list of all devices this @serial_drivers set binds to 1466 1467 * 1467 1468 * Registers all the drivers in the @serial_drivers array, and dynamically 1468 1469 * creates a struct usb_driver with the name @name and id_table of @id_table. 1469 1470 */ 1470 - int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[], 1471 - const char *name, 1472 - const struct usb_device_id *id_table) 1471 + int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[], 1472 + struct module *owner, const char *name, 1473 + const struct usb_device_id *id_table) 1473 1474 { 1474 1475 int rc; 1475 1476 struct usb_driver *udriver; ··· 1515 1514 1516 1515 for (sd = serial_drivers; *sd; ++sd) { 1517 1516 (*sd)->usb_driver = udriver; 1517 + (*sd)->driver.owner = owner; 1518 1518 rc = usb_serial_register(*sd); 1519 1519 if (rc) 1520 1520 goto err_deregister_drivers; ··· 1534 1532 kfree(udriver); 1535 1533 return rc; 1536 1534 } 1537 - EXPORT_SYMBOL_GPL(usb_serial_register_drivers); 1535 + EXPORT_SYMBOL_GPL(__usb_serial_register_drivers); 1538 1536 1539 1537 /** 1540 1538 * usb_serial_deregister_drivers - deregister drivers for a usb-serial module
-2
drivers/usb/serial/usb_debug.c
··· 83 83 84 84 static struct usb_serial_driver debug_device = { 85 85 .driver = { 86 - .owner = THIS_MODULE, 87 86 .name = "debug", 88 87 }, 89 88 .id_table = id_table, ··· 95 96 96 97 static struct usb_serial_driver dbc_device = { 97 98 .driver = { 98 - .owner = THIS_MODULE, 99 99 .name = "xhci_dbc", 100 100 }, 101 101 .id_table = dbc_id_table,
-3
drivers/usb/serial/visor.c
··· 161 161 and Palm 4.0 devices */ 162 162 static struct usb_serial_driver handspring_device = { 163 163 .driver = { 164 - .owner = THIS_MODULE, 165 164 .name = "visor", 166 165 }, 167 166 .description = "Handspring Visor / Palm OS", ··· 179 180 /* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */ 180 181 static struct usb_serial_driver clie_5_device = { 181 182 .driver = { 182 - .owner = THIS_MODULE, 183 183 .name = "clie_5", 184 184 }, 185 185 .description = "Sony Clie 5.0", ··· 198 200 /* device info for the Sony Clie OS version 3.5 */ 199 201 static struct usb_serial_driver clie_3_5_device = { 200 202 .driver = { 201 - .owner = THIS_MODULE, 202 203 .name = "clie_3.5", 203 204 }, 204 205 .description = "Sony Clie 3.5",
-2
drivers/usb/serial/whiteheat.c
··· 91 91 92 92 static struct usb_serial_driver whiteheat_fake_device = { 93 93 .driver = { 94 - .owner = THIS_MODULE, 95 94 .name = "whiteheatnofirm", 96 95 }, 97 96 .description = "Connect Tech - WhiteHEAT - (prerenumeration)", ··· 102 103 103 104 static struct usb_serial_driver whiteheat_device = { 104 105 .driver = { 105 - .owner = THIS_MODULE, 106 106 .name = "whiteheat", 107 107 }, 108 108 .description = "Connect Tech - WhiteHEAT",
-1
drivers/usb/serial/wishbone-serial.c
··· 70 70 71 71 static struct usb_serial_driver wishbone_serial_device = { 72 72 .driver = { 73 - .owner = THIS_MODULE, 74 73 .name = "wishbone_serial", 75 74 }, 76 75 .id_table = id_table,
-1
drivers/usb/serial/xr_serial.c
··· 1082 1082 1083 1083 static struct usb_serial_driver xr_device = { 1084 1084 .driver = { 1085 - .owner = THIS_MODULE, 1086 1085 .name = "xr_serial", 1087 1086 }, 1088 1087 .id_table = id_table,
-1
drivers/usb/serial/xsens_mt.c
··· 49 49 50 50 static struct usb_serial_driver xsens_mt_device = { 51 51 .driver = { 52 - .owner = THIS_MODULE, 53 52 .name = "xsens_mt", 54 53 }, 55 54 .id_table = id_table,
+2 -2
drivers/usb/storage/alauda.c
··· 132 132 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 133 133 .driver_info = (flags) } 134 134 135 - static struct usb_device_id alauda_usb_ids[] = { 135 + static const struct usb_device_id alauda_usb_ids[] = { 136 136 # include "unusual_alauda.h" 137 137 { } /* Terminating entry */ 138 138 }; ··· 154 154 .initFunction = init_function, \ 155 155 } 156 156 157 - static struct us_unusual_dev alauda_unusual_dev_list[] = { 157 + static const struct us_unusual_dev alauda_unusual_dev_list[] = { 158 158 # include "unusual_alauda.h" 159 159 { } /* Terminating entry */ 160 160 };
+2 -2
drivers/usb/storage/cypress_atacb.c
··· 33 33 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 34 34 .driver_info = (flags) } 35 35 36 - static struct usb_device_id cypress_usb_ids[] = { 36 + static const struct usb_device_id cypress_usb_ids[] = { 37 37 # include "unusual_cypress.h" 38 38 { } /* Terminating entry */ 39 39 }; ··· 55 55 .initFunction = init_function, \ 56 56 } 57 57 58 - static struct us_unusual_dev cypress_unusual_dev_list[] = { 58 + static const struct us_unusual_dev cypress_unusual_dev_list[] = { 59 59 # include "unusual_cypress.h" 60 60 { } /* Terminating entry */ 61 61 };
+2 -2
drivers/usb/storage/datafab.c
··· 80 80 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 81 81 .driver_info = (flags) } 82 82 83 - static struct usb_device_id datafab_usb_ids[] = { 83 + static const struct usb_device_id datafab_usb_ids[] = { 84 84 # include "unusual_datafab.h" 85 85 { } /* Terminating entry */ 86 86 }; ··· 102 102 .initFunction = init_function, \ 103 103 } 104 104 105 - static struct us_unusual_dev datafab_unusual_dev_list[] = { 105 + static const struct us_unusual_dev datafab_unusual_dev_list[] = { 106 106 # include "unusual_datafab.h" 107 107 { } /* Terminating entry */ 108 108 };
+3 -3
drivers/usb/storage/ene_ub6250.c
··· 43 43 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 44 44 .driver_info = (flags)} 45 45 46 - static struct usb_device_id ene_ub6250_usb_ids[] = { 46 + static const struct usb_device_id ene_ub6250_usb_ids[] = { 47 47 # include "unusual_ene_ub6250.h" 48 48 { } /* Terminating entry */ 49 49 }; ··· 65 65 .initFunction = init_function, \ 66 66 } 67 67 68 - static struct us_unusual_dev ene_ub6250_unusual_dev_list[] = { 68 + static const struct us_unusual_dev ene_ub6250_unusual_dev_list[] = { 69 69 # include "unusual_ene_ub6250.h" 70 70 { } /* Terminating entry */ 71 71 }; ··· 1484 1484 static int ms_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb) 1485 1485 { 1486 1486 u32 bl_num; 1487 - u16 bl_len; 1487 + u32 bl_len; 1488 1488 unsigned int offset = 0; 1489 1489 unsigned char buf[8]; 1490 1490 struct scatterlist *sg = NULL;
+2 -2
drivers/usb/storage/freecom.c
··· 119 119 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 120 120 .driver_info = (flags) } 121 121 122 - static struct usb_device_id freecom_usb_ids[] = { 122 + static const struct usb_device_id freecom_usb_ids[] = { 123 123 # include "unusual_freecom.h" 124 124 { } /* Terminating entry */ 125 125 }; ··· 141 141 .initFunction = init_function, \ 142 142 } 143 143 144 - static struct us_unusual_dev freecom_unusual_dev_list[] = { 144 + static const struct us_unusual_dev freecom_unusual_dev_list[] = { 145 145 # include "unusual_freecom.h" 146 146 { } /* Terminating entry */ 147 147 };
+2 -2
drivers/usb/storage/isd200.c
··· 67 67 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 68 68 .driver_info = (flags) } 69 69 70 - static struct usb_device_id isd200_usb_ids[] = { 70 + static const struct usb_device_id isd200_usb_ids[] = { 71 71 # include "unusual_isd200.h" 72 72 { } /* Terminating entry */ 73 73 }; ··· 89 89 .initFunction = init_function, \ 90 90 } 91 91 92 - static struct us_unusual_dev isd200_unusual_dev_list[] = { 92 + static const struct us_unusual_dev isd200_unusual_dev_list[] = { 93 93 # include "unusual_isd200.h" 94 94 { } /* Terminating entry */ 95 95 };
+2 -2
drivers/usb/storage/jumpshot.c
··· 62 62 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 63 63 .driver_info = (flags) } 64 64 65 - static struct usb_device_id jumpshot_usb_ids[] = { 65 + static const struct usb_device_id jumpshot_usb_ids[] = { 66 66 # include "unusual_jumpshot.h" 67 67 { } /* Terminating entry */ 68 68 }; ··· 84 84 .initFunction = init_function, \ 85 85 } 86 86 87 - static struct us_unusual_dev jumpshot_unusual_dev_list[] = { 87 + static const struct us_unusual_dev jumpshot_unusual_dev_list[] = { 88 88 # include "unusual_jumpshot.h" 89 89 { } /* Terminating entry */ 90 90 };
+2 -2
drivers/usb/storage/karma.c
··· 51 51 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 52 52 .driver_info = (flags) } 53 53 54 - static struct usb_device_id karma_usb_ids[] = { 54 + static const struct usb_device_id karma_usb_ids[] = { 55 55 # include "unusual_karma.h" 56 56 { } /* Terminating entry */ 57 57 }; ··· 73 73 .initFunction = init_function, \ 74 74 } 75 75 76 - static struct us_unusual_dev karma_unusual_dev_list[] = { 76 + static const struct us_unusual_dev karma_unusual_dev_list[] = { 77 77 # include "unusual_karma.h" 78 78 { } /* Terminating entry */ 79 79 };
+2 -2
drivers/usb/storage/onetouch.c
··· 55 55 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 56 56 .driver_info = (flags) } 57 57 58 - static struct usb_device_id onetouch_usb_ids[] = { 58 + static const struct usb_device_id onetouch_usb_ids[] = { 59 59 # include "unusual_onetouch.h" 60 60 { } /* Terminating entry */ 61 61 }; ··· 77 77 .initFunction = init_function, \ 78 78 } 79 79 80 - static struct us_unusual_dev onetouch_unusual_dev_list[] = { 80 + static const struct us_unusual_dev onetouch_unusual_dev_list[] = { 81 81 # include "unusual_onetouch.h" 82 82 { } /* Terminating entry */ 83 83 };
+2 -2
drivers/usb/storage/sddr09.c
··· 63 63 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 64 64 .driver_info = (flags) } 65 65 66 - static struct usb_device_id sddr09_usb_ids[] = { 66 + static const struct usb_device_id sddr09_usb_ids[] = { 67 67 # include "unusual_sddr09.h" 68 68 { } /* Terminating entry */ 69 69 }; ··· 85 85 .initFunction = init_function, \ 86 86 } 87 87 88 - static struct us_unusual_dev sddr09_unusual_dev_list[] = { 88 + static const struct us_unusual_dev sddr09_unusual_dev_list[] = { 89 89 # include "unusual_sddr09.h" 90 90 { } /* Terminating entry */ 91 91 };
+2 -2
drivers/usb/storage/sddr55.c
··· 40 40 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 41 41 .driver_info = (flags) } 42 42 43 - static struct usb_device_id sddr55_usb_ids[] = { 43 + static const struct usb_device_id sddr55_usb_ids[] = { 44 44 # include "unusual_sddr55.h" 45 45 { } /* Terminating entry */ 46 46 }; ··· 62 62 .initFunction = init_function, \ 63 63 } 64 64 65 - static struct us_unusual_dev sddr55_unusual_dev_list[] = { 65 + static const struct us_unusual_dev sddr55_unusual_dev_list[] = { 66 66 # include "unusual_sddr55.h" 67 67 { } /* Terminating entry */ 68 68 };
+2 -2
drivers/usb/storage/shuttle_usbat.c
··· 162 162 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 163 163 .driver_info = (flags) } 164 164 165 - static struct usb_device_id usbat_usb_ids[] = { 165 + static const struct usb_device_id usbat_usb_ids[] = { 166 166 # include "unusual_usbat.h" 167 167 { } /* Terminating entry */ 168 168 }; ··· 184 184 .initFunction = init_function, \ 185 185 } 186 186 187 - static struct us_unusual_dev usbat_unusual_dev_list[] = { 187 + static const struct us_unusual_dev usbat_unusual_dev_list[] = { 188 188 # include "unusual_usbat.h" 189 189 { } /* Terminating entry */ 190 190 };
+1 -1
drivers/usb/storage/uas.c
··· 927 927 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ 928 928 .driver_info = (flags) } 929 929 930 - static struct usb_device_id uas_usb_ids[] = { 930 + static const struct usb_device_id uas_usb_ids[] = { 931 931 # include "unusual_uas.h" 932 932 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_BULK) }, 933 933 { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, USB_SC_SCSI, USB_PR_UAS) },
+4 -2
drivers/usb/typec/anx7411.c
··· 6 6 * Copyright(c) 2022, Analogix Semiconductor. All rights reserved. 7 7 * 8 8 */ 9 + #include <linux/bitfield.h> 9 10 #include <linux/gpio/consumer.h> 10 11 #include <linux/i2c.h> 11 12 #include <linux/interrupt.h> ··· 885 884 OCM_RESET); 886 885 ret |= anx7411_reg_write(ctx->tcpc_client, ANALOG_CTRL_10, 0x80); 887 886 /* Set TCPC to RD and DRP enable */ 888 - cc1 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT; 889 - cc2 = TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT; 887 + cc1 = FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD); 888 + cc2 = FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD); 890 889 ret |= anx7411_reg_write(ctx->tcpc_client, TCPC_ROLE_CTRL, 891 890 TCPC_ROLE_CTRL_DRP | cc1 | cc2); 892 891 ··· 1572 1571 {.compatible = "analogix,anx7411",}, 1573 1572 {}, 1574 1573 }; 1574 + MODULE_DEVICE_TABLE(of, anx_match_table); 1575 1575 1576 1576 static struct i2c_driver anx7411_driver = { 1577 1577 .driver = {
+29 -24
drivers/usb/typec/tcpm/maxim_contaminant.c
··· 5 5 * USB-C module to reduce wakeups due to contaminants. 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/device.h> 9 10 #include <linux/irqreturn.h> 10 11 #include <linux/module.h> ··· 46 45 #define READ1_SLEEP_MS 10 47 46 #define READ2_SLEEP_MS 5 48 47 49 - #define STATUS_CHECK(reg, mask, val) (((reg) & (mask)) == (val)) 50 - 51 48 #define IS_CC_OPEN(cc_status) \ 52 - (STATUS_CHECK((cc_status), TCPC_CC_STATUS_CC1_MASK << TCPC_CC_STATUS_CC1_SHIFT, \ 53 - TCPC_CC_STATE_SRC_OPEN) && STATUS_CHECK((cc_status), \ 54 - TCPC_CC_STATUS_CC2_MASK << \ 55 - TCPC_CC_STATUS_CC2_SHIFT, \ 56 - TCPC_CC_STATE_SRC_OPEN)) 49 + (FIELD_GET(TCPC_CC_STATUS_CC1, cc_status) == TCPC_CC_STATE_SRC_OPEN \ 50 + && FIELD_GET(TCPC_CC_STATUS_CC2, cc_status) == TCPC_CC_STATE_SRC_OPEN) 57 51 58 52 static int max_contaminant_adc_to_mv(struct max_tcpci_chip *chip, enum fladc_select channel, 59 53 bool ua_src, u8 fladc) ··· 76 80 int ret; 77 81 78 82 /* Channel & scale select */ 79 - ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL_MASK, 80 - channel << ADC_CHANNEL_OFFSET); 83 + ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL, 84 + FIELD_PREP(ADCINSEL, channel)); 81 85 if (ret < 0) 82 86 return ret; 83 87 ··· 96 100 if (ret < 0) 97 101 return ret; 98 102 99 - ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL_MASK, 0); 103 + ret = regmap_update_bits(regmap, TCPC_VENDOR_ADC_CTRL1, ADCINSEL, 104 + FIELD_PREP(ADCINSEL, 0)); 100 105 if (ret < 0) 101 106 return ret; 102 107 ··· 117 120 if (channel == CC1_SCALE1 || channel == CC2_SCALE1 || channel == CC1_SCALE2 || 118 121 channel == CC2_SCALE2) { 119 122 /* Enable 1uA current source */ 120 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL_MASK, 121 - ULTRA_LOW_POWER_MODE); 123 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL, 124 + FIELD_PREP(CCLPMODESEL, ULTRA_LOW_POWER_MODE)); 122 125 if (ret < 0) 123 126 return ret; 124 127 125 128 /* Enable 1uA current source */ 126 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, UA_1_SRC); 129 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, 130 + FIELD_PREP(CCRPCTRL, UA_1_SRC)); 127 131 if (ret < 0) 128 132 return ret; 129 133 ··· 178 180 int ret; 179 181 180 182 /* Enable 80uA source */ 181 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, UA_80_SRC); 183 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, 184 + FIELD_PREP(CCRPCTRL, UA_80_SRC)); 182 185 if (ret < 0) 183 186 return ret; 184 187 ··· 212 213 if (ret < 0) 213 214 return ret; 214 215 215 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL_MASK, 0); 216 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCRPCTRL, 217 + FIELD_PREP(CCRPCTRL, 0)); 216 218 if (ret < 0) 217 219 return ret; 218 220 ··· 284 284 u8 temp; 285 285 int ret; 286 286 287 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL3, CCWTRDEB_MASK | CCWTRSEL_MASK 288 - | WTRCYCLE_MASK, CCWTRDEB_1MS << CCWTRDEB_SHIFT | 289 - CCWTRSEL_1V << CCWTRSEL_SHIFT | WTRCYCLE_4_8_S << 290 - WTRCYCLE_SHIFT); 287 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL3, 288 + CCWTRDEB | CCWTRSEL | WTRCYCLE, 289 + FIELD_PREP(CCWTRDEB, CCWTRDEB_1MS) 290 + | FIELD_PREP(CCWTRSEL, CCWTRSEL_1V) 291 + | FIELD_PREP(WTRCYCLE, WTRCYCLE_4_8_S)); 291 292 if (ret < 0) 292 293 return ret; 293 294 ··· 303 302 if (ret < 0) 304 303 return ret; 305 304 306 - ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL_MASK, 307 - ULTRA_LOW_POWER_MODE); 305 + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL, 306 + FIELD_PREP(CCLPMODESEL, 307 + ULTRA_LOW_POWER_MODE)); 308 308 if (ret < 0) 309 309 return ret; 310 310 ret = max_tcpci_read8(chip, TCPC_VENDOR_CC_CTRL2, &temp); ··· 324 322 return 0; 325 323 } 326 324 327 - bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce) 325 + bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce, 326 + bool *cc_handled) 328 327 { 329 328 u8 cc_status, pwr_cntl; 330 329 int ret; 330 + 331 + *cc_handled = true; 331 332 332 333 ret = max_tcpci_read8(chip, TCPC_CC_STATUS, &cc_status); 333 334 if (ret < 0) ··· 373 368 return true; 374 369 } 375 370 } 376 - return false; 377 371 } else if (chip->contaminant_state == DETECTED) { 378 - if (STATUS_CHECK(cc_status, TCPC_CC_STATUS_TOGGLING, 0)) { 372 + if (!(cc_status & TCPC_CC_STATUS_TOGGLING)) { 379 373 chip->contaminant_state = max_contaminant_detect_contaminant(chip); 380 374 if (chip->contaminant_state == DETECTED) { 381 375 max_contaminant_enable_dry_detection(chip); ··· 383 379 } 384 380 } 385 381 382 + *cc_handled = false; 386 383 return false; 387 384 } 388 385
+71 -63
drivers/usb/typec/tcpm/tcpci.c
··· 5 5 * USB Type-C Port Controller Interface. 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/delay.h> 9 10 #include <linux/kernel.h> 10 11 #include <linux/module.h> ··· 104 103 105 104 switch (cc) { 106 105 case TYPEC_CC_RA: 107 - reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) | 108 - (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT); 106 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RA) 107 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RA)); 109 108 break; 110 109 case TYPEC_CC_RD: 111 - reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | 112 - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); 110 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) 111 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); 113 112 break; 114 113 case TYPEC_CC_RP_DEF: 115 - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | 116 - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | 117 - (TCPC_ROLE_CTRL_RP_VAL_DEF << 118 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 114 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) 115 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) 116 + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 117 + TCPC_ROLE_CTRL_RP_VAL_DEF)); 119 118 break; 120 119 case TYPEC_CC_RP_1_5: 121 - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | 122 - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | 123 - (TCPC_ROLE_CTRL_RP_VAL_1_5 << 124 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 120 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) 121 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) 122 + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 123 + TCPC_ROLE_CTRL_RP_VAL_1_5)); 125 124 break; 126 125 case TYPEC_CC_RP_3_0: 127 - reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | 128 - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) | 129 - (TCPC_ROLE_CTRL_RP_VAL_3_0 << 130 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 126 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) 127 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP) 128 + | FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 129 + TCPC_ROLE_CTRL_RP_VAL_3_0)); 131 130 break; 132 131 case TYPEC_CC_OPEN: 133 132 default: 134 - reg = (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT) | 135 - (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); 133 + reg = (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN) 134 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN)); 136 135 break; 137 136 } 138 137 139 138 if (vconn_pres) { 140 139 if (polarity == TYPEC_POLARITY_CC2) { 141 - reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT); 142 - reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT); 140 + reg &= ~TCPC_ROLE_CTRL_CC1; 141 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN); 143 142 } else { 144 - reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT); 145 - reg |= (TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT); 143 + reg &= ~TCPC_ROLE_CTRL_CC2; 144 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN); 146 145 } 147 146 } 148 147 ··· 168 167 * APPLY_RC state is when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and vbus autodischarge on 169 168 * disconnect is disabled. Bail out when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2. 170 169 */ 171 - if (((reg & (TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT)) >> 172 - TCPC_ROLE_CTRL_CC2_SHIFT) != 173 - ((reg & (TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT)) >> 174 - TCPC_ROLE_CTRL_CC1_SHIFT)) 170 + if (FIELD_GET(TCPC_ROLE_CTRL_CC2, reg) != FIELD_GET(TCPC_ROLE_CTRL_CC1, reg)) 175 171 return 0; 176 172 177 173 return regmap_update_bits(tcpci->regmap, TCPC_ROLE_CTRL, polarity == TYPEC_POLARITY_CC1 ? 178 - TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT : 179 - TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT, 174 + TCPC_ROLE_CTRL_CC2 : TCPC_ROLE_CTRL_CC1, 180 175 TCPC_ROLE_CTRL_CC_OPEN); 181 176 } 182 177 ··· 197 200 switch (cc) { 198 201 default: 199 202 case TYPEC_CC_RP_DEF: 200 - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << 201 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 203 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 204 + TCPC_ROLE_CTRL_RP_VAL_DEF); 202 205 break; 203 206 case TYPEC_CC_RP_1_5: 204 - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << 205 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 207 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 208 + TCPC_ROLE_CTRL_RP_VAL_1_5); 206 209 break; 207 210 case TYPEC_CC_RP_3_0: 208 - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << 209 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 211 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 212 + TCPC_ROLE_CTRL_RP_VAL_3_0); 210 213 break; 211 214 } 212 215 213 216 if (cc == TYPEC_CC_RD) 214 - reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | 215 - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); 217 + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) 218 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); 216 219 else 217 - reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | 218 - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT); 220 + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) 221 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP)); 219 222 ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); 220 223 if (ret < 0) 221 224 return ret; ··· 238 241 if (ret < 0) 239 242 return ret; 240 243 241 - *cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) & 242 - TCPC_CC_STATUS_CC1_MASK, 244 + *cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, reg), 243 245 reg & TCPC_CC_STATUS_TERM || 244 246 tcpc_presenting_rd(role_control, CC1)); 245 - *cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) & 246 - TCPC_CC_STATUS_CC2_MASK, 247 + *cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, reg), 247 248 reg & TCPC_CC_STATUS_TERM || 248 249 tcpc_presenting_rd(role_control, CC2)); 249 250 ··· 277 282 reg = reg & ~TCPC_ROLE_CTRL_DRP; 278 283 279 284 if (polarity == TYPEC_POLARITY_CC2) { 280 - reg &= ~(TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT); 285 + reg &= ~TCPC_ROLE_CTRL_CC2; 281 286 /* Local port is source */ 282 287 if (cc2 == TYPEC_CC_RD) 283 288 /* Role control would have the Rp setting when DRP was enabled */ 284 - reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT; 289 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP); 285 290 else 286 - reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT; 291 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD); 287 292 } else { 288 - reg &= ~(TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT); 293 + reg &= ~TCPC_ROLE_CTRL_CC1; 289 294 /* Local port is source */ 290 295 if (cc1 == TYPEC_CC_RD) 291 296 /* Role control would have the Rp setting when DRP was enabled */ 292 - reg |= TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT; 297 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP); 293 298 else 294 - reg |= TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT; 299 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD); 295 300 } 296 301 } 297 302 298 303 if (polarity == TYPEC_POLARITY_CC2) 299 - reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC1_SHIFT; 304 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_OPEN); 300 305 else 301 - reg |= TCPC_ROLE_CTRL_CC_OPEN << TCPC_ROLE_CTRL_CC2_SHIFT; 306 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_OPEN); 302 307 ret = regmap_write(tcpci->regmap, TCPC_ROLE_CTRL, reg); 303 308 if (ret < 0) 304 309 return ret; ··· 456 461 unsigned int reg; 457 462 int ret; 458 463 459 - reg = PD_REV20 << TCPC_MSG_HDR_INFO_REV_SHIFT; 464 + reg = FIELD_PREP(TCPC_MSG_HDR_INFO_REV, PD_REV20); 460 465 if (role == TYPEC_SOURCE) 461 466 reg |= TCPC_MSG_HDR_INFO_PWR_ROLE; 462 467 if (data == TYPEC_HOST) ··· 607 612 } 608 613 609 614 /* nRetryCount is 3 in PD2.0 spec where 2 in PD3.0 spec */ 610 - reg = ((negotiated_rev > PD_REV20 ? PD_RETRY_COUNT_3_0_OR_HIGHER : PD_RETRY_COUNT_DEFAULT) 611 - << TCPC_TRANSMIT_RETRY_SHIFT) | (type << TCPC_TRANSMIT_TYPE_SHIFT); 615 + reg = FIELD_PREP(TCPC_TRANSMIT_RETRY, 616 + (negotiated_rev > PD_REV20 617 + ? PD_RETRY_COUNT_3_0_OR_HIGHER 618 + : PD_RETRY_COUNT_DEFAULT)); 619 + reg |= FIELD_PREP(TCPC_TRANSMIT_TYPE, type); 612 620 ret = regmap_write(tcpci->regmap, TCPC_TRANSMIT, reg); 613 621 if (ret < 0) 614 622 return ret; ··· 707 709 { 708 710 u16 status; 709 711 int ret; 712 + int irq_ret; 710 713 unsigned int raw; 711 714 712 715 tcpci_read16(tcpci, TCPC_ALERT, &status); 716 + irq_ret = status & tcpci->alert_mask; 713 717 718 + process_status: 714 719 /* 715 720 * Clear alert status for everything except RX_STATUS, which shouldn't 716 721 * be cleared until we have successfully retrieved message. ··· 786 785 else if (status & TCPC_ALERT_TX_FAILED) 787 786 tcpm_pd_transmit_complete(tcpci->port, TCPC_TX_FAILED); 788 787 789 - return IRQ_RETVAL(status & tcpci->alert_mask); 788 + tcpci_read16(tcpci, TCPC_ALERT, &status); 789 + 790 + if (status & tcpci->alert_mask) 791 + goto process_status; 792 + 793 + return IRQ_RETVAL(irq_ret); 790 794 } 791 795 EXPORT_SYMBOL_GPL(tcpci_irq); 792 796 ··· 923 917 924 918 chip->data.set_orientation = err; 925 919 926 - chip->tcpci = tcpci_register_port(&client->dev, &chip->data); 927 - if (IS_ERR(chip->tcpci)) 928 - return PTR_ERR(chip->tcpci); 929 - 930 920 err = devm_request_threaded_irq(&client->dev, client->irq, NULL, 931 921 _tcpci_irq, 932 - IRQF_SHARED | IRQF_ONESHOT | IRQF_TRIGGER_LOW, 922 + IRQF_SHARED | IRQF_ONESHOT, 933 923 dev_name(&client->dev), chip); 934 - if (err < 0) { 935 - tcpci_unregister_port(chip->tcpci); 924 + if (err < 0) 936 925 return err; 937 - } 938 926 939 - return 0; 927 + /* 928 + * Disable irq while registering port. If irq is configured as an edge 929 + * irq this allow to keep track and process the irq as soon as it is enabled. 930 + */ 931 + disable_irq(client->irq); 932 + chip->tcpci = tcpci_register_port(&client->dev, &chip->data); 933 + enable_irq(client->irq); 934 + 935 + return PTR_ERR_OR_ZERO(chip->tcpci); 940 936 } 941 937 942 938 static void tcpci_remove(struct i2c_client *client)
+22 -12
drivers/usb/typec/tcpm/tcpci_maxim.h
··· 20 20 #define SBUOVPDIS BIT(7) 21 21 #define CCOVPDIS BIT(6) 22 22 #define SBURPCTRL BIT(5) 23 - #define CCLPMODESEL_MASK GENMASK(4, 3) 24 - #define ULTRA_LOW_POWER_MODE BIT(3) 25 - #define CCRPCTRL_MASK GENMASK(2, 0) 23 + #define CCLPMODESEL GENMASK(4, 3) 24 + #define ULTRA_LOW_POWER_MODE 1 25 + #define CCRPCTRL GENMASK(2, 0) 26 26 #define UA_1_SRC 1 27 27 #define UA_80_SRC 3 28 28 29 29 #define TCPC_VENDOR_CC_CTRL3 0x8e 30 - #define CCWTRDEB_MASK GENMASK(7, 6) 31 - #define CCWTRDEB_SHIFT 6 30 + #define CCWTRDEB GENMASK(7, 6) 32 31 #define CCWTRDEB_1MS 1 33 - #define CCWTRSEL_MASK GENMASK(5, 3) 34 - #define CCWTRSEL_SHIFT 3 32 + #define CCWTRSEL GENMASK(5, 3) 35 33 #define CCWTRSEL_1V 0x4 36 34 #define CCLADDERDIS BIT(2) 37 - #define WTRCYCLE_MASK BIT(0) 38 - #define WTRCYCLE_SHIFT 0 35 + #define WTRCYCLE GENMASK(0, 0) 39 36 #define WTRCYCLE_2_4_S 0 40 37 #define WTRCYCLE_4_8_S 1 41 38 42 39 #define TCPC_VENDOR_ADC_CTRL1 0x91 43 - #define ADCINSEL_MASK GENMASK(7, 5) 44 - #define ADC_CHANNEL_OFFSET 5 40 + #define ADCINSEL GENMASK(7, 5) 45 41 #define ADCEN BIT(0) 46 42 47 43 enum contamiant_state { ··· 81 85 return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8)); 82 86 } 83 87 84 - bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce); 88 + /** 89 + * max_contaminant_is_contaminant - Test if CC was toggled due to contaminant 90 + * 91 + * @chip: Handle to a struct max_tcpci_chip 92 + * @disconnect_while_debounce: Whether the disconnect was detected when CC 93 + * pins were debouncing 94 + * @cc_handled: Returns whether or not update to CC status was handled here 95 + * 96 + * Determine if a contaminant was detected. 97 + * 98 + * Returns: true if a contaminant was detected, false otherwise. cc_handled 99 + * is updated to reflect whether or not further CC handling is required. 100 + */ 101 + bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce, 102 + bool *cc_handled); 85 103 86 104 #endif // TCPCI_MAXIM_H_
+42 -40
drivers/usb/typec/tcpm/tcpci_maxim_core.c
··· 97 97 if (ret < 0) 98 98 return; 99 99 100 - alert_mask = TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | TCPC_ALERT_TX_FAILED | 101 - TCPC_ALERT_RX_HARD_RST | TCPC_ALERT_RX_STATUS | TCPC_ALERT_CC_STATUS | 102 - TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | TCPC_ALERT_POWER_STATUS | 103 - /* Enable Extended alert for detecting Fast Role Swap Signal */ 104 - TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS | TCPC_ALERT_FAULT; 100 + alert_mask = (TCPC_ALERT_TX_SUCCESS | TCPC_ALERT_TX_DISCARDED | 101 + TCPC_ALERT_TX_FAILED | TCPC_ALERT_RX_HARD_RST | 102 + TCPC_ALERT_RX_STATUS | TCPC_ALERT_POWER_STATUS | 103 + TCPC_ALERT_CC_STATUS | 104 + TCPC_ALERT_EXTND | TCPC_ALERT_EXTENDED_STATUS | 105 + TCPC_ALERT_VBUS_DISCNCT | TCPC_ALERT_RX_BUF_OVF | 106 + TCPC_ALERT_FAULT); 105 107 106 108 ret = max_tcpci_write16(chip, TCPC_ALERT_MASK, alert_mask); 107 109 if (ret < 0) { ··· 193 191 * Read complete, clear RX status alert bit. 194 192 * Clear overflow as well if set. 195 193 */ 196 - ret = max_tcpci_write16(chip, TCPC_ALERT, status & TCPC_ALERT_RX_BUF_OVF ? 197 - TCPC_ALERT_RX_STATUS | TCPC_ALERT_RX_BUF_OVF : 198 - TCPC_ALERT_RX_STATUS); 194 + ret = max_tcpci_write16(chip, TCPC_ALERT, 195 + TCPC_ALERT_RX_STATUS | (status & TCPC_ALERT_RX_BUF_OVF)); 199 196 if (ret < 0) 200 197 return; 201 198 ··· 296 295 * be cleared until we have successfully retrieved message. 297 296 */ 298 297 if (status & ~TCPC_ALERT_RX_STATUS) { 299 - mask = status & TCPC_ALERT_RX_BUF_OVF ? 300 - status & ~(TCPC_ALERT_RX_STATUS | TCPC_ALERT_RX_BUF_OVF) : 301 - status & ~TCPC_ALERT_RX_STATUS; 298 + mask = status & ~(TCPC_ALERT_RX_STATUS 299 + | (status & TCPC_ALERT_RX_BUF_OVF)); 302 300 ret = max_tcpci_write16(chip, TCPC_ALERT, mask); 303 301 if (ret < 0) { 304 302 dev_err(chip->dev, "ALERT clear failed\n"); ··· 357 357 tcpm_vbus_change(chip->port); 358 358 359 359 if (status & TCPC_ALERT_CC_STATUS) { 360 + bool cc_handled = false; 361 + 360 362 if (chip->contaminant_state == DETECTED || tcpm_port_is_toggling(chip->port)) { 361 - if (!max_contaminant_is_contaminant(chip, false)) 363 + if (!max_contaminant_is_contaminant(chip, false, &cc_handled)) 362 364 tcpm_port_clean(chip->port); 363 - } else { 364 - tcpm_cc_change(chip->port); 365 365 } 366 + if (!cc_handled) 367 + tcpm_cc_change(chip->port); 366 368 } 367 369 368 370 if (status & TCPC_ALERT_POWER_STATUS) ··· 399 397 } 400 398 while (status) { 401 399 irq_return = _max_tcpci_irq(chip, status); 402 - /* Do not return if the ALERT is already set. */ 400 + /* Do not return if a (new) ALERT is set (again). */ 403 401 ret = max_tcpci_read16(chip, TCPC_ALERT, &status); 404 402 if (ret < 0) 405 403 break; ··· 457 455 static void max_tcpci_check_contaminant(struct tcpci *tcpci, struct tcpci_data *tdata) 458 456 { 459 457 struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata); 458 + bool cc_handled; 460 459 461 - if (!max_contaminant_is_contaminant(chip, true)) 460 + if (!max_contaminant_is_contaminant(chip, true, &cc_handled)) 462 461 tcpm_port_clean(chip->port); 463 462 } 464 463 ··· 475 472 return true; 476 473 } 477 474 475 + static void max_tcpci_unregister_tcpci_port(void *tcpci) 476 + { 477 + tcpci_unregister_port(tcpci); 478 + } 479 + 478 480 static int max_tcpci_probe(struct i2c_client *client) 479 481 { 480 482 int ret; ··· 492 484 493 485 chip->client = client; 494 486 chip->data.regmap = devm_regmap_init_i2c(client, &max_tcpci_regmap_config); 495 - if (IS_ERR(chip->data.regmap)) { 496 - dev_err(&client->dev, "Regmap init failed\n"); 497 - return PTR_ERR(chip->data.regmap); 498 - } 487 + if (IS_ERR(chip->data.regmap)) 488 + return dev_err_probe(&client->dev, PTR_ERR(chip->data.regmap), 489 + "Regmap init failed\n"); 499 490 500 491 chip->dev = &client->dev; 501 492 i2c_set_clientdata(client, chip); 502 493 503 494 ret = max_tcpci_read8(chip, TCPC_POWER_STATUS, &power_status); 504 495 if (ret < 0) 505 - return ret; 496 + return dev_err_probe(&client->dev, ret, 497 + "Failed to read TCPC_POWER_STATUS\n"); 506 498 507 499 /* Chip level tcpci callbacks */ 508 500 chip->data.set_vbus = max_tcpci_set_vbus; ··· 519 511 520 512 max_tcpci_init_regs(chip); 521 513 chip->tcpci = tcpci_register_port(chip->dev, &chip->data); 522 - if (IS_ERR(chip->tcpci)) { 523 - dev_err(&client->dev, "TCPCI port registration failed\n"); 524 - return PTR_ERR(chip->tcpci); 525 - } 514 + if (IS_ERR(chip->tcpci)) 515 + return dev_err_probe(&client->dev, PTR_ERR(chip->tcpci), 516 + "TCPCI port registration failed\n"); 517 + 518 + ret = devm_add_action_or_reset(&client->dev, 519 + max_tcpci_unregister_tcpci_port, 520 + chip->tcpci); 521 + if (ret) 522 + return ret; 523 + 526 524 chip->port = tcpci_get_tcpm_port(chip->tcpci); 525 + 527 526 ret = max_tcpci_init_alert(chip, client); 528 527 if (ret < 0) 529 - goto unreg_port; 528 + return dev_err_probe(&client->dev, ret, 529 + "IRQ initialization failed\n"); 530 530 531 531 device_init_wakeup(chip->dev, true); 532 532 return 0; 533 - 534 - unreg_port: 535 - tcpci_unregister_port(chip->tcpci); 536 - 537 - return ret; 538 - } 539 - 540 - static void max_tcpci_remove(struct i2c_client *client) 541 - { 542 - struct max_tcpci_chip *chip = i2c_get_clientdata(client); 543 - 544 - if (!IS_ERR_OR_NULL(chip->tcpci)) 545 - tcpci_unregister_port(chip->tcpci); 546 533 } 547 534 548 535 static const struct i2c_device_id max_tcpci_id[] = { ··· 560 557 .of_match_table = of_match_ptr(max_tcpci_of_match), 561 558 }, 562 559 .probe = max_tcpci_probe, 563 - .remove = max_tcpci_remove, 564 560 .id_table = max_tcpci_id, 565 561 }; 566 562 module_i2c_driver(max_tcpci_i2c_driver);
+13 -14
drivers/usb/typec/tcpm/tcpci_rt1711h.c
··· 5 5 * Richtek RT1711H Type-C Chip Driver 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/bits.h> 9 10 #include <linux/kernel.h> 10 11 #include <linux/mod_devicetable.h> ··· 196 195 if (ret < 0) 197 196 return ret; 198 197 199 - cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) & 200 - TCPC_CC_STATUS_CC1_MASK, 198 + cc1 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC1, status), 201 199 status & TCPC_CC_STATUS_TERM || 202 200 tcpc_presenting_rd(role, CC1)); 203 - cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) & 204 - TCPC_CC_STATUS_CC2_MASK, 201 + cc2 = tcpci_to_typec_cc(FIELD_GET(TCPC_CC_STATUS_CC2, status), 205 202 status & TCPC_CC_STATUS_TERM || 206 203 tcpc_presenting_rd(role, CC2)); 207 204 ··· 232 233 switch (cc) { 233 234 default: 234 235 case TYPEC_CC_RP_DEF: 235 - reg |= (TCPC_ROLE_CTRL_RP_VAL_DEF << 236 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 236 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 237 + TCPC_ROLE_CTRL_RP_VAL_DEF); 237 238 break; 238 239 case TYPEC_CC_RP_1_5: 239 - reg |= (TCPC_ROLE_CTRL_RP_VAL_1_5 << 240 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 240 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 241 + TCPC_ROLE_CTRL_RP_VAL_1_5); 241 242 break; 242 243 case TYPEC_CC_RP_3_0: 243 - reg |= (TCPC_ROLE_CTRL_RP_VAL_3_0 << 244 - TCPC_ROLE_CTRL_RP_VAL_SHIFT); 244 + reg |= FIELD_PREP(TCPC_ROLE_CTRL_RP_VAL, 245 + TCPC_ROLE_CTRL_RP_VAL_3_0); 245 246 break; 246 247 } 247 248 248 249 if (cc == TYPEC_CC_RD) 249 - reg |= (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | 250 - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT); 250 + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD) 251 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD)); 251 252 else 252 - reg |= (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) | 253 - (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT); 253 + reg |= (FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP) 254 + | FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP)); 254 255 255 256 ret = rt1711h_write8(chip, TCPC_ROLE_CTRL, reg); 256 257 if (ret < 0)
+2 -1
drivers/usb/typec/tipd/core.c
··· 1460 1460 1461 1461 if (!client->irq) 1462 1462 cancel_delayed_work_sync(&tps->wq_poll); 1463 + else 1464 + devm_free_irq(tps->dev, client->irq, tps); 1463 1465 1464 - devm_free_irq(tps->dev, client->irq, tps); 1465 1466 tps6598x_disconnect(tps, 0); 1466 1467 typec_unregister_port(tps->port); 1467 1468 usb_role_switch_put(tps->role_sw);
+64 -96
drivers/usb/typec/ucsi/ucsi.c
··· 38 38 39 39 void ucsi_notify_common(struct ucsi *ucsi, u32 cci) 40 40 { 41 + /* Ignore bogus data in CCI if busy indicator is set. */ 42 + if (cci & UCSI_CCI_BUSY) 43 + return; 44 + 41 45 if (UCSI_CCI_CONNECTOR(cci)) 42 46 ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); 43 47 ··· 103 99 104 100 *cci = 0; 105 101 106 - /* 107 - * Below UCSI 2.0, MESSAGE_IN was limited to 16 bytes. Truncate the 108 - * reads here. 109 - */ 110 - if (ucsi->version <= UCSI_VERSION_1_2) 111 - size = clamp(size, 0, 16); 102 + if (size > UCSI_MAX_DATA_LENGTH(ucsi)) 103 + return -EINVAL; 112 104 113 105 ret = ucsi->ops->sync_control(ucsi, command); 114 - if (ret) 115 - return ret; 116 - 117 - ret = ucsi->ops->read_cci(ucsi, cci); 118 - if (ret) 119 - return ret; 106 + if (ucsi->ops->read_cci(ucsi, cci)) 107 + return -EIO; 120 108 121 109 if (*cci & UCSI_CCI_BUSY) 122 - return -EBUSY; 110 + return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY; 111 + if (ret) 112 + return ret; 123 113 124 114 if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) 125 115 return -EIO; ··· 146 148 int ret; 147 149 148 150 command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num); 149 - ret = ucsi_run_command(ucsi, command, &cci, 150 - &error, sizeof(error), false); 151 - 152 - if (cci & UCSI_CCI_BUSY) { 153 - ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false); 154 - 155 - return ret ? ret : -EBUSY; 156 - } 157 - 151 + ret = ucsi_run_command(ucsi, command, &cci, &error, sizeof(error), false); 158 152 if (ret < 0) 159 153 return ret; 160 - 161 - if (cci & UCSI_CCI_ERROR) 162 - return -EIO; 163 154 164 155 switch (error) { 165 156 case UCSI_ERROR_INCOMPATIBLE_PARTNER: ··· 225 238 mutex_lock(&ucsi->ppm_lock); 226 239 227 240 ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack); 228 - if (cci & UCSI_CCI_BUSY) 229 - ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false) ?: -EBUSY; 230 - else if (cci & UCSI_CCI_ERROR) 241 + 242 + if (cci & UCSI_CCI_ERROR) 231 243 ret = ucsi_read_error(ucsi, connector_num); 232 244 233 245 mutex_unlock(&ucsi->ppm_lock); ··· 738 752 &pd_caps); 739 753 } 740 754 741 - static int ucsi_read_identity(struct ucsi_connector *con, u8 recipient, 742 - u8 offset, u8 bytes, void *resp) 755 + static int ucsi_get_pd_message(struct ucsi_connector *con, u8 recipient, 756 + size_t bytes, void *data, u8 type) 743 757 { 744 - struct ucsi *ucsi = con->ucsi; 758 + size_t len = min(bytes, UCSI_MAX_DATA_LENGTH(con->ucsi)); 745 759 u64 command; 760 + u8 offset; 746 761 int ret; 747 762 748 - command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | 749 - UCSI_CONNECTOR_NUMBER(con->num); 750 - command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); 751 - command |= UCSI_GET_PD_MESSAGE_OFFSET(offset); 752 - command |= UCSI_GET_PD_MESSAGE_BYTES(bytes); 753 - command |= UCSI_GET_PD_MESSAGE_TYPE(UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); 763 + for (offset = 0; offset < bytes; offset += len) { 764 + len = min(len, bytes - offset); 754 765 755 - ret = ucsi_send_command(ucsi, command, resp, bytes); 756 - if (ret < 0) 757 - dev_err(ucsi->dev, "UCSI_GET_PD_MESSAGE failed (%d)\n", ret); 766 + command = UCSI_COMMAND(UCSI_GET_PD_MESSAGE) | UCSI_CONNECTOR_NUMBER(con->num); 767 + command |= UCSI_GET_PD_MESSAGE_RECIPIENT(recipient); 768 + command |= UCSI_GET_PD_MESSAGE_OFFSET(offset); 769 + command |= UCSI_GET_PD_MESSAGE_BYTES(len); 770 + command |= UCSI_GET_PD_MESSAGE_TYPE(type); 758 771 759 - return ret; 760 - } 761 - 762 - static int ucsi_get_identity(struct ucsi_connector *con, u8 recipient, 763 - struct usb_pd_identity *id) 764 - { 765 - struct ucsi *ucsi = con->ucsi; 766 - struct ucsi_pd_message_disc_id resp = {}; 767 - int ret; 768 - 769 - if (ucsi->version < UCSI_VERSION_2_0) { 770 - /* 771 - * Before UCSI v2.0, MESSAGE_IN is 16 bytes which cannot fit 772 - * the 28 byte identity response including the VDM header. 773 - * First request the VDM header, ID Header VDO, Cert Stat VDO 774 - * and Product VDO. 775 - */ 776 - ret = ucsi_read_identity(con, recipient, 0, 0x10, &resp); 777 - if (ret < 0) 778 - return ret; 779 - 780 - 781 - /* Then request Product Type VDO1 through Product Type VDO3. */ 782 - ret = ucsi_read_identity(con, recipient, 0x10, 0xc, 783 - &resp.vdo[0]); 784 - if (ret < 0) 785 - return ret; 786 - 787 - } else { 788 - /* 789 - * In UCSI v2.0 and after, MESSAGE_IN is large enough to request 790 - * the large enough to request the full Discover Identity 791 - * response at once. 792 - */ 793 - ret = ucsi_read_identity(con, recipient, 0x0, 0x1c, &resp); 772 + ret = ucsi_send_command(con->ucsi, command, data + offset, len); 794 773 if (ret < 0) 795 774 return ret; 796 775 } 797 776 798 - id->id_header = resp.id_header; 799 - id->cert_stat = resp.cert_stat; 800 - id->product = resp.product; 801 - id->vdo[0] = resp.vdo[0]; 802 - id->vdo[1] = resp.vdo[1]; 803 - id->vdo[2] = resp.vdo[2]; 804 777 return 0; 805 778 } 806 779 807 780 static int ucsi_get_partner_identity(struct ucsi_connector *con) 808 781 { 782 + u32 vdo[7] = {}; 809 783 int ret; 810 784 811 - ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP, 812 - &con->partner_identity); 785 + ret = ucsi_get_pd_message(con, UCSI_RECIPIENT_SOP, sizeof(vdo), vdo, 786 + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); 813 787 if (ret < 0) 814 788 return ret; 815 789 790 + /* VDM Header is not part of struct usb_pd_identity, so dropping it. */ 791 + con->partner_identity = *(struct usb_pd_identity *)&vdo[1]; 792 + 816 793 ret = typec_partner_set_identity(con->partner); 817 - if (ret < 0) { 818 - dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", 819 - ret); 820 - } 794 + if (ret < 0) 795 + dev_err(con->ucsi->dev, "Failed to set partner identity (%d)\n", ret); 821 796 822 797 return ret; 823 798 } 824 799 825 800 static int ucsi_get_cable_identity(struct ucsi_connector *con) 826 801 { 802 + u32 vdo[7] = {}; 827 803 int ret; 828 804 829 - ret = ucsi_get_identity(con, UCSI_RECIPIENT_SOP_P, 830 - &con->cable_identity); 805 + ret = ucsi_get_pd_message(con, UCSI_RECIPIENT_SOP_P, sizeof(vdo), vdo, 806 + UCSI_GET_PD_MESSAGE_TYPE_IDENTITY); 831 807 if (ret < 0) 832 808 return ret; 833 809 810 + con->cable_identity = *(struct usb_pd_identity *)&vdo[1]; 811 + 834 812 ret = typec_cable_set_identity(con->cable); 835 - if (ret < 0) { 836 - dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", 837 - ret); 838 - } 813 + if (ret < 0) 814 + dev_err(con->ucsi->dev, "Failed to set cable identity (%d)\n", ret); 839 815 840 816 return ret; 841 817 } ··· 941 993 break; 942 994 } 943 995 944 - desc.identity = &con->cable_identity; 996 + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) 997 + desc.identity = &con->cable_identity; 945 998 desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & cable_prop.flags); 946 999 947 1000 if (con->ucsi->version >= UCSI_VERSION_2_1) ··· 1043 1094 if (pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD) 1044 1095 ucsi_register_device_pdos(con); 1045 1096 1046 - desc.identity = &con->partner_identity; 1097 + if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) 1098 + desc.identity = &con->partner_identity; 1047 1099 desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; 1048 1100 1049 1101 partner = typec_register_partner(con->port, &desc); ··· 1199 1249 1200 1250 mutex_lock(&con->lock); 1201 1251 1252 + if (!test_and_set_bit(EVENT_PENDING, &ucsi->flags)) 1253 + dev_err_once(ucsi->dev, "%s entered without EVENT_PENDING\n", 1254 + __func__); 1255 + 1202 1256 command = UCSI_GET_CONNECTOR_STATUS | UCSI_CONNECTOR_NUMBER(con->num); 1203 1257 1204 1258 ret = ucsi_send_command_common(ucsi, command, &con->status, ··· 1295 1341 1296 1342 /* -------------------------------------------------------------------------- */ 1297 1343 1344 + /* 1345 + * Hard Reset bit field was defined with value 1 in UCSI spec version 1.0. 1346 + * Starting with spec version 1.1, Hard Reset bit field was removed from the 1347 + * CONNECTOR_RESET command, until spec 2.0 reintroduced it with value 0, so, in effect, 1348 + * the value to pass in to the command for a Hard Reset is different depending 1349 + * on the supported UCSI version by the LPM. 1350 + * 1351 + * For performing a Data Reset on LPMs supporting version 2.0 and greater, 1352 + * this function needs to be called with the second argument set to 0. 1353 + */ 1298 1354 static int ucsi_reset_connector(struct ucsi_connector *con, bool hard) 1299 1355 { 1300 1356 u64 command; 1301 1357 1302 1358 command = UCSI_CONNECTOR_RESET | UCSI_CONNECTOR_NUMBER(con->num); 1303 - command |= hard ? UCSI_CONNECTOR_RESET_HARD : 0; 1359 + 1360 + if (con->ucsi->version < UCSI_VERSION_1_1) 1361 + command |= hard ? UCSI_CONNECTOR_RESET_HARD_VER_1_0 : 0; 1362 + else if (con->ucsi->version >= UCSI_VERSION_2_0) 1363 + command |= hard ? 0 : UCSI_CONNECTOR_RESET_DATA_VER_2_0; 1304 1364 1305 1365 return ucsi_send_command(con->ucsi, command, NULL, 0); 1306 1366 }
+8 -38
drivers/usb/typec/ucsi/ucsi.h
··· 29 29 #define UCSIv2_MESSAGE_OUT 272 30 30 31 31 /* UCSI versions */ 32 + #define UCSI_VERSION_1_1 0x0110 32 33 #define UCSI_VERSION_1_2 0x0120 33 34 #define UCSI_VERSION_2_0 0x0200 34 35 #define UCSI_VERSION_2_1 0x0210 ··· 123 122 #define UCSI_DEFAULT_GET_CONNECTOR_NUMBER(_cmd_) (((_cmd_) >> 16) & GENMASK(6, 0)) 124 123 125 124 /* CONNECTOR_RESET command bits */ 126 - #define UCSI_CONNECTOR_RESET_HARD BIT(23) /* Deprecated in v1.1 */ 125 + #define UCSI_CONNECTOR_RESET_HARD_VER_1_0 BIT(23) /* Deprecated in v1.1 */ 126 + #define UCSI_CONNECTOR_RESET_DATA_VER_2_0 BIT(23) /* Redefined in v2.0 */ 127 + 127 128 128 129 /* ACK_CC_CI bits */ 129 130 #define UCSI_ACK_CONNECTOR_CHANGE BIT(16) ··· 347 344 #define UCSI_CONSTAT_PARTNER_TYPE_AUDIO 6 348 345 u32 request_data_obj; 349 346 350 - u8 pwr_status[3]; 351 - #define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_[0]) & GENMASK(1, 0)) 347 + u8 pwr_status; 348 + #define UCSI_CONSTAT_BC_STATUS(_p_) ((_p_) & GENMASK(1, 0)) 352 349 #define UCSI_CONSTAT_BC_NOT_CHARGING 0 353 350 #define UCSI_CONSTAT_BC_NOMINAL_CHARGING 1 354 351 #define UCSI_CONSTAT_BC_SLOW_CHARGING 2 355 352 #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3 356 - #define UCSI_CONSTAT_PROVIDER_CAP_LIMIT(_p_) (((_p_[0]) & GENMASK(5, 2)) >> 2) 357 - #define UCSI_CONSTAT_CAP_PWR_LOWERED 0 358 - #define UCSI_CONSTAT_CAP_PWR_BUDGET_LIMIT 1 359 - #define UCSI_CONSTAT_PROVIDER_PD_VERSION_OPER_MODE(_p_) \ 360 - ((get_unaligned_le32(_p_) & GENMASK(21, 6)) >> 6) 361 - #define UCSI_CONSTAT_ORIENTATION(_p_) (((_p_[2]) & GENMASK(6, 6)) >> 6) 362 - #define UCSI_CONSTAT_ORIENTATION_DIRECT 0 363 - #define UCSI_CONSTAT_ORIENTATION_FLIPPED 1 364 - #define UCSI_CONSTAT_SINK_PATH_STATUS(_p_) (((_p_[2]) & GENMASK(7, 7)) >> 7) 365 - #define UCSI_CONSTAT_SINK_PATH_DISABLED 0 366 - #define UCSI_CONSTAT_SINK_PATH_ENABLED 1 367 - u8 pwr_readings[9]; 368 - #define UCSI_CONSTAT_REV_CURR_PROT_STATUS(_p_) ((_p_[0]) & 0x1) 369 - #define UCSI_CONSTAT_PWR_READING_VALID(_p_) (((_p_[0]) & GENMASK(1, 1)) >> 1) 370 - #define UCSI_CONSTAT_CURRENT_SCALE(_p_) (((_p_[0]) & GENMASK(4, 2)) >> 2) 371 - #define UCSI_CONSTAT_PEAK_CURRENT(_p_) \ 372 - ((get_unaligned_le32(_p_) & GENMASK(20, 5)) >> 5) 373 - #define UCSI_CONSTAT_AVG_CURRENT(_p_) \ 374 - ((get_unaligned_le32(&(_p_)[2]) & GENMASK(20, 5)) >> 5) 375 - #define UCSI_CONSTAT_VOLTAGE_SCALE(_p_) \ 376 - ((get_unaligned_le16(&(_p_)[4]) & GENMASK(8, 5)) >> 5) 377 - #define UCSI_CONSTAT_VOLTAGE_READING(_p_) \ 378 - ((get_unaligned_le32(&(_p_)[5]) & GENMASK(16, 1)) >> 1) 379 - } __packed; 380 - 381 - /* 382 - * Data structure filled by PPM in response to GET_PD_MESSAGE command with the 383 - * Response Message Type set to Discover Identity Response. 384 - */ 385 - struct ucsi_pd_message_disc_id { 386 - u32 vdm_header; 387 - u32 id_header; 388 - u32 cert_stat; 389 - u32 product; 390 - u32 vdo[3]; 391 353 } __packed; 392 354 393 355 /* -------------------------------------------------------------------------- */ ··· 402 434 #define UCSI_NO_PARTNER_PDOS BIT(0) /* Don't read partner's PDOs */ 403 435 #define UCSI_DELAY_DEVICE_PDOS BIT(1) /* Reading PDOs fails until the parter is in PD mode */ 404 436 }; 437 + 438 + #define UCSI_MAX_DATA_LENGTH(u) (((u)->version < UCSI_VERSION_2_0) ? 0x10 : 0xff) 405 439 406 440 #define UCSI_MAX_SVID 5 407 441 #define UCSI_MAX_ALTMODES (UCSI_MAX_SVID * 6)
+1 -1
drivers/usb/typec/ucsi/ucsi_glink.c
··· 278 278 case UC_UCSI_USBC_NOTIFY_IND: 279 279 schedule_work(&ucsi->notify_work); 280 280 break; 281 - }; 281 + } 282 282 } 283 283 284 284 static void pmic_glink_ucsi_pdr_notify(void *priv, int state)
+18 -18
drivers/usb/usbip/vhci_hcd.c
··· 372 372 } 373 373 switch (wValue) { 374 374 case USB_PORT_FEAT_SUSPEND: 375 - if (hcd->speed == HCD_USB3) { 375 + if (hcd->speed >= HCD_USB3) { 376 376 pr_err(" ClearPortFeature: USB_PORT_FEAT_SUSPEND req not " 377 377 "supported for USB 3.0 roothub\n"); 378 378 goto error; ··· 388 388 case USB_PORT_FEAT_POWER: 389 389 usbip_dbg_vhci_rh( 390 390 " ClearPortFeature: USB_PORT_FEAT_POWER\n"); 391 - if (hcd->speed == HCD_USB3) 391 + if (hcd->speed >= HCD_USB3) 392 392 vhci_hcd->port_status[rhport] &= ~USB_SS_PORT_STAT_POWER; 393 393 else 394 394 vhci_hcd->port_status[rhport] &= ~USB_PORT_STAT_POWER; ··· 404 404 break; 405 405 case GetHubDescriptor: 406 406 usbip_dbg_vhci_rh(" GetHubDescriptor\n"); 407 - if (hcd->speed == HCD_USB3 && 407 + if (hcd->speed >= HCD_USB3 && 408 408 (wLength < USB_DT_SS_HUB_SIZE || 409 409 wValue != (USB_DT_SS_HUB << 8))) { 410 410 pr_err("Wrong hub descriptor type for USB 3.0 roothub.\n"); 411 411 goto error; 412 412 } 413 - if (hcd->speed == HCD_USB3) 413 + if (hcd->speed >= HCD_USB3) 414 414 ss_hub_descriptor((struct usb_hub_descriptor *) buf); 415 415 else 416 416 hub_descriptor((struct usb_hub_descriptor *) buf); 417 417 break; 418 418 case DeviceRequest | USB_REQ_GET_DESCRIPTOR: 419 - if (hcd->speed != HCD_USB3) 419 + if (hcd->speed < HCD_USB3) 420 420 goto error; 421 421 422 422 if ((wValue >> 8) != USB_DT_BOS) ··· 503 503 case USB_PORT_FEAT_LINK_STATE: 504 504 usbip_dbg_vhci_rh( 505 505 " SetPortFeature: USB_PORT_FEAT_LINK_STATE\n"); 506 - if (hcd->speed != HCD_USB3) { 506 + if (hcd->speed < HCD_USB3) { 507 507 pr_err("USB_PORT_FEAT_LINK_STATE req not " 508 508 "supported for USB 2.0 roothub\n"); 509 509 goto error; ··· 521 521 usbip_dbg_vhci_rh( 522 522 " SetPortFeature: USB_PORT_FEAT_U2_TIMEOUT\n"); 523 523 /* TODO: add suspend/resume support! */ 524 - if (hcd->speed != HCD_USB3) { 524 + if (hcd->speed < HCD_USB3) { 525 525 pr_err("USB_PORT_FEAT_U1/2_TIMEOUT req not " 526 526 "supported for USB 2.0 roothub\n"); 527 527 goto error; ··· 531 531 usbip_dbg_vhci_rh( 532 532 " SetPortFeature: USB_PORT_FEAT_SUSPEND\n"); 533 533 /* Applicable only for USB2.0 hub */ 534 - if (hcd->speed == HCD_USB3) { 534 + if (hcd->speed >= HCD_USB3) { 535 535 pr_err("USB_PORT_FEAT_SUSPEND req not " 536 536 "supported for USB 3.0 roothub\n"); 537 537 goto error; ··· 551 551 pr_err("invalid port number %d\n", wIndex); 552 552 goto error; 553 553 } 554 - if (hcd->speed == HCD_USB3) 554 + if (hcd->speed >= HCD_USB3) 555 555 vhci_hcd->port_status[rhport] |= USB_SS_PORT_STAT_POWER; 556 556 else 557 557 vhci_hcd->port_status[rhport] |= USB_PORT_STAT_POWER; ··· 564 564 goto error; 565 565 } 566 566 /* Applicable only for USB3.0 hub */ 567 - if (hcd->speed != HCD_USB3) { 567 + if (hcd->speed < HCD_USB3) { 568 568 pr_err("USB_PORT_FEAT_BH_PORT_RESET req not " 569 569 "supported for USB 2.0 roothub\n"); 570 570 goto error; ··· 578 578 goto error; 579 579 } 580 580 /* if it's already enabled, disable */ 581 - if (hcd->speed == HCD_USB3) { 581 + if (hcd->speed >= HCD_USB3) { 582 582 vhci_hcd->port_status[rhport] = 0; 583 583 vhci_hcd->port_status[rhport] = 584 584 (USB_SS_PORT_STAT_POWER | ··· 602 602 } 603 603 if (wValue >= 32) 604 604 goto error; 605 - if (hcd->speed == HCD_USB3) { 605 + if (hcd->speed >= HCD_USB3) { 606 606 if ((vhci_hcd->port_status[rhport] & 607 607 USB_SS_PORT_STAT_POWER) != 0) { 608 608 vhci_hcd->port_status[rhport] |= (1 << wValue); ··· 616 616 break; 617 617 case GetPortErrorCount: 618 618 usbip_dbg_vhci_rh(" GetPortErrorCount\n"); 619 - if (hcd->speed != HCD_USB3) { 619 + if (hcd->speed < HCD_USB3) { 620 620 pr_err("GetPortErrorCount req not " 621 621 "supported for USB 2.0 roothub\n"); 622 622 goto error; ··· 626 626 break; 627 627 case SetHubDepth: 628 628 usbip_dbg_vhci_rh(" SetHubDepth\n"); 629 - if (hcd->speed != HCD_USB3) { 629 + if (hcd->speed < HCD_USB3) { 630 630 pr_err("SetHubDepth req not supported for " 631 631 "USB 2.0 roothub\n"); 632 632 goto error; ··· 646 646 if (!invalid_rhport) { 647 647 dump_port_status_diff(prev_port_status[rhport], 648 648 vhci_hcd->port_status[rhport], 649 - hcd->speed == HCD_USB3); 649 + hcd->speed >= HCD_USB3); 650 650 } 651 651 } 652 652 usbip_dbg_vhci_rh(" bye\n"); ··· 1157 1157 } else { 1158 1158 vhci->vhci_hcd_ss = hcd_to_vhci_hcd(hcd); 1159 1159 vhci->vhci_hcd_ss->vhci = vhci; 1160 - hcd->speed = HCD_USB3; 1161 - hcd->self.root_hub->speed = USB_SPEED_SUPER; 1160 + hcd->speed = HCD_USB31; 1161 + hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; 1162 1162 } 1163 1163 1164 1164 /* ··· 1319 1319 .product_desc = driver_desc, 1320 1320 .hcd_priv_size = sizeof(struct vhci_hcd), 1321 1321 1322 - .flags = HCD_USB3 | HCD_SHARED, 1322 + .flags = HCD_USB31 | HCD_SHARED, 1323 1323 1324 1324 .reset = vhci_setup, 1325 1325 .start = vhci_start,
+2 -1
drivers/usb/usbip/vhci_sysfs.c
··· 283 283 case USB_SPEED_HIGH: 284 284 case USB_SPEED_WIRELESS: 285 285 case USB_SPEED_SUPER: 286 + case USB_SPEED_SUPER_PLUS: 286 287 break; 287 288 default: 288 289 pr_err("Failed attach request for unsupported USB speed: %s\n", ··· 350 349 vhci_hcd = hcd_to_vhci_hcd(hcd); 351 350 vhci = vhci_hcd->vhci; 352 351 353 - if (speed == USB_SPEED_SUPER) 352 + if (speed >= USB_SPEED_SUPER) 354 353 vdev = &vhci->vhci_hcd_ss->vdev[rhport]; 355 354 else 356 355 vdev = &vhci->vhci_hcd_hs->vdev[rhport];
+12 -7
include/linux/mutex.h
··· 49 49 50 50 #endif 51 51 52 - #ifndef CONFIG_PREEMPT_RT 53 52 /** 54 53 * mutex_init - initialize the mutex 55 54 * @mutex: the mutex to be initialized ··· 64 65 __mutex_init((mutex), #mutex, &__key); \ 65 66 } while (0) 66 67 68 + /** 69 + * mutex_init_with_key - initialize a mutex with a given lockdep key 70 + * @mutex: the mutex to be initialized 71 + * @key: the lockdep key to be associated with the mutex 72 + * 73 + * Initialize the mutex to the unlocked state. 74 + * 75 + * It is not allowed to initialize an already locked mutex. 76 + */ 77 + #define mutex_init_with_key(mutex, key) __mutex_init((mutex), #mutex, (key)) 78 + 79 + #ifndef CONFIG_PREEMPT_RT 67 80 #define __MUTEX_INITIALIZER(lockname) \ 68 81 { .owner = ATOMIC_LONG_INIT(0) \ 69 82 , .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ ··· 122 111 __mutex_rt_init((mutex), name, key); \ 123 112 } while (0) 124 113 125 - #define mutex_init(mutex) \ 126 - do { \ 127 - static struct lock_class_key __key; \ 128 - \ 129 - __mutex_init((mutex), #mutex, &__key); \ 130 - } while (0) 131 114 #endif /* CONFIG_PREEMPT_RT */ 132 115 133 116 #ifdef CONFIG_DEBUG_MUTEXES
+8
include/linux/usb.h
··· 495 495 496 496 struct usb_tt; 497 497 498 + enum usb_link_tunnel_mode { 499 + USB_LINK_UNKNOWN = 0, 500 + USB_LINK_NATIVE, 501 + USB_LINK_TUNNELED, 502 + }; 503 + 498 504 enum usb_port_connect_type { 499 505 USB_PORT_CONNECT_TYPE_UNKNOWN = 0, 500 506 USB_PORT_CONNECT_TYPE_HOT_PLUG, ··· 611 605 * WUSB devices are not, until we authorize them from user space. 612 606 * FIXME -- complete doc 613 607 * @authenticated: Crypto authentication passed 608 + * @tunnel_mode: Connection native or tunneled over USB4 614 609 * @lpm_capable: device supports LPM 615 610 * @lpm_devinit_allow: Allow USB3 device initiated LPM, exit latency is in range 616 611 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM ··· 721 714 unsigned do_remote_wakeup:1; 722 715 unsigned reset_resume:1; 723 716 unsigned port_is_suspended:1; 717 + enum usb_link_tunnel_mode tunnel_mode; 724 718 725 719 int slot_id; 726 720 struct usb2_lpm_parameters l1_params;
+1 -1
include/linux/usb/composite.h
··· 256 256 struct usb_ep *_ep); 257 257 int usb_func_wakeup(struct usb_function *func); 258 258 259 - #define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */ 259 + #define MAX_CONFIG_INTERFACES 32 260 260 261 261 /** 262 262 * struct usb_configuration - represents one gadget configuration
+2 -5
include/linux/usb/gadget_configfs.h
··· 4 4 5 5 #include <linux/configfs.h> 6 6 7 - int check_user_usb_string(const char *name, 8 - struct usb_gadget_strings *stringtab_dev); 9 - 10 7 #define GS_STRINGS_W(__struct, __name) \ 11 8 static ssize_t __struct##_##__name##_store(struct config_item *item, \ 12 9 const char *page, size_t len) \ ··· 34 37 .release = struct_in##_attr_release, \ 35 38 }; \ 36 39 \ 37 - static struct config_item_type struct_in##_langid_type = { \ 40 + static const struct config_item_type struct_in##_langid_type = { \ 38 41 .ct_item_ops = &struct_in##_langid_item_ops, \ 39 42 .ct_attrs = struct_in##_langid_attrs, \ 40 43 .ct_owner = THIS_MODULE, \ ··· 91 94 .drop_item = &struct_in##_strings_drop, \ 92 95 }; \ 93 96 \ 94 - static struct config_item_type struct_in##_strings_type = { \ 97 + static const struct config_item_type struct_in##_strings_type = { \ 95 98 .ct_group_ops = &struct_in##_strings_ops, \ 96 99 .ct_owner = THIS_MODULE, \ 97 100 }
+5 -2
include/linux/usb/serial.h
··· 311 311 #define to_usb_serial_driver(d) \ 312 312 container_of(d, struct usb_serial_driver, driver) 313 313 314 - int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[], 315 - const char *name, const struct usb_device_id *id_table); 314 + #define usb_serial_register_drivers(serial_drivers, name, id_table) \ 315 + __usb_serial_register_drivers(serial_drivers, THIS_MODULE, name, id_table) 316 + int __usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[], 317 + struct module *owner, const char *name, 318 + const struct usb_device_id *id_table); 316 319 void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]); 317 320 void usb_serial_port_softint(struct usb_serial_port *port); 318 321
+11 -20
include/linux/usb/tcpci.h
··· 63 63 64 64 #define TCPC_ROLE_CTRL 0x1a 65 65 #define TCPC_ROLE_CTRL_DRP BIT(6) 66 - #define TCPC_ROLE_CTRL_RP_VAL_SHIFT 4 67 - #define TCPC_ROLE_CTRL_RP_VAL_MASK 0x3 66 + #define TCPC_ROLE_CTRL_RP_VAL GENMASK(5, 4) 68 67 #define TCPC_ROLE_CTRL_RP_VAL_DEF 0x0 69 68 #define TCPC_ROLE_CTRL_RP_VAL_1_5 0x1 70 69 #define TCPC_ROLE_CTRL_RP_VAL_3_0 0x2 71 - #define TCPC_ROLE_CTRL_CC2_SHIFT 2 72 - #define TCPC_ROLE_CTRL_CC2_MASK 0x3 73 - #define TCPC_ROLE_CTRL_CC1_SHIFT 0 74 - #define TCPC_ROLE_CTRL_CC1_MASK 0x3 70 + #define TCPC_ROLE_CTRL_CC2 GENMASK(3, 2) 71 + #define TCPC_ROLE_CTRL_CC1 GENMASK(1, 0) 75 72 #define TCPC_ROLE_CTRL_CC_RA 0x0 76 73 #define TCPC_ROLE_CTRL_CC_RP 0x1 77 74 #define TCPC_ROLE_CTRL_CC_RD 0x2 ··· 89 92 #define TCPC_CC_STATUS_TERM BIT(4) 90 93 #define TCPC_CC_STATUS_TERM_RP 0 91 94 #define TCPC_CC_STATUS_TERM_RD 1 95 + #define TCPC_CC_STATUS_CC2 GENMASK(3, 2) 96 + #define TCPC_CC_STATUS_CC1 GENMASK(1, 0) 92 97 #define TCPC_CC_STATE_SRC_OPEN 0 93 - #define TCPC_CC_STATUS_CC2_SHIFT 2 94 - #define TCPC_CC_STATUS_CC2_MASK 0x3 95 - #define TCPC_CC_STATUS_CC1_SHIFT 0 96 - #define TCPC_CC_STATUS_CC1_MASK 0x3 97 98 98 99 #define TCPC_POWER_STATUS 0x1e 99 100 #define TCPC_POWER_STATUS_DBG_ACC_CON BIT(7) ··· 129 134 130 135 #define TCPC_MSG_HDR_INFO 0x2e 131 136 #define TCPC_MSG_HDR_INFO_DATA_ROLE BIT(3) 137 + #define TCPC_MSG_HDR_INFO_REV GENMASK(2, 1) 132 138 #define TCPC_MSG_HDR_INFO_PWR_ROLE BIT(0) 133 - #define TCPC_MSG_HDR_INFO_REV_SHIFT 1 134 - #define TCPC_MSG_HDR_INFO_REV_MASK 0x3 135 139 136 140 #define TCPC_RX_DETECT 0x2f 137 141 #define TCPC_RX_DETECT_HARD_RESET BIT(5) ··· 148 154 #define TCPC_RX_DATA 0x34 /* through 0x4f */ 149 155 150 156 #define TCPC_TRANSMIT 0x50 151 - #define TCPC_TRANSMIT_RETRY_SHIFT 4 152 - #define TCPC_TRANSMIT_RETRY_MASK 0x3 153 - #define TCPC_TRANSMIT_TYPE_SHIFT 0 154 - #define TCPC_TRANSMIT_TYPE_MASK 0x7 157 + #define TCPC_TRANSMIT_RETRY GENMASK(5, 4) 158 + #define TCPC_TRANSMIT_TYPE GENMASK(2, 0) 155 159 156 160 #define TCPC_TX_BYTE_CNT 0x51 157 161 #define TCPC_TX_HDR 0x52 ··· 170 178 171 179 #define tcpc_presenting_rd(reg, cc) \ 172 180 (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ 173 - (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ 174 - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) 181 + FIELD_GET(TCPC_ROLE_CTRL_## cc, reg) == TCPC_ROLE_CTRL_CC_RD) 175 182 176 183 struct tcpci; 177 184 ··· 181 190 * Optional; Callback to perform chip specific operations when FRS 182 191 * is sourcing vbus. 183 192 * @auto_discharge_disconnect: 184 - * Optional; Enables TCPC to autonously discharge vbus on disconnect. 193 + * Optional; Enables TCPC to autonomously discharge vbus on disconnect. 185 194 * @vbus_vsafe0v: 186 195 * optional; Set when TCPC can detect whether vbus is at VSAFE0V. 187 196 * @set_partner_usb_comm_capable: ··· 247 256 if (sink) 248 257 return TYPEC_CC_RP_3_0; 249 258 fallthrough; 250 - case 0x0: 259 + case TCPC_CC_STATE_SRC_OPEN: 251 260 default: 252 261 return TYPEC_CC_OPEN; 253 262 }
+6 -2
include/uapi/linux/usb/ch9.h
··· 254 254 #define USB_DT_DEVICE_CAPABILITY 0x10 255 255 #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11 256 256 #define USB_DT_WIRE_ADAPTER 0x21 257 + /* From USB Device Firmware Upgrade Specification, Revision 1.1 */ 258 + #define USB_DT_DFU_FUNCTIONAL 0x21 259 + /* these are from the Wireless USB spec */ 257 260 #define USB_DT_RPIPE 0x22 258 261 #define USB_DT_CS_RADIO_CONTROL 0x23 259 262 /* From the T10 UAS specification */ ··· 332 329 #define USB_CLASS_USB_TYPE_C_BRIDGE 0x12 333 330 #define USB_CLASS_MISC 0xef 334 331 #define USB_CLASS_APP_SPEC 0xfe 335 - #define USB_CLASS_VENDOR_SPEC 0xff 332 + #define USB_SUBCLASS_DFU 0x01 336 333 337 - #define USB_SUBCLASS_VENDOR_SPEC 0xff 334 + #define USB_CLASS_VENDOR_SPEC 0xff 335 + #define USB_SUBCLASS_VENDOR_SPEC 0xff 338 336 339 337 /*-------------------------------------------------------------------------*/ 340 338
+89 -8
include/uapi/linux/usb/functionfs.h
··· 3 3 #define _UAPI__LINUX_FUNCTIONFS_H__ 4 4 5 5 6 + #include <linux/const.h> 6 7 #include <linux/types.h> 7 8 #include <linux/ioctl.h> 8 9 ··· 37 36 __le16 wMaxPacketSize; 38 37 __u8 bInterval; 39 38 } __attribute__((packed)); 39 + 40 + /** 41 + * struct usb_dfu_functional_descriptor - DFU Functional descriptor 42 + * @bLength: Size of the descriptor (bytes) 43 + * @bDescriptorType: USB_DT_DFU_FUNCTIONAL 44 + * @bmAttributes: DFU attributes 45 + * @wDetachTimeOut: Maximum time to wait after DFU_DETACH (ms, le16) 46 + * @wTransferSize: Maximum number of bytes per control-write (le16) 47 + * @bcdDFUVersion: DFU Spec version (BCD, le16) 48 + */ 49 + struct usb_dfu_functional_descriptor { 50 + __u8 bLength; 51 + __u8 bDescriptorType; 52 + __u8 bmAttributes; 53 + __le16 wDetachTimeOut; 54 + __le16 wTransferSize; 55 + __le16 bcdDFUVersion; 56 + } __attribute__ ((packed)); 57 + 58 + /* from DFU functional descriptor bmAttributes */ 59 + #define DFU_FUNC_ATT_CAN_DOWNLOAD _BITUL(0) 60 + #define DFU_FUNC_ATT_CAN_UPLOAD _BITUL(1) 61 + #define DFU_FUNC_ATT_MANIFEST_TOLERANT _BITUL(2) 62 + #define DFU_FUNC_ATT_WILL_DETACH _BITUL(3) 63 + 40 64 41 65 struct usb_functionfs_descs_head_v2 { 42 66 __le32 magic; ··· 130 104 131 105 #ifndef __KERNEL__ 132 106 133 - /* 107 + /** 108 + * DOC: descriptors 109 + * 134 110 * Descriptors format: 135 111 * 112 + * +-----+-----------+--------------+--------------------------------------+ 136 113 * | off | name | type | description | 137 - * |-----+-----------+--------------+--------------------------------------| 114 + * +-----+-----------+--------------+--------------------------------------+ 138 115 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 | 116 + * +-----+-----------+--------------+--------------------------------------+ 139 117 * | 4 | length | LE32 | length of the whole data chunk | 118 + * +-----+-----------+--------------+--------------------------------------+ 140 119 * | 8 | flags | LE32 | combination of functionfs_flags | 120 + * +-----+-----------+--------------+--------------------------------------+ 141 121 * | | eventfd | LE32 | eventfd file descriptor | 122 + * +-----+-----------+--------------+--------------------------------------+ 142 123 * | | fs_count | LE32 | number of full-speed descriptors | 124 + * +-----+-----------+--------------+--------------------------------------+ 143 125 * | | hs_count | LE32 | number of high-speed descriptors | 126 + * +-----+-----------+--------------+--------------------------------------+ 144 127 * | | ss_count | LE32 | number of super-speed descriptors | 128 + * +-----+-----------+--------------+--------------------------------------+ 145 129 * | | os_count | LE32 | number of MS OS descriptors | 130 + * +-----+-----------+--------------+--------------------------------------+ 146 131 * | | fs_descrs | Descriptor[] | list of full-speed descriptors | 132 + * +-----+-----------+--------------+--------------------------------------+ 147 133 * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 134 + * +-----+-----------+--------------+--------------------------------------+ 148 135 * | | ss_descrs | Descriptor[] | list of super-speed descriptors | 136 + * +-----+-----------+--------------+--------------------------------------+ 149 137 * | | os_descrs | OSDesc[] | list of MS OS descriptors | 138 + * +-----+-----------+--------------+--------------------------------------+ 150 139 * 151 140 * Depending on which flags are set, various fields may be missing in the 152 141 * structure. Any flags that are not recognised cause the whole block to be ··· 169 128 * 170 129 * Legacy descriptors format (deprecated as of 3.14): 171 130 * 131 + * +-----+-----------+--------------+--------------------------------------+ 172 132 * | off | name | type | description | 173 - * |-----+-----------+--------------+--------------------------------------| 133 + * +-----+-----------+--------------+--------------------------------------+ 174 134 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC | 135 + * +-----+-----------+--------------+--------------------------------------+ 175 136 * | 4 | length | LE32 | length of the whole data chunk | 137 + * +-----+-----------+--------------+--------------------------------------+ 176 138 * | 8 | fs_count | LE32 | number of full-speed descriptors | 139 + * +-----+-----------+--------------+--------------------------------------+ 177 140 * | 12 | hs_count | LE32 | number of high-speed descriptors | 141 + * +-----+-----------+--------------+--------------------------------------+ 178 142 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors | 143 + * +-----+-----------+--------------+--------------------------------------+ 179 144 * | | hs_descrs | Descriptor[] | list of high-speed descriptors | 145 + * +-----+-----------+--------------+--------------------------------------+ 180 146 * 181 147 * All numbers must be in little endian order. 182 148 * 183 149 * Descriptor[] is an array of valid USB descriptors which have the following 184 150 * format: 185 151 * 152 + * +-----+-----------------+------+--------------------------+ 186 153 * | off | name | type | description | 187 - * |-----+-----------------+------+--------------------------| 154 + * +-----+-----------------+------+--------------------------+ 188 155 * | 0 | bLength | U8 | length of the descriptor | 156 + * +-----+-----------------+------+--------------------------+ 189 157 * | 1 | bDescriptorType | U8 | descriptor type | 158 + * +-----+-----------------+------+--------------------------+ 190 159 * | 2 | payload | | descriptor's payload | 160 + * +-----+-----------------+------+--------------------------+ 191 161 * 192 162 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of 193 163 * the following formats: 194 164 * 165 + * +-----+-----------------+------+--------------------------+ 195 166 * | off | name | type | description | 196 - * |-----+-----------------+------+--------------------------| 167 + * +-----+-----------------+------+--------------------------+ 197 168 * | 0 | inteface | U8 | related interface number | 169 + * +-----+-----------------+------+--------------------------+ 198 170 * | 1 | dwLength | U32 | length of the descriptor | 171 + * +-----+-----------------+------+--------------------------+ 199 172 * | 5 | bcdVersion | U16 | currently supported: 1 | 173 + * +-----+-----------------+------+--------------------------+ 200 174 * | 7 | wIndex | U16 | currently supported: 4 | 175 + * +-----+-----------------+------+--------------------------+ 201 176 * | 9 | bCount | U8 | number of ext. compat. | 177 + * +-----+-----------------+------+--------------------------+ 202 178 * | 10 | Reserved | U8 | 0 | 179 + * +-----+-----------------+------+--------------------------+ 203 180 * | 11 | ExtCompat[] | | list of ext. compat. d. | 181 + * +-----+-----------------+------+--------------------------+ 204 182 * 183 + * +-----+-----------------+------+--------------------------+ 205 184 * | off | name | type | description | 206 - * |-----+-----------------+------+--------------------------| 185 + * +-----+-----------------+------+--------------------------+ 207 186 * | 0 | inteface | U8 | related interface number | 187 + * +-----+-----------------+------+--------------------------+ 208 188 * | 1 | dwLength | U32 | length of the descriptor | 189 + * +-----+-----------------+------+--------------------------+ 209 190 * | 5 | bcdVersion | U16 | currently supported: 1 | 191 + * +-----+-----------------+------+--------------------------+ 210 192 * | 7 | wIndex | U16 | currently supported: 5 | 193 + * +-----+-----------------+------+--------------------------+ 211 194 * | 9 | wCount | U16 | number of ext. compat. | 195 + * +-----+-----------------+------+--------------------------+ 212 196 * | 11 | ExtProp[] | | list of ext. prop. d. | 197 + * +-----+-----------------+------+--------------------------+ 213 198 * 214 199 * ExtCompat[] is an array of valid Extended Compatiblity descriptors 215 200 * which have the following format: 216 201 * 202 + * +-----+-----------------------+------+-------------------------------------+ 217 203 * | off | name | type | description | 218 - * |-----+-----------------------+------+-------------------------------------| 204 + * +-----+-----------------------+------+-------------------------------------+ 219 205 * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st| 206 + * +-----+-----------------------+------+-------------------------------------+ 220 207 * | | | | interface in an IAD group | 208 + * +-----+-----------------------+------+-------------------------------------+ 221 209 * | 1 | Reserved | U8 | 1 | 210 + * +-----+-----------------------+------+-------------------------------------+ 222 211 * | 2 | CompatibleID | U8[8]| compatible ID string | 212 + * +-----+-----------------------+------+-------------------------------------+ 223 213 * | 10 | SubCompatibleID | U8[8]| subcompatible ID string | 214 + * +-----+-----------------------+------+-------------------------------------+ 224 215 * | 18 | Reserved | U8[6]| 0 | 216 + * +-----+-----------------------+------+-------------------------------------+ 225 217 * 226 218 * ExtProp[] is an array of valid Extended Properties descriptors 227 219 * which have the following format: 228 220 * 221 + * +-----+-----------------------+------+-------------------------------------+ 229 222 * | off | name | type | description | 230 - * |-----+-----------------------+------+-------------------------------------| 223 + * +-----+-----------------------+------+-------------------------------------+ 231 224 * | 0 | dwSize | U32 | length of the descriptor | 225 + * +-----+-----------------------+------+-------------------------------------+ 232 226 * | 4 | dwPropertyDataType | U32 | 1..7 | 227 + * +-----+-----------------------+------+-------------------------------------+ 233 228 * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) | 229 + * +-----+-----------------------+------+-------------------------------------+ 234 230 * | 10 | bPropertyName |U8[NL]| name of this property | 231 + * +-----+-----------------------+------+-------------------------------------+ 235 232 * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) | 233 + * +-----+-----------------------+------+-------------------------------------+ 236 234 * |14+NL| bProperty |U8[DL]| payload of this property | 235 + * +-----+-----------------------+------+-------------------------------------+ 237 236 */ 238 237 239 238 struct usb_functionfs_strings_head {
+40
include/uapi/linux/usb/g_hid.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2 + 3 + #ifndef __UAPI_LINUX_USB_G_HID_H 4 + #define __UAPI_LINUX_USB_G_HID_H 5 + 6 + #include <linux/types.h> 7 + 8 + /* Maximum HID report length for High-Speed USB (i.e. USB 2.0) */ 9 + #define MAX_REPORT_LENGTH 64 10 + 11 + /** 12 + * struct usb_hidg_report - response to GET_REPORT 13 + * @report_id: report ID that this is a response for 14 + * @userspace_req: 15 + * !0 this report is used for any pending GET_REPORT request 16 + * but wait on userspace to issue a new report on future requests 17 + * 0 this report is to be used for any future GET_REPORT requests 18 + * @length: length of the report response 19 + * @data: report response 20 + * @padding: padding for 32/64 bit compatibility 21 + * 22 + * Structure used by GADGET_HID_WRITE_GET_REPORT ioctl on /dev/hidg*. 23 + */ 24 + struct usb_hidg_report { 25 + __u8 report_id; 26 + __u8 userspace_req; 27 + __u16 length; 28 + __u8 data[MAX_REPORT_LENGTH]; 29 + __u8 padding[4]; 30 + }; 31 + 32 + /* The 'g' code is used by gadgetfs and hid gadget ioctl requests. 33 + * Don't add any colliding codes to either driver, and keep 34 + * them in unique ranges. 35 + */ 36 + 37 + #define GADGET_HID_READ_GET_REPORT_ID _IOR('g', 0x41, __u8) 38 + #define GADGET_HID_WRITE_GET_REPORT _IOW('g', 0x42, struct usb_hidg_report) 39 + 40 + #endif /* __UAPI_LINUX_USB_G_HID_H */
+1 -1
include/uapi/linux/usb/gadgetfs.h
··· 62 62 }; 63 63 64 64 65 - /* The 'g' code is also used by printer gadget ioctl requests. 65 + /* The 'g' code is also used by printer and hid gadget ioctl requests. 66 66 * Don't add any colliding codes to either driver, and keep 67 67 * them in unique ranges (size 0x20 for now). 68 68 */
+6
net/9p/Kconfig
··· 40 40 This builds support for a transport for 9pfs between 41 41 two Xen domains. 42 42 43 + config NET_9P_USBG 44 + bool "9P USB Gadget Transport" 45 + depends on USB_GADGET=y || USB_GADGET=NET_9P 46 + help 47 + This builds support for a transport for 9pfs over 48 + usb gadget. 43 49 44 50 config NET_9P_RDMA 45 51 depends on INET && INFINIBAND && INFINIBAND_ADDR_TRANS
+4
net/9p/Makefile
··· 4 4 obj-$(CONFIG_NET_9P_XEN) += 9pnet_xen.o 5 5 obj-$(CONFIG_NET_9P_VIRTIO) += 9pnet_virtio.o 6 6 obj-$(CONFIG_NET_9P_RDMA) += 9pnet_rdma.o 7 + obj-$(CONFIG_NET_9P_USBG) += 9pnet_usbg.o 7 8 8 9 9pnet-objs := \ 9 10 mod.o \ ··· 24 23 25 24 9pnet_rdma-objs := \ 26 25 trans_rdma.o \ 26 + 27 + 9pnet_usbg-objs := \ 28 + trans_usbg.o \
+956
net/9p/trans_usbg.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * trans_usbg.c - USB peripheral usb9pfs configuration driver and transport. 4 + * 5 + * Copyright (C) 2024 Michael Grzeschik <m.grzeschik@pengutronix.de> 6 + */ 7 + 8 + /* Gadget usb9pfs only needs two bulk endpoints, and will use the usb9pfs 9 + * transport to mount host exported filesystem via usb gadget. 10 + */ 11 + 12 + /* +--------------------------+ | +--------------------------+ 13 + * | 9PFS mounting client | | | 9PFS exporting server | 14 + * SW | | | | | 15 + * | (this:trans_usbg) | | |(e.g. diod or nfs-ganesha)| 16 + * +-------------^------------+ | +-------------^------------+ 17 + * | | | 18 + * ------------------|------------------------------------|------------- 19 + * | | | 20 + * +-------------v------------+ | +-------------v------------+ 21 + * | | | | | 22 + * HW | USB Device Controller <---------> USB Host Controller | 23 + * | | | | | 24 + * +--------------------------+ | +--------------------------+ 25 + */ 26 + 27 + #include <linux/cleanup.h> 28 + #include <linux/kernel.h> 29 + #include <linux/module.h> 30 + #include <linux/usb/composite.h> 31 + #include <linux/usb/func_utils.h> 32 + 33 + #include <net/9p/9p.h> 34 + #include <net/9p/client.h> 35 + #include <net/9p/transport.h> 36 + 37 + #define DEFAULT_BUFLEN 16384 38 + 39 + struct f_usb9pfs { 40 + struct p9_client *client; 41 + 42 + /* 9p request lock for en/dequeue */ 43 + spinlock_t lock; 44 + 45 + struct usb_request *in_req; 46 + struct usb_request *out_req; 47 + 48 + struct usb_ep *in_ep; 49 + struct usb_ep *out_ep; 50 + 51 + struct completion send; 52 + struct completion received; 53 + 54 + unsigned int buflen; 55 + 56 + struct usb_function function; 57 + }; 58 + 59 + static inline struct f_usb9pfs *func_to_usb9pfs(struct usb_function *f) 60 + { 61 + return container_of(f, struct f_usb9pfs, function); 62 + } 63 + 64 + struct f_usb9pfs_opts { 65 + struct usb_function_instance func_inst; 66 + unsigned int buflen; 67 + 68 + struct f_usb9pfs_dev *dev; 69 + 70 + /* Read/write access to configfs attributes is handled by configfs. 71 + * 72 + * This is to protect the data from concurrent access by read/write 73 + * and create symlink/remove symlink. 74 + */ 75 + struct mutex lock; 76 + int refcnt; 77 + }; 78 + 79 + struct f_usb9pfs_dev { 80 + struct f_usb9pfs *usb9pfs; 81 + struct f_usb9pfs_opts *opts; 82 + char tag[41]; 83 + bool inuse; 84 + 85 + struct list_head usb9pfs_instance; 86 + }; 87 + 88 + static DEFINE_MUTEX(usb9pfs_lock); 89 + static struct list_head usbg_instance_list; 90 + 91 + static int usb9pfs_queue_tx(struct f_usb9pfs *usb9pfs, struct p9_req_t *p9_tx_req, 92 + gfp_t gfp_flags) 93 + { 94 + struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; 95 + struct usb_request *req = usb9pfs->in_req; 96 + int ret; 97 + 98 + if (!(p9_tx_req->tc.size % usb9pfs->in_ep->maxpacket)) 99 + req->zero = 1; 100 + 101 + req->buf = p9_tx_req->tc.sdata; 102 + req->length = p9_tx_req->tc.size; 103 + req->context = p9_tx_req; 104 + 105 + dev_dbg(&cdev->gadget->dev, "%s usb9pfs send --> %d/%d, zero: %d\n", 106 + usb9pfs->in_ep->name, req->actual, req->length, req->zero); 107 + 108 + ret = usb_ep_queue(usb9pfs->in_ep, req, gfp_flags); 109 + if (ret) 110 + req->context = NULL; 111 + 112 + dev_dbg(&cdev->gadget->dev, "tx submit --> %d\n", ret); 113 + 114 + return ret; 115 + } 116 + 117 + static int usb9pfs_queue_rx(struct f_usb9pfs *usb9pfs, struct usb_request *req, 118 + gfp_t gfp_flags) 119 + { 120 + struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; 121 + int ret; 122 + 123 + ret = usb_ep_queue(usb9pfs->out_ep, req, gfp_flags); 124 + 125 + dev_dbg(&cdev->gadget->dev, "rx submit --> %d\n", ret); 126 + 127 + return ret; 128 + } 129 + 130 + static int usb9pfs_transmit(struct f_usb9pfs *usb9pfs, struct p9_req_t *p9_req) 131 + { 132 + int ret = 0; 133 + 134 + guard(spinlock_irqsave)(&usb9pfs->lock); 135 + 136 + ret = usb9pfs_queue_tx(usb9pfs, p9_req, GFP_ATOMIC); 137 + if (ret) 138 + return ret; 139 + 140 + list_del(&p9_req->req_list); 141 + 142 + p9_req_get(p9_req); 143 + 144 + return ret; 145 + } 146 + 147 + static void usb9pfs_tx_complete(struct usb_ep *ep, struct usb_request *req) 148 + { 149 + struct f_usb9pfs *usb9pfs = ep->driver_data; 150 + struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; 151 + struct p9_req_t *p9_tx_req = req->context; 152 + unsigned long flags; 153 + 154 + /* reset zero packages */ 155 + req->zero = 0; 156 + 157 + if (req->status) { 158 + dev_err(&cdev->gadget->dev, "%s usb9pfs complete --> %d, %d/%d\n", 159 + ep->name, req->status, req->actual, req->length); 160 + return; 161 + } 162 + 163 + dev_dbg(&cdev->gadget->dev, "%s usb9pfs complete --> %d, %d/%d\n", 164 + ep->name, req->status, req->actual, req->length); 165 + 166 + spin_lock_irqsave(&usb9pfs->lock, flags); 167 + WRITE_ONCE(p9_tx_req->status, REQ_STATUS_SENT); 168 + 169 + p9_req_put(usb9pfs->client, p9_tx_req); 170 + 171 + req->context = NULL; 172 + 173 + spin_unlock_irqrestore(&usb9pfs->lock, flags); 174 + 175 + complete(&usb9pfs->send); 176 + } 177 + 178 + static struct p9_req_t *usb9pfs_rx_header(struct f_usb9pfs *usb9pfs, void *buf) 179 + { 180 + struct p9_req_t *p9_rx_req; 181 + struct p9_fcall rc; 182 + int ret; 183 + 184 + /* start by reading header */ 185 + rc.sdata = buf; 186 + rc.offset = 0; 187 + rc.capacity = P9_HDRSZ; 188 + rc.size = P9_HDRSZ; 189 + 190 + p9_debug(P9_DEBUG_TRANS, "mux %p got %zu bytes\n", usb9pfs, 191 + rc.capacity - rc.offset); 192 + 193 + ret = p9_parse_header(&rc, &rc.size, NULL, NULL, 0); 194 + if (ret) { 195 + p9_debug(P9_DEBUG_ERROR, 196 + "error parsing header: %d\n", ret); 197 + return NULL; 198 + } 199 + 200 + p9_debug(P9_DEBUG_TRANS, 201 + "mux %p pkt: size: %d bytes tag: %d\n", 202 + usb9pfs, rc.size, rc.tag); 203 + 204 + p9_rx_req = p9_tag_lookup(usb9pfs->client, rc.tag); 205 + if (!p9_rx_req || p9_rx_req->status != REQ_STATUS_SENT) { 206 + p9_debug(P9_DEBUG_ERROR, "Unexpected packet tag %d\n", rc.tag); 207 + return NULL; 208 + } 209 + 210 + if (rc.size > p9_rx_req->rc.capacity) { 211 + p9_debug(P9_DEBUG_ERROR, 212 + "requested packet size too big: %d for tag %d with capacity %zd\n", 213 + rc.size, rc.tag, p9_rx_req->rc.capacity); 214 + p9_req_put(usb9pfs->client, p9_rx_req); 215 + return NULL; 216 + } 217 + 218 + if (!p9_rx_req->rc.sdata) { 219 + p9_debug(P9_DEBUG_ERROR, 220 + "No recv fcall for tag %d (req %p), disconnecting!\n", 221 + rc.tag, p9_rx_req); 222 + p9_req_put(usb9pfs->client, p9_rx_req); 223 + return NULL; 224 + } 225 + 226 + return p9_rx_req; 227 + } 228 + 229 + static void usb9pfs_rx_complete(struct usb_ep *ep, struct usb_request *req) 230 + { 231 + struct f_usb9pfs *usb9pfs = ep->driver_data; 232 + struct usb_composite_dev *cdev = usb9pfs->function.config->cdev; 233 + struct p9_req_t *p9_rx_req; 234 + 235 + if (req->status) { 236 + dev_err(&cdev->gadget->dev, "%s usb9pfs complete --> %d, %d/%d\n", 237 + ep->name, req->status, req->actual, req->length); 238 + return; 239 + } 240 + 241 + p9_rx_req = usb9pfs_rx_header(usb9pfs, req->buf); 242 + if (!p9_rx_req) 243 + return; 244 + 245 + memcpy(p9_rx_req->rc.sdata, req->buf, req->actual); 246 + 247 + p9_rx_req->rc.size = req->actual; 248 + 249 + p9_client_cb(usb9pfs->client, p9_rx_req, REQ_STATUS_RCVD); 250 + p9_req_put(usb9pfs->client, p9_rx_req); 251 + 252 + complete(&usb9pfs->received); 253 + } 254 + 255 + static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) 256 + { 257 + int value; 258 + 259 + value = usb_ep_disable(ep); 260 + if (value < 0) 261 + dev_info(&cdev->gadget->dev, 262 + "disable %s --> %d\n", ep->name, value); 263 + } 264 + 265 + static void disable_usb9pfs(struct f_usb9pfs *usb9pfs) 266 + { 267 + struct usb_composite_dev *cdev = 268 + usb9pfs->function.config->cdev; 269 + 270 + if (usb9pfs->in_req) { 271 + usb_ep_free_request(usb9pfs->in_ep, usb9pfs->in_req); 272 + usb9pfs->in_req = NULL; 273 + } 274 + 275 + if (usb9pfs->out_req) { 276 + usb_ep_free_request(usb9pfs->out_ep, usb9pfs->out_req); 277 + usb9pfs->out_req = NULL; 278 + } 279 + 280 + disable_ep(cdev, usb9pfs->in_ep); 281 + disable_ep(cdev, usb9pfs->out_ep); 282 + dev_dbg(&cdev->gadget->dev, "%s disabled\n", 283 + usb9pfs->function.name); 284 + } 285 + 286 + static int alloc_requests(struct usb_composite_dev *cdev, 287 + struct f_usb9pfs *usb9pfs) 288 + { 289 + int ret; 290 + 291 + usb9pfs->in_req = usb_ep_alloc_request(usb9pfs->in_ep, GFP_ATOMIC); 292 + if (!usb9pfs->in_req) { 293 + ret = -ENOENT; 294 + goto fail; 295 + } 296 + 297 + usb9pfs->out_req = alloc_ep_req(usb9pfs->out_ep, usb9pfs->buflen); 298 + if (!usb9pfs->out_req) { 299 + ret = -ENOENT; 300 + goto fail_in; 301 + } 302 + 303 + usb9pfs->in_req->complete = usb9pfs_tx_complete; 304 + usb9pfs->out_req->complete = usb9pfs_rx_complete; 305 + 306 + /* length will be set in complete routine */ 307 + usb9pfs->in_req->context = usb9pfs; 308 + usb9pfs->out_req->context = usb9pfs; 309 + 310 + return 0; 311 + 312 + fail_in: 313 + usb_ep_free_request(usb9pfs->in_ep, usb9pfs->in_req); 314 + fail: 315 + return ret; 316 + } 317 + 318 + static int enable_endpoint(struct usb_composite_dev *cdev, 319 + struct f_usb9pfs *usb9pfs, struct usb_ep *ep) 320 + { 321 + int ret; 322 + 323 + ret = config_ep_by_speed(cdev->gadget, &usb9pfs->function, ep); 324 + if (ret) 325 + return ret; 326 + 327 + ret = usb_ep_enable(ep); 328 + if (ret < 0) 329 + return ret; 330 + 331 + ep->driver_data = usb9pfs; 332 + 333 + return 0; 334 + } 335 + 336 + static int 337 + enable_usb9pfs(struct usb_composite_dev *cdev, struct f_usb9pfs *usb9pfs) 338 + { 339 + struct p9_client *client; 340 + int ret = 0; 341 + 342 + ret = enable_endpoint(cdev, usb9pfs, usb9pfs->in_ep); 343 + if (ret) 344 + goto out; 345 + 346 + ret = enable_endpoint(cdev, usb9pfs, usb9pfs->out_ep); 347 + if (ret) 348 + goto disable_in; 349 + 350 + ret = alloc_requests(cdev, usb9pfs); 351 + if (ret) 352 + goto disable_out; 353 + 354 + client = usb9pfs->client; 355 + if (client) 356 + client->status = Connected; 357 + 358 + dev_dbg(&cdev->gadget->dev, "%s enabled\n", usb9pfs->function.name); 359 + return 0; 360 + 361 + disable_out: 362 + usb_ep_disable(usb9pfs->out_ep); 363 + disable_in: 364 + usb_ep_disable(usb9pfs->in_ep); 365 + out: 366 + return ret; 367 + } 368 + 369 + static int p9_usbg_create(struct p9_client *client, const char *devname, char *args) 370 + { 371 + struct f_usb9pfs_dev *dev; 372 + struct f_usb9pfs *usb9pfs; 373 + int ret = -ENOENT; 374 + int found = 0; 375 + 376 + if (!devname) 377 + return -EINVAL; 378 + 379 + guard(mutex)(&usb9pfs_lock); 380 + 381 + list_for_each_entry(dev, &usbg_instance_list, usb9pfs_instance) { 382 + if (!strncmp(devname, dev->tag, strlen(devname))) { 383 + if (!dev->inuse) { 384 + dev->inuse = true; 385 + found = 1; 386 + break; 387 + } 388 + ret = -EBUSY; 389 + break; 390 + } 391 + } 392 + 393 + if (!found) { 394 + pr_err("no channels available for device %s\n", devname); 395 + return ret; 396 + } 397 + 398 + usb9pfs = dev->usb9pfs; 399 + if (!usb9pfs) 400 + return -EINVAL; 401 + 402 + client->trans = (void *)usb9pfs; 403 + if (!usb9pfs->in_req) 404 + client->status = Disconnected; 405 + else 406 + client->status = Connected; 407 + usb9pfs->client = client; 408 + 409 + client->trans_mod->maxsize = usb9pfs->buflen; 410 + 411 + complete(&usb9pfs->received); 412 + 413 + return 0; 414 + } 415 + 416 + static void usb9pfs_clear_tx(struct f_usb9pfs *usb9pfs) 417 + { 418 + struct p9_req_t *req; 419 + 420 + guard(spinlock_irqsave)(&usb9pfs->lock); 421 + 422 + req = usb9pfs->in_req->context; 423 + if (!req) 424 + return; 425 + 426 + if (!req->t_err) 427 + req->t_err = -ECONNRESET; 428 + 429 + p9_client_cb(usb9pfs->client, req, REQ_STATUS_ERROR); 430 + } 431 + 432 + static void p9_usbg_close(struct p9_client *client) 433 + { 434 + struct f_usb9pfs *usb9pfs; 435 + struct f_usb9pfs_dev *dev; 436 + struct f_usb9pfs_opts *opts; 437 + 438 + if (!client) 439 + return; 440 + 441 + usb9pfs = client->trans; 442 + if (!usb9pfs) 443 + return; 444 + 445 + client->status = Disconnected; 446 + 447 + usb9pfs_clear_tx(usb9pfs); 448 + 449 + opts = container_of(usb9pfs->function.fi, 450 + struct f_usb9pfs_opts, func_inst); 451 + 452 + dev = opts->dev; 453 + 454 + mutex_lock(&usb9pfs_lock); 455 + dev->inuse = false; 456 + mutex_unlock(&usb9pfs_lock); 457 + } 458 + 459 + static int p9_usbg_request(struct p9_client *client, struct p9_req_t *p9_req) 460 + { 461 + struct f_usb9pfs *usb9pfs = client->trans; 462 + int ret; 463 + 464 + if (client->status != Connected) 465 + return -EBUSY; 466 + 467 + ret = wait_for_completion_killable(&usb9pfs->received); 468 + if (ret) 469 + return ret; 470 + 471 + ret = usb9pfs_transmit(usb9pfs, p9_req); 472 + if (ret) 473 + return ret; 474 + 475 + ret = wait_for_completion_killable(&usb9pfs->send); 476 + if (ret) 477 + return ret; 478 + 479 + return usb9pfs_queue_rx(usb9pfs, usb9pfs->out_req, GFP_ATOMIC); 480 + } 481 + 482 + static int p9_usbg_cancel(struct p9_client *client, struct p9_req_t *req) 483 + { 484 + struct f_usb9pfs *usb9pfs = client->trans; 485 + int ret = 1; 486 + 487 + p9_debug(P9_DEBUG_TRANS, "client %p req %p\n", client, req); 488 + 489 + guard(spinlock_irqsave)(&usb9pfs->lock); 490 + 491 + if (req->status == REQ_STATUS_UNSENT) { 492 + list_del(&req->req_list); 493 + WRITE_ONCE(req->status, REQ_STATUS_FLSHD); 494 + p9_req_put(client, req); 495 + ret = 0; 496 + } 497 + 498 + return ret; 499 + } 500 + 501 + static struct p9_trans_module p9_usbg_trans = { 502 + .name = "usbg", 503 + .create = p9_usbg_create, 504 + .close = p9_usbg_close, 505 + .request = p9_usbg_request, 506 + .cancel = p9_usbg_cancel, 507 + .owner = THIS_MODULE, 508 + }; 509 + 510 + /*-------------------------------------------------------------------------*/ 511 + 512 + #define USB_PROTOCOL_9PFS 0x09 513 + 514 + static struct usb_interface_descriptor usb9pfs_intf = { 515 + .bLength = sizeof(usb9pfs_intf), 516 + .bDescriptorType = USB_DT_INTERFACE, 517 + 518 + .bNumEndpoints = 2, 519 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 520 + .bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC, 521 + .bInterfaceProtocol = USB_PROTOCOL_9PFS, 522 + 523 + /* .iInterface = DYNAMIC */ 524 + }; 525 + 526 + /* full speed support: */ 527 + 528 + static struct usb_endpoint_descriptor fs_usb9pfs_source_desc = { 529 + .bLength = USB_DT_ENDPOINT_SIZE, 530 + .bDescriptorType = USB_DT_ENDPOINT, 531 + 532 + .bEndpointAddress = USB_DIR_IN, 533 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 534 + }; 535 + 536 + static struct usb_endpoint_descriptor fs_usb9pfs_sink_desc = { 537 + .bLength = USB_DT_ENDPOINT_SIZE, 538 + .bDescriptorType = USB_DT_ENDPOINT, 539 + 540 + .bEndpointAddress = USB_DIR_OUT, 541 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 542 + }; 543 + 544 + static struct usb_descriptor_header *fs_usb9pfs_descs[] = { 545 + (struct usb_descriptor_header *)&usb9pfs_intf, 546 + (struct usb_descriptor_header *)&fs_usb9pfs_sink_desc, 547 + (struct usb_descriptor_header *)&fs_usb9pfs_source_desc, 548 + NULL, 549 + }; 550 + 551 + /* high speed support: */ 552 + 553 + static struct usb_endpoint_descriptor hs_usb9pfs_source_desc = { 554 + .bLength = USB_DT_ENDPOINT_SIZE, 555 + .bDescriptorType = USB_DT_ENDPOINT, 556 + 557 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 558 + .wMaxPacketSize = cpu_to_le16(512), 559 + }; 560 + 561 + static struct usb_endpoint_descriptor hs_usb9pfs_sink_desc = { 562 + .bLength = USB_DT_ENDPOINT_SIZE, 563 + .bDescriptorType = USB_DT_ENDPOINT, 564 + 565 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 566 + .wMaxPacketSize = cpu_to_le16(512), 567 + }; 568 + 569 + static struct usb_descriptor_header *hs_usb9pfs_descs[] = { 570 + (struct usb_descriptor_header *)&usb9pfs_intf, 571 + (struct usb_descriptor_header *)&hs_usb9pfs_source_desc, 572 + (struct usb_descriptor_header *)&hs_usb9pfs_sink_desc, 573 + NULL, 574 + }; 575 + 576 + /* super speed support: */ 577 + 578 + static struct usb_endpoint_descriptor ss_usb9pfs_source_desc = { 579 + .bLength = USB_DT_ENDPOINT_SIZE, 580 + .bDescriptorType = USB_DT_ENDPOINT, 581 + 582 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 583 + .wMaxPacketSize = cpu_to_le16(1024), 584 + }; 585 + 586 + static struct usb_ss_ep_comp_descriptor ss_usb9pfs_source_comp_desc = { 587 + .bLength = USB_DT_SS_EP_COMP_SIZE, 588 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 589 + .bMaxBurst = 0, 590 + .bmAttributes = 0, 591 + .wBytesPerInterval = 0, 592 + }; 593 + 594 + static struct usb_endpoint_descriptor ss_usb9pfs_sink_desc = { 595 + .bLength = USB_DT_ENDPOINT_SIZE, 596 + .bDescriptorType = USB_DT_ENDPOINT, 597 + 598 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 599 + .wMaxPacketSize = cpu_to_le16(1024), 600 + }; 601 + 602 + static struct usb_ss_ep_comp_descriptor ss_usb9pfs_sink_comp_desc = { 603 + .bLength = USB_DT_SS_EP_COMP_SIZE, 604 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 605 + .bMaxBurst = 0, 606 + .bmAttributes = 0, 607 + .wBytesPerInterval = 0, 608 + }; 609 + 610 + static struct usb_descriptor_header *ss_usb9pfs_descs[] = { 611 + (struct usb_descriptor_header *)&usb9pfs_intf, 612 + (struct usb_descriptor_header *)&ss_usb9pfs_source_desc, 613 + (struct usb_descriptor_header *)&ss_usb9pfs_source_comp_desc, 614 + (struct usb_descriptor_header *)&ss_usb9pfs_sink_desc, 615 + (struct usb_descriptor_header *)&ss_usb9pfs_sink_comp_desc, 616 + NULL, 617 + }; 618 + 619 + /* function-specific strings: */ 620 + static struct usb_string strings_usb9pfs[] = { 621 + [0].s = "usb9pfs input to output", 622 + { } /* end of list */ 623 + }; 624 + 625 + static struct usb_gadget_strings stringtab_usb9pfs = { 626 + .language = 0x0409, /* en-us */ 627 + .strings = strings_usb9pfs, 628 + }; 629 + 630 + static struct usb_gadget_strings *usb9pfs_strings[] = { 631 + &stringtab_usb9pfs, 632 + NULL, 633 + }; 634 + 635 + /*-------------------------------------------------------------------------*/ 636 + 637 + static int usb9pfs_func_bind(struct usb_configuration *c, 638 + struct usb_function *f) 639 + { 640 + struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); 641 + struct f_usb9pfs_opts *opts; 642 + struct usb_composite_dev *cdev = c->cdev; 643 + int ret; 644 + int id; 645 + 646 + /* allocate interface ID(s) */ 647 + id = usb_interface_id(c, f); 648 + if (id < 0) 649 + return id; 650 + usb9pfs_intf.bInterfaceNumber = id; 651 + 652 + id = usb_string_id(cdev); 653 + if (id < 0) 654 + return id; 655 + strings_usb9pfs[0].id = id; 656 + usb9pfs_intf.iInterface = id; 657 + 658 + /* allocate endpoints */ 659 + usb9pfs->in_ep = usb_ep_autoconfig(cdev->gadget, 660 + &fs_usb9pfs_source_desc); 661 + if (!usb9pfs->in_ep) 662 + goto autoconf_fail; 663 + 664 + usb9pfs->out_ep = usb_ep_autoconfig(cdev->gadget, 665 + &fs_usb9pfs_sink_desc); 666 + if (!usb9pfs->out_ep) 667 + goto autoconf_fail; 668 + 669 + /* support high speed hardware */ 670 + hs_usb9pfs_source_desc.bEndpointAddress = 671 + fs_usb9pfs_source_desc.bEndpointAddress; 672 + hs_usb9pfs_sink_desc.bEndpointAddress = 673 + fs_usb9pfs_sink_desc.bEndpointAddress; 674 + 675 + /* support super speed hardware */ 676 + ss_usb9pfs_source_desc.bEndpointAddress = 677 + fs_usb9pfs_source_desc.bEndpointAddress; 678 + ss_usb9pfs_sink_desc.bEndpointAddress = 679 + fs_usb9pfs_sink_desc.bEndpointAddress; 680 + 681 + ret = usb_assign_descriptors(f, fs_usb9pfs_descs, hs_usb9pfs_descs, 682 + ss_usb9pfs_descs, ss_usb9pfs_descs); 683 + if (ret) 684 + return ret; 685 + 686 + opts = container_of(f->fi, struct f_usb9pfs_opts, func_inst); 687 + opts->dev->usb9pfs = usb9pfs; 688 + 689 + dev_dbg(&cdev->gadget->dev, "%s speed %s: IN/%s, OUT/%s\n", 690 + (gadget_is_superspeed(c->cdev->gadget) ? "super" : 691 + (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), 692 + f->name, usb9pfs->in_ep->name, usb9pfs->out_ep->name); 693 + 694 + return 0; 695 + 696 + autoconf_fail: 697 + ERROR(cdev, "%s: can't autoconfigure on %s\n", 698 + f->name, cdev->gadget->name); 699 + return -ENODEV; 700 + } 701 + 702 + static void usb9pfs_func_unbind(struct usb_configuration *c, 703 + struct usb_function *f) 704 + { 705 + struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); 706 + 707 + disable_usb9pfs(usb9pfs); 708 + } 709 + 710 + static void usb9pfs_free_func(struct usb_function *f) 711 + { 712 + struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); 713 + struct f_usb9pfs_opts *opts; 714 + 715 + kfree(usb9pfs); 716 + 717 + opts = container_of(f->fi, struct f_usb9pfs_opts, func_inst); 718 + 719 + mutex_lock(&opts->lock); 720 + opts->refcnt--; 721 + mutex_unlock(&opts->lock); 722 + 723 + usb_free_all_descriptors(f); 724 + } 725 + 726 + static int usb9pfs_set_alt(struct usb_function *f, 727 + unsigned int intf, unsigned int alt) 728 + { 729 + struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); 730 + struct usb_composite_dev *cdev = f->config->cdev; 731 + 732 + return enable_usb9pfs(cdev, usb9pfs); 733 + } 734 + 735 + static void usb9pfs_disable(struct usb_function *f) 736 + { 737 + struct f_usb9pfs *usb9pfs = func_to_usb9pfs(f); 738 + 739 + usb9pfs_clear_tx(usb9pfs); 740 + } 741 + 742 + static struct usb_function *usb9pfs_alloc(struct usb_function_instance *fi) 743 + { 744 + struct f_usb9pfs_opts *usb9pfs_opts; 745 + struct f_usb9pfs *usb9pfs; 746 + 747 + usb9pfs = kzalloc(sizeof(*usb9pfs), GFP_KERNEL); 748 + if (!usb9pfs) 749 + return ERR_PTR(-ENOMEM); 750 + 751 + spin_lock_init(&usb9pfs->lock); 752 + 753 + init_completion(&usb9pfs->send); 754 + init_completion(&usb9pfs->received); 755 + 756 + usb9pfs_opts = container_of(fi, struct f_usb9pfs_opts, func_inst); 757 + 758 + mutex_lock(&usb9pfs_opts->lock); 759 + usb9pfs_opts->refcnt++; 760 + mutex_unlock(&usb9pfs_opts->lock); 761 + 762 + usb9pfs->buflen = usb9pfs_opts->buflen; 763 + 764 + usb9pfs->function.name = "usb9pfs"; 765 + usb9pfs->function.bind = usb9pfs_func_bind; 766 + usb9pfs->function.unbind = usb9pfs_func_unbind; 767 + usb9pfs->function.set_alt = usb9pfs_set_alt; 768 + usb9pfs->function.disable = usb9pfs_disable; 769 + usb9pfs->function.strings = usb9pfs_strings; 770 + 771 + usb9pfs->function.free_func = usb9pfs_free_func; 772 + 773 + return &usb9pfs->function; 774 + } 775 + 776 + static inline struct f_usb9pfs_opts *to_f_usb9pfs_opts(struct config_item *item) 777 + { 778 + return container_of(to_config_group(item), struct f_usb9pfs_opts, 779 + func_inst.group); 780 + } 781 + 782 + static inline struct f_usb9pfs_opts *fi_to_f_usb9pfs_opts(struct usb_function_instance *fi) 783 + { 784 + return container_of(fi, struct f_usb9pfs_opts, func_inst); 785 + } 786 + 787 + static void usb9pfs_attr_release(struct config_item *item) 788 + { 789 + struct f_usb9pfs_opts *usb9pfs_opts = to_f_usb9pfs_opts(item); 790 + 791 + usb_put_function_instance(&usb9pfs_opts->func_inst); 792 + } 793 + 794 + static struct configfs_item_operations usb9pfs_item_ops = { 795 + .release = usb9pfs_attr_release, 796 + }; 797 + 798 + static ssize_t f_usb9pfs_opts_buflen_show(struct config_item *item, char *page) 799 + { 800 + struct f_usb9pfs_opts *opts = to_f_usb9pfs_opts(item); 801 + int ret; 802 + 803 + mutex_lock(&opts->lock); 804 + ret = sysfs_emit(page, "%d\n", opts->buflen); 805 + mutex_unlock(&opts->lock); 806 + 807 + return ret; 808 + } 809 + 810 + static ssize_t f_usb9pfs_opts_buflen_store(struct config_item *item, 811 + const char *page, size_t len) 812 + { 813 + struct f_usb9pfs_opts *opts = to_f_usb9pfs_opts(item); 814 + int ret; 815 + u32 num; 816 + 817 + guard(mutex)(&opts->lock); 818 + 819 + if (opts->refcnt) 820 + return -EBUSY; 821 + 822 + ret = kstrtou32(page, 0, &num); 823 + if (ret) 824 + return ret; 825 + 826 + opts->buflen = num; 827 + 828 + return len; 829 + } 830 + 831 + CONFIGFS_ATTR(f_usb9pfs_opts_, buflen); 832 + 833 + static struct configfs_attribute *usb9pfs_attrs[] = { 834 + &f_usb9pfs_opts_attr_buflen, 835 + NULL, 836 + }; 837 + 838 + static const struct config_item_type usb9pfs_func_type = { 839 + .ct_item_ops = &usb9pfs_item_ops, 840 + .ct_attrs = usb9pfs_attrs, 841 + .ct_owner = THIS_MODULE, 842 + }; 843 + 844 + static struct f_usb9pfs_dev *_usb9pfs_do_find_dev(const char *tag) 845 + { 846 + struct f_usb9pfs_dev *usb9pfs_dev; 847 + 848 + if (!tag) 849 + return NULL; 850 + 851 + list_for_each_entry(usb9pfs_dev, &usbg_instance_list, usb9pfs_instance) { 852 + if (strcmp(usb9pfs_dev->tag, tag) == 0) 853 + return usb9pfs_dev; 854 + } 855 + 856 + return NULL; 857 + } 858 + 859 + static int usb9pfs_tag_instance(struct f_usb9pfs_dev *dev, const char *tag) 860 + { 861 + struct f_usb9pfs_dev *existing; 862 + int ret = 0; 863 + 864 + guard(mutex)(&usb9pfs_lock); 865 + 866 + existing = _usb9pfs_do_find_dev(tag); 867 + if (!existing) 868 + strscpy(dev->tag, tag, ARRAY_SIZE(dev->tag)); 869 + else if (existing != dev) 870 + ret = -EBUSY; 871 + 872 + return ret; 873 + } 874 + 875 + static int usb9pfs_set_inst_tag(struct usb_function_instance *fi, const char *tag) 876 + { 877 + if (strlen(tag) >= sizeof_field(struct f_usb9pfs_dev, tag)) 878 + return -ENAMETOOLONG; 879 + return usb9pfs_tag_instance(fi_to_f_usb9pfs_opts(fi)->dev, tag); 880 + } 881 + 882 + static void usb9pfs_free_instance(struct usb_function_instance *fi) 883 + { 884 + struct f_usb9pfs_opts *usb9pfs_opts = 885 + container_of(fi, struct f_usb9pfs_opts, func_inst); 886 + struct f_usb9pfs_dev *dev = usb9pfs_opts->dev; 887 + 888 + mutex_lock(&usb9pfs_lock); 889 + list_del(&dev->usb9pfs_instance); 890 + mutex_unlock(&usb9pfs_lock); 891 + 892 + kfree(usb9pfs_opts); 893 + } 894 + 895 + static struct usb_function_instance *usb9pfs_alloc_instance(void) 896 + { 897 + struct f_usb9pfs_opts *usb9pfs_opts; 898 + struct f_usb9pfs_dev *dev; 899 + 900 + usb9pfs_opts = kzalloc(sizeof(*usb9pfs_opts), GFP_KERNEL); 901 + if (!usb9pfs_opts) 902 + return ERR_PTR(-ENOMEM); 903 + 904 + mutex_init(&usb9pfs_opts->lock); 905 + 906 + usb9pfs_opts->func_inst.set_inst_name = usb9pfs_set_inst_tag; 907 + usb9pfs_opts->func_inst.free_func_inst = usb9pfs_free_instance; 908 + 909 + usb9pfs_opts->buflen = DEFAULT_BUFLEN; 910 + 911 + dev = kzalloc(sizeof(*dev), GFP_KERNEL); 912 + if (IS_ERR(dev)) { 913 + kfree(usb9pfs_opts); 914 + return ERR_CAST(dev); 915 + } 916 + 917 + usb9pfs_opts->dev = dev; 918 + dev->opts = usb9pfs_opts; 919 + 920 + config_group_init_type_name(&usb9pfs_opts->func_inst.group, "", 921 + &usb9pfs_func_type); 922 + 923 + mutex_lock(&usb9pfs_lock); 924 + list_add_tail(&dev->usb9pfs_instance, &usbg_instance_list); 925 + mutex_unlock(&usb9pfs_lock); 926 + 927 + return &usb9pfs_opts->func_inst; 928 + } 929 + DECLARE_USB_FUNCTION(usb9pfs, usb9pfs_alloc_instance, usb9pfs_alloc); 930 + 931 + static int __init usb9pfs_modinit(void) 932 + { 933 + int ret; 934 + 935 + INIT_LIST_HEAD(&usbg_instance_list); 936 + 937 + ret = usb_function_register(&usb9pfsusb_func); 938 + if (!ret) 939 + v9fs_register_trans(&p9_usbg_trans); 940 + 941 + return ret; 942 + } 943 + 944 + static void __exit usb9pfs_modexit(void) 945 + { 946 + usb_function_unregister(&usb9pfsusb_func); 947 + v9fs_unregister_trans(&p9_usbg_trans); 948 + } 949 + 950 + module_init(usb9pfs_modinit); 951 + module_exit(usb9pfs_modexit); 952 + 953 + MODULE_ALIAS_9P("usbg"); 954 + MODULE_LICENSE("GPL"); 955 + MODULE_DESCRIPTION("USB gadget 9pfs transport"); 956 + MODULE_AUTHOR("Michael Grzeschik");
+243
tools/usb/p9_fwd.py
··· 1 + #!/usr/bin/env python3 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + import argparse 5 + import errno 6 + import logging 7 + import socket 8 + import struct 9 + import time 10 + 11 + import usb.core 12 + import usb.util 13 + 14 + 15 + def path_from_usb_dev(dev): 16 + """Takes a pyUSB device as argument and returns a string. 17 + The string is a Path representation of the position of the USB device on the USB bus tree. 18 + 19 + This path is used to find a USB device on the bus or all devices connected to a HUB. 20 + The path is made up of the number of the USB controller followed be the ports of the HUB tree.""" 21 + if dev.port_numbers: 22 + dev_path = ".".join(str(i) for i in dev.port_numbers) 23 + return f"{dev.bus}-{dev_path}" 24 + return "" 25 + 26 + 27 + HEXDUMP_FILTER = "".join(chr(x).isprintable() and chr(x) or "." for x in range(128)) + "." * 128 28 + 29 + 30 + class Forwarder: 31 + @staticmethod 32 + def _log_hexdump(data): 33 + if not logging.root.isEnabledFor(logging.TRACE): 34 + return 35 + L = 16 36 + for c in range(0, len(data), L): 37 + chars = data[c : c + L] 38 + dump = " ".join(f"{x:02x}" for x in chars) 39 + printable = "".join(HEXDUMP_FILTER[x] for x in chars) 40 + line = f"{c:08x} {dump:{L*3}s} |{printable:{L}s}|" 41 + logging.root.log(logging.TRACE, "%s", line) 42 + 43 + def __init__(self, server, vid, pid, path): 44 + self.stats = { 45 + "c2s packets": 0, 46 + "c2s bytes": 0, 47 + "s2c packets": 0, 48 + "s2c bytes": 0, 49 + } 50 + self.stats_logged = time.monotonic() 51 + 52 + def find_filter(dev): 53 + dev_path = path_from_usb_dev(dev) 54 + if path is not None: 55 + return dev_path == path 56 + return True 57 + 58 + dev = usb.core.find(idVendor=vid, idProduct=pid, custom_match=find_filter) 59 + if dev is None: 60 + raise ValueError("Device not found") 61 + 62 + logging.info(f"found device: {dev.bus}/{dev.address} located at {path_from_usb_dev(dev)}") 63 + 64 + # dev.set_configuration() is not necessary since g_multi has only one 65 + usb9pfs = None 66 + # g_multi adds 9pfs as last interface 67 + cfg = dev.get_active_configuration() 68 + for intf in cfg: 69 + # we have to detach the usb-storage driver from multi gadget since 70 + # stall option could be set, which will lead to spontaneous port 71 + # resets and our transfers will run dead 72 + if intf.bInterfaceClass == 0x08: 73 + if dev.is_kernel_driver_active(intf.bInterfaceNumber): 74 + dev.detach_kernel_driver(intf.bInterfaceNumber) 75 + 76 + if intf.bInterfaceClass == 0xFF and intf.bInterfaceSubClass == 0xFF and intf.bInterfaceProtocol == 0x09: 77 + usb9pfs = intf 78 + if usb9pfs is None: 79 + raise ValueError("Interface not found") 80 + 81 + logging.info(f"claiming interface:\n{usb9pfs}") 82 + usb.util.claim_interface(dev, usb9pfs.bInterfaceNumber) 83 + ep_out = usb.util.find_descriptor( 84 + usb9pfs, 85 + custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT, 86 + ) 87 + assert ep_out is not None 88 + ep_in = usb.util.find_descriptor( 89 + usb9pfs, 90 + custom_match=lambda e: usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN, 91 + ) 92 + assert ep_in is not None 93 + logging.info("interface claimed") 94 + 95 + self.ep_out = ep_out 96 + self.ep_in = ep_in 97 + self.dev = dev 98 + 99 + # create and connect socket 100 + self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 101 + self.s.connect(server) 102 + 103 + logging.info("connected to server") 104 + 105 + def c2s(self): 106 + """forward a request from the USB client to the TCP server""" 107 + data = None 108 + while data is None: 109 + try: 110 + logging.log(logging.TRACE, "c2s: reading") 111 + data = self.ep_in.read(self.ep_in.wMaxPacketSize) 112 + except usb.core.USBTimeoutError: 113 + logging.log(logging.TRACE, "c2s: reading timed out") 114 + continue 115 + except usb.core.USBError as e: 116 + if e.errno == errno.EIO: 117 + logging.debug("c2s: reading failed with %s, retrying", repr(e)) 118 + time.sleep(0.5) 119 + continue 120 + logging.error("c2s: reading failed with %s, aborting", repr(e)) 121 + raise 122 + size = struct.unpack("<I", data[:4])[0] 123 + while len(data) < size: 124 + data += self.ep_in.read(size - len(data)) 125 + logging.log(logging.TRACE, "c2s: writing") 126 + self._log_hexdump(data) 127 + self.s.send(data) 128 + logging.debug("c2s: forwarded %i bytes", size) 129 + self.stats["c2s packets"] += 1 130 + self.stats["c2s bytes"] += size 131 + 132 + def s2c(self): 133 + """forward a response from the TCP server to the USB client""" 134 + logging.log(logging.TRACE, "s2c: reading") 135 + data = self.s.recv(4) 136 + size = struct.unpack("<I", data[:4])[0] 137 + while len(data) < size: 138 + data += self.s.recv(size - len(data)) 139 + logging.log(logging.TRACE, "s2c: writing") 140 + self._log_hexdump(data) 141 + while data: 142 + written = self.ep_out.write(data) 143 + assert written > 0 144 + data = data[written:] 145 + if size % self.ep_out.wMaxPacketSize == 0: 146 + logging.log(logging.TRACE, "sending zero length packet") 147 + self.ep_out.write(b"") 148 + logging.debug("s2c: forwarded %i bytes", size) 149 + self.stats["s2c packets"] += 1 150 + self.stats["s2c bytes"] += size 151 + 152 + def log_stats(self): 153 + logging.info("statistics:") 154 + for k, v in self.stats.items(): 155 + logging.info(f" {k+':':14s} {v}") 156 + 157 + def log_stats_interval(self, interval=5): 158 + if (time.monotonic() - self.stats_logged) < interval: 159 + return 160 + 161 + self.log_stats() 162 + self.stats_logged = time.monotonic() 163 + 164 + 165 + def try_get_usb_str(dev, name): 166 + try: 167 + with open(f"/sys/bus/usb/devices/{dev.bus}-{dev.address}/{name}") as f: 168 + return f.read().strip() 169 + except FileNotFoundError: 170 + return None 171 + 172 + 173 + def list_usb(args): 174 + vid, pid = [int(x, 16) for x in args.id.split(":", 1)] 175 + 176 + print("Bus | Addr | Manufacturer | Product | ID | Path") 177 + print("--- | ---- | ---------------- | ---------------- | --------- | ----") 178 + for dev in usb.core.find(find_all=True, idVendor=vid, idProduct=pid): 179 + path = path_from_usb_dev(dev) or "" 180 + manufacturer = try_get_usb_str(dev, "manufacturer") or "unknown" 181 + product = try_get_usb_str(dev, "product") or "unknown" 182 + print( 183 + f"{dev.bus:3} | {dev.address:4} | {manufacturer:16} | {product:16} | {dev.idVendor:04x}:{dev.idProduct:04x} | {path:18}" 184 + ) 185 + 186 + 187 + def connect(args): 188 + vid, pid = [int(x, 16) for x in args.id.split(":", 1)] 189 + 190 + f = Forwarder(server=(args.server, args.port), vid=vid, pid=pid, path=args.path) 191 + 192 + try: 193 + while True: 194 + f.c2s() 195 + f.s2c() 196 + f.log_stats_interval() 197 + finally: 198 + f.log_stats() 199 + 200 + 201 + def main(): 202 + parser = argparse.ArgumentParser( 203 + description="Forward 9PFS requests from USB to TCP", 204 + ) 205 + 206 + parser.add_argument("--id", type=str, default="1d6b:0109", help="vid:pid of target device") 207 + parser.add_argument("--path", type=str, required=False, help="path of target device") 208 + parser.add_argument("-v", "--verbose", action="count", default=0) 209 + 210 + subparsers = parser.add_subparsers() 211 + subparsers.required = True 212 + subparsers.dest = "command" 213 + 214 + parser_list = subparsers.add_parser("list", help="List all connected 9p gadgets") 215 + parser_list.set_defaults(func=list_usb) 216 + 217 + parser_connect = subparsers.add_parser( 218 + "connect", help="Forward messages between the usb9pfs gadget and the 9p server" 219 + ) 220 + parser_connect.set_defaults(func=connect) 221 + connect_group = parser_connect.add_argument_group() 222 + connect_group.required = True 223 + parser_connect.add_argument("-s", "--server", type=str, default="127.0.0.1", help="server hostname") 224 + parser_connect.add_argument("-p", "--port", type=int, default=564, help="server port") 225 + 226 + args = parser.parse_args() 227 + 228 + logging.TRACE = logging.DEBUG - 5 229 + logging.addLevelName(logging.TRACE, "TRACE") 230 + 231 + if args.verbose >= 2: 232 + level = logging.TRACE 233 + elif args.verbose: 234 + level = logging.DEBUG 235 + else: 236 + level = logging.INFO 237 + logging.basicConfig(level=level, format="%(asctime)-15s %(levelname)-8s %(message)s") 238 + 239 + args.func(args) 240 + 241 + 242 + if __name__ == "__main__": 243 + main()