Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1030026rdb; Fri, 19 Jan 2024 06:15:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlJhPAX/hEJpkEyofIyaKTiKwYhmrg2nMXrXGo0Ydc39DbRYOACK5xjCyffypwPLg+vhIy X-Received: by 2002:aa7:d704:0:b0:55a:6be7:b24b with SMTP id t4-20020aa7d704000000b0055a6be7b24bmr216280edq.32.1705673752773; Fri, 19 Jan 2024 06:15:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705673752; cv=pass; d=google.com; s=arc-20160816; b=sFqkkYDmpULb64r6fC1lc5tEEhiV55c7tnVAc4WYYo8cd4Kidd5PPl/CKXHyAW09tl gIpVpEh4JUg2BqqGkjbO8LEYFkmYtcHwpibvhHvnn00gVSs2Ps9lJEn5ztBZOKxEgnac Yxh8xxSpkxXotQKKjngpRoI190VkGUmxZuJraraUdqRpd+tQ38dr0v4Yab7UUxK+d1Y+ FXtlI/ZukCgsnh6NhzIwQh3atirlTharp/exnUS7EioLwFrdkf5jdLR4FLv+ksANcv9V cqu6i8vyR9HjI1u66tDZki/yVdXvXMJ9oRKcQRpA0GPoMe3Sy7NUJAFloyzdLHQNMAxA vM4g== 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=qa/33Z1AXHLQT39I1xDt/AX4AkPqz5LW8Qa+TK+D2ngOCs1g4ZCQ2bxeFDXcvvg1qw qkOILbwfcO7r3UkacJIq2tgnVTUqownwRb/NeytCbr+mbmqRW0tjGQjhd/i8pWhn1Jo1 69PoMs2y4IpgacCsfAiSas6aJ3gkCWvXsIxdludZMjTE7zjPsRmRmgphUubKUAKTsKJw W4w5ABkIM0mAEc2A1tMSEzJATXtkJSifjIT5TyqPmNtJFFNjab+Zb5Nh3O//pPYV09QV oD1ga8E+MKOejemiO0EhIM4JYjim3S+iyC3W9UzOB7z0mVdRrrQcYMK1eh0xThGhGqwH ajog== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=NaAbiMYN; 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-31250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31250-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 fd2-20020a056402388200b005597f92d6b4si4180423edb.325.2024.01.19.06.15.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 06:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31250-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=NaAbiMYN; 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-31250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31250-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 895811F2594D for ; Fri, 19 Jan 2024 14:15:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C33ED54BE8; Fri, 19 Jan 2024 14:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="NaAbiMYN" 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 9302B54BDA; Fri, 19 Jan 2024 14:14:37 +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=1705673679; cv=none; b=t2vxTBkqMT5MoeHGKhCGDSStnu+9XH+1DaBhRQyuomgcqrxAArmir9uofvigAtnuLjpwB9LR8BY059iMqJ8/0amqo/oJwXFCgNLqfqdne/vuqCsbGf4OsSuy9DNbwQ/mfoBVH0u9a0DQV55+pWmX8S3OE3xTy/bYNEk3I3Q1bZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705673679; c=relaxed/simple; bh=66FzAt7nJpAY9ka7VMdHoplxE2iQOAZv1WQkaTZVLTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vov6kZmDQcwsHtgGMLT70DKSoRwH3xXRrb/EvGYmLsh9KEIoN66Fdebv6h0qhgqvmh1ZQeEZyBZzewr1JdUEwCbjMXnzhVMoto0EOtBdQQiSeizpvhbAdhnGgAO22qYgyl2XWkT5LRoXUDs0DGJG6ImUfFE+MoBFJM+YCiD1pg4= 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=NaAbiMYN; 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=1705673653; 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=NaAbiMYNA0AFJ1EOYLqs/WsQDOJFW4kjOTy5BHngcJ3g7fQNN1JRmaxyrKqwxaeT10DLx6 T/t9sAqiAQOdlMHR4xSm/2PaVYL5NNRDZmkExUzP1K+6bXsSsg+vJUIOe7o66dFXNKxz1T BAnGgTqNlP4vbEWAzuO4NKw3WXxW5dY= From: Paul Cercueil To: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: Jonathan Cameron , =?UTF-8?q?Nuno=20S=C3=A1?= , 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, Paul Cercueil Subject: [PATCH v5 3/6] usb: gadget: Support already-mapped DMA SGs Date: Fri, 19 Jan 2024 15:13:59 +0100 Message-ID: <20240119141402.44262-4-paul@crapouillou.net> In-Reply-To: <20240119141402.44262-1-paul@crapouillou.net> References: <20240119141402.44262-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