Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1329590rdb; Fri, 19 Jan 2024 16:15:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFh5LQiXbMJ+KkOwuLAJUjDoGPc3TB+CNuwjEGQrexhfhDFY0mbZb+2jiaRUN3/cdxJnBGJ X-Received: by 2002:a05:6402:1242:b0:558:6213:d36c with SMTP id l2-20020a056402124200b005586213d36cmr251677edw.75.1705709720648; Fri, 19 Jan 2024 16:15:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705709720; cv=pass; d=google.com; s=arc-20160816; b=0wSTe1ooMc/T5PXAjJAbH6M/DdlmHTDR1lY8+fWm85/LcsVh2vw2UCUAnhod6f7qD+ vmdR8DCylnrR4sNvtP2l3PEcBzNEGuuQ1phlv5JKfTeYLK2NRNr/truaVx7QXY4sYY3U 70gnlQ4lR99m0TUKw/TYPTR5Baodr7xZM5dT/uTKIPNwj6cs7HIPNgzTqMmwHBpuEzZ7 DyNxrLa5OLnXVXDZUmym/K7k1Ulz9iqSfK8yiGYUqih0IQ1TNyWrchdoFsctYGiOgKW0 tozxscnN4/P9LV7V4z37FeypHZpFQN++fjNRcFvYDdguL11HDG4/v/U2HiUdepYfVqbN ua3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:autocrypt:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=uTRM9d6bvlbWT4CTU/U4qeImT68CpFKTYfre+yx+3OQ=; fh=8TlcXF88b0q9LBvP+ek+DL8lCDDMOIK8bAdMpSlDIaQ=; b=WdUxE20uYzE+MFSd/C+w6WD55im19TNIzipbpiZ5vUoD74tPwEHPkBobBAvlQsAPQ9 WYjvRH3e21GAAVxCE5nNlq+B4uJaAIhtnFV86ax6hmw2KOV3OmRcDKtQ/dX1RElnPn9L /jO+RgvdYhsztpBrslEGLkEO3HzNrkcNLc/PgOiuBaqjAjxOJbaBE//8QWRcYn9AZPEJ KxteOeWMUvB65xywyb0n/yzKILs1s2N8jTm++wSMIcOwpJn5DBvA4i6RGkniBq5xwfSK 2CagD6MLYwcoPQUDHytcVEuymoJHPj67NajVDg6v9qY7O+h5Sco7AenumlT0Okz584JH fTmg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=JA265L43; 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-31640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a5-20020a50e705000000b00557a6155605si8216633edn.174.2024.01.19.16.15.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 16:15:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31640-linux.lists.archive=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=JA265L43; 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-31640-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31640-linux.lists.archive=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 68D941F2290C for ; Sat, 20 Jan 2024 00:15:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37525815; Sat, 20 Jan 2024 00:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="JA265L43" 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 A6B15170; Sat, 20 Jan 2024 00:15:02 +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=1705709704; cv=none; b=hvbJLZQhZrZNDpP9jBhcsm/eeSEsP4Y2OuPyWuFaXBx3wUuVkiial0zC5K/NiLeZtVdYXq/6TAuUVSLFK9ZRy4l5fRuCEGHkXoEALfkXPiAkGKvXVKjz8ZhFcHudSsAJL88hUee5gAx96IROx9efyDPsutAeW8SnRKAvGWHPgjQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705709704; c=relaxed/simple; bh=W7OnWjDgrb5ZNuxFpvFGDTPEYhVuCP6OSB6O3x5tm3Q=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=ktus0gD9mvJpeDSd1KfyWUaQSRFqveZLDhWAwaVumMFphV5zjFlIbozVVv7h9TQ7YauGYeDcdt8JuZEDlpcbHWfWeDNl7R1KnCwv2ELCOhv7p6NQlSFKGVBkpW8EIuuV2BGrNor3n76yrEc9Ic4MWSNmVH8jx4Y3clCvT49Cukw= 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=JA265L43; 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=1705709694; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=uTRM9d6bvlbWT4CTU/U4qeImT68CpFKTYfre+yx+3OQ=; b=JA265L43X+KVrNQQpKTeItKpNrS74hBHSilZLefH+GSdoIa6uDIXf4ZrMKJYw2cM106Vp6 BQC7TTWrnq9Vj+5LxaM33VHNWqeReEPckoCVSemlDGNc/QfOnOhmwjrJbAGucqHWZWf0ra vjxOzGBKes+Jac25P3fz9YBWxAGp9Tk= Message-ID: <59799a40d8cc425dc5a847a0c8e25730db4fc5c8.camel@crapouillou.net> Subject: Re: [PATCH v4 1/4] usb: gadget: Support already-mapped DMA SGs From: Paul Cercueil To: Frank Li Cc: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , Christian =?ISO-8859-1?Q?K=F6nig?= , Jonathan Cameron , Nuno =?ISO-8859-1?Q?S=E1?= , Michael Hennerich , 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 Date: Sat, 20 Jan 2024 01:14:52 +0100 In-Reply-To: References: <20240117122646.41616-1-paul@crapouillou.net> <20240117122646.41616-2-paul@crapouillou.net> Autocrypt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rfzp9ryxd1tCnbV+tG8VHQWiZXNqN7062DygSNXFUfQ0vZ3J2D4oAcIAEXTymRQ2+hr3Hf7I61KMHWeSkCvCG2decTYsHlw5Erix/jYWqVOtX0roOOLqWkqpQQJWtU+biWrAksmFmCp5fXIg1Nlg39v21xCXBGxJkxyTYuhdWyu1yDQ+LSIUAEQEAAYkBNgQYAQoAIBYhBNdHYd8OeCBwpMuVxnPua9InSr1BBQJdCoXBAhsMAAoJEHPua9InSr1B4wsH/Az767YCT0FSsMNt1jkkdLCBi7nY0GTW+PLP1a4zvVqFMo/vD6uz1ZflVTUAEvcTi3VHYZrlgjcxmcGu239oruqUS8Qy/xgZBp9KF0NTWQSl1iBfVbIU5VV1vHS6r77W5x0qXgfvAUWOH4gmN3MnF01SH2zMcLiaUGF+mcwl15rHbjnT3Nu2399aSE6cep86igfCAyFUOXjYEGlJy+c6UyT+DUylpjQg0nl8MlZ/7Whg2fAU9+FALIbQYQzGlT4c71SibR9T741jnegHhlmV4WXXUD6roFt54t0MSAFSVxzG8mLcSjR2cLUJ3NIPXixYUSEn3tQhfZj07xIIjWxAYZo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi Frank, Le vendredi 19 janvier 2024 =C3=A0 16:49 -0500, Frank Li a =C3=A9crit=C2=A0= : > 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. > >=20 > > Signed-off-by: Paul Cercueil > > --- > > =C2=A0drivers/usb/gadget/udc/core.c | 7 ++++++- > > =C2=A0include/linux/usb/gadget.h=C2=A0=C2=A0=C2=A0 | 2 ++ > > =C2=A02 files changed, 8 insertions(+), 1 deletion(-) > >=20 > > 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, > > =C2=A0 if (req->length =3D=3D 0) > > =C2=A0 return 0; > > =C2=A0 > > + if (req->sg_was_mapped) { > > + req->num_mapped_sgs =3D req->num_sgs; > > + return 0; > > + } > > + > > =C2=A0 if (req->num_sgs) { > > =C2=A0 int=C2=A0=C2=A0=C2=A0=C2=A0 mapped; > > =C2=A0 > > @@ -948,7 +953,7 @@ EXPORT_SYMBOL_GPL(usb_gadget_map_request); > > =C2=A0void usb_gadget_unmap_request_by_dev(struct device *dev, > > =C2=A0 struct usb_request *req, int is_in) > > =C2=A0{ > > - if (req->length =3D=3D 0) > > + if (req->length =3D=3D 0 || req->sg_was_mapped) > > =C2=A0 return; > > =C2=A0 > > =C2=A0 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; > > =C2=A0 * @short_not_ok: When reading data, makes short packets be > > =C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0 treated as errors (queue stops advanci= ng till cleanup). > > =C2=A0 * @dma_mapped: Indicates if request has been mapped to DMA > > (internal) > > + * @sg_was_mapped: Set if the scatterlist has been mapped before > > the request > > =C2=A0 * @complete: Function called when request completes, so this > > request and > > =C2=A0 * its buffer may be re-used.=C2=A0 The function will always be > > called with > > =C2=A0 * interrupts disabled, and it must not sleep. > > @@ -111,6 +112,7 @@ struct usb_request { > > =C2=A0 unsigned zero:1; > > =C2=A0 unsigned short_not_ok:1; > > =C2=A0 unsigned dma_mapped:1; > > + unsigned sg_was_mapped:1; >=20 > why not use dma_mapped direclty? Because of the unmap case. We want to know whether we should unmap or not. >=20 > Frank Cheers, -Paul >=20 > > =C2=A0 > > =C2=A0 void (*complete)(struct usb_ep *ep, > > =C2=A0 struct usb_request *req); > > --=20 > > 2.43.0 > >=20