linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Fix the fotg210-udc driver
@ 2021-03-24 14:11 Fabian Vogt
  2021-03-24 14:11 ` [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size Fabian Vogt
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

Moin!

USB is the main way of communicating with the TI Nspire CX II calculators,
so supporting the controller in Linux is necessary to make the port
somewhat useful. While implementing support for the specific controller
model inside, I found and fixed various bugs in this driver. Most of them
are part of the original driver code already and are so severe, that I
seriously wonder whether anyone actually used this driver ever.

With this series applied and some CX II specific commits on top, the
driver works fine for both USB serial and ethernet here.

The CX II support patches build upon this series, to avoid bigger
reiterations I'll submit them once this series got some positive feedback.

Cheers,
Fabian

To: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Yuan-Hsin Chen <yhchen@faraday-tech.com>
CC: linux-usb@vger.kernel.org

Fabian Vogt (7):
  fotg210-udc: Fix DMA on EP0 for length > max packet size
  fotg210-udc: Fix EP0 IN requests bigger than two packets
  fotg210-udc: Remove a dubious condition leading to fotg210_done
  fotg210-udc: Mask GRP2 interrupts we don't handle
  fotg210-udc: Call usb_gadget_udc_reset
  fotg210-udc: Don't DMA more than the buffer can take
  fotg210-udc: Complete OUT requests on short packets

 drivers/usb/gadget/udc/fotg210-udc.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 2/7] fotg210-udc: Fix EP0 IN requests bigger than two packets Fabian Vogt
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

For a 75 Byte request, it would send the first 64 separately, then detect
that the remaining 11 Byte fit into a single DMA, but due to this bug set
the length to the original 75 Bytes. This leads to a DMA failure (which is
ignored...) and the request completes without the remaining bytes having
been sent.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 596fe26a7c56..482d867ac96f 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -346,7 +346,7 @@ static void fotg210_start_dma(struct fotg210_ep *ep,
 		if (req->req.length - req->req.actual > ep->ep.maxpacket)
 			length = ep->ep.maxpacket;
 		else
-			length = req->req.length;
+			length = req->req.length - req->req.actual;
 	}
 
 	d = dma_map_single(dev, buffer, length,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/7] fotg210-udc: Fix EP0 IN requests bigger than two packets
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
  2021-03-24 14:11 ` [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 3/7] fotg210-udc: Remove a dubious condition leading to fotg210_done Fabian Vogt
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

For a 134 Byte packet, it sends the first two 64 Byte packets just fine,
but then notice that less than a packet is remaining and call fotg210_done
without actually sending the rest.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 482d867ac96f..539808f62e2e 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -834,7 +834,7 @@ static void fotg210_ep0in(struct fotg210_udc *fotg210)
 		if (req->req.length)
 			fotg210_start_dma(ep, req);
 
-		if ((req->req.length - req->req.actual) < ep->ep.maxpacket)
+		if (req->req.actual == req->req.length)
 			fotg210_done(ep, req, 0);
 	} else {
 		fotg210_set_cxdone(fotg210);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/7] fotg210-udc: Remove a dubious condition leading to fotg210_done
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
  2021-03-24 14:11 ` [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size Fabian Vogt
  2021-03-24 14:11 ` [PATCH 2/7] fotg210-udc: Fix EP0 IN requests bigger than two packets Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 4/7] fotg210-udc: Mask GRP2 interrupts we don't handle Fabian Vogt
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

When the EP0 IN request was not completed but less than a packet sent,
it would complete the request successfully. That doesn't make sense
and can't really happen as fotg210_start_dma always sends
min(length, maxpkt) bytes.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 539808f62e2e..911f1a5cd1f4 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -379,8 +379,7 @@ static void fotg210_ep0_queue(struct fotg210_ep *ep,
 	}
 	if (ep->dir_in) { /* if IN */
 		fotg210_start_dma(ep, req);
-		if ((req->req.length == req->req.actual) ||
-		    (req->req.actual < ep->ep.maxpacket))
+		if (req->req.length == req->req.actual)
 			fotg210_done(ep, req, 0);
 	} else { /* OUT */
 		u32 value = ioread32(ep->fotg210->reg + FOTG210_DMISGR0);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/7] fotg210-udc: Mask GRP2 interrupts we don't handle
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
                   ` (2 preceding siblings ...)
  2021-03-24 14:11 ` [PATCH 3/7] fotg210-udc: Remove a dubious condition leading to fotg210_done Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 5/7] fotg210-udc: Call usb_gadget_udc_reset Fabian Vogt
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

Currently it leaves unhandled interrupts unmasked, but those are never
acked. In the case of a "device idle" interrupt, this leads to an
effectively frozen system until plugging it in.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 911f1a5cd1f4..d7693b8d7c54 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -1040,6 +1040,12 @@ static void fotg210_init(struct fotg210_udc *fotg210)
 	value &= ~DMCR_GLINT_EN;
 	iowrite32(value, fotg210->reg + FOTG210_DMCR);
 
