[PATCH v2 2/2] usb: cdnsp: Fix lack of removing request from pending list.

2021-04-19 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch fixes lack of removing request from ep->pending_list on failure
of the stop endpoint command. Driver even after failing this command
must remove request from ep->pending_list.
Without this fix driver can stuck in cdnsp_gadget_ep_disable function
in loop:
while (!list_empty(>pending_list)) {
preq = next_request(>pending_list);
cdnsp_ep_dequeue(pep, preq);
}

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
Driver")
Signed-off-by: Pawel Laszczak 

---
Changelog:
v2:
- removed blank space
- added "Fixes" tag

 drivers/usb/cdns3/cdnsp-gadget.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index 56707b6b0f57..c083985e387b 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -422,17 +422,17 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct 
cdnsp_request *preq)
 int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq)
 {
struct cdnsp_device *pdev = pep->pdev;
-   int ret;
+   int ret_stop = 0;
+   int ret_rem;
 
trace_cdnsp_request_dequeue(preq);
 
-   if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING) {
-   ret = cdnsp_cmd_stop_ep(pdev, pep);
-   if (ret)
-   return ret;
-   }
+   if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING)
+   ret_stop = cdnsp_cmd_stop_ep(pdev, pep);
+
+   ret_rem = cdnsp_remove_request(pdev, preq, pep);
 
-   return cdnsp_remove_request(pdev, preq, pep);
+   return ret_rem ? ret_rem : ret_stop;
 }
 
 static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev)
-- 
2.25.1



RE: [PATCH 1/2] usb: gadget: f_uac2: Stop endpoint before enabling it.

2021-04-19 Thread Pawel Laszczak
>On 21-04-19 09:50:53, Pawel Laszczak wrote:
>> From: Pawel Laszczak 
>>
>> Patch adds disabling endpoint before enabling it during changing
>> alternate setting. Lack of this functionality causes that in some
>> cases uac2 queue the same request multiple time.
>> Such situation can occur when host send set interface with
>> alternate setting 1 twice.
>>
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  drivers/usb/gadget/function/f_uac2.c | 8 
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/function/f_uac2.c 
>> b/drivers/usb/gadget/function/f_uac2.c
>> index 9cc5c512a5cd..7d20a9d8a1b4 100644
>> --- a/drivers/usb/gadget/function/f_uac2.c
>> +++ b/drivers/usb/gadget/function/f_uac2.c
>> @@ -890,17 +890,17 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, 
>> unsigned alt)
>>  if (intf == uac2->as_out_intf) {
>>  uac2->as_out_alt = alt;
>>
>> +u_audio_stop_capture(>g_audio);
>> +
>>  if (alt)
>>  ret = u_audio_start_capture(>g_audio);
>> -else
>> -u_audio_stop_capture(>g_audio);
>>  } else if (intf == uac2->as_in_intf) {
>>  uac2->as_in_alt = alt;
>>
>> +u_audio_stop_playback(>g_audio);
>> +
>>  if (alt)
>>  ret = u_audio_start_playback(>g_audio);
>> -else
>> -u_audio_stop_playback(>g_audio);
>>  } else {
>>  dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
>>  return -EINVAL;
>
>To avoid this, you may use prm->ep_enabled to judge if the endpoint has
>already enabled.

Such condition is as first instruction inside u_audio_stop_playback->free_ep  
function,
so we don't need duplicate it here.

>
>--
>
>Thanks,
>Peter Chen

--

Regards,
Pawe Laszczak


[PATCH 2/2] usb: cdnsp: Fix lack of removing request from pending list.

2021-04-19 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch fixes lack of removing request from ep->pending_list on failure
of the stop endpoint command. Driver even after failing this command
must remove request from ep->pending_list.
Without this fix driver can stuck in cdnsp_gadget_ep_disable function
in loop:
while (!list_empty(>pending_list)) {
preq = next_request(>pending_list);
cdnsp_ep_dequeue(pep, preq);
}

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index 6182c9bc65de..1ca8c1777a5c 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -424,17 +424,17 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct 
cdnsp_request *preq)
 int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq)
 {
struct cdnsp_device *pdev = pep->pdev;
-   int ret;
+   int ret_stop = 0;
+   int ret_rem;
 
trace_cdnsp_request_dequeue(preq);
 
-   if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING) {
-   ret = cdnsp_cmd_stop_ep(pdev, pep);
-   if (ret)
-   return ret;
-   }
+   if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING)
+   ret_stop = cdnsp_cmd_stop_ep(pdev, pep);
+
+   ret_rem =  cdnsp_remove_request(pdev, preq, pep);
 
-   return cdnsp_remove_request(pdev, preq, pep);
+   return ret_rem ? ret_rem : ret_stop;
 }
 
 static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev)
-- 
2.25.1



[PATCH 1/2] usb: gadget: f_uac2: Stop endpoint before enabling it.

2021-04-19 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch adds disabling endpoint before enabling it during changing
alternate setting. Lack of this functionality causes that in some
cases uac2 queue the same request multiple time.
Such situation can occur when host send set interface with
alternate setting 1 twice.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/gadget/function/f_uac2.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c 
b/drivers/usb/gadget/function/f_uac2.c
index 9cc5c512a5cd..7d20a9d8a1b4 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -890,17 +890,17 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, 
unsigned alt)
if (intf == uac2->as_out_intf) {
uac2->as_out_alt = alt;
 
+   u_audio_stop_capture(>g_audio);
+
if (alt)
ret = u_audio_start_capture(>g_audio);
-   else
-   u_audio_stop_capture(>g_audio);
} else if (intf == uac2->as_in_intf) {
uac2->as_in_alt = alt;
 
+   u_audio_stop_playback(>g_audio);
+
if (alt)
ret = u_audio_start_playback(>g_audio);
-   else
-   u_audio_stop_playback(>g_audio);
} else {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
return -EINVAL;
-- 
2.25.1



RE: [PATCH v2] usb: cdnsp: Fixes issue with Configure Endpoint command

2021-04-11 Thread Pawel Laszczak
>
>On 21-04-07 08:36:29, Pawel Laszczak wrote:
>> From: Pawel Laszczak 
>>
>> Patch adds flag EP_UNCONFIGURED to detect whether endpoint was
>> unconfigured. This flag is set in cdnsp_reset_device after Reset Device
>> command. Among others this command disables all non control endpoints.
>> Flag is used in cdnsp_gadget_ep_disable to protect controller against
>> invoking Configure Endpoint command on disabled endpoint. Lack of this
>> protection in some cases caused that Configure Endpoint command completed
>> with Context State Error code completion.
>>
>> Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
>> Driver")
>> Signed-off-by: Pawel Laszczak 
>
>Pawel, it is a little late for v5.12, I apply it to v5.13-rc1 if you
>don't mind.
>
>Peter

Yes, you can apply it to v5.13-rc1.

Thanks.

r
>>
>> ---
>> Changelog:
>> v2:
>> - removed useless blank line
>> - changed the EP_UNCONFIGURED to limit changes in patch
>>
>>  drivers/usb/cdns3/cdnsp-gadget.c | 17 -
>>  drivers/usb/cdns3/cdnsp-gadget.h |  1 +
>>  2 files changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-gadget.c 
>> b/drivers/usb/cdns3/cdnsp-gadget.c
>> index d7d4bdd57f46..56707b6b0f57 100644
>> --- a/drivers/usb/cdns3/cdnsp-gadget.c
>> +++ b/drivers/usb/cdns3/cdnsp-gadget.c
>> @@ -727,7 +727,7 @@ int cdnsp_reset_device(struct cdnsp_device *pdev)
>>   * are in Disabled state.
>>   */
>>  for (i = 1; i < CDNSP_ENDPOINTS_NUM; ++i)
>> -pdev->eps[i].ep_state |= EP_STOPPED;
>> +pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED;
>>
>>  trace_cdnsp_handle_cmd_reset_dev(slot_ctx);
>>
>> @@ -942,6 +942,7 @@ static int cdnsp_gadget_ep_enable(struct usb_ep *ep,
>>
>>  pep = to_cdnsp_ep(ep);
>>  pdev = pep->pdev;
>> +pep->ep_state &= ~EP_UNCONFIGURED;
>>
>>  if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED,
>>"%s is already enabled\n", pep->name))
>> @@ -1023,9 +1024,13 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
>>  goto finish;
>>  }
>>
>> -cdnsp_cmd_stop_ep(pdev, pep);
>>  pep->ep_state |= EP_DIS_IN_RROGRESS;
>> -cdnsp_cmd_flush_ep(pdev, pep);
>> +
>> +/* Endpoint was unconfigured by Reset Device command. */
>> +if (!(pep->ep_state & EP_UNCONFIGURED)) {
>> +cdnsp_cmd_stop_ep(pdev, pep);
>> +cdnsp_cmd_flush_ep(pdev, pep);
>> +}
>>
>>  /* Remove all queued USB requests. */
>>  while (!list_empty(>pending_list)) {
>> @@ -1043,10 +1048,12 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
>>
>>  cdnsp_endpoint_zero(pdev, pep);
>>
>> -ret = cdnsp_update_eps_configuration(pdev, pep);
>> +if (!(pep->ep_state & EP_UNCONFIGURED))
>> +ret = cdnsp_update_eps_configuration(pdev, pep);
>> +
>>  cdnsp_free_endpoint_rings(pdev, pep);
>>
>> -pep->ep_state &= ~EP_ENABLED;
>> +pep->ep_state &= ~(EP_ENABLED | EP_UNCONFIGURED);
>>  pep->ep_state |= EP_STOPPED;
>>
>>  finish:
>> diff --git a/drivers/usb/cdns3/cdnsp-gadget.h 
>> b/drivers/usb/cdns3/cdnsp-gadget.h
>> index 6bbb26548c04..783ca8ffde00 100644
>> --- a/drivers/usb/cdns3/cdnsp-gadget.h
>> +++ b/drivers/usb/cdns3/cdnsp-gadget.h
>> @@ -835,6 +835,7 @@ struct cdnsp_ep {
>>  #define EP_WEDGEBIT(4)
>>  #define EP0_HALTED_STATUS   BIT(5)
>>  #define EP_HAS_STREAMS  BIT(6)
>> +#define EP_UNCONFIGURED BIT(7)
>>
>>  bool skip;
>>  };
>> --
>> 2.25.1
>>
>
>--
>
>Thanks,
>Peter Chen

--

Regards,
Pawel Laszczak


[PATCH v2] usb: cdnsp: Fixes issue with Configure Endpoint command

2021-04-07 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch adds flag EP_UNCONFIGURED to detect whether endpoint was
unconfigured. This flag is set in cdnsp_reset_device after Reset Device
command. Among others this command disables all non control endpoints.
Flag is used in cdnsp_gadget_ep_disable to protect controller against
invoking Configure Endpoint command on disabled endpoint. Lack of this
protection in some cases caused that Configure Endpoint command completed
with Context State Error code completion.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
Driver")
Signed-off-by: Pawel Laszczak 

---
Changelog:
v2:
- removed useless blank line
- changed the EP_UNCONFIGURED to limit changes in patch

 drivers/usb/cdns3/cdnsp-gadget.c | 17 -
 drivers/usb/cdns3/cdnsp-gadget.h |  1 +
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index d7d4bdd57f46..56707b6b0f57 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -727,7 +727,7 @@ int cdnsp_reset_device(struct cdnsp_device *pdev)
 * are in Disabled state.
 */
for (i = 1; i < CDNSP_ENDPOINTS_NUM; ++i)
-   pdev->eps[i].ep_state |= EP_STOPPED;
+   pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED;
 
trace_cdnsp_handle_cmd_reset_dev(slot_ctx);
 
@@ -942,6 +942,7 @@ static int cdnsp_gadget_ep_enable(struct usb_ep *ep,
 
pep = to_cdnsp_ep(ep);
pdev = pep->pdev;
+   pep->ep_state &= ~EP_UNCONFIGURED;
 
if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED,
  "%s is already enabled\n", pep->name))
@@ -1023,9 +1024,13 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
goto finish;
}
 
-   cdnsp_cmd_stop_ep(pdev, pep);
pep->ep_state |= EP_DIS_IN_RROGRESS;
-   cdnsp_cmd_flush_ep(pdev, pep);
+
+   /* Endpoint was unconfigured by Reset Device command. */
+   if (!(pep->ep_state & EP_UNCONFIGURED)) {
+   cdnsp_cmd_stop_ep(pdev, pep);
+   cdnsp_cmd_flush_ep(pdev, pep);
+   }
 
/* Remove all queued USB requests. */
while (!list_empty(>pending_list)) {
@@ -1043,10 +1048,12 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
 
cdnsp_endpoint_zero(pdev, pep);
 
-   ret = cdnsp_update_eps_configuration(pdev, pep);
+   if (!(pep->ep_state & EP_UNCONFIGURED))
+   ret = cdnsp_update_eps_configuration(pdev, pep);
+
cdnsp_free_endpoint_rings(pdev, pep);
 
-   pep->ep_state &= ~EP_ENABLED;
+   pep->ep_state &= ~(EP_ENABLED | EP_UNCONFIGURED);
pep->ep_state |= EP_STOPPED;
 
 finish:
diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h
index 6bbb26548c04..783ca8ffde00 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.h
+++ b/drivers/usb/cdns3/cdnsp-gadget.h
@@ -835,6 +835,7 @@ struct cdnsp_ep {
 #define EP_WEDGE   BIT(4)
 #define EP0_HALTED_STATUS  BIT(5)
 #define EP_HAS_STREAMS BIT(6)
+#define EP_UNCONFIGUREDBIT(7)
 
bool skip;
 };
-- 
2.25.1



RE: [PATCH] usb: cdnsp: Fixes issue with Configure Endpoint command

2021-03-29 Thread Pawel Laszczak
Hi Peter,

>
>On 21-03-22 07:09:02, Pawel Laszczak wrote:
>> From: Pawel Laszczak 
>>
>> Patch adds flag EP_UNCONFIGURED to detect whether endpoint was
>> unconfigured. This flag is set in cdnsp_reset_device after Reset Device
>> command. Among others this command disables all non control endpoints.
>> Flag is used in cdnsp_gadget_ep_disable to protect controller against
>> invoking Configure Endpoint command on disabled endpoint. Lack of this
>> protection in some cases caused that Configure Endpoint command completed
>> with Context State Error code completion.
>>
>> Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
>> Driver")
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  drivers/usb/cdns3/cdnsp-gadget.c | 18 +-
>>  drivers/usb/cdns3/cdnsp-gadget.h | 11 ++-
>>  2 files changed, 19 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-gadget.c 
>> b/drivers/usb/cdns3/cdnsp-gadget.c
>> index d7d4bdd57f46..de17cc4ad91a 100644
>> --- a/drivers/usb/cdns3/cdnsp-gadget.c
>> +++ b/drivers/usb/cdns3/cdnsp-gadget.c
>> @@ -727,7 +727,7 @@ int cdnsp_reset_device(struct cdnsp_device *pdev)
>>   * are in Disabled state.
>>   */
>>  for (i = 1; i < CDNSP_ENDPOINTS_NUM; ++i)
>> -pdev->eps[i].ep_state |= EP_STOPPED;
>> +pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED;
>>
>>  trace_cdnsp_handle_cmd_reset_dev(slot_ctx);
>>
>> @@ -942,6 +942,7 @@ static int cdnsp_gadget_ep_enable(struct usb_ep *ep,
>>
>>  pep = to_cdnsp_ep(ep);
>>  pdev = pep->pdev;
>> +pep->ep_state &= ~EP_UNCONFIGURED;
>>
>>  if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED,
>>"%s is already enabled\n", pep->name))
>> @@ -1023,9 +1024,13 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
>>  goto finish;
>>  }
>>
>> -cdnsp_cmd_stop_ep(pdev, pep);
>>  pep->ep_state |= EP_DIS_IN_RROGRESS;
>> -cdnsp_cmd_flush_ep(pdev, pep);
>> +
>> +/* Endpoint was unconfigured by Reset Device command. */
>> +if (!(pep->ep_state & EP_UNCONFIGURED)) {
>> +cdnsp_cmd_stop_ep(pdev, pep);
>> +cdnsp_cmd_flush_ep(pdev, pep);
>> +}
>>
>>  /* Remove all queued USB requests. */
>>  while (!list_empty(>pending_list)) {
>> @@ -1036,6 +1041,7 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
>>  cdnsp_invalidate_ep_events(pdev, pep);
>>
>>  pep->ep_state &= ~EP_DIS_IN_RROGRESS;
>> +
>
>Useless blank line
>
>>  drop_flag = cdnsp_get_endpoint_flag(pep->endpoint.desc);
>>  ctrl_ctx = cdnsp_get_input_control_ctx(>in_ctx);
>>  ctrl_ctx->drop_flags = cpu_to_le32(drop_flag);
>> @@ -1043,10 +1049,12 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
>>
>>  cdnsp_endpoint_zero(pdev, pep);
>>
>> -ret = cdnsp_update_eps_configuration(pdev, pep);
>> +if (!(pep->ep_state & EP_UNCONFIGURED))
>> +ret = cdnsp_update_eps_configuration(pdev, pep);
>> +
>>  cdnsp_free_endpoint_rings(pdev, pep);
>>
>> -pep->ep_state &= ~EP_ENABLED;
>> +pep->ep_state &= ~(EP_ENABLED | EP_UNCONFIGURED);
>>  pep->ep_state |= EP_STOPPED;
>>
>>  finish:
>> diff --git a/drivers/usb/cdns3/cdnsp-gadget.h 
>> b/drivers/usb/cdns3/cdnsp-gadget.h
>> index 6bbb26548c04..e628bd539e23 100644
>> --- a/drivers/usb/cdns3/cdnsp-gadget.h
>> +++ b/drivers/usb/cdns3/cdnsp-gadget.h
>> @@ -830,11 +830,12 @@ struct cdnsp_ep {
>>  unsigned int ep_state;
>>  #define EP_ENABLED  BIT(0)
>>  #define EP_DIS_IN_RROGRESS  BIT(1)
>> -#define EP_HALTED   BIT(2)
>> -#define EP_STOPPED  BIT(3)
>> -#define EP_WEDGEBIT(4)
>> -#define EP0_HALTED_STATUS   BIT(5)
>> -#define EP_HAS_STREAMS  BIT(6)
>> +#define EP_UNCONFIGURED BIT(2)
>
>Why add new flag as BIT(2), it causes many changes in this patch?

In my feeling, EP_UNCONFIGURED is more associates with the first 2 flags, so 
I've decided 
put it after BIT(1).  

>
>> +#define EP_HALTED   BIT(3)
>> +#define EP_STOPPED  BIT(4)
>> +#define EP_WEDGEBIT(5)
>> +#define EP0_HALTED_STATUS   BIT(6)
>> +#define EP_HAS_STREAMS  BIT(7)
>>
>>  bool skip;
>>  };
>> --
>> 2.25.1
>>
>
>--
>
>Thanks,
>Peter Chen



RE: [PATCH] usb: cdns3: delete repeated clear operations

2021-03-29 Thread Pawel Laszczak
>
>On 21-03-22 07:19:46, Pawel Laszczak wrote:
>> Hi Peter,
>>
>> Can you add this patch to for-usb-next branch.
>>
>
>Feel free add your ACK base on this patch.
>
>Peter
>> Thanks.
>>
>> >
>> >
>> >dma_alloc_coherent already zeroes out memory, so memset is not needed.
>> >
>> >Signed-off-by: Wang Qing 
>>
>> Reviewed-by: Pawel Laszczak 


Acked-by: Pawel Laszczak 

>>
>> >---
>> > drivers/usb/cdns3/cdnsp-mem.c | 1 -
>> > 1 file changed, 1 deletion(-)
>> >
>> >diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c
>> >index 7a84e92..1d1b9a4
>> >--- a/drivers/usb/cdns3/cdnsp-mem.c
>> >+++ b/drivers/usb/cdns3/cdnsp-mem.c
>> >@@ -1231,7 +1231,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
>> >if (!pdev->dcbaa)
>> >return -ENOMEM;
>> >
>> >-   memset(pdev->dcbaa, 0, sizeof(*pdev->dcbaa));
>> >pdev->dcbaa->dma = dma;
>> >
>> >cdnsp_write_64(dma, >op_regs->dcbaa_ptr);
>> >--
>> >2.7.4
>>
>> Regards,
>> Pawel Laszczak
>
>--
>
>Thanks,
>Peter Chen

Regards,
Pawel Laszczak



RE: [PATCH] usb: cdnsp: remove redundant initialization of variable ret

2021-03-29 Thread Pawel Laszczak
Hi Colin,

Thanks for this fix. 

>
>From: Colin Ian King 
>
>The variable ret is being initialized with a value that is
>never read and it is being updated later with a new value.  The
>initialization is redundant and can be removed.
>
>Addresses-Coverity: ("Unused value")
>Signed-off-by: Colin Ian King 

Reviewed-by: Pawel Laszczak 

>---
> drivers/usb/cdns3/cdnsp-mem.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c
>index 7a84e928710e..d87b640e7b49 100644
>--- a/drivers/usb/cdns3/cdnsp-mem.c
>+++ b/drivers/usb/cdns3/cdnsp-mem.c
>@@ -686,7 +686,7 @@ static void cdnsp_free_priv_device(struct cdnsp_device 
>*pdev)
>
> static int cdnsp_alloc_priv_device(struct cdnsp_device *pdev)
> {
>-  int ret = -ENOMEM;
>+  int ret;
>
>   ret = cdnsp_init_device_ctx(pdev);
>   if (ret)
>--
>2.30.2

Regards,
Pawel Laszczak



RE: [PATCH] usb: cdns3: delete repeated clear operations

2021-03-22 Thread Pawel Laszczak
Hi Peter,

Can you add this patch to for-usb-next branch.

Thanks.

>
>
>dma_alloc_coherent already zeroes out memory, so memset is not needed.
>
>Signed-off-by: Wang Qing 

Reviewed-by: Pawel Laszczak 

>---
> drivers/usb/cdns3/cdnsp-mem.c | 1 -
> 1 file changed, 1 deletion(-)
>
>diff --git a/drivers/usb/cdns3/cdnsp-mem.c b/drivers/usb/cdns3/cdnsp-mem.c
>index 7a84e92..1d1b9a4
>--- a/drivers/usb/cdns3/cdnsp-mem.c
>+++ b/drivers/usb/cdns3/cdnsp-mem.c
>@@ -1231,7 +1231,6 @@ int cdnsp_mem_init(struct cdnsp_device *pdev)
>   if (!pdev->dcbaa)
>   return -ENOMEM;
>
>-  memset(pdev->dcbaa, 0, sizeof(*pdev->dcbaa));
>   pdev->dcbaa->dma = dma;
>
>   cdnsp_write_64(dma, >op_regs->dcbaa_ptr);
>--
>2.7.4

Regards,
Pawel Laszczak


[PATCH] usb: cdnsp: Fixes issue with Configure Endpoint command

2021-03-22 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch adds flag EP_UNCONFIGURED to detect whether endpoint was
unconfigured. This flag is set in cdnsp_reset_device after Reset Device
command. Among others this command disables all non control endpoints.
Flag is used in cdnsp_gadget_ep_disable to protect controller against
invoking Configure Endpoint command on disabled endpoint. Lack of this
protection in some cases caused that Configure Endpoint command completed
with Context State Error code completion.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
Driver")
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.c | 18 +-
 drivers/usb/cdns3/cdnsp-gadget.h | 11 ++-
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index d7d4bdd57f46..de17cc4ad91a 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -727,7 +727,7 @@ int cdnsp_reset_device(struct cdnsp_device *pdev)
 * are in Disabled state.
 */
for (i = 1; i < CDNSP_ENDPOINTS_NUM; ++i)
-   pdev->eps[i].ep_state |= EP_STOPPED;
+   pdev->eps[i].ep_state |= EP_STOPPED | EP_UNCONFIGURED;
 
trace_cdnsp_handle_cmd_reset_dev(slot_ctx);
 
@@ -942,6 +942,7 @@ static int cdnsp_gadget_ep_enable(struct usb_ep *ep,
 
pep = to_cdnsp_ep(ep);
pdev = pep->pdev;
+   pep->ep_state &= ~EP_UNCONFIGURED;
 
if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED,
  "%s is already enabled\n", pep->name))
@@ -1023,9 +1024,13 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
goto finish;
}
 
-   cdnsp_cmd_stop_ep(pdev, pep);
pep->ep_state |= EP_DIS_IN_RROGRESS;
-   cdnsp_cmd_flush_ep(pdev, pep);
+
+   /* Endpoint was unconfigured by Reset Device command. */
+   if (!(pep->ep_state & EP_UNCONFIGURED)) {
+   cdnsp_cmd_stop_ep(pdev, pep);
+   cdnsp_cmd_flush_ep(pdev, pep);
+   }
 
