Skip to contentSkip to conversation

usb: cdns3: bug-fixes for usb-linus

PATCH In review Peter Chen 2 participants 9 messages Jun 23, 2020

Subsystems (4)
lore
Share & tools
lore

Peter Chen

author
#0 lore raw

cover usb: cdns3: bug-fixes for usb-linus

Peter Chen (3):
usb: cdns3: ep0: fix the test mode set incorrectly
usb: cdns3: trace: using correct dir value
usb: cdns3: ep0: add spinlock for cdns3_check_new_setup

 drivers/usb/cdns3/ep0.c   | 10 ++++++----
 drivers/usb/cdns3/trace.h |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 usb: cdns3: ep0: fix the test mode set incorrectly

The 'tmode' is ctrl->wIndex, changing it as the real test mode value for register assignment.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
 drivers/usb/cdns3/ep0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/cdns3/ep0.c +2 -1
index 2465a84e8fee..74a1ff5000ba 100644
@@ -327,7 +327,8 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
 		if (!set || (tmode & 0xff) != 0)
 			return -EINVAL;
 
-		switch (tmode >> 8) {
+		tmode >>= 8;
+		switch (tmode) {
 		case TEST_J:
 		case TEST_K:
 		case TEST_SE0_NAK:
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/3
#2 lore raw

RE: [PATCH 1/3] usb: cdns3: ep0: fix the test mode set incorrectly

Hi,

Quoted 18 lines

The 'tmode' is ctrl->wIndex, changing it as the real test mode value for register assignment.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")

---
drivers/usb/cdns3/ep0.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/cdns3/ep0.c +0 -0
index 2465a84e8fee..74a1ff5000ba 100644

drivers/usb/cdns3/ep0.c static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, · line 331

Quoted 6 lines
drivers/usb/cdns3/ep0.c +2 -1
@@ -327,7 +327,8 @@ static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev,
 		if (!set || (tmode & 0xff) != 0)
 			return -EINVAL;
 
-		switch (tmode >> 8) {
+		tmode >>= 8;
+		switch (tmode) {

For me it's looks the same, but it's ok.

Quoted 5 lines
drivers/usb/cdns3/ep0.c +0 -1
 		case TEST_J:
 		case TEST_K:
 		case TEST_SE0_NAK:
--

2.17.1

author
#3 lore raw

RE: [PATCH 1/3] usb: cdns3: ep0: fix the test mode set incorrectly

Quoted 7 lines

drivers/usb/cdns3/ep0.c static int cdns3_ep0_feature_handle_device(struct

Quoted 6 lines
drivers/usb/cdns3/ep0.c index renamed from drivers/usb/cdns3/ep0.c +0 -0

2465a84e8fee..74a1ff5000ba 100644

drivers/usb/cdns3/ep0.c +0 -0
@@ -327,7 +327,8 @@ static int cdns3_ep0_feature_handle_device(struct

cdns3_device *priv_dev,

Quoted 9 lines

drivers/usb/cdns3/ep0.c static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, · line 331

Quoted 6 lines
drivers/usb/cdns3/ep0.c +2 -1
 		if (!set || (tmode & 0xff) != 0)
 			return -EINVAL;
 
-		switch (tmode >> 8) {
+		tmode >>= 8;
+		switch (tmode) {

For me it's looks the same, but it's ok.

Pawel, please check the coming code, it uses tmode to set the register which is incorrect before shift. (line 336)

328                 tmode >>= 8;
329                 switch (tmode) {
330                 case TEST_J:
331                 case TEST_K:
332                 case TEST_SE0_NAK:
333                 case TEST_PACKET:

334 cdns3_set_register_bit(&priv_dev->regs->usb_cmd,
335 USB_CMD_STMODE |
336 USB_STS_TMODE_SEL(tmode - 1));
337 break;

Peter

maintainer
#4 lore raw

RE: [PATCH 1/3] usb: cdns3: ep0: fix the test mode set incorrectly

Quoted 17 lines
Quoted 7 lines

drivers/usb/cdns3/ep0.c static int cdns3_ep0_feature_handle_device(struct

Quoted 6 lines
drivers/usb/cdns3/ep0.c index renamed from drivers/usb/cdns3/ep0.c +0 -0

2465a84e8fee..74a1ff5000ba 100644

drivers/usb/cdns3/ep0.c +0 -0
@@ -327,7 +327,8 @@ static int cdns3_ep0_feature_handle_device(struct

cdns3_device *priv_dev,

Quoted 9 lines

drivers/usb/cdns3/ep0.c static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, · line 331

Quoted 6 lines
drivers/usb/cdns3/ep0.c +2 -1
 		if (!set || (tmode & 0xff) != 0)
 			return -EINVAL;
 
-		switch (tmode >> 8) {
+		tmode >>= 8;
+		switch (tmode) {

For me it's looks the same, but it's ok.

Quoted 2 lines

Pawel, please check the coming code, it uses tmode to set the register which is incorrect before shift. (line 336)

Rigth, thanks for clarification.

Quoted 13 lines
328                 tmode >>= 8;
329                 switch (tmode) {
330                 case TEST_J:
331                 case TEST_K:
332                 case TEST_SE0_NAK:
333                 case TEST_PACKET:

334 cdns3_set_register_bit(&priv_dev->regs->usb_cmd,
335 USB_CMD_STMODE |
336 USB_STS_TMODE_SEL(tmode - 1));
337 break;

Peter

author
#5 lore raw

PATCH 2/3 usb: cdns3: trace: using correct dir value

In reply to Peter Chen

It should use the correct direction value from register, not depends on previous software setting. It fixed the EP number wrong issue at trace when the TRBERR interrupt occurs for EP0IN.

When the EP0IN IOC has finished, software prepares the setup packet request, the expected direction is OUT, but at that time, the TRBERR for EP0IN may occur since it is DMULT mode, the DMA does not stop until TRBERR has met.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
 drivers/usb/cdns3/trace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/cdns3/trace.h +1 -1
index de2c34d5bfc5..0a2a3269bfac 100644
@@ -156,7 +156,7 @@ DECLARE_EVENT_CLASS(cdns3_log_ep0_irq,
 		__dynamic_array(char, str, CDNS3_MSG_MAX)
 	),
 	TP_fast_assign(
-		__entry->ep_dir = priv_dev->ep0_data_dir;
+		__entry->ep_dir = priv_dev->selected_ep;
 		__entry->ep_sts = ep_sts;
 	),
 	TP_printk("%s", cdns3_decode_ep0_irq(__get_str(str),
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 2/3
#6 lore raw

RE: [PATCH 2/3] usb: cdns3: trace: using correct dir value

Quoted 6 lines

It should use the correct direction value from register, not depends on previous software setting. It fixed the EP number wrong issue at trace when the TRBERR interrupt occurs for EP0IN.

Quoted 8 lines

When the EP0IN IOC has finished, software prepares the setup packet request, the expected direction is OUT, but at that time, the TRBERR for EP0IN may occur since it is DMULT mode, the DMA does not stop until TRBERR has met.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
Quoted 19 lines

---
drivers/usb/cdns3/trace.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/cdns3/trace.h +1 -2
index de2c34d5bfc5..0a2a3269bfac 100644
@@ -156,7 +156,7 @@ DECLARE_EVENT_CLASS(cdns3_log_ep0_irq,
 		__dynamic_array(char, str, CDNS3_MSG_MAX)
 	),
 	TP_fast_assign(
-		__entry->ep_dir = priv_dev->ep0_data_dir;
+		__entry->ep_dir = priv_dev->selected_ep;
 		__entry->ep_sts = ep_sts;
 	),
 	TP_printk("%s", cdns3_decode_ep0_irq(__get_str(str),
--

2.17.1

author
#7 lore raw

PATCH 3/3 usb: cdns3: ep0: add spinlock for cdns3_check_new_setup

In reply to Peter Chen

The other thread may access other endpoints when the cdns3_check_new_setup is handling, add spinlock to protect it.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
---
 drivers/usb/cdns3/ep0.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/cdns3/ep0.c +4 -3
index 74a1ff5000ba..5aa69980e7ff 100644
@@ -705,15 +705,17 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
 	int ret = 0;
 	u8 zlp = 0;
 
+	spin_lock_irqsave(&priv_dev->lock, flags);
 	trace_cdns3_ep0_queue(priv_dev, request);
 
 	/* cancel the request if controller receive new SETUP packet. */
-	if (cdns3_check_new_setup(priv_dev))
+	if (cdns3_check_new_setup(priv_dev)) {
+		spin_unlock_irqrestore(&priv_dev->lock, flags);
 		return -ECONNRESET;
+	}
 
 	/* send STATUS stage. Should be called only for SET_CONFIGURATION */
 	if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) {
-		spin_lock_irqsave(&priv_dev->lock, flags);
 		cdns3_select_ep(priv_dev, 0x00);
 
 		erdy_sent = !priv_dev->hw_configured_flag;
@@ -738,7 +740,6 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
 		return 0;
 	}
 
-	spin_lock_irqsave(&priv_dev->lock, flags);
 	if (!list_empty(&priv_ep->pending_req_list)) {
 		dev_err(priv_dev->dev,
 			"can't handle multiple requests for ep0\n");
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 3/3
#8 lore raw

RE: [PATCH 3/3] usb: cdns3: ep0: add spinlock for cdns3_check_new_setup

Quoted 7 lines

The other thread may access other endpoints when the cdns3_check_new_setup is handling, add spinlock to protect it.

Fixes 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
Quoted 38 lines

---
drivers/usb/cdns3/ep0.c | 7 ++++---

1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/cdns3/ep0.c +4 -4
index 74a1ff5000ba..5aa69980e7ff 100644
@@ -705,15 +705,17 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
 	int ret = 0;
 	u8 zlp = 0;
 
+	spin_lock_irqsave(&priv_dev->lock, flags);
 	trace_cdns3_ep0_queue(priv_dev, request);
 
 	/* cancel the request if controller receive new SETUP packet. */
-	if (cdns3_check_new_setup(priv_dev))
+	if (cdns3_check_new_setup(priv_dev)) {
+		spin_unlock_irqrestore(&priv_dev->lock, flags);
 		return -ECONNRESET;
+	}
 
 	/* send STATUS stage. Should be called only for SET_CONFIGURATION */
 	if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) {
-		spin_lock_irqsave(&priv_dev->lock, flags);
 		cdns3_select_ep(priv_dev, 0x00);
 
 		erdy_sent = !priv_dev->hw_configured_flag;
@@ -738,7 +740,6 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep,
 		return 0;
 	}
 
-	spin_lock_irqsave(&priv_dev->lock, flags);
 	if (!list_empty(&priv_ep->pending_req_list)) {
 		dev_err(priv_dev->dev,
 			"can't handle multiple requests for ep0\n");
--

2.17.1