From nobody Thu Oct 9 02:19:10 2025 Received: from fllvem-ot04.ext.ti.com (fllvem-ot04.ext.ti.com [198.47.19.246]) (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 50EE81CCEE0; Mon, 23 Jun 2025 05:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.246 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750657088; cv=none; b=PSZcLV+12F72GZFGTJVtCa38L2s7MIwQjL3Ty/I80uTng4y2swUr38RhYNckyvqRJEeV6A5KiEZJqZkWXLnJ+cfdXKQwH4V9963iYzL7SQP/0IaZKR1UQouiC9Dpt+Bfl/e8Ip4OHFPzVTFwym35RHJr/AXw7ZqIp9NEGx1wenU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750657088; c=relaxed/simple; bh=rxoDgLTuIkBhIi6wMwE935f4rsRaviT9U8zNctx0XD8=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t5r3DLrjw7E3zvadgWn6nm3N6rTLUVlz18/EGEtI4ZdbgPF4Bc0jXVY49pb3ZX6tGWEdu8je9Olr+JekWM1gInbgycV6Ew/MLoMMsjyPWHaYIs9ZSwDJi7Y71PcpdXRS0ZQPqNlwwG7eeuKJTzag2mjb7x/PLc4fGJ/gHfDSa5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=U0F7dUdn; arc=none smtp.client-ip=198.47.19.246 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="U0F7dUdn" Received: from lelvem-sh01.itg.ti.com ([10.180.77.71]) by fllvem-ot04.ext.ti.com (8.15.2/8.15.2) with ESMTP id 55N5c0mJ1447391; Mon, 23 Jun 2025 00:38:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1750657080; bh=qPDu97suDP0aSdU3roBpwlaCvYP1s/VTci9lg7WXmio=; h=From:To:Subject:Date:In-Reply-To:References; b=U0F7dUdndBlXHXYdhNiby8gMMgpHZC2PMGuwpyILiwWFi/ElqognnRYI4T4KbEs3x +fS1Bt/1FiRewlqJGsoQUHjUdbvX/xab1C1PpVz/WZRpFR+d7VcYOPtKDUfpoERzHi 37mLyg915/Yz+qomlgG476dR9qGUfBUoxLvYbQ/8= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by lelvem-sh01.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 55N5c0BP183709 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Mon, 23 Jun 2025 00:38:00 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Mon, 23 Jun 2025 00:38:00 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55 via Frontend Transport; Mon, 23 Jun 2025 00:38:00 -0500 Received: from uda0498651.dhcp.ti.com (uda0498651.dhcp.ti.com [172.24.227.7]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 55N5bSqU3428603; Mon, 23 Jun 2025 00:37:55 -0500 From: Sai Sree Kartheek Adivi To: Peter Ujfalusi , Vinod Koul , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Nishanth Menon , Santosh Shilimkar , Sai Sree Kartheek Adivi , , , , , , , , , Subject: [PATCH v3 05/17] dmaengine: ti: k3-udma: move ring management functions to k3-udma-common.c Date: Mon, 23 Jun 2025 11:07:04 +0530 Message-ID: <20250623053716.1493974-6-s-adivi@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250623053716.1493974-1-s-adivi@ti.com> References: <20250623053716.1493974-1-s-adivi@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" Relocate the ring management functions such as push, pop, and reset from k3-udma.c to k3-udma-common.c file. These operations are common across multiple K3 UDMA variants and will be reused by future implementations like K3 UDMA v2. No functional changes intended. Signed-off-by: Sai Sree Kartheek Adivi --- drivers/dma/ti/k3-udma-common.c | 100 ++++++++++++++++++++++++++++++++ drivers/dma/ti/k3-udma.c | 100 -------------------------------- drivers/dma/ti/k3-udma.h | 4 ++ 3 files changed, 104 insertions(+), 100 deletions(-) diff --git a/drivers/dma/ti/k3-udma-common.c b/drivers/dma/ti/k3-udma-commo= n.c index 742edc0ea14db..384f0c7e0dc52 100644 --- a/drivers/dma/ti/k3-udma-common.c +++ b/drivers/dma/ti/k3-udma-common.c @@ -1229,3 +1229,103 @@ void udma_desc_pre_callback(struct virt_dma_chan *v= c, } } } + +int udma_push_to_ring(struct udma_chan *uc, int idx) +{ + struct udma_desc *d =3D uc->desc; + struct k3_ring *ring =3D NULL; + dma_addr_t paddr; + + switch (uc->config.dir) { + case DMA_DEV_TO_MEM: + ring =3D uc->rflow->fd_ring; + break; + case DMA_MEM_TO_DEV: + case DMA_MEM_TO_MEM: + ring =3D uc->tchan->t_ring; + break; + default: + return -EINVAL; + } + + /* RX flush packet: idx =3D=3D -1 is only passed in case of DEV_TO_MEM */ + if (idx =3D=3D -1) { + paddr =3D udma_get_rx_flush_hwdesc_paddr(uc); + } else { + paddr =3D udma_curr_cppi5_desc_paddr(d, idx); + + wmb(); /* Ensure that writes are not moved over this point */ + } + + return k3_ringacc_ring_push(ring, &paddr); +} + +int udma_pop_from_ring(struct udma_chan *uc, dma_addr_t *addr) +{ + struct k3_ring *ring =3D NULL; + int ret; + + switch (uc->config.dir) { + case DMA_DEV_TO_MEM: + ring =3D uc->rflow->r_ring; + break; + case DMA_MEM_TO_DEV: + case DMA_MEM_TO_MEM: + ring =3D uc->tchan->tc_ring; + break; + default: + return -ENOENT; + } + + ret =3D k3_ringacc_ring_pop(ring, addr); + if (ret) + return ret; + + rmb(); /* Ensure that reads are not moved before this point */ + + /* Teardown completion */ + if (cppi5_desc_is_tdcm(*addr)) + return 0; + + /* Check for flush descriptor */ + if (udma_desc_is_rx_flush(uc, *addr)) + return -ENOENT; + + return 0; +} + +void udma_reset_rings(struct udma_chan *uc) +{ + struct k3_ring *ring1 =3D NULL; + struct k3_ring *ring2 =3D NULL; + + switch (uc->config.dir) { + case DMA_DEV_TO_MEM: + if (uc->rchan) { + ring1 =3D uc->rflow->fd_ring; + ring2 =3D uc->rflow->r_ring; + } + break; + case DMA_MEM_TO_DEV: + case DMA_MEM_TO_MEM: + if (uc->tchan) { + ring1 =3D uc->tchan->t_ring; + ring2 =3D uc->tchan->tc_ring; + } + break; + default: + break; + } + + if (ring1) + k3_ringacc_ring_reset_dma(ring1, + k3_ringacc_ring_get_occ(ring1)); + if (ring2) + k3_ringacc_ring_reset(ring2); + + /* make sure we are not leaking memory by stalled descriptor */ + if (uc->terminated_desc) { + udma_desc_free(&uc->terminated_desc->vd); + uc->terminated_desc =3D NULL; + } +} diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c index 0a1291829611f..214a1ca1e1776 100644 --- a/drivers/dma/ti/k3-udma.c +++ b/drivers/dma/ti/k3-udma.c @@ -174,106 +174,6 @@ static bool udma_is_chan_paused(struct udma_chan *uc) return false; } =20 -static int udma_push_to_ring(struct udma_chan *uc, int idx) -{ - struct udma_desc *d =3D uc->desc; - struct k3_ring *ring =3D NULL; - dma_addr_t paddr; - - switch (uc->config.dir) { - case DMA_DEV_TO_MEM: - ring =3D uc->rflow->fd_ring; - break; - case DMA_MEM_TO_DEV: - case DMA_MEM_TO_MEM: - ring =3D uc->tchan->t_ring; - break; - default: - return -EINVAL; - } - - /* RX flush packet: idx =3D=3D -1 is only passed in case of DEV_TO_MEM */ - if (idx =3D=3D -1) { - paddr =3D udma_get_rx_flush_hwdesc_paddr(uc); - } else { - paddr =3D udma_curr_cppi5_desc_paddr(d, idx); - - wmb(); /* Ensure that writes are not moved over this point */ - } - - return k3_ringacc_ring_push(ring, &paddr); -} - -static int udma_pop_from_ring(struct udma_chan *uc, dma_addr_t *addr) -{ - struct k3_ring *ring =3D NULL; - int ret; - - switch (uc->config.dir) { - case DMA_DEV_TO_MEM: - ring =3D uc->rflow->r_ring; - break; - case DMA_MEM_TO_DEV: - case DMA_MEM_TO_MEM: - ring =3D uc->tchan->tc_ring; - break; - default: - return -ENOENT; - } - - ret =3D k3_ringacc_ring_pop(ring, addr); - if (ret) - return ret; - - rmb(); /* Ensure that reads are not moved before this point */ - - /* Teardown completion */ - if (cppi5_desc_is_tdcm(*addr)) - return 0; - - /* Check for flush descriptor */ - if (udma_desc_is_rx_flush(uc, *addr)) - return -ENOENT; - - return 0; -} - -static void udma_reset_rings(struct udma_chan *uc) -{ - struct k3_ring *ring1 =3D NULL; - struct k3_ring *ring2 =3D NULL; - - switch (uc->config.dir) { - case DMA_DEV_TO_MEM: - if (uc->rchan) { - ring1 =3D uc->rflow->fd_ring; - ring2 =3D uc->rflow->r_ring; - } - break; - case DMA_MEM_TO_DEV: - case DMA_MEM_TO_MEM: - if (uc->tchan) { - ring1 =3D uc->tchan->t_ring; - ring2 =3D uc->tchan->tc_ring; - } - break; - default: - break; - } - - if (ring1) - k3_ringacc_ring_reset_dma(ring1, - k3_ringacc_ring_get_occ(ring1)); - if (ring2) - k3_ringacc_ring_reset(ring2); - - /* make sure we are not leaking memory by stalled descriptor */ - if (uc->terminated_desc) { - udma_desc_free(&uc->terminated_desc->vd); - uc->terminated_desc =3D NULL; - } -} - static void udma_decrement_byte_counters(struct udma_chan *uc, u32 val) { if (uc->desc->dir =3D=3D DMA_DEV_TO_MEM) { diff --git a/drivers/dma/ti/k3-udma.h b/drivers/dma/ti/k3-udma.h index 7c807bd9e178b..4c6e5b946d5cf 100644 --- a/drivers/dma/ti/k3-udma.h +++ b/drivers/dma/ti/k3-udma.h @@ -610,6 +610,10 @@ void udma_desc_pre_callback(struct virt_dma_chan *vc, struct virt_dma_desc *vd, struct dmaengine_result *result); =20 +int udma_push_to_ring(struct udma_chan *uc, int idx); +int udma_pop_from_ring(struct udma_chan *uc, dma_addr_t *addr); +void udma_reset_rings(struct udma_chan *uc); + /* Direct access to UDMA low lever resources for the glue layer */ int xudma_navss_psil_pair(struct udma_dev *ud, u32 src_thread, u32 dst_thr= ead); int xudma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread, --=20 2.34.1