mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pawel Laszczak <pawell@cadence.com>
To: Frank Li <Frank.li@nxp.com>,
	"peter.chen@kernel.org" <peter.chen@kernel.org>,
	"rogerq@kernel.org" <rogerq@kernel.org>,
	"a-govindraju@ti.com" <a-govindraju@ti.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: RE: cdns3 uvc first ISO parkage lost problem
Date: Mon, 30 Oct 2023 06:34:48 +0000	[thread overview]
Message-ID: <BYAPR07MB5381F7224612F0C0793B6B29DDA1A@BYAPR07MB5381.namprd07.prod.outlook.com> (raw)
In-Reply-To: <ZTvhEl+JcnhJXcrl@lizhi-Precision-Tower-5810>


>
>hi Pawel Laszczak
>
>Recently, I met the problem when use uvc. UVC report jpg header error.
>
>Basic reproduce steps.
>Gadget side:
>1 -
>	https://urldefense.com/v3/__https://gist.github.com/kbingham/c39c
>4cc7c20882a104c08df5206e2f9f?permalink_comment_id=3270713__;!!EHscm
>S1ygiU1lA!H1h8GlLnbS6vqklXm_2qGyinP638O62Kk2eLB9zeMkjAGXUAPYyPXDL
>FasSqYt16xq0RGT0Ff-cP4A$
>	uvc-gadget.sh start
>2 -
>	https://urldefense.com/v3/__https://git.ideasonboard.org/uvc-
>gadget.git__;!!EHscmS1ygiU1lA!H1h8GlLnbS6vqklXm_2qGyinP638O62Kk2eLB9z
>eMkjAGXUAPYyPXDLFasSqYt16xq0RGT1ogOdRQA$
>	uvc-gadget -i test.jpg
>
>
>Host side:
>	https://urldefense.com/v3/__https://github.com/thekvs/uvccapture2
>__;!!EHscmS1ygiU1lA!H1h8GlLnbS6vqklXm_2qGyinP638O62Kk2eLB9zeMkjAGX
>UAPYyPXDLFasSqYt16xq0RGT1MNlKiXA$
>	uvccapture2 --device /dev/video0  --resolution 640x360 --count 1 --
>result 8qxp.jpeg
>
>	It will report jpeg header error.
>
>
>After debugs, I found two problem.
>
>Problem 1, sg is enabled. so uvc driver will use sg. each package include two
>trb,  trb0 is 8bytes header, trb1 is 1016bytes. total 1024.
>
>num_trb here is wrong.
>it should be
>	num_trb = priv_ep->interval * request->num_mapped_sgs.
>
>because priv_ep->interval is 1, I just simple set to request->num_mapped_sg
>as below patch. USB analyer show one whole 1024 ISO package sent out as
>expectation although document said only support one TD when use ISO
>(Maybe my doc is too old).

Support for sg  in uvc has been added after upstreaming this driver, so the driver
needs some improvement. 

Calculating of num_trb probably will more complicated change.

You can see how it is implemented in 
https://elixir.bootlin.com/linux/latest/source/drivers/usb/gadget/udc/cdns2/cdns2-gadget.c#L412.

CDNS2 is different controller and support only HS but has borrowed the DMA part from CDNS3.
It was upsteamed after adding sg to UVC.

Regarding TD, it is true that controller can support only one TD per  SOF but this TD can contain many TRBs

>
>diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-
>gadget.c
>index 69a44bd7e5d02..8cc99a885883f 100644
>--- a/drivers/usb/cdns3/cdns3-gadget.c
>+++ b/drivers/usb/cdns3/cdns3-gadget.c
>@@ -1125,10 +1125,7 @@ static int cdns3_ep_run_transfer(struct
>cdns3_endpoint *priv_ep,
>        struct scatterlist *s = NULL;
>        bool sg_supported = !!(request->num_mapped_sgs);
>
>-       if (priv_ep->type == USB_ENDPOINT_XFER_ISOC)
>-               num_trb = priv_ep->interval;
>-       else
>-               num_trb = sg_supported ? request->num_mapped_sgs : 1;
>+       num_trb = sg_supported ? request->num_mapped_sgs : 1;
>
>        if (num_trb > priv_ep->free_trbs) {
>                priv_ep->flags |= EP_RING_FULL;
>
>
>*** Problem 2 ***
>
>According to doc and my observation, looks like hardware fetch data into FIFO
>when get SOF, then transfer data when get IN token. Each SOF will increase
>TRB regardless it is ready or not.

Yes, but this fetched data will be sent in next  ITP. 

>
>When gadget complete equeue ISO data, so SOF will increase TRB regardless if
>there are IN token.
>
>   SOF       SOF       SOF     SOF  IN    SOF ....
>      TRB0      TRB1      TRB2      TRB3  ...
>
>
>Host may start get data at some time after gadget queue data.
>
>So TRB0..2 data will be lost.
>
>If it is audio data, it should be okay. But for uvc, it is jpeg header, so host side
>report error.
>
>I checked dwc gadget driver, which start equeue ISO data only get NYET.
>
>I check cdns spec, there are ISOERR. But it is never happen. According to
>document, ISOERR should issue when IN token and FIFO no data.
>

Current CDNS3 driver has disabled ISOERR. Did you enable it?

>I tried below method
>	1.  Delay queue TRB, but no ISOERR.
>	2.  queue a lenght 0 TRB,but no ISOERR
>
>My question is how to delay queue TRB to ISO IN token really happen to avoid
>lost JPEG header.
>
>Frank
>
>
>
>
>


       reply	other threads:[~2023-10-30  6:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ZTvhEl+JcnhJXcrl@lizhi-Precision-Tower-5810>
2023-10-30  6:34 ` Pawel Laszczak [this message]
2023-10-30 16:21   ` Frank Li
2023-11-06 11:12     ` Pawel Laszczak
2023-11-06 15:38       ` Frank Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BYAPR07MB5381F7224612F0C0793B6B29DDA1A@BYAPR07MB5381.namprd07.prod.outlook.com \
    --to=pawell@cadence.com \
    --cc=Frank.li@nxp.com \
    --cc=a-govindraju@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=rogerq@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®