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.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB / Thunderbolt driver updates from Greg KH:
"Here is the USB and Thunderbolt driver updates for 6.14-rc1. Nothing
huge in here, just lots of new hardware support and updates for
existing drivers. Changes here are:

- big gadget f_tcm driver update

- other gadget driver updates and fixes

- thunderbolt driver updates for new hardware and capabilities and
lots more debugging functionality to handle it when things aren't
working well.

- xhci driver updates

- new USB-serial device updates

- typec driver updates, including a chrome platform driver (acked by
the subsystem maintainers)

- other small driver updates

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

* tag 'usb-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (123 commits)
usb: hcd: Bump local buffer size in rh_string()
Revert "usb: gadget: u_serial: Disable ep before setting port to null to fix the crash caused by port being null"
usb: typec: tcpci: Prevent Sink disconnection before vPpsShutdown in SPR PPS
usb: xhci: tegra: Fix OF boolean read warning
usb: host: xhci-plat: add support compatible ID PNP0D15
usb: typec: ucsi: Add a macro definition for UCSI v1.0
usb: dwc3: core: Defer the probe until USB power supply ready
usbip: Correct format specifier for seqnum from %d to %u
usbip: Fix seqnum sign extension issue in vhci_tx_urb
dt-bindings: usb: snps,dwc3: Split core description
usb: quirks: Add NO_LPM quirk for TOSHIBA TransMemory-Mx device
usb: dwc3: gadget: Reinitiate stream for all host NoStream behavior
USB: Use str_enable_disable-like helpers
USB: gadget: Use str_enable_disable-like helpers
USB: phy: Use str_enable_disable-like helpers
USB: typec: Use str_enable_disable-like helpers
USB: host: Use str_enable_disable-like helpers
USB: Replace own str_plural with common one
USB: serial: quatech2: fix null-ptr-deref in qt2_process_read_urb()
usb: phy: Remove API devm_usb_put_phy()
...

+3833 -1483
+7
Documentation/devicetree/bindings/connector/usb-connector.yaml
··· 293 293 PD negotiation till BC1.2 detection completes. 294 294 default: 0 295 295 296 + pd-revision: 297 + description: Specifies the maximum USB PD revision and version supported by 298 + the connector. This property is specified in the following order; 299 + <revision_major, revision_minor, version_major, version_minor>. 300 + $ref: /schemas/types.yaml#/definitions/uint8-array 301 + maxItems: 4 302 + 296 303 dependencies: 297 304 sink-vdos-v1: [ sink-vdos ] 298 305 sink-vdos: [ sink-vdos-v1 ]
+20 -20
Documentation/devicetree/bindings/usb/aspeed,usb-vhub.yaml
··· 113 113 - | 114 114 #include <dt-bindings/clock/aspeed-clock.h> 115 115 vhub: usb-vhub@1e6a0000 { 116 - compatible = "aspeed,ast2500-usb-vhub"; 117 - reg = <0x1e6a0000 0x300>; 118 - interrupts = <5>; 119 - clocks = <&syscon ASPEED_CLK_GATE_USBPORT1CLK>; 120 - aspeed,vhub-downstream-ports = <5>; 121 - aspeed,vhub-generic-endpoints = <15>; 122 - pinctrl-names = "default"; 123 - pinctrl-0 = <&pinctrl_usb2ad_default>; 116 + compatible = "aspeed,ast2500-usb-vhub"; 117 + reg = <0x1e6a0000 0x300>; 118 + interrupts = <5>; 119 + clocks = <&syscon ASPEED_CLK_GATE_USBPORT1CLK>; 120 + aspeed,vhub-downstream-ports = <5>; 121 + aspeed,vhub-generic-endpoints = <15>; 122 + pinctrl-names = "default"; 123 + pinctrl-0 = <&pinctrl_usb2ad_default>; 124 124 125 - vhub-vendor-id = <0x1d6b>; 126 - vhub-product-id = <0x0107>; 127 - vhub-device-revision = <0x0100>; 128 - vhub-strings { 129 - #address-cells = <1>; 130 - #size-cells = <0>; 125 + vhub-vendor-id = <0x1d6b>; 126 + vhub-product-id = <0x0107>; 127 + vhub-device-revision = <0x0100>; 128 + vhub-strings { 129 + #address-cells = <1>; 130 + #size-cells = <0>; 131 131 132 - string@409 { 133 - reg = <0x409>; 134 - manufacturer = "ASPEED"; 135 - product = "USB Virtual Hub"; 136 - serial-number = "0000"; 137 - }; 132 + string@409 { 133 + reg = <0x409>; 134 + manufacturer = "ASPEED"; 135 + product = "USB Virtual Hub"; 136 + serial-number = "0000"; 138 137 }; 138 + }; 139 139 };
+7 -7
Documentation/devicetree/bindings/usb/brcm,bdc.yaml
··· 41 41 42 42 examples: 43 43 - | 44 - usb@f0b02000 { 45 - compatible = "brcm,bdc-udc-v2"; 46 - reg = <0xf0b02000 0xfc4>; 47 - interrupts = <0x0 0x60 0x0>; 48 - phys = <&usbphy_0 0x0>; 49 - clocks = <&sw_usbd>; 50 - }; 44 + usb@f0b02000 { 45 + compatible = "brcm,bdc-udc-v2"; 46 + reg = <0xf0b02000 0xfc4>; 47 + interrupts = <0x0 0x60 0x0>; 48 + phys = <&usbphy_0 0x0>; 49 + clocks = <&sw_usbd>; 50 + };
+12 -12
Documentation/devicetree/bindings/usb/cypress,hx3.yaml
··· 56 56 57 57 /* 2.0 hub on port 1 */ 58 58 hub_2_0: hub@1 { 59 - compatible = "usb4b4,6504"; 60 - reg = <1>; 61 - peer-hub = <&hub_3_0>; 62 - reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 63 - vdd-supply = <&reg_1v2_usb>; 64 - vdd2-supply = <&reg_3v3_usb>; 59 + compatible = "usb4b4,6504"; 60 + reg = <1>; 61 + peer-hub = <&hub_3_0>; 62 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 63 + vdd-supply = <&reg_1v2_usb>; 64 + vdd2-supply = <&reg_3v3_usb>; 65 65 }; 66 66 67 67 /* 3.0 hub on port 2 */ 68 68 hub_3_0: hub@2 { 69 - compatible = "usb4b4,6506"; 70 - reg = <2>; 71 - peer-hub = <&hub_2_0>; 72 - reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 73 - vdd-supply = <&reg_1v2_usb>; 74 - vdd2-supply = <&reg_3v3_usb>; 69 + compatible = "usb4b4,6506"; 70 + reg = <2>; 71 + peer-hub = <&hub_2_0>; 72 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 73 + vdd-supply = <&reg_1v2_usb>; 74 + vdd2-supply = <&reg_3v3_usb>; 75 75 }; 76 76 };
+2 -2
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 192 192 193 193 examples: 194 194 - | 195 - usb@101c0000 { 195 + usb@101c0000 { 196 196 compatible = "rockchip,rk3066-usb", "snps,dwc2"; 197 197 reg = <0x10180000 0x40000>; 198 198 interrupts = <18>; ··· 200 200 clock-names = "otg"; 201 201 phys = <&usbphy>; 202 202 phy-names = "usb2-phy"; 203 - }; 203 + }; 204 204 205 205 ...
+10 -10
Documentation/devicetree/bindings/usb/fcs,fsa4480.yaml
··· 87 87 #size-cells = <0>; 88 88 89 89 typec-mux@42 { 90 - compatible = "fcs,fsa4480"; 91 - reg = <0x42>; 90 + compatible = "fcs,fsa4480"; 91 + reg = <0x42>; 92 92 93 - interrupts-extended = <&tlmm 2 IRQ_TYPE_LEVEL_LOW>; 93 + interrupts-extended = <&tlmm 2 IRQ_TYPE_LEVEL_LOW>; 94 94 95 - vcc-supply = <&vreg_bob>; 95 + vcc-supply = <&vreg_bob>; 96 96 97 - mode-switch; 98 - orientation-switch; 97 + mode-switch; 98 + orientation-switch; 99 99 100 - port { 101 - fsa4480_ept: endpoint { 102 - remote-endpoint = <&typec_controller>; 100 + port { 101 + fsa4480_ept: endpoint { 102 + remote-endpoint = <&typec_controller>; 103 + }; 103 104 }; 104 - }; 105 105 }; 106 106 }; 107 107 ...
+1
Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml
··· 20 20 items: 21 21 - enum: 22 22 - nxp,cbdtu02043 23 + - onnn,fsusb42 23 24 - onnn,fsusb43l10x 24 25 - pericom,pi3usb102 25 26 - ti,tmuxhs4212
+15 -15
Documentation/devicetree/bindings/usb/intel,keembay-dwc3.yaml
··· 58 58 #define KEEM_BAY_A53_AUX_USB_SUSPEND 59 59 60 60 usb { 61 - compatible = "intel,keembay-dwc3"; 62 - clocks = <&scmi_clk KEEM_BAY_A53_AUX_USB>, 63 - <&scmi_clk KEEM_BAY_A53_AUX_USB_REF>, 64 - <&scmi_clk KEEM_BAY_A53_AUX_USB_ALT_REF>, 65 - <&scmi_clk KEEM_BAY_A53_AUX_USB_SUSPEND>; 66 - clock-names = "async_master", "ref", "alt_ref", "suspend"; 67 - ranges; 68 - #address-cells = <1>; 69 - #size-cells = <1>; 61 + compatible = "intel,keembay-dwc3"; 62 + clocks = <&scmi_clk KEEM_BAY_A53_AUX_USB>, 63 + <&scmi_clk KEEM_BAY_A53_AUX_USB_REF>, 64 + <&scmi_clk KEEM_BAY_A53_AUX_USB_ALT_REF>, 65 + <&scmi_clk KEEM_BAY_A53_AUX_USB_SUSPEND>; 66 + clock-names = "async_master", "ref", "alt_ref", "suspend"; 67 + ranges; 68 + #address-cells = <1>; 69 + #size-cells = <1>; 70 70 71 - usb@34000000 { 72 - compatible = "snps,dwc3"; 73 - reg = <0x34000000 0x10000>; 74 - interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>; 75 - dr_mode = "peripheral"; 76 - }; 71 + usb@34000000 { 72 + compatible = "snps,dwc3"; 73 + reg = <0x34000000 0x10000>; 74 + interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>; 75 + dr_mode = "peripheral"; 76 + }; 77 77 };
+9 -9
Documentation/devicetree/bindings/usb/ite,it5205.yaml
··· 54 54 #size-cells = <0>; 55 55 56 56 typec-mux@48 { 57 - compatible = "ite,it5205"; 58 - reg = <0x48>; 57 + compatible = "ite,it5205"; 58 + reg = <0x48>; 59 59 60 - mode-switch; 61 - orientation-switch; 60 + mode-switch; 61 + orientation-switch; 62 62 63 - vcc-supply = <&mt6359_vibr_ldo_reg>; 63 + vcc-supply = <&mt6359_vibr_ldo_reg>; 64 64 65 - port { 66 - it5205_usbss_sbu: endpoint { 67 - remote-endpoint = <&typec_controller>; 65 + port { 66 + it5205_usbss_sbu: endpoint { 67 + remote-endpoint = <&typec_controller>; 68 + }; 68 69 }; 69 - }; 70 70 }; 71 71 }; 72 72 ...
+7 -2
Documentation/devicetree/bindings/usb/maxim,max33359.yaml
··· 13 13 14 14 properties: 15 15 compatible: 16 - enum: 17 - - maxim,max33359 16 + oneOf: 17 + - enum: 18 + - maxim,max33359 19 + - items: 20 + - const: maxim,max77759-tcpci 21 + - const: maxim,max33359 18 22 19 23 reg: 20 24 maxItems: 1 ··· 74 70 PDO_FIXED_DUAL_ROLE) 75 71 PDO_FIXED(9000, 2000, 0)>; 76 72 sink-bc12-completion-time-ms = <500>; 73 + pd-revision = /bits/ 8 <0x03 0x01 0x01 0x08>; 77 74 }; 78 75 }; 79 76 };
+14 -14
Documentation/devicetree/bindings/usb/maxim,max3420-udc.yaml
··· 50 50 51 51 examples: 52 52 - | 53 - #include <dt-bindings/gpio/gpio.h> 54 - #include <dt-bindings/interrupt-controller/irq.h> 55 - spi { 56 - #address-cells = <1>; 57 - #size-cells = <0>; 53 + #include <dt-bindings/gpio/gpio.h> 54 + #include <dt-bindings/interrupt-controller/irq.h> 55 + spi { 56 + #address-cells = <1>; 57 + #size-cells = <0>; 58 58 59 - udc@0 { 60 - compatible = "maxim,max3420-udc"; 61 - reg = <0>; 62 - interrupt-parent = <&gpio>; 63 - interrupts = <0 IRQ_TYPE_EDGE_FALLING>, <10 IRQ_TYPE_EDGE_BOTH>; 64 - interrupt-names = "udc", "vbus"; 65 - spi-max-frequency = <12500000>; 66 - }; 67 - }; 59 + udc@0 { 60 + compatible = "maxim,max3420-udc"; 61 + reg = <0>; 62 + interrupt-parent = <&gpio>; 63 + interrupts = <0 IRQ_TYPE_EDGE_FALLING>, <10 IRQ_TYPE_EDGE_BOTH>; 64 + interrupt-names = "udc", "vbus"; 65 + spi-max-frequency = <12500000>; 66 + }; 67 + };
+2 -2
Documentation/devicetree/bindings/usb/nvidia,tegra210-xusb.yaml
··· 189 189 #size-cells = <0>; 190 190 191 191 ethernet@1 { 192 - compatible = "usb955,9ff"; 193 - reg = <1>; 192 + compatible = "usb955,9ff"; 193 + reg = <1>; 194 194 }; 195 195 };
+5
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml
··· 27 27 - qcom,msm8998-dwc3 28 28 - qcom,qcm2290-dwc3 29 29 - qcom,qcs404-dwc3 30 + - qcom,qcs615-dwc3 30 31 - qcom,qcs8300-dwc3 31 32 - qcom,qdu1000-dwc3 32 33 - qcom,sa8775p-dwc3 ··· 343 342 contains: 344 343 enum: 345 344 - qcom,qcm2290-dwc3 345 + - qcom,qcs615-dwc3 346 346 - qcom,sar2130p-dwc3 347 347 - qcom,sc8180x-dwc3 348 348 - qcom,sc8180x-dwc3-mp ··· 456 454 then: 457 455 properties: 458 456 interrupts: 457 + minItems: 3 459 458 maxItems: 4 460 459 interrupt-names: 460 + minItems: 3 461 461 items: 462 462 - const: pwr_event 463 463 - const: dp_hs_phy_irq ··· 474 470 - qcom,ipq4019-dwc3 475 471 - qcom,ipq8064-dwc3 476 472 - qcom,msm8994-dwc3 473 + - qcom,qcs615-dwc3 477 474 - qcom,qcs8300-dwc3 478 475 - qcom,qdu1000-dwc3 479 476 - qcom,sa8775p-dwc3
+18 -18
Documentation/devicetree/bindings/usb/renesas,rzv2m-usb3drd.yaml
··· 104 104 #size-cells = <1>; 105 105 106 106 usb3host: usb@85060000 { 107 - compatible = "renesas,r9a09g011-xhci", 108 - "renesas,rzv2m-xhci"; 109 - reg = <0x85060000 0x2000>; 110 - interrupts = <GIC_SPI 245 IRQ_TYPE_LEVEL_HIGH>; 111 - clocks = <&cpg CPG_MOD R9A09G011_USB_ACLK_H>, 112 - <&cpg CPG_MOD R9A09G011_USB_PCLK>; 113 - clock-names = "axi", "reg"; 114 - power-domains = <&cpg>; 115 - resets = <&cpg R9A09G011_USB_ARESETN_H>; 107 + compatible = "renesas,r9a09g011-xhci", 108 + "renesas,rzv2m-xhci"; 109 + reg = <0x85060000 0x2000>; 110 + interrupts = <GIC_SPI 245 IRQ_TYPE_LEVEL_HIGH>; 111 + clocks = <&cpg CPG_MOD R9A09G011_USB_ACLK_H>, 112 + <&cpg CPG_MOD R9A09G011_USB_PCLK>; 113 + clock-names = "axi", "reg"; 114 + power-domains = <&cpg>; 115 + resets = <&cpg R9A09G011_USB_ARESETN_H>; 116 116 }; 117 117 118 118 usb3peri: usb3peri@85070000 { 119 - compatible = "renesas,r9a09g011-usb3-peri", 120 - "renesas,rzv2m-usb3-peri"; 121 - reg = <0x85070000 0x400>; 122 - interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>; 123 - clocks = <&cpg CPG_MOD R9A09G011_USB_ACLK_P>, 124 - <&cpg CPG_MOD R9A09G011_USB_PCLK>; 125 - clock-names = "axi", "reg"; 126 - power-domains = <&cpg>; 127 - resets = <&cpg R9A09G011_USB_ARESETN_P>; 119 + compatible = "renesas,r9a09g011-usb3-peri", 120 + "renesas,rzv2m-usb3-peri"; 121 + reg = <0x85070000 0x400>; 122 + interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>; 123 + clocks = <&cpg CPG_MOD R9A09G011_USB_ACLK_P>, 124 + <&cpg CPG_MOD R9A09G011_USB_PCLK>; 125 + clock-names = "axi", "reg"; 126 + power-domains = <&cpg>; 127 + resets = <&cpg R9A09G011_USB_ARESETN_P>; 128 128 }; 129 129 };
+12 -12
Documentation/devicetree/bindings/usb/renesas,usb3-peri.yaml
··· 132 132 usb-role-switch; 133 133 134 134 ports { 135 - #address-cells = <1>; 136 - #size-cells = <0>; 137 - port@0 { 138 - reg = <0>; 139 - usb3_hs_ep: endpoint { 140 - remote-endpoint = <&hs_ep>; 141 - }; 135 + #address-cells = <1>; 136 + #size-cells = <0>; 137 + port@0 { 138 + reg = <0>; 139 + usb3_hs_ep: endpoint { 140 + remote-endpoint = <&hs_ep>; 142 141 }; 143 - port@1 { 144 - reg = <1>; 145 - usb3_role_switch: endpoint { 146 - remote-endpoint = <&hd3ss3220_out_ep>; 147 - }; 142 + }; 143 + port@1 { 144 + reg = <1>; 145 + usb3_role_switch: endpoint { 146 + remote-endpoint = <&hd3ss3220_out_ep>; 148 147 }; 148 + }; 149 149 }; 150 150 };
+2
Documentation/devicetree/bindings/usb/renesas,usbhs.yaml
··· 26 26 - renesas,usbhs-r9a07g043 # RZ/G2UL and RZ/Five 27 27 - renesas,usbhs-r9a07g044 # RZ/G2{L,LC} 28 28 - renesas,usbhs-r9a07g054 # RZ/V2L 29 + - renesas,usbhs-r9a08g045 # RZ/G3S 29 30 - const: renesas,rzg2l-usbhs 30 31 31 32 - items: ··· 131 130 - renesas,usbhs-r9a07g043 132 131 - renesas,usbhs-r9a07g044 133 132 - renesas,usbhs-r9a07g054 133 + - renesas,usbhs-r9a08g045 134 134 then: 135 135 properties: 136 136 interrupts:
+415
Documentation/devicetree/bindings/usb/snps,dwc3-common.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/snps,dwc3-common.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Synopsys DesignWare USB3 Controller common properties 8 + 9 + maintainers: 10 + - Felipe Balbi <balbi@kernel.org> 11 + 12 + description: 13 + Defines the properties of the DWC3 core as being embedded in either an 14 + vendor-specific implementation or as a standalone component. 15 + 16 + allOf: 17 + - $ref: usb-drd.yaml# 18 + - if: 19 + properties: 20 + dr_mode: 21 + const: peripheral 22 + 23 + required: 24 + - dr_mode 25 + then: 26 + $ref: usb.yaml# 27 + else: 28 + $ref: usb-xhci.yaml# 29 + 30 + properties: 31 + extcon: 32 + maxItems: 1 33 + deprecated: true 34 + 35 + usb-phy: 36 + minItems: 1 37 + items: 38 + - description: USB2/HS PHY 39 + - description: USB3/SS PHY 40 + 41 + phys: 42 + minItems: 1 43 + maxItems: 19 44 + 45 + phy-names: 46 + minItems: 1 47 + maxItems: 19 48 + oneOf: 49 + - items: 50 + enum: [ usb2-phy, usb3-phy ] 51 + - items: 52 + pattern: "^usb(2-([0-9]|1[0-4])|3-[0-3])$" 53 + 54 + snps,usb2-lpm-disable: 55 + description: Indicate if we don't want to enable USB2 HW LPM for host 56 + mode. 57 + type: boolean 58 + 59 + snps,usb3_lpm_capable: 60 + description: Determines if platform is USB3 LPM capable 61 + type: boolean 62 + 63 + snps,usb2-gadget-lpm-disable: 64 + description: Indicate if we don't want to enable USB2 HW LPM for gadget 65 + mode. 66 + type: boolean 67 + 68 + snps,dis-start-transfer-quirk: 69 + description: 70 + When set, disable isoc START TRANSFER command failure SW work-around 71 + for DWC_usb31 version 1.70a-ea06 and prior. 72 + type: boolean 73 + 74 + snps,disable_scramble_quirk: 75 + description: 76 + True when SW should disable data scrambling. Only really useful for FPGA 77 + builds. 78 + type: boolean 79 + 80 + snps,has-lpm-erratum: 81 + description: True when DWC3 was configured with LPM Erratum enabled 82 + type: boolean 83 + 84 + snps,lpm-nyet-threshold: 85 + description: LPM NYET threshold 86 + $ref: /schemas/types.yaml#/definitions/uint8 87 + 88 + snps,u2exit_lfps_quirk: 89 + description: Set if we want to enable u2exit lfps quirk 90 + type: boolean 91 + 92 + snps,u2ss_inp3_quirk: 93 + description: Set if we enable P3 OK for U2/SS Inactive quirk 94 + type: boolean 95 + 96 + snps,req_p1p2p3_quirk: 97 + description: 98 + When set, the core will always request for P1/P2/P3 transition sequence. 99 + type: boolean 100 + 101 + snps,del_p1p2p3_quirk: 102 + description: 103 + When set core will delay P1/P2/P3 until a certain amount of 8B10B errors 104 + occur. 105 + type: boolean 106 + 107 + snps,del_phy_power_chg_quirk: 108 + description: When set core will delay PHY power change from P0 to P1/P2/P3. 109 + type: boolean 110 + 111 + snps,lfps_filter_quirk: 112 + description: When set core will filter LFPS reception. 113 + type: boolean 114 + 115 + snps,rx_detect_poll_quirk: 116 + description: 117 + when set core will disable a 400us delay to start Polling LFPS after 118 + RX.Detect. 119 + type: boolean 120 + 121 + snps,tx_de_emphasis_quirk: 122 + description: When set core will set Tx de-emphasis value 123 + type: boolean 124 + 125 + snps,tx_de_emphasis: 126 + description: 127 + The value driven to the PHY is controlled by the LTSSM during USB3 128 + Compliance mode. 129 + $ref: /schemas/types.yaml#/definitions/uint8 130 + enum: 131 + - 0 # -6dB de-emphasis 132 + - 1 # -3.5dB de-emphasis 133 + - 2 # No de-emphasis 134 + 135 + snps,dis_u3_susphy_quirk: 136 + description: When set core will disable USB3 suspend phy 137 + type: boolean 138 + 139 + snps,dis_u2_susphy_quirk: 140 + description: When set core will disable USB2 suspend phy 141 + type: boolean 142 + 143 + snps,dis_enblslpm_quirk: 144 + description: 145 + When set clears the enblslpm in GUSB2PHYCFG, disabling the suspend signal 146 + to the PHY. 147 + type: boolean 148 + 149 + snps,dis-u1-entry-quirk: 150 + description: Set if link entering into U1 needs to be disabled 151 + type: boolean 152 + 153 + snps,dis-u2-entry-quirk: 154 + description: Set if link entering into U2 needs to be disabled 155 + type: boolean 156 + 157 + snps,dis_rxdet_inp3_quirk: 158 + description: 159 + When set core will disable receiver detection in PHY P3 power state. 160 + type: boolean 161 + 162 + snps,dis-u2-freeclk-exists-quirk: 163 + description: 164 + When set, clear the u2_freeclk_exists in GUSB2PHYCFG, specify that USB2 165 + PHY doesn't provide a free-running PHY clock. 166 + type: boolean 167 + 168 + snps,dis-del-phy-power-chg-quirk: 169 + description: 170 + When set core will change PHY power from P0 to P1/P2/P3 without delay. 171 + type: boolean 172 + 173 + snps,dis-tx-ipgap-linecheck-quirk: 174 + description: When set, disable u2mac linestate check during HS transmit 175 + type: boolean 176 + 177 + snps,parkmode-disable-ss-quirk: 178 + description: 179 + When set, all SuperSpeed bus instances in park mode are disabled. 180 + type: boolean 181 + 182 + snps,parkmode-disable-hs-quirk: 183 + description: 184 + When set, all HighSpeed bus instances in park mode are disabled. 185 + type: boolean 186 + 187 + snps,dis_metastability_quirk: 188 + description: 189 + When set, disable metastability workaround. CAUTION! Use only if you are 190 + absolutely sure of it. 191 + type: boolean 192 + 193 + snps,dis-split-quirk: 194 + description: 195 + When set, change the way URBs are handled by the driver. Needed to 196 + avoid -EPROTO errors with usbhid on some devices (Hikey 970). 197 + type: boolean 198 + 199 + snps,gfladj-refclk-lpm-sel-quirk: 200 + description: 201 + When set, run the SOF/ITP counter based on ref_clk. 202 + type: boolean 203 + 204 + snps,resume-hs-terminations: 205 + description: 206 + Fix the issue of HS terminations CRC error on resume by enabling this 207 + quirk. When set, all the termsel, xcvrsel, opmode becomes 0 during end 208 + of resume. This option is to support certain legacy ULPI PHYs. 209 + type: boolean 210 + 211 + snps,ulpi-ext-vbus-drv: 212 + description: 213 + Some ULPI USB PHY does not support internal VBUS supply, and driving 214 + the CPEN pin, requires the configuration of the ulpi DRVVBUSEXTERNAL 215 + bit. When set, the xhci host will configure the USB2 PHY drives VBUS 216 + with an external supply. 217 + type: boolean 218 + 219 + snps,is-utmi-l1-suspend: 220 + description: 221 + True when DWC3 asserts output signal utmi_l1_suspend_n, false when 222 + asserts utmi_sleep_n. 223 + type: boolean 224 + 225 + snps,hird-threshold: 226 + description: HIRD threshold 227 + $ref: /schemas/types.yaml#/definitions/uint8 228 + 229 + snps,hsphy_interface: 230 + description: 231 + High-Speed PHY interface selection between UTMI+ and ULPI when the 232 + DWC_USB3_HSPHY_INTERFACE has value 3. 233 + $ref: /schemas/types.yaml#/definitions/string 234 + enum: [utmi, ulpi] 235 + 236 + snps,quirk-frame-length-adjustment: 237 + description: 238 + Value for GFLADJ_30MHZ field of GFLADJ register for post-silicon frame 239 + length adjustment when the fladj_30mhz_sdbnd signal is invalid or 240 + incorrect. 241 + $ref: /schemas/types.yaml#/definitions/uint32 242 + minimum: 0 243 + maximum: 0x3f 244 + 245 + snps,ref-clock-period-ns: 246 + description: 247 + Value for REFCLKPER field of GUCTL register for reference clock period in 248 + nanoseconds, when the hardware set default does not match the actual 249 + clock. 250 + 251 + This binding is deprecated. Instead, provide an appropriate reference clock. 252 + minimum: 8 253 + maximum: 62 254 + deprecated: true 255 + 256 + snps,rx-thr-num-pkt: 257 + description: 258 + USB RX packet threshold count. In host mode, this field specifies 259 + the space that must be available in the RX FIFO before the core can 260 + start the corresponding USB RX transaction (burst). 261 + In device mode, this field specifies the space that must be 262 + available in the RX FIFO before the core can send ERDY for a 263 + flow-controlled endpoint. It is only used for SuperSpeed. 264 + The valid values for this field are from 1 to 15. (DWC3 SuperSpeed 265 + USB 3.0 Controller Databook) 266 + $ref: /schemas/types.yaml#/definitions/uint8 267 + minimum: 1 268 + maximum: 15 269 + 270 + snps,rx-max-burst: 271 + description: 272 + Max USB RX burst size. In host mode, this field specifies the 273 + Maximum Bulk IN burst the DWC_usb3 core can perform. When the system 274 + bus is slower than the USB, RX FIFO can overrun during a long burst. 275 + You can program a smaller value to this field to limit the RX burst 276 + size that the core can perform. It only applies to SS Bulk, 277 + Isochronous, and Interrupt IN endpoints in the host mode. 278 + In device mode, this field specifies the NUMP value that is sent in 279 + ERDY for an OUT endpoint. 280 + The valid values for this field are from 1 to 16. (DWC3 SuperSpeed 281 + USB 3.0 Controller Databook) 282 + $ref: /schemas/types.yaml#/definitions/uint8 283 + minimum: 1 284 + maximum: 16 285 + 286 + snps,tx-thr-num-pkt: 287 + description: 288 + USB TX packet threshold count. This field specifies the number of 289 + packets that must be in the TXFIFO before the core can start 290 + transmission for the corresponding USB transaction (burst). 291 + This count is valid in both host and device modes. It is only used 292 + for SuperSpeed operation. 293 + Valid values are from 1 to 15. (DWC3 SuperSpeed USB 3.0 Controller 294 + Databook) 295 + $ref: /schemas/types.yaml#/definitions/uint8 296 + minimum: 1 297 + maximum: 15 298 + 299 + snps,tx-max-burst: 300 + description: 301 + Max USB TX burst size. When the system bus is slower than the USB, 302 + TX FIFO can underrun during a long burst. Program a smaller value 303 + to this field to limit the TX burst size that the core can execute. 304 + In Host mode, it only applies to SS Bulk, Isochronous, and Interrupt 305 + OUT endpoints. This value is not used in device mode. 306 + Valid values are from 1 to 16. (DWC3 SuperSpeed USB 3.0 Controller 307 + Databook) 308 + $ref: /schemas/types.yaml#/definitions/uint8 309 + minimum: 1 310 + maximum: 16 311 + 312 + snps,rx-thr-num-pkt-prd: 313 + description: 314 + Periodic ESS RX packet threshold count (host mode only). Set this and 315 + snps,rx-max-burst-prd to a valid, non-zero value 1-16 (DWC_usb31 316 + programming guide section 1.2.4) to enable periodic ESS RX threshold. 317 + $ref: /schemas/types.yaml#/definitions/uint8 318 + minimum: 1 319 + maximum: 16 320 + 321 + snps,rx-max-burst-prd: 322 + description: 323 + Max periodic ESS RX burst size (host mode only). Set this and 324 + snps,rx-thr-num-pkt-prd to a valid, non-zero value 1-16 (DWC_usb31 325 + programming guide section 1.2.4) to enable periodic ESS RX threshold. 326 + $ref: /schemas/types.yaml#/definitions/uint8 327 + minimum: 1 328 + maximum: 16 329 + 330 + snps,tx-thr-num-pkt-prd: 331 + description: 332 + Periodic ESS TX packet threshold count (host mode only). Set this and 333 + snps,tx-max-burst-prd to a valid, non-zero value 1-16 (DWC_usb31 334 + programming guide section 1.2.3) to enable periodic ESS TX threshold. 335 + $ref: /schemas/types.yaml#/definitions/uint8 336 + minimum: 1 337 + maximum: 16 338 + 339 + snps,tx-max-burst-prd: 340 + description: 341 + Max periodic ESS TX burst size (host mode only). Set this and 342 + snps,tx-thr-num-pkt-prd to a valid, non-zero value 1-16 (DWC_usb31 343 + programming guide section 1.2.3) to enable periodic ESS TX threshold. 344 + $ref: /schemas/types.yaml#/definitions/uint8 345 + minimum: 1 346 + maximum: 16 347 + 348 + tx-fifo-resize: 349 + description: Determines if the TX fifos can be dynamically resized depending 350 + on the number of IN endpoints used and if bursting is supported. This 351 + may help improve bandwidth on platforms with higher system latencies, as 352 + increased fifo space allows for the controller to prefetch data into its 353 + internal memory. 354 + type: boolean 355 + 356 + tx-fifo-max-num: 357 + description: Specifies the max number of packets the txfifo resizing logic 358 + can account for when higher endpoint bursting is used. (bMaxBurst > 6) The 359 + higher the number, the more fifo space the txfifo resizing logic will 360 + allocate for that endpoint. 361 + $ref: /schemas/types.yaml#/definitions/uint8 362 + minimum: 3 363 + 364 + snps,incr-burst-type-adjustment: 365 + description: 366 + Value for INCR burst type of GSBUSCFG0 register, undefined length INCR 367 + burst type enable and INCRx type. A single value means INCRX burst mode 368 + enabled. If more than one value specified, undefined length INCR burst 369 + type will be enabled with burst lengths utilized up to the maximum 370 + of the values passed in this property. 371 + $ref: /schemas/types.yaml#/definitions/uint32-array 372 + minItems: 1 373 + maxItems: 8 374 + uniqueItems: true 375 + items: 376 + enum: [1, 4, 8, 16, 32, 64, 128, 256] 377 + 378 + num-hc-interrupters: 379 + maximum: 8 380 + default: 1 381 + 382 + port: 383 + $ref: /schemas/graph.yaml#/properties/port 384 + description: 385 + This port is used with the 'usb-role-switch' property to connect the 386 + dwc3 to type C connector. 387 + 388 + ports: 389 + $ref: /schemas/graph.yaml#/properties/ports 390 + description: 391 + Those ports should be used with any connector to the data bus of this 392 + controller using the OF graph bindings specified if the "usb-role-switch" 393 + property is used. 394 + 395 + properties: 396 + port@0: 397 + $ref: /schemas/graph.yaml#/properties/port 398 + description: High Speed (HS) data bus. 399 + 400 + port@1: 401 + $ref: /schemas/graph.yaml#/properties/port 402 + description: Super Speed (SS) data bus. 403 + 404 + wakeup-source: 405 + $ref: /schemas/types.yaml#/definitions/flag 406 + description: 407 + Enable USB remote wakeup. 408 + 409 + required: 410 + - compatible 411 + - reg 412 + 413 + additionalProperties: true 414 + ... 415 +
+1 -390
Documentation/devicetree/bindings/usb/snps,dwc3.yaml
··· 15 15 compatible string. 16 16 17 17 allOf: 18 - - $ref: usb-drd.yaml# 19 - - if: 20 - properties: 21 - dr_mode: 22 - const: peripheral 23 - 24 - required: 25 - - dr_mode 26 - then: 27 - $ref: usb.yaml# 28 - else: 29 - $ref: usb-xhci.yaml# 18 + - $ref: snps,dwc3-common.yaml# 30 19 31 20 properties: 32 21 compatible: ··· 59 70 60 71 dma-coherent: true 61 72 62 - extcon: 63 - maxItems: 1 64 - deprecated: true 65 - 66 73 iommus: 67 74 maxItems: 1 68 - 69 - usb-phy: 70 - minItems: 1 71 - items: 72 - - description: USB2/HS PHY 73 - - description: USB3/SS PHY 74 - 75 - phys: 76 - minItems: 1 77 - maxItems: 19 78 - 79 - phy-names: 80 - minItems: 1 81 - maxItems: 19 82 - oneOf: 83 - - items: 84 - enum: [ usb2-phy, usb3-phy ] 85 - - items: 86 - pattern: "^usb(2-([0-9]|1[0-4])|3-[0-3])$" 87 75 88 76 power-domains: 89 77 description: ··· 74 108 75 109 resets: 76 110 minItems: 1 77 - 78 - snps,usb2-lpm-disable: 79 - description: Indicate if we don't want to enable USB2 HW LPM for host 80 - mode. 81 - type: boolean 82 - 83 - snps,usb3_lpm_capable: 84 - description: Determines if platform is USB3 LPM capable 85 - type: boolean 86 - 87 - snps,usb2-gadget-lpm-disable: 88 - description: Indicate if we don't want to enable USB2 HW LPM for gadget 89 - mode. 90 - type: boolean 91 - 92 - snps,dis-start-transfer-quirk: 93 - description: 94 - When set, disable isoc START TRANSFER command failure SW work-around 95 - for DWC_usb31 version 1.70a-ea06 and prior. 96 - type: boolean 97 - 98 - snps,disable_scramble_quirk: 99 - description: 100 - True when SW should disable data scrambling. Only really useful for FPGA 101 - builds. 102 - type: boolean 103 - 104 - snps,has-lpm-erratum: 105 - description: True when DWC3 was configured with LPM Erratum enabled 106 - type: boolean 107 - 108 - snps,lpm-nyet-threshold: 109 - description: LPM NYET threshold 110 - $ref: /schemas/types.yaml#/definitions/uint8 111 - 112 - snps,u2exit_lfps_quirk: 113 - description: Set if we want to enable u2exit lfps quirk 114 - type: boolean 115 - 116 - snps,u2ss_inp3_quirk: 117 - description: Set if we enable P3 OK for U2/SS Inactive quirk 118 - type: boolean 119 - 120 - snps,req_p1p2p3_quirk: 121 - description: 122 - When set, the core will always request for P1/P2/P3 transition sequence. 123 - type: boolean 124 - 125 - snps,del_p1p2p3_quirk: 126 - description: 127 - When set core will delay P1/P2/P3 until a certain amount of 8B10B errors 128 - occur. 129 - type: boolean 130 - 131 - snps,del_phy_power_chg_quirk: 132 - description: When set core will delay PHY power change from P0 to P1/P2/P3. 133 - type: boolean 134 - 135 - snps,lfps_filter_quirk: 136 - description: When set core will filter LFPS reception. 137 - type: boolean 138 - 139 - snps,rx_detect_poll_quirk: 140 - description: 141 - when set core will disable a 400us delay to start Polling LFPS after 142 - RX.Detect. 143 - type: boolean 144 - 145 - snps,tx_de_emphasis_quirk: 146 - description: When set core will set Tx de-emphasis value 147 - type: boolean 148 - 149 - snps,tx_de_emphasis: 150 - description: 151 - The value driven to the PHY is controlled by the LTSSM during USB3 152 - Compliance mode. 153 - $ref: /schemas/types.yaml#/definitions/uint8 154 - enum: 155 - - 0 # -6dB de-emphasis 156 - - 1 # -3.5dB de-emphasis 157 - - 2 # No de-emphasis 158 - 159 - snps,dis_u3_susphy_quirk: 160 - description: When set core will disable USB3 suspend phy 161 - type: boolean 162 - 163 - snps,dis_u2_susphy_quirk: 164 - description: When set core will disable USB2 suspend phy 165 - type: boolean 166 - 167 - snps,dis_enblslpm_quirk: 168 - description: 169 - When set clears the enblslpm in GUSB2PHYCFG, disabling the suspend signal 170 - to the PHY. 171 - type: boolean 172 - 173 - snps,dis-u1-entry-quirk: 174 - description: Set if link entering into U1 needs to be disabled 175 - type: boolean 176 - 177 - snps,dis-u2-entry-quirk: 178 - description: Set if link entering into U2 needs to be disabled 179 - type: boolean 180 - 181 - snps,dis_rxdet_inp3_quirk: 182 - description: 183 - When set core will disable receiver detection in PHY P3 power state. 184 - type: boolean 185 - 186 - snps,dis-u2-freeclk-exists-quirk: 187 - description: 188 - When set, clear the u2_freeclk_exists in GUSB2PHYCFG, specify that USB2 189 - PHY doesn't provide a free-running PHY clock. 190 - type: boolean 191 - 192 - snps,dis-del-phy-power-chg-quirk: 193 - description: 194 - When set core will change PHY power from P0 to P1/P2/P3 without delay. 195 - type: boolean 196 - 197 - snps,dis-tx-ipgap-linecheck-quirk: 198 - description: When set, disable u2mac linestate check during HS transmit 199 - type: boolean 200 - 201 - snps,parkmode-disable-ss-quirk: 202 - description: 203 - When set, all SuperSpeed bus instances in park mode are disabled. 204 - type: boolean 205 - 206 - snps,parkmode-disable-hs-quirk: 207 - description: 208 - When set, all HighSpeed bus instances in park mode are disabled. 209 - type: boolean 210 - 211 - snps,dis_metastability_quirk: 212 - description: 213 - When set, disable metastability workaround. CAUTION! Use only if you are 214 - absolutely sure of it. 215 - type: boolean 216 - 217 - snps,dis-split-quirk: 218 - description: 219 - When set, change the way URBs are handled by the driver. Needed to 220 - avoid -EPROTO errors with usbhid on some devices (Hikey 970). 221 - type: boolean 222 - 223 - snps,gfladj-refclk-lpm-sel-quirk: 224 - description: 225 - When set, run the SOF/ITP counter based on ref_clk. 226 - type: boolean 227 - 228 - snps,resume-hs-terminations: 229 - description: 230 - Fix the issue of HS terminations CRC error on resume by enabling this 231 - quirk. When set, all the termsel, xcvrsel, opmode becomes 0 during end 232 - of resume. This option is to support certain legacy ULPI PHYs. 233 - type: boolean 234 - 235 - snps,ulpi-ext-vbus-drv: 236 - description: 237 - Some ULPI USB PHY does not support internal VBUS supply, and driving 238 - the CPEN pin, requires the configuration of the ulpi DRVVBUSEXTERNAL 239 - bit. When set, the xhci host will configure the USB2 PHY drives VBUS 240 - with an external supply. 241 - type: boolean 242 - 243 - snps,is-utmi-l1-suspend: 244 - description: 245 - True when DWC3 asserts output signal utmi_l1_suspend_n, false when 246 - asserts utmi_sleep_n. 247 - type: boolean 248 - 249 - snps,hird-threshold: 250 - description: HIRD threshold 251 - $ref: /schemas/types.yaml#/definitions/uint8 252 - 253 - snps,hsphy_interface: 254 - description: 255 - High-Speed PHY interface selection between UTMI+ and ULPI when the 256 - DWC_USB3_HSPHY_INTERFACE has value 3. 257 - $ref: /schemas/types.yaml#/definitions/string 258 - enum: [utmi, ulpi] 259 - 260 - snps,quirk-frame-length-adjustment: 261 - description: 262 - Value for GFLADJ_30MHZ field of GFLADJ register for post-silicon frame 263 - length adjustment when the fladj_30mhz_sdbnd signal is invalid or 264 - incorrect. 265 - $ref: /schemas/types.yaml#/definitions/uint32 266 - minimum: 0 267 - maximum: 0x3f 268 - 269 - snps,ref-clock-period-ns: 270 - description: 271 - Value for REFCLKPER field of GUCTL register for reference clock period in 272 - nanoseconds, when the hardware set default does not match the actual 273 - clock. 274 - 275 - This binding is deprecated. Instead, provide an appropriate reference clock. 276 - minimum: 8 277 - maximum: 62 278 - deprecated: true 279 - 280 - snps,rx-thr-num-pkt: 281 - description: 282 - USB RX packet threshold count. In host mode, this field specifies 283 - the space that must be available in the RX FIFO before the core can 284 - start the corresponding USB RX transaction (burst). 285 - In device mode, this field specifies the space that must be 286 - available in the RX FIFO before the core can send ERDY for a 287 - flow-controlled endpoint. It is only used for SuperSpeed. 288 - The valid values for this field are from 1 to 15. (DWC3 SuperSpeed 289 - USB 3.0 Controller Databook) 290 - $ref: /schemas/types.yaml#/definitions/uint8 291 - minimum: 1 292 - maximum: 15 293 - 294 - snps,rx-max-burst: 295 - description: 296 - Max USB RX burst size. In host mode, this field specifies the 297 - Maximum Bulk IN burst the DWC_usb3 core can perform. When the system 298 - bus is slower than the USB, RX FIFO can overrun during a long burst. 299 - You can program a smaller value to this field to limit the RX burst 300 - size that the core can perform. It only applies to SS Bulk, 301 - Isochronous, and Interrupt IN endpoints in the host mode. 302 - In device mode, this field specifies the NUMP value that is sent in 303 - ERDY for an OUT endpoint. 304 - The valid values for this field are from 1 to 16. (DWC3 SuperSpeed 305 - USB 3.0 Controller Databook) 306 - $ref: /schemas/types.yaml#/definitions/uint8 307 - minimum: 1 308 - maximum: 16 309 - 310 - snps,tx-thr-num-pkt: 311 - description: 312 - USB TX packet threshold count. This field specifies the number of 313 - packets that must be in the TXFIFO before the core can start 314 - transmission for the corresponding USB transaction (burst). 315 - This count is valid in both host and device modes. It is only used 316 - for SuperSpeed operation. 317 - Valid values are from 1 to 15. (DWC3 SuperSpeed USB 3.0 Controller 318 - Databook) 319 - $ref: /schemas/types.yaml#/definitions/uint8 320 - minimum: 1 321 - maximum: 15 322 - 323 - snps,tx-max-burst: 324 - description: 325 - Max USB TX burst size. When the system bus is slower than the USB, 326 - TX FIFO can underrun during a long burst. Program a smaller value 327 - to this field to limit the TX burst size that the core can execute. 328 - In Host mode, it only applies to SS Bulk, Isochronous, and Interrupt 329 - OUT endpoints. This value is not used in device mode. 330 - Valid values are from 1 to 16. (DWC3 SuperSpeed USB 3.0 Controller 331 - Databook) 332 - $ref: /schemas/types.yaml#/definitions/uint8 333 - minimum: 1 334 - maximum: 16 335 - 336 - snps,rx-thr-num-pkt-prd: 337 - description: 338 - Periodic ESS RX packet threshold count (host mode only). Set this and 339 - snps,rx-max-burst-prd to a valid, non-zero value 1-16 (DWC_usb31 340 - programming guide section 1.2.4) to enable periodic ESS RX threshold. 341 - $ref: /schemas/types.yaml#/definitions/uint8 342 - minimum: 1 343 - maximum: 16 344 - 345 - snps,rx-max-burst-prd: 346 - description: 347 - Max periodic ESS RX burst size (host mode only). Set this and 348 - snps,rx-thr-num-pkt-prd to a valid, non-zero value 1-16 (DWC_usb31 349 - programming guide section 1.2.4) to enable periodic ESS RX threshold. 350 - $ref: /schemas/types.yaml#/definitions/uint8 351 - minimum: 1 352 - maximum: 16 353 - 354 - snps,tx-thr-num-pkt-prd: 355 - description: 356 - Periodic ESS TX packet threshold count (host mode only). Set this and 357 - snps,tx-max-burst-prd to a valid, non-zero value 1-16 (DWC_usb31 358 - programming guide section 1.2.3) to enable periodic ESS TX threshold. 359 - $ref: /schemas/types.yaml#/definitions/uint8 360 - minimum: 1 361 - maximum: 16 362 - 363 - snps,tx-max-burst-prd: 364 - description: 365 - Max periodic ESS TX burst size (host mode only). Set this and 366 - snps,tx-thr-num-pkt-prd to a valid, non-zero value 1-16 (DWC_usb31 367 - programming guide section 1.2.3) to enable periodic ESS TX threshold. 368 - $ref: /schemas/types.yaml#/definitions/uint8 369 - minimum: 1 370 - maximum: 16 371 - 372 - tx-fifo-resize: 373 - description: Determines if the TX fifos can be dynamically resized depending 374 - on the number of IN endpoints used and if bursting is supported. This 375 - may help improve bandwidth on platforms with higher system latencies, as 376 - increased fifo space allows for the controller to prefetch data into its 377 - internal memory. 378 - type: boolean 379 - 380 - tx-fifo-max-num: 381 - description: Specifies the max number of packets the txfifo resizing logic 382 - can account for when higher endpoint bursting is used. (bMaxBurst > 6) The 383 - higher the number, the more fifo space the txfifo resizing logic will 384 - allocate for that endpoint. 385 - $ref: /schemas/types.yaml#/definitions/uint8 386 - minimum: 3 387 - 388 - snps,incr-burst-type-adjustment: 389 - description: 390 - Value for INCR burst type of GSBUSCFG0 register, undefined length INCR 391 - burst type enable and INCRx type. A single value means INCRX burst mode 392 - enabled. If more than one value specified, undefined length INCR burst 393 - type will be enabled with burst lengths utilized up to the maximum 394 - of the values passed in this property. 395 - $ref: /schemas/types.yaml#/definitions/uint32-array 396 - minItems: 1 397 - maxItems: 8 398 - uniqueItems: true 399 - items: 400 - enum: [1, 4, 8, 16, 32, 64, 128, 256] 401 - 402 - num-hc-interrupters: 403 - maximum: 8 404 - default: 1 405 - 406 - port: 407 - $ref: /schemas/graph.yaml#/properties/port 408 - description: 409 - This port is used with the 'usb-role-switch' property to connect the 410 - dwc3 to type C connector. 411 - 412 - ports: 413 - $ref: /schemas/graph.yaml#/properties/ports 414 - description: 415 - Those ports should be used with any connector to the data bus of this 416 - controller using the OF graph bindings specified if the "usb-role-switch" 417 - property is used. 418 - 419 - properties: 420 - port@0: 421 - $ref: /schemas/graph.yaml#/properties/port 422 - description: High Speed (HS) data bus. 423 - 424 - port@1: 425 - $ref: /schemas/graph.yaml#/properties/port 426 - description: Super Speed (SS) data bus. 427 - 428 - wakeup-source: 429 - $ref: /schemas/types.yaml#/definitions/flag 430 - description: 431 - Enable USB remote wakeup. 432 111 433 112 unevaluatedProperties: false 434 113
+19 -19
Documentation/devicetree/bindings/usb/ti,hd3ss3220.yaml
··· 56 56 #size-cells = <0>; 57 57 58 58 hd3ss3220@47 { 59 - compatible = "ti,hd3ss3220"; 60 - reg = <0x47>; 61 - interrupt-parent = <&gpio6>; 62 - interrupts = <3>; 59 + compatible = "ti,hd3ss3220"; 60 + reg = <0x47>; 61 + interrupt-parent = <&gpio6>; 62 + interrupts = <3>; 63 63 64 - ports { 65 - #address-cells = <1>; 66 - #size-cells = <0>; 67 - port@0 { 68 - reg = <0>; 69 - hd3ss3220_in_ep: endpoint { 70 - remote-endpoint = <&ss_ep>; 71 - }; 72 - }; 73 - port@1 { 74 - reg = <1>; 75 - hd3ss3220_out_ep: endpoint { 76 - remote-endpoint = <&usb3_role_switch>; 77 - }; 78 - }; 64 + ports { 65 + #address-cells = <1>; 66 + #size-cells = <0>; 67 + port@0 { 68 + reg = <0>; 69 + hd3ss3220_in_ep: endpoint { 70 + remote-endpoint = <&ss_ep>; 71 + }; 79 72 }; 73 + port@1 { 74 + reg = <1>; 75 + hd3ss3220_out_ep: endpoint { 76 + remote-endpoint = <&usb3_role_switch>; 77 + }; 78 + }; 79 + }; 80 80 }; 81 81 };
+3 -3
Documentation/devicetree/bindings/usb/ti,tusb73x0-pci.yaml
··· 48 48 device_type = "pci"; 49 49 50 50 usb@0 { 51 - compatible = "pci104c,8241"; 52 - reg = <0x0 0x0 0x0 0x0 0x0>; 53 - ti,pwron-active-high; 51 + compatible = "pci104c,8241"; 52 + reg = <0x0 0x0 0x0 0x0 0x0>; 53 + ti,pwron-active-high; 54 54 }; 55 55 };
+10 -10
Documentation/devicetree/bindings/usb/ti,usb8020b.yaml
··· 51 51 52 52 /* 2.0 hub on port 1 */ 53 53 hub_2_0: hub@1 { 54 - compatible = "usb451,8027"; 55 - reg = <1>; 56 - peer-hub = <&hub_3_0>; 57 - reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 58 - vdd-supply = <&usb_hub_fixed_3v3>; 54 + compatible = "usb451,8027"; 55 + reg = <1>; 56 + peer-hub = <&hub_3_0>; 57 + reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 58 + vdd-supply = <&usb_hub_fixed_3v3>; 59 59 }; 60 60 61 61 /* 3.0 hub on port 2 */ 62 62 hub_3_0: hub@2 { 63 - compatible = "usb451,8025"; 64 - reg = <2>; 65 - peer-hub = <&hub_2_0>; 66 - reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 67 - vdd-supply = <&usb_hub_fixed_3v3>; 63 + compatible = "usb451,8025"; 64 + reg = <2>; 65 + peer-hub = <&hub_2_0>; 66 + reset-gpios = <&pio 7 GPIO_ACTIVE_HIGH>; 67 + vdd-supply = <&usb_hub_fixed_3v3>; 68 68 }; 69 69 };
+8 -8
Documentation/devicetree/bindings/usb/ti,usb8041.yaml
··· 51 51 52 52 /* 2.0 hub on port 1 */ 53 53 hub_2_0: hub@1 { 54 - compatible = "usb451,8142"; 55 - reg = <1>; 56 - peer-hub = <&hub_3_0>; 57 - reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 54 + compatible = "usb451,8142"; 55 + reg = <1>; 56 + peer-hub = <&hub_3_0>; 57 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 58 58 }; 59 59 60 60 /* 3.0 hub on port 2 */ 61 61 hub_3_0: hub@2 { 62 - compatible = "usb451,8140"; 63 - reg = <2>; 64 - peer-hub = <&hub_2_0>; 65 - reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 62 + compatible = "usb451,8140"; 63 + reg = <2>; 64 + peer-hub = <&hub_2_0>; 65 + reset-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>; 66 66 }; 67 67 };
-1
Documentation/driver-api/driver-model/devres.rst
··· 404 404 devm_usb_get_phy() 405 405 devm_usb_get_phy_by_node() 406 406 devm_usb_get_phy_by_phandle() 407 - devm_usb_put_phy() 408 407 409 408 PINCTRL 410 409 devm_pinctrl_get()
+6 -6
Documentation/usb/usbip_protocol.rst
··· 285 285 +-----------+--------+------------+---------------------------------------------------+ 286 286 | 0x138 | 2 | | bcdDevice | 287 287 +-----------+--------+------------+---------------------------------------------------+ 288 - | 0x139 | 1 | | bDeviceClass | 288 + | 0x13A | 1 | | bDeviceClass | 289 289 +-----------+--------+------------+---------------------------------------------------+ 290 - | 0x13A | 1 | | bDeviceSubClass | 290 + | 0x13B | 1 | | bDeviceSubClass | 291 291 +-----------+--------+------------+---------------------------------------------------+ 292 - | 0x13B | 1 | | bDeviceProtocol | 292 + | 0x13C | 1 | | bDeviceProtocol | 293 293 +-----------+--------+------------+---------------------------------------------------+ 294 - | 0x13C | 1 | | bConfigurationValue | 294 + | 0x13D | 1 | | bConfigurationValue | 295 295 +-----------+--------+------------+---------------------------------------------------+ 296 - | 0x13D | 1 | | bNumConfigurations | 296 + | 0x13E | 1 | | bNumConfigurations | 297 297 +-----------+--------+------------+---------------------------------------------------+ 298 - | 0x13E | 1 | | bNumInterfaces | 298 + | 0x13F | 1 | | bNumInterfaces | 299 299 +-----------+--------+------------+---------------------------------------------------+ 300 300 301 301 The following four commands have a common basic header called
+10
MAINTAINERS
··· 5481 5481 5482 5482 CHROMEOS EC USB TYPE-C DRIVER 5483 5483 M: Prashant Malani <pmalani@chromium.org> 5484 + M: Benson Leung <bleung@chromium.org> 5485 + M: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> 5484 5486 L: chrome-platform@lists.linux.dev 5485 5487 S: Maintained 5486 5488 F: drivers/platform/chrome/cros_ec_typec.* 5489 + F: drivers/platform/chrome/cros_typec_altmode.* 5487 5490 F: drivers/platform/chrome/cros_typec_switch.c 5488 5491 F: drivers/platform/chrome/cros_typec_vdm.* 5489 5492 ··· 5501 5498 L: chrome-platform@lists.linux.dev 5502 5499 S: Maintained 5503 5500 F: drivers/watchdog/cros_ec_wdt.c 5501 + 5502 + CHROMEOS UCSI DRIVER 5503 + M: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> 5504 + M: Łukasz Bartosik <ukaszb@chromium.org> 5505 + L: chrome-platform@lists.linux.dev 5506 + S: Maintained 5507 + F: drivers/usb/typec/ucsi/cros_ec_ucsi.c 5504 5508 5505 5509 CHRONTEL CH7322 CEC DRIVER 5506 5510 M: Joe Tessler <jrt@google.com>
+7
drivers/platform/chrome/Kconfig
··· 237 237 To compile this driver as a module, choose M here: the 238 238 module will be called cros_ec_sysfs. 239 239 240 + config CROS_EC_TYPEC_ALTMODES 241 + bool 242 + help 243 + Selectable symbol to enable altmodes. 244 + 240 245 config CROS_EC_TYPEC 241 246 tristate "ChromeOS EC Type-C Connector Control" 242 247 depends on MFD_CROS_EC_DEV && TYPEC 243 248 depends on CROS_USBPD_NOTIFY 244 249 depends on USB_ROLE_SWITCH 245 250 default MFD_CROS_EC_DEV 251 + select CROS_EC_TYPEC_ALTMODES if TYPEC_DP_ALTMODE 252 + select CROS_EC_TYPEC_ALTMODES if TYPEC_TBT_ALTMODE 246 253 help 247 254 If you say Y here, you get support for accessing Type C connector 248 255 information from the Chrome OS EC.
+4
drivers/platform/chrome/Makefile
··· 19 19 obj-$(CONFIG_CROS_EC_UART) += cros_ec_uart.o 20 20 cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o 21 21 cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o 22 + ifneq ($(CONFIG_CROS_EC_TYPEC_ALTMODES),) 23 + cros-ec-typec-objs += cros_typec_altmode.o 24 + endif 22 25 obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o 26 + 23 27 obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o 24 28 obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o 25 29 obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
+32 -14
drivers/platform/chrome/cros_ec_typec.c
··· 18 18 19 19 #include "cros_ec_typec.h" 20 20 #include "cros_typec_vdm.h" 21 + #include "cros_typec_altmode.h" 21 22 22 23 #define DRV_NAME "cros-ec-typec" 23 24 ··· 291 290 struct typec_altmode *amode; 292 291 293 292 /* All PD capable CrOS devices are assumed to support DP altmode. */ 293 + memset(&desc, 0, sizeof(desc)); 294 294 desc.svid = USB_TYPEC_DP_SID; 295 295 desc.mode = USB_TYPEC_DP_MODE; 296 296 desc.vdo = DP_PORT_VDO; 297 - amode = typec_port_register_altmode(port->port, &desc); 297 + amode = cros_typec_register_displayport(port, &desc, 298 + typec->ap_driven_altmode); 298 299 if (IS_ERR(amode)) 299 300 return PTR_ERR(amode); 300 301 port->port_altmode[CROS_EC_ALTMODE_DP] = amode; 301 - typec_altmode_set_drvdata(amode, port); 302 - amode->ops = &port_amode_ops; 303 302 304 303 /* 305 304 * Register TBT compatibility alt mode. The EC will not enter the mode 306 - * if it doesn't support it, so it's safe to register it unconditionally 307 - * here for now. 305 + * if it doesn't support it and it will not enter automatically by 306 + * design so we can use the |ap_driven_altmode| feature to check if we 307 + * should register it. 308 308 */ 309 - memset(&desc, 0, sizeof(desc)); 310 - desc.svid = USB_TYPEC_TBT_SID; 311 - desc.mode = TYPEC_ANY_MODE; 312 - amode = typec_port_register_altmode(port->port, &desc); 313 - if (IS_ERR(amode)) 314 - return PTR_ERR(amode); 315 - port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; 316 - typec_altmode_set_drvdata(amode, port); 317 - amode->ops = &port_amode_ops; 309 + if (typec->ap_driven_altmode) { 310 + memset(&desc, 0, sizeof(desc)); 311 + desc.svid = USB_TYPEC_TBT_SID; 312 + desc.mode = TBT_MODE; 313 + desc.inactive = true; 314 + amode = cros_typec_register_thunderbolt(port, &desc); 315 + if (IS_ERR(amode)) 316 + return PTR_ERR(amode); 317 + port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; 318 + } 318 319 319 320 port->state.alt = NULL; 320 321 port->state.mode = TYPEC_STATE_USB; ··· 579 576 if (!ret) 580 577 ret = typec_mux_set(port->mux, &port->state); 581 578 579 + if (!ret) 580 + ret = cros_typec_displayport_status_update(port->state.alt, 581 + port->state.data); 582 + 582 583 return ret; 583 584 } 584 585 ··· 626 619 }; 627 620 struct ec_params_usb_pd_mux_ack mux_ack; 628 621 enum typec_orientation orientation; 622 + struct cros_typec_altmode_node *node; 629 623 int ret; 630 624 631 625 ret = cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, ··· 683 675 dev_dbg(typec->dev, 684 676 "Unrecognized mode requested, mux flags: %x\n", 685 677 port->mux_flags); 678 + } 679 + 680 + /* Iterate all partner alt-modes and set the active alternate mode. */ 681 + list_for_each_entry(node, &port->partner_mode_list, list) { 682 + typec_altmode_update_active( 683 + node->amode, 684 + port->state.alt && 685 + node->amode->svid == port->state.alt->svid); 686 686 } 687 687 688 688 mux_ack: ··· 1260 1244 1261 1245 typec->typec_cmd_supported = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); 1262 1246 typec->needs_mux_ack = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); 1247 + typec->ap_driven_altmode = cros_ec_check_features( 1248 + ec_dev, EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY); 1263 1249 1264 1250 ret = cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, 1265 1251 &resp, sizeof(resp));
+1
drivers/platform/chrome/cros_ec_typec.h
··· 39 39 struct work_struct port_work; 40 40 bool typec_cmd_supported; 41 41 bool needs_mux_ack; 42 + bool ap_driven_altmode; 42 43 }; 43 44 44 45 /* Per port data. */
+373
drivers/platform/chrome/cros_typec_altmode.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Alt-mode implementation on ChromeOS EC. 4 + * 5 + * Copyright 2024 Google LLC 6 + * Author: Abhishek Pandit-Subedi <abhishekpandit@chromium.org> 7 + */ 8 + #include "cros_ec_typec.h" 9 + 10 + #include <linux/mutex.h> 11 + #include <linux/workqueue.h> 12 + #include <linux/usb/typec_dp.h> 13 + #include <linux/usb/typec_tbt.h> 14 + #include <linux/usb/pd_vdo.h> 15 + 16 + #include "cros_typec_altmode.h" 17 + 18 + struct cros_typec_altmode_data { 19 + struct work_struct work; 20 + struct cros_typec_port *port; 21 + struct typec_altmode *alt; 22 + bool ap_mode_entry; 23 + 24 + struct mutex lock; 25 + u32 header; 26 + u32 *vdo_data; 27 + u8 vdo_size; 28 + 29 + u16 sid; 30 + u8 mode; 31 + }; 32 + 33 + struct cros_typec_dp_data { 34 + struct cros_typec_altmode_data adata; 35 + struct typec_displayport_data data; 36 + bool configured; 37 + bool pending_status_update; 38 + }; 39 + 40 + static void cros_typec_altmode_work(struct work_struct *work) 41 + { 42 + struct cros_typec_altmode_data *data = 43 + container_of(work, struct cros_typec_altmode_data, work); 44 + 45 + mutex_lock(&data->lock); 46 + 47 + if (typec_altmode_vdm(data->alt, data->header, data->vdo_data, 48 + data->vdo_size)) 49 + dev_err(&data->alt->dev, "VDM 0x%x failed\n", data->header); 50 + 51 + data->header = 0; 52 + data->vdo_data = NULL; 53 + data->vdo_size = 0; 54 + 55 + mutex_unlock(&data->lock); 56 + } 57 + 58 + static int cros_typec_altmode_enter(struct typec_altmode *alt, u32 *vdo) 59 + { 60 + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); 61 + struct ec_params_typec_control req = { 62 + .port = adata->port->port_num, 63 + .command = TYPEC_CONTROL_COMMAND_ENTER_MODE, 64 + }; 65 + int svdm_version; 66 + int ret; 67 + 68 + if (!adata->ap_mode_entry) { 69 + dev_warn(&alt->dev, 70 + "EC does not support AP driven mode entry\n"); 71 + return -EOPNOTSUPP; 72 + } 73 + 74 + if (adata->sid == USB_TYPEC_DP_SID) 75 + req.mode_to_enter = CROS_EC_ALTMODE_DP; 76 + else if (adata->sid == USB_TYPEC_TBT_SID) 77 + req.mode_to_enter = CROS_EC_ALTMODE_TBT; 78 + else 79 + return -EOPNOTSUPP; 80 + 81 + ret = cros_ec_cmd(adata->port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, 82 + &req, sizeof(req), NULL, 0); 83 + if (ret < 0) 84 + return ret; 85 + 86 + svdm_version = typec_altmode_get_svdm_version(alt); 87 + if (svdm_version < 0) 88 + return svdm_version; 89 + 90 + mutex_lock(&adata->lock); 91 + 92 + adata->header = VDO(adata->sid, 1, svdm_version, CMD_ENTER_MODE); 93 + adata->header |= VDO_OPOS(adata->mode); 94 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 95 + adata->vdo_data = NULL; 96 + adata->vdo_size = 1; 97 + schedule_work(&adata->work); 98 + 99 + mutex_unlock(&adata->lock); 100 + return ret; 101 + } 102 + 103 + static int cros_typec_altmode_exit(struct typec_altmode *alt) 104 + { 105 + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); 106 + struct ec_params_typec_control req = { 107 + .port = adata->port->port_num, 108 + .command = TYPEC_CONTROL_COMMAND_EXIT_MODES, 109 + }; 110 + int svdm_version; 111 + int ret; 112 + 113 + if (!adata->ap_mode_entry) { 114 + dev_warn(&alt->dev, 115 + "EC does not support AP driven mode exit\n"); 116 + return -EOPNOTSUPP; 117 + } 118 + 119 + ret = cros_ec_cmd(adata->port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, 120 + &req, sizeof(req), NULL, 0); 121 + 122 + if (ret < 0) 123 + return ret; 124 + 125 + svdm_version = typec_altmode_get_svdm_version(alt); 126 + if (svdm_version < 0) 127 + return svdm_version; 128 + 129 + mutex_lock(&adata->lock); 130 + 131 + adata->header = VDO(adata->sid, 1, svdm_version, CMD_EXIT_MODE); 132 + adata->header |= VDO_OPOS(adata->mode); 133 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 134 + adata->vdo_data = NULL; 135 + adata->vdo_size = 1; 136 + schedule_work(&adata->work); 137 + 138 + mutex_unlock(&adata->lock); 139 + return ret; 140 + } 141 + 142 + static int cros_typec_displayport_vdm(struct typec_altmode *alt, u32 header, 143 + const u32 *data, int count) 144 + { 145 + struct cros_typec_dp_data *dp_data = typec_altmode_get_drvdata(alt); 146 + struct cros_typec_altmode_data *adata = &dp_data->adata; 147 + 148 + 149 + int cmd_type = PD_VDO_CMDT(header); 150 + int cmd = PD_VDO_CMD(header); 151 + int svdm_version; 152 + 153 + svdm_version = typec_altmode_get_svdm_version(alt); 154 + if (svdm_version < 0) 155 + return svdm_version; 156 + 157 + mutex_lock(&adata->lock); 158 + 159 + switch (cmd_type) { 160 + case CMDT_INIT: 161 + if (PD_VDO_SVDM_VER(header) < svdm_version) { 162 + typec_partner_set_svdm_version(adata->port->partner, 163 + PD_VDO_SVDM_VER(header)); 164 + svdm_version = PD_VDO_SVDM_VER(header); 165 + } 166 + 167 + adata->header = VDO(adata->sid, 1, svdm_version, cmd); 168 + adata->header |= VDO_OPOS(adata->mode); 169 + 170 + /* 171 + * DP_CMD_CONFIGURE: We can't actually do anything with the 172 + * provided VDO yet so just send back an ACK. 173 + * 174 + * DP_CMD_STATUS_UPDATE: We wait for Mux changes to send 175 + * DPStatus Acks. 176 + */ 177 + switch (cmd) { 178 + case DP_CMD_CONFIGURE: 179 + dp_data->data.conf = *data; 180 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 181 + dp_data->configured = true; 182 + schedule_work(&adata->work); 183 + break; 184 + case DP_CMD_STATUS_UPDATE: 185 + dp_data->pending_status_update = true; 186 + break; 187 + default: 188 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 189 + schedule_work(&adata->work); 190 + break; 191 + } 192 + 193 + break; 194 + default: 195 + break; 196 + } 197 + 198 + mutex_unlock(&adata->lock); 199 + return 0; 200 + } 201 + 202 + static int cros_typec_thunderbolt_vdm(struct typec_altmode *alt, u32 header, 203 + const u32 *data, int count) 204 + { 205 + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); 206 + 207 + int cmd_type = PD_VDO_CMDT(header); 208 + int cmd = PD_VDO_CMD(header); 209 + int svdm_version; 210 + 211 + svdm_version = typec_altmode_get_svdm_version(alt); 212 + if (svdm_version < 0) 213 + return svdm_version; 214 + 215 + mutex_lock(&adata->lock); 216 + 217 + switch (cmd_type) { 218 + case CMDT_INIT: 219 + if (PD_VDO_SVDM_VER(header) < svdm_version) { 220 + typec_partner_set_svdm_version(adata->port->partner, 221 + PD_VDO_SVDM_VER(header)); 222 + svdm_version = PD_VDO_SVDM_VER(header); 223 + } 224 + 225 + adata->header = VDO(adata->sid, 1, svdm_version, cmd); 226 + adata->header |= VDO_OPOS(adata->mode); 227 + 228 + switch (cmd) { 229 + case CMD_ENTER_MODE: 230 + /* Don't respond to the enter mode vdm because it 231 + * triggers mux configuration. This is handled directly 232 + * by the cros_ec_typec driver so the Thunderbolt driver 233 + * doesn't need to be involved. 234 + */ 235 + break; 236 + default: 237 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 238 + schedule_work(&adata->work); 239 + break; 240 + } 241 + 242 + break; 243 + default: 244 + break; 245 + } 246 + 247 + mutex_unlock(&adata->lock); 248 + return 0; 249 + } 250 + 251 + 252 + static int cros_typec_altmode_vdm(struct typec_altmode *alt, u32 header, 253 + const u32 *data, int count) 254 + { 255 + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); 256 + 257 + if (!adata->ap_mode_entry) 258 + return -EOPNOTSUPP; 259 + 260 + if (adata->sid == USB_TYPEC_DP_SID) 261 + return cros_typec_displayport_vdm(alt, header, data, count); 262 + 263 + if (adata->sid == USB_TYPEC_TBT_SID) 264 + return cros_typec_thunderbolt_vdm(alt, header, data, count); 265 + 266 + return -EINVAL; 267 + } 268 + 269 + static const struct typec_altmode_ops cros_typec_altmode_ops = { 270 + .enter = cros_typec_altmode_enter, 271 + .exit = cros_typec_altmode_exit, 272 + .vdm = cros_typec_altmode_vdm, 273 + }; 274 + 275 + #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) 276 + int cros_typec_displayport_status_update(struct typec_altmode *altmode, 277 + struct typec_displayport_data *data) 278 + { 279 + struct cros_typec_dp_data *dp_data = 280 + typec_altmode_get_drvdata(altmode); 281 + struct cros_typec_altmode_data *adata = &dp_data->adata; 282 + 283 + if (!dp_data->pending_status_update) { 284 + dev_dbg(&altmode->dev, 285 + "Got DPStatus without a pending request\n"); 286 + return 0; 287 + } 288 + 289 + if (dp_data->configured && dp_data->data.conf != data->conf) 290 + dev_dbg(&altmode->dev, 291 + "DP Conf doesn't match. Requested 0x%04x, Actual 0x%04x\n", 292 + dp_data->data.conf, data->conf); 293 + 294 + mutex_lock(&adata->lock); 295 + 296 + dp_data->data = *data; 297 + dp_data->pending_status_update = false; 298 + adata->header |= VDO_CMDT(CMDT_RSP_ACK); 299 + adata->vdo_data = &dp_data->data.status; 300 + adata->vdo_size = 2; 301 + schedule_work(&adata->work); 302 + 303 + mutex_unlock(&adata->lock); 304 + 305 + return 0; 306 + } 307 + 308 + struct typec_altmode * 309 + cros_typec_register_displayport(struct cros_typec_port *port, 310 + struct typec_altmode_desc *desc, 311 + bool ap_mode_entry) 312 + { 313 + struct typec_altmode *alt; 314 + struct cros_typec_dp_data *dp_data; 315 + struct cros_typec_altmode_data *adata; 316 + 317 + alt = typec_port_register_altmode(port->port, desc); 318 + if (IS_ERR(alt)) 319 + return alt; 320 + 321 + dp_data = devm_kzalloc(&alt->dev, sizeof(*dp_data), GFP_KERNEL); 322 + if (!dp_data) { 323 + typec_unregister_altmode(alt); 324 + return ERR_PTR(-ENOMEM); 325 + } 326 + 327 + adata = &dp_data->adata; 328 + INIT_WORK(&adata->work, cros_typec_altmode_work); 329 + mutex_init(&adata->lock); 330 + adata->alt = alt; 331 + adata->port = port; 332 + adata->ap_mode_entry = ap_mode_entry; 333 + adata->sid = desc->svid; 334 + adata->mode = desc->mode; 335 + 336 + typec_altmode_set_ops(alt, &cros_typec_altmode_ops); 337 + typec_altmode_set_drvdata(alt, adata); 338 + 339 + return alt; 340 + } 341 + #endif 342 + 343 + #if IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) 344 + struct typec_altmode * 345 + cros_typec_register_thunderbolt(struct cros_typec_port *port, 346 + struct typec_altmode_desc *desc) 347 + { 348 + struct typec_altmode *alt; 349 + struct cros_typec_altmode_data *adata; 350 + 351 + alt = typec_port_register_altmode(port->port, desc); 352 + if (IS_ERR(alt)) 353 + return alt; 354 + 355 + adata = devm_kzalloc(&alt->dev, sizeof(*adata), GFP_KERNEL); 356 + if (!adata) { 357 + typec_unregister_altmode(alt); 358 + return ERR_PTR(-ENOMEM); 359 + } 360 + 361 + INIT_WORK(&adata->work, cros_typec_altmode_work); 362 + adata->alt = alt; 363 + adata->port = port; 364 + adata->ap_mode_entry = true; 365 + adata->sid = desc->svid; 366 + adata->mode = desc->mode; 367 + 368 + typec_altmode_set_ops(alt, &cros_typec_altmode_ops); 369 + typec_altmode_set_drvdata(alt, adata); 370 + 371 + return alt; 372 + } 373 + #endif
+51
drivers/platform/chrome/cros_typec_altmode.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + 3 + #ifndef __CROS_TYPEC_ALTMODE_H__ 4 + #define __CROS_TYPEC_ALTMODE_H__ 5 + 6 + #include <linux/kconfig.h> 7 + #include <linux/usb/typec.h> 8 + 9 + struct cros_typec_port; 10 + struct typec_altmode; 11 + struct typec_altmode_desc; 12 + struct typec_displayport_data; 13 + 14 + #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) 15 + struct typec_altmode * 16 + cros_typec_register_displayport(struct cros_typec_port *port, 17 + struct typec_altmode_desc *desc, 18 + bool ap_mode_entry); 19 + 20 + int cros_typec_displayport_status_update(struct typec_altmode *altmode, 21 + struct typec_displayport_data *data); 22 + #else 23 + static inline struct typec_altmode * 24 + cros_typec_register_displayport(struct cros_typec_port *port, 25 + struct typec_altmode_desc *desc, 26 + bool ap_mode_entry) 27 + { 28 + return typec_port_register_altmode(port->port, desc); 29 + } 30 + 31 + static inline int cros_typec_displayport_status_update(struct typec_altmode *altmode, 32 + struct typec_displayport_data *data) 33 + { 34 + return 0; 35 + } 36 + #endif 37 + 38 + #if IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) 39 + struct typec_altmode * 40 + cros_typec_register_thunderbolt(struct cros_typec_port *port, 41 + struct typec_altmode_desc *desc); 42 + #else 43 + static inline struct typec_altmode * 44 + cros_typec_register_thunderbolt(struct cros_typec_port *port, 45 + struct typec_altmode_desc *desc) 46 + { 47 + return typec_port_register_altmode(port->port, desc); 48 + } 49 + #endif 50 + 51 + #endif /* __CROS_TYPEC_ALTMODE_H__ */
+7 -4
drivers/thunderbolt/ctl.c
··· 70 70 #define tb_ctl_dbg(ctl, format, arg...) \ 71 71 dev_dbg(&(ctl)->nhi->pdev->dev, format, ## arg) 72 72 73 + #define tb_ctl_dbg_once(ctl, format, arg...) \ 74 + dev_dbg_once(&(ctl)->nhi->pdev->dev, format, ## arg) 75 + 73 76 static DECLARE_WAIT_QUEUE_HEAD(tb_cfg_request_cancel_queue); 74 77 /* Serializes access to request kref_get/put */ 75 78 static DEFINE_MUTEX(tb_cfg_request_lock); ··· 268 265 return res; 269 266 } 270 267 271 - static void tb_cfg_print_error(struct tb_ctl *ctl, 268 + static void tb_cfg_print_error(struct tb_ctl *ctl, enum tb_cfg_space space, 272 269 const struct tb_cfg_result *res) 273 270 { 274 271 WARN_ON(res->err != 1); ··· 282 279 * Invalid cfg_space/offset/length combination in 283 280 * cfg_read/cfg_write. 284 281 */ 285 - tb_ctl_dbg(ctl, "%llx:%x: invalid config space or offset\n", 286 - res->response_route, res->response_port); 282 + tb_ctl_dbg_once(ctl, "%llx:%x: invalid config space (%u) or offset\n", 283 + res->response_route, res->response_port, space); 287 284 return; 288 285 case TB_CFG_ERROR_NO_SUCH_PORT: 289 286 /* ··· 1075 1072 res->tb_error == TB_CFG_ERROR_INVALID_CONFIG_SPACE) 1076 1073 return -ENODEV; 1077 1074 1078 - tb_cfg_print_error(ctl, res); 1075 + tb_cfg_print_error(ctl, space, res); 1079 1076 1080 1077 if (res->tb_error == TB_CFG_ERROR_LOCK) 1081 1078 return -EACCES;
-1
drivers/thunderbolt/ctl.h
··· 140 140 enum tb_cfg_space space, u32 offset, u32 length); 141 141 int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route); 142 142 143 - 144 143 #endif
+58 -11
drivers/thunderbolt/debugfs.c
··· 168 168 * offset relative_offset cap_id vs_cap_id value\n 169 169 * v[0] v[1] v[2] v[3] v[4] 170 170 * 171 + * For Path configuration space: 172 + * Short format is: offset value\n 173 + * v[0] v[1] 174 + * Long format as produced from the read side: 175 + * offset relative_offset in_hop_id value\n 176 + * v[0] v[1] v[2] v[3] 177 + * 171 178 * For Counter configuration space: 172 179 * Short format is: offset\n 173 180 * v[0] ··· 198 191 } 199 192 200 193 #if IS_ENABLED(CONFIG_USB4_DEBUGFS_WRITE) 201 - static ssize_t regs_write(struct tb_switch *sw, struct tb_port *port, 202 - const char __user *user_buf, size_t count, 203 - loff_t *ppos) 194 + /* 195 + * Path registers need to be written in double word pairs and they both must be 196 + * read before written. This writes one double word in patch config space 197 + * following the spec flow. 198 + */ 199 + static int path_write_one(struct tb_port *port, u32 val, u32 offset) 204 200 { 201 + u32 index = offset % PATH_LEN; 202 + u32 offs = offset - index; 203 + u32 data[PATH_LEN]; 204 + int ret; 205 + 206 + ret = tb_port_read(port, data, TB_CFG_HOPS, offs, PATH_LEN); 207 + if (ret) 208 + return ret; 209 + data[index] = val; 210 + return tb_port_write(port, data, TB_CFG_HOPS, offs, PATH_LEN); 211 + } 212 + 213 + static ssize_t regs_write(struct tb_switch *sw, struct tb_port *port, 214 + enum tb_cfg_space space, const char __user *user_buf, 215 + size_t count, loff_t *ppos) 216 + { 217 + int long_fmt_len, ret = 0; 205 218 struct tb *tb = sw->tb; 206 219 char *line, *buf; 207 220 u32 val, offset; 208 - int ret = 0; 209 221 210 222 buf = validate_and_copy_from_user(user_buf, &count); 211 223 if (IS_ERR(buf)) ··· 240 214 /* User did hardware changes behind the driver's back */ 241 215 add_taint(TAINT_USER, LOCKDEP_STILL_OK); 242 216 217 + if (space == TB_CFG_HOPS) 218 + long_fmt_len = 4; 219 + else 220 + long_fmt_len = 5; 221 + 243 222 line = buf; 244 - while (parse_line(&line, &offset, &val, 2, 5)) { 245 - if (port) 246 - ret = tb_port_write(port, &val, TB_CFG_PORT, offset, 1); 247 - else 223 + while (parse_line(&line, &offset, &val, 2, long_fmt_len)) { 224 + if (port) { 225 + if (space == TB_CFG_HOPS) 226 + ret = path_write_one(port, val, offset); 227 + else 228 + ret = tb_port_write(port, &val, space, offset, 1); 229 + } else { 248 230 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, offset, 1); 231 + } 249 232 if (ret) 250 233 break; 251 234 } ··· 275 240 struct seq_file *s = file->private_data; 276 241 struct tb_port *port = s->private; 277 242 278 - return regs_write(port->sw, port, user_buf, count, ppos); 243 + return regs_write(port->sw, port, TB_CFG_PORT, user_buf, count, ppos); 244 + } 245 + 246 + static ssize_t path_write(struct file *file, const char __user *user_buf, 247 + size_t count, loff_t *ppos) 248 + { 249 + struct seq_file *s = file->private_data; 250 + struct tb_port *port = s->private; 251 + 252 + return regs_write(port->sw, port, TB_CFG_HOPS, user_buf, count, ppos); 279 253 } 280 254 281 255 static ssize_t switch_regs_write(struct file *file, const char __user *user_buf, ··· 293 249 struct seq_file *s = file->private_data; 294 250 struct tb_switch *sw = s->private; 295 251 296 - return regs_write(sw, NULL, user_buf, count, ppos); 252 + return regs_write(sw, NULL, TB_CFG_SWITCH, user_buf, count, ppos); 297 253 } 298 254 299 255 static bool parse_sb_line(char **line, u8 *reg, u8 *data, size_t data_size, ··· 445 401 #define DEBUGFS_MODE 0600 446 402 #else 447 403 #define port_regs_write NULL 404 + #define path_write NULL 448 405 #define switch_regs_write NULL 449 406 #define port_sb_regs_write NULL 450 407 #define retimer_sb_regs_write NULL ··· 2288 2243 2289 2244 return ret; 2290 2245 } 2291 - DEBUGFS_ATTR_RO(path); 2246 + DEBUGFS_ATTR_RW(path); 2292 2247 2293 2248 static int counter_set_regs_show(struct tb_port *port, struct seq_file *s, 2294 2249 int counter) ··· 2413 2368 sw->debugfs_dir = debugfs_dir; 2414 2369 debugfs_create_file("regs", DEBUGFS_MODE, debugfs_dir, sw, 2415 2370 &switch_regs_fops); 2371 + if (sw->drom) 2372 + debugfs_create_blob("drom", 0400, debugfs_dir, &sw->drom_blob); 2416 2373 2417 2374 tb_switch_for_each_port(sw, port) { 2418 2375 struct dentry *debugfs_dir;
+44 -34
drivers/thunderbolt/eeprom.c
··· 435 435 return 0; 436 436 } 437 437 438 + static int tb_switch_drom_alloc(struct tb_switch *sw, size_t size) 439 + { 440 + sw->drom = kzalloc(size, GFP_KERNEL); 441 + if (!sw->drom) 442 + return -ENOMEM; 443 + 444 + #ifdef CONFIG_DEBUG_FS 445 + sw->drom_blob.data = sw->drom; 446 + sw->drom_blob.size = size; 447 + #endif 448 + return 0; 449 + } 450 + 451 + static void tb_switch_drom_free(struct tb_switch *sw) 452 + { 453 + #ifdef CONFIG_DEBUG_FS 454 + sw->drom_blob.data = NULL; 455 + sw->drom_blob.size = 0; 456 + #endif 457 + kfree(sw->drom); 458 + sw->drom = NULL; 459 + } 460 + 438 461 /* 439 462 * tb_drom_copy_efi - copy drom supplied by EFI to sw->drom if present 440 463 */ ··· 470 447 if (len < 0 || len < sizeof(struct tb_drom_header)) 471 448 return -EINVAL; 472 449 473 - sw->drom = kmalloc(len, GFP_KERNEL); 474 - if (!sw->drom) 475 - return -ENOMEM; 450 + res = tb_switch_drom_alloc(sw, len); 451 + if (res) 452 + return res; 476 453 477 454 res = device_property_read_u8_array(dev, "ThunderboltDROM", sw->drom, 478 455 len); ··· 487 464 return 0; 488 465 489 466 err: 490 - kfree(sw->drom); 491 - sw->drom = NULL; 467 + tb_switch_drom_free(sw); 492 468 return -EINVAL; 493 469 } 494 470 ··· 513 491 514 492 /* Size includes CRC8 + UID + CRC32 */ 515 493 *size += 1 + 8 + 4; 516 - sw->drom = kzalloc(*size, GFP_KERNEL); 517 - if (!sw->drom) 518 - return -ENOMEM; 494 + ret = tb_switch_drom_alloc(sw, *size); 495 + if (ret) 496 + return ret; 519 497 520 498 ret = dma_port_flash_read(sw->dma_port, drom_offset, sw->drom, *size); 521 - if (ret) 522 - goto err_free; 499 + if (ret) { 500 + tb_switch_drom_free(sw); 501 + return ret; 502 + } 523 503 524 504 /* 525 505 * Read UID from the minimal DROM because the one in NVM is just ··· 529 505 */ 530 506 tb_drom_read_uid_only(sw, &sw->uid); 531 507 return 0; 532 - 533 - err_free: 534 - kfree(sw->drom); 535 - sw->drom = NULL; 536 - return ret; 537 508 } 538 509 539 510 static int usb4_copy_drom(struct tb_switch *sw, u16 *size) ··· 541 522 542 523 /* Size includes CRC8 + UID + CRC32 */ 543 524 *size += 1 + 8 + 4; 544 - sw->drom = kzalloc(*size, GFP_KERNEL); 545 - if (!sw->drom) 546 - return -ENOMEM; 525 + ret = tb_switch_drom_alloc(sw, *size); 526 + if (ret) 527 + return ret; 547 528 548 529 ret = usb4_switch_drom_read(sw, 0, sw->drom, *size); 549 - if (ret) { 550 - kfree(sw->drom); 551 - sw->drom = NULL; 552 - } 530 + if (ret) 531 + tb_switch_drom_free(sw); 553 532 554 533 return ret; 555 534 } ··· 569 552 return -EIO; 570 553 } 571 554 572 - sw->drom = kzalloc(*size, GFP_KERNEL); 573 - if (!sw->drom) 574 - return -ENOMEM; 555 + ret = tb_switch_drom_alloc(sw, *size); 556 + if (ret) 557 + return ret; 575 558 576 559 ret = tb_eeprom_read_n(sw, 0, sw->drom, *size); 577 560 if (ret) 578 - goto err; 561 + tb_switch_drom_free(sw); 579 562 580 - return 0; 581 - 582 - err: 583 - kfree(sw->drom); 584 - sw->drom = NULL; 585 563 return ret; 586 564 } 587 565 ··· 658 646 return 0; 659 647 660 648 err: 661 - kfree(sw->drom); 662 - sw->drom = NULL; 663 - 649 + tb_switch_drom_free(sw); 664 650 return ret; 665 651 } 666 652
+2 -2
drivers/thunderbolt/path.c
··· 581 581 } 582 582 } 583 583 path->activated = true; 584 - tb_dbg(path->tb, "path activation complete\n"); 584 + tb_dbg(path->tb, "%s path activation complete\n", path->name); 585 585 return 0; 586 586 err: 587 - tb_WARN(path->tb, "path activation failed\n"); 587 + tb_WARN(path->tb, "%s path activation failed\n", path->name); 588 588 return res; 589 589 } 590 590
+137 -59
drivers/thunderbolt/tb.c
··· 20 20 #define TB_RELEASE_BW_TIMEOUT 10000 /* ms */ 21 21 22 22 /* 23 + * How many time bandwidth allocation request from graphics driver is 24 + * retried if the DP tunnel is still activating. 25 + */ 26 + #define TB_BW_ALLOC_RETRIES 3 27 + 28 + /* 23 29 * Minimum bandwidth (in Mb/s) that is needed in the single transmitter/receiver 24 30 * direction. This is 40G - 10% guard band bandwidth. 25 31 */ ··· 75 69 } 76 70 77 71 struct tb_hotplug_event { 78 - struct work_struct work; 72 + struct delayed_work work; 79 73 struct tb *tb; 80 74 u64 route; 81 75 u8 port; 82 76 bool unplug; 77 + int retry; 83 78 }; 84 79 80 + static void tb_scan_port(struct tb_port *port); 85 81 static void tb_handle_hotplug(struct work_struct *work); 82 + static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port, 83 + const char *reason); 84 + static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port, 85 + int retry, unsigned long delay); 86 86 87 87 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) 88 88 { ··· 102 90 ev->route = route; 103 91 ev->port = port; 104 92 ev->unplug = unplug; 105 - INIT_WORK(&ev->work, tb_handle_hotplug); 106 - queue_work(tb->wq, &ev->work); 93 + INIT_DELAYED_WORK(&ev->work, tb_handle_hotplug); 94 + queue_delayed_work(tb->wq, &ev->work, 0); 107 95 } 108 96 109 97 /* enumeration & hot plug handling */ ··· 973 961 return 0; 974 962 975 963 err_free: 976 - tb_tunnel_free(tunnel); 964 + tb_tunnel_put(tunnel); 977 965 err_reclaim: 978 966 if (tb_route(parent)) 979 967 tb_reclaim_usb3_bandwidth(tb, down, up); ··· 1249 1237 /* Set the link configured */ 1250 1238 tb_switch_configure_link(sw); 1251 1239 } 1252 - 1253 - static void tb_scan_port(struct tb_port *port); 1254 1240 1255 1241 /* 1256 1242 * tb_scan_switch() - scan for and initialize downstream switches ··· 1737 1727 break; 1738 1728 } 1739 1729 1740 - tb_tunnel_free(tunnel); 1730 + tb_tunnel_put(tunnel); 1741 1731 } 1742 1732 1743 1733 /* ··· 1874 1864 return NULL; 1875 1865 } 1876 1866 1877 - static bool tb_tunnel_one_dp(struct tb *tb, struct tb_port *in, 1867 + static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data) 1868 + { 1869 + struct tb_port *in = tunnel->src_port; 1870 + struct tb_port *out = tunnel->dst_port; 1871 + struct tb *tb = data; 1872 + 1873 + mutex_lock(&tb->lock); 1874 + if (tb_tunnel_is_active(tunnel)) { 1875 + int consumed_up, consumed_down, ret; 1876 + 1877 + tb_tunnel_dbg(tunnel, "DPRX capabilities read completed\n"); 1878 + 1879 + /* If fail reading tunnel's consumed bandwidth, tear it down */ 1880 + ret = tb_tunnel_consumed_bandwidth(tunnel, &consumed_up, 1881 + &consumed_down); 1882 + if (ret) { 1883 + tb_tunnel_warn(tunnel, 1884 + "failed to read consumed bandwidth, tearing down\n"); 1885 + tb_deactivate_and_free_tunnel(tunnel); 1886 + } else { 1887 + tb_reclaim_usb3_bandwidth(tb, in, out); 1888 + /* 1889 + * Transition the links to asymmetric if the 1890 + * consumption exceeds the threshold. 1891 + */ 1892 + tb_configure_asym(tb, in, out, consumed_up, 1893 + consumed_down); 1894 + /* 1895 + * Update the domain with the new bandwidth 1896 + * estimation. 1897 + */ 1898 + tb_recalc_estimated_bandwidth(tb); 1899 + /* 1900 + * In case of DP tunnel exists, change host 1901 + * router's 1st children TMU mode to HiFi for 1902 + * CL0s to work. 1903 + */ 1904 + tb_increase_tmu_accuracy(tunnel); 1905 + } 1906 + } else { 1907 + struct tb_port *in = tunnel->src_port; 1908 + 1909 + /* 1910 + * This tunnel failed to establish. This means DPRX 1911 + * negotiation most likely did not complete which 1912 + * happens either because there is no graphics driver 1913 + * loaded or not all DP cables where connected to the 1914 + * discrete router. 1915 + * 1916 + * In both cases we remove the DP IN adapter from the 1917 + * available resources as it is not usable. This will 1918 + * also tear down the tunnel and try to re-use the 1919 + * released DP OUT. 1920 + * 1921 + * It will be added back only if there is hotplug for 1922 + * the DP IN again. 1923 + */ 1924 + tb_tunnel_warn(tunnel, "not active, tearing down\n"); 1925 + tb_dp_resource_unavailable(tb, in, "DPRX negotiation failed"); 1926 + } 1927 + mutex_unlock(&tb->lock); 1928 + 1929 + tb_domain_put(tb); 1930 + } 1931 + 1932 + static void tb_tunnel_one_dp(struct tb *tb, struct tb_port *in, 1878 1933 struct tb_port *out) 1879 1934 { 1880 1935 int available_up, available_down, ret, link_nr; 1881 1936 struct tb_cm *tcm = tb_priv(tb); 1882 - int consumed_up, consumed_down; 1883 1937 struct tb_tunnel *tunnel; 1884 1938 1885 1939 /* ··· 1995 1921 available_up, available_down); 1996 1922 1997 1923 tunnel = tb_tunnel_alloc_dp(tb, in, out, link_nr, available_up, 1998 - available_down); 1924 + available_down, tb_dp_tunnel_active, 1925 + tb_domain_get(tb)); 1999 1926 if (!tunnel) { 2000 1927 tb_port_dbg(out, "could not allocate DP tunnel\n"); 2001 1928 goto err_reclaim_usb; 2002 1929 } 2003 1930 2004 - if (tb_tunnel_activate(tunnel)) { 1931 + list_add_tail(&tunnel->list, &tcm->tunnel_list); 1932 + 1933 + ret = tb_tunnel_activate(tunnel); 1934 + if (ret && ret != -EINPROGRESS) { 2005 1935 tb_port_info(out, "DP tunnel activation failed, aborting\n"); 1936 + list_del(&tunnel->list); 2006 1937 goto err_free; 2007 1938 } 2008 1939 2009 - /* If fail reading tunnel's consumed bandwidth, tear it down */ 2010 - ret = tb_tunnel_consumed_bandwidth(tunnel, &consumed_up, &consumed_down); 2011 - if (ret) 2012 - goto err_deactivate; 1940 + return; 2013 1941 2014 - list_add_tail(&tunnel->list, &tcm->tunnel_list); 2015 - 2016 - tb_reclaim_usb3_bandwidth(tb, in, out); 2017 - /* 2018 - * Transition the links to asymmetric if the consumption exceeds 2019 - * the threshold. 2020 - */ 2021 - tb_configure_asym(tb, in, out, consumed_up, consumed_down); 2022 - 2023 - /* Update the domain with the new bandwidth estimation */ 2024 - tb_recalc_estimated_bandwidth(tb); 2025 - 2026 - /* 2027 - * In case of DP tunnel exists, change host router's 1st children 2028 - * TMU mode to HiFi for CL0s to work. 2029 - */ 2030 - tb_increase_tmu_accuracy(tunnel); 2031 - return true; 2032 - 2033 - err_deactivate: 2034 - tb_tunnel_deactivate(tunnel); 2035 1942 err_free: 2036 - tb_tunnel_free(tunnel); 1943 + tb_tunnel_put(tunnel); 2037 1944 err_reclaim_usb: 2038 1945 tb_reclaim_usb3_bandwidth(tb, in, out); 1946 + tb_domain_put(tb); 2039 1947 err_detach_group: 2040 1948 tb_detach_bandwidth_group(in); 2041 1949 err_dealloc_dp: ··· 2027 1971 pm_runtime_put_autosuspend(&out->sw->dev); 2028 1972 pm_runtime_mark_last_busy(&in->sw->dev); 2029 1973 pm_runtime_put_autosuspend(&in->sw->dev); 2030 - 2031 - return false; 2032 1974 } 2033 1975 2034 1976 static void tb_tunnel_dp(struct tb *tb) ··· 2144 2090 } 2145 2091 } 2146 2092 2147 - static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port) 2093 + static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port, 2094 + const char *reason) 2148 2095 { 2149 2096 struct tb_port *in, *out; 2150 2097 struct tb_tunnel *tunnel; 2151 2098 2152 2099 if (tb_port_is_dpin(port)) { 2153 - tb_port_dbg(port, "DP IN resource unavailable\n"); 2100 + tb_port_dbg(port, "DP IN resource unavailable: %s\n", reason); 2154 2101 in = port; 2155 2102 out = NULL; 2156 2103 } else { 2157 - tb_port_dbg(port, "DP OUT resource unavailable\n"); 2104 + tb_port_dbg(port, "DP OUT resource unavailable: %s\n", reason); 2158 2105 in = NULL; 2159 2106 out = port; 2160 2107 } ··· 2237 2182 2238 2183 tb_tunnel_deactivate(tunnel); 2239 2184 list_del(&tunnel->list); 2240 - tb_tunnel_free(tunnel); 2185 + tb_tunnel_put(tunnel); 2241 2186 return 0; 2242 2187 } 2243 2188 ··· 2267 2212 if (tb_tunnel_activate(tunnel)) { 2268 2213 tb_port_info(up, 2269 2214 "PCIe tunnel activation failed, aborting\n"); 2270 - tb_tunnel_free(tunnel); 2215 + tb_tunnel_put(tunnel); 2271 2216 return -EIO; 2272 2217 } 2273 2218 ··· 2326 2271 return 0; 2327 2272 2328 2273 err_free: 2329 - tb_tunnel_free(tunnel); 2274 + tb_tunnel_put(tunnel); 2330 2275 err_clx: 2331 2276 tb_enable_clx(sw); 2332 2277 mutex_unlock(&tb->lock); ··· 2389 2334 */ 2390 2335 static void tb_handle_hotplug(struct work_struct *work) 2391 2336 { 2392 - struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work); 2337 + struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work.work); 2393 2338 struct tb *tb = ev->tb; 2394 2339 struct tb_cm *tcm = tb_priv(tb); 2395 2340 struct tb_switch *sw; ··· 2461 2406 tb_xdomain_put(xd); 2462 2407 tb_port_unconfigure_xdomain(port); 2463 2408 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) { 2464 - tb_dp_resource_unavailable(tb, port); 2409 + tb_dp_resource_unavailable(tb, port, "adapter unplug"); 2465 2410 } else if (!port->port) { 2466 2411 tb_sw_dbg(sw, "xHCI disconnect request\n"); 2467 2412 tb_switch_xhci_disconnect(sw); ··· 2694 2639 2695 2640 static void tb_handle_dp_bandwidth_request(struct work_struct *work) 2696 2641 { 2697 - struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work); 2642 + struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work.work); 2698 2643 int requested_bw, requested_up, requested_down, ret; 2699 2644 struct tb_tunnel *tunnel; 2700 2645 struct tb *tb = ev->tb; ··· 2721 2666 goto put_sw; 2722 2667 } 2723 2668 2724 - tb_port_dbg(in, "handling bandwidth allocation request\n"); 2669 + tb_port_dbg(in, "handling bandwidth allocation request, retry %d\n", ev->retry); 2725 2670 2726 2671 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, NULL); 2727 2672 if (!tunnel) { ··· 2774 2719 2775 2720 ret = tb_alloc_dp_bandwidth(tunnel, &requested_up, &requested_down); 2776 2721 if (ret) { 2777 - if (ret == -ENOBUFS) 2722 + if (ret == -ENOBUFS) { 2778 2723 tb_tunnel_warn(tunnel, 2779 2724 "not enough bandwidth available\n"); 2780 - else 2725 + } else if (ret == -ENOTCONN) { 2726 + tb_tunnel_dbg(tunnel, "not active yet\n"); 2727 + /* 2728 + * We got bandwidth allocation request but the 2729 + * tunnel is not yet active. This means that 2730 + * tb_dp_tunnel_active() is not yet called for 2731 + * this tunnel. Allow it some time and retry 2732 + * this request a couple of times. 2733 + */ 2734 + if (ev->retry < TB_BW_ALLOC_RETRIES) { 2735 + tb_tunnel_dbg(tunnel, 2736 + "retrying bandwidth allocation request\n"); 2737 + tb_queue_dp_bandwidth_request(tb, ev->route, 2738 + ev->port, 2739 + ev->retry + 1, 2740 + msecs_to_jiffies(50)); 2741 + } else { 2742 + tb_tunnel_dbg(tunnel, 2743 + "run out of retries, failing the request"); 2744 + } 2745 + } else { 2781 2746 tb_tunnel_warn(tunnel, 2782 2747 "failed to change bandwidth allocation\n"); 2748 + } 2783 2749 } else { 2784 2750 tb_tunnel_dbg(tunnel, 2785 2751 "bandwidth allocation changed to %d/%d Mb/s\n", ··· 2821 2745 kfree(ev); 2822 2746 } 2823 2747 2824 - static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port) 2748 + static void tb_queue_dp_bandwidth_request(struct tb *tb, u64 route, u8 port, 2749 + int retry, unsigned long delay) 2825 2750 { 2826 2751 struct tb_hotplug_event *ev; 2827 2752 ··· 2833 2756 ev->tb = tb; 2834 2757 ev->route = route; 2835 2758 ev->port = port; 2836 - INIT_WORK(&ev->work, tb_handle_dp_bandwidth_request); 2837 - queue_work(tb->wq, &ev->work); 2759 + ev->retry = retry; 2760 + INIT_DELAYED_WORK(&ev->work, tb_handle_dp_bandwidth_request); 2761 + queue_delayed_work(tb->wq, &ev->work, delay); 2838 2762 } 2839 2763 2840 2764 static void tb_handle_notification(struct tb *tb, u64 route, ··· 2855 2777 if (tb_cfg_ack_notification(tb->ctl, route, error)) 2856 2778 tb_warn(tb, "could not ack notification on %llx\n", 2857 2779 route); 2858 - tb_queue_dp_bandwidth_request(tb, route, error->port); 2780 + tb_queue_dp_bandwidth_request(tb, route, error->port, 0, 0); 2859 2781 break; 2860 2782 2861 2783 default: ··· 2910 2832 */ 2911 2833 if (tb_tunnel_is_dma(tunnel)) 2912 2834 tb_tunnel_deactivate(tunnel); 2913 - tb_tunnel_free(tunnel); 2835 + tb_tunnel_put(tunnel); 2914 2836 } 2915 2837 tb_switch_remove(tb->root_switch); 2916 2838 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ ··· 3106 3028 if (tb_tunnel_is_usb3(tunnel)) 3107 3029 usb3_delay = 500; 3108 3030 tb_tunnel_deactivate(tunnel); 3109 - tb_tunnel_free(tunnel); 3031 + tb_tunnel_put(tunnel); 3110 3032 } 3111 3033 3112 3034 /* Re-create our tunnels now */ ··· 3117 3039 /* Only need to do it once */ 3118 3040 usb3_delay = 0; 3119 3041 } 3120 - tb_tunnel_restart(tunnel); 3042 + tb_tunnel_activate(tunnel); 3121 3043 } 3122 3044 if (!list_empty(&tcm->tunnel_list)) { 3123 3045 /* ··· 3227 3149 tb_free_invalid_tunnels(tb); 3228 3150 tb_restore_children(tb->root_switch); 3229 3151 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) 3230 - tb_tunnel_restart(tunnel); 3152 + tb_tunnel_activate(tunnel); 3231 3153 tb_switch_enter_redrive(tb->root_switch); 3232 3154 tcm->hotplug_active = true; 3233 3155 mutex_unlock(&tb->lock);
+5
drivers/thunderbolt/tb.h
··· 9 9 #ifndef TB_H_ 10 10 #define TB_H_ 11 11 12 + #include <linux/debugfs.h> 12 13 #include <linux/nvmem-provider.h> 13 14 #include <linux/pci.h> 14 15 #include <linux/thunderbolt.h> ··· 161 160 * @max_pcie_credits: Router preferred number of buffers for PCIe 162 161 * @max_dma_credits: Router preferred number of buffers for DMA/P2P 163 162 * @clx: CLx states on the upstream link of the router 163 + * @drom_blob: DROM debugfs blob wrapper 164 164 * 165 165 * When the switch is being added or removed to the domain (other 166 166 * switches) you need to have domain lock held. ··· 214 212 unsigned int max_pcie_credits; 215 213 unsigned int max_dma_credits; 216 214 unsigned int clx; 215 + #ifdef CONFIG_DEBUG_FS 216 + struct debugfs_blob_wrapper drom_blob; 217 + #endif 217 218 }; 218 219 219 220 /**
+45 -45
drivers/thunderbolt/test.c
··· 1382 1382 KUNIT_EXPECT_PTR_EQ(test, tunnel2->paths[1]->hops[0].in_port, up); 1383 1383 KUNIT_EXPECT_PTR_EQ(test, tunnel2->paths[1]->hops[1].out_port, down); 1384 1384 1385 - tb_tunnel_free(tunnel2); 1386 - tb_tunnel_free(tunnel1); 1385 + tb_tunnel_put(tunnel2); 1386 + tb_tunnel_put(tunnel1); 1387 1387 } 1388 1388 1389 1389 static void tb_test_tunnel_dp(struct kunit *test) ··· 1406 1406 in = &host->ports[5]; 1407 1407 out = &dev->ports[13]; 1408 1408 1409 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 1409 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 1410 1410 KUNIT_ASSERT_NOT_NULL(test, tunnel); 1411 1411 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP); 1412 1412 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in); ··· 1421 1421 KUNIT_ASSERT_EQ(test, tunnel->paths[2]->path_length, 2); 1422 1422 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[0].in_port, out); 1423 1423 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[1].out_port, in); 1424 - tb_tunnel_free(tunnel); 1424 + tb_tunnel_put(tunnel); 1425 1425 } 1426 1426 1427 1427 static void tb_test_tunnel_dp_chain(struct kunit *test) ··· 1452 1452 in = &host->ports[5]; 1453 1453 out = &dev4->ports[14]; 1454 1454 1455 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 1455 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 1456 1456 KUNIT_ASSERT_NOT_NULL(test, tunnel); 1457 1457 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP); 1458 1458 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in); ··· 1467 1467 KUNIT_ASSERT_EQ(test, tunnel->paths[2]->path_length, 3); 1468 1468 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[0].in_port, out); 1469 1469 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[2].out_port, in); 1470 - tb_tunnel_free(tunnel); 1470 + tb_tunnel_put(tunnel); 1471 1471 } 1472 1472 1473 1473 static void tb_test_tunnel_dp_tree(struct kunit *test) ··· 1502 1502 in = &dev2->ports[13]; 1503 1503 out = &dev5->ports[13]; 1504 1504 1505 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 1505 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 1506 1506 KUNIT_ASSERT_NOT_NULL(test, tunnel); 1507 1507 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP); 1508 1508 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in); ··· 1517 1517 KUNIT_ASSERT_EQ(test, tunnel->paths[2]->path_length, 4); 1518 1518 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[0].in_port, out); 1519 1519 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[3].out_port, in); 1520 - tb_tunnel_free(tunnel); 1520 + tb_tunnel_put(tunnel); 1521 1521 } 1522 1522 1523 1523 static void tb_test_tunnel_dp_max_length(struct kunit *test) ··· 1567 1567 in = &dev6->ports[13]; 1568 1568 out = &dev12->ports[13]; 1569 1569 1570 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 1570 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 1571 1571 KUNIT_ASSERT_NOT_NULL(test, tunnel); 1572 1572 KUNIT_EXPECT_EQ(test, tunnel->type, TB_TUNNEL_DP); 1573 1573 KUNIT_EXPECT_PTR_EQ(test, tunnel->src_port, in); ··· 1597 1597 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[6].out_port, 1598 1598 &host->ports[1]); 1599 1599 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[2]->hops[12].out_port, in); 1600 - tb_tunnel_free(tunnel); 1600 + tb_tunnel_put(tunnel); 1601 1601 } 1602 1602 1603 1603 static void tb_test_tunnel_3dp(struct kunit *test) ··· 1637 1637 out2 = &dev5->ports[13]; 1638 1638 out3 = &dev4->ports[14]; 1639 1639 1640 - tunnel1 = tb_tunnel_alloc_dp(NULL, in1, out1, 1, 0, 0); 1640 + tunnel1 = tb_tunnel_alloc_dp(NULL, in1, out1, 1, 0, 0, NULL, NULL); 1641 1641 KUNIT_ASSERT_TRUE(test, tunnel1 != NULL); 1642 1642 KUNIT_EXPECT_EQ(test, tunnel1->type, TB_TUNNEL_DP); 1643 1643 KUNIT_EXPECT_PTR_EQ(test, tunnel1->src_port, in1); ··· 1645 1645 KUNIT_ASSERT_EQ(test, tunnel1->npaths, 3); 1646 1646 KUNIT_ASSERT_EQ(test, tunnel1->paths[0]->path_length, 3); 1647 1647 1648 - tunnel2 = tb_tunnel_alloc_dp(NULL, in2, out2, 1, 0, 0); 1648 + tunnel2 = tb_tunnel_alloc_dp(NULL, in2, out2, 1, 0, 0, NULL, NULL); 1649 1649 KUNIT_ASSERT_TRUE(test, tunnel2 != NULL); 1650 1650 KUNIT_EXPECT_EQ(test, tunnel2->type, TB_TUNNEL_DP); 1651 1651 KUNIT_EXPECT_PTR_EQ(test, tunnel2->src_port, in2); ··· 1653 1653 KUNIT_ASSERT_EQ(test, tunnel2->npaths, 3); 1654 1654 KUNIT_ASSERT_EQ(test, tunnel2->paths[0]->path_length, 4); 1655 1655 1656 - tunnel3 = tb_tunnel_alloc_dp(NULL, in3, out3, 1, 0, 0); 1656 + tunnel3 = tb_tunnel_alloc_dp(NULL, in3, out3, 1, 0, 0, NULL, NULL); 1657 1657 KUNIT_ASSERT_TRUE(test, tunnel3 != NULL); 1658 1658 KUNIT_EXPECT_EQ(test, tunnel3->type, TB_TUNNEL_DP); 1659 1659 KUNIT_EXPECT_PTR_EQ(test, tunnel3->src_port, in3); ··· 1661 1661 KUNIT_ASSERT_EQ(test, tunnel3->npaths, 3); 1662 1662 KUNIT_ASSERT_EQ(test, tunnel3->paths[0]->path_length, 3); 1663 1663 1664 - tb_tunnel_free(tunnel2); 1665 - tb_tunnel_free(tunnel1); 1664 + tb_tunnel_put(tunnel2); 1665 + tb_tunnel_put(tunnel1); 1666 1666 } 1667 1667 1668 1668 static void tb_test_tunnel_usb3(struct kunit *test) ··· 1716 1716 KUNIT_EXPECT_PTR_EQ(test, tunnel2->paths[1]->hops[0].in_port, up); 1717 1717 KUNIT_EXPECT_PTR_EQ(test, tunnel2->paths[1]->hops[1].out_port, down); 1718 1718 1719 - tb_tunnel_free(tunnel2); 1720 - tb_tunnel_free(tunnel1); 1719 + tb_tunnel_put(tunnel2); 1720 + tb_tunnel_put(tunnel1); 1721 1721 } 1722 1722 1723 1723 static void tb_test_tunnel_port_on_path(struct kunit *test) ··· 1750 1750 in = &dev2->ports[13]; 1751 1751 out = &dev5->ports[13]; 1752 1752 1753 - dp_tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 1753 + dp_tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 1754 1754 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel); 1755 1755 1756 1756 KUNIT_EXPECT_TRUE(test, tb_tunnel_port_on_path(dp_tunnel, in)); ··· 1783 1783 port = &dev4->ports[1]; 1784 1784 KUNIT_EXPECT_FALSE(test, tb_tunnel_port_on_path(dp_tunnel, port)); 1785 1785 1786 - tb_tunnel_free(dp_tunnel); 1786 + tb_tunnel_put(dp_tunnel); 1787 1787 } 1788 1788 1789 1789 static void tb_test_tunnel_dma(struct kunit *test) ··· 1826 1826 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[0].out_port, port); 1827 1827 KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[0].next_hop_index, 8); 1828 1828 1829 - tb_tunnel_free(tunnel); 1829 + tb_tunnel_put(tunnel); 1830 1830 } 1831 1831 1832 1832 static void tb_test_tunnel_dma_rx(struct kunit *test) ··· 1863 1863 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, nhi); 1864 1864 KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 2); 1865 1865 1866 - tb_tunnel_free(tunnel); 1866 + tb_tunnel_put(tunnel); 1867 1867 } 1868 1868 1869 1869 static void tb_test_tunnel_dma_tx(struct kunit *test) ··· 1900 1900 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[0]->hops[0].out_port, port); 1901 1901 KUNIT_EXPECT_EQ(test, tunnel->paths[0]->hops[0].next_hop_index, 15); 1902 1902 1903 - tb_tunnel_free(tunnel); 1903 + tb_tunnel_put(tunnel); 1904 1904 } 1905 1905 1906 1906 static void tb_test_tunnel_dma_chain(struct kunit *test) ··· 1966 1966 KUNIT_EXPECT_PTR_EQ(test, tunnel->paths[1]->hops[2].out_port, port); 1967 1967 KUNIT_EXPECT_EQ(test, tunnel->paths[1]->hops[2].next_hop_index, 8); 1968 1968 1969 - tb_tunnel_free(tunnel); 1969 + tb_tunnel_put(tunnel); 1970 1970 } 1971 1971 1972 1972 static void tb_test_tunnel_dma_match(struct kunit *test) ··· 1993 1993 KUNIT_ASSERT_TRUE(test, tb_tunnel_match_dma(tunnel, -1, -1, -1, -1)); 1994 1994 KUNIT_ASSERT_FALSE(test, tb_tunnel_match_dma(tunnel, 8, -1, 8, -1)); 1995 1995 1996 - tb_tunnel_free(tunnel); 1996 + tb_tunnel_put(tunnel); 1997 1997 1998 1998 tunnel = tb_tunnel_alloc_dma(NULL, nhi, port, 15, 1, -1, -1); 1999 1999 KUNIT_ASSERT_NOT_NULL(test, tunnel); ··· 2005 2005 KUNIT_ASSERT_FALSE(test, tb_tunnel_match_dma(tunnel, -1, -1, 15, 1)); 2006 2006 KUNIT_ASSERT_FALSE(test, tb_tunnel_match_dma(tunnel, 15, 11, -1, -1)); 2007 2007 2008 - tb_tunnel_free(tunnel); 2008 + tb_tunnel_put(tunnel); 2009 2009 2010 2010 tunnel = tb_tunnel_alloc_dma(NULL, nhi, port, -1, -1, 15, 11); 2011 2011 KUNIT_ASSERT_NOT_NULL(test, tunnel); ··· 2017 2017 KUNIT_ASSERT_FALSE(test, tb_tunnel_match_dma(tunnel, -1, -1, 10, 11)); 2018 2018 KUNIT_ASSERT_FALSE(test, tb_tunnel_match_dma(tunnel, 15, 11, -1, -1)); 2019 2019 2020 - tb_tunnel_free(tunnel); 2020 + tb_tunnel_put(tunnel); 2021 2021 } 2022 2022 2023 2023 static void tb_test_credit_alloc_legacy_not_bonded(struct kunit *test) ··· 2050 2050 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2051 2051 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 16U); 2052 2052 2053 - tb_tunnel_free(tunnel); 2053 + tb_tunnel_put(tunnel); 2054 2054 } 2055 2055 2056 2056 static void tb_test_credit_alloc_legacy_bonded(struct kunit *test) ··· 2083 2083 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2084 2084 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 32U); 2085 2085 2086 - tb_tunnel_free(tunnel); 2086 + tb_tunnel_put(tunnel); 2087 2087 } 2088 2088 2089 2089 static void tb_test_credit_alloc_pcie(struct kunit *test) ··· 2116 2116 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2117 2117 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 64U); 2118 2118 2119 - tb_tunnel_free(tunnel); 2119 + tb_tunnel_put(tunnel); 2120 2120 } 2121 2121 2122 2122 static void tb_test_credit_alloc_without_dp(struct kunit *test) ··· 2166 2166 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2167 2167 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 64U); 2168 2168 2169 - tb_tunnel_free(tunnel); 2169 + tb_tunnel_put(tunnel); 2170 2170 } 2171 2171 2172 2172 static void tb_test_credit_alloc_dp(struct kunit *test) ··· 2182 2182 in = &host->ports[5]; 2183 2183 out = &dev->ports[14]; 2184 2184 2185 - tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 2185 + tunnel = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 2186 2186 KUNIT_ASSERT_NOT_NULL(test, tunnel); 2187 2187 KUNIT_ASSERT_EQ(test, tunnel->npaths, (size_t)3); 2188 2188 ··· 2210 2210 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2211 2211 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 1U); 2212 2212 2213 - tb_tunnel_free(tunnel); 2213 + tb_tunnel_put(tunnel); 2214 2214 } 2215 2215 2216 2216 static void tb_test_credit_alloc_usb3(struct kunit *test) ··· 2243 2243 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2244 2244 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 32U); 2245 2245 2246 - tb_tunnel_free(tunnel); 2246 + tb_tunnel_put(tunnel); 2247 2247 } 2248 2248 2249 2249 static void tb_test_credit_alloc_dma(struct kunit *test) ··· 2279 2279 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2280 2280 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 14U); 2281 2281 2282 - tb_tunnel_free(tunnel); 2282 + tb_tunnel_put(tunnel); 2283 2283 } 2284 2284 2285 2285 static void tb_test_credit_alloc_dma_multiple(struct kunit *test) ··· 2356 2356 * Release the first DMA tunnel. That should make 14 buffers 2357 2357 * available for the next tunnel. 2358 2358 */ 2359 - tb_tunnel_free(tunnel1); 2359 + tb_tunnel_put(tunnel1); 2360 2360 2361 2361 tunnel3 = tb_tunnel_alloc_dma(NULL, nhi, port, 10, 3, 10, 3); 2362 2362 KUNIT_ASSERT_NOT_NULL(test, tunnel3); ··· 2375 2375 KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U); 2376 2376 KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 14U); 2377 2377 2378 - tb_tunnel_free(tunnel3); 2379 - tb_tunnel_free(tunnel2); 2378 + tb_tunnel_put(tunnel3); 2379 + tb_tunnel_put(tunnel2); 2380 2380 } 2381 2381 2382 2382 static struct tb_tunnel *TB_TEST_PCIE_TUNNEL(struct kunit *test, ··· 2418 2418 2419 2419 in = &host->ports[5]; 2420 2420 out = &dev->ports[13]; 2421 - dp_tunnel1 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 2421 + dp_tunnel1 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 2422 2422 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel1); 2423 2423 KUNIT_ASSERT_EQ(test, dp_tunnel1->npaths, (size_t)3); 2424 2424 ··· 2455 2455 2456 2456 in = &host->ports[6]; 2457 2457 out = &dev->ports[14]; 2458 - dp_tunnel2 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0); 2458 + dp_tunnel2 = tb_tunnel_alloc_dp(NULL, in, out, 1, 0, 0, NULL, NULL); 2459 2459 KUNIT_ASSERT_NOT_NULL(test, dp_tunnel2); 2460 2460 KUNIT_ASSERT_EQ(test, dp_tunnel2->npaths, (size_t)3); 2461 2461 ··· 2595 2595 dma_tunnel1 = TB_TEST_DMA_TUNNEL1(test, host, dev); 2596 2596 dma_tunnel2 = TB_TEST_DMA_TUNNEL2(test, host, dev); 2597 2597 2598 - tb_tunnel_free(dma_tunnel2); 2599 - tb_tunnel_free(dma_tunnel1); 2600 - tb_tunnel_free(usb3_tunnel); 2601 - tb_tunnel_free(dp_tunnel2); 2602 - tb_tunnel_free(dp_tunnel1); 2603 - tb_tunnel_free(pcie_tunnel); 2598 + tb_tunnel_put(dma_tunnel2); 2599 + tb_tunnel_put(dma_tunnel1); 2600 + tb_tunnel_put(usb3_tunnel); 2601 + tb_tunnel_put(dp_tunnel2); 2602 + tb_tunnel_put(dp_tunnel1); 2603 + tb_tunnel_put(pcie_tunnel); 2604 2604 } 2605 2605 2606 2606 static const u32 root_directory[] = {
+249 -157
drivers/thunderbolt/tunnel.c
··· 70 70 #define USB4_V2_PCI_MIN_BANDWIDTH (1500 * TB_PCI_WEIGHT) 71 71 #define USB4_V2_USB3_MIN_BANDWIDTH (1500 * TB_USB3_WEIGHT) 72 72 73 + /* 74 + * According to VESA spec, the DPRX negotiation shall compete in 5 75 + * seconds after tunnel is established. Since at least i915 can runtime 76 + * suspend if there is nothing connected, and that it polls any new 77 + * connections every 10 seconds, we use 12 seconds here. 78 + * 79 + * These are in ms. 80 + */ 81 + #define TB_DPRX_TIMEOUT 12000 82 + #define TB_DPRX_WAIT_TIMEOUT 25 83 + #define TB_DPRX_POLL_DELAY 50 84 + 85 + static int dprx_timeout = TB_DPRX_TIMEOUT; 86 + module_param(dprx_timeout, int, 0444); 87 + MODULE_PARM_DESC(dprx_timeout, 88 + "DPRX capability read timeout in ms, -1 waits forever (default: " 89 + __MODULE_STRING(TB_DPRX_TIMEOUT) ")"); 90 + 73 91 static unsigned int dma_credits = TB_DMA_CREDITS; 74 92 module_param(dma_credits, uint, 0444); 75 93 MODULE_PARM_DESC(dma_credits, "specify custom credits for DMA tunnels (default: " ··· 99 81 "enable bandwidth allocation mode if supported (default: true)"); 100 82 101 83 static const char * const tb_tunnel_names[] = { "PCI", "DP", "DMA", "USB3" }; 84 + 85 + /* Synchronizes kref_get()/put() of struct tb_tunnel */ 86 + static DEFINE_MUTEX(tb_tunnel_lock); 102 87 103 88 static inline unsigned int tb_usable_credits(const struct tb_port *port) 104 89 { ··· 176 155 177 156 tunnel->paths = kcalloc(npaths, sizeof(tunnel->paths[0]), GFP_KERNEL); 178 157 if (!tunnel->paths) { 179 - tb_tunnel_free(tunnel); 158 + kfree(tunnel); 180 159 return NULL; 181 160 } 182 161 ··· 184 163 tunnel->tb = tb; 185 164 tunnel->npaths = npaths; 186 165 tunnel->type = type; 166 + kref_init(&tunnel->kref); 187 167 188 168 return tunnel; 169 + } 170 + 171 + static void tb_tunnel_get(struct tb_tunnel *tunnel) 172 + { 173 + mutex_lock(&tb_tunnel_lock); 174 + kref_get(&tunnel->kref); 175 + mutex_unlock(&tb_tunnel_lock); 176 + } 177 + 178 + static void tb_tunnel_destroy(struct kref *kref) 179 + { 180 + struct tb_tunnel *tunnel = container_of(kref, typeof(*tunnel), kref); 181 + int i; 182 + 183 + if (tunnel->destroy) 184 + tunnel->destroy(tunnel); 185 + 186 + for (i = 0; i < tunnel->npaths; i++) { 187 + if (tunnel->paths[i]) 188 + tb_path_free(tunnel->paths[i]); 189 + } 190 + 191 + kfree(tunnel->paths); 192 + kfree(tunnel); 193 + } 194 + 195 + void tb_tunnel_put(struct tb_tunnel *tunnel) 196 + { 197 + mutex_lock(&tb_tunnel_lock); 198 + kref_put(&tunnel->kref, tb_tunnel_destroy); 199 + mutex_unlock(&tb_tunnel_lock); 189 200 } 190 201 191 202 static int tb_pci_set_ext_encapsulation(struct tb_tunnel *tunnel, bool enable) ··· 408 355 err_deactivate: 409 356 tb_tunnel_deactivate(tunnel); 410 357 err_free: 411 - tb_tunnel_free(tunnel); 358 + tb_tunnel_put(tunnel); 412 359 413 360 return NULL; 414 361 } ··· 457 404 return tunnel; 458 405 459 406 err_free: 460 - tb_tunnel_free(tunnel); 407 + tb_tunnel_put(tunnel); 461 408 return NULL; 462 409 } 463 410 ··· 904 851 return 0; 905 852 } 906 853 907 - static int tb_dp_init(struct tb_tunnel *tunnel) 854 + static int tb_dp_pre_activate(struct tb_tunnel *tunnel) 908 855 { 909 856 struct tb_port *in = tunnel->src_port; 910 857 struct tb_switch *sw = in->sw; ··· 930 877 return tb_dp_bandwidth_alloc_mode_enable(tunnel); 931 878 } 932 879 933 - static void tb_dp_deinit(struct tb_tunnel *tunnel) 880 + static void tb_dp_post_deactivate(struct tb_tunnel *tunnel) 934 881 { 935 882 struct tb_port *in = tunnel->src_port; 936 883 ··· 940 887 usb4_dp_port_set_cm_bandwidth_mode_supported(in, false); 941 888 tb_tunnel_dbg(tunnel, "bandwidth allocation mode disabled\n"); 942 889 } 890 + } 891 + 892 + static ktime_t dprx_timeout_to_ktime(int timeout_msec) 893 + { 894 + return timeout_msec >= 0 ? 895 + ktime_add_ms(ktime_get(), timeout_msec) : KTIME_MAX; 896 + } 897 + 898 + static int tb_dp_wait_dprx(struct tb_tunnel *tunnel, int timeout_msec) 899 + { 900 + ktime_t timeout = dprx_timeout_to_ktime(timeout_msec); 901 + struct tb_port *in = tunnel->src_port; 902 + 903 + /* 904 + * Wait for DPRX done. Normally it should be already set for 905 + * active tunnel. 906 + */ 907 + do { 908 + u32 val; 909 + int ret; 910 + 911 + ret = tb_port_read(in, &val, TB_CFG_PORT, 912 + in->cap_adap + DP_COMMON_CAP, 1); 913 + if (ret) 914 + return ret; 915 + 916 + if (val & DP_COMMON_CAP_DPRX_DONE) 917 + return 0; 918 + 919 + usleep_range(100, 150); 920 + } while (ktime_before(ktime_get(), timeout)); 921 + 922 + tb_tunnel_dbg(tunnel, "DPRX read timeout\n"); 923 + return -ETIMEDOUT; 924 + } 925 + 926 + static void tb_dp_dprx_work(struct work_struct *work) 927 + { 928 + struct tb_tunnel *tunnel = container_of(work, typeof(*tunnel), dprx_work.work); 929 + struct tb *tb = tunnel->tb; 930 + 931 + if (!tunnel->dprx_canceled) { 932 + mutex_lock(&tb->lock); 933 + if (tb_dp_is_usb4(tunnel->src_port->sw) && 934 + tb_dp_wait_dprx(tunnel, TB_DPRX_WAIT_TIMEOUT)) { 935 + if (ktime_before(ktime_get(), tunnel->dprx_timeout)) { 936 + queue_delayed_work(tb->wq, &tunnel->dprx_work, 937 + msecs_to_jiffies(TB_DPRX_POLL_DELAY)); 938 + mutex_unlock(&tb->lock); 939 + return; 940 + } 941 + } else { 942 + tunnel->state = TB_TUNNEL_ACTIVE; 943 + } 944 + mutex_unlock(&tb->lock); 945 + } 946 + 947 + if (tunnel->callback) 948 + tunnel->callback(tunnel, tunnel->callback_data); 949 + } 950 + 951 + static int tb_dp_dprx_start(struct tb_tunnel *tunnel) 952 + { 953 + /* 954 + * Bump up the reference to keep the tunnel around. It will be 955 + * dropped in tb_dp_dprx_stop() once the tunnel is deactivated. 956 + */ 957 + tb_tunnel_get(tunnel); 958 + 959 + if (tunnel->callback) { 960 + tunnel->dprx_timeout = dprx_timeout_to_ktime(dprx_timeout); 961 + queue_delayed_work(tunnel->tb->wq, &tunnel->dprx_work, 0); 962 + return -EINPROGRESS; 963 + } 964 + 965 + return tb_dp_is_usb4(tunnel->src_port->sw) ? 966 + tb_dp_wait_dprx(tunnel, dprx_timeout) : 0; 967 + } 968 + 969 + static void tb_dp_dprx_stop(struct tb_tunnel *tunnel) 970 + { 971 + tunnel->dprx_canceled = true; 972 + cancel_delayed_work(&tunnel->dprx_work); 973 + tb_tunnel_put(tunnel); 943 974 } 944 975 945 976 static int tb_dp_activate(struct tb_tunnel *tunnel, bool active) ··· 1047 910 paths[TB_DP_AUX_PATH_IN]->hops[0].in_hop_index, 1048 911 paths[TB_DP_AUX_PATH_OUT]->hops[last].next_hop_index); 1049 912 } else { 913 + tb_dp_dprx_stop(tunnel); 1050 914 tb_dp_port_hpd_clear(tunnel->src_port); 1051 915 tb_dp_port_set_hops(tunnel->src_port, 0, 0, 0); 1052 916 if (tb_port_is_dpout(tunnel->dst_port)) ··· 1058 920 if (ret) 1059 921 return ret; 1060 922 1061 - if (tb_port_is_dpout(tunnel->dst_port)) 1062 - return tb_dp_port_enable(tunnel->dst_port, active); 923 + if (tb_port_is_dpout(tunnel->dst_port)) { 924 + ret = tb_dp_port_enable(tunnel->dst_port, active); 925 + if (ret) 926 + return ret; 927 + } 1063 928 1064 - return 0; 929 + return active ? tb_dp_dprx_start(tunnel) : 0; 1065 930 } 1066 931 1067 932 /** ··· 1217 1076 return 0; 1218 1077 } 1219 1078 1220 - static int tb_dp_wait_dprx(struct tb_tunnel *tunnel, int timeout_msec) 1221 - { 1222 - ktime_t timeout = ktime_add_ms(ktime_get(), timeout_msec); 1223 - struct tb_port *in = tunnel->src_port; 1224 - 1225 - /* 1226 - * Wait for DPRX done. Normally it should be already set for 1227 - * active tunnel. 1228 - */ 1229 - do { 1230 - u32 val; 1231 - int ret; 1232 - 1233 - ret = tb_port_read(in, &val, TB_CFG_PORT, 1234 - in->cap_adap + DP_COMMON_CAP, 1); 1235 - if (ret) 1236 - return ret; 1237 - 1238 - if (val & DP_COMMON_CAP_DPRX_DONE) { 1239 - tb_tunnel_dbg(tunnel, "DPRX read done\n"); 1240 - return 0; 1241 - } 1242 - usleep_range(100, 150); 1243 - } while (ktime_before(ktime_get(), timeout)); 1244 - 1245 - tb_tunnel_dbg(tunnel, "DPRX read timeout\n"); 1246 - return -ETIMEDOUT; 1247 - } 1248 - 1249 1079 /* Read cap from tunnel DP IN */ 1250 1080 static int tb_dp_read_cap(struct tb_tunnel *tunnel, unsigned int cap, u32 *rate, 1251 1081 u32 *lanes) ··· 1280 1168 int ret; 1281 1169 1282 1170 if (tb_dp_is_usb4(sw)) { 1283 - /* 1284 - * On USB4 routers check if the bandwidth allocation 1285 - * mode is enabled first and then read the bandwidth 1286 - * through those registers. 1287 - */ 1288 - ret = tb_dp_bandwidth_mode_consumed_bandwidth(tunnel, consumed_up, 1289 - consumed_down); 1290 - if (ret < 0) { 1291 - if (ret != -EOPNOTSUPP) 1171 + ret = tb_dp_wait_dprx(tunnel, 0); 1172 + if (ret) { 1173 + if (ret == -ETIMEDOUT) { 1174 + /* 1175 + * While we wait for DPRX complete the 1176 + * tunnel consumes as much as it had 1177 + * been reserved initially. 1178 + */ 1179 + ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, 1180 + &rate, &lanes); 1181 + if (ret) 1182 + return ret; 1183 + } else { 1292 1184 return ret; 1293 - } else if (!ret) { 1294 - return 0; 1185 + } 1186 + } else { 1187 + /* 1188 + * On USB4 routers check if the bandwidth allocation 1189 + * mode is enabled first and then read the bandwidth 1190 + * through those registers. 1191 + */ 1192 + ret = tb_dp_bandwidth_mode_consumed_bandwidth(tunnel, consumed_up, 1193 + consumed_down); 1194 + if (ret < 0) { 1195 + if (ret != -EOPNOTSUPP) 1196 + return ret; 1197 + } else if (!ret) { 1198 + return 0; 1199 + } 1200 + ret = tb_dp_read_cap(tunnel, DP_COMMON_CAP, &rate, &lanes); 1201 + if (ret) 1202 + return ret; 1295 1203 } 1296 - /* 1297 - * Then see if the DPRX negotiation is ready and if yes 1298 - * return that bandwidth (it may be smaller than the 1299 - * reduced one). According to VESA spec, the DPRX 1300 - * negotiation shall compete in 5 seconds after tunnel 1301 - * established. We give it 100ms extra just in case. 1302 - */ 1303 - ret = tb_dp_wait_dprx(tunnel, 5100); 1304 - if (ret) 1305 - return ret; 1306 - ret = tb_dp_read_cap(tunnel, DP_COMMON_CAP, &rate, &lanes); 1307 - if (ret) 1308 - return ret; 1309 1204 } else if (sw->generation >= 2) { 1310 1205 ret = tb_dp_read_cap(tunnel, DP_REMOTE_CAP, &rate, &lanes); 1311 1206 if (ret) ··· 1484 1365 if (!tunnel) 1485 1366 return NULL; 1486 1367 1487 - tunnel->init = tb_dp_init; 1488 - tunnel->deinit = tb_dp_deinit; 1368 + tunnel->pre_activate = tb_dp_pre_activate; 1489 1369 tunnel->activate = tb_dp_activate; 1370 + tunnel->post_deactivate = tb_dp_post_deactivate; 1490 1371 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; 1491 1372 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; 1492 1373 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; ··· 1543 1424 err_deactivate: 1544 1425 tb_tunnel_deactivate(tunnel); 1545 1426 err_free: 1546 - tb_tunnel_free(tunnel); 1427 + tb_tunnel_put(tunnel); 1547 1428 1548 1429 return NULL; 1549 1430 } ··· 1558 1439 * %0 if no available bandwidth. 1559 1440 * @max_down: Maximum available downstream bandwidth for the DP tunnel. 1560 1441 * %0 if no available bandwidth. 1442 + * @callback: Optional callback that is called when the DP tunnel is 1443 + * fully activated (or there is an error) 1444 + * @callback_data: Optional data for @callback 1561 1445 * 1562 1446 * Allocates a tunnel between @in and @out that is capable of tunneling 1563 - * Display Port traffic. 1447 + * Display Port traffic. If @callback is not %NULL it will be called 1448 + * after tb_tunnel_activate() once the tunnel has been fully activated. 1449 + * It can call tb_tunnel_is_active() to check if activation was 1450 + * successful (or if it returns %false there was some sort of issue). 1451 + * The @callback is called without @tb->lock held. 1564 1452 * 1565 - * Return: Returns a tb_tunnel on success or NULL on failure. 1453 + * Return: Returns a tb_tunnel on success or &NULL on failure. 1566 1454 */ 1567 1455 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in, 1568 1456 struct tb_port *out, int link_nr, 1569 - int max_up, int max_down) 1457 + int max_up, int max_down, 1458 + void (*callback)(struct tb_tunnel *, void *), 1459 + void *callback_data) 1570 1460 { 1571 1461 struct tb_tunnel *tunnel; 1572 1462 struct tb_path **paths; ··· 1589 1461 if (!tunnel) 1590 1462 return NULL; 1591 1463 1592 - tunnel->init = tb_dp_init; 1593 - tunnel->deinit = tb_dp_deinit; 1464 + tunnel->pre_activate = tb_dp_pre_activate; 1594 1465 tunnel->activate = tb_dp_activate; 1466 + tunnel->post_deactivate = tb_dp_post_deactivate; 1595 1467 tunnel->maximum_bandwidth = tb_dp_maximum_bandwidth; 1596 1468 tunnel->allocated_bandwidth = tb_dp_allocated_bandwidth; 1597 1469 tunnel->alloc_bandwidth = tb_dp_alloc_bandwidth; ··· 1600 1472 tunnel->dst_port = out; 1601 1473 tunnel->max_up = max_up; 1602 1474 tunnel->max_down = max_down; 1475 + tunnel->callback = callback; 1476 + tunnel->callback_data = callback_data; 1477 + INIT_DELAYED_WORK(&tunnel->dprx_work, tb_dp_dprx_work); 1603 1478 1604 1479 paths = tunnel->paths; 1605 1480 pm_support = usb4_switch_version(in->sw) >= 2; ··· 1631 1500 return tunnel; 1632 1501 1633 1502 err_free: 1634 - tb_tunnel_free(tunnel); 1503 + tb_tunnel_put(tunnel); 1635 1504 return NULL; 1636 1505 } 1637 1506 ··· 1751 1620 } 1752 1621 } 1753 1622 1754 - static void tb_dma_deinit_path(struct tb_path *path) 1623 + static void tb_dma_destroy_path(struct tb_path *path) 1755 1624 { 1756 1625 struct tb_path_hop *hop; 1757 1626 ··· 1759 1628 tb_dma_release_credits(hop); 1760 1629 } 1761 1630 1762 - static void tb_dma_deinit(struct tb_tunnel *tunnel) 1631 + static void tb_dma_destroy(struct tb_tunnel *tunnel) 1763 1632 { 1764 1633 int i; 1765 1634 1766 1635 for (i = 0; i < tunnel->npaths; i++) { 1767 1636 if (!tunnel->paths[i]) 1768 1637 continue; 1769 - tb_dma_deinit_path(tunnel->paths[i]); 1638 + tb_dma_destroy_path(tunnel->paths[i]); 1770 1639 } 1771 1640 } 1772 1641 ··· 1812 1681 1813 1682 tunnel->src_port = nhi; 1814 1683 tunnel->dst_port = dst; 1815 - tunnel->deinit = tb_dma_deinit; 1684 + tunnel->destroy = tb_dma_destroy; 1816 1685 1817 1686 credits = min_not_zero(dma_credits, nhi->sw->max_dma_credits); 1818 1687 ··· 1843 1712 return tunnel; 1844 1713 1845 1714 err_free: 1846 - tb_tunnel_free(tunnel); 1715 + tb_tunnel_put(tunnel); 1847 1716 return NULL; 1848 1717 } 1849 1718 ··· 1924 1793 return min(up_max_rate, down_max_rate); 1925 1794 } 1926 1795 1927 - static int tb_usb3_init(struct tb_tunnel *tunnel) 1796 + static int tb_usb3_pre_activate(struct tb_tunnel *tunnel) 1928 1797 { 1929 1798 tb_tunnel_dbg(tunnel, "allocating initial bandwidth %d/%d Mb/s\n", 1930 1799 tunnel->allocated_up, tunnel->allocated_down); ··· 2155 2024 tb_tunnel_dbg(tunnel, "currently allocated bandwidth %d/%d Mb/s\n", 2156 2025 tunnel->allocated_up, tunnel->allocated_down); 2157 2026 2158 - tunnel->init = tb_usb3_init; 2027 + tunnel->pre_activate = tb_usb3_pre_activate; 2159 2028 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; 2160 2029 tunnel->release_unused_bandwidth = 2161 2030 tb_usb3_release_unused_bandwidth; ··· 2169 2038 err_deactivate: 2170 2039 tb_tunnel_deactivate(tunnel); 2171 2040 err_free: 2172 - tb_tunnel_free(tunnel); 2041 + tb_tunnel_put(tunnel); 2173 2042 2174 2043 return NULL; 2175 2044 } ··· 2225 2094 path = tb_path_alloc(tb, down, TB_USB3_HOPID, up, TB_USB3_HOPID, 0, 2226 2095 "USB3 Down"); 2227 2096 if (!path) { 2228 - tb_tunnel_free(tunnel); 2097 + tb_tunnel_put(tunnel); 2229 2098 return NULL; 2230 2099 } 2231 2100 tb_usb3_init_path(path); ··· 2234 2103 path = tb_path_alloc(tb, up, TB_USB3_HOPID, down, TB_USB3_HOPID, 0, 2235 2104 "USB3 Up"); 2236 2105 if (!path) { 2237 - tb_tunnel_free(tunnel); 2106 + tb_tunnel_put(tunnel); 2238 2107 return NULL; 2239 2108 } 2240 2109 tb_usb3_init_path(path); ··· 2244 2113 tunnel->allocated_up = min(max_rate, max_up); 2245 2114 tunnel->allocated_down = min(max_rate, max_down); 2246 2115 2247 - tunnel->init = tb_usb3_init; 2116 + tunnel->pre_activate = tb_usb3_pre_activate; 2248 2117 tunnel->consumed_bandwidth = tb_usb3_consumed_bandwidth; 2249 2118 tunnel->release_unused_bandwidth = 2250 2119 tb_usb3_release_unused_bandwidth; ··· 2253 2122 } 2254 2123 2255 2124 return tunnel; 2256 - } 2257 - 2258 - /** 2259 - * tb_tunnel_free() - free a tunnel 2260 - * @tunnel: Tunnel to be freed 2261 - * 2262 - * Frees a tunnel. The tunnel does not need to be deactivated. 2263 - */ 2264 - void tb_tunnel_free(struct tb_tunnel *tunnel) 2265 - { 2266 - int i; 2267 - 2268 - if (!tunnel) 2269 - return; 2270 - 2271 - if (tunnel->deinit) 2272 - tunnel->deinit(tunnel); 2273 - 2274 - for (i = 0; i < tunnel->npaths; i++) { 2275 - if (tunnel->paths[i]) 2276 - tb_path_free(tunnel->paths[i]); 2277 - } 2278 - 2279 - kfree(tunnel->paths); 2280 - kfree(tunnel); 2281 2125 } 2282 2126 2283 2127 /** ··· 2273 2167 } 2274 2168 2275 2169 /** 2276 - * tb_tunnel_restart() - activate a tunnel after a hardware reset 2277 - * @tunnel: Tunnel to restart 2170 + * tb_tunnel_activate() - activate a tunnel 2171 + * @tunnel: Tunnel to activate 2278 2172 * 2279 - * Return: 0 on success and negative errno in case if failure 2173 + * Return: 0 on success and negative errno in case if failure. 2174 + * Specifically returns %-EINPROGRESS if the tunnel activation is still 2175 + * in progress (that's for DP tunnels to complete DPRX capabilities 2176 + * read). 2280 2177 */ 2281 - int tb_tunnel_restart(struct tb_tunnel *tunnel) 2178 + int tb_tunnel_activate(struct tb_tunnel *tunnel) 2282 2179 { 2283 2180 int res, i; 2284 2181 ··· 2298 2189 } 2299 2190 } 2300 2191 2301 - if (tunnel->init) { 2302 - res = tunnel->init(tunnel); 2192 + tunnel->state = TB_TUNNEL_ACTIVATING; 2193 + 2194 + if (tunnel->pre_activate) { 2195 + res = tunnel->pre_activate(tunnel); 2303 2196 if (res) 2304 2197 return res; 2305 2198 } ··· 2314 2203 2315 2204 if (tunnel->activate) { 2316 2205 res = tunnel->activate(tunnel, true); 2317 - if (res) 2206 + if (res) { 2207 + if (res == -EINPROGRESS) 2208 + return res; 2318 2209 goto err; 2210 + } 2319 2211 } 2320 2212 2213 + tunnel->state = TB_TUNNEL_ACTIVE; 2321 2214 return 0; 2322 2215 2323 2216 err: 2324 2217 tb_tunnel_warn(tunnel, "activation failed\n"); 2325 2218 tb_tunnel_deactivate(tunnel); 2326 2219 return res; 2327 - } 2328 - 2329 - /** 2330 - * tb_tunnel_activate() - activate a tunnel 2331 - * @tunnel: Tunnel to activate 2332 - * 2333 - * Return: Returns 0 on success or an error code on failure. 2334 - */ 2335 - int tb_tunnel_activate(struct tb_tunnel *tunnel) 2336 - { 2337 - int i; 2338 - 2339 - for (i = 0; i < tunnel->npaths; i++) { 2340 - if (tunnel->paths[i]->activated) { 2341 - tb_tunnel_WARN(tunnel, 2342 - "trying to activate an already activated tunnel\n"); 2343 - return -EINVAL; 2344 - } 2345 - } 2346 - 2347 - return tb_tunnel_restart(tunnel); 2348 2220 } 2349 2221 2350 2222 /** ··· 2347 2253 if (tunnel->paths[i] && tunnel->paths[i]->activated) 2348 2254 tb_path_deactivate(tunnel->paths[i]); 2349 2255 } 2256 + 2257 + if (tunnel->post_deactivate) 2258 + tunnel->post_deactivate(tunnel); 2259 + 2260 + tunnel->state = TB_TUNNEL_INACTIVE; 2350 2261 } 2351 2262 2352 2263 /** ··· 2378 2279 return false; 2379 2280 } 2380 2281 2381 - static bool tb_tunnel_is_active(const struct tb_tunnel *tunnel) 2282 + // Is tb_tunnel_activate() called for the tunnel 2283 + static bool tb_tunnel_is_activated(const struct tb_tunnel *tunnel) 2382 2284 { 2383 - int i; 2384 - 2385 - for (i = 0; i < tunnel->npaths; i++) { 2386 - if (!tunnel->paths[i]) 2387 - return false; 2388 - if (!tunnel->paths[i]->activated) 2389 - return false; 2390 - } 2391 - 2392 - return true; 2285 + return tunnel->state == TB_TUNNEL_ACTIVATING || tb_tunnel_is_active(tunnel); 2393 2286 } 2394 2287 2395 2288 /** ··· 2398 2307 int *max_down) 2399 2308 { 2400 2309 if (!tb_tunnel_is_active(tunnel)) 2401 - return -EINVAL; 2310 + return -ENOTCONN; 2402 2311 2403 2312 if (tunnel->maximum_bandwidth) 2404 2313 return tunnel->maximum_bandwidth(tunnel, max_up, max_down); ··· 2419 2328 int *allocated_down) 2420 2329 { 2421 2330 if (!tb_tunnel_is_active(tunnel)) 2422 - return -EINVAL; 2331 + return -ENOTCONN; 2423 2332 2424 2333 if (tunnel->allocated_bandwidth) 2425 2334 return tunnel->allocated_bandwidth(tunnel, allocated_up, ··· 2442 2351 int *alloc_down) 2443 2352 { 2444 2353 if (!tb_tunnel_is_active(tunnel)) 2445 - return -EINVAL; 2354 + return -ENOTCONN; 2446 2355 2447 2356 if (tunnel->alloc_bandwidth) 2448 2357 return tunnel->alloc_bandwidth(tunnel, alloc_up, alloc_down); ··· 2467 2376 { 2468 2377 int up_bw = 0, down_bw = 0; 2469 2378 2470 - if (!tb_tunnel_is_active(tunnel)) 2471 - goto out; 2472 - 2473 - if (tunnel->consumed_bandwidth) { 2379 + /* 2380 + * Here we need to distinguish between not active tunnel from 2381 + * tunnels that are either fully active or activation started. 2382 + * The latter is true for DP tunnels where we must report the 2383 + * consumed to be the maximum we gave it until DPRX capabilities 2384 + * read is done by the graphics driver. 2385 + */ 2386 + if (tb_tunnel_is_activated(tunnel) && tunnel->consumed_bandwidth) { 2474 2387 int ret; 2475 2388 2476 2389 ret = tunnel->consumed_bandwidth(tunnel, &up_bw, &down_bw); 2477 2390 if (ret) 2478 2391 return ret; 2479 - 2480 - tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw, 2481 - down_bw); 2482 2392 } 2483 2393 2484 - out: 2485 2394 if (consumed_up) 2486 2395 *consumed_up = up_bw; 2487 2396 if (consumed_down) 2488 2397 *consumed_down = down_bw; 2489 2398 2399 + tb_tunnel_dbg(tunnel, "consumed bandwidth %d/%d Mb/s\n", up_bw, down_bw); 2490 2400 return 0; 2491 2401 } 2492 2402 ··· 2503 2411 int tb_tunnel_release_unused_bandwidth(struct tb_tunnel *tunnel) 2504 2412 { 2505 2413 if (!tb_tunnel_is_active(tunnel)) 2506 - return 0; 2414 + return -ENOTCONN; 2507 2415 2508 2416 if (tunnel->release_unused_bandwidth) { 2509 2417 int ret;
+54 -7
drivers/thunderbolt/tunnel.h
··· 19 19 }; 20 20 21 21 /** 22 + * enum tb_tunnel_state - State of a tunnel 23 + * @TB_TUNNEL_INACTIVE: tb_tunnel_activate() is not called for the tunnel 24 + * @TB_TUNNEL_ACTIVATING: tb_tunnel_activate() returned successfully for the tunnel 25 + * @TB_TUNNEL_ACTIVE: The tunnel is fully active 26 + */ 27 + enum tb_tunnel_state { 28 + TB_TUNNEL_INACTIVE, 29 + TB_TUNNEL_ACTIVATING, 30 + TB_TUNNEL_ACTIVE, 31 + }; 32 + 33 + /** 22 34 * struct tb_tunnel - Tunnel between two ports 35 + * @kref: Reference count 23 36 * @tb: Pointer to the domain 24 37 * @src_port: Source port of the tunnel 25 38 * @dst_port: Destination port of the tunnel. For discovered incomplete 26 39 * tunnels may be %NULL or null adapter port instead. 27 40 * @paths: All paths required by the tunnel 28 41 * @npaths: Number of paths in @paths 29 - * @init: Optional tunnel specific initialization 30 - * @deinit: Optional tunnel specific de-initialization 42 + * @pre_activate: Optional tunnel specific initialization called before 43 + * activation. Can touch hardware. 31 44 * @activate: Optional tunnel specific activation/deactivation 45 + * @post_deactivate: Optional tunnel specific de-initialization called 46 + * after deactivation. Can touch hardware. 47 + * @destroy: Optional tunnel specific callback called when the tunnel 48 + * memory is being released. Should not touch hardware. 32 49 * @maximum_bandwidth: Returns maximum possible bandwidth for this tunnel 33 50 * @allocated_bandwidth: Return how much bandwidth is allocated for the tunnel 34 51 * @alloc_bandwidth: Change tunnel bandwidth allocation ··· 54 37 * @reclaim_available_bandwidth: Reclaim back available bandwidth 55 38 * @list: Tunnels are linked using this field 56 39 * @type: Type of the tunnel 40 + * @state: Current state of the tunnel 57 41 * @max_up: Maximum upstream bandwidth (Mb/s) available for the tunnel. 58 42 * Only set if the bandwidth needs to be limited. 59 43 * @max_down: Maximum downstream bandwidth (Mb/s) available for the tunnel. ··· 63 45 * @allocated_down: Allocated downstream bandwidth (only for USB3) 64 46 * @bw_mode: DP bandwidth allocation mode registers can be used to 65 47 * determine consumed and allocated bandwidth 48 + * @dprx_canceled: Was DPRX capabilities read poll canceled 49 + * @dprx_timeout: If set DPRX capabilities read poll work will timeout after this passes 50 + * @dprx_work: Worker that is scheduled to poll completion of DPRX capabilities read 51 + * @callback: Optional callback called when DP tunnel is fully activated 52 + * @callback_data: Optional data for @callback 66 53 */ 67 54 struct tb_tunnel { 55 + struct kref kref; 68 56 struct tb *tb; 69 57 struct tb_port *src_port; 70 58 struct tb_port *dst_port; 71 59 struct tb_path **paths; 72 60 size_t npaths; 73 - int (*init)(struct tb_tunnel *tunnel); 74 - void (*deinit)(struct tb_tunnel *tunnel); 61 + int (*pre_activate)(struct tb_tunnel *tunnel); 75 62 int (*activate)(struct tb_tunnel *tunnel, bool activate); 63 + void (*post_deactivate)(struct tb_tunnel *tunnel); 64 + void (*destroy)(struct tb_tunnel *tunnel); 76 65 int (*maximum_bandwidth)(struct tb_tunnel *tunnel, int *max_up, 77 66 int *max_down); 78 67 int (*allocated_bandwidth)(struct tb_tunnel *tunnel, int *allocated_up, ··· 94 69 int *available_down); 95 70 struct list_head list; 96 71 enum tb_tunnel_type type; 72 + enum tb_tunnel_state state; 97 73 int max_up; 98 74 int max_down; 99 75 int allocated_up; 100 76 int allocated_down; 101 77 bool bw_mode; 78 + bool dprx_canceled; 79 + ktime_t dprx_timeout; 80 + struct delayed_work dprx_work; 81 + void (*callback)(struct tb_tunnel *tunnel, void *data); 82 + void *callback_data; 102 83 }; 103 84 104 85 struct tb_tunnel *tb_tunnel_discover_pci(struct tb *tb, struct tb_port *down, ··· 117 86 bool alloc_hopid); 118 87 struct tb_tunnel *tb_tunnel_alloc_dp(struct tb *tb, struct tb_port *in, 119 88 struct tb_port *out, int link_nr, 120 - int max_up, int max_down); 89 + int max_up, int max_down, 90 + void (*callback)(struct tb_tunnel *, void *), 91 + void *callback_data); 121 92 struct tb_tunnel *tb_tunnel_alloc_dma(struct tb *tb, struct tb_port *nhi, 122 93 struct tb_port *dst, int transmit_path, 123 94 int transmit_ring, int receive_path, ··· 132 99 struct tb_port *down, int max_up, 133 100 int max_down); 134 101 135 - void tb_tunnel_free(struct tb_tunnel *tunnel); 102 + void tb_tunnel_put(struct tb_tunnel *tunnel); 136 103 int tb_tunnel_activate(struct tb_tunnel *tunnel); 137 - int tb_tunnel_restart(struct tb_tunnel *tunnel); 138 104 void tb_tunnel_deactivate(struct tb_tunnel *tunnel); 105 + 106 + /** 107 + * tb_tunnel_is_active() - Is tunnel fully activated 108 + * @tunnel: Tunnel to check 109 + * 110 + * Returns %true if @tunnel is fully activated. For other than DP 111 + * tunnels this is pretty much once tb_tunnel_activate() returns 112 + * successfully. However, for DP tunnels this returns %true only once the 113 + * DPRX capabilities read has been issued successfully. 114 + */ 115 + static inline bool tb_tunnel_is_active(const struct tb_tunnel *tunnel) 116 + { 117 + return tunnel->state == TB_TUNNEL_ACTIVE; 118 + } 119 + 139 120 bool tb_tunnel_is_invalid(struct tb_tunnel *tunnel); 140 121 bool tb_tunnel_port_on_path(const struct tb_tunnel *tunnel, 141 122 const struct tb_port *port);
+7 -6
drivers/usb/cdns3/cdnsp-gadget.c
··· 15 15 #include <linux/delay.h> 16 16 #include <linux/log2.h> 17 17 #include <linux/slab.h> 18 + #include <linux/string_choices.h> 18 19 #include <linux/pci.h> 19 20 #include <linux/irq.h> 20 21 #include <linux/dmi.h> ··· 1672 1671 "CTRL: %s, INT: %s, BULK: %s, ISOC %s, " 1673 1672 "SupDir IN: %s, OUT: %s\n", 1674 1673 pep->name, 1024, 1675 - (pep->endpoint.caps.type_control) ? "yes" : "no", 1676 - (pep->endpoint.caps.type_int) ? "yes" : "no", 1677 - (pep->endpoint.caps.type_bulk) ? "yes" : "no", 1678 - (pep->endpoint.caps.type_iso) ? "yes" : "no", 1679 - (pep->endpoint.caps.dir_in) ? "yes" : "no", 1680 - (pep->endpoint.caps.dir_out) ? "yes" : "no"); 1674 + str_yes_no(pep->endpoint.caps.type_control), 1675 + str_yes_no(pep->endpoint.caps.type_int), 1676 + str_yes_no(pep->endpoint.caps.type_bulk), 1677 + str_yes_no(pep->endpoint.caps.type_iso), 1678 + str_yes_no(pep->endpoint.caps.dir_in), 1679 + str_yes_no(pep->endpoint.caps.dir_out)); 1681 1680 1682 1681 INIT_LIST_HEAD(&pep->pending_list); 1683 1682 }
+1 -3
drivers/usb/cdns3/core.c
··· 529 529 int ret = 0; 530 530 531 531 if (cdns_power_is_lost(cdns)) { 532 - if (cdns->role_sw) { 533 - cdns->role = cdns_role_get(cdns->role_sw); 534 - } else { 532 + if (!cdns->role_sw) { 535 533 real_role = cdns_hw_role_state_machine(cdns); 536 534 if (real_role != cdns->role) { 537 535 ret = cdns_hw_role_switch(cdns);
+10 -3
drivers/usb/chipidea/host.c
··· 13 13 #include <linux/usb/hcd.h> 14 14 #include <linux/usb/chipidea.h> 15 15 #include <linux/regulator/consumer.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/pinctrl/consumer.h> 17 18 18 19 #include "../host/ehci.h" ··· 57 56 if (ret) { 58 57 dev_err(dev, 59 58 "Failed to %s vbus regulator, ret=%d\n", 60 - enable ? "enable" : "disable", ret); 59 + str_enable_disable(enable), ret); 61 60 return ret; 62 61 } 63 62 priv->enabled = enable; ··· 257 256 struct device *dev = hcd->self.controller; 258 257 struct ci_hdrc *ci = dev_get_drvdata(dev); 259 258 260 - port_index = wIndex & 0xff; 261 - port_index -= (port_index > 0); 259 + /* 260 + * Avoid out-of-bounds values while calculating the port index 261 + * from wIndex. The compiler doesn't like pointers to invalid 262 + * addresses, even if they are never used. 263 + */ 264 + port_index = (wIndex - 1) & 0xff; 265 + if (port_index >= HCS_N_PORTS_MAX) 266 + port_index = 0; 262 267 status_reg = &ehci->regs->port_status[port_index]; 263 268 264 269 spin_lock_irqsave(&ehci->lock, flags);
+1 -1
drivers/usb/class/usblp.c
··· 87 87 /* Get two-int array: [0]=vendor ID, [1]=product ID: */ 88 88 #define LPIOC_GET_VID_PID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_VID_PID, len) 89 89 /* Perform class specific soft reset */ 90 - #define LPIOC_SOFT_RESET _IOC(_IOC_NONE, 'P', IOCNR_SOFT_RESET, 0); 90 + #define LPIOC_SOFT_RESET _IOC(_IOC_NONE, 'P', IOCNR_SOFT_RESET, 0) 91 91 92 92 /* 93 93 * A DEVICE_ID string may include the printer's serial number.
+14
drivers/usb/common/common.c
··· 41 41 } 42 42 EXPORT_SYMBOL_GPL(usb_ep_type_string); 43 43 44 + /** 45 + * usb_otg_state_string() - returns human readable name of OTG state. 46 + * @state: the OTG state to return the human readable name of. If it's not 47 + * any of the states defined in usb_otg_state enum, 'UNDEFINED' will be 48 + * returned. 49 + */ 44 50 const char *usb_otg_state_string(enum usb_otg_state state) 45 51 { 46 52 static const char *const names[] = { ··· 185 179 [USB_DR_MODE_OTG] = "otg", 186 180 }; 187 181 182 + /** 183 + * usb_get_dr_mode_from_string() - Get dual role mode for given string 184 + * @str: String to find the corresponding dual role mode for 185 + * 186 + * This function performs a lookup for the given string and returns the 187 + * corresponding enum usb_dr_mode. If no match for the string could be found, 188 + * 'USB_DR_MODE_UNKNOWN' is returned. 189 + */ 188 190 static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) 189 191 { 190 192 int ret;
+2 -1
drivers/usb/common/usb-conn-gpio.c
··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/power_supply.h> 21 21 #include <linux/regulator/consumer.h> 22 + #include <linux/string_choices.h> 22 23 #include <linux/usb/role.h> 23 24 24 25 #define USB_GPIO_DEB_MS 20 /* ms */ ··· 112 111 113 112 if (info->vbus) 114 113 dev_dbg(info->dev, "vbus regulator is %s\n", 115 - regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); 114 + str_enabled_disabled(regulator_is_enabled(info->vbus))); 116 115 117 116 power_supply_changed(info->charger); 118 117 }
+7 -12
drivers/usb/core/config.c
··· 9 9 #include <linux/usb/quirks.h> 10 10 #include <linux/module.h> 11 11 #include <linux/slab.h> 12 + #include <linux/string_choices.h> 12 13 #include <linux/device.h> 13 14 #include <asm/byteorder.h> 14 15 #include "usb.h" ··· 18 17 #define USB_MAXALTSETTING 128 /* Hard limit */ 19 18 20 19 #define USB_MAXCONFIG 8 /* Arbitrary limit */ 21 - 22 - 23 - static inline const char *plural(int n) 24 - { 25 - return (n == 1 ? "" : "s"); 26 - } 27 20 28 21 static int find_next_descriptor(unsigned char *buffer, int size, 29 22 int dt1, int dt2, int *num_skipped) ··· 479 484 retval = buffer - buffer0 + i; 480 485 if (n > 0) 481 486 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 482 - n, plural(n), "endpoint"); 487 + n, str_plural(n), "endpoint"); 483 488 return retval; 484 489 485 490 skip_to_next_endpoint_or_interface_descriptor: ··· 558 563 alt->extralen = i; 559 564 if (n > 0) 560 565 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 561 - n, plural(n), "interface"); 566 + n, str_plural(n), "interface"); 562 567 buffer += i; 563 568 size -= i; 564 569 ··· 600 605 dev_notice(ddev, "config %d interface %d altsetting %d has %d " 601 606 "endpoint descriptor%s, different from the interface " 602 607 "descriptor's value: %d\n", 603 - cfgno, inum, asnum, n, plural(n), num_ep_orig); 608 + cfgno, inum, asnum, n, str_plural(n), num_ep_orig); 604 609 return buffer - buffer0; 605 610 606 611 skip_to_next_interface_descriptor: ··· 659 664 if (size2 < sizeof(struct usb_descriptor_header)) { 660 665 dev_notice(ddev, "config %d descriptor has %d excess " 661 666 "byte%s, ignoring\n", 662 - cfgno, size2, plural(size2)); 667 + cfgno, size2, str_plural(size2)); 663 668 break; 664 669 } 665 670 ··· 749 754 if (n != nintf) 750 755 dev_notice(ddev, "config %d has %d interface%s, different from " 751 756 "the descriptor's value: %d\n", 752 - cfgno, n, plural(n), nintf_orig); 757 + cfgno, n, str_plural(n), nintf_orig); 753 758 else if (n == 0) 754 759 dev_notice(ddev, "config %d has no interfaces?\n", cfgno); 755 760 config->desc.bNumInterfaces = nintf = n; ··· 793 798 config->extralen = i; 794 799 if (n > 0) 795 800 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 796 - n, plural(n), "configuration"); 801 + n, str_plural(n), "configuration"); 797 802 buffer += i; 798 803 size -= i; 799 804
+3 -4
drivers/usb/core/driver.c
··· 1086 1086 pr_info("%s: registered new interface driver %s\n", 1087 1087 usbcore_name, new_driver->name); 1088 1088 1089 - out: 1090 - return retval; 1089 + return 0; 1091 1090 1092 1091 out_newid: 1093 1092 driver_unregister(&new_driver->driver); 1094 - 1093 + out: 1095 1094 pr_err("%s: error %d registering interface driver %s\n", 1096 1095 usbcore_name, retval, new_driver->name); 1097 - goto out; 1096 + return retval; 1098 1097 } 1099 1098 EXPORT_SYMBOL_GPL(usb_register_driver); 1100 1099
+4 -8
drivers/usb/core/generic.c
··· 21 21 22 22 #include <linux/usb.h> 23 23 #include <linux/usb/hcd.h> 24 + #include <linux/string_choices.h> 24 25 #include <uapi/linux/usb/audio.h> 25 26 #include "usb.h" 26 - 27 - static inline const char *plural(int n) 28 - { 29 - return (n == 1 ? "" : "s"); 30 - } 31 27 32 28 static int is_rndis(struct usb_interface_descriptor *desc) 33 29 { ··· 190 194 if (insufficient_power > 0) 191 195 dev_info(&udev->dev, "rejected %d configuration%s " 192 196 "due to insufficient available bus power\n", 193 - insufficient_power, plural(insufficient_power)); 197 + insufficient_power, str_plural(insufficient_power)); 194 198 195 199 if (best) { 196 200 i = best->desc.bConfigurationValue; 197 201 dev_dbg(&udev->dev, 198 202 "configuration #%d chosen from %d choice%s\n", 199 - i, num_configs, plural(num_configs)); 203 + i, num_configs, str_plural(num_configs)); 200 204 } else { 201 205 i = -1; 202 206 dev_warn(&udev->dev, 203 207 "no configuration chosen from %d choice%s\n", 204 - num_configs, plural(num_configs)); 208 + num_configs, str_plural(num_configs)); 205 209 } 206 210 return i; 207 211 }
+13 -2
drivers/usb/core/hcd-pci.c
··· 422 422 bool do_wakeup; 423 423 int retval; 424 424 425 - do_wakeup = PMSG_IS_AUTO(msg) ? true : device_may_wakeup(dev); 425 + if (PMSG_IS_AUTO(msg)) 426 + do_wakeup = true; 427 + else if (PMSG_NO_WAKEUP(msg)) 428 + do_wakeup = false; 429 + else 430 + do_wakeup = device_may_wakeup(dev); 426 431 427 432 /* Root hub suspend should have stopped all downstream traffic, 428 433 * and all bus master traffic. And done so for both the interface ··· 526 521 return suspend_common(dev, PMSG_SUSPEND); 527 522 } 528 523 524 + static int hcd_pci_freeze(struct device *dev) 525 + { 526 + return suspend_common(dev, PMSG_FREEZE); 527 + } 528 + 529 529 static int hcd_pci_suspend_noirq(struct device *dev) 530 530 { 531 531 struct pci_dev *pci_dev = to_pci_dev(dev); ··· 600 590 #else 601 591 602 592 #define hcd_pci_suspend NULL 593 + #define hcd_pci_freeze NULL 603 594 #define hcd_pci_suspend_noirq NULL 604 595 #define hcd_pci_poweroff_late NULL 605 596 #define hcd_pci_resume_noirq NULL ··· 635 624 .suspend_noirq = hcd_pci_suspend_noirq, 636 625 .resume_noirq = hcd_pci_resume_noirq, 637 626 .resume = hcd_pci_resume, 638 - .freeze = hcd_pci_suspend, 627 + .freeze = hcd_pci_freeze, 639 628 .freeze_noirq = check_root_hub_suspended, 640 629 .thaw_noirq = NULL, 641 630 .thaw = hcd_pci_resume,
+1 -1
drivers/usb/core/hcd.c
··· 415 415 static unsigned 416 416 rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len) 417 417 { 418 - char buf[100]; 418 + char buf[160]; 419 419 char const *s; 420 420 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04}; 421 421
+5 -5
drivers/usb/core/hub.c
··· 18 18 #include <linux/sched/mm.h> 19 19 #include <linux/list.h> 20 20 #include <linux/slab.h> 21 + #include <linux/string_choices.h> 21 22 #include <linux/kcov.h> 22 23 #include <linux/ioctl.h> 23 24 #include <linux/usb.h> ··· 1497 1496 1498 1497 maxchild = hub->descriptor->bNbrPorts; 1499 1498 dev_info(hub_dev, "%d port%s detected\n", maxchild, 1500 - (maxchild == 1) ? "" : "s"); 1499 + str_plural(maxchild)); 1501 1500 1502 1501 hub->ports = kcalloc(maxchild, sizeof(struct usb_port *), GFP_KERNEL); 1503 1502 if (!hub->ports) { ··· 4140 4139 break; 4141 4140 default: 4142 4141 dev_warn(&udev->dev, "%s: Can't %s non-U1 or U2 state.\n", 4143 - __func__, enable ? "enable" : "disable"); 4142 + __func__, str_enable_disable(enable)); 4144 4143 return -EINVAL; 4145 4144 } 4146 4145 4147 4146 if (udev->state != USB_STATE_CONFIGURED) { 4148 4147 dev_dbg(&udev->dev, "%s: Can't %s %s state " 4149 4148 "for unconfigured device.\n", 4150 - __func__, enable ? "enable" : "disable", 4149 + __func__, str_enable_disable(enable), 4151 4150 usb3_lpm_names[state]); 4152 4151 return 0; 4153 4152 } ··· 4173 4172 } 4174 4173 if (ret < 0) { 4175 4174 dev_warn(&udev->dev, "%s of device-initiated %s failed.\n", 4176 - enable ? "Enable" : "Disable", 4177 - usb3_lpm_names[state]); 4175 + str_enable_disable(enable), usb3_lpm_names[state]); 4178 4176 return -EBUSY; 4179 4177 } 4180 4178 return 0;
+2 -1
drivers/usb/core/port.c
··· 9 9 10 10 #include <linux/kstrtox.h> 11 11 #include <linux/slab.h> 12 + #include <linux/string_choices.h> 12 13 #include <linux/sysfs.h> 13 14 #include <linux/pm_qos.h> 14 15 #include <linux/component.h> ··· 26 25 { 27 26 struct usb_port *port_dev = to_usb_port(dev); 28 27 29 - return sysfs_emit(buf, "%s\n", port_dev->early_stop ? "yes" : "no"); 28 + return sysfs_emit(buf, "%s\n", str_yes_no(port_dev->early_stop)); 30 29 } 31 30 32 31 static ssize_t early_stop_store(struct device *dev, struct device_attribute *attr,
+3
drivers/usb/core/quirks.c
··· 394 394 /* Kingston DataTraveler 3.0 */ 395 395 { USB_DEVICE(0x0951, 0x1666), .driver_info = USB_QUIRK_NO_LPM }, 396 396 397 + /* TOSHIBA TransMemory-Mx */ 398 + { USB_DEVICE(0x0930, 0x1408), .driver_info = USB_QUIRK_NO_LPM }, 399 + 397 400 /* NVIDIA Jetson devices in Force Recovery mode */ 398 401 { USB_DEVICE(0x0955, 0x7018), .driver_info = USB_QUIRK_RESET_RESUME }, 399 402 { USB_DEVICE(0x0955, 0x7019), .driver_info = USB_QUIRK_RESET_RESUME },
+6 -6
drivers/usb/core/sysfs.c
··· 854 854 855 855 static ssize_t 856 856 descriptors_read(struct file *filp, struct kobject *kobj, 857 - struct bin_attribute *attr, 857 + const struct bin_attribute *attr, 858 858 char *buf, loff_t off, size_t count) 859 859 { 860 860 struct device *dev = kobj_to_dev(kobj); ··· 890 890 } 891 891 return count - nleft; 892 892 } 893 - static BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */ 893 + static const BIN_ATTR_RO(descriptors, 18 + 65535); /* dev descr + max-size raw descriptor */ 894 894 895 895 static ssize_t 896 896 bos_descriptors_read(struct file *filp, struct kobject *kobj, 897 - struct bin_attribute *attr, 897 + const struct bin_attribute *attr, 898 898 char *buf, loff_t off, size_t count) 899 899 { 900 900 struct device *dev = kobj_to_dev(kobj); ··· 913 913 } 914 914 return n; 915 915 } 916 - static BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */ 916 + static const BIN_ATTR_RO(bos_descriptors, 65535); /* max-size BOS */ 917 917 918 918 /* When modifying this list, be sure to modify dev_bin_attrs_are_visible() 919 919 * accordingly. 920 920 */ 921 - static struct bin_attribute *dev_bin_attrs[] = { 921 + static const struct bin_attribute *const dev_bin_attrs[] = { 922 922 &bin_attr_descriptors, 923 923 &bin_attr_bos_descriptors, 924 924 NULL ··· 944 944 } 945 945 946 946 static const struct attribute_group dev_bin_attr_grp = { 947 - .bin_attrs = dev_bin_attrs, 947 + .bin_attrs_new = dev_bin_attrs, 948 948 .is_bin_visible = dev_bin_attrs_are_visible, 949 949 }; 950 950
+45 -10
drivers/usb/dwc3/core.c
··· 1479 1479 } 1480 1480 } 1481 1481 1482 + /* 1483 + * STAR 9001346572: This issue affects DWC_usb31 versions 1.80a and 1484 + * prior. When an active endpoint not currently cached in the host 1485 + * controller is chosen to be cached to the same index as an endpoint 1486 + * receiving NAKs, the endpoint receiving NAKs enters continuous 1487 + * retry mode. This prevents it from being evicted from the host 1488 + * controller cache, blocking the new endpoint from being cached and 1489 + * serviced. 1490 + * 1491 + * To resolve this, for controller versions 1.70a and 1.80a, set the 1492 + * GUCTL3 bit[16] (USB2.0 Internal Retry Disable) to 1. This bit 1493 + * disables the USB2.0 internal retry feature. The GUCTL3[16] register 1494 + * function is available only from version 1.70a. 1495 + */ 1496 + if (DWC3_VER_IS_WITHIN(DWC31, 170A, 180A)) { 1497 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); 1498 + reg |= DWC3_GUCTL3_USB20_RETRY_DISABLE; 1499 + dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); 1500 + } 1501 + 1482 1502 return 0; 1483 1503 1484 1504 err_power_off_phy: ··· 1684 1664 u8 tx_thr_num_pkt_prd = 0; 1685 1665 u8 tx_max_burst_prd = 0; 1686 1666 u8 tx_fifo_resize_max_num; 1687 - const char *usb_psy_name; 1688 - int ret; 1689 1667 1690 1668 /* default to highest possible threshold */ 1691 1669 lpm_nyet_threshold = 0xf; ··· 1717 1699 dwc->sysdev = dwc->dev; 1718 1700 1719 1701 dwc->sys_wakeup = device_may_wakeup(dwc->sysdev); 1720 - 1721 - ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name); 1722 - if (ret >= 0) { 1723 - dwc->usb_psy = power_supply_get_by_name(usb_psy_name); 1724 - if (!dwc->usb_psy) 1725 - dev_err(dev, "couldn't get usb power supply\n"); 1726 - } 1727 1702 1728 1703 dwc->has_lpm_erratum = device_property_read_bool(dev, 1729 1704 "snps,has-lpm-erratum"); ··· 2120 2109 return 0; 2121 2110 } 2122 2111 2112 + static struct power_supply *dwc3_get_usb_power_supply(struct dwc3 *dwc) 2113 + { 2114 + struct power_supply *usb_psy; 2115 + const char *usb_psy_name; 2116 + int ret; 2117 + 2118 + ret = device_property_read_string(dwc->dev, "usb-psy-name", &usb_psy_name); 2119 + if (ret < 0) 2120 + return NULL; 2121 + 2122 + usb_psy = power_supply_get_by_name(usb_psy_name); 2123 + if (!usb_psy) 2124 + return ERR_PTR(-EPROBE_DEFER); 2125 + 2126 + return usb_psy; 2127 + } 2128 + 2123 2129 static int dwc3_probe(struct platform_device *pdev) 2124 2130 { 2125 2131 struct device *dev = &pdev->dev; ··· 2192 2164 dwc3_get_properties(dwc); 2193 2165 2194 2166 dwc3_get_software_properties(dwc); 2167 + 2168 + dwc->usb_psy = dwc3_get_usb_power_supply(dwc); 2169 + if (IS_ERR(dwc->usb_psy)) 2170 + return dev_err_probe(dev, PTR_ERR(dwc->usb_psy), "couldn't get usb power supply\n"); 2195 2171 2196 2172 dwc->reset = devm_reset_control_array_get_optional_shared(dev); 2197 2173 if (IS_ERR(dwc->reset)) { ··· 2621 2589 pinctrl_pm_select_default_state(dev); 2622 2590 2623 2591 pm_runtime_disable(dev); 2624 - pm_runtime_set_active(dev); 2592 + ret = pm_runtime_set_active(dev); 2593 + if (ret) 2594 + goto out; 2625 2595 2626 2596 ret = dwc3_resume_common(dwc, PMSG_RESUME); 2627 2597 if (ret) 2628 2598 pm_runtime_set_suspended(dev); 2629 2599 2600 + out: 2630 2601 pm_runtime_enable(dev); 2631 2602 2632 2603 return ret;
+3 -2
drivers/usb/dwc3/core.h
··· 425 425 426 426 /* Global User Control Register 3 */ 427 427 #define DWC3_GUCTL3_SPLITDISABLE BIT(14) 428 + #define DWC3_GUCTL3_USB20_RETRY_DISABLE BIT(16) 428 429 429 430 /* Device Configuration Register */ 430 431 #define DWC3_DCFG_NUMLANES(n) (((n) & 0x3) << 30) /* DWC_usb32 only */ ··· 743 742 */ 744 743 struct dwc3_ep { 745 744 struct usb_ep endpoint; 745 + struct delayed_work nostream_work; 746 746 struct list_head cancelled_list; 747 747 struct list_head pending_list; 748 748 struct list_head started_list; ··· 766 764 #define DWC3_EP_WAIT_TRANSFER_COMPLETE BIT(7) 767 765 #define DWC3_EP_IGNORE_NEXT_NOSTREAM BIT(8) 768 766 #define DWC3_EP_FORCE_RESTART_STREAM BIT(9) 769 - #define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) 767 + #define DWC3_EP_STREAM_PRIMED BIT(10) 770 768 #define DWC3_EP_PENDING_CLEAR_STALL BIT(11) 771 769 #define DWC3_EP_TXFIFO_RESIZED BIT(12) 772 770 #define DWC3_EP_DELAY_STOP BIT(13) ··· 959 957 struct usb_request request; 960 958 struct list_head list; 961 959 struct dwc3_ep *dep; 962 - struct scatterlist *sg; 963 960 struct scatterlist *start_sg; 964 961 965 962 unsigned int num_pending_sgs;
+56 -27
drivers/usb/dwc3/dwc3-am62.c
··· 108 108 109 109 #define DWC3_AM62_AUTOSUSPEND_DELAY 100 110 110 111 + #define USBSS_DEBUG_CFG_OFF 0x0 112 + #define USBSS_DEBUG_CFG_DISABLED 0x7 113 + 111 114 struct dwc3_am62 { 112 115 struct device *dev; 113 116 void __iomem *usbss; ··· 120 117 unsigned int offset; 121 118 unsigned int vbus_divider; 122 119 u32 wakeup_stat; 120 + void __iomem *phy_regs; 123 121 }; 124 122 125 123 static const int dwc3_ti_rate_table[] = { /* in KHZ */ ··· 170 166 if (ret) 171 167 return ret; 172 168 169 + of_node_put(args.np); 173 170 am62->offset = args.args[0]; 174 171 175 172 /* Core voltage. PHY_CORE_VOLTAGE bit Recommended to be 0 always */ ··· 189 184 return 0; 190 185 } 191 186 187 + static int dwc3_ti_init(struct dwc3_am62 *am62) 188 + { 189 + int ret; 190 + u32 reg; 191 + 192 + /* Read the syscon property and set the rate code */ 193 + ret = phy_syscon_pll_refclk(am62); 194 + if (ret) 195 + return ret; 196 + 197 + /* Workaround Errata i2409 */ 198 + if (am62->phy_regs) { 199 + reg = readl(am62->phy_regs + USB_PHY_PLL_REG12); 200 + reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN; 201 + writel(reg, am62->phy_regs + USB_PHY_PLL_REG12); 202 + } 203 + 204 + /* VBUS divider select */ 205 + reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG); 206 + if (am62->vbus_divider) 207 + reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT; 208 + 209 + dwc3_ti_writel(am62, USBSS_PHY_CONFIG, reg); 210 + 211 + clk_prepare_enable(am62->usb2_refclk); 212 + 213 + /* Set mode valid bit to indicate role is valid */ 214 + reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL); 215 + reg |= USBSS_MODE_VALID; 216 + dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg); 217 + 218 + return 0; 219 + } 220 + 192 221 static int dwc3_ti_probe(struct platform_device *pdev) 193 222 { 194 223 struct device *dev = &pdev->dev; 195 224 struct device_node *node = pdev->dev.of_node; 196 225 struct dwc3_am62 *am62; 197 226 unsigned long rate; 198 - void __iomem *phy; 199 227 int i, ret; 200 - u32 reg; 201 228 202 229 am62 = devm_kzalloc(dev, sizeof(*am62), GFP_KERNEL); 203 230 if (!am62) ··· 265 228 266 229 am62->rate_code = i; 267 230 268 - /* Read the syscon property and set the rate code */ 269 - ret = phy_syscon_pll_refclk(am62); 270 - if (ret) 271 - return ret; 272 - 273 - /* Workaround Errata i2409 */ 274 - phy = devm_platform_ioremap_resource(pdev, 1); 275 - if (IS_ERR(phy)) { 231 + am62->phy_regs = devm_platform_ioremap_resource(pdev, 1); 232 + if (IS_ERR(am62->phy_regs)) { 276 233 dev_err(dev, "can't map PHY IOMEM resource. Won't apply i2409 fix.\n"); 277 - phy = NULL; 278 - } else { 279 - reg = readl(phy + USB_PHY_PLL_REG12); 280 - reg |= USB_PHY_PLL_LDO_REF_EN | USB_PHY_PLL_LDO_REF_EN_EN; 281 - writel(reg, phy + USB_PHY_PLL_REG12); 234 + am62->phy_regs = NULL; 282 235 } 283 236 284 - /* VBUS divider select */ 285 237 am62->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider"); 286 - reg = dwc3_ti_readl(am62, USBSS_PHY_CONFIG); 287 - if (am62->vbus_divider) 288 - reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT; 289 238 290 - dwc3_ti_writel(am62, USBSS_PHY_CONFIG, reg); 239 + ret = dwc3_ti_init(am62); 240 + if (ret) 241 + return ret; 291 242 292 243 pm_runtime_set_active(dev); 293 244 pm_runtime_enable(dev); ··· 283 258 * Don't ignore its dependencies with its children 284 259 */ 285 260 pm_suspend_ignore_children(dev, false); 286 - clk_prepare_enable(am62->usb2_refclk); 287 261 pm_runtime_get_noresume(dev); 288 262 289 263 ret = of_platform_populate(node, NULL, NULL, dev); ··· 290 266 dev_err(dev, "failed to create dwc3 core: %d\n", ret); 291 267 goto err_pm_disable; 292 268 } 293 - 294 - /* Set mode valid bit to indicate role is valid */ 295 - reg = dwc3_ti_readl(am62, USBSS_MODE_CONTROL); 296 - reg |= USBSS_MODE_VALID; 297 - dwc3_ti_writel(am62, USBSS_MODE_CONTROL, reg); 298 269 299 270 /* Device has capability to wakeup system from sleep */ 300 271 device_set_wakeup_capable(dev, true); ··· 358 339 dwc3_ti_writel(am62, USBSS_WAKEUP_STAT, USBSS_WAKEUP_STAT_CLR); 359 340 } 360 341 342 + /* just to track if module resets on suspend */ 343 + dwc3_ti_writel(am62, USBSS_DEBUG_CFG, USBSS_DEBUG_CFG_DISABLED); 344 + 361 345 clk_disable_unprepare(am62->usb2_refclk); 362 346 363 347 return 0; ··· 371 349 struct dwc3_am62 *am62 = dev_get_drvdata(dev); 372 350 u32 reg; 373 351 374 - clk_prepare_enable(am62->usb2_refclk); 352 + reg = dwc3_ti_readl(am62, USBSS_DEBUG_CFG); 353 + if (reg != USBSS_DEBUG_CFG_DISABLED) { 354 + /* lost power/context */ 355 + dwc3_ti_init(am62); 356 + } else { 357 + dwc3_ti_writel(am62, USBSS_DEBUG_CFG, USBSS_DEBUG_CFG_OFF); 358 + clk_prepare_enable(am62->usb2_refclk); 359 + } 375 360 376 361 if (device_may_wakeup(dev)) { 377 362 /* Clear wakeup config enable bits */
+6 -7
drivers/usb/dwc3/dwc3-omap.c
··· 457 457 458 458 struct dwc3_omap *omap; 459 459 struct device *dev = &pdev->dev; 460 - struct regulator *vbus_reg = NULL; 460 + struct regulator *vbus_reg; 461 461 462 462 int ret; 463 463 int irq; ··· 483 483 if (IS_ERR(base)) 484 484 return PTR_ERR(base); 485 485 486 - if (of_property_read_bool(node, "vbus-supply")) { 487 - vbus_reg = devm_regulator_get(dev, "vbus"); 488 - if (IS_ERR(vbus_reg)) { 489 - dev_err(dev, "vbus init failed\n"); 490 - return PTR_ERR(vbus_reg); 491 - } 486 + vbus_reg = devm_regulator_get_optional(dev, "vbus"); 487 + if (IS_ERR(vbus_reg)) { 488 + if (PTR_ERR(vbus_reg) != -ENODEV) 489 + return dev_err_probe(dev, PTR_ERR(vbus_reg), "vbus init failed\n"); 490 + vbus_reg = NULL; 492 491 } 493 492 494 493 omap->dev = dev;
+2 -4
drivers/usb/dwc3/dwc3-st.c
··· 309 309 reset_control_assert(dwc3_data->rstc_rst); 310 310 } 311 311 312 - #ifdef CONFIG_PM_SLEEP 313 312 static int st_dwc3_suspend(struct device *dev) 314 313 { 315 314 struct st_dwc3 *dwc3_data = dev_get_drvdata(dev); ··· 342 343 343 344 return 0; 344 345 } 345 - #endif /* CONFIG_PM_SLEEP */ 346 346 347 - static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume); 347 + static DEFINE_SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume); 348 348 349 349 static const struct of_device_id st_dwc3_match[] = { 350 350 { .compatible = "st,stih407-dwc3" }, ··· 358 360 .driver = { 359 361 .name = "usb-st-dwc3", 360 362 .of_match_table = st_dwc3_match, 361 - .pm = &st_dwc3_dev_pm_ops, 363 + .pm = pm_sleep_ptr(&st_dwc3_dev_pm_ops), 362 364 }, 363 365 }; 364 366
+59 -52
drivers/usb/dwc3/gadget.c
··· 996 996 997 997 /* 998 998 * All stream eps will reinitiate stream on NoStream 999 - * rejection until we can determine that the host can 1000 - * prime after the first transfer. 999 + * rejection. 1001 1000 * 1002 1001 * However, if the controller is capable of 1003 1002 * TXF_FLUSH_BYPASS, then IN direction endpoints will ··· 2739 2740 __dwc3_gadget_stop(dwc); 2740 2741 spin_unlock_irqrestore(&dwc->lock, flags); 2741 2742 2743 + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); 2744 + 2742 2745 return ret; 2743 2746 } 2744 2747 ··· 3299 3298 return dwc3_alloc_trb_pool(dep); 3300 3299 } 3301 3300 3301 + #define nostream_work_to_dep(w) (container_of(to_delayed_work(w), struct dwc3_ep, nostream_work)) 3302 + static void dwc3_nostream_work(struct work_struct *work) 3303 + { 3304 + struct dwc3_ep *dep = nostream_work_to_dep(work); 3305 + struct dwc3 *dwc = dep->dwc; 3306 + unsigned long flags; 3307 + 3308 + spin_lock_irqsave(&dwc->lock, flags); 3309 + if (dep->flags & DWC3_EP_STREAM_PRIMED) 3310 + goto out; 3311 + 3312 + if ((dep->flags & DWC3_EP_IGNORE_NEXT_NOSTREAM) || 3313 + (!DWC3_MST_CAPABLE(&dwc->hwparams) && 3314 + !(dep->flags & DWC3_EP_WAIT_TRANSFER_COMPLETE))) 3315 + goto out; 3316 + /* 3317 + * If the host rejects a stream due to no active stream, by the 3318 + * USB and xHCI spec, the endpoint will be put back to idle 3319 + * state. When the host is ready (buffer added/updated), it will 3320 + * prime the endpoint to inform the usb device controller. This 3321 + * triggers the device controller to issue ERDY to restart the 3322 + * stream. However, some hosts don't follow this and keep the 3323 + * endpoint in the idle state. No prime will come despite host 3324 + * streams are updated, and the device controller will not be 3325 + * triggered to generate ERDY to move the next stream data. To 3326 + * workaround this and maintain compatibility with various 3327 + * hosts, force to reinitiate the stream until the host is ready 3328 + * instead of waiting for the host to prime the endpoint. 3329 + */ 3330 + if (DWC3_VER_IS_WITHIN(DWC32, 100A, ANY)) { 3331 + unsigned int cmd = DWC3_DGCMD_SET_ENDPOINT_PRIME; 3332 + 3333 + dwc3_send_gadget_generic_command(dwc, cmd, dep->number); 3334 + } else { 3335 + dep->flags |= DWC3_EP_DELAY_START; 3336 + dwc3_stop_active_transfer(dep, true, true); 3337 + spin_unlock_irqrestore(&dwc->lock, flags); 3338 + return; 3339 + } 3340 + out: 3341 + dep->flags &= ~DWC3_EP_IGNORE_NEXT_NOSTREAM; 3342 + spin_unlock_irqrestore(&dwc->lock, flags); 3343 + } 3344 + 3302 3345 static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum) 3303 3346 { 3304 3347 struct dwc3_ep *dep; ··· 3388 3343 INIT_LIST_HEAD(&dep->pending_list); 3389 3344 INIT_LIST_HEAD(&dep->started_list); 3390 3345 INIT_LIST_HEAD(&dep->cancelled_list); 3346 + INIT_DELAYED_WORK(&dep->nostream_work, dwc3_nostream_work); 3391 3347 3392 3348 dwc3_debugfs_create_endpoint_dir(dep); 3393 3349 ··· 3788 3742 static void dwc3_gadget_endpoint_stream_event(struct dwc3_ep *dep, 3789 3743 const struct dwc3_event_depevt *event) 3790 3744 { 3791 - struct dwc3 *dwc = dep->dwc; 3792 - 3793 3745 if (event->status == DEPEVT_STREAMEVT_FOUND) { 3794 - dep->flags |= DWC3_EP_FIRST_STREAM_PRIMED; 3795 - goto out; 3746 + cancel_delayed_work(&dep->nostream_work); 3747 + dep->flags |= DWC3_EP_STREAM_PRIMED; 3748 + dep->flags &= ~DWC3_EP_IGNORE_NEXT_NOSTREAM; 3749 + return; 3796 3750 } 3797 3751 3798 3752 /* Note: NoStream rejection event param value is 0 and not 0xFFFF */ 3799 3753 switch (event->parameters) { 3800 3754 case DEPEVT_STREAM_PRIME: 3801 - /* 3802 - * If the host can properly transition the endpoint state from 3803 - * idle to prime after a NoStream rejection, there's no need to 3804 - * force restarting the endpoint to reinitiate the stream. To 3805 - * simplify the check, assume the host follows the USB spec if 3806 - * it primed the endpoint more than once. 3807 - */ 3808 - if (dep->flags & DWC3_EP_FORCE_RESTART_STREAM) { 3809 - if (dep->flags & DWC3_EP_FIRST_STREAM_PRIMED) 3810 - dep->flags &= ~DWC3_EP_FORCE_RESTART_STREAM; 3811 - else 3812 - dep->flags |= DWC3_EP_FIRST_STREAM_PRIMED; 3813 - } 3814 - 3755 + cancel_delayed_work(&dep->nostream_work); 3756 + dep->flags |= DWC3_EP_STREAM_PRIMED; 3757 + dep->flags &= ~DWC3_EP_IGNORE_NEXT_NOSTREAM; 3815 3758 break; 3816 3759 case DEPEVT_STREAM_NOSTREAM: 3817 - if ((dep->flags & DWC3_EP_IGNORE_NEXT_NOSTREAM) || 3818 - !(dep->flags & DWC3_EP_FORCE_RESTART_STREAM) || 3819 - (!DWC3_MST_CAPABLE(&dwc->hwparams) && 3820 - !(dep->flags & DWC3_EP_WAIT_TRANSFER_COMPLETE))) 3821 - break; 3822 - 3823 - /* 3824 - * If the host rejects a stream due to no active stream, by the 3825 - * USB and xHCI spec, the endpoint will be put back to idle 3826 - * state. When the host is ready (buffer added/updated), it will 3827 - * prime the endpoint to inform the usb device controller. This 3828 - * triggers the device controller to issue ERDY to restart the 3829 - * stream. However, some hosts don't follow this and keep the 3830 - * endpoint in the idle state. No prime will come despite host 3831 - * streams are updated, and the device controller will not be 3832 - * triggered to generate ERDY to move the next stream data. To 3833 - * workaround this and maintain compatibility with various 3834 - * hosts, force to reinitiate the stream until the host is ready 3835 - * instead of waiting for the host to prime the endpoint. 3836 - */ 3837 - if (DWC3_VER_IS_WITHIN(DWC32, 100A, ANY)) { 3838 - unsigned int cmd = DWC3_DGCMD_SET_ENDPOINT_PRIME; 3839 - 3840 - dwc3_send_gadget_generic_command(dwc, cmd, dep->number); 3841 - } else { 3842 - dep->flags |= DWC3_EP_DELAY_START; 3843 - dwc3_stop_active_transfer(dep, true, true); 3844 - return; 3845 - } 3760 + dep->flags &= ~DWC3_EP_STREAM_PRIMED; 3761 + if (dep->flags & DWC3_EP_FORCE_RESTART_STREAM) 3762 + queue_delayed_work(system_wq, &dep->nostream_work, 3763 + msecs_to_jiffies(100)); 3846 3764 break; 3847 3765 } 3848 - 3849 - out: 3850 - dep->flags &= ~DWC3_EP_IGNORE_NEXT_NOSTREAM; 3851 3766 } 3852 3767 3853 3768 static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
+3 -2
drivers/usb/fotg210/fotg210-core.c
··· 13 13 #include <linux/of.h> 14 14 #include <linux/platform_device.h> 15 15 #include <linux/regmap.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/usb.h> 17 18 #include <linux/usb/otg.h> 18 19 ··· 120 119 ret = regmap_update_bits(fotg->map, GEMINI_GLOBAL_MISC_CTRL, mask, val); 121 120 if (ret) 122 121 dev_err(fotg->dev, "failed to %s VBUS\n", 123 - enable ? "enable" : "disable"); 124 - dev_info(fotg->dev, "%s: %s VBUS\n", __func__, enable ? "enable" : "disable"); 122 + str_enable_disable(enable)); 123 + dev_info(fotg->dev, "%s: %s VBUS\n", __func__, str_enable_disable(enable)); 125 124 } 126 125 127 126 static int fotg210_probe(struct platform_device *pdev)
+2 -2
drivers/usb/gadget/function/f_ecm.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/device.h> 15 15 #include <linux/etherdevice.h> 16 + #include <linux/string_choices.h> 16 17 17 18 #include "u_ether.h" 18 19 #include "u_ether_configfs.h" ··· 388 387 event->wLength = 0; 389 388 req->length = sizeof *event; 390 389 391 - DBG(cdev, "notify connect %s\n", 392 - ecm->is_open ? "true" : "false"); 390 + DBG(cdev, "notify connect %s\n", str_true_false(ecm->is_open)); 393 391 ecm->notify_state = ECM_NOTIFY_SPEED; 394 392 break; 395 393
+2 -1
drivers/usb/gadget/function/f_ncm.c
··· 17 17 #include <linux/device.h> 18 18 #include <linux/etherdevice.h> 19 19 #include <linux/crc32.h> 20 + #include <linux/string_choices.h> 20 21 21 22 #include <linux/usb/cdc.h> 22 23 ··· 559 558 req->length = sizeof *event; 560 559 561 560 DBG(cdev, "notify connect %s\n", 562 - ncm->is_open ? "true" : "false"); 561 + str_true_false(ncm->is_open)); 563 562 ncm->notify_state = NCM_NOTIFY_NONE; 564 563 break; 565 564
+529 -194
drivers/usb/gadget/function/f_tcm.c
··· 12 12 #include <linux/string.h> 13 13 #include <linux/configfs.h> 14 14 #include <linux/ctype.h> 15 + #include <linux/delay.h> 15 16 #include <linux/usb/ch9.h> 16 17 #include <linux/usb/composite.h> 17 18 #include <linux/usb/gadget.h> ··· 51 50 if (fu->flags & USBG_BOT_CMD_PEND) 52 51 return 0; 53 52 54 - ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); 53 + ret = usb_ep_queue(fu->ep_out, fu->cmd[0].req, GFP_ATOMIC); 55 54 if (!ret) 56 55 fu->flags |= USBG_BOT_CMD_PEND; 57 56 return ret; ··· 63 62 struct f_uas *fu = cmd->fu; 64 63 65 64 transport_generic_free_cmd(&cmd->se_cmd, 0); 66 - if (req->status < 0) { 67 - pr_err("ERR %s(%d)\n", __func__, __LINE__); 65 + if (req->status == -ESHUTDOWN) 68 66 return; 69 - } 67 + 68 + if (req->status < 0) 69 + pr_err("ERR %s(%d)\n", __func__, __LINE__); 70 70 71 71 /* CSW completed, wait for next CBW */ 72 72 bot_enqueue_cmd_cbw(fu); ··· 138 136 } 139 137 req->complete = bot_err_compl; 140 138 req->context = cmd; 141 - req->buf = fu->cmd.buf; 139 + req->buf = fu->cmd[0].buf; 142 140 usb_ep_queue(ep, req, GFP_KERNEL); 143 141 } else { 144 142 bot_enqueue_sense_code(fu, cmd); ··· 198 196 if (req->status < 0) 199 197 pr_err("ERR %s(%d)\n", __func__, __LINE__); 200 198 199 + if (req->status == -ESHUTDOWN) { 200 + transport_generic_free_cmd(&cmd->se_cmd, 0); 201 + return; 202 + } 203 + 201 204 bot_send_status(cmd, true); 202 205 } 203 206 ··· 251 244 static int bot_send_write_request(struct usbg_cmd *cmd) 252 245 { 253 246 struct f_uas *fu = cmd->fu; 254 - struct se_cmd *se_cmd = &cmd->se_cmd; 255 - struct usb_gadget *gadget = fuas_to_gadget(fu); 256 247 int ret; 257 248 258 - init_completion(&cmd->write_complete); 259 249 cmd->fu = fu; 260 250 261 251 if (!cmd->data_len) { 262 252 cmd->csw_code = US_BULK_STAT_PHASE; 263 253 return -EINVAL; 264 254 } 265 - 266 - if (!gadget->sg_supported) { 267 - cmd->data_buf = kmalloc(se_cmd->data_length, GFP_KERNEL); 268 - if (!cmd->data_buf) 269 - return -ENOMEM; 270 - 271 - fu->bot_req_out->buf = cmd->data_buf; 272 - } else { 273 - fu->bot_req_out->buf = NULL; 274 - fu->bot_req_out->num_sgs = se_cmd->t_data_nents; 275 - fu->bot_req_out->sg = se_cmd->t_data_sg; 276 - } 277 - 278 - fu->bot_req_out->complete = usbg_data_write_cmpl; 279 - fu->bot_req_out->length = se_cmd->data_length; 280 - fu->bot_req_out->context = cmd; 281 255 282 256 ret = usbg_prepare_w_request(cmd, fu->bot_req_out); 283 257 if (ret) ··· 267 279 if (ret) 268 280 pr_err("%s(%d)\n", __func__, __LINE__); 269 281 270 - wait_for_completion(&cmd->write_complete); 271 - target_execute_cmd(se_cmd); 272 282 cleanup: 273 283 return ret; 274 284 } ··· 278 292 struct f_uas *fu = req->context; 279 293 int ret; 280 294 281 - fu->flags &= ~USBG_BOT_CMD_PEND; 282 - 283 - if (req->status < 0) 295 + if (req->status == -ESHUTDOWN) 284 296 return; 285 297 298 + fu->flags &= ~USBG_BOT_CMD_PEND; 299 + 300 + if (req->status < 0) { 301 + struct usb_gadget *gadget = fuas_to_gadget(fu); 302 + 303 + dev_err(&gadget->dev, "BOT command req err (%d)\n", req->status); 304 + bot_enqueue_cmd_cbw(fu); 305 + return; 306 + } 307 + 286 308 ret = bot_submit_command(fu, req->buf, req->actual); 287 - if (ret) 309 + if (ret) { 288 310 pr_err("%s(%d): %d\n", __func__, __LINE__, ret); 311 + if (!(fu->flags & USBG_BOT_WEDGED)) 312 + usb_ep_set_wedge(fu->ep_in); 313 + 314 + fu->flags |= USBG_BOT_WEDGED; 315 + bot_enqueue_cmd_cbw(fu); 316 + } else if (fu->flags & USBG_BOT_WEDGED) { 317 + fu->flags &= ~USBG_BOT_WEDGED; 318 + usb_ep_clear_halt(fu->ep_in); 319 + } 289 320 } 290 321 291 322 static int bot_prepare_reqs(struct f_uas *fu) ··· 317 314 if (!fu->bot_req_out) 318 315 goto err_out; 319 316 320 - fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); 321 - if (!fu->cmd.req) 317 + fu->cmd[0].req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); 318 + if (!fu->cmd[0].req) 322 319 goto err_cmd; 323 320 324 321 fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); ··· 330 327 fu->bot_status.req->complete = bot_status_complete; 331 328 fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); 332 329 333 - fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); 334 - if (!fu->cmd.buf) 330 + fu->cmd[0].buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); 331 + if (!fu->cmd[0].buf) 335 332 goto err_buf; 336 333 337 - fu->cmd.req->complete = bot_cmd_complete; 338 - fu->cmd.req->buf = fu->cmd.buf; 339 - fu->cmd.req->length = fu->ep_out->maxpacket; 340 - fu->cmd.req->context = fu; 334 + fu->cmd[0].req->complete = bot_cmd_complete; 335 + fu->cmd[0].req->buf = fu->cmd[0].buf; 336 + fu->cmd[0].req->length = fu->ep_out->maxpacket; 337 + fu->cmd[0].req->context = fu; 341 338 342 339 ret = bot_enqueue_cmd_cbw(fu); 343 340 if (ret) 344 341 goto err_queue; 345 342 return 0; 346 343 err_queue: 347 - kfree(fu->cmd.buf); 348 - fu->cmd.buf = NULL; 344 + kfree(fu->cmd[0].buf); 345 + fu->cmd[0].buf = NULL; 349 346 err_buf: 350 347 usb_ep_free_request(fu->ep_in, fu->bot_status.req); 351 348 err_sts: 352 - usb_ep_free_request(fu->ep_out, fu->cmd.req); 353 - fu->cmd.req = NULL; 349 + usb_ep_free_request(fu->ep_out, fu->cmd[0].req); 350 + fu->cmd[0].req = NULL; 354 351 err_cmd: 355 352 usb_ep_free_request(fu->ep_out, fu->bot_req_out); 356 353 fu->bot_req_out = NULL; ··· 375 372 376 373 usb_ep_free_request(fu->ep_in, fu->bot_req_in); 377 374 usb_ep_free_request(fu->ep_out, fu->bot_req_out); 378 - usb_ep_free_request(fu->ep_out, fu->cmd.req); 375 + usb_ep_free_request(fu->ep_out, fu->cmd[0].req); 379 376 usb_ep_free_request(fu->ep_in, fu->bot_status.req); 380 377 381 - kfree(fu->cmd.buf); 378 + kfree(fu->cmd[0].buf); 382 379 383 380 fu->bot_req_in = NULL; 384 381 fu->bot_req_out = NULL; 385 - fu->cmd.req = NULL; 382 + fu->cmd[0].req = NULL; 386 383 fu->bot_status.req = NULL; 387 - fu->cmd.buf = NULL; 384 + fu->cmd[0].buf = NULL; 388 385 } 389 386 390 387 static void bot_set_alt(struct f_uas *fu) ··· 444 441 pr_err("No LUNs configured?\n"); 445 442 return -EINVAL; 446 443 } 447 - /* 448 - * If 4 LUNs are present we return 3 i.e. LUN 0..3 can be 449 - * accessed. The upper limit is 0xf 450 - */ 451 444 luns--; 452 - if (luns > 0xf) { 445 + if (luns > US_BULK_MAX_LUN_LIMIT) { 453 446 pr_info_once("Limiting the number of luns to 16\n"); 454 - luns = 0xf; 447 + luns = US_BULK_MAX_LUN_LIMIT; 455 448 } 456 449 ret_lun = cdev->req->buf; 457 450 *ret_lun = luns; ··· 456 457 457 458 case US_BULK_RESET_REQUEST: 458 459 /* XXX maybe we should remove previous requests for IN + OUT */ 460 + if (fu->flags & USBG_BOT_WEDGED) { 461 + fu->flags &= ~USBG_BOT_WEDGED; 462 + usb_ep_clear_halt(fu->ep_in); 463 + } 464 + 459 465 bot_enqueue_cmd_cbw(fu); 460 466 return 0; 461 467 } ··· 468 464 } 469 465 470 466 /* Start uas.c code */ 467 + 468 + static int tcm_to_uasp_response(enum tcm_tmrsp_table code) 469 + { 470 + switch (code) { 471 + case TMR_FUNCTION_FAILED: 472 + return RC_TMF_FAILED; 473 + case TMR_FUNCTION_COMPLETE: 474 + case TMR_TASK_DOES_NOT_EXIST: 475 + return RC_TMF_COMPLETE; 476 + case TMR_LUN_DOES_NOT_EXIST: 477 + return RC_INCORRECT_LUN; 478 + case TMR_FUNCTION_REJECTED: 479 + case TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED: 480 + default: 481 + return RC_TMF_NOT_SUPPORTED; 482 + } 483 + } 484 + 485 + static unsigned char uasp_to_tcm_func(int code) 486 + { 487 + switch (code) { 488 + case TMF_ABORT_TASK: 489 + return TMR_ABORT_TASK; 490 + case TMF_ABORT_TASK_SET: 491 + return TMR_ABORT_TASK_SET; 492 + case TMF_CLEAR_TASK_SET: 493 + return TMR_CLEAR_TASK_SET; 494 + case TMF_LOGICAL_UNIT_RESET: 495 + return TMR_LUN_RESET; 496 + case TMF_CLEAR_ACA: 497 + return TMR_CLEAR_ACA; 498 + case TMF_I_T_NEXUS_RESET: 499 + case TMF_QUERY_TASK: 500 + case TMF_QUERY_TASK_SET: 501 + case TMF_QUERY_ASYNC_EVENT: 502 + default: 503 + return TMR_UNKNOWN; 504 + } 505 + } 471 506 472 507 static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) 473 508 { ··· 525 482 526 483 static void uasp_free_cmdreq(struct f_uas *fu) 527 484 { 528 - usb_ep_free_request(fu->ep_cmd, fu->cmd.req); 529 - kfree(fu->cmd.buf); 530 - fu->cmd.req = NULL; 531 - fu->cmd.buf = NULL; 485 + int i; 486 + 487 + for (i = 0; i < USBG_NUM_CMDS; i++) { 488 + usb_ep_free_request(fu->ep_cmd, fu->cmd[i].req); 489 + kfree(fu->cmd[i].buf); 490 + fu->cmd[i].req = NULL; 491 + fu->cmd[i].buf = NULL; 492 + } 532 493 } 533 494 534 495 static void uasp_cleanup_old_alt(struct f_uas *fu) ··· 547 500 usb_ep_disable(fu->ep_status); 548 501 usb_ep_disable(fu->ep_cmd); 549 502 550 - for (i = 0; i < UASP_SS_EP_COMP_NUM_STREAMS; i++) 503 + for (i = 0; i < USBG_NUM_CMDS; i++) 551 504 uasp_cleanup_one_stream(fu, &fu->stream[i]); 552 505 uasp_free_cmdreq(fu); 553 506 } ··· 559 512 struct se_cmd *se_cmd = &cmd->se_cmd; 560 513 struct f_uas *fu = cmd->fu; 561 514 struct usb_gadget *gadget = fuas_to_gadget(fu); 562 - struct uas_stream *stream = cmd->stream; 515 + struct uas_stream *stream = &fu->stream[se_cmd->map_tag]; 563 516 564 517 if (!gadget->sg_supported) { 565 518 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); ··· 579 532 } 580 533 581 534 stream->req_in->is_last = 1; 535 + stream->req_in->stream_id = cmd->tag; 582 536 stream->req_in->complete = uasp_status_data_cmpl; 583 537 stream->req_in->length = se_cmd->data_length; 584 538 stream->req_in->context = cmd; ··· 592 544 { 593 545 struct se_cmd *se_cmd = &cmd->se_cmd; 594 546 struct sense_iu *iu = &cmd->sense_iu; 595 - struct uas_stream *stream = cmd->stream; 547 + struct uas_stream *stream = &cmd->fu->stream[se_cmd->map_tag]; 596 548 597 549 cmd->state = UASP_QUEUE_COMMAND; 598 550 iu->iu_id = IU_ID_STATUS; ··· 604 556 iu->len = cpu_to_be16(se_cmd->scsi_sense_length); 605 557 iu->status = se_cmd->scsi_status; 606 558 stream->req_status->is_last = 1; 559 + stream->req_status->stream_id = cmd->tag; 607 560 stream->req_status->context = cmd; 608 561 stream->req_status->length = se_cmd->scsi_sense_length + 16; 609 562 stream->req_status->buf = iu; 610 563 stream->req_status->complete = uasp_status_data_cmpl; 611 564 } 612 565 566 + static void uasp_prepare_response(struct usbg_cmd *cmd) 567 + { 568 + struct se_cmd *se_cmd = &cmd->se_cmd; 569 + struct response_iu *rsp_iu = &cmd->response_iu; 570 + struct uas_stream *stream = &cmd->fu->stream[se_cmd->map_tag]; 571 + 572 + cmd->state = UASP_QUEUE_COMMAND; 573 + rsp_iu->iu_id = IU_ID_RESPONSE; 574 + rsp_iu->tag = cpu_to_be16(cmd->tag); 575 + 576 + if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) 577 + rsp_iu->response_code = cmd->tmr_rsp; 578 + else 579 + rsp_iu->response_code = 580 + tcm_to_uasp_response(se_cmd->se_tmr_req->response); 581 + 582 + /* 583 + * The UASP driver must support all the task management functions listed 584 + * in Table 20 of UAS-r04. To remain compliant while indicate that the 585 + * TMR did not go through, report RC_TMF_FAILED instead of 586 + * RC_TMF_NOT_SUPPORTED and print a warning to the user. 587 + */ 588 + switch (cmd->tmr_func) { 589 + case TMF_ABORT_TASK: 590 + case TMF_ABORT_TASK_SET: 591 + case TMF_CLEAR_TASK_SET: 592 + case TMF_LOGICAL_UNIT_RESET: 593 + case TMF_CLEAR_ACA: 594 + case TMF_I_T_NEXUS_RESET: 595 + case TMF_QUERY_TASK: 596 + case TMF_QUERY_TASK_SET: 597 + case TMF_QUERY_ASYNC_EVENT: 598 + if (rsp_iu->response_code == RC_TMF_NOT_SUPPORTED) { 599 + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu); 600 + 601 + dev_warn(&gadget->dev, "TMF function %d not supported\n", 602 + cmd->tmr_func); 603 + rsp_iu->response_code = RC_TMF_FAILED; 604 + } 605 + break; 606 + default: 607 + break; 608 + } 609 + 610 + stream->req_status->is_last = 1; 611 + stream->req_status->stream_id = cmd->tag; 612 + stream->req_status->context = cmd; 613 + stream->req_status->length = sizeof(struct response_iu); 614 + stream->req_status->buf = rsp_iu; 615 + stream->req_status->complete = uasp_status_data_cmpl; 616 + } 617 + 618 + static void usbg_release_cmd(struct se_cmd *se_cmd); 619 + static int uasp_send_tm_response(struct usbg_cmd *cmd); 620 + 613 621 static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) 614 622 { 615 623 struct usbg_cmd *cmd = req->context; 616 - struct uas_stream *stream = cmd->stream; 617 624 struct f_uas *fu = cmd->fu; 625 + struct uas_stream *stream = &fu->stream[cmd->se_cmd.map_tag]; 618 626 int ret; 619 627 620 - if (req->status < 0) 628 + if (req->status == -ESHUTDOWN) 621 629 goto cleanup; 622 630 623 631 switch (cmd->state) { ··· 704 600 break; 705 601 706 602 case UASP_QUEUE_COMMAND: 707 - transport_generic_free_cmd(&cmd->se_cmd, 0); 708 - usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); 603 + /* 604 + * Overlapped command detected and cancelled. 605 + * So send overlapped attempted status. 606 + */ 607 + if (cmd->tmr_rsp == RC_OVERLAPPED_TAG && 608 + req->status == -ECONNRESET) { 609 + uasp_send_tm_response(cmd); 610 + return; 611 + } 612 + 613 + hash_del(&stream->node); 614 + 615 + /* 616 + * If no command submitted to target core here, just free the 617 + * bitmap index. This is for the cases where f_tcm handles 618 + * status response instead of the target core. 619 + */ 620 + if (cmd->tmr_rsp != RC_OVERLAPPED_TAG && 621 + cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) { 622 + struct se_session *se_sess; 623 + 624 + se_sess = fu->tpg->tpg_nexus->tvn_se_sess; 625 + sbitmap_queue_clear(&se_sess->sess_tag_pool, 626 + cmd->se_cmd.map_tag, 627 + cmd->se_cmd.map_cpu); 628 + } else { 629 + transport_generic_free_cmd(&cmd->se_cmd, 0); 630 + } 631 + 632 + usb_ep_queue(fu->ep_cmd, cmd->req, GFP_ATOMIC); 633 + complete(&stream->cmd_completion); 709 634 break; 710 635 711 636 default: ··· 743 610 return; 744 611 745 612 cleanup: 613 + hash_del(&stream->node); 746 614 transport_generic_free_cmd(&cmd->se_cmd, 0); 747 615 } 748 616 749 617 static int uasp_send_status_response(struct usbg_cmd *cmd) 750 618 { 751 619 struct f_uas *fu = cmd->fu; 752 - struct uas_stream *stream = cmd->stream; 620 + struct uas_stream *stream = &fu->stream[cmd->se_cmd.map_tag]; 753 621 struct sense_iu *iu = &cmd->sense_iu; 754 622 755 623 iu->tag = cpu_to_be16(cmd->tag); 756 - stream->req_status->complete = uasp_status_data_cmpl; 757 - stream->req_status->context = cmd; 758 624 cmd->fu = fu; 759 625 uasp_prepare_status(cmd); 626 + return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); 627 + } 628 + 629 + static int uasp_send_tm_response(struct usbg_cmd *cmd) 630 + { 631 + struct f_uas *fu = cmd->fu; 632 + struct uas_stream *stream = &fu->stream[cmd->se_cmd.map_tag]; 633 + struct response_iu *iu = &cmd->response_iu; 634 + 635 + iu->tag = cpu_to_be16(cmd->tag); 636 + cmd->fu = fu; 637 + uasp_prepare_response(cmd); 760 638 return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); 761 639 } 762 640 763 641 static int uasp_send_read_response(struct usbg_cmd *cmd) 764 642 { 765 643 struct f_uas *fu = cmd->fu; 766 - struct uas_stream *stream = cmd->stream; 644 + struct uas_stream *stream = &fu->stream[cmd->se_cmd.map_tag]; 767 645 struct sense_iu *iu = &cmd->sense_iu; 768 646 int ret; 769 647 ··· 818 674 { 819 675 struct f_uas *fu = cmd->fu; 820 676 struct se_cmd *se_cmd = &cmd->se_cmd; 821 - struct uas_stream *stream = cmd->stream; 677 + struct uas_stream *stream = &fu->stream[se_cmd->map_tag]; 822 678 struct sense_iu *iu = &cmd->sense_iu; 823 679 int ret; 824 680 825 - init_completion(&cmd->write_complete); 826 681 cmd->fu = fu; 827 682 828 683 iu->tag = cpu_to_be16(cmd->tag); ··· 853 710 pr_err("%s(%d)\n", __func__, __LINE__); 854 711 } 855 712 856 - wait_for_completion(&cmd->write_complete); 857 - target_execute_cmd(se_cmd); 858 713 cleanup: 859 714 return ret; 860 715 } 861 716 862 - static int usbg_submit_command(struct f_uas *, void *, unsigned int); 717 + static int usbg_submit_command(struct f_uas *, struct usb_request *); 863 718 864 719 static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) 865 720 { 866 721 struct f_uas *fu = req->context; 867 - int ret; 868 722 869 - if (req->status < 0) 723 + if (req->status == -ESHUTDOWN) 870 724 return; 871 725 872 - ret = usbg_submit_command(fu, req->buf, req->actual); 873 - /* 874 - * Once we tune for performance enqueue the command req here again so 875 - * we can receive a second command while we processing this one. Pay 876 - * attention to properly sync STAUS endpoint with DATA IN + OUT so you 877 - * don't break HS. 878 - */ 879 - if (!ret) 726 + if (req->status < 0) { 727 + usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC); 880 728 return; 881 - usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); 729 + } 730 + 731 + usbg_submit_command(fu, req); 882 732 } 883 733 884 734 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) 885 735 { 736 + init_completion(&stream->cmd_completion); 737 + 886 738 stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); 887 739 if (!stream->req_in) 888 740 goto out; ··· 902 764 return -ENOMEM; 903 765 } 904 766 905 - static int uasp_alloc_cmd(struct f_uas *fu) 767 + static int uasp_alloc_cmd(struct f_uas *fu, int i) 906 768 { 907 - fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); 908 - if (!fu->cmd.req) 769 + fu->cmd[i].req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); 770 + if (!fu->cmd[i].req) 909 771 goto err; 910 772 911 - fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); 912 - if (!fu->cmd.buf) 773 + fu->cmd[i].buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); 774 + if (!fu->cmd[i].buf) 913 775 goto err_buf; 914 776 915 - fu->cmd.req->complete = uasp_cmd_complete; 916 - fu->cmd.req->buf = fu->cmd.buf; 917 - fu->cmd.req->length = fu->ep_cmd->maxpacket; 918 - fu->cmd.req->context = fu; 777 + fu->cmd[i].req->complete = uasp_cmd_complete; 778 + fu->cmd[i].req->buf = fu->cmd[i].buf; 779 + fu->cmd[i].req->length = fu->ep_cmd->maxpacket; 780 + fu->cmd[i].req->context = fu; 919 781 return 0; 920 782 921 783 err_buf: 922 - usb_ep_free_request(fu->ep_cmd, fu->cmd.req); 784 + usb_ep_free_request(fu->ep_cmd, fu->cmd[i].req); 923 785 err: 924 786 return -ENOMEM; 925 - } 926 - 927 - static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) 928 - { 929 - int i; 930 - 931 - for (i = 0; i < max_streams; i++) { 932 - struct uas_stream *s = &fu->stream[i]; 933 - 934 - s->req_in->stream_id = i + 1; 935 - s->req_out->stream_id = i + 1; 936 - s->req_status->stream_id = i + 1; 937 - } 938 787 } 939 788 940 789 static int uasp_prepare_reqs(struct f_uas *fu) 941 790 { 942 791 int ret; 943 792 int i; 944 - int max_streams; 945 793 946 - if (fu->flags & USBG_USE_STREAMS) 947 - max_streams = UASP_SS_EP_COMP_NUM_STREAMS; 948 - else 949 - max_streams = 1; 950 - 951 - for (i = 0; i < max_streams; i++) { 794 + for (i = 0; i < USBG_NUM_CMDS; i++) { 952 795 ret = uasp_alloc_stream_res(fu, &fu->stream[i]); 953 796 if (ret) 954 797 goto err_cleanup; 955 798 } 956 799 957 - ret = uasp_alloc_cmd(fu); 958 - if (ret) 959 - goto err_free_stream; 960 - uasp_setup_stream_res(fu, max_streams); 800 + for (i = 0; i < USBG_NUM_CMDS; i++) { 801 + ret = uasp_alloc_cmd(fu, i); 802 + if (ret) 803 + goto err_free_stream; 961 804 962 - ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); 963 - if (ret) 964 - goto err_free_stream; 805 + ret = usb_ep_queue(fu->ep_cmd, fu->cmd[i].req, GFP_ATOMIC); 806 + if (ret) 807 + goto err_free_stream; 808 + } 965 809 966 810 return 0; 967 811 ··· 1034 914 case READ_TOC: 1035 915 case READ_FORMAT_CAPACITIES: 1036 916 case REQUEST_SENSE: 917 + case ATA_12: 918 + case ATA_16: 1037 919 ret = DMA_FROM_DEVICE; 1038 920 break; 1039 921 ··· 1079 957 struct usbg_cmd *cmd = req->context; 1080 958 struct se_cmd *se_cmd = &cmd->se_cmd; 1081 959 1082 - if (req->status < 0) { 960 + cmd->state = UASP_QUEUE_COMMAND; 961 + 962 + if (req->status == -ESHUTDOWN) { 963 + struct uas_stream *stream = &cmd->fu->stream[se_cmd->map_tag]; 964 + 965 + hash_del(&stream->node); 966 + target_put_sess_cmd(se_cmd); 967 + transport_generic_free_cmd(&cmd->se_cmd, 0); 968 + return; 969 + } 970 + 971 + if (req->status) { 1083 972 pr_err("%s() state %d transfer failed\n", __func__, cmd->state); 1084 973 goto cleanup; 1085 974 } ··· 1102 969 se_cmd->data_length); 1103 970 } 1104 971 1105 - complete(&cmd->write_complete); 972 + cmd->flags |= USBG_CMD_PENDING_DATA_WRITE; 973 + queue_work(cmd->fu->tpg->workqueue, &cmd->work); 1106 974 return; 1107 975 1108 976 cleanup: 1109 - transport_generic_free_cmd(&cmd->se_cmd, 0); 977 + target_put_sess_cmd(se_cmd); 978 + 979 + /* Command was aborted due to overlapped tag */ 980 + if (cmd->state == UASP_QUEUE_COMMAND && 981 + cmd->tmr_rsp == RC_OVERLAPPED_TAG) { 982 + uasp_send_tm_response(cmd); 983 + return; 984 + } 985 + 986 + transport_send_check_condition_and_sense(se_cmd, 987 + TCM_CHECK_CONDITION_ABORT_CMD, 0); 1110 988 } 1111 989 1112 990 static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) ··· 1139 995 } 1140 996 1141 997 req->is_last = 1; 998 + req->stream_id = cmd->tag; 1142 999 req->complete = usbg_data_write_cmpl; 1143 1000 req->length = se_cmd->data_length; 1144 1001 req->context = cmd; 1002 + 1003 + cmd->state = UASP_SEND_STATUS; 1145 1004 return 0; 1146 1005 } 1147 1006 ··· 1184 1037 return uasp_send_read_response(cmd); 1185 1038 } 1186 1039 1187 - static void usbg_cmd_work(struct work_struct *work) 1040 + static void usbg_aborted_task(struct se_cmd *se_cmd); 1041 + 1042 + static void usbg_submit_tmr(struct usbg_cmd *cmd) 1188 1043 { 1189 - struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); 1044 + struct se_session *se_sess; 1045 + struct se_cmd *se_cmd; 1046 + int flags = TARGET_SCF_ACK_KREF; 1047 + 1048 + se_cmd = &cmd->se_cmd; 1049 + se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess; 1050 + 1051 + target_submit_tmr(se_cmd, se_sess, 1052 + cmd->response_iu.add_response_info, 1053 + cmd->unpacked_lun, NULL, uasp_to_tcm_func(cmd->tmr_func), 1054 + GFP_ATOMIC, cmd->tag, flags); 1055 + } 1056 + 1057 + static void usbg_submit_cmd(struct usbg_cmd *cmd) 1058 + { 1190 1059 struct se_cmd *se_cmd; 1191 1060 struct tcm_usbg_nexus *tv_nexus; 1192 1061 struct usbg_tpg *tpg; 1193 1062 int dir, flags = (TARGET_SCF_UNKNOWN_SIZE | TARGET_SCF_ACK_KREF); 1194 1063 1064 + /* 1065 + * Note: each command will spawn its own process, and each stage of the 1066 + * command is processed sequentially. Should this no longer be the case, 1067 + * locking is needed. 1068 + */ 1069 + if (cmd->flags & USBG_CMD_PENDING_DATA_WRITE) { 1070 + target_execute_cmd(&cmd->se_cmd); 1071 + cmd->flags &= ~USBG_CMD_PENDING_DATA_WRITE; 1072 + return; 1073 + } 1074 + 1195 1075 se_cmd = &cmd->se_cmd; 1196 1076 tpg = cmd->fu->tpg; 1197 1077 tv_nexus = tpg->tpg_nexus; 1198 1078 dir = get_cmd_dir(cmd->cmd_buf); 1199 - if (dir < 0) { 1200 - __target_init_cmd(se_cmd, 1201 - tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1202 - tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, 1203 - cmd->prio_attr, cmd->sense_iu.sense, 1204 - cmd->unpacked_lun, NULL); 1079 + if (dir < 0) 1205 1080 goto out; 1206 - } 1207 1081 1208 1082 target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf, 1209 1083 cmd->sense_iu.sense, cmd->unpacked_lun, 0, 1210 1084 cmd->prio_attr, dir, flags); 1085 + 1211 1086 return; 1212 1087 1213 1088 out: 1089 + __target_init_cmd(se_cmd, 1090 + tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1091 + tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, 1092 + cmd->prio_attr, cmd->sense_iu.sense, 1093 + cmd->unpacked_lun, NULL); 1214 1094 transport_send_check_condition_and_sense(se_cmd, 1215 - TCM_UNSUPPORTED_SCSI_OPCODE, 1); 1216 - transport_generic_free_cmd(&cmd->se_cmd, 0); 1095 + TCM_UNSUPPORTED_SCSI_OPCODE, 0); 1096 + } 1097 + 1098 + static void usbg_cmd_work(struct work_struct *work) 1099 + { 1100 + struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); 1101 + 1102 + /* 1103 + * Failure is detected by f_tcm here. Skip submitting the command to the 1104 + * target core if we already know the failing response and send the usb 1105 + * response to the host directly. 1106 + */ 1107 + if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) 1108 + goto skip; 1109 + 1110 + if (cmd->tmr_func) 1111 + usbg_submit_tmr(cmd); 1112 + else 1113 + usbg_submit_cmd(cmd); 1114 + 1115 + return; 1116 + 1117 + skip: 1118 + if (cmd->tmr_rsp == RC_OVERLAPPED_TAG) { 1119 + struct f_uas *fu = cmd->fu; 1120 + struct se_session *se_sess; 1121 + struct uas_stream *stream = NULL; 1122 + struct hlist_node *tmp; 1123 + struct usbg_cmd *active_cmd = NULL; 1124 + 1125 + se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess; 1126 + 1127 + hash_for_each_possible_safe(fu->stream_hash, stream, tmp, node, cmd->tag) { 1128 + int i = stream - &fu->stream[0]; 1129 + 1130 + active_cmd = &((struct usbg_cmd *)se_sess->sess_cmd_map)[i]; 1131 + if (active_cmd->tag == cmd->tag) 1132 + break; 1133 + } 1134 + 1135 + /* Sanity check */ 1136 + if (!stream || (active_cmd && active_cmd->tag != cmd->tag)) { 1137 + usbg_submit_command(cmd->fu, cmd->req); 1138 + return; 1139 + } 1140 + 1141 + reinit_completion(&stream->cmd_completion); 1142 + 1143 + /* 1144 + * A UASP command consists of the command, data, and status 1145 + * stages, each operating sequentially from different endpoints. 1146 + * 1147 + * Each USB endpoint operates independently, and depending on 1148 + * hardware implementation, a completion callback for a transfer 1149 + * from one endpoint may not reflect the order of completion on 1150 + * the wire. This is particularly true for devices with 1151 + * endpoints that have independent interrupts and event buffers. 1152 + * 1153 + * The driver must still detect misbehaving hosts and respond 1154 + * with an overlap status. To reduce false overlap failures, 1155 + * allow the active and matching stream ID a brief 1ms to 1156 + * complete before responding with an overlap command failure. 1157 + * Overlap failure should be rare. 1158 + */ 1159 + wait_for_completion_timeout(&stream->cmd_completion, msecs_to_jiffies(1)); 1160 + 1161 + /* If the previous stream is completed, retry the command. */ 1162 + if (!hash_hashed(&stream->node)) { 1163 + usbg_submit_command(cmd->fu, cmd->req); 1164 + return; 1165 + } 1166 + 1167 + /* 1168 + * The command isn't submitted to the target core, so we're safe 1169 + * to remove the bitmap index from the session tag pool. 1170 + */ 1171 + sbitmap_queue_clear(&se_sess->sess_tag_pool, 1172 + cmd->se_cmd.map_tag, 1173 + cmd->se_cmd.map_cpu); 1174 + 1175 + /* 1176 + * Overlap command tag detected. Cancel any pending transfer of 1177 + * the command submitted to target core. 1178 + */ 1179 + active_cmd->tmr_rsp = RC_OVERLAPPED_TAG; 1180 + usbg_aborted_task(&active_cmd->se_cmd); 1181 + 1182 + /* Send the response after the transfer is aborted. */ 1183 + return; 1184 + } 1185 + 1186 + uasp_send_tm_response(cmd); 1217 1187 } 1218 1188 1219 1189 static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, ··· 1348 1084 memset(cmd, 0, sizeof(*cmd)); 1349 1085 cmd->se_cmd.map_tag = tag; 1350 1086 cmd->se_cmd.map_cpu = cpu; 1087 + cmd->se_cmd.cpuid = cpu; 1351 1088 cmd->se_cmd.tag = cmd->tag = scsi_tag; 1352 1089 cmd->fu = fu; 1353 1090 ··· 1357 1092 1358 1093 static void usbg_release_cmd(struct se_cmd *); 1359 1094 1360 - static int usbg_submit_command(struct f_uas *fu, 1361 - void *cmdbuf, unsigned int len) 1095 + static int usbg_submit_command(struct f_uas *fu, struct usb_request *req) 1362 1096 { 1363 - struct command_iu *cmd_iu = cmdbuf; 1097 + struct iu *iu = req->buf; 1364 1098 struct usbg_cmd *cmd; 1365 1099 struct usbg_tpg *tpg = fu->tpg; 1366 1100 struct tcm_usbg_nexus *tv_nexus; 1101 + struct uas_stream *stream; 1102 + struct hlist_node *tmp; 1103 + struct command_iu *cmd_iu; 1367 1104 u32 cmd_len; 1368 1105 u16 scsi_tag; 1369 - 1370 - if (cmd_iu->iu_id != IU_ID_COMMAND) { 1371 - pr_err("Unsupported type %d\n", cmd_iu->iu_id); 1372 - return -EINVAL; 1373 - } 1374 1106 1375 1107 tv_nexus = tpg->tpg_nexus; 1376 1108 if (!tv_nexus) { ··· 1375 1113 return -EINVAL; 1376 1114 } 1377 1115 1378 - cmd_len = (cmd_iu->len & ~0x3) + 16; 1379 - if (cmd_len > USBG_MAX_CMD) 1380 - return -EINVAL; 1381 - 1382 - scsi_tag = be16_to_cpup(&cmd_iu->tag); 1116 + scsi_tag = be16_to_cpup(&iu->tag); 1383 1117 cmd = usbg_get_cmd(fu, tv_nexus, scsi_tag); 1384 1118 if (IS_ERR(cmd)) { 1385 1119 pr_err("usbg_get_cmd failed\n"); 1386 1120 return -ENOMEM; 1387 1121 } 1388 - memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); 1389 1122 1390 - if (fu->flags & USBG_USE_STREAMS) { 1391 - if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) 1392 - goto err; 1393 - if (!cmd->tag) 1394 - cmd->stream = &fu->stream[0]; 1395 - else 1396 - cmd->stream = &fu->stream[cmd->tag - 1]; 1397 - } else { 1398 - cmd->stream = &fu->stream[0]; 1123 + cmd->req = req; 1124 + cmd->fu = fu; 1125 + cmd->tag = scsi_tag; 1126 + cmd->se_cmd.tag = scsi_tag; 1127 + cmd->tmr_func = 0; 1128 + cmd->tmr_rsp = RC_RESPONSE_UNKNOWN; 1129 + cmd->flags = 0; 1130 + 1131 + cmd_iu = (struct command_iu *)iu; 1132 + 1133 + /* Command and Task Management IUs share the same LUN offset */ 1134 + cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); 1135 + 1136 + if (iu->iu_id != IU_ID_COMMAND && iu->iu_id != IU_ID_TASK_MGMT) { 1137 + cmd->tmr_rsp = RC_INVALID_INFO_UNIT; 1138 + goto skip; 1399 1139 } 1140 + 1141 + hash_for_each_possible_safe(fu->stream_hash, stream, tmp, node, scsi_tag) { 1142 + struct usbg_cmd *active_cmd; 1143 + struct se_session *se_sess; 1144 + int i = stream - &fu->stream[0]; 1145 + 1146 + se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess; 1147 + active_cmd = &((struct usbg_cmd *)se_sess->sess_cmd_map)[i]; 1148 + 1149 + if (active_cmd->tag == scsi_tag) { 1150 + cmd->tmr_rsp = RC_OVERLAPPED_TAG; 1151 + goto skip; 1152 + } 1153 + } 1154 + 1155 + stream = &fu->stream[cmd->se_cmd.map_tag]; 1156 + hash_add(fu->stream_hash, &stream->node, scsi_tag); 1157 + 1158 + if (iu->iu_id == IU_ID_TASK_MGMT) { 1159 + struct task_mgmt_iu *tm_iu; 1160 + 1161 + tm_iu = (struct task_mgmt_iu *)iu; 1162 + cmd->tmr_func = tm_iu->function; 1163 + goto skip; 1164 + } 1165 + 1166 + cmd_len = (cmd_iu->len & ~0x3) + 16; 1167 + if (cmd_len > USBG_MAX_CMD) { 1168 + target_free_tag(tv_nexus->tvn_se_sess, &cmd->se_cmd); 1169 + hash_del(&stream->node); 1170 + return -EINVAL; 1171 + } 1172 + memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); 1400 1173 1401 1174 switch (cmd_iu->prio_attr & 0x7) { 1402 1175 case UAS_HEAD_TAG: ··· 1452 1155 break; 1453 1156 } 1454 1157 1455 - cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); 1456 - 1158 + skip: 1457 1159 INIT_WORK(&cmd->work, usbg_cmd_work); 1458 1160 queue_work(tpg->workqueue, &cmd->work); 1459 1161 1460 1162 return 0; 1461 - err: 1462 - usbg_release_cmd(&cmd->se_cmd); 1463 - return -EINVAL; 1464 1163 } 1465 1164 1466 1165 static void bot_cmd_work(struct work_struct *work) ··· 1465 1172 struct se_cmd *se_cmd; 1466 1173 struct tcm_usbg_nexus *tv_nexus; 1467 1174 struct usbg_tpg *tpg; 1175 + int flags = TARGET_SCF_ACK_KREF; 1468 1176 int dir; 1177 + 1178 + /* 1179 + * Note: each command will spawn its own process, and each stage of the 1180 + * command is processed sequentially. Should this no longer be the case, 1181 + * locking is needed. 1182 + */ 1183 + if (cmd->flags & USBG_CMD_PENDING_DATA_WRITE) { 1184 + target_execute_cmd(&cmd->se_cmd); 1185 + cmd->flags &= ~USBG_CMD_PENDING_DATA_WRITE; 1186 + return; 1187 + } 1469 1188 1470 1189 se_cmd = &cmd->se_cmd; 1471 1190 tpg = cmd->fu->tpg; 1472 1191 tv_nexus = tpg->tpg_nexus; 1473 1192 dir = get_cmd_dir(cmd->cmd_buf); 1474 - if (dir < 0) { 1475 - __target_init_cmd(se_cmd, 1476 - tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1477 - tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, 1478 - cmd->prio_attr, cmd->sense_iu.sense, 1479 - cmd->unpacked_lun, NULL); 1193 + if (dir < 0) 1480 1194 goto out; 1481 - } 1482 1195 1483 1196 target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, 1484 1197 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, 1485 - cmd->data_len, cmd->prio_attr, dir, 0); 1198 + cmd->data_len, cmd->prio_attr, dir, flags); 1486 1199 return; 1487 1200 1488 1201 out: 1202 + __target_init_cmd(se_cmd, 1203 + tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, 1204 + tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, 1205 + cmd->prio_attr, cmd->sense_iu.sense, 1206 + cmd->unpacked_lun, NULL); 1489 1207 transport_send_check_condition_and_sense(se_cmd, 1490 - TCM_UNSUPPORTED_SCSI_OPCODE, 1); 1491 - transport_generic_free_cmd(&cmd->se_cmd, 0); 1208 + TCM_UNSUPPORTED_SCSI_OPCODE, 0); 1492 1209 } 1493 1210 1494 1211 static int bot_submit_command(struct f_uas *fu, ··· 1542 1239 cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; 1543 1240 cmd->data_len = le32_to_cpu(cbw->DataTransferLength); 1544 1241 cmd->se_cmd.tag = le32_to_cpu(cmd->bot_tag); 1242 + cmd->flags = 0; 1545 1243 1546 1244 INIT_WORK(&cmd->work, bot_cmd_work); 1547 1245 queue_work(tpg->workqueue, &cmd->work); ··· 1579 1275 se_cmd); 1580 1276 struct se_session *se_sess = se_cmd->se_sess; 1581 1277 1278 + cmd->tag = 0; 1582 1279 kfree(cmd->data_buf); 1583 1280 target_free_tag(se_sess, se_cmd); 1584 1281 } 1585 1282 1586 1283 static void usbg_queue_tm_rsp(struct se_cmd *se_cmd) 1587 1284 { 1285 + struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, se_cmd); 1286 + 1287 + uasp_send_tm_response(cmd); 1588 1288 } 1589 1289 1590 1290 static void usbg_aborted_task(struct se_cmd *se_cmd) 1591 1291 { 1292 + struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, se_cmd); 1293 + struct f_uas *fu = cmd->fu; 1294 + struct usb_gadget *gadget = fuas_to_gadget(fu); 1295 + struct uas_stream *stream = &fu->stream[se_cmd->map_tag]; 1296 + int ret = 0; 1297 + 1298 + if (stream->req_out->status == -EINPROGRESS) 1299 + ret = usb_ep_dequeue(fu->ep_out, stream->req_out); 1300 + else if (stream->req_in->status == -EINPROGRESS) 1301 + ret = usb_ep_dequeue(fu->ep_in, stream->req_in); 1302 + else if (stream->req_status->status == -EINPROGRESS) 1303 + ret = usb_ep_dequeue(fu->ep_status, stream->req_status); 1304 + 1305 + if (ret) 1306 + dev_err(&gadget->dev, "Failed to abort cmd tag %d, (%d)\n", 1307 + cmd->tag, ret); 1308 + 1309 + cmd->state = UASP_QUEUE_COMMAND; 1592 1310 } 1593 1311 1594 1312 static const char *usbg_check_wwn(const char *name) ··· 1681 1355 goto unref_dep; 1682 1356 mutex_init(&tpg->tpg_mutex); 1683 1357 atomic_set(&tpg->tpg_port_count, 0); 1684 - tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); 1358 + tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 1359 + WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE); 1685 1360 if (!tpg->workqueue) 1686 1361 goto free_tpg; 1687 1362 ··· 2073 1746 static struct usb_ss_ep_comp_descriptor uasp_bi_ep_comp_desc = { 2074 1747 .bLength = sizeof(uasp_bi_ep_comp_desc), 2075 1748 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 2076 - .bMaxBurst = 0, 1749 + .bMaxBurst = 15, 2077 1750 .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, 2078 1751 .wBytesPerInterval = 0, 2079 1752 }; ··· 2081 1754 static struct usb_ss_ep_comp_descriptor bot_bi_ep_comp_desc = { 2082 1755 .bLength = sizeof(bot_bi_ep_comp_desc), 2083 1756 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 2084 - .bMaxBurst = 0, 1757 + .bMaxBurst = 15, 2085 1758 }; 2086 1759 2087 1760 static struct usb_endpoint_descriptor uasp_bo_desc = { ··· 2116 1789 static struct usb_ss_ep_comp_descriptor uasp_bo_ep_comp_desc = { 2117 1790 .bLength = sizeof(uasp_bo_ep_comp_desc), 2118 1791 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 1792 + .bMaxBurst = 15, 2119 1793 .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, 2120 1794 }; 2121 1795 2122 1796 static struct usb_ss_ep_comp_descriptor bot_bo_ep_comp_desc = { 2123 1797 .bLength = sizeof(bot_bo_ep_comp_desc), 2124 1798 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 1799 + .bMaxBurst = 15, 2125 1800 }; 2126 1801 2127 1802 static struct usb_endpoint_descriptor uasp_status_desc = { ··· 2300 1971 bot_intf_desc.bInterfaceNumber = iface; 2301 1972 uasp_intf_desc.bInterfaceNumber = iface; 2302 1973 fu->iface = iface; 2303 - ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_bi_desc, 2304 - &uasp_bi_ep_comp_desc); 1974 + ep = usb_ep_autoconfig(gadget, &uasp_fs_bi_desc); 2305 1975 if (!ep) 2306 1976 goto ep_fail; 2307 1977 2308 1978 fu->ep_in = ep; 2309 1979 2310 - ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_bo_desc, 2311 - &uasp_bo_ep_comp_desc); 1980 + ep = usb_ep_autoconfig(gadget, &uasp_fs_bo_desc); 2312 1981 if (!ep) 2313 1982 goto ep_fail; 2314 1983 fu->ep_out = ep; 2315 1984 2316 - ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_status_desc, 2317 - &uasp_status_in_ep_comp_desc); 1985 + ep = usb_ep_autoconfig(gadget, &uasp_fs_status_desc); 2318 1986 if (!ep) 2319 1987 goto ep_fail; 2320 1988 fu->ep_status = ep; 2321 1989 2322 - ep = usb_ep_autoconfig_ss(gadget, &uasp_ss_cmd_desc, 2323 - &uasp_cmd_comp_desc); 1990 + ep = usb_ep_autoconfig(gadget, &uasp_fs_cmd_desc); 2324 1991 if (!ep) 2325 1992 goto ep_fail; 2326 1993 fu->ep_cmd = ep; 2327 1994 2328 1995 /* Assume endpoint addresses are the same for both speeds */ 2329 - uasp_bi_desc.bEndpointAddress = uasp_ss_bi_desc.bEndpointAddress; 2330 - uasp_bo_desc.bEndpointAddress = uasp_ss_bo_desc.bEndpointAddress; 1996 + uasp_bi_desc.bEndpointAddress = uasp_fs_bi_desc.bEndpointAddress; 1997 + uasp_bo_desc.bEndpointAddress = uasp_fs_bo_desc.bEndpointAddress; 2331 1998 uasp_status_desc.bEndpointAddress = 2332 - uasp_ss_status_desc.bEndpointAddress; 2333 - uasp_cmd_desc.bEndpointAddress = uasp_ss_cmd_desc.bEndpointAddress; 1999 + uasp_fs_status_desc.bEndpointAddress; 2000 + uasp_cmd_desc.bEndpointAddress = uasp_fs_cmd_desc.bEndpointAddress; 2334 2001 2335 - uasp_fs_bi_desc.bEndpointAddress = uasp_ss_bi_desc.bEndpointAddress; 2336 - uasp_fs_bo_desc.bEndpointAddress = uasp_ss_bo_desc.bEndpointAddress; 2337 - uasp_fs_status_desc.bEndpointAddress = 2338 - uasp_ss_status_desc.bEndpointAddress; 2339 - uasp_fs_cmd_desc.bEndpointAddress = uasp_ss_cmd_desc.bEndpointAddress; 2002 + uasp_ss_bi_desc.bEndpointAddress = uasp_fs_bi_desc.bEndpointAddress; 2003 + uasp_ss_bo_desc.bEndpointAddress = uasp_fs_bo_desc.bEndpointAddress; 2004 + uasp_ss_status_desc.bEndpointAddress = 2005 + uasp_fs_status_desc.bEndpointAddress; 2006 + uasp_ss_cmd_desc.bEndpointAddress = uasp_fs_cmd_desc.bEndpointAddress; 2340 2007 2341 2008 ret = usb_assign_descriptors(f, uasp_fs_function_desc, 2342 2009 uasp_hs_function_desc, uasp_ss_function_desc, ··· 2376 2051 2377 2052 static int tcm_get_alt(struct usb_function *f, unsigned intf) 2378 2053 { 2379 - if (intf == bot_intf_desc.bInterfaceNumber) 2054 + struct f_uas *fu = to_f_uas(f); 2055 + 2056 + if (fu->iface != intf) 2057 + return -EOPNOTSUPP; 2058 + 2059 + if (fu->flags & USBG_IS_BOT) 2380 2060 return USB_G_ALT_INT_BBB; 2381 - if (intf == uasp_intf_desc.bInterfaceNumber) 2061 + else if (fu->flags & USBG_IS_UAS) 2382 2062 return USB_G_ALT_INT_UAS; 2383 2063 2384 2064 return -EOPNOTSUPP; ··· 2392 2062 static int tcm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 2393 2063 { 2394 2064 struct f_uas *fu = to_f_uas(f); 2065 + 2066 + if (fu->iface != intf) 2067 + return -EOPNOTSUPP; 2395 2068 2396 2069 if ((alt == USB_G_ALT_INT_BBB) || (alt == USB_G_ALT_INT_UAS)) { 2397 2070 struct guas_setup_wq *work; ··· 2604 2271 fu->function.disable = tcm_disable; 2605 2272 fu->function.free_func = tcm_free; 2606 2273 fu->tpg = tpg_instances[i].tpg; 2274 + 2275 + hash_init(fu->stream_hash); 2607 2276 mutex_unlock(&tpg_instances_lock); 2608 2277 2609 2278 return &fu->function;
+1 -1
drivers/usb/gadget/function/storage_common.h
··· 131 131 #define FSG_BUFLEN ((u32)16384) 132 132 133 133 /* Maximal number of LUNs supported in mass storage function */ 134 - #define FSG_MAX_LUNS 16 134 + #define FSG_MAX_LUNS (US_BULK_MAX_LUN_LIMIT + 1) 135 135 136 136 enum fsg_buffer_state { 137 137 BUF_STATE_SENDING = -2,
+22 -6
drivers/usb/gadget/function/tcm.h
··· 4 4 5 5 #include <linux/kref.h> 6 6 /* #include <linux/usb/uas.h> */ 7 + #include <linux/hashtable.h> 7 8 #include <linux/usb/composite.h> 8 9 #include <linux/usb/uas.h> 9 10 #include <linux/usb/storage.h> ··· 14 13 #define USBG_NAMELEN 32 15 14 16 15 #define fuas_to_gadget(f) (f->function.config->cdev->gadget) 17 - #define UASP_SS_EP_COMP_LOG_STREAMS 4 16 + #define UASP_SS_EP_COMP_LOG_STREAMS 5 18 17 #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) 18 + 19 + #define USBG_NUM_CMDS (UASP_SS_EP_COMP_NUM_STREAMS + 1) 19 20 20 21 enum { 21 22 USB_G_STR_INT_UAS = 0, ··· 27 24 #define USB_G_ALT_INT_BBB 0 28 25 #define USB_G_ALT_INT_UAS 1 29 26 30 - #define USB_G_DEFAULT_SESSION_TAGS 128 27 + #define USB_G_DEFAULT_SESSION_TAGS USBG_NUM_CMDS 31 28 32 29 struct tcm_usbg_nexus { 33 30 struct se_session *tvn_se_sess; ··· 75 72 struct se_cmd se_cmd; 76 73 void *data_buf; /* used if no sg support available */ 77 74 struct f_uas *fu; 78 - struct completion write_complete; 79 75 struct kref ref; 76 + 77 + struct usb_request *req; 78 + 79 + u32 flags; 80 + #define USBG_CMD_PENDING_DATA_WRITE BIT(0) 80 81 81 82 /* UAS only */ 82 83 u16 tag; 83 84 u16 prio_attr; 84 85 struct sense_iu sense_iu; 86 + struct response_iu response_iu; 85 87 enum uas_state state; 86 - struct uas_stream *stream; 88 + 89 + int tmr_func; 90 + int tmr_rsp; 91 + #define RC_RESPONSE_UNKNOWN 0xff 87 92 88 93 /* BOT only */ 89 94 __le32 bot_tag; ··· 104 93 struct usb_request *req_in; 105 94 struct usb_request *req_out; 106 95 struct usb_request *req_status; 96 + 97 + struct completion cmd_completion; 98 + struct hlist_node node; 107 99 }; 108 100 109 101 struct usbg_cdb { ··· 130 116 #define USBG_USE_STREAMS (1 << 2) 131 117 #define USBG_IS_BOT (1 << 3) 132 118 #define USBG_BOT_CMD_PEND (1 << 4) 119 + #define USBG_BOT_WEDGED (1 << 5) 133 120 134 - struct usbg_cdb cmd; 121 + struct usbg_cdb cmd[USBG_NUM_CMDS]; 135 122 struct usb_ep *ep_in; 136 123 struct usb_ep *ep_out; 137 124 138 125 /* UAS */ 139 126 struct usb_ep *ep_status; 140 127 struct usb_ep *ep_cmd; 141 - struct uas_stream stream[UASP_SS_EP_COMP_NUM_STREAMS]; 128 + struct uas_stream stream[USBG_NUM_CMDS]; 129 + DECLARE_HASHTABLE(stream_hash, UASP_SS_EP_COMP_LOG_STREAMS); 142 130 143 131 /* BOT */ 144 132 struct bot_status bot_status;
+6 -5
drivers/usb/gadget/function/u_serial.c
··· 21 21 #include <linux/tty.h> 22 22 #include <linux/tty_flip.h> 23 23 #include <linux/slab.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/export.h> 25 26 #include <linux/module.h> 26 27 #include <linux/console.h> ··· 1421 1420 /* REVISIT as above: how best to track this? */ 1422 1421 port->port_line_coding = gser->port_line_coding; 1423 1422 1424 - /* disable endpoints, aborting down any active I/O */ 1425 - usb_ep_disable(gser->out); 1426 - usb_ep_disable(gser->in); 1427 - 1428 1423 port->port_usb = NULL; 1429 1424 gser->ioport = NULL; 1430 1425 if (port->port.count > 0) { ··· 1431 1434 port->suspended = false; 1432 1435 spin_unlock(&port->port_lock); 1433 1436 spin_unlock_irqrestore(&serial_port_lock, flags); 1437 + 1438 + /* disable endpoints, aborting down any active I/O */ 1439 + usb_ep_disable(gser->out); 1440 + usb_ep_disable(gser->in); 1434 1441 1435 1442 /* finally, free any unused/unusable I/O buffers */ 1436 1443 spin_lock_irqsave(&port->port_lock, flags); ··· 1546 1545 1547 1546 pr_debug("%s: registered %d ttyGS* device%s\n", __func__, 1548 1547 MAX_U_SERIAL_PORTS, 1549 - (MAX_U_SERIAL_PORTS == 1) ? "" : "s"); 1548 + str_plural(MAX_U_SERIAL_PORTS)); 1550 1549 1551 1550 return status; 1552 1551 fail:
+2 -1
drivers/usb/gadget/legacy/inode.c
··· 20 20 #include <linux/uaccess.h> 21 21 #include <linux/sched.h> 22 22 #include <linux/slab.h> 23 + #include <linux/string_choices.h> 23 24 #include <linux/poll.h> 24 25 #include <linux/kthread.h> 25 26 #include <linux/aio.h> ··· 1183 1182 { 1184 1183 struct dev_data *dev = fd->private_data; 1185 1184 // caller must F_SETOWN before signal delivery happens 1186 - VDEBUG (dev, "%s %s\n", __func__, on ? "on" : "off"); 1185 + VDEBUG(dev, "%s %s\n", __func__, str_on_off(on)); 1187 1186 return fasync_helper (f, fd, on, &dev->fasync); 1188 1187 } 1189 1188
+2 -1
drivers/usb/gadget/udc/aspeed-vhub/hub.c
··· 22 22 #include <linux/usb/gadget.h> 23 23 #include <linux/of.h> 24 24 #include <linux/regmap.h> 25 + #include <linux/string_choices.h> 25 26 #include <linux/dma-mapping.h> 26 27 #include <linux/bcd.h> 27 28 #include <linux/version.h> ··· 220 219 if (wValue == USB_DEVICE_REMOTE_WAKEUP) { 221 220 ep->vhub->wakeup_en = is_set; 222 221 EPDBG(ep, "Hub remote wakeup %s\n", 223 - is_set ? "enabled" : "disabled"); 222 + str_enabled_disabled(is_set)); 224 223 return std_req_complete; 225 224 } 226 225
+2 -1
drivers/usb/gadget/udc/at91_udc.c
··· 16 16 #include <linux/delay.h> 17 17 #include <linux/ioport.h> 18 18 #include <linux/slab.h> 19 + #include <linux/string_choices.h> 19 20 #include <linux/errno.h> 20 21 #include <linux/list.h> 21 22 #include <linux/interrupt.h> ··· 132 131 seq_printf(s, "csr %08x rxbytes=%d %s %s %s" EIGHTBITS "\n", 133 132 csr, 134 133 (csr & 0x07ff0000) >> 16, 135 - (csr & (1 << 15)) ? "enabled" : "disabled", 134 + str_enabled_disabled(csr & (1 << 15)), 136 135 (csr & (1 << 11)) ? "DATA1" : "DATA0", 137 136 types[(csr & 0x700) >> 8], 138 137
+7 -6
drivers/usb/gadget/udc/cdns2/cdns2-gadget.c
··· 29 29 #include <linux/pm_runtime.h> 30 30 #include <linux/interrupt.h> 31 31 #include <linux/property.h> 32 + #include <linux/string_choices.h> 32 33 #include <linux/dmapool.h> 33 34 #include <linux/iopoll.h> 34 35 ··· 2234 2233 dev_dbg(pdev->dev, "Init %s, SupType: CTRL: %s, INT: %s, " 2235 2234 "BULK: %s, ISOC %s, SupDir IN: %s, OUT: %s\n", 2236 2235 pep->name, 2237 - (pep->endpoint.caps.type_control) ? "yes" : "no", 2238 - (pep->endpoint.caps.type_int) ? "yes" : "no", 2239 - (pep->endpoint.caps.type_bulk) ? "yes" : "no", 2240 - (pep->endpoint.caps.type_iso) ? "yes" : "no", 2241 - (pep->endpoint.caps.dir_in) ? "yes" : "no", 2242 - (pep->endpoint.caps.dir_out) ? "yes" : "no"); 2236 + str_yes_no(pep->endpoint.caps.type_control), 2237 + str_yes_no(pep->endpoint.caps.type_int), 2238 + str_yes_no(pep->endpoint.caps.type_bulk), 2239 + str_yes_no(pep->endpoint.caps.type_iso), 2240 + str_yes_no(pep->endpoint.caps.dir_in), 2241 + str_yes_no(pep->endpoint.caps.dir_out)); 2243 2242 2244 2243 INIT_LIST_HEAD(&pep->pending_list); 2245 2244 INIT_LIST_HEAD(&pep->deferred_list);
+2 -1
drivers/usb/gadget/udc/dummy_hcd.c
··· 28 28 #include <linux/delay.h> 29 29 #include <linux/ioport.h> 30 30 #include <linux/slab.h> 31 + #include <linux/string_choices.h> 31 32 #include <linux/errno.h> 32 33 #include <linux/init.h> 33 34 #include <linux/hrtimer.h> ··· 626 625 desc->bEndpointAddress & 0x0f, 627 626 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 628 627 usb_ep_type_string(usb_endpoint_type(desc)), 629 - max, ep->stream_en ? "enabled" : "disabled"); 628 + max, str_enabled_disabled(ep->stream_en)); 630 629 631 630 /* at this point real hardware should be NAKing transfers 632 631 * to that endpoint, until a buffer is queued to it.
+2 -1
drivers/usb/gadget/udc/fsl_udc_core.c
··· 22 22 #include <linux/errno.h> 23 23 #include <linux/err.h> 24 24 #include <linux/slab.h> 25 + #include <linux/string_choices.h> 25 26 #include <linux/init.h> 26 27 #include <linux/list.h> 27 28 #include <linux/interrupt.h> ··· 1182 1181 1183 1182 udc = container_of(gadget, struct fsl_udc, gadget); 1184 1183 spin_lock_irqsave(&udc->lock, flags); 1185 - dev_vdbg(&gadget->dev, "VBUS %s\n", is_active ? "on" : "off"); 1184 + dev_vdbg(&gadget->dev, "VBUS %s\n", str_on_off(is_active)); 1186 1185 udc->vbus_active = (is_active != 0); 1187 1186 if (can_pullup(udc)) 1188 1187 fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+2 -1
drivers/usb/gadget/udc/omap_udc.c
··· 18 18 #include <linux/errno.h> 19 19 #include <linux/delay.h> 20 20 #include <linux/slab.h> 21 + #include <linux/string_choices.h> 21 22 #include <linux/timer.h> 22 23 #include <linux/list.h> 23 24 #include <linux/interrupt.h> ··· 1253 1252 1254 1253 udc = container_of(gadget, struct omap_udc, gadget); 1255 1254 spin_lock_irqsave(&udc->lock, flags); 1256 - VDBG("VBUS %s\n", is_active ? "on" : "off"); 1255 + VDBG("VBUS %s\n", str_on_off(is_active)); 1257 1256 udc->vbus_active = (is_active != 0); 1258 1257 if (cpu_is_omap15xx()) { 1259 1258 /* "software" detect, ignored if !VBUS_MODE_1510 */
+2 -1
drivers/usb/gadget/udc/pxa27x_udc.c
··· 20 20 #include <linux/gpio.h> 21 21 #include <linux/gpio/consumer.h> 22 22 #include <linux/slab.h> 23 + #include <linux/string_choices.h> 23 24 #include <linux/prefetch.h> 24 25 #include <linux/byteorder/generic.h> 25 26 #include <linux/platform_data/pxa2xx_udc.h> ··· 1084 1083 1085 1084 is_first_req = list_empty(&ep->queue); 1086 1085 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n", 1087 - _req, is_first_req ? "yes" : "no", 1086 + _req, str_yes_no(is_first_req), 1088 1087 _req->length, _req->buf); 1089 1088 1090 1089 if (!ep->enabled) {
+2 -1
drivers/usb/host/oxu210hp-hcd.c
··· 15 15 #include <linux/ioport.h> 16 16 #include <linux/sched.h> 17 17 #include <linux/slab.h> 18 + #include <linux/string_choices.h> 18 19 #include <linux/errno.h> 19 20 #include <linux/timer.h> 20 21 #include <linux/list.h> ··· 2757 2756 if (!HCS_PPC(oxu->hcs_params)) 2758 2757 return; 2759 2758 2760 - oxu_dbg(oxu, "...power%s ports...\n", is_on ? "up" : "down"); 2759 + oxu_dbg(oxu, "...power%s ports...\n", str_up_down(is_on)); 2761 2760 for (port = HCS_N_PORTS(oxu->hcs_params); port > 0; ) { 2762 2761 if (is_on) 2763 2762 oxu_hub_control(oxu_to_hcd(oxu), SetPortFeature,
+2 -1
drivers/usb/host/sl811-hcd.c
··· 48 48 #include <linux/usb/hcd.h> 49 49 #include <linux/platform_device.h> 50 50 #include <linux/prefetch.h> 51 + #include <linux/string_choices.h> 51 52 #include <linux/debugfs.h> 52 53 #include <linux/seq_file.h> 53 54 ··· 99 98 if (sl811->board && sl811->board->port_power) { 100 99 /* switch VBUS, at 500mA unless hub power budget gets set */ 101 100 dev_dbg(hcd->self.controller, "power %s\n", 102 - is_on ? "on" : "off"); 101 + str_on_off(is_on)); 103 102 sl811->board->port_power(hcd->self.controller, is_on); 104 103 } 105 104
+6
drivers/usb/host/xhci-caps.h
··· 83 83 #define HCC2_CIC(p) ((p) & (1 << 5)) 84 84 /* true: HC support Extended TBC Capability, Isoc burst count > 65535 */ 85 85 #define HCC2_ETC(p) ((p) & (1 << 6)) 86 + /* true: HC support Extended TBC TRB Status Capability */ 87 + #define HCC2_ETC_TSC(p) ((p) & (1 << 7)) 88 + /* true: HC support Get/Set Extended Property Capability */ 89 + #define HCC2_GSC(p) ((p) & (1 << 8)) 90 + /* true: HC support Virtualization Based Trusted I/O Capability */ 91 + #define HCC2_VTC(p) ((p) & (1 << 9))
+1 -1
drivers/usb/host/xhci-dbgcap.c
··· 957 957 /* set fast poll rate if there are pending data transfers */ 958 958 if (!list_empty(&dbc->eps[BULK_OUT].list_pending) || 959 959 !list_empty(&dbc->eps[BULK_IN].list_pending)) 960 - poll_interval = 1; 960 + poll_interval = 0; 961 961 break; 962 962 default: 963 963 dev_info(dbc->dev, "stop handling dbc events\n");
+65 -33
drivers/usb/host/xhci-dbgtty.c
··· 110 110 } 111 111 } 112 112 113 + /* 114 + * Queue received data to tty buffer and push it. 115 + * 116 + * Returns nr of remaining bytes that didn't fit tty buffer, i.e. 0 if all 117 + * bytes sucessfullt moved. In case of error returns negative errno. 118 + * Call with lock held 119 + */ 120 + static int dbc_rx_push_buffer(struct dbc_port *port, struct dbc_request *req) 121 + { 122 + char *packet = req->buf; 123 + unsigned int n, size = req->actual; 124 + int count; 125 + 126 + if (!req->actual) 127 + return 0; 128 + 129 + /* if n_read is set then request was partially moved to tty buffer */ 130 + n = port->n_read; 131 + if (n) { 132 + packet += n; 133 + size -= n; 134 + } 135 + 136 + count = tty_insert_flip_string(&port->port, packet, size); 137 + if (count) 138 + tty_flip_buffer_push(&port->port); 139 + if (count != size) { 140 + port->n_read += count; 141 + return size - count; 142 + } 143 + 144 + port->n_read = 0; 145 + return 0; 146 + } 147 + 113 148 static void 114 149 dbc_read_complete(struct xhci_dbc *dbc, struct dbc_request *req) 115 150 { 116 151 unsigned long flags; 117 152 struct dbc_port *port = dbc_to_port(dbc); 153 + struct tty_struct *tty; 154 + int untransferred; 155 + 156 + tty = port->port.tty; 118 157 119 158 spin_lock_irqsave(&port->port_lock, flags); 159 + 160 + /* 161 + * Only defer copyig data to tty buffer in case: 162 + * - !list_empty(&port->read_queue), there are older pending data 163 + * - tty is throttled 164 + * - failed to copy all data to buffer, defer remaining part 165 + */ 166 + 167 + if (list_empty(&port->read_queue) && tty && !tty_throttled(tty)) { 168 + untransferred = dbc_rx_push_buffer(port, req); 169 + if (untransferred == 0) { 170 + list_add_tail(&req->list_pool, &port->read_pool); 171 + if (req->status != -ESHUTDOWN) 172 + dbc_start_rx(port); 173 + goto out; 174 + } 175 + } 176 + 177 + /* defer moving data from req to tty buffer to a tasklet */ 120 178 list_add_tail(&req->list_pool, &port->read_queue); 121 179 tasklet_schedule(&port->push); 180 + out: 122 181 spin_unlock_irqrestore(&port->port_lock, flags); 123 182 } 124 183 ··· 390 331 struct dbc_request *req; 391 332 struct tty_struct *tty; 392 333 unsigned long flags; 393 - bool do_push = false; 394 334 bool disconnect = false; 395 335 struct dbc_port *port = from_tasklet(port, t, push); 396 336 struct list_head *queue = &port->read_queue; 337 + int untransferred; 397 338 398 339 spin_lock_irqsave(&port->port_lock, flags); 399 340 tty = port->port.tty; ··· 415 356 break; 416 357 } 417 358 418 - if (req->actual) { 419 - char *packet = req->buf; 420 - unsigned int n, size = req->actual; 421 - int count; 422 - 423 - n = port->n_read; 424 - if (n) { 425 - packet += n; 426 - size -= n; 427 - } 428 - 429 - count = tty_insert_flip_string(&port->port, packet, 430 - size); 431 - if (count) 432 - do_push = true; 433 - if (count != size) { 434 - port->n_read += count; 435 - break; 436 - } 437 - port->n_read = 0; 438 - } 359 + untransferred = dbc_rx_push_buffer(port, req); 360 + if (untransferred > 0) 361 + break; 439 362 440 363 list_move_tail(&req->list_pool, &port->read_pool); 441 364 } 442 365 443 - if (do_push) 444 - tty_flip_buffer_push(&port->port); 445 - 446 - if (!list_empty(queue) && tty) { 447 - if (!tty_throttled(tty)) { 448 - if (do_push) 449 - tasklet_schedule(&port->push); 450 - else 451 - pr_warn("ttyDBC0: RX not scheduled?\n"); 452 - } 453 - } 366 + if (!list_empty(queue)) 367 + tasklet_schedule(&port->push); 454 368 455 369 if (!disconnect) 456 370 dbc_start_rx(port);
+3
drivers/usb/host/xhci-plat.c
··· 330 330 usb3_hcd->can_do_streams = 1; 331 331 332 332 if (xhci->shared_hcd) { 333 + xhci->shared_hcd->rsrc_start = hcd->rsrc_start; 334 + xhci->shared_hcd->rsrc_len = hcd->rsrc_len; 333 335 ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); 334 336 if (ret) 335 337 goto put_usb3_hcd; ··· 569 567 static const struct acpi_device_id usb_xhci_acpi_match[] = { 570 568 /* XHCI-compliant USB Controller */ 571 569 { "PNP0D10", }, 570 + { "PNP0D15", }, 572 571 { } 573 572 }; 574 573 MODULE_DEVICE_TABLE(acpi, usb_xhci_acpi_match);
+11 -7
drivers/usb/host/xhci-ring.c
··· 55 55 #include <linux/jiffies.h> 56 56 #include <linux/scatterlist.h> 57 57 #include <linux/slab.h> 58 + #include <linux/string_choices.h> 58 59 #include <linux/dma-mapping.h> 59 60 #include "xhci.h" 60 61 #include "xhci-trace.h" ··· 423 422 if ((xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue) && 424 423 !(xhci->xhc_state & XHCI_STATE_DYING)) { 425 424 xhci->current_cmd = cur_cmd; 426 - xhci_mod_cmd_timer(xhci); 425 + if (cur_cmd) 426 + xhci_mod_cmd_timer(xhci); 427 427 xhci_ring_cmd_db(xhci); 428 428 } 429 429 } ··· 1651 1649 NEC_FW_MINOR(le32_to_cpu(event->status))); 1652 1650 } 1653 1651 1654 - static void xhci_complete_del_and_free_cmd(struct xhci_command *cmd, u32 status) 1652 + static void xhci_complete_del_and_free_cmd(struct xhci_command *cmd, u32 comp_code, u32 comp_param) 1655 1653 { 1656 1654 list_del(&cmd->cmd_list); 1657 1655 1658 1656 if (cmd->completion) { 1659 - cmd->status = status; 1657 + cmd->status = comp_code; 1658 + cmd->comp_param = comp_param; 1660 1659 complete(cmd->completion); 1661 1660 } else { 1662 1661 kfree(cmd); ··· 1669 1666 struct xhci_command *cur_cmd, *tmp_cmd; 1670 1667 xhci->current_cmd = NULL; 1671 1668 list_for_each_entry_safe(cur_cmd, tmp_cmd, &xhci->cmd_list, cmd_list) 1672 - xhci_complete_del_and_free_cmd(cur_cmd, COMP_COMMAND_ABORTED); 1669 + xhci_complete_del_and_free_cmd(cur_cmd, COMP_COMMAND_ABORTED, 0); 1673 1670 } 1674 1671 1675 1672 void xhci_handle_command_timeout(struct work_struct *work) ··· 1754 1751 struct xhci_event_cmd *event) 1755 1752 { 1756 1753 unsigned int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); 1754 + u32 status = le32_to_cpu(event->status); 1757 1755 u64 cmd_dma; 1758 1756 dma_addr_t cmd_dequeue_dma; 1759 1757 u32 cmd_comp_code; ··· 1883 1879 } 1884 1880 1885 1881 event_handled: 1886 - xhci_complete_del_and_free_cmd(cmd, cmd_comp_code); 1882 + xhci_complete_del_and_free_cmd(cmd, cmd_comp_code, COMP_PARAM(status)); 1887 1883 1888 1884 inc_deq(xhci, xhci->cmd_ring); 1889 1885 } ··· 3442 3438 if (xhci_interval != ep_interval) { 3443 3439 dev_dbg_ratelimited(&urb->dev->dev, 3444 3440 "Driver uses different interval (%d microframe%s) than xHCI (%d microframe%s)\n", 3445 - ep_interval, ep_interval == 1 ? "" : "s", 3446 - xhci_interval, xhci_interval == 1 ? "" : "s"); 3441 + ep_interval, str_plural(ep_interval), 3442 + xhci_interval, str_plural(xhci_interval)); 3447 3443 urb->interval = xhci_interval; 3448 3444 /* Convert back to frames for LS/FS devices */ 3449 3445 if (urb->dev->speed == USB_SPEED_LOW ||
+4 -3
drivers/usb/host/xhci-tegra.c
··· 26 26 #include <linux/regulator/consumer.h> 27 27 #include <linux/reset.h> 28 28 #include <linux/slab.h> 29 + #include <linux/string_choices.h> 29 30 #include <linux/usb/otg.h> 30 31 #include <linux/usb/phy.h> 31 32 #include <linux/usb/role.h> ··· 725 724 if (err < 0) { 726 725 dev_err(dev, 727 726 "failed to %s LFPS detection on USB3#%u: %d\n", 728 - enable ? "enable" : "disable", port, err); 727 + str_enable_disable(enable), port, err); 729 728 rsp.cmd = MBOX_CMD_NAK; 730 729 } else { 731 730 rsp.cmd = MBOX_CMD_ACK; ··· 1350 1349 u32 status; 1351 1350 int ret; 1352 1351 1353 - dev_dbg(tegra->dev, "host mode %s\n", tegra->host_mode ? "on" : "off"); 1352 + dev_dbg(tegra->dev, "host mode %s\n", str_on_off(tegra->host_mode)); 1354 1353 1355 1354 mutex_lock(&tegra->lock); 1356 1355 ··· 1668 1667 goto put_padctl; 1669 1668 } 1670 1669 1671 - if (!of_property_read_bool(pdev->dev.of_node, "power-domains")) { 1670 + if (!of_property_present(pdev->dev.of_node, "power-domains")) { 1672 1671 tegra->host_rst = devm_reset_control_get(&pdev->dev, 1673 1672 "xusb_host"); 1674 1673 if (IS_ERR(tegra->host_rst)) {
+2 -1
drivers/usb/host/xhci.c
··· 17 17 #include <linux/module.h> 18 18 #include <linux/moduleparam.h> 19 19 #include <linux/slab.h> 20 + #include <linux/string_choices.h> 20 21 #include <linux/dmi.h> 21 22 #include <linux/dma-mapping.h> 22 23 ··· 4524 4523 hlpm_addr = ports[port_num]->addr + PORTHLPMC; 4525 4524 4526 4525 xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", 4527 - enable ? "enable" : "disable", port_num + 1); 4526 + str_enable_disable(enable), port_num + 1); 4528 4527 4529 4528 if (enable) { 4530 4529 /* Host supports BESL timeout instead of HIRD */
+4
drivers/usb/host/xhci.h
··· 529 529 /* Input context for changing device state */ 530 530 struct xhci_container_ctx *in_ctx; 531 531 u32 status; 532 + u32 comp_param; 532 533 int slot_id; 533 534 /* If completion is null, no one is waiting on this command 534 535 * and the structure can be freed after the command completes. ··· 959 958 __le32 status; 960 959 __le32 flags; 961 960 }; 961 + 962 + /* status bitmasks */ 963 + #define COMP_PARAM(p) ((p) & 0xffffff) /* Command Completion Parameter */ 962 964 963 965 /* Address device - disable SetAddress */ 964 966 #define TRB_BSR (1<<9)
+2 -1
drivers/usb/mtu3/mtu3_debugfs.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include <linux/uaccess.h> 11 12 12 13 #include "mtu3.h" ··· 480 479 struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; 481 480 482 481 seq_printf(sf, "vbus state: %s\n(echo on/off)\n", 483 - regulator_is_enabled(otg_sx->vbus) ? "on" : "off"); 482 + str_on_off(regulator_is_enabled(otg_sx->vbus))); 484 483 485 484 return 0; 486 485 }
+2 -1
drivers/usb/mtu3/mtu3_dr.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include "mtu3.h" 11 12 #include "mtu3_dr.h" 12 13 #include "mtu3_debug.h" ··· 110 109 if (!vbus) 111 110 return 0; 112 111 113 - dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, is_on ? "on" : "off"); 112 + dev_dbg(ssusb->dev, "%s: turn %s\n", __func__, str_on_off(is_on)); 114 113 115 114 if (is_on) { 116 115 ret = regulator_enable(vbus);
+2 -1
drivers/usb/mtu3/mtu3_gadget.c
··· 7 7 * Author: Chunfeng Yun <chunfeng.yun@mediatek.com> 8 8 */ 9 9 10 + #include <linux/string_choices.h> 10 11 #include "mtu3.h" 11 12 #include "mtu3_trace.h" 12 13 ··· 491 490 unsigned long flags; 492 491 493 492 dev_dbg(mtu->dev, "%s (%s) for %sactive device\n", __func__, 494 - is_on ? "on" : "off", mtu->is_active ? "" : "in"); 493 + str_on_off(is_on), mtu->is_active ? "" : "in"); 495 494 496 495 pm_runtime_get_sync(mtu->dev); 497 496
+2 -1
drivers/usb/musb/da8xx.c
··· 21 21 #include <linux/of_platform.h> 22 22 #include <linux/phy/phy.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/dma-mapping.h> 25 26 #include <linux/usb/usb_phy_generic.h> 26 27 ··· 307 306 } 308 307 309 308 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 310 - drvvbus ? "on" : "off", 309 + str_on_off(drvvbus), 311 310 usb_otg_state_string(musb->xceiv->otg->state), 312 311 err ? " ERROR" : "", 313 312 devctl);
+2 -1
drivers/usb/musb/musb_core.c
··· 72 72 #include <linux/kobject.h> 73 73 #include <linux/prefetch.h> 74 74 #include <linux/platform_device.h> 75 + #include <linux/string_choices.h> 75 76 #include <linux/io.h> 76 77 #include <linux/iopoll.h> 77 78 #include <linux/dma-mapping.h> ··· 1938 1937 pm_runtime_put_sync(dev); 1939 1938 1940 1939 return sprintf(buf, "Vbus %s, timeout %lu msec\n", 1941 - vbus ? "on" : "off", val); 1940 + str_on_off(vbus), val); 1942 1941 } 1943 1942 static DEVICE_ATTR_RW(vbus); 1944 1943
+2 -1
drivers/usb/musb/musb_dsps.c
··· 24 24 #include <linux/usb/usb_phy_generic.h> 25 25 #include <linux/platform_data/usb-omap.h> 26 26 #include <linux/sizes.h> 27 + #include <linux/string_choices.h> 27 28 28 29 #include <linux/of.h> 29 30 #include <linux/of_address.h> ··· 379 378 380 379 /* NOTE: this must complete power-on within 100 ms. */ 381 380 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 382 - drvvbus ? "on" : "off", 381 + str_on_off(drvvbus), 383 382 usb_otg_state_string(musb->xceiv->otg->state), 384 383 err ? " ERROR" : "", 385 384 devctl);
+2 -1
drivers/usb/musb/musb_gadget.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/smp.h> 16 16 #include <linux/spinlock.h> 17 + #include <linux/string_choices.h> 17 18 #include <linux/delay.h> 18 19 #include <linux/dma-mapping.h> 19 20 #include <linux/slab.h> ··· 1607 1606 /* FIXME if on, HdrcStart; if off, HdrcStop */ 1608 1607 1609 1608 musb_dbg(musb, "gadget D+ pullup %s", 1610 - is_on ? "on" : "off"); 1609 + str_on_off(is_on)); 1611 1610 musb_writeb(musb->mregs, MUSB_POWER, power); 1612 1611 } 1613 1612
+2 -1
drivers/usb/musb/musb_host.c
··· 13 13 #include <linux/delay.h> 14 14 #include <linux/sched.h> 15 15 #include <linux/slab.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/errno.h> 17 18 #include <linux/list.h> 18 19 #include <linux/dma-mapping.h> ··· 1029 1028 + urb->actual_length); 1030 1029 musb_dbg(musb, "Sending %d byte%s to ep0 fifo %p", 1031 1030 fifo_count, 1032 - (fifo_count == 1) ? "" : "s", 1031 + str_plural(fifo_count), 1033 1032 fifo_dest); 1034 1033 musb_write_fifo(hw_ep, fifo_count, fifo_dest); 1035 1034
+2 -1
drivers/usb/phy/phy-fsl-usb.c
··· 12 12 #include <linux/kernel.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/slab.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/proc_fs.h> 16 17 #include <linux/errno.h> 17 18 #include <linux/interrupt.h> ··· 530 529 if (!otg->gadget || !otg->gadget->dev.parent) 531 530 return -ENODEV; 532 531 533 - VDBG("gadget %s\n", on ? "on" : "off"); 532 + VDBG("gadget %s\n", str_on_off(on)); 534 533 dev = otg->gadget->dev.parent; 535 534 536 535 if (on) {
+2 -1
drivers/usb/phy/phy-mv-usb.c
··· 15 15 #include <linux/clk.h> 16 16 #include <linux/workqueue.h> 17 17 #include <linux/platform_device.h> 18 + #include <linux/string_choices.h> 18 19 19 20 #include <linux/usb.h> 20 21 #include <linux/usb/ch9.h> ··· 218 217 if (!otg->gadget) 219 218 return; 220 219 221 - dev_info(mvotg->phy.dev, "gadget %s\n", on ? "on" : "off"); 220 + dev_info(mvotg->phy.dev, "gadget %s\n", str_on_off(on)); 222 221 223 222 if (on) 224 223 usb_gadget_vbus_connect(otg->gadget);
+2 -1
drivers/usb/phy/phy-tahvo.c
··· 18 18 #include <linux/extcon-provider.h> 19 19 #include <linux/kernel.h> 20 20 #include <linux/module.h> 21 + #include <linux/string_choices.h> 21 22 #include <linux/usb/otg.h> 22 23 #include <linux/mfd/retu.h> 23 24 #include <linux/usb/gadget.h> ··· 64 63 struct device_attribute *attr, char *buf) 65 64 { 66 65 struct tahvo_usb *tu = dev_get_drvdata(device); 67 - return sprintf(buf, "%s\n", tu->vbus_state ? "on" : "off"); 66 + return sprintf(buf, "%s\n", str_on_off(tu->vbus_state)); 68 67 } 69 68 static DEVICE_ATTR_RO(vbus); 70 69
-26
drivers/usb/phy/phy.c
··· 346 346 usb_put_phy(res->phy); 347 347 } 348 348 349 - static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) 350 - { 351 - struct usb_phy **phy = res; 352 - 353 - return *phy == match_data; 354 - } 355 - 356 349 static void usb_charger_init(struct usb_phy *usb_phy) 357 350 { 358 351 usb_phy->chg_type = UNKNOWN_TYPE; ··· 606 613 return phy; 607 614 } 608 615 EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle); 609 - 610 - /** 611 - * devm_usb_put_phy - release the USB PHY 612 - * @dev: device that wants to release this phy 613 - * @phy: the phy returned by devm_usb_get_phy() 614 - * 615 - * destroys the devres associated with this phy and invokes usb_put_phy 616 - * to release the phy. 617 - * 618 - * For use by USB host and peripheral drivers. 619 - */ 620 - void devm_usb_put_phy(struct device *dev, struct usb_phy *phy) 621 - { 622 - int r; 623 - 624 - r = devres_release(dev, devm_usb_phy_release, devm_usb_phy_match, phy); 625 - dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); 626 - } 627 - EXPORT_SYMBOL_GPL(devm_usb_put_phy); 628 616 629 617 /** 630 618 * usb_put_phy - release the USB PHY
+31 -4
drivers/usb/serial/ch341.c
··· 63 63 #define CH341_REG_DIVISOR 0x13 64 64 #define CH341_REG_LCR 0x18 65 65 #define CH341_REG_LCR2 0x25 66 + #define CH341_REG_FLOW_CTL 0x27 66 67 67 68 #define CH341_NBREAK_BITS 0x01 68 69 ··· 77 76 #define CH341_LCR_CS7 0x02 78 77 #define CH341_LCR_CS6 0x01 79 78 #define CH341_LCR_CS5 0x00 79 + 80 + #define CH341_FLOW_CTL_NONE 0x00 81 + #define CH341_FLOW_CTL_RTSCTS 0x01 80 82 81 83 #define CH341_QUIRK_LIMITED_PRESCALER BIT(0) 82 84 #define CH341_QUIRK_SIMULATE_BREAK BIT(1) ··· 482 478 return r; 483 479 } 484 480 481 + static void ch341_set_flow_control(struct tty_struct *tty, 482 + struct usb_serial_port *port, 483 + const struct ktermios *old_termios) 484 + { 485 + u16 flow_ctl; 486 + int r; 487 + 488 + if (C_CRTSCTS(tty)) 489 + flow_ctl = CH341_FLOW_CTL_RTSCTS; 490 + else 491 + flow_ctl = CH341_FLOW_CTL_NONE; 492 + 493 + r = ch341_control_out(port->serial->dev, 494 + CH341_REQ_WRITE_REG, 495 + (CH341_REG_FLOW_CTL << 8) | CH341_REG_FLOW_CTL, 496 + (flow_ctl << 8) | flow_ctl); 497 + if (r < 0 && old_termios) { 498 + tty->termios.c_cflag &= ~CRTSCTS; 499 + tty->termios.c_cflag |= (old_termios->c_cflag & CRTSCTS); 500 + } 501 + } 502 + 485 503 /* Old_termios contains the original termios settings and 486 504 * tty->termios contains the new setting to be used. 487 505 */ ··· 572 546 spin_unlock_irqrestore(&priv->lock, flags); 573 547 574 548 ch341_set_handshake(port->serial->dev, priv->mcr); 549 + 550 + ch341_set_flow_control(tty, port, old_termios); 575 551 } 576 552 577 553 /* ··· 660 632 661 633 static int ch341_break_ctl(struct tty_struct *tty, int break_state) 662 634 { 663 - const uint16_t ch341_break_reg = 664 - ((uint16_t) CH341_REG_LCR << 8) | CH341_REG_BREAK; 635 + const u16 ch341_break_reg = (CH341_REG_LCR << 8) | CH341_REG_BREAK; 665 636 struct usb_serial_port *port = tty->driver_data; 666 637 struct ch341_private *priv = usb_get_serial_port_data(port); 638 + u16 reg_contents; 639 + u8 break_reg[2]; 667 640 int r; 668 - uint16_t reg_contents; 669 - uint8_t break_reg[2]; 670 641 671 642 if (priv->quirks & CH341_QUIRK_SIMULATE_BREAK) 672 643 return ch341_simulate_break(tty, break_state);
+1 -1
drivers/usb/serial/quatech2.c
··· 503 503 504 504 newport = *(ch + 3); 505 505 506 - if (newport > serial->num_ports) { 506 + if (newport >= serial->num_ports) { 507 507 dev_err(&port->dev, 508 508 "%s - port change to invalid port: %i\n", 509 509 __func__, newport);
+1 -2
drivers/usb/storage/Kconfig
··· 3 3 # USB Storage driver configuration 4 4 # 5 5 6 - comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may" 7 - comment "also be needed; see USB_STORAGE Help for more info" 6 + comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed; see USB_STORAGE Help for more info" 8 7 9 8 config USB_STORAGE 10 9 tristate "USB Mass Storage support"
+2 -2
drivers/usb/storage/shuttle_usbat.c
··· 32 32 #include <linux/errno.h> 33 33 #include <linux/module.h> 34 34 #include <linux/slab.h> 35 + #include <linux/string_choices.h> 35 36 #include <linux/cdrom.h> 36 37 37 38 #include <scsi/scsi.h> ··· 652 651 return USB_STOR_TRANSPORT_FAILED; 653 652 654 653 usb_stor_dbg(us, "Redoing %s\n", 655 - direction == DMA_TO_DEVICE 656 - ? "write" : "read"); 654 + str_write_read(direction == DMA_TO_DEVICE)); 657 655 658 656 } else if (result != USB_STOR_XFER_GOOD) 659 657 return USB_STOR_TRANSPORT_ERROR;
+2 -6
drivers/usb/storage/transport.c
··· 1087 1087 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n", 1088 1088 result, us->iobuf[0]); 1089 1089 1090 - /* 1091 - * If we have a successful request, return the result if valid. The 1092 - * CBW LUN field is 4 bits wide, so the value reported by the device 1093 - * should fit into that. 1094 - */ 1090 + /* If we have a successful request, return the result if valid. */ 1095 1091 if (result > 0) { 1096 - if (us->iobuf[0] < 16) { 1092 + if (us->iobuf[0] <= US_BULK_MAX_LUN_LIMIT) { 1097 1093 return us->iobuf[0]; 1098 1094 } else { 1099 1095 dev_info(&us->pusb_intf->dev,
+9
drivers/usb/typec/altmodes/Kconfig
··· 23 23 To compile this driver as a module, choose M here: the 24 24 module will be called typec_nvidia. 25 25 26 + config TYPEC_TBT_ALTMODE 27 + tristate "Thunderbolt3 Alternate Mode driver" 28 + help 29 + Select this option if you have Thunderbolt3 hardware on your 30 + system. 31 + 32 + To compile this driver as a module, choose M here: the 33 + module will be called typec_thunderbolt. 34 + 26 35 endmenu
+2
drivers/usb/typec/altmodes/Makefile
··· 4 4 typec_displayport-y := displayport.o 5 5 obj-$(CONFIG_TYPEC_NVIDIA_ALTMODE) += typec_nvidia.o 6 6 typec_nvidia-y := nvidia.o 7 + obj-$(CONFIG_TYPEC_TBT_ALTMODE) += typec_thunderbolt.o 8 + typec_thunderbolt-y := thunderbolt.o
+2 -2
drivers/usb/typec/altmodes/displayport.c
··· 252 252 case DP_STATE_ENTER: 253 253 ret = typec_altmode_enter(dp->alt, NULL); 254 254 if (ret && ret != -EBUSY) 255 - dev_err(&dp->alt->dev, "failed to enter mode\n"); 255 + dev_err(&dp->alt->dev, "failed to enter mode: %d\n", ret); 256 256 break; 257 257 case DP_STATE_ENTER_PRIME: 258 258 ret = typec_cable_altmode_enter(dp->alt, TYPEC_PLUG_SOP_P, NULL); ··· 791 791 EXPORT_SYMBOL_GPL(dp_altmode_remove); 792 792 793 793 static const struct typec_device_id dp_typec_id[] = { 794 - { USB_TYPEC_DP_SID, USB_TYPEC_DP_MODE }, 794 + { USB_TYPEC_DP_SID }, 795 795 { }, 796 796 }; 797 797 MODULE_DEVICE_TABLE(typec, dp_typec_id);
+1 -1
drivers/usb/typec/altmodes/nvidia.c
··· 24 24 } 25 25 26 26 static const struct typec_device_id nvidia_typec_id[] = { 27 - { USB_TYPEC_NVIDIA_VLINK_SID, TYPEC_ANY_MODE }, 27 + { USB_TYPEC_NVIDIA_VLINK_SID }, 28 28 { }, 29 29 }; 30 30 MODULE_DEVICE_TABLE(typec, nvidia_typec_id);
+388
drivers/usb/typec/altmodes/thunderbolt.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * USB Typec-C Thunderbolt3 Alternate Mode driver 4 + * 5 + * Copyright (C) 2019 Intel Corporation 6 + * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com> 7 + */ 8 + 9 + #include <linux/lockdep.h> 10 + #include <linux/module.h> 11 + #include <linux/mutex.h> 12 + #include <linux/workqueue.h> 13 + #include <linux/usb/pd_vdo.h> 14 + #include <linux/usb/typec_altmode.h> 15 + #include <linux/usb/typec_tbt.h> 16 + 17 + enum tbt_state { 18 + TBT_STATE_IDLE, 19 + TBT_STATE_SOP_P_ENTER, 20 + TBT_STATE_SOP_PP_ENTER, 21 + TBT_STATE_ENTER, 22 + TBT_STATE_EXIT, 23 + TBT_STATE_SOP_PP_EXIT, 24 + TBT_STATE_SOP_P_EXIT 25 + }; 26 + 27 + struct tbt_altmode { 28 + enum tbt_state state; 29 + struct typec_cable *cable; 30 + struct typec_altmode *alt; 31 + struct typec_altmode *plug[2]; 32 + u32 enter_vdo; 33 + 34 + struct work_struct work; 35 + struct mutex lock; /* device lock */ 36 + }; 37 + 38 + static bool tbt_ready(struct typec_altmode *alt); 39 + 40 + static int tbt_enter_mode(struct tbt_altmode *tbt) 41 + { 42 + struct typec_altmode *plug = tbt->plug[TYPEC_PLUG_SOP_P]; 43 + u32 vdo; 44 + 45 + vdo = tbt->alt->vdo & (TBT_VENDOR_SPECIFIC_B0 | TBT_VENDOR_SPECIFIC_B1); 46 + vdo |= tbt->alt->vdo & TBT_INTEL_SPECIFIC_B0; 47 + vdo |= TBT_MODE; 48 + 49 + if (plug) { 50 + if (typec_cable_is_active(tbt->cable)) 51 + vdo |= TBT_ENTER_MODE_ACTIVE_CABLE; 52 + 53 + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_SPEED(plug->vdo)); 54 + vdo |= plug->vdo & TBT_CABLE_ROUNDED; 55 + vdo |= plug->vdo & TBT_CABLE_OPTICAL; 56 + vdo |= plug->vdo & TBT_CABLE_RETIMER; 57 + vdo |= plug->vdo & TBT_CABLE_LINK_TRAINING; 58 + } else { 59 + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_USB3_PASSIVE); 60 + } 61 + 62 + tbt->enter_vdo = vdo; 63 + return typec_altmode_enter(tbt->alt, &vdo); 64 + } 65 + 66 + static void tbt_altmode_work(struct work_struct *work) 67 + { 68 + struct tbt_altmode *tbt = container_of(work, struct tbt_altmode, work); 69 + int ret; 70 + 71 + mutex_lock(&tbt->lock); 72 + 73 + switch (tbt->state) { 74 + case TBT_STATE_SOP_P_ENTER: 75 + ret = typec_cable_altmode_enter(tbt->alt, TYPEC_PLUG_SOP_P, NULL); 76 + if (ret) { 77 + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_P]->dev, 78 + "failed to enter mode (%d)\n", ret); 79 + goto disable_plugs; 80 + } 81 + break; 82 + case TBT_STATE_SOP_PP_ENTER: 83 + ret = typec_cable_altmode_enter(tbt->alt, TYPEC_PLUG_SOP_PP, NULL); 84 + if (ret) { 85 + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_PP]->dev, 86 + "failed to enter mode (%d)\n", ret); 87 + goto disable_plugs; 88 + } 89 + break; 90 + case TBT_STATE_ENTER: 91 + ret = tbt_enter_mode(tbt); 92 + if (ret) 93 + dev_dbg(&tbt->alt->dev, "failed to enter mode (%d)\n", 94 + ret); 95 + break; 96 + case TBT_STATE_EXIT: 97 + typec_altmode_exit(tbt->alt); 98 + break; 99 + case TBT_STATE_SOP_PP_EXIT: 100 + typec_cable_altmode_exit(tbt->alt, TYPEC_PLUG_SOP_PP); 101 + break; 102 + case TBT_STATE_SOP_P_EXIT: 103 + typec_cable_altmode_exit(tbt->alt, TYPEC_PLUG_SOP_P); 104 + break; 105 + default: 106 + break; 107 + } 108 + 109 + tbt->state = TBT_STATE_IDLE; 110 + 111 + mutex_unlock(&tbt->lock); 112 + return; 113 + 114 + disable_plugs: 115 + for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) { 116 + if (tbt->plug[i]) 117 + typec_altmode_put_plug(tbt->plug[i]); 118 + 119 + tbt->plug[i] = NULL; 120 + } 121 + 122 + tbt->state = TBT_STATE_ENTER; 123 + schedule_work(&tbt->work); 124 + mutex_unlock(&tbt->lock); 125 + } 126 + 127 + /* 128 + * If SOP' is available, enter that first (which will trigger a VDM response 129 + * that will enter SOP" if available and then the port). If entering SOP' fails, 130 + * stop attempting to enter either cable altmode (probably not supported) and 131 + * directly enter the port altmode. 132 + */ 133 + static int tbt_enter_modes_ordered(struct typec_altmode *alt) 134 + { 135 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 136 + int ret = 0; 137 + 138 + lockdep_assert_held(&tbt->lock); 139 + 140 + if (!tbt_ready(tbt->alt)) 141 + return -ENODEV; 142 + 143 + if (tbt->plug[TYPEC_PLUG_SOP_P]) { 144 + ret = typec_cable_altmode_enter(alt, TYPEC_PLUG_SOP_P, NULL); 145 + if (ret < 0) { 146 + for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) { 147 + if (tbt->plug[i]) 148 + typec_altmode_put_plug(tbt->plug[i]); 149 + 150 + tbt->plug[i] = NULL; 151 + } 152 + } else { 153 + return ret; 154 + } 155 + } 156 + 157 + return tbt_enter_mode(tbt); 158 + } 159 + 160 + static int tbt_cable_altmode_vdm(struct typec_altmode *alt, 161 + enum typec_plug_index sop, const u32 hdr, 162 + const u32 *vdo, int count) 163 + { 164 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 165 + int cmd_type = PD_VDO_CMDT(hdr); 166 + int cmd = PD_VDO_CMD(hdr); 167 + 168 + mutex_lock(&tbt->lock); 169 + 170 + if (tbt->state != TBT_STATE_IDLE) { 171 + mutex_unlock(&tbt->lock); 172 + return -EBUSY; 173 + } 174 + 175 + switch (cmd_type) { 176 + case CMDT_RSP_ACK: 177 + switch (cmd) { 178 + case CMD_ENTER_MODE: 179 + /* 180 + * Following the order described in USB Type-C Spec 181 + * R2.0 Section 6.7.3: SOP', SOP", then port. 182 + */ 183 + if (sop == TYPEC_PLUG_SOP_P) { 184 + if (tbt->plug[TYPEC_PLUG_SOP_PP]) 185 + tbt->state = TBT_STATE_SOP_PP_ENTER; 186 + else 187 + tbt->state = TBT_STATE_ENTER; 188 + } else if (sop == TYPEC_PLUG_SOP_PP) 189 + tbt->state = TBT_STATE_ENTER; 190 + 191 + break; 192 + case CMD_EXIT_MODE: 193 + /* Exit in opposite order: Port, SOP", then SOP'. */ 194 + if (sop == TYPEC_PLUG_SOP_PP) 195 + tbt->state = TBT_STATE_SOP_P_EXIT; 196 + break; 197 + } 198 + break; 199 + default: 200 + break; 201 + } 202 + 203 + if (tbt->state != TBT_STATE_IDLE) 204 + schedule_work(&tbt->work); 205 + 206 + mutex_unlock(&tbt->lock); 207 + return 0; 208 + } 209 + 210 + static int tbt_altmode_vdm(struct typec_altmode *alt, 211 + const u32 hdr, const u32 *vdo, int count) 212 + { 213 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 214 + struct typec_thunderbolt_data data; 215 + int cmd_type = PD_VDO_CMDT(hdr); 216 + int cmd = PD_VDO_CMD(hdr); 217 + 218 + mutex_lock(&tbt->lock); 219 + 220 + if (tbt->state != TBT_STATE_IDLE) { 221 + mutex_unlock(&tbt->lock); 222 + return -EBUSY; 223 + } 224 + 225 + switch (cmd_type) { 226 + case CMDT_RSP_ACK: 227 + /* Port altmode is last to enter and first to exit. */ 228 + switch (cmd) { 229 + case CMD_ENTER_MODE: 230 + memset(&data, 0, sizeof(data)); 231 + 232 + data.device_mode = tbt->alt->vdo; 233 + data.enter_vdo = tbt->enter_vdo; 234 + if (tbt->plug[TYPEC_PLUG_SOP_P]) 235 + data.cable_mode = tbt->plug[TYPEC_PLUG_SOP_P]->vdo; 236 + 237 + typec_altmode_notify(alt, TYPEC_STATE_MODAL, &data); 238 + break; 239 + case CMD_EXIT_MODE: 240 + if (tbt->plug[TYPEC_PLUG_SOP_PP]) 241 + tbt->state = TBT_STATE_SOP_PP_EXIT; 242 + else if (tbt->plug[TYPEC_PLUG_SOP_P]) 243 + tbt->state = TBT_STATE_SOP_P_EXIT; 244 + break; 245 + } 246 + break; 247 + case CMDT_RSP_NAK: 248 + switch (cmd) { 249 + case CMD_ENTER_MODE: 250 + dev_warn(&alt->dev, "Enter Mode refused\n"); 251 + break; 252 + default: 253 + break; 254 + } 255 + break; 256 + default: 257 + break; 258 + } 259 + 260 + if (tbt->state != TBT_STATE_IDLE) 261 + schedule_work(&tbt->work); 262 + 263 + mutex_unlock(&tbt->lock); 264 + 265 + return 0; 266 + } 267 + 268 + static int tbt_altmode_activate(struct typec_altmode *alt, int activate) 269 + { 270 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 271 + int ret; 272 + 273 + mutex_lock(&tbt->lock); 274 + 275 + if (activate) 276 + ret = tbt_enter_modes_ordered(alt); 277 + else 278 + ret = typec_altmode_exit(alt); 279 + 280 + mutex_unlock(&tbt->lock); 281 + 282 + return ret; 283 + } 284 + 285 + static const struct typec_altmode_ops tbt_altmode_ops = { 286 + .vdm = tbt_altmode_vdm, 287 + .activate = tbt_altmode_activate 288 + }; 289 + 290 + static const struct typec_cable_ops tbt_cable_ops = { 291 + .vdm = tbt_cable_altmode_vdm, 292 + }; 293 + 294 + static int tbt_altmode_probe(struct typec_altmode *alt) 295 + { 296 + struct tbt_altmode *tbt; 297 + 298 + tbt = devm_kzalloc(&alt->dev, sizeof(*tbt), GFP_KERNEL); 299 + if (!tbt) 300 + return -ENOMEM; 301 + 302 + INIT_WORK(&tbt->work, tbt_altmode_work); 303 + mutex_init(&tbt->lock); 304 + tbt->alt = alt; 305 + 306 + alt->desc = "Thunderbolt3"; 307 + typec_altmode_set_drvdata(alt, tbt); 308 + typec_altmode_set_ops(alt, &tbt_altmode_ops); 309 + 310 + if (tbt_ready(alt)) { 311 + if (tbt->plug[TYPEC_PLUG_SOP_P]) 312 + tbt->state = TBT_STATE_SOP_P_ENTER; 313 + else if (tbt->plug[TYPEC_PLUG_SOP_PP]) 314 + tbt->state = TBT_STATE_SOP_PP_ENTER; 315 + else 316 + tbt->state = TBT_STATE_ENTER; 317 + schedule_work(&tbt->work); 318 + } 319 + 320 + return 0; 321 + } 322 + 323 + static void tbt_altmode_remove(struct typec_altmode *alt) 324 + { 325 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 326 + 327 + for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) { 328 + if (tbt->plug[i]) 329 + typec_altmode_put_plug(tbt->plug[i]); 330 + } 331 + 332 + if (tbt->cable) 333 + typec_cable_put(tbt->cable); 334 + } 335 + 336 + static bool tbt_ready(struct typec_altmode *alt) 337 + { 338 + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); 339 + struct typec_altmode *plug; 340 + 341 + if (tbt->cable) 342 + return true; 343 + 344 + /* Thunderbolt 3 requires a cable with eMarker */ 345 + tbt->cable = typec_cable_get(typec_altmode2port(tbt->alt)); 346 + if (!tbt->cable) 347 + return false; 348 + 349 + /* We accept systems without SOP' or SOP''. This means the port altmode 350 + * driver will be responsible for properly ordering entry/exit. 351 + */ 352 + for (int i = 0; i < TYPEC_PLUG_SOP_PP + 1; i++) { 353 + plug = typec_altmode_get_plug(tbt->alt, i); 354 + if (IS_ERR(plug)) 355 + continue; 356 + 357 + if (!plug || plug->svid != USB_TYPEC_TBT_SID) 358 + break; 359 + 360 + plug->desc = "Thunderbolt3"; 361 + plug->cable_ops = &tbt_cable_ops; 362 + typec_altmode_set_drvdata(plug, tbt); 363 + 364 + tbt->plug[i] = plug; 365 + } 366 + 367 + return true; 368 + } 369 + 370 + static const struct typec_device_id tbt_typec_id[] = { 371 + { USB_TYPEC_TBT_SID }, 372 + { } 373 + }; 374 + MODULE_DEVICE_TABLE(typec, tbt_typec_id); 375 + 376 + static struct typec_altmode_driver tbt_altmode_driver = { 377 + .id_table = tbt_typec_id, 378 + .probe = tbt_altmode_probe, 379 + .remove = tbt_altmode_remove, 380 + .driver = { 381 + .name = "typec-thunderbolt", 382 + } 383 + }; 384 + module_typec_altmode_driver(tbt_altmode_driver); 385 + 386 + MODULE_AUTHOR("Heikki Krogerus <heikki.krogerus@linux.intel.com>"); 387 + MODULE_LICENSE("GPL"); 388 + MODULE_DESCRIPTION("Thunderbolt3 USB Type-C Alternate Mode");
+2 -4
drivers/usb/typec/bus.c
··· 454 454 const struct typec_device_id *id; 455 455 456 456 for (id = drv->id_table; id->svid; id++) 457 - if (id->svid == altmode->svid && 458 - (id->mode == TYPEC_ANY_MODE || id->mode == altmode->mode)) 457 + if (id->svid == altmode->svid) 459 458 return 1; 460 459 return 0; 461 460 } ··· 469 470 if (add_uevent_var(env, "MODE=%u", altmode->mode)) 470 471 return -ENOMEM; 471 472 472 - return add_uevent_var(env, "MODALIAS=typec:id%04Xm%02X", 473 - altmode->svid, altmode->mode); 473 + return add_uevent_var(env, "MODALIAS=typec:id%04X", altmode->svid); 474 474 } 475 475 476 476 static int typec_altmode_create_links(struct altmode *alt)
+9 -7
drivers/usb/typec/class.c
··· 10 10 #include <linux/mutex.h> 11 11 #include <linux/property.h> 12 12 #include <linux/slab.h> 13 + #include <linux/string_choices.h> 13 14 #include <linux/usb/pd_vdo.h> 14 15 #include <linux/usb/typec_mux.h> 15 16 #include <linux/usb/typec_retimer.h> ··· 238 237 if (!is_typec_altmode(dev)) 239 238 return 0; 240 239 241 - return ((adev->svid == id->svid) && (adev->mode == id->mode)); 240 + return (adev->svid == id->svid); 242 241 } 243 242 244 243 static void typec_altmode_set_partner(struct altmode *altmode) 245 244 { 246 245 struct typec_altmode *adev = &altmode->adev; 247 - struct typec_device_id id = { adev->svid, adev->mode, }; 246 + struct typec_device_id id = { adev->svid }; 248 247 struct typec_port *port = typec_altmode2port(adev); 249 248 struct altmode *partner; 250 249 struct device *dev; ··· 362 361 { 363 362 struct typec_altmode *alt = to_typec_altmode(dev); 364 363 365 - return sprintf(buf, "%s\n", alt->active ? "yes" : "no"); 364 + return sprintf(buf, "%s\n", str_yes_no(alt->active)); 366 365 } 367 366 368 367 static ssize_t active_store(struct device *dev, struct device_attribute *attr, ··· 459 458 struct typec_altmode *adev = to_typec_altmode(kobj_to_dev(kobj)); 460 459 461 460 if (attr == &dev_attr_active.attr) 462 - if (!adev->ops || !adev->ops->activate) 461 + if (!is_typec_port(adev->dev.parent) && 462 + (!adev->ops || !adev->ops->activate)) 463 463 return 0444; 464 464 465 465 return attr->mode; ··· 565 563 566 564 if (is_port) { 567 565 alt->attrs[3] = &dev_attr_supported_roles.attr; 568 - alt->adev.active = true; /* Enabled by default */ 566 + alt->adev.active = !desc->inactive; /* Enabled by default */ 569 567 } 570 568 571 569 sprintf(alt->group_name, "mode%d", desc->mode); ··· 708 706 { 709 707 struct typec_partner *p = to_typec_partner(dev); 710 708 711 - return sprintf(buf, "%s\n", p->usb_pd ? "yes" : "no"); 709 + return sprintf(buf, "%s\n", str_yes_no(p->usb_pd)); 712 710 } 713 711 static DEVICE_ATTR_RO(supports_usb_power_delivery); 714 712 ··· 1860 1858 struct typec_port *port = to_typec_port(dev); 1861 1859 1862 1860 return sprintf(buf, "%s\n", 1863 - port->vconn_role == TYPEC_SOURCE ? "yes" : "no"); 1861 + str_yes_no(port->vconn_role == TYPEC_SOURCE)); 1864 1862 } 1865 1863 static DEVICE_ATTR_RW(vconn_source); 1866 1864
+184 -23
drivers/usb/typec/hd3ss3220.c
··· 16 16 #include <linux/delay.h> 17 17 #include <linux/workqueue.h> 18 18 19 + #define HD3SS3220_REG_CN_STAT 0x08 19 20 #define HD3SS3220_REG_CN_STAT_CTRL 0x09 20 21 #define HD3SS3220_REG_GEN_CTRL 0x0A 21 22 #define HD3SS3220_REG_DEV_REV 0xA0 23 + 24 + /* Register HD3SS3220_REG_CN_STAT */ 25 + #define HD3SS3220_REG_CN_STAT_CURRENT_MODE_MASK (BIT(7) | BIT(6)) 26 + #define HD3SS3220_REG_CN_STAT_CURRENT_MODE_DEFAULT 0x00 27 + #define HD3SS3220_REG_CN_STAT_CURRENT_MODE_MID BIT(6) 28 + #define HD3SS3220_REG_CN_STAT_CURRENT_MODE_HIGH BIT(7) 22 29 23 30 /* Register HD3SS3220_REG_CN_STAT_CTRL*/ 24 31 #define HD3SS3220_REG_CN_STAT_CTRL_ATTACHED_STATE_MASK (BIT(7) | BIT(6)) ··· 35 28 #define HD3SS3220_REG_CN_STAT_CTRL_INT_STATUS BIT(4) 36 29 37 30 /* Register HD3SS3220_REG_GEN_CTRL*/ 31 + #define HD3SS3220_REG_GEN_CTRL_DISABLE_TERM BIT(0) 38 32 #define HD3SS3220_REG_GEN_CTRL_SRC_PREF_MASK (BIT(2) | BIT(1)) 39 33 #define HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_DEFAULT 0x00 40 34 #define HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SNK BIT(1) 41 35 #define HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SRC (BIT(2) | BIT(1)) 36 + #define HD3SS3220_REG_GEN_CTRL_MODE_SELECT_MASK (BIT(5) | BIT(4)) 37 + #define HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DEFAULT 0x00 38 + #define HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DFP BIT(5) 39 + #define HD3SS3220_REG_GEN_CTRL_MODE_SELECT_UFP BIT(4) 40 + #define HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DRP (BIT(5) | BIT(4)) 42 41 43 42 struct hd3ss3220 { 44 43 struct device *dev; ··· 56 43 bool poll; 57 44 }; 58 45 59 - static int hd3ss3220_set_source_pref(struct hd3ss3220 *hd3ss3220, int src_pref) 46 + static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode) 60 47 { 48 + int current_mode; 49 + 50 + switch (power_opmode) { 51 + case TYPEC_PWR_MODE_USB: 52 + current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_DEFAULT; 53 + break; 54 + case TYPEC_PWR_MODE_1_5A: 55 + current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_MID; 56 + break; 57 + case TYPEC_PWR_MODE_3_0A: 58 + current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_HIGH; 59 + break; 60 + case TYPEC_PWR_MODE_PD: /* Power delivery not supported */ 61 + default: 62 + dev_err(hd3ss3220->dev, "bad power operation mode: %d\n", power_opmode); 63 + return -EINVAL; 64 + } 65 + 66 + return regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT, 67 + HD3SS3220_REG_CN_STAT_CURRENT_MODE_MASK, 68 + current_mode); 69 + } 70 + 71 + static int hd3ss3220_set_port_type(struct hd3ss3220 *hd3ss3220, int type) 72 + { 73 + int mode_select, err; 74 + 75 + switch (type) { 76 + case TYPEC_PORT_SRC: 77 + mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DFP; 78 + break; 79 + case TYPEC_PORT_SNK: 80 + mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_UFP; 81 + break; 82 + case TYPEC_PORT_DRP: 83 + mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DRP; 84 + break; 85 + default: 86 + dev_err(hd3ss3220->dev, "bad port type: %d\n", type); 87 + return -EINVAL; 88 + } 89 + 90 + /* Disable termination before changing MODE_SELECT as required by datasheet */ 91 + err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, 92 + HD3SS3220_REG_GEN_CTRL_DISABLE_TERM, 93 + HD3SS3220_REG_GEN_CTRL_DISABLE_TERM); 94 + if (err < 0) { 95 + dev_err(hd3ss3220->dev, "Failed to disable port for mode change: %d\n", err); 96 + return err; 97 + } 98 + 99 + err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, 100 + HD3SS3220_REG_GEN_CTRL_MODE_SELECT_MASK, 101 + mode_select); 102 + if (err < 0) { 103 + dev_err(hd3ss3220->dev, "Failed to change mode: %d\n", err); 104 + regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, 105 + HD3SS3220_REG_GEN_CTRL_DISABLE_TERM, 0); 106 + return err; 107 + } 108 + 109 + err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, 110 + HD3SS3220_REG_GEN_CTRL_DISABLE_TERM, 0); 111 + if (err < 0) 112 + dev_err(hd3ss3220->dev, "Failed to re-enable port after mode change: %d\n", err); 113 + 114 + return err; 115 + } 116 + 117 + static int hd3ss3220_set_source_pref(struct hd3ss3220 *hd3ss3220, int prefer_role) 118 + { 119 + int src_pref; 120 + 121 + switch (prefer_role) { 122 + case TYPEC_NO_PREFERRED_ROLE: 123 + src_pref = HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_DEFAULT; 124 + break; 125 + case TYPEC_SINK: 126 + src_pref = HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SNK; 127 + break; 128 + case TYPEC_SOURCE: 129 + src_pref = HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SRC; 130 + break; 131 + default: 132 + dev_err(hd3ss3220->dev, "bad role preference: %d\n", prefer_role); 133 + return -EINVAL; 134 + } 135 + 61 136 return regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL, 62 137 HD3SS3220_REG_GEN_CTRL_SRC_PREF_MASK, 63 138 src_pref); ··· 177 76 return attached_state; 178 77 } 179 78 180 - static int hd3ss3220_dr_set(struct typec_port *port, enum typec_data_role role) 79 + static int hd3ss3220_try_role(struct typec_port *port, int role) 181 80 { 182 81 struct hd3ss3220 *hd3ss3220 = typec_get_drvdata(port); 183 - enum usb_role role_val; 184 - int pref, ret = 0; 185 82 186 - if (role == TYPEC_HOST) { 187 - role_val = USB_ROLE_HOST; 188 - pref = HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SRC; 189 - } else { 190 - role_val = USB_ROLE_DEVICE; 191 - pref = HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_TRY_SNK; 192 - } 83 + return hd3ss3220_set_source_pref(hd3ss3220, role); 84 + } 193 85 194 - ret = hd3ss3220_set_source_pref(hd3ss3220, pref); 195 - usleep_range(10, 100); 86 + static int hd3ss3220_port_type_set(struct typec_port *port, enum typec_port_type type) 87 + { 88 + struct hd3ss3220 *hd3ss3220 = typec_get_drvdata(port); 196 89 197 - usb_role_switch_set_role(hd3ss3220->role_sw, role_val); 198 - typec_set_data_role(hd3ss3220->port, role); 199 - 200 - return ret; 90 + return hd3ss3220_set_port_type(hd3ss3220, type); 201 91 } 202 92 203 93 static const struct typec_operations hd3ss3220_ops = { 204 - .dr_set = hd3ss3220_dr_set 94 + .try_role = hd3ss3220_try_role, 95 + .port_type_set = hd3ss3220_port_type_set, 205 96 }; 206 97 207 98 static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220) ··· 201 108 enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220); 202 109 203 110 usb_role_switch_set_role(hd3ss3220->role_sw, role_state); 204 - if (role_state == USB_ROLE_NONE) 205 - hd3ss3220_set_source_pref(hd3ss3220, 206 - HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_DEFAULT); 207 111 208 112 switch (role_state) { 209 113 case USB_ROLE_HOST: ··· 252 162 return hd3ss3220_irq(hd3ss3220); 253 163 } 254 164 165 + static int hd3ss3220_configure_power_opmode(struct hd3ss3220 *hd3ss3220, 166 + struct fwnode_handle *connector) 167 + { 168 + /* 169 + * Supported power operation mode can be configured through device tree 170 + */ 171 + const char *cap_str; 172 + int ret, power_opmode; 173 + 174 + ret = fwnode_property_read_string(connector, "typec-power-opmode", &cap_str); 175 + if (ret) 176 + return 0; 177 + 178 + power_opmode = typec_find_pwr_opmode(cap_str); 179 + return hd3ss3220_set_power_opmode(hd3ss3220, power_opmode); 180 + } 181 + 182 + static int hd3ss3220_configure_port_type(struct hd3ss3220 *hd3ss3220, 183 + struct fwnode_handle *connector, 184 + struct typec_capability *cap) 185 + { 186 + /* 187 + * Port type can be configured through device tree 188 + */ 189 + const char *cap_str; 190 + int ret; 191 + 192 + ret = fwnode_property_read_string(connector, "power-role", &cap_str); 193 + if (ret) 194 + return 0; 195 + 196 + ret = typec_find_port_power_role(cap_str); 197 + if (ret < 0) 198 + return ret; 199 + 200 + cap->type = ret; 201 + return hd3ss3220_set_port_type(hd3ss3220, cap->type); 202 + } 203 + 204 + static int hd3ss3220_configure_source_pref(struct hd3ss3220 *hd3ss3220, 205 + struct fwnode_handle *connector, 206 + struct typec_capability *cap) 207 + { 208 + /* 209 + * Preferred role can be configured through device tree 210 + */ 211 + const char *cap_str; 212 + int ret; 213 + 214 + ret = fwnode_property_read_string(connector, "try-power-role", &cap_str); 215 + if (ret) 216 + return 0; 217 + 218 + ret = typec_find_power_role(cap_str); 219 + if (ret < 0) 220 + return ret; 221 + 222 + cap->prefer_role = ret; 223 + return hd3ss3220_set_source_pref(hd3ss3220, cap->prefer_role); 224 + } 225 + 255 226 static const struct regmap_config config = { 256 227 .reg_bits = 8, 257 228 .val_bits = 8, ··· 339 188 if (IS_ERR(hd3ss3220->regmap)) 340 189 return PTR_ERR(hd3ss3220->regmap); 341 190 342 - hd3ss3220_set_source_pref(hd3ss3220, 343 - HD3SS3220_REG_GEN_CTRL_SRC_PREF_DRP_DEFAULT); 344 191 /* For backward compatibility check the connector child node first */ 345 192 connector = device_get_named_child_node(hd3ss3220->dev, "connector"); 346 193 if (connector) { ··· 366 217 typec_cap.ops = &hd3ss3220_ops; 367 218 typec_cap.fwnode = connector; 368 219 220 + ret = hd3ss3220_configure_source_pref(hd3ss3220, connector, &typec_cap); 221 + if (ret < 0) 222 + goto err_put_role; 223 + 224 + ret = hd3ss3220_configure_port_type(hd3ss3220, connector, &typec_cap); 225 + if (ret < 0) 226 + goto err_put_role; 227 + 369 228 hd3ss3220->port = typec_register_port(&client->dev, &typec_cap); 370 229 if (IS_ERR(hd3ss3220->port)) { 371 230 ret = PTR_ERR(hd3ss3220->port); 372 231 goto err_put_role; 373 232 } 233 + 234 + ret = hd3ss3220_configure_power_opmode(hd3ss3220, connector); 235 + if (ret < 0) 236 + goto err_unreg_port; 374 237 375 238 hd3ss3220_set_role(hd3ss3220); 376 239 ret = regmap_read(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL, &data);
+1 -1
drivers/usb/typec/mux/intel_pmc_mux.c
··· 718 718 static void pmc_mux_port_debugfs_init(struct pmc_usb_port *port) 719 719 { 720 720 struct dentry *debugfs_dir; 721 - char name[6]; 721 + char name[8]; 722 722 723 723 snprintf(name, sizeof(name), "port%d", port->usb3_port - 1); 724 724
+12 -12
drivers/usb/typec/tcpm/fusb302.c
··· 24 24 #include <linux/slab.h> 25 25 #include <linux/spinlock.h> 26 26 #include <linux/string.h> 27 + #include <linux/string_choices.h> 27 28 #include <linux/types.h> 28 29 #include <linux/usb.h> 29 30 #include <linux/usb/typec.h> ··· 734 733 735 734 mutex_lock(&chip->lock); 736 735 if (chip->vconn_on == on) { 737 - fusb302_log(chip, "vconn is already %s", on ? "On" : "Off"); 736 + fusb302_log(chip, "vconn is already %s", str_on_off(on)); 738 737 goto done; 739 738 } 740 739 if (on) { ··· 747 746 if (ret < 0) 748 747 goto done; 749 748 chip->vconn_on = on; 750 - fusb302_log(chip, "vconn := %s", on ? "On" : "Off"); 749 + fusb302_log(chip, "vconn := %s", str_on_off(on)); 751 750 done: 752 751 mutex_unlock(&chip->lock); 753 752 ··· 762 761 763 762 mutex_lock(&chip->lock); 764 763 if (chip->vbus_on == on) { 765 - fusb302_log(chip, "vbus is already %s", on ? "On" : "Off"); 764 + fusb302_log(chip, "vbus is already %s", str_on_off(on)); 766 765 } else { 767 766 if (on) 768 767 ret = regulator_enable(chip->vbus); ··· 770 769 ret = regulator_disable(chip->vbus); 771 770 if (ret < 0) { 772 771 fusb302_log(chip, "cannot %s vbus regulator, ret=%d", 773 - on ? "enable" : "disable", ret); 772 + str_enable_disable(on), ret); 774 773 goto done; 775 774 } 776 775 chip->vbus_on = on; 777 - fusb302_log(chip, "vbus := %s", on ? "On" : "Off"); 776 + fusb302_log(chip, "vbus := %s", str_on_off(on)); 778 777 } 779 778 if (chip->charge_on == charge) 780 - fusb302_log(chip, "charge is already %s", 781 - charge ? "On" : "Off"); 779 + fusb302_log(chip, "charge is already %s", str_on_off(charge)); 782 780 else 783 781 chip->charge_on = charge; 784 782 ··· 854 854 ret = fusb302_pd_set_auto_goodcrc(chip, on); 855 855 if (ret < 0) { 856 856 fusb302_log(chip, "cannot turn %s auto GCRC, ret=%d", 857 - on ? "on" : "off", ret); 857 + str_on_off(on), ret); 858 858 goto done; 859 859 } 860 860 ret = fusb302_pd_set_interrupts(chip, on); 861 861 if (ret < 0) { 862 862 fusb302_log(chip, "cannot turn %s pd interrupts, ret=%d", 863 - on ? "on" : "off", ret); 863 + str_on_off(on), ret); 864 864 goto done; 865 865 } 866 - fusb302_log(chip, "pd := %s", on ? "on" : "off"); 866 + fusb302_log(chip, "pd := %s", str_on_off(on)); 867 867 done: 868 868 mutex_unlock(&chip->lock); 869 869 ··· 1531 1531 if (interrupt & FUSB_REG_INTERRUPT_VBUSOK) { 1532 1532 vbus_present = !!(status0 & FUSB_REG_STATUS0_VBUSOK); 1533 1533 fusb302_log(chip, "IRQ: VBUS_OK, vbus=%s", 1534 - vbus_present ? "On" : "Off"); 1534 + str_on_off(vbus_present)); 1535 1535 if (vbus_present != chip->vbus_present) { 1536 1536 chip->vbus_present = vbus_present; 1537 1537 tcpm_vbus_change(chip->tcpm_port); ··· 1562 1562 if ((interrupt & FUSB_REG_INTERRUPT_COMP_CHNG) && intr_comp_chng) { 1563 1563 comp_result = !!(status0 & FUSB_REG_STATUS0_COMP); 1564 1564 fusb302_log(chip, "IRQ: COMP_CHNG, comp=%s", 1565 - comp_result ? "true" : "false"); 1565 + str_true_false(comp_result)); 1566 1566 if (comp_result) { 1567 1567 /* cc level > Rd_threshold, detach */ 1568 1568 chip->cc1 = TYPEC_CC_OPEN;
+2 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
··· 12 12 #include <linux/regmap.h> 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/slab.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/usb/pd.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include "qcom_pmic_typec.h" ··· 419 418 420 419 spin_unlock_irqrestore(&pmic_typec_pdphy->lock, flags); 421 420 422 - dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", on ? "on" : "off"); 421 + dev_dbg(pmic_typec_pdphy->dev, "set_pd_rx: %s\n", str_on_off(on)); 423 422 424 423 return ret; 425 424 }
+2 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy_stub.c
··· 12 12 #include <linux/regmap.h> 13 13 #include <linux/regulator/consumer.h> 14 14 #include <linux/slab.h> 15 + #include <linux/string_choices.h> 15 16 #include <linux/usb/pd.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include "qcom_pmic_typec.h" ··· 39 38 struct pmic_typec *tcpm = tcpc_to_tcpm(tcpc); 40 39 struct device *dev = tcpm->dev; 41 40 42 - dev_dbg(dev, "set_pd_rx: %s\n", on ? "on" : "off"); 41 + dev_dbg(dev, "set_pd_rx: %s\n", str_on_off(on)); 43 42 44 43 return 0; 45 44 }
+3 -1
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
··· 13 13 #include <linux/regmap.h> 14 14 #include <linux/regulator/consumer.h> 15 15 #include <linux/slab.h> 16 + #include <linux/string_choices.h> 16 17 #include <linux/usb/tcpm.h> 17 18 #include <linux/usb/typec_mux.h> 18 19 #include <linux/workqueue.h> ··· 563 562 spin_unlock_irqrestore(&pmic_typec_port->lock, flags); 564 563 565 564 dev_dbg(dev, "set_vconn: orientation %d control 0x%08x state %s cc %s vconn %s\n", 566 - orientation, value, on ? "on" : "off", misc_to_vconn(misc), misc_to_cc(misc)); 565 + orientation, value, str_on_off(on), misc_to_vconn(misc), 566 + misc_to_cc(misc)); 567 567 568 568 return ret; 569 569 }
+11 -6
drivers/usb/typec/tcpm/tcpci.c
··· 27 27 #define VPPS_NEW_MIN_PERCENT 95 28 28 #define VPPS_VALID_MIN_MV 100 29 29 #define VSINKDISCONNECT_PD_MIN_PERCENT 90 30 + #define VPPS_SHUTDOWN_MIN_PERCENT 85 30 31 31 32 struct tcpci { 32 33 struct device *dev; ··· 283 282 if (cc2 == TYPEC_CC_RD) 284 283 /* Role control would have the Rp setting when DRP was enabled */ 285 284 reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RP); 286 - else 285 + else if (cc2 >= TYPEC_CC_RP_DEF) 287 286 reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC2, TCPC_ROLE_CTRL_CC_RD); 288 287 } else { 289 288 reg &= ~TCPC_ROLE_CTRL_CC1; ··· 291 290 if (cc1 == TYPEC_CC_RD) 292 291 /* Role control would have the Rp setting when DRP was enabled */ 293 292 reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RP); 294 - else 293 + else if (cc1 >= TYPEC_CC_RP_DEF) 295 294 reg |= FIELD_PREP(TCPC_ROLE_CTRL_CC1, TCPC_ROLE_CTRL_CC_RD); 296 295 } 297 296 } ··· 367 366 } 368 367 369 368 static int tcpci_set_auto_vbus_discharge_threshold(struct tcpc_dev *dev, enum typec_pwr_opmode mode, 370 - bool pps_active, u32 requested_vbus_voltage_mv) 369 + bool pps_active, u32 requested_vbus_voltage_mv, 370 + u32 apdo_min_voltage_mv) 371 371 { 372 372 struct tcpci *tcpci = tcpc_to_tcpci(dev); 373 373 unsigned int pwr_ctrl, threshold = 0; ··· 390 388 threshold = AUTO_DISCHARGE_DEFAULT_THRESHOLD_MV; 391 389 } else if (mode == TYPEC_PWR_MODE_PD) { 392 390 if (pps_active) 393 - threshold = ((VPPS_NEW_MIN_PERCENT * requested_vbus_voltage_mv / 100) - 394 - VSINKPD_MIN_IR_DROP_MV - VPPS_VALID_MIN_MV) * 395 - VSINKDISCONNECT_PD_MIN_PERCENT / 100; 391 + /* 392 + * To prevent disconnect when the source is in Current Limit Mode. 393 + * Set the threshold to the lowest possible voltage vPpsShutdown (min) 394 + */ 395 + threshold = VPPS_SHUTDOWN_MIN_PERCENT * apdo_min_voltage_mv / 100 - 396 + VSINKPD_MIN_IR_DROP_MV; 396 397 else 397 398 threshold = ((VSRC_NEW_MIN_PERCENT * requested_vbus_voltage_mv / 100) - 398 399 VSINKPD_MIN_IR_DROP_MV - VSRC_VALID_MIN_MV) *
-1
drivers/usb/typec/tcpm/tcpci_mt6370.c
··· 11 11 #include <linux/mod_devicetable.h> 12 12 #include <linux/module.h> 13 13 #include <linux/platform_device.h> 14 - #include <linux/pm_wakeup.h> 15 14 #include <linux/pm_wakeirq.h> 16 15 #include <linux/regmap.h> 17 16 #include <linux/regulator/consumer.h>
+94 -10
drivers/usb/typec/tcpm/tcpm.c
··· 21 21 #include <linux/seq_file.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/spinlock.h> 24 + #include <linux/string_choices.h> 24 25 #include <linux/usb.h> 25 26 #include <linux/usb/pd.h> 26 27 #include <linux/usb/pd_ado.h> ··· 186 185 S(UNSTRUCTURED_VDMS), \ 187 186 S(STRUCTURED_VDMS), \ 188 187 S(COUNTRY_INFO), \ 189 - S(COUNTRY_CODES) 188 + S(COUNTRY_CODES), \ 189 + S(REVISION_INFORMATION) 190 190 191 191 #define GENERATE_ENUM(e) e 192 192 #define GENERATE_STRING(s) #s ··· 227 225 PD_MSG_CTRL_NOT_SUPP, 228 226 PD_MSG_DATA_SINK_CAP, 229 227 PD_MSG_DATA_SOURCE_CAP, 228 + PD_MSG_DATA_REV, 230 229 }; 231 230 232 231 enum adev_actions { ··· 311 308 struct usb_power_delivery_capabilities *sink_cap; 312 309 struct usb_power_delivery_capabilities_desc sink_desc; 313 310 unsigned int operating_snk_mw; 311 + }; 312 + 313 + struct pd_revision_info { 314 + u8 rev_major; 315 + u8 rev_minor; 316 + u8 ver_major; 317 + u8 ver_minor; 314 318 }; 315 319 316 320 /* ··· 577 567 578 568 /* Timer deadline values configured at runtime */ 579 569 struct pd_timings timings; 570 + 571 + /* Indicates maximum (revision, version) supported */ 572 + struct pd_revision_info pd_rev; 580 573 #ifdef CONFIG_DEBUG_FS 581 574 struct dentry *dentry; 582 575 struct mutex logbuffer_lock; /* log buffer access lock */ ··· 893 880 894 881 if (port->tcpc->enable_auto_vbus_discharge) { 895 882 ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); 896 - tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable", 897 - ret); 883 + tcpm_log_force(port, "%s vbus discharge ret:%d", 884 + str_enable_disable(enable), ret); 898 885 if (!ret) 899 886 port->auto_vbus_discharge_enabled = enable; 900 887 } ··· 1245 1232 default: 1246 1233 return 0; 1247 1234 } 1235 + } 1236 + 1237 + static int tcpm_pd_send_revision(struct tcpm_port *port) 1238 + { 1239 + struct pd_message msg; 1240 + u32 rmdo; 1241 + 1242 + memset(&msg, 0, sizeof(msg)); 1243 + rmdo = RMDO(port->pd_rev.rev_major, port->pd_rev.rev_minor, 1244 + port->pd_rev.ver_major, port->pd_rev.ver_minor); 1245 + msg.payload[0] = cpu_to_le32(rmdo); 1246 + msg.header = PD_HEADER_LE(PD_DATA_REVISION, 1247 + port->pwr_role, 1248 + port->data_role, 1249 + port->negotiated_rev, 1250 + port->message_id, 1251 + 1); 1252 + return tcpm_pd_transmit(port, TCPC_TX_SOP, &msg); 1248 1253 } 1249 1254 1250 1255 static int tcpm_pd_send_source_caps(struct tcpm_port *port) ··· 2974 2943 return 0; 2975 2944 2976 2945 ret = port->tcpc->set_auto_vbus_discharge_threshold(port->tcpc, mode, pps_active, 2977 - requested_vbus_voltage); 2946 + requested_vbus_voltage, 2947 + port->pps_data.min_volt); 2978 2948 tcpm_log_force(port, 2979 - "set_auto_vbus_discharge_threshold mode:%d pps_active:%c vbus:%u ret:%d", 2980 - mode, pps_active ? 'y' : 'n', requested_vbus_voltage, ret); 2949 + "set_auto_vbus_discharge_threshold mode:%d pps_active:%c vbus:%u pps_apdo_min_volt:%u ret:%d", 2950 + mode, pps_active ? 'y' : 'n', requested_vbus_voltage, 2951 + port->pps_data.min_volt, ret); 2981 2952 2982 2953 return ret; 2983 2954 } ··· 3570 3537 PD_MSG_CTRL_NOT_SUPP, 3571 3538 NONE_AMS); 3572 3539 break; 3540 + case PD_CTRL_GET_REVISION: 3541 + if (port->negotiated_rev >= PD_REV30 && port->pd_rev.rev_major) 3542 + tcpm_pd_handle_msg(port, PD_MSG_DATA_REV, 3543 + REVISION_INFORMATION); 3544 + else 3545 + tcpm_pd_handle_msg(port, 3546 + port->negotiated_rev < PD_REV30 ? 3547 + PD_MSG_CTRL_REJECT : 3548 + PD_MSG_CTRL_NOT_SUPP, 3549 + NONE_AMS); 3550 + break; 3573 3551 default: 3574 3552 tcpm_pd_handle_msg(port, 3575 3553 port->negotiated_rev < PD_REV30 ? ··· 3824 3780 } else { 3825 3781 tcpm_ams_finish(port); 3826 3782 } 3783 + break; 3784 + case PD_MSG_DATA_REV: 3785 + ret = tcpm_pd_send_revision(port); 3786 + if (ret) 3787 + tcpm_log(port, 3788 + "Unable to send revision msg, ret=%d", 3789 + ret); 3790 + tcpm_ams_finish(port); 3827 3791 break; 3828 3792 default: 3829 3793 break; ··· 4442 4390 4443 4391 static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capable) 4444 4392 { 4445 - tcpm_log(port, "Setting usb_comm capable %s", capable ? "true" : "false"); 4393 + tcpm_log(port, "Setting usb_comm capable %s", str_true_false(capable)); 4446 4394 4447 4395 if (port->tcpc->set_partner_usb_comm_capable) 4448 4396 port->tcpc->set_partner_usb_comm_capable(port->tcpc, capable); ··· 4824 4772 port->caps_count = 0; 4825 4773 port->pd_capable = true; 4826 4774 tcpm_set_state_cond(port, SRC_SEND_CAPABILITIES_TIMEOUT, 4827 - PD_T_SEND_SOURCE_CAP); 4775 + PD_T_SENDER_RESPONSE); 4828 4776 } 4829 4777 break; 4830 4778 case SRC_SEND_CAPABILITIES_TIMEOUT: ··· 7088 7036 7089 7037 static int tcpm_port_register_pd(struct tcpm_port *port) 7090 7038 { 7091 - struct usb_power_delivery_desc desc = { port->typec_caps.pd_revision }; 7039 + u16 pd_revision = port->typec_caps.pd_revision; 7040 + u16 pd_version = port->pd_rev.ver_major << 8 | port->pd_rev.ver_minor; 7041 + struct usb_power_delivery_desc desc = { pd_revision, pd_version }; 7092 7042 struct usb_power_delivery_capabilities *cap; 7093 7043 int ret, i; 7094 7044 ··· 7383 7329 } 7384 7330 7385 7331 return 0; 7332 + } 7333 + 7334 + static void tcpm_fw_get_pd_revision(struct tcpm_port *port, struct fwnode_handle *fwnode) 7335 + { 7336 + int ret; 7337 + u8 val[4]; 7338 + 7339 + ret = fwnode_property_count_u8(fwnode, "pd-revision"); 7340 + if (!ret || ret != 4) { 7341 + tcpm_log(port, "Unable to find pd-revision property or incorrect array size"); 7342 + return; 7343 + } 7344 + 7345 + ret = fwnode_property_read_u8_array(fwnode, "pd-revision", val, 4); 7346 + if (ret) { 7347 + tcpm_log(port, "Failed to parse pd-revision, ret:(%d)", ret); 7348 + return; 7349 + } 7350 + 7351 + port->pd_rev.rev_major = val[0]; 7352 + port->pd_rev.rev_minor = val[1]; 7353 + port->pd_rev.ver_major = val[2]; 7354 + port->pd_rev.ver_minor = val[3]; 7386 7355 } 7387 7356 7388 7357 /* Power Supply access to expose source power information */ ··· 7746 7669 goto out_destroy_wq; 7747 7670 7748 7671 tcpm_fw_get_timings(port, tcpc->fwnode); 7672 + tcpm_fw_get_pd_revision(port, tcpc->fwnode); 7749 7673 7750 7674 port->try_role = port->typec_caps.prefer_role; 7751 7675 7752 7676 port->typec_caps.revision = 0x0120; /* Type-C spec release 1.2 */ 7753 - port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ 7677 + 7678 + if (port->pd_rev.rev_major) 7679 + port->typec_caps.pd_revision = port->pd_rev.rev_major << 8 | 7680 + port->pd_rev.rev_minor; 7681 + else 7682 + port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ 7683 + 7754 7684 port->typec_caps.svdm_version = SVDM_VER_2_0; 7755 7685 port->typec_caps.driver_data = port; 7756 7686 port->typec_caps.ops = &tcpm_ops;
+13
drivers/usb/typec/ucsi/Kconfig
··· 69 69 To compile the driver as a module, choose M here: the module will be 70 70 called ucsi_glink. 71 71 72 + config CROS_EC_UCSI 73 + tristate "UCSI Driver for ChromeOS EC" 74 + depends on MFD_CROS_EC_DEV 75 + depends on CROS_USBPD_NOTIFY 76 + depends on !EXTCON_TCSS_CROS_EC 77 + default MFD_CROS_EC_DEV 78 + help 79 + This driver enables UCSI support for a ChromeOS EC. The EC is 80 + expected to implement a PPM. 81 + 82 + To compile the driver as a module, choose M here: the module 83 + will be called cros_ec_ucsi. 84 + 72 85 config UCSI_LENOVO_YOGA_C630 73 86 tristate "UCSI Interface Driver for Lenovo Yoga C630" 74 87 depends on EC_LENOVO_YOGA_C630
+1
drivers/usb/typec/ucsi/Makefile
··· 21 21 obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o 22 22 obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o 23 23 obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o 24 + obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o 24 25 obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o
+333
drivers/usb/typec/ucsi/cros_ec_ucsi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * UCSI driver for ChromeOS EC 4 + * 5 + * Copyright 2024 Google LLC. 6 + */ 7 + 8 + #include <linux/container_of.h> 9 + #include <linux/dev_printk.h> 10 + #include <linux/jiffies.h> 11 + #include <linux/mod_devicetable.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_data/cros_ec_commands.h> 14 + #include <linux/platform_data/cros_usbpd_notify.h> 15 + #include <linux/platform_data/cros_ec_proto.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/slab.h> 18 + #include <linux/wait.h> 19 + 20 + #include "ucsi.h" 21 + 22 + /* 23 + * Maximum size in bytes of a UCSI message between AP and EC 24 + */ 25 + #define MAX_EC_DATA_SIZE 256 26 + 27 + /* 28 + * Maximum time in milliseconds the cros_ec_ucsi driver 29 + * will wait for a response to a command or and ack. 30 + */ 31 + #define WRITE_TMO_MS 5000 32 + 33 + /* Number of times to attempt recovery from a write timeout before giving up. */ 34 + #define WRITE_TMO_CTR_MAX 5 35 + 36 + struct cros_ucsi_data { 37 + struct device *dev; 38 + struct ucsi *ucsi; 39 + 40 + struct cros_ec_device *ec; 41 + struct notifier_block nb; 42 + struct work_struct work; 43 + struct delayed_work write_tmo; 44 + int tmo_counter; 45 + 46 + struct completion complete; 47 + unsigned long flags; 48 + }; 49 + 50 + static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val, 51 + size_t val_len) 52 + { 53 + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); 54 + struct ec_params_ucsi_ppm_get req = { 55 + .offset = offset, 56 + .size = val_len, 57 + }; 58 + int ret; 59 + 60 + if (val_len > MAX_EC_DATA_SIZE) { 61 + dev_err(udata->dev, "Can't read %zu bytes. Too big.\n", val_len); 62 + return -EINVAL; 63 + } 64 + 65 + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET, 66 + &req, sizeof(req), val, val_len); 67 + if (ret < 0) { 68 + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d\n", ret); 69 + return ret; 70 + } 71 + return 0; 72 + } 73 + 74 + static int cros_ucsi_read_version(struct ucsi *ucsi, u16 *version) 75 + { 76 + return cros_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version)); 77 + } 78 + 79 + static int cros_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) 80 + { 81 + return cros_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); 82 + } 83 + 84 + static int cros_ucsi_read_message_in(struct ucsi *ucsi, void *val, 85 + size_t val_len) 86 + { 87 + return cros_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len); 88 + } 89 + 90 + static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) 91 + { 92 + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); 93 + u8 ec_buf[sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd)]; 94 + struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *) ec_buf; 95 + int ret; 96 + 97 + req->offset = UCSI_CONTROL; 98 + memcpy(req->data, &cmd, sizeof(cmd)); 99 + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET, 100 + req, sizeof(ec_buf), NULL, 0); 101 + if (ret < 0) { 102 + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d\n", ret); 103 + return ret; 104 + } 105 + return 0; 106 + } 107 + 108 + static int cros_ucsi_sync_control(struct ucsi *ucsi, u64 cmd) 109 + { 110 + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); 111 + int ret; 112 + 113 + ret = ucsi_sync_control_common(ucsi, cmd); 114 + switch (ret) { 115 + case -EBUSY: 116 + /* EC may return -EBUSY if CCI.busy is set. 117 + * Convert this to a timeout. 118 + */ 119 + case -ETIMEDOUT: 120 + /* Schedule recovery attempt when we timeout 121 + * or tried to send a command while still busy. 122 + */ 123 + cancel_delayed_work_sync(&udata->write_tmo); 124 + schedule_delayed_work(&udata->write_tmo, 125 + msecs_to_jiffies(WRITE_TMO_MS)); 126 + break; 127 + case 0: 128 + /* Successful write. Cancel any pending recovery work. */ 129 + cancel_delayed_work_sync(&udata->write_tmo); 130 + break; 131 + } 132 + 133 + return ret; 134 + } 135 + 136 + static const struct ucsi_operations cros_ucsi_ops = { 137 + .read_version = cros_ucsi_read_version, 138 + .read_cci = cros_ucsi_read_cci, 139 + .read_message_in = cros_ucsi_read_message_in, 140 + .async_control = cros_ucsi_async_control, 141 + .sync_control = cros_ucsi_sync_control, 142 + }; 143 + 144 + static void cros_ucsi_work(struct work_struct *work) 145 + { 146 + struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work); 147 + u32 cci; 148 + 149 + if (cros_ucsi_read_cci(udata->ucsi, &cci)) 150 + return; 151 + 152 + ucsi_notify_common(udata->ucsi, cci); 153 + } 154 + 155 + static void cros_ucsi_write_timeout(struct work_struct *work) 156 + { 157 + struct cros_ucsi_data *udata = 158 + container_of(work, struct cros_ucsi_data, write_tmo.work); 159 + u32 cci; 160 + u64 cmd; 161 + 162 + if (cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) { 163 + dev_err(udata->dev, 164 + "Reading CCI failed; no write timeout recovery possible.\n"); 165 + return; 166 + } 167 + 168 + if (cci & UCSI_CCI_BUSY) { 169 + udata->tmo_counter++; 170 + 171 + if (udata->tmo_counter <= WRITE_TMO_CTR_MAX) 172 + schedule_delayed_work(&udata->write_tmo, 173 + msecs_to_jiffies(WRITE_TMO_MS)); 174 + else 175 + dev_err(udata->dev, 176 + "PPM unresponsive - too many write timeouts.\n"); 177 + 178 + return; 179 + } 180 + 181 + /* No longer busy means we can reset our timeout counter. */ 182 + udata->tmo_counter = 0; 183 + 184 + /* Need to ack previous command which may have timed out. */ 185 + if (cci & UCSI_CCI_COMMAND_COMPLETE) { 186 + cmd = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE; 187 + cros_ucsi_async_control(udata->ucsi, cmd); 188 + 189 + /* Check again after a few seconds that the system has 190 + * recovered to make sure our async write above was successful. 191 + */ 192 + schedule_delayed_work(&udata->write_tmo, 193 + msecs_to_jiffies(WRITE_TMO_MS)); 194 + return; 195 + } 196 + 197 + /* We recovered from a previous timeout. Treat this as a recovery from 198 + * suspend and call resume. 199 + */ 200 + ucsi_resume(udata->ucsi); 201 + } 202 + 203 + static int cros_ucsi_event(struct notifier_block *nb, 204 + unsigned long host_event, void *_notify) 205 + { 206 + struct cros_ucsi_data *udata = container_of(nb, struct cros_ucsi_data, nb); 207 + 208 + if (!(host_event & PD_EVENT_PPM)) 209 + return NOTIFY_OK; 210 + 211 + dev_dbg(udata->dev, "UCSI notification received\n"); 212 + flush_work(&udata->work); 213 + schedule_work(&udata->work); 214 + 215 + return NOTIFY_OK; 216 + } 217 + 218 + static void cros_ucsi_destroy(struct cros_ucsi_data *udata) 219 + { 220 + cros_usbpd_unregister_notify(&udata->nb); 221 + cancel_delayed_work_sync(&udata->write_tmo); 222 + cancel_work_sync(&udata->work); 223 + ucsi_destroy(udata->ucsi); 224 + } 225 + 226 + static int cros_ucsi_probe(struct platform_device *pdev) 227 + { 228 + struct device *dev = &pdev->dev; 229 + struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent); 230 + struct cros_ucsi_data *udata; 231 + int ret; 232 + 233 + udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); 234 + if (!udata) 235 + return -ENOMEM; 236 + 237 + udata->dev = dev; 238 + 239 + udata->ec = ec_data->ec_dev; 240 + if (!udata->ec) 241 + return dev_err_probe(dev, -ENODEV, "couldn't find parent EC device\n"); 242 + 243 + platform_set_drvdata(pdev, udata); 244 + 245 + INIT_WORK(&udata->work, cros_ucsi_work); 246 + INIT_DELAYED_WORK(&udata->write_tmo, cros_ucsi_write_timeout); 247 + init_completion(&udata->complete); 248 + 249 + udata->ucsi = ucsi_create(dev, &cros_ucsi_ops); 250 + if (IS_ERR(udata->ucsi)) 251 + return dev_err_probe(dev, PTR_ERR(udata->ucsi), "failed to allocate UCSI instance\n"); 252 + 253 + ucsi_set_drvdata(udata->ucsi, udata); 254 + 255 + udata->nb.notifier_call = cros_ucsi_event; 256 + ret = cros_usbpd_register_notify(&udata->nb); 257 + if (ret) { 258 + dev_err_probe(dev, ret, "failed to register notifier\n"); 259 + ucsi_destroy(udata->ucsi); 260 + return ret; 261 + } 262 + 263 + ret = ucsi_register(udata->ucsi); 264 + if (ret) { 265 + dev_err_probe(dev, ret, "failed to register UCSI\n"); 266 + cros_ucsi_destroy(udata); 267 + return ret; 268 + } 269 + 270 + return 0; 271 + } 272 + 273 + static void cros_ucsi_remove(struct platform_device *dev) 274 + { 275 + struct cros_ucsi_data *udata = platform_get_drvdata(dev); 276 + 277 + ucsi_unregister(udata->ucsi); 278 + cros_ucsi_destroy(udata); 279 + } 280 + 281 + static int __maybe_unused cros_ucsi_suspend(struct device *dev) 282 + { 283 + struct cros_ucsi_data *udata = dev_get_drvdata(dev); 284 + 285 + cancel_delayed_work_sync(&udata->write_tmo); 286 + cancel_work_sync(&udata->work); 287 + 288 + return 0; 289 + } 290 + 291 + static void __maybe_unused cros_ucsi_complete(struct device *dev) 292 + { 293 + struct cros_ucsi_data *udata = dev_get_drvdata(dev); 294 + 295 + ucsi_resume(udata->ucsi); 296 + } 297 + 298 + /* 299 + * UCSI protocol is also used on ChromeOS platforms which reply on 300 + * cros_ec_lpc.c driver for communication with embedded controller (EC). 301 + * On such platforms communication with the EC is not available until 302 + * the .complete() callback of the cros_ec_lpc driver is executed. 303 + * For this reason we delay ucsi_resume() until the .complete() stage 304 + * otherwise UCSI SET_NOTIFICATION_ENABLE command will fail and we won't 305 + * receive any UCSI notifications from the EC where PPM is implemented. 306 + */ 307 + static const struct dev_pm_ops cros_ucsi_pm_ops = { 308 + #ifdef CONFIG_PM_SLEEP 309 + .suspend = cros_ucsi_suspend, 310 + .complete = cros_ucsi_complete, 311 + #endif 312 + }; 313 + 314 + static const struct platform_device_id cros_ucsi_id[] = { 315 + { KBUILD_MODNAME, 0 }, 316 + {} 317 + }; 318 + MODULE_DEVICE_TABLE(platform, cros_ucsi_id); 319 + 320 + static struct platform_driver cros_ucsi_driver = { 321 + .driver = { 322 + .name = KBUILD_MODNAME, 323 + .pm = &cros_ucsi_pm_ops, 324 + }, 325 + .id_table = cros_ucsi_id, 326 + .probe = cros_ucsi_probe, 327 + .remove = cros_ucsi_remove, 328 + }; 329 + 330 + module_platform_driver(cros_ucsi_driver); 331 + 332 + MODULE_LICENSE("GPL"); 333 + MODULE_DESCRIPTION("UCSI driver for ChromeOS EC");
+1
drivers/usb/typec/ucsi/ucsi.h
··· 30 30 #define UCSIv2_MESSAGE_OUT 272 31 31 32 32 /* UCSI versions */ 33 + #define UCSI_VERSION_1_0 0x0100 33 34 #define UCSI_VERSION_1_1 0x0110 34 35 #define UCSI_VERSION_1_2 0x0120 35 36 #define UCSI_VERSION_2_0 0x0200
+1 -1
drivers/usb/typec/ucsi/ucsi_yoga_c630.c
··· 71 71 return yoga_c630_ec_ucsi_write(uec->ec, (u8*)&command); 72 72 } 73 73 74 - const struct ucsi_operations yoga_c630_ucsi_ops = { 74 + static const struct ucsi_operations yoga_c630_ucsi_ops = { 75 75 .read_version = yoga_c630_ucsi_read_version, 76 76 .read_cci = yoga_c630_ucsi_read_cci, 77 77 .read_message_in = yoga_c630_ucsi_read_message_in,
+1 -1
drivers/usb/usbip/stub_rx.c
··· 269 269 return 0; 270 270 } 271 271 272 - usbip_dbg_stub_rx("seqnum %d is not pending\n", 272 + usbip_dbg_stub_rx("seqnum %u is not pending\n", 273 273 pdu->u.cmd_unlink.seqnum); 274 274 275 275 /*
+1 -1
drivers/usb/usbip/stub_tx.c
··· 201 201 202 202 /* 1. setup usbip_header */ 203 203 setup_ret_submit_pdu(&pdu_header, urb); 204 - usbip_dbg_stub_tx("setup txdata seqnum: %d\n", 204 + usbip_dbg_stub_tx("setup txdata seqnum: %u\n", 205 205 pdu_header.base.seqnum); 206 206 207 207 if (priv->sgl) {
+5 -8
drivers/usb/usbip/vhci_hcd.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/platform_device.h> 13 13 #include <linux/slab.h> 14 + #include <linux/string_choices.h> 14 15 15 16 #include "usbip_common.h" 16 17 #include "vhci.h" ··· 676 675 677 676 spin_lock_irqsave(&vdev->priv_lock, flags); 678 677 679 - priv->seqnum = atomic_inc_return(&vhci_hcd->seqnum); 678 + priv->seqnum = (u32)atomic_inc_return(&vhci_hcd->seqnum); 680 679 if (priv->seqnum == 0xffff) 681 680 dev_info(&urb->dev->dev, "seqnum max\n"); 682 681 ··· 1162 1161 hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS; 1163 1162 } 1164 1163 1165 - /* 1166 - * Support SG. 1167 - * sg_tablesize is an arbitrary value to alleviate memory pressure 1168 - * on the host. 1169 - */ 1170 - hcd->self.sg_tablesize = 32; 1164 + /* accept arbitrarily long scatter-gather lists */ 1165 + hcd->self.sg_tablesize = ~0; 1171 1166 hcd->self.no_sg_constraint = 1; 1172 1167 1173 1168 return 0; ··· 1450 1453 if (connected > 0) { 1451 1454 dev_info(&pdev->dev, 1452 1455 "We have %d active connection%s. Do not suspend.\n", 1453 - connected, (connected == 1 ? "" : "s")); 1456 + connected, str_plural(connected)); 1454 1457 ret = -EBUSY; 1455 1458 } else { 1456 1459 dev_info(&pdev->dev, "suspend vhci_hcd");
+3 -3
drivers/usb/usbip/vhci_rx.c
··· 66 66 spin_unlock_irqrestore(&vdev->priv_lock, flags); 67 67 68 68 if (!urb) { 69 - pr_err("cannot find a urb of seqnum %u max seqnum %d\n", 69 + pr_err("cannot find a urb of seqnum %u max seqnum %u\n", 70 70 pdu->base.seqnum, 71 71 atomic_read(&vhci_hcd->seqnum)); 72 72 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP); ··· 162 162 * already received the result of its submit result and gave 163 163 * back the URB. 164 164 */ 165 - pr_info("the urb (seqnum %d) was already given back\n", 165 + pr_info("the urb (seqnum %u) was already given back\n", 166 166 pdu->base.seqnum); 167 167 } else { 168 - usbip_dbg_vhci_rx("now giveback urb %d\n", pdu->base.seqnum); 168 + usbip_dbg_vhci_rx("now giveback urb %u\n", pdu->base.seqnum); 169 169 170 170 /* If unlink is successful, status is -ECONNRESET */ 171 171 urb->status = pdu->u.ret_unlink.status;
+4 -4
drivers/usb/usbip/vudc_sysfs.c
··· 67 67 * Exposes device descriptor from the gadget driver. 68 68 */ 69 69 static ssize_t dev_desc_read(struct file *file, struct kobject *kobj, 70 - struct bin_attribute *attr, char *out, 70 + const struct bin_attribute *attr, char *out, 71 71 loff_t off, size_t count) 72 72 { 73 73 struct device *dev = kobj_to_dev(kobj); ··· 88 88 spin_unlock_irqrestore(&udc->lock, flags); 89 89 return ret; 90 90 } 91 - static BIN_ATTR_RO(dev_desc, sizeof(struct usb_device_descriptor)); 91 + static const BIN_ATTR_RO(dev_desc, sizeof(struct usb_device_descriptor)); 92 92 93 93 static ssize_t usbip_sockfd_store(struct device *dev, 94 94 struct device_attribute *attr, ··· 252 252 NULL, 253 253 }; 254 254 255 - static struct bin_attribute *dev_bin_attrs[] = { 255 + static const struct bin_attribute *const dev_bin_attrs[] = { 256 256 &bin_attr_dev_desc, 257 257 NULL, 258 258 }; 259 259 260 260 static const struct attribute_group vudc_attr_group = { 261 261 .attrs = dev_attrs, 262 - .bin_attrs = dev_bin_attrs, 262 + .bin_attrs_new = dev_bin_attrs, 263 263 }; 264 264 265 265 const struct attribute_group *vudc_groups[] = {
+1 -1
drivers/usb/usbip/vudc_tx.c
··· 107 107 108 108 /* 1. setup usbip_header */ 109 109 setup_ret_submit_pdu(&pdu_header, urb_p); 110 - usbip_dbg_stub_tx("setup txdata seqnum: %d\n", 110 + usbip_dbg_stub_tx("setup txdata seqnum: %u\n", 111 111 pdu_header.base.seqnum); 112 112 usbip_header_correct_endian(&pdu_header, 1); 113 113
+27 -1
include/linux/platform_data/cros_ec_commands.h
··· 5044 5044 #define PD_EVENT_POWER_CHANGE BIT(1) 5045 5045 #define PD_EVENT_IDENTITY_RECEIVED BIT(2) 5046 5046 #define PD_EVENT_DATA_SWAP BIT(3) 5047 + #define PD_EVENT_TYPEC BIT(4) 5048 + #define PD_EVENT_PPM BIT(5) 5049 + 5047 5050 struct ec_response_host_event_status { 5048 - uint32_t status; /* PD MCU host event status */ 5051 + uint32_t status; /* PD MCU host event status */ 5049 5052 } __ec_align4; 5050 5053 5051 5054 /* Set USB type-C port role and muxes */ ··· 6107 6104 } __ec_align1; 6108 6105 6109 6106 #undef VDO_MAX_SIZE 6107 + 6108 + /* 6109 + * UCSI OPM-PPM commands 6110 + * 6111 + * These commands are used for communication between OPM and PPM. 6112 + * Only UCSI3.0 is tested. 6113 + */ 6114 + 6115 + #define EC_CMD_UCSI_PPM_SET 0x0140 6116 + 6117 + /* The data size is stored in the host command protocol header. */ 6118 + struct ec_params_ucsi_ppm_set { 6119 + uint16_t offset; 6120 + uint8_t data[]; 6121 + } __ec_align2; 6122 + 6123 + #define EC_CMD_UCSI_PPM_GET 0x0141 6124 + 6125 + /* For 'GET' sub-commands, data will be returned as a raw payload. */ 6126 + struct ec_params_ucsi_ppm_get { 6127 + uint16_t offset; 6128 + uint8_t size; 6129 + } __ec_align2; 6110 6130 6111 6131 /*****************************************************************************/ 6112 6132 /* The command range 0x200-0x2FF is reserved for Rotor. */
+2 -1
include/linux/pm.h
··· 570 570 { .event = PM_EVENT_AUTO_RESUME, }) 571 571 572 572 #define PMSG_IS_AUTO(msg) (((msg).event & PM_EVENT_AUTO) != 0) 573 - 573 + #define PMSG_NO_WAKEUP(msg) (((msg).event & \ 574 + (PM_EVENT_FREEZE | PM_EVENT_QUIESCE)) != 0) 574 575 /* 575 576 * Device run-time power management status. 576 577 *
+20 -2
include/linux/usb/pd.h
··· 33 33 PD_CTRL_FR_SWAP = 19, 34 34 PD_CTRL_GET_PPS_STATUS = 20, 35 35 PD_CTRL_GET_COUNTRY_CODES = 21, 36 - /* 22-31 Reserved */ 36 + /* 22-23 Reserved */ 37 + PD_CTRL_GET_REVISION = 24, 38 + /* 25-31 Reserved */ 37 39 }; 38 40 39 41 enum pd_data_msg_type { ··· 48 46 PD_DATA_ALERT = 6, 49 47 PD_DATA_GET_COUNTRY_INFO = 7, 50 48 PD_DATA_ENTER_USB = 8, 51 - /* 9-14 Reserved */ 49 + /* 9-11 Reserved */ 50 + PD_DATA_REVISION = 12, 51 + /* 13-14 Reserved */ 52 52 PD_DATA_VENDOR_DEF = 15, 53 53 /* 16-31 Reserved */ 54 54 }; ··· 456 452 #define EUDO_DP_SUPPORT BIT(15) 457 453 #define EUDO_TBT_SUPPORT BIT(14) 458 454 #define EUDO_HOST_PRESENT BIT(13) 455 + 456 + /* 457 + * Request Message Data Object (PD Revision 3.1+ only) 458 + * -------- 459 + * <31:28> :: Revision Major 460 + * <27:24> :: Revision Minor 461 + * <23:20> :: Version Major 462 + * <19:16> :: Version Minor 463 + * <15:0> :: Reserved, Shall be set to zero 464 + */ 465 + 466 + #define RMDO(rev_maj, rev_min, ver_maj, ver_min) \ 467 + (((rev_maj) & 0xf) << 28 | ((rev_min) & 0xf) << 24 | \ 468 + ((ver_maj) & 0xf) << 20 | ((ver_min) & 0xf) << 16) 459 469 460 470 /* USB PD timers and counters */ 461 471 #define PD_T_NO_RESPONSE 5000 /* 4.5 - 5.5 seconds */
-5
include/linux/usb/phy.h
··· 223 223 extern struct usb_phy *devm_usb_get_phy_by_node(struct device *dev, 224 224 struct device_node *node, struct notifier_block *nb); 225 225 extern void usb_put_phy(struct usb_phy *); 226 - extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x); 227 226 extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); 228 227 extern void usb_phy_set_charger_current(struct usb_phy *usb_phy, 229 228 unsigned int mA); ··· 255 256 } 256 257 257 258 static inline void usb_put_phy(struct usb_phy *x) 258 - { 259 - } 260 - 261 - static inline void devm_usb_put_phy(struct device *dev, struct usb_phy *x) 262 259 { 263 260 } 264 261
+8
include/linux/usb/storage.h
··· 82 82 #define US_BULK_RESET_REQUEST 0xff 83 83 #define US_BULK_GET_MAX_LUN 0xfe 84 84 85 + /* 86 + * If 4 LUNs are supported then the LUNs would be 87 + * numbered from 0 to 3, and the return value for 88 + * US_BULK_GET_MAX_LUN request would be 3. The valid 89 + * LUN field is 4 bits wide, the upper limit is 0x0f. 90 + */ 91 + #define US_BULK_MAX_LUN_LIMIT 0x0f 92 + 85 93 #endif
+2 -1
include/linux/usb/tcpm.h
··· 163 163 void (*frs_sourcing_vbus)(struct tcpc_dev *dev); 164 164 int (*enable_auto_vbus_discharge)(struct tcpc_dev *dev, bool enable); 165 165 int (*set_auto_vbus_discharge_threshold)(struct tcpc_dev *dev, enum typec_pwr_opmode mode, 166 - bool pps_active, u32 requested_vbus_voltage); 166 + bool pps_active, u32 requested_vbus_voltage, 167 + u32 pps_apdo_min_voltage); 167 168 bool (*is_vbus_vsafe0v)(struct tcpc_dev *dev); 168 169 void (*set_partner_usb_comm_capable)(struct tcpc_dev *dev, bool enable); 169 170 void (*check_contaminant)(struct tcpc_dev *dev);
+2
include/linux/usb/typec.h
··· 140 140 * @mode: Index of the Mode 141 141 * @vdo: VDO returned by Discover Modes USB PD command 142 142 * @roles: Only for ports. DRP if the mode is available in both roles 143 + * @inactive: Only for ports. Make this port inactive (default is active). 143 144 * 144 145 * Description of an Alternate Mode which a connector, cable plug or partner 145 146 * supports. ··· 151 150 u32 vdo; 152 151 /* Only used with ports */ 153 152 enum typec_port_data roles; 153 + bool inactive; 154 154 }; 155 155 156 156 void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision);
+1
include/linux/usb/typec_tbt.h
··· 44 44 45 45 #define TBT_GEN3_NON_ROUNDED 0 46 46 #define TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED 1 47 + #define TBT_CABLE_ROUNDED BIT(19) 47 48 #define TBT_CABLE_OPTICAL BIT(21) 48 49 #define TBT_CABLE_RETIMER BIT(22) 49 50 #define TBT_CABLE_LINK_TRAINING BIT(23)
+4 -4
include/uapi/linux/usb/functionfs.h
··· 206 206 * +-----+-----------------+------+--------------------------+ 207 207 * | off | name | type | description | 208 208 * +-----+-----------------+------+--------------------------+ 209 - * | 0 | inteface | U8 | related interface number | 209 + * | 0 | interface | U8 | related interface number | 210 210 * +-----+-----------------+------+--------------------------+ 211 211 * | 1 | dwLength | U32 | length of the descriptor | 212 212 * +-----+-----------------+------+--------------------------+ ··· 224 224 * +-----+-----------------+------+--------------------------+ 225 225 * | off | name | type | description | 226 226 * +-----+-----------------+------+--------------------------+ 227 - * | 0 | inteface | U8 | related interface number | 227 + * | 0 | interface | U8 | related interface number | 228 228 * +-----+-----------------+------+--------------------------+ 229 229 * | 1 | dwLength | U32 | length of the descriptor | 230 230 * +-----+-----------------+------+--------------------------+ ··· 237 237 * | 11 | ExtProp[] | | list of ext. prop. d. | 238 238 * +-----+-----------------+------+--------------------------+ 239 239 * 240 - * ExtCompat[] is an array of valid Extended Compatiblity descriptors 240 + * ExtCompat[] is an array of valid Extended Compatibility descriptors 241 241 * which have the following format: 242 242 * 243 243 * +-----+-----------------------+------+-------------------------------------+ ··· 295 295 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang | 296 296 * 297 297 * For each language there is one stringtab entry (ie. there are lang_count 298 - * stringtab entires). Each StringTab has following format: 298 + * stringtab entries). Each StringTab has following format: 299 299 * 300 300 * | off | name | type | description | 301 301 * |-----+---------+-------------------+------------------------------------|
-1
scripts/mod/devicetable-offsets.c
··· 237 237 238 238 DEVID(typec_device_id); 239 239 DEVID_FIELD(typec_device_id, svid); 240 - DEVID_FIELD(typec_device_id, mode); 241 240 242 241 DEVID(tee_client_device_id); 243 242 DEVID_FIELD(tee_client_device_id, uuid);
+2 -7
scripts/mod/file2alias.c
··· 1219 1219 module_alias_printf(mod, true, "tbsvc:%s", alias); 1220 1220 } 1221 1221 1222 - /* Looks like: typec:idNmN */ 1222 + /* Looks like: typec:idN */ 1223 1223 static void do_typec_entry(struct module *mod, void *symval) 1224 1224 { 1225 - char alias[256] = {}; 1226 - 1227 1225 DEF_FIELD(symval, typec_device_id, svid); 1228 - DEF_FIELD(symval, typec_device_id, mode); 1229 1226 1230 - ADD(alias, "m", mode != TYPEC_ANY_MODE, mode); 1231 - 1232 - module_alias_printf(mod, false, "typec:id%04X%s", svid, alias); 1227 + module_alias_printf(mod, false, "typec:id%04X", svid); 1233 1228 } 1234 1229 1235 1230 /* Looks like: tee:uuid */