From patchwork Tue Dec 12 11:10:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 177252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7648430vqy; Tue, 12 Dec 2023 03:12:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IES1uB93HcSTyUKlmOn7wnJKrkFy3v8zMF39InDpwf0pthJ7oe2BV3oRMM7je6sRPGD8D/I X-Received: by 2002:a05:6a00:8b01:b0:6ce:38fd:5124 with SMTP id if1-20020a056a008b0100b006ce38fd5124mr2123864pfb.60.1702379557057; Tue, 12 Dec 2023 03:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702379557; cv=none; d=google.com; s=arc-20160816; b=WIiBYpEn65HwI7Ij+nZdLUTJBb3pichPWNhC7BgXZFoRsU1Eb4B0dwzOmEwRmeo0bF 1BI1lT5wRfRbrjhB+VjlX36eOkExqXro5K5+1TGLCDKqo/ls3+DrWdUvONghygCXEwwQ lvBZqJlx1k8PX2iDLMBrlKCZvlRnxOcl7Htux8mI4f1O+NgRzq77W+ih5lbp6nSErU4K nbwGiURUJFwb98aekLefdx17T+8xZl2Zu8QD3Egzdxo/gul2dCVu+l2N1rWs0F6uOXVY Ew5Cnjs71ye/6KJMPOSuRwHr8DwMwe4XJooyAegXAv9LXN4C7AVJEql180N/vkC9gDC9 MyCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PvkANg04A2utzuZAggw+6HPpsozwSzDkEwa7BpI7mhM=; fh=kWHopdWuWktDcnjSO11R7sPQi0EWg865jqRuCsOPYXE=; b=dH3+RpPfrOrYYGCE7ov3NQXd8PBYL1f4EID7zPWyhO9gz6YugsiR/v6TyIL4oQ6mAH xwBXmiG7waRP+TIvrobinL/tiphg3xwhORo7pVaLcUGee1ujv0te4JWsBvX5deE3uKBW 3Fe9vqJT7TFSETStZAE+ioR6yK5S0rj/ceVoX0OWkRpxQ6Nntw8BtvxCwYhm3QMLQC8+ pP0j9fLSVqM231nxlJ1XeH3kmPKb/wK7CXYeRyp9jQ5opkzFoXPSW7k5gQjC9/UmN61A 9iZdPAi8x8eye3ejmBMoz5CJeY9FLdwak4JFf2QeacwcPyjhAPrXzHHs1p7JWvo3uA6B hO7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=ym91uVEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id s6-20020a6550c6000000b005b8f61fcba6si7261091pgp.452.2023.12.12.03.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 03:12:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=ym91uVEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 537CE8072A04; Tue, 12 Dec 2023 03:12:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235130AbjLLLMR (ORCPT + 99 others); Tue, 12 Dec 2023 06:12:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235134AbjLLLLz (ORCPT ); Tue, 12 Dec 2023 06:11:55 -0500 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E861136; Tue, 12 Dec 2023 03:10:44 -0800 (PST) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 3BCBAO3k031728; Tue, 12 Dec 2023 05:10:24 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1702379424; bh=PvkANg04A2utzuZAggw+6HPpsozwSzDkEwa7BpI7mhM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ym91uVEHlmGoLgfFRoymYYV8JwoBCkTjoSt/EI8c1RgQbl45K32fRnzC4Wt0RbzDY KKI0drNj4qBwG608Ifbcbsyu4NAiO7htNe7dbc4hncl7ZtRXu9GC36TivlHOAPNVG2 LAN2iXgLKFvn82rgj0y024NW87VUluaSf8xc9f54= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 3BCBAOHW043985 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 12 Dec 2023 05:10:24 -0600 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 12 Dec 2023 05:10:24 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 12 Dec 2023 05:10:24 -0600 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [172.24.227.9]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 3BCBABA1088764; Tue, 12 Dec 2023 05:10:22 -0600 From: Siddharth Vadapalli To: , CC: , , , , , Subject: [PATCH v2 4/4] dmaengine: ti: k3-udma-glue: Add function to request RX channel by ID Date: Tue, 12 Dec 2023 16:40:11 +0530 Message-ID: <20231212111011.1401641-5-s-vadapalli@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212111011.1401641-1-s-vadapalli@ti.com> References: <20231212111011.1401641-1-s-vadapalli@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Dec 2023 03:12:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785074346390851542 X-GMAIL-MSGID: 1785074346390851542 The existing function k3_udma_glue_request_remote_rx_chn() supports requesting an RX DMA channel and flow by the name of the RX DMA channel. Add support to request RX channel by ID in the form of a new function k3_udma_glue_request_remote_rx_chn_by_id() and export it for use by drivers which are probed by alternate methods (non device-tree) but still wish to make use of the existing DMA APIs. Such drivers could be informed about the RX channel to use by RPMsg for example. Since the implementation of k3_udma_glue_request_remote_rx_chn_by_id() reuses most of the code in k3_udma_glue_request_remote_rx_chn(), create a new function k3_udma_glue_request_remote_rx_chn_common() for the common code. Signed-off-by: Siddharth Vadapalli --- Changes since v1: - Updated commit message indicating the use-case for which the patch is being added. drivers/dma/ti/k3-udma-glue.c | 136 ++++++++++++++++++++++--------- include/linux/dma/k3-udma-glue.h | 4 + 2 files changed, 101 insertions(+), 39 deletions(-) diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c index ea5119a5e8eb..996614b60675 100644 --- a/drivers/dma/ti/k3-udma-glue.c +++ b/drivers/dma/ti/k3-udma-glue.c @@ -1072,52 +1072,21 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name, return ERR_PTR(ret); } -static struct k3_udma_glue_rx_channel * -k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name, - struct k3_udma_glue_rx_channel_cfg *cfg) +static int +k3_udma_glue_request_remote_rx_chn_common(struct k3_udma_glue_rx_channel *rx_chn, + struct k3_udma_glue_rx_channel_cfg *cfg, + struct device *dev) { - struct k3_udma_glue_rx_channel *rx_chn; int ret, i; - if (cfg->flow_id_num <= 0 || - cfg->flow_id_use_rxchan_id || - cfg->def_flow_cfg || - cfg->flow_id_base < 0) - return ERR_PTR(-EINVAL); - - /* - * Remote RX channel is under control of Remote CPU core, so - * Linux can only request and manipulate by dedicated RX flows - */ - - rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); - if (!rx_chn) - return ERR_PTR(-ENOMEM); - - rx_chn->common.dev = dev; - rx_chn->common.swdata_size = cfg->swdata_size; - rx_chn->remote = true; - rx_chn->udma_rchan_id = -1; - rx_chn->flow_num = cfg->flow_id_num; - rx_chn->flow_id_base = cfg->flow_id_base; - rx_chn->psil_paired = false; - - /* parse of udmap channel */ - ret = of_k3_udma_glue_parse_chn(dev->of_node, name, - &rx_chn->common, false); - if (ret) - goto err; - rx_chn->common.hdesc_size = cppi5_hdesc_calc_size(rx_chn->common.epib, rx_chn->common.psdata_size, rx_chn->common.swdata_size); rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num, sizeof(*rx_chn->flows), GFP_KERNEL); - if (!rx_chn->flows) { - ret = -ENOMEM; - goto err; - } + if (!rx_chn->flows) + return -ENOMEM; rx_chn->common.chan_dev.class = &k3_udma_glue_devclass; rx_chn->common.chan_dev.parent = xudma_get_device(rx_chn->common.udmax); @@ -1128,7 +1097,7 @@ k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name, dev_err(dev, "Channel Device registration failed %d\n", ret); put_device(&rx_chn->common.chan_dev); rx_chn->common.chan_dev.parent = NULL; - goto err; + return ret; } if (xudma_is_pktdma(rx_chn->common.udmax)) { @@ -1140,19 +1109,108 @@ k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name, ret = k3_udma_glue_allocate_rx_flows(rx_chn, cfg); if (ret) - goto err; + return ret; for (i = 0; i < rx_chn->flow_num; i++) rx_chn->flows[i].udma_rflow_id = rx_chn->flow_id_base + i; k3_udma_glue_dump_rx_chn(rx_chn); + return 0; +} + +static struct k3_udma_glue_rx_channel * +k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name, + struct k3_udma_glue_rx_channel_cfg *cfg) +{ + struct k3_udma_glue_rx_channel *rx_chn; + int ret; + + if (cfg->flow_id_num <= 0 || + cfg->flow_id_use_rxchan_id || + cfg->def_flow_cfg || + cfg->flow_id_base < 0) + return ERR_PTR(-EINVAL); + + /* + * Remote RX channel is under control of Remote CPU core, so + * Linux can only request and manipulate by dedicated RX flows + */ + + rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); + if (!rx_chn) + return ERR_PTR(-ENOMEM); + + rx_chn->common.dev = dev; + rx_chn->common.swdata_size = cfg->swdata_size; + rx_chn->remote = true; + rx_chn->udma_rchan_id = -1; + rx_chn->flow_num = cfg->flow_id_num; + rx_chn->flow_id_base = cfg->flow_id_base; + rx_chn->psil_paired = false; + + /* parse of udmap channel */ + ret = of_k3_udma_glue_parse_chn(dev->of_node, name, + &rx_chn->common, false); + if (ret) + goto err; + + ret = k3_udma_glue_request_remote_rx_chn_common(rx_chn, cfg, dev); + if (ret) + goto err; + + return rx_chn; + +err: + k3_udma_glue_release_rx_chn(rx_chn); + return ERR_PTR(ret); +} + +struct k3_udma_glue_rx_channel * +k3_udma_glue_request_remote_rx_chn_by_id(struct device *dev, struct device_node *udmax_np, + struct k3_udma_glue_rx_channel_cfg *cfg, u32 thread_id) +{ + struct k3_udma_glue_rx_channel *rx_chn; + int ret; + + if (cfg->flow_id_num <= 0 || + cfg->flow_id_use_rxchan_id || + cfg->def_flow_cfg || + cfg->flow_id_base < 0) + return ERR_PTR(-EINVAL); + + /* + * Remote RX channel is under control of Remote CPU core, so + * Linux can only request and manipulate by dedicated RX flows + */ + + rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL); + if (!rx_chn) + return ERR_PTR(-ENOMEM); + + rx_chn->common.dev = dev; + rx_chn->common.swdata_size = cfg->swdata_size; + rx_chn->remote = true; + rx_chn->udma_rchan_id = -1; + rx_chn->flow_num = cfg->flow_id_num; + rx_chn->flow_id_base = cfg->flow_id_base; + rx_chn->psil_paired = false; + + ret = of_k3_udma_glue_parse_chn_by_id(udmax_np, &rx_chn->common, false, thread_id); + if (ret) + goto err; + + ret = k3_udma_glue_request_remote_rx_chn_common(rx_chn, cfg, dev); + if (ret) + goto err; + return rx_chn; err: k3_udma_glue_release_rx_chn(rx_chn); return ERR_PTR(ret); } +EXPORT_SYMBOL_GPL(k3_udma_glue_request_remote_rx_chn_by_id); struct k3_udma_glue_rx_channel * k3_udma_glue_request_rx_chn(struct device *dev, const char *name, diff --git a/include/linux/dma/k3-udma-glue.h b/include/linux/dma/k3-udma-glue.h index 6205d84430ca..89dc59d7c5e2 100644 --- a/include/linux/dma/k3-udma-glue.h +++ b/include/linux/dma/k3-udma-glue.h @@ -113,6 +113,10 @@ struct k3_udma_glue_rx_channel *k3_udma_glue_request_rx_chn( const char *name, struct k3_udma_glue_rx_channel_cfg *cfg); +struct k3_udma_glue_rx_channel * +k3_udma_glue_request_remote_rx_chn_by_id(struct device *dev, struct device_node *udmax_np, + struct k3_udma_glue_rx_channel_cfg *cfg, u32 thread_id); + void k3_udma_glue_release_rx_chn(struct k3_udma_glue_rx_channel *rx_chn); int k3_udma_glue_enable_rx_chn(struct k3_udma_glue_rx_channel *rx_chn); void k3_udma_glue_disable_rx_chn(struct k3_udma_glue_rx_channel *rx_chn);