Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1577131rdb; Mon, 8 Jan 2024 04:01:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7lPJOS3t8A5WyICCX8FCysgQlEReveXeN+7kSbgWl5RHyX75lfBDf217bPYjrbwABVd0C X-Received: by 2002:a05:6102:2c0c:b0:467:c84f:c3e3 with SMTP id ie12-20020a0561022c0c00b00467c84fc3e3mr819589vsb.30.1704715302495; Mon, 08 Jan 2024 04:01:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704715302; cv=none; d=google.com; s=arc-20160816; b=arXOGs5cK1yGmpVfq1COBP29TqhFzyAoQgOwTSN4JvLtpUMcDoZivymMggi09MnseA k3TajRFtK9O23wrDvORIisLLGzNWKpoKup6zmYmkpP7HKzZfT5sg9k+Ot2ciYyS98kix GPIzv6Ik2guX9/ofxAjb9pw4QnSVMx7gKNXoav94Z4XnwSPVBbx8CFYyv6Y21O3eBDer Qj74laSRaP4+M2YGB3C03v3h2q0GapCgcir15vgBudaFAE/EC/VwQbSUQFK8MLUqVUuj HcDYI022MsjfUnSzbBm7WYd3GBDdOjz4UFMAMie7mPIgUu4SHT+iG1NMMkf1YNIkaYiF G/hw== ARC-Message-Signature: i=1; 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=uCl+pDf5A/h9/EhC2a7e6oA3XsaNDDsC5zMoVf40Kzc=; b=BEcgfRS4MIH0Usfa0MHnMAdBQM7m7t+SDqNc+JtWpe38HX8inIap6d0AJEJrcyZPkK h3Qdw/jTqfoJIgoLaHEu/EAMUT2hjStCIWcq3Y5zFh9reT4fTSSrwjnshHUZxqGuZ/IR ab50h4SlFEWxSwnuEkU31kNRzWTLPKA3+17FHbwehmHRZUSev93T4bRs41Xn20KZa5f/ k+80ZzSZSBVJNiqh5lPqG+WTe/9rA/2TI2Gt1FZE+QwLt2p35J9kdMNTU4EIZ3y3vqnR TpgW/mpTu0C6rq+rEHHXIKx8gtZguIh5pBmmeNle5/qhHXl4b/ffhhk+FekGQUfrAxbH /Fdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="EJknILA/"; spf=pass (google.com: domain of linux-kernel+bounces-19461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n21-20020a0561023ed500b00466fea13693si721752vsv.153.2024.01.08.04.01.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 04:01:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="EJknILA/"; spf=pass (google.com: domain of linux-kernel+bounces-19461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19461-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3D37F1C21FF0 for ; Mon, 8 Jan 2024 12:01:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D4182941B; Mon, 8 Jan 2024 12:01:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="EJknILA/" X-Original-To: linux-kernel@vger.kernel.org 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 E52F424B44; Mon, 8 Jan 2024 12:01:17 +0000 (UTC) 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=1704715263; 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=EJknILA/HcKeDAL+7bQrURFIu+gP9lVq+/v4qUkcgDZvksaoRrwtu5A38lq0FNq3QBtxEV ompQuhN94wCW3HbKR7KvZuWRG9E0cifTT1ZcaZPQIyVvV3DELCVMJqbc3VobOa9OzmVcFB MNsdzO4yEXjkqXxXizWm6M6a92ciaLg= From: Paul Cercueil To: Greg Kroah-Hartman , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jonathan Corbet Cc: Jonathan Cameron , =?UTF-8?q?Nuno=20S=C3=A1?= , Michael Hennerich , Andrzej Pietrasiewicz , 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 Subject: [PATCH v3 1/4] usb: gadget: Support already-mapped DMA SGs Date: Mon, 8 Jan 2024 13:00:53 +0100 Message-ID: <20240108120056.22165-2-paul@crapouillou.net> In-Reply-To: <20240108120056.22165-1-paul@crapouillou.net> References: <20240108120056.22165-1-paul@crapouillou.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes 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 --- 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; void (*complete)(struct usb_ep *ep, struct usb_request *req); -- 2.43.0