+	/* enable only grp2 irqs we handle */
+	iowrite32(~(DISGR2_DMA_ERROR | DISGR2_RX0BYTE_INT | DISGR2_TX0BYTE_INT
+		    | DISGR2_ISO_SEQ_ABORT_INT | DISGR2_ISO_SEQ_ERR_INT
+		    | DISGR2_RESM_INT | DISGR2_SUSP_INT | DISGR2_USBRST_INT),
+		  fotg210->reg + FOTG210_DMISGR2);
+
 	/* disable all fifo interrupt */
 	iowrite32(~(u32)0, fotg210->reg + FOTG210_DMISGR1);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/7] fotg210-udc: Call usb_gadget_udc_reset
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
                   ` (3 preceding siblings ...)
  2021-03-24 14:11 ` [PATCH 4/7] fotg210-udc: Mask GRP2 interrupts we don't handle Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 6/7] fotg210-udc: Don't DMA more than the buffer can take Fabian Vogt
  2021-03-24 14:11 ` [PATCH 7/7] fotg210-udc: Complete OUT requests on short packets Fabian Vogt
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

Notify the UDC core that a bus reset occurred.

Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index d7693b8d7c54..6a4c60d5b2c2 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -890,6 +890,8 @@ static irqreturn_t fotg210_irq(int irq, void *_fotg210)
 		int_grp2 &= ~int_msk2;
 
 		if (int_grp2 & DISGR2_USBRST_INT) {
+			usb_gadget_udc_reset(&fotg210->gadget,
+					     fotg210->driver);
 			value = ioread32(reg);
 			value &= ~DISGR2_USBRST_INT;
 			iowrite32(value, reg);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/7] fotg210-udc: Don't DMA more than the buffer can take
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
                   ` (4 preceding siblings ...)
  2021-03-24 14:11 ` [PATCH 5/7] fotg210-udc: Call usb_gadget_udc_reset Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  2021-03-24 14:11 ` [PATCH 7/7] fotg210-udc: Complete OUT requests on short packets Fabian Vogt
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

Before this, it wrote as much as available into the buffer, even if it
didn't fit.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 6a4c60d5b2c2..7716bd1c8753 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -338,8 +338,9 @@ static void fotg210_start_dma(struct fotg210_ep *ep,
 		} else {
 			buffer = req->req.buf + req->req.actual;
 			length = ioread32(ep->fotg210->reg +
-					FOTG210_FIBCR(ep->epnum - 1));
-			length &= FIBCR_BCFX;
+					FOTG210_FIBCR(ep->epnum - 1)) & FIBCR_BCFX;
+			if (length > req->req.length - req->req.actual)
+				length = req->req.length - req->req.actual;
 		}
 	} else {
 		buffer = req->req.buf + req->req.actual;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 7/7] fotg210-udc: Complete OUT requests on short packets
  2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
                   ` (5 preceding siblings ...)
  2021-03-24 14:11 ` [PATCH 6/7] fotg210-udc: Don't DMA more than the buffer can take Fabian Vogt
@ 2021-03-24 14:11 ` Fabian Vogt
  6 siblings, 0 replies; 8+ messages in thread
From: Fabian Vogt @ 2021-03-24 14:11 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Fabian Vogt, Greg Kroah-Hartman, Yuan-Hsin Chen, linux-usb

A short packet indicates the end of a transfer and marks the request as
complete.

Fixes: b84a8dee23fd ("usb: gadget: add Faraday fotg210_udc driver")
Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
---
 drivers/usb/gadget/udc/fotg210-udc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
index 7716bd1c8753..6cb7daf725b9 100644
--- a/drivers/usb/gadget/udc/fotg210-udc.c
+++ b/drivers/usb/gadget/udc/fotg210-udc.c
@@ -863,12 +863,16 @@ static void fotg210_out_fifo_handler(struct fotg210_ep *ep)
 {
 	struct fotg210_request *req = list_entry(ep->queue.next,
 						 struct fotg210_request, queue);
+	int disgr1 = ioread32(ep->fotg210->reg + FOTG210_DISGR1);
 
 	fotg210_start_dma(ep, req);
 
-	/* finish out transfer */
+	/* Complete the request when it's full or a short packet arrived.
+	 * Like other drivers, short_not_ok isn't handled.
+	 */
+
 	if (req->req.length == req->req.actual ||
-	    req->req.actual < ep->ep.maxpacket)
+	    (disgr1 & DISGR1_SPK_INT(ep->epnum - 1)))
 		fotg210_done(ep, req, 0);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-24 14:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 14:11 [PATCH 0/7] Fix the fotg210-udc driver Fabian Vogt
2021-03-24 14:11 ` [PATCH 1/7] fotg210-udc: Fix DMA on EP0 for length > max packet size Fabian Vogt
2021-03-24 14:11 ` [PATCH 2/7] fotg210-udc: Fix EP0 IN requests bigger than two packets Fabian Vogt
2021-03-24 14:11 ` [PATCH 3/7] fotg210-udc: Remove a dubious condition leading to fotg210_done Fabian Vogt
2021-03-24 14:11 ` [PATCH 4/7] fotg210-udc: Mask GRP2 interrupts we don't handle Fabian Vogt
2021-03-24 14:11 ` [PATCH 5/7] fotg210-udc: Call usb_gadget_udc_reset Fabian Vogt
2021-03-24 14:11 ` [PATCH 6/7] fotg210-udc: Don't DMA more than the buffer can take Fabian Vogt
2021-03-24 14:11 ` [PATCH 7/7] fotg210-udc: Complete OUT requests on short packets Fabian Vogt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).