From nobody Thu Oct 2 19:27:13 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 41FD7329F1F for ; Thu, 11 Sep 2025 22:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757628051; cv=none; b=jq7X3oI/WHj4ifb6ceC0fhpTyXKIXLt0htgm0r3tEHbIe1QlyksqXjQAdV8fLMjlFZhjZNOtIM1MfevqVaKjOb28RLLAxlOSK2b8kLeo2gCdDvUeq+QBxWmTMQSiurYxynI9w9UwsMLNHZqHdAHiOOrFGczcY9el9YiXUKRg6sg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757628051; c=relaxed/simple; bh=NMqZyM7F1/2gyalRZwDIJ+zvaEMeLaDzM/RD+zRYdRU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GTGJQnV6MrRT/UZaOfjRR5mbhXPFwjwhlBX2LJDPZ4IUy+EL/cMwLmxYZYTtPut15EscZaaXk0mP/sWkqk0cbC6JgR2WAcAsej97tYry8DKAz1qjHqzC5sFyXDOpDJTcmKlTNtSi2EOw5uehgs9z+3BpUG6jxv8yntj8nltx7Ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uwpLU-0005sG-L2; Fri, 12 Sep 2025 00:00:48 +0200 From: Marco Felsch Date: Fri, 12 Sep 2025 00:00:41 +0200 Subject: [PATCH 1/2] dmaengine: add device_link support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250912-v6-16-topic-dma-devlink-v1-1-4debc2fbf901@pengutronix.de> References: <20250912-v6-16-topic-dma-devlink-v1-0-4debc2fbf901@pengutronix.de> In-Reply-To: <20250912-v6-16-topic-dma-devlink-v1-0-4debc2fbf901@pengutronix.de> To: Vinod Koul , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Jiada Wang , Frank Li Cc: dmaengine@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Shift the device dependency handling to the driver core by adding support for devlinks. The link between the consumer device and the dmaengine device is established by the consumer via the dma_request_chan() automatically if the dmaengine driver supports it (create_devlink flag set). By adding the devlink support it is ensured that the supplier can't be removed while the consumer still uses the dmaengine. Furthermore it ensures that the supplier driver is present and actual bound before the consumer is uses the supplier. Additional PM and runtime-PM dependency handling can be added easily too by setting the required flags (not implemented by this commit). The new create_devlink flag controlls the devlink creation to not cause any regressions with existing dmaengine drivers. This flag can be removed once all drivers are successfully tested to support devlinks. Signed-off-by: Marco Felsch --- drivers/dma/dmaengine.c | 15 +++++++++++++++ include/linux/dmaengine.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 758fcd0546d8bde8e8dddc6039848feeb1e24475..e81985ab806ae87ff3aa4739fe6= f6328b2587f2e 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -858,6 +858,21 @@ struct dma_chan *dma_request_chan(struct device *dev, = const char *name) /* No functional issue if it fails, users are supposed to test before use= */ #endif =20 + /* + * Devlinks between the dmaengine device and the consumer device + * are optional till all dmaengine drivers are converted/tested. + */ + if (chan->device->create_devlink) { + struct device_link *dl; + + dl =3D device_link_add(dev, chan->device->dev, DL_FLAG_AUTOREMOVE_CONSUM= ER); + if (!dl) { + dev_err(dev, "failed to create device link to %s\n", + dev_name(chan->device->dev)); + return ERR_PTR(-EINVAL); + } + } + chan->name =3D kasprintf(GFP_KERNEL, "dma:%s", name); if (!chan->name) return chan; diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index bb146c5ac3e4ccd7bc0afbf3b28e5b3d659ad62f..c67737a358df659f2bf050a9ccb= 8d23b17ceb357 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -817,6 +817,8 @@ struct dma_filter { * DMA tansaction with no software intervention for reinitialization. * Zero value means unlimited number of entries. * @descriptor_reuse: a submitted transfer can be resubmitted after comple= tion + * @create_devlink: create a devlink between a dma_chan_dev supplier and + * dma-channel consumer device * @residue_granularity: granularity of the transfer residue reported * by tx_status * @device_alloc_chan_resources: allocate resources and return the @@ -894,6 +896,7 @@ struct dma_device { u32 max_burst; u32 max_sg_burst; bool descriptor_reuse; + bool create_devlink; enum dma_residue_granularity residue_granularity; =20 int (*device_alloc_chan_resources)(struct dma_chan *chan); --=20 2.47.3 From nobody Thu Oct 2 19:27:13 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (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 60870329F2B for ; Thu, 11 Sep 2025 22:00:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757628051; cv=none; b=FQZi8t7vWMg7UipF9+Ibtc3Y0KICRzmvgSEwmpIyjH874Jjf8JEbWqGSfzjNE5xQQjZ5giCmlq/b61j832/ztG3+uq8xpWvFSm3MfPzOiburG5DKHG0bNSTGShKToTyyJzcm+HXEX/C7vHc+L4yOZbcRFC+9i9KfuZFTPqwYpx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757628051; c=relaxed/simple; bh=BNKjLiMwo7xVG7m5N0r9qNaKtaldo4UnpNJT9EOqrg0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZCHkvBSA4iYkEkOdgG7vH5pvIEMCZJdrneqJxWrb9OMInKohmccMsxCHzwtLJz1+1pXmUJw47U9EC1gUa0ZFrA9UKRyCZI/Q8tZf533Nu6VlH+mAZlsvRwuIKn6/hpTD7OraZYlpv4EIXtVt5c4IDtvaQFBfWfZJ6lzBtdHYZ9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uwpLU-0005sG-Me; Fri, 12 Sep 2025 00:00:48 +0200 From: Marco Felsch Date: Fri, 12 Sep 2025 00:00:42 +0200 Subject: [PATCH 2/2] dmaengine: imx-sdma: fix supplier/consumer dependency handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250912-v6-16-topic-dma-devlink-v1-2-4debc2fbf901@pengutronix.de> References: <20250912-v6-16-topic-dma-devlink-v1-0-4debc2fbf901@pengutronix.de> In-Reply-To: <20250912-v6-16-topic-dma-devlink-v1-0-4debc2fbf901@pengutronix.de> To: Vinod Koul , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Jiada Wang , Frank Li Cc: dmaengine@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marco Felsch X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The whole driver was converted to the devm APIs except for this last for-loop. This loop is buggy due to three reasons: 1) It removes the channels without removing the users first. This can lead to very bad situations. 2) The loop starts at 0 and which is channel0 which is a special control channel not registered via vchan_init(). Therefore the remove() always Oops because of NULL pointer exception. 3) sdma_free_chan_resources() disable the clks unconditional without checking if the clks are enabled. This is done for all MAX_DMA_CHANNELS which hang the system if there is at least one unused channel. The first issue is fixed by making use of the dmaengine devlink support. The second issue is fixed by not doing anything on channel0. The last issue is also fixed by the devlink support because during the consumer teardown phase each requested channel is dropped accordingly so the dmaengine driver doesn't need to this. To sum-up, all issues are fixed by dropping the .remove() callback and let the frameworks do their job. Reviewed-by: Frank Li Signed-off-by: Marco Felsch --- drivers/dma/imx-sdma.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index d4430e6e56deda7de3538e42af7987a456957b43..a11317c8827297d1d6b8ddc0254= ecf549e486001 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -2393,6 +2393,7 @@ static int sdma_probe(struct platform_device *pdev) sdma->dma_device.device_prep_dma_memcpy =3D sdma_prep_memcpy; sdma->dma_device.device_issue_pending =3D sdma_issue_pending; sdma->dma_device.copy_align =3D 2; + sdma->dma_device.create_devlink =3D true; dma_set_max_seg_size(sdma->dma_device.dev, SDMA_BD_MAX_CNT); =20 platform_set_drvdata(pdev, sdma); @@ -2432,25 +2433,11 @@ static int sdma_probe(struct platform_device *pdev) return 0; } =20 -static void sdma_remove(struct platform_device *pdev) -{ - struct sdma_engine *sdma =3D platform_get_drvdata(pdev); - int i; - - /* Kill the tasklet */ - for (i =3D 0; i < MAX_DMA_CHANNELS; i++) { - struct sdma_channel *sdmac =3D &sdma->channel[i]; - - sdma_free_chan_resources(&sdmac->vc.chan); - } -} - static struct platform_driver sdma_driver =3D { .driver =3D { .name =3D "imx-sdma", .of_match_table =3D sdma_dt_ids, }, - .remove =3D sdma_remove, .probe =3D sdma_probe, }; =20 --=20 2.47.3