Add USB driver for HPE GXP Architecture
Subsystems (2)
v2 cover Add USB driver for HPE GXP Architecture
From: Richard Yu <[email protected]>
The GXP hub controller presents a four ports to host software. Each port is logically connected to one control endpoint and four generic endpoints.
---
Changes since v1:
*Renamed binding.
*Removed all unneeded include files.
*Using generic node name, usb-hub.
*Removed of_match_ptr().
*Using helper for both get resource and IO remap. *Using dev_err_probe() return in probe routine. *Used sizeof(*...) in the code instead of sizeof(struct...). *Removed the term "virtual" as it is still a device. *Removed the downstream port number and generic endpoints
number properties from device tree structure.
Richard Yu (3):
dt-bindings: usb: Add HPE GXP HUB Controller
usb: gadget: udc: gxp-udc: add HPE GXP USB HUB support
MAINTAINERS: add USB HUB support for GXP
.../devicetree/bindings/usb/hpe,gxp-hub.yaml | 53 + MAINTAINERS | 2 + drivers/usb/gadget/udc/Kconfig | 10 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/gxp-udc.c | 1371 +++++++++++++++++ 5 files changed, 1437 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/hpe,gxp-hub.yaml create mode 100644 drivers/usb/gadget/udc/gxp-udc.c
Signature · 1 line
2.17.1
PATCH v2 1/3 dt-bindings: usb: Add HPE GXP HUB Controller
From: Richard Yu <[email protected]>
Provide access to the two register regions for GXP HUB controller through the hpe,gxp-hub binding.
---
v2:
*Removed the term "virtual" as it is still a device. *Removed the downstream port number and generic endpoints
number properties from device tree structure.
--- .../devicetree/bindings/usb/hpe,gxp-hub.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/hpe,gxp-hub.yaml
Documentation/devicetree/bindings/usb/hpe,gxp-hub.yaml new file +53 -0
@@ -0,0 +1,53 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/hpe,gxp-hub.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HPE GXP USB HUB controller + +maintainers: + - Nick Hawkins <[email protected]> + - Richard Yu <[email protected]> + +description: + The HPE GXP USB HUB Controller implements 1 set of USB + register and several sets of device and endpoint registers to support + the HUB's downstream USB devices. + +properties: + compatible: + enum: + - hpe,gxp-hub + + reg: + items: + - description: GXP hub (gxphub) controller register set + - description: Several sets of Device and Endpoint registers to support + the HUB's downstream USB devices. + + reg-names: + items: + - const: gxphub + - const: udc + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - reg-names + - interrupts + +additionalProperties: false + +examples: + - | + usb-hub@80400800 { + compatible = "hpe,gxp-hub"; + reg = <0x80400800 0x0200>, <0x80401000 0x8000>; + reg-names = "gxphub", "udc"; + interrupts = <13>; + interrupt-parent = <&vic1>; + };
Signature · 1 line
2.17.1
Re: [PATCH v2 1/3] dt-bindings: usb: Add HPE GXP HUB Controller
Quoted 9 lines · On Thu, 07 Sep 2023 16:05:59 -0500, [email protected] wrote:
From: Richard Yu <[email protected]>
Provide access to the two register regions for GXP HUB controller through the hpe,gxp-hub binding.
Signed-off-by Richard Yu <[email protected]>---
Quoted 9 lines
v2:
*Removed the term "virtual" as it is still a device. *Removed the downstream port number and generic endpoints
number properties from device tree structure.--- .../devicetree/bindings/usb/hpe,gxp-hub.yaml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/hpe,gxp-hub.yaml
PATCH v2 2/3 usb: gadget: udc: gxp-udc: add HPE GXP USB HUB support
In reply to [email protected]From: Richard Yu <[email protected]>
The HPE GXP HUB controller presents a four port EHCI compatible PCI function to host software. Each port is logically connected to one control endpoint and four programmable endpoints.
---
v2:
*Removed all unneeded include files.
*Using generic node name, usb-hub.
*Removed of_match_ptr().
*Using helper for both get resource and IO remap. *Using dev_err_probe() return in probe routine. *Used sizeof(*...) in the code instead of sizeof(struct...). *Removed the downstream port number and generic endpoints
number properties from device tree structure.
--- drivers/usb/gadget/udc/Kconfig | 10 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/gxp-udc.c | 1371 ++++++++++++++++++++++++++++++ 3 files changed, 1382 insertions(+) create mode 100644 drivers/usb/gadget/udc/gxp-udc.c
drivers/usb/gadget/udc/Kconfig +10 -0
@@ -461,6 +461,16 @@ config USB_ASPEED_UDC dynamically linked module called "aspeed_udc" and force all gadget drivers to also be dynamically linked. +config USB_GXP_UDC + bool "GXP HUB Driver" + depends on ARCH_HPE_GXP || COMPILE_TEST + help + Enables HPE GXP HUB driver for HPE GXP. The GXP HUB + supports 4 ports. Each port supports 1 control + endpoint and 4 programmable endpoints. + + Say "y" to add support for GXP HUB driver + source "drivers/usb/gadget/udc/aspeed-vhub/Kconfig" #
drivers/usb/gadget/udc/Makefile +1 -0
@@ -42,3 +42,4 @@ obj-$(CONFIG_USB_ASPEED_VHUB) += aspeed-vhub/ obj-$(CONFIG_USB_ASPEED_UDC) += aspeed_udc.o obj-$(CONFIG_USB_BDC_UDC) += bdc/ obj-$(CONFIG_USB_MAX3420_UDC) += max3420_udc.o +obj-$(CONFIG_USB_GXP_UDC) += gxp-udc.o
drivers/usb/gadget/udc/gxp-udc.c new file +1371 -0
1,371 lines not on this page · raw message
Signature · 1 line
2.17.1
Greg KH
maintainerRe: [PATCH v2 2/3] usb: gadget: udc: gxp-udc: add HPE GXP USB HUB support
drivers/usb/gadget/udc/gxp-udc.c line 134
Quoted 10 lines · On Thu, Sep 07, 2023 at 04:06:00PM -0500, [email protected] wrote:
drivers/usb/gadget/udc/gxp-udc.c new file +10
-0+struct gxp_udc_drvdata { +void __iomem *base; +struct platform_device *pdev; +struct regmap *udcg_map; +struct gxp_udc_ep ep[GXP_UDC_MAX_NUM_EP ]; + +int irq; + +/* sysfs enclosure for the gadget gunk */ +struct device *port_dev;
A "raw" struct device? That's not ok. It's also going to break things, how was this tested? What does it look like in sysfs with this device?
Quoted 14 lines
drivers/usb/gadget/udc/gxp-udc.c new file +14
-0+/* +* The UDC core really needs us to have separate and uniquely +* named "parent" devices for each port so we create a sub device +* here for that purpose +*/ + drvdata->port_dev =kzalloc (sizeof (*drvdata->port_dev),GFP_KERNEL ); +if (!drvdata->port_dev) { + rc = -ENOMEM ; + goto fail_alloc; + } +device_initialize (drvdata->port_dev); + drvdata->port_dev->release = gxp_udc_dev_release; + drvdata->port_dev->parent = parent; +dev_set_name (drvdata->port_dev,"%s:p%d" ,dev_name (parent), idx +1 );
drivers/usb/gadget/udc/gxp-udc.c line 1260
Quoted 10 lines
drivers/usb/gadget/udc/gxp-udc.c new file +10
-0+ +/* DMA setting */ + drvdata->port_dev->dma_mask = parent->dma_mask; + drvdata->port_dev->coherent_dma_mask = parent->coherent_dma_mask; + drvdata->port_dev->bus_dma_limit = parent->bus_dma_limit; + drvdata->port_dev->dma_range_map = parent->dma_range_map; + drvdata->port_dev->dma_parms = parent->dma_parms; + drvdata->port_dev->dma_pools = parent->dma_pools; + + rc =device_add (drvdata->port_dev);
So you createad a "raw" device that does not belong to any bus or type and add it to sysfs? Why? Shouldn't it be a "virtual" device if you really want/need one?
Quoted 7 lines
drivers/usb/gadget/udc/gxp-udc.c new file +7
-0+if (rc) + goto fail_add; + +/* Populate gadget */ +gxp_udc_init (drvdata); + + rc =usb_add_gadget_udc (drvdata->port_dev, &drvdata->gadget);
drivers/usb/gadget/udc/gxp-udc.c line 1277
Quoted 10 lines
drivers/usb/gadget/udc/gxp-udc.c new file +10
-0+if (rc !=0 ) { +dev_err (drvdata->port_dev,"add gadget failed\n" ); + goto fail_udc; + } + rc =devm_request_irq (drvdata->port_dev, + drvdata->irq, + gxp_udc_irq, +IRQF_SHARED , + gxp_udc_name[drvdata->vdevnum], + drvdata);
devm_request_irq() is _very_ tricky, are you _SURE_ you got it right here? Why do you need to use it?
drivers/usb/gadget/udc/gxp-udc.c line 1286
Quoted 8 lines
drivers/usb/gadget/udc/gxp-udc.c new file +8
-0+if (rc <0 ) { +dev_err (drvdata->port_dev,"irq request failed\n" ); + goto fail_udc; + } + +return 0 ; + +/* ran code to simulate these three error exit, no double free */
What does this comment mean?
drivers/usb/gadget/udc/gxp-udc.c line 1295
Quoted 9 lines
drivers/usb/gadget/udc/gxp-udc.c new file +9
-0+fail_udc: +device_del (drvdata->port_dev); +fail_add: +put_device (drvdata->port_dev); +fail_alloc: +devm_kfree (parent, drvdata); + +return rc; +}
Where is the device removed from the system when done?
thanks,
greg k-h
RE: [PATCH v2 2/3] usb: gadget: udc: gxp-udc: add HPE GXP USB HUB support
Hi Greg KH,
Thank you very much for the feedback and sorry for the late respond.
Quoted 4 lines · On Thu, Sep 07, 2023 at 04:06:00PM -0500, [email protected] wrote:
Quoted 4 lines
drivers/usb/gadget/udc/gxp-udc.c new file +4
-0+struct gxp_udc_drvdata { +void __iomem *base; +struct platform_device *pdev; +struct regmap *udcg_map;
Quoted 8 lines
drivers/usb/gadget/udc/gxp-udc.c line 134
Quoted 6 lines
drivers/usb/gadget/udc/gxp-udc.c new file +6
-0+struct gxp_udc_ep ep[GXP_UDC_MAX_NUM_EP ]; + +int irq; + +/* sysfs enclosure for the gadget gunk */ +struct device *port_dev;A "raw" struct device? That's not ok. It's also going to break things, how was this tested? What does it look like in sysfs with this device?
I am using aspeed-vhub as example to write this gxp-hub driver. My struct gxp_udc_drvdata{} Is similar to the struct ast_vhub_dev{} in drivers/usb/gadget/udc/aspeed-vhub/vhub.h The "struct device *port_dev;" is for the child device which is attached to the hub device.
I tested this driver by modifying the create_usbhid.sh and ikvm_input.hpp in the obmc-ikvm. The modification is just changing the dev_name to be "80400800.usb-hub". I have made sure that the KVM is working. (The virtual keyboard and virtual mouse are working).
The devices will be shown as ./sys/devices/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p1 ./sys/devices/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p2 ./sys/devices/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p3 ./sys/devices/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p4
./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p1 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p2 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p3 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p4
Quoted 20 lines
Quoted 20 lines
drivers/usb/gadget/udc/gxp-udc.c new file +20
-0+/* +* The UDC core really needs us to have separate and uniquely +* named "parent" devices for each port so we create a sub device +* here for that purpose +*/ + drvdata->port_dev =kzalloc (sizeof (*drvdata->port_dev),GFP_KERNEL ); +if (!drvdata->port_dev) { + rc = -ENOMEM ; + goto fail_alloc; + } +device_initialize (drvdata->port_dev); + drvdata->port_dev->release = gxp_udc_dev_release; + drvdata->port_dev->parent = parent; +dev_set_name (drvdata->port_dev,"%s:p%d" ,dev_name (parent), idx + +1 ); + +/* DMA setting */ + drvdata->port_dev->dma_mask = parent->dma_mask; + drvdata->port_dev->coherent_dma_mask = parent->coherent_dma_mask; + drvdata->port_dev->bus_dma_limit = parent->bus_dma_limit;
Quoted 8 lines
drivers/usb/gadget/udc/gxp-udc.c line 1260
Quoted 5 lines
drivers/usb/gadget/udc/gxp-udc.c new file +5
-0+ drvdata->port_dev->dma_range_map = parent->dma_range_map; + drvdata->port_dev->dma_parms = parent->dma_parms; + drvdata->port_dev->dma_pools = parent->dma_pools; + + rc =device_add (drvdata->port_dev);So you createad a "raw" device that does not belong to any bus or type and add it to sysfs?
Why? Shouldn't it be a "virtual" device if you really want/need one?
I am just following the aspeed-vhub driver here. I thought I have to build the following entries:
./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p1 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p2 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p3 ./sys/bus/platform/devices/ahb@80000000/80400800.usb-hub/80400800.usb-hub:p4
In order for the ikvm application to get access the virtual devices.
Quoted 11 lines
Quoted 11 lines
drivers/usb/gadget/udc/gxp-udc.c new file +11
-0+if (rc) + goto fail_add; + +/* Populate gadget */ +gxp_udc_init (drvdata); + + rc =usb_add_gadget_udc (drvdata->port_dev, &drvdata->gadget); +if (rc !=0 ) { +dev_err (drvdata->port_dev,"add gadget failed\n" ); + goto fail_udc; + }
Quoted 8 lines
drivers/usb/gadget/udc/gxp-udc.c line 1277
Quoted 6 lines
drivers/usb/gadget/udc/gxp-udc.c new file +6
-0+ rc =devm_request_irq (drvdata->port_dev, + drvdata->irq, + gxp_udc_irq, +IRQF_SHARED , + gxp_udc_name[drvdata->vdevnum], + drvdata);
devm_request_irq()is _very_ tricky, are you _SURE_ you got it right here? Why do you need to use it?
I thought this is to install my device interrupt handler. Again, I just followed the aspeed-vhub driver. The Aspeed-vhub driver is doing it at ast_vhub_probe() core.c file.
In previous review, Mr. Kolowski pointed out that this is very tricky using "IRQF_SHARED". I tried all the Available flag and none are working for me, except "IRQF_SHARED". I also confirmed that the Aspeed-vhub driver is also using "IRQF_SHARED".
Quoted 10 lines
drivers/usb/gadget/udc/gxp-udc.c line 1286
Quoted 8 lines
drivers/usb/gadget/udc/gxp-udc.c new file +8
-0+if (rc <0 ) { +dev_err (drvdata->port_dev,"irq request failed\n" ); + goto fail_udc; + } + +return 0 ; + +/* ran code to simulate these three error exit, no double free */ What does this comment mean?
I will remove this comment. I put it in there because it was pointed out there is potential double free in the previous review. I ran through the error exit test cases and did not see any problem.
Quoted 11 lines
drivers/usb/gadget/udc/gxp-udc.c line 1295
Quoted 9 lines
drivers/usb/gadget/udc/gxp-udc.c new file +9
-0+fail_udc: +device_del (drvdata->port_dev); +fail_add: +put_device (drvdata->port_dev); +fail_alloc: +devm_kfree (parent, drvdata); + +return rc; +}Where is the device removed from the system when done?
I will add the device removed routine in the next check-in.
Quoted 3 lines
thanks,
greg k-h
Thank you very much
Richard.
PATCH v2 3/3 MAINTAINERS: add USB HUB support for GXP
In reply to [email protected]From: Richard Yu <[email protected]>
Add the usb hub driver and dt-bindinng documents.
---
v2:
*Changed file to hpe,gxp-hub.yaml
--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -2245,6 +2245,7 @@ F: Documentation/devicetree/bindings/hwmon/hpe,gxp-fan-ctrl.yaml F: Documentation/devicetree/bindings/i2c/hpe,gxp-i2c.yaml F: Documentation/devicetree/bindings/spi/hpe,gxp-spifi.yaml F: Documentation/devicetree/bindings/timer/hpe,gxp-timer.yaml +F: Documentation/devicetree/bindings/usb/hpe,gxp-hub.yaml F: Documentation/hwmon/gxp-fan-ctrl.rst F: arch/arm/boot/dts/hpe-bmc* F: arch/arm/boot/dts/hpe-gxp*
@@ -2253,6 +2254,7 @@ F: drivers/clocksource/timer-gxp.c F: drivers/hwmon/gxp-fan-ctrl.c F: drivers/i2c/busses/i2c-gxp.c F: drivers/spi/spi-gxp.c +F: drivers/usb/gadget/udc/gxp-udc.c F: drivers/watchdog/gxp-wdt.c ARM/IGEP MACHINE SUPPORT
Signature · 1 line
2.17.1