Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp970197rdb; Tue, 30 Jan 2024 04:24:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFG2saf2UeBhZ1R254RUVy1Pz9MT+qAyAcmgBXzlMzaeTfx7X2UzJTfYLjPTne3kH6AOkoO X-Received: by 2002:a17:902:e549:b0:1d8:fae3:21ea with SMTP id n9-20020a170902e54900b001d8fae321eamr2858112plf.61.1706617487410; Tue, 30 Jan 2024 04:24:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617487; cv=pass; d=google.com; s=arc-20160816; b=rm66+8867jQpMtJ16m7HMAhtigQkYMMu7K6sEj+tJVkGyQ7GmjccvQy8rQT9pepxOI 0zd6CZMiBLOGngbBgMh9M9q1uD3ekxbqC+KxJdeSPDgV+kJk8TbWT+sL0BmC+X4VnYdy rud2ODydyxdXeUPxqPsfponm0Tft63M2ignAw4oSDzd1hv5b/15+Gb6Am9dbTIoTFm8G Ct6E0X6otE0I+qx14DoYOu35puMfQsK+dZ4/zuQn00UwwDkXg6Pp12ei3pElK+vYhZHw /8h3ygbgdqs9Up7nCQGxKdi3iKmwKJuEad0U877CDtYwkBDhYf2kXGtUp5ZEV5Qd6Lyu NXSw== 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=rOwklx3n4HddILOil3p/QTffAKooJ/gOk0lSkLfkcvQ=; b=bUlBgPdU9fJxx6I5pJbMlSRZ5dpC0WVcnCdfOZl46VBaXQ/aaZE1cVoZ0hTeEGsdO7 beKbO0TVGiYkDJEtPIXnGSdyFMyjZSUEUoe5regFBW0Cz9cMhBtJr3pJ4mYJKA28NoDW jLhqtp3hGBMiWsFQZzAPxRFLobwFQ9DG/rgGHwnB/Y6iqpp0IZipKAGgIYw8+gYE5Ge0 5upm7+7OmXd2FnE+veePrdbXxDy/1stV98/Y0VHM1MCPfyIMS0XLYV2uXY2hrDUo6h8U 60QGUfIie2I/b6D761elx6KGZDGo/H5HEUoticr3XvFR4RWtr7FpGXrLWg0cHoBCVYcv 2HYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=uStG4m2O; 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-44596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44596-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b10-20020a170902d50a00b001d72c4b75d4si7295533plg.559.2024.01.30.04.24.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:24:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=uStG4m2O; 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-44596-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44596-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B3FDD2899AF for ; Tue, 30 Jan 2024 12:24:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 136F66A331; Tue, 30 Jan 2024 12:24:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="uStG4m2O" 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 B206167E9C; Tue, 30 Jan 2024 12:23:57 +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=1706617440; cv=none; b=NUOu7lHQqmJnEjS3w+D5AajlHIkzFLD1IsrzkVVLdCUe2//MQRZN9aiv6AE0kJHohR5Egx8uhMGWTKXpeKzvZQj3spmE50n8urcDlAUfrHBHg6v3HEumh3vd/u46elOpejjIqqGj3DO8FQllhbQrgWnuUjH37KZsj2b/54SwMzc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706617440; c=relaxed/simple; bh=66FzAt7nJpAY9ka7VMdHoplxE2iQOAZv1WQkaTZVLTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jNYstDiDeY2lAtcY3BsXlFC2k6xw59IVAIq3RgQ9Bh9kXP2KIyQY7heV35BMYFGZ2ynhKPKI/RsJb0DLN/Vsk2BJkID+yRDYLND1vQeNZbOb6Z0/VUpdbrWfMg1Xl2hBH/1vf0wofzciBj5mTk1S9cbJ7oNADKHBqeU7ilEX7es= 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=uStG4m2O; 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=1706617428; 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=uStG4m2OiYDXjAnbZhvlePwi6RCL5a65XfVMHf3kIDQFND4jkC6cwEBz0jaA9AW1MZbf1/ 2u/o3/68rPjN5owEZJ5rGx2hINs1wO31bHkjYDAEEB8LZF+afk4mDgWOr+EQfngv9sqZL3 QFrIivxNGWeocp6JrbECrSQlqQxE4YQ= From: Paul Cercueil To: Greg Kroah-Hartman , Jonathan Corbet , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: =?UTF-8?q?Nuno=20S=C3=A1?= , Jonathan Cameron , 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 v6 1/4] usb: gadget: Support already-mapped DMA SGs Date: Tue, 30 Jan 2024 13:23:37 +0100 Message-ID: <20240130122340.54813-2-paul@crapouillou.net> In-Reply-To: <20240130122340.54813-1-paul@crapouillou.net> References: <20240130122340.54813-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 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