blob: b7e674f2186aeffe9f3928adbf55c187701e6ce9 [file] [log] [blame]
Vignesh Rffcc66e2019-02-05 17:31:24 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Nishanth Menona94a4072023-11-01 15:56:03 -05003 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com
Vignesh Rffcc66e2019-02-05 17:31:24 +05304 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
5 */
6#define pr_fmt(fmt) "udma: " fmt
7
Simon Glass1eb69ae2019-11-14 12:57:39 -07008#include <cpu_func.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <asm/cache.h>
Vignesh Rffcc66e2019-02-05 17:31:24 +053011#include <asm/io.h>
12#include <asm/bitops.h>
13#include <malloc.h>
Matthias Schiffere5635932024-04-26 10:02:27 +020014#include <net.h>
Simon Glasscd93d622020-05-10 11:40:13 -060015#include <linux/bitops.h>
Masahiro Yamada9d86b892020-02-14 16:40:19 +090016#include <linux/dma-mapping.h>
Dhruva Gole742f3022022-09-20 10:56:02 +053017#include <linux/sizes.h>
Vignesh Rffcc66e2019-02-05 17:31:24 +053018#include <dm.h>
Simon Glass336d4612020-02-03 07:36:16 -070019#include <dm/device_compat.h>
Simon Glass61b29b82020-02-03 07:36:15 -070020#include <dm/devres.h>
Vignesh Rffcc66e2019-02-05 17:31:24 +053021#include <dm/read.h>
22#include <dm/of_access.h>
23#include <dma.h>
24#include <dma-uclass.h>
25#include <linux/delay.h>
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +053026#include <linux/bitmap.h>
Simon Glass61b29b82020-02-03 07:36:15 -070027#include <linux/err.h>
Simon Glass1e94b462023-09-14 18:21:46 -060028#include <linux/printk.h>
Vignesh Rffcc66e2019-02-05 17:31:24 +053029#include <linux/soc/ti/k3-navss-ringacc.h>
30#include <linux/soc/ti/cppi5.h>
31#include <linux/soc/ti/ti-udma.h>
32#include <linux/soc/ti/ti_sci_protocol.h>
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053033#include <linux/soc/ti/cppi5.h>
Vignesh Rffcc66e2019-02-05 17:31:24 +053034
35#include "k3-udma-hwdef.h"
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +053036#include "k3-psil-priv.h"
Vignesh Rffcc66e2019-02-05 17:31:24 +053037
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +053038#define K3_UDMA_MAX_RFLOWS 1024
39
Vignesh Rffcc66e2019-02-05 17:31:24 +053040struct udma_chan;
41
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053042enum k3_dma_type {
43 DMA_TYPE_UDMA = 0,
44 DMA_TYPE_BCDMA,
45 DMA_TYPE_PKTDMA,
46};
47
Vignesh Rffcc66e2019-02-05 17:31:24 +053048enum udma_mmr {
49 MMR_GCFG = 0,
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053050 MMR_BCHANRT,
Vignesh Rffcc66e2019-02-05 17:31:24 +053051 MMR_RCHANRT,
52 MMR_TCHANRT,
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +053053 MMR_RCHAN,
54 MMR_TCHAN,
55 MMR_RFLOW,
Vignesh Rffcc66e2019-02-05 17:31:24 +053056 MMR_LAST,
57};
58
59static const char * const mmr_names[] = {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053060 [MMR_GCFG] = "gcfg",
61 [MMR_BCHANRT] = "bchanrt",
62 [MMR_RCHANRT] = "rchanrt",
63 [MMR_TCHANRT] = "tchanrt",
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +053064 [MMR_RCHAN] = "rchan",
65 [MMR_TCHAN] = "tchan",
66 [MMR_RFLOW] = "rflow",
Vignesh Rffcc66e2019-02-05 17:31:24 +053067};
68
69struct udma_tchan {
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +053070 void __iomem *reg_chan;
Vignesh Rffcc66e2019-02-05 17:31:24 +053071 void __iomem *reg_rt;
72
73 int id;
74 struct k3_nav_ring *t_ring; /* Transmit ring */
75 struct k3_nav_ring *tc_ring; /* Transmit Completion ring */
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053076 int tflow_id; /* applicable only for PKTDMA */
77
78};
79
80#define udma_bchan udma_tchan
81
82struct udma_rflow {
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +053083 void __iomem *reg_rflow;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053084 int id;
85 struct k3_nav_ring *fd_ring; /* Free Descriptor ring */
86 struct k3_nav_ring *r_ring; /* Receive ring */
Vignesh Rffcc66e2019-02-05 17:31:24 +053087};
88
89struct udma_rchan {
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +053090 void __iomem *reg_chan;
Vignesh Rffcc66e2019-02-05 17:31:24 +053091 void __iomem *reg_rt;
92
93 int id;
Vignesh Rffcc66e2019-02-05 17:31:24 +053094};
95
Vignesh Raghavendra9a928512021-05-10 20:06:08 +053096struct udma_oes_offsets {
97 /* K3 UDMA Output Event Offset */
98 u32 udma_rchan;
99
100 /* BCDMA Output Event Offsets */
101 u32 bcdma_bchan_data;
102 u32 bcdma_bchan_ring;
103 u32 bcdma_tchan_data;
104 u32 bcdma_tchan_ring;
105 u32 bcdma_rchan_data;
106 u32 bcdma_rchan_ring;
107
108 /* PKTDMA Output Event Offsets */
109 u32 pktdma_tchan_flow;
110 u32 pktdma_rchan_flow;
111};
112
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +0530113#define UDMA_FLAG_PDMA_ACC32 BIT(0)
114#define UDMA_FLAG_PDMA_BURST BIT(1)
115#define UDMA_FLAG_TDTYPE BIT(2)
116
117struct udma_match_data {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530118 enum k3_dma_type type;
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +0530119 u32 psil_base;
120 bool enable_memcpy_support;
121 u32 flags;
122 u32 statictr_z_mask;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530123 struct udma_oes_offsets oes;
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +0530124
125 u8 tpl_levels;
126 u32 level_start_idx[];
127};
128
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530129enum udma_rm_range {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530130 RM_RANGE_BCHAN = 0,
131 RM_RANGE_TCHAN,
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530132 RM_RANGE_RCHAN,
133 RM_RANGE_RFLOW,
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530134 RM_RANGE_TFLOW,
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530135 RM_RANGE_LAST,
136};
137
138struct udma_tisci_rm {
139 const struct ti_sci_handle *tisci;
140 const struct ti_sci_rm_udmap_ops *tisci_udmap_ops;
141 u32 tisci_dev_id;
142
143 /* tisci information for PSI-L thread pairing/unpairing */
144 const struct ti_sci_rm_psil_ops *tisci_psil_ops;
145 u32 tisci_navss_dev_id;
146
147 struct ti_sci_resource *rm_ranges[RM_RANGE_LAST];
148};
149
Vignesh Rffcc66e2019-02-05 17:31:24 +0530150struct udma_dev {
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530151 struct udevice *dev;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530152 void __iomem *mmrs[MMR_LAST];
153
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530154 struct udma_tisci_rm tisci_rm;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530155 struct k3_nav_ringacc *ringacc;
156
157 u32 features;
158
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530159 int bchan_cnt;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530160 int tchan_cnt;
161 int echan_cnt;
162 int rchan_cnt;
163 int rflow_cnt;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530164 int tflow_cnt;
165 unsigned long *bchan_map;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530166 unsigned long *tchan_map;
167 unsigned long *rchan_map;
168 unsigned long *rflow_map;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530169 unsigned long *rflow_map_reserved;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530170 unsigned long *tflow_map;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530171
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530172 struct udma_bchan *bchans;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530173 struct udma_tchan *tchans;
174 struct udma_rchan *rchans;
175 struct udma_rflow *rflows;
176
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +0530177 struct udma_match_data *match_data;
178
Vignesh Rffcc66e2019-02-05 17:31:24 +0530179 struct udma_chan *channels;
180 u32 psil_base;
181
182 u32 ch_count;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530183};
184
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530185struct udma_chan_config {
186 u32 psd_size; /* size of Protocol Specific Data */
187 u32 metadata_size; /* (needs_epib ? 16:0) + psd_size */
188 u32 hdesc_size; /* Size of a packet descriptor in packet mode */
189 int remote_thread_id;
190 u32 atype;
191 u32 src_thread;
192 u32 dst_thread;
193 enum psil_endpoint_type ep_type;
194 enum udma_tp_level channel_tpl; /* Channel Throughput Level */
195
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530196 /* PKTDMA mapped channel */
197 int mapped_channel_id;
198 /* PKTDMA default tflow or rflow for mapped channel */
199 int default_flow_id;
200
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530201 enum dma_direction dir;
202
203 unsigned int pkt_mode:1; /* TR or packet */
204 unsigned int needs_epib:1; /* EPIB is needed for the communication or not */
205 unsigned int enable_acc32:1;
206 unsigned int enable_burst:1;
207 unsigned int notdpkt:1; /* Suppress sending TDC packet */
208};
209
Vignesh Rffcc66e2019-02-05 17:31:24 +0530210struct udma_chan {
211 struct udma_dev *ud;
212 char name[20];
213
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530214 struct udma_bchan *bchan;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530215 struct udma_tchan *tchan;
216 struct udma_rchan *rchan;
217 struct udma_rflow *rflow;
218
Vignesh Raghavendra5e6d9cc2019-12-04 22:17:21 +0530219 struct ti_udma_drv_chan_cfg_data cfg_data;
220
Vignesh Rffcc66e2019-02-05 17:31:24 +0530221 u32 bcnt; /* number of bytes completed since the start of the channel */
222
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530223 struct udma_chan_config config;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530224
225 u32 id;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530226
227 struct cppi5_host_desc_t *desc_tx;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530228 bool in_use;
229 void *desc_rx;
230 u32 num_rx_bufs;
231 u32 desc_rx_cur;
232
233};
234
235#define UDMA_CH_1000(ch) (ch * 0x1000)
236#define UDMA_CH_100(ch) (ch * 0x100)
237#define UDMA_CH_40(ch) (ch * 0x40)
238
239#ifdef PKTBUFSRX
240#define UDMA_RX_DESC_NUM PKTBUFSRX
241#else
242#define UDMA_RX_DESC_NUM 4
243#endif
244
245/* Generic register access functions */
246static inline u32 udma_read(void __iomem *base, int reg)
247{
248 u32 v;
249
250 v = __raw_readl(base + reg);
251 pr_debug("READL(32): v(%08X)<--reg(%p)\n", v, base + reg);
252 return v;
253}
254
255static inline void udma_write(void __iomem *base, int reg, u32 val)
256{
257 pr_debug("WRITEL(32): v(%08X)-->reg(%p)\n", val, base + reg);
258 __raw_writel(val, base + reg);
259}
260
261static inline void udma_update_bits(void __iomem *base, int reg,
262 u32 mask, u32 val)
263{
264 u32 tmp, orig;
265
266 orig = udma_read(base, reg);
267 tmp = orig & ~mask;
268 tmp |= (val & mask);
269
270 if (tmp != orig)
271 udma_write(base, reg, tmp);
272}
273
274/* TCHANRT */
275static inline u32 udma_tchanrt_read(struct udma_tchan *tchan, int reg)
276{
277 if (!tchan)
278 return 0;
279 return udma_read(tchan->reg_rt, reg);
280}
281
282static inline void udma_tchanrt_write(struct udma_tchan *tchan,
283 int reg, u32 val)
284{
285 if (!tchan)
286 return;
287 udma_write(tchan->reg_rt, reg, val);
288}
289
290/* RCHANRT */
291static inline u32 udma_rchanrt_read(struct udma_rchan *rchan, int reg)
292{
293 if (!rchan)
294 return 0;
295 return udma_read(rchan->reg_rt, reg);
296}
297
298static inline void udma_rchanrt_write(struct udma_rchan *rchan,
299 int reg, u32 val)
300{
301 if (!rchan)
302 return;
303 udma_write(rchan->reg_rt, reg, val);
304}
305
306static inline int udma_navss_psil_pair(struct udma_dev *ud, u32 src_thread,
307 u32 dst_thread)
308{
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530309 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
310
Vignesh Rffcc66e2019-02-05 17:31:24 +0530311 dst_thread |= UDMA_PSIL_DST_THREAD_ID_OFFSET;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530312
313 return tisci_rm->tisci_psil_ops->pair(tisci_rm->tisci,
314 tisci_rm->tisci_navss_dev_id,
315 src_thread, dst_thread);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530316}
317
318static inline int udma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread,
319 u32 dst_thread)
320{
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530321 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
322
Vignesh Rffcc66e2019-02-05 17:31:24 +0530323 dst_thread |= UDMA_PSIL_DST_THREAD_ID_OFFSET;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530324
325 return tisci_rm->tisci_psil_ops->unpair(tisci_rm->tisci,
326 tisci_rm->tisci_navss_dev_id,
327 src_thread, dst_thread);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530328}
329
330static inline char *udma_get_dir_text(enum dma_direction dir)
331{
332 switch (dir) {
333 case DMA_DEV_TO_MEM:
334 return "DEV_TO_MEM";
335 case DMA_MEM_TO_DEV:
336 return "MEM_TO_DEV";
337 case DMA_MEM_TO_MEM:
338 return "MEM_TO_MEM";
339 case DMA_DEV_TO_DEV:
340 return "DEV_TO_DEV";
341 default:
342 break;
343 }
344
345 return "invalid";
346}
347
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +0530348#include "k3-udma-u-boot.c"
349
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530350static void udma_reset_uchan(struct udma_chan *uc)
351{
352 memset(&uc->config, 0, sizeof(uc->config));
353 uc->config.remote_thread_id = -1;
354 uc->config.mapped_channel_id = -1;
355 uc->config.default_flow_id = -1;
356}
357
Vignesh Rffcc66e2019-02-05 17:31:24 +0530358static inline bool udma_is_chan_running(struct udma_chan *uc)
359{
360 u32 trt_ctl = 0;
361 u32 rrt_ctl = 0;
362
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530363 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530364 case DMA_DEV_TO_MEM:
365 rrt_ctl = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_CTL_REG);
366 pr_debug("%s: rrt_ctl: 0x%08x (peer: 0x%08x)\n",
367 __func__, rrt_ctl,
368 udma_rchanrt_read(uc->rchan,
369 UDMA_RCHAN_RT_PEER_RT_EN_REG));
370 break;
371 case DMA_MEM_TO_DEV:
372 trt_ctl = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_CTL_REG);
373 pr_debug("%s: trt_ctl: 0x%08x (peer: 0x%08x)\n",
374 __func__, trt_ctl,
375 udma_tchanrt_read(uc->tchan,
376 UDMA_TCHAN_RT_PEER_RT_EN_REG));
377 break;
378 case DMA_MEM_TO_MEM:
379 trt_ctl = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_CTL_REG);
380 rrt_ctl = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_CTL_REG);
381 break;
382 default:
383 break;
384 }
385
386 if (trt_ctl & UDMA_CHAN_RT_CTL_EN || rrt_ctl & UDMA_CHAN_RT_CTL_EN)
387 return true;
388
389 return false;
390}
391
Vignesh Rffcc66e2019-02-05 17:31:24 +0530392static int udma_pop_from_ring(struct udma_chan *uc, dma_addr_t *addr)
393{
394 struct k3_nav_ring *ring = NULL;
395 int ret = -ENOENT;
396
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530397 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530398 case DMA_DEV_TO_MEM:
Vignesh Raghavendra7be51212020-07-06 13:26:26 +0530399 ring = uc->rflow->r_ring;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530400 break;
401 case DMA_MEM_TO_DEV:
402 ring = uc->tchan->tc_ring;
403 break;
404 case DMA_MEM_TO_MEM:
405 ring = uc->tchan->tc_ring;
406 break;
407 default:
408 break;
409 }
410
411 if (ring && k3_nav_ringacc_ring_get_occ(ring))
412 ret = k3_nav_ringacc_ring_pop(ring, addr);
413
414 return ret;
415}
416
417static void udma_reset_rings(struct udma_chan *uc)
418{
419 struct k3_nav_ring *ring1 = NULL;
420 struct k3_nav_ring *ring2 = NULL;
421
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530422 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530423 case DMA_DEV_TO_MEM:
Vignesh Raghavendra7be51212020-07-06 13:26:26 +0530424 ring1 = uc->rflow->fd_ring;
425 ring2 = uc->rflow->r_ring;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530426 break;
427 case DMA_MEM_TO_DEV:
428 ring1 = uc->tchan->t_ring;
429 ring2 = uc->tchan->tc_ring;
430 break;
431 case DMA_MEM_TO_MEM:
432 ring1 = uc->tchan->t_ring;
433 ring2 = uc->tchan->tc_ring;
434 break;
435 default:
436 break;
437 }
438
439 if (ring1)
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530440 k3_nav_ringacc_ring_reset_dma(ring1, k3_nav_ringacc_ring_get_occ(ring1));
Vignesh Rffcc66e2019-02-05 17:31:24 +0530441 if (ring2)
442 k3_nav_ringacc_ring_reset(ring2);
443}
444
445static void udma_reset_counters(struct udma_chan *uc)
446{
447 u32 val;
448
449 if (uc->tchan) {
450 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_BCNT_REG);
451 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_BCNT_REG, val);
452
453 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_SBCNT_REG);
454 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_SBCNT_REG, val);
455
456 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_PCNT_REG);
457 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_PCNT_REG, val);
458
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530459 if (!uc->bchan) {
460 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_PEER_BCNT_REG);
461 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_PEER_BCNT_REG, val);
462 }
Vignesh Rffcc66e2019-02-05 17:31:24 +0530463 }
464
465 if (uc->rchan) {
466 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_BCNT_REG);
467 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_BCNT_REG, val);
468
469 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_SBCNT_REG);
470 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_SBCNT_REG, val);
471
472 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_PCNT_REG);
473 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_PCNT_REG, val);
474
475 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_PEER_BCNT_REG);
476 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_PEER_BCNT_REG, val);
477 }
478
479 uc->bcnt = 0;
480}
481
482static inline int udma_stop_hard(struct udma_chan *uc)
483{
484 pr_debug("%s: ENTER (chan%d)\n", __func__, uc->id);
485
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530486 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530487 case DMA_DEV_TO_MEM:
488 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_PEER_RT_EN_REG, 0);
489 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_CTL_REG, 0);
490 break;
491 case DMA_MEM_TO_DEV:
492 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG, 0);
493 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_PEER_RT_EN_REG, 0);
494 break;
495 case DMA_MEM_TO_MEM:
496 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_CTL_REG, 0);
497 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG, 0);
498 break;
499 default:
500 return -EINVAL;
501 }
502
503 return 0;
504}
505
506static int udma_start(struct udma_chan *uc)
507{
508 /* Channel is already running, no need to proceed further */
509 if (udma_is_chan_running(uc))
510 goto out;
511
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530512 pr_debug("%s: chan:%d dir:%s\n",
513 __func__, uc->id, udma_get_dir_text(uc->config.dir));
Vignesh Rffcc66e2019-02-05 17:31:24 +0530514
515 /* Make sure that we clear the teardown bit, if it is set */
516 udma_stop_hard(uc);
517
518 /* Reset all counters */
519 udma_reset_counters(uc);
520
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530521 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530522 case DMA_DEV_TO_MEM:
523 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_CTL_REG,
524 UDMA_CHAN_RT_CTL_EN);
525
526 /* Enable remote */
527 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_PEER_RT_EN_REG,
528 UDMA_PEER_RT_EN_ENABLE);
529
530 pr_debug("%s(rx): RT_CTL:0x%08x PEER RT_ENABLE:0x%08x\n",
531 __func__,
532 udma_rchanrt_read(uc->rchan,
533 UDMA_RCHAN_RT_CTL_REG),
534 udma_rchanrt_read(uc->rchan,
535 UDMA_RCHAN_RT_PEER_RT_EN_REG));
536 break;
537 case DMA_MEM_TO_DEV:
538 /* Enable remote */
539 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_PEER_RT_EN_REG,
540 UDMA_PEER_RT_EN_ENABLE);
541
542 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG,
543 UDMA_CHAN_RT_CTL_EN);
544
545 pr_debug("%s(tx): RT_CTL:0x%08x PEER RT_ENABLE:0x%08x\n",
546 __func__,
Vignesh Raghavendrac16cdd42019-12-09 10:25:36 +0530547 udma_tchanrt_read(uc->tchan,
Vignesh Rffcc66e2019-02-05 17:31:24 +0530548 UDMA_TCHAN_RT_CTL_REG),
Vignesh Raghavendrac16cdd42019-12-09 10:25:36 +0530549 udma_tchanrt_read(uc->tchan,
Vignesh Rffcc66e2019-02-05 17:31:24 +0530550 UDMA_TCHAN_RT_PEER_RT_EN_REG));
551 break;
552 case DMA_MEM_TO_MEM:
553 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_CTL_REG,
554 UDMA_CHAN_RT_CTL_EN);
555 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG,
556 UDMA_CHAN_RT_CTL_EN);
557
558 break;
559 default:
560 return -EINVAL;
561 }
562
563 pr_debug("%s: DONE chan:%d\n", __func__, uc->id);
564out:
565 return 0;
566}
567
568static inline void udma_stop_mem2dev(struct udma_chan *uc, bool sync)
569{
570 int i = 0;
571 u32 val;
572
573 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG,
574 UDMA_CHAN_RT_CTL_EN |
575 UDMA_CHAN_RT_CTL_TDOWN);
576
577 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_CTL_REG);
578
579 while (sync && (val & UDMA_CHAN_RT_CTL_EN)) {
580 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_CTL_REG);
581 udelay(1);
582 if (i > 1000) {
583 printf(" %s TIMEOUT !\n", __func__);
584 break;
585 }
586 i++;
587 }
588
589 val = udma_tchanrt_read(uc->tchan, UDMA_TCHAN_RT_PEER_RT_EN_REG);
590 if (val & UDMA_PEER_RT_EN_ENABLE)
591 printf("%s: peer not stopped TIMEOUT !\n", __func__);
592}
593
594static inline void udma_stop_dev2mem(struct udma_chan *uc, bool sync)
595{
596 int i = 0;
597 u32 val;
598
599 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_PEER_RT_EN_REG,
600 UDMA_PEER_RT_EN_ENABLE |
601 UDMA_PEER_RT_EN_TEARDOWN);
602
603 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_CTL_REG);
604
605 while (sync && (val & UDMA_CHAN_RT_CTL_EN)) {
606 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_CTL_REG);
607 udelay(1);
608 if (i > 1000) {
609 printf("%s TIMEOUT !\n", __func__);
610 break;
611 }
612 i++;
613 }
614
615 val = udma_rchanrt_read(uc->rchan, UDMA_RCHAN_RT_PEER_RT_EN_REG);
616 if (val & UDMA_PEER_RT_EN_ENABLE)
617 printf("%s: peer not stopped TIMEOUT !\n", __func__);
618}
619
620static inline int udma_stop(struct udma_chan *uc)
621{
622 pr_debug("%s: chan:%d dir:%s\n",
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530623 __func__, uc->id, udma_get_dir_text(uc->config.dir));
Vignesh Rffcc66e2019-02-05 17:31:24 +0530624
625 udma_reset_counters(uc);
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530626 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530627 case DMA_DEV_TO_MEM:
628 udma_stop_dev2mem(uc, true);
629 break;
630 case DMA_MEM_TO_DEV:
631 udma_stop_mem2dev(uc, true);
632 break;
633 case DMA_MEM_TO_MEM:
634 udma_rchanrt_write(uc->rchan, UDMA_RCHAN_RT_CTL_REG, 0);
635 udma_tchanrt_write(uc->tchan, UDMA_TCHAN_RT_CTL_REG, 0);
636 break;
637 default:
638 return -EINVAL;
639 }
640
641 return 0;
642}
643
644static void udma_poll_completion(struct udma_chan *uc, dma_addr_t *paddr)
645{
646 int i = 1;
647
648 while (udma_pop_from_ring(uc, paddr)) {
649 udelay(1);
650 if (!(i % 1000000))
651 printf(".");
652 i++;
653 }
654}
655
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +0530656static struct udma_rflow *__udma_reserve_rflow(struct udma_dev *ud, int id)
657{
658 DECLARE_BITMAP(tmp, K3_UDMA_MAX_RFLOWS);
659
660 if (id >= 0) {
661 if (test_bit(id, ud->rflow_map)) {
662 dev_err(ud->dev, "rflow%d is in use\n", id);
663 return ERR_PTR(-ENOENT);
664 }
665 } else {
666 bitmap_or(tmp, ud->rflow_map, ud->rflow_map_reserved,
667 ud->rflow_cnt);
668
669 id = find_next_zero_bit(tmp, ud->rflow_cnt, ud->rchan_cnt);
670 if (id >= ud->rflow_cnt)
671 return ERR_PTR(-ENOENT);
672 }
673
674 __set_bit(id, ud->rflow_map);
675 return &ud->rflows[id];
676}
677
Vignesh Rffcc66e2019-02-05 17:31:24 +0530678#define UDMA_RESERVE_RESOURCE(res) \
679static struct udma_##res *__udma_reserve_##res(struct udma_dev *ud, \
680 int id) \
681{ \
682 if (id >= 0) { \
683 if (test_bit(id, ud->res##_map)) { \
684 dev_err(ud->dev, "res##%d is in use\n", id); \
685 return ERR_PTR(-ENOENT); \
686 } \
687 } else { \
688 id = find_first_zero_bit(ud->res##_map, ud->res##_cnt); \
689 if (id == ud->res##_cnt) { \
690 return ERR_PTR(-ENOENT); \
691 } \
692 } \
693 \
694 __set_bit(id, ud->res##_map); \
695 return &ud->res##s[id]; \
696}
697
698UDMA_RESERVE_RESOURCE(tchan);
699UDMA_RESERVE_RESOURCE(rchan);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530700
701static int udma_get_tchan(struct udma_chan *uc)
702{
703 struct udma_dev *ud = uc->ud;
704
705 if (uc->tchan) {
706 dev_dbg(ud->dev, "chan%d: already have tchan%d allocated\n",
707 uc->id, uc->tchan->id);
708 return 0;
709 }
710
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530711 uc->tchan = __udma_reserve_tchan(ud, uc->config.mapped_channel_id);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530712 if (IS_ERR(uc->tchan))
713 return PTR_ERR(uc->tchan);
714
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530715 if (ud->tflow_cnt) {
716 int tflow_id;
717
718 /* Only PKTDMA have support for tx flows */
719 if (uc->config.default_flow_id >= 0)
720 tflow_id = uc->config.default_flow_id;
721 else
722 tflow_id = uc->tchan->id;
723
724 if (test_bit(tflow_id, ud->tflow_map)) {
725 dev_err(ud->dev, "tflow%d is in use\n", tflow_id);
726 __clear_bit(uc->tchan->id, ud->tchan_map);
727 uc->tchan = NULL;
728 return -ENOENT;
729 }
730
731 uc->tchan->tflow_id = tflow_id;
732 __set_bit(tflow_id, ud->tflow_map);
733 } else {
734 uc->tchan->tflow_id = -1;
735 }
736
Vignesh Rffcc66e2019-02-05 17:31:24 +0530737 pr_debug("chan%d: got tchan%d\n", uc->id, uc->tchan->id);
738
Vignesh Rffcc66e2019-02-05 17:31:24 +0530739 return 0;
740}
741
742static int udma_get_rchan(struct udma_chan *uc)
743{
744 struct udma_dev *ud = uc->ud;
745
746 if (uc->rchan) {
747 dev_dbg(ud->dev, "chan%d: already have rchan%d allocated\n",
748 uc->id, uc->rchan->id);
749 return 0;
750 }
751
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530752 uc->rchan = __udma_reserve_rchan(ud, uc->config.mapped_channel_id);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530753 if (IS_ERR(uc->rchan))
754 return PTR_ERR(uc->rchan);
755
756 pr_debug("chan%d: got rchan%d\n", uc->id, uc->rchan->id);
757
Vignesh Rffcc66e2019-02-05 17:31:24 +0530758 return 0;
759}
760
761static int udma_get_chan_pair(struct udma_chan *uc)
762{
763 struct udma_dev *ud = uc->ud;
764 int chan_id, end;
765
766 if ((uc->tchan && uc->rchan) && uc->tchan->id == uc->rchan->id) {
767 dev_info(ud->dev, "chan%d: already have %d pair allocated\n",
768 uc->id, uc->tchan->id);
769 return 0;
770 }
771
772 if (uc->tchan) {
773 dev_err(ud->dev, "chan%d: already have tchan%d allocated\n",
774 uc->id, uc->tchan->id);
775 return -EBUSY;
776 } else if (uc->rchan) {
777 dev_err(ud->dev, "chan%d: already have rchan%d allocated\n",
778 uc->id, uc->rchan->id);
779 return -EBUSY;
780 }
781
782 /* Can be optimized, but let's have it like this for now */
783 end = min(ud->tchan_cnt, ud->rchan_cnt);
784 for (chan_id = 0; chan_id < end; chan_id++) {
785 if (!test_bit(chan_id, ud->tchan_map) &&
786 !test_bit(chan_id, ud->rchan_map))
787 break;
788 }
789
790 if (chan_id == end)
791 return -ENOENT;
792
793 __set_bit(chan_id, ud->tchan_map);
794 __set_bit(chan_id, ud->rchan_map);
795 uc->tchan = &ud->tchans[chan_id];
796 uc->rchan = &ud->rchans[chan_id];
797
798 pr_debug("chan%d: got t/rchan%d pair\n", uc->id, chan_id);
799
Vignesh Rffcc66e2019-02-05 17:31:24 +0530800 return 0;
801}
802
803static int udma_get_rflow(struct udma_chan *uc, int flow_id)
804{
805 struct udma_dev *ud = uc->ud;
806
807 if (uc->rflow) {
808 dev_dbg(ud->dev, "chan%d: already have rflow%d allocated\n",
809 uc->id, uc->rflow->id);
810 return 0;
811 }
812
813 if (!uc->rchan)
814 dev_warn(ud->dev, "chan%d: does not have rchan??\n", uc->id);
815
816 uc->rflow = __udma_reserve_rflow(ud, flow_id);
817 if (IS_ERR(uc->rflow))
818 return PTR_ERR(uc->rflow);
819
820 pr_debug("chan%d: got rflow%d\n", uc->id, uc->rflow->id);
821 return 0;
822}
823
824static void udma_put_rchan(struct udma_chan *uc)
825{
826 struct udma_dev *ud = uc->ud;
827
828 if (uc->rchan) {
829 dev_dbg(ud->dev, "chan%d: put rchan%d\n", uc->id,
830 uc->rchan->id);
831 __clear_bit(uc->rchan->id, ud->rchan_map);
832 uc->rchan = NULL;
833 }
834}
835
836static void udma_put_tchan(struct udma_chan *uc)
837{
838 struct udma_dev *ud = uc->ud;
839
840 if (uc->tchan) {
841 dev_dbg(ud->dev, "chan%d: put tchan%d\n", uc->id,
842 uc->tchan->id);
843 __clear_bit(uc->tchan->id, ud->tchan_map);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530844 if (uc->tchan->tflow_id >= 0)
845 __clear_bit(uc->tchan->tflow_id, ud->tflow_map);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530846 uc->tchan = NULL;
847 }
848}
849
850static void udma_put_rflow(struct udma_chan *uc)
851{
852 struct udma_dev *ud = uc->ud;
853
854 if (uc->rflow) {
855 dev_dbg(ud->dev, "chan%d: put rflow%d\n", uc->id,
856 uc->rflow->id);
857 __clear_bit(uc->rflow->id, ud->rflow_map);
858 uc->rflow = NULL;
859 }
860}
861
862static void udma_free_tx_resources(struct udma_chan *uc)
863{
864 if (!uc->tchan)
865 return;
866
867 k3_nav_ringacc_ring_free(uc->tchan->t_ring);
868 k3_nav_ringacc_ring_free(uc->tchan->tc_ring);
869 uc->tchan->t_ring = NULL;
870 uc->tchan->tc_ring = NULL;
871
872 udma_put_tchan(uc);
873}
874
875static int udma_alloc_tx_resources(struct udma_chan *uc)
876{
877 struct k3_nav_ring_cfg ring_cfg;
878 struct udma_dev *ud = uc->ud;
MD Danish Anwar4312a1d2024-01-30 11:48:04 +0530879 struct udma_tchan *tchan;
880 int ring_idx, ret;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530881
882 ret = udma_get_tchan(uc);
883 if (ret)
884 return ret;
885
MD Danish Anwar4312a1d2024-01-30 11:48:04 +0530886 tchan = uc->tchan;
Udit Kumar70226402024-02-21 19:53:44 +0530887 if (tchan->tflow_id > 0)
MD Danish Anwar4312a1d2024-01-30 11:48:04 +0530888 ring_idx = tchan->tflow_id;
889 else
Udit Kumar70226402024-02-21 19:53:44 +0530890 ring_idx = tchan->id;
MD Danish Anwar4312a1d2024-01-30 11:48:04 +0530891
892 ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, ring_idx, -1,
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530893 &uc->tchan->t_ring,
894 &uc->tchan->tc_ring);
895 if (ret) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530896 ret = -EBUSY;
897 goto err_tx_ring;
898 }
899
Vignesh Rffcc66e2019-02-05 17:31:24 +0530900 memset(&ring_cfg, 0, sizeof(ring_cfg));
901 ring_cfg.size = 16;
902 ring_cfg.elm_size = K3_NAV_RINGACC_RING_ELSIZE_8;
Vignesh Raghavendrace1a3072019-12-09 10:25:37 +0530903 ring_cfg.mode = K3_NAV_RINGACC_RING_MODE_RING;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530904
905 ret = k3_nav_ringacc_ring_cfg(uc->tchan->t_ring, &ring_cfg);
906 ret |= k3_nav_ringacc_ring_cfg(uc->tchan->tc_ring, &ring_cfg);
907
908 if (ret)
909 goto err_ringcfg;
910
911 return 0;
912
913err_ringcfg:
914 k3_nav_ringacc_ring_free(uc->tchan->tc_ring);
915 uc->tchan->tc_ring = NULL;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530916 k3_nav_ringacc_ring_free(uc->tchan->t_ring);
917 uc->tchan->t_ring = NULL;
918err_tx_ring:
919 udma_put_tchan(uc);
920
921 return ret;
922}
923
924static void udma_free_rx_resources(struct udma_chan *uc)
925{
926 if (!uc->rchan)
927 return;
928
Vignesh Raghavendra7be51212020-07-06 13:26:26 +0530929 if (uc->rflow) {
930 k3_nav_ringacc_ring_free(uc->rflow->fd_ring);
931 k3_nav_ringacc_ring_free(uc->rflow->r_ring);
932 uc->rflow->fd_ring = NULL;
933 uc->rflow->r_ring = NULL;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530934
Vignesh Raghavendra7be51212020-07-06 13:26:26 +0530935 udma_put_rflow(uc);
936 }
937
Vignesh Rffcc66e2019-02-05 17:31:24 +0530938 udma_put_rchan(uc);
939}
940
941static int udma_alloc_rx_resources(struct udma_chan *uc)
942{
943 struct k3_nav_ring_cfg ring_cfg;
944 struct udma_dev *ud = uc->ud;
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530945 struct udma_rflow *rflow;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530946 int fd_ring_id;
947 int ret;
948
949 ret = udma_get_rchan(uc);
950 if (ret)
951 return ret;
952
953 /* For MEM_TO_MEM we don't need rflow or rings */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +0530954 if (uc->config.dir == DMA_MEM_TO_MEM)
Vignesh Rffcc66e2019-02-05 17:31:24 +0530955 return 0;
956
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530957 if (uc->config.default_flow_id >= 0)
958 ret = udma_get_rflow(uc, uc->config.default_flow_id);
959 else
960 ret = udma_get_rflow(uc, uc->rchan->id);
961
Vignesh Rffcc66e2019-02-05 17:31:24 +0530962 if (ret) {
963 ret = -EBUSY;
964 goto err_rflow;
965 }
966
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530967 rflow = uc->rflow;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +0530968 if (ud->tflow_cnt) {
969 fd_ring_id = ud->tflow_cnt + rflow->id;
970 } else {
971 fd_ring_id = ud->bchan_cnt + ud->tchan_cnt + ud->echan_cnt +
972 uc->rchan->id;
973 }
974
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530975 ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, fd_ring_id, -1,
976 &rflow->fd_ring, &rflow->r_ring);
977 if (ret) {
Vignesh Rffcc66e2019-02-05 17:31:24 +0530978 ret = -EBUSY;
979 goto err_rx_ring;
980 }
981
Vignesh Rffcc66e2019-02-05 17:31:24 +0530982 memset(&ring_cfg, 0, sizeof(ring_cfg));
983 ring_cfg.size = 16;
984 ring_cfg.elm_size = K3_NAV_RINGACC_RING_ELSIZE_8;
Vignesh Raghavendrace1a3072019-12-09 10:25:37 +0530985 ring_cfg.mode = K3_NAV_RINGACC_RING_MODE_RING;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530986
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530987 ret = k3_nav_ringacc_ring_cfg(rflow->fd_ring, &ring_cfg);
988 ret |= k3_nav_ringacc_ring_cfg(rflow->r_ring, &ring_cfg);
Vignesh Rffcc66e2019-02-05 17:31:24 +0530989 if (ret)
990 goto err_ringcfg;
991
992 return 0;
993
994err_ringcfg:
Vignesh Raghavendraddcf5312020-07-06 13:26:27 +0530995 k3_nav_ringacc_ring_free(rflow->r_ring);
996 rflow->r_ring = NULL;
997 k3_nav_ringacc_ring_free(rflow->fd_ring);
998 rflow->fd_ring = NULL;
Vignesh Rffcc66e2019-02-05 17:31:24 +0530999err_rx_ring:
1000 udma_put_rflow(uc);
1001err_rflow:
1002 udma_put_rchan(uc);
1003
1004 return ret;
1005}
1006
1007static int udma_alloc_tchan_sci_req(struct udma_chan *uc)
1008{
1009 struct udma_dev *ud = uc->ud;
1010 int tc_ring = k3_nav_ringacc_get_ring_id(uc->tchan->tc_ring);
1011 struct ti_sci_msg_rm_udmap_tx_ch_cfg req;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301012 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301013 u32 mode;
1014 int ret;
1015
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301016 if (uc->config.pkt_mode)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301017 mode = TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR;
1018 else
1019 mode = TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBRR;
1020
1021 req.valid_params = TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID |
1022 TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
1023 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301024 req.nav_id = tisci_rm->tisci_dev_id;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301025 req.index = uc->tchan->id;
1026 req.tx_chan_type = mode;
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301027 if (uc->config.dir == DMA_MEM_TO_MEM)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301028 req.tx_fetch_size = sizeof(struct cppi5_desc_hdr_t) >> 2;
1029 else
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301030 req.tx_fetch_size = cppi5_hdesc_calc_size(uc->config.needs_epib,
1031 uc->config.psd_size,
Vignesh Rffcc66e2019-02-05 17:31:24 +05301032 0) >> 2;
1033 req.txcq_qnum = tc_ring;
1034
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301035 ret = tisci_rm->tisci_udmap_ops->tx_ch_cfg(tisci_rm->tisci, &req);
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301036 if (ret) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301037 dev_err(ud->dev, "tisci tx alloc failed %d\n", ret);
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301038 return ret;
1039 }
Vignesh Rffcc66e2019-02-05 17:31:24 +05301040
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301041 /*
1042 * Above TI SCI call handles firewall configuration, cfg
1043 * register configuration still has to be done locally in
1044 * absence of RM services.
1045 */
1046 if (IS_ENABLED(CONFIG_K3_DM_FW))
1047 udma_alloc_tchan_raw(uc);
1048
1049 return 0;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301050}
1051
1052static int udma_alloc_rchan_sci_req(struct udma_chan *uc)
1053{
1054 struct udma_dev *ud = uc->ud;
Vignesh Raghavendra7be51212020-07-06 13:26:26 +05301055 int fd_ring = k3_nav_ringacc_get_ring_id(uc->rflow->fd_ring);
1056 int rx_ring = k3_nav_ringacc_get_ring_id(uc->rflow->r_ring);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301057 int tc_ring = k3_nav_ringacc_get_ring_id(uc->tchan->tc_ring);
1058 struct ti_sci_msg_rm_udmap_rx_ch_cfg req = { 0 };
1059 struct ti_sci_msg_rm_udmap_flow_cfg flow_req = { 0 };
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301060 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301061 u32 mode;
1062 int ret;
1063
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301064 if (uc->config.pkt_mode)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301065 mode = TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR;
1066 else
1067 mode = TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBRR;
1068
1069 req.valid_params = TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID |
1070 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID |
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301071 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301072 req.nav_id = tisci_rm->tisci_dev_id;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301073 req.index = uc->rchan->id;
1074 req.rx_chan_type = mode;
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301075 if (uc->config.dir == DMA_MEM_TO_MEM) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301076 req.rx_fetch_size = sizeof(struct cppi5_desc_hdr_t) >> 2;
1077 req.rxcq_qnum = tc_ring;
1078 } else {
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301079 req.rx_fetch_size = cppi5_hdesc_calc_size(uc->config.needs_epib,
1080 uc->config.psd_size,
Vignesh Rffcc66e2019-02-05 17:31:24 +05301081 0) >> 2;
1082 req.rxcq_qnum = rx_ring;
1083 }
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301084 if (ud->match_data->type == DMA_TYPE_UDMA &&
1085 uc->rflow->id != uc->rchan->id &&
1086 uc->config.dir != DMA_MEM_TO_MEM) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301087 req.flowid_start = uc->rflow->id;
1088 req.flowid_cnt = 1;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301089 req.valid_params |= TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_START_VALID |
1090 TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_CNT_VALID;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301091 }
1092
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301093 ret = tisci_rm->tisci_udmap_ops->rx_ch_cfg(tisci_rm->tisci, &req);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301094 if (ret) {
1095 dev_err(ud->dev, "tisci rx %u cfg failed %d\n",
1096 uc->rchan->id, ret);
1097 return ret;
1098 }
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301099 if (uc->config.dir == DMA_MEM_TO_MEM)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301100 return ret;
1101
1102 flow_req.valid_params =
1103 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_EINFO_PRESENT_VALID |
1104 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PSINFO_PRESENT_VALID |
1105 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_ERROR_HANDLING_VALID |
1106 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DESC_TYPE_VALID |
1107 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID |
1108 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_HI_SEL_VALID |
1109 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_LO_SEL_VALID |
1110 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_HI_SEL_VALID |
1111 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_LO_SEL_VALID |
1112 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID |
1113 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID |
1114 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID |
1115 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID |
1116 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PS_LOCATION_VALID;
1117
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301118 flow_req.nav_id = tisci_rm->tisci_dev_id;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301119 flow_req.flow_index = uc->rflow->id;
1120
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301121 if (uc->config.needs_epib)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301122 flow_req.rx_einfo_present = 1;
1123 else
1124 flow_req.rx_einfo_present = 0;
1125
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301126 if (uc->config.psd_size)
Vignesh Rffcc66e2019-02-05 17:31:24 +05301127 flow_req.rx_psinfo_present = 1;
1128 else
1129 flow_req.rx_psinfo_present = 0;
1130
1131 flow_req.rx_error_handling = 0;
1132 flow_req.rx_desc_type = 0;
1133 flow_req.rx_dest_qnum = rx_ring;
1134 flow_req.rx_src_tag_hi_sel = 2;
1135 flow_req.rx_src_tag_lo_sel = 4;
1136 flow_req.rx_dest_tag_hi_sel = 5;
1137 flow_req.rx_dest_tag_lo_sel = 4;
1138 flow_req.rx_fdq0_sz0_qnum = fd_ring;
1139 flow_req.rx_fdq1_qnum = fd_ring;
1140 flow_req.rx_fdq2_qnum = fd_ring;
1141 flow_req.rx_fdq3_qnum = fd_ring;
1142 flow_req.rx_ps_location = 0;
1143
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301144 ret = tisci_rm->tisci_udmap_ops->rx_flow_cfg(tisci_rm->tisci,
1145 &flow_req);
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301146 if (ret) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301147 dev_err(ud->dev, "tisci rx %u flow %u cfg failed %d\n",
1148 uc->rchan->id, uc->rflow->id, ret);
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301149 return ret;
1150 }
Vignesh Rffcc66e2019-02-05 17:31:24 +05301151
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301152 /*
1153 * Above TI SCI call handles firewall configuration, cfg
1154 * register configuration still has to be done locally in
1155 * absence of RM services.
1156 */
1157 if (IS_ENABLED(CONFIG_K3_DM_FW))
1158 udma_alloc_rchan_raw(uc);
1159
1160 return 0;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301161}
1162
1163static int udma_alloc_chan_resources(struct udma_chan *uc)
1164{
1165 struct udma_dev *ud = uc->ud;
1166 int ret;
1167
1168 pr_debug("%s: chan:%d as %s\n",
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301169 __func__, uc->id, udma_get_dir_text(uc->config.dir));
Vignesh Rffcc66e2019-02-05 17:31:24 +05301170
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301171 switch (uc->config.dir) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301172 case DMA_MEM_TO_MEM:
1173 /* Non synchronized - mem to mem type of transfer */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301174 uc->config.pkt_mode = false;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301175 ret = udma_get_chan_pair(uc);
1176 if (ret)
1177 return ret;
1178
1179 ret = udma_alloc_tx_resources(uc);
1180 if (ret)
1181 goto err_free_res;
1182
1183 ret = udma_alloc_rx_resources(uc);
1184 if (ret)
1185 goto err_free_res;
1186
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301187 uc->config.src_thread = ud->psil_base + uc->tchan->id;
1188 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | 0x8000;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301189 break;
1190 case DMA_MEM_TO_DEV:
1191 /* Slave transfer synchronized - mem to dev (TX) trasnfer */
1192 ret = udma_alloc_tx_resources(uc);
1193 if (ret)
1194 goto err_free_res;
1195
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301196 uc->config.src_thread = ud->psil_base + uc->tchan->id;
1197 uc->config.dst_thread = uc->config.remote_thread_id;
1198 uc->config.dst_thread |= 0x8000;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301199
1200 break;
1201 case DMA_DEV_TO_MEM:
1202 /* Slave transfer synchronized - dev to mem (RX) trasnfer */
1203 ret = udma_alloc_rx_resources(uc);
1204 if (ret)
1205 goto err_free_res;
1206
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301207 uc->config.src_thread = uc->config.remote_thread_id;
1208 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | 0x8000;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301209
1210 break;
1211 default:
1212 /* Can not happen */
1213 pr_debug("%s: chan:%d invalid direction (%u)\n",
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301214 __func__, uc->id, uc->config.dir);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301215 return -EINVAL;
1216 }
1217
1218 /* We have channel indexes and rings */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301219 if (uc->config.dir == DMA_MEM_TO_MEM) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301220 ret = udma_alloc_tchan_sci_req(uc);
1221 if (ret)
1222 goto err_free_res;
1223
1224 ret = udma_alloc_rchan_sci_req(uc);
1225 if (ret)
1226 goto err_free_res;
1227 } else {
1228 /* Slave transfer */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301229 if (uc->config.dir == DMA_MEM_TO_DEV) {
Vignesh Rffcc66e2019-02-05 17:31:24 +05301230 ret = udma_alloc_tchan_sci_req(uc);
1231 if (ret)
1232 goto err_free_res;
1233 } else {
1234 ret = udma_alloc_rchan_sci_req(uc);
1235 if (ret)
1236 goto err_free_res;
1237 }
1238 }
1239
Peter Ujfalusi54877722019-04-25 12:08:15 +05301240 if (udma_is_chan_running(uc)) {
1241 dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
1242 udma_stop(uc);
1243 if (udma_is_chan_running(uc)) {
1244 dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
1245 goto err_free_res;
1246 }
1247 }
1248
Vignesh Rffcc66e2019-02-05 17:31:24 +05301249 /* PSI-L pairing */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301250 ret = udma_navss_psil_pair(ud, uc->config.src_thread, uc->config.dst_thread);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301251 if (ret) {
1252 dev_err(ud->dev, "k3_nav_psil_request_link fail\n");
1253 goto err_free_res;
1254 }
1255
1256 return 0;
1257
1258err_free_res:
1259 udma_free_tx_resources(uc);
1260 udma_free_rx_resources(uc);
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301261 uc->config.remote_thread_id = -1;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301262 return ret;
1263}
1264
1265static void udma_free_chan_resources(struct udma_chan *uc)
1266{
Vignesh Raghavendra85bdcf02020-09-17 20:11:22 +05301267 /* Hard reset UDMA channel */
1268 udma_stop_hard(uc);
1269 udma_reset_counters(uc);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301270
1271 /* Release PSI-L pairing */
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301272 udma_navss_psil_unpair(uc->ud, uc->config.src_thread, uc->config.dst_thread);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301273
1274 /* Reset the rings for a new start */
1275 udma_reset_rings(uc);
1276 udma_free_tx_resources(uc);
1277 udma_free_rx_resources(uc);
1278
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301279 uc->config.remote_thread_id = -1;
1280 uc->config.dir = DMA_MEM_TO_MEM;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301281}
1282
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301283static const char * const range_names[] = {
1284 [RM_RANGE_BCHAN] = "ti,sci-rm-range-bchan",
1285 [RM_RANGE_TCHAN] = "ti,sci-rm-range-tchan",
1286 [RM_RANGE_RCHAN] = "ti,sci-rm-range-rchan",
1287 [RM_RANGE_RFLOW] = "ti,sci-rm-range-rflow",
1288 [RM_RANGE_TFLOW] = "ti,sci-rm-range-tflow",
1289};
1290
Vignesh Rffcc66e2019-02-05 17:31:24 +05301291static int udma_get_mmrs(struct udevice *dev)
1292{
1293 struct udma_dev *ud = dev_get_priv(dev);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301294 u32 cap2, cap3, cap4;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301295 int i;
1296
Matthias Schiffer5fecea12023-09-27 15:33:34 +02001297 ud->mmrs[MMR_GCFG] = dev_read_addr_name_ptr(dev, mmr_names[MMR_GCFG]);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301298 if (!ud->mmrs[MMR_GCFG])
1299 return -EINVAL;
1300
1301 cap2 = udma_read(ud->mmrs[MMR_GCFG], 0x28);
1302 cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c);
1303
1304 switch (ud->match_data->type) {
1305 case DMA_TYPE_UDMA:
1306 ud->rflow_cnt = cap3 & 0x3fff;
1307 ud->tchan_cnt = cap2 & 0x1ff;
1308 ud->echan_cnt = (cap2 >> 9) & 0x1ff;
1309 ud->rchan_cnt = (cap2 >> 18) & 0x1ff;
1310 break;
1311 case DMA_TYPE_BCDMA:
1312 ud->bchan_cnt = cap2 & 0x1ff;
1313 ud->tchan_cnt = (cap2 >> 9) & 0x1ff;
1314 ud->rchan_cnt = (cap2 >> 18) & 0x1ff;
1315 break;
1316 case DMA_TYPE_PKTDMA:
1317 cap4 = udma_read(ud->mmrs[MMR_GCFG], 0x30);
1318 ud->tchan_cnt = cap2 & 0x1ff;
1319 ud->rchan_cnt = (cap2 >> 18) & 0x1ff;
1320 ud->rflow_cnt = cap3 & 0x3fff;
1321 ud->tflow_cnt = cap4 & 0x3fff;
1322 break;
1323 default:
1324 return -EINVAL;
1325 }
1326
1327 for (i = 1; i < MMR_LAST; i++) {
1328 if (i == MMR_BCHANRT && ud->bchan_cnt == 0)
1329 continue;
1330 if (i == MMR_TCHANRT && ud->tchan_cnt == 0)
1331 continue;
1332 if (i == MMR_RCHANRT && ud->rchan_cnt == 0)
1333 continue;
1334
Matthias Schiffer5fecea12023-09-27 15:33:34 +02001335 ud->mmrs[i] = dev_read_addr_name_ptr(dev, mmr_names[i]);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301336 if (!ud->mmrs[i])
1337 return -EINVAL;
1338 }
1339
1340 return 0;
1341}
1342
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301343static int udma_setup_resources(struct udma_dev *ud)
1344{
1345 struct udevice *dev = ud->dev;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301346 int i;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301347 struct ti_sci_resource_desc *rm_desc;
1348 struct ti_sci_resource *rm_res;
1349 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301350
1351 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt),
1352 sizeof(unsigned long), GFP_KERNEL);
1353 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans),
1354 GFP_KERNEL);
1355 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt),
1356 sizeof(unsigned long), GFP_KERNEL);
1357 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans),
1358 GFP_KERNEL);
1359 ud->rflow_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rflow_cnt),
1360 sizeof(unsigned long), GFP_KERNEL);
1361 ud->rflow_map_reserved = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt),
1362 sizeof(unsigned long),
1363 GFP_KERNEL);
1364 ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows),
1365 GFP_KERNEL);
1366
1367 if (!ud->tchan_map || !ud->rchan_map || !ud->rflow_map ||
1368 !ud->rflow_map_reserved || !ud->tchans || !ud->rchans ||
1369 !ud->rflows)
1370 return -ENOMEM;
1371
1372 /*
1373 * RX flows with the same Ids as RX channels are reserved to be used
1374 * as default flows if remote HW can't generate flow_ids. Those
1375 * RX flows can be requested only explicitly by id.
1376 */
1377 bitmap_set(ud->rflow_map_reserved, 0, ud->rchan_cnt);
1378
1379 /* Get resource ranges from tisci */
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301380 for (i = 0; i < RM_RANGE_LAST; i++) {
1381 if (i == RM_RANGE_BCHAN || i == RM_RANGE_TFLOW)
1382 continue;
1383
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301384 tisci_rm->rm_ranges[i] =
1385 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev,
1386 tisci_rm->tisci_dev_id,
1387 (char *)range_names[i]);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301388 }
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301389
1390 /* tchan ranges */
1391 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN];
1392 if (IS_ERR(rm_res)) {
1393 bitmap_zero(ud->tchan_map, ud->tchan_cnt);
1394 } else {
1395 bitmap_fill(ud->tchan_map, ud->tchan_cnt);
1396 for (i = 0; i < rm_res->sets; i++) {
1397 rm_desc = &rm_res->desc[i];
1398 bitmap_clear(ud->tchan_map, rm_desc->start,
1399 rm_desc->num);
1400 }
1401 }
1402
1403 /* rchan and matching default flow ranges */
1404 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN];
1405 if (IS_ERR(rm_res)) {
1406 bitmap_zero(ud->rchan_map, ud->rchan_cnt);
1407 bitmap_zero(ud->rflow_map, ud->rchan_cnt);
1408 } else {
1409 bitmap_fill(ud->rchan_map, ud->rchan_cnt);
1410 bitmap_fill(ud->rflow_map, ud->rchan_cnt);
1411 for (i = 0; i < rm_res->sets; i++) {
1412 rm_desc = &rm_res->desc[i];
1413 bitmap_clear(ud->rchan_map, rm_desc->start,
1414 rm_desc->num);
1415 bitmap_clear(ud->rflow_map, rm_desc->start,
1416 rm_desc->num);
1417 }
1418 }
1419
1420 /* GP rflow ranges */
1421 rm_res = tisci_rm->rm_ranges[RM_RANGE_RFLOW];
1422 if (IS_ERR(rm_res)) {
1423 bitmap_clear(ud->rflow_map, ud->rchan_cnt,
1424 ud->rflow_cnt - ud->rchan_cnt);
1425 } else {
1426 bitmap_set(ud->rflow_map, ud->rchan_cnt,
1427 ud->rflow_cnt - ud->rchan_cnt);
1428 for (i = 0; i < rm_res->sets; i++) {
1429 rm_desc = &rm_res->desc[i];
1430 bitmap_clear(ud->rflow_map, rm_desc->start,
1431 rm_desc->num);
1432 }
1433 }
1434
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301435 return 0;
1436}
1437
1438static int bcdma_setup_resources(struct udma_dev *ud)
1439{
1440 int i;
1441 struct udevice *dev = ud->dev;
1442 struct ti_sci_resource_desc *rm_desc;
1443 struct ti_sci_resource *rm_res;
1444 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
1445
1446 ud->bchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt),
1447 sizeof(unsigned long), GFP_KERNEL);
1448 ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans),
1449 GFP_KERNEL);
1450 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt),
1451 sizeof(unsigned long), GFP_KERNEL);
1452 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans),
1453 GFP_KERNEL);
1454 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt),
1455 sizeof(unsigned long), GFP_KERNEL);
1456 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans),
1457 GFP_KERNEL);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301458 ud->rflows = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows),
1459 GFP_KERNEL);
1460
1461 if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map ||
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301462 !ud->bchans || !ud->tchans || !ud->rchans ||
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301463 !ud->rflows)
1464 return -ENOMEM;
1465
1466 /* Get resource ranges from tisci */
1467 for (i = 0; i < RM_RANGE_LAST; i++) {
1468 if (i == RM_RANGE_RFLOW || i == RM_RANGE_TFLOW)
1469 continue;
1470
1471 tisci_rm->rm_ranges[i] =
1472 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev,
1473 tisci_rm->tisci_dev_id,
1474 (char *)range_names[i]);
1475 }
1476
1477 /* bchan ranges */
1478 rm_res = tisci_rm->rm_ranges[RM_RANGE_BCHAN];
1479 if (IS_ERR(rm_res)) {
1480 bitmap_zero(ud->bchan_map, ud->bchan_cnt);
1481 } else {
1482 bitmap_fill(ud->bchan_map, ud->bchan_cnt);
1483 for (i = 0; i < rm_res->sets; i++) {
1484 rm_desc = &rm_res->desc[i];
1485 bitmap_clear(ud->bchan_map, rm_desc->start,
1486 rm_desc->num);
1487 dev_dbg(dev, "ti-sci-res: bchan: %d:%d\n",
1488 rm_desc->start, rm_desc->num);
1489 }
1490 }
1491
1492 /* tchan ranges */
1493 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN];
1494 if (IS_ERR(rm_res)) {
1495 bitmap_zero(ud->tchan_map, ud->tchan_cnt);
1496 } else {
1497 bitmap_fill(ud->tchan_map, ud->tchan_cnt);
1498 for (i = 0; i < rm_res->sets; i++) {
1499 rm_desc = &rm_res->desc[i];
1500 bitmap_clear(ud->tchan_map, rm_desc->start,
1501 rm_desc->num);
1502 dev_dbg(dev, "ti-sci-res: tchan: %d:%d\n",
1503 rm_desc->start, rm_desc->num);
1504 }
1505 }
1506
1507 /* rchan ranges */
1508 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN];
1509 if (IS_ERR(rm_res)) {
1510 bitmap_zero(ud->rchan_map, ud->rchan_cnt);
1511 } else {
1512 bitmap_fill(ud->rchan_map, ud->rchan_cnt);
1513 for (i = 0; i < rm_res->sets; i++) {
1514 rm_desc = &rm_res->desc[i];
1515 bitmap_clear(ud->rchan_map, rm_desc->start,
1516 rm_desc->num);
1517 dev_dbg(dev, "ti-sci-res: rchan: %d:%d\n",
1518 rm_desc->start, rm_desc->num);
1519 }
1520 }
1521
1522 return 0;
1523}
1524
1525static int pktdma_setup_resources(struct udma_dev *ud)
1526{
1527 int i;
1528 struct udevice *dev = ud->dev;
1529 struct ti_sci_resource *rm_res;
1530 struct ti_sci_resource_desc *rm_desc;
1531 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
1532
1533 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt),
1534 sizeof(unsigned long), GFP_KERNEL);
1535 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans),
1536 GFP_KERNEL);
1537 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt),
1538 sizeof(unsigned long), GFP_KERNEL);
1539 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans),
1540 GFP_KERNEL);
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301541 ud->rflow_map = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt),
1542 sizeof(unsigned long),
1543 GFP_KERNEL);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301544 ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows),
1545 GFP_KERNEL);
1546 ud->tflow_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tflow_cnt),
1547 sizeof(unsigned long), GFP_KERNEL);
1548
1549 if (!ud->tchan_map || !ud->rchan_map || !ud->tflow_map || !ud->tchans ||
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301550 !ud->rchans || !ud->rflows || !ud->rflow_map)
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301551 return -ENOMEM;
1552
1553 /* Get resource ranges from tisci */
1554 for (i = 0; i < RM_RANGE_LAST; i++) {
1555 if (i == RM_RANGE_BCHAN)
1556 continue;
1557
1558 tisci_rm->rm_ranges[i] =
1559 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev,
1560 tisci_rm->tisci_dev_id,
1561 (char *)range_names[i]);
1562 }
1563
1564 /* tchan ranges */
1565 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN];
1566 if (IS_ERR(rm_res)) {
1567 bitmap_zero(ud->tchan_map, ud->tchan_cnt);
1568 } else {
1569 bitmap_fill(ud->tchan_map, ud->tchan_cnt);
1570 for (i = 0; i < rm_res->sets; i++) {
1571 rm_desc = &rm_res->desc[i];
1572 bitmap_clear(ud->tchan_map, rm_desc->start,
1573 rm_desc->num);
1574 dev_dbg(dev, "ti-sci-res: tchan: %d:%d\n",
1575 rm_desc->start, rm_desc->num);
1576 }
1577 }
1578
1579 /* rchan ranges */
1580 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN];
1581 if (IS_ERR(rm_res)) {
1582 bitmap_zero(ud->rchan_map, ud->rchan_cnt);
1583 } else {
1584 bitmap_fill(ud->rchan_map, ud->rchan_cnt);
1585 for (i = 0; i < rm_res->sets; i++) {
1586 rm_desc = &rm_res->desc[i];
1587 bitmap_clear(ud->rchan_map, rm_desc->start,
1588 rm_desc->num);
1589 dev_dbg(dev, "ti-sci-res: rchan: %d:%d\n",
1590 rm_desc->start, rm_desc->num);
1591 }
1592 }
1593
1594 /* rflow ranges */
1595 rm_res = tisci_rm->rm_ranges[RM_RANGE_RFLOW];
1596 if (IS_ERR(rm_res)) {
1597 /* all rflows are assigned exclusively to Linux */
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301598 bitmap_zero(ud->rflow_map, ud->rflow_cnt);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301599 } else {
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301600 bitmap_fill(ud->rflow_map, ud->rflow_cnt);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301601 for (i = 0; i < rm_res->sets; i++) {
1602 rm_desc = &rm_res->desc[i];
Vignesh Raghavendra4af5e5f2021-12-23 19:27:30 +05301603 bitmap_clear(ud->rflow_map, rm_desc->start,
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301604 rm_desc->num);
1605 dev_dbg(dev, "ti-sci-res: rflow: %d:%d\n",
1606 rm_desc->start, rm_desc->num);
1607 }
1608 }
1609
1610 /* tflow ranges */
1611 rm_res = tisci_rm->rm_ranges[RM_RANGE_TFLOW];
1612 if (IS_ERR(rm_res)) {
1613 /* all tflows are assigned exclusively to Linux */
1614 bitmap_zero(ud->tflow_map, ud->tflow_cnt);
1615 } else {
1616 bitmap_fill(ud->tflow_map, ud->tflow_cnt);
1617 for (i = 0; i < rm_res->sets; i++) {
1618 rm_desc = &rm_res->desc[i];
1619 bitmap_clear(ud->tflow_map, rm_desc->start,
1620 rm_desc->num);
1621 dev_dbg(dev, "ti-sci-res: tflow: %d:%d\n",
1622 rm_desc->start, rm_desc->num);
1623 }
1624 }
1625
1626 return 0;
1627}
1628
1629static int setup_resources(struct udma_dev *ud)
1630{
1631 struct udevice *dev = ud->dev;
1632 int ch_count, ret;
1633
1634 switch (ud->match_data->type) {
1635 case DMA_TYPE_UDMA:
1636 ret = udma_setup_resources(ud);
1637 break;
1638 case DMA_TYPE_BCDMA:
1639 ret = bcdma_setup_resources(ud);
1640 break;
1641 case DMA_TYPE_PKTDMA:
1642 ret = pktdma_setup_resources(ud);
1643 break;
1644 default:
1645 return -EINVAL;
1646 }
1647
1648 if (ret)
1649 return ret;
1650
1651 ch_count = ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt;
1652 if (ud->bchan_cnt)
1653 ch_count -= bitmap_weight(ud->bchan_map, ud->bchan_cnt);
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301654 ch_count -= bitmap_weight(ud->tchan_map, ud->tchan_cnt);
1655 ch_count -= bitmap_weight(ud->rchan_map, ud->rchan_cnt);
1656 if (!ch_count)
1657 return -ENODEV;
1658
1659 ud->channels = devm_kcalloc(dev, ch_count, sizeof(*ud->channels),
1660 GFP_KERNEL);
1661 if (!ud->channels)
1662 return -ENOMEM;
1663
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301664 switch (ud->match_data->type) {
1665 case DMA_TYPE_UDMA:
1666 dev_dbg(dev,
1667 "Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n",
1668 ch_count,
1669 ud->tchan_cnt - bitmap_weight(ud->tchan_map,
1670 ud->tchan_cnt),
1671 ud->rchan_cnt - bitmap_weight(ud->rchan_map,
1672 ud->rchan_cnt),
1673 ud->rflow_cnt - bitmap_weight(ud->rflow_map,
1674 ud->rflow_cnt));
1675 break;
1676 case DMA_TYPE_BCDMA:
1677 dev_dbg(dev,
1678 "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n",
1679 ch_count,
1680 ud->bchan_cnt - bitmap_weight(ud->bchan_map,
1681 ud->bchan_cnt),
1682 ud->tchan_cnt - bitmap_weight(ud->tchan_map,
1683 ud->tchan_cnt),
1684 ud->rchan_cnt - bitmap_weight(ud->rchan_map,
1685 ud->rchan_cnt));
1686 break;
1687 case DMA_TYPE_PKTDMA:
1688 dev_dbg(dev,
1689 "Channels: %d (tchan: %u, rchan: %u)\n",
1690 ch_count,
1691 ud->tchan_cnt - bitmap_weight(ud->tchan_map,
1692 ud->tchan_cnt),
1693 ud->rchan_cnt - bitmap_weight(ud->rchan_map,
1694 ud->rchan_cnt));
1695 break;
1696 default:
1697 break;
1698 }
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301699
1700 return ch_count;
1701}
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301702
Vignesh Rffcc66e2019-02-05 17:31:24 +05301703static int udma_probe(struct udevice *dev)
1704{
1705 struct dma_dev_priv *uc_priv = dev_get_uclass_priv(dev);
1706 struct udma_dev *ud = dev_get_priv(dev);
1707 int i, ret;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301708 struct udevice *tmp;
1709 struct udevice *tisci_dev = NULL;
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301710 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
1711 ofnode navss_ofnode = ofnode_get_parent(dev_ofnode(dev));
1712
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301713 ud->match_data = (void *)dev_get_driver_data(dev);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301714 ret = udma_get_mmrs(dev);
1715 if (ret)
1716 return ret;
1717
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05301718 ud->psil_base = ud->match_data->psil_base;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301719
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301720 ret = uclass_get_device_by_phandle(UCLASS_FIRMWARE, dev,
1721 "ti,sci", &tisci_dev);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301722 if (ret) {
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301723 debug("Failed to get TISCI phandle (%d)\n", ret);
1724 tisci_rm->tisci = NULL;
1725 return -EINVAL;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301726 }
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301727 tisci_rm->tisci = (struct ti_sci_handle *)
1728 (ti_sci_get_handle_from_sysfw(tisci_dev));
Vignesh Rffcc66e2019-02-05 17:31:24 +05301729
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301730 tisci_rm->tisci_dev_id = -1;
1731 ret = dev_read_u32(dev, "ti,sci-dev-id", &tisci_rm->tisci_dev_id);
1732 if (ret) {
1733 dev_err(dev, "ti,sci-dev-id read failure %d\n", ret);
1734 return ret;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301735 }
1736
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301737 tisci_rm->tisci_navss_dev_id = -1;
1738 ret = ofnode_read_u32(navss_ofnode, "ti,sci-dev-id",
1739 &tisci_rm->tisci_navss_dev_id);
1740 if (ret) {
1741 dev_err(dev, "navss sci-dev-id read failure %d\n", ret);
1742 return ret;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301743 }
1744
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301745 tisci_rm->tisci_udmap_ops = &tisci_rm->tisci->ops.rm_udmap_ops;
1746 tisci_rm->tisci_psil_ops = &tisci_rm->tisci->ops.rm_psil_ops;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301747
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301748 if (ud->match_data->type == DMA_TYPE_UDMA) {
1749 ret = uclass_get_device_by_phandle(UCLASS_MISC, dev,
1750 "ti,ringacc", &tmp);
1751 ud->ringacc = dev_get_priv(tmp);
1752 } else {
1753 struct k3_ringacc_init_data ring_init_data;
1754
1755 ring_init_data.tisci = ud->tisci_rm.tisci;
1756 ring_init_data.tisci_dev_id = ud->tisci_rm.tisci_dev_id;
1757 if (ud->match_data->type == DMA_TYPE_BCDMA) {
1758 ring_init_data.num_rings = ud->bchan_cnt +
1759 ud->tchan_cnt +
1760 ud->rchan_cnt;
1761 } else {
1762 ring_init_data.num_rings = ud->rflow_cnt +
1763 ud->tflow_cnt;
1764 }
1765
1766 ud->ringacc = k3_ringacc_dmarings_init(dev, &ring_init_data);
1767 }
1768 if (IS_ERR(ud->ringacc))
1769 return PTR_ERR(ud->ringacc);
1770
Vignesh Raghavendraa8837cf2019-12-09 10:25:32 +05301771 ud->dev = dev;
Siddharth Vadapalli33303102024-02-20 15:34:51 +05301772 ret = setup_resources(ud);
1773 if (ret < 0)
1774 return ret;
1775
1776 ud->ch_count = ret;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301777
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301778 for (i = 0; i < ud->bchan_cnt; i++) {
1779 struct udma_bchan *bchan = &ud->bchans[i];
1780
1781 bchan->id = i;
1782 bchan->reg_rt = ud->mmrs[MMR_BCHANRT] + i * 0x1000;
1783 }
Vignesh Rffcc66e2019-02-05 17:31:24 +05301784
Vignesh Rffcc66e2019-02-05 17:31:24 +05301785 for (i = 0; i < ud->tchan_cnt; i++) {
1786 struct udma_tchan *tchan = &ud->tchans[i];
1787
1788 tchan->id = i;
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301789 tchan->reg_chan = ud->mmrs[MMR_TCHAN] + UDMA_CH_100(i);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301790 tchan->reg_rt = ud->mmrs[MMR_TCHANRT] + UDMA_CH_1000(i);
1791 }
1792
1793 for (i = 0; i < ud->rchan_cnt; i++) {
1794 struct udma_rchan *rchan = &ud->rchans[i];
1795
1796 rchan->id = i;
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301797 rchan->reg_chan = ud->mmrs[MMR_RCHAN] + UDMA_CH_100(i);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301798 rchan->reg_rt = ud->mmrs[MMR_RCHANRT] + UDMA_CH_1000(i);
1799 }
1800
1801 for (i = 0; i < ud->rflow_cnt; i++) {
1802 struct udma_rflow *rflow = &ud->rflows[i];
1803
1804 rflow->id = i;
Vignesh Raghavendra5abb6942021-06-07 19:47:53 +05301805 rflow->reg_rflow = ud->mmrs[MMR_RFLOW] + UDMA_CH_40(i);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301806 }
1807
1808 for (i = 0; i < ud->ch_count; i++) {
1809 struct udma_chan *uc = &ud->channels[i];
1810
1811 uc->ud = ud;
1812 uc->id = i;
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301813 uc->config.remote_thread_id = -1;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301814 uc->bchan = NULL;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301815 uc->tchan = NULL;
1816 uc->rchan = NULL;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301817 uc->config.mapped_channel_id = -1;
1818 uc->config.default_flow_id = -1;
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05301819 uc->config.dir = DMA_MEM_TO_MEM;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301820 sprintf(uc->name, "UDMA chan%d\n", i);
1821 if (!i)
1822 uc->in_use = true;
1823 }
1824
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301825 pr_debug("%s(rev: 0x%08x) CAP0-3: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
1826 dev->name,
Vignesh Rffcc66e2019-02-05 17:31:24 +05301827 udma_read(ud->mmrs[MMR_GCFG], 0),
1828 udma_read(ud->mmrs[MMR_GCFG], 0x20),
1829 udma_read(ud->mmrs[MMR_GCFG], 0x24),
1830 udma_read(ud->mmrs[MMR_GCFG], 0x28),
1831 udma_read(ud->mmrs[MMR_GCFG], 0x2c));
1832
1833 uc_priv->supported = DMA_SUPPORTS_MEM_TO_MEM | DMA_SUPPORTS_MEM_TO_DEV;
1834
Siddharth Vadapalli33303102024-02-20 15:34:51 +05301835 return 0;
Vignesh Rffcc66e2019-02-05 17:31:24 +05301836}
1837
Vignesh Raghavendrab0ab0082019-12-09 10:25:38 +05301838static int udma_push_to_ring(struct k3_nav_ring *ring, void *elem)
1839{
1840 u64 addr = 0;
1841
1842 memcpy(&addr, &elem, sizeof(elem));
1843 return k3_nav_ringacc_ring_push(ring, &addr);
1844}
1845
Vignesh Rffcc66e2019-02-05 17:31:24 +05301846static int *udma_prep_dma_memcpy(struct udma_chan *uc, dma_addr_t dest,
1847 dma_addr_t src, size_t len)
1848{
1849 u32 tc_ring_id = k3_nav_ringacc_get_ring_id(uc->tchan->tc_ring);
1850 struct cppi5_tr_type15_t *tr_req;
1851 int num_tr;
1852 size_t tr_size = sizeof(struct cppi5_tr_type15_t);
1853 u16 tr0_cnt0, tr0_cnt1, tr1_cnt0;
1854 unsigned long dummy;
1855 void *tr_desc;
1856 size_t desc_size;
1857
1858 if (len < SZ_64K) {
1859 num_tr = 1;
1860 tr0_cnt0 = len;
1861 tr0_cnt1 = 1;
1862 } else {
1863 unsigned long align_to = __ffs(src | dest);
1864
1865 if (align_to > 3)
1866 align_to = 3;
1867 /*
1868 * Keep simple: tr0: SZ_64K-alignment blocks,
1869 * tr1: the remaining
1870 */
1871 num_tr = 2;
1872 tr0_cnt0 = (SZ_64K - BIT(align_to));
1873 if (len / tr0_cnt0 >= SZ_64K) {
1874 dev_err(uc->ud->dev, "size %zu is not supported\n",
1875 len);
1876 return NULL;
1877 }
1878
1879 tr0_cnt1 = len / tr0_cnt0;
1880 tr1_cnt0 = len % tr0_cnt0;
1881 }
1882
1883 desc_size = cppi5_trdesc_calc_size(num_tr, tr_size);
1884 tr_desc = dma_alloc_coherent(desc_size, &dummy);
1885 if (!tr_desc)
1886 return NULL;
1887 memset(tr_desc, 0, desc_size);
1888
1889 cppi5_trdesc_init(tr_desc, num_tr, tr_size, 0, 0);
1890 cppi5_desc_set_pktids(tr_desc, uc->id, 0x3fff);
1891 cppi5_desc_set_retpolicy(tr_desc, 0, tc_ring_id);
1892
1893 tr_req = tr_desc + tr_size;
1894
1895 cppi5_tr_init(&tr_req[0].flags, CPPI5_TR_TYPE15, false, true,
1896 CPPI5_TR_EVENT_SIZE_COMPLETION, 1);
1897 cppi5_tr_csf_set(&tr_req[0].flags, CPPI5_TR_CSF_SUPR_EVT);
1898
1899 tr_req[0].addr = src;
1900 tr_req[0].icnt0 = tr0_cnt0;
1901 tr_req[0].icnt1 = tr0_cnt1;
1902 tr_req[0].icnt2 = 1;
1903 tr_req[0].icnt3 = 1;
1904 tr_req[0].dim1 = tr0_cnt0;
1905
1906 tr_req[0].daddr = dest;
1907 tr_req[0].dicnt0 = tr0_cnt0;
1908 tr_req[0].dicnt1 = tr0_cnt1;
1909 tr_req[0].dicnt2 = 1;
1910 tr_req[0].dicnt3 = 1;
1911 tr_req[0].ddim1 = tr0_cnt0;
1912
1913 if (num_tr == 2) {
1914 cppi5_tr_init(&tr_req[1].flags, CPPI5_TR_TYPE15, false, true,
1915 CPPI5_TR_EVENT_SIZE_COMPLETION, 0);
1916 cppi5_tr_csf_set(&tr_req[1].flags, CPPI5_TR_CSF_SUPR_EVT);
1917
1918 tr_req[1].addr = src + tr0_cnt1 * tr0_cnt0;
1919 tr_req[1].icnt0 = tr1_cnt0;
1920 tr_req[1].icnt1 = 1;
1921 tr_req[1].icnt2 = 1;
1922 tr_req[1].icnt3 = 1;
1923
1924 tr_req[1].daddr = dest + tr0_cnt1 * tr0_cnt0;
1925 tr_req[1].dicnt0 = tr1_cnt0;
1926 tr_req[1].dicnt1 = 1;
1927 tr_req[1].dicnt2 = 1;
1928 tr_req[1].dicnt3 = 1;
1929 }
1930
1931 cppi5_tr_csf_set(&tr_req[num_tr - 1].flags, CPPI5_TR_CSF_EOP);
1932
Vignesh Raghavendraf03cb5c2019-12-09 10:25:39 +05301933 flush_dcache_range((unsigned long)tr_desc,
1934 ALIGN((unsigned long)tr_desc + desc_size,
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05301935 ARCH_DMA_MINALIGN));
Vignesh Rffcc66e2019-02-05 17:31:24 +05301936
Vignesh Raghavendrab0ab0082019-12-09 10:25:38 +05301937 udma_push_to_ring(uc->tchan->t_ring, tr_desc);
Vignesh Rffcc66e2019-02-05 17:31:24 +05301938
1939 return 0;
1940}
1941
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05301942#define TISCI_BCDMA_BCHAN_VALID_PARAMS ( \
1943 TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID | \
1944 TI_SCI_MSG_VALUE_RM_UDMAP_CH_EXTENDED_CH_TYPE_VALID)
1945
1946#define TISCI_BCDMA_TCHAN_VALID_PARAMS ( \
1947 TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID | \
1948 TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID)
1949
1950#define TISCI_BCDMA_RCHAN_VALID_PARAMS ( \
1951 TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID)
1952
1953#define TISCI_UDMA_TCHAN_VALID_PARAMS ( \
1954 TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID | \
1955 TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_EINFO_VALID | \
1956 TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_PSWORDS_VALID | \
1957 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID | \
1958 TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID | \
1959 TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID | \
1960 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID | \
1961 TI_SCI_MSG_VALUE_RM_UDMAP_CH_ATYPE_VALID)
1962
1963#define TISCI_UDMA_RCHAN_VALID_PARAMS ( \
1964 TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID | \
1965 TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID | \
1966 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID | \
1967 TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID | \
1968 TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_SHORT_VALID | \
1969 TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_LONG_VALID | \
1970 TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_START_VALID | \
1971 TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_CNT_VALID | \
1972 TI_SCI_MSG_VALUE_RM_UDMAP_CH_ATYPE_VALID)
1973
1974static int bcdma_tisci_m2m_channel_config(struct udma_chan *uc)
1975{
1976 struct udma_dev *ud = uc->ud;
1977 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
1978 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops;
1979 struct ti_sci_msg_rm_udmap_tx_ch_cfg req_tx = { 0 };
1980 struct udma_bchan *bchan = uc->bchan;
1981 int ret = 0;
1982
1983 req_tx.valid_params = TISCI_BCDMA_BCHAN_VALID_PARAMS;
1984 req_tx.nav_id = tisci_rm->tisci_dev_id;
1985 req_tx.extended_ch_type = TI_SCI_RM_BCDMA_EXTENDED_CH_TYPE_BCHAN;
1986 req_tx.index = bchan->id;
1987
1988 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx);
1989 if (ret)
1990 dev_err(ud->dev, "bchan%d cfg failed %d\n", bchan->id, ret);
1991
1992 return ret;
1993}
1994
1995static struct udma_bchan *__bcdma_reserve_bchan(struct udma_dev *ud, int id)
1996{
1997 if (id >= 0) {
1998 if (test_bit(id, ud->bchan_map)) {
1999 dev_err(ud->dev, "bchan%d is in use\n", id);
2000 return ERR_PTR(-ENOENT);
2001 }
2002 } else {
2003 id = find_next_zero_bit(ud->bchan_map, ud->bchan_cnt, 0);
2004 if (id == ud->bchan_cnt)
2005 return ERR_PTR(-ENOENT);
2006 }
2007 __set_bit(id, ud->bchan_map);
2008 return &ud->bchans[id];
2009}
2010
2011static int bcdma_get_bchan(struct udma_chan *uc)
2012{
2013 struct udma_dev *ud = uc->ud;
2014
2015 if (uc->bchan) {
2016 dev_err(ud->dev, "chan%d: already have bchan%d allocated\n",
2017 uc->id, uc->bchan->id);
2018 return 0;
2019 }
2020
2021 uc->bchan = __bcdma_reserve_bchan(ud, -1);
2022 if (IS_ERR(uc->bchan))
2023 return PTR_ERR(uc->bchan);
2024
2025 uc->tchan = uc->bchan;
2026
2027 return 0;
2028}
2029
2030static void bcdma_put_bchan(struct udma_chan *uc)
2031{
2032 struct udma_dev *ud = uc->ud;
2033
2034 if (uc->bchan) {
2035 dev_dbg(ud->dev, "chan%d: put bchan%d\n", uc->id,
2036 uc->bchan->id);
2037 __clear_bit(uc->bchan->id, ud->bchan_map);
2038 uc->bchan = NULL;
2039 uc->tchan = NULL;
2040 }
2041}
2042
2043static void bcdma_free_bchan_resources(struct udma_chan *uc)
2044{
2045 if (!uc->bchan)
2046 return;
2047
2048 k3_nav_ringacc_ring_free(uc->bchan->tc_ring);
2049 k3_nav_ringacc_ring_free(uc->bchan->t_ring);
2050 uc->bchan->tc_ring = NULL;
2051 uc->bchan->t_ring = NULL;
2052
2053 bcdma_put_bchan(uc);
2054}
2055
2056static int bcdma_alloc_bchan_resources(struct udma_chan *uc)
2057{
2058 struct k3_nav_ring_cfg ring_cfg;
2059 struct udma_dev *ud = uc->ud;
2060 int ret;
2061
2062 ret = bcdma_get_bchan(uc);
2063 if (ret)
2064 return ret;
2065
2066 ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, uc->bchan->id, -1,
2067 &uc->bchan->t_ring,
2068 &uc->bchan->tc_ring);
2069 if (ret) {
2070 ret = -EBUSY;
2071 goto err_ring;
2072 }
2073
2074 memset(&ring_cfg, 0, sizeof(ring_cfg));
2075 ring_cfg.size = 16;
2076 ring_cfg.elm_size = K3_NAV_RINGACC_RING_ELSIZE_8;
2077 ring_cfg.mode = K3_NAV_RINGACC_RING_MODE_RING;
2078
2079 ret = k3_nav_ringacc_ring_cfg(uc->bchan->t_ring, &ring_cfg);
2080 if (ret)
2081 goto err_ringcfg;
2082
2083 return 0;
2084
2085err_ringcfg:
2086 k3_nav_ringacc_ring_free(uc->bchan->tc_ring);
2087 uc->bchan->tc_ring = NULL;
2088 k3_nav_ringacc_ring_free(uc->bchan->t_ring);
2089 uc->bchan->t_ring = NULL;
2090err_ring:
2091 bcdma_put_bchan(uc);
2092
2093 return ret;
2094}
2095
2096static int bcdma_tisci_tx_channel_config(struct udma_chan *uc)
2097{
2098 struct udma_dev *ud = uc->ud;
2099 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
2100 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops;
2101 struct udma_tchan *tchan = uc->tchan;
2102 struct ti_sci_msg_rm_udmap_tx_ch_cfg req_tx = { 0 };
2103 int ret = 0;
2104
2105 req_tx.valid_params = TISCI_BCDMA_TCHAN_VALID_PARAMS;
2106 req_tx.nav_id = tisci_rm->tisci_dev_id;
2107 req_tx.index = tchan->id;
2108 req_tx.tx_supr_tdpkt = uc->config.notdpkt;
2109 if (uc->config.ep_type == PSIL_EP_PDMA_XY &&
2110 ud->match_data->flags & UDMA_FLAG_TDTYPE) {
2111 /* wait for peer to complete the teardown for PDMAs */
2112 req_tx.valid_params |=
2113 TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_TDTYPE_VALID;
2114 req_tx.tx_tdtype = 1;
2115 }
2116
2117 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx);
2118 if (ret)
2119 dev_err(ud->dev, "tchan%d cfg failed %d\n", tchan->id, ret);
2120
2121 return ret;
2122}
2123
2124#define pktdma_tisci_tx_channel_config bcdma_tisci_tx_channel_config
2125
2126static int pktdma_tisci_rx_channel_config(struct udma_chan *uc)
2127{
2128 struct udma_dev *ud = uc->ud;
2129 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm;
2130 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops;
2131 struct ti_sci_msg_rm_udmap_rx_ch_cfg req_rx = { 0 };
2132 struct ti_sci_msg_rm_udmap_flow_cfg flow_req = { 0 };
2133 int ret = 0;
2134
2135 req_rx.valid_params = TISCI_BCDMA_RCHAN_VALID_PARAMS;
2136 req_rx.nav_id = tisci_rm->tisci_dev_id;
2137 req_rx.index = uc->rchan->id;
2138
2139 ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx);
2140 if (ret) {
2141 dev_err(ud->dev, "rchan%d cfg failed %d\n", uc->rchan->id, ret);
2142 return ret;
2143 }
2144
2145 flow_req.valid_params =
2146 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_EINFO_PRESENT_VALID |
2147 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PSINFO_PRESENT_VALID |
2148 TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_ERROR_HANDLING_VALID;
2149
2150 flow_req.nav_id = tisci_rm->tisci_dev_id;
2151 flow_req.flow_index = uc->rflow->id;
2152
2153 if (uc->config.needs_epib)
2154 flow_req.rx_einfo_present = 1;
2155 else
2156 flow_req.rx_einfo_present = 0;
2157 if (uc->config.psd_size)
2158 flow_req.rx_psinfo_present = 1;
2159 else
2160 flow_req.rx_psinfo_present = 0;
Vignesh Raghavendraf8461352023-03-08 09:42:57 +05302161 flow_req.rx_error_handling = 0;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302162
2163 ret = tisci_ops->rx_flow_cfg(tisci_rm->tisci, &flow_req);
2164
2165 if (ret)
2166 dev_err(ud->dev, "flow%d config failed: %d\n", uc->rflow->id,
2167 ret);
2168
2169 return ret;
2170}
2171
2172static int bcdma_alloc_chan_resources(struct udma_chan *uc)
2173{
2174 int ret;
2175
2176 uc->config.pkt_mode = false;
2177
2178 switch (uc->config.dir) {
2179 case DMA_MEM_TO_MEM:
2180 /* Non synchronized - mem to mem type of transfer */
2181 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-MEM\n", __func__,
2182 uc->id);
2183
2184 ret = bcdma_alloc_bchan_resources(uc);
2185 if (ret)
2186 return ret;
2187
2188 ret = bcdma_tisci_m2m_channel_config(uc);
2189 break;
2190 default:
2191 /* Can not happen */
2192 dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n",
2193 __func__, uc->id, uc->config.dir);
2194 return -EINVAL;
2195 }
2196
2197 /* check if the channel configuration was successful */
2198 if (ret)
2199 goto err_res_free;
2200
2201 if (udma_is_chan_running(uc)) {
2202 dev_warn(uc->ud->dev, "chan%d: is running!\n", uc->id);
2203 udma_stop(uc);
2204 if (udma_is_chan_running(uc)) {
2205 dev_err(uc->ud->dev, "chan%d: won't stop!\n", uc->id);
2206 goto err_res_free;
2207 }
2208 }
2209
2210 udma_reset_rings(uc);
2211
2212 return 0;
2213
2214err_res_free:
2215 bcdma_free_bchan_resources(uc);
2216 udma_free_tx_resources(uc);
2217 udma_free_rx_resources(uc);
2218
2219 udma_reset_uchan(uc);
2220
2221 return ret;
2222}
2223
2224static int pktdma_alloc_chan_resources(struct udma_chan *uc)
2225{
2226 struct udma_dev *ud = uc->ud;
2227 int ret;
2228
2229 switch (uc->config.dir) {
2230 case DMA_MEM_TO_DEV:
2231 /* Slave transfer synchronized - mem to dev (TX) trasnfer */
2232 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__,
2233 uc->id);
2234
2235 ret = udma_alloc_tx_resources(uc);
2236 if (ret) {
2237 uc->config.remote_thread_id = -1;
2238 return ret;
2239 }
2240
2241 uc->config.src_thread = ud->psil_base + uc->tchan->id;
2242 uc->config.dst_thread = uc->config.remote_thread_id;
2243 uc->config.dst_thread |= K3_PSIL_DST_THREAD_ID_OFFSET;
2244
2245 ret = pktdma_tisci_tx_channel_config(uc);
2246 break;
2247 case DMA_DEV_TO_MEM:
2248 /* Slave transfer synchronized - dev to mem (RX) trasnfer */
2249 dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__,
2250 uc->id);
2251
2252 ret = udma_alloc_rx_resources(uc);
2253 if (ret) {
2254 uc->config.remote_thread_id = -1;
2255 return ret;
2256 }
2257
2258 uc->config.src_thread = uc->config.remote_thread_id;
2259 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) |
2260 K3_PSIL_DST_THREAD_ID_OFFSET;
2261
2262 ret = pktdma_tisci_rx_channel_config(uc);
2263 break;
2264 default:
2265 /* Can not happen */
2266 dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n",
2267 __func__, uc->id, uc->config.dir);
2268 return -EINVAL;
2269 }
2270
2271 /* check if the channel configuration was successful */
2272 if (ret)
2273 goto err_res_free;
2274
2275 /* PSI-L pairing */
2276 ret = udma_navss_psil_pair(ud, uc->config.src_thread, uc->config.dst_thread);
2277 if (ret) {
2278 dev_err(ud->dev, "PSI-L pairing failed: 0x%04x -> 0x%04x\n",
2279 uc->config.src_thread, uc->config.dst_thread);
2280 goto err_res_free;
2281 }
2282
2283 if (udma_is_chan_running(uc)) {
2284 dev_warn(ud->dev, "chan%d: is running!\n", uc->id);
2285 udma_stop(uc);
2286 if (udma_is_chan_running(uc)) {
2287 dev_err(ud->dev, "chan%d: won't stop!\n", uc->id);
2288 goto err_res_free;
2289 }
2290 }
2291
2292 udma_reset_rings(uc);
2293
2294 if (uc->tchan)
2295 dev_dbg(ud->dev,
2296 "chan%d: tchan%d, tflow%d, Remote thread: 0x%04x\n",
2297 uc->id, uc->tchan->id, uc->tchan->tflow_id,
2298 uc->config.remote_thread_id);
2299 else if (uc->rchan)
2300 dev_dbg(ud->dev,
2301 "chan%d: rchan%d, rflow%d, Remote thread: 0x%04x\n",
2302 uc->id, uc->rchan->id, uc->rflow->id,
2303 uc->config.remote_thread_id);
2304 return 0;
2305
2306err_res_free:
2307 udma_free_tx_resources(uc);
2308 udma_free_rx_resources(uc);
2309
2310 udma_reset_uchan(uc);
2311
2312 return ret;
2313}
2314
Vignesh Rffcc66e2019-02-05 17:31:24 +05302315static int udma_transfer(struct udevice *dev, int direction,
Andrew Davisb9add642022-10-07 12:11:13 -05002316 dma_addr_t dst, dma_addr_t src, size_t len)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302317{
2318 struct udma_dev *ud = dev_get_priv(dev);
2319 /* Channel0 is reserved for memcpy */
2320 struct udma_chan *uc = &ud->channels[0];
2321 dma_addr_t paddr = 0;
2322 int ret;
2323
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302324 switch (ud->match_data->type) {
2325 case DMA_TYPE_UDMA:
2326 ret = udma_alloc_chan_resources(uc);
2327 break;
2328 case DMA_TYPE_BCDMA:
2329 ret = bcdma_alloc_chan_resources(uc);
2330 break;
2331 default:
2332 return -EINVAL;
2333 };
Vignesh Rffcc66e2019-02-05 17:31:24 +05302334 if (ret)
2335 return ret;
2336
Andrew Davisb9add642022-10-07 12:11:13 -05002337 udma_prep_dma_memcpy(uc, dst, src, len);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302338 udma_start(uc);
2339 udma_poll_completion(uc, &paddr);
2340 udma_stop(uc);
2341
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302342 switch (ud->match_data->type) {
2343 case DMA_TYPE_UDMA:
2344 udma_free_chan_resources(uc);
2345 break;
2346 case DMA_TYPE_BCDMA:
2347 bcdma_free_bchan_resources(uc);
2348 break;
2349 default:
2350 return -EINVAL;
2351 };
2352
Vignesh Rffcc66e2019-02-05 17:31:24 +05302353 return 0;
2354}
2355
2356static int udma_request(struct dma *dma)
2357{
2358 struct udma_dev *ud = dev_get_priv(dma->dev);
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302359 struct udma_chan_config *ucc;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302360 struct udma_chan *uc;
2361 unsigned long dummy;
2362 int ret;
2363
2364 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2365 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2366 return -EINVAL;
2367 }
2368
2369 uc = &ud->channels[dma->id];
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302370 ucc = &uc->config;
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302371 switch (ud->match_data->type) {
2372 case DMA_TYPE_UDMA:
2373 ret = udma_alloc_chan_resources(uc);
2374 break;
2375 case DMA_TYPE_BCDMA:
2376 ret = bcdma_alloc_chan_resources(uc);
2377 break;
2378 case DMA_TYPE_PKTDMA:
2379 ret = pktdma_alloc_chan_resources(uc);
2380 break;
2381 default:
2382 return -EINVAL;
2383 }
Vignesh Rffcc66e2019-02-05 17:31:24 +05302384 if (ret) {
2385 dev_err(dma->dev, "alloc dma res failed %d\n", ret);
2386 return -EINVAL;
2387 }
2388
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302389 if (uc->config.dir == DMA_MEM_TO_DEV) {
2390 uc->desc_tx = dma_alloc_coherent(ucc->hdesc_size, &dummy);
2391 memset(uc->desc_tx, 0, ucc->hdesc_size);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302392 } else {
2393 uc->desc_rx = dma_alloc_coherent(
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302394 ucc->hdesc_size * UDMA_RX_DESC_NUM, &dummy);
2395 memset(uc->desc_rx, 0, ucc->hdesc_size * UDMA_RX_DESC_NUM);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302396 }
2397
2398 uc->in_use = true;
2399 uc->desc_rx_cur = 0;
2400 uc->num_rx_bufs = 0;
2401
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302402 if (uc->config.dir == DMA_DEV_TO_MEM) {
Vignesh Raghavendra5e6d9cc2019-12-04 22:17:21 +05302403 uc->cfg_data.flow_id_base = uc->rflow->id;
2404 uc->cfg_data.flow_id_cnt = 1;
2405 }
2406
Vignesh Rffcc66e2019-02-05 17:31:24 +05302407 return 0;
2408}
2409
Simon Glassaae95882020-02-03 07:35:55 -07002410static int udma_rfree(struct dma *dma)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302411{
2412 struct udma_dev *ud = dev_get_priv(dma->dev);
2413 struct udma_chan *uc;
2414
2415 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2416 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2417 return -EINVAL;
2418 }
2419 uc = &ud->channels[dma->id];
2420
2421 if (udma_is_chan_running(uc))
2422 udma_stop(uc);
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302423
2424 udma_navss_psil_unpair(ud, uc->config.src_thread,
2425 uc->config.dst_thread);
2426
2427 bcdma_free_bchan_resources(uc);
2428 udma_free_tx_resources(uc);
2429 udma_free_rx_resources(uc);
2430 udma_reset_uchan(uc);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302431
2432 uc->in_use = false;
2433
2434 return 0;
2435}
2436
2437static int udma_enable(struct dma *dma)
2438{
2439 struct udma_dev *ud = dev_get_priv(dma->dev);
2440 struct udma_chan *uc;
2441 int ret;
2442
2443 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2444 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2445 return -EINVAL;
2446 }
2447 uc = &ud->channels[dma->id];
2448
2449 ret = udma_start(uc);
2450
2451 return ret;
2452}
2453
2454static int udma_disable(struct dma *dma)
2455{
2456 struct udma_dev *ud = dev_get_priv(dma->dev);
2457 struct udma_chan *uc;
2458 int ret = 0;
2459
2460 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2461 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2462 return -EINVAL;
2463 }
2464 uc = &ud->channels[dma->id];
2465
2466 if (udma_is_chan_running(uc))
2467 ret = udma_stop(uc);
2468 else
2469 dev_err(dma->dev, "%s not running\n", __func__);
2470
2471 return ret;
2472}
2473
2474static int udma_send(struct dma *dma, void *src, size_t len, void *metadata)
2475{
2476 struct udma_dev *ud = dev_get_priv(dma->dev);
2477 struct cppi5_host_desc_t *desc_tx;
2478 dma_addr_t dma_src = (dma_addr_t)src;
2479 struct ti_udma_drv_packet_data packet_data = { 0 };
2480 dma_addr_t paddr;
2481 struct udma_chan *uc;
2482 u32 tc_ring_id;
2483 int ret;
2484
Keerthya3f25b92019-04-24 16:33:54 +05302485 if (metadata)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302486 packet_data = *((struct ti_udma_drv_packet_data *)metadata);
2487
2488 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2489 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2490 return -EINVAL;
2491 }
2492 uc = &ud->channels[dma->id];
2493
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302494 if (uc->config.dir != DMA_MEM_TO_DEV)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302495 return -EINVAL;
2496
2497 tc_ring_id = k3_nav_ringacc_get_ring_id(uc->tchan->tc_ring);
2498
2499 desc_tx = uc->desc_tx;
2500
2501 cppi5_hdesc_reset_hbdesc(desc_tx);
2502
2503 cppi5_hdesc_init(desc_tx,
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302504 uc->config.needs_epib ? CPPI5_INFO0_HDESC_EPIB_PRESENT : 0,
2505 uc->config.psd_size);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302506 cppi5_hdesc_set_pktlen(desc_tx, len);
2507 cppi5_hdesc_attach_buf(desc_tx, dma_src, len, dma_src, len);
2508 cppi5_desc_set_pktids(&desc_tx->hdr, uc->id, 0x3fff);
2509 cppi5_desc_set_retpolicy(&desc_tx->hdr, 0, tc_ring_id);
2510 /* pass below information from caller */
2511 cppi5_hdesc_set_pkttype(desc_tx, packet_data.pkt_type);
2512 cppi5_desc_set_tags_ids(&desc_tx->hdr, 0, packet_data.dest_tag);
2513
Vignesh Raghavendraf03cb5c2019-12-09 10:25:39 +05302514 flush_dcache_range((unsigned long)dma_src,
2515 ALIGN((unsigned long)dma_src + len,
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05302516 ARCH_DMA_MINALIGN));
Vignesh Raghavendraf03cb5c2019-12-09 10:25:39 +05302517 flush_dcache_range((unsigned long)desc_tx,
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302518 ALIGN((unsigned long)desc_tx + uc->config.hdesc_size,
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05302519 ARCH_DMA_MINALIGN));
Vignesh Rffcc66e2019-02-05 17:31:24 +05302520
Vignesh Raghavendrab0ab0082019-12-09 10:25:38 +05302521 ret = udma_push_to_ring(uc->tchan->t_ring, uc->desc_tx);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302522 if (ret) {
2523 dev_err(dma->dev, "TX dma push fail ch_id %lu %d\n",
2524 dma->id, ret);
2525 return ret;
2526 }
2527
2528 udma_poll_completion(uc, &paddr);
2529
2530 return 0;
2531}
2532
2533static int udma_receive(struct dma *dma, void **dst, void *metadata)
2534{
2535 struct udma_dev *ud = dev_get_priv(dma->dev);
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302536 struct udma_chan_config *ucc;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302537 struct cppi5_host_desc_t *desc_rx;
2538 dma_addr_t buf_dma;
2539 struct udma_chan *uc;
2540 u32 buf_dma_len, pkt_len;
2541 u32 port_id = 0;
2542 int ret;
2543
2544 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2545 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2546 return -EINVAL;
2547 }
2548 uc = &ud->channels[dma->id];
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302549 ucc = &uc->config;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302550
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302551 if (uc->config.dir != DMA_DEV_TO_MEM)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302552 return -EINVAL;
2553 if (!uc->num_rx_bufs)
2554 return -EINVAL;
2555
Vignesh Raghavendra7be51212020-07-06 13:26:26 +05302556 ret = k3_nav_ringacc_ring_pop(uc->rflow->r_ring, &desc_rx);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302557 if (ret && ret != -ENODATA) {
2558 dev_err(dma->dev, "rx dma fail ch_id:%lu %d\n", dma->id, ret);
2559 return ret;
2560 } else if (ret == -ENODATA) {
2561 return 0;
2562 }
2563
2564 /* invalidate cache data */
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05302565 invalidate_dcache_range((ulong)desc_rx,
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302566 (ulong)(desc_rx + ucc->hdesc_size));
Vignesh Rffcc66e2019-02-05 17:31:24 +05302567
2568 cppi5_hdesc_get_obuf(desc_rx, &buf_dma, &buf_dma_len);
2569 pkt_len = cppi5_hdesc_get_pktlen(desc_rx);
2570
2571 /* invalidate cache data */
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05302572 invalidate_dcache_range((ulong)buf_dma,
2573 (ulong)(buf_dma + buf_dma_len));
Vignesh Rffcc66e2019-02-05 17:31:24 +05302574
2575 cppi5_desc_get_tags_ids(&desc_rx->hdr, &port_id, NULL);
2576
2577 *dst = (void *)buf_dma;
2578 uc->num_rx_bufs--;
2579
2580 return pkt_len;
2581}
2582
2583static int udma_of_xlate(struct dma *dma, struct ofnode_phandle_args *args)
2584{
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302585 struct udma_chan_config *ucc;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302586 struct udma_dev *ud = dev_get_priv(dma->dev);
2587 struct udma_chan *uc = &ud->channels[0];
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302588 struct psil_endpoint_config *ep_config;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302589 u32 val;
2590
2591 for (val = 0; val < ud->ch_count; val++) {
2592 uc = &ud->channels[val];
2593 if (!uc->in_use)
2594 break;
2595 }
2596
2597 if (val == ud->ch_count)
2598 return -EBUSY;
2599
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302600 ucc = &uc->config;
2601 ucc->remote_thread_id = args->args[0];
2602 if (ucc->remote_thread_id & K3_PSIL_DST_THREAD_ID_OFFSET)
2603 ucc->dir = DMA_MEM_TO_DEV;
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302604 else
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302605 ucc->dir = DMA_DEV_TO_MEM;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302606
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302607 ep_config = psil_get_ep_config(ucc->remote_thread_id);
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302608 if (IS_ERR(ep_config)) {
2609 dev_err(ud->dev, "No configuration for psi-l thread 0x%04x\n",
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302610 uc->config.remote_thread_id);
2611 ucc->dir = DMA_MEM_TO_MEM;
2612 ucc->remote_thread_id = -1;
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302613 return false;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302614 }
2615
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302616 ucc->pkt_mode = ep_config->pkt_mode;
2617 ucc->channel_tpl = ep_config->channel_tpl;
2618 ucc->notdpkt = ep_config->notdpkt;
2619 ucc->ep_type = ep_config->ep_type;
Vignesh Rffcc66e2019-02-05 17:31:24 +05302620
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302621 if (ud->match_data->type == DMA_TYPE_PKTDMA &&
2622 ep_config->mapped_channel_id >= 0) {
2623 ucc->mapped_channel_id = ep_config->mapped_channel_id;
2624 ucc->default_flow_id = ep_config->default_flow_id;
2625 } else {
2626 ucc->mapped_channel_id = -1;
2627 ucc->default_flow_id = -1;
2628 }
2629
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302630 ucc->needs_epib = ep_config->needs_epib;
2631 ucc->psd_size = ep_config->psd_size;
2632 ucc->metadata_size = (ucc->needs_epib ? CPPI5_INFO0_HDESC_EPIB_SIZE : 0) + ucc->psd_size;
2633
2634 ucc->hdesc_size = cppi5_hdesc_calc_size(ucc->needs_epib,
2635 ucc->psd_size, 0);
2636 ucc->hdesc_size = ALIGN(ucc->hdesc_size, ARCH_DMA_MINALIGN);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302637
2638 dma->id = uc->id;
2639 pr_debug("Allocated dma chn:%lu epib:%d psdata:%u meta:%u thread_id:%x\n",
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302640 dma->id, ucc->needs_epib,
2641 ucc->psd_size, ucc->metadata_size,
2642 ucc->remote_thread_id);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302643
2644 return 0;
2645}
2646
2647int udma_prepare_rcv_buf(struct dma *dma, void *dst, size_t size)
2648{
2649 struct udma_dev *ud = dev_get_priv(dma->dev);
2650 struct cppi5_host_desc_t *desc_rx;
2651 dma_addr_t dma_dst;
2652 struct udma_chan *uc;
2653 u32 desc_num;
2654
2655 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2656 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2657 return -EINVAL;
2658 }
2659 uc = &ud->channels[dma->id];
2660
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302661 if (uc->config.dir != DMA_DEV_TO_MEM)
Vignesh Rffcc66e2019-02-05 17:31:24 +05302662 return -EINVAL;
2663
2664 if (uc->num_rx_bufs >= UDMA_RX_DESC_NUM)
2665 return -EINVAL;
2666
2667 desc_num = uc->desc_rx_cur % UDMA_RX_DESC_NUM;
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302668 desc_rx = uc->desc_rx + (desc_num * uc->config.hdesc_size);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302669 dma_dst = (dma_addr_t)dst;
2670
2671 cppi5_hdesc_reset_hbdesc(desc_rx);
2672
2673 cppi5_hdesc_init(desc_rx,
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302674 uc->config.needs_epib ? CPPI5_INFO0_HDESC_EPIB_PRESENT : 0,
2675 uc->config.psd_size);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302676 cppi5_hdesc_set_pktlen(desc_rx, size);
2677 cppi5_hdesc_attach_buf(desc_rx, dma_dst, size, dma_dst, size);
2678
Matthias Schiffer1db973b2024-04-26 10:02:28 +02002679 invalidate_dcache_range((unsigned long)dma_dst,
2680 (unsigned long)(dma_dst + size));
2681
Vignesh Raghavendraf03cb5c2019-12-09 10:25:39 +05302682 flush_dcache_range((unsigned long)desc_rx,
Vignesh Raghavendraaf374c22020-07-06 13:26:25 +05302683 ALIGN((unsigned long)desc_rx + uc->config.hdesc_size,
Vignesh Raghavendrac0b94902019-12-09 10:25:35 +05302684 ARCH_DMA_MINALIGN));
Vignesh Rffcc66e2019-02-05 17:31:24 +05302685
Vignesh Raghavendra7be51212020-07-06 13:26:26 +05302686 udma_push_to_ring(uc->rflow->fd_ring, desc_rx);
Vignesh Rffcc66e2019-02-05 17:31:24 +05302687
2688 uc->num_rx_bufs++;
2689 uc->desc_rx_cur++;
2690
2691 return 0;
2692}
2693
Vignesh Raghavendra5e6d9cc2019-12-04 22:17:21 +05302694static int udma_get_cfg(struct dma *dma, u32 id, void **data)
2695{
2696 struct udma_dev *ud = dev_get_priv(dma->dev);
2697 struct udma_chan *uc;
2698
2699 if (dma->id >= (ud->rchan_cnt + ud->tchan_cnt)) {
2700 dev_err(dma->dev, "invalid dma ch_id %lu\n", dma->id);
2701 return -EINVAL;
2702 }
2703
2704 switch (id) {
2705 case TI_UDMA_CHAN_PRIV_INFO:
2706 uc = &ud->channels[dma->id];
2707 *data = &uc->cfg_data;
2708 return 0;
2709 }
2710
2711 return -EINVAL;
2712}
2713
Vignesh Rffcc66e2019-02-05 17:31:24 +05302714static const struct dma_ops udma_ops = {
2715 .transfer = udma_transfer,
2716 .of_xlate = udma_of_xlate,
2717 .request = udma_request,
Simon Glassaae95882020-02-03 07:35:55 -07002718 .rfree = udma_rfree,
Vignesh Rffcc66e2019-02-05 17:31:24 +05302719 .enable = udma_enable,
2720 .disable = udma_disable,
2721 .send = udma_send,
2722 .receive = udma_receive,
2723 .prepare_rcv_buf = udma_prepare_rcv_buf,
Vignesh Raghavendra5e6d9cc2019-12-04 22:17:21 +05302724 .get_cfg = udma_get_cfg,
Vignesh Rffcc66e2019-02-05 17:31:24 +05302725};
2726
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302727static struct udma_match_data am654_main_data = {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302728 .type = DMA_TYPE_UDMA,
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302729 .psil_base = 0x1000,
2730 .enable_memcpy_support = true,
2731 .statictr_z_mask = GENMASK(11, 0),
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302732 .oes = {
2733 .udma_rchan = 0x200,
2734 },
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302735 .tpl_levels = 2,
2736 .level_start_idx = {
2737 [0] = 8, /* Normal channels */
2738 [1] = 0, /* High Throughput channels */
2739 },
2740};
2741
2742static struct udma_match_data am654_mcu_data = {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302743 .type = DMA_TYPE_UDMA,
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302744 .psil_base = 0x6000,
2745 .enable_memcpy_support = true,
2746 .statictr_z_mask = GENMASK(11, 0),
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302747 .oes = {
2748 .udma_rchan = 0x200,
2749 },
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302750 .tpl_levels = 2,
2751 .level_start_idx = {
2752 [0] = 2, /* Normal channels */
2753 [1] = 0, /* High Throughput channels */
2754 },
2755};
2756
2757static struct udma_match_data j721e_main_data = {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302758 .type = DMA_TYPE_UDMA,
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302759 .psil_base = 0x1000,
2760 .enable_memcpy_support = true,
2761 .flags = UDMA_FLAG_PDMA_ACC32 | UDMA_FLAG_PDMA_BURST | UDMA_FLAG_TDTYPE,
2762 .statictr_z_mask = GENMASK(23, 0),
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302763 .oes = {
2764 .udma_rchan = 0x400,
2765 },
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302766 .tpl_levels = 3,
2767 .level_start_idx = {
2768 [0] = 16, /* Normal channels */
2769 [1] = 4, /* High Throughput channels */
2770 [2] = 0, /* Ultra High Throughput channels */
2771 },
2772};
2773
2774static struct udma_match_data j721e_mcu_data = {
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302775 .type = DMA_TYPE_UDMA,
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302776 .psil_base = 0x6000,
2777 .enable_memcpy_support = true,
2778 .flags = UDMA_FLAG_PDMA_ACC32 | UDMA_FLAG_PDMA_BURST | UDMA_FLAG_TDTYPE,
2779 .statictr_z_mask = GENMASK(23, 0),
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302780 .oes = {
2781 .udma_rchan = 0x400,
2782 },
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302783 .tpl_levels = 2,
2784 .level_start_idx = {
2785 [0] = 2, /* Normal channels */
2786 [1] = 0, /* High Throughput channels */
2787 },
2788};
2789
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302790static struct udma_match_data am64_bcdma_data = {
2791 .type = DMA_TYPE_BCDMA,
2792 .psil_base = 0x2000, /* for tchan and rchan, not applicable to bchan */
2793 .enable_memcpy_support = true, /* Supported via bchan */
2794 .flags = UDMA_FLAG_PDMA_ACC32 | UDMA_FLAG_PDMA_BURST | UDMA_FLAG_TDTYPE,
2795 .statictr_z_mask = GENMASK(23, 0),
2796 .oes = {
2797 .bcdma_bchan_data = 0x2200,
2798 .bcdma_bchan_ring = 0x2400,
2799 .bcdma_tchan_data = 0x2800,
2800 .bcdma_tchan_ring = 0x2a00,
2801 .bcdma_rchan_data = 0x2e00,
2802 .bcdma_rchan_ring = 0x3000,
2803 },
2804 /* No throughput levels */
2805};
2806
2807static struct udma_match_data am64_pktdma_data = {
2808 .type = DMA_TYPE_PKTDMA,
2809 .psil_base = 0x1000,
2810 .enable_memcpy_support = false,
2811 .flags = UDMA_FLAG_PDMA_ACC32 | UDMA_FLAG_PDMA_BURST | UDMA_FLAG_TDTYPE,
2812 .statictr_z_mask = GENMASK(23, 0),
2813 .oes = {
2814 .pktdma_tchan_flow = 0x1200,
2815 .pktdma_rchan_flow = 0x1600,
2816 },
2817 /* No throughput levels */
2818};
2819
Vignesh Rffcc66e2019-02-05 17:31:24 +05302820static const struct udevice_id udma_ids[] = {
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302821 {
2822 .compatible = "ti,am654-navss-main-udmap",
2823 .data = (ulong)&am654_main_data,
2824 },
2825 {
2826 .compatible = "ti,am654-navss-mcu-udmap",
2827 .data = (ulong)&am654_mcu_data,
2828 }, {
2829 .compatible = "ti,j721e-navss-main-udmap",
2830 .data = (ulong)&j721e_main_data,
2831 }, {
2832 .compatible = "ti,j721e-navss-mcu-udmap",
2833 .data = (ulong)&j721e_mcu_data,
2834 },
Vignesh Raghavendra9a928512021-05-10 20:06:08 +05302835 {
2836 .compatible = "ti,am64-dmss-bcdma",
2837 .data = (ulong)&am64_bcdma_data,
2838 },
2839 {
2840 .compatible = "ti,am64-dmss-pktdma",
2841 .data = (ulong)&am64_pktdma_data,
2842 },
Vignesh Raghavendra5c92fff2020-07-07 13:43:34 +05302843 { /* Sentinel */ },
Vignesh Rffcc66e2019-02-05 17:31:24 +05302844};
2845
2846U_BOOT_DRIVER(ti_edma3) = {
2847 .name = "ti-udma",
2848 .id = UCLASS_DMA,
2849 .of_match = udma_ids,
2850 .ops = &udma_ops,
2851 .probe = udma_probe,
Simon Glass41575d82020-12-03 16:55:17 -07002852 .priv_auto = sizeof(struct udma_dev),
Vignesh Rffcc66e2019-02-05 17:31:24 +05302853};