* [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario
@ 2021-06-27 12:57 Kelly Devilliv
2021-06-27 12:57 ` [PATCH 1/3] Revert "usb: host: fotg210: Use dma_pool_zalloc" Kelly Devilliv
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Kelly Devilliv @ 2021-06-27 12:57 UTC (permalink / raw)
To: gregkh, shubhankarvk, lee.jones, gustavoars, chunfeng.yun
Cc: linux-usb, linux-kernel, Kelly Devilliv
Hi :-)
Currently, I tried to support usb camera on the fotg210 host
controller but came across a few issues, for example system
crash, video streaming error, etc. As fotg210 is an ehci-like
controller, I borrowed some ideas from the ehci-hcd driver,
and at least the usb camera can work now.
By the way, the fotg210-hcd driver seems a bit out of date,
is there any plan to update it based on the latest ehci-hcd
driver?
Thank you!
Kelly Devilliv (3):
Revert "usb: host: fotg210: Use dma_pool_zalloc"
usb: host: fotg210: fix the endpoint's transactional opportunities
calculation
usb: host: fotg210: fix the actual_length of an iso packet
drivers/usb/host/fotg210-hcd.c | 48 +++++++++++++++++-----------------
drivers/usb/host/fotg210.h | 5 ----
2 files changed, 24 insertions(+), 29 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Revert "usb: host: fotg210: Use dma_pool_zalloc"
2021-06-27 12:57 [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Kelly Devilliv
@ 2021-06-27 12:57 ` Kelly Devilliv
2021-06-27 12:57 ` [PATCH 2/3] usb: host: fotg210: fix the endpoint's transactional opportunities calculation Kelly Devilliv
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Kelly Devilliv @ 2021-06-27 12:57 UTC (permalink / raw)
To: gregkh, shubhankarvk, lee.jones, gustavoars, chunfeng.yun
Cc: linux-usb, linux-kernel, Kelly Devilliv
This reverts commit cb6a0db8fdc12433ed4281331de0c3923dc2807b for the
same reason as commit 43b78f1155c868208a413082179251f5fba78153 in the
ehci-hcd driver.
Alan writes:
What you can't see just from reading the patch is that in both
cases (ehci->itd_pool and ehci->sitd_pool) there are two
allocation paths -- the two branches of an "if" statement -- and
only one of the paths calls dma_pool_[z]alloc. However, the
memset is needed for both paths, and so it can't be eliminated.
Given that it must be present, there's no advantage to calling
dma_pool_zalloc rather than dma_pool_alloc.
Signed-off-by: Kelly Devilliv <kelly.devilliv@gmail.com>
---
drivers/usb/host/fotg210-hcd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index 9c2eda0918e1..bb50a7a7318a 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -1857,9 +1857,11 @@ static struct fotg210_qh *fotg210_qh_alloc(struct fotg210_hcd *fotg210,
qh = kzalloc(sizeof(*qh), GFP_ATOMIC);
if (!qh)
goto done;
- qh->hw = dma_pool_zalloc(fotg210->qh_pool, flags, &dma);
+ qh->hw = (struct fotg210_qh_hw *)
+ dma_pool_alloc(fotg210->qh_pool, flags, &dma);
if (!qh->hw)
goto fail;
+ memset(qh->hw, 0, sizeof(*qh->hw));
qh->qh_dma = dma;
INIT_LIST_HEAD(&qh->qtd_list);
@@ -4111,7 +4113,7 @@ static int itd_urb_transaction(struct fotg210_iso_stream *stream,
} else {
alloc_itd:
spin_unlock_irqrestore(&fotg210->lock, flags);
- itd = dma_pool_zalloc(fotg210->itd_pool, mem_flags,
+ itd = dma_pool_alloc(fotg210->itd_pool, mem_flags,
&itd_dma);
spin_lock_irqsave(&fotg210->lock, flags);
if (!itd) {
@@ -4121,6 +4123,7 @@ static int itd_urb_transaction(struct fotg210_iso_stream *stream,
}
}
+ memset(itd, 0, sizeof(*itd));
itd->itd_dma = itd_dma;
list_add(&itd->itd_list, &sched->td_list);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] usb: host: fotg210: fix the endpoint's transactional opportunities calculation
2021-06-27 12:57 [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Kelly Devilliv
2021-06-27 12:57 ` [PATCH 1/3] Revert "usb: host: fotg210: Use dma_pool_zalloc" Kelly Devilliv
@ 2021-06-27 12:57 ` Kelly Devilliv
2021-06-27 12:57 ` [PATCH 3/3] usb: host: fotg210: fix the actual_length of an iso packet Kelly Devilliv
2021-07-21 8:03 ` [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Kelly Devilliv @ 2021-06-27 12:57 UTC (permalink / raw)
To: gregkh, shubhankarvk, lee.jones, gustavoars, chunfeng.yun
Cc: linux-usb, linux-kernel, Kelly Devilliv
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we should make use of the
usb_endpoint_* helpers instead and remove the unnecessary
max_packet()/hb_mult() macro.
Signed-off-by: Kelly Devilliv <kelly.devilliv@gmail.com>
---
drivers/usb/host/fotg210-hcd.c | 36 ++++++++++++++++------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index bb50a7a7318a..c38a6c2a8d95 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -2511,11 +2511,6 @@ static unsigned qh_completions(struct fotg210_hcd *fotg210,
return count;
}
-/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
-#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
-/* ... and packet size, for any kind of endpoint descriptor */
-#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
-
/* reverse of qh_urb_transaction: free a list of TDs.
* used for cleanup after errors, before HC sees an URB's TDs.
*/
@@ -2601,7 +2596,7 @@ static struct list_head *qh_urb_transaction(struct fotg210_hcd *fotg210,
token |= (1 /* "in" */ << 8);
/* else it's already initted to "out" pid (0 << 8) */
- maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
+ maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input);
/*
* buffer gets wrapped in one or more qtds;
@@ -2715,9 +2710,11 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
gfp_t flags)
{
struct fotg210_qh *qh = fotg210_qh_alloc(fotg210, flags);
+ struct usb_host_endpoint *ep;
u32 info1 = 0, info2 = 0;
int is_input, type;
int maxp = 0;
+ int mult;
struct usb_tt *tt = urb->dev->tt;
struct fotg210_qh_hw *hw;
@@ -2732,14 +2729,15 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
is_input = usb_pipein(urb->pipe);
type = usb_pipetype(urb->pipe);
- maxp = usb_maxpacket(urb->dev, urb->pipe, !is_input);
+ ep = usb_pipe_endpoint(urb->dev, urb->pipe);
+ maxp = usb_endpoint_maxp(&ep->desc);
+ mult = usb_endpoint_maxp_mult(&ep->desc);
/* 1024 byte maxpacket is a hardware ceiling. High bandwidth
* acts like up to 3KB, but is built from smaller packets.
*/
- if (max_packet(maxp) > 1024) {
- fotg210_dbg(fotg210, "bogus qh maxpacket %d\n",
- max_packet(maxp));
+ if (maxp > 1024) {
+ fotg210_dbg(fotg210, "bogus qh maxpacket %d\n", maxp);
goto done;
}
@@ -2753,8 +2751,7 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
*/
if (type == PIPE_INTERRUPT) {
qh->usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
- is_input, 0,
- hb_mult(maxp) * max_packet(maxp)));
+ is_input, 0, mult * maxp));
qh->start = NO_FRAME;
if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -2791,7 +2788,7 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
think_time = tt ? tt->think_time : 0;
qh->tt_usecs = NS_TO_US(think_time +
usb_calc_bus_time(urb->dev->speed,
- is_input, 0, max_packet(maxp)));
+ is_input, 0, maxp));
qh->period = urb->interval;
if (qh->period > fotg210->periodic_size) {
qh->period = fotg210->periodic_size;
@@ -2854,11 +2851,11 @@ static struct fotg210_qh *qh_make(struct fotg210_hcd *fotg210, struct urb *urb,
* to help them do so. So now people expect to use
* such nonconformant devices with Linux too; sigh.
*/
- info1 |= max_packet(maxp) << 16;
+ info1 |= maxp << 16;
info2 |= (FOTG210_TUNE_MULT_HS << 30);
} else { /* PIPE_INTERRUPT */
- info1 |= max_packet(maxp) << 16;
- info2 |= hb_mult(maxp) << 30;
+ info1 |= maxp << 16;
+ info2 |= mult << 30;
}
break;
default:
@@ -3928,6 +3925,7 @@ static void iso_stream_init(struct fotg210_hcd *fotg210,
int is_input;
long bandwidth;
unsigned multi;
+ struct usb_host_endpoint *ep;
/*
* this might be a "high bandwidth" highspeed endpoint,
@@ -3935,14 +3933,14 @@ static void iso_stream_init(struct fotg210_hcd *fotg210,
*/
epnum = usb_pipeendpoint(pipe);
is_input = usb_pipein(pipe) ? USB_DIR_IN : 0;
- maxp = usb_maxpacket(dev, pipe, !is_input);
+ ep = usb_pipe_endpoint(dev, pipe);
+ maxp = usb_endpoint_maxp(&ep->desc);
if (is_input)
buf1 = (1 << 11);
else
buf1 = 0;
- maxp = max_packet(maxp);
- multi = hb_mult(maxp);
+ multi = usb_endpoint_maxp_mult(&ep->desc);
buf1 |= maxp;
maxp *= multi;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] usb: host: fotg210: fix the actual_length of an iso packet
2021-06-27 12:57 [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Kelly Devilliv
2021-06-27 12:57 ` [PATCH 1/3] Revert "usb: host: fotg210: Use dma_pool_zalloc" Kelly Devilliv
2021-06-27 12:57 ` [PATCH 2/3] usb: host: fotg210: fix the endpoint's transactional opportunities calculation Kelly Devilliv
@ 2021-06-27 12:57 ` Kelly Devilliv
2021-07-21 8:03 ` [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Kelly Devilliv @ 2021-06-27 12:57 UTC (permalink / raw)
To: gregkh, shubhankarvk, lee.jones, gustavoars, chunfeng.yun
Cc: linux-usb, linux-kernel, Kelly Devilliv
We should acquire the actual_length of an iso packet
from the iTD directly using FOTG210_ITD_LENGTH() macro.
Signed-off-by: Kelly Devilliv <kelly.devilliv@gmail.com>
---
drivers/usb/host/fotg210-hcd.c | 5 ++---
drivers/usb/host/fotg210.h | 5 -----
2 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
index c38a6c2a8d95..48ff10958d0d 100644
--- a/drivers/usb/host/fotg210-hcd.c
+++ b/drivers/usb/host/fotg210-hcd.c
@@ -4462,13 +4462,12 @@ static bool itd_complete(struct fotg210_hcd *fotg210, struct fotg210_itd *itd)
/* HC need not update length with this error */
if (!(t & FOTG210_ISOC_BABBLE)) {
- desc->actual_length =
- fotg210_itdlen(urb, desc, t);
+ desc->actual_length = FOTG210_ITD_LENGTH(t);
urb->actual_length += desc->actual_length;
}
} else if (likely((t & FOTG210_ISOC_ACTIVE) == 0)) {
desc->status = 0;
- desc->actual_length = fotg210_itdlen(urb, desc, t);
+ desc->actual_length = FOTG210_ITD_LENGTH(t);
urb->actual_length += desc->actual_length;
} else {
/* URB was too late */
diff --git a/drivers/usb/host/fotg210.h b/drivers/usb/host/fotg210.h
index 6cee40ec65b4..67f59517ebad 100644
--- a/drivers/usb/host/fotg210.h
+++ b/drivers/usb/host/fotg210.h
@@ -686,11 +686,6 @@ static inline unsigned fotg210_read_frame_index(struct fotg210_hcd *fotg210)
return fotg210_readl(fotg210, &fotg210->regs->frame_index);
}
-#define fotg210_itdlen(urb, desc, t) ({ \
- usb_pipein((urb)->pipe) ? \
- (desc)->length - FOTG210_ITD_LENGTH(t) : \
- FOTG210_ITD_LENGTH(t); \
-})
/*-------------------------------------------------------------------------*/
#endif /* __LINUX_FOTG210_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario
2021-06-27 12:57 [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Kelly Devilliv
` (2 preceding siblings ...)
2021-06-27 12:57 ` [PATCH 3/3] usb: host: fotg210: fix the actual_length of an iso packet Kelly Devilliv
@ 2021-07-21 8:03 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-07-21 8:03 UTC (permalink / raw)
To: Kelly Devilliv
Cc: shubhankarvk, lee.jones, gustavoars, chunfeng.yun, linux-usb,
linux-kernel
On Sun, Jun 27, 2021 at 08:57:44PM +0800, Kelly Devilliv wrote:
> Hi :-)
>
> Currently, I tried to support usb camera on the fotg210 host
> controller but came across a few issues, for example system
> crash, video streaming error, etc. As fotg210 is an ehci-like
> controller, I borrowed some ideas from the ehci-hcd driver,
> and at least the usb camera can work now.
>
> By the way, the fotg210-hcd driver seems a bit out of date,
> is there any plan to update it based on the latest ehci-hcd
> driver?
No idea, feel free to send changes to fix it up!
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-21 8:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 12:57 [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Kelly Devilliv
2021-06-27 12:57 ` [PATCH 1/3] Revert "usb: host: fotg210: Use dma_pool_zalloc" Kelly Devilliv
2021-06-27 12:57 ` [PATCH 2/3] usb: host: fotg210: fix the endpoint's transactional opportunities calculation Kelly Devilliv
2021-06-27 12:57 ` [PATCH 3/3] usb: host: fotg210: fix the actual_length of an iso packet Kelly Devilliv
2021-07-21 8:03 ` [PATCH 0/3] usb: host: fotg210: fix malfunctions in usb camera scenario Greg KH
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).