From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795520765; b=I/NWGjOZpzOCU4RSjpn0ziJDlPn6HRuHyH1pF1BTf4+rtrASQ/Amk4IXhQlCLTQoo2Qh ZvxhingHSEyosxlyIHIsIk9owZoFzqRbuWaMtvMuCtpEGCWTq8a0yGwvaTVQzcLU8F3c8 VMGM/EdJwWl9Jl9KP+5YMrYBeR5ElsIhF3HqOCHNRLW6cmoc1CBTm7Eo0GIWWYVIzbVO/ Z+Dm/YWAUwCxJL2jXVSUUHsa2Ge+dwbaTZjFlCWqcCXsym1qW/e/A87BAIZWXcJD9D9y+ 3id2ysyeYlGE+OlsWOEDrijLr2OlSilOjVidHHeEZrun0M7x6k6WgvvDGVg9St+vn6Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795520765; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=gSX1BW3kAPgIaGk9mATBn5DBpE41plDztfRufi9tKrM=; b=B80r/sGKWL9mE4udx2IAo3gM8aFSJ6dQmzhACZqHoxkipeLPwUIp3QB+QD5sQ5bUiO5u YtLUWTqq7YoHlRRFQjM7CYiPUB1qgC+cBRLOd2yMmNvwPj+3tsnuiUcJz49J2/l9Gw4yK bGMiZL1MD65BeFnlVe9LuSVNCK7/kv1TEf9HqEHaLxaAqzL48EaOjFHX2dzXTjszLZ5G6 dSYwBpfrIkHd7YJLVOIcGIHMMn6jRhSeCmibZOkKVetYjvi/vmKCz4hePPp8lYZ+9TYAL kPBpGmux4E6QhQxJySOrdEQBj/viQG4Cf85aLr7ekHZwrfSVe46qNOshaEJQYpvm0wg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GksH3kAe; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A395160A3806; Tue, 24 Nov 2026 11:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GksH3kAe Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795520765; b=Y3JHBehKaq41q4W672Q5CIE2ulL0kTYPkWpFamySEHJDF5uCbE9AXEBety2bZ0k2dLDU UpU7/6dXjlxTxrwKnoXnfojVDMmn0xJbuUNUL+oI/LKyvYXTeBIvXObJL3OnS3/VSpq0I yTeh+GAXkG6Dhc9MFQsMPb3aHAqvBT6GYdfB2XUquzy4+BlkZLAHzscvmcVXft0h4RAeG A/gYrQg+pkZ9SfsoM8hQ6S6QRuXWjOCiDqq537m32CPMLsGCEQR12/aMdt4+S4+rP1quE Cf4QlGddLjKAWVHEWBRzLNe1FQ/gGRsdb5zyKmnj8SKPSa4yL6nn1ov2YDI6NPoz9VA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795520765; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=gSX1BW3kAPgIaGk9mATBn5DBpE41plDztfRufi9tKrM=; b=Fd8iqPCMFmUKMXWstnrUnLCC8QRSwcjxnpBqDw2w6100ps/y+mVeQvusF5xxvvq9jGzS MR+fZuB11hRdBoMgwAUwh3t87xFu9RkQPPpwIEitWA50M/KqxYvD+dFnxaYtCnWPGTuEl cx7FZ1koNz5VZTkiqLx8rpXht+vVcG4znmvj45fbyqAXobgayKHzG/FULC6PEqm+QGxAz UwRbmXChT6iePznzKO1UjMUWge5WINZJQ+OsXr/UqyH0gx6lBvMtVxOdQJ2gTxUAnXdfP oJ4rap5HBinR9WJSZ517ruvURqy9xRMoTfIDDdOSkYMXUx6etKlF3kC6Vl7Kd7fxfPA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id DAE6A1F000E0; Tue, 24 Nov 2026 11:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795520765; bh=gSX1BW3kAPgIaGk9mATBn5DBpE41plDztfRufi9tKrM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=GksH3kAeFI5QR670r//NFZcosU3jz7rsj1uJCxPkk9LFJsXQhOOEIxaYcVfDwN634 bTQ6Q8rx8TBaHbzW3K0Sx5aUs3iqiqgTgPYvIQu8iuOKZ32q8+5MLD3z6/j1v4G0VG oIH1KqOhdLT2el/AMG3QnsjaJQrikyDZX68o2jfNYMmJZmo+Z1fAmmLDRboy2zKFoI S21BlvTixKDa4OgmQ9dL8PEe7ND7HeqU5XaX+N1UiyEPRRQbc8xCbx+16RWcd4vWDK 3MWb8MXyQYrGRpmHsJkJ4XYFMM5M6QSSPRr7BN9kP/nC5EuN+U4tFgICt7KRh1YpU9 OFUnm05nIPGxA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id D297D4CA2F; Tue, 24 Nov 2026 11:45:28 +0000 (UTC) From: Sai Sree Kartheek Adivi via B4 Relay Date: Tue, 24 Nov 2026 17:15:20 +0530 Subject: [PATCH v13 18/20] dmaengine: ti: k3-udma-v2: Add support for PKTDMA V2 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261124-dma-upstream-v13-v13-18-bd4251fdc6d4@ti.com> References: <20261124-dma-upstream-v13-v13-0-bd4251fdc6d4@ti.com> In-Reply-To: <20261124-dma-upstream-v13-v13-0-bd4251fdc6d4@ti.com> To: Vignesh Raghavendra , Vinod Koul , Frank Li , Peter Ujfalusi , Nishanth Menon , Santosh Shilimkar , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, sebin.francis@ti.com, Sai Sree Kartheek Adivi X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795520724; l=16049; i=s-adivi@ti.com; s=20261124; h=from:subject:message-id; bh=zFe7iCIGOT1KnIa0m2SMT4geGBLUn0/bCkZlpzZa5GA=; b=G9NI5G1KBQ435wJ7DED4bDRmN8u78af6Tguynh7Sz2EwBY/cNOkvoxJKVlMoYdzUTgaro4+/w P5lhEHVLqA/AKPEkmlfIOwZsl41Ry+v+xBUaT61deZ6xEayFrijP876 X-Developer-Key: i=s-adivi@ti.com; a=ed25519; pk=EtOwVxmXDuYMgw3DqFtPDBpf8ZvbO89w1fJm4w5yPI8= X-Endpoint-Received: by B4 Relay for s-adivi@ti.com/20261124 with auth_id=1627 X-Original-From: Sai Sree Kartheek Adivi Reply-To: s-adivi@ti.com Content-Transfer-Encoding: 7bit From: Sai Sree Kartheek Adivi The PKTDMA V2 is different than the existing PKTDMA supported by the k3-udma driver. The changes in PKTDMA V2 are: - Autopair: There is no longer a need for PSIL pair and AUTOPAIR bit needs to set in the RT_CTL register. - Static channel mapping: Each channel is mapped to a single peripheral. - Direct IRQs: There is no INT-A and interrupt lines from DMA are directly connected to GIC. - Remote side configuration handled by DMA. So no need to write to PEER registers to START / STOP / PAUSE / TEARDOWN. - Unified Channel Space: Tx and Rx channels share a single register space. Each channel index is specifically fixed in hardware as either Tx or Rx in an interleaved manner. Reviewed-by: Vignesh Raghavendra Signed-off-by: Sai Sree Kartheek Adivi --- drivers/dma/ti/k3-udma-common.c | 33 ++++-- drivers/dma/ti/k3-udma-glue.c | 23 ++++ drivers/dma/ti/k3-udma-private.c | 22 +++- drivers/dma/ti/k3-udma-v2.c | 236 ++++++++++++++++++++++++++++++++++++--- drivers/dma/ti/k3-udma.h | 3 + 5 files changed, 291 insertions(+), 26 deletions(-) diff --git a/drivers/dma/ti/k3-udma-common.c b/drivers/dma/ti/k3-udma-common.c index 42d918c6ba168..42c4064d72b4f 100644 --- a/drivers/dma/ti/k3-udma-common.c +++ b/drivers/dma/ti/k3-udma-common.c @@ -2496,8 +2496,15 @@ static int pktdma_setup_resources(struct udma_dev *ud) ud->tchan_map = devm_bitmap_zalloc(dev, ud->tchan_cnt, GFP_KERNEL); ud->tchans = devm_kzalloc_objs(dev, *ud->tchans, ud->tchan_cnt); - ud->rchan_map = devm_bitmap_zalloc(dev, ud->rchan_cnt, GFP_KERNEL); - ud->rchans = devm_kzalloc_objs(dev, *ud->rchans, ud->rchan_cnt); + if (ud->match_data->version == K3_UDMA_V1) { + ud->rchan_map = devm_bitmap_zalloc(dev, ud->rchan_cnt, GFP_KERNEL); + ud->rchans = devm_kzalloc_objs(dev, *ud->rchans, ud->rchan_cnt); + } else { + ud->rchan_map = ud->tchan_map; + ud->rchans = ud->tchans; + ud->chan_map = ud->tchan_map; + ud->chans = ud->tchans; + } ud->rflow_in_use = devm_kzalloc_objs(dev, unsigned long, BITS_TO_LONGS(ud->rflow_cnt)); ud->rflows = devm_kzalloc_objs(dev, *ud->rflows, ud->rflow_cnt); @@ -2600,13 +2607,21 @@ int k3_udma_setup_resources(struct udma_dev *ud) } break; case DMA_TYPE_PKTDMA: - dev_info(dev, - "Channels: %d (tchan: %u, rchan: %u)\n", - ch_count, - ud->tchan_cnt - bitmap_weight(ud->tchan_map, - ud->tchan_cnt), - ud->rchan_cnt - bitmap_weight(ud->rchan_map, - ud->rchan_cnt)); + if (ud->match_data->version == K3_UDMA_V1) { + dev_info(dev, + "Channels: %d (tchan: %u, rchan: %u)\n", + ch_count, + ud->tchan_cnt - bitmap_weight(ud->tchan_map, + ud->tchan_cnt), + ud->rchan_cnt - bitmap_weight(ud->rchan_map, + ud->rchan_cnt)); + } else { + dev_info(dev, + "Channels: %d (tchan + rchan: %u)\n", + ch_count, + ud->chan_cnt - bitmap_weight(ud->chan_map, + ud->chan_cnt)); + } break; default: break; diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c index 34b282d9a727a..d25f8f46a4301 100644 --- a/drivers/dma/ti/k3-udma-glue.c +++ b/drivers/dma/ti/k3-udma-glue.c @@ -166,6 +166,29 @@ static int of_k3_udma_glue_parse_chn(struct device_node *chn_np, goto out_put_spec; thread_id = dma_spec.args[0]; + + /* + * V2 PKTDMA DT specifiers encode the hardware flow/channel ID in + * args[0] rather than the PSI-L thread ID used by V1. Resolve the + * PSI-L thread ID before the common path checks the direction bit. + */ + if (common->udmax->match_data->version == K3_UDMA_V2 && + xudma_is_pktdma(common->udmax)) { + struct psil_endpoint_config *ep_cfg; + u32 psil_thread_id; + bool dev_to_mem; + + ep_cfg = psil_get_ep_config_by_id(thread_id, true, + &psil_thread_id, &dev_to_mem); + if (IS_ERR(ep_cfg)) { + dev_err(common->dev, + "No PSI-L config for flow %u\n", thread_id); + ret = PTR_ERR(ep_cfg); + goto out_put_spec; + } + thread_id = psil_thread_id; + } + if (dma_spec.args_count == 2) { if (dma_spec.args[1] > 2 && !xudma_is_pktdma(common->udmax)) { dev_err(common->dev, "Invalid channel atype: %u\n", diff --git a/drivers/dma/ti/k3-udma-private.c b/drivers/dma/ti/k3-udma-private.c index d2501e074bcfb..3f6235cd4d72a 100644 --- a/drivers/dma/ti/k3-udma-private.c +++ b/drivers/dma/ti/k3-udma-private.c @@ -190,16 +190,30 @@ EXPORT_SYMBOL(xudma_is_pktdma); int xudma_pktdma_tflow_get_irq(struct udma_dev *ud, int udma_tflow_id) { - const struct udma_oes_offsets *oes = &ud->soc_data->oes; + if (ud->match_data->version == K3_UDMA_V1) { + const struct udma_oes_offsets *oes = &ud->soc_data->oes; - return msi_get_virq(ud->dev, udma_tflow_id + oes->pktdma_tchan_flow); + return msi_get_virq(ud->dev, udma_tflow_id + oes->pktdma_tchan_flow); + } + struct platform_device *pdev = to_platform_device(ud->dev); + char irq_name[10]; + + snprintf(irq_name, sizeof(irq_name), "tx-%u", udma_tflow_id); + return platform_get_irq_byname(pdev, irq_name); } EXPORT_SYMBOL(xudma_pktdma_tflow_get_irq); int xudma_pktdma_rflow_get_irq(struct udma_dev *ud, int udma_rflow_id) { - const struct udma_oes_offsets *oes = &ud->soc_data->oes; + if (ud->match_data->version == K3_UDMA_V1) { + const struct udma_oes_offsets *oes = &ud->soc_data->oes; + + return msi_get_virq(ud->dev, udma_rflow_id + oes->pktdma_rchan_flow); + } + struct platform_device *pdev = to_platform_device(ud->dev); + char irq_name[10]; - return msi_get_virq(ud->dev, udma_rflow_id + oes->pktdma_rchan_flow); + snprintf(irq_name, sizeof(irq_name), "rx-%u", udma_rflow_id); + return platform_get_irq_byname(pdev, irq_name); } EXPORT_SYMBOL(xudma_pktdma_rflow_get_irq); diff --git a/drivers/dma/ti/k3-udma-v2.c b/drivers/dma/ti/k3-udma-v2.c index b401d4ba17ded..7d3dd9c552c3a 100644 --- a/drivers/dma/ti/k3-udma-v2.c +++ b/drivers/dma/ti/k3-udma-v2.c @@ -610,7 +610,7 @@ static int udma_v2_alloc_rx_resources(struct udma_chan *uc) rflow = uc->rflow; if (ud->tflow_cnt) - fd_ring_id = ud->tflow_cnt + rflow->id; + fd_ring_id = rflow->id; else fd_ring_id = uc->rchan->id; ret = k3_ringacc_request_rings_pair(ud->ringacc, fd_ring_id, -1, @@ -803,6 +803,155 @@ static int bcdma_v2_alloc_chan_resources(struct dma_chan *chan) return ret; } +static int pktdma_v2_alloc_chan_resources(struct dma_chan *chan) +{ + struct udma_chan *uc = to_udma_chan(chan); + struct udma_dev *ud = to_udma_dev(chan->device); + struct platform_device *pdev = to_platform_device(ud->dev); + char irq_name[10]; + u32 irq_ring_idx; + int ret; + + /* + * Make sure that the completion is in a known state: + * No teardown, the channel is idle + */ + reinit_completion(&uc->teardown_completed); + complete_all(&uc->teardown_completed); + uc->state = UDMA_CHAN_IS_IDLE; + + switch (uc->config.dir) { + case DMA_MEM_TO_DEV: + /* Slave transfer synchronized - mem to dev (TX) transfer */ + dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__, + uc->id); + + ret = udma_v2_alloc_tx_resources(uc); + if (ret) { + uc->config.remote_thread_id = -1; + return ret; + } + + uc->config.src_thread = ud->psil_base + uc->tchan->id; + uc->config.dst_thread = uc->config.remote_thread_id; + uc->config.dst_thread |= K3_PSIL_DST_THREAD_ID_OFFSET; + + /* + * Use the tx flow ID here, matching how the TX ring itself + * was addressed in udma_v2_alloc_tx_resources() and how the + * glue layer (xudma_pktdma_tflow_get_irq()) looks up this + * same IRQ, instead of mapped_channel_id. + */ + irq_ring_idx = uc->tchan->tflow_id; + break; + case DMA_DEV_TO_MEM: + /* Slave transfer synchronized - dev to mem (RX) transfer */ + dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__, + uc->id); + + ret = udma_v2_alloc_rx_resources(uc); + if (ret) { + uc->config.remote_thread_id = -1; + return ret; + } + + uc->config.src_thread = uc->config.remote_thread_id; + uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | + K3_PSIL_DST_THREAD_ID_OFFSET; + + /* Use the rx flow ID here, see the DMA_MEM_TO_DEV case above */ + irq_ring_idx = uc->rflow->id; + udma_write(uc->rflow->reg_rt, UDMA_RX_FLOWRT_RFA, BIT(28)); + break; + default: + /* Can not happen */ + dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n", + __func__, uc->id, uc->config.dir); + return -EINVAL; + } + + /* check if the channel configuration was successful */ + if (ret) + goto err_res_free; + + if (udma_is_chan_running(uc)) { + dev_warn(ud->dev, "chan%d: is running!\n", uc->id); + ud->reset_chan(uc, false); + if (udma_is_chan_running(uc)) { + dev_err(ud->dev, "chan%d: won't stop!\n", uc->id); + ret = -EBUSY; + goto err_res_free; + } + } + + uc->dma_dev = dmaengine_get_dma_device(chan); + uc->hdesc_pool = dma_pool_create(uc->name, uc->dma_dev, + uc->config.hdesc_size, ud->desc_align, + 0); + if (!uc->hdesc_pool) { + dev_err(ud->ddev.dev, + "Descriptor pool allocation failed\n"); + uc->use_dma_pool = false; + ret = -ENOMEM; + goto err_res_free; + } + + uc->use_dma_pool = true; + + uc->psil_paired = true; + + INIT_DELAYED_WORK(&uc->tx_drain.work, udma_check_tx_completion); + + udma_reset_rings(uc); + + if (uc->config.dir == DMA_MEM_TO_DEV) + snprintf(irq_name, sizeof(irq_name), "tx-%u", irq_ring_idx); + else + snprintf(irq_name, sizeof(irq_name), "rx-%u", irq_ring_idx); + uc->irq_num_ring = platform_get_irq_byname(pdev, irq_name); + if (uc->irq_num_ring < 0) { + ret = uc->irq_num_ring; + goto err_res_free; + } + + ret = request_irq(uc->irq_num_ring, udma_v2_ring_irq_handler, + IRQF_SHARED | IRQF_TRIGGER_HIGH, uc->name, uc); + + if (ret) { + dev_err(ud->dev, "chan%d: ring irq request failed\n", uc->id); + goto err_irq_free; + } + + uc->irq_num_udma = 0; + + if (uc->tchan) + dev_dbg(ud->dev, + "chan%d: tchan%d, tflow%d, Remote thread: 0x%04x\n", + uc->id, uc->tchan->id, uc->tchan->tflow_id, + uc->config.remote_thread_id); + else if (uc->rchan) + dev_dbg(ud->dev, + "chan%d: rchan%d, rflow%d, Remote thread: 0x%04x\n", + uc->id, uc->rchan->id, uc->rflow->id, + uc->config.remote_thread_id); + return 0; + +err_irq_free: + uc->irq_num_ring = 0; +err_res_free: + udma_free_tx_resources(uc); + udma_free_rx_resources(uc); + + udma_reset_uchan(uc); + + if (uc->use_dma_pool) { + dma_pool_destroy(uc->hdesc_pool); + uc->use_dma_pool = false; + } + + return ret; +} + static enum dma_status udma_v2_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) @@ -1065,11 +1214,34 @@ static struct udma_match_data bcdma_v2_am62l_data = { .rchan_cnt = 128, }; +static struct udma_match_data pktdma_v2_am62l_data = { + .type = DMA_TYPE_PKTDMA, + .version = K3_UDMA_V2, + .psil_base = 0x1000, + .enable_memcpy_support = false, /* PKTDMA does not support MEM_TO_MEM */ + .flags = UDMA_FLAGS_J7_CLASS, + .statictr_z_mask = GENMASK(23, 0), + .burst_size = { + TI_SCI_RM_UDMAP_CHAN_BURST_SIZE_64_BYTES, /* Normal Channels */ + 0, /* No H Channels */ + 0, /* No UH Channels */ + }, + .tchan_cnt = 97, + .rchan_cnt = 97, + .chan_cnt = 97, + .tflow_cnt = 112, + .rflow_cnt = 112, +}; + static const struct of_device_id udma_of_match[] = { { .compatible = "ti,am62l-dmss-bcdma", .data = &bcdma_v2_am62l_data, }, + { + .compatible = "ti,am62l-dmss-pktdma", + .data = &pktdma_v2_am62l_data, + }, { /* Sentinel */ }, }; @@ -1088,15 +1260,23 @@ static int udma_v2_get_mmrs(struct platform_device *pdev, struct udma_dev *ud) if (IS_ERR(ud->mmrs[V2_MMR_GCFG])) return PTR_ERR(ud->mmrs[V2_MMR_GCFG]); - ud->bchan_cnt = ud->match_data->bchan_cnt; - /* There are no tchan and rchan in BCDMA_V2. + /* There are no tchan and rchan in BCDMA_V2 and PKTDMA_V2. * Duplicate chan as tchan and rchan to keep the common code - * in k3-udma-common.c functional for BCDMA_V2. + * in k3-udma-common.c functional. */ - ud->chan_cnt = ud->match_data->chan_cnt; - ud->tchan_cnt = ud->match_data->chan_cnt; - ud->rchan_cnt = ud->match_data->chan_cnt; - ud->rflow_cnt = ud->chan_cnt; + if (ud->match_data->type == DMA_TYPE_BCDMA) { + ud->bchan_cnt = ud->match_data->bchan_cnt; + ud->chan_cnt = ud->match_data->chan_cnt; + ud->tchan_cnt = ud->match_data->chan_cnt; + ud->rchan_cnt = ud->match_data->chan_cnt; + ud->rflow_cnt = ud->chan_cnt; + } else if (ud->match_data->type == DMA_TYPE_PKTDMA) { + ud->chan_cnt = ud->match_data->chan_cnt; + ud->tchan_cnt = ud->match_data->tchan_cnt; + ud->rchan_cnt = ud->match_data->rchan_cnt; + ud->tflow_cnt = ud->match_data->tflow_cnt; + ud->rflow_cnt = ud->match_data->rflow_cnt; + } for (i = 1; i < V2_MMR_LAST; i++) { if (i == V2_MMR_BCHANRT && ud->bchan_cnt == 0) @@ -1150,6 +1330,7 @@ static int udma_v2_probe(struct platform_device *pdev) ud->reset_chan = udma_v2_reset_chan; ud->decrement_byte_counters = udma_v2_decrement_byte_counters; ud->bcdma_setup_sci_resources = NULL; + ud->pktdma_setup_sci_resources = NULL; ret = udma_v2_get_mmrs(pdev, ud); if (ret) @@ -1157,7 +1338,24 @@ static int udma_v2_probe(struct platform_device *pdev) struct k3_ringacc_init_data ring_init_data = {0}; - ring_init_data.num_rings = ud->bchan_cnt + ud->chan_cnt; + if (ud->match_data->type == DMA_TYPE_BCDMA) { + ring_init_data.num_rings = ud->bchan_cnt + ud->chan_cnt; + } else if (ud->match_data->type == DMA_TYPE_PKTDMA) { + /* + * tflow_cnt == rflow_cnt on this hardware and tx/rx flow IDs + * for a given channel coincide, so a single ring array sized + * to rflow_cnt covers both; any extra flow indices beyond a + * channel's own ID are reserved for that channel and not + * reused elsewhere, so there is no collision. + */ + ring_init_data.num_rings = ud->rflow_cnt; + + ud->rflow_rt = devm_platform_ioremap_resource_byname(pdev, "ringrt"); + if (IS_ERR(ud->rflow_rt)) + return PTR_ERR(ud->rflow_rt); + + ring_init_data.base_rt = ud->rflow_rt; + } ud->ringacc = k3_ringacc_dmarings_init(pdev, &ring_init_data); @@ -1166,8 +1364,10 @@ static int udma_v2_probe(struct platform_device *pdev) dma_cap_set(DMA_SLAVE, ud->ddev.cap_mask); - dma_cap_set(DMA_CYCLIC, ud->ddev.cap_mask); - ud->ddev.device_prep_dma_cyclic = udma_prep_dma_cyclic; + if (ud->match_data->type != DMA_TYPE_PKTDMA) { + dma_cap_set(DMA_CYCLIC, ud->ddev.cap_mask); + ud->ddev.device_prep_dma_cyclic = udma_prep_dma_cyclic; + } ud->ddev.device_config = udma_slave_config; ud->ddev.device_prep_slave_sg = udma_prep_slave_sg; @@ -1181,8 +1381,18 @@ static int udma_v2_probe(struct platform_device *pdev) ud->ddev.dbg_summary_show = udma_dbg_summary_show; #endif - ud->ddev.device_alloc_chan_resources = - bcdma_v2_alloc_chan_resources; + switch (ud->match_data->type) { + case DMA_TYPE_BCDMA: + ud->ddev.device_alloc_chan_resources = + bcdma_v2_alloc_chan_resources; + break; + case DMA_TYPE_PKTDMA: + ud->ddev.device_alloc_chan_resources = + pktdma_v2_alloc_chan_resources; + break; + default: + return -EINVAL; + } ud->ddev.device_free_chan_resources = udma_free_chan_resources; diff --git a/drivers/dma/ti/k3-udma.h b/drivers/dma/ti/k3-udma.h index 13d47234967a4..cd705fcc94f08 100644 --- a/drivers/dma/ti/k3-udma.h +++ b/drivers/dma/ti/k3-udma.h @@ -28,8 +28,11 @@ #define UDMA_RX_FLOW_ID_FW_OES_REG 0x80 #define UDMA_RX_FLOW_ID_FW_STATUS_REG 0x88 +#define UDMA_RX_FLOWRT_RFA 0x8 + /* BCHANRT/TCHANRT/RCHANRT registers */ #define UDMA_CHAN_RT_CTL_REG 0x0 +#define UDMA_CHAN_RT_CFG_REG 0x4 #define UDMA_CHAN_RT_SWTRIG_REG 0x8 #define UDMA_CHAN_RT_STDATA_REG 0x80 -- 2.55.0