All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Chen <peter.chen@nxp.com>
To: balbi@kernel.org
Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com,
	rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com,
	Peter Chen <peter.chen@nxp.com>
Subject: [PATCH v2 1/8] usb: cdns3: gadget: using correct sg operations
Date: Thu, 10 Sep 2020 17:11:23 +0800	[thread overview]
Message-ID: <20200910091130.20937-2-peter.chen@nxp.com> (raw)
In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com>

It needs to use request->num_mapped_sgs to indicate mapped sg number,
the request->num_sgs is the sg number before the mapping. These two
entries have different values for the platforms which iommu or
swiotlb is used. Besides, it needs to use correct sg APIs for
mapped sg list for TRB assignment.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
---
 drivers/usb/cdns3/gadget.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index 2ea4d30e1828..2d6dd6896937 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -1098,11 +1098,13 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 	u32 control;
 	int pcs;
 	u16 total_tdl = 0;
+	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 = request->num_sgs ? request->num_sgs : 1;
+		num_trb = sg_supported ? request->num_mapped_sgs : 1;
 
 	if (num_trb > priv_ep->free_trbs) {
 		priv_ep->flags |= EP_RING_FULL;
@@ -1162,6 +1164,9 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 	if (priv_dev->dev_ver <= DEV_VER_V2)
 		togle_pcs = cdns3_wa1_update_guard(priv_ep, trb);
 
+	if (sg_supported)
+		s = request->sg;
+
 	/* set incorrect Cycle Bit for first trb*/
 	control = priv_ep->pcs ? 0 : TRB_CYCLE;
 
@@ -1171,13 +1176,13 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 
 		/* fill TRB */
 		control |= TRB_TYPE(TRB_NORMAL);
-		trb->buffer = cpu_to_le32(TRB_BUFFER(request->num_sgs == 0
-				? trb_dma : request->sg[sg_iter].dma_address));
-
-		if (likely(!request->num_sgs))
+		if (sg_supported) {
+			trb->buffer = cpu_to_le32(TRB_BUFFER(sg_dma_address(s)));
+			length = sg_dma_len(s);
+		} else {
+			trb->buffer = cpu_to_le32(TRB_BUFFER(trb_dma));
 			length = request->length;
-		else
-			length = request->sg[sg_iter].length;
+		}
 
 		if (likely(priv_dev->dev_ver >= DEV_VER_V2))
 			td_size = DIV_ROUND_UP(length,
@@ -1215,6 +1220,9 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 		else
 			priv_req->trb->control = cpu_to_le32(control);
 
+		if (sg_supported)
+			s = sg_next(s);
+
 		control = 0;
 		++sg_iter;
 		priv_req->end_trb = priv_ep->enqueue;
-- 
2.17.1


  reply	other threads:[~2020-09-10  9:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10  9:11 [PATCH v2 0/8] usb: cdns3: improve the sg use case Peter Chen
2020-09-10  9:11 ` Peter Chen [this message]
2020-09-24  7:27   ` [PATCH v2 1/8] usb: cdns3: gadget: using correct sg operations Felipe Balbi
2020-09-24  9:33     ` Peter Chen
2020-09-29  3:40       ` Peter Chen
2020-09-29  6:29         ` Felipe Balbi
2020-09-10  9:11 ` [PATCH v2 2/8] usb: cdns3: gadget: improve the dump TRB operation at cdns3_ep_run_transfer Peter Chen
2020-09-10  9:11 ` [PATCH v2 3/8] usb: cdns3: gadget: calculate TDL correctly Peter Chen
2020-09-10  9:11 ` [PATCH v2 4/8] usb: cdns3: gadget: add CHAIN and ISP bit for sg list use case Peter Chen
2020-09-10  9:11 ` [PATCH v2 5/8] usb: cdns3: gadget: handle sg list use case at completion correctly Peter Chen
2020-09-10  9:11 ` [PATCH v2 6/8] usb: cdns3: gadget: need to handle sg case for workaround 2 case Peter Chen
2020-09-10  9:11 ` [PATCH v2 7/8] usb: cdns3: gadget: sg_support is only for DEV_VER_V2 or above Peter Chen
2020-09-10  9:11 ` [PATCH v2 8/8] usb: cdns3: gadget: enlarge the TRB ring length Peter Chen

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=20200910091130.20937-2-peter.chen@nxp.com \
    --to=peter.chen@nxp.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@nxp.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=pawell@cadence.com \
    --cc=rogerq@ti.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.