/* Remove all queued USB requests. */
while (!list_empty(>pending_list)) {
@@ -1036,6 +1041,7 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
cdnsp_invalidate_ep_events(pdev, pep);
 
pep->ep_state &= ~EP_DIS_IN_RROGRESS;
+
drop_flag = cdnsp_get_endpoint_flag(pep->endpoint.desc);
ctrl_ctx = cdnsp_get_input_control_ctx(>in_ctx);
ctrl_ctx->drop_flags = cpu_to_le32(drop_flag);
@@ -1043,10 +1049,12 @@ static int cdnsp_gadget_ep_disable(struct usb_ep *ep)
 
cdnsp_endpoint_zero(pdev, pep);
 
-   ret = cdnsp_update_eps_configuration(pdev, pep);
+   if (!(pep->ep_state & EP_UNCONFIGURED))
+   ret = cdnsp_update_eps_configuration(pdev, pep);
+
cdnsp_free_endpoint_rings(pdev, pep);
 
-   pep->ep_state &= ~EP_ENABLED;
+   pep->ep_state &= ~(EP_ENABLED | EP_UNCONFIGURED);
pep->ep_state |= EP_STOPPED;
 
 finish:
diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h
index 6bbb26548c04..e628bd539e23 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.h
+++ b/drivers/usb/cdns3/cdnsp-gadget.h
@@ -830,11 +830,12 @@ struct cdnsp_ep {
unsigned int ep_state;
 #define EP_ENABLED BIT(0)
 #define EP_DIS_IN_RROGRESS BIT(1)
-#define EP_HALTED  BIT(2)
-#define EP_STOPPED BIT(3)
-#define EP_WEDGE   BIT(4)
-#define EP0_HALTED_STATUS  BIT(5)
-#define EP_HAS_STREAMS BIT(6)
+#define EP_UNCONFIGUREDBIT(2)
+#define EP_HALTED  BIT(3)
+#define EP_STOPPED BIT(4)
+#define EP_WEDGE   BIT(5)
+#define EP0_HALTED_STATUS  BIT(6)
+#define EP_HAS_STREAMS BIT(7)
 
bool skip;
 };
-- 
2.25.1



RE: linux-next: Fixes tag needs some work in the usb-chipidea-fixes tree

2021-03-22 Thread Pawel Laszczak
Hi Stephen,

I've send the new version

Thanks,

>
>Hi all,
>
>In commit
>
>  67a788c7c3e7 ("usb: cdnsp: Fixes issue with dequeuing requests after 
> disabling endpoint")
>
>Fixes tag
>
>  Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence 
> USBSSP DRD Driver")
>
>has these problem(s):
>
>  - leading word 'commit' unexpected
>
>--
>Cheers,
>Stephen Rothwell

Regards,
Pawel Laszczak


[PATCH v2] usb: cdnsp: Fixes issue with dequeuing requests after disabling endpoint

2021-03-21 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch fixes the bug:
BUG: kernel NULL pointer dereference, address: 0050
PGD 0 P4D 0
Oops: 0002 [#1] SMP PTI
CPU: 0 PID: 4137 Comm: uvc-gadget Tainted: G   OE 
5.10.0-next-20201214+ #3
Hardware name: ASUS All Series/Q87T, BIOS 0908 07/22/2014
RIP: 0010:cdnsp_remove_request+0xe9/0x530 [cdnsp_udc_pci]
Code: 01 00 00 31 f6 48 89 df e8 64 d4 ff ff 48 8b 43 08 48 8b 13 45 31 f6 48 
89 42 08 48 89 10 b8 98 ff ff ff 48 89 1b 48 89 5b 08 <41> 83 6d 50 01 41 83 af 
d0 00 00 00 01 41 f6 84 24 78 20 00 00 08
RSP: 0018:b68d00d07b60 EFLAGS: 00010046
RAX: ff98 RBX: 9d29c57fbf00 RCX: 1400
RDX: 9d29c57fbf00 RSI:  RDI: 9d29c57fbf00
RBP: b68d00d07bb0 R08: 9d2ad9510a00 R09: 9d2ac011c000
R10: 9d2a12b6e760 R11:  R12: 9d29d3fb8000
R13:  R14:  R15: 9d29d3fb88c0
FS:  () GS:9d2adba0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0050 CR3: 000102164005 CR4: 001706f0
Call Trace:
 cdnsp_ep_dequeue+0x3c/0x90 [cdnsp_udc_pci]
 cdnsp_gadget_ep_dequeue+0x3f/0x80 [cdnsp_udc_pci]
 usb_ep_dequeue+0x21/0x70 [udc_core]
 uvcg_video_enable+0x19d/0x220 [usb_f_uvc]
 uvc_v4l2_release+0x49/0x90 [usb_f_uvc]
 v4l2_release+0xa5/0x100 [videodev]
 __fput+0x99/0x250
 fput+0xe/0x10
 task_work_run+0x75/0xb0
 do_exit+0x370/0xb80
 do_group_exit+0x43/0xa0
 get_signal+0x12d/0x820
 arch_do_signal_or_restart+0xb2/0x870
 ? __switch_to_asm+0x36/0x70
 ? kern_select+0xc6/0x100
 exit_to_user_mode_prepare+0xfc/0x170
 syscall_exit_to_user_mode+0x2a/0x40
 do_syscall_64+0x43/0x80
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fe969cf5dd7
Code: Unable to access opcode bytes at RIP 0x7fe969cf5dad.

Problem occurs for UVC class. During disconnecting the UVC class disable
endpoints and then start dequeuing all requests. This leads to situation
where requests are removed twice. The first one in
cdnsp_gadget_ep_disable and the second in cdnsp_gadget_ep_dequeue
function.
Patch adds condition in cdnsp_gadget_ep_dequeue function which allows
dequeue requests only from enabled endpoint.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
Driver")
Signed-off-by: Pawel Laszczak 

---
Changelog:
v2:
- removed unexpected 'commit' word from fixes tag

 drivers/usb/cdns3/cdnsp-gadget.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index f2ebbacd932e..d7d4bdd57f46 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -1128,6 +1128,10 @@ static int cdnsp_gadget_ep_dequeue(struct usb_ep *ep,
return -ESHUTDOWN;
}
 
+   /* Requests has been dequeued during disabling endpoint. */
+   if (!(pep->ep_state & EP_ENABLED))
+   return 0;
+
spin_lock_irqsave(>lock, flags);
ret = cdnsp_ep_dequeue(pep, to_cdnsp_request(request));
spin_unlock_irqrestore(>lock, flags);
-- 
2.25.1



[PATCH] usb: cdnsp: Fixes issue with dequeuing requests after disabling endpoint

2021-03-18 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch fixes the bug:
BUG: kernel NULL pointer dereference, address: 0050
PGD 0 P4D 0
Oops: 0002 [#1] SMP PTI
CPU: 0 PID: 4137 Comm: uvc-gadget Tainted: G   OE 
5.10.0-next-20201214+ #3
Hardware name: ASUS All Series/Q87T, BIOS 0908 07/22/2014
RIP: 0010:cdnsp_remove_request+0xe9/0x530 [cdnsp_udc_pci]
Code: 01 00 00 31 f6 48 89 df e8 64 d4 ff ff 48 8b 43 08 48 8b 13 45 31 f6 48 
89 42 08 48 89 10 b8 98 ff ff ff 48 89 1b 48 89 5b 08 <41> 83 6d 50 01 41 83 af 
d0 00 00 00 01 41 f6 84 24 78 20 00 00 08
RSP: 0018:b68d00d07b60 EFLAGS: 00010046
RAX: ff98 RBX: 9d29c57fbf00 RCX: 1400
RDX: 9d29c57fbf00 RSI:  RDI: 9d29c57fbf00
RBP: b68d00d07bb0 R08: 9d2ad9510a00 R09: 9d2ac011c000
R10: 9d2a12b6e760 R11:  R12: 9d29d3fb8000
R13:  R14:  R15: 9d29d3fb88c0
FS:  () GS:9d2adba0() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 0050 CR3: 000102164005 CR4: 001706f0
Call Trace:
 cdnsp_ep_dequeue+0x3c/0x90 [cdnsp_udc_pci]
 cdnsp_gadget_ep_dequeue+0x3f/0x80 [cdnsp_udc_pci]
 usb_ep_dequeue+0x21/0x70 [udc_core]
 uvcg_video_enable+0x19d/0x220 [usb_f_uvc]
 uvc_v4l2_release+0x49/0x90 [usb_f_uvc]
 v4l2_release+0xa5/0x100 [videodev]
 __fput+0x99/0x250
 fput+0xe/0x10
 task_work_run+0x75/0xb0
 do_exit+0x370/0xb80
 do_group_exit+0x43/0xa0
 get_signal+0x12d/0x820
 arch_do_signal_or_restart+0xb2/0x870
 ? __switch_to_asm+0x36/0x70
 ? kern_select+0xc6/0x100
 exit_to_user_mode_prepare+0xfc/0x170
 syscall_exit_to_user_mode+0x2a/0x40
 do_syscall_64+0x43/0x80
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fe969cf5dd7
Code: Unable to access opcode bytes at RIP 0x7fe969cf5dad.

Problem occurs for UVC class. During disconnecting the UVC class disable
endpoints and then start dequeuing all requests. This leads to situation
where requests are removed twice. The first one in
cdnsp_gadget_ep_disable and the second in cdnsp_gadget_ep_dequeue
function.
Patch adds condition in cdnsp_gadget_ep_dequeue function which allows
dequeue requests only from enabled endpoint.

Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP 
DRD Driver")
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index f2ebbacd932e..d7d4bdd57f46 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -1128,6 +1128,10 @@ static int cdnsp_gadget_ep_dequeue(struct usb_ep *ep,
return -ESHUTDOWN;
}
 
+   /* Requests has been dequeued during disabling endpoint. */
+   if (!(pep->ep_state & EP_ENABLED))
+   return 0;
+
spin_lock_irqsave(>lock, flags);
ret = cdnsp_ep_dequeue(pep, to_cdnsp_request(request));
spin_unlock_irqrestore(>lock, flags);
-- 
2.25.1



[PATCH v4 2/2] usb: webcam: Invalid size of Processing Unit Descriptor

2021-03-15 Thread Pawel Laszczak
From: Pawel Laszczak 

According with USB Device Class Definition for Video Device the
Processing Unit Descriptor bLength should be 12 (10 + bmControlSize),
but it has 11.

Invalid length caused that Processing Unit Descriptor Test Video form
CV tool failed. To fix this issue patch adds bmVideoStandards into
uvc_processing_unit_descriptor structure.

The bmVideoStandards field was added in UVC 1.1 and it wasn't part of
UVC 1.0a.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Pawel Laszczak 

---
Changelog:
v4:
- fixed compilation error caused by v2
v3:
- updated the commit message
- added bmVideoStandard field to UVC gadget driver
v2:
- updated UVC_DT_PROCESSING_UNIT_SIZE macro

 drivers/usb/gadget/function/f_uvc.c | 1 +
 drivers/usb/gadget/legacy/webcam.c  | 1 +
 include/uapi/linux/usb/video.h  | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c 
b/drivers/usb/gadget/function/f_uvc.c
index 5d62720bb9e1..e3b0a79c8f01 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -823,6 +823,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
pd->bmControls[0]   = 1;
pd->bmControls[1]   = 0;
pd->iProcessing = 0;
+   pd->bmVideoStandards= 0;
 
od = >uvc_output_terminal;
od->bLength = UVC_DT_OUTPUT_TERMINAL_SIZE;
diff --git a/drivers/usb/gadget/legacy/webcam.c 
b/drivers/usb/gadget/legacy/webcam.c
index 3a61de4bb2b1..accb4dacf715 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -125,6 +125,7 @@ static const struct uvc_processing_unit_descriptor 
uvc_processing = {
.bmControls[0]  = 1,
.bmControls[1]  = 0,
.iProcessing= 0,
+   .bmVideoStandards   = 0,
 };
 
 static const struct uvc_output_terminal_descriptor uvc_output_terminal = {
diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
index d854cb19c42c..bfdae12cdacf 100644
--- a/include/uapi/linux/usb/video.h
+++ b/include/uapi/linux/usb/video.h
@@ -302,9 +302,10 @@ struct uvc_processing_unit_descriptor {
__u8   bControlSize;
__u8   bmControls[2];
__u8   iProcessing;
+   __u8   bmVideoStandards;
 } __attribute__((__packed__));
 
-#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
+#define UVC_DT_PROCESSING_UNIT_SIZE(n) (10+(n))
 
 /* 3.7.2.6. Extension Unit Descriptor */
 struct uvc_extension_unit_descriptor {
-- 
2.25.1



RE: [PATCH v3 2/2] usb: webcam: Invalid size of Processing Unit Descriptor

2021-03-15 Thread Pawel Laszczak


Please ignore this one patch. I need to resend it. It causes compilation error.
Sorry for that.  

>
>From: Pawel Laszczak 
>
>According with USB Device Class Definition for Video Device the
>Processing Unit Descriptor bLength should be 12 (10 + bmControlSize),
>but it has 11.
>
>Invalid length caused that Processing Unit Descriptor Test Video form
>CV tool failed. To fix this issue patch adds bmVideoStandards into
>uvc_processing_unit_descriptor structure.
>
>The bmVideoStandards field was added in UVC 1.1 and it wasn't part of
>UVC 1.0a.
>
>Reviewed-by: Laurent Pinchart 
>Signed-off-by: Pawel Laszczak 
>
>---
>Changelog:
>v3:
>- updated the commit message
>- added bmVideoStandard field to UVC gadget driver
>v2:
>- updated UVC_DT_PROCESSING_UNIT_SIZE macro
>
> drivers/usb/gadget/function/f_uvc.c | 1 +
> drivers/usb/gadget/legacy/webcam.c  | 1 +
> include/uapi/linux/usb/video.h  | 3 ++-
> 3 files changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/usb/gadget/function/f_uvc.c 
>b/drivers/usb/gadget/function/f_uvc.c
>index 5d62720bb9e1..e3b0a79c8f01 100644
>--- a/drivers/usb/gadget/function/f_uvc.c
>+++ b/drivers/usb/gadget/function/f_uvc.c
>@@ -823,6 +823,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
>   pd->bmControls[0]   = 1;
>   pd->bmControls[1]   = 0;
>   pd->iProcessing = 0;
>+  pd->bmVideoStandards= 0;
>
>   od = >uvc_output_terminal;
>   od->bLength = UVC_DT_OUTPUT_TERMINAL_SIZE;
>diff --git a/drivers/usb/gadget/legacy/webcam.c 
>b/drivers/usb/gadget/legacy/webcam.c
>index 3a61de4bb2b1..accb4dacf715 100644
>--- a/drivers/usb/gadget/legacy/webcam.c
>+++ b/drivers/usb/gadget/legacy/webcam.c
>@@ -125,6 +125,7 @@ static const struct uvc_processing_unit_descriptor 
>uvc_processing = {
>   .bmControls[0]  = 1,
>   .bmControls[1]  = 0,
>   .iProcessing= 0,
>+  .bmVideoStandrads   = 0,
> };
>
> static const struct uvc_output_terminal_descriptor uvc_output_terminal = {
>diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
>index d854cb19c42c..bfdae12cdacf 100644
>--- a/include/uapi/linux/usb/video.h
>+++ b/include/uapi/linux/usb/video.h
>@@ -302,9 +302,10 @@ struct uvc_processing_unit_descriptor {
>   __u8   bControlSize;
>   __u8   bmControls[2];
>   __u8   iProcessing;
>+  __u8   bmVideoStandards;
> } __attribute__((__packed__));
>
>-#define UVC_DT_PROCESSING_UNIT_SIZE(n)    (9+(n))
>+#define UVC_DT_PROCESSING_UNIT_SIZE(n)(10+(n))
>
> /* 3.7.2.6. Extension Unit Descriptor */
> struct uvc_extension_unit_descriptor {
>--
>2.25.1

Regards,
Pawel Laszczak


[PATCH v2 1/2] usb: gadget: uvc: Updating bcdUVC field to 0x0110

2021-03-15 Thread Pawel Laszczak
From: Pawel Laszczak 

Command Verifier during UVC Descriptor Tests (Class Video Control
Interface Descriptor Test Video) complains about:

Video Control Interface Header bcdUVC is 0x0100. USB Video Class
specification 1.0 has been replaced by 1.1 specification
(UVC: 6.2.26) Class Video Control Interface Descriptor bcdUVC is not 1.1

Reviewed-by: Laurent Pinchart 
Signed-off-by: Pawel Laszczak 

---
Changlog:
v2:
- fixed typo in commit message

 drivers/usb/gadget/function/uvc_configfs.c | 2 +-
 drivers/usb/gadget/legacy/webcam.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/uvc_configfs.c 
b/drivers/usb/gadget/function/uvc_configfs.c
index 00fb58e50a15..cd28dec837dd 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -231,7 +231,7 @@ static struct config_item *uvcg_control_header_make(struct 
config_group *group,
h->desc.bLength = UVC_DT_HEADER_SIZE(1);
h->desc.bDescriptorType = USB_DT_CS_INTERFACE;
h->desc.bDescriptorSubType  = UVC_VC_HEADER;
-   h->desc.bcdUVC  = cpu_to_le16(0x0100);
+   h->desc.bcdUVC  = cpu_to_le16(0x0110);
h->desc.dwClockFrequency= cpu_to_le32(4800);
 
config_item_init_type_name(>item, name, _control_header_type);
diff --git a/drivers/usb/gadget/legacy/webcam.c 
b/drivers/usb/gadget/legacy/webcam.c
index a9f8eb8e1c76..3a61de4bb2b1 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -90,7 +90,7 @@ static const struct UVC_HEADER_DESCRIPTOR(1) 
uvc_control_header = {
.bLength= UVC_DT_HEADER_SIZE(1),
.bDescriptorType= USB_DT_CS_INTERFACE,
.bDescriptorSubType = UVC_VC_HEADER,
-   .bcdUVC = cpu_to_le16(0x0100),
+   .bcdUVC = cpu_to_le16(0x0110),
.wTotalLength   = 0, /* dynamic */
.dwClockFrequency   = cpu_to_le32(4800),
.bInCollection  = 0, /* dynamic */
-- 
2.25.1



[PATCH v3 2/2] usb: webcam: Invalid size of Processing Unit Descriptor

2021-03-15 Thread Pawel Laszczak
From: Pawel Laszczak 

According with USB Device Class Definition for Video Device the
Processing Unit Descriptor bLength should be 12 (10 + bmControlSize),
but it has 11.

Invalid length caused that Processing Unit Descriptor Test Video form
CV tool failed. To fix this issue patch adds bmVideoStandards into
uvc_processing_unit_descriptor structure.

The bmVideoStandards field was added in UVC 1.1 and it wasn't part of
UVC 1.0a.

Reviewed-by: Laurent Pinchart 
Signed-off-by: Pawel Laszczak 

---
Changelog:
v3:
- updated the commit message
- added bmVideoStandard field to UVC gadget driver
v2:
- updated UVC_DT_PROCESSING_UNIT_SIZE macro

 drivers/usb/gadget/function/f_uvc.c | 1 +
 drivers/usb/gadget/legacy/webcam.c  | 1 +
 include/uapi/linux/usb/video.h  | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c 
b/drivers/usb/gadget/function/f_uvc.c
index 5d62720bb9e1..e3b0a79c8f01 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -823,6 +823,7 @@ static struct usb_function_instance *uvc_alloc_inst(void)
pd->bmControls[0]   = 1;
pd->bmControls[1]   = 0;
pd->iProcessing = 0;
+   pd->bmVideoStandards= 0;
 
od = >uvc_output_terminal;
od->bLength = UVC_DT_OUTPUT_TERMINAL_SIZE;
diff --git a/drivers/usb/gadget/legacy/webcam.c 
b/drivers/usb/gadget/legacy/webcam.c
index 3a61de4bb2b1..accb4dacf715 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -125,6 +125,7 @@ static const struct uvc_processing_unit_descriptor 
uvc_processing = {
.bmControls[0]  = 1,
.bmControls[1]  = 0,
.iProcessing= 0,
+   .bmVideoStandrads   = 0,
 };
 
 static const struct uvc_output_terminal_descriptor uvc_output_terminal = {
diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
index d854cb19c42c..bfdae12cdacf 100644
--- a/include/uapi/linux/usb/video.h
+++ b/include/uapi/linux/usb/video.h
@@ -302,9 +302,10 @@ struct uvc_processing_unit_descriptor {
__u8   bControlSize;
__u8   bmControls[2];
__u8   iProcessing;
+   __u8   bmVideoStandards;
 } __attribute__((__packed__));
 
-#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
+#define UVC_DT_PROCESSING_UNIT_SIZE(n) (10+(n))
 
 /* 3.7.2.6. Extension Unit Descriptor */
 struct uvc_extension_unit_descriptor {
-- 
2.25.1



RE: [PATCH 1/2] usb: gadget: uvc: Updating bcdUVC field to 0x0110

2021-03-14 Thread Pawel Laszczak
Hi Laurent
>
>Hello Pawel,
>
>Thank you for the patch.
>
>On Sun, Mar 14, 2021 at 09:58:46AM +0800, Peter Chen wrote:
>> On 21-03-08 11:27:34, Pawel Laszczak wrote:
>> > From: Pawel Laszczak 
>> >
>> > Command Verifier during UVC Descriptor Tests (Class Video Control
>> > Interface Descriptor Test Video) compleins about:
>>
>> %s/compleins/complains
>>
>> > Video Control Interface Header bcdUVC is 0x0100. USB Video Class
>> > specification 1.0 has been replaced by 1.1 specification
>> > (UVC: 6.2.26) Class Video Control Interface Descriptor bcdUVC is not 1.1
>>
>> What does this (UVC: 6.2.26) mean? There are only 4 chapters for this
>> spec, Am I something wrong?
>
>I assume this is a reference to a test case in the test suite.

It's a reference to UVC Compliance Test Spec.pdf. 
This document is part of Command Verifier tester.

I will resend the patch without typo. 

Thanks

>
>> > Signed-off-by: Pawel Laszczak 
>> > ---
>> >  drivers/usb/gadget/function/uvc_configfs.c | 2 +-
>> >  drivers/usb/gadget/legacy/webcam.c | 2 +-
>> >  2 files changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/drivers/usb/gadget/function/uvc_configfs.c 
>> > b/drivers/usb/gadget/function/uvc_configfs.c
>> > index 00fb58e50a15..cd28dec837dd 100644
>> > --- a/drivers/usb/gadget/function/uvc_configfs.c
>> > +++ b/drivers/usb/gadget/function/uvc_configfs.c
>> > @@ -231,7 +231,7 @@ static struct config_item 
>> > *uvcg_control_header_make(struct config_group *group,
>> >h->desc.bLength = UVC_DT_HEADER_SIZE(1);
>> >h->desc.bDescriptorType = USB_DT_CS_INTERFACE;
>> >h->desc.bDescriptorSubType  = UVC_VC_HEADER;
>> > -  h->desc.bcdUVC  = cpu_to_le16(0x0100);
>> > +  h->desc.bcdUVC  = cpu_to_le16(0x0110);
>> >h->desc.dwClockFrequency= cpu_to_le32(4800);
>> >
>> >config_item_init_type_name(>item, name, _control_header_type);
>> > diff --git a/drivers/usb/gadget/legacy/webcam.c 
>> > b/drivers/usb/gadget/legacy/webcam.c
>> > index a9f8eb8e1c76..3a61de4bb2b1 100644
>> > --- a/drivers/usb/gadget/legacy/webcam.c
>> > +++ b/drivers/usb/gadget/legacy/webcam.c
>> > @@ -90,7 +90,7 @@ static const struct UVC_HEADER_DESCRIPTOR(1) 
>> > uvc_control_header = {
>> >.bLength= UVC_DT_HEADER_SIZE(1),
>> >.bDescriptorType= USB_DT_CS_INTERFACE,
>> >.bDescriptorSubType = UVC_VC_HEADER,
>> > -  .bcdUVC = cpu_to_le16(0x0100),
>> > +  .bcdUVC = cpu_to_le16(0x0110),
>> >.wTotalLength   = 0, /* dynamic */
>> >.dwClockFrequency   = cpu_to_le32(4800),
>> >.bInCollection  = 0, /* dynamic */
>
>The change looks good to me. With the typo in the commit message fixed,
>
>Reviewed-by: Laurent Pinchart 
>
--

Regards
Pawel Laszczak


RE: [PATCH] usb: gadget: uvc: add bInterval checking for HS mode

2021-03-09 Thread Pawel Laszczak
Please check whether the problem occurs in this fragment of code:
https://elixir.bootlin.com/linux/latest/source/drivers/usb/cdns3/gadget.c#L2569

zlp_buff is allocated with kzalloc.

Pawel

>>On Fri, Mar 5, 2021 at 12:40 AM Pawel Laszczak <mailto:paw...@cadence.com> 
>>wrote:
>>From: Pawel Laszczak <mailto:paw...@cadence.com>
>>
>>Patch adds extra checking for bInterval passed by configfs.
>>The 5.6.4 chapter of USB Specification (rev. 2.0) say:
>>"A high-bandwidth endpoint must specify a period of 1x125 µs
>>(i.e., a bInterval value of 1)."
>>
>>The issue was observed during testing UVC class on CV.
>>I treat this change as improvement because we can control
>>bInterval by configfs.
>>
>>Signed-off-by: Pawel Laszczak <mailto:paw...@cadence.com>
>>---
>> drivers/usb/gadget/function/f_uvc.c | 6 ++
>> 1 file changed, 6 insertions(+)
>>
>>diff --git a/drivers/usb/gadget/function/f_uvc.c 
>>b/drivers/usb/gadget/function/f_uvc.c
>>index 44b4352a2676..5d62720bb9e1 100644
>>--- a/drivers/usb/gadget/function/f_uvc.c
>>+++ b/drivers/usb/gadget/function/f_uvc.c
>>@@ -631,6 +631,12 @@ uvc_function_bind(struct usb_configuration *c, struct 
>>usb_function *f)
>>                cpu_to_le16(min(opts->streaming_maxpacket, 1023U));
>>        uvc_fs_streaming_ep.bInterval = opts->streaming_interval;
>>
>>+       /* A high-bandwidth endpoint must specify a bInterval value of 1 */
>>+       if (max_packet_mult > 1)
>>+               uvc_hs_streaming_ep.bInterval = 1;
>>+       else
>>+               uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>>+
>>
>>There is a "uvc_hs_streaming_ep.bInterval = opts->streaming_interval;" again 
>>at below code
>>Besides, the default value is 1 for opts->streaming_interval. What the real 
>>issue you observed
>>at CV test?
>>
>
>The issue occurs when I intentionally set:
>echo 3072  > functions/$FUNCTION/streaming_maxpacket
>echo 4 > functions/$FUNCTION/streaming_interval
>
>Then for  CV CH9 TD 9.5: Endpoint Descriptor test it got:
>"(Mult = 2)Illegal high speed isochronous endpoint MaxPacketSize : 0x400
>(USB: 1.2.78) A High speed Interrupt/Isochronous endpoint must have a 
>MaxPacketSize between
>683 and 1024 and bInterval value of 1 when the Mult value is two."
>
>For default value CV passed.  Of course, I can fix it by changing  
>streaming_interval, but I thought that
>it could be good to have protection against this issue.
>Especially since Usb 2 specification say that bInterval must be 1 for high 
>bandwidth endpoints.
>
>Pawel
>
>>Peter
>>
>>        uvc_hs_streaming_ep.wMaxPacketSize =
>>                cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
>>        uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>>--
>>2.25.1


[PATCH v2 2/2] usb: webcam: Invalid size of Processing Unit Descriptor

2021-03-09 Thread Pawel Laszczak
From: Pawel Laszczak 

According with USB Device Class Definition for Video Device the
Processing Unit Descriptor bLength should be 12 (10 + bmControlSize),
but it has 11.

Invalid length caused that Processing Unit Descriptor Test Video form
CV tool failed. To fix this issue patch adds bmVideoStandards into
uvc_processing_unit_descriptor structure.

Signed-off-by: Pawel Laszczak 
---
Changelog:
v2:
- updated UVC_DT_PROCESSING_UNIT_SIZE macro

 include/uapi/linux/usb/video.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
index d854cb19c42c..bfdae12cdacf 100644
--- a/include/uapi/linux/usb/video.h
+++ b/include/uapi/linux/usb/video.h
@@ -302,9 +302,10 @@ struct uvc_processing_unit_descriptor {
__u8   bControlSize;
__u8   bmControls[2];
__u8   iProcessing;
+   __u8   bmVideoStandards;
 } __attribute__((__packed__));
 
-#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
+#define UVC_DT_PROCESSING_UNIT_SIZE(n) (10+(n))
 
 /* 3.7.2.6. Extension Unit Descriptor */
 struct uvc_extension_unit_descriptor {
-- 
2.25.1



RE: [PATCH] usb: gadget: uvc: add bInterval checking for HS mode

2021-03-08 Thread Pawel Laszczak
Peter,

You're right. This patch is wrong. I didn't remove the 
"uvc_hs_streaming_ep.bInterval"
assignment. 

It has been fixed in v2.

Pawel

>>
>>On Fri, Mar 5, 2021 at 12:40 AM Pawel Laszczak <mailto:paw...@cadence.com> 
>>wrote:
>>From: Pawel Laszczak <mailto:paw...@cadence.com>
>>
>>Patch adds extra checking for bInterval passed by configfs.
>>The 5.6.4 chapter of USB Specification (rev. 2.0) say:
>>"A high-bandwidth endpoint must specify a period of 1x125 µs
>>(i.e., a bInterval value of 1)."
>>
>>The issue was observed during testing UVC class on CV.
>>I treat this change as improvement because we can control
>>bInterval by configfs.
>>
>>Signed-off-by: Pawel Laszczak <mailto:paw...@cadence.com>
>>---
>> drivers/usb/gadget/function/f_uvc.c | 6 ++
>> 1 file changed, 6 insertions(+)
>>
>>diff --git a/drivers/usb/gadget/function/f_uvc.c 
>>b/drivers/usb/gadget/function/f_uvc.c
>>index 44b4352a2676..5d62720bb9e1 100644
>>--- a/drivers/usb/gadget/function/f_uvc.c
>>+++ b/drivers/usb/gadget/function/f_uvc.c
>>@@ -631,6 +631,12 @@ uvc_function_bind(struct usb_configuration *c, struct 
>>usb_function *f)
>>                cpu_to_le16(min(opts->streaming_maxpacket, 1023U));
>>        uvc_fs_streaming_ep.bInterval = opts->streaming_interval;
>>
>>+       /* A high-bandwidth endpoint must specify a bInterval value of 1 */
>>+       if (max_packet_mult > 1)
>>+               uvc_hs_streaming_ep.bInterval = 1;
>>+       else
>>+               uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>>+
>>
>>There is a "uvc_hs_streaming_ep.bInterval = opts->streaming_interval;" again 
>>at below code
>>Besides, the default value is 1 for opts->streaming_interval. What the real 
>>issue you observed
>>at CV test?
>>
>
>The issue occurs when I intentionally set:
>echo 3072  > functions/$FUNCTION/streaming_maxpacket
>echo 4 > functions/$FUNCTION/streaming_interval
>
>Then for  CV CH9 TD 9.5: Endpoint Descriptor test it got:
>"(Mult = 2)Illegal high speed isochronous endpoint MaxPacketSize : 0x400
>(USB: 1.2.78) A High speed Interrupt/Isochronous endpoint must have a 
>MaxPacketSize between
>683 and 1024 and bInterval value of 1 when the Mult value is two."
>
>For default value CV passed.  Of course, I can fix it by changing  
>streaming_interval, but I thought that
>it could be good to have protection against this issue.
>Especially since Usb 2 specification say that bInterval must be 1 for high 
>bandwidth endpoints.
>
>Pawel
>
>>Peter
>>
>>        uvc_hs_streaming_ep.wMaxPacketSize =
>>                cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
>>        uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>>--
>>2.25.1

Thanks,
Pawel Laszczak


[PATCH v2] usb: gadget: uvc: add bInterval checking for HS mode

2021-03-08 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch adds extra checking for bInterval passed by configfs.
The 5.6.4 chapter of USB Specification (rev. 2.0) say:
"A high-bandwidth endpoint must specify a period of 1x125 µs
(i.e., a bInterval value of 1)."

The issue was observed during testing UVC class on CV.
I treat this change as improvement because we can control
bInterval by configfs.

Signed-off-by: Pawel Laszczak 

---
Changlog:
v2:
- removed duplicated assignment

 drivers/usb/gadget/function/f_uvc.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c 
b/drivers/usb/gadget/function/f_uvc.c
index 44b4352a2676..ed77a126a74f 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -633,7 +633,12 @@ uvc_function_bind(struct usb_configuration *c, struct 
usb_function *f)
 
uvc_hs_streaming_ep.wMaxPacketSize =
cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
-   uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
+
+   /* A high-bandwidth endpoint must specify a bInterval value of 1 */
+   if (max_packet_mult > 1)
+   uvc_hs_streaming_ep.bInterval = 1;
+   else
+   uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
 
uvc_ss_streaming_ep.wMaxPacketSize = cpu_to_le16(max_packet_size);
uvc_ss_streaming_ep.bInterval = opts->streaming_interval;
-- 
2.25.1



[PATCH 2/2] usb: webcam: Invalid size of Processing Unit Descriptor

2021-03-08 Thread Pawel Laszczak
From: Pawel Laszczak 

According with USB Device Class Definition for Video Device the
Processing Unit Descriptor bLength should be 12 (10 + bmControlSize),
but it has 11.

Invalid length caused that Processing Unit Descriptor Test Video form
CV tool failed. To fix this issue patch adds bmVideoStandards into
uvc_processing_unit_descriptor structure.

Signed-off-by: Pawel Laszczak 
---
 include/uapi/linux/usb/video.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h
index d854cb19c42c..2a54e8fdd341 100644
--- a/include/uapi/linux/usb/video.h
+++ b/include/uapi/linux/usb/video.h
@@ -302,6 +302,7 @@ struct uvc_processing_unit_descriptor {
__u8   bControlSize;
__u8   bmControls[2];
__u8   iProcessing;
+   __u8   bmVideoStandards;
 } __attribute__((__packed__));
 
 #define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
-- 
2.25.1



[PATCH 1/2] usb: gadget: uvc: Updating bcdUVC field to 0x0110

2021-03-08 Thread Pawel Laszczak
From: Pawel Laszczak 

Command Verifier during UVC Descriptor Tests (Class Video Control
Interface Descriptor Test Video) compleins about:

Video Control Interface Header bcdUVC is 0x0100. USB Video Class
specification 1.0 has been replaced by 1.1 specification
(UVC: 6.2.26) Class Video Control Interface Descriptor bcdUVC is not 1.1

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/gadget/function/uvc_configfs.c | 2 +-
 drivers/usb/gadget/legacy/webcam.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/uvc_configfs.c 
b/drivers/usb/gadget/function/uvc_configfs.c
index 00fb58e50a15..cd28dec837dd 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -231,7 +231,7 @@ static struct config_item *uvcg_control_header_make(struct 
config_group *group,
h->desc.bLength = UVC_DT_HEADER_SIZE(1);
h->desc.bDescriptorType = USB_DT_CS_INTERFACE;
h->desc.bDescriptorSubType  = UVC_VC_HEADER;
-   h->desc.bcdUVC  = cpu_to_le16(0x0100);
+   h->desc.bcdUVC  = cpu_to_le16(0x0110);
h->desc.dwClockFrequency= cpu_to_le32(4800);
 
config_item_init_type_name(>item, name, _control_header_type);
diff --git a/drivers/usb/gadget/legacy/webcam.c 
b/drivers/usb/gadget/legacy/webcam.c
index a9f8eb8e1c76..3a61de4bb2b1 100644
--- a/drivers/usb/gadget/legacy/webcam.c
+++ b/drivers/usb/gadget/legacy/webcam.c
@@ -90,7 +90,7 @@ static const struct UVC_HEADER_DESCRIPTOR(1) 
uvc_control_header = {
.bLength= UVC_DT_HEADER_SIZE(1),
.bDescriptorType= USB_DT_CS_INTERFACE,
.bDescriptorSubType = UVC_VC_HEADER,
-   .bcdUVC = cpu_to_le16(0x0100),
+   .bcdUVC = cpu_to_le16(0x0110),
.wTotalLength   = 0, /* dynamic */
.dwClockFrequency   = cpu_to_le32(4800),
.bInCollection  = 0, /* dynamic */
-- 
2.25.1



RE: [PATCH] usb: gadget: uvc: add bInterval checking for HS mode

2021-03-08 Thread Pawel Laszczak
>
>On Fri, Mar 5, 2021 at 12:40 AM Pawel Laszczak <mailto:paw...@cadence.com> 
>wrote:
>From: Pawel Laszczak <mailto:paw...@cadence.com>
>
>Patch adds extra checking for bInterval passed by configfs.
>The 5.6.4 chapter of USB Specification (rev. 2.0) say:
>"A high-bandwidth endpoint must specify a period of 1x125 µs
>(i.e., a bInterval value of 1)."
>
>The issue was observed during testing UVC class on CV.
>I treat this change as improvement because we can control
>bInterval by configfs.
>
>Signed-off-by: Pawel Laszczak <mailto:paw...@cadence.com>
>---
> drivers/usb/gadget/function/f_uvc.c | 6 ++
> 1 file changed, 6 insertions(+)
>
>diff --git a/drivers/usb/gadget/function/f_uvc.c 
>b/drivers/usb/gadget/function/f_uvc.c
>index 44b4352a2676..5d62720bb9e1 100644
>--- a/drivers/usb/gadget/function/f_uvc.c
>+++ b/drivers/usb/gadget/function/f_uvc.c
>@@ -631,6 +631,12 @@ uvc_function_bind(struct usb_configuration *c, struct 
>usb_function *f)
>                cpu_to_le16(min(opts->streaming_maxpacket, 1023U));
>        uvc_fs_streaming_ep.bInterval = opts->streaming_interval;
>
>+       /* A high-bandwidth endpoint must specify a bInterval value of 1 */
>+       if (max_packet_mult > 1)
>+               uvc_hs_streaming_ep.bInterval = 1;
>+       else
>+               uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>+
>
>There is a "uvc_hs_streaming_ep.bInterval = opts->streaming_interval;" again 
>at below code
>Besides, the default value is 1 for opts->streaming_interval. What the real 
>issue you observed
>at CV test?
>

The issue occurs when I intentionally set:
echo 3072  > functions/$FUNCTION/streaming_maxpacket
echo 4 > functions/$FUNCTION/streaming_interval

Then for  CV CH9 TD 9.5: Endpoint Descriptor test it got:
"(Mult = 2)Illegal high speed isochronous endpoint MaxPacketSize : 0x400
(USB: 1.2.78) A High speed Interrupt/Isochronous endpoint must have a 
MaxPacketSize between
683 and 1024 and bInterval value of 1 when the Mult value is two."

For default value CV passed.  Of course, I can fix it by changing  
streaming_interval, but I thought that
it could be good to have protection against this issue. 
Especially since Usb 2 specification say that bInterval must be 1 for high 
bandwidth endpoints.

Pawel

>Peter
>
>        uvc_hs_streaming_ep.wMaxPacketSize =
>                cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
>        uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
>--
>2.25.1


RE: [PATCH] usb: cdnsp: Fixes incorrect value in ISOC TRB

2021-03-07 Thread Pawel Laszczak


You have right. It's the operator priority issue.

I've made  this condition as separate "if" statement as suggested by Greg.

V2 has been posted.

Pawel
>
>
>On 21-03-05 06:10:59, Pawel Laszczak wrote:
>> From: Pawel Laszczak 
>>
>> The value "start_cycle ? 0 : 1" in assignment caused
>> implicit truncation whole value to 1 byte.
>> To fix the issue, an explicit casting has been added.
>
>The root cause for this issue should be operator "|" priority higher
>than "? :", I think just add () for start_cycle ? 0 : 1 could fix it.
>Please double confirm it, and change the commit log if necessary
>
>Peter
>>
>> Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence 
>> USBSSP DRD Driver")
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  drivers/usb/cdns3/cdnsp-ring.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
>> index f9170d177a89..d35bc4490216 100644
>> --- a/drivers/usb/cdns3/cdnsp-ring.c
>> +++ b/drivers/usb/cdns3/cdnsp-ring.c
>> @@ -2197,7 +2197,7 @@ static int cdnsp_queue_isoc_tx(struct cdnsp_device 
>> *pdev,
>>   * inverted in the first TDs isoc TRB.
>>   */
>>  field = TRB_TYPE(TRB_ISOC) | TRB_TLBPC(last_burst_pkt) |
>> -start_cycle ? 0 : 1 | TRB_SIA | TRB_TBC(burst_count);
>> +    (u32)(start_cycle ? 0 : 1) | TRB_SIA | TRB_TBC(burst_count);
>>
>>  /* Fill the rest of the TRB fields, and remaining normal TRBs. */
>>  for (i = 0; i < trbs_per_td; i++) {
>> --
>> 2.25.1
>>

--

Thanks,
Pawel Laszczak



[PATCH v2] usb: cdnsp: Fixes incorrect value in ISOC TRB

2021-03-07 Thread Pawel Laszczak
From: Pawel Laszczak 

Fixes issue with priority of operator. Operator "|" priority is
higher then "? :".
To improve the readability the operator "? :" has been replaced with
"if ()" statement.

Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD 
Driver")
Signed-off-by: Pawel Laszczak 

---
Changelog:
v2:
- changed the commit log
- added separate "if" statement to improve readability

 drivers/usb/cdns3/cdnsp-ring.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
index e15e13ba27dc..b23f09a68427 100644
--- a/drivers/usb/cdns3/cdnsp-ring.c
+++ b/drivers/usb/cdns3/cdnsp-ring.c
@@ -2198,7 +2198,10 @@ static int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev,
 * inverted in the first TDs isoc TRB.
 */
field = TRB_TYPE(TRB_ISOC) | TRB_TLBPC(last_burst_pkt) |
-   start_cycle ? 0 : 1 | TRB_SIA | TRB_TBC(burst_count);
+   TRB_SIA | TRB_TBC(burst_count);
+
+   if (!start_cycle)
+   field |= TRB_CYCLE;
 
/* Fill the rest of the TRB fields, and remaining normal TRBs. */
for (i = 0; i < trbs_per_td; i++) {
-- 
2.25.1



RE: [PATCH] usb: cdnsp: Fixes incorrect value in ISOC TRB

2021-03-04 Thread Pawel Laszczak
Hi,

Please ignore this patch. I put incorrect address to Peter. I have sent again 
this patch with correct email address.

>-Original Message-
>From: Pawel Laszczak 
>Sent: Friday, March 5, 2021 6:00 AM
>To: peter.c...@nxp.com
>Cc: gre...@linuxfoundation.org; linux-...@vger.kernel.org; 
>linux-kernel@vger.kernel.org; Rahul Kumar ;
>Sanket Parmar ; Pawel Laszczak 
>Subject: [PATCH] usb: cdnsp: Fixes incorrect value in ISOC TRB
>
>From: Pawel Laszczak 
>
>The value "start_cycle ? 0 : 1" in assignment caused
>implicit truncation whole value to 1 byte.
>To fix the issue, an explicit casting has been added.
>
>Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP 
>DRD Driver")
>Signed-off-by: Pawel Laszczak 
>---
> drivers/usb/cdns3/cdnsp-ring.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
>index f9170d177a89..d35bc4490216 100644
>--- a/drivers/usb/cdns3/cdnsp-ring.c
>+++ b/drivers/usb/cdns3/cdnsp-ring.c
>@@ -2197,7 +2197,7 @@ static int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev,
>* inverted in the first TDs isoc TRB.
>*/
>   field = TRB_TYPE(TRB_ISOC) | TRB_TLBPC(last_burst_pkt) |
>-  start_cycle ? 0 : 1 | TRB_SIA | TRB_TBC(burst_count);
>+  (u32)(start_cycle ? 0 : 1) | TRB_SIA | TRB_TBC(burst_count);
>
>   /* Fill the rest of the TRB fields, and remaining normal TRBs. */
>   for (i = 0; i < trbs_per_td; i++) {
>--
>2.25.1

Regards,
Pawel Laszczak


[PATCH] usb: cdnsp: Fixes incorrect value in ISOC TRB

2021-03-04 Thread Pawel Laszczak
From: Pawel Laszczak 

The value "start_cycle ? 0 : 1" in assignment caused
implicit truncation whole value to 1 byte.
To fix the issue, an explicit casting has been added.

Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP 
DRD Driver")
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
index f9170d177a89..d35bc4490216 100644
--- a/drivers/usb/cdns3/cdnsp-ring.c
+++ b/drivers/usb/cdns3/cdnsp-ring.c
@@ -2197,7 +2197,7 @@ static int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev,
 * inverted in the first TDs isoc TRB.
 */
field = TRB_TYPE(TRB_ISOC) | TRB_TLBPC(last_burst_pkt) |
-   start_cycle ? 0 : 1 | TRB_SIA | TRB_TBC(burst_count);
+   (u32)(start_cycle ? 0 : 1) | TRB_SIA | TRB_TBC(burst_count);
 
/* Fill the rest of the TRB fields, and remaining normal TRBs. */
for (i = 0; i < trbs_per_td; i++) {
-- 
2.25.1



[PATCH] usb: cdnsp: Fixes incorrect value in ISOC TRB

2021-03-04 Thread Pawel Laszczak
From: Pawel Laszczak 

The value "start_cycle ? 0 : 1" in assignment caused
implicit truncation whole value to 1 byte.
To fix the issue, an explicit casting has been added.

Fixes: commit 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP 
DRD Driver")
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
index f9170d177a89..d35bc4490216 100644
--- a/drivers/usb/cdns3/cdnsp-ring.c
+++ b/drivers/usb/cdns3/cdnsp-ring.c
@@ -2197,7 +2197,7 @@ static int cdnsp_queue_isoc_tx(struct cdnsp_device *pdev,
 * inverted in the first TDs isoc TRB.
 */
field = TRB_TYPE(TRB_ISOC) | TRB_TLBPC(last_burst_pkt) |
-   start_cycle ? 0 : 1 | TRB_SIA | TRB_TBC(burst_count);
+   (u32)(start_cycle ? 0 : 1) | TRB_SIA | TRB_TBC(burst_count);
 
/* Fill the rest of the TRB fields, and remaining normal TRBs. */
for (i = 0; i < trbs_per_td; i++) {
-- 
2.25.1



[PATCH] usb: gadget: uvc: add bInterval checking for HS mode

2021-03-04 Thread Pawel Laszczak
From: Pawel Laszczak 

Patch adds extra checking for bInterval passed by configfs.
The 5.6.4 chapter of USB Specification (rev. 2.0) say:
"A high-bandwidth endpoint must specify a period of 1x125 µs
(i.e., a bInterval value of 1)."

The issue was observed during testing UVC class on CV.
I treat this change as improvement because we can control
bInterval by configfs.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/gadget/function/f_uvc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/gadget/function/f_uvc.c 
b/drivers/usb/gadget/function/f_uvc.c
index 44b4352a2676..5d62720bb9e1 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -631,6 +631,12 @@ uvc_function_bind(struct usb_configuration *c, struct 
usb_function *f)
cpu_to_le16(min(opts->streaming_maxpacket, 1023U));
uvc_fs_streaming_ep.bInterval = opts->streaming_interval;
 
+   /* A high-bandwidth endpoint must specify a bInterval value of 1 */
+   if (max_packet_mult > 1)
+   uvc_hs_streaming_ep.bInterval = 1;
+   else
+   uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
+
uvc_hs_streaming_ep.wMaxPacketSize =
cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11));
uvc_hs_streaming_ep.bInterval = opts->streaming_interval;
-- 
2.25.1



RE: [PATCH 0/2] tracing: Detect unsafe dereferencing of pointers from trace events

2021-02-28 Thread Pawel Laszczak


+ Peter Chen - Maintainer of CDNS3 driver

>
>[ Resending with an address that should work for Felipe ]
>
>On Sat, 27 Feb 2021 14:18:02 -0500
>Steven Rostedt  wrote:
>
>> On Fri, 26 Feb 2021 14:21:00 -0800
>> Linus Torvalds  wrote:
>>
>> > On Fri, Feb 26, 2021 at 11:07 AM Steven Rostedt  
>> > wrote:
>> > >
>> > > The first patch scans the print fmts of the trace events looking for
>> > > dereferencing pointers from %p*, and making sure that they refer back
>> > > to the trace event itself.
>> > >
>> > > The second patch handles strings "%s" [..]
>> >
>> > Doing this at runtime really feels like the wrong thing to do.
>> >
>> > It won't even protect us from what happened - people like me and
>> > Andrew won't even run those tracepoints in the first place, so we
>> > won't notice.
>> >
>> > It really would be much better in every respect to have this done by
>> > checkpatch, I think.
>>
>> And after fixing the parsing to not trigger false positives, an
>> allyesconfig boot found this:
>>
>> event cdns3_gadget_giveback has unsafe dereference of argument 11
>> print_fmt: "%s: req: %p, req buff %p, length: %u/%u %s%s%s, status: %d, trb: 
>> [start:%d, end:%d: virt addr %pa], flags:%x SID: %u",
>__get_str(name), REC->req, REC->buf,
>>  REC->actual, REC->length, REC->zero ? "Z" : "z", REC->short_not_ok ? "S" : 
>> "s", REC->no_interrupt ? "I" : "i", REC->status, REC-
>>start_trb, REC->end_trb, REC->start_trb_addr, REC->flags, RE
>> C->stream_id
>>
>> (as the above is from a trace event class, it triggered for every event
>> in that class).
>>
>> As it looks like it uses %pa which IIUC from the printk code, it
>> dereferences the pointer to find it's virtual address. The event has
>> this as the field:
>>
>> __field(struct cdns3_trb *, start_trb_addr)
>>
>> Assigns it with:
>>
>> __entry->start_trb_addr = req->trb;
>>
>> And prints that with %pa, which will dereference pointer at the time of
>> reading, where the address in question may no longer be around. That
>> looks to me as a potential bug.
>>
>> [ Cc'd the people responsible for that code. ]
>>
>> -- Steve



RE: [PATCH][next] usb: cdnsp: Fix spelling mistake "delagete" -> "delegate"

2021-02-04 Thread Pawel Laszczak


I've sent the patch that remove this one and others similar printk from driver.

>
>
>On Thu, Feb 04, 2021 at 05:07:16AM +0000, Pawel Laszczak wrote:
>> Hi Dan,
>>
>> >> From: Colin Ian King 
>> >>
>> >> There is a spelling mistake in a literal string. Fix it.
>> >>
>> >> Signed-off-by: Colin Ian King 
>> >> ---
>> >>  drivers/usb/cdns3/cdnsp-ep0.c | 2 +-
>> >>  1 file changed, 1 insertion(+), 1 deletion(-)
>> >>
>> >> diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c
>> >> index e2b1bcb3f80e..e30931ebc870 100644
>> >> --- a/drivers/usb/cdns3/cdnsp-ep0.c
>> >> +++ b/drivers/usb/cdns3/cdnsp-ep0.c
>> >> @@ -45,7 +45,7 @@ static int cdnsp_ep0_delegate_req(struct cdnsp_device 
>> >> *pdev,
>> >>  {
>> >>   int ret;
>> >>
>> >> - trace_cdnsp_ep0_request("delagete");
>> >> + trace_cdnsp_ep0_request("delegate");
>> >>
>> >
>> >This printk is useless and should just be deleted.  Use ftrace instead.
>>
>> Maybe this printk is redundant but it's more comfortable in use.
>> To debug I can simply enable cdns-dev events (echo cdnsp-dev:* > set_event)
>> and I will get the full  picture of what the driver is doing.
>>
>> Otherwise, I must remember which function I need to add to set_ftrace_filter.
>> Of course, by default I can simply add all cdnsp* functions (echo cdnsp* > 
>> set_ftrace_filter) but it
>> increases the trace log and makes it a little more difficult to analyze.
>>
>> So maybe in some cases we shouldn't complain for such printk ?
>>
>> It's my private opinion and not necessarily correct :)
>
>Please don't have duplicate tracepoints for something like "this
>function is now called", it's redundant.
>

Thanks,
Pawel Laszczak


[PATCH] usb: cdnsp: Removes some useless trace events

2021-02-04 Thread Pawel Laszczak
Patch removes some useless trace events that can
be replaced by ftrace.

Reported-by: Dan Carpenter 
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-ep0.c|  5 -
 drivers/usb/cdns3/cdnsp-gadget.c |  2 --
 drivers/usb/cdns3/cdnsp-ring.c   |  1 -
 drivers/usb/cdns3/cdnsp-trace.h  | 10 --
 4 files changed, 18 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c
index e2b1bcb3f80e..9b8325f82499 100644
--- a/drivers/usb/cdns3/cdnsp-ep0.c
+++ b/drivers/usb/cdns3/cdnsp-ep0.c
@@ -24,13 +24,11 @@ static void cdnsp_ep0_stall(struct cdnsp_device *pdev)
preq = next_request(>pending_list);
 
if (pdev->three_stage_setup) {
-   trace_cdnsp_ep0_data_stage("send stall");
cdnsp_halt_endpoint(pdev, pep, true);
 
if (preq)
cdnsp_gadget_giveback(pep, preq, -ECONNRESET);
} else {
-   trace_cdnsp_ep0_status_stage("send stall");
pep->ep_state |= EP0_HALTED_STATUS;
 
if (preq)
@@ -45,8 +43,6 @@ static int cdnsp_ep0_delegate_req(struct cdnsp_device *pdev,
 {
int ret;
 
-   trace_cdnsp_ep0_request("delagete");
-
spin_unlock(>lock);
ret = pdev->gadget_driver->setup(>gadget, ctrl);
spin_lock(>lock);
@@ -130,7 +126,6 @@ static int cdnsp_ep0_set_address(struct cdnsp_device *pdev,
 
 int cdnsp_status_stage(struct cdnsp_device *pdev)
 {
-   trace_cdnsp_ep0_status_stage("preparing");
pdev->ep0_stage = CDNSP_STATUS_STAGE;
pdev->ep0_preq.request.length = 0;
 
diff --git a/drivers/usb/cdns3/cdnsp-gadget.c b/drivers/usb/cdns3/cdnsp-gadget.c
index f28f1508f049..f2ebbacd932e 100644
--- a/drivers/usb/cdns3/cdnsp-gadget.c
+++ b/drivers/usb/cdns3/cdnsp-gadget.c
@@ -237,8 +237,6 @@ static int cdnsp_start(struct cdnsp_device *pdev)
temp |= (CMD_R_S | CMD_DEVEN);
writel(temp, >op_regs->command);
 
-   trace_cdnsp_init("Turn on controller");
-
pdev->cdnsp_state = 0;
 
/*
diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
index e15e13ba27dc..f9170d177a89 100644
--- a/drivers/usb/cdns3/cdnsp-ring.c
+++ b/drivers/usb/cdns3/cdnsp-ring.c
@@ -266,7 +266,6 @@ static void cdnsp_force_l0_go(struct cdnsp_device *pdev)
 /* Ring the doorbell after placing a command on the ring. */
 void cdnsp_ring_cmd_db(struct cdnsp_device *pdev)
 {
-   trace_cdnsp_cmd_drbl("Ding Dong");
writel(DB_VALUE_CMD, >dba->cmd_db);
 }
 
diff --git a/drivers/usb/cdns3/cdnsp-trace.h b/drivers/usb/cdns3/cdnsp-trace.h
index a9de1daadf07..5aa88ca012de 100644
--- a/drivers/usb/cdns3/cdnsp-trace.h
+++ b/drivers/usb/cdns3/cdnsp-trace.h
@@ -158,11 +158,6 @@ DEFINE_EVENT(cdnsp_log_simple, cdnsp_slot_id,
TP_ARGS(msg)
 );
 
-DEFINE_EVENT(cdnsp_log_simple, cdnsp_cmd_drbl,
-   TP_PROTO(char *msg),
-   TP_ARGS(msg)
-);
-
 DEFINE_EVENT(cdnsp_log_simple, cdnsp_no_room_on_ring,
TP_PROTO(char *msg),
TP_ARGS(msg)
@@ -173,11 +168,6 @@ DEFINE_EVENT(cdnsp_log_simple, cdnsp_ep0_status_stage,
TP_ARGS(msg)
 );
 
-DEFINE_EVENT(cdnsp_log_simple, cdnsp_ep0_data_stage,
-   TP_PROTO(char *msg),
-   TP_ARGS(msg)
-);
-
 DEFINE_EVENT(cdnsp_log_simple, cdnsp_ep0_request,
TP_PROTO(char *msg),
TP_ARGS(msg)
-- 
2.25.1



RE: [PATCH][next] usb: cdnsp: Fix spelling mistake "delagete" -> "delegate"

2021-02-03 Thread Pawel Laszczak
Hi Dan,

>> From: Colin Ian King 
>>
>> There is a spelling mistake in a literal string. Fix it.
>>
>> Signed-off-by: Colin Ian King 
>> ---
>>  drivers/usb/cdns3/cdnsp-ep0.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c
>> index e2b1bcb3f80e..e30931ebc870 100644
>> --- a/drivers/usb/cdns3/cdnsp-ep0.c
>> +++ b/drivers/usb/cdns3/cdnsp-ep0.c
>> @@ -45,7 +45,7 @@ static int cdnsp_ep0_delegate_req(struct cdnsp_device 
>> *pdev,
>>  {
>>  int ret;
>>
>> -trace_cdnsp_ep0_request("delagete");
>> +trace_cdnsp_ep0_request("delegate");
>>
>
>This printk is useless and should just be deleted.  Use ftrace instead.

Maybe this printk is redundant but it's more comfortable in use.
To debug I can simply enable cdns-dev events (echo cdnsp-dev:* > set_event)
and I will get the full  picture of what the driver is doing.

Otherwise, I must remember which function I need to add to set_ftrace_filter.
Of course, by default I can simply add all cdnsp* functions (echo cdnsp* > 
set_ftrace_filter) but it
increases the trace log and makes it a little more difficult to analyze.

So maybe in some cases we shouldn't complain for such printk ?

It's my private opinion and not necessarily correct :)

Thanks,
Pawel Laszczak

>
>regards,
>dan carpenter



RE: [PATCH v2] usb: cdnsp: fixes undefined reference to cdns_remove

2021-01-13 Thread Pawel Laszczak
Hi Peter,

Can you replace the previous version with this one. 
The v1 still has problem with undefined reference when CONFIG_PCI or 
CONFIG_ACPI are disabled.

V2 fixes this issue. 

Thanks,
Regards,
Pawel Laszczak


>From: Pawel Laszczak 
>Sent: Wednesday, January 13, 2021 3:14 PM
>To: peter.c...@nxp.com
>Cc: rdun...@infradead.org; a-govindr...@ti.com; gre...@linuxfoundation.org; 
>linux-...@vger.kernel.org; linux-
>ker...@vger.kernel.org; Rahul Kumar ; 
>ge...@linux-m68k.org; Pawel Laszczak 
>Subject: [PATCH v2] usb: cdnsp: fixes undefined reference to cdns_remove
>
>Patch fixes the following errors:
>ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_remove':
>cdnsp-pci.c:(.text+0x80): undefined reference to `cdns_remove'
>ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_probe':
>cdnsp-pci.c:(.text+0x34c): undefined reference to `cdns_init'
>
>Issue occurs for USB/CDNS3/CDNSP kernel configuration:
>CONFIG_USB=m
>CONFIG_USB_CDNS_SUPPORT=y
>CONFIG_USB_CDNS3=m
>CONFIG_USB_CDNS3_PCI_WRAP=m
>CONFIG_USB_CDNSP_PCI=y
>
>Reported-by: Randy Dunlap 
>Signed-off-by: Pawel Laszczak 
>---
>changelog:
>v2
>- added missing condition
>
> drivers/usb/cdns3/Makefile | 8 
> 1 file changed, 8 insertions(+)
>
>diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
>index 3f9b7fa8a594..61edb2f89276 100644
>--- a/drivers/usb/cdns3/Makefile
>+++ b/drivers/usb/cdns3/Makefile
>@@ -26,7 +26,15 @@ obj-$(CONFIG_USB_CDNS3_TI)  += cdns3-ti.o
> obj-$(CONFIG_USB_CDNS3_IMX)   += cdns3-imx.o
>
> cdnsp-udc-pci-y   := cdnsp-pci.o
>+
>+ifdef CONFIG_USB_CDNSP_PCI
>+ifeq ($(CONFIG_USB),m)
>+obj-m += cdnsp-udc-pci.o
>+else
> obj-$(CONFIG_USB_CDNSP_PCI)   += cdnsp-udc-pci.o
>+endif
>+endif
>+
> cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)  += cdnsp-ring.o cdnsp-gadget.o \
>  cdnsp-mem.o cdnsp-ep0.o
>
>--
>2.17.1



[PATCH v2] usb: cdnsp: fixes undefined reference to cdns_remove

2021-01-13 Thread Pawel Laszczak
Patch fixes the following errors:
ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_remove':
cdnsp-pci.c:(.text+0x80): undefined reference to `cdns_remove'
ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_probe':
cdnsp-pci.c:(.text+0x34c): undefined reference to `cdns_init'

Issue occurs for USB/CDNS3/CDNSP kernel configuration:
CONFIG_USB=m
CONFIG_USB_CDNS_SUPPORT=y
CONFIG_USB_CDNS3=m
CONFIG_USB_CDNS3_PCI_WRAP=m
CONFIG_USB_CDNSP_PCI=y

Reported-by: Randy Dunlap 
Signed-off-by: Pawel Laszczak 
---
changelog:
v2
- added missing condition

 drivers/usb/cdns3/Makefile | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index 3f9b7fa8a594..61edb2f89276 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -26,7 +26,15 @@ obj-$(CONFIG_USB_CDNS3_TI)   += cdns3-ti.o
 obj-$(CONFIG_USB_CDNS3_IMX)+= cdns3-imx.o
 
 cdnsp-udc-pci-y:= cdnsp-pci.o
+
+ifdef CONFIG_USB_CDNSP_PCI
+ifeq ($(CONFIG_USB),m)
+obj-m  += cdnsp-udc-pci.o
+else
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
+endif
+endif
+
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
 
-- 
2.17.1



[PATCH] usb: cdnsp: fixes undefined reference to cdns_remove

2021-01-11 Thread Pawel Laszczak
Patch fixes the following errors:
ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_remove':
cdnsp-pci.c:(.text+0x80): undefined reference to `cdns_remove'
ld: drivers/usb/cdns3/cdnsp-pci.o: in function `cdnsp_pci_probe':
cdnsp-pci.c:(.text+0x34c): undefined reference to `cdns_init'

Issue occurs for USB/CDNS3/CDNSP kernel configuration:
CONFIG_USB=m
CONFIG_USB_CDNS_SUPPORT=y
CONFIG_USB_CDNS3=m
CONFIG_USB_CDNS3_PCI_WRAP=m
CONFIG_USB_CDNSP_PCI=y

Reported-by: Randy Dunlap 
Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index 3f9b7fa8a594..be906910f98b 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -26,7 +26,11 @@ obj-$(CONFIG_USB_CDNS3_TI)   += cdns3-ti.o
 obj-$(CONFIG_USB_CDNS3_IMX)+= cdns3-imx.o
 
 cdnsp-udc-pci-y:= cdnsp-pci.o
+ifeq ($(CONFIG_USB),m)
+obj-m  += cdnsp-udc-pci.o
+else
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
+endif
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
 
-- 
2.17.1



RE: [PATCH] usb: cdns3: Adds missing __iomem markers

2021-01-11 Thread Pawel Laszczak
Hi Peter,

What about this patch, can you apply it into for-usb-next ?

Thanks
Pawel

>
>Patch adds missing __iomem markers in core.h file
>and makes some changes in drd.c file related with
>these markers.
>
>The lack of __iomem has reported by sparse checker
>on parsic architecture.
>
>Signed-off-by: Pawel Laszczak 
>Reported-by: kernel test robot 
>---
> drivers/usb/cdns3/core.h | 12 ++--
> drivers/usb/cdns3/drd.c  | 12 ++--
> 2 files changed, 12 insertions(+), 12 deletions(-)
>
>diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
>index f8e350cef699..bfa39795208e 100644
>--- a/drivers/usb/cdns3/core.h
>+++ b/drivers/usb/cdns3/core.h
>@@ -86,12 +86,12 @@ struct cdns {
>   struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
>   struct cdns3_usb_regs __iomem   *dev_regs;
>
>-  struct resource otg_res;
>-  struct cdns3_otg_legacy_regs*otg_v0_regs;
>-  struct cdns3_otg_regs   *otg_v1_regs;
>-  struct cdnsp_otg_regs   *otg_cdnsp_regs;
>-  struct cdns_otg_common_regs *otg_regs;
>-  struct cdns_otg_irq_regs*otg_irq_regs;
>+  struct resource otg_res;
>+  struct cdns3_otg_legacy_regs __iomem*otg_v0_regs;
>+  struct cdns3_otg_regs __iomem   *otg_v1_regs;
>+  struct cdnsp_otg_regs __iomem   *otg_cdnsp_regs;
>+  struct cdns_otg_common_regs __iomem *otg_regs;
>+  struct cdns_otg_irq_reg __iomem *otg_irq_regs;
> #define CDNS3_CONTROLLER_V0   0
> #define CDNS3_CONTROLLER_V1   1
> #define CDNSP_CONTROLLER_V2   2
>diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
>index 605a413db727..0701853b501c 100644
>--- a/drivers/usb/cdns3/drd.c
>+++ b/drivers/usb/cdns3/drd.c
>@@ -27,7 +27,7 @@
>  */
> static int cdns_set_mode(struct cdns *cdns, enum usb_dr_mode mode)
> {
>-  u32 __iomem *override_reg;
>+  void __iomem  *override_reg;
>   u32 reg;
>
>   switch (mode) {
>@@ -406,7 +406,7 @@ int cdns_drd_init(struct cdns *cdns)
>   cdns->otg_v1_regs = NULL;
>   cdns->otg_cdnsp_regs = NULL;
>   cdns->otg_regs = regs;
>-  cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
>+  cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem  *)
>>otg_v0_regs->ien;
>   writel(1, >otg_v0_regs->simulate);
>   dev_dbg(cdns->dev, "DRD version v0 (%08x)\n",
>@@ -416,14 +416,14 @@ int cdns_drd_init(struct cdns *cdns)
>   cdns->otg_v1_regs = regs;
>   cdns->otg_cdnsp_regs = regs;
>
>-  cdns->otg_regs = (void *)>otg_v1_regs->cmd;
>+  cdns->otg_regs = (void __iomem *)>otg_v1_regs->cmd;
>
>-  if (cdns->otg_cdnsp_regs->did == OTG_CDNSP_DID) {
>-  cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
>+  if (readl(cdns->otg_cdnsp_regs->did) == OTG_CDNSP_DID) {
>+  cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
>*)
> >otg_cdnsp_regs->ien;
>   cdns->version  = CDNSP_CONTROLLER_V2;
>   } else {
>-  cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
>+  cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
>*)
> >otg_v1_regs->ien;
>   writel(1, >otg_v1_regs->simulate);
>   cdns->version  = CDNS3_CONTROLLER_V1;
>--
>2.17.1



[PATCH v2] usb: cdns3: Adds missing __iomem markers

2020-12-15 Thread Pawel Laszczak
Patch adds missing __iomem markers in core.h file
and makes some changes in drd.c file related with
these markers.

The lack of __iomem has reported by sparse checker
on parsic architecture.

Reported-by: kernel test robot 
Signed-off-by: Pawel Laszczak 
---
Changelog:
v2
 - fixed typo in cdns_otg_irq_regs name
 - fixed incorrect argument in readl

 drivers/usb/cdns3/core.h | 12 ++--
 drivers/usb/cdns3/drd.c  | 12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index f8e350cef699..ab0cb68acd23 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -86,12 +86,12 @@ struct cdns {
struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
struct cdns3_usb_regs __iomem   *dev_regs;
 
-   struct resource otg_res;
-   struct cdns3_otg_legacy_regs*otg_v0_regs;
-   struct cdns3_otg_regs   *otg_v1_regs;
-   struct cdnsp_otg_regs   *otg_cdnsp_regs;
-   struct cdns_otg_common_regs *otg_regs;
-   struct cdns_otg_irq_regs*otg_irq_regs;
+   struct resource otg_res;
+   struct cdns3_otg_legacy_regs __iomem*otg_v0_regs;
+   struct cdns3_otg_regs __iomem   *otg_v1_regs;
+   struct cdnsp_otg_regs __iomem   *otg_cdnsp_regs;
+   struct cdns_otg_common_regs __iomem *otg_regs;
+   struct cdns_otg_irq_regs __iomem*otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
 #define CDNSP_CONTROLLER_V22
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 605a413db727..fa5318ade3e1 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -27,7 +27,7 @@
  */
 static int cdns_set_mode(struct cdns *cdns, enum usb_dr_mode mode)
 {
-   u32 __iomem *override_reg;
+   void __iomem  *override_reg;
u32 reg;
 
switch (mode) {
@@ -406,7 +406,7 @@ int cdns_drd_init(struct cdns *cdns)
cdns->otg_v1_regs = NULL;
cdns->otg_cdnsp_regs = NULL;
cdns->otg_regs = regs;
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem  *)
 >otg_v0_regs->ien;
writel(1, >otg_v0_regs->simulate);
dev_dbg(cdns->dev, "DRD version v0 (%08x)\n",
@@ -416,14 +416,14 @@ int cdns_drd_init(struct cdns *cdns)
cdns->otg_v1_regs = regs;
cdns->otg_cdnsp_regs = regs;
 
-   cdns->otg_regs = (void *)>otg_v1_regs->cmd;
+   cdns->otg_regs = (void __iomem *)>otg_v1_regs->cmd;
 
-   if (cdns->otg_cdnsp_regs->did == OTG_CDNSP_DID) {
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   if (readl(>otg_cdnsp_regs->did) == OTG_CDNSP_DID) {
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
*)
  >otg_cdnsp_regs->ien;
cdns->version  = CDNSP_CONTROLLER_V2;
} else {
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
*)
  >otg_v1_regs->ien;
writel(1, >otg_v1_regs->simulate);
cdns->version  = CDNS3_CONTROLLER_V1;
-- 
2.17.1



RE: [PATCH 1/2] usb: cdnsp: Fixes for sparse warnings

2020-12-14 Thread Pawel Laszczak
>>On 20-12-15 05:27:38, Pawel Laszczak wrote:
>>> >
>>> >
>>> >On 20-12-14 13:03:44, Pawel Laszczak wrote:
>>> >> Patch fixes all sparse warnings in cdsnp driver.
>>> >>
>>> >> It fixes the following warnings:
>>> >> cdnsp-ring.c:1441: warning: incorrect type in assignment
>>> >> cdnsp-ring.c:1444: warning: restricted __le32 degrades to integer
>>> >> cdnsp-ring.c:2200: warning: dubious: x | !y
>>> >> cdnsp-gadget.c:501: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:504: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:507: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:508: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:509: warning: invalid assignment: |=
>>> >> cdnsp-gadget.c:510: warning: cast from restricted __le32
>>> >> cdnsp-gadget.c:558: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:561: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:570: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:1571: warning: incorrect type in argument 1
>>> >> cdnsp-gadget.c:1602: warning: restricted __le32 degrades to integer
>>> >> cdnsp-gadget.c:1760: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1762: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1763: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1764: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1765: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1766: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:1767: warning: incorrect type in assignment
>>> >> cdnsp-gadget.c:458: warning: cast truncates bits from constant value
>>> >> (07ff becomes 7ff)
>>> >> cdnsp-gadget.c:666: warning: cast truncates bits from constant value
>>> >> (07ff becomes 7ff)
>>> >> cdnsp-mem.c:762: warning: incorrect type in assignment
>>> >> cdnsp-mem.c:763: warning: incorrect type in assignment
>>> >> cdnsp-mem.c:928: warning: cast from restricted __le16
>>> >> cdnsp-mem.c:1187: warning: incorrect type in assignment
>>> >> cdnsp-mem.c:1191: warning: incorrect type in assignment
>>> >> cdnsp-ep0.c:142: warning: incorrect type in assignment
>>> >> cdnsp-ep0.c:144: warning: restricted __le32 degrades to integer
>>> >> cdnsp-ep0.c:147: warning: restricted __le32 degrades to integer
>>> >> cdnsp-ep0.c:148: warning: restricted __le32 degrades to integer
>>> >> cdnsp-ep0.c:179: warning: incorrect type in argument 1
>>> >> cdnsp-ep0.c:311: warning: incorrect type in argument 1
>>> >> cdnsp-ep0.c:469: warning: incorrect type in assignment
>>> >> cdnsp-trace.h:611:1: warning: cast from restricted __le32
>>> >>
>>> >> Signed-off-by: Pawel Laszczak 
>>> >> Reported-by: kernel test robot 
>>> >
>>> >Hi Pawel,
>>> >
>>> >The Reported-by tag should be above your Sob tag, I will change it.
>>> >Except the patch reported build error by kernel test robot, I will apply
>>> >your other four patches after finishing the compile test.
>>> >
>>> >Peter
>>>
>>> Hi Peter,
>>>
>>> I'm going to fix the "usb: cdns3: Adds missing __iomem markers"  today.
>>> I haven't  seen any issue on ARCH=parisc. Maybe it's some specific riscv 
>>> arch issue.
>>>
>>> I believe that:
>>> [auto build test WARNING on next-20201211]
>>> [cannot apply to peter.chen-usb/ci-for-usb-next v5.10 v5.10-rc7 v5.10-rc6 
>>> v5.10]
>>>
>>> is not the problem. I based on  peter.chen-usb/for-usb-next.
>>>
>>> Also I can't open the url from kernel test robot report.
>>> Maybe there is some temporary issue with server.
>>>
>>
>>Thanks for checking it, I have already pushed your other four patches.
>>Besides, there is still a build error issue for new cdns3 driver.
>>
>>https://urldefense.com/v3/__https://www.spinics.net/lists/linux-
>>usb/msg206073.html__;!!EHscmS1ygiU1lA!X6rYk64ILtzjyHW903LAhBRjMKi9C2eyJWEXVlEZm0ly2BiNzY2wK46Ulq7q5w$
>>
>
>Did you applied: [PATCH] usb: cdnsp: Fix 

RE: [PATCH 1/2] usb: cdnsp: Fixes for sparse warnings

2020-12-14 Thread Pawel Laszczak
>On 20-12-15 05:27:38, Pawel Laszczak wrote:
>> >
>> >
>> >On 20-12-14 13:03:44, Pawel Laszczak wrote:
>> >> Patch fixes all sparse warnings in cdsnp driver.
>> >>
>> >> It fixes the following warnings:
>> >> cdnsp-ring.c:1441: warning: incorrect type in assignment
>> >> cdnsp-ring.c:1444: warning: restricted __le32 degrades to integer
>> >> cdnsp-ring.c:2200: warning: dubious: x | !y
>> >> cdnsp-gadget.c:501: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:504: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:507: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:508: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:509: warning: invalid assignment: |=
>> >> cdnsp-gadget.c:510: warning: cast from restricted __le32
>> >> cdnsp-gadget.c:558: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:561: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:570: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:1571: warning: incorrect type in argument 1
>> >> cdnsp-gadget.c:1602: warning: restricted __le32 degrades to integer
>> >> cdnsp-gadget.c:1760: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1762: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1763: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1764: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1765: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1766: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:1767: warning: incorrect type in assignment
>> >> cdnsp-gadget.c:458: warning: cast truncates bits from constant value
>> >> (07ff becomes 7ff)
>> >> cdnsp-gadget.c:666: warning: cast truncates bits from constant value
>> >> (07ff becomes 7ff)
>> >> cdnsp-mem.c:762: warning: incorrect type in assignment
>> >> cdnsp-mem.c:763: warning: incorrect type in assignment
>> >> cdnsp-mem.c:928: warning: cast from restricted __le16
>> >> cdnsp-mem.c:1187: warning: incorrect type in assignment
>> >> cdnsp-mem.c:1191: warning: incorrect type in assignment
>> >> cdnsp-ep0.c:142: warning: incorrect type in assignment
>> >> cdnsp-ep0.c:144: warning: restricted __le32 degrades to integer
>> >> cdnsp-ep0.c:147: warning: restricted __le32 degrades to integer
>> >> cdnsp-ep0.c:148: warning: restricted __le32 degrades to integer
>> >> cdnsp-ep0.c:179: warning: incorrect type in argument 1
>> >> cdnsp-ep0.c:311: warning: incorrect type in argument 1
>> >> cdnsp-ep0.c:469: warning: incorrect type in assignment
>> >> cdnsp-trace.h:611:1: warning: cast from restricted __le32
>> >>
>> >> Signed-off-by: Pawel Laszczak 
>> >> Reported-by: kernel test robot 
>> >
>> >Hi Pawel,
>> >
>> >The Reported-by tag should be above your Sob tag, I will change it.
>> >Except the patch reported build error by kernel test robot, I will apply
>> >your other four patches after finishing the compile test.
>> >
>> >Peter
>>
>> Hi Peter,
>>
>> I'm going to fix the "usb: cdns3: Adds missing __iomem markers"  today.
>> I haven't  seen any issue on ARCH=parisc. Maybe it's some specific riscv 
>> arch issue.
>>
>> I believe that:
>> [auto build test WARNING on next-20201211]
>> [cannot apply to peter.chen-usb/ci-for-usb-next v5.10 v5.10-rc7 v5.10-rc6 
>> v5.10]
>>
>> is not the problem. I based on  peter.chen-usb/for-usb-next.
>>
>> Also I can't open the url from kernel test robot report.
>> Maybe there is some temporary issue with server.
>>
>
>Thanks for checking it, I have already pushed your other four patches.
>Besides, there is still a build error issue for new cdns3 driver.
>
>https://urldefense.com/v3/__https://www.spinics.net/lists/linux-
>usb/msg206073.html__;!!EHscmS1ygiU1lA!X6rYk64ILtzjyHW903LAhBRjMKi9C2eyJWEXVlEZm0ly2BiNzY2wK46Ulq7q5w$
>

Did you applied: [PATCH] usb: cdnsp: Fix for undefined reference to 
`usb_hcd_is_primary_hcd' ?

Pawel

>Peter
>> Thanks,
>> Pawel
>>
>> >> ---
>> >>  drivers/usb/cdns3/cdnsp-debug.h  |  2 +-
>> >>  drivers/usb/cdns3/cdnsp-ep0.c| 13 ++---
>> >>  drivers/usb/cdns3/cdnsp-gadget.c | 24

RE: [PATCH 1/2] usb: cdnsp: Fixes for sparse warnings

2020-12-14 Thread Pawel Laszczak
>
>
>On 20-12-14 13:03:44, Pawel Laszczak wrote:
>> Patch fixes all sparse warnings in cdsnp driver.
>>
>> It fixes the following warnings:
>> cdnsp-ring.c:1441: warning: incorrect type in assignment
>> cdnsp-ring.c:1444: warning: restricted __le32 degrades to integer
>> cdnsp-ring.c:2200: warning: dubious: x | !y
>> cdnsp-gadget.c:501: warning: incorrect type in assignment
>> cdnsp-gadget.c:504: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:507: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:508: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:509: warning: invalid assignment: |=
>> cdnsp-gadget.c:510: warning: cast from restricted __le32
>> cdnsp-gadget.c:558: warning: incorrect type in assignment
>> cdnsp-gadget.c:561: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:570: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:1571: warning: incorrect type in argument 1
>> cdnsp-gadget.c:1602: warning: restricted __le32 degrades to integer
>> cdnsp-gadget.c:1760: warning: incorrect type in assignment
>> cdnsp-gadget.c:1762: warning: incorrect type in assignment
>> cdnsp-gadget.c:1763: warning: incorrect type in assignment
>> cdnsp-gadget.c:1764: warning: incorrect type in assignment
>> cdnsp-gadget.c:1765: warning: incorrect type in assignment
>> cdnsp-gadget.c:1766: warning: incorrect type in assignment
>> cdnsp-gadget.c:1767: warning: incorrect type in assignment
>> cdnsp-gadget.c:458: warning: cast truncates bits from constant value
>> (07ff becomes 7ff)
>> cdnsp-gadget.c:666: warning: cast truncates bits from constant value
>> (07ff becomes 7ff)
>> cdnsp-mem.c:762: warning: incorrect type in assignment
>> cdnsp-mem.c:763: warning: incorrect type in assignment
>> cdnsp-mem.c:928: warning: cast from restricted __le16
>> cdnsp-mem.c:1187: warning: incorrect type in assignment
>> cdnsp-mem.c:1191: warning: incorrect type in assignment
>> cdnsp-ep0.c:142: warning: incorrect type in assignment
>> cdnsp-ep0.c:144: warning: restricted __le32 degrades to integer
>> cdnsp-ep0.c:147: warning: restricted __le32 degrades to integer
>> cdnsp-ep0.c:148: warning: restricted __le32 degrades to integer
>> cdnsp-ep0.c:179: warning: incorrect type in argument 1
>> cdnsp-ep0.c:311: warning: incorrect type in argument 1
>> cdnsp-ep0.c:469: warning: incorrect type in assignment
>> cdnsp-trace.h:611:1: warning: cast from restricted __le32
>>
>> Signed-off-by: Pawel Laszczak 
>> Reported-by: kernel test robot 
>
>Hi Pawel,
>
>The Reported-by tag should be above your Sob tag, I will change it.
>Except the patch reported build error by kernel test robot, I will apply
>your other four patches after finishing the compile test.
>
>Peter

Hi Peter,

I'm going to fix the "usb: cdns3: Adds missing __iomem markers"  today.
I haven't  seen any issue on ARCH=parisc. Maybe it's some specific riscv arch 
issue.

I believe that:
[auto build test WARNING on next-20201211]
[cannot apply to peter.chen-usb/ci-for-usb-next v5.10 v5.10-rc7 v5.10-rc6 v5.10]

is not the problem. I based on  peter.chen-usb/for-usb-next.

Also I can't open the url from kernel test robot report.
Maybe there is some temporary issue with server. 

Thanks,
Pawel

>> ---
>>  drivers/usb/cdns3/cdnsp-debug.h  |  2 +-
>>  drivers/usb/cdns3/cdnsp-ep0.c| 13 ++---
>>  drivers/usb/cdns3/cdnsp-gadget.c | 24 +---
>>  drivers/usb/cdns3/cdnsp-gadget.h | 13 +++--
>>  drivers/usb/cdns3/cdnsp-mem.c| 11 ++-
>>  drivers/usb/cdns3/cdnsp-ring.c   |  4 ++--
>>  drivers/usb/cdns3/cdnsp-trace.h  |  2 +-
>>  7 files changed, 32 insertions(+), 37 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-debug.h 
>> b/drivers/usb/cdns3/cdnsp-debug.h
>> index d6345d4d2911..a8776df2d4e0 100644
>> --- a/drivers/usb/cdns3/cdnsp-debug.h
>> +++ b/drivers/usb/cdns3/cdnsp-debug.h
>> @@ -414,7 +414,7 @@ static inline const char *cdnsp_decode_slot_context(u32 
>> info, u32 info2,
>>  s = "UNKNOWN speed";
>>  }
>>
>> -ret = sprintf(str, "%s Ctx Entries %ld",
>> +ret = sprintf(str, "%s Ctx Entries %d",
>>s, (info & LAST_CTX_MASK) >> 27);
>>
>>  ret += sprintf(str + ret, " [Intr %ld] Addr %ld State %s",
>> diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c
>> index d55b59ed7381..e2b1bcb3f80e 100644
>> --- a/driver

[PATCH] usb: cdns3: Adds missing __iomem markers

2020-12-14 Thread Pawel Laszczak
Patch adds missing __iomem markers in core.h file
and makes some changes in drd.c file related with
these markers.

The lack of __iomem has reported by sparse checker
on parsic architecture.

Signed-off-by: Pawel Laszczak 
Reported-by: kernel test robot 
---
 drivers/usb/cdns3/core.h | 12 ++--
 drivers/usb/cdns3/drd.c  | 12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index f8e350cef699..bfa39795208e 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -86,12 +86,12 @@ struct cdns {
struct resource xhci_res[CDNS_XHCI_RESOURCES_NUM];
struct cdns3_usb_regs __iomem   *dev_regs;
 
-   struct resource otg_res;
-   struct cdns3_otg_legacy_regs*otg_v0_regs;
-   struct cdns3_otg_regs   *otg_v1_regs;
-   struct cdnsp_otg_regs   *otg_cdnsp_regs;
-   struct cdns_otg_common_regs *otg_regs;
-   struct cdns_otg_irq_regs*otg_irq_regs;
+   struct resource otg_res;
+   struct cdns3_otg_legacy_regs __iomem*otg_v0_regs;
+   struct cdns3_otg_regs __iomem   *otg_v1_regs;
+   struct cdnsp_otg_regs __iomem   *otg_cdnsp_regs;
+   struct cdns_otg_common_regs __iomem *otg_regs;
+   struct cdns_otg_irq_reg __iomem *otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
 #define CDNSP_CONTROLLER_V22
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 605a413db727..0701853b501c 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -27,7 +27,7 @@
  */
 static int cdns_set_mode(struct cdns *cdns, enum usb_dr_mode mode)
 {
-   u32 __iomem *override_reg;
+   void __iomem  *override_reg;
u32 reg;
 
switch (mode) {
@@ -406,7 +406,7 @@ int cdns_drd_init(struct cdns *cdns)
cdns->otg_v1_regs = NULL;
cdns->otg_cdnsp_regs = NULL;
cdns->otg_regs = regs;
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem  *)
 >otg_v0_regs->ien;
writel(1, >otg_v0_regs->simulate);
dev_dbg(cdns->dev, "DRD version v0 (%08x)\n",
@@ -416,14 +416,14 @@ int cdns_drd_init(struct cdns *cdns)
cdns->otg_v1_regs = regs;
cdns->otg_cdnsp_regs = regs;
 
-   cdns->otg_regs = (void *)>otg_v1_regs->cmd;
+   cdns->otg_regs = (void __iomem *)>otg_v1_regs->cmd;
 
-   if (cdns->otg_cdnsp_regs->did == OTG_CDNSP_DID) {
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   if (readl(cdns->otg_cdnsp_regs->did) == OTG_CDNSP_DID) {
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
*)
  >otg_cdnsp_regs->ien;
cdns->version  = CDNSP_CONTROLLER_V2;
} else {
-   cdns->otg_irq_regs = (struct cdns_otg_irq_regs *)
+   cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem 
*)
  >otg_v1_regs->ien;
writel(1, >otg_v1_regs->simulate);
cdns->version  = CDNS3_CONTROLLER_V1;
-- 
2.17.1



[PATCH 1/2] usb: cdnsp: Fixes for sparse warnings

2020-12-14 Thread Pawel Laszczak
Patch fixes all sparse warnings in cdsnp driver.

It fixes the following warnings:
cdnsp-ring.c:1441: warning: incorrect type in assignment
cdnsp-ring.c:1444: warning: restricted __le32 degrades to integer
cdnsp-ring.c:2200: warning: dubious: x | !y
cdnsp-gadget.c:501: warning: incorrect type in assignment
cdnsp-gadget.c:504: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:507: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:508: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:509: warning: invalid assignment: |=
cdnsp-gadget.c:510: warning: cast from restricted __le32
cdnsp-gadget.c:558: warning: incorrect type in assignment
cdnsp-gadget.c:561: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:570: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:1571: warning: incorrect type in argument 1
cdnsp-gadget.c:1602: warning: restricted __le32 degrades to integer
cdnsp-gadget.c:1760: warning: incorrect type in assignment
cdnsp-gadget.c:1762: warning: incorrect type in assignment
cdnsp-gadget.c:1763: warning: incorrect type in assignment
cdnsp-gadget.c:1764: warning: incorrect type in assignment
cdnsp-gadget.c:1765: warning: incorrect type in assignment
cdnsp-gadget.c:1766: warning: incorrect type in assignment
cdnsp-gadget.c:1767: warning: incorrect type in assignment
cdnsp-gadget.c:458: warning: cast truncates bits from constant value
(07ff becomes 7ff)
cdnsp-gadget.c:666: warning: cast truncates bits from constant value
(07ff becomes 7ff)
cdnsp-mem.c:762: warning: incorrect type in assignment
cdnsp-mem.c:763: warning: incorrect type in assignment
cdnsp-mem.c:928: warning: cast from restricted __le16
cdnsp-mem.c:1187: warning: incorrect type in assignment
cdnsp-mem.c:1191: warning: incorrect type in assignment
cdnsp-ep0.c:142: warning: incorrect type in assignment
cdnsp-ep0.c:144: warning: restricted __le32 degrades to integer
cdnsp-ep0.c:147: warning: restricted __le32 degrades to integer
cdnsp-ep0.c:148: warning: restricted __le32 degrades to integer
cdnsp-ep0.c:179: warning: incorrect type in argument 1
cdnsp-ep0.c:311: warning: incorrect type in argument 1
cdnsp-ep0.c:469: warning: incorrect type in assignment
cdnsp-trace.h:611:1: warning: cast from restricted __le32

Signed-off-by: Pawel Laszczak 
Reported-by: kernel test robot 
---
 drivers/usb/cdns3/cdnsp-debug.h  |  2 +-
 drivers/usb/cdns3/cdnsp-ep0.c| 13 ++---
 drivers/usb/cdns3/cdnsp-gadget.c | 24 +---
 drivers/usb/cdns3/cdnsp-gadget.h | 13 +++--
 drivers/usb/cdns3/cdnsp-mem.c| 11 ++-
 drivers/usb/cdns3/cdnsp-ring.c   |  4 ++--
 drivers/usb/cdns3/cdnsp-trace.h  |  2 +-
 7 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/drivers/usb/cdns3/cdnsp-debug.h b/drivers/usb/cdns3/cdnsp-debug.h
index d6345d4d2911..a8776df2d4e0 100644
--- a/drivers/usb/cdns3/cdnsp-debug.h
+++ b/drivers/usb/cdns3/cdnsp-debug.h
@@ -414,7 +414,7 @@ static inline const char *cdnsp_decode_slot_context(u32 
info, u32 info2,
s = "UNKNOWN speed";
}
 
-   ret = sprintf(str, "%s Ctx Entries %ld",
+   ret = sprintf(str, "%s Ctx Entries %d",
  s, (info & LAST_CTX_MASK) >> 27);
 
ret += sprintf(str + ret, " [Intr %ld] Addr %ld State %s",
diff --git a/drivers/usb/cdns3/cdnsp-ep0.c b/drivers/usb/cdns3/cdnsp-ep0.c
index d55b59ed7381..e2b1bcb3f80e 100644
--- a/drivers/usb/cdns3/cdnsp-ep0.c
+++ b/drivers/usb/cdns3/cdnsp-ep0.c
@@ -137,10 +137,8 @@ int cdnsp_status_stage(struct cdnsp_device *pdev)
return cdnsp_ep_enqueue(pdev->ep0_preq.pep, >ep0_preq);
 }
 
-static int cdnsp_w_index_to_ep_index(__le32  wIndex)
+static int cdnsp_w_index_to_ep_index(u16 wIndex)
 {
-   wIndex = le32_to_cpu(wIndex);
-
if (!(wIndex & USB_ENDPOINT_NUMBER_MASK))
return 0;
 
@@ -176,7 +174,8 @@ static int cdnsp_ep0_handle_status(struct cdnsp_device 
*pdev,
 */
return cdnsp_ep0_delegate_req(pdev, ctrl);
case USB_RECIP_ENDPOINT:
-   pep = >eps[cdnsp_w_index_to_ep_index(ctrl->wIndex)];
+   ep_sts = cdnsp_w_index_to_ep_index(le16_to_cpu(ctrl->wIndex));
+   pep = >eps[ep_sts];
ep_sts = GET_EP_CTX_STATE(pep->out_ctx);
 
/* check if endpoint is stalled */
@@ -305,10 +304,10 @@ static int cdnsp_ep0_handle_feature_endpoint(struct 
cdnsp_device *pdev,
 int set)
 {
struct cdnsp_ep *pep;
-   u32 wValue;
+   u16 wValue;
 
wValue = le16_to_cpu(ctrl->wValue);
-   pep = >eps[cdnsp_w_index_to_ep_index(ctrl->wIndex)];
+   pep = >eps[cdnsp_w_index_to_ep_index(le16_to_cpu(ctrl->wIndex))];
 
switch (wValue) {
case USB_ENDPOINT_HALT:
@@ -435,7 +434,7 @@ void cdnsp

[PATCH] usb: cdns3: Fixes for sparse warnings

2020-12-14 Thread Pawel Laszczak
Patch fixes the following warnings:
cdns3-gadget.c:1203: sparse: warning: incorrect type
 in assignment (different base types)
cdns3-gadget.c:1203: sparse:  expected restricted __le32 [usertype] length
cdns3-gadget.c:1203: sparse:  got unsigned long
cdns3-gadget.c:1250: sparse: warning: invalid assignment: |=
cdns3-gadget.c:1250: sparse:  left side has type restricted __le32
cdns3-gadget.c:1250: sparse:  right side has type unsigned long
cdns3-gadget.c:1253: sparse: warning: invalid assignment: |=
cdns3-gadget.c:1253: sparse:  left side has type restricted __le32
cdns3-gadget.c:1253: sparse:  right side has type unsigned long
cdns3-ep0.c:367: sparse: warning: restricted __le16 degrades to integer
cdns3-ep0.c:792: sparse: warning: symbol 'cdns3_gadget_ep0_ops' was not
  declared. Should it be static?

Signed-off-by: Pawel Laszczak 
Reported-by: kernel test robot 
---
 drivers/usb/cdns3/cdns3-ep0.c| 4 ++--
 drivers/usb/cdns3/cdns3-gadget.c | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-ep0.c b/drivers/usb/cdns3/cdns3-ep0.c
index b0390fe9a396..9a17802275d5 100644
--- a/drivers/usb/cdns3/cdns3-ep0.c
+++ b/drivers/usb/cdns3/cdns3-ep0.c
@@ -364,7 +364,7 @@ static int cdns3_ep0_feature_handle_endpoint(struct 
cdns3_device *priv_dev,
if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT)
return -EINVAL;
 
-   if (!(ctrl->wIndex & ~USB_DIR_IN))
+   if (!(le16_to_cpu(ctrl->wIndex) & ~USB_DIR_IN))
return 0;
 
index = cdns3_ep_addr_to_index(le16_to_cpu(ctrl->wIndex));
@@ -789,7 +789,7 @@ int cdns3_gadget_ep_set_wedge(struct usb_ep *ep)
return 0;
 }
 
-const struct usb_ep_ops cdns3_gadget_ep0_ops = {
+static const struct usb_ep_ops cdns3_gadget_ep0_ops = {
.enable = cdns3_gadget_ep0_enable,
.disable = cdns3_gadget_ep0_disable,
.alloc_request = cdns3_gadget_ep_alloc_request,
diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
index 9b8b0cd3d2c2..582bfeceedb4 100644
--- a/drivers/usb/cdns3/cdns3-gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -1200,7 +1200,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint 
*priv_ep,
td_size = DIV_ROUND_UP(request->length,
   priv_ep->endpoint.maxpacket);
if (priv_dev->gadget.speed == USB_SPEED_SUPER)
-   trb->length = TRB_TDL_SS_SIZE(td_size);
+   trb->length = cpu_to_le32(TRB_TDL_SS_SIZE(td_size));
else
control |= TRB_TDL_HS_SIZE(td_size);
}
@@ -1247,10 +1247,10 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint 
*priv_ep,
priv_req->trb->control = cpu_to_le32(control);
 
if (sg_supported) {
-   trb->control |= TRB_ISP;
+   trb->control |= cpu_to_le32(TRB_ISP);
/* Don't set chain bit for last TRB */
if (sg_iter < num_trb - 1)
-   trb->control |= TRB_CHAIN;
+   trb->control |= cpu_to_le32(TRB_CHAIN);
 
s = sg_next(s);
}
-- 
2.17.1



RE: linux-next: Tree for Dec 9 (usb/cdns3)

2020-12-10 Thread Pawel Laszczak
Peter,

>
>>
>>>
>>>On 20-12-09 16:58:16, Randy Dunlap wrote:
>>>> On 12/9/20 2:44 AM, Stephen Rothwell wrote:
>>>> > Hi all,
>>>> >
>>>> > Changes since 20201208:
>>>> >
>>>>
>>>> (I don't know what to do about this one -- seeking help.)
>>>
>>>Add Pawel.
>>>
>>>Hi Pawel,
>>>
>>>Add old cdns3 logic, when the CONFIG_USB=m
>>>If CONFIG_USB_CDNS3 is M, the host will be built as module
>>>If CONFIG_USB_CDNS3 is build-in, the host will not built due to
>>>USB=m, so USB!= USB_CDNS3 at below dependency.
>>>
>>>config USB_CDNS3_HOST
>>> bool "Cadence USB3 host controller"
>>> depends on USB=y || USB=USB_CDNS3
>>>
>>>So, it has no such issue.
>>>
>>>But after adding CDNSSP support, the configuration relationship is
>>>much complicated, both CDNS3 and CDNSSP could choose host file,
>>>would you have a check for this issue?
>>
>>I can recreate this issue. I will try to resolve it.
>
>config USB_CDNS3_HOST
>bool "Cadence USB3 host controller"
>-   depends on USB=y || USB=USB_CDNS3
>+   depends on USB=USB_CDNS3
>select USB_CDNS_HOST
>help
>  Say Y here to enable host controller functionality of the
>@@ -110,7 +110,7 @@ config USB_CDNSP_GADGET
>
> config USB_CDNSP_HOST
>bool "Cadence CDNSP host controller"
>-   depends on USB=y || USB=USB_CDNSP_PCI
>+   depends on USB=USB_CDNSP_PCI
>select USB_CDNS_HOST
>help
>  Say Y here to enable host controller functionality of the
>
>Peter, what about such change. It fix this issue but I need to check
>It with some other kernel configurations.
>At this moment it's the only solution which I've found but
>it's introduces some limitation in CDNS3/CDNSP configuration.

It doesn't work correct.
I posted the patch with other solution. 

>
>>
>>>
>>>Peter
>>>
>>>>
>>>>
>>>> on x86_64:
>>>>
>>>> ld: drivers/usb/cdns3/host.o: in function `xhci_cdns3_suspend_quirk':
>>>> host.c:(.text+0x9): undefined reference to `usb_hcd_is_primary_hcd'
>>>>
>>>> This reference to 'usb_hdc_is_primary_hcd' is from hcd_to_xhci(),
>>>> which is being built as a loadable module:
>>>>
>>>> int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>>>> {
>>>>    struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>>>>
>>>>
>>>>
>>>>
>>>> CONFIG_USB_GADGET=y
>>>> CONFIG_USB_SUPPORT=y
>>>> CONFIG_USB_COMMON=y
>>>> # CONFIG_USB_CONN_GPIO is not set
>>>> CONFIG_USB_ARCH_HAS_HCD=y
>>>> CONFIG_USB=m
>>>>
>>>> CONFIG_USB_CDNS_SUPPORT=y
>>>> CONFIG_USB_CDNS_HOST=y
>>>> CONFIG_USB_CDNS3=m
>>>> CONFIG_USB_CDNS3_GADGET=y
>>>> CONFIG_USB_CDNS3_HOST=y
>>>>
>>>> Problem is mostly that CONFIG_USB=m and CONFIG_USB_GADGET=y.
>>>>
>>>>
>>>> Full randconfig file is attached.
>>>>
>>>>
>>>> thanks.
>>>> --
>>>> ~Randy
>>>> Reported-by: Randy Dunlap 
>>>
>>>
>>>
--

Thanks
Pawel Laszczak



RE: linux-next: Tree for Dec 9 (usb/cdns3)

2020-12-10 Thread Pawel Laszczak
Peter,

>
>>
>>On 20-12-09 16:58:16, Randy Dunlap wrote:
>>> On 12/9/20 2:44 AM, Stephen Rothwell wrote:
>>> > Hi all,
>>> >
>>> > Changes since 20201208:
>>> >
>>>
>>> (I don't know what to do about this one -- seeking help.)
>>
>>Add Pawel.
>>
>>Hi Pawel,
>>
>>Add old cdns3 logic, when the CONFIG_USB=m
>>If CONFIG_USB_CDNS3 is M, the host will be built as module
>>If CONFIG_USB_CDNS3 is build-in, the host will not built due to
>>USB=m, so USB!= USB_CDNS3 at below dependency.
>>
>>config USB_CDNS3_HOST
>>  bool "Cadence USB3 host controller"
>>  depends on USB=y || USB=USB_CDNS3
>>
>>So, it has no such issue.
>>
>>But after adding CDNSSP support, the configuration relationship is
>>much complicated, both CDNS3 and CDNSSP could choose host file,
>>would you have a check for this issue?
>
>I can recreate this issue. I will try to resolve it.

config USB_CDNS3_HOST
bool "Cadence USB3 host controller"
-   depends on USB=y || USB=USB_CDNS3
+   depends on USB=USB_CDNS3
select USB_CDNS_HOST
help
  Say Y here to enable host controller functionality of the
@@ -110,7 +110,7 @@ config USB_CDNSP_GADGET

 config USB_CDNSP_HOST
bool "Cadence CDNSP host controller"
-   depends on USB=y || USB=USB_CDNSP_PCI
+   depends on USB=USB_CDNSP_PCI
select USB_CDNS_HOST
help
  Say Y here to enable host controller functionality of the

Peter, what about such change. It fix this issue but I need to check
It with some other kernel configurations. 
At this moment it's the only solution which I've found but
it's introduces some limitation in CDNS3/CDNSP configuration.

>
>>
>>Peter
>>
>>>
>>>
>>> on x86_64:
>>>
>>> ld: drivers/usb/cdns3/host.o: in function `xhci_cdns3_suspend_quirk':
>>> host.c:(.text+0x9): undefined reference to `usb_hcd_is_primary_hcd'
>>>
>>> This reference to 'usb_hdc_is_primary_hcd' is from hcd_to_xhci(),
>>> which is being built as a loadable module:
>>>
>>> int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>>> {
>>> struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>>>
>>>
>>>
>>>
>>> CONFIG_USB_GADGET=y
>>> CONFIG_USB_SUPPORT=y
>>> CONFIG_USB_COMMON=y
>>> # CONFIG_USB_CONN_GPIO is not set
>>> CONFIG_USB_ARCH_HAS_HCD=y
>>> CONFIG_USB=m
>>>
>>> CONFIG_USB_CDNS_SUPPORT=y
>>> CONFIG_USB_CDNS_HOST=y
>>> CONFIG_USB_CDNS3=m
>>> CONFIG_USB_CDNS3_GADGET=y
>>> CONFIG_USB_CDNS3_HOST=y
>>>
>>> Problem is mostly that CONFIG_USB=m and CONFIG_USB_GADGET=y.
>>>
>>>
>>> Full randconfig file is attached.
>>>
>>>
>>> thanks.
>>> --
>>> ~Randy
>>> Reported-by: Randy Dunlap 
>>
>>
>>
--

Thanks
Pawel Laszczak



RE: linux-next: Tree for Dec 9 (usb/cdns3)

2020-12-10 Thread Pawel Laszczak


>
>On 20-12-09 16:58:16, Randy Dunlap wrote:
>> On 12/9/20 2:44 AM, Stephen Rothwell wrote:
>> > Hi all,
>> >
>> > Changes since 20201208:
>> >
>>
>> (I don't know what to do about this one -- seeking help.)
>
>Add Pawel.
>
>Hi Pawel,
>
>Add old cdns3 logic, when the CONFIG_USB=m
>If CONFIG_USB_CDNS3 is M, the host will be built as module
>If CONFIG_USB_CDNS3 is build-in, the host will not built due to
>USB=m, so USB!= USB_CDNS3 at below dependency.
>
>config USB_CDNS3_HOST
>   bool "Cadence USB3 host controller"
>   depends on USB=y || USB=USB_CDNS3
>
>So, it has no such issue.
>
>But after adding CDNSSP support, the configuration relationship is
>much complicated, both CDNS3 and CDNSSP could choose host file,
>would you have a check for this issue?

I can recreate this issue. I will try to resolve it. 

>
>Peter
>
>>
>>
>> on x86_64:
>>
>> ld: drivers/usb/cdns3/host.o: in function `xhci_cdns3_suspend_quirk':
>> host.c:(.text+0x9): undefined reference to `usb_hcd_is_primary_hcd'
>>
>> This reference to 'usb_hdc_is_primary_hcd' is from hcd_to_xhci(),
>> which is being built as a loadable module:
>>
>> int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>> {
>>  struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>>
>>
>>
>>
>> CONFIG_USB_GADGET=y
>> CONFIG_USB_SUPPORT=y
>> CONFIG_USB_COMMON=y
>> # CONFIG_USB_CONN_GPIO is not set
>> CONFIG_USB_ARCH_HAS_HCD=y
>> CONFIG_USB=m
>>
>> CONFIG_USB_CDNS_SUPPORT=y
>> CONFIG_USB_CDNS_HOST=y
>> CONFIG_USB_CDNS3=m
>> CONFIG_USB_CDNS3_GADGET=y
>> CONFIG_USB_CDNS3_HOST=y
>>
>> Problem is mostly that CONFIG_USB=m and CONFIG_USB_GADGET=y.
>>
>>
>> Full randconfig file is attached.
>>
>>
>> thanks.
>> --
>> ~Randy
>> Reported-by: Randy Dunlap 
>
>
>
--

Thanks
Pawel Laszczak



RE: [PATCH] usb: cdns3: Fixed kernel test robot warning

2020-12-09 Thread Pawel Laszczak
>
>On 12/9/20 12:15 PM, Souptick Joarder wrote:
>> Kernel test robot throws below warning ->
>>
>> In file included from drivers/usb/cdns3/core.c:23:
 drivers/usb/cdns3/host-export.h:27:51: warning: 'struct usb_hcd'
 declared inside parameter list will not be visible outside of this
 definition or declaration
>>   27 | static inline int xhci_cdns3_suspend_quirk(struct usb_hcd
>> *hcd)
>>  |   ^~~
>>
>> This patch will silence it.
>
>Really?  Didn't silence it for me when I tested this patch.
>
>Also, please see
>
>https://urldefense.com/v3/__https://lore.kernel.org/linux-
>usb/dbbpr04mb7979502194410bb1ae96df038b...@dbbpr04mb7979.eurprd04.prod.outlook.com/T/*m7f73fdd57c0f1577fb610dc
>af28646b53fa7dc26__;Iw!!EHscmS1ygiU1lA!XZzHlY6luEH3QepkggEsHS0x7oNNiz0XI9Xey3oIQpfSd1UVQEGzXbgXpfS2Eg$
>
>(what a strange URL)
>
>I now get these 2 warnings:
>
>In file included from ../drivers/usb/cdns3/core.c:23:0:
>../drivers/usb/cdns3/host-export.h:27:44: warning: ‘struct usb_hcd’ declared 
>inside parameter list will not be visible outside of this
>definition or declaration
> static int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>^~~
>  CC [M]  drivers/usb/gadget/function/uvc_queue.o
>../drivers/usb/cdns3/host-export.h:27:12: warning: ‘xhci_cdns3_suspend_quirk’ 
>defined but not used [-Wunused-function]
> static int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>^~~~
>

The best way for resolving this issue is to remove xhci_cdns3_suspend_quirk
from host-export.h file. It's used only in host.c file so it can be declared 
there
as static.

Thanks
Pawel

>
>> Reported-by: kernel test robot 
>> Signed-off-by: Souptick Joarder 
>> ---
>>  drivers/usb/cdns3/host-export.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/cdns3/host-export.h 
>> b/drivers/usb/cdns3/host-export.h
>> index fb8541b..c1259af 100644
>> --- a/drivers/usb/cdns3/host-export.h
>> +++ b/drivers/usb/cdns3/host-export.h
>> @@ -24,7 +24,7 @@ static inline int cdns_host_init(struct cdns *cdns)
>>  }
>>
>>  static inline void cdns_host_exit(struct cdns *cdns) { }
>> -static inline int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>> +static int xhci_cdns3_suspend_quirk(struct usb_hcd *hcd)
>>  {
>>  return 0;
>>  }
>>
>
>
>--
>~Randy
>Reported-by: Randy Dunlap 


[PATCH v5 10/10] MAINTAINERS: add Cadence USBSSP DRD IP driver entry

2020-12-07 Thread Pawel Laszczak
Patch adds entry for USBSSP (CDNSP) driver into MAINTARNERS file.

Signed-off-by: Pawel Laszczak 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 213b92ffe891..255390789176 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3859,6 +3859,15 @@ S:   Maintained
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
 F: Documentation/devicetree/bindings/usb/cdns,usb3.yaml
 F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdnsp*
+
+CADENCE USBSSP DRD IP DRIVER
+M: Pawel Laszczak 
+L: linux-...@vger.kernel.org
+S: Maintained
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
+F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdns3*
 
 CADET FM/AM RADIO RECEIVER DRIVER
 M: Hans Verkuil 
-- 
2.17.1



[PATCH v5 03/10] usb: cdns3: Moves reusable code to separate module

2020-12-07 Thread Pawel Laszczak
Patch moves common reusable code used by cdns3 and cdnsp driver
to cdns-usb-common library. This library include core.c, drd.c
and host.c files.

Signed-off-by: Pawel Laszczak 
Tested-by: Aswath Govindraju 
---
 drivers/usb/cdns3/Kconfig  |  8 
 drivers/usb/cdns3/Makefile |  8 +---
 drivers/usb/cdns3/cdns3-plat.c |  2 ++
 drivers/usb/cdns3/core.c   | 18 +++---
 drivers/usb/cdns3/core.h   |  3 +++
 drivers/usb/cdns3/drd.c|  3 ++-
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
index 84716d216ae5..58154c0a73ac 100644
--- a/drivers/usb/cdns3/Kconfig
+++ b/drivers/usb/cdns3/Kconfig
@@ -1,8 +1,15 @@
+config CDNS_USB_COMMON
+   tristate
+
+config CDNS_USB_HOST
+   bool
+
 config USB_CDNS3
tristate "Cadence USB3 Dual-Role Controller"
depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA
select USB_XHCI_PLATFORM if USB_XHCI_HCD
select USB_ROLE_SWITCH
+   select CDNS_USB_COMMON
help
  Say Y here if your system has a Cadence USB3 dual-role controller.
  It supports: dual-role switch, Host-only, and Peripheral-only.
@@ -25,6 +32,7 @@ config USB_CDNS3_GADGET
 config USB_CDNS3_HOST
bool "Cadence USB3 host controller"
depends on USB=y || USB=USB_CDNS3
+   select CDNS_USB_HOST
help
  Say Y here to enable host controller functionality of the
  Cadence driver.
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a1fe9612053a..16df87abf3cf 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,17 +2,19 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= cdns3-plat.o core.o drd.o
+cdns-usb-common-y  := core.o drd.o
+cdns3-y:= cdns3-plat.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
+obj-$(CONFIG_CDNS_USB_COMMON)  += cdns-usb-common.o
+
+cdns-usb-common-$(CONFIG_CDNS_USB_HOST) += host.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
 cdns3-$(CONFIG_TRACING)+= trace.o
 endif
 
-cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o
-
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
 obj-$(CONFIG_USB_CDNS3_TI) += cdns3-ti.o
 obj-$(CONFIG_USB_CDNS3_IMX)+= cdns3-imx.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index 5dcb83af6c86..d7b07f1729d5 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -18,6 +18,7 @@
 #include 
 
 #include "core.h"
+#include "gadget-export.h"
 
 static int set_phy_power_on(struct cdns3 *cdns)
 {
@@ -134,6 +135,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
if (ret)
goto err_phy_power_on;
 
+   cdns->gadget_init = cdns3_gadget_init;
ret = cdns3_init(cdns);
if (ret)
goto err_cdns_init;
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 7b67a7c74586..81ea035c0e11 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -19,10 +19,8 @@
 #include 
 #include 
 
-#include "gadget.h"
 #include "core.h"
 #include "host-export.h"
-#include "gadget-export.h"
 #include "drd.h"
 
 static int cdns3_idle_init(struct cdns3 *cdns);
@@ -147,7 +145,11 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
}
 
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
-   ret = cdns3_gadget_init(cdns);
+   if (cdns->gadget_init)
+   ret = cdns->gadget_init(cdns);
+   else
+   ret = -ENXIO;
+
if (ret) {
dev_err(dev, "Device initialization failed with %d\n",
ret);
@@ -477,6 +479,7 @@ int cdns3_init(struct cdns3 *cdns)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(cdns3_init);
 
 /**
  * cdns3_remove - unbind drd driver and clean up
@@ -491,6 +494,7 @@ int cdns3_remove(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_remove);
 
 #ifdef CONFIG_PM_SLEEP
 int cdns3_suspend(struct cdns3 *cdns)
@@ -509,6 +513,7 @@ int cdns3_suspend(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_suspend);
 
 int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 {
@@ -525,4 +530,11 @@ int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_resume);
 #endif /* CONFIG_PM_SLEEP */
+
+MODULE_AUTHOR("Peter Chen ");
+MODULE_AUTHOR("Pawel Laszczak ");
+MODULE_AUTHOR("Roger Quadros ");
+MODULE_DESCRIPTION("

[PATCH v5 02/10] usb: cdns3: Split core.c into cdns3-plat and core.c file

2020-12-07 Thread Pawel Laszczak
Patch splits file core.c into core.c containing the common reusable code
and cnd3-plat.c containing device platform specific code. These changes
are required to make possible reuse DRD part of CDNS3 driver in CDNSP
driver.

Signed-off-by: Pawel Laszczak 
Tested-by: Aswath Govindraju 
---
 drivers/usb/cdns3/Makefile |   2 +-
 drivers/usb/cdns3/cdns3-plat.c | 312 +
 drivers/usb/cdns3/core.c   | 284 +++---
 drivers/usb/cdns3/core.h   |   6 +
 drivers/usb/cdns3/drd.c|   1 -
 drivers/usb/cdns3/drd.h|   1 -
 6 files changed, 343 insertions(+), 263 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdns3-plat.c

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index d47e341a6f39..a1fe9612053a 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,7 +2,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= core.o drd.o
+cdns3-y:= cdns3-plat.o core.o drd.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
new file mode 100644
index ..5dcb83af6c86
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence USBSS DRD Driver.
+ *
+ * Copyright (C) 2018-2020 Cadence.
+ * Copyright (C) 2017-2018 NXP
+ * Copyright (C) 2019 Texas Instruments
+ *
+ *
+ * Author: Peter Chen 
+ * Pawel Laszczak 
+ * Roger Quadros 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+
+static int set_phy_power_on(struct cdns3 *cdns)
+{
+   int ret;
+
+   ret = phy_power_on(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   ret = phy_power_on(cdns->usb3_phy);
+   if (ret)
+   phy_power_off(cdns->usb2_phy);
+
+   return ret;
+}
+
+static void set_phy_power_off(struct cdns3 *cdns)
+{
+   phy_power_off(cdns->usb3_phy);
+   phy_power_off(cdns->usb2_phy);
+}
+
+/**
+ * cdns3_plat_probe - probe for cdns3 core device
+ * @pdev: Pointer to cdns3 core platform device
+ *
+ * Returns 0 on success otherwise negative errno
+ */
+static int cdns3_plat_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;
+   cdns->pdata = dev_get_platdata(dev);
+
+   platform_set_drvdata(pdev, cdns);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host");
+   if (!res) {
+   dev_err(dev, "missing host IRQ\n");
+   return -ENODEV;
+   }
+
+   cdns->xhci_res[0] = *res;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci");
+   if (!res) {
+   dev_err(dev, "couldn't get xhci resource\n");
+   return -ENXIO;
+   }
+
+   cdns->xhci_res[1] = *res;
+
+   cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral");
+
+   if (cdns->dev_irq < 0)
+   return cdns->dev_irq;
+
+   regs = devm_platform_ioremap_resource_byname(pdev, "dev");
+   if (IS_ERR(regs))
+   return PTR_ERR(regs);
+   cdns->dev_regs  = regs;
+
+   cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
+   if (cdns->otg_irq < 0)
+   return cdns->otg_irq;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
+   if (!res) {
+   dev_err(dev, "couldn't get otg resource\n");
+   return -ENXIO;
+   }
+
+   cdns->phyrst_a_enable = device_property_read_bool(dev, 
"cdns,phyrst-a-enable");
+
+   cdns->otg_res = *res;
+
+   cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+   if (cdns->wakeup_irq == -EPROBE_DEFER)
+   return cdns->wakeup_irq;
+   else if (cdns->wakeup_irq == 0)
+   return -EINVAL;
+
+   if (cdns->wakeup_irq < 0) {
+   dev_dbg(dev, "couldn't get wakeup irq\n");
+   cdns->wakeup_irq = 0x0;
+   }
+
+   cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy");
+   if (IS_ERR(cdns->usb2_phy))
+   return PTR_ERR(cdns->usb2_phy);
+
+   ret = phy_init(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,us

[PATCH v5 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-12-07 Thread Pawel Laszczak
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 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.

The device side of USBSS DRD controller is compliant with XHCI.
The architecture for device side is almost the same as for host side,
and most of the XHCI specification can be used to understand how
this controller operates.

This controller and driver support Full Speed, Hight Speed, Supper Speed
and Supper Speed Plus USB protocol.

The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
The last letter of this acronym means PLUS. The formal name of controller
is USBSSP but it's to generic so I've decided to use CDNSP.

The patch 1: adds support for DRD CDNSP.
The patch 2: separates common code that can be reusable by cdnsp driver.
The patch 3: moves reusable code to separate module.
The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
The patch 5: adopts gadget_dev pointer in cdns structure to make possible 
 use it in both drivers.
The patches 6-8: add the main part of driver and has been intentionally
 split into 3 part. In my opinion such division should not
 affect understanding and reviewing the driver, and cause that
 main patch (7/8) is little smaller. Patch 6 introduces main
 header file for driver, 7 is the main part that implements all
 functionality of driver and 8 introduces tracepoints.
The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.

Changlog from v4:
- fixed bug in cdns3_plat_runtime_resume as suggested  by Peter Chen
- fixed bug in cdns3_plat_suspend as suggested  by Peter Chen
- some typos have been removed

Changlog from v3:
- added 'T' to MAINTAINERS file for CDNSP entry
- updated common code with latest cdns3 fixes

Changlog from v2:
- removed not used pdev parameter from cdnsp_read/wite_64 functions
- fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
- replaced some constant value with CDNSP_ENDPOINTS_NUM macro
- replaced 'true' with '1' in bits description in cdnsp-gadget.h file
- fixed some typos
- some other less important changes suggested by Peter Chen

Changlog from v1:
- updated common code to latest cdns3 driver
- moved cdnsp driver files to cdns3 as suggested  by Peter Chen
- removed duplicate code from cdnsp_ep0_set_config function
- added cdns3 prefixes to file related with USBSS driver
- updated MAINTAINERS file
- fixed issue with U1
- fixed issue with L1
- some less improtant changes suggested  by Chunfeng Yun
---

Pawel Laszczak (10):
  usb: cdns3: Add support for DRD CDNSP
  usb: cdns3: Split core.c into cdns3-plat and core.c file
  usb: cdns3: Moves reusable code to separate module
  usb: cdns3: Refactoring names in reusable code
  usb: cdns3: Changed type of gadget_dev in cdns structure
  usb: cdnsp: Device side header file for CDNSP driver
  usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver
  usb: cdnsp: Add tracepoints for CDNSP driver
  usb: cdns3: Change file names for cdns3 driver.
  MAINTAINERS: add Cadence USBSSP DRD IP driver entry

 MAINTAINERS   |9 +
 drivers/usb/Makefile  |2 +
 drivers/usb/cdns3/Kconfig |   61 +-
 drivers/usb/cdns3/Makefile|   30 +-
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}  |0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}  |4 +-
 .../usb/cdns3/{gadget.c => cdns3-gadget.c}|   28 +-
 .../usb/cdns3/{gadget.h => cdns3-gadget.h}|0
 drivers/usb/cdns3/cdns3-imx.c |2 +-
 drivers/usb/cdns3/cdns3-plat.c|  315 +++
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}  |2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}  |6 +-
 drivers/usb/cdns3/cdnsp-debug.h   |  583 
 drivers/usb/cdns3/cdnsp-ep0.c |  495 
 drivers/usb/cdns3/cdnsp-gadget.c  | 2017 ++
 drivers/usb/cdns3/cdnsp-gadget.h  | 1600 +++
 drivers/usb/cdns3/cdnsp-mem.c | 1325 +
 drivers/usb/cdns3/cdnsp-pci.c |  255 ++
 drivers/usb/cdns3/cdnsp-ring.c| 2439 +
 drivers/usb/cdns3/cdnsp-trace.c   |   12 +
 drivers/usb/cdns3/cdnsp-trace.h   |  840 ++
 drivers/usb/cdns3/core.c  |  455 +--
 drivers/usb/cdns3/core.h  |   54 +-
 drivers/usb/cdns3/drd.c   |  222 +-
 dr

[PATCH v5 04/10] usb: cdns3: Refactoring names in reusable code

2020-12-07 Thread Pawel Laszczak
Patch change the functions and objects names in reusable code.
The reusable code includes core.c, core.h, drd.c and drd.h files.
It also changes the names of all references to these functions and
objects in other cdns3 files. There are a lot of changes, but all
changes are very trivial.
The reason of this patch is to avoid of mixing prefix cdns3 and cdnsp in
in cdnsp driver what could introduce some confusion in understanding
of cdnsp driver.
This patch assumes to use three different prefixes in Cadence
USB drivers:
  cdns: for common reusable code
  cdnsp: for names related only with cdnsp driver
  cdns3: for names related only with cdns3 driver

Signed-off-by: Pawel Laszczak 
Tested-by: Aswath Govindraju 
---
 drivers/usb/cdns3/cdns3-imx.c |   2 +-
 drivers/usb/cdns3/cdns3-plat.c|  25 +++---
 drivers/usb/cdns3/core.c  | 142 +++---
 drivers/usb/cdns3/core.h  |  46 +-
 drivers/usb/cdns3/drd.c   | 100 ++---
 drivers/usb/cdns3/drd.h   |  26 +++---
 drivers/usb/cdns3/gadget-export.h |   4 +-
 drivers/usb/cdns3/gadget.c|  24 ++---
 drivers/usb/cdns3/host-export.h   |   6 +-
 drivers/usb/cdns3/host.c  |  22 ++---
 10 files changed, 199 insertions(+), 198 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
index 22a56c4dce67..d9fb68766a15 100644
--- a/drivers/usb/cdns3/cdns3-imx.c
+++ b/drivers/usb/cdns3/cdns3-imx.c
@@ -250,7 +250,7 @@ static void cdns3_set_wakeup(struct cdns_imx *data, bool 
enable)
 static int cdns_imx_platform_suspend(struct device *dev,
bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
struct device *parent = dev->parent;
struct cdns_imx *data = dev_get_drvdata(parent);
void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs);
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index d7b07f1729d5..4b18e1c6a4bb 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -20,7 +20,7 @@
 #include "core.h"
 #include "gadget-export.h"
 
-static int set_phy_power_on(struct cdns3 *cdns)
+static int set_phy_power_on(struct cdns *cdns)
 {
int ret;
 
@@ -35,7 +35,7 @@ static int set_phy_power_on(struct cdns3 *cdns)
return ret;
 }
 
-static void set_phy_power_off(struct cdns3 *cdns)
+static void set_phy_power_off(struct cdns *cdns)
 {
phy_power_off(cdns->usb3_phy);
phy_power_off(cdns->usb2_phy);
@@ -51,7 +51,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
struct resource *res;
-   struct cdns3 *cdns;
+   struct cdns *cdns;
void __iomem *regs;
int ret;
 
@@ -136,7 +136,8 @@ static int cdns3_plat_probe(struct platform_device *pdev)
goto err_phy_power_on;
 
cdns->gadget_init = cdns3_gadget_init;
-   ret = cdns3_init(cdns);
+
+   ret = cdns_init(cdns);
if (ret)
goto err_cdns_init;
 
@@ -175,13 +176,13 @@ static int cdns3_plat_probe(struct platform_device *pdev)
  */
 static int cdns3_plat_remove(struct platform_device *pdev)
 {
-   struct cdns3 *cdns = platform_get_drvdata(pdev);
+   struct cdns *cdns = platform_get_drvdata(pdev);
struct device *dev = cdns->dev;
 
pm_runtime_get_sync(dev);
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);
-   cdns3_remove(cdns);
+   cdns_remove(cdns);
set_phy_power_off(cdns);
phy_exit(cdns->usb2_phy);
phy_exit(cdns->usb3_phy);
@@ -193,7 +194,7 @@ static int cdns3_plat_remove(struct platform_device *pdev)
 static int cdns3_set_platform_suspend(struct device *dev,
  bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret = 0;
 
if (cdns->pdata && cdns->pdata->platform_suspend)
@@ -204,7 +205,7 @@ static int cdns3_set_platform_suspend(struct device *dev,
 
 static int cdns3_controller_suspend(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
bool wakeup;
unsigned long flags;
 
@@ -228,7 +229,7 @@ static int cdns3_controller_suspend(struct device *dev, 
pm_message_t msg)
 
 static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret;
unsigned long flags;
 
@@ -242,7 +243,7 @@ static int cdns3_controller_resume(struct device *dev, 
pm_message_t msg)
cdns3_set_platform_suspend(cdns->dev, false, false);
 
spin_lock_irqsave(>lock, flags);
-   cdns3_resume(

[PATCH v5 08/10] usb: cdnsp: Add tracepoints for CDNSP driver

2020-12-07 Thread Pawel Laszczak
Patch adds the series of tracepoints that can be used for
debugging issues detected in driver.

Signed-off-by: Pawel Laszczak 
Reviewed-by: Peter Chen 
---
 drivers/usb/cdns3/Makefile   |   5 +
 drivers/usb/cdns3/cdnsp-debug.h  | 583 +
 drivers/usb/cdns3/cdnsp-ep0.c|  22 +-
 drivers/usb/cdns3/cdnsp-gadget.c |  75 ++-
 drivers/usb/cdns3/cdnsp-mem.c|  18 +-
 drivers/usb/cdns3/cdnsp-ring.c   |  75 ++-
 drivers/usb/cdns3/cdnsp-trace.c  |  12 +
 drivers/usb/cdns3/cdnsp-trace.h  | 840 +++
 8 files changed, 1614 insertions(+), 16 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdnsp-debug.h
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.c
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.h

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a84b129f14b8..a4fdaabdbe18 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
+CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
 cdns3-y:= cdns3-plat.o
@@ -23,3 +24,7 @@ cdnsp-udc-pci-y   := 
cdnsp-pci.o
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
+
+ifneq ($(CONFIG_USB_CDNSP_GADGET),)
+cdnsp-udc-pci-$(CONFIG_TRACING)+= cdnsp-trace.o
+endif
diff --git a/drivers/usb/cdns3/cdnsp-debug.h b/drivers/usb/cdns3/cdnsp-debug.h
new file mode 100644
index ..d6345d4d2911
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-debug.h
@@ -0,0 +1,583 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ */
+#ifndef __LINUX_CDNSP_DEBUG
+#define __LINUX_CDNSP_DEBUG
+
+static inline const char *cdnsp_trb_comp_code_string(u8 status)
+{
+   switch (status) {
+   case COMP_INVALID:
+   return "Invalid";
+   case COMP_SUCCESS:
+   return "Success";
+   case COMP_DATA_BUFFER_ERROR:
+   return "Data Buffer Error";
+   case COMP_BABBLE_DETECTED_ERROR:
+   return "Babble Detected";
+   case COMP_TRB_ERROR:
+   return "TRB Error";
+   case COMP_RESOURCE_ERROR:
+   return "Resource Error";
+   case COMP_NO_SLOTS_AVAILABLE_ERROR:
+   return "No Slots Available Error";
+   case COMP_INVALID_STREAM_TYPE_ERROR:
+   return "Invalid Stream Type Error";
+   case COMP_SLOT_NOT_ENABLED_ERROR:
+   return "Slot Not Enabled Error";
+   case COMP_ENDPOINT_NOT_ENABLED_ERROR:
+   return "Endpoint Not Enabled Error";
+   case COMP_SHORT_PACKET:
+   return "Short Packet";
+   case COMP_RING_UNDERRUN:
+   return "Ring Underrun";
+   case COMP_RING_OVERRUN:
+   return "Ring Overrun";
+   case COMP_VF_EVENT_RING_FULL_ERROR:
+   return "VF Event Ring Full Error";
+   case COMP_PARAMETER_ERROR:
+   return "Parameter Error";
+   case COMP_CONTEXT_STATE_ERROR:
+   return "Context State Error";
+   case COMP_EVENT_RING_FULL_ERROR:
+   return "Event Ring Full Error";
+   case COMP_INCOMPATIBLE_DEVICE_ERROR:
+   return "Incompatible Device Error";
+   case COMP_MISSED_SERVICE_ERROR:
+   return "Missed Service Error";
+   case COMP_COMMAND_RING_STOPPED:
+   return "Command Ring Stopped";
+   case COMP_COMMAND_ABORTED:
+   return "Command Aborted";
+   case COMP_STOPPED:
+   return "Stopped";
+   case COMP_STOPPED_LENGTH_INVALID:
+   return "Stopped - Length Invalid";
+   case COMP_STOPPED_SHORT_PACKET:
+   return "Stopped - Short Packet";
+   case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR:
+   return "Max Exit Latency Too Large Error";
+   case COMP_ISOCH_BUFFER_OVERRUN:
+   return "Isoch Buffer Overrun";
+   case COMP_EVENT_LOST_ERROR:
+   return "Event Lost Error";
+   case COMP_UNDEFINED_ERROR:
+   return "Undefined Error";
+   case COMP_INVALID_STREAM_ID_ERROR:
+   return "Invalid Stream ID Error";
+   default:
+   return "Unknown!!

[PATCH v5 06/10] usb: cdnsp: Device side header file for CDNSP driver

2020-12-07 Thread Pawel Laszczak
Patch defines macros, registers and structures used by
Device side driver.

Because the size of main patch is very big, I’ve decided to create
separate patch for cdnsp-gadget.h. It should simplify reviewing the code.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.h | 1463 ++
 1 file changed, 1463 insertions(+)
 create mode 100644 drivers/usb/cdns3/cdnsp-gadget.h

diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h
new file mode 100644
index ..93da1dcdad60
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-gadget.h
@@ -0,0 +1,1463 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ * Code based on Linux XHCI driver.
+ * Origin: Copyright (C) 2008 Intel Corp.
+ */
+#ifndef __LINUX_CDNSP_GADGET_H
+#define __LINUX_CDNSP_GADGET_H
+
+#include 
+#include 
+#include 
+
+/* Max number slots - only 1 is allowed. */
+#define CDNSP_DEV_MAX_SLOTS1
+
+#define CDNSP_EP0_SETUP_SIZE   512
+
+/* One control and 15 for in and 15 for out endpoints. */
+#define CDNSP_ENDPOINTS_NUM31
+
+/* Best Effort Service Latency. */
+#define CDNSP_DEFAULT_BESL 0
+
+/* Device Controller command default timeout value in us */
+#define CDNSP_CMD_TIMEOUT  (15 * 1000)
+
+/* Up to 16 ms to halt an device controller */
+#define CDNSP_MAX_HALT_USEC(16 * 1000)
+
+#define CDNSP_CTX_SIZE 2112
+
+/*
+ * Controller register interface.
+ */
+
+/**
+ * struct cdnsp_cap_regs - CDNSP Registers.
+ * @hc_capbase:Length of the capabilities register and controller
+ *  version number
+ * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
+ * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
+ * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
+ * @hcc_params: HCCPARAMS - Capability Parameters
+ * @db_off: DBOFF - Doorbell array offset
+ * @run_regs_off: RTSOFF - Runtime register space offset
+ * @hcc_params2: HCCPARAMS2 Capability Parameters 2,
+ */
+struct cdnsp_cap_regs {
+   __le32 hc_capbase;
+   __le32 hcs_params1;
+   __le32 hcs_params2;
+   __le32 hcs_params3;
+   __le32 hcc_params;
+   __le32 db_off;
+   __le32 run_regs_off;
+   __le32 hcc_params2;
+   /* Reserved up to (CAPLENGTH - 0x1C) */
+};
+
+/* hc_capbase bitmasks. */
+/* bits 7:0 - how long is the Capabilities register. */
+#define HC_LENGTH(p)   (((p) >> 00) & GENMASK(7, 0))
+/* bits 31:16  */
+#define HC_VERSION(p)  (((p) >> 16) & GENMASK(15, 1))
+
+/* HCSPARAMS1 - hcs_params1 - bitmasks */
+/* bits 0:7, Max Device Endpoints */
+#define HCS_ENDPOINTS_MASK GENMASK(7, 0)
+#define HCS_ENDPOINTS(p)   (((p) & HCS_ENDPOINTS_MASK) >> 0)
+
+/* HCCPARAMS offset from PCI base address */
+#define HCC_PARAMS_OFFSET  0x10
+
+/* HCCPARAMS - hcc_params - bitmasks */
+/* 1: device controller can use 64-bit address pointers. */
+#define HCC_64BIT_ADDR(p)  ((p) & BIT(0))
+/* 1: device controller uses 64-byte Device Context structures. */
+#define HCC_64BYTE_CONTEXT(p)  ((p) & BIT(2))
+/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */
+#define HCC_MAX_PSA(p) p) >> 12) & 0xf) + 1)
+/* Extended Capabilities pointer from PCI base. */
+#define HCC_EXT_CAPS(p)(((p) & GENMASK(31, 16)) >> 16)
+
+#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
+
+/* db_off bitmask - bits 0:1 reserved. */
+#define DBOFF_MASK GENMASK(31, 2)
+
+/* run_regs_off bitmask - bits 0:4 reserved. */
+#define RTSOFF_MASKGENMASK(31, 5)
+
+/**
+ * struct cdnsp_op_regs - Device Controller Operational Registers.
+ * @command: USBCMD - Controller command register.
+ * @status: USBSTS - Controller status register.
+ * @page_size: This indicates the page size that the device controller 
supports.
+ * If bit n is set, the controller supports a page size of 
2^(n+12),
+ * up to a 128MB page size. 4K is the minimum page size.
+ * @dnctrl: DNCTRL - Device notification control register.
+ * @cmd_ring: CRP - 64-bit Command Ring Pointer.
+ * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer.
+ * @config_reg: CONFIG - Configure Register
+ * @port_reg_base: PORTSCn - base address for Port Status and Control
+ * Each port has a Port Status and Control register,
+ * followed by a Port Power Management Status and Control
+ * register, a Port Link Info register, and a reserved
+ * register.
+ */
+struct cdnsp_op_regs {
+   __le32 command;
+   __le32 status;
+   __le32 page_size;
+   __le32 reserved1;
+   __le32 reserved2;
+   __le32 dnctrl;
+   __le64 cmd_ring;
+   /* rsvd: offset 0x20-2F. */
+   __le32 reserved3[4];
+   __le64 dcbaa_ptr;
+   __le32 config_reg;
+   /* rsvd: offset 0x3

[PATCH v5 05/10] usb: cdns3: Changed type of gadget_dev in cdns structure

2020-12-07 Thread Pawel Laszczak
Patch changes the type for gadget_dev pointer in cdns structure from
pointer to cdns3_device structure to void pointer.
This filed is in reusable code and after this change it will be used to
point to both cdns3_device or cdnsp_device objects.

Signed-off-by: Pawel Laszczak 
Tested-by: Aswath Govindraju 
---
 drivers/usb/cdns3/core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index f664eb2d8df4..cbd2e1cc8eb1 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -64,7 +64,7 @@ struct cdns3_platform_data {
  * @roles: array of supported roles for this controller
  * @role: current role
  * @host_dev: the child host device pointer for cdns core
- * @gadget_dev: the child gadget device pointer for cdns3 core
+ * @gadget_dev: the child gadget device pointer
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
  * @mutex: the mutex for concurrent code at driver
@@ -104,7 +104,7 @@ struct cdns {
struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
enum usb_role   role;
struct platform_device  *host_dev;
-   struct cdns3_device *gadget_dev;
+   void*gadget_dev;
struct phy  *usb2_phy;
struct phy  *usb3_phy;
/* mutext used in workqueue*/
-- 
2.17.1



[PATCH v5 01/10] usb: cdns3: Add support for DRD CDNSP

2020-12-07 Thread Pawel Laszczak
Patch adds support for Cadence DRD Super Speed Plus controller(CDNSP).
CDNSP DRD is a part of Cadence CDNSP controller.
The DRD CDNSP controller has a lot of difference on hardware level but on
software level is quite compatible with CDNS3 DRD. For this reason
CDNS3 DRD part of CDNS3 driver was reused for CDNSP driver.

Signed-off-by: Pawel Laszczak 
Tested-by: Aswath Govindraju 
---
 drivers/usb/cdns3/core.c |  24 +++---
 drivers/usb/cdns3/core.h |   5 ++
 drivers/usb/cdns3/drd.c  | 101 +++
 drivers/usb/cdns3/drd.h  |  67 +-
 4 files changed, 148 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 1991cb5cf6bf..04990812181d 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -97,13 +97,23 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 * can be restricted later depending on strap pin configuration.
 */
if (dr_mode == USB_DR_MODE_UNKNOWN) {
-   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
-   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_OTG;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
-   dr_mode = USB_DR_MODE_HOST;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_PERIPHERAL;
+   if (cdns->version == CDNSP_CONTROLLER_V2) {
+   if (IS_ENABLED(CONFIG_USB_CDNSP_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   } else {
+   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   }
}
 
/*
diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index 3176f924293a..0d87871499ea 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -55,7 +55,9 @@ struct cdns3_platform_data {
  * @otg_res: the resource for otg
  * @otg_v0_regs: pointer to base of v0 otg registers
  * @otg_v1_regs: pointer to base of v1 otg registers
+ * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
  * @otg_regs: pointer to base of otg registers
+ * @otg_irq_regs: pointer to interrupt registers
  * @otg_irq: irq number for otg controller
  * @dev_irq: irq number for device controller
  * @wakeup_irq: irq number for wakeup event, it is optional
@@ -86,9 +88,12 @@ struct cdns3 {
struct resource otg_res;
struct cdns3_otg_legacy_regs*otg_v0_regs;
struct cdns3_otg_regs   *otg_v1_regs;
+   struct cdnsp_otg_regs   *otg_cdnsp_regs;
struct cdns3_otg_common_regs*otg_regs;
+   struct cdns3_otg_irq_regs   *otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
+#define CDNSP_CONTROLLER_V22
u32 version;
boolphyrst_a_enable;
 
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 38ccd29e4cde..95863d44e3e0 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -2,13 +2,12 @@
 /*
  * Cadence USBSS DRD Driver.
  *
- * Copyright (C) 2018-2019 Cadence.
+ * Copyright (C) 2018-2020 Cadence.
  * Copyright (C) 2019 Texas Instruments
  *
  * Author: Pawel Laszczak 
  * Roger Quadros 
  *
- *
  */
 #include 
 #include 
@@ -28,8 +27,9 @@
  *
  * Returns 0 on success otherwise negative errno
  */
-int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
+static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
 {
+   u32 __iomem *override_reg;
u32 reg;
 
switch (mode) {
@@ -39,11 +39,24 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode 
mode)
break;
case USB_DR_MODE_OTG:
dev_dbg(cdns->dev, "Set controller to OTG mode\n");
-   if (cdns->version == CDNS3_CONTROLLER_V1) {
-   reg = readl(>otg_v1_regs->override);
+
+   if (cdns->version == CDNSP_CONTROLLER_V2)
+   override_reg = >otg_cdnsp_regs->override;
+   else if (cdns->version == CDNS3_CONTROLLER_V1)
+ 

[PATCH v5 09/10] usb: cdns3: Change file names for cdns3 driver.

2020-12-07 Thread Pawel Laszczak
Patch adds prefix cdns3- to all file names related only to
cdns3 driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile | 6 +++---
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}   | 0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}   | 4 ++--
 drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} | 4 ++--
 drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} | 0
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}   | 2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}   | 6 +++---
 7 files changed, 11 insertions(+), 11 deletions(-)
 rename drivers/usb/cdns3/{debug.h => cdns3-debug.h} (100%)
 rename drivers/usb/cdns3/{ep0.c => cdns3-ep0.c} (99%)
 rename drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} (99%)
 rename drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} (100%)
 rename drivers/usb/cdns3/{trace.c => cdns3-trace.c} (89%)
 rename drivers/usb/cdns3/{trace.h => cdns3-trace.h} (99%)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a4fdaabdbe18..01a9a9620044 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
-CFLAGS_trace.o := -I$(src)
+CFLAGS_cdns3-trace.o   := -I$(src)
 CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
@@ -10,10 +10,10 @@ obj-$(CONFIG_USB_CDNS3) += 
cdns3.o
 obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns-usb-common.o
 
 cdns-usb-common-$(CONFIG_USB_CDNS_HOST)+= host.o
-cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)   += cdns3-gadget.o cdns3-ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
-cdns3-$(CONFIG_TRACING)+= trace.o
+cdns3-$(CONFIG_TRACING)+= cdns3-trace.o
 endif
 
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/cdns3-debug.h
similarity index 100%
rename from drivers/usb/cdns3/debug.h
rename to drivers/usb/cdns3/cdns3-debug.h
diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/cdns3-ep0.c
similarity index 99%
rename from drivers/usb/cdns3/ep0.c
rename to drivers/usb/cdns3/cdns3-ep0.c
index d3121a32cc68..b0390fe9a396 100644
--- a/drivers/usb/cdns3/ep0.c
+++ b/drivers/usb/cdns3/cdns3-ep0.c
@@ -13,8 +13,8 @@
 #include 
 #include 
 
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 
 static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
similarity index 99%
rename from drivers/usb/cdns3/gadget.c
rename to drivers/usb/cdns3/cdns3-gadget.c
index 5890e535aefc..9b8b0cd3d2c2 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -63,8 +63,8 @@
 
 #include "core.h"
 #include "gadget-export.h"
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 #include "drd.h"
 
 static int __cdns3_gadget_ep_queue(struct usb_ep *ep,
diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/cdns3-gadget.h
similarity index 100%
rename from drivers/usb/cdns3/gadget.h
rename to drivers/usb/cdns3/cdns3-gadget.h
diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/cdns3-trace.c
similarity index 89%
rename from drivers/usb/cdns3/trace.c
rename to drivers/usb/cdns3/cdns3-trace.c
index 459fa72d9c74..b9858acaef02 100644
--- a/drivers/usb/cdns3/trace.c
+++ b/drivers/usb/cdns3/cdns3-trace.c
@@ -8,4 +8,4 @@
  */
 
 #define CREATE_TRACE_POINTS
-#include "trace.h"
+#include "cdns3-trace.h"
diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/cdns3-trace.h
similarity index 99%
rename from drivers/usb/cdns3/trace.h
rename to drivers/usb/cdns3/cdns3-trace.h
index 0a2a3269bfac..8648c7a7a9dd 100644
--- a/drivers/usb/cdns3/trace.h
+++ b/drivers/usb/cdns3/cdns3-trace.h
@@ -19,8 +19,8 @@
 #include 
 #include 
 #include "core.h"
-#include "gadget.h"
-#include "debug.h"
+#include "cdns3-gadget.h"
+#include "cdns3-debug.h"
 
 #define CDNS3_MSG_MAX  500
 
@@ -565,6 +565,6 @@ DEFINE_EVENT(cdns3_log_request_handled, 
cdns3_request_handled,
 #define TRACE_INCLUDE_PATH .
 
 #undef TRACE_INCLUDE_FILE
-#define TRACE_INCLUDE_FILE trace
+#define TRACE_INCLUDE_FILE cdns3-trace
 
 #include 
-- 
2.17.1



RE: [PATCH v4 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-12-03 Thread Pawel Laszczak
>
>On 20-12-02 14:25:38, 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 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.
>>
>> The device side of USBSS DRD controller is compliant with XHCI.
>> The architecture for device side is almost the same as for host side,
>> and most of the XHCI specification can be used to understand how
>> this controller operates.
>>
>> This controller and driver support Full Speed, Hight Speed, Supper Speed
>> and Supper Speed Plus USB protocol.
>>
>> The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
>> The last letter of this acronym means PLUS. The formal name of controller
>> is USBSSP but it's to generic so I've decided to use CDNSP.
>>
>> The patch 1: adds support for DRD CDNSP.
>> The patch 2: separates common code that can be reusable by cdnsp driver.
>> The patch 3: moves reusable code to separate module.
>> The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
>> The patch 5: adopts gadget_dev pointer in cdns structure to make possible
>>  use it in both drivers.
>> The patches 6-8: add the main part of driver and has been intentionally
>>  split into 3 part. In my opinion such division should not
>>  affect understanding and reviewing the driver, and cause that
>>  main patch (7/8) is little smaller. Patch 6 introduces main
>>  header file for driver, 7 is the main part that implements all
>>  functionality of driver and 8 introduces tracepoints.
>> The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
>> the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.
>
>Hi Pawel,
>
>You may need to fix below:
>
>
>diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
>index 04bccf6daaba..30d69b639492 100644
>--- a/drivers/usb/cdns3/cdns3-plat.c
>+++ b/drivers/usb/cdns3/cdns3-plat.c
>@@ -4,7 +4,7 @@
>  *
>  * Copyright (C) 2018-2020 Cadence.
>  * Copyright (C) 2017-2018 NXP
>- * Copyright (C) 2019 Texas Instrumentsq
>+ * Copyright (C) 2019 Texas Instruments
>  *
>  *
>  * Author: Peter Chen 
>
> static int cdns3_plat_runtime_resume(struct device *dev)
> {
>-  return cdns3_controller_resume(dev, PMSG_SUSPEND);
>+  return cdns3_controller_resume(dev, PMSG_AUTO_RESUME);
> }
>@@ -273,7 +273,14 @@ static int cdns3_plat_suspend(struct device *dev)
>
>   cdns_suspend(cdns);
>
>-  return cdns3_controller_suspend(dev, PMSG_AUTO_SUSPEND);
>+  return cdns3_controller_suspend(dev, PMSG_SUSPEND);
>
>I am porting and testing your patches at NXP platforms.
>

Thanks for that,
I tried to compare the original code with this one very carefully but
I omit this. Also during testing no problem arose.

I will wait some day and on Tuesday or on Wednesday I will post
v5 with your fix. 

>
>>
>> Changlog from v3:
>> - added 'T' to MAINTAINERS file for CDNSP entry
>> - updated common code with latest cdns3 fixes
>>
>> Changlog from v2:
>> - removed not used pdev parameter from cdnsp_read/wite_64 functions
>> - fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
>> - replaced some constant value with CDNSP_ENDPOINTS_NUM macro
>> - replaced 'true' with '1' in bits description in cdnsp-gadget.h file
>> - fixed some typos
>> - some other less important changes suggested by Peter Chen
>>
>> Changlog from v1:
>> - updated common code to latest cdns3 driver
>> - moved cdnsp driver files to cdns3 as sugested by Peter Chan
>> - removed duplicate code from cdnsp_ep0_set_config function
>> - added cdns3 prefixes to file related with USBSS driver
>> - updated MAINTAINERS file
>> - fixed issue with U1
>> - fixed issue with L1
>> - some less improtant changes sugested by Chunfeng Yun
>> ---
>>
>> Pawel Laszczak (10):
>>   usb: cdns3: Add support for DRD CDNSP
>>   usb: cdns3: Split core.c into cdns3-plat and core.c file
>>   usb: cdns3: Moves reusable code to separate module
>>   usb: cdns3: Refactoring names in reusable code
>>   usb: cdns3: Changed type of ga

[PATCH v4 03/10] usb: cdns3: Moves reusable code to separate module

2020-12-02 Thread Pawel Laszczak
Patch moves common reusable code used by cdns3 and cdnsp driver
to cdns-usb-common library. This library include core.c, drd.c
and host.c files.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Kconfig  |  8 
 drivers/usb/cdns3/Makefile |  8 +---
 drivers/usb/cdns3/cdns3-plat.c |  2 ++
 drivers/usb/cdns3/core.c   | 18 +++---
 drivers/usb/cdns3/core.h   |  3 +++
 drivers/usb/cdns3/drd.c|  3 ++-
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
index 84716d216ae5..58154c0a73ac 100644
--- a/drivers/usb/cdns3/Kconfig
+++ b/drivers/usb/cdns3/Kconfig
@@ -1,8 +1,15 @@
+config CDNS_USB_COMMON
+   tristate
+
+config CDNS_USB_HOST
+   bool
+
 config USB_CDNS3
tristate "Cadence USB3 Dual-Role Controller"
depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA
select USB_XHCI_PLATFORM if USB_XHCI_HCD
select USB_ROLE_SWITCH
+   select CDNS_USB_COMMON
help
  Say Y here if your system has a Cadence USB3 dual-role controller.
  It supports: dual-role switch, Host-only, and Peripheral-only.
@@ -25,6 +32,7 @@ config USB_CDNS3_GADGET
 config USB_CDNS3_HOST
bool "Cadence USB3 host controller"
depends on USB=y || USB=USB_CDNS3
+   select CDNS_USB_HOST
help
  Say Y here to enable host controller functionality of the
  Cadence driver.
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a1fe9612053a..16df87abf3cf 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,17 +2,19 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= cdns3-plat.o core.o drd.o
+cdns-usb-common-y  := core.o drd.o
+cdns3-y:= cdns3-plat.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
+obj-$(CONFIG_CDNS_USB_COMMON)  += cdns-usb-common.o
+
+cdns-usb-common-$(CONFIG_CDNS_USB_HOST) += host.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
 cdns3-$(CONFIG_TRACING)+= trace.o
 endif
 
-cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o
-
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
 obj-$(CONFIG_USB_CDNS3_TI) += cdns3-ti.o
 obj-$(CONFIG_USB_CDNS3_IMX)+= cdns3-imx.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index bfb57ded9664..5371da7abb27 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -18,6 +18,7 @@
 #include 
 
 #include "core.h"
+#include "gadget-export.h"
 
 static int set_phy_power_on(struct cdns3 *cdns)
 {
@@ -134,6 +135,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
if (ret)
goto err_phy_power_on;
 
+   cdns->gadget_init = cdns3_gadget_init;
ret = cdns3_init(cdns);
if (ret)
goto err_cdns_init;
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 7b67a7c74586..81ea035c0e11 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -19,10 +19,8 @@
 #include 
 #include 
 
-#include "gadget.h"
 #include "core.h"
 #include "host-export.h"
-#include "gadget-export.h"
 #include "drd.h"
 
 static int cdns3_idle_init(struct cdns3 *cdns);
@@ -147,7 +145,11 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
}
 
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
-   ret = cdns3_gadget_init(cdns);
+   if (cdns->gadget_init)
+   ret = cdns->gadget_init(cdns);
+   else
+   ret = -ENXIO;
+
if (ret) {
dev_err(dev, "Device initialization failed with %d\n",
ret);
@@ -477,6 +479,7 @@ int cdns3_init(struct cdns3 *cdns)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(cdns3_init);
 
 /**
  * cdns3_remove - unbind drd driver and clean up
@@ -491,6 +494,7 @@ int cdns3_remove(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_remove);
 
 #ifdef CONFIG_PM_SLEEP
 int cdns3_suspend(struct cdns3 *cdns)
@@ -509,6 +513,7 @@ int cdns3_suspend(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_suspend);
 
 int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 {
@@ -525,4 +530,11 @@ int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_resume);
 #endif /* CONFIG_PM_SLEEP */
+
+MODULE_AUTHOR("Peter Chen ");
+MODULE_AUTHOR("Pawel Laszczak ");
+MODULE_AUTHOR("Roger Quadros ");
+MODULE_DESCRIPTION("Cadence USBSS and USBSSP DRD Dr

[PATCH v4 09/10] usb: cdns3: Change file names for cdns3 driver.

2020-12-02 Thread Pawel Laszczak
Patch adds prefix cdns3- to all file names related only to
cdns3 driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile | 6 +++---
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}   | 0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}   | 4 ++--
 drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} | 4 ++--
 drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} | 0
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}   | 2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}   | 6 +++---
 7 files changed, 11 insertions(+), 11 deletions(-)
 rename drivers/usb/cdns3/{debug.h => cdns3-debug.h} (100%)
 rename drivers/usb/cdns3/{ep0.c => cdns3-ep0.c} (99%)
 rename drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} (99%)
 rename drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} (100%)
 rename drivers/usb/cdns3/{trace.c => cdns3-trace.c} (89%)
 rename drivers/usb/cdns3/{trace.h => cdns3-trace.h} (99%)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a4fdaabdbe18..01a9a9620044 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
-CFLAGS_trace.o := -I$(src)
+CFLAGS_cdns3-trace.o   := -I$(src)
 CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
@@ -10,10 +10,10 @@ obj-$(CONFIG_USB_CDNS3) += 
cdns3.o
 obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns-usb-common.o
 
 cdns-usb-common-$(CONFIG_USB_CDNS_HOST)+= host.o
-cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)   += cdns3-gadget.o cdns3-ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
-cdns3-$(CONFIG_TRACING)+= trace.o
+cdns3-$(CONFIG_TRACING)+= cdns3-trace.o
 endif
 
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/cdns3-debug.h
similarity index 100%
rename from drivers/usb/cdns3/debug.h
rename to drivers/usb/cdns3/cdns3-debug.h
diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/cdns3-ep0.c
similarity index 99%
rename from drivers/usb/cdns3/ep0.c
rename to drivers/usb/cdns3/cdns3-ep0.c
index d3121a32cc68..b0390fe9a396 100644
--- a/drivers/usb/cdns3/ep0.c
+++ b/drivers/usb/cdns3/cdns3-ep0.c
@@ -13,8 +13,8 @@
 #include 
 #include 
 
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 
 static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
similarity index 99%
rename from drivers/usb/cdns3/gadget.c
rename to drivers/usb/cdns3/cdns3-gadget.c
index 5890e535aefc..9b8b0cd3d2c2 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -63,8 +63,8 @@
 
 #include "core.h"
 #include "gadget-export.h"
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 #include "drd.h"
 
 static int __cdns3_gadget_ep_queue(struct usb_ep *ep,
diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/cdns3-gadget.h
similarity index 100%
rename from drivers/usb/cdns3/gadget.h
rename to drivers/usb/cdns3/cdns3-gadget.h
diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/cdns3-trace.c
similarity index 89%
rename from drivers/usb/cdns3/trace.c
rename to drivers/usb/cdns3/cdns3-trace.c
index 459fa72d9c74..b9858acaef02 100644
--- a/drivers/usb/cdns3/trace.c
+++ b/drivers/usb/cdns3/cdns3-trace.c
@@ -8,4 +8,4 @@
  */
 
 #define CREATE_TRACE_POINTS
-#include "trace.h"
+#include "cdns3-trace.h"
diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/cdns3-trace.h
similarity index 99%
rename from drivers/usb/cdns3/trace.h
rename to drivers/usb/cdns3/cdns3-trace.h
index 0a2a3269bfac..8648c7a7a9dd 100644
--- a/drivers/usb/cdns3/trace.h
+++ b/drivers/usb/cdns3/cdns3-trace.h
@@ -19,8 +19,8 @@
 #include 
 #include 
 #include "core.h"
-#include "gadget.h"
-#include "debug.h"
+#include "cdns3-gadget.h"
+#include "cdns3-debug.h"
 
 #define CDNS3_MSG_MAX  500
 
@@ -565,6 +565,6 @@ DEFINE_EVENT(cdns3_log_request_handled, 
cdns3_request_handled,
 #define TRACE_INCLUDE_PATH .
 
 #undef TRACE_INCLUDE_FILE
-#define TRACE_INCLUDE_FILE trace
+#define TRACE_INCLUDE_FILE cdns3-trace
 
 #include 
-- 
2.17.1



[PATCH v4 01/10] usb: cdns3: Add support for DRD CDNSP

2020-12-02 Thread Pawel Laszczak
Patch adds support for Cadence DRD Super Speed Plus controller(CDNSP).
CDNSP DRD is a part of Cadence CDNSP controller.
The DRD CDNSP controller has a lot of difference on hardware level but on
software level is quite compatible with CDNS3 DRD. For this reason
CDNS3 DRD part of CDNS3 driver was reused for CDNSP driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.c |  24 +++---
 drivers/usb/cdns3/core.h |   5 ++
 drivers/usb/cdns3/drd.c  | 101 +++
 drivers/usb/cdns3/drd.h  |  67 +-
 4 files changed, 148 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 1991cb5cf6bf..04990812181d 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -97,13 +97,23 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 * can be restricted later depending on strap pin configuration.
 */
if (dr_mode == USB_DR_MODE_UNKNOWN) {
-   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
-   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_OTG;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
-   dr_mode = USB_DR_MODE_HOST;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_PERIPHERAL;
+   if (cdns->version == CDNSP_CONTROLLER_V2) {
+   if (IS_ENABLED(CONFIG_USB_CDNSP_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   } else {
+   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   }
}
 
/*
diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index 3176f924293a..0d87871499ea 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -55,7 +55,9 @@ struct cdns3_platform_data {
  * @otg_res: the resource for otg
  * @otg_v0_regs: pointer to base of v0 otg registers
  * @otg_v1_regs: pointer to base of v1 otg registers
+ * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
  * @otg_regs: pointer to base of otg registers
+ * @otg_irq_regs: pointer to interrupt registers
  * @otg_irq: irq number for otg controller
  * @dev_irq: irq number for device controller
  * @wakeup_irq: irq number for wakeup event, it is optional
@@ -86,9 +88,12 @@ struct cdns3 {
struct resource otg_res;
struct cdns3_otg_legacy_regs*otg_v0_regs;
struct cdns3_otg_regs   *otg_v1_regs;
+   struct cdnsp_otg_regs   *otg_cdnsp_regs;
struct cdns3_otg_common_regs*otg_regs;
+   struct cdns3_otg_irq_regs   *otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
+#define CDNSP_CONTROLLER_V22
u32 version;
boolphyrst_a_enable;
 
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 38ccd29e4cde..95863d44e3e0 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -2,13 +2,12 @@
 /*
  * Cadence USBSS DRD Driver.
  *
- * Copyright (C) 2018-2019 Cadence.
+ * Copyright (C) 2018-2020 Cadence.
  * Copyright (C) 2019 Texas Instruments
  *
  * Author: Pawel Laszczak 
  * Roger Quadros 
  *
- *
  */
 #include 
 #include 
@@ -28,8 +27,9 @@
  *
  * Returns 0 on success otherwise negative errno
  */
-int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
+static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
 {
+   u32 __iomem *override_reg;
u32 reg;
 
switch (mode) {
@@ -39,11 +39,24 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode 
mode)
break;
case USB_DR_MODE_OTG:
dev_dbg(cdns->dev, "Set controller to OTG mode\n");
-   if (cdns->version == CDNS3_CONTROLLER_V1) {
-   reg = readl(>otg_v1_regs->override);
+
+   if (cdns->version == CDNSP_CONTROLLER_V2)
+   override_reg = >otg_cdnsp_regs->override;
+   else if (cdns->version == CDNS3_CONTROLLER_V1)
+ 

[PATCH v4 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-12-02 Thread Pawel Laszczak
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 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.

The device side of USBSS DRD controller is compliant with XHCI.
The architecture for device side is almost the same as for host side,
and most of the XHCI specification can be used to understand how
this controller operates.

This controller and driver support Full Speed, Hight Speed, Supper Speed
and Supper Speed Plus USB protocol.

The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
The last letter of this acronym means PLUS. The formal name of controller
is USBSSP but it's to generic so I've decided to use CDNSP.

The patch 1: adds support for DRD CDNSP.
The patch 2: separates common code that can be reusable by cdnsp driver.
The patch 3: moves reusable code to separate module.
The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
The patch 5: adopts gadget_dev pointer in cdns structure to make possible 
 use it in both drivers.
The patches 6-8: add the main part of driver and has been intentionally
 split into 3 part. In my opinion such division should not
 affect understanding and reviewing the driver, and cause that
 main patch (7/8) is little smaller. Patch 6 introduces main
 header file for driver, 7 is the main part that implements all
 functionality of driver and 8 introduces tracepoints.
The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.

Changlog from v3:
- added 'T' to MAINTAINERS file for CDNSP entry
- updated common code with latest cdns3 fixes

Changlog from v2:
- removed not used pdev parameter from cdnsp_read/wite_64 functions
- fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
- replaced some constant value with CDNSP_ENDPOINTS_NUM macro
- replaced 'true' with '1' in bits description in cdnsp-gadget.h file
- fixed some typos
- some other less important changes suggested by Peter Chen

Changlog from v1:
- updated common code to latest cdns3 driver
- moved cdnsp driver files to cdns3 as sugested by Peter Chan
- removed duplicate code from cdnsp_ep0_set_config function
- added cdns3 prefixes to file related with USBSS driver
- updated MAINTAINERS file
- fixed issue with U1
- fixed issue with L1
- some less improtant changes sugested by Chunfeng Yun
---

Pawel Laszczak (10):
  usb: cdns3: Add support for DRD CDNSP
  usb: cdns3: Split core.c into cdns3-plat and core.c file
  usb: cdns3: Moves reusable code to separate module
  usb: cdns3: Refactoring names in reusable code
  usb: cdns3: Changed type of gadget_dev in cdns structure
  usb: cdnsp: Device side header file for CDNSP driver
  usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver
  usb: cdnsp: Add tracepoints for CDNSP driver
  usb: cdns3: Change file names for cdns3 driver.
  MAINTAINERS: add Cadence USBSSP DRD IP driver entry

 MAINTAINERS   |9 +
 drivers/usb/Makefile  |2 +
 drivers/usb/cdns3/Kconfig |   61 +-
 drivers/usb/cdns3/Makefile|   30 +-
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}  |0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}  |4 +-
 .../usb/cdns3/{gadget.c => cdns3-gadget.c}|   28 +-
 .../usb/cdns3/{gadget.h => cdns3-gadget.h}|0
 drivers/usb/cdns3/cdns3-imx.c |2 +-
 drivers/usb/cdns3/cdns3-plat.c|  315 +++
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}  |2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}  |6 +-
 drivers/usb/cdns3/cdnsp-debug.h   |  583 
 drivers/usb/cdns3/cdnsp-ep0.c |  495 
 drivers/usb/cdns3/cdnsp-gadget.c  | 2017 ++
 drivers/usb/cdns3/cdnsp-gadget.h  | 1600 +++
 drivers/usb/cdns3/cdnsp-mem.c | 1325 +
 drivers/usb/cdns3/cdnsp-pci.c |  255 ++
 drivers/usb/cdns3/cdnsp-ring.c| 2439 +
 drivers/usb/cdns3/cdnsp-trace.c   |   12 +
 drivers/usb/cdns3/cdnsp-trace.h   |  840 ++
 drivers/usb/cdns3/core.c  |  455 +--
 drivers/usb/cdns3/core.h  |   54 +-
 drivers/usb/cdns3/drd.c   |  222 +-
 drivers/usb/cdns3/drd.h   |   94 +-
 drivers/usb/cdns3/gadget-export.h |   22 +-
 drivers/usb/cdns3/host-export.h   |   13 +-
 drivers/usb/cdns3/host.c  

[PATCH v4 10/10] MAINTAINERS: add Cadence USBSSP DRD IP driver entry

2020-12-02 Thread Pawel Laszczak
Patch adds entry for USBSSP (CDNSP) driver into MAINTARNERS file.

Signed-off-by: Pawel Laszczak 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 213b92ffe891..255390789176 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3859,6 +3859,15 @@ S:   Maintained
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
 F: Documentation/devicetree/bindings/usb/cdns,usb3.yaml
 F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdnsp*
+
+CADENCE USBSSP DRD IP DRIVER
+M: Pawel Laszczak 
+L: linux-...@vger.kernel.org
+S: Maintained
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
+F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdns3*
 
 CADET FM/AM RADIO RECEIVER DRIVER
 M: Hans Verkuil 
-- 
2.17.1



[PATCH v4 02/10] usb: cdns3: Split core.c into cdns3-plat and core.c file

2020-12-02 Thread Pawel Laszczak
Patch splits file core.c into core.c containing the common reusable code
and cnd3-plat.c containing device platform specific code. These changes
are required to make possible reuse DRD part of CDNS3 driver in CDNSP
driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile |   2 +-
 drivers/usb/cdns3/cdns3-plat.c | 312 +
 drivers/usb/cdns3/core.c   | 284 +++---
 drivers/usb/cdns3/core.h   |   6 +
 drivers/usb/cdns3/drd.c|   1 -
 drivers/usb/cdns3/drd.h|   1 -
 6 files changed, 343 insertions(+), 263 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdns3-plat.c

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index d47e341a6f39..a1fe9612053a 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,7 +2,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= core.o drd.o
+cdns3-y:= cdns3-plat.o core.o drd.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
new file mode 100644
index ..bfb57ded9664
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence USBSS DRD Driver.
+ *
+ * Copyright (C) 2018-2020 Cadence.
+ * Copyright (C) 2017-2018 NXP
+ * Copyright (C) 2019 Texas Instrumentsq
+ *
+ *
+ * Author: Peter Chen 
+ * Pawel Laszczak 
+ * Roger Quadros 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+
+static int set_phy_power_on(struct cdns3 *cdns)
+{
+   int ret;
+
+   ret = phy_power_on(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   ret = phy_power_on(cdns->usb3_phy);
+   if (ret)
+   phy_power_off(cdns->usb2_phy);
+
+   return ret;
+}
+
+static void set_phy_power_off(struct cdns3 *cdns)
+{
+   phy_power_off(cdns->usb3_phy);
+   phy_power_off(cdns->usb2_phy);
+}
+
+/**
+ * cdns3_plat_probe - probe for cdns3 core device
+ * @pdev: Pointer to cdns3 core platform device
+ *
+ * Returns 0 on success otherwise negative errno
+ */
+static int cdns3_plat_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;
+   cdns->pdata = dev_get_platdata(dev);
+
+   platform_set_drvdata(pdev, cdns);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host");
+   if (!res) {
+   dev_err(dev, "missing host IRQ\n");
+   return -ENODEV;
+   }
+
+   cdns->xhci_res[0] = *res;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci");
+   if (!res) {
+   dev_err(dev, "couldn't get xhci resource\n");
+   return -ENXIO;
+   }
+
+   cdns->xhci_res[1] = *res;
+
+   cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral");
+
+   if (cdns->dev_irq < 0)
+   return cdns->dev_irq;
+
+   regs = devm_platform_ioremap_resource_byname(pdev, "dev");
+   if (IS_ERR(regs))
+   return PTR_ERR(regs);
+   cdns->dev_regs  = regs;
+
+   cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
+   if (cdns->otg_irq < 0)
+   return cdns->otg_irq;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
+   if (!res) {
+   dev_err(dev, "couldn't get otg resource\n");
+   return -ENXIO;
+   }
+
+   cdns->phyrst_a_enable = device_property_read_bool(dev, 
"cdns,phyrst-a-enable");
+
+   cdns->otg_res = *res;
+
+   cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+   if (cdns->wakeup_irq == -EPROBE_DEFER)
+   return cdns->wakeup_irq;
+   else if (cdns->wakeup_irq == 0)
+   return -EINVAL;
+
+   if (cdns->wakeup_irq < 0) {
+   dev_dbg(dev, "couldn't get wakeup irq\n");
+   cdns->wakeup_irq = 0x0;
+   }
+
+   cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy");
+   if (IS_ERR(cdns->usb2_phy))
+   return PTR_ERR(cdns->usb2_phy);
+
+   ret = phy_init(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy");
+  

[PATCH v4 04/10] usb: cdns3: Refactoring names in reusable code

2020-12-02 Thread Pawel Laszczak
Patch change the functions and objects names in reusable code.
The reusable code includes core.c, core.h, drd.c and drd.h files.
It also changes the names of all references to these functions and
objects in other cdns3 files. There are a lot of changes, but all
changes are very trivial.
The reason of this patch is to avoid of mixing prefix cdns3 and cdnsp in
in cdnsp driver what could introduce some confusion in understanding
of cdnsp driver.
This patch assumes to use three different prefixes in Cadence
USB drivers:
  cdns: for common reusable code
  cdnsp: for names related only with cdnsp driver
  cdns3: for names related only with cdns3 driver

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdns3-imx.c |   2 +-
 drivers/usb/cdns3/cdns3-plat.c|  25 +++---
 drivers/usb/cdns3/core.c  | 142 +++---
 drivers/usb/cdns3/core.h  |  46 +-
 drivers/usb/cdns3/drd.c   | 100 ++---
 drivers/usb/cdns3/drd.h   |  26 +++---
 drivers/usb/cdns3/gadget-export.h |   4 +-
 drivers/usb/cdns3/gadget.c|  24 ++---
 drivers/usb/cdns3/host-export.h   |   6 +-
 drivers/usb/cdns3/host.c  |  22 ++---
 10 files changed, 199 insertions(+), 198 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
index 22a56c4dce67..d9fb68766a15 100644
--- a/drivers/usb/cdns3/cdns3-imx.c
+++ b/drivers/usb/cdns3/cdns3-imx.c
@@ -250,7 +250,7 @@ static void cdns3_set_wakeup(struct cdns_imx *data, bool 
enable)
 static int cdns_imx_platform_suspend(struct device *dev,
bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
struct device *parent = dev->parent;
struct cdns_imx *data = dev_get_drvdata(parent);
void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs);
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index 5371da7abb27..04bccf6daaba 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -20,7 +20,7 @@
 #include "core.h"
 #include "gadget-export.h"
 
-static int set_phy_power_on(struct cdns3 *cdns)
+static int set_phy_power_on(struct cdns *cdns)
 {
int ret;
 
@@ -35,7 +35,7 @@ static int set_phy_power_on(struct cdns3 *cdns)
return ret;
 }
 
-static void set_phy_power_off(struct cdns3 *cdns)
+static void set_phy_power_off(struct cdns *cdns)
 {
phy_power_off(cdns->usb3_phy);
phy_power_off(cdns->usb2_phy);
@@ -51,7 +51,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
struct resource *res;
-   struct cdns3 *cdns;
+   struct cdns *cdns;
void __iomem *regs;
int ret;
 
@@ -136,7 +136,8 @@ static int cdns3_plat_probe(struct platform_device *pdev)
goto err_phy_power_on;
 
cdns->gadget_init = cdns3_gadget_init;
-   ret = cdns3_init(cdns);
+
+   ret = cdns_init(cdns);
if (ret)
goto err_cdns_init;
 
@@ -175,13 +176,13 @@ static int cdns3_plat_probe(struct platform_device *pdev)
  */
 static int cdns3_plat_remove(struct platform_device *pdev)
 {
-   struct cdns3 *cdns = platform_get_drvdata(pdev);
+   struct cdns *cdns = platform_get_drvdata(pdev);
struct device *dev = cdns->dev;
 
pm_runtime_get_sync(dev);
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);
-   cdns3_remove(cdns);
+   cdns_remove(cdns);
set_phy_power_off(cdns);
phy_exit(cdns->usb2_phy);
phy_exit(cdns->usb3_phy);
@@ -193,7 +194,7 @@ static int cdns3_plat_remove(struct platform_device *pdev)
 static int cdns3_set_platform_suspend(struct device *dev,
  bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret = 0;
 
if (cdns->pdata && cdns->pdata->platform_suspend)
@@ -204,7 +205,7 @@ static int cdns3_set_platform_suspend(struct device *dev,
 
 static int cdns3_controller_suspend(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
bool wakeup;
unsigned long flags;
 
@@ -228,7 +229,7 @@ static int cdns3_controller_suspend(struct device *dev, 
pm_message_t msg)
 
 static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret;
unsigned long flags;
 
@@ -242,7 +243,7 @@ static int cdns3_controller_resume(struct device *dev, 
pm_message_t msg)
cdns3_set_platform_suspend(cdns->dev, false, false);
 
spin_lock_irqsave(>lock, flags);
-   cdns3_resume(cdns, !PMSG_IS_AUTO(msg));
+

[PATCH v4 06/10] usb: cdnsp: Device side header file for CDNSP driver

2020-12-02 Thread Pawel Laszczak
Patch defines macros, registers and structures used by
Device side driver.

Because the size of main patch is very big, I’ve decided to create
separate patch for cdnsp-gadget.h. It should simplify reviewing the code.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.h | 1463 ++
 1 file changed, 1463 insertions(+)
 create mode 100644 drivers/usb/cdns3/cdnsp-gadget.h

diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h
new file mode 100644
index ..93da1dcdad60
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-gadget.h
@@ -0,0 +1,1463 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ * Code based on Linux XHCI driver.
+ * Origin: Copyright (C) 2008 Intel Corp.
+ */
+#ifndef __LINUX_CDNSP_GADGET_H
+#define __LINUX_CDNSP_GADGET_H
+
+#include 
+#include 
+#include 
+
+/* Max number slots - only 1 is allowed. */
+#define CDNSP_DEV_MAX_SLOTS1
+
+#define CDNSP_EP0_SETUP_SIZE   512
+
+/* One control and 15 for in and 15 for out endpoints. */
+#define CDNSP_ENDPOINTS_NUM31
+
+/* Best Effort Service Latency. */
+#define CDNSP_DEFAULT_BESL 0
+
+/* Device Controller command default timeout value in us */
+#define CDNSP_CMD_TIMEOUT  (15 * 1000)
+
+/* Up to 16 ms to halt an device controller */
+#define CDNSP_MAX_HALT_USEC(16 * 1000)
+
+#define CDNSP_CTX_SIZE 2112
+
+/*
+ * Controller register interface.
+ */
+
+/**
+ * struct cdnsp_cap_regs - CDNSP Registers.
+ * @hc_capbase:Length of the capabilities register and controller
+ *  version number
+ * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
+ * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
+ * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
+ * @hcc_params: HCCPARAMS - Capability Parameters
+ * @db_off: DBOFF - Doorbell array offset
+ * @run_regs_off: RTSOFF - Runtime register space offset
+ * @hcc_params2: HCCPARAMS2 Capability Parameters 2,
+ */
+struct cdnsp_cap_regs {
+   __le32 hc_capbase;
+   __le32 hcs_params1;
+   __le32 hcs_params2;
+   __le32 hcs_params3;
+   __le32 hcc_params;
+   __le32 db_off;
+   __le32 run_regs_off;
+   __le32 hcc_params2;
+   /* Reserved up to (CAPLENGTH - 0x1C) */
+};
+
+/* hc_capbase bitmasks. */
+/* bits 7:0 - how long is the Capabilities register. */
+#define HC_LENGTH(p)   (((p) >> 00) & GENMASK(7, 0))
+/* bits 31:16  */
+#define HC_VERSION(p)  (((p) >> 16) & GENMASK(15, 1))
+
+/* HCSPARAMS1 - hcs_params1 - bitmasks */
+/* bits 0:7, Max Device Endpoints */
+#define HCS_ENDPOINTS_MASK GENMASK(7, 0)
+#define HCS_ENDPOINTS(p)   (((p) & HCS_ENDPOINTS_MASK) >> 0)
+
+/* HCCPARAMS offset from PCI base address */
+#define HCC_PARAMS_OFFSET  0x10
+
+/* HCCPARAMS - hcc_params - bitmasks */
+/* 1: device controller can use 64-bit address pointers. */
+#define HCC_64BIT_ADDR(p)  ((p) & BIT(0))
+/* 1: device controller uses 64-byte Device Context structures. */
+#define HCC_64BYTE_CONTEXT(p)  ((p) & BIT(2))
+/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */
+#define HCC_MAX_PSA(p) p) >> 12) & 0xf) + 1)
+/* Extended Capabilities pointer from PCI base. */
+#define HCC_EXT_CAPS(p)(((p) & GENMASK(31, 16)) >> 16)
+
+#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
+
+/* db_off bitmask - bits 0:1 reserved. */
+#define DBOFF_MASK GENMASK(31, 2)
+
+/* run_regs_off bitmask - bits 0:4 reserved. */
+#define RTSOFF_MASKGENMASK(31, 5)
+
+/**
+ * struct cdnsp_op_regs - Device Controller Operational Registers.
+ * @command: USBCMD - Controller command register.
+ * @status: USBSTS - Controller status register.
+ * @page_size: This indicates the page size that the device controller 
supports.
+ * If bit n is set, the controller supports a page size of 
2^(n+12),
+ * up to a 128MB page size. 4K is the minimum page size.
+ * @dnctrl: DNCTRL - Device notification control register.
+ * @cmd_ring: CRP - 64-bit Command Ring Pointer.
+ * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer.
+ * @config_reg: CONFIG - Configure Register
+ * @port_reg_base: PORTSCn - base address for Port Status and Control
+ * Each port has a Port Status and Control register,
+ * followed by a Port Power Management Status and Control
+ * register, a Port Link Info register, and a reserved
+ * register.
+ */
+struct cdnsp_op_regs {
+   __le32 command;
+   __le32 status;
+   __le32 page_size;
+   __le32 reserved1;
+   __le32 reserved2;
+   __le32 dnctrl;
+   __le64 cmd_ring;
+   /* rsvd: offset 0x20-2F. */
+   __le32 reserved3[4];
+   __le64 dcbaa_ptr;
+   __le32 config_reg;
+   /* rsvd: offset 0x3

[PATCH v4 08/10] usb: cdnsp: Add tracepoints for CDNSP driver

2020-12-02 Thread Pawel Laszczak
Patch adds the series of tracepoints that can be used for
debugging issues detected in driver.

Signed-off-by: Pawel Laszczak 
Reviewed-by: Peter Chen 
---
 drivers/usb/cdns3/Makefile   |   5 +
 drivers/usb/cdns3/cdnsp-debug.h  | 583 +
 drivers/usb/cdns3/cdnsp-ep0.c|  22 +-
 drivers/usb/cdns3/cdnsp-gadget.c |  75 ++-
 drivers/usb/cdns3/cdnsp-mem.c|  18 +-
 drivers/usb/cdns3/cdnsp-ring.c   |  75 ++-
 drivers/usb/cdns3/cdnsp-trace.c  |  12 +
 drivers/usb/cdns3/cdnsp-trace.h  | 840 +++
 8 files changed, 1614 insertions(+), 16 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdnsp-debug.h
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.c
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.h

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a84b129f14b8..a4fdaabdbe18 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
+CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
 cdns3-y:= cdns3-plat.o
@@ -23,3 +24,7 @@ cdnsp-udc-pci-y   := 
cdnsp-pci.o
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
+
+ifneq ($(CONFIG_USB_CDNSP_GADGET),)
+cdnsp-udc-pci-$(CONFIG_TRACING)+= cdnsp-trace.o
+endif
diff --git a/drivers/usb/cdns3/cdnsp-debug.h b/drivers/usb/cdns3/cdnsp-debug.h
new file mode 100644
index ..d6345d4d2911
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-debug.h
@@ -0,0 +1,583 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ */
+#ifndef __LINUX_CDNSP_DEBUG
+#define __LINUX_CDNSP_DEBUG
+
+static inline const char *cdnsp_trb_comp_code_string(u8 status)
+{
+   switch (status) {
+   case COMP_INVALID:
+   return "Invalid";
+   case COMP_SUCCESS:
+   return "Success";
+   case COMP_DATA_BUFFER_ERROR:
+   return "Data Buffer Error";
+   case COMP_BABBLE_DETECTED_ERROR:
+   return "Babble Detected";
+   case COMP_TRB_ERROR:
+   return "TRB Error";
+   case COMP_RESOURCE_ERROR:
+   return "Resource Error";
+   case COMP_NO_SLOTS_AVAILABLE_ERROR:
+   return "No Slots Available Error";
+   case COMP_INVALID_STREAM_TYPE_ERROR:
+   return "Invalid Stream Type Error";
+   case COMP_SLOT_NOT_ENABLED_ERROR:
+   return "Slot Not Enabled Error";
+   case COMP_ENDPOINT_NOT_ENABLED_ERROR:
+   return "Endpoint Not Enabled Error";
+   case COMP_SHORT_PACKET:
+   return "Short Packet";
+   case COMP_RING_UNDERRUN:
+   return "Ring Underrun";
+   case COMP_RING_OVERRUN:
+   return "Ring Overrun";
+   case COMP_VF_EVENT_RING_FULL_ERROR:
+   return "VF Event Ring Full Error";
+   case COMP_PARAMETER_ERROR:
+   return "Parameter Error";
+   case COMP_CONTEXT_STATE_ERROR:
+   return "Context State Error";
+   case COMP_EVENT_RING_FULL_ERROR:
+   return "Event Ring Full Error";
+   case COMP_INCOMPATIBLE_DEVICE_ERROR:
+   return "Incompatible Device Error";
+   case COMP_MISSED_SERVICE_ERROR:
+   return "Missed Service Error";
+   case COMP_COMMAND_RING_STOPPED:
+   return "Command Ring Stopped";
+   case COMP_COMMAND_ABORTED:
+   return "Command Aborted";
+   case COMP_STOPPED:
+   return "Stopped";
+   case COMP_STOPPED_LENGTH_INVALID:
+   return "Stopped - Length Invalid";
+   case COMP_STOPPED_SHORT_PACKET:
+   return "Stopped - Short Packet";
+   case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR:
+   return "Max Exit Latency Too Large Error";
+   case COMP_ISOCH_BUFFER_OVERRUN:
+   return "Isoch Buffer Overrun";
+   case COMP_EVENT_LOST_ERROR:
+   return "Event Lost Error";
+   case COMP_UNDEFINED_ERROR:
+   return "Undefined Error";
+   case COMP_INVALID_STREAM_ID_ERROR:
+   return "Invalid Stream ID Error";
+   default:
+   return "Unknown!!

[PATCH v4 05/10] usb: cdns3: Changed type of gadget_dev in cdns structure

2020-12-02 Thread Pawel Laszczak
Patch changes the type for gadget_dev pointer in cdns structure from
pointer to cdns3_device structure to void pointer.
This filed is in reusable code and after this change it will be used to
point to both cdns3_device or cdnsp_device objects.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index f664eb2d8df4..cbd2e1cc8eb1 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -64,7 +64,7 @@ struct cdns3_platform_data {
  * @roles: array of supported roles for this controller
  * @role: current role
  * @host_dev: the child host device pointer for cdns core
- * @gadget_dev: the child gadget device pointer for cdns3 core
+ * @gadget_dev: the child gadget device pointer
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
  * @mutex: the mutex for concurrent code at driver
@@ -104,7 +104,7 @@ struct cdns {
struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
enum usb_role   role;
struct platform_device  *host_dev;
-   struct cdns3_device *gadget_dev;
+   void*gadget_dev;
struct phy  *usb2_phy;
struct phy  *usb3_phy;
/* mutext used in workqueue*/
-- 
2.17.1



RE: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"

2020-11-25 Thread Pawel Laszczak
>
>On 25/11/2020 02:36, Peter Chen wrote:
>> On 20-11-24 14:22:25, Roger Quadros wrote:
>>> Peter,
>>>
>>> On 24/11/2020 13:47, Peter Chen wrote:
 On 20-11-24 12:33:34, Roger Quadros wrote:

 I am sorry about that. Do you use role switch /sys entry, if you have
 used, I prefer using "usb-role-switch" property at dts to judge if SoC
 OTG signals or external signals for role switch. If you have not used
 it, I prefer only setting cdns->role_sw for role switch use cases.

>>>
>>> We use both hardware role switch and /sys entries for manually forcing a
>>> certain role.
>>>
>>> We do not set any "usb-role-switch" property at DTS.
>>>
>>> Currently cdns->role_sw is being always set by driver irrespective of 
>>> any DT
>>> property, so this patch is clearly wrong and needs to be reverted.
>>>
>>> What do you think?
>>>
>>
>> Could you accept below fix?
>>
>> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
>> index 2e469139769f..fdd52e87a7b2 100644
>> --- a/drivers/usb/cdns3/core.c
>> +++ b/drivers/usb/cdns3/core.c
>> @@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
>>enum usb_role real_role, current_role;
>>int ret = 0;
>>
>> -   /* Depends on role switch class */
>> -   if (cdns->role_sw)
>> +   /* quit if switch role through external signals */
>> +   if (device_property_read_bool(cdns->dev, "usb-role-switch"))
>>return 0;
>>
>>pm_runtime_get_sync(cdns->dev);
>
> Although this will fix the issue I don't think this is making the driver 
> to behave
> as expected with usb-role-switch property.
>
> Now, even if usb-role-switch property is not present the driver will 
> still register
> the role switch driver.
>
> I think we need to register the role switch driver only if 
> usb-role-switch property
> is present. We would also need to set the default role if 
> role-switch-default-mode is present.
>
> How about the following? It still doesn't handle role-switch-default-mode 
> property though.
>

 Roger, you said you also use /sys entries (I suppose it means through role
 switch class) to do role switch, with your change, there will be no /sys
 entry for role switch.
>>>
>>> Sorry for the confusion. Although we do need both features (SW role switch 
>>> + HW role switch)
>>> I don't think it is required to operate simultaneously. If users need SW 
>>> control they can set the DT flag.
>>>
>>
>> I see. I prefer embracing all things related to role switch under the
>> firmware entry condition. Besides, I find another issue that devm_request_irq
>> for wakeup_irq does not call usb_role_switch_unregister if it has
>> failed. So, probably, two patches are needed. I am OK you send the
>> patches to fix both.
>
>Pawel, can you please confirm that if you are ok with either h/w role switching
>or s/w role switching but not both working at the same time?
>
>It would have been nice by user to to know the current role even for h/w based
>swithcing but it looks like now that won't be possible.

For the moment it's ok for me, but form testing point of view it could be nice
to have possibility to easy choose between these two modes in dynamically way.

For PCI based on platform probably I will have to add some parameter to 
cdns3-pci.ko
module to allow selecting modes. I don't  use DTS. 

Don't worry about it now. You can post this fix. 

Cheers,
Pawel 

>
>cheers,
>-roger
>>
>> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
>> index 2e469139769f..fc6a8152406c 100644
>> --- a/drivers/usb/cdns3/core.c
>> +++ b/drivers/usb/cdns3/core.c
>> @@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
>>*/
>>   static int cdns3_probe(struct platform_device *pdev)
>>   {
>> -struct usb_role_switch_desc sw_desc = { };
>>  struct device *dev = >dev;
>>  struct resource *res;
>>  struct cdns3 *cdns;
>> @@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
>>  if (ret)
>>  goto err2;
>>
>> -sw_desc.set = cdns3_role_set;
>> -sw_desc.get = cdns3_role_get;
>> -sw_desc.allow_userspace_control = true;
>> -sw_desc.driver_data = cdns;
>> -if (device_property_read_bool(dev, "usb-role-switch"))
>> +if (device_property_read_bool(dev, "usb-role-switch")) {
>> +struct usb_role_switch_desc sw_desc = { };
>> +
>> +sw_desc.set = cdns3_role_set;
>> +sw_desc.get = cdns3_role_get;
>> +sw_desc.allow_userspace_control = true;
>> +sw_desc.driver_data = cdns;
>>  sw_desc.fwnode = dev->fwnode;
>>
>> -cdns->role_sw = usb_role_switch_register(dev, _desc);
>> -if (IS_ERR(cdns->role_sw)) {
>> -ret = 

RE: [PATCH v3 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-24 Thread Pawel Laszczak
Peter,

>
>>On 20-11-19 15:12:57, 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 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.
>>>
>>> The device side of USBSS DRD controller is compliant with XHCI.
>>> The architecture for device side is almost the same as for host side,
>>> and most of the XHCI specification can be used to understand how
>>> this controller operates.
>>>
>>> This controller and driver support Full Speed, Hight Speed, Supper Speed
>>> and Supper Speed Plus USB protocol.
>>>
>>> The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
>>> The last letter of this acronym means PLUS. The formal name of controller
>>> is USBSSP but it's to generic so I've decided to use CDNSP.
>>>
>>> The patch 1: adds support for DRD CDNSP.
>>> The patch 2: separates common code that can be reusable by cdnsp driver.
>>> The patch 3: moves reusable code to separate module.
>>> The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
>>> The patch 5: adopts gadget_dev pointer in cdns structure to make possible
>>>  use it in both drivers.
>>> The patches 6-8: add the main part of driver and has been intentionally
>>>  split into 3 part. In my opinion such division should not
>>>  affect understanding and reviewing the driver, and cause that
>>>  main patch (7/8) is little smaller. Patch 6 introduces main
>>>  header file for driver, 7 is the main part that implements all
>>>  functionality of driver and 8 introduces tracepoints.
>>> The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
>>> the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.
>>>
>>> Changlog from v2:
>>> - removed not used pdev parameter from cdnsp_read/wite_64 functions
>>> - fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
>>> - replaced some constant value with CDNSP_ENDPOINTS_NUM macro
>>> - replaced 'true' with '1' in bits description in cdnsp-gadget.h file
>>> - fixed some typos
>>> - some other less important changes suggested by Peter Chen
>>
>>Hi Pawel,
>>
>>I have updated my -next tree as the latest usb-next tree which v5.10-rc4
>>is included, would you please rebase my tree and send again, I could apply 
>>your
>>patches and test, if test could pass, I will apply it to my -next tree.
>>You don't need to rebase again since it is a huge patch set, will take some
>>efforts for rebase.
>>
>
>I'll try to post it tomorrow.

Can I send the new version CDNSP or I should wait for completion
'Re: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"' and 
applying the appropriate fix to your repo ?



Thanks
Pawel


RE: [PATCH v3 10/10] MAINTAINERS: add Cadence USBSSP DRD IP driver entry

2020-11-24 Thread Pawel Laszczak
Peter,

>
>On 20-11-19 15:13:07, Pawel Laszczak wrote:
>> Patch adds entry for USBSSP (CDNSP) driver into MAINTARNERS file.
>>
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  MAINTAINERS | 8 
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 842fef329119..70c31fd2cd61 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -3867,6 +3867,14 @@ S:Maintained
>>  T:  git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
>>  F:  Documentation/devicetree/bindings/usb/cdns,usb3.yaml
>>  F:  drivers/usb/cdns3/
>> +X:  drivers/usb/cdns3/cdnsp*
>> +
>> +CADENCE USBSSP DRD IP DRIVER
>> +M:  Pawel Laszczak 
>> +L:  linux-...@vger.kernel.org
>> +S:  Maintained
>> +F:  drivers/usb/cdns3/
>> +X:  drivers/usb/cdns3/cdns3*
>>
>
>Hi Pawel,
>
>You may add "T" for which tree for cdns3 ssp driver.

It make sense. I will do it.

--

Thanks,
Pawel


RE: [PATCH v3 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-24 Thread Pawel Laszczak
Sekhar,

>
>
>On 24/11/20 2:51 PM, Pawel Laszczak wrote:
>> Peter,
>>
>>> On 20-11-19 15:12:57, 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 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.
>>>>
>>>> The device side of USBSS DRD controller is compliant with XHCI.
>>>> The architecture for device side is almost the same as for host side,
>>>> and most of the XHCI specification can be used to understand how
>>>> this controller operates.
>>>>
>>>> This controller and driver support Full Speed, Hight Speed, Supper Speed
>>>> and Supper Speed Plus USB protocol.
>>>>
>>>> The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
>>>> The last letter of this acronym means PLUS. The formal name of controller
>>>> is USBSSP but it's to generic so I've decided to use CDNSP.
>>>>
>>>> The patch 1: adds support for DRD CDNSP.
>>>> The patch 2: separates common code that can be reusable by cdnsp driver.
>>>> The patch 3: moves reusable code to separate module.
>>>> The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
>>>> The patch 5: adopts gadget_dev pointer in cdns structure to make possible
>>>>  use it in both drivers.
>>>> The patches 6-8: add the main part of driver and has been intentionally
>>>>  split into 3 part. In my opinion such division should not
>>>>  affect understanding and reviewing the driver, and cause that
>>>>  main patch (7/8) is little smaller. Patch 6 introduces main
>>>>  header file for driver, 7 is the main part that implements all
>>>>  functionality of driver and 8 introduces tracepoints.
>>>> The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
>>>> the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.
>>>>
>>>> Changlog from v2:
>>>> - removed not used pdev parameter from cdnsp_read/wite_64 functions
>>>> - fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
>>>> - replaced some constant value with CDNSP_ENDPOINTS_NUM macro
>>>> - replaced 'true' with '1' in bits description in cdnsp-gadget.h file
>>>> - fixed some typos
>>>> - some other less important changes suggested by Peter Chen
>>>
>>> Hi Pawel,
>>>
>>> I have updated my -next tree as the latest usb-next tree which v5.10-rc4
>>> is included, would you please rebase my tree and send again, I could apply 
>>> your
>>> patches and test, if test could pass, I will apply it to my -next tree.
>>> You don't need to rebase again since it is a huge patch set, will take some
>>> efforts for rebase.
>>>
>>
>> I'll try to post it tomorrow.
>
>Pawel, have you tested TI J7 for regressions after this series? After
>your latest changes, can you post a tree which someone in TI can test?

No I haven't test it on J7.  For testing I'm using PCIe based platform for
both cnds3 and cdnsp driver. 

Why you can't use the latest kernel version and current series ? 

--

Thanks
Pawel



RE: [PATCH v3 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-24 Thread Pawel Laszczak
Peter,

>On 20-11-19 15:12:57, 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 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.
>>
>> The device side of USBSS DRD controller is compliant with XHCI.
>> The architecture for device side is almost the same as for host side,
>> and most of the XHCI specification can be used to understand how
>> this controller operates.
>>
>> This controller and driver support Full Speed, Hight Speed, Supper Speed
>> and Supper Speed Plus USB protocol.
>>
>> The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
>> The last letter of this acronym means PLUS. The formal name of controller
>> is USBSSP but it's to generic so I've decided to use CDNSP.
>>
>> The patch 1: adds support for DRD CDNSP.
>> The patch 2: separates common code that can be reusable by cdnsp driver.
>> The patch 3: moves reusable code to separate module.
>> The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
>> The patch 5: adopts gadget_dev pointer in cdns structure to make possible
>>  use it in both drivers.
>> The patches 6-8: add the main part of driver and has been intentionally
>>  split into 3 part. In my opinion such division should not
>>  affect understanding and reviewing the driver, and cause that
>>  main patch (7/8) is little smaller. Patch 6 introduces main
>>  header file for driver, 7 is the main part that implements all
>>  functionality of driver and 8 introduces tracepoints.
>> The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
>> the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.
>>
>> Changlog from v2:
>> - removed not used pdev parameter from cdnsp_read/wite_64 functions
>> - fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
>> - replaced some constant value with CDNSP_ENDPOINTS_NUM macro
>> - replaced 'true' with '1' in bits description in cdnsp-gadget.h file
>> - fixed some typos
>> - some other less important changes suggested by Peter Chen
>
>Hi Pawel,
>
>I have updated my -next tree as the latest usb-next tree which v5.10-rc4
>is included, would you please rebase my tree and send again, I could apply your
>patches and test, if test could pass, I will apply it to my -next tree.
>You don't need to rebase again since it is a huge patch set, will take some
>efforts for rebase.
>

I'll try to post it tomorrow.

>>
>> Changlog from v1:
>> - updated common code to latest cdns3 driver
>> - moved cdnsp driver files to cdns3 as sugested by Peter Chan
>> - removed duplicate code from cdnsp_ep0_set_config function
>> - added cdns3 prefixes to file related with USBSS driver
>> - updated MAINTAINERS file
>> - fixed issue with U1
>> - fixed issue with L1
>> - some less improtant changes sugested by Chunfeng Yun
>> ---
>>
>> Pawel Laszczak (10):
>>   usb: cdns3: Add support for DRD CDNSP
>>   usb: cdns3: Split core.c into cdns3-plat and core.c file
>>   usb: cdns3: Moves reusable code to separate module
>>   usb: cdns3: Refactoring names in reusable code
>>   usb: cdns3: Changed type of gadget_dev in cdns structure
>>   usb: cdnsp: Device side header file for CDNSP driver
>>   usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver
>>   usb: cdnsp: Add tracepoints for CDNSP driver
>>   usb: cdns3: Change file names for cdns3 driver.
>>   MAINTAINERS: add Cadence USBSSP DRD IP driver entry
>>
>>  MAINTAINERS   |8 +
>>  drivers/usb/Makefile  |2 +
>>  drivers/usb/cdns3/Kconfig |   61 +-
>>  drivers/usb/cdns3/Makefile|   30 +-
>>  drivers/usb/cdns3/{debug.h => cdns3-debug.h}  |0
>>  drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}  |4 +-
>>  .../usb/cdns3/{gadget.c => cdns3-gadget.c}|   28 +-
>>  .../usb/cdns3/{gadget.h => cdns3-gadget.h}|0
>>  drivers/usb/cdns3/cdns3-imx.c |2 +-
>>  drivers/usb/cdns3/cdns3-plat.c|  315 +++
>>  driv

RE: [PATCH] usb: cdns3: fix NULL pointer dereference on no platform data

2020-11-23 Thread Pawel Laszczak
Hi,

>
>Some platforms (e.g. TI) will not have any platform data which will
>lead to NULL pointer dereference if we don't check for NULL pdata.
>
>Fixes: a284b7fd1b8f ("usb: cdns3: add quirk for enable runtime pm by default")
>Reported-by: Nishanth Menon 
>Signed-off-by: Roger Quadros 

Acked-by: Pawel Laszczak 

I see the same issue on my PCI based platform. 

But I afraid that there will be some conflict with applying my CDSNP series 
after
applying this patch on Peter Chen branch :(

>---
> drivers/usb/cdns3/core.c | 2 +-
> drivers/usb/cdns3/host.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
>index 54d841aa626f..0f08aebce86d 100644
>--- a/drivers/usb/cdns3/core.c
>+++ b/drivers/usb/cdns3/core.c
>@@ -559,7 +559,7 @@ static int cdns3_probe(struct platform_device *pdev)
>   device_set_wakeup_capable(dev, true);
>   pm_runtime_set_active(dev);
>   pm_runtime_enable(dev);
>-  if (!(cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
>+  if (!(cdns->pdata && (cdns->pdata->quirks & 
>CDNS3_DEFAULT_PM_RUNTIME_ALLOW)))
>   pm_runtime_forbid(dev);
>
>   /*
>diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c
>index 08103785a17a..ec89f2e5430f 100644
>--- a/drivers/usb/cdns3/host.c
>+++ b/drivers/usb/cdns3/host.c
>@@ -59,7 +59,7 @@ static int __cdns3_host_init(struct cdns3 *cdns)
>   goto err1;
>   }
>
>-  if (cdns->pdata->quirks & CDNS3_DEFAULT_PM_RUNTIME_ALLOW)
>+  if (cdns->pdata && (cdns->pdata->quirks & 
>CDNS3_DEFAULT_PM_RUNTIME_ALLOW))
>   cdns->xhci_plat_data->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW;
>
>   ret = platform_device_add_data(xhci, cdns->xhci_plat_data,

--
Regards,
Pawel Laszczak


[PATCH v3 10/10] MAINTAINERS: add Cadence USBSSP DRD IP driver entry

2020-11-19 Thread Pawel Laszczak
Patch adds entry for USBSSP (CDNSP) driver into MAINTARNERS file.

Signed-off-by: Pawel Laszczak 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 842fef329119..70c31fd2cd61 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3867,6 +3867,14 @@ S:   Maintained
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
 F: Documentation/devicetree/bindings/usb/cdns,usb3.yaml
 F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdnsp*
+
+CADENCE USBSSP DRD IP DRIVER
+M: Pawel Laszczak 
+L: linux-...@vger.kernel.org
+S: Maintained
+F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdns3*
 
 CADET FM/AM RADIO RECEIVER DRIVER
 M: Hans Verkuil 
-- 
2.17.1



[PATCH v3 09/10] usb: cdns3: Change file names for cdns3 driver.

2020-11-19 Thread Pawel Laszczak
Patch adds prefix cdns3- to all file names related only to
cdns3 driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile | 6 +++---
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}   | 0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}   | 4 ++--
 drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} | 4 ++--
 drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} | 0
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}   | 2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}   | 6 +++---
 7 files changed, 11 insertions(+), 11 deletions(-)
 rename drivers/usb/cdns3/{debug.h => cdns3-debug.h} (100%)
 rename drivers/usb/cdns3/{ep0.c => cdns3-ep0.c} (99%)
 rename drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} (99%)
 rename drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} (100%)
 rename drivers/usb/cdns3/{trace.c => cdns3-trace.c} (89%)
 rename drivers/usb/cdns3/{trace.h => cdns3-trace.h} (99%)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a4fdaabdbe18..01a9a9620044 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
-CFLAGS_trace.o := -I$(src)
+CFLAGS_cdns3-trace.o   := -I$(src)
 CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
@@ -10,10 +10,10 @@ obj-$(CONFIG_USB_CDNS3) += 
cdns3.o
 obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns-usb-common.o
 
 cdns-usb-common-$(CONFIG_USB_CDNS_HOST)+= host.o
-cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)   += cdns3-gadget.o cdns3-ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
-cdns3-$(CONFIG_TRACING)+= trace.o
+cdns3-$(CONFIG_TRACING)+= cdns3-trace.o
 endif
 
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/cdns3-debug.h
similarity index 100%
rename from drivers/usb/cdns3/debug.h
rename to drivers/usb/cdns3/cdns3-debug.h
diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/cdns3-ep0.c
similarity index 99%
rename from drivers/usb/cdns3/ep0.c
rename to drivers/usb/cdns3/cdns3-ep0.c
index d3121a32cc68..b0390fe9a396 100644
--- a/drivers/usb/cdns3/ep0.c
+++ b/drivers/usb/cdns3/cdns3-ep0.c
@@ -13,8 +13,8 @@
 #include 
 #include 
 
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 
 static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
similarity index 99%
rename from drivers/usb/cdns3/gadget.c
rename to drivers/usb/cdns3/cdns3-gadget.c
index 9e0a82063873..d507a23c7047 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -63,8 +63,8 @@
 
 #include "core.h"
 #include "gadget-export.h"
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 #include "drd.h"
 
 static int __cdns3_gadget_ep_queue(struct usb_ep *ep,
diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/cdns3-gadget.h
similarity index 100%
rename from drivers/usb/cdns3/gadget.h
rename to drivers/usb/cdns3/cdns3-gadget.h
diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/cdns3-trace.c
similarity index 89%
rename from drivers/usb/cdns3/trace.c
rename to drivers/usb/cdns3/cdns3-trace.c
index 459fa72d9c74..b9858acaef02 100644
--- a/drivers/usb/cdns3/trace.c
+++ b/drivers/usb/cdns3/cdns3-trace.c
@@ -8,4 +8,4 @@
  */
 
 #define CREATE_TRACE_POINTS
-#include "trace.h"
+#include "cdns3-trace.h"
diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/cdns3-trace.h
similarity index 99%
rename from drivers/usb/cdns3/trace.h
rename to drivers/usb/cdns3/cdns3-trace.h
index 0a2a3269bfac..8648c7a7a9dd 100644
--- a/drivers/usb/cdns3/trace.h
+++ b/drivers/usb/cdns3/cdns3-trace.h
@@ -19,8 +19,8 @@
 #include 
 #include 
 #include "core.h"
-#include "gadget.h"
-#include "debug.h"
+#include "cdns3-gadget.h"
+#include "cdns3-debug.h"
 
 #define CDNS3_MSG_MAX  500
 
@@ -565,6 +565,6 @@ DEFINE_EVENT(cdns3_log_request_handled, 
cdns3_request_handled,
 #define TRACE_INCLUDE_PATH .
 
 #undef TRACE_INCLUDE_FILE
-#define TRACE_INCLUDE_FILE trace
+#define TRACE_INCLUDE_FILE cdns3-trace
 
 #include 
-- 
2.17.1



[PATCH v3 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-19 Thread Pawel Laszczak
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 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.

The device side of USBSS DRD controller is compliant with XHCI.
The architecture for device side is almost the same as for host side,
and most of the XHCI specification can be used to understand how
this controller operates.

This controller and driver support Full Speed, Hight Speed, Supper Speed
and Supper Speed Plus USB protocol.

The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
The last letter of this acronym means PLUS. The formal name of controller
is USBSSP but it's to generic so I've decided to use CDNSP.

The patch 1: adds support for DRD CDNSP.
The patch 2: separates common code that can be reusable by cdnsp driver.
The patch 3: moves reusable code to separate module.
The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
The patch 5: adopts gadget_dev pointer in cdns structure to make possible 
 use it in both drivers.
The patches 6-8: add the main part of driver and has been intentionally
 split into 3 part. In my opinion such division should not
 affect understanding and reviewing the driver, and cause that
 main patch (7/8) is little smaller. Patch 6 introduces main
 header file for driver, 7 is the main part that implements all
 functionality of driver and 8 introduces tracepoints.
The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.

Changlog from v2:
- removed not used pdev parameter from cdnsp_read/wite_64 functions
- fixed incorrect value assigned to CDNSP_ENDPOINTS_NUM (32 -> 31)
- replaced some constant value with CDNSP_ENDPOINTS_NUM macro
- replaced 'true' with '1' in bits description in cdnsp-gadget.h file
- fixed some typos
- some other less important changes suggested by Peter Chen

Changlog from v1:
- updated common code to latest cdns3 driver
- moved cdnsp driver files to cdns3 as sugested by Peter Chan
- removed duplicate code from cdnsp_ep0_set_config function
- added cdns3 prefixes to file related with USBSS driver
- updated MAINTAINERS file
- fixed issue with U1
- fixed issue with L1
- some less improtant changes sugested by Chunfeng Yun
---

Pawel Laszczak (10):
  usb: cdns3: Add support for DRD CDNSP
  usb: cdns3: Split core.c into cdns3-plat and core.c file
  usb: cdns3: Moves reusable code to separate module
  usb: cdns3: Refactoring names in reusable code
  usb: cdns3: Changed type of gadget_dev in cdns structure
  usb: cdnsp: Device side header file for CDNSP driver
  usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver
  usb: cdnsp: Add tracepoints for CDNSP driver
  usb: cdns3: Change file names for cdns3 driver.
  MAINTAINERS: add Cadence USBSSP DRD IP driver entry

 MAINTAINERS   |8 +
 drivers/usb/Makefile  |2 +
 drivers/usb/cdns3/Kconfig |   61 +-
 drivers/usb/cdns3/Makefile|   30 +-
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}  |0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}  |4 +-
 .../usb/cdns3/{gadget.c => cdns3-gadget.c}|   28 +-
 .../usb/cdns3/{gadget.h => cdns3-gadget.h}|0
 drivers/usb/cdns3/cdns3-imx.c |2 +-
 drivers/usb/cdns3/cdns3-plat.c|  315 +++
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}  |2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}  |6 +-
 drivers/usb/cdns3/cdnsp-debug.h   |  583 
 drivers/usb/cdns3/cdnsp-ep0.c |  495 
 drivers/usb/cdns3/cdnsp-gadget.c  | 2017 ++
 drivers/usb/cdns3/cdnsp-gadget.h  | 1600 +++
 drivers/usb/cdns3/cdnsp-mem.c | 1325 +
 drivers/usb/cdns3/cdnsp-pci.c |  255 ++
 drivers/usb/cdns3/cdnsp-ring.c| 2439 +
 drivers/usb/cdns3/cdnsp-trace.c   |   12 +
 drivers/usb/cdns3/cdnsp-trace.h   |  840 ++
 drivers/usb/cdns3/core.c  |  454 +--
 drivers/usb/cdns3/core.h  |   54 +-
 drivers/usb/cdns3/drd.c   |  222 +-
 drivers/usb/cdns3/drd.h   |   94 +-
 drivers/usb/cdns3/gadget-export.h |   22 +-
 drivers/usb/cdns3/host-export.h   |   13 +-
 drivers/usb/cdns3/host.c  |   22 +-
 28 files changed, 10398 insertions(+), 507 deletions(-)
 rename drivers/usb/cdns3/{debug.h =

[PATCH v3 06/10] usb: cdnsp: Device side header file for CDNSP driver

2020-11-19 Thread Pawel Laszczak
Patch defines macros, registers and structures used by
Device side driver.

Because the size of main patch is very big, I’ve decided to create
separate patch for cdnsp-gadget.h. It should simplify reviewing the code.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdnsp-gadget.h | 1463 ++
 1 file changed, 1463 insertions(+)
 create mode 100644 drivers/usb/cdns3/cdnsp-gadget.h

diff --git a/drivers/usb/cdns3/cdnsp-gadget.h b/drivers/usb/cdns3/cdnsp-gadget.h
new file mode 100644
index ..93da1dcdad60
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-gadget.h
@@ -0,0 +1,1463 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ * Code based on Linux XHCI driver.
+ * Origin: Copyright (C) 2008 Intel Corp.
+ */
+#ifndef __LINUX_CDNSP_GADGET_H
+#define __LINUX_CDNSP_GADGET_H
+
+#include 
+#include 
+#include 
+
+/* Max number slots - only 1 is allowed. */
+#define CDNSP_DEV_MAX_SLOTS1
+
+#define CDNSP_EP0_SETUP_SIZE   512
+
+/* One control and 15 for in and 15 for out endpoints. */
+#define CDNSP_ENDPOINTS_NUM31
+
+/* Best Effort Service Latency. */
+#define CDNSP_DEFAULT_BESL 0
+
+/* Device Controller command default timeout value in us */
+#define CDNSP_CMD_TIMEOUT  (15 * 1000)
+
+/* Up to 16 ms to halt an device controller */
+#define CDNSP_MAX_HALT_USEC(16 * 1000)
+
+#define CDNSP_CTX_SIZE 2112
+
+/*
+ * Controller register interface.
+ */
+
+/**
+ * struct cdnsp_cap_regs - CDNSP Registers.
+ * @hc_capbase:Length of the capabilities register and controller
+ *  version number
+ * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
+ * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
+ * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
+ * @hcc_params: HCCPARAMS - Capability Parameters
+ * @db_off: DBOFF - Doorbell array offset
+ * @run_regs_off: RTSOFF - Runtime register space offset
+ * @hcc_params2: HCCPARAMS2 Capability Parameters 2,
+ */
+struct cdnsp_cap_regs {
+   __le32 hc_capbase;
+   __le32 hcs_params1;
+   __le32 hcs_params2;
+   __le32 hcs_params3;
+   __le32 hcc_params;
+   __le32 db_off;
+   __le32 run_regs_off;
+   __le32 hcc_params2;
+   /* Reserved up to (CAPLENGTH - 0x1C) */
+};
+
+/* hc_capbase bitmasks. */
+/* bits 7:0 - how long is the Capabilities register. */
+#define HC_LENGTH(p)   (((p) >> 00) & GENMASK(7, 0))
+/* bits 31:16  */
+#define HC_VERSION(p)  (((p) >> 16) & GENMASK(15, 1))
+
+/* HCSPARAMS1 - hcs_params1 - bitmasks */
+/* bits 0:7, Max Device Endpoints */
+#define HCS_ENDPOINTS_MASK GENMASK(7, 0)
+#define HCS_ENDPOINTS(p)   (((p) & HCS_ENDPOINTS_MASK) >> 0)
+
+/* HCCPARAMS offset from PCI base address */
+#define HCC_PARAMS_OFFSET  0x10
+
+/* HCCPARAMS - hcc_params - bitmasks */
+/* 1: device controller can use 64-bit address pointers. */
+#define HCC_64BIT_ADDR(p)  ((p) & BIT(0))
+/* 1: device controller uses 64-byte Device Context structures. */
+#define HCC_64BYTE_CONTEXT(p)  ((p) & BIT(2))
+/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15. */
+#define HCC_MAX_PSA(p) p) >> 12) & 0xf) + 1)
+/* Extended Capabilities pointer from PCI base. */
+#define HCC_EXT_CAPS(p)(((p) & GENMASK(31, 16)) >> 16)
+
+#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
+
+/* db_off bitmask - bits 0:1 reserved. */
+#define DBOFF_MASK GENMASK(31, 2)
+
+/* run_regs_off bitmask - bits 0:4 reserved. */
+#define RTSOFF_MASKGENMASK(31, 5)
+
+/**
+ * struct cdnsp_op_regs - Device Controller Operational Registers.
+ * @command: USBCMD - Controller command register.
+ * @status: USBSTS - Controller status register.
+ * @page_size: This indicates the page size that the device controller 
supports.
+ * If bit n is set, the controller supports a page size of 
2^(n+12),
+ * up to a 128MB page size. 4K is the minimum page size.
+ * @dnctrl: DNCTRL - Device notification control register.
+ * @cmd_ring: CRP - 64-bit Command Ring Pointer.
+ * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer.
+ * @config_reg: CONFIG - Configure Register
+ * @port_reg_base: PORTSCn - base address for Port Status and Control
+ * Each port has a Port Status and Control register,
+ * followed by a Port Power Management Status and Control
+ * register, a Port Link Info register, and a reserved
+ * register.
+ */
+struct cdnsp_op_regs {
+   __le32 command;
+   __le32 status;
+   __le32 page_size;
+   __le32 reserved1;
+   __le32 reserved2;
+   __le32 dnctrl;
+   __le64 cmd_ring;
+   /* rsvd: offset 0x20-2F. */
+   __le32 reserved3[4];
+   __le64 dcbaa_ptr;
+   __le32 config_reg;
+   /* rsvd: offset 0x3

[PATCH v3 04/10] usb: cdns3: Refactoring names in reusable code

2020-11-19 Thread Pawel Laszczak
Patch change the functions and objects names in reusable code.
The reusable code includes core.c, core.h, drd.c and drd.h files.
It also changes the names of all references to these functions and
objects in other cdns3 files. There are a lot of changes, but all
changes are very trivial.
The reason of this patch is to avoid of mixing prefix cdns3 and cdnsp in
in cdnsp driver what could introduce some confusion in understanding
of cdnsp driver.
This patch assumes to use three different prefixes in Cadence
USB drivers:
  cdns: for common reusable code
  cdnsp: for names related only with cdnsp driver
  cdns3: for names related only with cdns3 driver

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdns3-imx.c |   2 +-
 drivers/usb/cdns3/cdns3-plat.c|  25 +++---
 drivers/usb/cdns3/core.c  | 142 +++---
 drivers/usb/cdns3/core.h  |  46 +-
 drivers/usb/cdns3/drd.c   | 100 ++---
 drivers/usb/cdns3/drd.h   |  26 +++---
 drivers/usb/cdns3/gadget-export.h |   4 +-
 drivers/usb/cdns3/gadget.c|  24 ++---
 drivers/usb/cdns3/host-export.h   |   6 +-
 drivers/usb/cdns3/host.c  |  22 ++---
 10 files changed, 199 insertions(+), 198 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
index 22a56c4dce67..d9fb68766a15 100644
--- a/drivers/usb/cdns3/cdns3-imx.c
+++ b/drivers/usb/cdns3/cdns3-imx.c
@@ -250,7 +250,7 @@ static void cdns3_set_wakeup(struct cdns_imx *data, bool 
enable)
 static int cdns_imx_platform_suspend(struct device *dev,
bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
struct device *parent = dev->parent;
struct cdns_imx *data = dev_get_drvdata(parent);
void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs);
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index ddebb1511c56..477832db67b7 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -20,7 +20,7 @@
 #include "core.h"
 #include "gadget-export.h"
 
-static int set_phy_power_on(struct cdns3 *cdns)
+static int set_phy_power_on(struct cdns *cdns)
 {
int ret;
 
@@ -35,7 +35,7 @@ static int set_phy_power_on(struct cdns3 *cdns)
return ret;
 }
 
-static void set_phy_power_off(struct cdns3 *cdns)
+static void set_phy_power_off(struct cdns *cdns)
 {
phy_power_off(cdns->usb3_phy);
phy_power_off(cdns->usb2_phy);
@@ -51,7 +51,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
struct resource *res;
-   struct cdns3 *cdns;
+   struct cdns *cdns;
void __iomem *regs;
int ret;
 
@@ -136,7 +136,8 @@ static int cdns3_plat_probe(struct platform_device *pdev)
goto err_phy_power_on;
 
cdns->gadget_init = cdns3_gadget_init;
-   ret = cdns3_init(cdns);
+
+   ret = cdns_init(cdns);
if (ret)
goto err_cdns_init;
 
@@ -175,13 +176,13 @@ static int cdns3_plat_probe(struct platform_device *pdev)
  */
 static int cdns3_plat_remove(struct platform_device *pdev)
 {
-   struct cdns3 *cdns = platform_get_drvdata(pdev);
+   struct cdns *cdns = platform_get_drvdata(pdev);
struct device *dev = cdns->dev;
 
pm_runtime_get_sync(dev);
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);
-   cdns3_remove(cdns);
+   cdns_remove(cdns);
set_phy_power_off(cdns);
phy_exit(cdns->usb2_phy);
phy_exit(cdns->usb3_phy);
@@ -193,7 +194,7 @@ static int cdns3_plat_remove(struct platform_device *pdev)
 static int cdns3_set_platform_suspend(struct device *dev,
  bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret = 0;
 
if (cdns->pdata && cdns->pdata->platform_suspend)
@@ -204,7 +205,7 @@ static int cdns3_set_platform_suspend(struct device *dev,
 
 static int cdns3_controller_suspend(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
bool wakeup;
unsigned long flags;
 
@@ -228,7 +229,7 @@ static int cdns3_controller_suspend(struct device *dev, 
pm_message_t msg)
 
 static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret;
unsigned long flags;
 
@@ -242,7 +243,7 @@ static int cdns3_controller_resume(struct device *dev, 
pm_message_t msg)
cdns3_set_platform_suspend(cdns->dev, false, false);
 
spin_lock_irqsave(>lock, flags);
-   cdns3_resume(cdns, !PMSG_IS_AUTO(msg));
+

[PATCH v3 08/10] usb: cdnsp: Add tracepoints for CDNSP driver

2020-11-19 Thread Pawel Laszczak
Patch adds the series of tracepoints that can be used for
debugging issues detected in driver.

Signed-off-by: Pawel Laszczak 
Reviewed-by: Peter Chen 
---
 drivers/usb/cdns3/Makefile   |   5 +
 drivers/usb/cdns3/cdnsp-debug.h  | 583 +
 drivers/usb/cdns3/cdnsp-ep0.c|  22 +-
 drivers/usb/cdns3/cdnsp-gadget.c |  75 ++-
 drivers/usb/cdns3/cdnsp-mem.c|  18 +-
 drivers/usb/cdns3/cdnsp-ring.c   |  75 ++-
 drivers/usb/cdns3/cdnsp-trace.c  |  12 +
 drivers/usb/cdns3/cdnsp-trace.h  | 840 +++
 8 files changed, 1614 insertions(+), 16 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdnsp-debug.h
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.c
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.h

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a84b129f14b8..a4fdaabdbe18 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
+CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
 cdns3-y:= cdns3-plat.o
@@ -23,3 +24,7 @@ cdnsp-udc-pci-y   := 
cdnsp-pci.o
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
+
+ifneq ($(CONFIG_USB_CDNSP_GADGET),)
+cdnsp-udc-pci-$(CONFIG_TRACING)+= cdnsp-trace.o
+endif
diff --git a/drivers/usb/cdns3/cdnsp-debug.h b/drivers/usb/cdns3/cdnsp-debug.h
new file mode 100644
index ..d6345d4d2911
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-debug.h
@@ -0,0 +1,583 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ */
+#ifndef __LINUX_CDNSP_DEBUG
+#define __LINUX_CDNSP_DEBUG
+
+static inline const char *cdnsp_trb_comp_code_string(u8 status)
+{
+   switch (status) {
+   case COMP_INVALID:
+   return "Invalid";
+   case COMP_SUCCESS:
+   return "Success";
+   case COMP_DATA_BUFFER_ERROR:
+   return "Data Buffer Error";
+   case COMP_BABBLE_DETECTED_ERROR:
+   return "Babble Detected";
+   case COMP_TRB_ERROR:
+   return "TRB Error";
+   case COMP_RESOURCE_ERROR:
+   return "Resource Error";
+   case COMP_NO_SLOTS_AVAILABLE_ERROR:
+   return "No Slots Available Error";
+   case COMP_INVALID_STREAM_TYPE_ERROR:
+   return "Invalid Stream Type Error";
+   case COMP_SLOT_NOT_ENABLED_ERROR:
+   return "Slot Not Enabled Error";
+   case COMP_ENDPOINT_NOT_ENABLED_ERROR:
+   return "Endpoint Not Enabled Error";
+   case COMP_SHORT_PACKET:
+   return "Short Packet";
+   case COMP_RING_UNDERRUN:
+   return "Ring Underrun";
+   case COMP_RING_OVERRUN:
+   return "Ring Overrun";
+   case COMP_VF_EVENT_RING_FULL_ERROR:
+   return "VF Event Ring Full Error";
+   case COMP_PARAMETER_ERROR:
+   return "Parameter Error";
+   case COMP_CONTEXT_STATE_ERROR:
+   return "Context State Error";
+   case COMP_EVENT_RING_FULL_ERROR:
+   return "Event Ring Full Error";
+   case COMP_INCOMPATIBLE_DEVICE_ERROR:
+   return "Incompatible Device Error";
+   case COMP_MISSED_SERVICE_ERROR:
+   return "Missed Service Error";
+   case COMP_COMMAND_RING_STOPPED:
+   return "Command Ring Stopped";
+   case COMP_COMMAND_ABORTED:
+   return "Command Aborted";
+   case COMP_STOPPED:
+   return "Stopped";
+   case COMP_STOPPED_LENGTH_INVALID:
+   return "Stopped - Length Invalid";
+   case COMP_STOPPED_SHORT_PACKET:
+   return "Stopped - Short Packet";
+   case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR:
+   return "Max Exit Latency Too Large Error";
+   case COMP_ISOCH_BUFFER_OVERRUN:
+   return "Isoch Buffer Overrun";
+   case COMP_EVENT_LOST_ERROR:
+   return "Event Lost Error";
+   case COMP_UNDEFINED_ERROR:
+   return "Undefined Error";
+   case COMP_INVALID_STREAM_ID_ERROR:
+   return "Invalid Stream ID Error";
+   default:
+   return "Unknown!!

[PATCH v3 01/10] usb: cdns3: Add support for DRD CDNSP

2020-11-19 Thread Pawel Laszczak
Patch adds support for Cadence DRD Super Speed Plus controller(CDNSP).
CDNSP DRD is a part of Cadence CDNSP controller.
The DRD CDNSP controller has a lot of difference on hardware level but on
software level is quite compatible with CDNS3 DRD. For this reason
CDNS3 DRD part of CDNS3 driver was reused for CDNSP driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.c |  24 +++---
 drivers/usb/cdns3/core.h |   5 ++
 drivers/usb/cdns3/drd.c  | 101 +++
 drivers/usb/cdns3/drd.h  |  67 +-
 4 files changed, 148 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 54d841aa626f..2a85d1583ea8 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -97,13 +97,23 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 * can be restricted later depending on strap pin configuration.
 */
if (dr_mode == USB_DR_MODE_UNKNOWN) {
-   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
-   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_OTG;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
-   dr_mode = USB_DR_MODE_HOST;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_PERIPHERAL;
+   if (cdns->version == CDNSP_CONTROLLER_V2) {
+   if (IS_ENABLED(CONFIG_USB_CDNSP_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   } else {
+   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   }
}
 
/*
diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index 3176f924293a..0d87871499ea 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -55,7 +55,9 @@ struct cdns3_platform_data {
  * @otg_res: the resource for otg
  * @otg_v0_regs: pointer to base of v0 otg registers
  * @otg_v1_regs: pointer to base of v1 otg registers
+ * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
  * @otg_regs: pointer to base of otg registers
+ * @otg_irq_regs: pointer to interrupt registers
  * @otg_irq: irq number for otg controller
  * @dev_irq: irq number for device controller
  * @wakeup_irq: irq number for wakeup event, it is optional
@@ -86,9 +88,12 @@ struct cdns3 {
struct resource otg_res;
struct cdns3_otg_legacy_regs*otg_v0_regs;
struct cdns3_otg_regs   *otg_v1_regs;
+   struct cdnsp_otg_regs   *otg_cdnsp_regs;
struct cdns3_otg_common_regs*otg_regs;
+   struct cdns3_otg_irq_regs   *otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
+#define CDNSP_CONTROLLER_V22
u32 version;
boolphyrst_a_enable;
 
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 38ccd29e4cde..95863d44e3e0 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -2,13 +2,12 @@
 /*
  * Cadence USBSS DRD Driver.
  *
- * Copyright (C) 2018-2019 Cadence.
+ * Copyright (C) 2018-2020 Cadence.
  * Copyright (C) 2019 Texas Instruments
  *
  * Author: Pawel Laszczak 
  * Roger Quadros 
  *
- *
  */
 #include 
 #include 
@@ -28,8 +27,9 @@
  *
  * Returns 0 on success otherwise negative errno
  */
-int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
+static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
 {
+   u32 __iomem *override_reg;
u32 reg;
 
switch (mode) {
@@ -39,11 +39,24 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode 
mode)
break;
case USB_DR_MODE_OTG:
dev_dbg(cdns->dev, "Set controller to OTG mode\n");
-   if (cdns->version == CDNS3_CONTROLLER_V1) {
-   reg = readl(>otg_v1_regs->override);
+
+   if (cdns->version == CDNSP_CONTROLLER_V2)
+   override_reg = >otg_cdnsp_regs->override;
+   else if (cdns->version == CDNS3_CONTROLLER_V1)
+ 

[PATCH v3 05/10] usb: cdns3: Changed type of gadget_dev in cdns structure

2020-11-19 Thread Pawel Laszczak
Patch changes the type for gadget_dev pointer in cdns structure from
pointer to cdns3_device structure to void pointer.
This filed is in reusable code and after this change it will be used to
point to both cdns3_device or cdnsp_device objects.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index f664eb2d8df4..cbd2e1cc8eb1 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -64,7 +64,7 @@ struct cdns3_platform_data {
  * @roles: array of supported roles for this controller
  * @role: current role
  * @host_dev: the child host device pointer for cdns core
- * @gadget_dev: the child gadget device pointer for cdns3 core
+ * @gadget_dev: the child gadget device pointer
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
  * @mutex: the mutex for concurrent code at driver
@@ -104,7 +104,7 @@ struct cdns {
struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
enum usb_role   role;
struct platform_device  *host_dev;
-   struct cdns3_device *gadget_dev;
+   void*gadget_dev;
struct phy  *usb2_phy;
struct phy  *usb3_phy;
/* mutext used in workqueue*/
-- 
2.17.1



[PATCH v3 02/10] usb: cdns3: Split core.c into cdns3-plat and core.c file

2020-11-19 Thread Pawel Laszczak
Patch splits file core.c into core.c containing the common reusable code
and cnd3-plat.c containing device platform specific code. These changes
are required to make possible reuse DRD part of CDNS3 driver in CDNSP
driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile |   2 +-
 drivers/usb/cdns3/cdns3-plat.c | 312 +
 drivers/usb/cdns3/core.c   | 283 +++---
 drivers/usb/cdns3/core.h   |   6 +
 drivers/usb/cdns3/drd.c|   1 -
 drivers/usb/cdns3/drd.h|   1 -
 6 files changed, 342 insertions(+), 263 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdns3-plat.c

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index d47e341a6f39..a1fe9612053a 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,7 +2,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= core.o drd.o
+cdns3-y:= cdns3-plat.o core.o drd.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
new file mode 100644
index ..d538b3b2657f
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence USBSS DRD Driver.
+ *
+ * Copyright (C) 2018-2020 Cadence.
+ * Copyright (C) 2017-2018 NXP
+ * Copyright (C) 2019 Texas Instrumentsq
+ *
+ *
+ * Author: Peter Chen 
+ * Pawel Laszczak 
+ * Roger Quadros 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+
+static int set_phy_power_on(struct cdns3 *cdns)
+{
+   int ret;
+
+   ret = phy_power_on(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   ret = phy_power_on(cdns->usb3_phy);
+   if (ret)
+   phy_power_off(cdns->usb2_phy);
+
+   return ret;
+}
+
+static void set_phy_power_off(struct cdns3 *cdns)
+{
+   phy_power_off(cdns->usb3_phy);
+   phy_power_off(cdns->usb2_phy);
+}
+
+/**
+ * cdns3_plat_probe - probe for cdns3 core device
+ * @pdev: Pointer to cdns3 core platform device
+ *
+ * Returns 0 on success otherwise negative errno
+ */
+static int cdns3_plat_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;
+   cdns->pdata = dev_get_platdata(dev);
+
+   platform_set_drvdata(pdev, cdns);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host");
+   if (!res) {
+   dev_err(dev, "missing host IRQ\n");
+   return -ENODEV;
+   }
+
+   cdns->xhci_res[0] = *res;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci");
+   if (!res) {
+   dev_err(dev, "couldn't get xhci resource\n");
+   return -ENXIO;
+   }
+
+   cdns->xhci_res[1] = *res;
+
+   cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral");
+
+   if (cdns->dev_irq < 0)
+   return cdns->dev_irq;
+
+   regs = devm_platform_ioremap_resource_byname(pdev, "dev");
+   if (IS_ERR(regs))
+   return PTR_ERR(regs);
+   cdns->dev_regs  = regs;
+
+   cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
+   if (cdns->otg_irq < 0)
+   return cdns->otg_irq;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
+   if (!res) {
+   dev_err(dev, "couldn't get otg resource\n");
+   return -ENXIO;
+   }
+
+   cdns->phyrst_a_enable = device_property_read_bool(dev, 
"cdns,phyrst-a-enable");
+
+   cdns->otg_res = *res;
+
+   cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+   if (cdns->wakeup_irq == -EPROBE_DEFER)
+   return cdns->wakeup_irq;
+   else if (cdns->wakeup_irq == 0)
+   return -EINVAL;
+
+   if (cdns->wakeup_irq < 0) {
+   dev_dbg(dev, "couldn't get wakeup irq\n");
+   cdns->wakeup_irq = 0x0;
+   }
+
+   cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy");
+   if (IS_ERR(cdns->usb2_phy))
+   return PTR_ERR(cdns->usb2_phy);
+
+   ret = phy_init(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy");
+  

[PATCH v3 03/10] usb: cdns3: Moves reusable code to separate module

2020-11-19 Thread Pawel Laszczak
Patch moves common reusable code used by cdns3 and cdnsp driver
to cdns-usb-common library. This library include core.c, drd.c
and host.c files.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Kconfig  |  8 
 drivers/usb/cdns3/Makefile |  8 +---
 drivers/usb/cdns3/cdns3-plat.c |  2 ++
 drivers/usb/cdns3/core.c   | 18 +++---
 drivers/usb/cdns3/core.h   |  3 +++
 drivers/usb/cdns3/drd.c|  3 ++-
 6 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
index 84716d216ae5..58154c0a73ac 100644
--- a/drivers/usb/cdns3/Kconfig
+++ b/drivers/usb/cdns3/Kconfig
@@ -1,8 +1,15 @@
+config CDNS_USB_COMMON
+   tristate
+
+config CDNS_USB_HOST
+   bool
+
 config USB_CDNS3
tristate "Cadence USB3 Dual-Role Controller"
depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA
select USB_XHCI_PLATFORM if USB_XHCI_HCD
select USB_ROLE_SWITCH
+   select CDNS_USB_COMMON
help
  Say Y here if your system has a Cadence USB3 dual-role controller.
  It supports: dual-role switch, Host-only, and Peripheral-only.
@@ -25,6 +32,7 @@ config USB_CDNS3_GADGET
 config USB_CDNS3_HOST
bool "Cadence USB3 host controller"
depends on USB=y || USB=USB_CDNS3
+   select CDNS_USB_HOST
help
  Say Y here to enable host controller functionality of the
  Cadence driver.
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a1fe9612053a..16df87abf3cf 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,17 +2,19 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= cdns3-plat.o core.o drd.o
+cdns-usb-common-y  := core.o drd.o
+cdns3-y:= cdns3-plat.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
+obj-$(CONFIG_CDNS_USB_COMMON)  += cdns-usb-common.o
+
+cdns-usb-common-$(CONFIG_CDNS_USB_HOST) += host.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
 cdns3-$(CONFIG_TRACING)+= trace.o
 endif
 
-cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o
-
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
 obj-$(CONFIG_USB_CDNS3_TI) += cdns3-ti.o
 obj-$(CONFIG_USB_CDNS3_IMX)+= cdns3-imx.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index d538b3b2657f..ddebb1511c56 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -18,6 +18,7 @@
 #include 
 
 #include "core.h"
+#include "gadget-export.h"
 
 static int set_phy_power_on(struct cdns3 *cdns)
 {
@@ -134,6 +135,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
if (ret)
goto err_phy_power_on;
 
+   cdns->gadget_init = cdns3_gadget_init;
ret = cdns3_init(cdns);
if (ret)
goto err_cdns_init;
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 758fd5d67196..4fedf32855af 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -19,10 +19,8 @@
 #include 
 #include 
 
-#include "gadget.h"
 #include "core.h"
 #include "host-export.h"
-#include "gadget-export.h"
 #include "drd.h"
 
 static int cdns3_idle_init(struct cdns3 *cdns);
@@ -147,7 +145,11 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
}
 
if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
-   ret = cdns3_gadget_init(cdns);
+   if (cdns->gadget_init)
+   ret = cdns->gadget_init(cdns);
+   else
+   ret = -ENXIO;
+
if (ret) {
dev_err(dev, "Device initialization failed with %d\n",
ret);
@@ -473,6 +475,7 @@ int cdns3_init(struct cdns3 *cdns)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(cdns3_init);
 
 /**
  * cdns3_remove - unbind drd driver and clean up
@@ -487,6 +490,7 @@ int cdns3_remove(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_remove);
 
 #ifdef CONFIG_PM_SLEEP
 int cdns3_suspend(struct cdns3 *cdns)
@@ -505,6 +509,7 @@ int cdns3_suspend(struct cdns3 *cdns)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_suspend);
 
 int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 {
@@ -521,4 +526,11 @@ int cdns3_resume(struct cdns3 *cdns, u8 set_active)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(cdns3_resume);
 #endif /* CONFIG_PM_SLEEP */
+
+MODULE_AUTHOR("Peter Chen ");
+MODULE_AUTHOR("Pawel Laszczak ");
+MODULE_AUTHOR("Roger Quadros ");
+MODULE_DESCRIPTION("Cadence USBSS and USBSSP DRD Dr

RE: [PATCH v2 06/10] usb: cdnsp: Device side header file for CDNSP driver

2020-11-17 Thread Pawel Laszczak
Hi,

>On 20-11-06 12:42:56, Pawel Laszczak wrote:
>> Patch defines macros, registers and structures used by
>> Device side driver.
>>
>> Because the size of main patch is very big, I’ve decided to create
>> separate patch for cdnsp-gadget.h. It should simplify reviewing the code.
>>
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  drivers/usb/cdns3/cdnsp-gadget.h | 1463 ++
>>  1 file changed, 1463 insertions(+)
>>  create mode 100644 drivers/usb/cdns3/cdnsp-gadget.h
>>
>> diff --git a/drivers/usb/cdns3/cdnsp-gadget.h 
>> b/drivers/usb/cdns3/cdnsp-gadget.h
>> new file mode 100644
>> index ..29d5e2d00879
>> --- /dev/null
>> +++ b/drivers/usb/cdns3/cdnsp-gadget.h
>> @@ -0,0 +1,1463 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Cadence CDNSP DRD Driver.
>> + *
>> + * Copyright (C) 2020 Cadence.
>> + *
>> + * Author: Pawel Laszczak 
>> + *
>> + * Code based on Linux XHCI driver.
>> + * Origin: Copyright (C) 2008 Intel Corp.
>> + */
>> +#ifndef __LINUX_CDNSP_GADGET_H
>> +#define __LINUX_CDNSP_GADGET_H
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/* Max number slots - only 1 is allowed. */
>> +#define CDNSP_DEV_MAX_SLOTS 1
>> +
>> +#define CDNSP_EP0_SETUP_SIZE512
>> +
>> +/*16 for in and 16 for out. */
>> +#define CDNSP_ENDPOINTS_NUM 32
>> +
>> +/* Best Effort Service Latency. */
>> +#define CDNSP_DEFAULT_BESL  0
>> +
>> +/* Device Controller command default timeout value in us */
>> +#define CDNSP_CMD_TIMEOUT   (15 * 1000)
>> +
>> +/* Up to 16 ms to halt an device controller */
>> +#define CDNSP_MAX_HALT_USEC (16 * 1000)
>> +
>> +#define CDNSP_CTX_SIZE  2112
>> +
>> +/*
>> + * Controller register interface.
>> + */
>> +
>> +/**
>> + * struct cdnsp_cap_regs - CDNSP Registers.
>> + * @hc_capbase: Length of the capabilities register and controller
>> + *  version number
>> + * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
>> + * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
>> + * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
>> + * @hcc_params: HCCPARAMS - Capability Parameters
>> + * @db_off: DBOFF - Doorbell array offset
>> + * @run_regs_off: RTSOFF - Runtime register space offset
>> + * @hcc_params2: HCCPARAMS2 Capability Parameters 2,
>> + */
>> +struct cdnsp_cap_regs {
>> +__le32 hc_capbase;
>> +__le32 hcs_params1;
>> +__le32 hcs_params2;
>> +__le32 hcs_params3;
>> +__le32 hcc_params;
>> +__le32 db_off;
>> +__le32 run_regs_off;
>> +__le32 hcc_params2;
>> +/* Reserved up to (CAPLENGTH - 0x1C) */
>> +};
>> +
>> +/* hc_capbase bitmasks. */
>> +/* bits 7:0 - how long is the Capabilities register. */
>> +#define HC_LENGTH(p)(((p) >> 00) & GENMASK(7, 0))
>> +/* bits 31:16   */
>> +#define HC_VERSION(p)   (((p) >> 16) & GENMASK(15, 1))
>> +
>> +/* HCSPARAMS1 - hcs_params1 - bitmasks */
>> +/* bits 0:7, Max Device Endpoints */
>> +#define HCS_ENDPOINTS_MASK  GENMASK(7, 0)
>> +#define HCS_ENDPOINTS(p)(((p) & HCS_ENDPOINTS_MASK) >> 0)
>> +
>> +/* HCCPARAMS offset from PCI base address */
>> +#define HCC_PARAMS_OFFSET   0x10
>> +
>> +/* HCCPARAMS - hcc_params - bitmasks */
>> +/* true: device controller can use 64-bit address pointers. */
>
>What does "true" mean at above comment?

I understand that it's ambiguous. 

True is not always equal  1. 
I will replace it with 1. 

Thanks for review.

  

--
Regards,
Pawel


RE: [PATCH v2 03/10] usb: cdns3: Moves reusable code to separate module

2020-11-10 Thread Pawel Laszczak
>
>On Tue, Nov 10, 2020 at 11:21:22AM +, Peter Chen wrote:
>> On 20-11-10 09:20:54, Pawel Laszczak wrote:
>> > Hi,
>> >
>> > >>
>> > >>  int cdns3_hw_role_switch(struct cdns3 *cdns);
>> > >> -int cdns3_init(struct cdns3 *cdns);
>> > >> -int cdns3_remove(struct cdns3 *cdns);
>> > >> +extern int cdns3_init(struct cdns3 *cdns);
>> > >> +extern int cdns3_remove(struct cdns3 *cdns);
>> > >
>> > >Why add "extern" here and below?
>> > >
>> >
>> > These functions are the API between cdnsp and cdns3 modules.
>> > It's looks like a common approach in kernel.
>> > Many or even most of API function in kernel has "extern".
>> >
>>
>> Even you have not written "extern" keyword, the "extern" is
>> added implicitly by compiler. Usually, we use "extern" for variable
>> or the function is defined at assembly. You could see some
>> "extern" keyword use cases at include/linux/device.h.
>
>We are moving away from using this keyword for functions now, if at all
>possible please.  Only use it for variables, I think checkpatch now
>catches it as well.
>

Ok, I will remove all extern from driver. 
Removing it also will remove checkpatch.pl warmings.

Thanks
Pawel


RE: [PATCH v2 03/10] usb: cdns3: Moves reusable code to separate module

2020-11-10 Thread Pawel Laszczak
Hi,

>
>On 20-11-06 12:42:53, Pawel Laszczak wrote:
>> Patch moves common reusable code used by cdns3 and cdnsp driver
>> to cdns-usb-common library. This library include core.c, drd.c
>> and host.c files.
>>
>> Signed-off-by: Pawel Laszczak 
>> ---
>>  drivers/usb/cdns3/Kconfig  |  8 
>>  drivers/usb/cdns3/Makefile |  8 +---
>>  drivers/usb/cdns3/cdns3-plat.c |  2 ++
>>  drivers/usb/cdns3/core.c   | 18 +++---
>>  drivers/usb/cdns3/core.h   | 11 +++
>>  drivers/usb/cdns3/drd.c|  3 ++-
>>  drivers/usb/cdns3/drd.h|  4 ++--
>>  7 files changed, 41 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
>> index 84716d216ae5..58154c0a73ac 100644
>> --- a/drivers/usb/cdns3/Kconfig
>> +++ b/drivers/usb/cdns3/Kconfig
>> @@ -1,8 +1,15 @@
>> +config CDNS_USB_COMMON
>> +tristate
>> +
>> +config CDNS_USB_HOST
>> +bool
>> +
>>  config USB_CDNS3
>>  tristate "Cadence USB3 Dual-Role Controller"
>>  depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA
>>  select USB_XHCI_PLATFORM if USB_XHCI_HCD
>>  select USB_ROLE_SWITCH
>> +select CDNS_USB_COMMON
>>  help
>>Say Y here if your system has a Cadence USB3 dual-role controller.
>>It supports: dual-role switch, Host-only, and Peripheral-only.
>> @@ -25,6 +32,7 @@ config USB_CDNS3_GADGET
>>  config USB_CDNS3_HOST
>>  bool "Cadence USB3 host controller"
>>  depends on USB=y || USB=USB_CDNS3
>> +select CDNS_USB_HOST
>>  help
>>Say Y here to enable host controller functionality of the
>>Cadence driver.
>> diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
>> index a1fe9612053a..16df87abf3cf 100644
>> --- a/drivers/usb/cdns3/Makefile
>> +++ b/drivers/usb/cdns3/Makefile
>> @@ -2,17 +2,19 @@
>>  # define_trace.h needs to know how to find our header
>>  CFLAGS_trace.o  := -I$(src)
>>
>> -cdns3-y := cdns3-plat.o core.o drd.o
>> +cdns-usb-common-y   := core.o drd.o
>> +cdns3-y := cdns3-plat.o
>>
>>  obj-$(CONFIG_USB_CDNS3) += cdns3.o
>> +obj-$(CONFIG_CDNS_USB_COMMON)   += cdns-usb-common.o
>> +
>> +cdns-usb-common-$(CONFIG_CDNS_USB_HOST) += host.o
>>  cdns3-$(CONFIG_USB_CDNS3_GADGET)+= gadget.o ep0.o
>>
>>  ifneq ($(CONFIG_USB_CDNS3_GADGET),)
>>  cdns3-$(CONFIG_TRACING) += trace.o
>>  endif
>>
>> -cdns3-$(CONFIG_USB_CDNS3_HOST)  += host.o
>> -
>>  obj-$(CONFIG_USB_CDNS3_PCI_WRAP)+= cdns3-pci-wrap.o
>>  obj-$(CONFIG_USB_CDNS3_TI)  += cdns3-ti.o
>>  obj-$(CONFIG_USB_CDNS3_IMX) += cdns3-imx.o
>> diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
>> index b74882af3a9f..562163c81911 100644
>> --- a/drivers/usb/cdns3/cdns3-plat.c
>> +++ b/drivers/usb/cdns3/cdns3-plat.c
>> @@ -18,6 +18,7 @@
>>  #include 
>>
>>  #include "core.h"
>> +#include "gadget-export.h"
>>
>>  static int set_phy_power_on(struct cdns3 *cdns)
>>  {
>> @@ -134,6 +135,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
>>  if (ret)
>>  goto err_phy_power_on;
>>
>> +cdns->gadget_init = cdns3_gadget_init;
>>  ret = cdns3_init(cdns);
>>  if (ret)
>>  goto err_cdns_init;
>> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
>> index 758fd5d67196..4fedf32855af 100644
>> --- a/drivers/usb/cdns3/core.c
>> +++ b/drivers/usb/cdns3/core.c
>> @@ -19,10 +19,8 @@
>>  #include 
>>  #include 
>>
>> -#include "gadget.h"
>>  #include "core.h"
>>  #include "host-export.h"
>> -#include "gadget-export.h"
>>  #include "drd.h"
>>
>>  static int cdns3_idle_init(struct cdns3 *cdns);
>> @@ -147,7 +145,11 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
>>  }
>>
>>  if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) {
>> -ret = cdns3_gadget_init(cdns);
>> +if (cdns->gadget_init)
>> +ret = cdns->gadget_init(cdns);
>> +else
>> +ret = -ENXIO;
>> +
&

RE: [PATCH v2 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-09 Thread Pawel Laszczak
Hi,

>
>On Fri, Nov 06, 2020 at 12:42:50PM +0100, 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 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.
>>
>> The device side of USBSS DRD controller is compliant with XHCI.
>> The architecture for device side is almost the same as for host side,
>> and most of the XHCI specification can be used to understand how
>> this controller operates.
>>
>> This controller and driver support Full Speed, Hight Speed, Supper Speed
>> and Supper Speed Plus USB protocol.
>>
>> The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
>> The last letter of this acronym means PLUS. The formal name of controller
>> is USBSSP but it's to generic so I've decided to use CDNSP.
>>
>> The patch 1: adds support for DRD CDNSP.
>> The patch 2: separates common code that can be reusable by cdnsp driver.
>> The patch 3: moves reusable code to separate module.
>> The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
>> The patch 5: adopts gadget_dev pointer in cdns structure to make possible
>>  use it in both drivers.
>> The patches 6-8: add the main part of driver and has been intentionally
>>  split into 3 part. In my opinion such division should not
>>  affect understanding and reviewing the driver, and cause that
>>  main patch (7/8) is little smaller. Patch 6 introduces main
>>  header file for driver, 7 is the main part that implements all
>>  functionality of driver and 8 introduces tracepoints.
>> The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
>> the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.
>>
>> Changlog from v1:
>> - updated common code to latest cdns3 driver
>> - moved cdnsp driver files to cdns3 as sugested by Peter Chan
>> - removed duplicate code from cdnsp_ep0_set_config function
>> - added cdns3 prefixes to file related with USBSS driver
>> - updated MAINTAINERS file
>> - fixed issue with U1
>> - fixed issue with L1
>> - some less improtant changes sugested by Chunfeng Yun
>
>After a quick review, I don't see anything wrong with this series, nice
>work.
>
>It does feel odd you need to split things into a "common" and then 2
>other modules, but I guess it makes sense.  Worst case, over time, you
>merge them back together after everyone just ends up enabling both of
>them :)
>
>Felipe, want me to take these directly, or should they go through your
>tree after you review them?  I never remember with this driver whose it
>goes through.
>

Thanks Greg for fast review. 
It could be good to take these from Peter Chen branch. 
Let's wait for Peter review and opinion.  

There are some changes that can have impact on existing cdns3 driver.

Regards,
Pawel



[PATCH v2 02/10] usb: cdns3: Split core.c into cdns3-plat and core.c file

2020-11-06 Thread Pawel Laszczak
Patch splits file core.c into core.c containing the common reusable code
and cnd3-plat.c containing device platform specific code. These changes
are required to make possible reuse DRD part of CDNS3 driver in CDNSP
driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile |   2 +-
 drivers/usb/cdns3/cdns3-plat.c | 311 +
 drivers/usb/cdns3/core.c   | 282 +++---
 drivers/usb/cdns3/core.h   |   6 +
 drivers/usb/cdns3/drd.c|   1 -
 drivers/usb/cdns3/drd.h|   1 -
 6 files changed, 341 insertions(+), 262 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdns3-plat.c

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index d47e341a6f39..a1fe9612053a 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -2,7 +2,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
 
-cdns3-y:= core.o drd.o
+cdns3-y:= cdns3-plat.o core.o drd.o
 
 obj-$(CONFIG_USB_CDNS3)+= cdns3.o
 cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
new file mode 100644
index ..b74882af3a9f
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -0,0 +1,311 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence USBSS DRD Driver.
+ *
+ * Copyright (C) 2018-2020 Cadence.
+ * Copyright (C) 2017-2018 NXP
+ * Copyright (C) 2019 Texas Instrumentsq
+ *
+ *
+ * Author: Peter Chen 
+ * Pawel Laszczak 
+ * Roger Quadros 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+
+static int set_phy_power_on(struct cdns3 *cdns)
+{
+   int ret;
+
+   ret = phy_power_on(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   ret = phy_power_on(cdns->usb3_phy);
+   if (ret)
+   phy_power_off(cdns->usb2_phy);
+
+   return ret;
+}
+
+static void set_phy_power_off(struct cdns3 *cdns)
+{
+   phy_power_off(cdns->usb3_phy);
+   phy_power_off(cdns->usb2_phy);
+}
+
+/**
+ * cdns3_plat_probe - probe for cdns3 core device
+ * @pdev: Pointer to cdns3 core platform device
+ *
+ * Returns 0 on success otherwise negative errno
+ */
+static int cdns3_plat_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;
+   cdns->pdata = dev_get_platdata(dev);
+
+   platform_set_drvdata(pdev, cdns);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "host");
+   if (!res) {
+   dev_err(dev, "missing host IRQ\n");
+   return -ENODEV;
+   }
+
+   cdns->xhci_res[0] = *res;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "xhci");
+   if (!res) {
+   dev_err(dev, "couldn't get xhci resource\n");
+   return -ENXIO;
+   }
+
+   cdns->xhci_res[1] = *res;
+
+   cdns->dev_irq = platform_get_irq_byname(pdev, "peripheral");
+
+   if (cdns->dev_irq < 0)
+   return cdns->dev_irq;
+
+   regs = devm_platform_ioremap_resource_byname(pdev, "dev");
+   if (IS_ERR(regs))
+   return PTR_ERR(regs);
+   cdns->dev_regs  = regs;
+
+   cdns->otg_irq = platform_get_irq_byname(pdev, "otg");
+   if (cdns->otg_irq < 0)
+   return cdns->otg_irq;
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "otg");
+   if (!res) {
+   dev_err(dev, "couldn't get otg resource\n");
+   return -ENXIO;
+   }
+
+   cdns->phyrst_a_enable = device_property_read_bool(dev, 
"cdns,phyrst-a-enable");
+
+   cdns->otg_res = *res;
+
+   cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+   if (cdns->wakeup_irq == -EPROBE_DEFER)
+   return cdns->wakeup_irq;
+   else if (cdns->wakeup_irq == 0)
+   return -EINVAL;
+
+   if (cdns->wakeup_irq < 0) {
+   dev_dbg(dev, "couldn't get wakeup irq\n");
+   cdns->wakeup_irq = 0x0;
+   }
+
+   cdns->usb2_phy = devm_phy_optional_get(dev, "cdns3,usb2-phy");
+   if (IS_ERR(cdns->usb2_phy))
+   return PTR_ERR(cdns->usb2_phy);
+
+   ret = phy_init(cdns->usb2_phy);
+   if (ret)
+   return ret;
+
+   cdns->usb3_phy = devm_phy_optional_get(dev, "cdns3,usb3-phy");
+  

[PATCH v2 10/10] MAINTAINERS: add Cadence USBSSP DRD IP driver entry

2020-11-06 Thread Pawel Laszczak
Patch adds entry for USBSSP (CDNSP) driver into MAINTARNERS file.

Signed-off-by: Pawel Laszczak 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f41d0e29b331..731150530d10 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3866,7 +3866,14 @@ L:   linux-...@vger.kernel.org
 S: Maintained
 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
 F: Documentation/devicetree/bindings/usb/cdns-usb3.txt
+X: drivers/usb/cdns3/cdnsp*
+
+CADENCE USBSSP DRD IP DRIVER
+M: Pawel Laszczak 
+L: linux-...@vger.kernel.org
+S: Maintained
 F: drivers/usb/cdns3/
+X: drivers/usb/cdns3/cdns3*
 
 CADET FM/AM RADIO RECEIVER DRIVER
 M: Hans Verkuil 
-- 
2.17.1



[PATCH v2 00/10] Introduced new Cadence USBSSP DRD Driver.

2020-11-06 Thread Pawel Laszczak
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 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.

The device side of USBSS DRD controller is compliant with XHCI.
The architecture for device side is almost the same as for host side,
and most of the XHCI specification can be used to understand how
this controller operates.

This controller and driver support Full Speed, Hight Speed, Supper Speed
and Supper Speed Plus USB protocol.

The prefix cdnsp used in driver has chosen by analogy to cdn3 driver.
The last letter of this acronym means PLUS. The formal name of controller
is USBSSP but it's to generic so I've decided to use CDNSP.

The patch 1: adds support for DRD CDNSP.
The patch 2: separates common code that can be reusable by cdnsp driver.
The patch 3: moves reusable code to separate module.
The patch 4: changes prefixes in reusable code from cdns3 to common cdns.
The patch 5: adopts gadget_dev pointer in cdns structure to make possible 
 use it in both drivers.
The patches 6-8: add the main part of driver and has been intentionally
 split into 3 part. In my opinion such division should not
 affect understanding and reviewing the driver, and cause that
 main patch (7/8) is little smaller. Patch 6 introduces main
 header file for driver, 7 is the main part that implements all
 functionality of driver and 8 introduces tracepoints.
The patch 9: Adds cdns3 prefixes to files related with USBSS driver.
the patch 10: Adds USBSSP DRD IP driver entry to MAINTAINERS file.

Changlog from v1:
- updated common code to latest cdns3 driver
- moved cdnsp driver files to cdns3 as sugested by Peter Chan
- removed duplicate code from cdnsp_ep0_set_config function
- added cdns3 prefixes to file related with USBSS driver
- updated MAINTAINERS file
- fixed issue with U1
- fixed issue with L1
- some less improtant changes sugested by Chunfeng Yun
---

Pawel Laszczak (10):
  usb: cdns3: Add support for DRD CDNSP
  usb: cdns3: Split core.c into cdns3-plat and core.c file
  usb: cdns3: Moves reusable code to separate module
  usb: cdns3: Refactoring names in reusable code
  usb: cdns3: Changed type of gadget_dev in cdns structure
  usb: cdnsp: Device side header file for CDNSP driver
  usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver
  usb: cdnsp: Add tracepoints for CDNSP driver
  usb: cdns3: Change file names for cdns3 driver.
  MAINTAINERS: add Cadence USBSSP DRD IP driver entry

 MAINTAINERS   |7 +
 drivers/usb/Makefile  |2 +
 drivers/usb/cdns3/Kconfig |   61 +-
 drivers/usb/cdns3/Makefile|   30 +-
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}  |0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}  |4 +-
 .../usb/cdns3/{gadget.c => cdns3-gadget.c}|   28 +-
 .../usb/cdns3/{gadget.h => cdns3-gadget.h}|0
 drivers/usb/cdns3/cdns3-imx.c |2 +-
 drivers/usb/cdns3/cdns3-plat.c|  314 +++
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}  |2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}  |6 +-
 drivers/usb/cdns3/cdnsp-debug.h   |  583 
 drivers/usb/cdns3/cdnsp-ep0.c |  496 
 drivers/usb/cdns3/cdnsp-gadget.c  | 2016 ++
 drivers/usb/cdns3/cdnsp-gadget.h  | 1602 +++
 drivers/usb/cdns3/cdnsp-mem.c | 1325 +
 drivers/usb/cdns3/cdnsp-pci.c |  255 ++
 drivers/usb/cdns3/cdnsp-ring.c| 2439 +
 drivers/usb/cdns3/cdnsp-trace.c   |   12 +
 drivers/usb/cdns3/cdnsp-trace.h   |  840 ++
 drivers/usb/cdns3/core.c  |  453 +--
 drivers/usb/cdns3/core.h  |   54 +-
 drivers/usb/cdns3/drd.c   |  223 +-
 drivers/usb/cdns3/drd.h   |   94 +-
 drivers/usb/cdns3/gadget-export.h |   22 +-
 drivers/usb/cdns3/host-export.h   |   12 +-
 drivers/usb/cdns3/host.c  |   22 +-
 28 files changed, 10398 insertions(+), 506 deletions(-)
 rename drivers/usb/cdns3/{debug.h => cdns3-debug.h} (100%)
 rename drivers/usb/cdns3/{ep0.c => cdns3-ep0.c} (99%)
 rename drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} (99%)
 rename drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} (100%)
 create mode 100644 drivers/usb/cdns3/cdns3-plat.c
 rename drivers/usb/cdns3/{trace.c => cdns3-trace.c} (89%)
 rename drivers/usb/cdns3/{trace.h => cdns

[PATCH v2 09/10] usb: cdns3: Change file names for cdns3 driver.

2020-11-06 Thread Pawel Laszczak
Patch adds prefix cdns3- to all file names related only to
cdsn3 driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile | 6 +++---
 drivers/usb/cdns3/{debug.h => cdns3-debug.h}   | 0
 drivers/usb/cdns3/{ep0.c => cdns3-ep0.c}   | 4 ++--
 drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} | 4 ++--
 drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} | 0
 drivers/usb/cdns3/{trace.c => cdns3-trace.c}   | 2 +-
 drivers/usb/cdns3/{trace.h => cdns3-trace.h}   | 6 +++---
 7 files changed, 11 insertions(+), 11 deletions(-)
 rename drivers/usb/cdns3/{debug.h => cdns3-debug.h} (100%)
 rename drivers/usb/cdns3/{ep0.c => cdns3-ep0.c} (99%)
 rename drivers/usb/cdns3/{gadget.c => cdns3-gadget.c} (99%)
 rename drivers/usb/cdns3/{gadget.h => cdns3-gadget.h} (100%)
 rename drivers/usb/cdns3/{trace.c => cdns3-trace.c} (89%)
 rename drivers/usb/cdns3/{trace.h => cdns3-trace.h} (99%)

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a4fdaabdbe18..01a9a9620044 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
-CFLAGS_trace.o := -I$(src)
+CFLAGS_cdns3-trace.o   := -I$(src)
 CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
@@ -10,10 +10,10 @@ obj-$(CONFIG_USB_CDNS3) += 
cdns3.o
 obj-$(CONFIG_USB_CDNS_SUPPORT) += cdns-usb-common.o
 
 cdns-usb-common-$(CONFIG_USB_CDNS_HOST)+= host.o
-cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o ep0.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)   += cdns3-gadget.o cdns3-ep0.o
 
 ifneq ($(CONFIG_USB_CDNS3_GADGET),)
-cdns3-$(CONFIG_TRACING)+= trace.o
+cdns3-$(CONFIG_TRACING)+= cdns3-trace.o
 endif
 
 obj-$(CONFIG_USB_CDNS3_PCI_WRAP)   += cdns3-pci-wrap.o
diff --git a/drivers/usb/cdns3/debug.h b/drivers/usb/cdns3/cdns3-debug.h
similarity index 100%
rename from drivers/usb/cdns3/debug.h
rename to drivers/usb/cdns3/cdns3-debug.h
diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/cdns3-ep0.c
similarity index 99%
rename from drivers/usb/cdns3/ep0.c
rename to drivers/usb/cdns3/cdns3-ep0.c
index d3121a32cc68..b0390fe9a396 100644
--- a/drivers/usb/cdns3/ep0.c
+++ b/drivers/usb/cdns3/cdns3-ep0.c
@@ -13,8 +13,8 @@
 #include 
 #include 
 
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 
 static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
similarity index 99%
rename from drivers/usb/cdns3/gadget.c
rename to drivers/usb/cdns3/cdns3-gadget.c
index 9e0a82063873..d507a23c7047 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -63,8 +63,8 @@
 
 #include "core.h"
 #include "gadget-export.h"
-#include "gadget.h"
-#include "trace.h"
+#include "cdns3-gadget.h"
+#include "cdns3-trace.h"
 #include "drd.h"
 
 static int __cdns3_gadget_ep_queue(struct usb_ep *ep,
diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/cdns3-gadget.h
similarity index 100%
rename from drivers/usb/cdns3/gadget.h
rename to drivers/usb/cdns3/cdns3-gadget.h
diff --git a/drivers/usb/cdns3/trace.c b/drivers/usb/cdns3/cdns3-trace.c
similarity index 89%
rename from drivers/usb/cdns3/trace.c
rename to drivers/usb/cdns3/cdns3-trace.c
index 459fa72d9c74..b9858acaef02 100644
--- a/drivers/usb/cdns3/trace.c
+++ b/drivers/usb/cdns3/cdns3-trace.c
@@ -8,4 +8,4 @@
  */
 
 #define CREATE_TRACE_POINTS
-#include "trace.h"
+#include "cdns3-trace.h"
diff --git a/drivers/usb/cdns3/trace.h b/drivers/usb/cdns3/cdns3-trace.h
similarity index 99%
rename from drivers/usb/cdns3/trace.h
rename to drivers/usb/cdns3/cdns3-trace.h
index 0a2a3269bfac..8648c7a7a9dd 100644
--- a/drivers/usb/cdns3/trace.h
+++ b/drivers/usb/cdns3/cdns3-trace.h
@@ -19,8 +19,8 @@
 #include 
 #include 
 #include "core.h"
-#include "gadget.h"
-#include "debug.h"
+#include "cdns3-gadget.h"
+#include "cdns3-debug.h"
 
 #define CDNS3_MSG_MAX  500
 
@@ -565,6 +565,6 @@ DEFINE_EVENT(cdns3_log_request_handled, 
cdns3_request_handled,
 #define TRACE_INCLUDE_PATH .
 
 #undef TRACE_INCLUDE_FILE
-#define TRACE_INCLUDE_FILE trace
+#define TRACE_INCLUDE_FILE cdns3-trace
 
 #include 
-- 
2.17.1



[PATCH v2 01/10] usb: cdns3: Add support for DRD CDNSP

2020-11-06 Thread Pawel Laszczak
Patch adds support for Cadence DRD Super Speed Plus controller(CDNSP).
CDNSP DRD is a part of Cadence CDNSP controller.
The DRD CDNSP controller has a lot of difference on hardware level but on
software level is quite compatible with CDNS3 DRD. For this reason
CDNS3 DRD part of CDNS3 driver was reused for CDNSP driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.c |  24 +++---
 drivers/usb/cdns3/core.h |   5 ++
 drivers/usb/cdns3/drd.c  | 101 +++
 drivers/usb/cdns3/drd.h  |  67 +-
 4 files changed, 148 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index f2dedce3a40e..58a3cb0e2a5d 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -97,13 +97,23 @@ static int cdns3_core_init_role(struct cdns3 *cdns)
 * can be restricted later depending on strap pin configuration.
 */
if (dr_mode == USB_DR_MODE_UNKNOWN) {
-   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
-   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_OTG;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
-   dr_mode = USB_DR_MODE_HOST;
-   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
-   dr_mode = USB_DR_MODE_PERIPHERAL;
+   if (cdns->version == CDNSP_CONTROLLER_V2) {
+   if (IS_ENABLED(CONFIG_USB_CDNSP_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNSP_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   } else {
+   if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) &&
+   IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_OTG;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST))
+   dr_mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET))
+   dr_mode = USB_DR_MODE_PERIPHERAL;
+   }
}
 
/*
diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index 8a40d53d5ede..3af8eb7ca844 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -53,7 +53,9 @@ struct cdns3_platform_data {
  * @otg_res: the resource for otg
  * @otg_v0_regs: pointer to base of v0 otg registers
  * @otg_v1_regs: pointer to base of v1 otg registers
+ * @otg_cdnsp_regs: pointer to base of CDNSP otg registers
  * @otg_regs: pointer to base of otg registers
+ * @otg_irq_regs: pointer to interrupt registers
  * @otg_irq: irq number for otg controller
  * @dev_irq: irq number for device controller
  * @wakeup_irq: irq number for wakeup event, it is optional
@@ -83,9 +85,12 @@ struct cdns3 {
struct resource otg_res;
struct cdns3_otg_legacy_regs*otg_v0_regs;
struct cdns3_otg_regs   *otg_v1_regs;
+   struct cdnsp_otg_regs   *otg_cdnsp_regs;
struct cdns3_otg_common_regs*otg_regs;
+   struct cdns3_otg_irq_regs   *otg_irq_regs;
 #define CDNS3_CONTROLLER_V00
 #define CDNS3_CONTROLLER_V11
+#define CDNSP_CONTROLLER_V22
u32 version;
boolphyrst_a_enable;
 
diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c
index 38ccd29e4cde..95863d44e3e0 100644
--- a/drivers/usb/cdns3/drd.c
+++ b/drivers/usb/cdns3/drd.c
@@ -2,13 +2,12 @@
 /*
  * Cadence USBSS DRD Driver.
  *
- * Copyright (C) 2018-2019 Cadence.
+ * Copyright (C) 2018-2020 Cadence.
  * Copyright (C) 2019 Texas Instruments
  *
  * Author: Pawel Laszczak 
  * Roger Quadros 
  *
- *
  */
 #include 
 #include 
@@ -28,8 +27,9 @@
  *
  * Returns 0 on success otherwise negative errno
  */
-int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
+static int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode)
 {
+   u32 __iomem *override_reg;
u32 reg;
 
switch (mode) {
@@ -39,11 +39,24 @@ int cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode 
mode)
break;
case USB_DR_MODE_OTG:
dev_dbg(cdns->dev, "Set controller to OTG mode\n");
-   if (cdns->version == CDNS3_CONTROLLER_V1) {
-   reg = readl(>otg_v1_regs->override);
+
+   if (cdns->version == CDNSP_CONTROLLER_V2)
+   override_reg = >otg_cdnsp_regs->override;
+   else if (cdns->version == CDNS3_CONTROLLER_V1)
+ 

[PATCH v2 08/10] usb: cdnsp: Add tracepoints for CDNSP driver

2020-11-06 Thread Pawel Laszczak
Patch adds the series of tracepoints that can be used for
debugging issues detected in driver.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/Makefile   |   5 +
 drivers/usb/cdns3/cdnsp-debug.h  | 583 +
 drivers/usb/cdns3/cdnsp-ep0.c|  22 +-
 drivers/usb/cdns3/cdnsp-gadget.c |  75 ++-
 drivers/usb/cdns3/cdnsp-mem.c|  18 +-
 drivers/usb/cdns3/cdnsp-ring.c   |  75 ++-
 drivers/usb/cdns3/cdnsp-trace.c  |  12 +
 drivers/usb/cdns3/cdnsp-trace.h  | 840 +++
 8 files changed, 1614 insertions(+), 16 deletions(-)
 create mode 100644 drivers/usb/cdns3/cdnsp-debug.h
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.c
 create mode 100644 drivers/usb/cdns3/cdnsp-trace.h

diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index a84b129f14b8..a4fdaabdbe18 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o := -I$(src)
+CFLAGS_cdnsp-trace.o   := -I$(src)
 
 cdns-usb-common-y  := core.o drd.o
 cdns3-y:= cdns3-plat.o
@@ -23,3 +24,7 @@ cdnsp-udc-pci-y   := 
cdnsp-pci.o
 obj-$(CONFIG_USB_CDNSP_PCI)+= cdnsp-udc-pci.o
 cdnsp-udc-pci-$(CONFIG_USB_CDNSP_GADGET)   += cdnsp-ring.o cdnsp-gadget.o \
   cdnsp-mem.o cdnsp-ep0.o
+
+ifneq ($(CONFIG_USB_CDNSP_GADGET),)
+cdnsp-udc-pci-$(CONFIG_TRACING)+= cdnsp-trace.o
+endif
diff --git a/drivers/usb/cdns3/cdnsp-debug.h b/drivers/usb/cdns3/cdnsp-debug.h
new file mode 100644
index ..d6345d4d2911
--- /dev/null
+++ b/drivers/usb/cdns3/cdnsp-debug.h
@@ -0,0 +1,583 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cadence CDNSP DRD Driver.
+ *
+ * Copyright (C) 2020 Cadence.
+ *
+ * Author: Pawel Laszczak 
+ *
+ */
+#ifndef __LINUX_CDNSP_DEBUG
+#define __LINUX_CDNSP_DEBUG
+
+static inline const char *cdnsp_trb_comp_code_string(u8 status)
+{
+   switch (status) {
+   case COMP_INVALID:
+   return "Invalid";
+   case COMP_SUCCESS:
+   return "Success";
+   case COMP_DATA_BUFFER_ERROR:
+   return "Data Buffer Error";
+   case COMP_BABBLE_DETECTED_ERROR:
+   return "Babble Detected";
+   case COMP_TRB_ERROR:
+   return "TRB Error";
+   case COMP_RESOURCE_ERROR:
+   return "Resource Error";
+   case COMP_NO_SLOTS_AVAILABLE_ERROR:
+   return "No Slots Available Error";
+   case COMP_INVALID_STREAM_TYPE_ERROR:
+   return "Invalid Stream Type Error";
+   case COMP_SLOT_NOT_ENABLED_ERROR:
+   return "Slot Not Enabled Error";
+   case COMP_ENDPOINT_NOT_ENABLED_ERROR:
+   return "Endpoint Not Enabled Error";
+   case COMP_SHORT_PACKET:
+   return "Short Packet";
+   case COMP_RING_UNDERRUN:
+   return "Ring Underrun";
+   case COMP_RING_OVERRUN:
+   return "Ring Overrun";
+   case COMP_VF_EVENT_RING_FULL_ERROR:
+   return "VF Event Ring Full Error";
+   case COMP_PARAMETER_ERROR:
+   return "Parameter Error";
+   case COMP_CONTEXT_STATE_ERROR:
+   return "Context State Error";
+   case COMP_EVENT_RING_FULL_ERROR:
+   return "Event Ring Full Error";
+   case COMP_INCOMPATIBLE_DEVICE_ERROR:
+   return "Incompatible Device Error";
+   case COMP_MISSED_SERVICE_ERROR:
+   return "Missed Service Error";
+   case COMP_COMMAND_RING_STOPPED:
+   return "Command Ring Stopped";
+   case COMP_COMMAND_ABORTED:
+   return "Command Aborted";
+   case COMP_STOPPED:
+   return "Stopped";
+   case COMP_STOPPED_LENGTH_INVALID:
+   return "Stopped - Length Invalid";
+   case COMP_STOPPED_SHORT_PACKET:
+   return "Stopped - Short Packet";
+   case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR:
+   return "Max Exit Latency Too Large Error";
+   case COMP_ISOCH_BUFFER_OVERRUN:
+   return "Isoch Buffer Overrun";
+   case COMP_EVENT_LOST_ERROR:
+   return "Event Lost Error";
+   case COMP_UNDEFINED_ERROR:
+   return "Undefined Error";
+   case COMP_INVALID_STREAM_ID_ERROR:
+   return "Invalid Stream ID Error";
+   default:
+   return "Unknown!!";
+  

[PATCH v2 04/10] usb: cdns3: Refactoring names in reusable code

2020-11-06 Thread Pawel Laszczak
Patch change the functions and objects names in reusable code.
The reusable code includes core.c, core.h, drd.c and drd.h files.
It also changes the names of all references to these functions and
objects in other cdns3 files. There are a lot of changes, but all
changes are very trivial.
The reason of this patch is to avoid of mixing prefix cdns3 and cdnsp in
in cdnsp driver what could introduce some confusion in understanding
of cdnsp driver.
This patch assumes to use three different prefixes in Cadence
USB drivers:
  cdns: for common reusable code
  cdnsp: for names related only with cdnsp driver
  cdns3: for names related only with cdns3 driver

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/cdns3-imx.c |   2 +-
 drivers/usb/cdns3/cdns3-plat.c|  25 +++---
 drivers/usb/cdns3/core.c  | 142 +++---
 drivers/usb/cdns3/core.h  |  46 +-
 drivers/usb/cdns3/drd.c   | 100 ++---
 drivers/usb/cdns3/drd.h   |  26 +++---
 drivers/usb/cdns3/gadget-export.h |   4 +-
 drivers/usb/cdns3/gadget.c|  24 ++---
 drivers/usb/cdns3/host-export.h   |   6 +-
 drivers/usb/cdns3/host.c  |  22 ++---
 10 files changed, 199 insertions(+), 198 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-imx.c b/drivers/usb/cdns3/cdns3-imx.c
index 54a2d70a9c73..366e88f068ef 100644
--- a/drivers/usb/cdns3/cdns3-imx.c
+++ b/drivers/usb/cdns3/cdns3-imx.c
@@ -250,7 +250,7 @@ static void cdns3_set_wakeup(struct cdns_imx *data, bool 
enable)
 static int cdns_imx_platform_suspend(struct device *dev,
bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
struct device *parent = dev->parent;
struct cdns_imx *data = dev_get_drvdata(parent);
void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs);
diff --git a/drivers/usb/cdns3/cdns3-plat.c b/drivers/usb/cdns3/cdns3-plat.c
index 562163c81911..99b5dae4a80c 100644
--- a/drivers/usb/cdns3/cdns3-plat.c
+++ b/drivers/usb/cdns3/cdns3-plat.c
@@ -20,7 +20,7 @@
 #include "core.h"
 #include "gadget-export.h"
 
-static int set_phy_power_on(struct cdns3 *cdns)
+static int set_phy_power_on(struct cdns *cdns)
 {
int ret;
 
@@ -35,7 +35,7 @@ static int set_phy_power_on(struct cdns3 *cdns)
return ret;
 }
 
-static void set_phy_power_off(struct cdns3 *cdns)
+static void set_phy_power_off(struct cdns *cdns)
 {
phy_power_off(cdns->usb3_phy);
phy_power_off(cdns->usb2_phy);
@@ -51,7 +51,7 @@ static int cdns3_plat_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
struct resource *res;
-   struct cdns3 *cdns;
+   struct cdns *cdns;
void __iomem *regs;
int ret;
 
@@ -136,7 +136,8 @@ static int cdns3_plat_probe(struct platform_device *pdev)
goto err_phy_power_on;
 
cdns->gadget_init = cdns3_gadget_init;
-   ret = cdns3_init(cdns);
+
+   ret = cdns_init(cdns);
if (ret)
goto err_cdns_init;
 
@@ -174,13 +175,13 @@ static int cdns3_plat_probe(struct platform_device *pdev)
  */
 static int cdns3_plat_remove(struct platform_device *pdev)
 {
-   struct cdns3 *cdns = platform_get_drvdata(pdev);
+   struct cdns *cdns = platform_get_drvdata(pdev);
struct device *dev = cdns->dev;
 
pm_runtime_get_sync(dev);
pm_runtime_disable(dev);
pm_runtime_put_noidle(dev);
-   cdns3_remove(cdns);
+   cdns_remove(cdns);
set_phy_power_off(cdns);
phy_exit(cdns->usb2_phy);
phy_exit(cdns->usb3_phy);
@@ -192,7 +193,7 @@ static int cdns3_plat_remove(struct platform_device *pdev)
 static int cdns3_set_platform_suspend(struct device *dev,
  bool suspend, bool wakeup)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret = 0;
 
if (cdns->pdata && cdns->pdata->platform_suspend)
@@ -203,7 +204,7 @@ static int cdns3_set_platform_suspend(struct device *dev,
 
 static int cdns3_controller_suspend(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
bool wakeup;
unsigned long flags;
 
@@ -227,7 +228,7 @@ static int cdns3_controller_suspend(struct device *dev, 
pm_message_t msg)
 
 static int cdns3_controller_resume(struct device *dev, pm_message_t msg)
 {
-   struct cdns3 *cdns = dev_get_drvdata(dev);
+   struct cdns *cdns = dev_get_drvdata(dev);
int ret;
unsigned long flags;
 
@@ -241,7 +242,7 @@ static int cdns3_controller_resume(struct device *dev, 
pm_message_t msg)
cdns3_set_platform_suspend(cdns->dev, false, false);
 
spin_lock_irqsave(>lock, flags);
-   cdns3_resume(cdns, !PMSG_IS_AUTO(msg));
+

[PATCH v2 05/10] usb: cdns3: Changed type of gadget_dev in cdns structure

2020-11-06 Thread Pawel Laszczak
Patch changes the type for gadget_dev pointer in cdns structure from
pointer to cdns3_device structure to void pointer.
This filed is in reusable code and after this change it will be used to
point to both cdns3_device or cdnsp_device objects.

Signed-off-by: Pawel Laszczak 
---
 drivers/usb/cdns3/core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h
index 2dc4bb1c6b6d..055bb89f54ca 100644
--- a/drivers/usb/cdns3/core.h
+++ b/drivers/usb/cdns3/core.h
@@ -62,7 +62,7 @@ struct cdns3_platform_data {
  * @roles: array of supported roles for this controller
  * @role: current role
  * @host_dev: the child host device pointer for cdns core
- * @gadget_dev: the child gadget device pointer for cdns3 core
+ * @gadget_dev: the child gadget device pointer
  * @usb2_phy: pointer to USB2 PHY
  * @usb3_phy: pointer to USB3 PHY
  * @mutex: the mutex for concurrent code at driver
@@ -101,7 +101,7 @@ struct cdns {
struct cdns_role_driver *roles[USB_ROLE_DEVICE + 1];
enum usb_role   role;
struct platform_device  *host_dev;
-   struct cdns3_device *gadget_dev;
+   void*gadget_dev;
struct phy  *usb2_phy;
struct phy  *usb3_phy;
/* mutext used in workqueue*/
-- 
2.17.1



  1   2   3   4   >