xref: /openbmc/linux/drivers/dma/ti/k3-udma-glue.c (revision f291209eca5eba0b4704fa0832af57b12dbc1a02)
1d7024191SGrygorii Strashko // SPDX-License-Identifier: GPL-2.0
2d7024191SGrygorii Strashko /*
3d7024191SGrygorii Strashko  * K3 NAVSS DMA glue interface
4d7024191SGrygorii Strashko  *
5d7024191SGrygorii Strashko  * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
6d7024191SGrygorii Strashko  *
7d7024191SGrygorii Strashko  */
8d7024191SGrygorii Strashko 
956b0a668SKevin Hilman #include <linux/module.h>
10d7024191SGrygorii Strashko #include <linux/atomic.h>
11d7024191SGrygorii Strashko #include <linux/delay.h>
12d7024191SGrygorii Strashko #include <linux/dma-mapping.h>
13d7024191SGrygorii Strashko #include <linux/io.h>
14d7024191SGrygorii Strashko #include <linux/init.h>
15d7024191SGrygorii Strashko #include <linux/of.h>
16d7024191SGrygorii Strashko #include <linux/platform_device.h>
17d7024191SGrygorii Strashko #include <linux/soc/ti/k3-ringacc.h>
18d7024191SGrygorii Strashko #include <linux/dma/ti-cppi5.h>
19d7024191SGrygorii Strashko #include <linux/dma/k3-udma-glue.h>
20d7024191SGrygorii Strashko 
21d7024191SGrygorii Strashko #include "k3-udma.h"
22d7024191SGrygorii Strashko #include "k3-psil-priv.h"
23d7024191SGrygorii Strashko 
24d7024191SGrygorii Strashko struct k3_udma_glue_common {
25d7024191SGrygorii Strashko 	struct device *dev;
265b65781dSVignesh Raghavendra 	struct device chan_dev;
27d7024191SGrygorii Strashko 	struct udma_dev *udmax;
28d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm;
29d7024191SGrygorii Strashko 	struct k3_ringacc *ringacc;
30d7024191SGrygorii Strashko 	u32 src_thread;
31d7024191SGrygorii Strashko 	u32 dst_thread;
32d7024191SGrygorii Strashko 
33d7024191SGrygorii Strashko 	u32  hdesc_size;
34d7024191SGrygorii Strashko 	bool epib;
35d7024191SGrygorii Strashko 	u32  psdata_size;
36d7024191SGrygorii Strashko 	u32  swdata_size;
375b65781dSVignesh Raghavendra 	u32  atype_asel;
385b65781dSVignesh Raghavendra 	struct psil_endpoint_config *ep_config;
39d7024191SGrygorii Strashko };
40d7024191SGrygorii Strashko 
41d7024191SGrygorii Strashko struct k3_udma_glue_tx_channel {
42d7024191SGrygorii Strashko 	struct k3_udma_glue_common common;
43d7024191SGrygorii Strashko 
44d7024191SGrygorii Strashko 	struct udma_tchan *udma_tchanx;
45d7024191SGrygorii Strashko 	int udma_tchan_id;
46d7024191SGrygorii Strashko 
47d7024191SGrygorii Strashko 	struct k3_ring *ringtx;
48d7024191SGrygorii Strashko 	struct k3_ring *ringtxcq;
49d7024191SGrygorii Strashko 
50d7024191SGrygorii Strashko 	bool psil_paired;
51d7024191SGrygorii Strashko 
52d7024191SGrygorii Strashko 	int virq;
53d7024191SGrygorii Strashko 
54d7024191SGrygorii Strashko 	atomic_t free_pkts;
55d7024191SGrygorii Strashko 	bool tx_pause_on_err;
56d7024191SGrygorii Strashko 	bool tx_filt_einfo;
57d7024191SGrygorii Strashko 	bool tx_filt_pswords;
58d7024191SGrygorii Strashko 	bool tx_supr_tdpkt;
595b65781dSVignesh Raghavendra 
605b65781dSVignesh Raghavendra 	int udma_tflow_id;
61d7024191SGrygorii Strashko };
62d7024191SGrygorii Strashko 
63d7024191SGrygorii Strashko struct k3_udma_glue_rx_flow {
64d7024191SGrygorii Strashko 	struct udma_rflow *udma_rflow;
65d7024191SGrygorii Strashko 	int udma_rflow_id;
66d7024191SGrygorii Strashko 	struct k3_ring *ringrx;
67d7024191SGrygorii Strashko 	struct k3_ring *ringrxfdq;
68d7024191SGrygorii Strashko 
69d7024191SGrygorii Strashko 	int virq;
70d7024191SGrygorii Strashko };
71d7024191SGrygorii Strashko 
72d7024191SGrygorii Strashko struct k3_udma_glue_rx_channel {
73d7024191SGrygorii Strashko 	struct k3_udma_glue_common common;
74d7024191SGrygorii Strashko 
75d7024191SGrygorii Strashko 	struct udma_rchan *udma_rchanx;
76d7024191SGrygorii Strashko 	int udma_rchan_id;
77d7024191SGrygorii Strashko 	bool remote;
78d7024191SGrygorii Strashko 
79d7024191SGrygorii Strashko 	bool psil_paired;
80d7024191SGrygorii Strashko 
81d7024191SGrygorii Strashko 	u32  swdata_size;
82d7024191SGrygorii Strashko 	int  flow_id_base;
83d7024191SGrygorii Strashko 
84d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flows;
85d7024191SGrygorii Strashko 	u32 flow_num;
86d7024191SGrygorii Strashko 	u32 flows_ready;
87d7024191SGrygorii Strashko };
88d7024191SGrygorii Strashko 
k3_udma_chan_dev_release(struct device * dev)895b65781dSVignesh Raghavendra static void k3_udma_chan_dev_release(struct device *dev)
905b65781dSVignesh Raghavendra {
915b65781dSVignesh Raghavendra 	/* The struct containing the device is devm managed */
925b65781dSVignesh Raghavendra }
935b65781dSVignesh Raghavendra 
945b65781dSVignesh Raghavendra static struct class k3_udma_glue_devclass = {
955b65781dSVignesh Raghavendra 	.name		= "k3_udma_glue_chan",
965b65781dSVignesh Raghavendra 	.dev_release	= k3_udma_chan_dev_release,
975b65781dSVignesh Raghavendra };
985b65781dSVignesh Raghavendra 
99d7024191SGrygorii Strashko #define K3_UDMAX_TDOWN_TIMEOUT_US 1000
100d7024191SGrygorii Strashko 
of_k3_udma_glue_parse(struct device_node * udmax_np,struct k3_udma_glue_common * common)101d7024191SGrygorii Strashko static int of_k3_udma_glue_parse(struct device_node *udmax_np,
102d7024191SGrygorii Strashko 				 struct k3_udma_glue_common *common)
103d7024191SGrygorii Strashko {
104d7024191SGrygorii Strashko 	common->udmax = of_xudma_dev_get(udmax_np, NULL);
105d7024191SGrygorii Strashko 	if (IS_ERR(common->udmax))
106d7024191SGrygorii Strashko 		return PTR_ERR(common->udmax);
107d7024191SGrygorii Strashko 
108aa8a4c4eSPeter Ujfalusi 	common->ringacc = xudma_get_ringacc(common->udmax);
109d7024191SGrygorii Strashko 	common->tisci_rm = xudma_dev_get_tisci_rm(common->udmax);
110d7024191SGrygorii Strashko 
111d7024191SGrygorii Strashko 	return 0;
112d7024191SGrygorii Strashko }
113d7024191SGrygorii Strashko 
of_k3_udma_glue_parse_chn(struct device_node * chn_np,const char * name,struct k3_udma_glue_common * common,bool tx_chn)114d7024191SGrygorii Strashko static int of_k3_udma_glue_parse_chn(struct device_node *chn_np,
115d7024191SGrygorii Strashko 		const char *name, struct k3_udma_glue_common *common,
116d7024191SGrygorii Strashko 		bool tx_chn)
117d7024191SGrygorii Strashko {
118d7024191SGrygorii Strashko 	struct of_phandle_args dma_spec;
119d7024191SGrygorii Strashko 	u32 thread_id;
120d7024191SGrygorii Strashko 	int ret = 0;
121d7024191SGrygorii Strashko 	int index;
122d7024191SGrygorii Strashko 
123d7024191SGrygorii Strashko 	if (unlikely(!name))
124d7024191SGrygorii Strashko 		return -EINVAL;
125d7024191SGrygorii Strashko 
126d7024191SGrygorii Strashko 	index = of_property_match_string(chn_np, "dma-names", name);
127d7024191SGrygorii Strashko 	if (index < 0)
128d7024191SGrygorii Strashko 		return index;
129d7024191SGrygorii Strashko 
130d7024191SGrygorii Strashko 	if (of_parse_phandle_with_args(chn_np, "dmas", "#dma-cells", index,
131d7024191SGrygorii Strashko 				       &dma_spec))
132d7024191SGrygorii Strashko 		return -ENOENT;
133d7024191SGrygorii Strashko 
1345b65781dSVignesh Raghavendra 	ret = of_k3_udma_glue_parse(dma_spec.np, common);
1355b65781dSVignesh Raghavendra 	if (ret)
1365b65781dSVignesh Raghavendra 		goto out_put_spec;
1375b65781dSVignesh Raghavendra 
138d7024191SGrygorii Strashko 	thread_id = dma_spec.args[0];
1390ebcf1a2SPeter Ujfalusi 	if (dma_spec.args_count == 2) {
1405b65781dSVignesh Raghavendra 		if (dma_spec.args[1] > 2 && !xudma_is_pktdma(common->udmax)) {
1410ebcf1a2SPeter Ujfalusi 			dev_err(common->dev, "Invalid channel atype: %u\n",
1420ebcf1a2SPeter Ujfalusi 				dma_spec.args[1]);
1430ebcf1a2SPeter Ujfalusi 			ret = -EINVAL;
1440ebcf1a2SPeter Ujfalusi 			goto out_put_spec;
1450ebcf1a2SPeter Ujfalusi 		}
1465b65781dSVignesh Raghavendra 		if (dma_spec.args[1] > 15 && xudma_is_pktdma(common->udmax)) {
1475b65781dSVignesh Raghavendra 			dev_err(common->dev, "Invalid channel asel: %u\n",
1485b65781dSVignesh Raghavendra 				dma_spec.args[1]);
1495b65781dSVignesh Raghavendra 			ret = -EINVAL;
1505b65781dSVignesh Raghavendra 			goto out_put_spec;
1515b65781dSVignesh Raghavendra 		}
1525b65781dSVignesh Raghavendra 
1535b65781dSVignesh Raghavendra 		common->atype_asel = dma_spec.args[1];
1540ebcf1a2SPeter Ujfalusi 	}
155d7024191SGrygorii Strashko 
156d7024191SGrygorii Strashko 	if (tx_chn && !(thread_id & K3_PSIL_DST_THREAD_ID_OFFSET)) {
157d7024191SGrygorii Strashko 		ret = -EINVAL;
158d7024191SGrygorii Strashko 		goto out_put_spec;
159d7024191SGrygorii Strashko 	}
160d7024191SGrygorii Strashko 
161d7024191SGrygorii Strashko 	if (!tx_chn && (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET)) {
162d7024191SGrygorii Strashko 		ret = -EINVAL;
163d7024191SGrygorii Strashko 		goto out_put_spec;
164d7024191SGrygorii Strashko 	}
165d7024191SGrygorii Strashko 
166d7024191SGrygorii Strashko 	/* get psil endpoint config */
1675b65781dSVignesh Raghavendra 	common->ep_config = psil_get_ep_config(thread_id);
1685b65781dSVignesh Raghavendra 	if (IS_ERR(common->ep_config)) {
169d7024191SGrygorii Strashko 		dev_err(common->dev,
170d7024191SGrygorii Strashko 			"No configuration for psi-l thread 0x%04x\n",
171d7024191SGrygorii Strashko 			thread_id);
1725b65781dSVignesh Raghavendra 		ret = PTR_ERR(common->ep_config);
173d7024191SGrygorii Strashko 		goto out_put_spec;
174d7024191SGrygorii Strashko 	}
175d7024191SGrygorii Strashko 
1765b65781dSVignesh Raghavendra 	common->epib = common->ep_config->needs_epib;
1775b65781dSVignesh Raghavendra 	common->psdata_size = common->ep_config->psd_size;
178d7024191SGrygorii Strashko 
179d7024191SGrygorii Strashko 	if (tx_chn)
180d7024191SGrygorii Strashko 		common->dst_thread = thread_id;
181d7024191SGrygorii Strashko 	else
182d7024191SGrygorii Strashko 		common->src_thread = thread_id;
183d7024191SGrygorii Strashko 
184d7024191SGrygorii Strashko out_put_spec:
185d7024191SGrygorii Strashko 	of_node_put(dma_spec.np);
186d7024191SGrygorii Strashko 	return ret;
187d7024191SGrygorii Strashko };
188d7024191SGrygorii Strashko 
k3_udma_glue_dump_tx_chn(struct k3_udma_glue_tx_channel * tx_chn)189d7024191SGrygorii Strashko static void k3_udma_glue_dump_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
190d7024191SGrygorii Strashko {
191d7024191SGrygorii Strashko 	struct device *dev = tx_chn->common.dev;
192d7024191SGrygorii Strashko 
193d7024191SGrygorii Strashko 	dev_dbg(dev, "dump_tx_chn:\n"
194d7024191SGrygorii Strashko 		"udma_tchan_id: %d\n"
195d7024191SGrygorii Strashko 		"src_thread: %08x\n"
196d7024191SGrygorii Strashko 		"dst_thread: %08x\n",
197d7024191SGrygorii Strashko 		tx_chn->udma_tchan_id,
198d7024191SGrygorii Strashko 		tx_chn->common.src_thread,
199d7024191SGrygorii Strashko 		tx_chn->common.dst_thread);
200d7024191SGrygorii Strashko }
201d7024191SGrygorii Strashko 
k3_udma_glue_dump_tx_rt_chn(struct k3_udma_glue_tx_channel * chn,char * mark)202d7024191SGrygorii Strashko static void k3_udma_glue_dump_tx_rt_chn(struct k3_udma_glue_tx_channel *chn,
203d7024191SGrygorii Strashko 					char *mark)
204d7024191SGrygorii Strashko {
205d7024191SGrygorii Strashko 	struct device *dev = chn->common.dev;
206d7024191SGrygorii Strashko 
207d7024191SGrygorii Strashko 	dev_dbg(dev, "=== dump ===> %s\n", mark);
208bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_CTL_REG,
209bc7e5523SPeter Ujfalusi 		xudma_tchanrt_read(chn->udma_tchanx, UDMA_CHAN_RT_CTL_REG));
210bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_PEER_RT_EN_REG,
211d7024191SGrygorii Strashko 		xudma_tchanrt_read(chn->udma_tchanx,
212bc7e5523SPeter Ujfalusi 				   UDMA_CHAN_RT_PEER_RT_EN_REG));
213bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_PCNT_REG,
214bc7e5523SPeter Ujfalusi 		xudma_tchanrt_read(chn->udma_tchanx, UDMA_CHAN_RT_PCNT_REG));
215bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_BCNT_REG,
216bc7e5523SPeter Ujfalusi 		xudma_tchanrt_read(chn->udma_tchanx, UDMA_CHAN_RT_BCNT_REG));
217bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_SBCNT_REG,
218bc7e5523SPeter Ujfalusi 		xudma_tchanrt_read(chn->udma_tchanx, UDMA_CHAN_RT_SBCNT_REG));
219d7024191SGrygorii Strashko }
220d7024191SGrygorii Strashko 
k3_udma_glue_cfg_tx_chn(struct k3_udma_glue_tx_channel * tx_chn)221d7024191SGrygorii Strashko static int k3_udma_glue_cfg_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
222d7024191SGrygorii Strashko {
223d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm = tx_chn->common.tisci_rm;
224d7024191SGrygorii Strashko 	struct ti_sci_msg_rm_udmap_tx_ch_cfg req;
225d7024191SGrygorii Strashko 
226d7024191SGrygorii Strashko 	memset(&req, 0, sizeof(req));
227d7024191SGrygorii Strashko 
228d7024191SGrygorii Strashko 	req.valid_params = TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID |
229d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_EINFO_VALID |
230d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_PSWORDS_VALID |
231d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
232d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID |
233d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
2340ebcf1a2SPeter Ujfalusi 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID |
2350ebcf1a2SPeter Ujfalusi 			TI_SCI_MSG_VALUE_RM_UDMAP_CH_ATYPE_VALID;
236d7024191SGrygorii Strashko 	req.nav_id = tisci_rm->tisci_dev_id;
237d7024191SGrygorii Strashko 	req.index = tx_chn->udma_tchan_id;
238d7024191SGrygorii Strashko 	if (tx_chn->tx_pause_on_err)
239d7024191SGrygorii Strashko 		req.tx_pause_on_err = 1;
240d7024191SGrygorii Strashko 	if (tx_chn->tx_filt_einfo)
241d7024191SGrygorii Strashko 		req.tx_filt_einfo = 1;
242d7024191SGrygorii Strashko 	if (tx_chn->tx_filt_pswords)
243d7024191SGrygorii Strashko 		req.tx_filt_pswords = 1;
244d7024191SGrygorii Strashko 	req.tx_chan_type = TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR;
245d7024191SGrygorii Strashko 	if (tx_chn->tx_supr_tdpkt)
246d7024191SGrygorii Strashko 		req.tx_supr_tdpkt = 1;
247d7024191SGrygorii Strashko 	req.tx_fetch_size = tx_chn->common.hdesc_size >> 2;
248d7024191SGrygorii Strashko 	req.txcq_qnum = k3_ringacc_get_ring_id(tx_chn->ringtxcq);
2495b65781dSVignesh Raghavendra 	req.tx_atype = tx_chn->common.atype_asel;
250d7024191SGrygorii Strashko 
251d7024191SGrygorii Strashko 	return tisci_rm->tisci_udmap_ops->tx_ch_cfg(tisci_rm->tisci, &req);
252d7024191SGrygorii Strashko }
253d7024191SGrygorii Strashko 
k3_udma_glue_request_tx_chn(struct device * dev,const char * name,struct k3_udma_glue_tx_channel_cfg * cfg)254d7024191SGrygorii Strashko struct k3_udma_glue_tx_channel *k3_udma_glue_request_tx_chn(struct device *dev,
255d7024191SGrygorii Strashko 		const char *name, struct k3_udma_glue_tx_channel_cfg *cfg)
256d7024191SGrygorii Strashko {
257d7024191SGrygorii Strashko 	struct k3_udma_glue_tx_channel *tx_chn;
258d7024191SGrygorii Strashko 	int ret;
259d7024191SGrygorii Strashko 
260d7024191SGrygorii Strashko 	tx_chn = devm_kzalloc(dev, sizeof(*tx_chn), GFP_KERNEL);
261d7024191SGrygorii Strashko 	if (!tx_chn)
262d7024191SGrygorii Strashko 		return ERR_PTR(-ENOMEM);
263d7024191SGrygorii Strashko 
264d7024191SGrygorii Strashko 	tx_chn->common.dev = dev;
265d7024191SGrygorii Strashko 	tx_chn->common.swdata_size = cfg->swdata_size;
266d7024191SGrygorii Strashko 	tx_chn->tx_pause_on_err = cfg->tx_pause_on_err;
267d7024191SGrygorii Strashko 	tx_chn->tx_filt_einfo = cfg->tx_filt_einfo;
268d7024191SGrygorii Strashko 	tx_chn->tx_filt_pswords = cfg->tx_filt_pswords;
269d7024191SGrygorii Strashko 	tx_chn->tx_supr_tdpkt = cfg->tx_supr_tdpkt;
270d7024191SGrygorii Strashko 
271d7024191SGrygorii Strashko 	/* parse of udmap channel */
272d7024191SGrygorii Strashko 	ret = of_k3_udma_glue_parse_chn(dev->of_node, name,
273d7024191SGrygorii Strashko 					&tx_chn->common, true);
274d7024191SGrygorii Strashko 	if (ret)
275d7024191SGrygorii Strashko 		goto err;
276d7024191SGrygorii Strashko 
277d7024191SGrygorii Strashko 	tx_chn->common.hdesc_size = cppi5_hdesc_calc_size(tx_chn->common.epib,
278d7024191SGrygorii Strashko 						tx_chn->common.psdata_size,
279d7024191SGrygorii Strashko 						tx_chn->common.swdata_size);
280d7024191SGrygorii Strashko 
2815b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax))
2825b65781dSVignesh Raghavendra 		tx_chn->udma_tchan_id = tx_chn->common.ep_config->mapped_channel_id;
2835b65781dSVignesh Raghavendra 	else
2845b65781dSVignesh Raghavendra 		tx_chn->udma_tchan_id = -1;
2855b65781dSVignesh Raghavendra 
286d7024191SGrygorii Strashko 	/* request and cfg UDMAP TX channel */
2875b65781dSVignesh Raghavendra 	tx_chn->udma_tchanx = xudma_tchan_get(tx_chn->common.udmax,
2885b65781dSVignesh Raghavendra 					      tx_chn->udma_tchan_id);
289d7024191SGrygorii Strashko 	if (IS_ERR(tx_chn->udma_tchanx)) {
290d7024191SGrygorii Strashko 		ret = PTR_ERR(tx_chn->udma_tchanx);
291d7024191SGrygorii Strashko 		dev_err(dev, "UDMAX tchanx get err %d\n", ret);
292d7024191SGrygorii Strashko 		goto err;
293d7024191SGrygorii Strashko 	}
294d7024191SGrygorii Strashko 	tx_chn->udma_tchan_id = xudma_tchan_get_id(tx_chn->udma_tchanx);
295d7024191SGrygorii Strashko 
2965b65781dSVignesh Raghavendra 	tx_chn->common.chan_dev.class = &k3_udma_glue_devclass;
2975b65781dSVignesh Raghavendra 	tx_chn->common.chan_dev.parent = xudma_get_device(tx_chn->common.udmax);
2985b65781dSVignesh Raghavendra 	dev_set_name(&tx_chn->common.chan_dev, "tchan%d-0x%04x",
2995b65781dSVignesh Raghavendra 		     tx_chn->udma_tchan_id, tx_chn->common.dst_thread);
3005b65781dSVignesh Raghavendra 	ret = device_register(&tx_chn->common.chan_dev);
3015b65781dSVignesh Raghavendra 	if (ret) {
3025b65781dSVignesh Raghavendra 		dev_err(dev, "Channel Device registration failed %d\n", ret);
303ac2b9f34SYang Yingliang 		put_device(&tx_chn->common.chan_dev);
3045b65781dSVignesh Raghavendra 		tx_chn->common.chan_dev.parent = NULL;
3055b65781dSVignesh Raghavendra 		goto err;
3065b65781dSVignesh Raghavendra 	}
3075b65781dSVignesh Raghavendra 
3085b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax)) {
3095b65781dSVignesh Raghavendra 		/* prepare the channel device as coherent */
3105b65781dSVignesh Raghavendra 		tx_chn->common.chan_dev.dma_coherent = true;
3115b65781dSVignesh Raghavendra 		dma_coerce_mask_and_coherent(&tx_chn->common.chan_dev,
3125b65781dSVignesh Raghavendra 					     DMA_BIT_MASK(48));
3135b65781dSVignesh Raghavendra 	}
3145b65781dSVignesh Raghavendra 
315d7024191SGrygorii Strashko 	atomic_set(&tx_chn->free_pkts, cfg->txcq_cfg.size);
316d7024191SGrygorii Strashko 
3175b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax))
3185b65781dSVignesh Raghavendra 		tx_chn->udma_tflow_id = tx_chn->common.ep_config->default_flow_id;
3195b65781dSVignesh Raghavendra 	else
3205b65781dSVignesh Raghavendra 		tx_chn->udma_tflow_id = tx_chn->udma_tchan_id;
3215b65781dSVignesh Raghavendra 
322d7024191SGrygorii Strashko 	/* request and cfg rings */
3234927b1abSPeter Ujfalusi 	ret =  k3_ringacc_request_rings_pair(tx_chn->common.ringacc,
3245b65781dSVignesh Raghavendra 					     tx_chn->udma_tflow_id, -1,
3254927b1abSPeter Ujfalusi 					     &tx_chn->ringtx,
3264927b1abSPeter Ujfalusi 					     &tx_chn->ringtxcq);
3274927b1abSPeter Ujfalusi 	if (ret) {
3284927b1abSPeter Ujfalusi 		dev_err(dev, "Failed to get TX/TXCQ rings %d\n", ret);
329d7024191SGrygorii Strashko 		goto err;
330d7024191SGrygorii Strashko 	}
331d7024191SGrygorii Strashko 
332d553e2abSPeter Ujfalusi 	/* Set the dma_dev for the rings to be configured */
333d553e2abSPeter Ujfalusi 	cfg->tx_cfg.dma_dev = k3_udma_glue_tx_get_dma_device(tx_chn);
334d553e2abSPeter Ujfalusi 	cfg->txcq_cfg.dma_dev = cfg->tx_cfg.dma_dev;
335d553e2abSPeter Ujfalusi 
3365b65781dSVignesh Raghavendra 	/* Set the ASEL value for DMA rings of PKTDMA */
3375b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax)) {
3385b65781dSVignesh Raghavendra 		cfg->tx_cfg.asel = tx_chn->common.atype_asel;
3395b65781dSVignesh Raghavendra 		cfg->txcq_cfg.asel = tx_chn->common.atype_asel;
3405b65781dSVignesh Raghavendra 	}
3415b65781dSVignesh Raghavendra 
342d7024191SGrygorii Strashko 	ret = k3_ringacc_ring_cfg(tx_chn->ringtx, &cfg->tx_cfg);
343d7024191SGrygorii Strashko 	if (ret) {
344d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg ringtx %d\n", ret);
345d7024191SGrygorii Strashko 		goto err;
346d7024191SGrygorii Strashko 	}
347d7024191SGrygorii Strashko 
348d7024191SGrygorii Strashko 	ret = k3_ringacc_ring_cfg(tx_chn->ringtxcq, &cfg->txcq_cfg);
349d7024191SGrygorii Strashko 	if (ret) {
350d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg ringtx %d\n", ret);
351d7024191SGrygorii Strashko 		goto err;
352d7024191SGrygorii Strashko 	}
353d7024191SGrygorii Strashko 
354d7024191SGrygorii Strashko 	/* request and cfg psi-l */
355d7024191SGrygorii Strashko 	tx_chn->common.src_thread =
356d7024191SGrygorii Strashko 			xudma_dev_get_psil_base(tx_chn->common.udmax) +
357d7024191SGrygorii Strashko 			tx_chn->udma_tchan_id;
358d7024191SGrygorii Strashko 
359d7024191SGrygorii Strashko 	ret = k3_udma_glue_cfg_tx_chn(tx_chn);
360d7024191SGrygorii Strashko 	if (ret) {
361d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg tchan %d\n", ret);
362d7024191SGrygorii Strashko 		goto err;
363d7024191SGrygorii Strashko 	}
364d7024191SGrygorii Strashko 
365d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_chn(tx_chn);
366d7024191SGrygorii Strashko 
367d7024191SGrygorii Strashko 	return tx_chn;
368d7024191SGrygorii Strashko 
369d7024191SGrygorii Strashko err:
370d7024191SGrygorii Strashko 	k3_udma_glue_release_tx_chn(tx_chn);
371d7024191SGrygorii Strashko 	return ERR_PTR(ret);
372d7024191SGrygorii Strashko }
373d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_request_tx_chn);
374d7024191SGrygorii Strashko 
k3_udma_glue_release_tx_chn(struct k3_udma_glue_tx_channel * tx_chn)375d7024191SGrygorii Strashko void k3_udma_glue_release_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
376d7024191SGrygorii Strashko {
377d7024191SGrygorii Strashko 	if (tx_chn->psil_paired) {
378d7024191SGrygorii Strashko 		xudma_navss_psil_unpair(tx_chn->common.udmax,
379d7024191SGrygorii Strashko 					tx_chn->common.src_thread,
380d7024191SGrygorii Strashko 					tx_chn->common.dst_thread);
381d7024191SGrygorii Strashko 		tx_chn->psil_paired = false;
382d7024191SGrygorii Strashko 	}
383d7024191SGrygorii Strashko 
384d7024191SGrygorii Strashko 	if (!IS_ERR_OR_NULL(tx_chn->udma_tchanx))
385d7024191SGrygorii Strashko 		xudma_tchan_put(tx_chn->common.udmax,
386d7024191SGrygorii Strashko 				tx_chn->udma_tchanx);
387d7024191SGrygorii Strashko 
388d7024191SGrygorii Strashko 	if (tx_chn->ringtxcq)
389d7024191SGrygorii Strashko 		k3_ringacc_ring_free(tx_chn->ringtxcq);
390d7024191SGrygorii Strashko 
391d7024191SGrygorii Strashko 	if (tx_chn->ringtx)
392d7024191SGrygorii Strashko 		k3_ringacc_ring_free(tx_chn->ringtx);
3935b65781dSVignesh Raghavendra 
3945b65781dSVignesh Raghavendra 	if (tx_chn->common.chan_dev.parent) {
3955b65781dSVignesh Raghavendra 		device_unregister(&tx_chn->common.chan_dev);
3965b65781dSVignesh Raghavendra 		tx_chn->common.chan_dev.parent = NULL;
3975b65781dSVignesh Raghavendra 	}
398d7024191SGrygorii Strashko }
399d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_release_tx_chn);
400d7024191SGrygorii Strashko 
k3_udma_glue_push_tx_chn(struct k3_udma_glue_tx_channel * tx_chn,struct cppi5_host_desc_t * desc_tx,dma_addr_t desc_dma)401d7024191SGrygorii Strashko int k3_udma_glue_push_tx_chn(struct k3_udma_glue_tx_channel *tx_chn,
402d7024191SGrygorii Strashko 			     struct cppi5_host_desc_t *desc_tx,
403d7024191SGrygorii Strashko 			     dma_addr_t desc_dma)
404d7024191SGrygorii Strashko {
405d7024191SGrygorii Strashko 	u32 ringtxcq_id;
406d7024191SGrygorii Strashko 
407d7024191SGrygorii Strashko 	if (!atomic_add_unless(&tx_chn->free_pkts, -1, 0))
408d7024191SGrygorii Strashko 		return -ENOMEM;
409d7024191SGrygorii Strashko 
410d7024191SGrygorii Strashko 	ringtxcq_id = k3_ringacc_get_ring_id(tx_chn->ringtxcq);
411d7024191SGrygorii Strashko 	cppi5_desc_set_retpolicy(&desc_tx->hdr, 0, ringtxcq_id);
412d7024191SGrygorii Strashko 
413d7024191SGrygorii Strashko 	return k3_ringacc_ring_push(tx_chn->ringtx, &desc_dma);
414d7024191SGrygorii Strashko }
415d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_push_tx_chn);
416d7024191SGrygorii Strashko 
k3_udma_glue_pop_tx_chn(struct k3_udma_glue_tx_channel * tx_chn,dma_addr_t * desc_dma)417d7024191SGrygorii Strashko int k3_udma_glue_pop_tx_chn(struct k3_udma_glue_tx_channel *tx_chn,
418d7024191SGrygorii Strashko 			    dma_addr_t *desc_dma)
419d7024191SGrygorii Strashko {
420d7024191SGrygorii Strashko 	int ret;
421d7024191SGrygorii Strashko 
422d7024191SGrygorii Strashko 	ret = k3_ringacc_ring_pop(tx_chn->ringtxcq, desc_dma);
423d7024191SGrygorii Strashko 	if (!ret)
424d7024191SGrygorii Strashko 		atomic_inc(&tx_chn->free_pkts);
425d7024191SGrygorii Strashko 
426d7024191SGrygorii Strashko 	return ret;
427d7024191SGrygorii Strashko }
428d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_pop_tx_chn);
429d7024191SGrygorii Strashko 
k3_udma_glue_enable_tx_chn(struct k3_udma_glue_tx_channel * tx_chn)430d7024191SGrygorii Strashko int k3_udma_glue_enable_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
431d7024191SGrygorii Strashko {
43269973b48SGrygorii Strashko 	int ret;
43369973b48SGrygorii Strashko 
43469973b48SGrygorii Strashko 	ret = xudma_navss_psil_pair(tx_chn->common.udmax,
43569973b48SGrygorii Strashko 				    tx_chn->common.src_thread,
43669973b48SGrygorii Strashko 				    tx_chn->common.dst_thread);
43769973b48SGrygorii Strashko 	if (ret) {
43869973b48SGrygorii Strashko 		dev_err(tx_chn->common.dev, "PSI-L request err %d\n", ret);
43969973b48SGrygorii Strashko 		return ret;
44069973b48SGrygorii Strashko 	}
44169973b48SGrygorii Strashko 
44269973b48SGrygorii Strashko 	tx_chn->psil_paired = true;
44369973b48SGrygorii Strashko 
444bc7e5523SPeter Ujfalusi 	xudma_tchanrt_write(tx_chn->udma_tchanx, UDMA_CHAN_RT_PEER_RT_EN_REG,
44552c74d3dSGrygorii Strashko 			    UDMA_PEER_RT_EN_ENABLE);
446d7024191SGrygorii Strashko 
447bc7e5523SPeter Ujfalusi 	xudma_tchanrt_write(tx_chn->udma_tchanx, UDMA_CHAN_RT_CTL_REG,
44852c74d3dSGrygorii Strashko 			    UDMA_CHAN_RT_CTL_EN);
449d7024191SGrygorii Strashko 
450d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_rt_chn(tx_chn, "txchn en");
451d7024191SGrygorii Strashko 	return 0;
452d7024191SGrygorii Strashko }
453d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_enable_tx_chn);
454d7024191SGrygorii Strashko 
k3_udma_glue_disable_tx_chn(struct k3_udma_glue_tx_channel * tx_chn)455d7024191SGrygorii Strashko void k3_udma_glue_disable_tx_chn(struct k3_udma_glue_tx_channel *tx_chn)
456d7024191SGrygorii Strashko {
457d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_rt_chn(tx_chn, "txchn dis1");
458d7024191SGrygorii Strashko 
459bc7e5523SPeter Ujfalusi 	xudma_tchanrt_write(tx_chn->udma_tchanx, UDMA_CHAN_RT_CTL_REG, 0);
460d7024191SGrygorii Strashko 
461d7024191SGrygorii Strashko 	xudma_tchanrt_write(tx_chn->udma_tchanx,
462bc7e5523SPeter Ujfalusi 			    UDMA_CHAN_RT_PEER_RT_EN_REG, 0);
463d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_rt_chn(tx_chn, "txchn dis2");
46469973b48SGrygorii Strashko 
46569973b48SGrygorii Strashko 	if (tx_chn->psil_paired) {
46669973b48SGrygorii Strashko 		xudma_navss_psil_unpair(tx_chn->common.udmax,
46769973b48SGrygorii Strashko 					tx_chn->common.src_thread,
46869973b48SGrygorii Strashko 					tx_chn->common.dst_thread);
46969973b48SGrygorii Strashko 		tx_chn->psil_paired = false;
47069973b48SGrygorii Strashko 	}
471d7024191SGrygorii Strashko }
472d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_disable_tx_chn);
473d7024191SGrygorii Strashko 
k3_udma_glue_tdown_tx_chn(struct k3_udma_glue_tx_channel * tx_chn,bool sync)474d7024191SGrygorii Strashko void k3_udma_glue_tdown_tx_chn(struct k3_udma_glue_tx_channel *tx_chn,
475d7024191SGrygorii Strashko 			       bool sync)
476d7024191SGrygorii Strashko {
477d7024191SGrygorii Strashko 	int i = 0;
478d7024191SGrygorii Strashko 	u32 val;
479d7024191SGrygorii Strashko 
480d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_rt_chn(tx_chn, "txchn tdown1");
481d7024191SGrygorii Strashko 
482bc7e5523SPeter Ujfalusi 	xudma_tchanrt_write(tx_chn->udma_tchanx, UDMA_CHAN_RT_CTL_REG,
483d7024191SGrygorii Strashko 			    UDMA_CHAN_RT_CTL_EN | UDMA_CHAN_RT_CTL_TDOWN);
484d7024191SGrygorii Strashko 
485bc7e5523SPeter Ujfalusi 	val = xudma_tchanrt_read(tx_chn->udma_tchanx, UDMA_CHAN_RT_CTL_REG);
486d7024191SGrygorii Strashko 
487d7024191SGrygorii Strashko 	while (sync && (val & UDMA_CHAN_RT_CTL_EN)) {
488d7024191SGrygorii Strashko 		val = xudma_tchanrt_read(tx_chn->udma_tchanx,
489bc7e5523SPeter Ujfalusi 					 UDMA_CHAN_RT_CTL_REG);
490d7024191SGrygorii Strashko 		udelay(1);
491d7024191SGrygorii Strashko 		if (i > K3_UDMAX_TDOWN_TIMEOUT_US) {
492d7024191SGrygorii Strashko 			dev_err(tx_chn->common.dev, "TX tdown timeout\n");
493d7024191SGrygorii Strashko 			break;
494d7024191SGrygorii Strashko 		}
495d7024191SGrygorii Strashko 		i++;
496d7024191SGrygorii Strashko 	}
497d7024191SGrygorii Strashko 
498d7024191SGrygorii Strashko 	val = xudma_tchanrt_read(tx_chn->udma_tchanx,
499bc7e5523SPeter Ujfalusi 				 UDMA_CHAN_RT_PEER_RT_EN_REG);
500d7024191SGrygorii Strashko 	if (sync && (val & UDMA_PEER_RT_EN_ENABLE))
501d7024191SGrygorii Strashko 		dev_err(tx_chn->common.dev, "TX tdown peer not stopped\n");
502d7024191SGrygorii Strashko 	k3_udma_glue_dump_tx_rt_chn(tx_chn, "txchn tdown2");
503d7024191SGrygorii Strashko }
504d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_tdown_tx_chn);
505d7024191SGrygorii Strashko 
k3_udma_glue_reset_tx_chn(struct k3_udma_glue_tx_channel * tx_chn,void * data,void (* cleanup)(void * data,dma_addr_t desc_dma))506d7024191SGrygorii Strashko void k3_udma_glue_reset_tx_chn(struct k3_udma_glue_tx_channel *tx_chn,
507d7024191SGrygorii Strashko 			       void *data,
508d7024191SGrygorii Strashko 			       void (*cleanup)(void *data, dma_addr_t desc_dma))
509d7024191SGrygorii Strashko {
5105b65781dSVignesh Raghavendra 	struct device *dev = tx_chn->common.dev;
511d7024191SGrygorii Strashko 	dma_addr_t desc_dma;
512d7024191SGrygorii Strashko 	int occ_tx, i, ret;
513d7024191SGrygorii Strashko 
514d7024191SGrygorii Strashko 	/*
515d7024191SGrygorii Strashko 	 * TXQ reset need to be special way as it is input for udma and its
516d7024191SGrygorii Strashko 	 * state cached by udma, so:
517d7024191SGrygorii Strashko 	 * 1) save TXQ occ
518d7024191SGrygorii Strashko 	 * 2) clean up TXQ and call callback .cleanup() for each desc
519d7024191SGrygorii Strashko 	 * 3) reset TXQ in a special way
520d7024191SGrygorii Strashko 	 */
521d7024191SGrygorii Strashko 	occ_tx = k3_ringacc_ring_get_occ(tx_chn->ringtx);
5225b65781dSVignesh Raghavendra 	dev_dbg(dev, "TX reset occ_tx %u\n", occ_tx);
523d7024191SGrygorii Strashko 
524d7024191SGrygorii Strashko 	for (i = 0; i < occ_tx; i++) {
525d7024191SGrygorii Strashko 		ret = k3_ringacc_ring_pop(tx_chn->ringtx, &desc_dma);
526d7024191SGrygorii Strashko 		if (ret) {
5275b65781dSVignesh Raghavendra 			if (ret != -ENODATA)
5285b65781dSVignesh Raghavendra 				dev_err(dev, "TX reset pop %d\n", ret);
529d7024191SGrygorii Strashko 			break;
530d7024191SGrygorii Strashko 		}
531d7024191SGrygorii Strashko 		cleanup(data, desc_dma);
532d7024191SGrygorii Strashko 	}
533d7024191SGrygorii Strashko 
5345b65781dSVignesh Raghavendra 	/* reset TXCQ as it is not input for udma - expected to be empty */
5355b65781dSVignesh Raghavendra 	k3_ringacc_ring_reset(tx_chn->ringtxcq);
536d7024191SGrygorii Strashko 	k3_ringacc_ring_reset_dma(tx_chn->ringtx, occ_tx);
537d7024191SGrygorii Strashko }
538d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_reset_tx_chn);
539d7024191SGrygorii Strashko 
k3_udma_glue_tx_get_hdesc_size(struct k3_udma_glue_tx_channel * tx_chn)540d7024191SGrygorii Strashko u32 k3_udma_glue_tx_get_hdesc_size(struct k3_udma_glue_tx_channel *tx_chn)
541d7024191SGrygorii Strashko {
542d7024191SGrygorii Strashko 	return tx_chn->common.hdesc_size;
543d7024191SGrygorii Strashko }
544d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_tx_get_hdesc_size);
545d7024191SGrygorii Strashko 
k3_udma_glue_tx_get_txcq_id(struct k3_udma_glue_tx_channel * tx_chn)546d7024191SGrygorii Strashko u32 k3_udma_glue_tx_get_txcq_id(struct k3_udma_glue_tx_channel *tx_chn)
547d7024191SGrygorii Strashko {
548d7024191SGrygorii Strashko 	return k3_ringacc_get_ring_id(tx_chn->ringtxcq);
549d7024191SGrygorii Strashko }
550d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_tx_get_txcq_id);
551d7024191SGrygorii Strashko 
k3_udma_glue_tx_get_irq(struct k3_udma_glue_tx_channel * tx_chn)552d7024191SGrygorii Strashko int k3_udma_glue_tx_get_irq(struct k3_udma_glue_tx_channel *tx_chn)
553d7024191SGrygorii Strashko {
5545b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax)) {
5555b65781dSVignesh Raghavendra 		tx_chn->virq = xudma_pktdma_tflow_get_irq(tx_chn->common.udmax,
5565b65781dSVignesh Raghavendra 							  tx_chn->udma_tflow_id);
5575b65781dSVignesh Raghavendra 	} else {
558d7024191SGrygorii Strashko 		tx_chn->virq = k3_ringacc_get_ring_irq_num(tx_chn->ringtxcq);
5595b65781dSVignesh Raghavendra 	}
560d7024191SGrygorii Strashko 
561*f9a1d321SDan Carpenter 	if (!tx_chn->virq)
562*f9a1d321SDan Carpenter 		return -ENXIO;
563*f9a1d321SDan Carpenter 
564d7024191SGrygorii Strashko 	return tx_chn->virq;
565d7024191SGrygorii Strashko }
566d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_tx_get_irq);
567d7024191SGrygorii Strashko 
568426506a7SPeter Ujfalusi struct device *
k3_udma_glue_tx_get_dma_device(struct k3_udma_glue_tx_channel * tx_chn)569426506a7SPeter Ujfalusi 	k3_udma_glue_tx_get_dma_device(struct k3_udma_glue_tx_channel *tx_chn)
570426506a7SPeter Ujfalusi {
5715b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(tx_chn->common.udmax) &&
5725b65781dSVignesh Raghavendra 	    (tx_chn->common.atype_asel == 14 || tx_chn->common.atype_asel == 15))
5735b65781dSVignesh Raghavendra 		return &tx_chn->common.chan_dev;
5745b65781dSVignesh Raghavendra 
575426506a7SPeter Ujfalusi 	return xudma_get_device(tx_chn->common.udmax);
576426506a7SPeter Ujfalusi }
577426506a7SPeter Ujfalusi EXPORT_SYMBOL_GPL(k3_udma_glue_tx_get_dma_device);
578426506a7SPeter Ujfalusi 
k3_udma_glue_tx_dma_to_cppi5_addr(struct k3_udma_glue_tx_channel * tx_chn,dma_addr_t * addr)5795b65781dSVignesh Raghavendra void k3_udma_glue_tx_dma_to_cppi5_addr(struct k3_udma_glue_tx_channel *tx_chn,
5805b65781dSVignesh Raghavendra 				       dma_addr_t *addr)
5815b65781dSVignesh Raghavendra {
5825b65781dSVignesh Raghavendra 	if (!xudma_is_pktdma(tx_chn->common.udmax) ||
5835b65781dSVignesh Raghavendra 	    !tx_chn->common.atype_asel)
5845b65781dSVignesh Raghavendra 		return;
5855b65781dSVignesh Raghavendra 
5865b65781dSVignesh Raghavendra 	*addr |= (u64)tx_chn->common.atype_asel << K3_ADDRESS_ASEL_SHIFT;
5875b65781dSVignesh Raghavendra }
5885b65781dSVignesh Raghavendra EXPORT_SYMBOL_GPL(k3_udma_glue_tx_dma_to_cppi5_addr);
5895b65781dSVignesh Raghavendra 
k3_udma_glue_tx_cppi5_to_dma_addr(struct k3_udma_glue_tx_channel * tx_chn,dma_addr_t * addr)5905b65781dSVignesh Raghavendra void k3_udma_glue_tx_cppi5_to_dma_addr(struct k3_udma_glue_tx_channel *tx_chn,
5915b65781dSVignesh Raghavendra 				       dma_addr_t *addr)
5925b65781dSVignesh Raghavendra {
5935b65781dSVignesh Raghavendra 	if (!xudma_is_pktdma(tx_chn->common.udmax) ||
5945b65781dSVignesh Raghavendra 	    !tx_chn->common.atype_asel)
5955b65781dSVignesh Raghavendra 		return;
5965b65781dSVignesh Raghavendra 
5975b65781dSVignesh Raghavendra 	*addr &= (u64)GENMASK(K3_ADDRESS_ASEL_SHIFT - 1, 0);
5985b65781dSVignesh Raghavendra }
5995b65781dSVignesh Raghavendra EXPORT_SYMBOL_GPL(k3_udma_glue_tx_cppi5_to_dma_addr);
6005b65781dSVignesh Raghavendra 
k3_udma_glue_cfg_rx_chn(struct k3_udma_glue_rx_channel * rx_chn)601d7024191SGrygorii Strashko static int k3_udma_glue_cfg_rx_chn(struct k3_udma_glue_rx_channel *rx_chn)
602d7024191SGrygorii Strashko {
603d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm = rx_chn->common.tisci_rm;
604d7024191SGrygorii Strashko 	struct ti_sci_msg_rm_udmap_rx_ch_cfg req;
605d7024191SGrygorii Strashko 	int ret;
606d7024191SGrygorii Strashko 
607d7024191SGrygorii Strashko 	memset(&req, 0, sizeof(req));
608d7024191SGrygorii Strashko 
609d7024191SGrygorii Strashko 	req.valid_params = TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
610d7024191SGrygorii Strashko 			   TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID |
611d7024191SGrygorii Strashko 			   TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
6120ebcf1a2SPeter Ujfalusi 			   TI_SCI_MSG_VALUE_RM_UDMAP_CH_ATYPE_VALID;
613d7024191SGrygorii Strashko 
614d7024191SGrygorii Strashko 	req.nav_id = tisci_rm->tisci_dev_id;
615d7024191SGrygorii Strashko 	req.index = rx_chn->udma_rchan_id;
616d7024191SGrygorii Strashko 	req.rx_fetch_size = rx_chn->common.hdesc_size >> 2;
617d7024191SGrygorii Strashko 	/*
618d7024191SGrygorii Strashko 	 * TODO: we can't support rxcq_qnum/RCHAN[a]_RCQ cfg with current sysfw
619d7024191SGrygorii Strashko 	 * and udmax impl, so just configure it to invalid value.
620d7024191SGrygorii Strashko 	 * req.rxcq_qnum = k3_ringacc_get_ring_id(rx_chn->flows[0].ringrx);
621d7024191SGrygorii Strashko 	 */
622d7024191SGrygorii Strashko 	req.rxcq_qnum = 0xFFFF;
6235b65781dSVignesh Raghavendra 	if (!xudma_is_pktdma(rx_chn->common.udmax) && rx_chn->flow_num &&
6245b65781dSVignesh Raghavendra 	    rx_chn->flow_id_base != rx_chn->udma_rchan_id) {
625d7024191SGrygorii Strashko 		/* Default flow + extra ones */
6265b65781dSVignesh Raghavendra 		req.valid_params |= TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_START_VALID |
6275b65781dSVignesh Raghavendra 				    TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_CNT_VALID;
628d7024191SGrygorii Strashko 		req.flowid_start = rx_chn->flow_id_base;
629d7024191SGrygorii Strashko 		req.flowid_cnt = rx_chn->flow_num;
630d7024191SGrygorii Strashko 	}
631d7024191SGrygorii Strashko 	req.rx_chan_type = TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR;
6325b65781dSVignesh Raghavendra 	req.rx_atype = rx_chn->common.atype_asel;
633d7024191SGrygorii Strashko 
634d7024191SGrygorii Strashko 	ret = tisci_rm->tisci_udmap_ops->rx_ch_cfg(tisci_rm->tisci, &req);
635d7024191SGrygorii Strashko 	if (ret)
636d7024191SGrygorii Strashko 		dev_err(rx_chn->common.dev, "rchan%d cfg failed %d\n",
637d7024191SGrygorii Strashko 			rx_chn->udma_rchan_id, ret);
638d7024191SGrygorii Strashko 
639d7024191SGrygorii Strashko 	return ret;
640d7024191SGrygorii Strashko }
641d7024191SGrygorii Strashko 
k3_udma_glue_release_rx_flow(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_num)642d7024191SGrygorii Strashko static void k3_udma_glue_release_rx_flow(struct k3_udma_glue_rx_channel *rx_chn,
643d7024191SGrygorii Strashko 					 u32 flow_num)
644d7024191SGrygorii Strashko {
645d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_num];
646d7024191SGrygorii Strashko 
647d7024191SGrygorii Strashko 	if (IS_ERR_OR_NULL(flow->udma_rflow))
648d7024191SGrygorii Strashko 		return;
649d7024191SGrygorii Strashko 
650d7024191SGrygorii Strashko 	if (flow->ringrxfdq)
651d7024191SGrygorii Strashko 		k3_ringacc_ring_free(flow->ringrxfdq);
652d7024191SGrygorii Strashko 
653d7024191SGrygorii Strashko 	if (flow->ringrx)
654d7024191SGrygorii Strashko 		k3_ringacc_ring_free(flow->ringrx);
655d7024191SGrygorii Strashko 
656d7024191SGrygorii Strashko 	xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow);
657d7024191SGrygorii Strashko 	flow->udma_rflow = NULL;
658d7024191SGrygorii Strashko 	rx_chn->flows_ready--;
659d7024191SGrygorii Strashko }
660d7024191SGrygorii Strashko 
k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_idx,struct k3_udma_glue_rx_flow_cfg * flow_cfg)661d7024191SGrygorii Strashko static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn,
662d7024191SGrygorii Strashko 				    u32 flow_idx,
663d7024191SGrygorii Strashko 				    struct k3_udma_glue_rx_flow_cfg *flow_cfg)
664d7024191SGrygorii Strashko {
665d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_idx];
666d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm = rx_chn->common.tisci_rm;
667d7024191SGrygorii Strashko 	struct device *dev = rx_chn->common.dev;
668d7024191SGrygorii Strashko 	struct ti_sci_msg_rm_udmap_flow_cfg req;
669d7024191SGrygorii Strashko 	int rx_ring_id;
670d7024191SGrygorii Strashko 	int rx_ringfdq_id;
671d7024191SGrygorii Strashko 	int ret = 0;
672d7024191SGrygorii Strashko 
673d7024191SGrygorii Strashko 	flow->udma_rflow = xudma_rflow_get(rx_chn->common.udmax,
674d7024191SGrygorii Strashko 					   flow->udma_rflow_id);
675d7024191SGrygorii Strashko 	if (IS_ERR(flow->udma_rflow)) {
676d7024191SGrygorii Strashko 		ret = PTR_ERR(flow->udma_rflow);
677d7024191SGrygorii Strashko 		dev_err(dev, "UDMAX rflow get err %d\n", ret);
678018af9beSChristophe JAILLET 		return ret;
679d7024191SGrygorii Strashko 	}
680d7024191SGrygorii Strashko 
681d7024191SGrygorii Strashko 	if (flow->udma_rflow_id != xudma_rflow_get_id(flow->udma_rflow)) {
682018af9beSChristophe JAILLET 		ret = -ENODEV;
683018af9beSChristophe JAILLET 		goto err_rflow_put;
684d7024191SGrygorii Strashko 	}
685d7024191SGrygorii Strashko 
6865b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
6875b65781dSVignesh Raghavendra 		rx_ringfdq_id = flow->udma_rflow_id +
6885b65781dSVignesh Raghavendra 				xudma_get_rflow_ring_offset(rx_chn->common.udmax);
6895b65781dSVignesh Raghavendra 		rx_ring_id = 0;
6905b65781dSVignesh Raghavendra 	} else {
6915b65781dSVignesh Raghavendra 		rx_ring_id = flow_cfg->ring_rxq_id;
6925b65781dSVignesh Raghavendra 		rx_ringfdq_id = flow_cfg->ring_rxfdq0_id;
6935b65781dSVignesh Raghavendra 	}
6945b65781dSVignesh Raghavendra 
695d7024191SGrygorii Strashko 	/* request and cfg rings */
6964927b1abSPeter Ujfalusi 	ret =  k3_ringacc_request_rings_pair(rx_chn->common.ringacc,
6975b65781dSVignesh Raghavendra 					     rx_ringfdq_id, rx_ring_id,
6984927b1abSPeter Ujfalusi 					     &flow->ringrxfdq,
6994927b1abSPeter Ujfalusi 					     &flow->ringrx);
7004927b1abSPeter Ujfalusi 	if (ret) {
7014927b1abSPeter Ujfalusi 		dev_err(dev, "Failed to get RX/RXFDQ rings %d\n", ret);
702018af9beSChristophe JAILLET 		goto err_rflow_put;
703d7024191SGrygorii Strashko 	}
704d7024191SGrygorii Strashko 
705d553e2abSPeter Ujfalusi 	/* Set the dma_dev for the rings to be configured */
706d553e2abSPeter Ujfalusi 	flow_cfg->rx_cfg.dma_dev = k3_udma_glue_rx_get_dma_device(rx_chn);
707d553e2abSPeter Ujfalusi 	flow_cfg->rxfdq_cfg.dma_dev = flow_cfg->rx_cfg.dma_dev;
708d553e2abSPeter Ujfalusi 
7095b65781dSVignesh Raghavendra 	/* Set the ASEL value for DMA rings of PKTDMA */
7105b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
7115b65781dSVignesh Raghavendra 		flow_cfg->rx_cfg.asel = rx_chn->common.atype_asel;
7125b65781dSVignesh Raghavendra 		flow_cfg->rxfdq_cfg.asel = rx_chn->common.atype_asel;
7135b65781dSVignesh Raghavendra 	}
7145b65781dSVignesh Raghavendra 
715d7024191SGrygorii Strashko 	ret = k3_ringacc_ring_cfg(flow->ringrx, &flow_cfg->rx_cfg);
716d7024191SGrygorii Strashko 	if (ret) {
717d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg ringrx %d\n", ret);
718018af9beSChristophe JAILLET 		goto err_ringrxfdq_free;
719d7024191SGrygorii Strashko 	}
720d7024191SGrygorii Strashko 
721d7024191SGrygorii Strashko 	ret = k3_ringacc_ring_cfg(flow->ringrxfdq, &flow_cfg->rxfdq_cfg);
722d7024191SGrygorii Strashko 	if (ret) {
723d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg ringrxfdq %d\n", ret);
724018af9beSChristophe JAILLET 		goto err_ringrxfdq_free;
725d7024191SGrygorii Strashko 	}
726d7024191SGrygorii Strashko 
727d7024191SGrygorii Strashko 	if (rx_chn->remote) {
728d7024191SGrygorii Strashko 		rx_ring_id = TI_SCI_RESOURCE_NULL;
729d7024191SGrygorii Strashko 		rx_ringfdq_id = TI_SCI_RESOURCE_NULL;
730d7024191SGrygorii Strashko 	} else {
731d7024191SGrygorii Strashko 		rx_ring_id = k3_ringacc_get_ring_id(flow->ringrx);
732d7024191SGrygorii Strashko 		rx_ringfdq_id = k3_ringacc_get_ring_id(flow->ringrxfdq);
733d7024191SGrygorii Strashko 	}
734d7024191SGrygorii Strashko 
735d7024191SGrygorii Strashko 	memset(&req, 0, sizeof(req));
736d7024191SGrygorii Strashko 
737d7024191SGrygorii Strashko 	req.valid_params =
738d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_EINFO_PRESENT_VALID |
739d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PSINFO_PRESENT_VALID |
740d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_ERROR_HANDLING_VALID |
741d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DESC_TYPE_VALID |
742d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID |
743d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_HI_SEL_VALID |
744d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_LO_SEL_VALID |
745d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_HI_SEL_VALID |
746d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_LO_SEL_VALID |
747d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID |
748d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID |
749d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID |
750d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID;
751d7024191SGrygorii Strashko 	req.nav_id = tisci_rm->tisci_dev_id;
752d7024191SGrygorii Strashko 	req.flow_index = flow->udma_rflow_id;
753d7024191SGrygorii Strashko 	if (rx_chn->common.epib)
754d7024191SGrygorii Strashko 		req.rx_einfo_present = 1;
755d7024191SGrygorii Strashko 	if (rx_chn->common.psdata_size)
756d7024191SGrygorii Strashko 		req.rx_psinfo_present = 1;
757d7024191SGrygorii Strashko 	if (flow_cfg->rx_error_handling)
758d7024191SGrygorii Strashko 		req.rx_error_handling = 1;
759d7024191SGrygorii Strashko 	req.rx_desc_type = 0;
760d7024191SGrygorii Strashko 	req.rx_dest_qnum = rx_ring_id;
761d7024191SGrygorii Strashko 	req.rx_src_tag_hi_sel = 0;
762d7024191SGrygorii Strashko 	req.rx_src_tag_lo_sel = flow_cfg->src_tag_lo_sel;
763d7024191SGrygorii Strashko 	req.rx_dest_tag_hi_sel = 0;
764d7024191SGrygorii Strashko 	req.rx_dest_tag_lo_sel = 0;
765d7024191SGrygorii Strashko 	req.rx_fdq0_sz0_qnum = rx_ringfdq_id;
766d7024191SGrygorii Strashko 	req.rx_fdq1_qnum = rx_ringfdq_id;
767d7024191SGrygorii Strashko 	req.rx_fdq2_qnum = rx_ringfdq_id;
768d7024191SGrygorii Strashko 	req.rx_fdq3_qnum = rx_ringfdq_id;
769d7024191SGrygorii Strashko 
770d7024191SGrygorii Strashko 	ret = tisci_rm->tisci_udmap_ops->rx_flow_cfg(tisci_rm->tisci, &req);
771d7024191SGrygorii Strashko 	if (ret) {
772d7024191SGrygorii Strashko 		dev_err(dev, "flow%d config failed: %d\n", flow->udma_rflow_id,
773d7024191SGrygorii Strashko 			ret);
774018af9beSChristophe JAILLET 		goto err_ringrxfdq_free;
775d7024191SGrygorii Strashko 	}
776d7024191SGrygorii Strashko 
777d7024191SGrygorii Strashko 	rx_chn->flows_ready++;
778d7024191SGrygorii Strashko 	dev_dbg(dev, "flow%d config done. ready:%d\n",
779d7024191SGrygorii Strashko 		flow->udma_rflow_id, rx_chn->flows_ready);
780d7024191SGrygorii Strashko 
781d7024191SGrygorii Strashko 	return 0;
782018af9beSChristophe JAILLET 
783018af9beSChristophe JAILLET err_ringrxfdq_free:
784018af9beSChristophe JAILLET 	k3_ringacc_ring_free(flow->ringrxfdq);
785018af9beSChristophe JAILLET 	k3_ringacc_ring_free(flow->ringrx);
786018af9beSChristophe JAILLET 
787018af9beSChristophe JAILLET err_rflow_put:
788018af9beSChristophe JAILLET 	xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow);
789018af9beSChristophe JAILLET 	flow->udma_rflow = NULL;
790018af9beSChristophe JAILLET 
791d7024191SGrygorii Strashko 	return ret;
792d7024191SGrygorii Strashko }
793d7024191SGrygorii Strashko 
k3_udma_glue_dump_rx_chn(struct k3_udma_glue_rx_channel * chn)794d7024191SGrygorii Strashko static void k3_udma_glue_dump_rx_chn(struct k3_udma_glue_rx_channel *chn)
795d7024191SGrygorii Strashko {
796d7024191SGrygorii Strashko 	struct device *dev = chn->common.dev;
797d7024191SGrygorii Strashko 
798d7024191SGrygorii Strashko 	dev_dbg(dev, "dump_rx_chn:\n"
799d7024191SGrygorii Strashko 		"udma_rchan_id: %d\n"
800d7024191SGrygorii Strashko 		"src_thread: %08x\n"
801d7024191SGrygorii Strashko 		"dst_thread: %08x\n"
802d7024191SGrygorii Strashko 		"epib: %d\n"
803d7024191SGrygorii Strashko 		"hdesc_size: %u\n"
804d7024191SGrygorii Strashko 		"psdata_size: %u\n"
805d7024191SGrygorii Strashko 		"swdata_size: %u\n"
806d7024191SGrygorii Strashko 		"flow_id_base: %d\n"
807d7024191SGrygorii Strashko 		"flow_num: %d\n",
808d7024191SGrygorii Strashko 		chn->udma_rchan_id,
809d7024191SGrygorii Strashko 		chn->common.src_thread,
810d7024191SGrygorii Strashko 		chn->common.dst_thread,
811d7024191SGrygorii Strashko 		chn->common.epib,
812d7024191SGrygorii Strashko 		chn->common.hdesc_size,
813d7024191SGrygorii Strashko 		chn->common.psdata_size,
814d7024191SGrygorii Strashko 		chn->common.swdata_size,
815d7024191SGrygorii Strashko 		chn->flow_id_base,
816d7024191SGrygorii Strashko 		chn->flow_num);
817d7024191SGrygorii Strashko }
818d7024191SGrygorii Strashko 
k3_udma_glue_dump_rx_rt_chn(struct k3_udma_glue_rx_channel * chn,char * mark)819d7024191SGrygorii Strashko static void k3_udma_glue_dump_rx_rt_chn(struct k3_udma_glue_rx_channel *chn,
820d7024191SGrygorii Strashko 					char *mark)
821d7024191SGrygorii Strashko {
822d7024191SGrygorii Strashko 	struct device *dev = chn->common.dev;
823d7024191SGrygorii Strashko 
824d7024191SGrygorii Strashko 	dev_dbg(dev, "=== dump ===> %s\n", mark);
825d7024191SGrygorii Strashko 
826bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_CTL_REG,
827bc7e5523SPeter Ujfalusi 		xudma_rchanrt_read(chn->udma_rchanx, UDMA_CHAN_RT_CTL_REG));
828bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_PEER_RT_EN_REG,
829d7024191SGrygorii Strashko 		xudma_rchanrt_read(chn->udma_rchanx,
830bc7e5523SPeter Ujfalusi 				   UDMA_CHAN_RT_PEER_RT_EN_REG));
831bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_PCNT_REG,
832bc7e5523SPeter Ujfalusi 		xudma_rchanrt_read(chn->udma_rchanx, UDMA_CHAN_RT_PCNT_REG));
833bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_BCNT_REG,
834bc7e5523SPeter Ujfalusi 		xudma_rchanrt_read(chn->udma_rchanx, UDMA_CHAN_RT_BCNT_REG));
835bc7e5523SPeter Ujfalusi 	dev_dbg(dev, "0x%08X: %08X\n", UDMA_CHAN_RT_SBCNT_REG,
836bc7e5523SPeter Ujfalusi 		xudma_rchanrt_read(chn->udma_rchanx, UDMA_CHAN_RT_SBCNT_REG));
837d7024191SGrygorii Strashko }
838d7024191SGrygorii Strashko 
839d7024191SGrygorii Strashko static int
k3_udma_glue_allocate_rx_flows(struct k3_udma_glue_rx_channel * rx_chn,struct k3_udma_glue_rx_channel_cfg * cfg)840d7024191SGrygorii Strashko k3_udma_glue_allocate_rx_flows(struct k3_udma_glue_rx_channel *rx_chn,
841d7024191SGrygorii Strashko 			       struct k3_udma_glue_rx_channel_cfg *cfg)
842d7024191SGrygorii Strashko {
843d7024191SGrygorii Strashko 	int ret;
844d7024191SGrygorii Strashko 
845d7024191SGrygorii Strashko 	/* default rflow */
846d7024191SGrygorii Strashko 	if (cfg->flow_id_use_rxchan_id)
847d7024191SGrygorii Strashko 		return 0;
848d7024191SGrygorii Strashko 
849d7024191SGrygorii Strashko 	/* not a GP rflows */
850d7024191SGrygorii Strashko 	if (rx_chn->flow_id_base != -1 &&
851d7024191SGrygorii Strashko 	    !xudma_rflow_is_gp(rx_chn->common.udmax, rx_chn->flow_id_base))
852d7024191SGrygorii Strashko 		return 0;
853d7024191SGrygorii Strashko 
854d7024191SGrygorii Strashko 	/* Allocate range of GP rflows */
855d7024191SGrygorii Strashko 	ret = xudma_alloc_gp_rflow_range(rx_chn->common.udmax,
856d7024191SGrygorii Strashko 					 rx_chn->flow_id_base,
857d7024191SGrygorii Strashko 					 rx_chn->flow_num);
858d7024191SGrygorii Strashko 	if (ret < 0) {
859d7024191SGrygorii Strashko 		dev_err(rx_chn->common.dev, "UDMAX reserve_rflow %d cnt:%d err: %d\n",
860d7024191SGrygorii Strashko 			rx_chn->flow_id_base, rx_chn->flow_num, ret);
861d7024191SGrygorii Strashko 		return ret;
862d7024191SGrygorii Strashko 	}
863d7024191SGrygorii Strashko 	rx_chn->flow_id_base = ret;
864d7024191SGrygorii Strashko 
865d7024191SGrygorii Strashko 	return 0;
866d7024191SGrygorii Strashko }
867d7024191SGrygorii Strashko 
868d7024191SGrygorii Strashko static struct k3_udma_glue_rx_channel *
k3_udma_glue_request_rx_chn_priv(struct device * dev,const char * name,struct k3_udma_glue_rx_channel_cfg * cfg)869d7024191SGrygorii Strashko k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name,
870d7024191SGrygorii Strashko 				 struct k3_udma_glue_rx_channel_cfg *cfg)
871d7024191SGrygorii Strashko {
872d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_channel *rx_chn;
8735b65781dSVignesh Raghavendra 	struct psil_endpoint_config *ep_cfg;
874d7024191SGrygorii Strashko 	int ret, i;
875d7024191SGrygorii Strashko 
876d7024191SGrygorii Strashko 	if (cfg->flow_id_num <= 0)
877d7024191SGrygorii Strashko 		return ERR_PTR(-EINVAL);
878d7024191SGrygorii Strashko 
879d7024191SGrygorii Strashko 	if (cfg->flow_id_num != 1 &&
880d7024191SGrygorii Strashko 	    (cfg->def_flow_cfg || cfg->flow_id_use_rxchan_id))
881d7024191SGrygorii Strashko 		return ERR_PTR(-EINVAL);
882d7024191SGrygorii Strashko 
883d7024191SGrygorii Strashko 	rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL);
884d7024191SGrygorii Strashko 	if (!rx_chn)
885d7024191SGrygorii Strashko 		return ERR_PTR(-ENOMEM);
886d7024191SGrygorii Strashko 
887d7024191SGrygorii Strashko 	rx_chn->common.dev = dev;
888d7024191SGrygorii Strashko 	rx_chn->common.swdata_size = cfg->swdata_size;
889d7024191SGrygorii Strashko 	rx_chn->remote = false;
890d7024191SGrygorii Strashko 
891d7024191SGrygorii Strashko 	/* parse of udmap channel */
892d7024191SGrygorii Strashko 	ret = of_k3_udma_glue_parse_chn(dev->of_node, name,
893d7024191SGrygorii Strashko 					&rx_chn->common, false);
894d7024191SGrygorii Strashko 	if (ret)
895d7024191SGrygorii Strashko 		goto err;
896d7024191SGrygorii Strashko 
897d7024191SGrygorii Strashko 	rx_chn->common.hdesc_size = cppi5_hdesc_calc_size(rx_chn->common.epib,
898d7024191SGrygorii Strashko 						rx_chn->common.psdata_size,
899d7024191SGrygorii Strashko 						rx_chn->common.swdata_size);
900d7024191SGrygorii Strashko 
9015b65781dSVignesh Raghavendra 	ep_cfg = rx_chn->common.ep_config;
9025b65781dSVignesh Raghavendra 
9035b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax))
9045b65781dSVignesh Raghavendra 		rx_chn->udma_rchan_id = ep_cfg->mapped_channel_id;
9055b65781dSVignesh Raghavendra 	else
9065b65781dSVignesh Raghavendra 		rx_chn->udma_rchan_id = -1;
9075b65781dSVignesh Raghavendra 
908d7024191SGrygorii Strashko 	/* request and cfg UDMAP RX channel */
9095b65781dSVignesh Raghavendra 	rx_chn->udma_rchanx = xudma_rchan_get(rx_chn->common.udmax,
9105b65781dSVignesh Raghavendra 					      rx_chn->udma_rchan_id);
911d7024191SGrygorii Strashko 	if (IS_ERR(rx_chn->udma_rchanx)) {
912d7024191SGrygorii Strashko 		ret = PTR_ERR(rx_chn->udma_rchanx);
913d7024191SGrygorii Strashko 		dev_err(dev, "UDMAX rchanx get err %d\n", ret);
914d7024191SGrygorii Strashko 		goto err;
915d7024191SGrygorii Strashko 	}
916d7024191SGrygorii Strashko 	rx_chn->udma_rchan_id = xudma_rchan_get_id(rx_chn->udma_rchanx);
917d7024191SGrygorii Strashko 
9185b65781dSVignesh Raghavendra 	rx_chn->common.chan_dev.class = &k3_udma_glue_devclass;
9195b65781dSVignesh Raghavendra 	rx_chn->common.chan_dev.parent = xudma_get_device(rx_chn->common.udmax);
9205b65781dSVignesh Raghavendra 	dev_set_name(&rx_chn->common.chan_dev, "rchan%d-0x%04x",
9215b65781dSVignesh Raghavendra 		     rx_chn->udma_rchan_id, rx_chn->common.src_thread);
9225b65781dSVignesh Raghavendra 	ret = device_register(&rx_chn->common.chan_dev);
9235b65781dSVignesh Raghavendra 	if (ret) {
9245b65781dSVignesh Raghavendra 		dev_err(dev, "Channel Device registration failed %d\n", ret);
925ac2b9f34SYang Yingliang 		put_device(&rx_chn->common.chan_dev);
9265b65781dSVignesh Raghavendra 		rx_chn->common.chan_dev.parent = NULL;
9275b65781dSVignesh Raghavendra 		goto err;
9285b65781dSVignesh Raghavendra 	}
9295b65781dSVignesh Raghavendra 
9305b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
9315b65781dSVignesh Raghavendra 		/* prepare the channel device as coherent */
9325b65781dSVignesh Raghavendra 		rx_chn->common.chan_dev.dma_coherent = true;
9335b65781dSVignesh Raghavendra 		dma_coerce_mask_and_coherent(&rx_chn->common.chan_dev,
9345b65781dSVignesh Raghavendra 					     DMA_BIT_MASK(48));
9355b65781dSVignesh Raghavendra 	}
9365b65781dSVignesh Raghavendra 
9375b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
9385b65781dSVignesh Raghavendra 		int flow_start = cfg->flow_id_base;
9395b65781dSVignesh Raghavendra 		int flow_end;
9405b65781dSVignesh Raghavendra 
9415b65781dSVignesh Raghavendra 		if (flow_start == -1)
9425b65781dSVignesh Raghavendra 			flow_start = ep_cfg->flow_start;
9435b65781dSVignesh Raghavendra 
9445b65781dSVignesh Raghavendra 		flow_end = flow_start + cfg->flow_id_num - 1;
9455b65781dSVignesh Raghavendra 		if (flow_start < ep_cfg->flow_start ||
9465b65781dSVignesh Raghavendra 		    flow_end > (ep_cfg->flow_start + ep_cfg->flow_num - 1)) {
9475b65781dSVignesh Raghavendra 			dev_err(dev, "Invalid flow range requested\n");
9485b65781dSVignesh Raghavendra 			ret = -EINVAL;
9495b65781dSVignesh Raghavendra 			goto err;
9505b65781dSVignesh Raghavendra 		}
9515b65781dSVignesh Raghavendra 		rx_chn->flow_id_base = flow_start;
9525b65781dSVignesh Raghavendra 	} else {
953d7024191SGrygorii Strashko 		rx_chn->flow_id_base = cfg->flow_id_base;
954d7024191SGrygorii Strashko 
955d7024191SGrygorii Strashko 		/* Use RX channel id as flow id: target dev can't generate flow_id */
956d7024191SGrygorii Strashko 		if (cfg->flow_id_use_rxchan_id)
957d7024191SGrygorii Strashko 			rx_chn->flow_id_base = rx_chn->udma_rchan_id;
9585b65781dSVignesh Raghavendra 	}
9595b65781dSVignesh Raghavendra 
9605b65781dSVignesh Raghavendra 	rx_chn->flow_num = cfg->flow_id_num;
961d7024191SGrygorii Strashko 
962d7024191SGrygorii Strashko 	rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num,
963d7024191SGrygorii Strashko 				     sizeof(*rx_chn->flows), GFP_KERNEL);
964d7024191SGrygorii Strashko 	if (!rx_chn->flows) {
965d7024191SGrygorii Strashko 		ret = -ENOMEM;
966d7024191SGrygorii Strashko 		goto err;
967d7024191SGrygorii Strashko 	}
968d7024191SGrygorii Strashko 
969d7024191SGrygorii Strashko 	ret = k3_udma_glue_allocate_rx_flows(rx_chn, cfg);
970d7024191SGrygorii Strashko 	if (ret)
971d7024191SGrygorii Strashko 		goto err;
972d7024191SGrygorii Strashko 
973d7024191SGrygorii Strashko 	for (i = 0; i < rx_chn->flow_num; i++)
974d7024191SGrygorii Strashko 		rx_chn->flows[i].udma_rflow_id = rx_chn->flow_id_base + i;
975d7024191SGrygorii Strashko 
976d7024191SGrygorii Strashko 	/* request and cfg psi-l */
977d7024191SGrygorii Strashko 	rx_chn->common.dst_thread =
978d7024191SGrygorii Strashko 			xudma_dev_get_psil_base(rx_chn->common.udmax) +
979d7024191SGrygorii Strashko 			rx_chn->udma_rchan_id;
980d7024191SGrygorii Strashko 
981d7024191SGrygorii Strashko 	ret = k3_udma_glue_cfg_rx_chn(rx_chn);
982d7024191SGrygorii Strashko 	if (ret) {
983d7024191SGrygorii Strashko 		dev_err(dev, "Failed to cfg rchan %d\n", ret);
984d7024191SGrygorii Strashko 		goto err;
985d7024191SGrygorii Strashko 	}
986d7024191SGrygorii Strashko 
987d7024191SGrygorii Strashko 	/* init default RX flow only if flow_num = 1 */
988d7024191SGrygorii Strashko 	if (cfg->def_flow_cfg) {
989d7024191SGrygorii Strashko 		ret = k3_udma_glue_cfg_rx_flow(rx_chn, 0, cfg->def_flow_cfg);
990d7024191SGrygorii Strashko 		if (ret)
991d7024191SGrygorii Strashko 			goto err;
992d7024191SGrygorii Strashko 	}
993d7024191SGrygorii Strashko 
994d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_chn(rx_chn);
995d7024191SGrygorii Strashko 
996d7024191SGrygorii Strashko 	return rx_chn;
997d7024191SGrygorii Strashko 
998d7024191SGrygorii Strashko err:
999d7024191SGrygorii Strashko 	k3_udma_glue_release_rx_chn(rx_chn);
1000d7024191SGrygorii Strashko 	return ERR_PTR(ret);
1001d7024191SGrygorii Strashko }
1002d7024191SGrygorii Strashko 
1003d7024191SGrygorii Strashko 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)1004d7024191SGrygorii Strashko k3_udma_glue_request_remote_rx_chn(struct device *dev, const char *name,
1005d7024191SGrygorii Strashko 				   struct k3_udma_glue_rx_channel_cfg *cfg)
1006d7024191SGrygorii Strashko {
1007d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_channel *rx_chn;
1008d7024191SGrygorii Strashko 	int ret, i;
1009d7024191SGrygorii Strashko 
1010d7024191SGrygorii Strashko 	if (cfg->flow_id_num <= 0 ||
1011d7024191SGrygorii Strashko 	    cfg->flow_id_use_rxchan_id ||
1012d7024191SGrygorii Strashko 	    cfg->def_flow_cfg ||
1013d7024191SGrygorii Strashko 	    cfg->flow_id_base < 0)
1014d7024191SGrygorii Strashko 		return ERR_PTR(-EINVAL);
1015d7024191SGrygorii Strashko 
1016d7024191SGrygorii Strashko 	/*
1017d7024191SGrygorii Strashko 	 * Remote RX channel is under control of Remote CPU core, so
1018d7024191SGrygorii Strashko 	 * Linux can only request and manipulate by dedicated RX flows
1019d7024191SGrygorii Strashko 	 */
1020d7024191SGrygorii Strashko 
1021d7024191SGrygorii Strashko 	rx_chn = devm_kzalloc(dev, sizeof(*rx_chn), GFP_KERNEL);
1022d7024191SGrygorii Strashko 	if (!rx_chn)
1023d7024191SGrygorii Strashko 		return ERR_PTR(-ENOMEM);
1024d7024191SGrygorii Strashko 
1025d7024191SGrygorii Strashko 	rx_chn->common.dev = dev;
1026d7024191SGrygorii Strashko 	rx_chn->common.swdata_size = cfg->swdata_size;
1027d7024191SGrygorii Strashko 	rx_chn->remote = true;
1028d7024191SGrygorii Strashko 	rx_chn->udma_rchan_id = -1;
1029d7024191SGrygorii Strashko 	rx_chn->flow_num = cfg->flow_id_num;
1030d7024191SGrygorii Strashko 	rx_chn->flow_id_base = cfg->flow_id_base;
1031d7024191SGrygorii Strashko 	rx_chn->psil_paired = false;
1032d7024191SGrygorii Strashko 
1033d7024191SGrygorii Strashko 	/* parse of udmap channel */
1034d7024191SGrygorii Strashko 	ret = of_k3_udma_glue_parse_chn(dev->of_node, name,
1035d7024191SGrygorii Strashko 					&rx_chn->common, false);
1036d7024191SGrygorii Strashko 	if (ret)
1037d7024191SGrygorii Strashko 		goto err;
1038d7024191SGrygorii Strashko 
1039d7024191SGrygorii Strashko 	rx_chn->common.hdesc_size = cppi5_hdesc_calc_size(rx_chn->common.epib,
1040d7024191SGrygorii Strashko 						rx_chn->common.psdata_size,
1041d7024191SGrygorii Strashko 						rx_chn->common.swdata_size);
1042d7024191SGrygorii Strashko 
1043d7024191SGrygorii Strashko 	rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num,
1044d7024191SGrygorii Strashko 				     sizeof(*rx_chn->flows), GFP_KERNEL);
1045d7024191SGrygorii Strashko 	if (!rx_chn->flows) {
1046d7024191SGrygorii Strashko 		ret = -ENOMEM;
1047d7024191SGrygorii Strashko 		goto err;
1048d7024191SGrygorii Strashko 	}
1049d7024191SGrygorii Strashko 
10505b65781dSVignesh Raghavendra 	rx_chn->common.chan_dev.class = &k3_udma_glue_devclass;
10515b65781dSVignesh Raghavendra 	rx_chn->common.chan_dev.parent = xudma_get_device(rx_chn->common.udmax);
10525b65781dSVignesh Raghavendra 	dev_set_name(&rx_chn->common.chan_dev, "rchan_remote-0x%04x",
10535b65781dSVignesh Raghavendra 		     rx_chn->common.src_thread);
10545b65781dSVignesh Raghavendra 	ret = device_register(&rx_chn->common.chan_dev);
10555b65781dSVignesh Raghavendra 	if (ret) {
10565b65781dSVignesh Raghavendra 		dev_err(dev, "Channel Device registration failed %d\n", ret);
1057ac2b9f34SYang Yingliang 		put_device(&rx_chn->common.chan_dev);
10585b65781dSVignesh Raghavendra 		rx_chn->common.chan_dev.parent = NULL;
10595b65781dSVignesh Raghavendra 		goto err;
10605b65781dSVignesh Raghavendra 	}
10615b65781dSVignesh Raghavendra 
10625b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
10635b65781dSVignesh Raghavendra 		/* prepare the channel device as coherent */
10645b65781dSVignesh Raghavendra 		rx_chn->common.chan_dev.dma_coherent = true;
10655b65781dSVignesh Raghavendra 		dma_coerce_mask_and_coherent(&rx_chn->common.chan_dev,
10665b65781dSVignesh Raghavendra 					     DMA_BIT_MASK(48));
10675b65781dSVignesh Raghavendra 	}
10685b65781dSVignesh Raghavendra 
1069d7024191SGrygorii Strashko 	ret = k3_udma_glue_allocate_rx_flows(rx_chn, cfg);
1070d7024191SGrygorii Strashko 	if (ret)
1071d7024191SGrygorii Strashko 		goto err;
1072d7024191SGrygorii Strashko 
1073d7024191SGrygorii Strashko 	for (i = 0; i < rx_chn->flow_num; i++)
1074d7024191SGrygorii Strashko 		rx_chn->flows[i].udma_rflow_id = rx_chn->flow_id_base + i;
1075d7024191SGrygorii Strashko 
1076d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_chn(rx_chn);
1077d7024191SGrygorii Strashko 
1078d7024191SGrygorii Strashko 	return rx_chn;
1079d7024191SGrygorii Strashko 
1080d7024191SGrygorii Strashko err:
1081d7024191SGrygorii Strashko 	k3_udma_glue_release_rx_chn(rx_chn);
1082d7024191SGrygorii Strashko 	return ERR_PTR(ret);
1083d7024191SGrygorii Strashko }
1084d7024191SGrygorii Strashko 
1085d7024191SGrygorii Strashko struct k3_udma_glue_rx_channel *
k3_udma_glue_request_rx_chn(struct device * dev,const char * name,struct k3_udma_glue_rx_channel_cfg * cfg)1086d7024191SGrygorii Strashko k3_udma_glue_request_rx_chn(struct device *dev, const char *name,
1087d7024191SGrygorii Strashko 			    struct k3_udma_glue_rx_channel_cfg *cfg)
1088d7024191SGrygorii Strashko {
1089d7024191SGrygorii Strashko 	if (cfg->remote)
1090d7024191SGrygorii Strashko 		return k3_udma_glue_request_remote_rx_chn(dev, name, cfg);
1091d7024191SGrygorii Strashko 	else
1092d7024191SGrygorii Strashko 		return k3_udma_glue_request_rx_chn_priv(dev, name, cfg);
1093d7024191SGrygorii Strashko }
1094d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_request_rx_chn);
1095d7024191SGrygorii Strashko 
k3_udma_glue_release_rx_chn(struct k3_udma_glue_rx_channel * rx_chn)1096d7024191SGrygorii Strashko void k3_udma_glue_release_rx_chn(struct k3_udma_glue_rx_channel *rx_chn)
1097d7024191SGrygorii Strashko {
1098d7024191SGrygorii Strashko 	int i;
1099d7024191SGrygorii Strashko 
1100d7024191SGrygorii Strashko 	if (IS_ERR_OR_NULL(rx_chn->common.udmax))
1101d7024191SGrygorii Strashko 		return;
1102d7024191SGrygorii Strashko 
1103d7024191SGrygorii Strashko 	if (rx_chn->psil_paired) {
1104d7024191SGrygorii Strashko 		xudma_navss_psil_unpair(rx_chn->common.udmax,
1105d7024191SGrygorii Strashko 					rx_chn->common.src_thread,
1106d7024191SGrygorii Strashko 					rx_chn->common.dst_thread);
1107d7024191SGrygorii Strashko 		rx_chn->psil_paired = false;
1108d7024191SGrygorii Strashko 	}
1109d7024191SGrygorii Strashko 
1110d7024191SGrygorii Strashko 	for (i = 0; i < rx_chn->flow_num; i++)
1111d7024191SGrygorii Strashko 		k3_udma_glue_release_rx_flow(rx_chn, i);
1112d7024191SGrygorii Strashko 
1113d7024191SGrygorii Strashko 	if (xudma_rflow_is_gp(rx_chn->common.udmax, rx_chn->flow_id_base))
1114d7024191SGrygorii Strashko 		xudma_free_gp_rflow_range(rx_chn->common.udmax,
1115d7024191SGrygorii Strashko 					  rx_chn->flow_id_base,
1116d7024191SGrygorii Strashko 					  rx_chn->flow_num);
1117d7024191SGrygorii Strashko 
1118d7024191SGrygorii Strashko 	if (!IS_ERR_OR_NULL(rx_chn->udma_rchanx))
1119d7024191SGrygorii Strashko 		xudma_rchan_put(rx_chn->common.udmax,
1120d7024191SGrygorii Strashko 				rx_chn->udma_rchanx);
11215b65781dSVignesh Raghavendra 
11225b65781dSVignesh Raghavendra 	if (rx_chn->common.chan_dev.parent) {
11235b65781dSVignesh Raghavendra 		device_unregister(&rx_chn->common.chan_dev);
11245b65781dSVignesh Raghavendra 		rx_chn->common.chan_dev.parent = NULL;
11255b65781dSVignesh Raghavendra 	}
1126d7024191SGrygorii Strashko }
1127d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_release_rx_chn);
1128d7024191SGrygorii Strashko 
k3_udma_glue_rx_flow_init(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_idx,struct k3_udma_glue_rx_flow_cfg * flow_cfg)1129d7024191SGrygorii Strashko int k3_udma_glue_rx_flow_init(struct k3_udma_glue_rx_channel *rx_chn,
1130d7024191SGrygorii Strashko 			      u32 flow_idx,
1131d7024191SGrygorii Strashko 			      struct k3_udma_glue_rx_flow_cfg *flow_cfg)
1132d7024191SGrygorii Strashko {
1133d7024191SGrygorii Strashko 	if (flow_idx >= rx_chn->flow_num)
1134d7024191SGrygorii Strashko 		return -EINVAL;
1135d7024191SGrygorii Strashko 
1136d7024191SGrygorii Strashko 	return k3_udma_glue_cfg_rx_flow(rx_chn, flow_idx, flow_cfg);
1137d7024191SGrygorii Strashko }
1138d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_flow_init);
1139d7024191SGrygorii Strashko 
k3_udma_glue_rx_flow_get_fdq_id(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_idx)1140d7024191SGrygorii Strashko u32 k3_udma_glue_rx_flow_get_fdq_id(struct k3_udma_glue_rx_channel *rx_chn,
1141d7024191SGrygorii Strashko 				    u32 flow_idx)
1142d7024191SGrygorii Strashko {
1143d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow;
1144d7024191SGrygorii Strashko 
1145d7024191SGrygorii Strashko 	if (flow_idx >= rx_chn->flow_num)
1146d7024191SGrygorii Strashko 		return -EINVAL;
1147d7024191SGrygorii Strashko 
1148d7024191SGrygorii Strashko 	flow = &rx_chn->flows[flow_idx];
1149d7024191SGrygorii Strashko 
1150d7024191SGrygorii Strashko 	return k3_ringacc_get_ring_id(flow->ringrxfdq);
1151d7024191SGrygorii Strashko }
1152d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_flow_get_fdq_id);
1153d7024191SGrygorii Strashko 
k3_udma_glue_rx_get_flow_id_base(struct k3_udma_glue_rx_channel * rx_chn)1154d7024191SGrygorii Strashko u32 k3_udma_glue_rx_get_flow_id_base(struct k3_udma_glue_rx_channel *rx_chn)
1155d7024191SGrygorii Strashko {
1156d7024191SGrygorii Strashko 	return rx_chn->flow_id_base;
1157d7024191SGrygorii Strashko }
1158d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_get_flow_id_base);
1159d7024191SGrygorii Strashko 
k3_udma_glue_rx_flow_enable(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_idx)1160d7024191SGrygorii Strashko int k3_udma_glue_rx_flow_enable(struct k3_udma_glue_rx_channel *rx_chn,
1161d7024191SGrygorii Strashko 				u32 flow_idx)
1162d7024191SGrygorii Strashko {
1163d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_idx];
1164d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm = rx_chn->common.tisci_rm;
1165d7024191SGrygorii Strashko 	struct device *dev = rx_chn->common.dev;
1166d7024191SGrygorii Strashko 	struct ti_sci_msg_rm_udmap_flow_cfg req;
1167d7024191SGrygorii Strashko 	int rx_ring_id;
1168d7024191SGrygorii Strashko 	int rx_ringfdq_id;
1169d7024191SGrygorii Strashko 	int ret = 0;
1170d7024191SGrygorii Strashko 
1171d7024191SGrygorii Strashko 	if (!rx_chn->remote)
1172d7024191SGrygorii Strashko 		return -EINVAL;
1173d7024191SGrygorii Strashko 
1174d7024191SGrygorii Strashko 	rx_ring_id = k3_ringacc_get_ring_id(flow->ringrx);
1175d7024191SGrygorii Strashko 	rx_ringfdq_id = k3_ringacc_get_ring_id(flow->ringrxfdq);
1176d7024191SGrygorii Strashko 
1177d7024191SGrygorii Strashko 	memset(&req, 0, sizeof(req));
1178d7024191SGrygorii Strashko 
1179d7024191SGrygorii Strashko 	req.valid_params =
1180d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID |
1181d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID |
1182d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID |
1183d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID |
1184d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID;
1185d7024191SGrygorii Strashko 	req.nav_id = tisci_rm->tisci_dev_id;
1186d7024191SGrygorii Strashko 	req.flow_index = flow->udma_rflow_id;
1187d7024191SGrygorii Strashko 	req.rx_dest_qnum = rx_ring_id;
1188d7024191SGrygorii Strashko 	req.rx_fdq0_sz0_qnum = rx_ringfdq_id;
1189d7024191SGrygorii Strashko 	req.rx_fdq1_qnum = rx_ringfdq_id;
1190d7024191SGrygorii Strashko 	req.rx_fdq2_qnum = rx_ringfdq_id;
1191d7024191SGrygorii Strashko 	req.rx_fdq3_qnum = rx_ringfdq_id;
1192d7024191SGrygorii Strashko 
1193d7024191SGrygorii Strashko 	ret = tisci_rm->tisci_udmap_ops->rx_flow_cfg(tisci_rm->tisci, &req);
1194d7024191SGrygorii Strashko 	if (ret) {
1195d7024191SGrygorii Strashko 		dev_err(dev, "flow%d enable failed: %d\n", flow->udma_rflow_id,
1196d7024191SGrygorii Strashko 			ret);
1197d7024191SGrygorii Strashko 	}
1198d7024191SGrygorii Strashko 
1199d7024191SGrygorii Strashko 	return ret;
1200d7024191SGrygorii Strashko }
1201d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_flow_enable);
1202d7024191SGrygorii Strashko 
k3_udma_glue_rx_flow_disable(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_idx)1203d7024191SGrygorii Strashko int k3_udma_glue_rx_flow_disable(struct k3_udma_glue_rx_channel *rx_chn,
1204d7024191SGrygorii Strashko 				 u32 flow_idx)
1205d7024191SGrygorii Strashko {
1206d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_idx];
1207d7024191SGrygorii Strashko 	const struct udma_tisci_rm *tisci_rm = rx_chn->common.tisci_rm;
1208d7024191SGrygorii Strashko 	struct device *dev = rx_chn->common.dev;
1209d7024191SGrygorii Strashko 	struct ti_sci_msg_rm_udmap_flow_cfg req;
1210d7024191SGrygorii Strashko 	int ret = 0;
1211d7024191SGrygorii Strashko 
1212d7024191SGrygorii Strashko 	if (!rx_chn->remote)
1213d7024191SGrygorii Strashko 		return -EINVAL;
1214d7024191SGrygorii Strashko 
1215d7024191SGrygorii Strashko 	memset(&req, 0, sizeof(req));
1216d7024191SGrygorii Strashko 	req.valid_params =
1217d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID |
1218d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID |
1219d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID |
1220d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID |
1221d7024191SGrygorii Strashko 			TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID;
1222d7024191SGrygorii Strashko 	req.nav_id = tisci_rm->tisci_dev_id;
1223d7024191SGrygorii Strashko 	req.flow_index = flow->udma_rflow_id;
1224d7024191SGrygorii Strashko 	req.rx_dest_qnum = TI_SCI_RESOURCE_NULL;
1225d7024191SGrygorii Strashko 	req.rx_fdq0_sz0_qnum = TI_SCI_RESOURCE_NULL;
1226d7024191SGrygorii Strashko 	req.rx_fdq1_qnum = TI_SCI_RESOURCE_NULL;
1227d7024191SGrygorii Strashko 	req.rx_fdq2_qnum = TI_SCI_RESOURCE_NULL;
1228d7024191SGrygorii Strashko 	req.rx_fdq3_qnum = TI_SCI_RESOURCE_NULL;
1229d7024191SGrygorii Strashko 
1230d7024191SGrygorii Strashko 	ret = tisci_rm->tisci_udmap_ops->rx_flow_cfg(tisci_rm->tisci, &req);
1231d7024191SGrygorii Strashko 	if (ret) {
1232d7024191SGrygorii Strashko 		dev_err(dev, "flow%d disable failed: %d\n", flow->udma_rflow_id,
1233d7024191SGrygorii Strashko 			ret);
1234d7024191SGrygorii Strashko 	}
1235d7024191SGrygorii Strashko 
1236d7024191SGrygorii Strashko 	return ret;
1237d7024191SGrygorii Strashko }
1238d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_flow_disable);
1239d7024191SGrygorii Strashko 
k3_udma_glue_enable_rx_chn(struct k3_udma_glue_rx_channel * rx_chn)1240d7024191SGrygorii Strashko int k3_udma_glue_enable_rx_chn(struct k3_udma_glue_rx_channel *rx_chn)
1241d7024191SGrygorii Strashko {
124269973b48SGrygorii Strashko 	int ret;
124369973b48SGrygorii Strashko 
1244d7024191SGrygorii Strashko 	if (rx_chn->remote)
1245d7024191SGrygorii Strashko 		return -EINVAL;
1246d7024191SGrygorii Strashko 
1247d7024191SGrygorii Strashko 	if (rx_chn->flows_ready < rx_chn->flow_num)
1248d7024191SGrygorii Strashko 		return -EINVAL;
1249d7024191SGrygorii Strashko 
125069973b48SGrygorii Strashko 	ret = xudma_navss_psil_pair(rx_chn->common.udmax,
125169973b48SGrygorii Strashko 				    rx_chn->common.src_thread,
125269973b48SGrygorii Strashko 				    rx_chn->common.dst_thread);
125369973b48SGrygorii Strashko 	if (ret) {
125469973b48SGrygorii Strashko 		dev_err(rx_chn->common.dev, "PSI-L request err %d\n", ret);
125569973b48SGrygorii Strashko 		return ret;
125669973b48SGrygorii Strashko 	}
125769973b48SGrygorii Strashko 
125869973b48SGrygorii Strashko 	rx_chn->psil_paired = true;
125969973b48SGrygorii Strashko 
1260bc7e5523SPeter Ujfalusi 	xudma_rchanrt_write(rx_chn->udma_rchanx, UDMA_CHAN_RT_CTL_REG,
126152c74d3dSGrygorii Strashko 			    UDMA_CHAN_RT_CTL_EN);
1262d7024191SGrygorii Strashko 
1263bc7e5523SPeter Ujfalusi 	xudma_rchanrt_write(rx_chn->udma_rchanx, UDMA_CHAN_RT_PEER_RT_EN_REG,
1264d7024191SGrygorii Strashko 			    UDMA_PEER_RT_EN_ENABLE);
1265d7024191SGrygorii Strashko 
1266d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_rt_chn(rx_chn, "rxrt en");
1267d7024191SGrygorii Strashko 	return 0;
1268d7024191SGrygorii Strashko }
1269d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_enable_rx_chn);
1270d7024191SGrygorii Strashko 
k3_udma_glue_disable_rx_chn(struct k3_udma_glue_rx_channel * rx_chn)1271d7024191SGrygorii Strashko void k3_udma_glue_disable_rx_chn(struct k3_udma_glue_rx_channel *rx_chn)
1272d7024191SGrygorii Strashko {
1273d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_rt_chn(rx_chn, "rxrt dis1");
1274d7024191SGrygorii Strashko 
1275d7024191SGrygorii Strashko 	xudma_rchanrt_write(rx_chn->udma_rchanx,
1276bc7e5523SPeter Ujfalusi 			    UDMA_CHAN_RT_PEER_RT_EN_REG, 0);
1277bc7e5523SPeter Ujfalusi 	xudma_rchanrt_write(rx_chn->udma_rchanx, UDMA_CHAN_RT_CTL_REG, 0);
1278d7024191SGrygorii Strashko 
1279d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_rt_chn(rx_chn, "rxrt dis2");
128069973b48SGrygorii Strashko 
128169973b48SGrygorii Strashko 	if (rx_chn->psil_paired) {
128269973b48SGrygorii Strashko 		xudma_navss_psil_unpair(rx_chn->common.udmax,
128369973b48SGrygorii Strashko 					rx_chn->common.src_thread,
128469973b48SGrygorii Strashko 					rx_chn->common.dst_thread);
128569973b48SGrygorii Strashko 		rx_chn->psil_paired = false;
128669973b48SGrygorii Strashko 	}
1287d7024191SGrygorii Strashko }
1288d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_disable_rx_chn);
1289d7024191SGrygorii Strashko 
k3_udma_glue_tdown_rx_chn(struct k3_udma_glue_rx_channel * rx_chn,bool sync)1290d7024191SGrygorii Strashko void k3_udma_glue_tdown_rx_chn(struct k3_udma_glue_rx_channel *rx_chn,
1291d7024191SGrygorii Strashko 			       bool sync)
1292d7024191SGrygorii Strashko {
1293d7024191SGrygorii Strashko 	int i = 0;
1294d7024191SGrygorii Strashko 	u32 val;
1295d7024191SGrygorii Strashko 
1296d7024191SGrygorii Strashko 	if (rx_chn->remote)
1297d7024191SGrygorii Strashko 		return;
1298d7024191SGrygorii Strashko 
1299d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_rt_chn(rx_chn, "rxrt tdown1");
1300d7024191SGrygorii Strashko 
1301bc7e5523SPeter Ujfalusi 	xudma_rchanrt_write(rx_chn->udma_rchanx, UDMA_CHAN_RT_PEER_RT_EN_REG,
1302d7024191SGrygorii Strashko 			    UDMA_PEER_RT_EN_ENABLE | UDMA_PEER_RT_EN_TEARDOWN);
1303d7024191SGrygorii Strashko 
1304bc7e5523SPeter Ujfalusi 	val = xudma_rchanrt_read(rx_chn->udma_rchanx, UDMA_CHAN_RT_CTL_REG);
1305d7024191SGrygorii Strashko 
1306d7024191SGrygorii Strashko 	while (sync && (val & UDMA_CHAN_RT_CTL_EN)) {
1307d7024191SGrygorii Strashko 		val = xudma_rchanrt_read(rx_chn->udma_rchanx,
1308bc7e5523SPeter Ujfalusi 					 UDMA_CHAN_RT_CTL_REG);
1309d7024191SGrygorii Strashko 		udelay(1);
1310d7024191SGrygorii Strashko 		if (i > K3_UDMAX_TDOWN_TIMEOUT_US) {
1311d7024191SGrygorii Strashko 			dev_err(rx_chn->common.dev, "RX tdown timeout\n");
1312d7024191SGrygorii Strashko 			break;
1313d7024191SGrygorii Strashko 		}
1314d7024191SGrygorii Strashko 		i++;
1315d7024191SGrygorii Strashko 	}
1316d7024191SGrygorii Strashko 
1317d7024191SGrygorii Strashko 	val = xudma_rchanrt_read(rx_chn->udma_rchanx,
1318bc7e5523SPeter Ujfalusi 				 UDMA_CHAN_RT_PEER_RT_EN_REG);
1319d7024191SGrygorii Strashko 	if (sync && (val & UDMA_PEER_RT_EN_ENABLE))
1320d7024191SGrygorii Strashko 		dev_err(rx_chn->common.dev, "TX tdown peer not stopped\n");
1321d7024191SGrygorii Strashko 	k3_udma_glue_dump_rx_rt_chn(rx_chn, "rxrt tdown2");
1322d7024191SGrygorii Strashko }
1323d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_tdown_rx_chn);
1324d7024191SGrygorii Strashko 
k3_udma_glue_reset_rx_chn(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_num,void * data,void (* cleanup)(void * data,dma_addr_t desc_dma),bool skip_fdq)1325d7024191SGrygorii Strashko void k3_udma_glue_reset_rx_chn(struct k3_udma_glue_rx_channel *rx_chn,
1326d7024191SGrygorii Strashko 		u32 flow_num, void *data,
1327d7024191SGrygorii Strashko 		void (*cleanup)(void *data, dma_addr_t desc_dma), bool skip_fdq)
1328d7024191SGrygorii Strashko {
1329d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_num];
1330d7024191SGrygorii Strashko 	struct device *dev = rx_chn->common.dev;
1331d7024191SGrygorii Strashko 	dma_addr_t desc_dma;
1332d7024191SGrygorii Strashko 	int occ_rx, i, ret;
1333d7024191SGrygorii Strashko 
1334d7024191SGrygorii Strashko 	/* reset RXCQ as it is not input for udma - expected to be empty */
1335d7024191SGrygorii Strashko 	occ_rx = k3_ringacc_ring_get_occ(flow->ringrx);
1336d7024191SGrygorii Strashko 	dev_dbg(dev, "RX reset flow %u occ_rx %u\n", flow_num, occ_rx);
1337d7024191SGrygorii Strashko 
1338d7024191SGrygorii Strashko 	/* Skip RX FDQ in case one FDQ is used for the set of flows */
1339d7024191SGrygorii Strashko 	if (skip_fdq)
13405b65781dSVignesh Raghavendra 		goto do_reset;
1341d7024191SGrygorii Strashko 
1342d7024191SGrygorii Strashko 	/*
1343d7024191SGrygorii Strashko 	 * RX FDQ reset need to be special way as it is input for udma and its
1344d7024191SGrygorii Strashko 	 * state cached by udma, so:
1345d7024191SGrygorii Strashko 	 * 1) save RX FDQ occ
1346d7024191SGrygorii Strashko 	 * 2) clean up RX FDQ and call callback .cleanup() for each desc
1347d7024191SGrygorii Strashko 	 * 3) reset RX FDQ in a special way
1348d7024191SGrygorii Strashko 	 */
1349d7024191SGrygorii Strashko 	occ_rx = k3_ringacc_ring_get_occ(flow->ringrxfdq);
1350d7024191SGrygorii Strashko 	dev_dbg(dev, "RX reset flow %u occ_rx_fdq %u\n", flow_num, occ_rx);
1351d7024191SGrygorii Strashko 
1352d7024191SGrygorii Strashko 	for (i = 0; i < occ_rx; i++) {
1353d7024191SGrygorii Strashko 		ret = k3_ringacc_ring_pop(flow->ringrxfdq, &desc_dma);
1354d7024191SGrygorii Strashko 		if (ret) {
13555b65781dSVignesh Raghavendra 			if (ret != -ENODATA)
1356d7024191SGrygorii Strashko 				dev_err(dev, "RX reset pop %d\n", ret);
1357d7024191SGrygorii Strashko 			break;
1358d7024191SGrygorii Strashko 		}
1359d7024191SGrygorii Strashko 		cleanup(data, desc_dma);
1360d7024191SGrygorii Strashko 	}
1361d7024191SGrygorii Strashko 
1362d7024191SGrygorii Strashko 	k3_ringacc_ring_reset_dma(flow->ringrxfdq, occ_rx);
13635b65781dSVignesh Raghavendra 
13645b65781dSVignesh Raghavendra do_reset:
13655b65781dSVignesh Raghavendra 	k3_ringacc_ring_reset(flow->ringrx);
1366d7024191SGrygorii Strashko }
1367d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_reset_rx_chn);
1368d7024191SGrygorii Strashko 
k3_udma_glue_push_rx_chn(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_num,struct cppi5_host_desc_t * desc_rx,dma_addr_t desc_dma)1369d7024191SGrygorii Strashko int k3_udma_glue_push_rx_chn(struct k3_udma_glue_rx_channel *rx_chn,
1370d7024191SGrygorii Strashko 			     u32 flow_num, struct cppi5_host_desc_t *desc_rx,
1371d7024191SGrygorii Strashko 			     dma_addr_t desc_dma)
1372d7024191SGrygorii Strashko {
1373d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_num];
1374d7024191SGrygorii Strashko 
1375d7024191SGrygorii Strashko 	return k3_ringacc_ring_push(flow->ringrxfdq, &desc_dma);
1376d7024191SGrygorii Strashko }
1377d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_push_rx_chn);
1378d7024191SGrygorii Strashko 
k3_udma_glue_pop_rx_chn(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_num,dma_addr_t * desc_dma)1379d7024191SGrygorii Strashko int k3_udma_glue_pop_rx_chn(struct k3_udma_glue_rx_channel *rx_chn,
1380d7024191SGrygorii Strashko 			    u32 flow_num, dma_addr_t *desc_dma)
1381d7024191SGrygorii Strashko {
1382d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow = &rx_chn->flows[flow_num];
1383d7024191SGrygorii Strashko 
1384d7024191SGrygorii Strashko 	return k3_ringacc_ring_pop(flow->ringrx, desc_dma);
1385d7024191SGrygorii Strashko }
1386d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_pop_rx_chn);
1387d7024191SGrygorii Strashko 
k3_udma_glue_rx_get_irq(struct k3_udma_glue_rx_channel * rx_chn,u32 flow_num)1388d7024191SGrygorii Strashko int k3_udma_glue_rx_get_irq(struct k3_udma_glue_rx_channel *rx_chn,
1389d7024191SGrygorii Strashko 			    u32 flow_num)
1390d7024191SGrygorii Strashko {
1391d7024191SGrygorii Strashko 	struct k3_udma_glue_rx_flow *flow;
1392d7024191SGrygorii Strashko 
1393d7024191SGrygorii Strashko 	flow = &rx_chn->flows[flow_num];
1394d7024191SGrygorii Strashko 
13955b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax)) {
13965b65781dSVignesh Raghavendra 		flow->virq = xudma_pktdma_rflow_get_irq(rx_chn->common.udmax,
13975b65781dSVignesh Raghavendra 							flow->udma_rflow_id);
13985b65781dSVignesh Raghavendra 	} else {
1399d7024191SGrygorii Strashko 		flow->virq = k3_ringacc_get_ring_irq_num(flow->ringrx);
14005b65781dSVignesh Raghavendra 	}
1401d7024191SGrygorii Strashko 
1402d7024191SGrygorii Strashko 	return flow->virq;
1403d7024191SGrygorii Strashko }
1404d7024191SGrygorii Strashko EXPORT_SYMBOL_GPL(k3_udma_glue_rx_get_irq);
1405426506a7SPeter Ujfalusi 
1406426506a7SPeter Ujfalusi struct device *
k3_udma_glue_rx_get_dma_device(struct k3_udma_glue_rx_channel * rx_chn)1407426506a7SPeter Ujfalusi 	k3_udma_glue_rx_get_dma_device(struct k3_udma_glue_rx_channel *rx_chn)
1408426506a7SPeter Ujfalusi {
14095b65781dSVignesh Raghavendra 	if (xudma_is_pktdma(rx_chn->common.udmax) &&
14105b65781dSVignesh Raghavendra 	    (rx_chn->common.atype_asel == 14 || rx_chn->common.atype_asel == 15))
14115b65781dSVignesh Raghavendra 		return &rx_chn->common.chan_dev;
14125b65781dSVignesh Raghavendra 
1413426506a7SPeter Ujfalusi 	return xudma_get_device(rx_chn->common.udmax);
1414426506a7SPeter Ujfalusi }
1415426506a7SPeter Ujfalusi EXPORT_SYMBOL_GPL(k3_udma_glue_rx_get_dma_device);
14165b65781dSVignesh Raghavendra 
k3_udma_glue_rx_dma_to_cppi5_addr(struct k3_udma_glue_rx_channel * rx_chn,dma_addr_t * addr)14175b65781dSVignesh Raghavendra void k3_udma_glue_rx_dma_to_cppi5_addr(struct k3_udma_glue_rx_channel *rx_chn,
14185b65781dSVignesh Raghavendra 				       dma_addr_t *addr)
14195b65781dSVignesh Raghavendra {
14205b65781dSVignesh Raghavendra 	if (!xudma_is_pktdma(rx_chn->common.udmax) ||
14215b65781dSVignesh Raghavendra 	    !rx_chn->common.atype_asel)
14225b65781dSVignesh Raghavendra 		return;
14235b65781dSVignesh Raghavendra 
14245b65781dSVignesh Raghavendra 	*addr |= (u64)rx_chn->common.atype_asel << K3_ADDRESS_ASEL_SHIFT;
14255b65781dSVignesh Raghavendra }
14265b65781dSVignesh Raghavendra EXPORT_SYMBOL_GPL(k3_udma_glue_rx_dma_to_cppi5_addr);
14275b65781dSVignesh Raghavendra 
k3_udma_glue_rx_cppi5_to_dma_addr(struct k3_udma_glue_rx_channel * rx_chn,dma_addr_t * addr)14285b65781dSVignesh Raghavendra void k3_udma_glue_rx_cppi5_to_dma_addr(struct k3_udma_glue_rx_channel *rx_chn,
14295b65781dSVignesh Raghavendra 				       dma_addr_t *addr)
14305b65781dSVignesh Raghavendra {
14315b65781dSVignesh Raghavendra 	if (!xudma_is_pktdma(rx_chn->common.udmax) ||
14325b65781dSVignesh Raghavendra 	    !rx_chn->common.atype_asel)
14335b65781dSVignesh Raghavendra 		return;
14345b65781dSVignesh Raghavendra 
14355b65781dSVignesh Raghavendra 	*addr &= (u64)GENMASK(K3_ADDRESS_ASEL_SHIFT - 1, 0);
14365b65781dSVignesh Raghavendra }
14375b65781dSVignesh Raghavendra EXPORT_SYMBOL_GPL(k3_udma_glue_rx_cppi5_to_dma_addr);
14385b65781dSVignesh Raghavendra 
k3_udma_glue_class_init(void)14395b65781dSVignesh Raghavendra static int __init k3_udma_glue_class_init(void)
14405b65781dSVignesh Raghavendra {
14415b65781dSVignesh Raghavendra 	return class_register(&k3_udma_glue_devclass);
14425b65781dSVignesh Raghavendra }
144356b0a668SKevin Hilman 
144456b0a668SKevin Hilman module_init(k3_udma_glue_class_init);
144556b0a668SKevin Hilman MODULE_LICENSE("GPL v2");
1446