Message ID | 20240117122646.41616-2-paul@crapouillou.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp871445dye; Wed, 17 Jan 2024 04:27:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOwdctIr/HyHcyqjxODrCF6rHQreXElm1KjPebyZVxA0T5Ppo6VM2vCIjwEiac6zcEPYdv X-Received: by 2002:a05:6512:2351:b0:50e:455d:1bb4 with SMTP id p17-20020a056512235100b0050e455d1bb4mr5573909lfu.17.1705494465620; Wed, 17 Jan 2024 04:27:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705494465; cv=pass; d=google.com; s=arc-20160816; b=s3wpDhLsI9Oc73jJejBc5p1rvQ6gyE32ZDravhR1WeUNF+PLiuv4E0OfDx0gkOYvLO 8HX/BJecbI80a025N7X5S/XA2KJtS//YOJOlN30K+uFJvPC01sH4h9kgs4xU42Lk7TE9 BwowT9npyHy88NVjfi9I0CQH7N3W5RyBb9Vg0toIsaRbzCvRbBvOg1bWA3FqnPy84aB7 WllH+2EumyJ5DfDA+zzj4/Gaf39YN4qyZE8Qm/I9FhEeNVzpUTHbQI4cZ3ZKlCncjoLb jArkqonH7OyCRQVx1mLPRqZJqIpVGDcwmgQS5oos2pnFwaoy6cHIAAp0Htub+WyBXhYC J+1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SqXbfp61fzBHWNEqVrElLd46cr7HG/1wYVIvKKSn5jY=; fh=3Xwiw3h4BuSZxa4g5nlxoJvEg1Pn4zGp9h0k4mfsabo=; b=OK4OdmsNaciiujriscpN+poFKfVcOrDC3EEu9UO++uE4CgLbq6hE6rRsHGTbtISd7s kG0iqkbux+gVTXqBctJ5TVmyC6PPCeg67DkyLwpNQSPPF+PjWWpw3zwgt/FW7bqkCqLz SOZIlOIM1a6kir1iGmI42lUVHJxCSKD3ULIEmasn++M3dKw4w4Pnsb3CPlWl5ZRA5ENF 2xbuIAhw2KFeiZQ5a4jvj8upvJD4P2jmX0UsWll9gvHOKobyE4O271u0+fc+lJPw+RxY jfbTGlnf9kLioFRh9f9oq3epZhSNlRQBsDeY8RxWsSds38ePttqaL7XPUGzNB6H4aS/M vxGQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=223+VYq+; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g16-20020a17090670d000b00a298cb63827si5741409ejk.470.2024.01.17.04.27.45 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 04:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=223+VYq+; arc=pass (i=1 spf=pass spfdomain=crapouillou.net dkim=pass dkdomain=crapouillou.net dmarc=pass fromdomain=crapouillou.net); spf=pass (google.com: domain of linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 091BD1F25A7E for <ouuuleilei@gmail.com>; Wed, 17 Jan 2024 12:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43BE31EB43; Wed, 17 Jan 2024 12:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="223+VYq+" Received: from aposti.net (aposti.net [89.234.176.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CAA11EA6E; Wed, 17 Jan 2024 12:27:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.234.176.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705494425; cv=none; b=iWKcVFt9nA7u4Oi2GfESfi9RNPh3ckEgLE89Sdi1VQzlZYMRkgnckIMgRxDW/0XiWSSojuj4V5MSXsTgRVO+EgS4Z4sjT1rPo63DnKTEF8vU9qK8VFNAwsUnYybgucUU2qkWc+eYBOfwA6YYggK92+kYCK5Ph5IomrakCr1r/Yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705494425; c=relaxed/simple; bh=66FzAt7nJpAY9ka7VMdHoplxE2iQOAZv1WQkaTZVLTI=; h=DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:X-Spam; b=kzLsW74jUXEexFkygeWsiRGAbXGH+HTQGbcYDfw1wJntSCtJuvziXw8yW5g4EzJoolY48XqAeGNV1Uj2kCmO+hvAx2f+JGsfvLP6UAL21WWtNOv/+lY1LMdMfab2s1IrrPs1gb3w7Ng7XrWLvp0lxi5Vr6caoXIXEPWnmlUB2NQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net; spf=pass smtp.mailfrom=crapouillou.net; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b=223+VYq+; arc=none smtp.client-ip=89.234.176.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crapouillou.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1705494413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SqXbfp61fzBHWNEqVrElLd46cr7HG/1wYVIvKKSn5jY=; b=223+VYq+sNKlcr9ev/upoyhfOA7QKfzwcy2ytRmzFcW9tiJNZhBFP7Icx2D/cE6HkGGC+S FicGrecQKa3T7e642ZdQ1PZ4aswWX37cF6RM4V98cRtvafDFiZ3eQI1HL1PqyVRzDB+uG5 6vxQNtWC63HTGIlz41RK8dew84Qpqa8= From: Paul Cercueil <paul@crapouillou.net> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jonathan Corbet <corbet@lwn.net>, Sumit Semwal <sumit.semwal@linaro.org>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com> Cc: Jonathan Cameron <jic23@kernel.org>, =?utf-8?q?Nuno_S=C3=A1?= <noname.nuno@gmail.com>, Michael Hennerich <Michael.Hennerich@analog.com>, linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Paul Cercueil <paul@crapouillou.net> Subject: [PATCH v4 1/4] usb: gadget: Support already-mapped DMA SGs Date: Wed, 17 Jan 2024 13:26:43 +0100 Message-ID: <20240117122646.41616-2-paul@crapouillou.net> In-Reply-To: <20240117122646.41616-1-paul@crapouillou.net> References: <20240117122646.41616-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788340564929108957 X-GMAIL-MSGID: 1788340564929108957 |
Series | usb: gadget: functionfs: DMABUF import interface | |
Commit Message
Paul Cercueil
Jan. 17, 2024, 12:26 p.m. UTC
Add a new 'sg_was_mapped' field to the struct usb_request. This field
can be used to indicate that the scatterlist associated to the USB
transfer has already been mapped into the DMA space, and it does not
have to be done internally.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
drivers/usb/gadget/udc/core.c | 7 ++++++-
include/linux/usb/gadget.h | 2 ++
2 files changed, 8 insertions(+), 1 deletion(-)
Comments
On Wed, Jan 17, 2024 at 01:26:43PM +0100, Paul Cercueil wrote: > Add a new 'sg_was_mapped' field to the struct usb_request. This field > can be used to indicate that the scatterlist associated to the USB > transfer has already been mapped into the DMA space, and it does not > have to be done internally. > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > --- > drivers/usb/gadget/udc/core.c | 7 ++++++- > include/linux/usb/gadget.h | 2 ++ > 2 files changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c > index d59f94464b87..9d4150124fdb 100644 > --- a/drivers/usb/gadget/udc/core.c > +++ b/drivers/usb/gadget/udc/core.c > @@ -903,6 +903,11 @@ int usb_gadget_map_request_by_dev(struct device *dev, > if (req->length == 0) > return 0; > > + if (req->sg_was_mapped) { > + req->num_mapped_sgs = req->num_sgs; > + return 0; > + } > + > if (req->num_sgs) { > int mapped; > > @@ -948,7 +953,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); > void usb_gadget_unmap_request_by_dev(struct device *dev, > struct usb_request *req, int is_in) > { > - if (req->length == 0) > + if (req->length == 0 || req->sg_was_mapped) > return; > > if (req->num_mapped_sgs) { > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h > index a771ccc038ac..c529e4e06997 100644 > --- a/include/linux/usb/gadget.h > +++ b/include/linux/usb/gadget.h > @@ -52,6 +52,7 @@ struct usb_ep; > * @short_not_ok: When reading data, makes short packets be > * treated as errors (queue stops advancing till cleanup). > * @dma_mapped: Indicates if request has been mapped to DMA (internal) > + * @sg_was_mapped: Set if the scatterlist has been mapped before the request > * @complete: Function called when request completes, so this request and > * its buffer may be re-used. The function will always be called with > * interrupts disabled, and it must not sleep. > @@ -111,6 +112,7 @@ struct usb_request { > unsigned zero:1; > unsigned short_not_ok:1; > unsigned dma_mapped:1; > + unsigned sg_was_mapped:1; why not use dma_mapped direclty? Frank > > void (*complete)(struct usb_ep *ep, > struct usb_request *req); > -- > 2.43.0 >
Hi Frank, Le vendredi 19 janvier 2024 à 16:49 -0500, Frank Li a écrit : > On Wed, Jan 17, 2024 at 01:26:43PM +0100, Paul Cercueil wrote: > > Add a new 'sg_was_mapped' field to the struct usb_request. This > > field > > can be used to indicate that the scatterlist associated to the USB > > transfer has already been mapped into the DMA space, and it does > > not > > have to be done internally. > > > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > --- > > drivers/usb/gadget/udc/core.c | 7 ++++++- > > include/linux/usb/gadget.h | 2 ++ > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/usb/gadget/udc/core.c > > b/drivers/usb/gadget/udc/core.c > > index d59f94464b87..9d4150124fdb 100644 > > --- a/drivers/usb/gadget/udc/core.c > > +++ b/drivers/usb/gadget/udc/core.c > > @@ -903,6 +903,11 @@ int usb_gadget_map_request_by_dev(struct > > device *dev, > > if (req->length == 0) > > return 0; > > > > + if (req->sg_was_mapped) { > > + req->num_mapped_sgs = req->num_sgs; > > + return 0; > > + } > > + > > if (req->num_sgs) { > > int mapped; > > > > @@ -948,7 +953,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); > > void usb_gadget_unmap_request_by_dev(struct device *dev, > > struct usb_request *req, int is_in) > > { > > - if (req->length == 0) > > + if (req->length == 0 || req->sg_was_mapped) > > return; > > > > if (req->num_mapped_sgs) { > > diff --git a/include/linux/usb/gadget.h > > b/include/linux/usb/gadget.h > > index a771ccc038ac..c529e4e06997 100644 > > --- a/include/linux/usb/gadget.h > > +++ b/include/linux/usb/gadget.h > > @@ -52,6 +52,7 @@ struct usb_ep; > > * @short_not_ok: When reading data, makes short packets be > > * treated as errors (queue stops advancing till cleanup). > > * @dma_mapped: Indicates if request has been mapped to DMA > > (internal) > > + * @sg_was_mapped: Set if the scatterlist has been mapped before > > the request > > * @complete: Function called when request completes, so this > > request and > > * its buffer may be re-used. The function will always be > > called with > > * interrupts disabled, and it must not sleep. > > @@ -111,6 +112,7 @@ struct usb_request { > > unsigned zero:1; > > unsigned short_not_ok:1; > > unsigned dma_mapped:1; > > + unsigned sg_was_mapped:1; > > why not use dma_mapped direclty? Because of the unmap case. We want to know whether we should unmap or not. > > Frank Cheers, -Paul > > > > > void (*complete)(struct usb_ep *ep, > > struct usb_request *req); > > -- > > 2.43.0 > >
On Sat, Jan 20, 2024 at 01:14:52AM +0100, Paul Cercueil wrote: > Hi Frank, > > Le vendredi 19 janvier 2024 à 16:49 -0500, Frank Li a écrit : > > On Wed, Jan 17, 2024 at 01:26:43PM +0100, Paul Cercueil wrote: > > > Add a new 'sg_was_mapped' field to the struct usb_request. This > > > field > > > can be used to indicate that the scatterlist associated to the USB > > > transfer has already been mapped into the DMA space, and it does > > > not > > > have to be done internally. > > > > > > Signed-off-by: Paul Cercueil <paul@crapouillou.net> > > > --- > > > drivers/usb/gadget/udc/core.c | 7 ++++++- > > > include/linux/usb/gadget.h | 2 ++ > > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/usb/gadget/udc/core.c > > > b/drivers/usb/gadget/udc/core.c > > > index d59f94464b87..9d4150124fdb 100644 > > > --- a/drivers/usb/gadget/udc/core.c > > > +++ b/drivers/usb/gadget/udc/core.c > > > @@ -903,6 +903,11 @@ int usb_gadget_map_request_by_dev(struct > > > device *dev, > > > if (req->length == 0) > > > return 0; > > > > > > + if (req->sg_was_mapped) { > > > + req->num_mapped_sgs = req->num_sgs; > > > + return 0; > > > + } > > > + > > > if (req->num_sgs) { > > > int mapped; > > > > > > @@ -948,7 +953,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); > > > void usb_gadget_unmap_request_by_dev(struct device *dev, > > > struct usb_request *req, int is_in) > > > { > > > - if (req->length == 0) > > > + if (req->length == 0 || req->sg_was_mapped) > > > return; > > > > > > if (req->num_mapped_sgs) { > > > diff --git a/include/linux/usb/gadget.h > > > b/include/linux/usb/gadget.h > > > index a771ccc038ac..c529e4e06997 100644 > > > --- a/include/linux/usb/gadget.h > > > +++ b/include/linux/usb/gadget.h > > > @@ -52,6 +52,7 @@ struct usb_ep; > > > * @short_not_ok: When reading data, makes short packets be > > > * treated as errors (queue stops advancing till cleanup). > > > * @dma_mapped: Indicates if request has been mapped to DMA > > > (internal) > > > + * @sg_was_mapped: Set if the scatterlist has been mapped before > > > the request > > > * @complete: Function called when request completes, so this > > > request and > > > * its buffer may be re-used. The function will always be > > > called with > > > * interrupts disabled, and it must not sleep. > > > @@ -111,6 +112,7 @@ struct usb_request { > > > unsigned zero:1; > > > unsigned short_not_ok:1; > > > unsigned dma_mapped:1; > > > + unsigned sg_was_mapped:1; > > > > why not use dma_mapped direclty? > > Because of the unmap case. We want to know whether we should unmap or > not. I see, Thanks Frank > > > > > Frank > > Cheers, > -Paul > > > > > > > > > void (*complete)(struct usb_ep *ep, > > > struct usb_request *req); > > > -- > > > 2.43.0 > > > >
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index d59f94464b87..9d4150124fdb 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -903,6 +903,11 @@ int usb_gadget_map_request_by_dev(struct device *dev, if (req->length == 0) return 0; + if (req->sg_was_mapped) { + req->num_mapped_sgs = req->num_sgs; + return 0; + } + if (req->num_sgs) { int mapped; @@ -948,7 +953,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); void usb_gadget_unmap_request_by_dev(struct device *dev, struct usb_request *req, int is_in) { - if (req->length == 0) + if (req->length == 0 || req->sg_was_mapped) return; if (req->num_mapped_sgs) { diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index a771ccc038ac..c529e4e06997 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -52,6 +52,7 @@ struct usb_ep; * @short_not_ok: When reading data, makes short packets be * treated as errors (queue stops advancing till cleanup). * @dma_mapped: Indicates if request has been mapped to DMA (internal) + * @sg_was_mapped: Set if the scatterlist has been mapped before the request * @complete: Function called when request completes, so this request and * its buffer may be re-used. The function will always be called with * interrupts disabled, and it must not sleep. @@ -111,6 +112,7 @@ struct usb_request { unsigned zero:1; unsigned short_not_ok:1; unsigned dma_mapped:1; + unsigned sg_was_mapped:1; void (*complete)(struct usb_ep *ep, struct usb_request *req);