RE: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >Hi, > >On 22/07/19 12:02 AM, Pawel Laszczak wrote: >> + >> +/** >> + * cdns3_req_ep0_get_status - Handling of GET_STATUS standard USB request >> + * @priv_dev: extended gadget object >> + * @ctrl_req: pointer to received setup packet >> + * >> + * Returns 0 if success, error code on error >> + */ >> +static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, >> +struct usb_ctrlrequest *ctrl) >> +{ >> +__le16 *response_pkt; >> +u16 usb_status = 0; >> +u32 recip; >> +u32 reg; >> + >> +recip = ctrl->bRequestType & USB_RECIP_MASK; >> + >> +switch (recip) { >> +case USB_RECIP_DEVICE: >> +/* self powered */ >> +if (priv_dev->is_selfpowered) >> +usb_status = BIT(USB_DEVICE_SELF_POWERED); >> + >> +if (priv_dev->wake_up_flag) >> +usb_status |= BIT(USB_DEVICE_REMOTE_WAKEUP); >> + >> +if (priv_dev->gadget.speed != USB_SPEED_SUPER) >> +break; >> + >> +reg = readl(_dev->regs->usb_sts); > >I see usb_sts is read, but never used in this function? It's true, it's not used. Thanks. > >> + >> +if (priv_dev->u1_allowed) >> +usb_status |= BIT(USB_DEV_STAT_U1_ENABLED); >> + >> +if (priv_dev->u2_allowed) >> +usb_status |= BIT(USB_DEV_STAT_U2_ENABLED); >> + >> +break; >> +case USB_RECIP_INTERFACE: >> +return cdns3_ep0_delegate_req(priv_dev, ctrl); >> +case USB_RECIP_ENDPOINT: >> +/* check if endpoint is stalled */ >> +cdns3_select_ep(priv_dev, ctrl->wIndex); >> +if (EP_STS_STALL(readl(_dev->regs->ep_sts))) >> +usb_status = BIT(USB_ENDPOINT_HALT); >> +break; >> +default: >> +return -EINVAL; >> +} >> + >> +response_pkt = (__le16 *)priv_dev->setup_buf; >> +*response_pkt = cpu_to_le16(usb_status); >> + >> +cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, >> + sizeof(*response_pkt), 1, 0); >> +return 0; >> +} >> + > -- Cheers Pawell
RE: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > >On 21/07/2019 21:32, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver to Linux kernel. >> >> The Cadence USBSS DRD Controller is a highly configurable IP Core which >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >> The current driver has been validated with FPGA platform. We have >> support for PCIe bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliant with XHCI >> specification, so it works with standard XHCI Linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 46 + >> drivers/usb/cdns3/Makefile | 17 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 203 +++ >> drivers/usb/cdns3/core.c | 554 +++ >> drivers/usb/cdns3/core.h | 109 ++ >> drivers/usb/cdns3/debug.h | 171 ++ >> drivers/usb/cdns3/debugfs.c| 87 ++ >> drivers/usb/cdns3/drd.c| 390 + >> drivers/usb/cdns3/drd.h| 166 ++ >> drivers/usb/cdns3/ep0.c| 914 +++ >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 2338 >> drivers/usb/cdns3/gadget.h | 1321 >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 71 + >> drivers/usb/cdns3/trace.c | 11 + >> drivers/usb/cdns3/trace.h | 493 ++ >> 19 files changed, 6951 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> > > > >> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c >> new file mode 100644 >> index 0000..900b2ce08162 >> --- /dev/null >> +++ b/drivers/usb/cdns3/core.c >> @@ -0,0 +1,554 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Cadence USBSS DRD Driver. >> + * >> + * Copyright (C) 2018-2019 Cadence. >> + * Copyright (C) 2017-2018 NXP >> + * Copyright (C) 2019 Texas Instruments >> + * >> + * Author: Peter Chen >> + * Pawel Laszczak >> + * Roger Quadros >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "gadget.h" >> +#include "core.h" >> +#include "host-export.h" >> +#include "gadget-export.h" >> +#include "drd.h" >> +#include "debug.h" >> + >> +static inline >> +struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) >> +{ >> +WARN_ON(!cdns->roles[cdns->role]); >> +return cdns->roles[cdns->role]; >> +} >> + >> +static int cdns3_role_start(struct cdns3 *cdns, enum usb_role role) >> +{ >> +int ret; >> + >> +if (WARN_ON(role > USB_ROLE_DEVICE)) >> +return 0; >> + >> +mutex_lock(>mutex); >> +cdns->role = role; >> +mutex_unlock(>mutex); >> + >> +if (role == USB_ROLE_NONE) >> +return 0; > >We will need to have a role driver for NONE case so we can deal with >type-C cable swap case. I will post a patch at the end about this. >You can squash the patches and use them in the next revision. > >> + >> +if (!cdns->roles[role]) >> +return -ENXIO; >> + >> +if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE) >> +return 0; >> + >> +m
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Felipe >>> + >>> +static int cdns3_idle_init(struct cdns3 *cdns) >>> +{ >>> + struct cdns3_role_driver *rdrv; >>> + >>> + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); >>> + if (!rdrv) >>> + return -ENOMEM; >>> + >>> + rdrv->start = cdns3_idle_role_start; >>> + rdrv->stop = cdns3_idle_role_stop; >>> + rdrv->state = CDNS3_ROLE_STATE_INACTIVE; >>> + rdrv->suspend = NULL; >>> + rdrv->resume = NULL; >>> + rdrv->name = "idle"; >> >>why don't you use the mux framework for this? This looks a bit fishy >>too. Why do you have your own driver registration structure for your >>driver only? >> > >I assume you mean interface defined in include/linux/usb/role.h. >It's quite new framework and probably was added after I've start implementing >cdns3 driver. >At first glance it's look that I could use it. I've started integrating driver with role switch framework. Even if I use role switch interface , I still need this internal driver registration. It's convenient to use fallowing structure. struct cdns3_role_driver { int (*start)(struct cdns3 *cdns); void (*stop)(struct cdns3 *cdns); int (*suspend)(struct cdns3 *cdns, bool do_wakeup); int (*resume)(struct cdns3 *cdns, bool hibernated); const char *name; #define CDNS3_ROLE_STATE_INACTIVE 0 #define CDNS3_ROLE_STATE_ACTIVE 1 int state; }; Driver can supports: only Host, only Device or DRD - depending on configuration. If current configuration support only Host then driver assigns: rdrv_host->start= __cdns3_host_init; rdrv_host->stop = cdns3_host_exit; cdns->roles[CDNS3_ROLE_HOST] = rdrv_host cdns->roles[CDNS3_ROLE_GADGET = NULL; if support only Device then: rdrv_dev->start = __cdns3_ gadget _init; rdrv_dev->stop = cdns3_ gadget _exit; cdns->roles[CDNS3_ROLE_HOST]= NULL; for DRD: cdns->roles[CDNS3_ROLE_HOST = rdrv_host; cdns->roles[CDNS3_ROLE_GADGET] = rdrv_dev; So for DRD we will have both filled, but for only Device or Host we will have filled single element of array. With such array we can easily start/stop role by if (!cdns->roles[role]) not supported by configuration. else cdns->roles[role]->start / cdns->roles[role]->stop I don't need any extra: switch instruction or #ifdef statement. The name cdns3_role_driver can be misleading. Driver doesn't register the driver but rather the interface to Device/Host. Maybe I should change this name to cdns3_role_interface or cdns3_role_action ? Now I have my private enum: enum cdns3_roles { CDNS3_ROLE_IDLE = 0, CDNS3_ROLE_HOST, CDNS3_ROLE_GADGET, CDNS3_ROLE_END, }; I think I could replace it with usb_role. I need one extra state for IDLE but Instead of CDNS3_ROLE_IDLE I can use USB_ROLE_NONE. It should little simplify the driver and improve readability. Do you have any comments or suggestion ? Cheers, Pawel > >>> + >>> + cdns->roles[CDNS3_ROLE_IDLE] = rdrv; >>> + >>> + return 0; >>> +} >>> +
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> > >Hi, > >Pawel Laszczak writes: >>>>>> IRQF_ONESHOT can be used only in threaded handled. >>>>>> " >>>>>> * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler >>>>>> finished. >>>>>> *Used by threaded interrupts which need to keep the >>>>>> *irq line disabled until the threaded handler has been >>>>>> run. >>>>>> " >>>>> >>>>>so? >>>> >>>> I don't understand why If I don't have threaded handler why I need >>>> IRQF_ONESHOT. >>>> Why interrupt cannot be reenabled after hardirq handler finished ? >>>> I do not use threaded handler so this flag seem unnecessary. >>> >>>Unless this has changed over the years, it was a requirement from IRQ >>>susbystem. >>> >>> /* >>> * Drivers are often written to work w/o knowledge about the >>> * underlying irq chip implementation, so a request for a >>> * threaded irq without a primary hard irq context handler >>> * requires the ONESHOT flag to be set. Some irq chips like >>> * MSI based interrupts are per se one shot safe. Check the >>> * chip flags, so we can avoid the unmask dance at the end of >>> * the threaded handler for those. >>> */ >>> if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) >>> new->flags &= ~IRQF_ONESHOT; >> >> From description I understand that it should be set when driver uses only >> threaded handler without hard irq handler. >> eg. >> >> ret = devm_request_threaded_irq(dev, data->usb_id_irq, >> NULL, int3496_thread_isr, >> IRQF_SHARED | IRQF_ONESHOT | >> IRQF_TRIGGER_RISING | >> IRQF_TRIGGER_FALLING, >> dev_name(dev), data); >> >> It make sense, we don't have hard irq handler so we can't clear source of >> interrupt. >> If we clear it immediately in interrupt controller then the same interrupt >> could >> be raised again, because it was not cleared e.g in controller register. > >You are correct. Big mistake on my side. Apologies. All right, you're welcome. I learn a lot of during such discussions :). >-- >balbi
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> >Hi, > >Pawel Laszczak writes: >>>> IRQF_ONESHOT can be used only in threaded handled. >>>> " >>>> * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler >>>> finished. >>>> *Used by threaded interrupts which need to keep the >>>> *irq line disabled until the threaded handler has been >>>> run. >>>> " >>> >>>so? >> >> I don't understand why If I don't have threaded handler why I need >> IRQF_ONESHOT. >> Why interrupt cannot be reenabled after hardirq handler finished ? >> I do not use threaded handler so this flag seem unnecessary. > >Unless this has changed over the years, it was a requirement from IRQ >susbystem. > > /* >* Drivers are often written to work w/o knowledge about the >* underlying irq chip implementation, so a request for a >* threaded irq without a primary hard irq context handler >* requires the ONESHOT flag to be set. Some irq chips like >* MSI based interrupts are per se one shot safe. Check the >* chip flags, so we can avoid the unmask dance at the end of >* the threaded handler for those. >*/ > if (desc->irq_data.chip->flags & IRQCHIP_ONESHOT_SAFE) > new->flags &= ~IRQF_ONESHOT; >From description I understand that it should be set when driver uses only threaded handler without hard irq handler. eg. ret = devm_request_threaded_irq(dev, data->usb_id_irq, NULL, int3496_thread_isr, IRQF_SHARED | IRQF_ONESHOT | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, dev_name(dev), data); It make sense, we don't have hard irq handler so we can't clear source of interrupt. If we clear it immediately in interrupt controller then the same interrupt could be raised again, because it was not cleared e.g in controller register. >>>>>> +} else { >>>>>> +struct usb_request *request; >>>>>> + >>>>>> +if (priv_dev->eps[index]->flags & EP_WEDGE) { >>>>>> +cdns3_select_ep(priv_dev, 0x00); >>>>>> +return 0; >>>>>> +} >>>>>> + >>>>>> +cdns3_dbg(priv_ep->cdns3_dev, "Clear Stalled endpoint >>>>>> %s\n", >>>>>> + priv_ep->name); >>>>> >>>>>why do you need your own wrapper around dev_dbg()? This looks quite >>>>>unnecessary. >>>> >>>> It's generic function used for adding message to trace.log. It's not >>>> wrapper to dev_dbg >>>> >>>> void cdns3_dbg(struct cdns3_device *priv_dev, const char *fmt, ...) >>>> { >>>>struct va_format vaf; >>>>va_list args; >>>> >>>>va_start(args, fmt); >>>>vaf.fmt = fmt; >>>>vaf.va = >>>>trace_cdns3_log(priv_dev, ); >>>>va_end(args); >>>> } >>> >>>oh. Don't do it like that. Add a proper trace event that actually >>>decodes the information you want. These random messages will give you >>>trouble in the future. I had this sort of construct in dwc3 for a while >>>and it became clear that it's a bad idea. It's best to have trace events >>>that decode information coming from the HW. That way your trace logs >>>have a "predictable" shape/format and you can easily find problem areas. >> >> Ok , I will change this. >> I used such solution because I didn't want to create to many trace events. >> I used it only for rely used messages. > >If you have these messages that are *really* needed, then you should add >a trace event for it. Look at the events we have on dwc3 if you need >some inspiration. Could also look at the history of our trace events to >figure out how things changed over time. > >cheers > >-- >balbi
RE: [PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string.
>-Original Message- >From: Felipe Balbi >Sent: Tuesday, July 9, 2019 8:30 AM >To: Pawel Laszczak >Cc: gre...@linuxfoundation.org; linux-...@vger.kernel.org; rog...@ti.com; >linux-kernel@vger.kernel.org; jbergsa...@ti.com; >nsek...@ti.com; n...@ti.com; Suresh Punnoose ; Jayshri >Dajiram Pawar ; Rahul Kumar >; Anil Joy Varughese >Subject: RE: [PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and >usb_dr_mode_to_string. > >EXTERNAL MAIL > > > >Hi, > >Pawel Laszczak writes: >>>> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h >>>> index 69f1b6328532..c156817672c4 100644 >>>> --- a/include/linux/usb/otg.h >>>> +++ b/include/linux/usb/otg.h >>>> @@ -129,4 +129,20 @@ enum usb_dr_mode { >>>> */ >>>> extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); >>>> >>>> +/** >>>> + * usb_get_dr_mode_from_string - Convert string to dual role mode. >>>> + * @str: Pointer to the given string >>>> + * >>>> + * The function gets string and returns the correspondig enum usb_dr_mode. >>>> + */ >>>> +extern enum usb_dr_mode usb_get_dr_mode_from_string(const char *str); >>>> + >>>> +/** >>>> + * usb_dr_mode_to_string - Convert dual role mode to string. >>>> + * @dr_mode: Pointer to the given dual role mode >>>> + * >>>> + * The function gets enum usb_dr_mode, and returns the correspondig >>>> string. >>>> + */ >>>> +extern const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode); >>>> + >>>> #endif /* __LINUX_USB_OTG_H */ >>> >>>Still missing the stubs I mentioned. Did you try compiling with and >>>without common enabled? >>> >> Sorry, I thought that I send answer yesterday but it's look like I prepared >> the answer but >> I forgot to send. >> >> In /drivers/usb/Kconfig we have: >> >> config USB >> tristate "Support for Host-side USB" >> depends on USB_ARCH_HAS_HCD >> select USB_COMMON >> >> and in /drivers/usb/gadget/Kconfig we have: >> >> menuconfig USB_GADGET >> tristate "USB Gadget Support" >> select USB_COMMON >> >> I think that it should cover all cases. >> >> Am I right ? > >Run a few tens of randconfig builds and see if you ever catch any >problem. I think randconfig can produce a defconfig where USB=n >USB_GADGET=n and USB_COMMON=y. Ok, I will test it, but I think that it should work. The same situation we have for example with: usb_otg_state_string or usb_ep_type_string. > >-- >balbi
RE: [PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string.
Hi, > >Hi, > >Pawel Laszczak writes: >> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h >> index 69f1b6328532..c156817672c4 100644 >> --- a/include/linux/usb/otg.h >> +++ b/include/linux/usb/otg.h >> @@ -129,4 +129,20 @@ enum usb_dr_mode { >> */ >> extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); >> >> +/** >> + * usb_get_dr_mode_from_string - Convert string to dual role mode. >> + * @str: Pointer to the given string >> + * >> + * The function gets string and returns the correspondig enum usb_dr_mode. >> + */ >> +extern enum usb_dr_mode usb_get_dr_mode_from_string(const char *str); >> + >> +/** >> + * usb_dr_mode_to_string - Convert dual role mode to string. >> + * @dr_mode: Pointer to the given dual role mode >> + * >> + * The function gets enum usb_dr_mode, and returns the correspondig string. >> + */ >> +extern const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode); >> + >> #endif /* __LINUX_USB_OTG_H */ > >Still missing the stubs I mentioned. Did you try compiling with and >without common enabled? > Sorry, I thought that I send answer yesterday but it's look like I prepared the answer but I forgot to send. In /drivers/usb/Kconfig we have: config USB tristate "Support for Host-side USB" depends on USB_ARCH_HAS_HCD select USB_COMMON and in /drivers/usb/gadget/Kconfig we have: menuconfig USB_GADGET tristate "USB Gadget Support" select USB_COMMON I think that it should cover all cases. Am I right ? Pawel >-- >balbi
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
>Hi, > >Pawel Laszczak writes: >>>> +void cdns3_role_stop(struct cdns3 *cdns) >>> >>>not static? Why is it so that _start() is static but _stop() is not? >>>Looks fishy >> >> This function is used in cdns3_role_stop in debugfs.c file so it can't >> be static. > >it's still super fishy. Why don't you need _start() from debugfs.c? In >any case, the role framework would remove the need for any of this, I >suppose. Yes, I'm going to use the role framework so it will be probably changed. > >>>> +static int cdns3_idle_role_start(struct cdns3 *cnds) >>>> +{ /* Hold PHY in RESET */ >>> >>>huh? >>> >>>> + return 0; >>>> +} >>>> + >>>> +static void cdns3_idle_role_stop(struct cdns3 *cnds) >>>> +{ >>>> + /* Program Lane swap and bring PHY out of RESET */ >>> >>>double huh? >>> >> >> These functions were added for consistency with FSM described in controller >> specification. >> Yes, I know that you don't like empty functions :), but it could be helpful >> in >> understanding how this controller work. > >frankly, it really doesn't. An empty function doesn't really help IMHO. I will change it. > >>>> +static const char *const cdns3_mode[] = { >>>> + [USB_DR_MODE_UNKNOWN] = "unknown", >>>> + [USB_DR_MODE_OTG] = "otg", >>>> + [USB_DR_MODE_HOST] = "host", >>>> + [USB_DR_MODE_PERIPHERAL]= "device", >>>> +}; >>> >>>don't we have a generic version of this under usb/common ? >>> >> Yes, there is a similar array, but it is defined also as static >> and there is no function for converting value to string. >> There is only function for converting string to value. > >right. You can add the missing interface generically instead of >duplicating the enumeration. Patch adding such extension has posted. > >> There is also: >> [USB_DR_MODE_UNKNOWN]= "", >> Instead of: >> [USB_DR_MODE_UNKNOWN]= "unknown", >> >> So, for USB_DR_MODE_UNKNOWN user will not see anything information. > >But that's what "unknown" means :-) We don't know the information. > >>>> +static irqreturn_t cdns3_drd_irq(int irq, void *data) >>>> +{ >>>> + irqreturn_t ret = IRQ_NONE; >>>> + struct cdns3 *cdns = data; >>>> + u32 reg; >>>> + >>>> + if (cdns->dr_mode != USB_DR_MODE_OTG) >>>> + return ret; >>>> + >>>> + reg = readl(>otg_regs->ivect); >>>> + >>>> + if (!reg) >>>> + return ret; >>>> + >>>> + if (reg & OTGIEN_ID_CHANGE_INT) { >>>> + dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", >>>> + cdns3_get_id(cdns)); >>>> + >>>> + ret = IRQ_HANDLED; >>>> + } >>>> + >>>> + if (reg & (OTGIEN_VBUSVALID_RISE_INT | OTGIEN_VBUSVALID_FALL_INT)) { >>>> + dev_dbg(cdns->dev, "OTG IRQ: new VBUS: %d\n", >>>> + cdns3_get_vbus(cdns)); >>>> + >>>> + ret = IRQ_HANDLED; >>>> + } >>>> + >>>> + if (ret == IRQ_HANDLED) >>>> + queue_work(system_freezable_wq, >role_switch_wq); >>>> + >>>> + writel(~0, >otg_regs->ivect); >>>> + return ret; >>>> +} >>> >>>seems like you could use threaded irq to avoid this workqueue. >> >> >> This function is also called in cdns3_mode_write (debugfs.c file), >> therefor after changing it to threaded irq I will still need workqueue. > >Why? debugfs writes are not atomic. They run in process context, right? >Just don't disable interrupts while running this and you should be fine. Yes, It should work. > >>>> + cdns->desired_dr_mode = cdns->dr_mode; >>>> + cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; >>>> + >>>> + ret = devm_request_threaded_irq(cdns->dev, cdns->otg_irq, >>>> + cdns3_drd_irq, >>>> + NULL, IRQF_SHARED, >>> >>>if you don't have a threaded handler, you should set IRQF_ONESHOT. I >>>would prefer if you implement a threaded handler that doesn't require >>&
[PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string.
Patch introduces new function usb_dr_mode_to_string for converting dual role mod to string and removes static from usb_dr_mode_to_string definition. Both changes have made to avoid duplication of code by cdns3 driver. Signed-off-by: Pawel Laszczak --- drivers/usb/common/common.c | 12 +++- include/linux/usb/otg.h | 16 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 18f5dcf58b0d..a485071325b3 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -118,13 +118,14 @@ static const char *const usb_dr_modes[] = { [USB_DR_MODE_OTG] = "otg", }; -static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) +enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) { int ret; ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str); return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret; } +EXPORT_SYMBOL_GPL(usb_get_dr_mode_from_string); enum usb_dr_mode usb_get_dr_mode(struct device *dev) { @@ -139,6 +140,15 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev) } EXPORT_SYMBOL_GPL(usb_get_dr_mode); +const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode) +{ + if (dr_mode > USB_DR_MODE_UNKNOWN || dr_mode <= USB_DR_MODE_PERIPHERAL) + return usb_dr_modes[dr_mode]; + + return usb_dr_modes[USB_DR_MODE_UNKNOWN]; +} +EXPORT_SYMBOL_GPL(usb_dr_mode_to_string); + #ifdef CONFIG_OF /** * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 69f1b6328532..c156817672c4 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -129,4 +129,20 @@ enum usb_dr_mode { */ extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); +/** + * usb_get_dr_mode_from_string - Convert string to dual role mode. + * @str: Pointer to the given string + * + * The function gets string and returns the correspondig enum usb_dr_mode. + */ +extern enum usb_dr_mode usb_get_dr_mode_from_string(const char *str); + +/** + * usb_dr_mode_to_string - Convert dual role mode to string. + * @dr_mode: Pointer to the given dual role mode + * + * The function gets enum usb_dr_mode, and returns the correspondig string. + */ +extern const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode); + #endif /* __LINUX_USB_OTG_H */ -- 2.17.1
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> >(please send it as a formal patch from now on) I will send it. I think even today. > >Hi, > >Pawel Laszczak writes: >> The prototype was added , but not all text was past. Sorry for that. >> >> Fixed version: with your changes. >> >> / v2 corrected >> commit 4553d48dd0500085d90c8280e28714072279c3dd (HEAD) >> Author: Pawel Laszczak >> Date: Mon Jul 8 12:53:47 2019 +0200 >> >> usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string. >> >> Patch introduces new function usb_dr_mode_to_string for converting dual >> role >> mod to string and removes static from usb_dr_mode_to_string definition. >> >> Both changes have made to avoid duplication of code by cdns3 driver. > >missing Signed-off-by > >> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h >> index 69f1b6328532..c156817672c4 100644 >> --- a/include/linux/usb/otg.h >> +++ b/include/linux/usb/otg.h >> @@ -129,4 +129,20 @@ enum usb_dr_mode { >> */ >> extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); >> >> +/** >> + * usb_get_dr_mode_from_string - Convert string to dual role mode. >> + * @str: Pointer to the given string >> + * >> + * The function gets string and returns the correspondig enum usb_dr_mode. >> + */ > >why duplicate the documentation? Perhaps put it only in the header, >otherwise we will need to update two locations whenever these functions >change. Ok, I've removed it from drviers/usb/common/common.c. > >> +extern enum usb_dr_mode usb_get_dr_mode_from_string(const char *str); >> + >> +/** >> + * usb_dr_mode_to_string - Convert dual role mode to string. >> + * @dr_mode: Pointer to the given dual role mode >> + * >> + * The function gets enum usb_dr_mode, and returns the correspondig string. >> + */ >> +extern const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode); > >Don't you need a stub for builds when CONFIG_USB_COMMON=n? > We don't need it. It will be enabled when USB_GADGET or USB is enabled. It should cover all cases. menuconfig USB_GADGET tristate "USB Gadget Support" select USB_COMMON config USB tristate "Support for Host-side USB" depends on USB_ARCH_HAS_HCD select USB_COMMON Pawel >-- >balbi
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> >Hi, > >Pawel Laszczak writes: >> Please look at the changes in drivers/usb/common/common.c file. >> I'm going to add it as next patch to next version. >> >> >>>Pawel Laszczak writes: >>>>>> +void cdns3_role_stop(struct cdns3 *cdns) >>> >>>>>> +static const char *const cdns3_mode[] = { >>>>>> +[USB_DR_MODE_UNKNOWN] = "unknown", >>>>>> +[USB_DR_MODE_OTG] = "otg", >>>>>> +[USB_DR_MODE_HOST] = "host", >>>>>> +[USB_DR_MODE_PERIPHERAL]= "device", >>>>>> +}; >>>>> >>>>>don't we have a generic version of this under usb/common ? >>>>> >>>> Yes, there is a similar array, but it is defined also as static >>>> and there is no function for converting value to string. >>>> There is only function for converting string to value. >>> >>>right. You can add the missing interface generically instead of >>>duplicating the enumeration. >>> >>>> There is also: >>>> [USB_DR_MODE_UNKNOWN] = "", >>>> Instead of: >>>> [USB_DR_MODE_UNKNOWN] = "unknown", >>>> >>>> So, for USB_DR_MODE_UNKNOWN user will not see anything information. >>> >>>But that's what "unknown" means :-) We don't know the information. >>> >> >> // start >> commit 607754c60fabc43408f4f2de82d3560c72870787 (HEAD) >> Author: Pawel Laszczak >> Date: Mon Jul 8 12:53:47 2019 +0200 >> >> usb:common Added usb_get_dr_mode_from_string and usb_dr_mode_to_string. > >This would read better as: > > usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string. > >> >> Patch introduces new function usb_dr_mode_to_string for converting dual >> role >> mod to string and removes static from usb_dr_mode_to_string definition. >> >> Both changes have made to avoid duplication of code by cdns3 driver. >> >> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c >> index 18f5dcf58b0d..ab59954deff8 100644 >> --- a/drivers/usb/common/common.c >> +++ b/drivers/usb/common/common.c >> @@ -118,13 +118,20 @@ static const char *const usb_dr_modes[] = { >> [USB_DR_MODE_OTG] = "otg", >> }; >> >> -static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) >> +/** >> + * usb_get_dr_mode_from_string - Convert string to dual role mode. >> + * @str: Pointer to the given string >> + * >> + * The function gets string and returns the correspondig enum usb_dr_mode. >> + */ >> +enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) >> { >> int ret; >> >> ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str); >> return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret; >> } >> +EXPORT_SYMBOL_GPL(usb_get_dr_mode_from_string); >> >> enum usb_dr_mode usb_get_dr_mode(struct device *dev) >> { >> @@ -139,6 +146,21 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev) >> } >> EXPORT_SYMBOL_GPL(usb_get_dr_mode); >> >> +/** >> + * usb_dr_mode_to_string - Convert dual role mode to stringi. > >s/stringi/string > >> + * @dr_mode: Pointer to the given dual role mode >> + * >> + * The function gets enum usb_dr_mode, and returns the correspondig string. >> + */ >> +const *char usb_dr_mode_to_string(const enum usb_dr_mode dr_mode) >> +{ >> + if (dr_mode > USB_DR_MODE_UNKNOWN || dr_mode <= >> USB_DR_MODE_PERIPHERAL) >> + return usb_dr_modes[dr_mode]; >> + >> + return usb_dr_modes[USB_DR_MODE_UNKNOWN]; >> +} >> +EXPORT_SYMBOL_GPL(usb_dr_mode_to_string); > >missing prototype in a header file. > The prototype was added , but not all text was past. Sorry for that. Fixed version: with your changes. / v2 corrected commit 4553d48dd0500085d90c8280e28714072279c3dd (HEAD) Author: Pawel Laszczak Date: Mon Jul 8 12:53:47 2019 +0200 usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string. Patch introduces new function usb_dr_mode_to_string for converting dual role mod to string and removes static from usb_dr_mode_to_string definition. Both changes have made to avoid duplication of code by cdns3 driver. diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c ind
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Felipe Please look at the changes in drivers/usb/common/common.c file. I'm going to add it as next patch to next version. >Pawel Laszczak writes: >>>> +void cdns3_role_stop(struct cdns3 *cdns) > >>>> +static const char *const cdns3_mode[] = { >>>> + [USB_DR_MODE_UNKNOWN] = "unknown", >>>> + [USB_DR_MODE_OTG] = "otg", >>>> + [USB_DR_MODE_HOST] = "host", >>>> + [USB_DR_MODE_PERIPHERAL]= "device", >>>> +}; >>> >>>don't we have a generic version of this under usb/common ? >>> >> Yes, there is a similar array, but it is defined also as static >> and there is no function for converting value to string. >> There is only function for converting string to value. > >right. You can add the missing interface generically instead of >duplicating the enumeration. > >> There is also: >> [USB_DR_MODE_UNKNOWN]= "", >> Instead of: >> [USB_DR_MODE_UNKNOWN]= "unknown", >> >> So, for USB_DR_MODE_UNKNOWN user will not see anything information. > >But that's what "unknown" means :-) We don't know the information. > // start commit 607754c60fabc43408f4f2de82d3560c72870787 (HEAD) Author: Pawel Laszczak Date: Mon Jul 8 12:53:47 2019 +0200 usb:common Added usb_get_dr_mode_from_string and usb_dr_mode_to_string. Patch introduces new function usb_dr_mode_to_string for converting dual role mod to string and removes static from usb_dr_mode_to_string definition. Both changes have made to avoid duplication of code by cdns3 driver. diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 18f5dcf58b0d..ab59954deff8 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -118,13 +118,20 @@ static const char *const usb_dr_modes[] = { [USB_DR_MODE_OTG] = "otg", }; -static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) +/** + * usb_get_dr_mode_from_string - Convert string to dual role mode. + * @str: Pointer to the given string + * + * The function gets string and returns the correspondig enum usb_dr_mode. + */ +enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) { int ret; ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str); return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret; } +EXPORT_SYMBOL_GPL(usb_get_dr_mode_from_string); enum usb_dr_mode usb_get_dr_mode(struct device *dev) { @@ -139,6 +146,21 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev) } EXPORT_SYMBOL_GPL(usb_get_dr_mode); +/** + * usb_dr_mode_to_string - Convert dual role mode to stringi. + * @dr_mode: Pointer to the given dual role mode + * + * The function gets enum usb_dr_mode, and returns the correspondig string. + */ +const *char usb_dr_mode_to_string(const enum usb_dr_mode dr_mode) +{ + if (dr_mode > USB_DR_MODE_UNKNOWN || dr_mode <= USB_DR_MODE_PERIPHERAL) + return usb_dr_modes[dr_mode]; + + return usb_dr_modes[USB_DR_MODE_UNKNOWN]; +} +EXPORT_SYMBOL_GPL(usb_dr_mode_to_string); / end What do you thing about it ? Pawel
RE: [PATCH v9 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Felipe, > >Hi, > >Pawel Laszczak writes: >> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c >> new file mode 100644 >> index ..ddc73f1c87c5 >> --- /dev/null >> +++ b/drivers/usb/cdns3/core.c >> @@ -0,0 +1,543 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Cadence USBSS DRD Driver. >> + * >> + * Copyright (C) 2018-2019 Cadence. >> + * Copyright (C) 2017-2018 NXP >> + * Copyright (C) 2019 Texas Instruments >> + * >> + * Author: Peter Chen >> + * Pawel Laszczak >> + * Roger Quadros >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#include "gadget.h" >> +#include "core.h" >> +#include "host-export.h" >> +#include "gadget-export.h" >> +#include "drd.h" >> +#include "debug.h" >> + >> +/** >> + * cdns3_handshake - spin reading until handshake completes or fails >> + * @ptr: address of device controller register to be read >> + * @mask: bits to look at in result of read >> + * @done: value of those bits when handshake succeeds >> + * @usec: timeout in microseconds >> + * >> + * Returns negative errno, or zero on success >> + * >> + * Success happens when the "mask" bits have the specified value (hardware >> + * handshake done). There are two failure modes: "usec" have passed (major >> + * hardware flakeout), or the register reads as all-ones (hardware removed). >> + */ >> +int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) >> +{ >> +u32 result; >> + >> +do { >> +result = readl(ptr); >> +if (result == ~(u32)0) /* card removed */ >> +return -ENODEV; >> + >> +result &= mask; >> +if (result == done) >> +return 0; >> + >> +udelay(1); >> +usec--; >> +} while (usec > 0); >> + >> +return -ETIMEDOUT; > >looks like readl_poll_timeout_atomic() would handle this. > Actually, it works the same. I'm going to use it instead cdns3_handshake. >> +} >> + >> +static inline >> +struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) >> +{ >> +WARN_ON(cdns->role >= CDNS3_ROLE_END || !cdns->roles[cdns->role]); >> +return cdns->roles[cdns->role]; >> +} >> + >> +static int cdns3_role_start(struct cdns3 *cdns, enum cdns3_roles role) >> +{ >> +int ret; >> + >> +if (WARN_ON(role >= CDNS3_ROLE_END)) >> +return 0; >> + >> +if (!cdns->roles[role]) >> +return -ENXIO; >> + >> +if (cdns->roles[role]->state == CDNS3_ROLE_STATE_ACTIVE) >> +return 0; >> + >> +mutex_lock(>mutex); >> +cdns->role = role; >> +ret = cdns->roles[role]->start(cdns); >> +if (!ret) >> +cdns->roles[role]->state = CDNS3_ROLE_STATE_ACTIVE; >> +mutex_unlock(>mutex); >> +return ret; >> +} >> + >> +void cdns3_role_stop(struct cdns3 *cdns) > >not static? Why is it so that _start() is static but _stop() is not? >Looks fishy This function is used in cdns3_role_stop in debugfs.c file so it can't be static. >> +{ >> +enum cdns3_roles role = cdns->role; >> + >> +if (role >= CDNS3_ROLE_END) { >> +WARN_ON(role > CDNS3_ROLE_END); >> +return; >> +} >> + >> +if (cdns->roles[role]->state == CDNS3_ROLE_STATE_INACTIVE) >> +return; >> + >> +mutex_lock(>mutex); >> +cdns->roles[role]->stop(cdns); >> +cdns->roles[role]->state = CDNS3_ROLE_STATE_INACTIVE; >> +mutex_unlock(>mutex); >> +} >> + >> +static void cdns3_exit_roles(struct cdns3 *cdns) >> +{ >> +cdns3_role_stop(cdns); >> +cdns3_drd_exit(cdns); >> +} >> + >> +enum cdns3_roles cdsn3_get_real_role(struct cdns3 *cdns); >> + >> +static int cdns3_idle_role_start(struct cdns3 *cnds) >> +{ /* Hold PHY in RESET */ > >huh? > >> +return 0; >> +} >> + >> +static void cdns3_idle_role_stop(struct cdns3 *cnds) >> +{ >> +/* Program Lane swap and bring PHY out of RESET */ > >double huh? > Th
RE: [PATCH v9 2/6] usb:gadget Separated decoding functions from dwc3 driver.
> > >On Fri, Jul 05, 2019 at 11:39:57AM +0000, Pawel Laszczak wrote: >> >> >On Fri, Jul 05, 2019 at 11:57:14AM +0100, Pawel Laszczak wrote: >> >> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver >> >> to driver/usb/gadget/debug.c file. These moved functions include: >> >> dwc3_decode_get_status >> >> dwc3_decode_set_clear_feature >> >> dwc3_decode_set_address >> >> dwc3_decode_get_set_descriptor >> >> dwc3_decode_get_configuration >> >> dwc3_decode_set_configuration >> >> dwc3_decode_get_intf >> >> dwc3_decode_set_intf >> >> dwc3_decode_synch_frame >> >> dwc3_decode_set_sel >> >> dwc3_decode_set_isoch_delay >> >> dwc3_decode_ctrl >> >> >> >> These functions are used also in inroduced cdns3 driver. >> >> >> >> All functions prefixes were changed from dwc3 to usb. >> >> Also, function's parameters has been extended according to the name >> >> of fields in standard SETUP packet. >> >> Additionally, patch adds usb_decode_ctrl function to >> >> include/linux/usb/gadget.h file. >> > >> >No it does not :( >> >> I've forgot about this :( >> >> It should be include/linux/usb/ch.9.h >> >> > >> >> Signed-off-by: Pawel Laszczak >> >> --- >> >> drivers/usb/common/Makefile | 5 + >> >> drivers/usb/common/debug.c | 268 >> >> drivers/usb/dwc3/debug.h| 252 - >> >> drivers/usb/dwc3/trace.h| 2 +- >> >> include/linux/usb/ch9.h | 25 >> >> 5 files changed, 299 insertions(+), 253 deletions(-) >> >> create mode 100644 drivers/usb/common/debug.c >> >> >> >> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile >> >> index 0a7c45e85481..cdc66b59a6f0 100644 >> >> --- a/drivers/usb/common/Makefile >> >> +++ b/drivers/usb/common/Makefile >> >> @@ -5,6 +5,11 @@ >> >> >> >> obj-$(CONFIG_USB_COMMON) += usb-common.o >> >> usb-common-y += common.o >> >> + >> >> +ifneq ($(CONFIG_TRACING),) >> >> + usb-common-y += debug.o >> >> +endif >> > >> >So only enable this if tracing is not emabled? Or if enabled? I'm >> >confused, isn't there an easier way to write this? >> >> It's checks if CONFIG_TRACING is enable. >> It's a common way checking if option is enabled in usb subsystem. > >Why not just write this as: > usb-common-$(CONFIG_TRACING)+= debug.o >? Ok, I will do this in this way. Thanks. > >thanks, > >greg k-h
RE: [PATCH v9 2/6] usb:gadget Separated decoding functions from dwc3 driver.
>EXTERNAL MAIL > > > >Hi, > >Pawel Laszczak writes: >> diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h >> index da82606be605..d388a3a5ab7e 100644 >> --- a/include/linux/usb/ch9.h >> +++ b/include/linux/usb/ch9.h >> @@ -70,4 +70,29 @@ extern enum usb_device_speed usb_get_maximum_speed(struct >> device *dev); >> */ >> extern const char *usb_state_string(enum usb_device_state state); >> >> +/** >> + * usb_decode_ctrl - Returns human readable representation of control >> request. >> + * @str: buffer to return a human-readable representation of control >> request. >> + * This buffer should have about 200 bytes. >> + * @size: size of str buffer. >> + * @bRequestType: matches the USB bmRequestType field >> + * @bRequest: matches the USB bRequest field >> + * @wValue: matches the USB wValue field (CPU byte order) >> + * @wIndex: matches the USB wIndex field (CPU byte order) >> + * @wLength: matches the USB wLength field (CPU byte order) >> + * >> + * Function returns decoded, formatted and human-readable description of >> + * control request packet. >> + * >> + * The usage scenario for this is for tracepoints, so function as a return >> + * use the same value as in parameters. This approach allows to use this >> + * function in TP_printk >> + * >> + * Important: wValue, wIndex, wLength parameters before invoking this >> function >> + * should be processed by le16_to_cpu macro. >> + */ >> +extern const char *usb_decode_ctrl(char *str, size_t size, __u8 >> bRequestType, >> + __u8 bRequest, __u16 wValue, __u16 wIndex, >> + __u16 wLength); >> + > >where's the stub when !TRACING? Right, I will add #ifdef CONFIG_TRACING . #endif > >-- >balbi
RE: [PATCH v9 2/6] usb:gadget Separated decoding functions from dwc3 driver.
>On Fri, Jul 05, 2019 at 11:57:14AM +0100, Pawel Laszczak wrote: >> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver >> to driver/usb/gadget/debug.c file. These moved functions include: >> dwc3_decode_get_status >> dwc3_decode_set_clear_feature >> dwc3_decode_set_address >> dwc3_decode_get_set_descriptor >> dwc3_decode_get_configuration >> dwc3_decode_set_configuration >> dwc3_decode_get_intf >> dwc3_decode_set_intf >> dwc3_decode_synch_frame >> dwc3_decode_set_sel >> dwc3_decode_set_isoch_delay >> dwc3_decode_ctrl >> >> These functions are used also in inroduced cdns3 driver. >> >> All functions prefixes were changed from dwc3 to usb. >> Also, function's parameters has been extended according to the name >> of fields in standard SETUP packet. >> Additionally, patch adds usb_decode_ctrl function to >> include/linux/usb/gadget.h file. > >No it does not :( I've forgot about this :( It should be include/linux/usb/ch.9.h > >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/common/Makefile | 5 + >> drivers/usb/common/debug.c | 268 >> drivers/usb/dwc3/debug.h| 252 - >> drivers/usb/dwc3/trace.h| 2 +- >> include/linux/usb/ch9.h | 25 >> 5 files changed, 299 insertions(+), 253 deletions(-) >> create mode 100644 drivers/usb/common/debug.c >> >> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile >> index 0a7c45e85481..cdc66b59a6f0 100644 >> --- a/drivers/usb/common/Makefile >> +++ b/drivers/usb/common/Makefile >> @@ -5,6 +5,11 @@ >> >> obj-$(CONFIG_USB_COMMON) += usb-common.o >> usb-common-y += common.o >> + >> +ifneq ($(CONFIG_TRACING),) >> +usb-common-y += debug.o >> +endif > >So only enable this if tracing is not emabled? Or if enabled? I'm >confused, isn't there an easier way to write this? It's checks if CONFIG_TRACING is enable. It's a common way checking if option is enabled in usb subsystem. > >thanks, > >greg k-h
[PATCH v9 3/6] usb:gadget Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 89 ++ 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index d5a469bc67a3..60a9f70a0904 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -30,58 +30,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, -__u16 wValue, __u16 wIndex, -char *str, size_t size) +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", -({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), +usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? -({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); +usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- 2.17.1
[PATCH v9 0/6] Introduced new Cadence USBSS DRD Driver.
sue in cdns3_ep_onchip_buffer_reserve. - fixed issue with incorrect calculation the number of required on-chip buffer for OUT endpoints cdns3_ep_onchip_buffer_reserve. - fixed issue in __cdns3_gadget_init function: pm_runtime_get_sync was in incorrect place in. - removed some typos and improved comments as suggested by reviewers. - made some other minor changes as suggested by revivers. Changes since v3: - updated dt-binding as suggested by Rob Herring - updated patch 002, 003 and 004 according with patch: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git/commit/ ?h=next=7790b3556fccc555ae422f1576e97bf34c8ab8b6 posted by Felipe Balbi. - fixed issues related to isochronous transfers. - improved algorithm calculating number of on-chip buffers required by endpoints. - fixed incorrect macro EP_CFG_MULT in gadget.h file. - fixed potential issue with incorrect order of instruction - added wmb(). - made some minor changes suggested by reviewers. *Changes since v2: - made some text correction in Kconfig file as suggested by Randy Dunlap. - simplified Makefile as suggested by Peter Chan. - removed phy-names from dt-binding as suggested Rob Herring. - changed cdns3-usb.txt to cdns3-usb3.txt as suggested by Rob Herring. - added checking error code in some function in drd.c file as suggested by Peter Chan. - added reg-names to dt-binding documentation as suggested by Chunfeng Yun. - replaced platform_get_resource with platform_get_resource_byname. - made other changes suggested by Chunfeng Yun. - fixed bug in cdns3_get_id. Now function return id instead 1. - added trace_cdns3_log trace event. - simplify cdns3_disable_write function. - create separate patch for work around related with blocking endpoint issue. - Fixed issue related with stale data address in TRB. Issue: At some situations, the controller may get stale data address in TRB at below sequences: 1. Controller read TRB includes data address. 2. Software updates TRBs includes data address and Cycle bit. 3. Controller read TRB which includes Cycle bit. 4. DMA run with stale data address. - Fixed issue without transfer. In some cases not all interrupts disabled in Hard IRQ was enabled in Soft Irq. - Modified LFPS minimal U1 Exit time for controller revision 0x00024505. - Fixed issue - in some case selected endpoint was unexpectedly changed. - Fixed issue - after clearing halted endpoint transfer was not started. - Fixed issue - in some case driver send ACK instead STALL in status phase. - Fixed issues related to dequeue request. - Fixed incorrect operator in cdns3_ep_run_transfer function. Changes since v1: - Removed not implemented Suspend/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronous transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (6): dt-bindings: add binding for USBSS-DRD controller. usb:gadget Separated decoding functions from dwc3 driver. usb:gadget Patch simplify usb_decode_set_clear_feature function. usb:gadget Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver usb:cdns3 Fix for stuck packets in on-chip OUT buffer. .../devicetree/bindings/usb/cdns-usb3.txt | 45 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 18 + drivers/usb/cdns3/cdns3-pci-wrap.c| 157 + drivers/usb/cdns3/core.c | 543 drivers/usb/cdns3/core.h | 121 + drivers/usb/cdns3/debug.h | 173 ++ drivers/usb/cdns3/debugfs.c | 153 + drivers/
[PATCH v9 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handled by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. Issue has been fixed for DEV_VER_V2 version of controller. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 330 - drivers/usb/cdns3/gadget.h | 13 ++ 2 files changed, 341 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 4e9e8e43f634..63cde269db98 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -28,6 +28,32 @@ * * Issue has been fixed in DEV_VER_V3 version of controller. * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS3_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * Issue has been fixed in DEV_VER_V2 version of controller. + * */ #include @@ -98,6 +124,17 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -335,6 +372,246 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/* + * WA2: Set flag for all not ISOC OUT endpoints. If this flag is set + * driver try to detect whether endpoint need additional internal + * buffer for unblocking on-chip FIFO buffer. This flag will be cleared + * if before first DESCMISS interrupt the DMA will be armed. + */ +#define cdns3_wa2_enable_detection(priv_dev, ep_priv, reg) do { \ + if (!priv_ep->dir && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { \ + priv_ep->flags |= EP_QUIRK_EXTRA_BUF_DET; \ + (reg) |= EP_STS_EN_DESCMISEN; \ + } } while (0) + +/** + * cdns3_wa2_descmiss_copy_data copy data from internal requests to + * request queued by class driver. + * @priv_ep: extended endpoint object + * @request: request object + */ +static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, +struct usb_request *request) +{ + struct usb_request *descmiss_req; + struct cdns3_request *descmiss_priv_req; + + while (!list_empty(_ep->wa2_descmiss_req_list)) { + int chunk_end; + int length; + + descmiss_priv_req = + cdns3_next_priv_request(_ep->wa2_descmiss_req_list); + descmiss_req = _priv_req->request; + + /* driver c
[PATCH v9 4/6] usb:gadget Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 113 +++-- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index 60a9f70a0904..92a986aeaa5d 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -105,62 +105,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", -bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", -({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; -
[PATCH v9 1/6] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak Reviewed-by: Rob Herring --- .../devicetree/bindings/usb/cdns-usb3.txt | 45 +++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index ..b7dc606d37b5 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,45 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +- HOST registers area +- DEVICE registers area +- OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3" + - interrupts: Interrupts used by cdns3 controller: + "host" - interrupt used by XHCI driver. + "peripheral" - interrupt used by device driver + "otg" - interrupt used by DRD/OTG part of driver + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + - phy-names: from the *Generic PHY* bindings; + Supported names are: + - cdns3,usb2-phy + - cdns3,usb3-phy + + - cdns,on-chip-buff-size : size of memory intended as internal memory for endpoints + buffers expressed in KB + +Example: + usb@f300 { + compatible = "cdns,usb3"; + interrupts = , + , + ; + interrupt-names = "host", "peripheral", "otg"; + reg = <0xf300 0x1>, /* memory area for HOST registers */ + <0xf301 0x1>, /* memory area for DEVICE registers */ + <0xf302 0x1>; /* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + phys = <_phy>, <_phy>; + phy-names = "cdns3,usb2-phy", "cnds3,usb3-phy"; + }; -- 2.17.1
[PATCH v9 2/6] usb:gadget Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/gadget/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/gadget.h file. Signed-off-by: Pawel Laszczak --- drivers/usb/common/Makefile | 5 + drivers/usb/common/debug.c | 268 drivers/usb/dwc3/debug.h| 252 - drivers/usb/dwc3/trace.h| 2 +- include/linux/usb/ch9.h | 25 5 files changed, 299 insertions(+), 253 deletions(-) create mode 100644 drivers/usb/common/debug.c diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index 0a7c45e85481..cdc66b59a6f0 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile @@ -5,6 +5,11 @@ obj-$(CONFIG_USB_COMMON) += usb-common.o usb-common-y += common.o + +ifneq ($(CONFIG_TRACING),) + usb-common-y += debug.o +endif + usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c new file mode 100644 index ..d5a469bc67a3 --- /dev/null +++ b/drivers/usb/common/debug.c @@ -0,0 +1,268 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "Get Device Status(Length = %d)", wLength); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, +"Get Interface Status(Intf = %d, Length = %d)", +wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "Get Endpoint Status(ep%d%s)", +wIndex & ~USB_DIR_IN, +wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, +__u16 wValue, __u16 wIndex, +char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "%s Device Feature(%s%s)", +bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", +({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), +wValue == USB_DEVICE_TEST_MODE ? +({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; +
RE: linux-next: build failure after merge of the usb and usb-gadget trees
Hi, > >Hi, > >Greg KH writes: > >> On Thu, Jul 04, 2019 at 12:44:08PM +0300, Felipe Balbi wrote: >>> >>> Hi, >>> >>> Pawel Laszczak writes: >>> >>> >> >>> >> >>> >>Hi, >>> >> >>> >>Pawel Laszczak writes: >>> >> >>> >>>> >>> >>>>Hi, >>> >>>> >>> >>>>On Thu, Jul 4, 2019 at 9:59 AM Greg KH wrote: >>> >>>>> >>> >>>>> On Thu, Jul 04, 2019 at 04:34:58PM +1000, Stephen Rothwell wrote: >>> >>>>> > Hi all, >>> >>>>> > >>> >>>>> > After merging the usb tree, today's linux-next build (arm >>> >>>>> > multi_v7_defconfig) failed like this: >>> >>>>> > >>> >>>>> > arm-linux-gnueabi-ld: drivers/usb/dwc3/trace.o: in function >>> >>>>> > `trace_raw_output_dwc3_log_ctrl': >>> >>>>> > trace.c:(.text+0x119c): undefined reference to `usb_decode_ctrl' >>> >>>>> > >>> >>>>> > Caused by commit >>> >>>>> > >>> >>>>> > 3db1b636c07e ("usb:gadget Separated decoding functions from dwc3 >>> >>>>> > driver.") >>> >>>>> > >>> >>>>> > I have used the usb tree from next-20190703 for today. >>> >>>>> > >>> >>>>> > This also occurs in the usb-gadget tree so I have used the version >>> >>>>> > of >>> >>>>> > that from next-20190703 as well. >>> >>>>> >>> >>>>> Odd, I thought I pulled the usb-gadget tree into mine. Felipe, can >>> >>>>> you >>> >>>>> take a look at this to see if I messed something up? >>> >>>> >>> >>>>This looks like it was caused by Pawel's patches. >>> >>>> >>> >>>>I'll try to reproduce here and see what's causing it. >>> >>> >>> >>> Problem is in my Patch. I reproduced it, but I don't understand why >>> >>> compiler >>> >>> complains about usb_decode_ctrl. It's compiled into libcomposite.ko and >>> >>> declaration is in drivers/usb/gadget.h. >>> >> >>> >>That's because in multi_v7_defconfig dwc3 is built-in while libcomposite >>> >>is a module: >>> >> >>> >>CONFIG_USB_DWC3=y >>> >>CONFIG_USB_LIBCOMPOSITE=m >>> >> >>> >> >>> >>I remember that when you were doing this work, I asked you to move >>> >>functions to usb/common. Why did you deviate from that suggestion? It's >>> >>clear that decoding a ctrl request can be used by peripheral and host >>> >>and we wouldn't have to deal with this problem if you had just followed >>> >>the suggestion. >>> > >>> > Some time ago Greg wrote: >>> > " It's nice to have these in a common place, but you just bloated all of >>> > the USB-enabled systems in the world for the use of 2 odd-ball system >>> > controllers that almost no one has :) " >>> > >>> > So I moved these functions to gadget directory. >>> > >>> > It was mistake that I added debug.c file to libcomposite.ko. >>> >>> The plan is to use this decoding function for xHCI as well. Other host >>> controllers can use it as well. >>> >>> The biggest mistake was to put this under gadget. What you should have >>> done was create a file under usb/common that only gets compile in if >>> tracing is enabled. >>> >>> Then there's no bloating unless you have a kernel purposefuly built for >>> debugging and tracing. >>> >>> Greg, does that work for you? >> >> I guess, but I'd like to see patches before answering that :) > >Sure, understandable. I should've done a better job at filtering that >out. Sorry about htat I will return debug.c again to usb/common directory. I made it as suggested by Felipe. I will try correct this patches on Monday. I apologize for my mistake and for wasting your time. Regards, Pawel.
RE: linux-next: build failure after merge of the usb and usb-gadget trees
>> >> >>Hi, >> >>Pawel Laszczak writes: >> >>>> >>>>Hi, >>>> >>>>On Thu, Jul 4, 2019 at 9:59 AM Greg KH wrote: >>>>> >>>>> On Thu, Jul 04, 2019 at 04:34:58PM +1000, Stephen Rothwell wrote: >>>>> > Hi all, >>>>> > >>>>> > After merging the usb tree, today's linux-next build (arm >>>>> > multi_v7_defconfig) failed like this: >>>>> > >>>>> > arm-linux-gnueabi-ld: drivers/usb/dwc3/trace.o: in function >>>>> > `trace_raw_output_dwc3_log_ctrl': >>>>> > trace.c:(.text+0x119c): undefined reference to `usb_decode_ctrl' >>>>> > >>>>> > Caused by commit >>>>> > >>>>> > 3db1b636c07e ("usb:gadget Separated decoding functions from dwc3 >>>>> > driver.") >>>>> > >>>>> > I have used the usb tree from next-20190703 for today. >>>>> > >>>>> > This also occurs in the usb-gadget tree so I have used the version of >>>>> > that from next-20190703 as well. >>>>> >>>>> Odd, I thought I pulled the usb-gadget tree into mine. Felipe, can you >>>>> take a look at this to see if I messed something up? >>>> >>>>This looks like it was caused by Pawel's patches. >>>> >>>>I'll try to reproduce here and see what's causing it. >>> >>> Problem is in my Patch. I reproduced it, but I don't understand why compiler >>> complains about usb_decode_ctrl. It's compiled into libcomposite.ko and >>> declaration is in drivers/usb/gadget.h. >> >>That's because in multi_v7_defconfig dwc3 is built-in while libcomposite >>is a module: >> >>CONFIG_USB_DWC3=y >>CONFIG_USB_LIBCOMPOSITE=m >> >> >>I remember that when you were doing this work, I asked you to move >>functions to usb/common. Why did you deviate from that suggestion? It's >>clear that decoding a ctrl request can be used by peripheral and host >>and we wouldn't have to deal with this problem if you had just followed >>the suggestion. > >Some time ago Greg wrote: >" It's nice to have these in a common place, but you just bloated all of >the USB-enabled systems in the world for the use of 2 odd-ball system >controllers that almost no one has :) " > >So I moved these functions to gadget directory. > >It was mistake that I added debug.c file to libcomposite.ko. > I think that the best choice is leaving debug.c file In drivers/usb/gadget/ directory. But to do this I must to add this file to drivers/usb/dwc3/Makefile file and drivers/usb/cdns3/Makefile. The code will be compiled into both drivers, It will increase the size of kernel only when these driver will be enabled. What do you think about such solution ? >> >>Now we have to come up with a way to fix this that doesn't involve >>reverting my part2 tag in its entirety because there are other important >>things there. >> >>This is what I get for trusting people to do their part. I couldn't even >>compile test this since I don't have ARM compilers anymore (actually, >>just installed to test). Your customer, however, uses ARM cores so I >>would expect you to have at least compile tested this on ARM. How come >>this wasn't verified by anybody at TI? >> >>TI used to have automated testing for many of the important defconfigs, >>is that completely gone? Are you guys relying entirely on linux-next? >> >>Greg, if you prefer, please revert my part2 tag. If you do so, please >>let me know so I can drop the tag and commits from my tree as well. >> >>Pawel, please make sure this never happens again. It's pretty simple to >>avoid this sort of thing. I'll keep ARM compiler installed for >>build-testing as well. >> >>-- >>balbi
RE: linux-next: build failure after merge of the usb and usb-gadget trees
> > >Hi, > >Pawel Laszczak writes: > >>> >>>Hi, >>> >>>On Thu, Jul 4, 2019 at 9:59 AM Greg KH wrote: >>>> >>>> On Thu, Jul 04, 2019 at 04:34:58PM +1000, Stephen Rothwell wrote: >>>> > Hi all, >>>> > >>>> > After merging the usb tree, today's linux-next build (arm >>>> > multi_v7_defconfig) failed like this: >>>> > >>>> > arm-linux-gnueabi-ld: drivers/usb/dwc3/trace.o: in function >>>> > `trace_raw_output_dwc3_log_ctrl': >>>> > trace.c:(.text+0x119c): undefined reference to `usb_decode_ctrl' >>>> > >>>> > Caused by commit >>>> > >>>> > 3db1b636c07e ("usb:gadget Separated decoding functions from dwc3 >>>> > driver.") >>>> > >>>> > I have used the usb tree from next-20190703 for today. >>>> > >>>> > This also occurs in the usb-gadget tree so I have used the version of >>>> > that from next-20190703 as well. >>>> >>>> Odd, I thought I pulled the usb-gadget tree into mine. Felipe, can you >>>> take a look at this to see if I messed something up? >>> >>>This looks like it was caused by Pawel's patches. >>> >>>I'll try to reproduce here and see what's causing it. >> >> Problem is in my Patch. I reproduced it, but I don't understand why compiler >> complains about usb_decode_ctrl. It's compiled into libcomposite.ko and >> declaration is in drivers/usb/gadget.h. > >That's because in multi_v7_defconfig dwc3 is built-in while libcomposite >is a module: > >CONFIG_USB_DWC3=y >CONFIG_USB_LIBCOMPOSITE=m > > >I remember that when you were doing this work, I asked you to move >functions to usb/common. Why did you deviate from that suggestion? It's >clear that decoding a ctrl request can be used by peripheral and host >and we wouldn't have to deal with this problem if you had just followed >the suggestion. Some time ago Greg wrote: " It's nice to have these in a common place, but you just bloated all of the USB-enabled systems in the world for the use of 2 odd-ball system controllers that almost no one has :) " So I moved these functions to gadget directory. It was mistake that I added debug.c file to libcomposite.ko. > >Now we have to come up with a way to fix this that doesn't involve >reverting my part2 tag in its entirety because there are other important >things there. > >This is what I get for trusting people to do their part. I couldn't even >compile test this since I don't have ARM compilers anymore (actually, >just installed to test). Your customer, however, uses ARM cores so I >would expect you to have at least compile tested this on ARM. How come >this wasn't verified by anybody at TI? > >TI used to have automated testing for many of the important defconfigs, >is that completely gone? Are you guys relying entirely on linux-next? > >Greg, if you prefer, please revert my part2 tag. If you do so, please >let me know so I can drop the tag and commits from my tree as well. > >Pawel, please make sure this never happens again. It's pretty simple to >avoid this sort of thing. I'll keep ARM compiler installed for >build-testing as well. > >-- >balbi
RE: linux-next: build failure after merge of the usb and usb-gadget trees
> >Hi, > >On Thu, Jul 4, 2019 at 9:59 AM Greg KH wrote: >> >> On Thu, Jul 04, 2019 at 04:34:58PM +1000, Stephen Rothwell wrote: >> > Hi all, >> > >> > After merging the usb tree, today's linux-next build (arm >> > multi_v7_defconfig) failed like this: >> > >> > arm-linux-gnueabi-ld: drivers/usb/dwc3/trace.o: in function >> > `trace_raw_output_dwc3_log_ctrl': >> > trace.c:(.text+0x119c): undefined reference to `usb_decode_ctrl' >> > >> > Caused by commit >> > >> > 3db1b636c07e ("usb:gadget Separated decoding functions from dwc3 >> > driver.") >> > >> > I have used the usb tree from next-20190703 for today. >> > >> > This also occurs in the usb-gadget tree so I have used the version of >> > that from next-20190703 as well. >> >> Odd, I thought I pulled the usb-gadget tree into mine. Felipe, can you >> take a look at this to see if I messed something up? > >This looks like it was caused by Pawel's patches. > >I'll try to reproduce here and see what's causing it. Problem is in my Patch. I reproduced it, but I don't understand why compiler complains about usb_decode_ctrl. It's compiled into libcomposite.ko and declaration is in drivers/usb/gadget.h. > >-- >balbi
[PATCH v8 4/6] usb:gadget Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak --- drivers/usb/gadget/debug.c | 113 +++-- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index 60a9f70a0904..92a986aeaa5d 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -105,62 +105,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", -bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", -({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; -
[PATCH v8 2/6] usb:gadget Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/gadget/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/gadget.h file. Signed-off-by: Pawel Laszczak --- drivers/usb/dwc3/debug.h| 252 - drivers/usb/dwc3/trace.h| 2 +- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/debug.c | 268 include/linux/usb/gadget.h | 26 5 files changed, 296 insertions(+), 253 deletions(-) create mode 100644 drivers/usb/gadget/debug.c diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 068259fdfb0c..9baabed87d61 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -246,258 +246,6 @@ static inline const char *dwc3_gadget_event_string(char *str, size_t size, return str; } -static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str, - size_t size) -{ - switch (t & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "Get Device Status(Length = %d)", l); - break; - case USB_RECIP_INTERFACE: - snprintf(str, size, "Get Interface Status(Intf = %d, Length = %d)", - i, l); - break; - case USB_RECIP_ENDPOINT: - snprintf(str, size, "Get Endpoint Status(ep%d%s)", - i & ~USB_DIR_IN, - i & USB_DIR_IN ? "in" : "out"); - break; - } -} - -static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v, - __u16 i, char *str, size_t size) -{ - switch (t & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - snprintf(str, size, "%s Device Feature(%s%s)", - b == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (v) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), - v == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (i) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s;
[PATCH v8 0/6] Introduced new Cadence USBSS DRD Driver.
ace in. - removed some typos and improved comments as suggested by reviewers. - made some other minor changes as suggested by revivers. Changes since v3: - updated dt-binding as suggested by Rob Herring - updated patch 002, 003 and 004 according with patch: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git/commit/ ?h=next=7790b3556fccc555ae422f1576e97bf34c8ab8b6 posted by Felipe Balbi. - fixed issues related to isochronous transfers. - improved algorithm calculating number of on-chip buffers required by endpoints. - fixed incorrect macro EP_CFG_MULT in gadget.h file. - fixed potential issue with incorrect order of instruction - added wmb(). - made some minor changes suggested by reviewers. *Changes since v2: - made some text correction in Kconfig file as suggested by Randy Dunlap. - simplified Makefile as suggested by Peter Chan. - removed phy-names from dt-binding as suggested Rob Herring. - changed cdns3-usb.txt to cdns3-usb3.txt as suggested by Rob Herring. - added checking error code in some function in drd.c file as suggested by Peter Chan. - added reg-names to dt-binding documentation as suggested by Chunfeng Yun. - replaced platform_get_resource with platform_get_resource_byname. - made other changes suggested by Chunfeng Yun. - fixed bug in cdns3_get_id. Now function return id instead 1. - added trace_cdns3_log trace event. - simplify cdns3_disable_write function. - create separate patch for work around related with blocking endpoint issue. - Fixed issue related with stale data address in TRB. Issue: At some situations, the controller may get stale data address in TRB at below sequences: 1. Controller read TRB includes data address. 2. Software updates TRBs includes data address and Cycle bit. 3. Controller read TRB which includes Cycle bit. 4. DMA run with stale data address. - Fixed issue without transfer. In some cases not all interrupts disabled in Hard IRQ was enabled in Soft Irq. - Modified LFPS minimal U1 Exit time for controller revision 0x00024505. - Fixed issue - in some case selected endpoint was unexpectedly changed. - Fixed issue - after clearing halted endpoint transfer was not started. - Fixed issue - in some case driver send ACK instead STALL in status phase. - Fixed issues related to dequeue request. - Fixed incorrect operator in cdns3_ep_run_transfer function. Changes since v1: - Removed not implemented Suspend/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronous transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (6): dt-bindings: add binding for USBSS-DRD controller. usb:gadget Separated decoding functions from dwc3 driver. usb:gadget Patch simplify usb_decode_set_clear_feature function. usb:gadget Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver usb:cdns3 Fix for stuck packets in on-chip OUT buffer. .../devicetree/bindings/usb/cdns-usb3.txt | 45 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 14 + drivers/usb/cdns3/cdns3-pci-wrap.c| 157 + drivers/usb/cdns3/core.c | 543 drivers/usb/cdns3/core.h | 121 + drivers/usb/cdns3/debug.h | 173 ++ drivers/usb/cdns3/debugfs.c | 153 + drivers/usb/cdns3/drd.c | 379 +++ drivers/usb/cdns3/drd.h | 166 ++ drivers/usb/cdns3/ep0.c | 920 ++ drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadge
[PATCH v8 3/6] usb:gadget Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/gadget/debug.c | 89 ++ 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/usb/gadget/debug.c b/drivers/usb/gadget/debug.c index d5a469bc67a3..60a9f70a0904 100644 --- a/drivers/usb/gadget/debug.c +++ b/drivers/usb/gadget/debug.c @@ -30,58 +30,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, -__u16 wValue, __u16 wIndex, -char *str, size_t size) +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", -({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), +usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? -({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); +usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- 2.17.1
[PATCH v8 1/6] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak Reviewed-by: Rob Herring --- .../devicetree/bindings/usb/cdns-usb3.txt | 45 +++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index ..b7dc606d37b5 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,45 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +- HOST registers area +- DEVICE registers area +- OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3" + - interrupts: Interrupts used by cdns3 controller: + "host" - interrupt used by XHCI driver. + "peripheral" - interrupt used by device driver + "otg" - interrupt used by DRD/OTG part of driver + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + - phy-names: from the *Generic PHY* bindings; + Supported names are: + - cdns3,usb2-phy + - cdns3,usb3-phy + + - cdns,on-chip-buff-size : size of memory intended as internal memory for endpoints + buffers expressed in KB + +Example: + usb@f300 { + compatible = "cdns,usb3"; + interrupts = , + , + ; + interrupt-names = "host", "peripheral", "otg"; + reg = <0xf300 0x1>, /* memory area for HOST registers */ + <0xf301 0x1>, /* memory area for DEVICE registers */ + <0xf302 0x1>; /* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + phys = <_phy>, <_phy>; + phy-names = "cdns3,usb2-phy", "cnds3,usb3-phy"; + }; -- 2.17.1
[PATCH v8 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handled by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. Issue has been fixed for DEV_VER_V2 version of controller. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 330 - drivers/usb/cdns3/gadget.h | 13 ++ 2 files changed, 341 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 4e9e8e43f634..63cde269db98 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -28,6 +28,32 @@ * * Issue has been fixed in DEV_VER_V3 version of controller. * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS3_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * Issue has been fixed in DEV_VER_V2 version of controller. + * */ #include @@ -98,6 +124,17 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -335,6 +372,246 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/* + * WA2: Set flag for all not ISOC OUT endpoints. If this flag is set + * driver try to detect whether endpoint need additional internal + * buffer for unblocking on-chip FIFO buffer. This flag will be cleared + * if before first DESCMISS interrupt the DMA will be armed. + */ +#define cdns3_wa2_enable_detection(priv_dev, ep_priv, reg) do { \ + if (!priv_ep->dir && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { \ + priv_ep->flags |= EP_QUIRK_EXTRA_BUF_DET; \ + (reg) |= EP_STS_EN_DESCMISEN; \ + } } while (0) + +/** + * cdns3_wa2_descmiss_copy_data copy data from internal requests to + * request queued by class driver. + * @priv_ep: extended endpoint object + * @request: request object + */ +static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, +struct usb_request *request) +{ + struct usb_request *descmiss_req; + struct cdns3_request *descmiss_priv_req; + + while (!list_empty(_ep->wa2_descmiss_req_list)) { + int chunk_end; + int length; + + descmiss_priv_req = + cdns3_next_priv_request(_ep->wa2_descmiss_req_list); + descmiss_req = _priv_req->request; + + /* driver c
RE: [PATCH v7 1/6] dt-bindings: add binding for USBSS-DRD controller.
> >> - reg-names - register memory area names: >> "xhci" - for HOST registers space >> "dev" - for DEVICE registers space >> "otg" - for OTG/DRD registers space >> - compatible: Should contain: >> "cdns,usb3-1.0.0" - for 0x00024502 controller version >> "cdns,usb3-1.0.1" - for 0x00024509 controller version >> "cdns,usb3-1.0.2" - for 0x0002450C controller version >> "cdns,usb3-1.0.3" - for 0x0002450d controller version > >If the value can be read from register, why we still need different >compatibles? We don't need it. I left it only as information that cdns3 controller exist in 4 different version. > >> Example: >> usb@f300 { >> compatible = "cdns,usb3-1.0.1"; >> interrupts = , >> , >> ; >> interrupt-names = "host", "peripheral", "otg"; >> reg = <0xf300 0x1>, /* memory area for HOST >> registers */ >> <0xf301 0x1>, /* memory area for DEVICE >> registers */ >> <0xf302 0x1>; /* memory area for OTG/DRD >> registers >> */ >> reg-names = "xhci", "dev", "otg"; >> phys = <_phy>; >> phy-names = "cdns3,usbphy"; >> >> >> Maybe I should add also something for usb2_phy in dt-binding and in driver ? >> > >The PHY driver is located at: drivers/phy/cadence/phy-cadence-sierra.c. >Will we need another one for USB2 PHY? As I know sierra phy is USB3.0 phy. Also I know that we have torent phy driver for 2.0. It's ready but is has not yet in kernel. So I assume that I should change phys = <_phy>; phy-names = "cdns3,usbphy"; with: phys = <_phy>, <_phy>; phy-names = "cdns3,usbphy2", "cdns3,usbphy3"; Pawel > >Peter > > >> Thanks, >> Regards, >> Pawel >> >> >> >> >> Regards, >> >> Pawel >> >> >> >> >> >>> >> + >> +Optional properties: >> + - maximum-speed : valid arguments are "super-speed", "high-speed" and >> + "full-speed"; refer to usb/generic.txt >> + - dr_mode: Should be one of "host", "peripheral" or "otg". >> + - phys: reference to the USB PHY >> + >> +Example: >> + usb@f300 { >> + compatible = "cdns,usb3-1.0.1"; >> + interrupts = ; >> >>> >> >>> This example won't work as code requests for 3 separate interrupts. >> >>> >> + reg = <0xf300 0x1 /* memory area for HOST >> registers */ >> + 0xf301 0x1 /* memory area for >> DEVICE >> registers */ >> + 0xf302 0x1>;/* memory area for >> OTG/DRD registers */ >> + reg-names = "xhci", "dev", "otg"; >> + }; >> >> >>> >> > >> > >> >-- >> >cheers, >> >-roger >> > >> >Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. >> >Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
RE: [PATCH v7 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
>On Wed, Jun 05, 2019 at 11:03:49AM +0100, Pawel Laszczak wrote: >> diff --git a/drivers/usb/cdns3/debugfs.c b/drivers/usb/cdns3/debugfs.c >> new file mode 100644 >> index ..dfcbeb5e14f8 >> --- /dev/null >> +++ b/drivers/usb/cdns3/debugfs.c >> @@ -0,0 +1,173 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Cadence USBSS DRD Controller DebugFS filer. >> + * >> + * Copyright (C) 2018-2019 Cadence. >> + * >> + * Author: Pawel Laszczak >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> + >> +#include "core.h" >> +#include "gadget.h" >> +#include "drd.h" > >static const char *const cdns3_mode[] = { >[USB_DR_MODE_UNKNOWN] = "unknown", >[USB_DR_MODE_OTG] = "otg", >[USB_DR_MODE_HOST] = "host", >[USB_DR_MODE_PERIPHERAL]= "device", >}; > >> +static int cdns3_mode_show(struct seq_file *s, void *unused) >> +{ >> +struct cdns3 *cdns = s->private; >> + >> +switch (cdns->current_dr_mode) { >> +case USB_DR_MODE_HOST: >> +seq_puts(s, "host\n"); >> +break; >> +case USB_DR_MODE_PERIPHERAL: >> +seq_puts(s, "device\n"); >> +break; >> +case USB_DR_MODE_OTG: >> +seq_puts(s, "otg\n"); >> +break; >> +default: >> +seq_puts(s, "UNKNOWN mode\n"); >> +} > >All you should need here is: > >seq_puts(s, cdns3_mode[cdns->current_dr_mode]); > >> +return 0; >> +} >> + >> +static int cdns3_mode_open(struct inode *inode, struct file *file) >> +{ >> +return single_open(file, cdns3_mode_show, inode->i_private); >> +} >> + >> +static ssize_t cdns3_mode_write(struct file *file, >> +const char __user *ubuf, >> +size_t count, loff_t *ppos) >> +{ >> +struct seq_file *s = file->private_data; >> +struct cdns3 *cdns = s->private; >> +u32 mode = USB_DR_MODE_UNKNOWN; >> +char buf[32]; >> +int ret = 0; > >int ret; > >> +if (copy_from_user(, ubuf, min_t(size_t, sizeof(buf) - 1, count))) >> +return -EFAULT; > >return -EINVAL; Why? I've checked in some place in kernel and after copy_from_user are used EFAULT. I think that EINVAL is better but I wanted be consistent with the rest of kernel. Is there any explanation for this ? > >> + >> +if (cdns->debug_disable) { >> +dev_err(cdns->dev, >> +"Mode can't be changed when disable is set\n"); >> +return -EFAULT; > >return -EPERM; > >> +} >> + >> +if (!strncmp(buf, "host", 4)) { >> +if (cdns->dr_mode == USB_DR_MODE_HOST || >> +cdns->dr_mode == USB_DR_MODE_OTG) { >> +mode = USB_DR_MODE_HOST; >> +} >> +} >> + >> +if (!strncmp(buf, "device", 6)) >> +if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL || >> +cdns->dr_mode == USB_DR_MODE_OTG) >> +mode = USB_DR_MODE_PERIPHERAL; >> + >> +if (!strncmp(buf, "otg", 3) && cdns->dr_mode == USB_DR_MODE_OTG) >> +mode = USB_DR_MODE_OTG; >> + >> +if (mode == USB_DR_MODE_UNKNOWN) { >> +dev_err(cdns->dev, "Failed: incorrect mode setting\n"); >> +return -EFAULT; >> +} > >To cover all those, you just need to: > >ret = match_string(cdns3_mode, ARRAY_SIZE(cdns3_mode), buf)); >if (ret < 0 || ret == USB_DR_MODE_UNKNOWN) >return -EINVAL; > >> +if (cdns->current_dr_mode != mode) { >> +cdns->desired_dr_mode = mode; > >if (cdns->current_dr_mode != ret) > cdns->desired_dr_mode = ret; > >> +cdns3_role_stop(cdns); >> +ret = cdns3_drd_update_mode(cdns); >> +if (ret) >> +return ret; >> + >> +queue_work(system_freezable_wq, >role_switch_wq); >> +} >> + >> +return count; >> +} >> + >> +static const struct file_operations cdns3_mode_fops = { &
RE: [PATCH v7 2/6] usb:common Separated decoding functions from dwc3 driver.
>On Wed, Jun 05, 2019 at 11:03:46AM +0100, Pawel Laszczak wrote: > >> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver > >> to driver/usb/common/debug.c file. These moved functions include: > >> dwc3_decode_get_status > >> dwc3_decode_set_clear_feature > >> dwc3_decode_set_address > >> dwc3_decode_get_set_descriptor > >> dwc3_decode_get_configuration > >> dwc3_decode_set_configuration > >> dwc3_decode_get_intf > >> dwc3_decode_set_intf > >> dwc3_decode_synch_frame > >> dwc3_decode_set_sel > >> dwc3_decode_set_isoch_delay > >> dwc3_decode_ctrl > >> > >> These functions are used also in inroduced cdns3 driver. > >> > >> All functions prefixes were changed from dwc3 to usb. > >> Also, function's parameters has been extended according to the name > >> of fields in standard SETUP packet. > >> Additionally, patch adds usb_decode_ctrl function to > >> include/linux/usb/ch9.h file.i > >> > >> Signed-off-by: Pawel Laszczak > >> --- > >> drivers/usb/common/Makefile | 2 +- > >> drivers/usb/common/debug.c | 273 > >> drivers/usb/dwc3/debug.h| 252 - > >> drivers/usb/dwc3/trace.h| 2 +- > >> include/linux/usb/ch9.h | 25 > >> 5 files changed, 300 insertions(+), 254 deletions(-) > >> create mode 100644 drivers/usb/common/debug.c > >> > >> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile > >> index 0a7c45e85481..02eb01666289 100644 > >> --- a/drivers/usb/common/Makefile > >> +++ b/drivers/usb/common/Makefile > >> @@ -4,7 +4,7 @@ > >> # > >> > >> obj-$(CONFIG_USB_COMMON) += usb-common.o > >> -usb-common-y += common.o > >> +usb-common-y += common.o debug.o > >> usb-common-$(CONFIG_USB_LED_TRIG) += led.o > >> > >> obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o > >> diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c > >> new file mode 100644 > >> index ..f7218d794aa6 > >> --- /dev/null > >> +++ b/drivers/usb/common/debug.c > >> @@ -0,0 +1,273 @@ > >> +// SPDX-License-Identifier: GPL-2.0 > >> +/** > >> + * Common USB debugging functions > >> + * > >> + * Copyright (C) 2010-2011 Texas Instruments Incorporated - >> https://urldefense.proofpoint.com/v2/url?u=http- >3A__www.ti.com=DwIBAg=aUq983L2pue2FqKFoP6PGHMJQyoJ7kl3s3GZ-_haXqY=e1OgxfvkL0qo9XO6fX1gscva- >w03uSYC1nIyxl89-rI=hCAftKt20FnC6KiCwNbVrg7WoY-WnCtUjVuast3iJSw=Q4qhFXl4s1P2u0s65WgkulIRgV4KZtGphj7Xjr4t6yA= > >> + * > >> + * Authors: Felipe Balbi , > >> + * Sebastian Andrzej Siewior > >> + */ > >> + > >> +#ifndef __LINUX_USB_COMMON_DEBUG > >> +#define __LINUX_USB_COMMON_DEBUG > > > >Why are you doing thsi in a .c file? > Good question, I don't know :). Was removed Also I remember that you complained about placing it in drivers/usb/common. Currently this file is used only by two drivers dwc3 and cdns3. Both are USB controller drivers. Maybe it could be better to move it to: drivers/gadget/udc/debug.c drivers/gadget/debug.c drivers/gadget/common/debug.c or drivers/gadget/debug/debug.c What do you think Roger? Felipe it's also question for you. Thanks, Pawel > > >thanks, > > > >greg k-h
RE: [PATCH v7 1/6] dt-bindings: add binding for USBSS-DRD controller.
>> >>> >>> Pawel, >>> >>> On 05/06/2019 13:03, Pawel Laszczak wrote: >>>> This patch aim at documenting USB related dt-bindings for the >>>> Cadence USBSS-DRD controller. >>>> >>>> Signed-off-by: Pawel Laszczak >>>> Reviewed-by: Rob Herring >>>> >>>> --- >>>> .../devicetree/bindings/usb/cdns-usb3.txt | 30 +++ >>>> 1 file changed, 30 insertions(+) >>>> create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt >>>> >>>> diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt >>>> b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >>>> new file mode 100644 >>>> index ..1d2b449e3cb4 >>>> --- /dev/null >>>> +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >>>> @@ -0,0 +1,30 @@ >>>> +Binding for the Cadence USBSS-DRD controller >>>> + >>>> +Required properties: >>>> + - reg: Physical base address and size of the controller's register >>>> areas. >>>> + Controller has 3 different regions: >>>> + region 1 - HOST registers area >>>> + region 2 - DEVICE registers area >>>> + region 3 - OTG/DRD registers area >>>> + - reg-names - register memory area names: >>>> + "xhci" - for HOST registers space >>>> + "dev" - for DEVICE registers space >>>> + "otg" - for OTG/DRD registers space >>>> + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" >>>> + - interrupts: Interrupts used by cdns3 controller. >>> >>> Since we are requesting 3 separate named interrupts in code we need to >>> mention them here. >> >> Hi Roger, >> >> Yes, I know, but this code is Reviewed-by: Rob Herring, so I thought to add >> this as separate patch after putting this driver into kernel. >> > >Binding document should be updated as code changes. > >> I assume that after making some change in this file I should remove statement >> Reviewed-by: Rob Herring from this patch to start reviving >> from the beginning. > >Yes. > >> >> What do you think about such dt-binding: >> >> Required properties: >> - reg: Physical base address and size of the controller's register areas. >> Controller has 3 different regions: >> region 1 - HOST registers area >> region 2 - DEVICE registers area >> region 3 - OTG/DRD registers area > >Is it so that region 1 is always HOST? >offset 0 seems to be OTG though. > >If it is implementation specific then you could get rid of numbering. Right, I rid of numbering. > >> - reg-names - register memory area names: >> "xhci" - for HOST registers space >> "dev" - for DEVICE registers space >> "otg" - for OTG/DRD registers space >> - compatible: Should contain: >> "cdns,usb3-1.0.0" - for 0x00024502 controller version >> "cdns,usb3-1.0.1" - for 0x00024509 controller version >> "cdns,usb3-1.0.2" - for 0x0002450C controller version >> "cdns,usb3-1.0.3" - for 0x0002450d controller version >> >> - interrupts: Interrupts used by cdns3 controller: >> "host" - interrupt used by XHCI driver. >> "peripheral" - interrupt used by device driver >> "otg" - interrupt used by DRD/OTG part of driver >> >> Optional properties: >> - maximum-speed : valid arguments are "super-speed", "high-speed" and >>"full-speed"; refer to usb/generic.txt >> - dr_mode: Should be one of "host", "peripheral" or "otg". >> - phys: reference to the USB PHY > >need to add 'phy-names' since you request the PHY with name. > >> - on-chip-buff-size : size of memory intended as internal memory for >> endpoints >> buffers expressed in KB >> >> Example: >> usb@f300 { >> compatible = "cdns,usb3-1.0.1"; >> interrupts = > >coma missing. >> >here too. >> ; > >What is 7 and 8 ? Interrupt line number. As I remember device and host are connected to the same interrupt line. I'm not sure but first
RE: [PATCH v7 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> >On 05/06/2019 13:03, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver to Linux kernel. >> >> The Cadence USBSS DRD Driver is a highly configurable IP Core which >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >> The current driver has been validated with FPGA platform. We have >> support for PCIe bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliant with XHCI >> specification, so it works with standard XHCI Linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 14 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 157 ++ >> drivers/usb/cdns3/core.c | 529 +++ >> drivers/usb/cdns3/core.h | 121 ++ >> drivers/usb/cdns3/debug.h | 173 +++ >> drivers/usb/cdns3/debugfs.c| 173 +++ >> drivers/usb/cdns3/drd.c| 379 + >> drivers/usb/cdns3/drd.h| 166 ++ >> drivers/usb/cdns3/ep0.c| 915 +++ >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 2290 >> drivers/usb/cdns3/gadget.h | 1313 >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 76 + >> drivers/usb/cdns3/trace.c | 23 + >> drivers/usb/cdns3/trace.h | 447 ++ >> 19 files changed, 6880 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> > > > > >> +/** >> + * cdns3_probe - probe for cdns3 core device >> + * @pdev: Pointer to cdns3 core platform device >> + * >> + * Returns 0 on success otherwise negative errno >> + */ >> +static int cdns3_probe(struct platform_device *pdev) >> +{ >> +struct device *dev = >dev; >> +struct resource *res; >> +struct cdns3 *cdns; >> +void __iomem *regs; >> +int ret; >> + >> +ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); > >Are all cores supported by this driver limited to 32-bit? If not then >you need to set the mask based on compatibles? Two version: 0x00024509 and 0x0002450d support extended DMA address to 48 bits. The problem is that the 16 most significant bit indicate the segment that can be set per endpoint. We can assume that it will be constant per endpoint. All DMA memory for data buffers and for TRBs must be in this range. I think that Linux kernel (DMA subsystem) can't guarantee it. Using dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48)) not guarantee that segment part will be always the same. So the safest way is to limit DMA range to 32 bits. > Regards, Pawel
RE: [PATCH v7 1/6] dt-bindings: add binding for USBSS-DRD controller.
> >Pawel, > >On 05/06/2019 13:03, Pawel Laszczak wrote: >> This patch aim at documenting USB related dt-bindings for the >> Cadence USBSS-DRD controller. >> >> Signed-off-by: Pawel Laszczak >> Reviewed-by: Rob Herring >> >> --- >> .../devicetree/bindings/usb/cdns-usb3.txt | 30 +++ >> 1 file changed, 30 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt >> >> diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> new file mode 100644 >> index ..1d2b449e3cb4 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> @@ -0,0 +1,30 @@ >> +Binding for the Cadence USBSS-DRD controller >> + >> +Required properties: >> + - reg: Physical base address and size of the controller's register areas. >> + Controller has 3 different regions: >> + region 1 - HOST registers area >> + region 2 - DEVICE registers area >> + region 3 - OTG/DRD registers area >> + - reg-names - register memory area names: >> +"xhci" - for HOST registers space >> +"dev" - for DEVICE registers space >> +"otg" - for OTG/DRD registers space >> + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" >> + - interrupts: Interrupts used by cdns3 controller. > >Since we are requesting 3 separate named interrupts in code we need to >mention them here. Hi Roger, Yes, I know, but this code is Reviewed-by: Rob Herring, so I thought to add this as separate patch after putting this driver into kernel. I assume that after making some change in this file I should remove statement Reviewed-by: Rob Herring from this patch to start reviving from the beginning. What do you think about such dt-binding: Required properties: - reg: Physical base address and size of the controller's register areas. Controller has 3 different regions: region 1 - HOST registers area region 2 - DEVICE registers area region 3 - OTG/DRD registers area - reg-names - register memory area names: "xhci" - for HOST registers space "dev" - for DEVICE registers space "otg" - for OTG/DRD registers space - compatible: Should contain: "cdns,usb3-1.0.0" - for 0x00024502 controller version "cdns,usb3-1.0.1" - for 0x00024509 controller version "cdns,usb3-1.0.2" - for 0x0002450C controller version "cdns,usb3-1.0.3" - for 0x0002450d controller version - interrupts: Interrupts used by cdns3 controller: "host" - interrupt used by XHCI driver. "peripheral" - interrupt used by device driver "otg" - interrupt used by DRD/OTG part of driver Optional properties: - maximum-speed : valid arguments are "super-speed", "high-speed" and "full-speed"; refer to usb/generic.txt - dr_mode: Should be one of "host", "peripheral" or "otg". - phys: reference to the USB PHY - on-chip-buff-size : size of memory intended as internal memory for endpoints buffers expressed in KB Example: usb@f300 { compatible = "cdns,usb3-1.0.1"; interrupts = ; interrupt-names = "host", "peripheral", "otg"; reg = <0xf300 0x1 /* memory area for HOST registers */ 0xf301 0x1 /* memory area for DEVICE registers */ 0xf302 0x1>;/* memory area for OTG/DRD registers */ reg-names = "xhci", "dev", "otg"; }; Is this correct now ? Maybe I should add something additionally for phy ? Regards, Pawel > >> + >> +Optional properties: >> + - maximum-speed : valid arguments are "super-speed", "high-speed" and >> + "full-speed"; refer to usb/generic.txt >> + - dr_mode: Should be one of "host", "peripheral" or "otg". >> + - phys: reference to the USB PHY >> + >> +Example: >> +usb@f300 { >> +compatible = "cdns,usb3-1.0.1"; >> +interrupts = ; > >This example won't work as code requests for 3 separate interrupts. > >> +reg = <0xf300 0x1 /* memory area for HOST >> registers */ >> +0xf301 0x1 /* memory area for DEVICE >> registers */ >> +0xf302 0x1>;/* memory area for OTG/DRD >> registers */ >> +reg-names = "xhci", "dev", "otg"; >> +}; >> > >-- >cheers, >-roger > >Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. >Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
RE: [PATCH v7 0/6] Introduced new Cadence USBSS DRD Driver.
>On 6/5/2019 17:03, Pawel Laszczak wrote: >> This patch introduces new Cadence USBSS DRD driver to Linux kernel. >> >> The Cadence USBSS DRD Driver is a highly configurable IP Core which >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >The driver is not an IP Core, the hardware device is. > I remember that I had such comment in the paste. I don't know why there is "IP Core". I will change it. thanks , Pawel > >/Lars >
[PATCH v7 2/6] usb:common Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/common/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/ch9.h file.i Signed-off-by: Pawel Laszczak --- drivers/usb/common/Makefile | 2 +- drivers/usb/common/debug.c | 273 drivers/usb/dwc3/debug.h| 252 - drivers/usb/dwc3/trace.h| 2 +- include/linux/usb/ch9.h | 25 5 files changed, 300 insertions(+), 254 deletions(-) create mode 100644 drivers/usb/common/debug.c diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index 0a7c45e85481..02eb01666289 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_USB_COMMON) += usb-common.o -usb-common-y += common.o +usb-common-y += common.o debug.o usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c new file mode 100644 index ..f7218d794aa6 --- /dev/null +++ b/drivers/usb/common/debug.c @@ -0,0 +1,273 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#ifndef __LINUX_USB_COMMON_DEBUG +#define __LINUX_USB_COMMON_DEBUG + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "Get Device Status(Length = %d)", wLength); + break; + case USB_RECIP_INTERFACE: + snprintf(str, size, +"Get Interface Status(Intf = %d, Length = %d)", +wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "Get Endpoint Status(ep%d%s)", +wIndex & ~USB_DIR_IN, +wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, +__u16 wValue, __u16 wIndex, +char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "%s Device Feature(%s%s)", +bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", +({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), +wValue == USB_DEVICE_TEST_MODE ? +({ char *s; + switch (wIndex) { + case TEST_J: +
[PATCH v7 0/6] Introduced new Cadence USBSS DRD Driver.
nor changes suggested by reviewers. *Changes since v2: - made some text correction in Kconfig file as suggested by Randy Dunlap. - simplified Makefile as suggested by Peter Chan. - removed phy-names from dt-binding as suggested Rob Herring. - changed cdns3-usb.txt to cdns3-usb3.txt as suggested by Rob Herring. - added checking error code in some function in drd.c file as suggested by Peter Chan. - added reg-names to dt-binding documentation as suggested by Chunfeng Yun. - replaced platform_get_resource with platform_get_resource_byname. - made other changes suggested by Chunfeng Yun. - fixed bug in cdns3_get_id. Now function return id instead 1. - added trace_cdns3_log trace event. - simplify cdns3_disable_write function. - create separate patch for work around related with blocking endpoint issue. - Fixed issue related with stale data address in TRB. Issue: At some situations, the controller may get stale data address in TRB at below sequences: 1. Controller read TRB includes data address. 2. Software updates TRBs includes data address and Cycle bit. 3. Controller read TRB which includes Cycle bit. 4. DMA run with stale data address. - Fixed issue without transfer. In some cases not all interrupts disabled in Hard IRQ was enabled in Soft Irq. - Modified LFPS minimal U1 Exit time for controller revision 0x00024505. - Fixed issue - in some case selected endpoint was unexpectedly changed. - Fixed issue - after clearing halted endpoint transfer was not started. - Fixed issue - in some case driver send ACK instead STALL in status phase. - Fixed issues related to dequeue request. - Fixed incorrect operator in cdns3_ep_run_transfer function. Changes since v1: - Removed not implemented Suspend/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronous transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (6): dt-bindings: add binding for USBSS-DRD controller. usb:common Separated decoding functions from dwc3 driver. usb:common Patch simplify usb_decode_set_clear_feature function. usb:common Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver usb:cdns3 Fix for stuck packets in on-chip OUT buffer. .../devicetree/bindings/usb/cdns-usb3.txt | 30 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 14 + drivers/usb/cdns3/cdns3-pci-wrap.c| 157 + drivers/usb/cdns3/core.c | 529 drivers/usb/cdns3/core.h | 121 + drivers/usb/cdns3/debug.h | 173 ++ drivers/usb/cdns3/debugfs.c | 173 ++ drivers/usb/cdns3/drd.c | 379 +++ drivers/usb/cdns3/drd.h | 166 ++ drivers/usb/cdns3/ep0.c | 915 ++ drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadget.c| 2616 + drivers/usb/cdns3/gadget.h| 1326 + drivers/usb/cdns3/host-export.h | 28 + drivers/usb/cdns3/host.c | 76 + drivers/usb/cdns3/trace.c | 23 + drivers/usb/cdns3/trace.h | 447 +++ drivers/usb/common/Makefile |2 +- drivers/usb/common/debug.c| 273 ++ drivers/usb/dwc3/debug.h | 252 -- drivers/usb/dwc3/trace.h |2 +- include/linux/usb/ch9.h | 25 + 25 files changed, 7549 insertions(+), 254 deletions(-) create m
[PATCH v7 4/6] usb:common Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 113 +++-- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index f948eb7d51b8..a858b3838764 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -108,62 +108,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", -bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", -({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; -
[PATCH v7 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handled by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. Issue has been fixed for DEV_VER_V2 version of controller. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 330 - drivers/usb/cdns3/gadget.h | 13 ++ 2 files changed, 341 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index f3b22ec43c0a..30bcf972f848 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -28,6 +28,32 @@ * * Issue has been fixed in DEV_VER_V3 version of controller. * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS3_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * Issue has been fixed in DEV_VER_V2 version of controller. + * */ #include @@ -98,6 +124,17 @@ struct cdns3_aligned_buf *cdns3_next_align_buf(struct list_head *list) return list_first_entry_or_null(list, struct cdns3_aligned_buf, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -335,6 +372,246 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/* + * WA2: Set flag for all not ISOC OUT endpoints. If this flag is set + * driver try to detect whether endpoint need additional internal + * buffer for unblocking on-chip FIFO buffer. This flag will be cleared + * if before first DESCMISS interrupt the DMA will be armed. + */ +#define cdns3_wa2_enable_detection(priv_dev, ep_priv, reg) do { \ + if (!priv_ep->dir && priv_ep->type != USB_ENDPOINT_XFER_ISOC) { \ + priv_ep->flags |= EP_QUIRK_EXTRA_BUF_DET; \ + (reg) |= EP_STS_EN_DESCMISEN; \ + } } while (0) + +/** + * cdns3_wa2_descmiss_copy_data copy data from internal requests to + * request queued by class driver. + * @priv_ep: extended endpoint object + * @request: request object + */ +static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, +struct usb_request *request) +{ + struct usb_request *descmiss_req; + struct cdns3_request *descmiss_priv_req; + + while (!list_empty(_ep->wa2_descmiss_req_list)) { + int chunk_end; + int length; + + descmiss_priv_req = + cdns3_next_priv_request(_ep->wa2_descmiss_req_list); + descmiss_req = _priv_req->request; + + /* driver c
[PATCH v7 1/6] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak Reviewed-by: Rob Herring --- .../devicetree/bindings/usb/cdns-usb3.txt | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index ..1d2b449e3cb4 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,30 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +region 1 - HOST registers area +region 2 - DEVICE registers area +region 3 - OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" + - interrupts: Interrupts used by cdns3 controller. + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + +Example: + usb@f300 { + compatible = "cdns,usb3-1.0.1"; + interrupts = ; + reg = <0xf300 0x1 /* memory area for HOST registers */ + 0xf301 0x1 /* memory area for DEVICE registers */ + 0xf302 0x1>;/* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + }; -- 2.17.1
[PATCH v7 3/6] usb:common Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 89 ++ 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index f7218d794aa6..f948eb7d51b8 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -33,58 +33,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, -__u16 wValue, __u16 wIndex, -char *str, size_t size) +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", -({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), +usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? -({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); +usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- 2.17.1
RE: [PATCH v6 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
>>> On 10/04/19 1:18 PM, Pawel Laszczak wrote: >>>> +static void cdns3_wa1_tray_restore_cycle_bit(struct cdns3_device >>>> *priv_dev, >>>> + struct cdns3_endpoint *priv_ep) >>>> +{ >>>> + int dma_index; >>>> + u32 doorbell; >>>> + >>>> + doorbell = !!(readl(_dev->regs->ep_cmd) & EP_CMD_DRDY); >>> >>>> + dma_index = (readl(_dev->regs->ep_traddr) - >>>> + priv_ep->trb_pool_dma) / TRB_SIZE; >>> >>> This gets upgraded to 64-bit by 64-bit division whenever dma_addr_t is >>> 64-bit. That should be avoided. Following diff should fix it. >>> But please review the logic itself. You are subtracting a 64 bit entity >>>from a 32-bit entity. What is guaranteeing that priv_ep->trb_pool_dma is >>> 32-bit? >>> >>> There is one more instance of same issue in cdns3_request_handled(). >>> >>> Thanks, >>> Sekhar >>> >>> [1] >>> diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c >>> index bfd5dbf40c7e..e73b618501fb 100644 >>> --- a/drivers/usb/cdns3/gadget.c >>> +++ b/drivers/usb/cdns3/gadget.c >>> @@ -749,8 +749,8 @@ static void cdns3_wa1_tray_restore_cycle_bit(struct >>> cdns3_device *priv_dev, >>> u32 doorbell; >>> >>> doorbell = !!(readl(_dev->regs->ep_cmd) & EP_CMD_DRDY); >>> - dma_index = (readl(_dev->regs->ep_traddr) - >>> - priv_ep->trb_pool_dma) / TRB_SIZE; >>> + dma_index = readl(_dev->regs->ep_traddr) - priv_ep->trb_pool_dma; >>> + dma_index /= TRB_SIZE; >> >> Hi Sekhar, >> >> In the next latest version I added setting dma and coherent mask to 32-bits >> as suggested by Roger. >> Controller can do only 32-bit access. > >I think this should work for now except if in some future version of >controller the limitation of 32-bit access is fixed. I guess that might >mean different logic for DMA handling anyway. I now about new register that allows to set the segment address and extend the address to 48 bit, but it rather will not be used on Linux. By means of this register we can set the same segment memory for all area of DMA memory. I'm not sure if Linux allow to configure dma and coherent mask in this way. But ok, I will add this fix. Pawel, > >> DMA address space should be allocated from first 32 bits of address space. >> Most significant 32-bit >> of priv_ep->trb_pool_dma should be zeroed, so I do not assume any issue in >> this place. >> >> Have you seen any issue with this on your platform ? > >build fails with > >ERROR: "__aeabi_uldivmod" [drivers/usb/cdns3/cdns3.ko] undefined! > >on 32-bit platforms with ARM LPAE enabled. So please roll in the fix I >suggested. > >Thanks, >Sekhar
RE: [PATCH v6 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
> >On 10/04/19 1:18 PM, Pawel Laszczak wrote: >> +static void cdns3_wa1_tray_restore_cycle_bit(struct cdns3_device *priv_dev, >> + struct cdns3_endpoint *priv_ep) >> +{ >> +int dma_index; >> +u32 doorbell; >> + >> +doorbell = !!(readl(_dev->regs->ep_cmd) & EP_CMD_DRDY); > >> +dma_index = (readl(_dev->regs->ep_traddr) - >> +priv_ep->trb_pool_dma) / TRB_SIZE; > >This gets upgraded to 64-bit by 64-bit division whenever dma_addr_t is >64-bit. That should be avoided. Following diff should fix it. >But please review the logic itself. You are subtracting a 64 bit entity >from a 32-bit entity. What is guaranteeing that priv_ep->trb_pool_dma is >32-bit? > >There is one more instance of same issue in cdns3_request_handled(). > >Thanks, >Sekhar > >[1] >diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c >index bfd5dbf40c7e..e73b618501fb 100644 >--- a/drivers/usb/cdns3/gadget.c >+++ b/drivers/usb/cdns3/gadget.c >@@ -749,8 +749,8 @@ static void cdns3_wa1_tray_restore_cycle_bit(struct >cdns3_device *priv_dev, > u32 doorbell; > > doorbell = !!(readl(_dev->regs->ep_cmd) & EP_CMD_DRDY); >- dma_index = (readl(_dev->regs->ep_traddr) - >- priv_ep->trb_pool_dma) / TRB_SIZE; >+ dma_index = readl(_dev->regs->ep_traddr) - priv_ep->trb_pool_dma; >+ dma_index /= TRB_SIZE; Hi Sekhar, In the next latest version I added setting dma and coherent mask to 32-bits as suggested by Roger. Controller can do only 32-bit access. DMA address space should be allocated from first 32 bits of address space. Most significant 32-bit of priv_ep->trb_pool_dma should be zeroed, so I do not assume any issue in this place. Have you seen any issue with this on your platform ? Thanks, Pawel,
RE: [PATCH v4 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Hi, >Hi, > >On 21/02/2019 09:14, Felipe Balbi wrote: >> >> Hi, >> >> (please break your emails at 80-columns) >> >> Pawel Laszczak writes: >>>>> One more thing. Workaround has implemented algorithm that decide for which >>>>> endpoint it should be enabled. e.g for composite device MSC+NCM+ACM it >>>>> should work only for ACM OUT endpoint. >>>>> >>>> >>>> If ACM driver didn't queue the request for ACM OUT endpoint, why does the >>>> controller accept the data at all? >>>> >>>> I didn't understand why we need a workaround for this. It should be >>>> standard >>>> behaviour to NAK data if function driver didn't request for all endpoints. >>> >>> Yes, I agree with you. Controller shouldn’t accept such packet. As I know >>> this >>> behavior will be fixed in RTL. >>> >>> But I assume that some older version of this controller are one the market, >>> and driver should work correct with them. >>> >>> In the feature this workaround can be limited only to selected controllers. >>> >>> Even now I assume that it can be enabled/disabled by module parameter. >> >> no module parameters, please. Use revision detection in runtime. >> > >This is about whether to enable or disable the workaround. >By default we don't want this workaround to be enabled. > >I'm debating whether we should have this workaround at all or not. > >It has the following problems. > >1) It ACKs packets even when gadget end is not ready to accept the transfers. >2) It stores these packets in a temporary buffer and then pushes them to the >gadget driver whenever the gadget driver is ready to process the data. >3) Since the gadget driver can become ready at an indefinite time in the >future, it poses 2 problems: > a) It is sending stale data to the sink. (problematic at next protocol level?) > b) If this temporary buffer runs out we still hit the lock up issue. > >I think the right solution is to make sure that the gadget driver is always >reading all the enabled OUT endpoints *or* (keep the OUT endpoints disabled >if gadget driver is not ready to process OUT transfers). If driver disable endpoint then it not answer for packets from host. It will result that host reset the device, so I can't disable such endpoints. Other good solution is to change ACM driver in a way that it sends requests to controller driver after enabling endpoint. The class driver could decide what should do with such not expected packets. It could delete all or e.g keep only few last packets. This issue will be fixed in RTL but maybe driver should be compatible with previous controller’s version. By default, this workaround will be disabled or will depend on controller version. > >cheers, >-roger >-- >Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. >Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki Cheers, Pawel
RE: [PATCH v4 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >Pawel, > >On 14/02/2019 21:45, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver to linux kernel. >> >> The Cadence USBSS DRD Driver is a highly configurable IP Core whichi >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >> The current driver has been validated with FPGA burned. We have support >> for PCIe bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance with XHCI >> specification, so it works with standard XHCI linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 14 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 155 +++ >> drivers/usb/cdns3/core.c | 403 ++ >> drivers/usb/cdns3/core.h | 116 ++ >> drivers/usb/cdns3/debug.h | 168 +++ >> drivers/usb/cdns3/debugfs.c| 164 +++ >> drivers/usb/cdns3/drd.c| 365 + >> drivers/usb/cdns3/drd.h| 162 +++ >> drivers/usb/cdns3/ep0.c| 907 + >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 2003 >> drivers/usb/cdns3/gadget.h | 1207 + >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 72 + >> drivers/usb/cdns3/trace.c | 23 + >> drivers/usb/cdns3/trace.h | 404 ++ >> 19 files changed, 6267 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> >> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig >> index 987fc5ba6321..5f9334019d04 100644 >> --- a/drivers/usb/Kconfig >> +++ b/drivers/usb/Kconfig >> @@ -112,6 +112,8 @@ source "drivers/usb/usbip/Kconfig" >> >> endif >> >> +source "drivers/usb/cdns3/Kconfig" >> + >> source "drivers/usb/mtu3/Kconfig" >> >> source "drivers/usb/musb/Kconfig" >> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile >> index 7d1b8c82b208..ab125b966cac 100644 >> --- a/drivers/usb/Makefile >> +++ b/drivers/usb/Makefile >> @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/ >> obj-$(CONFIG_USB_DWC2) += dwc2/ >> obj-$(CONFIG_USB_ISP1760) += isp1760/ >> >> +obj-$(CONFIG_USB_CDNS3) += cdns3/ >> + >> obj-$(CONFIG_USB_MON) += mon/ >> obj-$(CONFIG_USB_MTU3) += mtu3/ >> >> diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig >> new file mode 100644 >> index ..27cb3d8dbe3d >> --- /dev/null >> +++ b/drivers/usb/cdns3/Kconfig >> @@ -0,0 +1,44 @@ >> +config USB_CDNS3 >> +tristate "Cadence USB3 Dual-Role Controller" >> +depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA >> +help >> + Say Y here if your system has a cadence USB3 dual-role controller. >> + It supports: dual-role switch, Host-only, and Peripheral-only. >> + >> + If you choose to build this driver is a dynamically linked >> + as module, the module will be called cdns3.ko. >> + >> +if USB_CDNS3 >> + >> +config USB_CDNS3_GADGET >> +bool "Cadence USB3 device controller" >> +depends on USB_GADGET >> +help >> + Say Y here to enable device controller functionality of the >> + cadence USBSS-DEV driver. > >"Cadence" ? > >>
RE: [PATCH v4 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
>From: Pawel Laszczak >Sent: Monday, March 4, 2019 12:02 PM >To: Chunfeng Yun >Cc: devicet...@vger.kernel.org; gre...@linuxfoundation.org; >felipe.ba...@linux.intel.com; mark.rutl...@arm.com; linux- >u...@vger.kernel.org; hdego...@redhat.com; heikki.kroge...@linux.intel.com; >andy.shevche...@gmail.com; robh...@kernel.org; >rog...@ti.com; linux-kernel@vger.kernel.org; jbergsa...@ti.com; >nsek...@ti.com; n...@ti.com; Suresh Punnoose >; peter.c...@nxp.com; Rahul Kumar >Subject: RE: [PATCH v4 5/6] usb:cdns3 Add Cadence USB3 DRD Driver > >Hi, >> >>hi, >>On Thu, 2019-02-14 at 19:45 +, Pawel Laszczak wrote: >>> This patch introduce new Cadence USBSS DRD driver to linux kernel. >>> >>> The Cadence USBSS DRD Driver is a highly configurable IP Core whichi >>> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >>> Host Only (XHCI)configurations. >>> >>> The current driver has been validated with FPGA burned. We have support >>> for PCIe bus, which is used on FPGA prototyping. >>> >>> The host side of USBSS-DRD controller is compliance with XHCI >>> specification, so it works with standard XHCI linux driver. >>> >>> Signed-off-by: Pawel Laszczak >>> --- >>> drivers/usb/Kconfig|2 + >>> drivers/usb/Makefile |2 + >>> drivers/usb/cdns3/Kconfig | 44 + >>> drivers/usb/cdns3/Makefile | 14 + >>> drivers/usb/cdns3/cdns3-pci-wrap.c | 155 +++ >>> drivers/usb/cdns3/core.c | 403 ++ >>> drivers/usb/cdns3/core.h | 116 ++ >>> drivers/usb/cdns3/debug.h | 168 +++ >>> drivers/usb/cdns3/debugfs.c| 164 +++ >>> drivers/usb/cdns3/drd.c| 365 + >>> drivers/usb/cdns3/drd.h| 162 +++ >>> drivers/usb/cdns3/ep0.c| 907 + >>> drivers/usb/cdns3/gadget-export.h | 28 + >>> drivers/usb/cdns3/gadget.c | 2003 >>> drivers/usb/cdns3/gadget.h | 1207 + >>> drivers/usb/cdns3/host-export.h| 28 + >>> drivers/usb/cdns3/host.c | 72 + >>> drivers/usb/cdns3/trace.c | 23 + >>> drivers/usb/cdns3/trace.h | 404 ++ >>> 19 files changed, 6267 insertions(+) >>> create mode 100644 drivers/usb/cdns3/Kconfig >>> create mode 100644 drivers/usb/cdns3/Makefile >>> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >>> create mode 100644 drivers/usb/cdns3/core.c >>> create mode 100644 drivers/usb/cdns3/core.h >>> create mode 100644 drivers/usb/cdns3/debug.h >>> create mode 100644 drivers/usb/cdns3/debugfs.c >>> create mode 100644 drivers/usb/cdns3/drd.c >>> create mode 100644 drivers/usb/cdns3/drd.h >>> create mode 100644 drivers/usb/cdns3/ep0.c >>> create mode 100644 drivers/usb/cdns3/gadget-export.h >>> create mode 100644 drivers/usb/cdns3/gadget.c >>> create mode 100644 drivers/usb/cdns3/gadget.h >>> create mode 100644 drivers/usb/cdns3/host-export.h >>> create mode 100644 drivers/usb/cdns3/host.c >>> create mode 100644 drivers/usb/cdns3/trace.c >>> create mode 100644 drivers/usb/cdns3/trace.h >>> >>> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig >>> index 987fc5ba6321..5f9334019d04 100644 >>> --- a/drivers/usb/Kconfig >>> +++ b/drivers/usb/Kconfig >>> @@ -112,6 +112,8 @@ source "drivers/usb/usbip/Kconfig" >>> >>> endif >>> >>> +source "drivers/usb/cdns3/Kconfig" >>> + >>> source "drivers/usb/mtu3/Kconfig" >>> >>> source "drivers/usb/musb/Kconfig" >>> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile >>> index 7d1b8c82b208..ab125b966cac 100644 >>> --- a/drivers/usb/Makefile >>> +++ b/drivers/usb/Makefile >>> @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3)+= dwc3/ >>> obj-$(CONFIG_USB_DWC2) += dwc2/ >>> obj-$(CONFIG_USB_ISP1760) += isp1760/ >>> >>> +obj-$(CONFIG_USB_CDNS3)+= cdns3/ >>> + >>> obj-$(CONFIG_USB_MON) += mon/ >>> obj-$(CONFIG_USB_MTU3) += mtu3/ >>> >>> diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig >>> new file mode 100644 >>> index ..27cb3d8dbe3d >>> --- /dev/null >>> +++ b/drivers/usb/cdns3/Kconfig &
RE: [PATCH v4 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > >hi, >On Thu, 2019-02-14 at 19:45 +0000, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver to linux kernel. >> >> The Cadence USBSS DRD Driver is a highly configurable IP Core whichi >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >> The current driver has been validated with FPGA burned. We have support >> for PCIe bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance with XHCI >> specification, so it works with standard XHCI linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 14 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 155 +++ >> drivers/usb/cdns3/core.c | 403 ++ >> drivers/usb/cdns3/core.h | 116 ++ >> drivers/usb/cdns3/debug.h | 168 +++ >> drivers/usb/cdns3/debugfs.c| 164 +++ >> drivers/usb/cdns3/drd.c| 365 + >> drivers/usb/cdns3/drd.h| 162 +++ >> drivers/usb/cdns3/ep0.c| 907 + >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 2003 >> drivers/usb/cdns3/gadget.h | 1207 + >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 72 + >> drivers/usb/cdns3/trace.c | 23 + >> drivers/usb/cdns3/trace.h | 404 ++ >> 19 files changed, 6267 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> >> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig >> index 987fc5ba6321..5f9334019d04 100644 >> --- a/drivers/usb/Kconfig >> +++ b/drivers/usb/Kconfig >> @@ -112,6 +112,8 @@ source "drivers/usb/usbip/Kconfig" >> >> endif >> >> +source "drivers/usb/cdns3/Kconfig" >> + >> source "drivers/usb/mtu3/Kconfig" >> >> source "drivers/usb/musb/Kconfig" >> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile >> index 7d1b8c82b208..ab125b966cac 100644 >> --- a/drivers/usb/Makefile >> +++ b/drivers/usb/Makefile >> @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/ >> obj-$(CONFIG_USB_DWC2) += dwc2/ >> obj-$(CONFIG_USB_ISP1760) += isp1760/ >> >> +obj-$(CONFIG_USB_CDNS3) += cdns3/ >> + >> obj-$(CONFIG_USB_MON) += mon/ >> obj-$(CONFIG_USB_MTU3) += mtu3/ >> >> diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig >> new file mode 100644 >> index ..27cb3d8dbe3d >> --- /dev/null >> +++ b/drivers/usb/cdns3/Kconfig >> @@ -0,0 +1,44 @@ >> +config USB_CDNS3 >> +tristate "Cadence USB3 Dual-Role Controller" >> +depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA >> +help >> + Say Y here if your system has a cadence USB3 dual-role controller. >> + It supports: dual-role switch, Host-only, and Peripheral-only. >> + >> + If you choose to build this driver is a dynamically linked >> + as module, the module will be called cdns3.ko. >> + >> +if USB_CDNS3 >> + >> +config USB_CDNS3_GADGET >> +bool "Cadence USB3 device controller" >> +depends on USB_GADGET >> +help >> + Say Y here to enable device controller functionality of the >> + cadence USBSS-DEV driver. >> + >> + This controller su
RE: [PATCH v4 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > >On Thu, Feb 14, 2019 at 07:45:13PM +, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver to linux kernel. > >Nit, "Linux" :) > >> The Cadence USBSS DRD Driver is a highly configurable IP Core whichi > >"whichi"? > >> can be instantiated as Dual-Role Device (DRD), Peripheral Only and >> Host Only (XHCI)configurations. >> >> The current driver has been validated with FPGA burned. We have support > >I can not parse that sentance, sorry. what does "with FPGA burned" >mean? I met with such sentence, and It's means that implementation (IP Core) Is loaded to FPGA. Maybe it was used from some historical reason, and nowadays it is not correct. I will replace it with ".. which is used on FPGA prototyping." > >> for PCIe bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance with XHCI > >"compliant" > >> specification, so it works with standard XHCI linux driver. > >"Linux" > >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 14 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 155 +++ >> drivers/usb/cdns3/core.c | 403 ++ >> drivers/usb/cdns3/core.h | 116 ++ >> drivers/usb/cdns3/debug.h | 168 +++ >> drivers/usb/cdns3/debugfs.c| 164 +++ >> drivers/usb/cdns3/drd.c| 365 + >> drivers/usb/cdns3/drd.h| 162 +++ >> drivers/usb/cdns3/ep0.c| 907 + >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 2003 >> drivers/usb/cdns3/gadget.h | 1207 + >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 72 + >> drivers/usb/cdns3/trace.c | 23 + >> drivers/usb/cdns3/trace.h | 404 ++ >> 19 files changed, 6267 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> >> diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig >> index 987fc5ba6321..5f9334019d04 100644 >> --- a/drivers/usb/Kconfig >> +++ b/drivers/usb/Kconfig >> @@ -112,6 +112,8 @@ source "drivers/usb/usbip/Kconfig" >> >> endif >> >> +source "drivers/usb/cdns3/Kconfig" >> + >> source "drivers/usb/mtu3/Kconfig" >> >> source "drivers/usb/musb/Kconfig" >> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile >> index 7d1b8c82b208..ab125b966cac 100644 >> --- a/drivers/usb/Makefile >> +++ b/drivers/usb/Makefile >> @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/ >> obj-$(CONFIG_USB_DWC2) += dwc2/ >> obj-$(CONFIG_USB_ISP1760) += isp1760/ >> >> +obj-$(CONFIG_USB_CDNS3) += cdns3/ >> + >> obj-$(CONFIG_USB_MON) += mon/ >> obj-$(CONFIG_USB_MTU3) += mtu3/ >> >> diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig >> new file mode 100644 >> index ..27cb3d8dbe3d >> --- /dev/null >> +++ b/drivers/usb/cdns3/Kconfig >> @@ -0,0 +1,44 @@ >> +config USB_CDNS3 >> +tristate "Cadence USB3 Dual-Role Controller" >> +depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA >> +help >> + Say Y here if your system has a cadence USB3 dual-role controller. >> + It supports: dual-role switch, Host-only, and Peripheral-only. >> + >> + If you
RE: [PATCH v4 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
> >On 20/02/2019 13:18, Pawel Laszczak wrote: >> Hi Roger. >>> >>> On 14/02/2019 21:45, Pawel Laszczak wrote: >>>> Controller for OUT endpoints has shared on-chip buffers for all incoming >>>> packets, including ep0out. It's FIFO buffer, so packets must be handle >>>> by DMA in correct order. If the first packet in the buffer will not be >>>> handled, then the following packets directed for other endpoints and >>>> functions will be blocked. >>>> >>>> Additionally the packets directed to one endpoint can block entire on-chip >>>> buffers. In this case transfer to other endpoints also will blocked. >>>> >>>> To resolve this issue after raising the descriptor missing interrupt >>>> driver prepares internal usb_request object and use it to arm DMA >>>> transfer. >>>> >>>> The problematic situation was observed in case when endpoint has >>>> been enabled but no usb_request were queued. Driver try detects >>>> such endpoints and will use this workaround only for these endpoint. >>>> >>>> Driver use limited number of buffer. This number can be set by macro >>>> CDNS_WA2_NUM_BUFFERS. >>>> >>>> Such blocking situation was observed on ACM gadget. For this function >>>> host send OUT data packet but ACM function is not prepared for >>>> this packet. It's cause that buffer placed in on chip memory block >>>> transfer to other endpoints. >>>> >>>> It's limitation of controller but maybe this issues should be fixed in >>>> function driver. >>>> >>>> This work around can be disabled/enabled by means of quirk_internal_buffer >>>> module parameter. By default feature is enabled. It can has impact to >>>> transfer performance and in most case this feature can be disabled. >>> >>> How much is the performance impact? >> >> I didn't check this, but performance will be decreased because driver has to >> copy data from internally allocated buffer to usb_request->buff. >> >>> You mentioned that the issue was observed only in the ACM case and >>> could be fixed in the function driver? >>> It seems pointless to enable an endpoint and not have any requests queued >>> for it. >> >> Yes, it’s true. The request in ACM class is send to Controller Driver when >> user read file associated >> with ACM gadget. Problem exist because host send data to controller but USB >> controller >> has not prepared buffer for this data by ACM class. >> >>> Isn't fixing the ACM driver (if there is a real issue) a better approach >>> than having >>> a workaround that affects performance of all other use cases? >> >> Yes it should be better. But what ACM driver should do with unexpected data. >> I'm not sure if we >> can simply delete them. >> >> The best solution would be to make modification in controller. In such case >> Controller shouldn't accept >> packet but should send NAK. > >Yes, that should be standard behaviour. No? > >> >> One more thing. Workaround has implemented algorithm that decide for which >> endpoint it should be enabled. >> e.g for composite device MSC+NCM+ACM it should work only for ACM OUT >> endpoint. >> > >If ACM driver didn't queue the request for ACM OUT endpoint, why does the >controller accept the data at all? >I didn't understand why we need a workaround for this. It should be standard >behaviour to NAK data if >function driver didn't request for all endpoints. Yes, I agree with you. Controller shouldn’t accept such packet. As I know this behavior will be fixed in RTL. But I assume that some older version of this controller are one the market, and driver should work correct with them. In the feature this workaround can be limited only to selected controllers. Even now I assume that it can be enabled/disabled by module parameter. > >Also I didn't understand why performance should be impacted to just NAK data. Data waiting in on-chip buffers can be very fast copied to system memory when DMA will be armed. In same case this feature can little increase performance, but it makes many problems under OS. Cheers, Pawel >cheers, >-roger > >> Cheers, >> Pawel >>> >>>> >>>> Signed-off-by: Pawel Laszczak >>>> --- >>>> drivers/usb/cdns3/gadget.c | 273 - >>>> drivers/usb/cdns3/gadget.h | 7 + >>>> 2 files changed, 278 i
RE: [PATCH v4 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Hi Roger. > >On 14/02/2019 21:45, Pawel Laszczak wrote: >> Controller for OUT endpoints has shared on-chip buffers for all incoming >> packets, including ep0out. It's FIFO buffer, so packets must be handle >> by DMA in correct order. If the first packet in the buffer will not be >> handled, then the following packets directed for other endpoints and >> functions will be blocked. >> >> Additionally the packets directed to one endpoint can block entire on-chip >> buffers. In this case transfer to other endpoints also will blocked. >> >> To resolve this issue after raising the descriptor missing interrupt >> driver prepares internal usb_request object and use it to arm DMA >> transfer. >> >> The problematic situation was observed in case when endpoint has >> been enabled but no usb_request were queued. Driver try detects >> such endpoints and will use this workaround only for these endpoint. >> >> Driver use limited number of buffer. This number can be set by macro >> CDNS_WA2_NUM_BUFFERS. >> >> Such blocking situation was observed on ACM gadget. For this function >> host send OUT data packet but ACM function is not prepared for >> this packet. It's cause that buffer placed in on chip memory block >> transfer to other endpoints. >> >> It's limitation of controller but maybe this issues should be fixed in >> function driver. >> >> This work around can be disabled/enabled by means of quirk_internal_buffer >> module parameter. By default feature is enabled. It can has impact to >> transfer performance and in most case this feature can be disabled. > >How much is the performance impact? I didn't check this, but performance will be decreased because driver has to copy data from internally allocated buffer to usb_request->buff. >You mentioned that the issue was observed only in the ACM case and >could be fixed in the function driver? >It seems pointless to enable an endpoint and not have any requests queued for >it. Yes, it’s true. The request in ACM class is send to Controller Driver when user read file associated with ACM gadget. Problem exist because host send data to controller but USB controller has not prepared buffer for this data by ACM class. >Isn't fixing the ACM driver (if there is a real issue) a better approach than >having >a workaround that affects performance of all other use cases? Yes it should be better. But what ACM driver should do with unexpected data. I'm not sure if we can simply delete them. The best solution would be to make modification in controller. In such case Controller shouldn't accept packet but should send NAK. One more thing. Workaround has implemented algorithm that decide for which endpoint it should be enabled. e.g for composite device MSC+NCM+ACM it should work only for ACM OUT endpoint. Cheers, Pawel > >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/cdns3/gadget.c | 273 - >> drivers/usb/cdns3/gadget.h | 7 + >> 2 files changed, 278 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c >> index 7f7f24ee3c4b..5dfbe6e1421c 100644 >> --- a/drivers/usb/cdns3/gadget.c >> +++ b/drivers/usb/cdns3/gadget.c >> @@ -27,6 +27,37 @@ >> * If (((Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr-1) or >> * (Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr)) >> * and (DRBL==1 and (not EP0))) >> + * >> + * Work around 2: >> + * Controller for OUT endpoints has shared on-chip buffers for all incoming >> + * packets, including ep0out. It's FIFO buffer, so packets must be handle >> by DMA >> + * in correct order. If the first packet in the buffer will not be handled, >> + * then the following packets directed for other endpoints and functions >> + * will be blocked. >> + * Additionally the packets directed to one endpoint can block entire >> on-chip >> + * buffers. In this case transfer to other endpoints also will blocked. >> + * >> + * To resolve this issue after raising the descriptor missing interrupt >> + * driver prepares internal usb_request object and use it to arm DMA >> transfer. >> + * >> + * The problematic situation was observed in case when endpoint has been >> enabled >> + * but no usb_request were queued. Driver try detects such endpoints and >> will >> + * use this workaround only for these endpoint. >> + * >> + * Driver use limited number of buffer. This number can be set by macro >> + * CDNS_WA2_NUM_BUFFERS. >> + * >> + * Such blocking situation was observed on ACM gadget. For th
RE: [PATCH v4 2/6] usb:common Separated decoding functions from dwc3 driver.
Hi, >On Thu, Feb 14, 2019 at 07:45:10PM +0000, Pawel Laszczak wrote: >> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver >> to driver/usb/common/debug.c file. These moved functions include: >> dwc3_decode_get_status >> dwc3_decode_set_clear_feature >> dwc3_decode_set_address >> dwc3_decode_get_set_descriptor >> dwc3_decode_get_configuration >> dwc3_decode_set_configuration >> dwc3_decode_get_intf >> dwc3_decode_set_intf >> dwc3_decode_synch_frame >> dwc3_decode_set_sel >> dwc3_decode_set_isoch_delay >> dwc3_decode_ctrl >> >> These functions are used also in inroduced cdns3 driver. >> >> All functions prefixes were changed from dwc3 to usb. >> Also, function's parameters has been extended according to the name >> of fields in standard SETUP packet. >> Additionally, patch adds usb_decode_ctrl function to >> include/linux/usb/ch9.h file. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/common/Makefile | 2 +- >> drivers/usb/common/debug.c | 270 >> drivers/usb/dwc3/debug.h| 249 - >> drivers/usb/dwc3/trace.h| 2 +- >> include/linux/usb/ch9.h | 25 >> 5 files changed, 297 insertions(+), 251 deletions(-) >> create mode 100644 drivers/usb/common/debug.c >> >> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile >> index fb4d5ef4165c..3d3d2962ea4b 100644 >> --- a/drivers/usb/common/Makefile >> +++ b/drivers/usb/common/Makefile >> @@ -4,7 +4,7 @@ >> # >> >> obj-$(CONFIG_USB_COMMON) += usb-common.o >> -usb-common-y += common.o >> +usb-common-y += common.o debug.o > >It's nice to have these in a common place, but you just bloated all of >the USB-enabled systems in the world for the use of 2 odd-ball system >controllers that almost no one has :) > >So, any way to only pull in this file if you actually need these >functions? > Yes, I'm using these functions a lot for debugging. It's only way to check what driver does. We are also going to upstreaming 3.1 controller so there will be a third driver using them :). I'm not sure If anyone will use them on host side, so we can consider whether they should be in usb/common directory. Maybe usb/gadget will be better place. Felipe, do you have any comments in this topic? Thanks Pawel
[PATCH v4 3/6] usb:common Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 89 ++ 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index 3fdf116da909..ad6c96aa45b0 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -30,58 +30,55 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } -static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, -__u16 wValue, __u16 wIndex, -char *str, size_t size) +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str, size_t size) { switch (bRequestType & USB_RECIP_MASK) { case USB_RECIP_DEVICE: snprintf(str, size, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", -({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), +usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? -({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); +usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: snprintf(str, size, "%s Interface Feature(%s)", -- 2.17.1
[PATCH v4 4/6] usb:common Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It improves code readability a little. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 113 +++-- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index ad6c96aa45b0..8e2c81a40cf8 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -105,62 +105,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str, size_t size) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)", -bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", -({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; -
[PATCH v4 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. It's limitation of controller but maybe this issues should be fixed in function driver. This work around can be disabled/enabled by means of quirk_internal_buffer module parameter. By default feature is enabled. It can has impact to transfer performance and in most case this feature can be disabled. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 273 - drivers/usb/cdns3/gadget.h | 7 + 2 files changed, 278 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 7f7f24ee3c4b..5dfbe6e1421c 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -27,6 +27,37 @@ * If (((Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr-1) or * (Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr)) * and (DRBL==1 and (not EP0))) + * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * It's limitation of controller but maybe this issues should be fixed in + * function driver. + * + * This work around can be disabled/enabled by means of quirk_internal_buffer + * module parameter. By default feature is enabled. It can has impact to + * transfer performance and in most case this feature can be disabled. */ #include @@ -42,6 +73,14 @@ static int __cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, gfp_t gfp_flags); +/* + * Parameter allows to disable/enable handling of work around 2 feature. + * By default this value is enabled. + */ +static bool quirk_internal_buffer = 1; +module_param(quirk_internal_buffer, bool, 0644); +MODULE_PARM_DESC(quirk_internal_buffer, "Disable/enable WA2 algorithm"); + /** * cdns3_handshake - spin reading until handshake completes or fails * @ptr: address of device controller register to be read @@ -105,6 +144,17 @@ struct usb_request *cdns3_next_request(struct list_head *list) return list_first_entry_or_null(list, struct usb_request, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -384,6 +434,53 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/** + * cdns3_descmiss_copy_data copy data from internal requests to request queued + * by class driver. + * @priv_ep: extended endpoint object +
[PATCH v4 0/6] Introduced new Cadence USBSS DRD Driver.
This patch introduce new Cadence USBSS DRD driver to linux kernel. The Cadence USBSS DRD Driver is a highly configurable IP Core whichi can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI)configurations. The current driver has been validated with FPGA burned. We have support for PCIe bus, which is used on FPGA prototyping. The host side of USBSS-DRD controller is compliance with XHCI specification, so it works with standard XHCI linux driver. Changes since v3: - updated dt-binding as suggested by Rob Herring - updated patch 002, 003 and 004 according with patch: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git/commit/ ?h=next=7790b3556fccc555ae422f1576e97bf34c8ab8b6 posted by Felipe Balbi. - fixed issues related to isochronous transfers. - improved algorithm calculating number of on-chip buffers required by endpoints. - fixed incorrect macro EP_CFG_MULT in gadget.h file. - fixed potential issue with incorrect order of instruction - added wmb(). - made some minor changes suggested by reviewers. *Changes since v2: - made some text correction in Kconfig file as suggested by Randy Dunlap. - simplified Makefile as suggested by Peter Chan. - removed phy-names from dt-binding as suggested Rob Herring. - changed cdns3-usb.txt to cdns3-usb3.txt as suggested by Rob Herring. - added checking error code in some function in drd.c file as suggested by Peter Chan. - added reg-names to dt-binding documentation as suggested by Chunfeng Yun. - replaced platform_get_resource with platform_get_resource_byname. - made other changes suggested by Chunfeng Yun. - fixed bug in cdns3_get_id. Now function return id instead 1. - added trace_cdns3_log trace event. - simplify cdns3_disable_write function. - create separate patch for work around related with blocking endpoint issue. - Fixed issue related with stale data address in TRB. Issue: At some situations, the controller may get stale data address in TRB at below sequences: 1. Controller read TRB includes data address. 2. Software updates TRBs includes data address and Cycle bit. 3. Controller read TRB which includes Cycle bit. 4. DMA run with stale data address. - Fixed issue without transfer. In some cases not all interrupts disabled in Hard IRQ was enabled in Soft Irq. - Modified LFPS minimal U1 Exit time for controller revision 0x00024505. - Fixed issue - in some case selected endpoint was unexpectedly changed. - Fixed issue - after clearing halted endpoint transfer was not started. - Fixed issue - in some case driver send ACK instead STALL in status phase. - Fixed issues related to dequeue request. - Fixed incorrect operator in cdns3_ep_run_transfer function. Changes since v1: - Removed not implemented Suspend/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronous transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (6): dt-bindings: add binding for USBSS-DRD controller. usb:common Separated decoding functions from dwc3 driver. usb:common Patch simplify usb_decode_set_clear_feature function. usb:common Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver usb:cdns3 Fix for stuck packets in on-chip OUT buffer. .../devicetree/bindings/usb/cdns-usb3.txt | 30 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 14 + drivers/usb/cdns3/cdns3-pci-wrap.c| 155 ++ drivers/usb/cdns3/core.c | 403 +++ drivers/usb/cdns3/core.h | 116 + drivers/usb/cdns3/debug.h
[PATCH v4 2/6] usb:common Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/common/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/ch9.h file. Signed-off-by: Pawel Laszczak --- drivers/usb/common/Makefile | 2 +- drivers/usb/common/debug.c | 270 drivers/usb/dwc3/debug.h| 249 - drivers/usb/dwc3/trace.h| 2 +- include/linux/usb/ch9.h | 25 5 files changed, 297 insertions(+), 251 deletions(-) create mode 100644 drivers/usb/common/debug.c diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index fb4d5ef4165c..3d3d2962ea4b 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_USB_COMMON) += usb-common.o -usb-common-y += common.o +usb-common-y += common.o debug.o usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c new file mode 100644 index ..3fdf116da909 --- /dev/null +++ b/drivers/usb/common/debug.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#ifndef __LINUX_USB_COMMON_DEBUG +#define __LINUX_USB_COMMON_DEBUG + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_INTERFACE: + snprintf(str, size, +"Get Interface Status(Intf = %d, Length = %d)", +wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + snprintf(str, size, "Get Endpoint Status(ep%d%s)", +wIndex & ~USB_DIR_IN, +wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, +__u16 wValue, __u16 wIndex, +char *str, size_t size) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + snprintf(str, size, "%s Device Feature(%s%s)", +bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", +({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), +wValue == USB_DEVICE_TEST_MODE ? +({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = &qu
[PATCH v4 1/6] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak --- .../devicetree/bindings/usb/cdns-usb3.txt | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index ..1d2b449e3cb4 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,30 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +region 1 - HOST registers area +region 2 - DEVICE registers area +region 3 - OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" + - interrupts: Interrupts used by cdns3 controller. + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + +Example: + usb@f300 { + compatible = "cdns,usb3-1.0.1"; + interrupts = ; + reg = <0xf300 0x1 /* memory area for HOST registers */ + 0xf301 0x1 /* memory area for DEVICE registers */ + 0xf302 0x1>;/* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + }; -- 2.17.1
RE: [PATCH v3 1/6] dt-bindings: add binding for USBSS-DRD controller.
Hi Rob, >On Thu, Jan 31, 2019 at 11:52:28AM +0000, Pawel Laszczak wrote: >> This patch aim at documenting USB related dt-bindings for the >> Cadence USBSS-DRD controller. >> >> Signed-off-by: Pawel Laszczak >> --- >> .../devicetree/bindings/usb/cdns-usb3.txt | 33 +++ >> 1 file changed, 33 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt >> >> diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> new file mode 100644 >> index ..6dc38be77f5c >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt >> @@ -0,0 +1,33 @@ >> +Binding for the Cadence USBSS-DRD controller >> + >> +Required properties: >> + - reg: Physical base address and size of the controller's register areas. >> + Controller has 3 different regions: >> + region 1 - HOST registers area >> + region 2 - DEVICE registers area >> + region 3 - OTG/DRD registers area >> + - reg-names - register memory area names: >> +"xhci" - for HOST registers space >> +"dev" - for DEVICE registers space >> +"otg" - for OTG/DRD registers space >> + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" >> + - interrupts: Interrupt specifier. Refer to interrupt bindings. >> +Driver supports only single interrupt line. > >Driver supports or h/w only has 1 interrupt? h/w internally has 3 separate interrupt line, but in my testing board they are ored. So physically driver sees only one h/w interrupt line and assumes that h/w has single common interrupt line. > >> +This single interrupt is shared between Device, >> +host and OTG/DRD part of driver. >> + >> +Optional properties: >> + - maximum-speed : valid arguments are "super-speed", "high-speed" and >> + "full-speed"; refer to usb/generic.txt >> + - dr_mode: Should be one of "host", "peripheral" or "otg". >> + - phys: reference to the USB PHY >> + >> +Example: >> +usb@f300 { >> +compatible = "cdns,usb3"; > >Doesn't match above. Right, should be: Compatible = " cdns,usb3-1.0.0", "cdns,usb3-1.0.1"; > >> +interrupts = ; >> +reg = <0xf300 0x1 /* memory area for HOST >> registers */ >> +0xf301 0x1 /* memory area for DEVICE >> registers */ >> +0xf302 0x1>;/* memory area for OTG/DRD >> registers */ > >Are these really 64KB long? That wastes virtual address space on 32-bit >systems if not. Yes, on my testing platform it takes 64KB. It's only example, and it could be limited. > >> +reg-names = "xhci", "dev", "otg"; >> +}; >> -- >> 2.17.1 >> Thanks Pawel
RE: [PATCH v3 2/6] usb:common Separated decoding functions from dwc3 driver.
> >Pawel Laszczak writes: >>>>> +/** >>>>> + * usb_decode_ctrl - Returns human readable representation of control >>>>> request. >>>>> + * @str: buffer to return a human-readable representation of control >>>>> request. >>>>> + * This buffer should have about 200 bytes. >>>> >>>> "about 200 bytes" is not very specific. >>>> >>>> Pass in the length so we know we don't overflow it. >>> >>>agree. >> I also agree and I will add such parameter. > >https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git/commit/?h=next=7790b3556fccc555ae422f1576e97bf34c8ab8b6 Cool :). Thanks. -- Pawel
RE: [PATCH v3 2/6] usb:common Separated decoding functions from dwc3 driver.
Hi, > >Greg KH writes: >> On Thu, Jan 31, 2019 at 11:52:29AM +, Pawel Laszczak wrote: >>> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver >>> to driver/usb/common/debug.c file. These moved functions include: >>> dwc3_decode_get_status >>> dwc3_decode_set_clear_feature >>> dwc3_decode_set_address >>> dwc3_decode_get_set_descriptor >>> dwc3_decode_get_configuration >>> dwc3_decode_set_configuration >>> dwc3_decode_get_intf >>> dwc3_decode_set_intf >>> dwc3_decode_synch_frame >>> dwc3_decode_set_sel >>> dwc3_decode_set_isoch_delay >>> dwc3_decode_ctrl >>> >>> These functions are used also in inroduced cdns3 driver. >>> >>> All functions prefixes were changed from dwc3 to usb. >> >> Ick, why? > >moving dwc3-specific code into generic code. > >>> Also, function's parameters has been extended according to the name >>> of fields in standard SETUP packet. >>> Additionally, patch adds usb_decode_ctrl function to >>> include/linux/usb/ch9.h file. >> >> Why ch9.h? It's not something that is specified in the spec, it's a >> usb-specific thing :) > >agree. Similar as usb_state_string function from include/linux/usb/ch9.h which "Returns human readable name for the state", the usb_decode_ctrl function make the same but for standard USB request. USB Request is usb-specifing thing. If my idea is not correct, can you suggest where this function declaration should be moved. > >>> +/** >>> + * usb_decode_ctrl - Returns human readable representation of control >>> request. >>> + * @str: buffer to return a human-readable representation of control >>> request. >>> + * This buffer should have about 200 bytes. >> >> "about 200 bytes" is not very specific. >> >> Pass in the length so we know we don't overflow it. > >agree. I also agree and I will add such parameter. > >>> + * @bRequestType: matches the USB bmRequestType field >>> + * @bRequest: matches the USB bRequest field >>> + * @wValue: matches the USB wValue field (CPU byte order) >>> + * @wIndex: matches the USB wIndex field (CPU byte order) >>> + * @wLength: matches the USB wLength field (CPU byte order) >>> + * >>> + * Function returns decoded, formatted and human-readable description of >>> + * control request packet. >>> + * >>> + * Important: wValue, wIndex, wLength parameters before invoking this >>> function >>> + * should be processed by le16_to_cpu macro. >>> + */ >>> +const char *usb_decode_ctrl(char *str, __u8 bRequestType, __u8 bRequest, >>> + __u16 wValue, __u16 wIndex, __u16 wLength); >> >> Why are you returning a value, isn't the data stored in str? Why not >> just return an int saying if the call succeeded or not? > >There is one detail here. The usage scenario for this is for >tracepoints. When dealing with tracepoints we want to delay decoding of >the data into strings until print-time. I guess it's best to illustrate >with an example: > >DECLARE_EVENT_CLASS(dwc3_log_ctrl, > TP_PROTO(struct usb_ctrlrequest *ctrl), > TP_ARGS(ctrl), > TP_STRUCT__entry( > __field(__u8, bRequestType) > __field(__u8, bRequest) > __field(__u16, wValue) > __field(__u16, wIndex) > __field(__u16, wLength) > __dynamic_array(char, str, DWC3_MSG_MAX) > ), > TP_fast_assign( > __entry->bRequestType = ctrl->bRequestType; > __entry->bRequest = ctrl->bRequest; > __entry->wValue = le16_to_cpu(ctrl->wValue); > __entry->wIndex = le16_to_cpu(ctrl->wIndex); > __entry->wLength = le16_to_cpu(ctrl->wLength); > ), > TP_printk("%s", dwc3_decode_ctrl(__get_str(str), DWC3_MSG_MAX, > __entry->bRequestType, > __entry->bRequest, __entry->wValue, > __entry->wIndex, __entry->wLength) > ) >); > >The above is the code is today (well, I've added buffer size as an >argument). If I make dwc3_decode_ctrl() return an integer, I can't call >it from TP_printk() time. I'd have to move it to TP_fast_assign() time >which is supposed to be, simply, a copy of the necessary data. IOW, I >would have this: > >DECL
RE: [PATCH v3 4/6] usb:common Simplify usb_decode_get_set_descriptor function.
>On Thu, Jan 31, 2019 at 11:52:31AM +0000, Pawel Laszczak wrote: >> Patch moves switch responsible for decoding descriptor type >> outside snprintf. It's little improves code readability. > >Should that last sentence read: "It improves code readability a little"? > Yes, it should. Thanks Pawel
RE: [PATCH v3 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >On Thu, Jan 31, 2019 at 11:52:32AM +0000, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver >> to linux kernel. >> >> The Cadence USBSS DRD Driver is a highly >> configurable IP Core which can be >> instantiated as Dual-Role Device (DRD), >> Peripheral Only and Host Only (XHCI) >> configurations. >> >> The current driver has been validated with >> FPGA burned. We have support for PCIe >> bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance >> with XHCI specification, so it works with >> standard XHCI linux driver. > >Please line-wrap this properly at 72 columns, like your editor asks you >to when you run git :) > >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 14 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 155 +++ >> drivers/usb/cdns3/core.c | 403 ++ >> drivers/usb/cdns3/core.h | 116 ++ >> drivers/usb/cdns3/debug.h | 168 +++ >> drivers/usb/cdns3/debugfs.c| 164 +++ >> drivers/usb/cdns3/drd.c| 365 + >> drivers/usb/cdns3/drd.h| 162 +++ >> drivers/usb/cdns3/ep0.c| 907 + >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 1985 >> drivers/usb/cdns3/gadget.h | 1207 + >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 72 + >> drivers/usb/cdns3/trace.c | 23 + >> drivers/usb/cdns3/trace.h | 404 ++ >> 19 files changed, 6249 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h > >This is way too big to try to review all at once. You need to break >this up into logical chunks, each one adding a single functionality to >make it possible to actually review it. > In the past driver was split into series of patch, but it was difficult to review for other reviewers so I made decision to prepare it in this way. The short discuss you can find on https://lkml.org/lkml/2018/11/30/502. Quotation: " >> Frankly, I don't understand why this is a series. It's a single driver and >> splitting it into >> a series just makes it more difficult to review, actually. >> >> Sure, a single patch will be large, but there's no way to have a functional >> driver until >> all patches are applied, anyway. >> > >Yes, I agree with Felipe. Pawel, you could remove the "RFC" prefix, and send >the whole >one as one patch. I will test it at my hardware. Ok, I will prepare such single patch. Peter I know that you have little different platform. Probably you should made some additional changes for your platform. " Thanks Pawel Laszczak.
RE: [PATCH v3 2/6] usb:common Separated decoding functions from dwc3 driver.
H Greg > >On Thu, Jan 31, 2019 at 11:52:29AM +, Pawel Laszczak wrote: >> Patch moves some decoding functions from driver/usb/dwc3/debug.h driver >> to driver/usb/common/debug.c file. These moved functions include: >> dwc3_decode_get_status >> dwc3_decode_set_clear_feature >> dwc3_decode_set_address >> dwc3_decode_get_set_descriptor >> dwc3_decode_get_configuration >> dwc3_decode_set_configuration >> dwc3_decode_get_intf >> dwc3_decode_set_intf >> dwc3_decode_synch_frame >> dwc3_decode_set_sel >> dwc3_decode_set_isoch_delay >> dwc3_decode_ctrl >> >> These functions are used also in inroduced cdns3 driver. >> >> All functions prefixes were changed from dwc3 to usb. > >Ick, why? Because CDNS3 driver in one of the previous version had implemented very similar function as dwc3 and Felipe suggested that we should make common file with these functions. He also suggested that this function also could be used on host side. It was the reason why I've took function from DWC driver and put it in separate file in usb/common directory. I change only the prefix to make this function more common. > >> Also, function's parameters has been extended according to the name >> of fields in standard SETUP packet. >> Additionally, patch adds usb_decode_ctrl function to >> include/linux/usb/ch9.h file. > >Why ch9.h? It's not something that is specified in the spec, it's a >usb-specific thing :) Why not ? Similar as usb_state_string function from include/linux/usb/ch9.h which " Returns human readable name for the state", the usb_decode_ctrl function make the same but for standard USB request. > >Also, the api for that function is not ok. If you are going to make >this something that the whole kernel can call, you have to fix it up: > >> +/** >> + * usb_decode_ctrl - Returns human readable representation of control >> request. >> + * @str: buffer to return a human-readable representation of control >> request. >> + * This buffer should have about 200 bytes. > >"about 200 bytes" is not very specific. > >Pass in the length so we know we don't overflow it. I didn't want to change to much this code, because it's not my code. I'm not sure if I should ? > >> + * @bRequestType: matches the USB bmRequestType field >> + * @bRequest: matches the USB bRequest field >> + * @wValue: matches the USB wValue field (CPU byte order) >> + * @wIndex: matches the USB wIndex field (CPU byte order) >> + * @wLength: matches the USB wLength field (CPU byte order) >> + * >> + * Function returns decoded, formatted and human-readable description of >> + * control request packet. >> + * >> + * Important: wValue, wIndex, wLength parameters before invoking this >> function >> + * should be processed by le16_to_cpu macro. >> + */ >> +const char *usb_decode_ctrl(char *str, __u8 bRequestType, __u8 bRequest, >> +__u16 wValue, __u16 wIndex, __u16 wLength); > >Why are you returning a value, isn't the data stored in str? Why not >just return an int saying if the call succeeded or not? Currently this function is called only from trace point, and probably it will be use only In this way. If function prototype looks like above, we can simply call it in following way: TP_printk("%s", usb_decode_ctrl(__get_str(str), __entry->bRequestType, __entry->bRequest, __entry->wValue, __entry->wIndex, __entry->wLength) Thanks Pawel laszczak
[PATCH v3 2/6] usb:common Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/common/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/ch9.h file. mend Signed-off-by: Pawel Laszczak --- drivers/usb/common/Makefile | 2 +- drivers/usb/common/debug.c | 265 drivers/usb/dwc3/debug.h| 243 - drivers/usb/dwc3/trace.h| 2 +- include/linux/usb/ch9.h | 19 +++ 5 files changed, 286 insertions(+), 245 deletions(-) create mode 100644 drivers/usb/common/debug.c diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index fb4d5ef4165c..3d3d2962ea4b 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_USB_COMMON) += usb-common.o -usb-common-y += common.o +usb-common-y += common.o debug.o usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c new file mode 100644 index ..824b3d793745 --- /dev/null +++ b/drivers/usb/common/debug.c @@ -0,0 +1,265 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#ifndef __LINUX_USB_COMMON_DEBUG +#define __LINUX_USB_COMMON_DEBUG + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_INTERFACE: + sprintf(str, "Get Interface Status(Intf = %d, Length = %d)", + wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + sprintf(str, "Get Endpoint Status(ep%d%s)", + wIndex & ~USB_DIR_IN, + wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + sprintf(str, "%s Device Feature(%s%s)", + bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + ({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), + wValue == USB_DEVICE_TEST_MODE ? + ({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = ": TEST_K"; + break; +
[PATCH v3 3/6] usb:common Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 83 ++ 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index 824b3d793745..bdd529a686e4 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -29,6 +29,44 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, char *str) @@ -37,50 +75,9 @@ static void usb_decode_set_clear_feature(__u8 bRequestType, case USB_RECIP_DEVICE: sprintf(str, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), + usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); + usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: sprintf(str, "%s Interface Feature(%s)", -- 2.17.1
[PATCH v3 1/6] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak --- .../devicetree/bindings/usb/cdns-usb3.txt | 33 +++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt diff --git a/Documentation/devicetree/bindings/usb/cdns-usb3.txt b/Documentation/devicetree/bindings/usb/cdns-usb3.txt new file mode 100644 index ..6dc38be77f5c --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns-usb3.txt @@ -0,0 +1,33 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +region 1 - HOST registers area +region 2 - DEVICE registers area +region 3 - OTG/DRD registers area + - reg-names - register memory area names: + "xhci" - for HOST registers space + "dev" - for DEVICE registers space + "otg" - for OTG/DRD registers space + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" + - interrupts: Interrupt specifier. Refer to interrupt bindings. + Driver supports only single interrupt line. +This single interrupt is shared between Device, + host and OTG/DRD part of driver. + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + +Example: + usb@f300 { + compatible = "cdns,usb3"; + interrupts = ; + reg = <0xf300 0x1 /* memory area for HOST registers */ + 0xf301 0x1 /* memory area for DEVICE registers */ + 0xf302 0x1>;/* memory area for OTG/DRD registers */ + reg-names = "xhci", "dev", "otg"; + }; -- 2.17.1
[PATCH v3 6/6] usb:cdns3 Fix for stuck packets in on-chip OUT buffer.
Controller for OUT endpoints has shared on-chip buffers for all incoming packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA in correct order. If the first packet in the buffer will not be handled, then the following packets directed for other endpoints and functions will be blocked. Additionally the packets directed to one endpoint can block entire on-chip buffers. In this case transfer to other endpoints also will blocked. To resolve this issue after raising the descriptor missing interrupt driver prepares internal usb_request object and use it to arm DMA transfer. The problematic situation was observed in case when endpoint has been enabled but no usb_request were queued. Driver try detects such endpoints and will use this workaround only for these endpoint. Driver use limited number of buffer. This number can be set by macro CDNS_WA2_NUM_BUFFERS. Such blocking situation was observed on ACM gadget. For this function host send OUT data packet but ACM function is not prepared for this packet. It's cause that buffer placed in on chip memory block transfer to other endpoints. It's limitation of controller but maybe this issues should be fixed in function driver. This work around can be disabled/enabled by means of quirk_internal_buffer module parameter. By default feature is enabled. It can has impact to transfer performance and in most case this feature can be disabled. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 273 - drivers/usb/cdns3/gadget.h | 7 + 2 files changed, 278 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 35985633470f..20e46d8e308e 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -27,6 +27,37 @@ * If (((Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr-1) or * (Dequeue Ptr (i.e. EP_TRADDR) == Enqueue Ptr)) * and (DRBL==1 and (not EP0))) + * + * Work around 2: + * Controller for OUT endpoints has shared on-chip buffers for all incoming + * packets, including ep0out. It's FIFO buffer, so packets must be handle by DMA + * in correct order. If the first packet in the buffer will not be handled, + * then the following packets directed for other endpoints and functions + * will be blocked. + * Additionally the packets directed to one endpoint can block entire on-chip + * buffers. In this case transfer to other endpoints also will blocked. + * + * To resolve this issue after raising the descriptor missing interrupt + * driver prepares internal usb_request object and use it to arm DMA transfer. + * + * The problematic situation was observed in case when endpoint has been enabled + * but no usb_request were queued. Driver try detects such endpoints and will + * use this workaround only for these endpoint. + * + * Driver use limited number of buffer. This number can be set by macro + * CDNS_WA2_NUM_BUFFERS. + * + * Such blocking situation was observed on ACM gadget. For this function + * host send OUT data packet but ACM function is not prepared for this packet. + * It's cause that buffer placed in on chip memory block transfer to other + * endpoints. + * + * It's limitation of controller but maybe this issues should be fixed in + * function driver. + * + * This work around can be disabled/enabled by means of quirk_internal_buffer + * module parameter. By default feature is enabled. It can has impact to + * transfer performance and in most case this feature can be disabled. */ #include @@ -42,6 +73,14 @@ static int __cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, gfp_t gfp_flags); +/* + * Parameter allows to disable/enable handling of work around 2 feature. + * By default this value is enabled. + */ +static bool quirk_internal_buffer = 1; +module_param(quirk_internal_buffer, bool, 0644); +MODULE_PARM_DESC(quirk_internal_buffer, "Disable/enable WA2 algorithm"); + /** * cdns3_handshake - spin reading until handshake completes or fails * @ptr: address of device controller register to be read @@ -105,6 +144,17 @@ struct usb_request *cdns3_next_request(struct list_head *list) return list_first_entry_or_null(list, struct usb_request, list); } +/** + * cdns3_next_priv_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct cdns3_request *cdns3_next_priv_request(struct list_head *list) +{ + return list_first_entry_or_null(list, struct cdns3_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -384,6 +434,53 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, return ret; } +/** + * cdns3_descmiss_copy_data copy data from internal requests to request queued + * by class driver. + * @priv_ep: extended endpoint object +
[PATCH v3 4/6] usb:common Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It's little improves code readability. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 111 +++-- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index bdd529a686e4..a2fbcefe1ea0 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -104,62 +104,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + sprintf(str, "%s %s Descriptor(Index = %d, Length = %d)", bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - ({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; -
[PATCH v3 0/6] Introduced new Cadence USBSS DRD Driver.
This patch set introduce new Cadence USBSS DRD driver to linux kernel. The Cadence USBSS DRD Driver s a highly configurable IP Core which can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI) configurations. The current driver has been validated with FPGA burned. We have support for PCIe bus, which is used on FPGA prototyping. The host site of USBSS controller is compliance with XHCI specification, so it works with standard XHCI linux driver. Changes since v2: - made some text correction in Kconfig file as suggested by Randy Dunlap. - simplified Makefile as suggested by Peter Chan. - removed phy-names from dt-binding as suggested Rob Herring. - changed cdns3-usb.txt to cdns3-usb3.txt as suggested by Rob Herring. - added checking error code in some function in drd.c file as suggested by Peter Chan. - added reg-names to dt-binding documentation as suggested by Chunfeng Yun. - replaced platform_get_resource with platform_get_resource_byname. - made other changes suggested by Chunfeng Yun. - fixed bug in cdns3_get_id. Now function return id instead 1. - added trace_cdns3_log trace event. - simplify cdns3_disable_write function. - create separate patch for work around related with blocking endpoint issue. - Fixed issue related with stale data address in TRB. Issue: At some situations, the controller may get stale data address in TRB at below sequences: 1. Controller read TRB includes data address. 2. Software updates TRBs includes data address and Cycle bit. 3. Controller read TRB which includes Cycle bit. 4. DMA run with stale data address. - Fixed issue without transfer. In some cases not all interrupts disabled in Hard IRQ was enabled in Soft Irq. - Modified LFPS minimal U1 Exit time for controller revision 0x00024505. - Fixed issue - in some case selected endpoint was unexpectedly changed. - Fixed issue - after clearing halted endpoint transfer was not started. - Fixed issue - in some case driver send ACK instead STALL in status phase. - Fixed issues related to dequeue request. - Fixed incorrect operator in cdns3_ep_run_transfer function. Changes since v1: - Removed not implemented Suspend/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronous transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (6): dt-bindings: add binding for USBSS-DRD controller. usb:common Separated decoding functions from dwc3 driver. usb:common Patch simplify usb_decode_set_clear_feature function. usb:common Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver usb:cdns3 Fix for stuck packets in on-chip OUT buffer. .../devicetree/bindings/usb/cdns-usb3.txt | 33 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 14 + drivers/usb/cdns3/cdns3-pci-wrap.c| 155 ++ drivers/usb/cdns3/core.c | 403 +++ drivers/usb/cdns3/core.h | 116 + drivers/usb/cdns3/debug.h | 168 ++ drivers/usb/cdns3/debugfs.c | 164 ++ drivers/usb/cdns3/drd.c | 365 +++ drivers/usb/cdns3/drd.h | 162 ++ drivers/usb/cdns3/ep0.c | 907 +++ drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadget.c| 2254 + drivers/usb/cdns3/gadget.h| 1214 + drivers/usb/cdns3/host-export.h | 28 + drivers/usb/cdns3/host.c | 72 + drivers/usb
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >On Thu, Jan 10, 2019 at 09:30:41AM +0800, Peter Chen wrote: >> On Mon, Dec 24, 2018 at 12:44 AM Pawel Laszczak wrote: >> - debugfs is nice to have feature, I suggest removing it at this >> initial version. Besides, role switch >> through /sys is normal feature, the end user may use it at real >> product, so, it is better at device's >> /sys entry instead of debugfs. >> >> - I don't know why you add "disable" at debugfs, please comment. > >As you imply here, no real-world functionality should ever be in >debugfs as it is an optional system component and kernel code should >work just fine without it being enabled (as more and more systems are >disabling it due to the obvious security problems it has.) > "disable" it's not required. It's used for testing. It allows to enable/disable the current role. It can be used for testing eg. connect/disconnect event. I mainly test the driver remotely and I can't do connect/disconnect by USB cable. "disable" allow me to get trace log from host/device without disconnecting cable: I'm using the fallowing sequence: - load cdns3.ko modules - echo 1 > disable - disable current role - echo cdns3:* tracing/set_event - echo 0 > disable - enable role again - cat tracing/trace. Pawel
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
Hi >On Sun, 2018-12-23 at 15:13 +0000, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver >> to linux kernel. > ><...> > >> diff --git a/drivers/usb/cdns3/cdns3-pci-wrap.c >> b/drivers/usb/cdns3/cdns3-pci-wrap.c >> new file mode 100644 >> index ..e93179c45ece >> --- /dev/null >> +++ b/drivers/usb/cdns3/cdns3-pci-wrap.c >> @@ -0,0 +1,157 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Cadence USBSS PCI Glue driver >> + * >> + * Copyright (C) 2018 Cadence. >> + * >> + * Author: Pawel Laszczak >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +struct cdns3_wrap { >> +struct platform_device *plat_dev; >> +struct pci_dev *hg_dev; >> +struct resource dev_res[4]; >> +}; >> + >> +struct cdns3_wrap wrap; >> + >> +#define RES_IRQ_ID 0 >> +#define RES_HOST_ID 1 >> +#define RES_DEV_ID 2 >> +#define RES_DRD_ID 3 >> + >> +#define PCI_BAR_HOST0 >> +#define PCI_BAR_DEV 2 >> +#define PCI_BAR_OTG 4 >> + >> +#define PCI_DEV_FN_HOST_DEVICE 0 >> +#define PCI_DEV_FN_OTG 1 >> + >> +#define PCI_DRIVER_NAME "cdns3-pci-usbss" >> +#define PLAT_DRIVER_NAME"cdns-usb3" >> + >> +#define CDNS_VENDOR_ID 0x17cd >> +#define CDNS_DEVICE_ID 0x0100 >> + >> +/** >> + * cdns3_pci_probe - Probe function for Cadence USB wrapper driver >> + * @pdev: platform device object >> + * @id: pci device id >> + * >> + * Returns 0 on success otherwise negative errno >> + */ >> +static int cdns3_pci_probe(struct pci_dev *pdev, >> + const struct pci_device_id *id) >> +{ >> +struct platform_device_info plat_info; >> +struct cdns3_wrap *wrap; >> +struct resource *res; >> +int err; >> + >> +/* >> + * for GADGET/HOST PCI (devfn) function number is 0, >> + * for OTG PCI (devfn) function number is 1 >> + */ >> +if (!id || pdev->devfn != PCI_DEV_FN_HOST_DEVICE) >> +return -EINVAL; >> + >> +err = pcim_enable_device(pdev); >> +if (err) { >> +dev_err(>dev, "Enabling PCI device has failed %d\n", err); >> +return err; >> +} >> + >> +pci_set_master(pdev); >> +wrap = devm_kzalloc(>dev, sizeof(*wrap), GFP_KERNEL); >> +if (!wrap) { >> +dev_err(>dev, "Failed to allocate memory\n"); >> +return -ENOMEM; >> +} >> + >> +/* function 0: host(BAR_0) + device(BAR_1) + otg(BAR_2)). */ >> +memset(wrap->dev_res, 0x00, >> + sizeof(struct resource) * ARRAY_SIZE(wrap->dev_res)); >> +dev_dbg(>dev, "Initialize Device resources\n"); >> +res = wrap->dev_res; >> + >> +res[RES_DEV_ID].start = pci_resource_start(pdev, PCI_BAR_DEV); >> +res[RES_DEV_ID].end = pci_resource_end(pdev, PCI_BAR_DEV); >> +res[RES_DEV_ID].name = "cdns3-dev-regs"; >> +res[RES_DEV_ID].flags = IORESOURCE_MEM; >> +dev_dbg(>dev, "USBSS-DEV physical base addr: %pa\n", >> +[RES_DEV_ID].start); >> + >> +res[RES_HOST_ID].start = pci_resource_start(pdev, PCI_BAR_HOST); >> +res[RES_HOST_ID].end = pci_resource_end(pdev, PCI_BAR_HOST); >> +res[RES_HOST_ID].name = "cdns3-xhci-regs"; >> +res[RES_HOST_ID].flags = IORESOURCE_MEM; >> +dev_dbg(>dev, "USBSS-XHCI physical base addr: %pa\n", >> +[RES_HOST_ID].start); >> + >> +res[RES_DRD_ID].start = pci_resource_start(pdev, PCI_BAR_OTG); >> +res[RES_DRD_ID].end = pci_resource_end(pdev, PCI_BAR_OTG); >> +res[RES_DRD_ID].name = "cdns3-otg"; >> +res[RES_DRD_ID].flags = IORESOURCE_MEM; >> +dev_dbg(>dev, "USBSS-DRD physical base addr: %pa\n", >> +[RES_DRD_ID].start); >> + >> +/* Interrupt common for both device and XHCI */ >> +wrap->dev_res[RES_IRQ_ID].start = pdev->irq; >> +wrap->dev_res[RES_IRQ_ID].name = "cdns3-irq"; >> +wrap->dev_res[RES_IRQ_ID].flags = IORESOURCE_IRQ; >> + >> +/* set up platform device info */ >> +memset(_info, 0, sizeof(plat_info)); >> +plat_info.parent = >dev; >>
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
Hi I can't recreate these issue on my environment. I use gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0. Maybe there are some differenct between these two compilers. Do you have any idea how I should change this fragment of code: sprintf(str, "%02x %02x %02x %02x %02x %02x %02x %02x", bRequestType, bRequest, cpu_to_le16(wValue) & 0xff, cpu_to_le16(wValue) >> 8, cpu_to_le16(wIndex) & 0xff, cpu_to_le16(wIndex) >> 8, cpu_to_le16(wLength) & 0xff, cpu_to_le16(wLength) >> 8); to remove "restricted __le16 degrades to integer" warnings ? Maybe I should cast all to u8. Then this code will look like: sprintf(str, "%02x %02x %02x %02x %02x %02x %02x %02x", bRequestType, bRequest, (u8)(cpu_to_le16(wValue) & 0xff), (u8)(cpu_to_le16(wValue) >> 8), (u8)(cpu_to_le16(wIndex) & 0xff), (u8)(cpu_to_le16(wIndex) >> 8), (u8)(cpu_to_le16(wLength) & 0xff), (u8)(cpu_to_le16(wLength) >> 8)); Should it Fix these warnings ? Cheers, Pawel >Thank you for the patch! Perhaps something to improve: > > > >[auto build test WARNING on usb/usb-testing] > >[also build test WARNING on v4.20-rc7 next-20181221] > >[if your patch is applied to the wrong git tree, please drop us a note to help >improve the system] > > > >url: >https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_0day-2Dci_linux_commits_Pawel-2DLaszczak_Introduced- >2Dnew-2DCadence-2DUSBSS-2DDRD-2DDriver_20181223-2D231813=DwIBAg=aUq983L2pue2FqKFoP6PGHMJQyoJ7kl3s3GZ- >_haXqY=e1OgxfvkL0qo9XO6fX1gscva-w03uSYC1nIyxl89-rI=JS8MUBEUPN46-me57xUY- >7hoBbSrlgd2SCB9ahNjK4s=bhpHqRyEtMdMbWdGoBqQ9Pz9wq7pRA7-OohrGik3BpM= > >base: https://urldefense.proofpoint.com/v2/url?u=https- >3A__git.kernel.org_pub_scm_linux_kernel_git_gregkh_usb.git=DwIBAg=aUq983L2pue2FqKFoP6PGHMJQyoJ7kl3s3GZ- >_haXqY=e1OgxfvkL0qo9XO6fX1gscva-w03uSYC1nIyxl89-rI=JS8MUBEUPN46-me57xUY- >7hoBbSrlgd2SCB9ahNjK4s=Vf__lGpV27zdf1egowm9p8YBJjz9aMmgbi8nW_Z_DLk= >usb-testing > >config: x86_64-allmodconfig (attached as .config) > >compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 > >reproduce: > ># save the attached .config to linux build tree > >make ARCH=x86_64 > > > >All warnings (new ones prefixed by >>): > > > >>> drivers/usb/common/debug.c:253:25: warning: restricted __le16 degrades to >>> integer > > drivers/usb/common/debug.c:254:25: warning: restricted __le16 degrades to > integer > > drivers/usb/common/debug.c:255:25: warning: restricted __le16 degrades to > integer > > drivers/usb/common/debug.c:256:25: warning: restricted __le16 degrades to > integer > > drivers/usb/common/debug.c:257:25: warning: restricted __le16 degrades to > integer > > drivers/usb/common/debug.c:258:25: warning: restricted __le16 degrades to > integer > > > >vim +253 drivers/usb/common/debug.c > > > >cefb8b21 Pawel Laszczak 2018-12-23 205 > >cefb8b21 Pawel Laszczak 2018-12-23 206 /** > >cefb8b21 Pawel Laszczak 2018-12-23 207 * usb_decode_ctrl - returns a string >representation of ctrl request > >cefb8b21 Pawel Laszczak 2018-12-23 208 */ > >cefb8b21 Pawel Laszczak 2018-12-23 209 const char *usb_decode_ctrl(char >*str, __u8 bRequestType, __u8 bRequest, > >cefb8b21 Pawel Laszczak 2018-12-23 210__u16 >wValue, __u16 wIndex, __u16 wLength) > >cefb8b21 Pawel Laszczak 2018-12-23 211 { > >cefb8b21 Pawel Laszczak 2018-12-23 212switch (bRequest) { > >cefb8b21 Pawel Laszczak 2018-12-23 213case USB_REQ_GET_STATUS: > >cefb8b21 Pawel Laszczak 2018-12-23 214 >usb_decode_get_status(bRequestType, wIndex, wLength, str); > >cefb8b21 Pawel Laszczak 2018-12-23 215break; > >cefb8b21 Pawel Laszczak 2018-12-23 216case USB_REQ_CLEAR_FEATURE: > >cefb8b21 Pawel Laszczak 2018-12-23 217case USB_REQ_SET_FEATURE: > >cefb8b21 Pawel Laszczak 2018-12-23 218 >usb_decode_set_clear_feature(bRequestType, bRequest, wValue, > >cefb8b21 Pawel Laszczak 2018-12-23 219 > wIndex, str); > >cefb8b21 Pawel Laszczak 2018-12-23 220break; > >cefb8b21 Pawel Laszczak 2018-12-23 221case USB_REQ_SET_ADDRESS: > >cefb8b21 Pawel Laszczak 2018-12-23 222
RE: [PATCH v1 1/2] dt-bindings: add binding for USBSS-DRD controller.
Hi Bob, >> >> >On Mon, Dec 10, 2018 at 12:39:14PM +, Pawel Laszczak wrote: >> >> This patch aim at documenting USB related dt-bindings for the >> >> Cadence USBSS-DRD controller. >> >> >> >> Signed-off-by: Pawel Laszczak > >[...] > >> >> + - phys: reference to the USB PHY >> >> + - phy-names: name of the USB PHY, should be "cdns3,usbphy" >> > >> >Don't need -names when there is only one. >> >> But in the future probably we will need to add next phy version. >> So maybe it's better to leave this name ? > >'-names' are for when there is more than one phy connected, not >different phy versions. For example, if you had separate phys for HS >and SS. > Thanks for the clarification. I will remove "-names" Cheers, Pawel
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Peter, > >> > >> >@@ -299,6 +306,7 @@ int cdns3_drd_init(struct cdns3 *cdns) >> >cdns->version = CDNS3_CONTROLLER_V0; >> >cdns->otg_v1_regs = NULL; >> >cdns->otg_regs = regs; >> >+ writel(0x1, >otg_v0_regs->simulate); >> >dev_info(cdns->dev, "DRD version v0 (%08x)\n", >> > readl(>otg_v0_regs->version)); >> >} else { >> >> I have confirmation from HW team that time that driver should wait after de- >> selecting mode is 2-3ms for simulate mode. It's time when FSM is in >> DRD_H_WAIT_VBUS_FAIL. >> Driver cannot re-enable the host/device mode before this time has elapsed. >> >> 3 ms is the maximum time. Additionally, you can confirm the current FSM >> state by >> reading the host_otg_state (bit 5:3) or dev_otg_state (2:0) from OTGSTATE >> register. >> >> If bit 0 in simulate register is cleared the time is exactly 1s. >> > >Thanks, Pawel. > >Would you please add below changes in your next revision? >- Set bit 0 in simulate register But it's used only for simulation environments to speed up simulation. On real platforms this bit should be cleared. I'm not sure if I can add some code related to simulation environment to driver. If yes then I must introduce the way, that allow to recognize this two modes. I could add module parameter or add additional config in Kconfig file. >- timeout logic for waiting host_otg_state or dev_otg_state at OTGSTATE >when switch to host or device. I will add such code. Pawel
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
HI, >> >> The host side of USBSS-DRD controller is compliance >> with XHCI specification, so it works with >> standard XHCI linux driver. >> > >After adding my glue layer change (with my phy part) and make one >change for this code, >the xHCI can work at my platform. I list the comments from today's >review and debug. >The comments are at Makefile and drd.c. > >> + If you choose to build this driver as module it will >> + be dynamically linked and module will be called cdns3-pci.ko >> + >> +endif >> diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile >> new file mode 100644 >> index ..3f63baa24294 >> --- /dev/null >> +++ b/drivers/usb/cdns3/Makefile >> @@ -0,0 +1,16 @@ >> +# SPDX-License-Identifier: GPL-2.0 >> +# define_trace.h needs to know how to find our header >> +CFLAGS_trace.o := -I$(src) >> + >> +obj-$(CONFIG_USB_CDNS3)+= cdns3.o >> +obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o >> + >> +cdns3-y:= core.o drd.o trace.o >> + >> +ifneq ($(CONFIG_DEBUG_FS),) >> + cdns3-y += debugfs.o >> +endif >> + >> +cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o >> +cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o >> +cdns3-pci-y:= cdns3-pci-wrap.o > >Why do you want add two lines for pci_wrap? I change this Makefile like below: I don't need these two lines. I will change it as you suggested. > ># SPDX-License-Identifier: GPL-2.0 ># define_trace.h needs to know how to find our header >CFLAGS_trace.o := -I$(src) > >cdns3-y := core.o drd.o trace.o >obj-$(CONFIG_USB_CDNS3) += cdns3.o >ifneq ($(CONFIG_DEBUG_FS),) >cdns3-y += debugfs.o >endif > >cdns3-$(CONFIG_USB_CDNS3_GADGET)+= gadget.o ep0.o >cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o >obj-$(CONFIG_USB_CDNS3_PCI_WRAP)+= cdns3-pci-wrap.o >obj-$(CONFIG_USB_CDNS3_IMX_WRAP)+= cdns3-imx.o > >and below is the diff: > >diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile >index 3f63baa24294..d1bca2829f57 100644 >--- a/drivers/usb/cdns3/Makefile >+++ b/drivers/usb/cdns3/Makefile >@@ -2,15 +2,13 @@ > # define_trace.h needs to know how to find our header > CFLAGS_trace.o := -I$(src) > >-obj-$(CONFIG_USB_CDNS3)+= cdns3.o >-obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o >- > cdns3-y:= core.o drd.o trace.o >- >+obj-$(CONFIG_USB_CDNS3)+= cdns3.o > ifneq ($(CONFIG_DEBUG_FS),) >cdns3-y += debugfs.o > endif > > cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o > cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o >-cdns3-pci-y:= cdns3-pci-wrap.o >+obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci-wrap.o >+obj-$(CONFIG_USB_CDNS3_IMX_WRAP) += cdns3-imx.o > > >> diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c >> new file mode 100644 >> index ..b0c32302eb0b >> --- /dev/null >> +++ b/drivers/usb/cdns3/drd.c >> @@ -0,0 +1,350 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* >> + * Cadence USBSS DRD Driver. >> + * >> + * Copyright (C) 2018 Cadence. >> + * >> + * Author: Pawel Laszczak > + * >> + */ >> +#include >> +#include >> +#include >> +#include >> + >> +#include "gadget.h" >> +#include "drd.h" >> +#include "core.h" >> + >> +static int cdns3_drd_switch_gadget(struct cdns3 *cdns, int on); >> +static int cdns3_drd_switch_host(struct cdns3 *cdns, int on); >> + >> +/** >> + * cdns3_set_mode - change mode of OTG Core >> + * @cdns: pointer to context structure >> + * @mode: selected mode from cdns_role >> + */ >> +void cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) >> +{ >> + u32 reg; >> + >> + cdns->current_dr_mode = mode; >> + >> + switch (mode) { >> + case USB_DR_MODE_PERIPHERAL: >> + dev_info(cdns->dev, "Set controller to Gadget mode\n"); >> + cdns3_drd_switch_gadget(cdns, 1); >> + break; >> + case USB_DR_MODE_HOST: >> + dev_info(cdns->dev, "
RE: [PATCH v2 5/5] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >> > + >> > + if (ret) >> > + return ret; >> > + >> > + state = readl(>otg_regs->sts); >> > + if (OTGSTS_OTG_NRDY(state) != 0) { >> > + dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); >> > + return -ENODEV; >> > + } >> > + >> > + ret = cdns3_drd_update_mode(cdns); >> > + >> >> Calling this function, it is timeout for waiting OTGSTS_XHCI_READY at otgsts, >> do you know possible reasons? After commenting out this function, my >> xHCI function >> works. >> > >Pawel, since OTG compliance (Known as HNP/SRP) has not been used >widely, Linux kernel does not >maintain it from some time ago (maybe 1-2 years). In software design, >we do not need to consider it from >hardware point, eg, kinds of OTG timer. For dual-role switch on the >fly, through /sys is enough. > >Through the debug, we find it needs to wait 1s after setting de-select >the host or gadget before request >XHCI at otg_regs->cmd, and enable fast simulate can reduce delay to >2-3ms. Would you please help >to check with your hardware team this behavior. With below changes, I >can get OTGSTS_XHCI_READY at otgsts. > >@@ -141,6 +143,7 @@ static int cdns3_drd_switch_host(struct cdns3 *cdns, int >on) >writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | > OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, > >otg_regs->cmd); >+ usleep_range(3000, 4000); >} > >return 0; >@@ -178,6 +181,7 @@ static int cdns3_drd_switch_gadget(struct cdns3 >*cdns, int on) >writel(OTGCMD_HOST_BUS_DROP | OTGCMD_DEV_BUS_DROP | > OTGCMD_DEV_POWER_OFF | OTGCMD_HOST_POWER_OFF, > >otg_regs->cmd); >+ usleep_range(3000, 4000); >} > >@@ -299,6 +306,7 @@ int cdns3_drd_init(struct cdns3 *cdns) >cdns->version = CDNS3_CONTROLLER_V0; >cdns->otg_v1_regs = NULL; >cdns->otg_regs = regs; >+ writel(0x1, >otg_v0_regs->simulate); >dev_info(cdns->dev, "DRD version v0 (%08x)\n", > readl(>otg_v0_regs->version)); >} else { I have confirmation from HW team that time that driver should wait after de-selecting mode is 2-3ms for simulate mode. It's time when FSM is in DRD_H_WAIT_VBUS_FAIL. Driver cannot re-enable the host/device mode before this time has elapsed. 3 ms is the maximum time. Additionally, you can confirm the current FSM state by reading the host_otg_state (bit 5:3) or dev_otg_state (2:0) from OTGSTATE register. If bit 0 in simulate register is cleared the time is exactly 1s. Cheers, Pawel
[PATCH v2 3/5] usb:common Patch simplify usb_decode_set_clear_feature function.
Patch adds usb_decode_test_mode and usb_decode_device_feature functions, which allow to make more readable and simplify the usb_decode_set_clear_feature function. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 83 ++ 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index 374fb9e94f37..77e565a38f29 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -29,6 +29,44 @@ static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, } } +static const char *usb_decode_device_feature(u16 wValue) +{ + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + return "Self Powered"; + case USB_DEVICE_REMOTE_WAKEUP: + return "Remote Wakeup"; + case USB_DEVICE_TEST_MODE: + return "Test Mode"; + case USB_DEVICE_U1_ENABLE: + return "U1 Enable"; + case USB_DEVICE_U2_ENABLE: + return "U2 Enable"; + case USB_DEVICE_LTM_ENABLE: + return "LTM Enable"; + default: + return "UNKNOWN"; + } +} + +static const char *usb_decode_test_mode(u16 wIndex) +{ + switch (wIndex) { + case TEST_J: + return ": TEST_J"; + case TEST_K: + return ": TEST_K"; + case TEST_SE0_NAK: + return ": TEST_SE0_NAK"; + case TEST_PACKET: + return ": TEST_PACKET"; + case TEST_FORCE_EN: + return ": TEST_FORCE_EN"; + default: + return ": UNKNOWN"; + } +} + static void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, char *str) @@ -37,50 +75,9 @@ static void usb_decode_set_clear_feature(__u8 bRequestType, case USB_RECIP_DEVICE: sprintf(str, "%s Device Feature(%s%s)", bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", - ({char *s; - switch (wValue) { - case USB_DEVICE_SELF_POWERED: - s = "Self Powered"; - break; - case USB_DEVICE_REMOTE_WAKEUP: - s = "Remote Wakeup"; - break; - case USB_DEVICE_TEST_MODE: - s = "Test Mode"; - break; - case USB_DEVICE_U1_ENABLE: - s = "U1 Enable"; - break; - case USB_DEVICE_U2_ENABLE: - s = "U2 Enable"; - break; - case USB_DEVICE_LTM_ENABLE: - s = "LTM Enable"; - break; - default: - s = "UNKNOWN"; - } s; }), + usb_decode_device_feature(wValue), wValue == USB_DEVICE_TEST_MODE ? - ({ char *s; - switch (wIndex) { - case TEST_J: - s = ": TEST_J"; - break; - case TEST_K: - s = ": TEST_K"; - break; - case TEST_SE0_NAK: - s = ": TEST_SE0_NAK"; - break; - case TEST_PACKET: - s = ": TEST_PACKET"; - break; - case TEST_FORCE_EN: - s = ": TEST_FORCE_EN"; - break; - default: - s = ": UNKNOWN"; - } s; }) : ""); + usb_decode_test_mode(wIndex) : ""); break; case USB_RECIP_INTERFACE: sprintf(str, "%s Interface Feature(%s)", -- 2.17.1
[PATCH v2 4/5] usb:common Simplify usb_decode_get_set_descriptor function.
Patch moves switch responsible for decoding descriptor type outside snprintf. It's little improves code readability. Signed-off-by: Pawel Laszczak --- drivers/usb/common/debug.c | 111 +++-- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c index 77e565a38f29..c15fa066339c 100644 --- a/drivers/usb/common/debug.c +++ b/drivers/usb/common/debug.c @@ -104,62 +104,65 @@ static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str) { + char *s; + + switch (wValue >> 8) { + case USB_DT_DEVICE: + s = "Device"; + break; + case USB_DT_CONFIG: + s = "Configuration"; + break; + case USB_DT_STRING: + s = "String"; + break; + case USB_DT_INTERFACE: + s = "Interface"; + break; + case USB_DT_ENDPOINT: + s = "Endpoint"; + break; + case USB_DT_DEVICE_QUALIFIER: + s = "Device Qualifier"; + break; + case USB_DT_OTHER_SPEED_CONFIG: + s = "Other Speed Config"; + break; + case USB_DT_INTERFACE_POWER: + s = "Interface Power"; + break; + case USB_DT_OTG: + s = "OTG"; + break; + case USB_DT_DEBUG: + s = "Debug"; + break; + case USB_DT_INTERFACE_ASSOCIATION: + s = "Interface Association"; + break; + case USB_DT_BOS: + s = "BOS"; + break; + case USB_DT_DEVICE_CAPABILITY: + s = "Device Capability"; + break; + case USB_DT_PIPE_USAGE: + s = "Pipe Usage"; + break; + case USB_DT_SS_ENDPOINT_COMP: + s = "SS Endpoint Companion"; + break; + case USB_DT_SSP_ISOC_ENDPOINT_COMP: + s = "SSP Isochronous Endpoint Companion"; + break; + default: + s = "UNKNOWN"; + break; + } + sprintf(str, "%s %s Descriptor(Index = %d, Length = %d)", bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set", - ({ char *s; - switch (wValue >> 8) { - case USB_DT_DEVICE: - s = "Device"; - break; - case USB_DT_CONFIG: - s = "Configuration"; - break; - case USB_DT_STRING: - s = "String"; - break; - case USB_DT_INTERFACE: - s = "Interface"; - break; - case USB_DT_ENDPOINT: - s = "Endpoint"; - break; - case USB_DT_DEVICE_QUALIFIER: - s = "Device Qualifier"; - break; - case USB_DT_OTHER_SPEED_CONFIG: - s = "Other Speed Config"; - break; - case USB_DT_INTERFACE_POWER: - s = "Interface Power"; - break; - case USB_DT_OTG: - s = "OTG"; - break; - case USB_DT_DEBUG: - s = "Debug"; - break; - case USB_DT_INTERFACE_ASSOCIATION: - s = "Interface Association"; - break; - case USB_DT_BOS: - s = "BOS"; - break; - case USB_DT_DEVICE_CAPABILITY: - s = "Device Capability"; - break; - case USB_DT_PIPE_USAGE: - s = "Pipe Usage"; - break; - case USB_DT_SS_ENDPOINT_COMP: - s = "SS Endpoint Companion"; - break; -
[PATCH v2 2/5] usb:common Separated decoding functions from dwc3 driver.
Patch moves some decoding functions from driver/usb/dwc3/debug.h driver to driver/usb/common/debug.c file. These moved functions include: dwc3_decode_get_status dwc3_decode_set_clear_feature dwc3_decode_set_address dwc3_decode_get_set_descriptor dwc3_decode_get_configuration dwc3_decode_set_configuration dwc3_decode_get_intf dwc3_decode_set_intf dwc3_decode_synch_frame dwc3_decode_set_sel dwc3_decode_set_isoch_delay dwc3_decode_ctrl These functions are used also in inroduced cdns3 driver. All functions prefixes were changed from dwc3 to usb. Also, function's parameters has been extended according to the name of fields in standard SETUP packet. Additionally, patch adds usb_decode_ctrl function to include/linux/usb/ch9.h file. mend Signed-off-by: Pawel Laszczak --- drivers/usb/common/Makefile | 2 +- drivers/usb/common/debug.c | 265 drivers/usb/dwc3/debug.h| 243 - drivers/usb/dwc3/trace.h| 2 +- include/linux/usb/ch9.h | 19 +++ 5 files changed, 286 insertions(+), 245 deletions(-) create mode 100644 drivers/usb/common/debug.c diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile index fb4d5ef4165c..3d3d2962ea4b 100644 --- a/drivers/usb/common/Makefile +++ b/drivers/usb/common/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_USB_COMMON) += usb-common.o -usb-common-y += common.o +usb-common-y += common.o debug.o usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o diff --git a/drivers/usb/common/debug.c b/drivers/usb/common/debug.c new file mode 100644 index ..374fb9e94f37 --- /dev/null +++ b/drivers/usb/common/debug.c @@ -0,0 +1,265 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * Common USB debugging functions + * + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com + * + * Authors: Felipe Balbi , + * Sebastian Andrzej Siewior + */ + +#ifndef __LINUX_USB_COMMON_DEBUG +#define __LINUX_USB_COMMON_DEBUG + +#include + +static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, + __u16 wLength, char *str) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_INTERFACE: + sprintf(str, "Get Interface Status(Intf = %d, Length = %d)", + wIndex, wLength); + break; + case USB_RECIP_ENDPOINT: + sprintf(str, "Get Endpoint Status(ep%d%s)", + wIndex & ~USB_DIR_IN, + wIndex & USB_DIR_IN ? "in" : "out"); + break; + } +} + +static void usb_decode_set_clear_feature(__u8 bRequestType, +__u8 bRequest, __u16 wValue, +__u16 wIndex, char *str) +{ + switch (bRequestType & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + sprintf(str, "%s Device Feature(%s%s)", + bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set", + ({char *s; + switch (wValue) { + case USB_DEVICE_SELF_POWERED: + s = "Self Powered"; + break; + case USB_DEVICE_REMOTE_WAKEUP: + s = "Remote Wakeup"; + break; + case USB_DEVICE_TEST_MODE: + s = "Test Mode"; + break; + case USB_DEVICE_U1_ENABLE: + s = "U1 Enable"; + break; + case USB_DEVICE_U2_ENABLE: + s = "U2 Enable"; + break; + case USB_DEVICE_LTM_ENABLE: + s = "LTM Enable"; + break; + default: + s = "UNKNOWN"; + } s; }), + wValue == USB_DEVICE_TEST_MODE ? + ({ char *s; + switch (wIndex) { + case TEST_J: + s = ": TEST_J"; + break; + case TEST_K: + s = ": TEST_K"; + break; +
[PATCH v2 0/5] Introduced new Cadence USBSS DRD Driver.
This patch set introduce new Cadence USBSS DRD driver to linux kernel. The Cadence USBSS DRD Driver s a highly configurable IP Core which can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI) configurations. The current driver has been validated with FPGA burned. We have support for PCIe bus, which is used on FPGA prototyping. The host site of USBSS controller is compliance with XHCI specification, so it works with standard XHCI linux driver. Changes since v1: - Removed not implemented Susped/Resume functions. - Fixed some issues in debugging related functions. - Added trace_cdns3_request_handled marker. - Added support for Isochronouse transfer. - Added some additional descriptions. - Fixed compilation error in cdns3_gadget_ep_disable. - Added detection of device controller version at runtime. - Upgraded dt-binding documentation. - Deleted ENOSYS from phy initialization section. It should be also removed from generic PHY driver. - added ep0_stage flag used during enumeration process. - Fixed issue with TEST MODE. - Added one common function for finish control transfer. - Separated some decoding function from dwc3 driver to common library file, and removed equivalents function from debug.h file as suggested by Felipe. - replaced function name cdns3_gadget_unconfig with cdns3_hw_reset_eps_config. - Improved algorithm fixing hardware issue related to blocking endpoints. This issue is related to on-chip shared FIFO buffers for OUT packets. Problem was reported by Peter Chan. - Changed organization of endpoint array in cdns3_device object. - added ep0 to common eps array - removed cdns3_free_trb_pool and cdns3_ep_addr_to_bit_pos macros. - removed ep0_trb_dma, ep0_trb fields from cdns3_device. - Removed ep0_request and ep_nums fields from cdns3_device. - Other minor changes according with Felipe suggestion. --- Pawel Laszczak (5): dt-bindings: add binding for USBSS-DRD controller. usb:common Separated decoding functions from dwc3 driver. usb:common Patch simplify usb_decode_set_clear_feature function. usb:common Simplify usb_decode_get_set_descriptor function. usb:cdns3 Add Cadence USB3 DRD Driver .../devicetree/bindings/usb/cdns3-usb.txt | 30 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 16 + drivers/usb/cdns3/cdns3-pci-wrap.c| 157 ++ drivers/usb/cdns3/core.c | 406 drivers/usb/cdns3/core.h | 116 + drivers/usb/cdns3/debug.h | 166 ++ drivers/usb/cdns3/debugfs.c | 168 ++ drivers/usb/cdns3/drd.c | 350 +++ drivers/usb/cdns3/drd.h | 162 ++ drivers/usb/cdns3/ep0.c | 896 +++ drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadget.c| 2102 + drivers/usb/cdns3/gadget.h| 1206 ++ drivers/usb/cdns3/host-export.h | 28 + drivers/usb/cdns3/host.c | 72 + drivers/usb/cdns3/trace.c | 11 + drivers/usb/cdns3/trace.h | 389 +++ drivers/usb/common/Makefile |2 +- drivers/usb/common/debug.c| 265 +++ drivers/usb/dwc3/debug.h | 243 -- drivers/usb/dwc3/trace.h |2 +- include/linux/usb/ch9.h | 19 + 25 files changed, 6637 insertions(+), 245 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt create mode 100644 drivers/usb/cdns3/Kconfig create mode 100644 drivers/usb/cdns3/Makefile create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c create mode 100644 drivers/usb/cdns3/core.c create mode 100644 drivers/usb/cdns3/core.h create mode 100644 drivers/usb/cdns3/debug.h create mode 100644 drivers/usb/cdns3/debugfs.c create mode 100644 drivers/usb/cdns3/drd.c create mode 100644 drivers/usb/cdns3/drd.h create mode 100644 drivers/usb/cdns3/ep0.c create mode 100644 drivers/usb/cdns3/gadget-export.h create mode 100644 drivers/usb/cdns3/gadget.c create mode 100644 drivers/usb/cdns3/gadget.h create mode 100644 drivers/usb/cdns3/host-export.h create mode 100644 drivers/usb/cdns3/host.c create mode 100644 drivers/usb/cdns3/trace.c create mode 100644 drivers/usb/cdns3/trace.h create mode 100644 drivers/usb/common/debug.c -- 2.17.1
[PATCH v2 1/5] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak --- .../devicetree/bindings/usb/cdns3-usb.txt | 30 +++ 1 file changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt b/Documentation/devicetree/bindings/usb/cdns3-usb.txt new file mode 100644 index ..cf93bd0de5cb --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt @@ -0,0 +1,30 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +region 1 - HOST registers area +region 2 - DEVICE registers area +region 3 - OTG/DRD registers area + - compatible: Should contain: "cdns,usb3-1.0.0" or "cdns,usb3-1.0.1" + - interrupts: Interrupt specifier. Refer to interrupt bindings. + Driver supports only single interrupt line. +This single interrupt is shared between Device, + host and OTG/DRD part of driver. + +Optional properties: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + - phy-names: name of the USB PHY, should be "cdns3,usbphy" + + +Example: + usb@f300 { + compatible = "cdns,usb3"; + interrupts = ; + reg = <0xf300 0x1 /* memory area for HOST registers */ + 0xf301 0x1 /* memory area for DEVICE registers */ + 0xf302 0x1>;/* memory area for OTG/DRD registers */ + }; -- 2.17.1
RE: [PATCH v1 1/2] dt-bindings: add binding for USBSS-DRD controller.
Hi Rob, >On Mon, Dec 10, 2018 at 12:39:14PM +0000, Pawel Laszczak wrote: >> This patch aim at documenting USB related dt-bindings for the >> Cadence USBSS-DRD controller. >> >> Signed-off-by: Pawel Laszczak >> --- >> .../devicetree/bindings/usb/cdns3-usb.txt | 31 +++ >> 1 file changed, 31 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt >> >> diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> new file mode 100644 >> index ..ae4a255f0b10 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt > >cdns-usb3.txt? In all functions we use prefix cdns3, so it was a reason for cdns3-usb.txt. I agree with you and I think that cdns-usb3.txt in this place will be better. 3 in cdns3 could be associated with company name, but that's not true. > >> @@ -0,0 +1,31 @@ >> +Binding for the Cadence USBSS-DRD controller >> + >> +Required properties: >> + - reg: Physical base address and size of the controller's register areas. >> + Controller has 3 different regions: >> + region 1 - HOST registers area >> + region 2 - DEVICE registers area >> + region 3 - OTG/DRD registers area >> + - compatible: Should contain: "cdns,usb3" > >Only 1 version of the IP block? I will add one more. Now I know that we should have at least one additional version. Controller version will be recognized at runtime, but in my opinion we should also have information about this in dt-binding documentation. > >> + - interrupts: Interrupt specifier. Refer to interrupt bindings. >> +Driver supports only single interrupt line. >> +This single interrupt is shared between Device, >> +host and OTG/DRD part of driver. >> + >> +Optional propertiesi: > >typo Thank, I know that already. Someone has already reported me this typo. "i" - insert mode in vim :) > >> + - maximum-speed : valid arguments are "super-speed", "high-speed" and >> + "full-speed"; refer to usb/generic.txt >> + - dr_mode: Should be one of "host", "peripheral" or "otg". >> + - phys: reference to the USB PHY >> + - phy-names: name of the USB PHY, should be "cdns3,usbphy" > >Don't need -names when there is only one. But in the future probably we will need to add next phy version. So maybe it's better to leave this name ? > >> + >> + >> +Example: >> +usb@f300 { >> +compatible = "cdns,usb3"; >> +interrupts = ; >> +reg = <0xf300 0x1 //memory area for HOST registers >> +0xf301 0x1 //memory area for DEVICE >> registers >> +0xf302 0x1>;//memory area for OTG/DRD >> registers >> +}; >> + >> -- >> 2.17.1 >> Thanks for comments Cheers, Pawel
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > +static irqreturn_t cdns3_device_irq_handler(int irq, void *data) +{ + struct cdns3_device *priv_dev; + struct cdns3 *cdns = data; + irqreturn_t ret = IRQ_NONE; + unsigned long flags; + u32 reg; + + priv_dev = cdns->gadget_dev; + spin_lock_irqsave(_dev->lock, flags); >>> >>>you're already running in hardirq context. Why do you need this lock at >>>all? I would be better to use the hardirq handler to mask your >>>interrupts, so they don't fire again, then used the top-half (softirq) >>>handler to actually handle the interrupts. >> >> Yes, spin_lock_irqsave is not necessary here. >> >> Do you mean replacing devm_request_irq with a request_threaded_irq ? >> I have single interrupt line shared between Host, Driver, DRD/OTG. >> I'm not sure if it will work more efficiently. > >The whole idea for running very little in hardirq context is to give the >scheduler a chance to decide what should run. This is important to >reduce latency when running with RT patchset applied, for >example. However, I'll give you that, it's a minor requirement. It's >just that, to me, it's a small detail that's easy to implement. I will do it in PATCH v2 or PATCH v3. I need to post next version before 24 of December, so if I can do it before this date then it will be in PATCH v2. Thanks Pawel
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Felipe > >Pawel Laszczak writes: > > >>>> + case USB_REQ_SET_ISOCH_DELAY: >>>> + sprintf(str, "Set Isochronous Delay Delay: %d ns", wValue); >>>> + break; >>>> + default: >>>> + sprintf(str, >>>> + "SETUP BRT: %02x BR: %02x V: %04x I: %04x L: %04x\n", >>>> + bRequestType, bRequest, >>>> + wValue, wIndex, wLength); >>>> + } >>>> + >>>> + return str; >>>> +} >>> >>>All of these are a flat out copy of dwc3's implementation. It's much, >>>much better to turn dwc3's implementation into a generic, reusable >>>library function then spinning your own as a duplicated effort. >> I agree, >> It would be nice to have a set of decoding function in some generic >> library. It could be used >> also by other drivers. >> Who should do this ? > >since you're the first to reuse it, then it should be you :-) So I can prepare debug.h in drivers/usb/gadget directory. Function form drivers/usb/dwc3/debug.h that could be common are: static inline void dwc3_decode_get_status(__u8 t, __u16 i, __u16 l, char *str) static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v, __u16 i, __u16 l, char *str) static inline void dwc3_decode_set_clear_feature(__u8 t, __u8 b, __u16 v, __u16 i, char *str) static inline void dwc3_decode_set_address(__u16 v, char *str) static inline void dwc3_decode_get_set_descriptor(__u8 t, __u8 b, __u16 v, __u16 i, __u16 l, char *str) static inline void dwc3_decode_get_configuration(__u16 l, char *str) static inline void dwc3_decode_set_configuration(__u8 v, char *str) static inline void dwc3_decode_get_intf(__u16 i, __u16 l, char *str) static inline void dwc3_decode_set_intf(__u8 v, __u16 i, char *str) static inline void dwc3_decode_synch_frame(__u16 i, __u16 l, char *str) static inline const char *dwc3_decode_ctrl(char *str, __u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength) After changed it could looks like: static inline void usb_decode_get_status(__u8 bRequestType, __u16 wIndex, __u16 wLength, char *str) static inline void usb _decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str) static inline void usb_decode_set_clear_feature(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, char *str) static inline void usb_decode_set_address(__u16 v, char *str) static inline void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength, char *str) static inline void usb_decode_get_configuration(__u16 wLength, char *str) static inline void usb_decode_set_configuration(__u8 wValue, char *str) static inline void usb_decode_get_intf(__u16 wIndex, __u16 wLength, char *str) static inline void usb_decode_set_intf(__u8 wValue, __u16 wIndex, char *str) static inline void usb_decode_synch_frame(__u16 wIndex, __u16 wLength, char *str) static inline const char * usb _decode_ctrl(char *str, __u8 bRequestType, __u8 bRequest, __u16 wValue, __u16 wIndex, __u16 wLength) Sorry but I prefer some more significant names :) For me functions in drivers/usb/dwc3/debug.h looks ok, but I think that could be better to add additional usb_decode_test_mode and usb_decode_device_feature and little simplify usb_decode_get_set_descriptor. What do you think about this? One more question. Can I add drivers/usb/gadget/debug.h file as part of my set patches, or this should be done as separate, new patch ? Cheers, Pawel
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > >On 12/12/18 12:22 PM, Felipe Balbi wrote: >> >> Hi >> >> Pawel Laszczak writes: >>>>> + cdns->phy = devm_phy_get(dev, "cdns3,usbphy"); >>>>> + if (IS_ERR(cdns->phy)) { >>>>> + ret = PTR_ERR(cdns->phy); >>>>> + if (ret == -ENOSYS || ret == -ENODEV) { >>>> >>>> Are you sure you can get ENOSYS here? Have you checked output of >>>> checkpatch --strict? >>>> -:852: WARNING: ENOSYS means 'invalid syscall nr' and nothing else >>> >>> Yes this error code can be returned by related to phy function if >>> CONFIG_GENERIC_PHY is disabled. >>> >>> I have seen this warning in output of checkpatch --strict . >> >> Kishon, seems like you shouldn't be using that error value. > >hmm, yeah should change the return value to -ENODEV when GENERIC_PHY is >disabled. > So I will remove this ENOSYS from next patch. I assume that it will be removed also from generic phy driver. Thanks, Pawel
RE: [RFC PATCH v2 08/15] usb:cdns3: Implements device operations part of the API
Hi > >On 14/12/18 4:56 PM, Felipe Balbi wrote: >> Hi, >> >> Sekhar Nori writes: All this should be part of comments in code along with information about controller versions which suffer from the errata. Is there a version of controller available which does not have the defect? Is there a future plan to fix this? If any of that is yes, you probably want to handle this with runtime detection of version (like done with DWC3_REVISION_XXX macros). Sometimes the hardware-read versions themselves are incorrect, so its better to introduce a version specific compatible too like "cdns,usb-1.0.0" (as hinted to by Rob Herring as well). >>> >>> custom match_ep is used and works with all versions of the gen1 >>> controller. Future (gen2) releases of the controller won’t have such >>> limitation but there is no plan to change current (gen1) functionality >>> of the controller. >>> >>> I will add comment before cdns3_gadget_match_ep function. >>> Also I will change cdns,usb3 to cdns,usb3-1.0.0 and add additional >>> cdns,usb3-1.0.1 compatible. >>> >>> cdns,usb3-1.0.1 will be for current version of controller which I use. >>> cdns,usb3-1.0.0 will be for older version - Peter Chan platform. >>> I now that I have some changes in controller, and one of them require >>> some changes in DRD driver. It will be safer to add two separate >>> version in compatibles. >>> >> >> Pawel, could we have correct register to show controller version? It is >> better we could version judgement at runtime instead of static >> compatible. > > Agree with detecting IP version at runtime. > > But please have some indication of version in compatible string too, why? Runtime detection by revision register should be the way to go if the HW provides it. Why duplicate the information in compatible string? > especially since you already know there is going to be another revision > of hardware. It has the advantage that one can easily grep to see which > hardware is running current version of controller without having access > to the hardware itself. Becomes useful later on when its time to > clean-up unused code when boards become obsolete or for requesting > testing help. This doesn't sound like a very strong argument, actually. Specially when you consider that, since driver will do revision checking based on revision register, you already have strings to grep. Moreover, we don't usually drop support just like that. >>> >>> AFAICS, it is impossible to know just by grep'ing if there is any >>> hardware still supported in kernel and using DWC3_REVISION_194A, for >>> example. >> >> but why do you even care? > >When, for example, its coming in the way of some clean-up I am >attempting to do. > >> >>> If we are never going to drop support for any revision, this does not >>> matter much. >>> >>> Also, once you have the controller supported behind PCI, then I guess >>> you are pretty much tied to having to read hardware revision at runtime. >> >> that's another argument *for* using runtime detection, not against it. > >I know :). I should have stated that in last e-mail itself, I am okay >with just runtime detection. I agree with you. Controller has usb_cap6 register that keep device controller version. It's not a problem doing such detection at runtime. I will do it in this way. But also I will add extra compatible to dt-binding. Even if this will not be used in driver, it informs that there are several versions of controller. Thanks, Pawel
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi Peter >On Mon, Dec 10, 2018 at 8:55 PM Pawel Laszczak wrote: >> >> This patch introduce new Cadence USBSS DRD driver >> to linux kernel. >> >> The Cadence USBSS DRD Driver is a highly >> configurable IP Core which can be >> instantiated as Dual-Role Device (DRD), >> Peripheral Only and Host Only (XHCI) >> configurations. >> >> The current driver has been validated with >> FPGA burned. We have support for PCIe >> bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance >> with XHCI specification, so it works with >> standard XHCI linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- > >I have compiled it at my ARM64 platform, and will give you more feedback after >adding platform support. Below is one compile warning, please fix > > CC drivers/usb/cdns3/host.o > AR drivers/usb/cdns3/cdns3-pci.o >/home/b29397/work/projects/linux-imx/drivers/usb/cdns3/gadget.c: In >function ‘cdns3_gadget_ep_disable’: >/home/b29397/work/projects/linux-imx/drivers/usb/cdns3/gadget.c:1122:19: >warning: ‘priv_dev’ may be used uninitialized in this function >[-Wmaybe-uninitialized] > dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); > ^~ > AR drivers/usb/cdns3/cdns3.o > I found this also. Some time ago I changed pr_err("usbss: invalid parameters\n"); to dev_err(priv_dev->dev, "usbss: invalid parameters\n"); In cdns3_gadget_ep_disable function and it was mistake. I don't know why I didn't see this warning before posting patch. Cheers Pawel
RE: [RFC PATCH v2 08/15] usb:cdns3: Implements device operations part of the API
Hi, > >On Wed, Dec 12, 2018 at 3:49 AM Pawel Laszczak wrote: >> >> Hi, >> >> >On 10/12/18 7:42 AM, Peter Chen wrote: >> >>>> +static struct usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, >> >>>> + struct >> >>>> usb_endpoint_descriptor *desc, >> >>>> + struct >> >>>> usb_ss_ep_comp_descriptor *comp_desc) >> >>>> +{ >> >>>> + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); >> >>>> + struct cdns3_endpoint *priv_ep; >> >>>> + unsigned long flags; >> >>>> + >> >>>> + priv_ep = cdns3_find_available_ss_ep(priv_dev, desc); >> >>>> + if (IS_ERR(priv_ep)) { >> >>>> + dev_err(_dev->dev, "no available ep\n"); >> >>>> + return NULL; >> >>>> + } >> >>>> + >> >>>> + dev_dbg(_dev->dev, "match endpoint: %s\n", priv_ep->name); >> >>>> + >> >>>> + spin_lock_irqsave(_dev->lock, flags); >> >>>> + priv_ep->endpoint.desc = desc; >> >>>> + priv_ep->dir = usb_endpoint_dir_in(desc) ? USB_DIR_IN : >> >>>> USB_DIR_OUT; >> >>>> + priv_ep->type = usb_endpoint_type(desc); >> >>>> + >> >>>> + list_add_tail(_ep->ep_match_pending_list, >> >>>> + _dev->ep_match_list); >> >>>> + spin_unlock_irqrestore(_dev->lock, flags); >> >>>> + return _ep->endpoint; >> >>>> +} >> >>> Why do you need a custom match_ep? >> >>> doesn't usb_ep_autoconfig suffice? >> >>> >> >>> You can check if EP is claimed or not by checking the ep->claimed flag. >> >>> >> >> It is a special requirement for this IP, the EP type and MaxPacketSize >> >> changing can't be done at runtime, eg, at ep->enable. See below commit >> >> for detail. >> >> >> >> usb: cdns3: gadget: configure all endpoints before set configuration >> >> >> >> Cadence IP has one limitation that all endpoints must be configured >> >> (Type & MaxPacketSize) before setting configuration through hardware >> >> register, it means we can't change endpoints configuration after >> >> set_configuration. >> >> >> >> In this patch, we add non-control endpoint through >> >> usb_ss->ep_match_list, >> >> which is added when the gadget driver uses usb_ep_autoconfig to >> >> configure >> >> specific endpoint; When the udc driver receives set_configurion >> >> request, >> >> it goes through usb_ss->ep_match_list, and configure all endpoints >> >> accordingly. >> >> >> >> At usb_ep_ops.enable/disable, we only enable and disable endpoint >> >> through >> >> ep_cfg register which can be changed after set_configuration, and do >> >> some software operation accordingly. >> > >> >All this should be part of comments in code along with information about >> >controller versions which suffer from the errata. >> > >> >Is there a version of controller available which does not have the >> >defect? Is there a future plan to fix this? >> > >> >If any of that is yes, you probably want to handle this with runtime >> >detection of version (like done with DWC3_REVISION_XXX macros). >> >Sometimes the hardware-read versions themselves are incorrect, so its >> >better to introduce a version specific compatible too like >> >"cdns,usb-1.0.0" (as hinted to by Rob Herring as well). >> > >> >> custom match_ep is used and works with all versions of the gen1 >> controller. Future (gen2) releases of the controller won’t have such >> limitation but there is no plan to change current (gen1) functionality >> of the controller. >> >> I will add comment before cdns3_gadget_match_ep function. >> Also I will change cdns,usb3 to cdns,usb3-1.0.0 and add additional >> cdns,usb3-1.0.1 compatible. >> >> cdns,usb3-1.0.1 will be for current version of controller which I use. >> cdns,usb3-1.0.0 will be for older version - Peter Chan platform. >> I now that I have some changes in controller, and one of them require >> some changes in DRD driver. It will be safer to add two separate >> version in compatibles. >> > >Pawel, could we have correct register to show controller version? It is >better we could version judgement at runtime instead of static compatible. > Ok, I will tray do this in this way. Pawel
RE: [PATCH v1 1/2] dt-bindings: add binding for USBSS-DRD controller.
Hi, >On Tue, Dec 11, 2018 at 6:19 PM Roger Quadros wrote: >> >> Pawel, >> >> On 10/12/18 14:39, Pawel Laszczak wrote: >> > This patch aim at documenting USB related dt-bindings for the >> > Cadence USBSS-DRD controller. >> > >> > Signed-off-by: Pawel Laszczak >> > --- >> > .../devicetree/bindings/usb/cdns3-usb.txt | 31 +++ >> > 1 file changed, 31 insertions(+) >> > create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt >> > >> > diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> > b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> > new file mode 100644 >> > index ..ae4a255f0b10 >> > --- /dev/null >> > +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> > @@ -0,0 +1,31 @@ >> > +Binding for the Cadence USBSS-DRD controller >> > + >> > +Required properties: >> > + - reg: Physical base address and size of the controller's register >> > areas. >> > + Controller has 3 different regions: >> > + region 1 - HOST registers area >> > + region 2 - DEVICE registers area >> > + region 3 - OTG/DRD registers area >> > + - compatible: Should contain: "cdns,usb3" >> > + - interrupts: Interrupt specifier. Refer to interrupt bindings. >> > + Driver supports only single interrupt line. >> > +This single interrupt is shared between Device, >> > + host and OTG/DRD part of driver. >> > + >> > +Optional propertiesi: >> >> s/propertiesi/properties >> >> > + - maximum-speed : valid arguments are "super-speed", "high-speed" and >> > + "full-speed"; refer to usb/generic.txt >> > + - dr_mode: Should be one of "host", "peripheral" or "otg". >> > + - phys: reference to the USB PHY >> > + - phy-names: name of the USB PHY, should be "cdns3,usbphy" >> > + >> > + >> > +Example: >> > + usb@f300 { >> > + compatible = "cdns,usb3"; >> > + interrupts = ; >> > + reg = <0xf300 0x1 //memory area for HOST >> > registers >> > + 0xf301 0x1 //memory area for DEVICE >> > registers >> > + 0xf302 0x1>;//memory area for OTG/DRD >> > registers >> >> Use "/* */" instead. >> >> > + }; >> > + >> > > >When running git am to apply patch, it has below warning, please fix them. > >Applying: dt-bindings: add binding for USBSS-DRD controller. >.git/rebase-apply/patch:42: new blank line at EOF. >+ >warning: 1 line adds whitespace errors. Ok, thanks Cheers Pawel
RE: [RFC PATCH v2 08/15] usb:cdns3: Implements device operations part of the API
Hi, >On 10/12/18 7:42 AM, Peter Chen wrote: +static struct usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, + struct usb_endpoint_descriptor *desc, + struct usb_ss_ep_comp_descriptor *comp_desc) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + struct cdns3_endpoint *priv_ep; + unsigned long flags; + + priv_ep = cdns3_find_available_ss_ep(priv_dev, desc); + if (IS_ERR(priv_ep)) { + dev_err(_dev->dev, "no available ep\n"); + return NULL; + } + + dev_dbg(_dev->dev, "match endpoint: %s\n", priv_ep->name); + + spin_lock_irqsave(_dev->lock, flags); + priv_ep->endpoint.desc = desc; + priv_ep->dir = usb_endpoint_dir_in(desc) ? USB_DIR_IN : USB_DIR_OUT; + priv_ep->type = usb_endpoint_type(desc); + + list_add_tail(_ep->ep_match_pending_list, + _dev->ep_match_list); + spin_unlock_irqrestore(_dev->lock, flags); + return _ep->endpoint; +} >>> Why do you need a custom match_ep? >>> doesn't usb_ep_autoconfig suffice? >>> >>> You can check if EP is claimed or not by checking the ep->claimed flag. >>> >> It is a special requirement for this IP, the EP type and MaxPacketSize >> changing can't be done at runtime, eg, at ep->enable. See below commit >> for detail. >> >> usb: cdns3: gadget: configure all endpoints before set configuration >> >> Cadence IP has one limitation that all endpoints must be configured >> (Type & MaxPacketSize) before setting configuration through hardware >> register, it means we can't change endpoints configuration after >> set_configuration. >> >> In this patch, we add non-control endpoint through usb_ss->ep_match_list, >> which is added when the gadget driver uses usb_ep_autoconfig to configure >> specific endpoint; When the udc driver receives set_configurion request, >> it goes through usb_ss->ep_match_list, and configure all endpoints >> accordingly. >> >> At usb_ep_ops.enable/disable, we only enable and disable endpoint through >> ep_cfg register which can be changed after set_configuration, and do >> some software operation accordingly. > >All this should be part of comments in code along with information about >controller versions which suffer from the errata. > >Is there a version of controller available which does not have the >defect? Is there a future plan to fix this? > >If any of that is yes, you probably want to handle this with runtime >detection of version (like done with DWC3_REVISION_XXX macros). >Sometimes the hardware-read versions themselves are incorrect, so its >better to introduce a version specific compatible too like >"cdns,usb-1.0.0" (as hinted to by Rob Herring as well). > custom match_ep is used and works with all versions of the gen1 controller. Future (gen2) releases of the controller won’t have such limitation but there is no plan to change current (gen1) functionality of the controller. I will add comment before cdns3_gadget_match_ep function. Also I will change cdns,usb3 to cdns,usb3-1.0.0 and add additional cdns,usb3-1.0.1 compatible. cdns,usb3-1.0.1 will be for current version of controller which I use. cdns,usb3-1.0.0 will be for older version - Peter Chan platform. I now that I have some changes in controller, and one of them require some changes in DRD driver. It will be safer to add two separate version in compatibles. Thanks Pawel
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, > >Pawel Laszczak writes: >> +static int cdns3_probe(struct platform_device *pdev) >> +{ >> +struct device *dev = >dev; >> +struct resource *res; >> +struct cdns3 *cdns; >> +void __iomem *regs; >> +int ret; >> + >> +cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); >> +if (!cdns) >> +return -ENOMEM; >> + >> +cdns->dev = dev; >> + >> +platform_set_drvdata(pdev, cdns); >> + >> +res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); >> +if (!res) { >> +dev_err(dev, "missing IRQ\n"); >> +return -ENODEV; >> +} >> +cdns->irq = res->start; >> + >> +cdns->xhci_res[0] = *res; >> + >> +/* >> + * Request memory region >> + * region-0: xHCI >> + * region-1: Peripheral >> + * region-2: OTG registers >> + */ >> +res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >> +cdns->xhci_res[1] = *res; >> + >> +res = platform_get_resource(pdev, IORESOURCE_MEM, 1); >> +regs = devm_ioremap_resource(dev, res); >> +if (IS_ERR(regs)) >> +return PTR_ERR(regs); >> +cdns->dev_regs = regs; >> + >> +res = platform_get_resource(pdev, IORESOURCE_MEM, 2); >> +regs = devm_ioremap_resource(dev, res); >> +if (IS_ERR(regs)) >> +return PTR_ERR(regs); >> +cdns->otg_regs = regs; >> + >> +mutex_init(>mutex); >> + >> +cdns->phy = devm_phy_get(dev, "cdns3,usbphy"); >> +if (IS_ERR(cdns->phy)) { >> +ret = PTR_ERR(cdns->phy); >> +if (ret == -ENOSYS || ret == -ENODEV) { > >Are you sure you can get ENOSYS here? Have you checked output of >checkpatch --strict? Yes this error code can be returned by related to phy function if CONFIG_GENERIC_PHY is disabled. I have seen this warning in output of checkpatch --strict . > >-:852: WARNING: ENOSYS means 'invalid syscall nr' and nothing else > >> +#ifdef CONFIG_PM_SLEEP >> +static int cdns3_suspend(struct device *dev) >> +{ >> +/* TODO: Implements this function. */ >> +return 0; >> +} >> + >> +static int cdns3_resume(struct device *dev) >> +{ >> +/* TODO: Implements this function. */ >> +return 0; >> +} >> +#endif /* CONFIG_PM_SLEEP */ >> +static int cdns3_runtime_suspend(struct device *dev) >> +{ /* TODO: Implements this function. */ >> +return 0; >> +} >> + >> +static int cdns3_runtime_resume(struct device *dev) >> +{ >> +/* TODO: Implements this function. */ >> +return 0; >> +} >> +#endif /* CONFIG_PM */ > >please no TODO stubs. Just get rid of your dev_pm_ops if you don't >implement them. Come up with a later patch adding a proper >implementation for PM. Ok. > >> +static int __init cdns3_driver_platform_register(void) >> +{ >> +return platform_driver_register(_driver); >> +} >> +module_init(cdns3_driver_platform_register); >> + >> +static void __exit cdns3_driver_platform_unregister(void) >> +{ >> +platform_driver_unregister(_driver); >> +} >> +module_exit(cdns3_driver_platform_unregister); > >module_platform_driver() Ok, > >> diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/debug.h >> new file mode 100644 >> index ..afb81d224718 >> --- /dev/null >> +++ b/drivers/usb/cdns3/debug.h >> @@ -0,0 +1,346 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +/* >> + * Cadence USBSS DRD Driver. >> + * Debug header file. >> + * >> + * Copyright (C) 2018 Cadence. >> + * >> + * Author: Pawel Laszczak >> + */ >> +#ifndef __LINUX_CDNS3_DEBUG >> +#define __LINUX_CDNS3_DEBUG >> +#include "gadget.h" >> + >> +static inline void cdns3_decode_get_status(u8 bRequestType, u16 wIndex, >> + u16 wLength, char *str) >> +{ >> +switch (bRequestType & USB_RECIP_MASK) { >> +case USB_RECIP_INTERFACE: >> +sprintf(str, "Get Interface Status Intf = %d, L: = %d", >> +wIndex, wLength); >> +break; >> +case USB_RECIP_ENDPOINT: >> +sprintf(str, "Get Endpoint Status ep%d%s", >> +wIndex & ~USB_DIR_IN, >> +wIndex & USB_DIR_IN ? "in" : "out"); >> +
RE: [PATCH v1 2/2] usb:cdns3 Add Cadence USB3 DRD Driver
Hi, >On 10/12/18 14:39, Pawel Laszczak wrote: >> This patch introduce new Cadence USBSS DRD driver >> to linux kernel. >> >> The Cadence USBSS DRD Driver is a highly >> configurable IP Core which can be >> instantiated as Dual-Role Device (DRD), >> Peripheral Only and Host Only (XHCI) >> configurations. >> >> The current driver has been validated with >> FPGA burned. We have support for PCIe >> bus, which is used on FPGA prototyping. >> >> The host side of USBSS-DRD controller is compliance >> with XHCI specification, so it works with >> standard XHCI linux driver. >> >> Signed-off-by: Pawel Laszczak >> --- >> drivers/usb/Kconfig|2 + >> drivers/usb/Makefile |2 + >> drivers/usb/cdns3/Kconfig | 44 + >> drivers/usb/cdns3/Makefile | 16 + >> drivers/usb/cdns3/cdns3-pci-wrap.c | 157 +++ >> drivers/usb/cdns3/core.c | 451 +++ >> drivers/usb/cdns3/core.h | 108 ++ >> drivers/usb/cdns3/debug.h | 346 ++ >> drivers/usb/cdns3/debugfs.c| 168 +++ >> drivers/usb/cdns3/drd.c| 315 + >> drivers/usb/cdns3/drd.h| 129 ++ >> drivers/usb/cdns3/ep0.c| 864 + >> drivers/usb/cdns3/gadget-export.h | 28 + >> drivers/usb/cdns3/gadget.c | 1802 >> drivers/usb/cdns3/gadget.h | 1177 ++ >> drivers/usb/cdns3/host-export.h| 28 + >> drivers/usb/cdns3/host.c | 74 ++ >> drivers/usb/cdns3/trace.c | 11 + >> drivers/usb/cdns3/trace.h | 343 ++ > >You went to the other extreme of combining everything (host/gadget/drd) >together >which again makes this very hard to review. > >I think what Felipe meant was to only combine the gadget driver code into one >patch. > >The series could be split into 6 patches like so. >-dt binding >-pci glue >-core driver >-host driver >-gadget driver >-drd driver Felipe wrote: " Frankly, I don't understand why this is a series. It's a single driver and splitting it into a series just makes it more difficult to review, actually. Sure, a single patch will be large, but there's no way to have a functional driver until all patches are applied, anyway. " Felipe should I split this driver as suggested by Roger ?. Now it's very big patch but it's still a single driver. >> 19 files changed, 6065 insertions(+) >> create mode 100644 drivers/usb/cdns3/Kconfig >> create mode 100644 drivers/usb/cdns3/Makefile >> create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c >> create mode 100644 drivers/usb/cdns3/core.c >> create mode 100644 drivers/usb/cdns3/core.h >> create mode 100644 drivers/usb/cdns3/debug.h >> create mode 100644 drivers/usb/cdns3/debugfs.c >> create mode 100644 drivers/usb/cdns3/drd.c >> create mode 100644 drivers/usb/cdns3/drd.h >> create mode 100644 drivers/usb/cdns3/ep0.c >> create mode 100644 drivers/usb/cdns3/gadget-export.h >> create mode 100644 drivers/usb/cdns3/gadget.c >> create mode 100644 drivers/usb/cdns3/gadget.h >> create mode 100644 drivers/usb/cdns3/host-export.h >> create mode 100644 drivers/usb/cdns3/host.c >> create mode 100644 drivers/usb/cdns3/trace.c >> create mode 100644 drivers/usb/cdns3/trace.h >> > > Cheers Pawel
[PATCH v1 1/2] dt-bindings: add binding for USBSS-DRD controller.
This patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak --- .../devicetree/bindings/usb/cdns3-usb.txt | 31 +++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt b/Documentation/devicetree/bindings/usb/cdns3-usb.txt new file mode 100644 index ..ae4a255f0b10 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt @@ -0,0 +1,31 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register areas. +Controller has 3 different regions: +region 1 - HOST registers area +region 2 - DEVICE registers area +region 3 - OTG/DRD registers area + - compatible: Should contain: "cdns,usb3" + - interrupts: Interrupt specifier. Refer to interrupt bindings. + Driver supports only single interrupt line. +This single interrupt is shared between Device, + host and OTG/DRD part of driver. + +Optional propertiesi: + - maximum-speed : valid arguments are "super-speed", "high-speed" and + "full-speed"; refer to usb/generic.txt + - dr_mode: Should be one of "host", "peripheral" or "otg". + - phys: reference to the USB PHY + - phy-names: name of the USB PHY, should be "cdns3,usbphy" + + +Example: + usb@f300 { + compatible = "cdns,usb3"; + interrupts = ; + reg = <0xf300 0x1 //memory area for HOST registers + 0xf301 0x1 //memory area for DEVICE registers + 0xf302 0x1>;//memory area for OTG/DRD registers + }; + -- 2.17.1
[PATCH v1 0/2] Introduced new Cadence USBSS DRD Driver.
This patch set introduce new Cadence USBSS DRD driver to linux kernel. The Cadence USBSS DRD Driver s a highly configurable IP Core which can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI) configurations. The current driver has been validated with FPGA burned. We have support for PCIe bus, which is used on FPGA prototyping. The host site of USBSS controller is compliance with XHCI specification, so it works with standard XHCI linux driver. --- Pawel Laszczak (2): dt-bindings: add binding for USBSS-DRD controller. usb:cdns3 Add Cadence USB3 DRD Driver .../devicetree/bindings/usb/cdns3-usb.txt | 31 + drivers/usb/Kconfig |2 + drivers/usb/Makefile |2 + drivers/usb/cdns3/Kconfig | 44 + drivers/usb/cdns3/Makefile| 16 + drivers/usb/cdns3/cdns3-pci-wrap.c| 157 ++ drivers/usb/cdns3/core.c | 451 + drivers/usb/cdns3/core.h | 108 + drivers/usb/cdns3/debug.h | 346 drivers/usb/cdns3/debugfs.c | 168 ++ drivers/usb/cdns3/drd.c | 315 +++ drivers/usb/cdns3/drd.h | 129 ++ drivers/usb/cdns3/ep0.c | 864 drivers/usb/cdns3/gadget-export.h | 28 + drivers/usb/cdns3/gadget.c| 1802 + drivers/usb/cdns3/gadget.h| 1177 +++ drivers/usb/cdns3/host-export.h | 28 + drivers/usb/cdns3/host.c | 74 + drivers/usb/cdns3/trace.c | 11 + drivers/usb/cdns3/trace.h | 343 20 files changed, 6096 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt create mode 100644 drivers/usb/cdns3/Kconfig create mode 100644 drivers/usb/cdns3/Makefile create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c create mode 100644 drivers/usb/cdns3/core.c create mode 100644 drivers/usb/cdns3/core.h create mode 100644 drivers/usb/cdns3/debug.h create mode 100644 drivers/usb/cdns3/debugfs.c create mode 100644 drivers/usb/cdns3/drd.c create mode 100644 drivers/usb/cdns3/drd.h create mode 100644 drivers/usb/cdns3/ep0.c create mode 100644 drivers/usb/cdns3/gadget-export.h create mode 100644 drivers/usb/cdns3/gadget.c create mode 100644 drivers/usb/cdns3/gadget.h create mode 100644 drivers/usb/cdns3/host-export.h create mode 100644 drivers/usb/cdns3/host.c create mode 100644 drivers/usb/cdns3/trace.c create mode 100644 drivers/usb/cdns3/trace.h -- 2.17.1
RE: [RFC PATCH v2 03/15] dt-bindings: add binding for USBSS-DRD controller.
Hi, >On Sun, Nov 18, 2018 at 10:08:59AM +0000, Pawel Laszczak wrote: >> Thsi patch aim at documenting USB related dt-bindings for the > >typo > >> Cadence USBSS-DRD controller. >> >> Signed-off-by: Pawel Laszczak >> --- >> .../devicetree/bindings/usb/cdns3-usb.txt | 17 + >> 1 file changed, 17 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt >> >> diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> new file mode 100644 >> index ..f9e953f32d47 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> @@ -0,0 +1,17 @@ >> +Binding for the Cadence USBSS-DRD controller >> + >> +Required properties: >> + - reg: Physical base address and size of the controller's register area. > >1 or 3 regions? If 3, what is each one and the order? I will add extra description. > >> + - compatible: Should contain: "cdns,usb3" > >Only one version and one set of bugs? Yes, currently we have only one version. > >> + - interrupts: Interrupt specifier. Refer to interrupt bindings. > >How many interrupts? Single line for Device/Host/OTG I will add description > >> + >> + >> +Example: >> +cdns3@f300 { > >usb@... > Ok. >> +compatible = "cdns,usb3"; >> +interrupts = ; >> +reg = <0xf300 0x1 //memory area for OTG/DRD >> registers >> +0xf301 0x1 //memory area for HOST registers >> +0xf302 0x1>;//memory area for Device >> registers >> +}; >> + >> -- >> 2.17.1 >> Thanks, Cheers Pawel
RE: [RFC PATCH v2 03/15] dt-bindings: add binding for USBSS-DRD controller.
Hi, >On Sun, Nov 18, 2018 at 10:08:59AM +0000, Pawel Laszczak wrote: >> Thsi patch aim at documenting USB related dt-bindings for the > >typo > >> Cadence USBSS-DRD controller. >> >> Signed-off-by: Pawel Laszczak >> --- >> .../devicetree/bindings/usb/cdns3-usb.txt | 17 + >> 1 file changed, 17 insertions(+) >> create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt >> >> diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> new file mode 100644 >> index ..f9e953f32d47 >> --- /dev/null >> +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt >> @@ -0,0 +1,17 @@ >> +Binding for the Cadence USBSS-DRD controller >> + >> +Required properties: >> + - reg: Physical base address and size of the controller's register area. > >1 or 3 regions? If 3, what is each one and the order? I will add extra description. > >> + - compatible: Should contain: "cdns,usb3" > >Only one version and one set of bugs? Yes, currently we have only one version. > >> + - interrupts: Interrupt specifier. Refer to interrupt bindings. > >How many interrupts? Single line for Device/Host/OTG I will add description > >> + >> + >> +Example: >> +cdns3@f300 { > >usb@... > Ok. >> +compatible = "cdns,usb3"; >> +interrupts = ; >> +reg = <0xf300 0x1 //memory area for OTG/DRD >> registers >> +0xf301 0x1 //memory area for HOST registers >> +0xf302 0x1>;//memory area for Device >> registers >> +}; >> + >> -- >> 2.17.1 >> Thanks, Cheers Pawel