From patchwork Fri Feb 23 12:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuno Sa X-Patchwork-Id: 13568983 Received: from mx0b-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D2257AE49; Fri, 23 Feb 2024 12:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708690302; cv=none; b=NRoK6Y06kvV6B2pWOrNjvsD5/KR6aZaUq69cGAG+bZaO8PHFb3dy0L99XqoFuTwQloTm72IwswgQo0ZD1EhTeIeN/Z2G3t7Ocixy0EM+5rp1zuUxwCQE8ZPmHEFZiuY4uGpxpiGj3bLGy76TxP7G0aq76jUCWsZqWLjJCiMGsiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708690302; c=relaxed/simple; bh=8vcHO36tMvJBYaQIg4kg4jsGX60/0ns6Wz2DI00SNZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=WhV4msqRe7TGb5rUZERAfNCfJMs4c8XnxpyME5RDUB/L+uOJy4Qap+jJb92MAtNU+89WfsFWFdNeOO3sQxEM1RcDem3QpzWpqQeda4DsGsSljvIg6YU9oWvbZZ6A/gE+T8U/oqPw+nit62uVH0kAjmsmzvlJIzLomSecpVvRguc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=Aee7tjMf; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="Aee7tjMf" Received: from pps.filterd (m0375855.ppops.net [127.0.0.1]) by mx0b-00128a01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41N6rkhQ030398; Fri, 23 Feb 2024 07:11:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=DKIM; bh=AHL9wuZ6NjAgHU9tTrQaaKgchoFJtL2nAbstE08xuHs=; b= Aee7tjMfJUe2n8cNf2gV7bNvGqxjeQlBYyTM15UR+G1ryLukG0/VoYkqYlP/Ycm8 oKvPkvC84x1f9/4OzGF7Tuy5z0ECOQc+z4pZAm1aHJETE6+Rx7mmj+TMb0WJAMDe 3jTUgBuA9FaWbRhATgkq1NUl//ek/XdnISgeowlbtTIESdfAs/r2dFO4wwo5P0kb CUB2tKIyO3mUUzKppTxWXk7a8bx8aX9AuH3268UpNBTQKjpxGYR7Eqtcd61nzKcs e/N+BpWbFt/vShd3U9j8JlDM78ucouCEoTVvOR6G7xwaVExRdOt98IS13KRctAp0 neH4navW9bgpH2WE98RuDg== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0b-00128a01.pphosted.com (PPS) with ESMTPS id 3wepgc11p5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 07:11:22 -0500 (EST) Received: from ASHBMBX8.ad.analog.com (ASHBMBX8.ad.analog.com [10.64.17.5]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 41NCB3Gm033116 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 23 Feb 2024 07:11:03 -0500 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 23 Feb 2024 07:11:02 -0500 Received: from ASHBMBX8.ad.analog.com (10.64.17.5) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Fri, 23 Feb 2024 07:11:02 -0500 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx8.ad.analog.com (10.64.17.5) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Fri, 23 Feb 2024 07:10:59 -0500 Received: from [127.0.0.1] ([10.44.3.55]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 41NCAb2S032246; Fri, 23 Feb 2024 07:10:51 -0500 From: Nuno Sa Date: Fri, 23 Feb 2024 13:13:59 +0100 Subject: [PATCH v7 1/6] dmaengine: Add API function dmaengine_prep_peripheral_dma_vec() Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <20240223-iio-dmabuf-v7-1-78cfaad117b9@analog.com> References: <20240223-iio-dmabuf-v7-0-78cfaad117b9@analog.com> In-Reply-To: <20240223-iio-dmabuf-v7-0-78cfaad117b9@analog.com> To: Vinod Koul , Lars-Peter Clausen , Jonathan Cameron , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Jonathan Corbet , Paul Cercueil CC: Daniel Vetter , Michael Hennerich , , , , , , X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708690439; l=2947; i=nuno.sa@analog.com; s=20231116; h=from:subject:message-id; bh=ag6No3ZSM+lmtuBS6wzs/qMjBzxkWwhfjdlmQiYwcgs=; b=dwvhYkI5YsBjCVbMFP1XabWD3t9oj8z/gfq1KJseMZJtvEmltpzm4CXAJ+MPCUXb6A0sJ016h Aha7KPAfYnVBbtBUEjKgZW4qBv/nXAJ4tWws4E1L5rhpuZGXkrqrc0u X-Developer-Key: i=nuno.sa@analog.com; a=ed25519; pk=3NQwYA013OUYZsmDFBf8rmyyr5iQlxV/9H4/Df83o1E= X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-GUID: 6jgOSJmpuyY7Yo8w4haJMmbs8gpJa0uH X-Proofpoint-ORIG-GUID: 6jgOSJmpuyY7Yo8w4haJMmbs8gpJa0uH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 mlxlogscore=825 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402230088 From: Paul Cercueil This function can be used to initiate a scatter-gather DMA transfer, where the address and size of each segment is located in one entry of the dma_vec array. The major difference with dmaengine_prep_slave_sg() is that it supports specifying the lengths of each DMA transfer; as trying to override the length of the transfer with dmaengine_prep_slave_sg() is a very tedious process. The introduction of a new API function is also justified by the fact that scatterlists are on their way out. Note that dmaengine_prep_interleaved_dma() is not helpful either in that case, as it assumes that the address of each segment will be higher than the one of the previous segment, which we just cannot guarantee in case of a scatter-gather transfer. Signed-off-by: Paul Cercueil Signed-off-by: Nuno Sa --- include/linux/dmaengine.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 752dbde4cec1..856df8cd9a4e 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -160,6 +160,16 @@ struct dma_interleaved_template { struct data_chunk sgl[]; }; +/** + * struct dma_vec - DMA vector + * @addr: Bus address of the start of the vector + * @len: Length in bytes of the DMA vector + */ +struct dma_vec { + dma_addr_t addr; + size_t len; +}; + /** * enum dma_ctrl_flags - DMA flags to augment operation preparation, * control completion, and communicate status. @@ -910,6 +920,10 @@ struct dma_device { struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( struct dma_chan *chan, unsigned long flags); + struct dma_async_tx_descriptor *(*device_prep_peripheral_dma_vec)( + struct dma_chan *chan, const struct dma_vec *vecs, + size_t nents, enum dma_transfer_direction direction, + unsigned long prep_flags, unsigned long flags); struct dma_async_tx_descriptor *(*device_prep_slave_sg)( struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, enum dma_transfer_direction direction, @@ -973,6 +987,19 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single( dir, flags, NULL); } +static inline struct dma_async_tx_descriptor *dmaengine_prep_peripheral_dma_vec( + struct dma_chan *chan, const struct dma_vec *vecs, size_t nents, + enum dma_transfer_direction dir, unsigned long prep_flags, + unsigned long flags) +{ + if (!chan || !chan->device || !chan->device->device_prep_peripheral_dma_vec) + return NULL; + + return chan->device->device_prep_peripheral_dma_vec(chan, vecs, nents, + dir, prep_flags, + flags); +} + static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg( struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, enum dma_transfer_direction dir, unsigned long flags)