Lines Matching +full:sci +full:- +full:rm +full:- +full:range +full:- +full:rchan

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
11 #include <linux/dma-mapping.h>
26 #include <linux/soc/ti/k3-ringacc.h>
29 #include <linux/dma/k3-event-router.h>
30 #include <linux/dma/ti-cppi5.h>
32 #include "../virt-dma.h"
33 #include "k3-udma.h"
34 #include "k3-psil-priv.h"
289 struct udma_rchan *rchan; member
359 if (!uc->tchan) in udma_tchanrt_read()
361 return udma_read(uc->tchan->reg_rt, reg); in udma_tchanrt_read()
366 if (!uc->tchan) in udma_tchanrt_write()
368 udma_write(uc->tchan->reg_rt, reg, val); in udma_tchanrt_write()
374 if (!uc->tchan) in udma_tchanrt_update_bits()
376 udma_update_bits(uc->tchan->reg_rt, reg, mask, val); in udma_tchanrt_update_bits()
382 if (!uc->rchan) in udma_rchanrt_read()
384 return udma_read(uc->rchan->reg_rt, reg); in udma_rchanrt_read()
389 if (!uc->rchan) in udma_rchanrt_write()
391 udma_write(uc->rchan->reg_rt, reg, val); in udma_rchanrt_write()
397 if (!uc->rchan) in udma_rchanrt_update_bits()
399 udma_update_bits(uc->rchan->reg_rt, reg, mask, val); in udma_rchanrt_update_bits()
404 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in navss_psil_pair()
407 return tisci_rm->tisci_psil_ops->pair(tisci_rm->tisci, in navss_psil_pair()
408 tisci_rm->tisci_navss_dev_id, in navss_psil_pair()
415 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in navss_psil_unpair()
418 return tisci_rm->tisci_psil_ops->unpair(tisci_rm->tisci, in navss_psil_unpair()
419 tisci_rm->tisci_navss_dev_id, in navss_psil_unpair()
425 struct device *chan_dev = &chan->dev->device; in k3_configure_chan_coherency()
429 chan->dev->chan_dma_dev = false; in k3_configure_chan_coherency()
431 chan_dev->dma_coherent = false; in k3_configure_chan_coherency()
432 chan_dev->dma_parms = NULL; in k3_configure_chan_coherency()
434 chan->dev->chan_dma_dev = true; in k3_configure_chan_coherency()
436 chan_dev->dma_coherent = true; in k3_configure_chan_coherency()
438 chan_dev->dma_parms = chan_dev->parent->dma_parms; in k3_configure_chan_coherency()
440 dev_warn(chan->device->dev, "Invalid ASEL value: %u\n", asel); in k3_configure_chan_coherency()
442 chan_dev->dma_coherent = false; in k3_configure_chan_coherency()
443 chan_dev->dma_parms = NULL; in k3_configure_chan_coherency()
451 for (i = 0; i < tpl_map->levels; i++) { in udma_get_chan_tpl_index()
452 if (chan_id >= tpl_map->start_idx[i]) in udma_get_chan_tpl_index()
461 memset(&uc->config, 0, sizeof(uc->config)); in udma_reset_uchan()
462 uc->config.remote_thread_id = -1; in udma_reset_uchan()
463 uc->config.mapped_channel_id = -1; in udma_reset_uchan()
464 uc->config.default_flow_id = -1; in udma_reset_uchan()
465 uc->state = UDMA_CHAN_IS_IDLE; in udma_reset_uchan()
470 struct device *dev = uc->ud->dev; in udma_dump_chan_stdata()
474 if (uc->config.dir == DMA_MEM_TO_DEV || uc->config.dir == DMA_MEM_TO_MEM) { in udma_dump_chan_stdata()
483 if (uc->config.dir == DMA_DEV_TO_MEM || uc->config.dir == DMA_MEM_TO_MEM) { in udma_dump_chan_stdata()
484 dev_dbg(dev, "RCHAN State data:\n"); in udma_dump_chan_stdata()
496 return d->hwdesc[idx].cppi5_desc_paddr; in udma_curr_cppi5_desc_paddr()
501 return d->hwdesc[idx].cppi5_desc_vaddr; in udma_curr_cppi5_desc_vaddr()
507 struct udma_desc *d = uc->terminated_desc; in udma_udma_desc_from_paddr()
511 d->desc_idx); in udma_udma_desc_from_paddr()
518 d = uc->desc; in udma_udma_desc_from_paddr()
521 d->desc_idx); in udma_udma_desc_from_paddr()
533 if (uc->use_dma_pool) { in udma_free_hwdesc()
536 for (i = 0; i < d->hwdesc_count; i++) { in udma_free_hwdesc()
537 if (!d->hwdesc[i].cppi5_desc_vaddr) in udma_free_hwdesc()
540 dma_pool_free(uc->hdesc_pool, in udma_free_hwdesc()
541 d->hwdesc[i].cppi5_desc_vaddr, in udma_free_hwdesc()
542 d->hwdesc[i].cppi5_desc_paddr); in udma_free_hwdesc()
544 d->hwdesc[i].cppi5_desc_vaddr = NULL; in udma_free_hwdesc()
546 } else if (d->hwdesc[0].cppi5_desc_vaddr) { in udma_free_hwdesc()
547 dma_free_coherent(uc->dma_dev, d->hwdesc[0].cppi5_desc_size, in udma_free_hwdesc()
548 d->hwdesc[0].cppi5_desc_vaddr, in udma_free_hwdesc()
549 d->hwdesc[0].cppi5_desc_paddr); in udma_free_hwdesc()
551 d->hwdesc[0].cppi5_desc_vaddr = NULL; in udma_free_hwdesc()
562 spin_lock_irqsave(&ud->lock, flags); in udma_purge_desc_work()
563 list_splice_tail_init(&ud->desc_to_purge, &head); in udma_purge_desc_work()
564 spin_unlock_irqrestore(&ud->lock, flags); in udma_purge_desc_work()
567 struct udma_chan *uc = to_udma_chan(vd->tx.chan); in udma_purge_desc_work()
568 struct udma_desc *d = to_udma_desc(&vd->tx); in udma_purge_desc_work()
571 list_del(&vd->node); in udma_purge_desc_work()
576 if (!list_empty(&ud->desc_to_purge)) in udma_purge_desc_work()
577 schedule_work(&ud->purge_work); in udma_purge_desc_work()
582 struct udma_dev *ud = to_udma_dev(vd->tx.chan->device); in udma_desc_free()
583 struct udma_chan *uc = to_udma_chan(vd->tx.chan); in udma_desc_free()
584 struct udma_desc *d = to_udma_desc(&vd->tx); in udma_desc_free()
587 if (uc->terminated_desc == d) in udma_desc_free()
588 uc->terminated_desc = NULL; in udma_desc_free()
590 if (uc->use_dma_pool) { in udma_desc_free()
596 spin_lock_irqsave(&ud->lock, flags); in udma_desc_free()
597 list_add_tail(&vd->node, &ud->desc_to_purge); in udma_desc_free()
598 spin_unlock_irqrestore(&ud->lock, flags); in udma_desc_free()
600 schedule_work(&ud->purge_work); in udma_desc_free()
608 if (uc->tchan) in udma_is_chan_running()
610 if (uc->rchan) in udma_is_chan_running()
623 switch (uc->config.dir) { in udma_is_chan_paused()
648 return uc->ud->rx_flush.hwdescs[uc->config.pkt_mode].cppi5_desc_paddr; in udma_get_rx_flush_hwdesc_paddr()
653 struct udma_desc *d = uc->desc; in udma_push_to_ring()
657 switch (uc->config.dir) { in udma_push_to_ring()
659 ring = uc->rflow->fd_ring; in udma_push_to_ring()
663 ring = uc->tchan->t_ring; in udma_push_to_ring()
666 return -EINVAL; in udma_push_to_ring()
669 /* RX flush packet: idx == -1 is only passed in case of DEV_TO_MEM */ in udma_push_to_ring()
670 if (idx == -1) { in udma_push_to_ring()
683 if (uc->config.dir != DMA_DEV_TO_MEM) in udma_desc_is_rx_flush()
697 switch (uc->config.dir) { in udma_pop_from_ring()
699 ring = uc->rflow->r_ring; in udma_pop_from_ring()
703 ring = uc->tchan->tc_ring; in udma_pop_from_ring()
706 return -ENOENT; in udma_pop_from_ring()
721 return -ENOENT; in udma_pop_from_ring()
731 switch (uc->config.dir) { in udma_reset_rings()
733 if (uc->rchan) { in udma_reset_rings()
734 ring1 = uc->rflow->fd_ring; in udma_reset_rings()
735 ring2 = uc->rflow->r_ring; in udma_reset_rings()
740 if (uc->tchan) { in udma_reset_rings()
741 ring1 = uc->tchan->t_ring; in udma_reset_rings()
742 ring2 = uc->tchan->tc_ring; in udma_reset_rings()
756 if (uc->terminated_desc) { in udma_reset_rings()
757 udma_desc_free(&uc->terminated_desc->vd); in udma_reset_rings()
758 uc->terminated_desc = NULL; in udma_reset_rings()
764 if (uc->desc->dir == DMA_DEV_TO_MEM) { in udma_decrement_byte_counters()
767 if (uc->config.ep_type != PSIL_EP_NATIVE) in udma_decrement_byte_counters()
772 if (!uc->bchan && uc->config.ep_type != PSIL_EP_NATIVE) in udma_decrement_byte_counters()
781 if (uc->tchan) { in udma_reset_counters()
791 if (!uc->bchan) { in udma_reset_counters()
797 if (uc->rchan) { in udma_reset_counters()
814 switch (uc->config.dir) { in udma_reset_chan()
828 return -EINVAL; in udma_reset_chan()
834 /* Hard reset: re-initialize the channel to reset */ in udma_reset_chan()
839 memcpy(&ucc_backup, &uc->config, sizeof(uc->config)); in udma_reset_chan()
840 uc->ud->ddev.device_free_chan_resources(&uc->vc.chan); in udma_reset_chan()
843 memcpy(&uc->config, &ucc_backup, sizeof(uc->config)); in udma_reset_chan()
844 ret = uc->ud->ddev.device_alloc_chan_resources(&uc->vc.chan); in udma_reset_chan()
850 * the rchan. in udma_reset_chan()
852 if (uc->config.dir == DMA_DEV_TO_MEM) in udma_reset_chan()
858 uc->state = UDMA_CHAN_IS_IDLE; in udma_reset_chan()
865 struct udma_chan_config *ucc = &uc->config; in udma_start_desc()
867 if (uc->ud->match_data->type == DMA_TYPE_UDMA && ucc->pkt_mode && in udma_start_desc()
868 (uc->cyclic || ucc->dir == DMA_DEV_TO_MEM)) { in udma_start_desc()
874 * PKTDMA supports pre-linked descriptor and cyclic is not in udma_start_desc()
877 for (i = 0; i < uc->desc->sglen; i++) in udma_start_desc()
887 if (uc->config.ep_type == PSIL_EP_NATIVE) in udma_chan_needs_reconfiguration()
891 if (memcmp(&uc->static_tr, &uc->desc->static_tr, sizeof(uc->static_tr))) in udma_chan_needs_reconfiguration()
899 struct virt_dma_desc *vd = vchan_next_desc(&uc->vc); in udma_start()
902 uc->desc = NULL; in udma_start()
903 return -ENOENT; in udma_start()
906 list_del(&vd->node); in udma_start()
908 uc->desc = to_udma_desc(&vd->tx); in udma_start()
922 switch (uc->desc->dir) { in udma_start()
925 if (uc->config.ep_type == PSIL_EP_PDMA_XY) { in udma_start()
926 u32 val = PDMA_STATIC_TR_Y(uc->desc->static_tr.elcnt) | in udma_start()
927 PDMA_STATIC_TR_X(uc->desc->static_tr.elsize); in udma_start()
929 uc->ud->match_data; in udma_start()
931 if (uc->config.enable_acc32) in udma_start()
933 if (uc->config.enable_burst) in udma_start()
942 PDMA_STATIC_TR_Z(uc->desc->static_tr.bstcnt, in udma_start()
943 match_data->statictr_z_mask)); in udma_start()
946 memcpy(&uc->static_tr, &uc->desc->static_tr, in udma_start()
947 sizeof(uc->static_tr)); in udma_start()
960 if (uc->config.ep_type == PSIL_EP_PDMA_XY) { in udma_start()
961 u32 val = PDMA_STATIC_TR_Y(uc->desc->static_tr.elcnt) | in udma_start()
962 PDMA_STATIC_TR_X(uc->desc->static_tr.elsize); in udma_start()
964 if (uc->config.enable_acc32) in udma_start()
966 if (uc->config.enable_burst) in udma_start()
974 memcpy(&uc->static_tr, &uc->desc->static_tr, in udma_start()
975 sizeof(uc->static_tr)); in udma_start()
994 return -EINVAL; in udma_start()
997 uc->state = UDMA_CHAN_IS_ACTIVE; in udma_start()
1005 enum udma_chan_state old_state = uc->state; in udma_stop()
1007 uc->state = UDMA_CHAN_IS_TERMINATING; in udma_stop()
1008 reinit_completion(&uc->teardown_completed); in udma_stop()
1010 switch (uc->config.dir) { in udma_stop()
1012 if (!uc->cyclic && !uc->desc) in udma_stop()
1013 udma_push_to_ring(uc, -1); in udma_stop()
1033 uc->state = old_state; in udma_stop()
1034 complete_all(&uc->teardown_completed); in udma_stop()
1035 return -EINVAL; in udma_stop()
1043 struct udma_desc *d = uc->desc; in udma_cyclic_packet_elapsed()
1046 h_desc = d->hwdesc[d->desc_idx].cppi5_desc_vaddr; in udma_cyclic_packet_elapsed()
1048 udma_push_to_ring(uc, d->desc_idx); in udma_cyclic_packet_elapsed()
1049 d->desc_idx = (d->desc_idx + 1) % d->sglen; in udma_cyclic_packet_elapsed()
1054 struct cppi5_host_desc_t *h_desc = d->hwdesc[0].cppi5_desc_vaddr; in udma_fetch_epib()
1056 memcpy(d->metadata, h_desc->epib, d->metadata_size); in udma_fetch_epib()
1069 if (uc->config.ep_type == PSIL_EP_NATIVE || in udma_is_desc_really_done()
1070 uc->config.dir != DMA_MEM_TO_DEV || !(uc->config.tx_flags & DMA_PREP_INTERRUPT)) in udma_is_desc_really_done()
1078 uc->tx_drain.residue = bcnt - peer_bcnt; in udma_is_desc_really_done()
1079 uc->tx_drain.tstamp = ktime_get(); in udma_is_desc_really_done()
1096 if (uc->desc) { in udma_check_tx_completion()
1098 residue_diff = uc->tx_drain.residue; in udma_check_tx_completion()
1099 time_diff = uc->tx_drain.tstamp; in udma_check_tx_completion()
1104 desc_done = udma_is_desc_really_done(uc, uc->desc); in udma_check_tx_completion()
1112 time_diff = ktime_sub(uc->tx_drain.tstamp, in udma_check_tx_completion()
1114 residue_diff -= uc->tx_drain.residue; in udma_check_tx_completion()
1123 uc->tx_drain.residue; in udma_check_tx_completion()
1126 schedule_delayed_work(&uc->tx_drain.work, HZ); in udma_check_tx_completion()
1135 if (uc->desc) { in udma_check_tx_completion()
1136 struct udma_desc *d = uc->desc; in udma_check_tx_completion()
1138 udma_decrement_byte_counters(uc, d->residue); in udma_check_tx_completion()
1140 vchan_cookie_complete(&d->vd); in udma_check_tx_completion()
1157 spin_lock(&uc->vc.lock); in udma_ring_irq_handler()
1161 complete_all(&uc->teardown_completed); in udma_ring_irq_handler()
1163 if (uc->terminated_desc) { in udma_ring_irq_handler()
1164 udma_desc_free(&uc->terminated_desc->vd); in udma_ring_irq_handler()
1165 uc->terminated_desc = NULL; in udma_ring_irq_handler()
1168 if (!uc->desc) in udma_ring_irq_handler()
1178 d->desc_idx); in udma_ring_irq_handler()
1180 dev_err(uc->ud->dev, "not matching descriptors!\n"); in udma_ring_irq_handler()
1184 if (d == uc->desc) { in udma_ring_irq_handler()
1186 if (uc->cyclic) { in udma_ring_irq_handler()
1188 vchan_cyclic_callback(&d->vd); in udma_ring_irq_handler()
1191 udma_decrement_byte_counters(uc, d->residue); in udma_ring_irq_handler()
1193 vchan_cookie_complete(&d->vd); in udma_ring_irq_handler()
1195 schedule_delayed_work(&uc->tx_drain.work, in udma_ring_irq_handler()
1204 dma_cookie_complete(&d->vd.tx); in udma_ring_irq_handler()
1208 spin_unlock(&uc->vc.lock); in udma_ring_irq_handler()
1218 spin_lock(&uc->vc.lock); in udma_udma_irq_handler()
1219 d = uc->desc; in udma_udma_irq_handler()
1221 d->tr_idx = (d->tr_idx + 1) % d->sglen; in udma_udma_irq_handler()
1223 if (uc->cyclic) { in udma_udma_irq_handler()
1224 vchan_cyclic_callback(&d->vd); in udma_udma_irq_handler()
1227 udma_decrement_byte_counters(uc, d->residue); in udma_udma_irq_handler()
1229 vchan_cookie_complete(&d->vd); in udma_udma_irq_handler()
1233 spin_unlock(&uc->vc.lock); in udma_udma_irq_handler()
1239 * __udma_alloc_gp_rflow_range - alloc range of GP RX flows
1244 * Allocate range of RX flow ids for future use, those flows can be requested
1245 * only using explicit flow id number. if @from is set to -1 it will try to find
1246 * first free range. if @from is positive value it will force allocation only
1247 * of the specified range of flows.
1249 * Returns -ENOMEM if can't find free range.
1250 * -EEXIST if requested range is busy.
1251 * -EINVAL if wrong input values passed.
1261 tmp_from = ud->rchan_cnt; in __udma_alloc_gp_rflow_range()
1263 if (tmp_from < ud->rchan_cnt) in __udma_alloc_gp_rflow_range()
1264 return -EINVAL; in __udma_alloc_gp_rflow_range()
1266 if (tmp_from + cnt > ud->rflow_cnt) in __udma_alloc_gp_rflow_range()
1267 return -EINVAL; in __udma_alloc_gp_rflow_range()
1269 bitmap_or(tmp, ud->rflow_gp_map, ud->rflow_gp_map_allocated, in __udma_alloc_gp_rflow_range()
1270 ud->rflow_cnt); in __udma_alloc_gp_rflow_range()
1273 ud->rflow_cnt, in __udma_alloc_gp_rflow_range()
1275 if (start >= ud->rflow_cnt) in __udma_alloc_gp_rflow_range()
1276 return -ENOMEM; in __udma_alloc_gp_rflow_range()
1279 return -EEXIST; in __udma_alloc_gp_rflow_range()
1281 bitmap_set(ud->rflow_gp_map_allocated, start, cnt); in __udma_alloc_gp_rflow_range()
1287 if (from < ud->rchan_cnt) in __udma_free_gp_rflow_range()
1288 return -EINVAL; in __udma_free_gp_rflow_range()
1289 if (from + cnt > ud->rflow_cnt) in __udma_free_gp_rflow_range()
1290 return -EINVAL; in __udma_free_gp_rflow_range()
1292 bitmap_clear(ud->rflow_gp_map_allocated, from, cnt); in __udma_free_gp_rflow_range()
1301 * TI-SCI FW will perform additional permission check ant way, it's in __udma_get_rflow()
1305 if (id < 0 || id >= ud->rflow_cnt) in __udma_get_rflow()
1306 return ERR_PTR(-ENOENT); in __udma_get_rflow()
1308 if (test_bit(id, ud->rflow_in_use)) in __udma_get_rflow()
1309 return ERR_PTR(-ENOENT); in __udma_get_rflow()
1311 if (ud->rflow_gp_map) { in __udma_get_rflow()
1313 if (!test_bit(id, ud->rflow_gp_map) && in __udma_get_rflow()
1314 !test_bit(id, ud->rflow_gp_map_allocated)) in __udma_get_rflow()
1315 return ERR_PTR(-EINVAL); in __udma_get_rflow()
1318 dev_dbg(ud->dev, "get rflow%d\n", id); in __udma_get_rflow()
1319 set_bit(id, ud->rflow_in_use); in __udma_get_rflow()
1320 return &ud->rflows[id]; in __udma_get_rflow()
1325 if (!test_bit(rflow->id, ud->rflow_in_use)) { in __udma_put_rflow()
1326 dev_err(ud->dev, "attempt to put unused rflow%d\n", rflow->id); in __udma_put_rflow()
1330 dev_dbg(ud->dev, "put rflow%d\n", rflow->id); in __udma_put_rflow()
1331 clear_bit(rflow->id, ud->rflow_in_use); in __udma_put_rflow()
1340 if (test_bit(id, ud->res##_map)) { \
1341 dev_err(ud->dev, "res##%d is in use\n", id); \
1342 return ERR_PTR(-ENOENT); \
1347 if (tpl >= ud->res##_tpl.levels) \
1348 tpl = ud->res##_tpl.levels - 1; \
1350 start = ud->res##_tpl.start_idx[tpl]; \
1352 id = find_next_zero_bit(ud->res##_map, ud->res##_cnt, \
1354 if (id == ud->res##_cnt) { \
1355 return ERR_PTR(-ENOENT); \
1359 set_bit(id, ud->res##_map); \
1360 return &ud->res##s[id]; \
1365 UDMA_RESERVE_RESOURCE(rchan);
1369 struct udma_dev *ud = uc->ud; in bcdma_get_bchan()
1373 if (uc->bchan) { in bcdma_get_bchan()
1374 dev_dbg(ud->dev, "chan%d: already have bchan%d allocated\n", in bcdma_get_bchan()
1375 uc->id, uc->bchan->id); in bcdma_get_bchan()
1383 if (uc->config.tr_trigger_type) in bcdma_get_bchan()
1386 tpl = ud->bchan_tpl.levels - 1; in bcdma_get_bchan()
1388 uc->bchan = __udma_reserve_bchan(ud, tpl, -1); in bcdma_get_bchan()
1389 if (IS_ERR(uc->bchan)) { in bcdma_get_bchan()
1390 ret = PTR_ERR(uc->bchan); in bcdma_get_bchan()
1391 uc->bchan = NULL; in bcdma_get_bchan()
1395 uc->tchan = uc->bchan; in bcdma_get_bchan()
1402 struct udma_dev *ud = uc->ud; in udma_get_tchan()
1405 if (uc->tchan) { in udma_get_tchan()
1406 dev_dbg(ud->dev, "chan%d: already have tchan%d allocated\n", in udma_get_tchan()
1407 uc->id, uc->tchan->id); in udma_get_tchan()
1412 * mapped_channel_id is -1 for UDMA, BCDMA and PKTDMA unmapped channels. in udma_get_tchan()
1416 uc->tchan = __udma_reserve_tchan(ud, uc->config.channel_tpl, in udma_get_tchan()
1417 uc->config.mapped_channel_id); in udma_get_tchan()
1418 if (IS_ERR(uc->tchan)) { in udma_get_tchan()
1419 ret = PTR_ERR(uc->tchan); in udma_get_tchan()
1420 uc->tchan = NULL; in udma_get_tchan()
1424 if (ud->tflow_cnt) { in udma_get_tchan()
1428 if (uc->config.default_flow_id >= 0) in udma_get_tchan()
1429 tflow_id = uc->config.default_flow_id; in udma_get_tchan()
1431 tflow_id = uc->tchan->id; in udma_get_tchan()
1433 if (test_bit(tflow_id, ud->tflow_map)) { in udma_get_tchan()
1434 dev_err(ud->dev, "tflow%d is in use\n", tflow_id); in udma_get_tchan()
1435 clear_bit(uc->tchan->id, ud->tchan_map); in udma_get_tchan()
1436 uc->tchan = NULL; in udma_get_tchan()
1437 return -ENOENT; in udma_get_tchan()
1440 uc->tchan->tflow_id = tflow_id; in udma_get_tchan()
1441 set_bit(tflow_id, ud->tflow_map); in udma_get_tchan()
1443 uc->tchan->tflow_id = -1; in udma_get_tchan()
1451 struct udma_dev *ud = uc->ud; in udma_get_rchan()
1454 if (uc->rchan) { in udma_get_rchan()
1455 dev_dbg(ud->dev, "chan%d: already have rchan%d allocated\n", in udma_get_rchan()
1456 uc->id, uc->rchan->id); in udma_get_rchan()
1461 * mapped_channel_id is -1 for UDMA, BCDMA and PKTDMA unmapped channels. in udma_get_rchan()
1465 uc->rchan = __udma_reserve_rchan(ud, uc->config.channel_tpl, in udma_get_rchan()
1466 uc->config.mapped_channel_id); in udma_get_rchan()
1467 if (IS_ERR(uc->rchan)) { in udma_get_rchan()
1468 ret = PTR_ERR(uc->rchan); in udma_get_rchan()
1469 uc->rchan = NULL; in udma_get_rchan()
1478 struct udma_dev *ud = uc->ud; in udma_get_chan_pair()
1481 if ((uc->tchan && uc->rchan) && uc->tchan->id == uc->rchan->id) { in udma_get_chan_pair()
1482 dev_info(ud->dev, "chan%d: already have %d pair allocated\n", in udma_get_chan_pair()
1483 uc->id, uc->tchan->id); in udma_get_chan_pair()
1487 if (uc->tchan) { in udma_get_chan_pair()
1488 dev_err(ud->dev, "chan%d: already have tchan%d allocated\n", in udma_get_chan_pair()
1489 uc->id, uc->tchan->id); in udma_get_chan_pair()
1490 return -EBUSY; in udma_get_chan_pair()
1491 } else if (uc->rchan) { in udma_get_chan_pair()
1492 dev_err(ud->dev, "chan%d: already have rchan%d allocated\n", in udma_get_chan_pair()
1493 uc->id, uc->rchan->id); in udma_get_chan_pair()
1494 return -EBUSY; in udma_get_chan_pair()
1498 end = min(ud->tchan_cnt, ud->rchan_cnt); in udma_get_chan_pair()
1501 * Note: in UDMAP the channel TPL is symmetric between tchan and rchan in udma_get_chan_pair()
1503 chan_id = ud->tchan_tpl.start_idx[ud->tchan_tpl.levels - 1]; in udma_get_chan_pair()
1505 if (!test_bit(chan_id, ud->tchan_map) && in udma_get_chan_pair()
1506 !test_bit(chan_id, ud->rchan_map)) in udma_get_chan_pair()
1511 return -ENOENT; in udma_get_chan_pair()
1513 set_bit(chan_id, ud->tchan_map); in udma_get_chan_pair()
1514 set_bit(chan_id, ud->rchan_map); in udma_get_chan_pair()
1515 uc->tchan = &ud->tchans[chan_id]; in udma_get_chan_pair()
1516 uc->rchan = &ud->rchans[chan_id]; in udma_get_chan_pair()
1519 uc->tchan->tflow_id = -1; in udma_get_chan_pair()
1526 struct udma_dev *ud = uc->ud; in udma_get_rflow()
1529 if (!uc->rchan) { in udma_get_rflow()
1530 dev_err(ud->dev, "chan%d: does not have rchan??\n", uc->id); in udma_get_rflow()
1531 return -EINVAL; in udma_get_rflow()
1534 if (uc->rflow) { in udma_get_rflow()
1535 dev_dbg(ud->dev, "chan%d: already have rflow%d allocated\n", in udma_get_rflow()
1536 uc->id, uc->rflow->id); in udma_get_rflow()
1540 uc->rflow = __udma_get_rflow(ud, flow_id); in udma_get_rflow()
1541 if (IS_ERR(uc->rflow)) { in udma_get_rflow()
1542 ret = PTR_ERR(uc->rflow); in udma_get_rflow()
1543 uc->rflow = NULL; in udma_get_rflow()
1552 struct udma_dev *ud = uc->ud; in bcdma_put_bchan()
1554 if (uc->bchan) { in bcdma_put_bchan()
1555 dev_dbg(ud->dev, "chan%d: put bchan%d\n", uc->id, in bcdma_put_bchan()
1556 uc->bchan->id); in bcdma_put_bchan()
1557 clear_bit(uc->bchan->id, ud->bchan_map); in bcdma_put_bchan()
1558 uc->bchan = NULL; in bcdma_put_bchan()
1559 uc->tchan = NULL; in bcdma_put_bchan()
1565 struct udma_dev *ud = uc->ud; in udma_put_rchan()
1567 if (uc->rchan) { in udma_put_rchan()
1568 dev_dbg(ud->dev, "chan%d: put rchan%d\n", uc->id, in udma_put_rchan()
1569 uc->rchan->id); in udma_put_rchan()
1570 clear_bit(uc->rchan->id, ud->rchan_map); in udma_put_rchan()
1571 uc->rchan = NULL; in udma_put_rchan()
1577 struct udma_dev *ud = uc->ud; in udma_put_tchan()
1579 if (uc->tchan) { in udma_put_tchan()
1580 dev_dbg(ud->dev, "chan%d: put tchan%d\n", uc->id, in udma_put_tchan()
1581 uc->tchan->id); in udma_put_tchan()
1582 clear_bit(uc->tchan->id, ud->tchan_map); in udma_put_tchan()
1584 if (uc->tchan->tflow_id >= 0) in udma_put_tchan()
1585 clear_bit(uc->tchan->tflow_id, ud->tflow_map); in udma_put_tchan()
1587 uc->tchan = NULL; in udma_put_tchan()
1593 struct udma_dev *ud = uc->ud; in udma_put_rflow()
1595 if (uc->rflow) { in udma_put_rflow()
1596 dev_dbg(ud->dev, "chan%d: put rflow%d\n", uc->id, in udma_put_rflow()
1597 uc->rflow->id); in udma_put_rflow()
1598 __udma_put_rflow(ud, uc->rflow); in udma_put_rflow()
1599 uc->rflow = NULL; in udma_put_rflow()
1605 if (!uc->bchan) in bcdma_free_bchan_resources()
1608 k3_ringacc_ring_free(uc->bchan->tc_ring); in bcdma_free_bchan_resources()
1609 k3_ringacc_ring_free(uc->bchan->t_ring); in bcdma_free_bchan_resources()
1610 uc->bchan->tc_ring = NULL; in bcdma_free_bchan_resources()
1611 uc->bchan->t_ring = NULL; in bcdma_free_bchan_resources()
1612 k3_configure_chan_coherency(&uc->vc.chan, 0); in bcdma_free_bchan_resources()
1620 struct udma_dev *ud = uc->ud; in bcdma_alloc_bchan_resources()
1627 ret = k3_ringacc_request_rings_pair(ud->ringacc, uc->bchan->id, -1, in bcdma_alloc_bchan_resources()
1628 &uc->bchan->t_ring, in bcdma_alloc_bchan_resources()
1629 &uc->bchan->tc_ring); in bcdma_alloc_bchan_resources()
1631 ret = -EBUSY; in bcdma_alloc_bchan_resources()
1640 k3_configure_chan_coherency(&uc->vc.chan, ud->asel); in bcdma_alloc_bchan_resources()
1641 ring_cfg.asel = ud->asel; in bcdma_alloc_bchan_resources()
1642 ring_cfg.dma_dev = dmaengine_get_dma_device(&uc->vc.chan); in bcdma_alloc_bchan_resources()
1644 ret = k3_ringacc_ring_cfg(uc->bchan->t_ring, &ring_cfg); in bcdma_alloc_bchan_resources()
1651 k3_ringacc_ring_free(uc->bchan->tc_ring); in bcdma_alloc_bchan_resources()
1652 uc->bchan->tc_ring = NULL; in bcdma_alloc_bchan_resources()
1653 k3_ringacc_ring_free(uc->bchan->t_ring); in bcdma_alloc_bchan_resources()
1654 uc->bchan->t_ring = NULL; in bcdma_alloc_bchan_resources()
1655 k3_configure_chan_coherency(&uc->vc.chan, 0); in bcdma_alloc_bchan_resources()
1664 if (!uc->tchan) in udma_free_tx_resources()
1667 k3_ringacc_ring_free(uc->tchan->t_ring); in udma_free_tx_resources()
1668 k3_ringacc_ring_free(uc->tchan->tc_ring); in udma_free_tx_resources()
1669 uc->tchan->t_ring = NULL; in udma_free_tx_resources()
1670 uc->tchan->tc_ring = NULL; in udma_free_tx_resources()
1678 struct udma_dev *ud = uc->ud; in udma_alloc_tx_resources()
1686 tchan = uc->tchan; in udma_alloc_tx_resources()
1687 if (tchan->tflow_id >= 0) in udma_alloc_tx_resources()
1688 ring_idx = tchan->tflow_id; in udma_alloc_tx_resources()
1690 ring_idx = ud->bchan_cnt + tchan->id; in udma_alloc_tx_resources()
1692 ret = k3_ringacc_request_rings_pair(ud->ringacc, ring_idx, -1, in udma_alloc_tx_resources()
1693 &tchan->t_ring, in udma_alloc_tx_resources()
1694 &tchan->tc_ring); in udma_alloc_tx_resources()
1696 ret = -EBUSY; in udma_alloc_tx_resources()
1703 if (ud->match_data->type == DMA_TYPE_UDMA) { in udma_alloc_tx_resources()
1708 k3_configure_chan_coherency(&uc->vc.chan, uc->config.asel); in udma_alloc_tx_resources()
1709 ring_cfg.asel = uc->config.asel; in udma_alloc_tx_resources()
1710 ring_cfg.dma_dev = dmaengine_get_dma_device(&uc->vc.chan); in udma_alloc_tx_resources()
1713 ret = k3_ringacc_ring_cfg(tchan->t_ring, &ring_cfg); in udma_alloc_tx_resources()
1714 ret |= k3_ringacc_ring_cfg(tchan->tc_ring, &ring_cfg); in udma_alloc_tx_resources()
1722 k3_ringacc_ring_free(uc->tchan->tc_ring); in udma_alloc_tx_resources()
1723 uc->tchan->tc_ring = NULL; in udma_alloc_tx_resources()
1724 k3_ringacc_ring_free(uc->tchan->t_ring); in udma_alloc_tx_resources()
1725 uc->tchan->t_ring = NULL; in udma_alloc_tx_resources()
1734 if (!uc->rchan) in udma_free_rx_resources()
1737 if (uc->rflow) { in udma_free_rx_resources()
1738 struct udma_rflow *rflow = uc->rflow; in udma_free_rx_resources()
1740 k3_ringacc_ring_free(rflow->fd_ring); in udma_free_rx_resources()
1741 k3_ringacc_ring_free(rflow->r_ring); in udma_free_rx_resources()
1742 rflow->fd_ring = NULL; in udma_free_rx_resources()
1743 rflow->r_ring = NULL; in udma_free_rx_resources()
1753 struct udma_dev *ud = uc->ud; in udma_alloc_rx_resources()
1764 if (uc->config.dir == DMA_MEM_TO_MEM) in udma_alloc_rx_resources()
1767 if (uc->config.default_flow_id >= 0) in udma_alloc_rx_resources()
1768 ret = udma_get_rflow(uc, uc->config.default_flow_id); in udma_alloc_rx_resources()
1770 ret = udma_get_rflow(uc, uc->rchan->id); in udma_alloc_rx_resources()
1773 ret = -EBUSY; in udma_alloc_rx_resources()
1777 rflow = uc->rflow; in udma_alloc_rx_resources()
1778 if (ud->tflow_cnt) in udma_alloc_rx_resources()
1779 fd_ring_id = ud->tflow_cnt + rflow->id; in udma_alloc_rx_resources()
1781 fd_ring_id = ud->bchan_cnt + ud->tchan_cnt + ud->echan_cnt + in udma_alloc_rx_resources()
1782 uc->rchan->id; in udma_alloc_rx_resources()
1784 ret = k3_ringacc_request_rings_pair(ud->ringacc, fd_ring_id, -1, in udma_alloc_rx_resources()
1785 &rflow->fd_ring, &rflow->r_ring); in udma_alloc_rx_resources()
1787 ret = -EBUSY; in udma_alloc_rx_resources()
1794 if (ud->match_data->type == DMA_TYPE_UDMA) { in udma_alloc_rx_resources()
1795 if (uc->config.pkt_mode) in udma_alloc_rx_resources()
1805 k3_configure_chan_coherency(&uc->vc.chan, uc->config.asel); in udma_alloc_rx_resources()
1806 ring_cfg.asel = uc->config.asel; in udma_alloc_rx_resources()
1807 ring_cfg.dma_dev = dmaengine_get_dma_device(&uc->vc.chan); in udma_alloc_rx_resources()
1810 ret = k3_ringacc_ring_cfg(rflow->fd_ring, &ring_cfg); in udma_alloc_rx_resources()
1813 ret |= k3_ringacc_ring_cfg(rflow->r_ring, &ring_cfg); in udma_alloc_rx_resources()
1821 k3_ringacc_ring_free(rflow->r_ring); in udma_alloc_rx_resources()
1822 rflow->r_ring = NULL; in udma_alloc_rx_resources()
1823 k3_ringacc_ring_free(rflow->fd_ring); in udma_alloc_rx_resources()
1824 rflow->fd_ring = NULL; in udma_alloc_rx_resources()
1867 struct udma_dev *ud = uc->ud; in udma_tisci_m2m_channel_config()
1868 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in udma_tisci_m2m_channel_config()
1869 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in udma_tisci_m2m_channel_config()
1870 struct udma_tchan *tchan = uc->tchan; in udma_tisci_m2m_channel_config()
1871 struct udma_rchan *rchan = uc->rchan; in udma_tisci_m2m_channel_config() local
1876 /* Non synchronized - mem to mem type of transfer */ in udma_tisci_m2m_channel_config()
1877 int tc_ring = k3_ringacc_get_ring_id(tchan->tc_ring); in udma_tisci_m2m_channel_config()
1881 if (ud->match_data->flags & UDMA_FLAG_BURST_SIZE) { in udma_tisci_m2m_channel_config()
1882 tpl = udma_get_chan_tpl_index(&ud->tchan_tpl, tchan->id); in udma_tisci_m2m_channel_config()
1884 burst_size = ud->match_data->burst_size[tpl]; in udma_tisci_m2m_channel_config()
1888 req_tx.nav_id = tisci_rm->tisci_dev_id; in udma_tisci_m2m_channel_config()
1889 req_tx.index = tchan->id; in udma_tisci_m2m_channel_config()
1893 req_tx.tx_atype = ud->atype; in udma_tisci_m2m_channel_config()
1899 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx); in udma_tisci_m2m_channel_config()
1901 dev_err(ud->dev, "tchan%d cfg failed %d\n", tchan->id, ret); in udma_tisci_m2m_channel_config()
1906 req_rx.nav_id = tisci_rm->tisci_dev_id; in udma_tisci_m2m_channel_config()
1907 req_rx.index = rchan->id; in udma_tisci_m2m_channel_config()
1911 req_rx.rx_atype = ud->atype; in udma_tisci_m2m_channel_config()
1917 ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx); in udma_tisci_m2m_channel_config()
1919 dev_err(ud->dev, "rchan%d alloc failed %d\n", rchan->id, ret); in udma_tisci_m2m_channel_config()
1926 struct udma_dev *ud = uc->ud; in bcdma_tisci_m2m_channel_config()
1927 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in bcdma_tisci_m2m_channel_config()
1928 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in bcdma_tisci_m2m_channel_config()
1930 struct udma_bchan *bchan = uc->bchan; in bcdma_tisci_m2m_channel_config()
1935 if (ud->match_data->flags & UDMA_FLAG_BURST_SIZE) { in bcdma_tisci_m2m_channel_config()
1936 tpl = udma_get_chan_tpl_index(&ud->bchan_tpl, bchan->id); in bcdma_tisci_m2m_channel_config()
1938 burst_size = ud->match_data->burst_size[tpl]; in bcdma_tisci_m2m_channel_config()
1942 req_tx.nav_id = tisci_rm->tisci_dev_id; in bcdma_tisci_m2m_channel_config()
1944 req_tx.index = bchan->id; in bcdma_tisci_m2m_channel_config()
1950 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx); in bcdma_tisci_m2m_channel_config()
1952 dev_err(ud->dev, "bchan%d cfg failed %d\n", bchan->id, ret); in bcdma_tisci_m2m_channel_config()
1959 struct udma_dev *ud = uc->ud; in udma_tisci_tx_channel_config()
1960 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in udma_tisci_tx_channel_config()
1961 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in udma_tisci_tx_channel_config()
1962 struct udma_tchan *tchan = uc->tchan; in udma_tisci_tx_channel_config()
1963 int tc_ring = k3_ringacc_get_ring_id(tchan->tc_ring); in udma_tisci_tx_channel_config()
1968 if (uc->config.pkt_mode) { in udma_tisci_tx_channel_config()
1970 fetch_size = cppi5_hdesc_calc_size(uc->config.needs_epib, in udma_tisci_tx_channel_config()
1971 uc->config.psd_size, 0); in udma_tisci_tx_channel_config()
1978 req_tx.nav_id = tisci_rm->tisci_dev_id; in udma_tisci_tx_channel_config()
1979 req_tx.index = tchan->id; in udma_tisci_tx_channel_config()
1981 req_tx.tx_supr_tdpkt = uc->config.notdpkt; in udma_tisci_tx_channel_config()
1984 req_tx.tx_atype = uc->config.atype; in udma_tisci_tx_channel_config()
1985 if (uc->config.ep_type == PSIL_EP_PDMA_XY && in udma_tisci_tx_channel_config()
1986 ud->match_data->flags & UDMA_FLAG_TDTYPE) { in udma_tisci_tx_channel_config()
1993 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx); in udma_tisci_tx_channel_config()
1995 dev_err(ud->dev, "tchan%d cfg failed %d\n", tchan->id, ret); in udma_tisci_tx_channel_config()
2002 struct udma_dev *ud = uc->ud; in bcdma_tisci_tx_channel_config()
2003 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in bcdma_tisci_tx_channel_config()
2004 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in bcdma_tisci_tx_channel_config()
2005 struct udma_tchan *tchan = uc->tchan; in bcdma_tisci_tx_channel_config()
2010 req_tx.nav_id = tisci_rm->tisci_dev_id; in bcdma_tisci_tx_channel_config()
2011 req_tx.index = tchan->id; in bcdma_tisci_tx_channel_config()
2012 req_tx.tx_supr_tdpkt = uc->config.notdpkt; in bcdma_tisci_tx_channel_config()
2013 if (ud->match_data->flags & UDMA_FLAG_TDTYPE) { in bcdma_tisci_tx_channel_config()
2020 ret = tisci_ops->tx_ch_cfg(tisci_rm->tisci, &req_tx); in bcdma_tisci_tx_channel_config()
2022 dev_err(ud->dev, "tchan%d cfg failed %d\n", tchan->id, ret); in bcdma_tisci_tx_channel_config()
2031 struct udma_dev *ud = uc->ud; in udma_tisci_rx_channel_config()
2032 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in udma_tisci_rx_channel_config()
2033 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in udma_tisci_rx_channel_config()
2034 struct udma_rchan *rchan = uc->rchan; in udma_tisci_rx_channel_config() local
2035 int fd_ring = k3_ringacc_get_ring_id(uc->rflow->fd_ring); in udma_tisci_rx_channel_config()
2036 int rx_ring = k3_ringacc_get_ring_id(uc->rflow->r_ring); in udma_tisci_rx_channel_config()
2042 if (uc->config.pkt_mode) { in udma_tisci_rx_channel_config()
2044 fetch_size = cppi5_hdesc_calc_size(uc->config.needs_epib, in udma_tisci_rx_channel_config()
2045 uc->config.psd_size, 0); in udma_tisci_rx_channel_config()
2052 req_rx.nav_id = tisci_rm->tisci_dev_id; in udma_tisci_rx_channel_config()
2053 req_rx.index = rchan->id; in udma_tisci_rx_channel_config()
2057 req_rx.rx_atype = uc->config.atype; in udma_tisci_rx_channel_config()
2059 ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx); in udma_tisci_rx_channel_config()
2061 dev_err(ud->dev, "rchan%d cfg failed %d\n", rchan->id, ret); in udma_tisci_rx_channel_config()
2080 flow_req.nav_id = tisci_rm->tisci_dev_id; in udma_tisci_rx_channel_config()
2081 flow_req.flow_index = rchan->id; in udma_tisci_rx_channel_config()
2083 if (uc->config.needs_epib) in udma_tisci_rx_channel_config()
2087 if (uc->config.psd_size) in udma_tisci_rx_channel_config()
2102 ret = tisci_ops->rx_flow_cfg(tisci_rm->tisci, &flow_req); in udma_tisci_rx_channel_config()
2105 dev_err(ud->dev, "flow%d config failed: %d\n", rchan->id, ret); in udma_tisci_rx_channel_config()
2112 struct udma_dev *ud = uc->ud; in bcdma_tisci_rx_channel_config()
2113 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in bcdma_tisci_rx_channel_config()
2114 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in bcdma_tisci_rx_channel_config()
2115 struct udma_rchan *rchan = uc->rchan; in bcdma_tisci_rx_channel_config() local
2120 req_rx.nav_id = tisci_rm->tisci_dev_id; in bcdma_tisci_rx_channel_config()
2121 req_rx.index = rchan->id; in bcdma_tisci_rx_channel_config()
2123 ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx); in bcdma_tisci_rx_channel_config()
2125 dev_err(ud->dev, "rchan%d cfg failed %d\n", rchan->id, ret); in bcdma_tisci_rx_channel_config()
2132 struct udma_dev *ud = uc->ud; in pktdma_tisci_rx_channel_config()
2133 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in pktdma_tisci_rx_channel_config()
2134 const struct ti_sci_rm_udmap_ops *tisci_ops = tisci_rm->tisci_udmap_ops; in pktdma_tisci_rx_channel_config()
2140 req_rx.nav_id = tisci_rm->tisci_dev_id; in pktdma_tisci_rx_channel_config()
2141 req_rx.index = uc->rchan->id; in pktdma_tisci_rx_channel_config()
2143 ret = tisci_ops->rx_ch_cfg(tisci_rm->tisci, &req_rx); in pktdma_tisci_rx_channel_config()
2145 dev_err(ud->dev, "rchan%d cfg failed %d\n", uc->rchan->id, ret); in pktdma_tisci_rx_channel_config()
2154 flow_req.nav_id = tisci_rm->tisci_dev_id; in pktdma_tisci_rx_channel_config()
2155 flow_req.flow_index = uc->rflow->id; in pktdma_tisci_rx_channel_config()
2157 if (uc->config.needs_epib) in pktdma_tisci_rx_channel_config()
2161 if (uc->config.psd_size) in pktdma_tisci_rx_channel_config()
2167 ret = tisci_ops->rx_flow_cfg(tisci_rm->tisci, &flow_req); in pktdma_tisci_rx_channel_config()
2170 dev_err(ud->dev, "flow%d config failed: %d\n", uc->rflow->id, in pktdma_tisci_rx_channel_config()
2179 struct udma_dev *ud = to_udma_dev(chan->device); in udma_alloc_chan_resources()
2180 const struct udma_soc_data *soc_data = ud->soc_data; in udma_alloc_chan_resources()
2185 uc->dma_dev = ud->dev; in udma_alloc_chan_resources()
2187 if (uc->config.pkt_mode || uc->config.dir == DMA_MEM_TO_MEM) { in udma_alloc_chan_resources()
2188 uc->use_dma_pool = true; in udma_alloc_chan_resources()
2190 if (uc->config.dir == DMA_MEM_TO_MEM) { in udma_alloc_chan_resources()
2191 uc->config.hdesc_size = cppi5_trdesc_calc_size( in udma_alloc_chan_resources()
2193 uc->config.pkt_mode = false; in udma_alloc_chan_resources()
2197 if (uc->use_dma_pool) { in udma_alloc_chan_resources()
2198 uc->hdesc_pool = dma_pool_create(uc->name, ud->ddev.dev, in udma_alloc_chan_resources()
2199 uc->config.hdesc_size, in udma_alloc_chan_resources()
2200 ud->desc_align, in udma_alloc_chan_resources()
2202 if (!uc->hdesc_pool) { in udma_alloc_chan_resources()
2203 dev_err(ud->ddev.dev, in udma_alloc_chan_resources()
2205 uc->use_dma_pool = false; in udma_alloc_chan_resources()
2206 ret = -ENOMEM; in udma_alloc_chan_resources()
2215 reinit_completion(&uc->teardown_completed); in udma_alloc_chan_resources()
2216 complete_all(&uc->teardown_completed); in udma_alloc_chan_resources()
2217 uc->state = UDMA_CHAN_IS_IDLE; in udma_alloc_chan_resources()
2219 switch (uc->config.dir) { in udma_alloc_chan_resources()
2221 /* Non synchronized - mem to mem type of transfer */ in udma_alloc_chan_resources()
2222 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-MEM\n", __func__, in udma_alloc_chan_resources()
2223 uc->id); in udma_alloc_chan_resources()
2241 uc->config.src_thread = ud->psil_base + uc->tchan->id; in udma_alloc_chan_resources()
2242 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | in udma_alloc_chan_resources()
2245 irq_ring = uc->tchan->tc_ring; in udma_alloc_chan_resources()
2246 irq_udma_idx = uc->tchan->id; in udma_alloc_chan_resources()
2251 /* Slave transfer synchronized - mem to dev (TX) trasnfer */ in udma_alloc_chan_resources()
2252 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__, in udma_alloc_chan_resources()
2253 uc->id); in udma_alloc_chan_resources()
2259 uc->config.src_thread = ud->psil_base + uc->tchan->id; in udma_alloc_chan_resources()
2260 uc->config.dst_thread = uc->config.remote_thread_id; in udma_alloc_chan_resources()
2261 uc->config.dst_thread |= K3_PSIL_DST_THREAD_ID_OFFSET; in udma_alloc_chan_resources()
2263 irq_ring = uc->tchan->tc_ring; in udma_alloc_chan_resources()
2264 irq_udma_idx = uc->tchan->id; in udma_alloc_chan_resources()
2269 /* Slave transfer synchronized - dev to mem (RX) trasnfer */ in udma_alloc_chan_resources()
2270 dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__, in udma_alloc_chan_resources()
2271 uc->id); in udma_alloc_chan_resources()
2277 uc->config.src_thread = uc->config.remote_thread_id; in udma_alloc_chan_resources()
2278 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | in udma_alloc_chan_resources()
2281 irq_ring = uc->rflow->r_ring; in udma_alloc_chan_resources()
2282 irq_udma_idx = soc_data->oes.udma_rchan + uc->rchan->id; in udma_alloc_chan_resources()
2288 dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n", in udma_alloc_chan_resources()
2289 __func__, uc->id, uc->config.dir); in udma_alloc_chan_resources()
2290 ret = -EINVAL; in udma_alloc_chan_resources()
2300 dev_warn(ud->dev, "chan%d: is running!\n", uc->id); in udma_alloc_chan_resources()
2303 dev_err(ud->dev, "chan%d: won't stop!\n", uc->id); in udma_alloc_chan_resources()
2304 ret = -EBUSY; in udma_alloc_chan_resources()
2309 /* PSI-L pairing */ in udma_alloc_chan_resources()
2310 ret = navss_psil_pair(ud, uc->config.src_thread, uc->config.dst_thread); in udma_alloc_chan_resources()
2312 dev_err(ud->dev, "PSI-L pairing failed: 0x%04x -> 0x%04x\n", in udma_alloc_chan_resources()
2313 uc->config.src_thread, uc->config.dst_thread); in udma_alloc_chan_resources()
2317 uc->psil_paired = true; in udma_alloc_chan_resources()
2319 uc->irq_num_ring = k3_ringacc_get_ring_irq_num(irq_ring); in udma_alloc_chan_resources()
2320 if (uc->irq_num_ring <= 0) { in udma_alloc_chan_resources()
2321 dev_err(ud->dev, "Failed to get ring irq (index: %u)\n", in udma_alloc_chan_resources()
2323 ret = -EINVAL; in udma_alloc_chan_resources()
2327 ret = request_irq(uc->irq_num_ring, udma_ring_irq_handler, in udma_alloc_chan_resources()
2328 IRQF_TRIGGER_HIGH, uc->name, uc); in udma_alloc_chan_resources()
2330 dev_err(ud->dev, "chan%d: ring irq request failed\n", uc->id); in udma_alloc_chan_resources()
2335 if (is_slave_direction(uc->config.dir) && !uc->config.pkt_mode) { in udma_alloc_chan_resources()
2336 uc->irq_num_udma = msi_get_virq(ud->dev, irq_udma_idx); in udma_alloc_chan_resources()
2337 if (uc->irq_num_udma <= 0) { in udma_alloc_chan_resources()
2338 dev_err(ud->dev, "Failed to get udma irq (index: %u)\n", in udma_alloc_chan_resources()
2340 free_irq(uc->irq_num_ring, uc); in udma_alloc_chan_resources()
2341 ret = -EINVAL; in udma_alloc_chan_resources()
2345 ret = request_irq(uc->irq_num_udma, udma_udma_irq_handler, 0, in udma_alloc_chan_resources()
2346 uc->name, uc); in udma_alloc_chan_resources()
2348 dev_err(ud->dev, "chan%d: UDMA irq request failed\n", in udma_alloc_chan_resources()
2349 uc->id); in udma_alloc_chan_resources()
2350 free_irq(uc->irq_num_ring, uc); in udma_alloc_chan_resources()
2354 uc->irq_num_udma = 0; in udma_alloc_chan_resources()
2362 uc->irq_num_ring = 0; in udma_alloc_chan_resources()
2363 uc->irq_num_udma = 0; in udma_alloc_chan_resources()
2365 navss_psil_unpair(ud, uc->config.src_thread, uc->config.dst_thread); in udma_alloc_chan_resources()
2366 uc->psil_paired = false; in udma_alloc_chan_resources()
2373 if (uc->use_dma_pool) { in udma_alloc_chan_resources()
2374 dma_pool_destroy(uc->hdesc_pool); in udma_alloc_chan_resources()
2375 uc->use_dma_pool = false; in udma_alloc_chan_resources()
2384 struct udma_dev *ud = to_udma_dev(chan->device); in bcdma_alloc_chan_resources()
2385 const struct udma_oes_offsets *oes = &ud->soc_data->oes; in bcdma_alloc_chan_resources()
2390 uc->config.pkt_mode = false; in bcdma_alloc_chan_resources()
2396 reinit_completion(&uc->teardown_completed); in bcdma_alloc_chan_resources()
2397 complete_all(&uc->teardown_completed); in bcdma_alloc_chan_resources()
2398 uc->state = UDMA_CHAN_IS_IDLE; in bcdma_alloc_chan_resources()
2400 switch (uc->config.dir) { in bcdma_alloc_chan_resources()
2402 /* Non synchronized - mem to mem type of transfer */ in bcdma_alloc_chan_resources()
2403 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-MEM\n", __func__, in bcdma_alloc_chan_resources()
2404 uc->id); in bcdma_alloc_chan_resources()
2410 irq_ring_idx = uc->bchan->id + oes->bcdma_bchan_ring; in bcdma_alloc_chan_resources()
2411 irq_udma_idx = uc->bchan->id + oes->bcdma_bchan_data; in bcdma_alloc_chan_resources()
2416 /* Slave transfer synchronized - mem to dev (TX) trasnfer */ in bcdma_alloc_chan_resources()
2417 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__, in bcdma_alloc_chan_resources()
2418 uc->id); in bcdma_alloc_chan_resources()
2422 uc->config.remote_thread_id = -1; in bcdma_alloc_chan_resources()
2426 uc->config.src_thread = ud->psil_base + uc->tchan->id; in bcdma_alloc_chan_resources()
2427 uc->config.dst_thread = uc->config.remote_thread_id; in bcdma_alloc_chan_resources()
2428 uc->config.dst_thread |= K3_PSIL_DST_THREAD_ID_OFFSET; in bcdma_alloc_chan_resources()
2430 irq_ring_idx = uc->tchan->id + oes->bcdma_tchan_ring; in bcdma_alloc_chan_resources()
2431 irq_udma_idx = uc->tchan->id + oes->bcdma_tchan_data; in bcdma_alloc_chan_resources()
2436 /* Slave transfer synchronized - dev to mem (RX) trasnfer */ in bcdma_alloc_chan_resources()
2437 dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__, in bcdma_alloc_chan_resources()
2438 uc->id); in bcdma_alloc_chan_resources()
2442 uc->config.remote_thread_id = -1; in bcdma_alloc_chan_resources()
2446 uc->config.src_thread = uc->config.remote_thread_id; in bcdma_alloc_chan_resources()
2447 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | in bcdma_alloc_chan_resources()
2450 irq_ring_idx = uc->rchan->id + oes->bcdma_rchan_ring; in bcdma_alloc_chan_resources()
2451 irq_udma_idx = uc->rchan->id + oes->bcdma_rchan_data; in bcdma_alloc_chan_resources()
2457 dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n", in bcdma_alloc_chan_resources()
2458 __func__, uc->id, uc->config.dir); in bcdma_alloc_chan_resources()
2459 return -EINVAL; in bcdma_alloc_chan_resources()
2467 dev_warn(ud->dev, "chan%d: is running!\n", uc->id); in bcdma_alloc_chan_resources()
2470 dev_err(ud->dev, "chan%d: won't stop!\n", uc->id); in bcdma_alloc_chan_resources()
2471 ret = -EBUSY; in bcdma_alloc_chan_resources()
2476 uc->dma_dev = dmaengine_get_dma_device(chan); in bcdma_alloc_chan_resources()
2477 if (uc->config.dir == DMA_MEM_TO_MEM && !uc->config.tr_trigger_type) { in bcdma_alloc_chan_resources()
2478 uc->config.hdesc_size = cppi5_trdesc_calc_size( in bcdma_alloc_chan_resources()
2481 uc->hdesc_pool = dma_pool_create(uc->name, ud->ddev.dev, in bcdma_alloc_chan_resources()
2482 uc->config.hdesc_size, in bcdma_alloc_chan_resources()
2483 ud->desc_align, in bcdma_alloc_chan_resources()
2485 if (!uc->hdesc_pool) { in bcdma_alloc_chan_resources()
2486 dev_err(ud->ddev.dev, in bcdma_alloc_chan_resources()
2488 uc->use_dma_pool = false; in bcdma_alloc_chan_resources()
2489 ret = -ENOMEM; in bcdma_alloc_chan_resources()
2493 uc->use_dma_pool = true; in bcdma_alloc_chan_resources()
2494 } else if (uc->config.dir != DMA_MEM_TO_MEM) { in bcdma_alloc_chan_resources()
2495 /* PSI-L pairing */ in bcdma_alloc_chan_resources()
2496 ret = navss_psil_pair(ud, uc->config.src_thread, in bcdma_alloc_chan_resources()
2497 uc->config.dst_thread); in bcdma_alloc_chan_resources()
2499 dev_err(ud->dev, in bcdma_alloc_chan_resources()
2500 "PSI-L pairing failed: 0x%04x -> 0x%04x\n", in bcdma_alloc_chan_resources()
2501 uc->config.src_thread, uc->config.dst_thread); in bcdma_alloc_chan_resources()
2505 uc->psil_paired = true; in bcdma_alloc_chan_resources()
2508 uc->irq_num_ring = msi_get_virq(ud->dev, irq_ring_idx); in bcdma_alloc_chan_resources()
2509 if (uc->irq_num_ring <= 0) { in bcdma_alloc_chan_resources()
2510 dev_err(ud->dev, "Failed to get ring irq (index: %u)\n", in bcdma_alloc_chan_resources()
2512 ret = -EINVAL; in bcdma_alloc_chan_resources()
2516 ret = request_irq(uc->irq_num_ring, udma_ring_irq_handler, in bcdma_alloc_chan_resources()
2517 IRQF_TRIGGER_HIGH, uc->name, uc); in bcdma_alloc_chan_resources()
2519 dev_err(ud->dev, "chan%d: ring irq request failed\n", uc->id); in bcdma_alloc_chan_resources()
2524 if (is_slave_direction(uc->config.dir)) { in bcdma_alloc_chan_resources()
2525 uc->irq_num_udma = msi_get_virq(ud->dev, irq_udma_idx); in bcdma_alloc_chan_resources()
2526 if (uc->irq_num_udma <= 0) { in bcdma_alloc_chan_resources()
2527 dev_err(ud->dev, "Failed to get bcdma irq (index: %u)\n", in bcdma_alloc_chan_resources()
2529 free_irq(uc->irq_num_ring, uc); in bcdma_alloc_chan_resources()
2530 ret = -EINVAL; in bcdma_alloc_chan_resources()
2534 ret = request_irq(uc->irq_num_udma, udma_udma_irq_handler, 0, in bcdma_alloc_chan_resources()
2535 uc->name, uc); in bcdma_alloc_chan_resources()
2537 dev_err(ud->dev, "chan%d: BCDMA irq request failed\n", in bcdma_alloc_chan_resources()
2538 uc->id); in bcdma_alloc_chan_resources()
2539 free_irq(uc->irq_num_ring, uc); in bcdma_alloc_chan_resources()
2543 uc->irq_num_udma = 0; in bcdma_alloc_chan_resources()
2548 INIT_DELAYED_WORK_ONSTACK(&uc->tx_drain.work, in bcdma_alloc_chan_resources()
2553 uc->irq_num_ring = 0; in bcdma_alloc_chan_resources()
2554 uc->irq_num_udma = 0; in bcdma_alloc_chan_resources()
2556 if (uc->psil_paired) in bcdma_alloc_chan_resources()
2557 navss_psil_unpair(ud, uc->config.src_thread, in bcdma_alloc_chan_resources()
2558 uc->config.dst_thread); in bcdma_alloc_chan_resources()
2559 uc->psil_paired = false; in bcdma_alloc_chan_resources()
2567 if (uc->use_dma_pool) { in bcdma_alloc_chan_resources()
2568 dma_pool_destroy(uc->hdesc_pool); in bcdma_alloc_chan_resources()
2569 uc->use_dma_pool = false; in bcdma_alloc_chan_resources()
2577 struct k3_event_route_data *router_data = chan->route_data; in bcdma_router_config()
2581 if (!uc->bchan) in bcdma_router_config()
2582 return -EINVAL; in bcdma_router_config()
2584 if (uc->config.tr_trigger_type != 1 && uc->config.tr_trigger_type != 2) in bcdma_router_config()
2585 return -EINVAL; in bcdma_router_config()
2587 trigger_event = uc->ud->soc_data->bcdma_trigger_event_offset; in bcdma_router_config()
2588 trigger_event += (uc->bchan->id * 2) + uc->config.tr_trigger_type - 1; in bcdma_router_config()
2590 return router_data->set_event(router_data->priv, trigger_event); in bcdma_router_config()
2596 struct udma_dev *ud = to_udma_dev(chan->device); in pktdma_alloc_chan_resources()
2597 const struct udma_oes_offsets *oes = &ud->soc_data->oes; in pktdma_alloc_chan_resources()
2605 reinit_completion(&uc->teardown_completed); in pktdma_alloc_chan_resources()
2606 complete_all(&uc->teardown_completed); in pktdma_alloc_chan_resources()
2607 uc->state = UDMA_CHAN_IS_IDLE; in pktdma_alloc_chan_resources()
2609 switch (uc->config.dir) { in pktdma_alloc_chan_resources()
2611 /* Slave transfer synchronized - mem to dev (TX) trasnfer */ in pktdma_alloc_chan_resources()
2612 dev_dbg(uc->ud->dev, "%s: chan%d as MEM-to-DEV\n", __func__, in pktdma_alloc_chan_resources()
2613 uc->id); in pktdma_alloc_chan_resources()
2617 uc->config.remote_thread_id = -1; in pktdma_alloc_chan_resources()
2621 uc->config.src_thread = ud->psil_base + uc->tchan->id; in pktdma_alloc_chan_resources()
2622 uc->config.dst_thread = uc->config.remote_thread_id; in pktdma_alloc_chan_resources()
2623 uc->config.dst_thread |= K3_PSIL_DST_THREAD_ID_OFFSET; in pktdma_alloc_chan_resources()
2625 irq_ring_idx = uc->tchan->tflow_id + oes->pktdma_tchan_flow; in pktdma_alloc_chan_resources()
2630 /* Slave transfer synchronized - dev to mem (RX) trasnfer */ in pktdma_alloc_chan_resources()
2631 dev_dbg(uc->ud->dev, "%s: chan%d as DEV-to-MEM\n", __func__, in pktdma_alloc_chan_resources()
2632 uc->id); in pktdma_alloc_chan_resources()
2636 uc->config.remote_thread_id = -1; in pktdma_alloc_chan_resources()
2640 uc->config.src_thread = uc->config.remote_thread_id; in pktdma_alloc_chan_resources()
2641 uc->config.dst_thread = (ud->psil_base + uc->rchan->id) | in pktdma_alloc_chan_resources()
2644 irq_ring_idx = uc->rflow->id + oes->pktdma_rchan_flow; in pktdma_alloc_chan_resources()
2650 dev_err(uc->ud->dev, "%s: chan%d invalid direction (%u)\n", in pktdma_alloc_chan_resources()
2651 __func__, uc->id, uc->config.dir); in pktdma_alloc_chan_resources()
2652 return -EINVAL; in pktdma_alloc_chan_resources()
2660 dev_warn(ud->dev, "chan%d: is running!\n", uc->id); in pktdma_alloc_chan_resources()
2663 dev_err(ud->dev, "chan%d: won't stop!\n", uc->id); in pktdma_alloc_chan_resources()
2664 ret = -EBUSY; in pktdma_alloc_chan_resources()
2669 uc->dma_dev = dmaengine_get_dma_device(chan); in pktdma_alloc_chan_resources()
2670 uc->hdesc_pool = dma_pool_create(uc->name, uc->dma_dev, in pktdma_alloc_chan_resources()
2671 uc->config.hdesc_size, ud->desc_align, in pktdma_alloc_chan_resources()
2673 if (!uc->hdesc_pool) { in pktdma_alloc_chan_resources()
2674 dev_err(ud->ddev.dev, in pktdma_alloc_chan_resources()
2676 uc->use_dma_pool = false; in pktdma_alloc_chan_resources()
2677 ret = -ENOMEM; in pktdma_alloc_chan_resources()
2681 uc->use_dma_pool = true; in pktdma_alloc_chan_resources()
2683 /* PSI-L pairing */ in pktdma_alloc_chan_resources()
2684 ret = navss_psil_pair(ud, uc->config.src_thread, uc->config.dst_thread); in pktdma_alloc_chan_resources()
2686 dev_err(ud->dev, "PSI-L pairing failed: 0x%04x -> 0x%04x\n", in pktdma_alloc_chan_resources()
2687 uc->config.src_thread, uc->config.dst_thread); in pktdma_alloc_chan_resources()
2691 uc->psil_paired = true; in pktdma_alloc_chan_resources()
2693 uc->irq_num_ring = msi_get_virq(ud->dev, irq_ring_idx); in pktdma_alloc_chan_resources()
2694 if (uc->irq_num_ring <= 0) { in pktdma_alloc_chan_resources()
2695 dev_err(ud->dev, "Failed to get ring irq (index: %u)\n", in pktdma_alloc_chan_resources()
2697 ret = -EINVAL; in pktdma_alloc_chan_resources()
2701 ret = request_irq(uc->irq_num_ring, udma_ring_irq_handler, in pktdma_alloc_chan_resources()
2702 IRQF_TRIGGER_HIGH, uc->name, uc); in pktdma_alloc_chan_resources()
2704 dev_err(ud->dev, "chan%d: ring irq request failed\n", uc->id); in pktdma_alloc_chan_resources()
2708 uc->irq_num_udma = 0; in pktdma_alloc_chan_resources()
2712 INIT_DELAYED_WORK_ONSTACK(&uc->tx_drain.work, in pktdma_alloc_chan_resources()
2715 if (uc->tchan) in pktdma_alloc_chan_resources()
2716 dev_dbg(ud->dev, in pktdma_alloc_chan_resources()
2718 uc->id, uc->tchan->id, uc->tchan->tflow_id, in pktdma_alloc_chan_resources()
2719 uc->config.remote_thread_id); in pktdma_alloc_chan_resources()
2720 else if (uc->rchan) in pktdma_alloc_chan_resources()
2721 dev_dbg(ud->dev, in pktdma_alloc_chan_resources()
2722 "chan%d: rchan%d, rflow%d, Remote thread: 0x%04x\n", in pktdma_alloc_chan_resources()
2723 uc->id, uc->rchan->id, uc->rflow->id, in pktdma_alloc_chan_resources()
2724 uc->config.remote_thread_id); in pktdma_alloc_chan_resources()
2728 uc->irq_num_ring = 0; in pktdma_alloc_chan_resources()
2730 navss_psil_unpair(ud, uc->config.src_thread, uc->config.dst_thread); in pktdma_alloc_chan_resources()
2731 uc->psil_paired = false; in pktdma_alloc_chan_resources()
2738 dma_pool_destroy(uc->hdesc_pool); in pktdma_alloc_chan_resources()
2739 uc->use_dma_pool = false; in pktdma_alloc_chan_resources()
2749 memcpy(&uc->cfg, cfg, sizeof(uc->cfg)); in udma_slave_config()
2771 dev_err(uc->ud->dev, "Unsupported TR size of %zu\n", tr_size); in udma_alloc_tr_desc()
2776 d = kzalloc(sizeof(*d) + sizeof(d->hwdesc[0]), GFP_NOWAIT); in udma_alloc_tr_desc()
2780 d->sglen = tr_count; in udma_alloc_tr_desc()
2782 d->hwdesc_count = 1; in udma_alloc_tr_desc()
2783 hwdesc = &d->hwdesc[0]; in udma_alloc_tr_desc()
2786 if (uc->use_dma_pool) { in udma_alloc_tr_desc()
2787 hwdesc->cppi5_desc_size = uc->config.hdesc_size; in udma_alloc_tr_desc()
2788 hwdesc->cppi5_desc_vaddr = dma_pool_zalloc(uc->hdesc_pool, in udma_alloc_tr_desc()
2790 &hwdesc->cppi5_desc_paddr); in udma_alloc_tr_desc()
2792 hwdesc->cppi5_desc_size = cppi5_trdesc_calc_size(tr_size, in udma_alloc_tr_desc()
2794 hwdesc->cppi5_desc_size = ALIGN(hwdesc->cppi5_desc_size, in udma_alloc_tr_desc()
2795 uc->ud->desc_align); in udma_alloc_tr_desc()
2796 hwdesc->cppi5_desc_vaddr = dma_alloc_coherent(uc->ud->dev, in udma_alloc_tr_desc()
2797 hwdesc->cppi5_desc_size, in udma_alloc_tr_desc()
2798 &hwdesc->cppi5_desc_paddr, in udma_alloc_tr_desc()
2802 if (!hwdesc->cppi5_desc_vaddr) { in udma_alloc_tr_desc()
2808 hwdesc->tr_req_base = hwdesc->cppi5_desc_vaddr + tr_size; in udma_alloc_tr_desc()
2810 hwdesc->tr_resp_base = hwdesc->tr_req_base + tr_size * tr_count; in udma_alloc_tr_desc()
2812 tr_desc = hwdesc->cppi5_desc_vaddr; in udma_alloc_tr_desc()
2814 if (uc->cyclic) in udma_alloc_tr_desc()
2818 ring_id = k3_ringacc_get_ring_id(uc->rflow->r_ring); in udma_alloc_tr_desc()
2820 ring_id = k3_ringacc_get_ring_id(uc->tchan->tc_ring); in udma_alloc_tr_desc()
2823 cppi5_desc_set_pktids(tr_desc, uc->id, in udma_alloc_tr_desc()
2831 * udma_get_tr_counters - calculate TR counters for a given length
2840 * First TR: SZ_64K-alignment blocks (tr0_cnt0, tr0_cnt1)
2844 * -EINVAL if the length can not be supported
2860 *tr0_cnt0 = SZ_64K - BIT(align_to); in udma_get_tr_counters()
2863 align_to--; in udma_get_tr_counters()
2866 return -EINVAL; in udma_get_tr_counters()
2904 d->sglen = sglen; in udma_prep_slave_sg_tr()
2906 if (uc->ud->match_data->type == DMA_TYPE_UDMA) in udma_prep_slave_sg_tr()
2909 asel = (u64)uc->config.asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_slave_sg_tr()
2911 tr_req = d->hwdesc[0].tr_req_base; in udma_prep_slave_sg_tr()
2918 dev_err(uc->ud->dev, "size %u is not supported\n", in udma_prep_slave_sg_tr()
2950 d->residue += sg_dma_len(sgent); in udma_prep_slave_sg_tr()
2953 cppi5_tr_csf_set(&tr_req[tr_idx - 1].flags, in udma_prep_slave_sg_tr()
2980 dev_addr = uc->cfg.src_addr; in udma_prep_slave_sg_triggered_tr()
2981 dev_width = uc->cfg.src_addr_width; in udma_prep_slave_sg_triggered_tr()
2982 burst = uc->cfg.src_maxburst; in udma_prep_slave_sg_triggered_tr()
2983 port_window = uc->cfg.src_port_window_size; in udma_prep_slave_sg_triggered_tr()
2985 dev_addr = uc->cfg.dst_addr; in udma_prep_slave_sg_triggered_tr()
2986 dev_width = uc->cfg.dst_addr_width; in udma_prep_slave_sg_triggered_tr()
2987 burst = uc->cfg.dst_maxburst; in udma_prep_slave_sg_triggered_tr()
2988 port_window = uc->cfg.dst_port_window_size; in udma_prep_slave_sg_triggered_tr()
2990 dev_err(uc->ud->dev, "%s: bad direction?\n", __func__); in udma_prep_slave_sg_triggered_tr()
2999 dev_err(uc->ud->dev, in udma_prep_slave_sg_triggered_tr()
3017 dev_err(uc->ud->dev, in udma_prep_slave_sg_triggered_tr()
3035 d->sglen = sglen; in udma_prep_slave_sg_triggered_tr()
3037 if (uc->ud->match_data->type == DMA_TYPE_UDMA) { in udma_prep_slave_sg_triggered_tr()
3041 asel = (u64)uc->config.asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_slave_sg_triggered_tr()
3045 tr_req = d->hwdesc[0].tr_req_base; in udma_prep_slave_sg_triggered_tr()
3054 dev_err(uc->ud->dev, "size %zu is not supported\n", in udma_prep_slave_sg_triggered_tr()
3065 uc->config.tr_trigger_type, in udma_prep_slave_sg_triggered_tr()
3075 tr_req[tr_idx].dim1 = (-1) * tr_cnt0; in udma_prep_slave_sg_triggered_tr()
3100 tr_req[tr_idx].ddim1 = (-1) * tr_cnt0; in udma_prep_slave_sg_triggered_tr()
3111 uc->config.tr_trigger_type, in udma_prep_slave_sg_triggered_tr()
3122 tr_req[tr_idx].dim1 = (-1) * tr_cnt0; in udma_prep_slave_sg_triggered_tr()
3145 tr_req[tr_idx].ddim1 = (-1) * tr_cnt0; in udma_prep_slave_sg_triggered_tr()
3150 d->residue += sg_len; in udma_prep_slave_sg_triggered_tr()
3153 cppi5_tr_csf_set(&tr_req[tr_idx - 1].flags, csf | CPPI5_TR_CSF_EOP); in udma_prep_slave_sg_triggered_tr()
3162 if (uc->config.ep_type != PSIL_EP_PDMA_XY) in udma_configure_statictr()
3168 d->static_tr.elsize = 0; in udma_configure_statictr()
3171 d->static_tr.elsize = 1; in udma_configure_statictr()
3174 d->static_tr.elsize = 2; in udma_configure_statictr()
3177 d->static_tr.elsize = 3; in udma_configure_statictr()
3180 d->static_tr.elsize = 4; in udma_configure_statictr()
3183 return -EINVAL; in udma_configure_statictr()
3186 d->static_tr.elcnt = elcnt; in udma_configure_statictr()
3194 if (uc->config.pkt_mode || !uc->cyclic) { in udma_configure_statictr()
3197 if (uc->cyclic) in udma_configure_statictr()
3198 d->static_tr.bstcnt = d->residue / d->sglen / div; in udma_configure_statictr()
3200 d->static_tr.bstcnt = d->residue / div; in udma_configure_statictr()
3202 if (uc->config.dir == DMA_DEV_TO_MEM && in udma_configure_statictr()
3203 d->static_tr.bstcnt > uc->ud->match_data->statictr_z_mask) in udma_configure_statictr()
3204 return -EINVAL; in udma_configure_statictr()
3206 d->static_tr.bstcnt = 0; in udma_configure_statictr()
3228 d->sglen = sglen; in udma_prep_slave_sg_pkt()
3229 d->hwdesc_count = sglen; in udma_prep_slave_sg_pkt()
3232 ring_id = k3_ringacc_get_ring_id(uc->rflow->r_ring); in udma_prep_slave_sg_pkt()
3234 ring_id = k3_ringacc_get_ring_id(uc->tchan->tc_ring); in udma_prep_slave_sg_pkt()
3236 if (uc->ud->match_data->type == DMA_TYPE_UDMA) in udma_prep_slave_sg_pkt()
3239 asel = (u64)uc->config.asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_slave_sg_pkt()
3242 struct udma_hwdesc *hwdesc = &d->hwdesc[i]; in udma_prep_slave_sg_pkt()
3247 hwdesc->cppi5_desc_vaddr = dma_pool_zalloc(uc->hdesc_pool, in udma_prep_slave_sg_pkt()
3249 &hwdesc->cppi5_desc_paddr); in udma_prep_slave_sg_pkt()
3250 if (!hwdesc->cppi5_desc_vaddr) { in udma_prep_slave_sg_pkt()
3251 dev_err(uc->ud->dev, in udma_prep_slave_sg_pkt()
3259 d->residue += sg_len; in udma_prep_slave_sg_pkt()
3260 hwdesc->cppi5_desc_size = uc->config.hdesc_size; in udma_prep_slave_sg_pkt()
3261 desc = hwdesc->cppi5_desc_vaddr; in udma_prep_slave_sg_pkt()
3266 cppi5_desc_set_pktids(&desc->hdr, uc->id, in udma_prep_slave_sg_pkt()
3268 cppi5_desc_set_retpolicy(&desc->hdr, 0, ring_id); in udma_prep_slave_sg_pkt()
3271 cppi5_desc_set_retpolicy(&desc->hdr, 0, 0xffff); in udma_prep_slave_sg_pkt()
3281 hwdesc->cppi5_desc_paddr | asel); in udma_prep_slave_sg_pkt()
3283 if (uc->ud->match_data->type == DMA_TYPE_PKTDMA || in udma_prep_slave_sg_pkt()
3288 if (d->residue >= SZ_4M) { in udma_prep_slave_sg_pkt()
3289 dev_err(uc->ud->dev, in udma_prep_slave_sg_pkt()
3290 "%s: Transfer size %u is over the supported 4M range\n", in udma_prep_slave_sg_pkt()
3291 __func__, d->residue); in udma_prep_slave_sg_pkt()
3297 h_desc = d->hwdesc[0].cppi5_desc_vaddr; in udma_prep_slave_sg_pkt()
3298 cppi5_hdesc_set_pktlen(h_desc, d->residue); in udma_prep_slave_sg_pkt()
3307 struct udma_chan *uc = to_udma_chan(desc->chan); in udma_attach_metadata()
3312 if (!uc->config.pkt_mode || !uc->config.metadata_size) in udma_attach_metadata()
3313 return -ENOTSUPP; in udma_attach_metadata()
3315 if (!data || len > uc->config.metadata_size) in udma_attach_metadata()
3316 return -EINVAL; in udma_attach_metadata()
3318 if (uc->config.needs_epib && len < CPPI5_INFO0_HDESC_EPIB_SIZE) in udma_attach_metadata()
3319 return -EINVAL; in udma_attach_metadata()
3321 h_desc = d->hwdesc[0].cppi5_desc_vaddr; in udma_attach_metadata()
3322 if (d->dir == DMA_MEM_TO_DEV) in udma_attach_metadata()
3323 memcpy(h_desc->epib, data, len); in udma_attach_metadata()
3325 if (uc->config.needs_epib) in udma_attach_metadata()
3326 psd_size -= CPPI5_INFO0_HDESC_EPIB_SIZE; in udma_attach_metadata()
3328 d->metadata = data; in udma_attach_metadata()
3329 d->metadata_size = len; in udma_attach_metadata()
3330 if (uc->config.needs_epib) in udma_attach_metadata()
3343 struct udma_chan *uc = to_udma_chan(desc->chan); in udma_get_metadata_ptr()
3346 if (!uc->config.pkt_mode || !uc->config.metadata_size) in udma_get_metadata_ptr()
3347 return ERR_PTR(-ENOTSUPP); in udma_get_metadata_ptr()
3349 h_desc = d->hwdesc[0].cppi5_desc_vaddr; in udma_get_metadata_ptr()
3351 *max_len = uc->config.metadata_size; in udma_get_metadata_ptr()
3353 *payload_len = cppi5_hdesc_epib_present(&h_desc->hdr) ? in udma_get_metadata_ptr()
3357 return h_desc->epib; in udma_get_metadata_ptr()
3364 struct udma_chan *uc = to_udma_chan(desc->chan); in udma_set_metadata_len()
3369 if (!uc->config.pkt_mode || !uc->config.metadata_size) in udma_set_metadata_len()
3370 return -ENOTSUPP; in udma_set_metadata_len()
3372 if (payload_len > uc->config.metadata_size) in udma_set_metadata_len()
3373 return -EINVAL; in udma_set_metadata_len()
3375 if (uc->config.needs_epib && payload_len < CPPI5_INFO0_HDESC_EPIB_SIZE) in udma_set_metadata_len()
3376 return -EINVAL; in udma_set_metadata_len()
3378 h_desc = d->hwdesc[0].cppi5_desc_vaddr; in udma_set_metadata_len()
3380 if (uc->config.needs_epib) { in udma_set_metadata_len()
3381 psd_size -= CPPI5_INFO0_HDESC_EPIB_SIZE; in udma_set_metadata_len()
3407 if (dir != uc->config.dir && in udma_prep_slave_sg()
3408 (uc->config.dir == DMA_MEM_TO_MEM && !uc->config.tr_trigger_type)) { in udma_prep_slave_sg()
3409 dev_err(chan->device->dev, in udma_prep_slave_sg()
3411 __func__, uc->id, in udma_prep_slave_sg()
3412 dmaengine_get_direction_text(uc->config.dir), in udma_prep_slave_sg()
3418 dev_width = uc->cfg.src_addr_width; in udma_prep_slave_sg()
3419 burst = uc->cfg.src_maxburst; in udma_prep_slave_sg()
3421 dev_width = uc->cfg.dst_addr_width; in udma_prep_slave_sg()
3422 burst = uc->cfg.dst_maxburst; in udma_prep_slave_sg()
3424 dev_err(chan->device->dev, "%s: bad direction?\n", __func__); in udma_prep_slave_sg()
3431 uc->config.tx_flags = tx_flags; in udma_prep_slave_sg()
3433 if (uc->config.pkt_mode) in udma_prep_slave_sg()
3436 else if (is_slave_direction(uc->config.dir)) in udma_prep_slave_sg()
3446 d->dir = dir; in udma_prep_slave_sg()
3447 d->desc_idx = 0; in udma_prep_slave_sg()
3448 d->tr_idx = 0; in udma_prep_slave_sg()
3452 dev_err(uc->ud->dev, in udma_prep_slave_sg()
3454 __func__, d->static_tr.bstcnt); in udma_prep_slave_sg()
3461 if (uc->config.metadata_size) in udma_prep_slave_sg()
3462 d->vd.tx.metadata_ops = &metadata_ops; in udma_prep_slave_sg()
3464 return vchan_tx_prep(&uc->vc, &d->vd, tx_flags); in udma_prep_slave_sg()
3483 dev_err(uc->ud->dev, "size %zu is not supported\n", in udma_prep_dma_cyclic_tr()
3494 tr_req = d->hwdesc[0].tr_req_base; in udma_prep_dma_cyclic_tr()
3495 if (uc->ud->match_data->type == DMA_TYPE_UDMA) in udma_prep_dma_cyclic_tr()
3499 ((u64)uc->config.asel << K3_ADDRESS_ASEL_SHIFT); in udma_prep_dma_cyclic_tr()
3547 if (periods > (K3_UDMA_DEFAULT_RING_SIZE - 1)) in udma_prep_dma_cyclic_pkt()
3557 d->hwdesc_count = periods; in udma_prep_dma_cyclic_pkt()
3559 /* TODO: re-check this... */ in udma_prep_dma_cyclic_pkt()
3561 ring_id = k3_ringacc_get_ring_id(uc->rflow->r_ring); in udma_prep_dma_cyclic_pkt()
3563 ring_id = k3_ringacc_get_ring_id(uc->tchan->tc_ring); in udma_prep_dma_cyclic_pkt()
3565 if (uc->ud->match_data->type != DMA_TYPE_UDMA) in udma_prep_dma_cyclic_pkt()
3566 buf_addr |= (u64)uc->config.asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_dma_cyclic_pkt()
3569 struct udma_hwdesc *hwdesc = &d->hwdesc[i]; in udma_prep_dma_cyclic_pkt()
3573 hwdesc->cppi5_desc_vaddr = dma_pool_zalloc(uc->hdesc_pool, in udma_prep_dma_cyclic_pkt()
3575 &hwdesc->cppi5_desc_paddr); in udma_prep_dma_cyclic_pkt()
3576 if (!hwdesc->cppi5_desc_vaddr) { in udma_prep_dma_cyclic_pkt()
3577 dev_err(uc->ud->dev, in udma_prep_dma_cyclic_pkt()
3585 hwdesc->cppi5_desc_size = uc->config.hdesc_size; in udma_prep_dma_cyclic_pkt()
3586 h_desc = hwdesc->cppi5_desc_vaddr; in udma_prep_dma_cyclic_pkt()
3592 cppi5_desc_set_pktids(&h_desc->hdr, uc->id, in udma_prep_dma_cyclic_pkt()
3594 cppi5_desc_set_retpolicy(&h_desc->hdr, 0, ring_id); in udma_prep_dma_cyclic_pkt()
3615 if (dir != uc->config.dir) { in udma_prep_dma_cyclic()
3616 dev_err(chan->device->dev, in udma_prep_dma_cyclic()
3618 __func__, uc->id, in udma_prep_dma_cyclic()
3619 dmaengine_get_direction_text(uc->config.dir), in udma_prep_dma_cyclic()
3624 uc->cyclic = true; in udma_prep_dma_cyclic()
3627 dev_width = uc->cfg.src_addr_width; in udma_prep_dma_cyclic()
3628 burst = uc->cfg.src_maxburst; in udma_prep_dma_cyclic()
3630 dev_width = uc->cfg.dst_addr_width; in udma_prep_dma_cyclic()
3631 burst = uc->cfg.dst_maxburst; in udma_prep_dma_cyclic()
3633 dev_err(uc->ud->dev, "%s: bad direction?\n", __func__); in udma_prep_dma_cyclic()
3640 if (uc->config.pkt_mode) in udma_prep_dma_cyclic()
3650 d->sglen = buf_len / period_len; in udma_prep_dma_cyclic()
3652 d->dir = dir; in udma_prep_dma_cyclic()
3653 d->residue = buf_len; in udma_prep_dma_cyclic()
3657 dev_err(uc->ud->dev, in udma_prep_dma_cyclic()
3659 __func__, d->static_tr.bstcnt); in udma_prep_dma_cyclic()
3666 if (uc->config.metadata_size) in udma_prep_dma_cyclic()
3667 d->vd.tx.metadata_ops = &metadata_ops; in udma_prep_dma_cyclic()
3669 return vchan_tx_prep(&uc->vc, &d->vd, flags); in udma_prep_dma_cyclic()
3684 if (uc->config.dir != DMA_MEM_TO_MEM) { in udma_prep_dma_memcpy()
3685 dev_err(chan->device->dev, in udma_prep_dma_memcpy()
3687 __func__, uc->id, in udma_prep_dma_memcpy()
3688 dmaengine_get_direction_text(uc->config.dir), in udma_prep_dma_memcpy()
3696 dev_err(uc->ud->dev, "size %zu is not supported\n", in udma_prep_dma_memcpy()
3705 d->dir = DMA_MEM_TO_MEM; in udma_prep_dma_memcpy()
3706 d->desc_idx = 0; in udma_prep_dma_memcpy()
3707 d->tr_idx = 0; in udma_prep_dma_memcpy()
3708 d->residue = len; in udma_prep_dma_memcpy()
3710 if (uc->ud->match_data->type != DMA_TYPE_UDMA) { in udma_prep_dma_memcpy()
3711 src |= (u64)uc->ud->asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_dma_memcpy()
3712 dest |= (u64)uc->ud->asel << K3_ADDRESS_ASEL_SHIFT; in udma_prep_dma_memcpy()
3717 tr_req = d->hwdesc[0].tr_req_base; in udma_prep_dma_memcpy()
3755 cppi5_tr_csf_set(&tr_req[num_tr - 1].flags, csf | CPPI5_TR_CSF_EOP); in udma_prep_dma_memcpy()
3757 if (uc->config.metadata_size) in udma_prep_dma_memcpy()
3758 d->vd.tx.metadata_ops = &metadata_ops; in udma_prep_dma_memcpy()
3760 return vchan_tx_prep(&uc->vc, &d->vd, tx_flags); in udma_prep_dma_memcpy()
3768 spin_lock_irqsave(&uc->vc.lock, flags); in udma_issue_pending()
3771 if (vchan_issue_pending(&uc->vc) && !uc->desc) { in udma_issue_pending()
3777 if (!(uc->state == UDMA_CHAN_IS_TERMINATING && in udma_issue_pending()
3782 spin_unlock_irqrestore(&uc->vc.lock, flags); in udma_issue_pending()
3793 spin_lock_irqsave(&uc->vc.lock, flags); in udma_tx_status()
3806 if (uc->desc && uc->desc->vd.tx.cookie == cookie) { in udma_tx_status()
3809 u32 residue = uc->desc->residue; in udma_tx_status()
3812 if (uc->desc->dir == DMA_MEM_TO_DEV) { in udma_tx_status()
3815 if (uc->config.ep_type != PSIL_EP_NATIVE) { in udma_tx_status()
3820 delay = bcnt - peer_bcnt; in udma_tx_status()
3822 } else if (uc->desc->dir == DMA_DEV_TO_MEM) { in udma_tx_status()
3825 if (uc->config.ep_type != PSIL_EP_NATIVE) { in udma_tx_status()
3830 delay = peer_bcnt - bcnt; in udma_tx_status()
3836 if (bcnt && !(bcnt % uc->desc->residue)) in udma_tx_status()
3839 residue -= bcnt % uc->desc->residue; in udma_tx_status()
3841 if (!residue && (uc->config.dir == DMA_DEV_TO_MEM || !delay)) { in udma_tx_status()
3854 spin_unlock_irqrestore(&uc->vc.lock, flags); in udma_tx_status()
3863 switch (uc->config.dir) { in udma_pause()
3880 return -EINVAL; in udma_pause()
3891 switch (uc->config.dir) { in udma_resume()
3906 return -EINVAL; in udma_resume()
3918 spin_lock_irqsave(&uc->vc.lock, flags); in udma_terminate_all()
3923 if (uc->desc) { in udma_terminate_all()
3924 uc->terminated_desc = uc->desc; in udma_terminate_all()
3925 uc->desc = NULL; in udma_terminate_all()
3926 uc->terminated_desc->terminated = true; in udma_terminate_all()
3927 cancel_delayed_work(&uc->tx_drain.work); in udma_terminate_all()
3930 uc->paused = false; in udma_terminate_all()
3932 vchan_get_all_descriptors(&uc->vc, &head); in udma_terminate_all()
3933 spin_unlock_irqrestore(&uc->vc.lock, flags); in udma_terminate_all()
3934 vchan_dma_desc_free_list(&uc->vc, &head); in udma_terminate_all()
3944 vchan_synchronize(&uc->vc); in udma_synchronize()
3946 if (uc->state == UDMA_CHAN_IS_TERMINATING) { in udma_synchronize()
3947 timeout = wait_for_completion_timeout(&uc->teardown_completed, in udma_synchronize()
3950 dev_warn(uc->ud->dev, "chan%d teardown timeout!\n", in udma_synchronize()
3951 uc->id); in udma_synchronize()
3959 dev_warn(uc->ud->dev, "chan%d refused to stop!\n", uc->id); in udma_synchronize()
3961 cancel_delayed_work_sync(&uc->tx_drain.work); in udma_synchronize()
3969 struct udma_chan *uc = to_udma_chan(&vc->chan); in udma_desc_pre_callback()
3976 d = to_udma_desc(&vd->tx); in udma_desc_pre_callback()
3978 if (d->metadata_size) in udma_desc_pre_callback()
3982 void *desc_vaddr = udma_curr_cppi5_desc_vaddr(d, d->desc_idx); in udma_desc_pre_callback()
3987 result->residue = d->residue - in udma_desc_pre_callback()
3989 if (result->residue) in udma_desc_pre_callback()
3990 result->result = DMA_TRANS_ABORTED; in udma_desc_pre_callback()
3992 result->result = DMA_TRANS_NOERROR; in udma_desc_pre_callback()
3994 result->residue = 0; in udma_desc_pre_callback()
3996 status = d->hwdesc[0].tr_resp_base->status; in udma_desc_pre_callback()
3998 result->result = DMA_TRANS_ABORTED; in udma_desc_pre_callback()
4000 result->result = DMA_TRANS_NOERROR; in udma_desc_pre_callback()
4016 spin_lock_irq(&vc->lock); in udma_vchan_complete()
4017 list_splice_tail_init(&vc->desc_completed, &head); in udma_vchan_complete()
4018 vd = vc->cyclic; in udma_vchan_complete()
4020 vc->cyclic = NULL; in udma_vchan_complete()
4021 dmaengine_desc_get_callback(&vd->tx, &cb); in udma_vchan_complete()
4025 spin_unlock_irq(&vc->lock); in udma_vchan_complete()
4033 dmaengine_desc_get_callback(&vd->tx, &cb); in udma_vchan_complete()
4035 list_del(&vd->node); in udma_vchan_complete()
4047 struct udma_dev *ud = to_udma_dev(chan->device); in udma_free_chan_resources()
4050 if (uc->terminated_desc) { in udma_free_chan_resources()
4055 cancel_delayed_work_sync(&uc->tx_drain.work); in udma_free_chan_resources()
4057 if (uc->irq_num_ring > 0) { in udma_free_chan_resources()
4058 free_irq(uc->irq_num_ring, uc); in udma_free_chan_resources()
4060 uc->irq_num_ring = 0; in udma_free_chan_resources()
4062 if (uc->irq_num_udma > 0) { in udma_free_chan_resources()
4063 free_irq(uc->irq_num_udma, uc); in udma_free_chan_resources()
4065 uc->irq_num_udma = 0; in udma_free_chan_resources()
4068 /* Release PSI-L pairing */ in udma_free_chan_resources()
4069 if (uc->psil_paired) { in udma_free_chan_resources()
4070 navss_psil_unpair(ud, uc->config.src_thread, in udma_free_chan_resources()
4071 uc->config.dst_thread); in udma_free_chan_resources()
4072 uc->psil_paired = false; in udma_free_chan_resources()
4075 vchan_free_chan_resources(&uc->vc); in udma_free_chan_resources()
4076 tasklet_kill(&uc->vc.task); in udma_free_chan_resources()
4083 if (uc->use_dma_pool) { in udma_free_chan_resources()
4084 dma_pool_destroy(uc->hdesc_pool); in udma_free_chan_resources()
4085 uc->use_dma_pool = false; in udma_free_chan_resources()
4108 if (chan->device->dev->driver != &udma_driver.driver && in udma_dma_filter_fn()
4109 chan->device->dev->driver != &bcdma_driver.driver && in udma_dma_filter_fn()
4110 chan->device->dev->driver != &pktdma_driver.driver) in udma_dma_filter_fn()
4114 ucc = &uc->config; in udma_dma_filter_fn()
4115 ud = uc->ud; in udma_dma_filter_fn()
4118 if (filter_param->atype > 2) { in udma_dma_filter_fn()
4119 dev_err(ud->dev, "Invalid channel atype: %u\n", in udma_dma_filter_fn()
4120 filter_param->atype); in udma_dma_filter_fn()
4124 if (filter_param->asel > 15) { in udma_dma_filter_fn()
4125 dev_err(ud->dev, "Invalid channel asel: %u\n", in udma_dma_filter_fn()
4126 filter_param->asel); in udma_dma_filter_fn()
4130 ucc->remote_thread_id = filter_param->remote_thread_id; in udma_dma_filter_fn()
4131 ucc->atype = filter_param->atype; in udma_dma_filter_fn()
4132 ucc->asel = filter_param->asel; in udma_dma_filter_fn()
4133 ucc->tr_trigger_type = filter_param->tr_trigger_type; in udma_dma_filter_fn()
4135 if (ucc->tr_trigger_type) { in udma_dma_filter_fn()
4136 ucc->dir = DMA_MEM_TO_MEM; in udma_dma_filter_fn()
4138 } else if (ucc->remote_thread_id & K3_PSIL_DST_THREAD_ID_OFFSET) { in udma_dma_filter_fn()
4139 ucc->dir = DMA_MEM_TO_DEV; in udma_dma_filter_fn()
4141 ucc->dir = DMA_DEV_TO_MEM; in udma_dma_filter_fn()
4144 ep_config = psil_get_ep_config(ucc->remote_thread_id); in udma_dma_filter_fn()
4146 dev_err(ud->dev, "No configuration for psi-l thread 0x%04x\n", in udma_dma_filter_fn()
4147 ucc->remote_thread_id); in udma_dma_filter_fn()
4148 ucc->dir = DMA_MEM_TO_MEM; in udma_dma_filter_fn()
4149 ucc->remote_thread_id = -1; in udma_dma_filter_fn()
4150 ucc->atype = 0; in udma_dma_filter_fn()
4151 ucc->asel = 0; in udma_dma_filter_fn()
4155 if (ud->match_data->type == DMA_TYPE_BCDMA && in udma_dma_filter_fn()
4156 ep_config->pkt_mode) { in udma_dma_filter_fn()
4157 dev_err(ud->dev, in udma_dma_filter_fn()
4158 "Only TR mode is supported (psi-l thread 0x%04x)\n", in udma_dma_filter_fn()
4159 ucc->remote_thread_id); in udma_dma_filter_fn()
4160 ucc->dir = DMA_MEM_TO_MEM; in udma_dma_filter_fn()
4161 ucc->remote_thread_id = -1; in udma_dma_filter_fn()
4162 ucc->atype = 0; in udma_dma_filter_fn()
4163 ucc->asel = 0; in udma_dma_filter_fn()
4167 ucc->pkt_mode = ep_config->pkt_mode; in udma_dma_filter_fn()
4168 ucc->channel_tpl = ep_config->channel_tpl; in udma_dma_filter_fn()
4169 ucc->notdpkt = ep_config->notdpkt; in udma_dma_filter_fn()
4170 ucc->ep_type = ep_config->ep_type; in udma_dma_filter_fn()
4172 if (ud->match_data->type == DMA_TYPE_PKTDMA && in udma_dma_filter_fn()
4173 ep_config->mapped_channel_id >= 0) { in udma_dma_filter_fn()
4174 ucc->mapped_channel_id = ep_config->mapped_channel_id; in udma_dma_filter_fn()
4175 ucc->default_flow_id = ep_config->default_flow_id; in udma_dma_filter_fn()
4177 ucc->mapped_channel_id = -1; in udma_dma_filter_fn()
4178 ucc->default_flow_id = -1; in udma_dma_filter_fn()
4181 if (ucc->ep_type != PSIL_EP_NATIVE) { in udma_dma_filter_fn()
4182 const struct udma_match_data *match_data = ud->match_data; in udma_dma_filter_fn()
4184 if (match_data->flags & UDMA_FLAG_PDMA_ACC32) in udma_dma_filter_fn()
4185 ucc->enable_acc32 = ep_config->pdma_acc32; in udma_dma_filter_fn()
4186 if (match_data->flags & UDMA_FLAG_PDMA_BURST) in udma_dma_filter_fn()
4187 ucc->enable_burst = ep_config->pdma_burst; in udma_dma_filter_fn()
4190 ucc->needs_epib = ep_config->needs_epib; in udma_dma_filter_fn()
4191 ucc->psd_size = ep_config->psd_size; in udma_dma_filter_fn()
4192 ucc->metadata_size = in udma_dma_filter_fn()
4193 (ucc->needs_epib ? CPPI5_INFO0_HDESC_EPIB_SIZE : 0) + in udma_dma_filter_fn()
4194 ucc->psd_size; in udma_dma_filter_fn()
4196 if (ucc->pkt_mode) in udma_dma_filter_fn()
4197 ucc->hdesc_size = ALIGN(sizeof(struct cppi5_host_desc_t) + in udma_dma_filter_fn()
4198 ucc->metadata_size, ud->desc_align); in udma_dma_filter_fn()
4200 dev_dbg(ud->dev, "chan%d: Remote thread: 0x%04x (%s)\n", uc->id, in udma_dma_filter_fn()
4201 ucc->remote_thread_id, dmaengine_get_direction_text(ucc->dir)); in udma_dma_filter_fn()
4206 dev_dbg(ud->dev, "chan%d: triggered channel (type: %u)\n", uc->id, in udma_dma_filter_fn()
4207 ucc->tr_trigger_type); in udma_dma_filter_fn()
4216 struct udma_dev *ud = ofdma->of_dma_data; in udma_of_xlate()
4217 dma_cap_mask_t mask = ud->ddev.cap_mask; in udma_of_xlate()
4221 if (ud->match_data->type == DMA_TYPE_BCDMA) { in udma_of_xlate()
4222 if (dma_spec->args_count != 3) in udma_of_xlate()
4225 filter_param.tr_trigger_type = dma_spec->args[0]; in udma_of_xlate()
4226 filter_param.remote_thread_id = dma_spec->args[1]; in udma_of_xlate()
4227 filter_param.asel = dma_spec->args[2]; in udma_of_xlate()
4230 if (dma_spec->args_count != 1 && dma_spec->args_count != 2) in udma_of_xlate()
4233 filter_param.remote_thread_id = dma_spec->args[0]; in udma_of_xlate()
4235 if (dma_spec->args_count == 2) { in udma_of_xlate()
4236 if (ud->match_data->type == DMA_TYPE_UDMA) { in udma_of_xlate()
4237 filter_param.atype = dma_spec->args[1]; in udma_of_xlate()
4241 filter_param.asel = dma_spec->args[1]; in udma_of_xlate()
4250 ofdma->of_node); in udma_of_xlate()
4252 dev_err(ud->dev, "get channel fail in %s.\n", __func__); in udma_of_xlate()
4253 return ERR_PTR(-EINVAL); in udma_of_xlate()
4339 .psil_base = 0x2000, /* for tchan and rchan, not applicable to bchan */
4377 .compatible = "ti,am654-navss-main-udmap",
4381 .compatible = "ti,am654-navss-mcu-udmap",
4384 .compatible = "ti,j721e-navss-main-udmap",
4387 .compatible = "ti,j721e-navss-mcu-udmap",
4391 .compatible = "ti,am64-dmss-bcdma",
4395 .compatible = "ti,am64-dmss-pktdma",
4399 .compatible = "ti,am62a-dmss-bcdma-csirx",
4403 .compatible = "ti,j721s2-dmss-bcdma-csi",
4458 ud->mmrs[MMR_GCFG] = devm_platform_ioremap_resource_byname(pdev, mmr_names[MMR_GCFG]); in udma_get_mmrs()
4459 if (IS_ERR(ud->mmrs[MMR_GCFG])) in udma_get_mmrs()
4460 return PTR_ERR(ud->mmrs[MMR_GCFG]); in udma_get_mmrs()
4462 cap2 = udma_read(ud->mmrs[MMR_GCFG], 0x28); in udma_get_mmrs()
4463 cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c); in udma_get_mmrs()
4465 switch (ud->match_data->type) { in udma_get_mmrs()
4467 ud->rflow_cnt = UDMA_CAP3_RFLOW_CNT(cap3); in udma_get_mmrs()
4468 ud->tchan_cnt = UDMA_CAP2_TCHAN_CNT(cap2); in udma_get_mmrs()
4469 ud->echan_cnt = UDMA_CAP2_ECHAN_CNT(cap2); in udma_get_mmrs()
4470 ud->rchan_cnt = UDMA_CAP2_RCHAN_CNT(cap2); in udma_get_mmrs()
4473 ud->bchan_cnt = BCDMA_CAP2_BCHAN_CNT(cap2) + in udma_get_mmrs()
4476 ud->tchan_cnt = BCDMA_CAP2_TCHAN_CNT(cap2); in udma_get_mmrs()
4477 ud->rchan_cnt = BCDMA_CAP2_RCHAN_CNT(cap2); in udma_get_mmrs()
4478 ud->rflow_cnt = ud->rchan_cnt; in udma_get_mmrs()
4481 cap4 = udma_read(ud->mmrs[MMR_GCFG], 0x30); in udma_get_mmrs()
4482 ud->tchan_cnt = UDMA_CAP2_TCHAN_CNT(cap2); in udma_get_mmrs()
4483 ud->rchan_cnt = UDMA_CAP2_RCHAN_CNT(cap2); in udma_get_mmrs()
4484 ud->rflow_cnt = UDMA_CAP3_RFLOW_CNT(cap3); in udma_get_mmrs()
4485 ud->tflow_cnt = PKTDMA_CAP4_TFLOW_CNT(cap4); in udma_get_mmrs()
4488 return -EINVAL; in udma_get_mmrs()
4492 if (i == MMR_BCHANRT && ud->bchan_cnt == 0) in udma_get_mmrs()
4494 if (i == MMR_TCHANRT && ud->tchan_cnt == 0) in udma_get_mmrs()
4496 if (i == MMR_RCHANRT && ud->rchan_cnt == 0) in udma_get_mmrs()
4499 ud->mmrs[i] = devm_platform_ioremap_resource_byname(pdev, mmr_names[i]); in udma_get_mmrs()
4500 if (IS_ERR(ud->mmrs[i])) in udma_get_mmrs()
4501 return PTR_ERR(ud->mmrs[i]); in udma_get_mmrs()
4511 bitmap_clear(map, rm_desc->start, rm_desc->num); in udma_mark_resource_ranges()
4512 bitmap_clear(map, rm_desc->start_sec, rm_desc->num_sec); in udma_mark_resource_ranges()
4513 dev_dbg(ud->dev, "ti_sci resource range for %s: %d:%d | %d:%d\n", name, in udma_mark_resource_ranges()
4514 rm_desc->start, rm_desc->num, rm_desc->start_sec, in udma_mark_resource_ranges()
4515 rm_desc->num_sec); in udma_mark_resource_ranges()
4519 [RM_RANGE_BCHAN] = "ti,sci-rm-range-bchan",
4520 [RM_RANGE_TCHAN] = "ti,sci-rm-range-tchan",
4521 [RM_RANGE_RCHAN] = "ti,sci-rm-range-rchan",
4522 [RM_RANGE_RFLOW] = "ti,sci-rm-range-rflow",
4523 [RM_RANGE_TFLOW] = "ti,sci-rm-range-tflow",
4529 struct device *dev = ud->dev; in udma_setup_resources()
4531 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in udma_setup_resources()
4535 cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c); in udma_setup_resources()
4536 if (of_device_is_compatible(dev->of_node, in udma_setup_resources()
4537 "ti,am654-navss-main-udmap")) { in udma_setup_resources()
4538 ud->tchan_tpl.levels = 2; in udma_setup_resources()
4539 ud->tchan_tpl.start_idx[0] = 8; in udma_setup_resources()
4540 } else if (of_device_is_compatible(dev->of_node, in udma_setup_resources()
4541 "ti,am654-navss-mcu-udmap")) { in udma_setup_resources()
4542 ud->tchan_tpl.levels = 2; in udma_setup_resources()
4543 ud->tchan_tpl.start_idx[0] = 2; in udma_setup_resources()
4545 ud->tchan_tpl.levels = 3; in udma_setup_resources()
4546 ud->tchan_tpl.start_idx[1] = UDMA_CAP3_UCHAN_CNT(cap3); in udma_setup_resources()
4547 ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); in udma_setup_resources()
4549 ud->tchan_tpl.levels = 2; in udma_setup_resources()
4550 ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); in udma_setup_resources()
4552 ud->tchan_tpl.levels = 1; in udma_setup_resources()
4555 ud->rchan_tpl.levels = ud->tchan_tpl.levels; in udma_setup_resources()
4556 ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; in udma_setup_resources()
4557 ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; in udma_setup_resources()
4559 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), in udma_setup_resources()
4561 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), in udma_setup_resources()
4563 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), in udma_setup_resources()
4565 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), in udma_setup_resources()
4567 ud->rflow_gp_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rflow_cnt), in udma_setup_resources()
4570 ud->rflow_gp_map_allocated = devm_kcalloc(dev, in udma_setup_resources()
4571 BITS_TO_LONGS(ud->rflow_cnt), in udma_setup_resources()
4574 ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), in udma_setup_resources()
4577 ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), in udma_setup_resources()
4580 if (!ud->tchan_map || !ud->rchan_map || !ud->rflow_gp_map || in udma_setup_resources()
4581 !ud->rflow_gp_map_allocated || !ud->tchans || !ud->rchans || in udma_setup_resources()
4582 !ud->rflows || !ud->rflow_in_use) in udma_setup_resources()
4583 return -ENOMEM; in udma_setup_resources()
4590 bitmap_set(ud->rflow_gp_map_allocated, 0, ud->rchan_cnt); in udma_setup_resources()
4593 bitmap_set(ud->rflow_gp_map, 0, ud->rflow_cnt); in udma_setup_resources()
4600 tisci_rm->rm_ranges[i] = in udma_setup_resources()
4601 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev, in udma_setup_resources()
4602 tisci_rm->tisci_dev_id, in udma_setup_resources()
4607 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN]; in udma_setup_resources()
4609 bitmap_zero(ud->tchan_map, ud->tchan_cnt); in udma_setup_resources()
4612 bitmap_fill(ud->tchan_map, ud->tchan_cnt); in udma_setup_resources()
4613 for (i = 0; i < rm_res->sets; i++) in udma_setup_resources()
4614 udma_mark_resource_ranges(ud, ud->tchan_map, in udma_setup_resources()
4615 &rm_res->desc[i], "tchan"); in udma_setup_resources()
4616 irq_res.sets = rm_res->sets; in udma_setup_resources()
4619 /* rchan and matching default flow ranges */ in udma_setup_resources()
4620 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN]; in udma_setup_resources()
4622 bitmap_zero(ud->rchan_map, ud->rchan_cnt); in udma_setup_resources()
4625 bitmap_fill(ud->rchan_map, ud->rchan_cnt); in udma_setup_resources()
4626 for (i = 0; i < rm_res->sets; i++) in udma_setup_resources()
4627 udma_mark_resource_ranges(ud, ud->rchan_map, in udma_setup_resources()
4628 &rm_res->desc[i], "rchan"); in udma_setup_resources()
4629 irq_res.sets += rm_res->sets; in udma_setup_resources()
4634 return -ENOMEM; in udma_setup_resources()
4635 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN]; in udma_setup_resources()
4638 irq_res.desc[0].num = ud->tchan_cnt; in udma_setup_resources()
4641 for (i = 0; i < rm_res->sets; i++) { in udma_setup_resources()
4642 irq_res.desc[i].start = rm_res->desc[i].start; in udma_setup_resources()
4643 irq_res.desc[i].num = rm_res->desc[i].num; in udma_setup_resources()
4644 irq_res.desc[i].start_sec = rm_res->desc[i].start_sec; in udma_setup_resources()
4645 irq_res.desc[i].num_sec = rm_res->desc[i].num_sec; in udma_setup_resources()
4648 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN]; in udma_setup_resources()
4651 irq_res.desc[i].num = ud->rchan_cnt; in udma_setup_resources()
4653 for (j = 0; j < rm_res->sets; j++, i++) { in udma_setup_resources()
4654 if (rm_res->desc[j].num) { in udma_setup_resources()
4655 irq_res.desc[i].start = rm_res->desc[j].start + in udma_setup_resources()
4656 ud->soc_data->oes.udma_rchan; in udma_setup_resources()
4657 irq_res.desc[i].num = rm_res->desc[j].num; in udma_setup_resources()
4659 if (rm_res->desc[j].num_sec) { in udma_setup_resources()
4660 irq_res.desc[i].start_sec = rm_res->desc[j].start_sec + in udma_setup_resources()
4661 ud->soc_data->oes.udma_rchan; in udma_setup_resources()
4662 irq_res.desc[i].num_sec = rm_res->desc[j].num_sec; in udma_setup_resources()
4666 ret = ti_sci_inta_msi_domain_alloc_irqs(ud->dev, &irq_res); in udma_setup_resources()
4669 dev_err(ud->dev, "Failed to allocate MSI interrupts\n"); in udma_setup_resources()
4674 rm_res = tisci_rm->rm_ranges[RM_RANGE_RFLOW]; in udma_setup_resources()
4677 bitmap_clear(ud->rflow_gp_map, ud->rchan_cnt, in udma_setup_resources()
4678 ud->rflow_cnt - ud->rchan_cnt); in udma_setup_resources()
4680 for (i = 0; i < rm_res->sets; i++) in udma_setup_resources()
4681 udma_mark_resource_ranges(ud, ud->rflow_gp_map, in udma_setup_resources()
4682 &rm_res->desc[i], "gp-rflow"); in udma_setup_resources()
4691 struct device *dev = ud->dev; in bcdma_setup_resources()
4693 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in bcdma_setup_resources()
4694 const struct udma_oes_offsets *oes = &ud->soc_data->oes; in bcdma_setup_resources()
4698 cap = udma_read(ud->mmrs[MMR_GCFG], 0x2c); in bcdma_setup_resources()
4700 ud->bchan_tpl.levels = 3; in bcdma_setup_resources()
4701 ud->bchan_tpl.start_idx[1] = BCDMA_CAP3_UBCHAN_CNT(cap); in bcdma_setup_resources()
4702 ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); in bcdma_setup_resources()
4704 ud->bchan_tpl.levels = 2; in bcdma_setup_resources()
4705 ud->bchan_tpl.start_idx[0] = BCDMA_CAP3_HBCHAN_CNT(cap); in bcdma_setup_resources()
4707 ud->bchan_tpl.levels = 1; in bcdma_setup_resources()
4710 cap = udma_read(ud->mmrs[MMR_GCFG], 0x30); in bcdma_setup_resources()
4712 ud->rchan_tpl.levels = 3; in bcdma_setup_resources()
4713 ud->rchan_tpl.start_idx[1] = BCDMA_CAP4_URCHAN_CNT(cap); in bcdma_setup_resources()
4714 ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); in bcdma_setup_resources()
4716 ud->rchan_tpl.levels = 2; in bcdma_setup_resources()
4717 ud->rchan_tpl.start_idx[0] = BCDMA_CAP4_HRCHAN_CNT(cap); in bcdma_setup_resources()
4719 ud->rchan_tpl.levels = 1; in bcdma_setup_resources()
4723 ud->tchan_tpl.levels = 3; in bcdma_setup_resources()
4724 ud->tchan_tpl.start_idx[1] = BCDMA_CAP4_UTCHAN_CNT(cap); in bcdma_setup_resources()
4725 ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); in bcdma_setup_resources()
4727 ud->tchan_tpl.levels = 2; in bcdma_setup_resources()
4728 ud->tchan_tpl.start_idx[0] = BCDMA_CAP4_HTCHAN_CNT(cap); in bcdma_setup_resources()
4730 ud->tchan_tpl.levels = 1; in bcdma_setup_resources()
4733 ud->bchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->bchan_cnt), in bcdma_setup_resources()
4735 ud->bchans = devm_kcalloc(dev, ud->bchan_cnt, sizeof(*ud->bchans), in bcdma_setup_resources()
4737 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), in bcdma_setup_resources()
4739 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), in bcdma_setup_resources()
4741 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), in bcdma_setup_resources()
4743 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), in bcdma_setup_resources()
4746 ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rchan_cnt), in bcdma_setup_resources()
4749 ud->rflows = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rflows), in bcdma_setup_resources()
4752 if (!ud->bchan_map || !ud->tchan_map || !ud->rchan_map || in bcdma_setup_resources()
4753 !ud->rflow_in_use || !ud->bchans || !ud->tchans || !ud->rchans || in bcdma_setup_resources()
4754 !ud->rflows) in bcdma_setup_resources()
4755 return -ENOMEM; in bcdma_setup_resources()
4761 if (i == RM_RANGE_BCHAN && ud->bchan_cnt == 0) in bcdma_setup_resources()
4763 if (i == RM_RANGE_TCHAN && ud->tchan_cnt == 0) in bcdma_setup_resources()
4765 if (i == RM_RANGE_RCHAN && ud->rchan_cnt == 0) in bcdma_setup_resources()
4768 tisci_rm->rm_ranges[i] = in bcdma_setup_resources()
4769 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev, in bcdma_setup_resources()
4770 tisci_rm->tisci_dev_id, in bcdma_setup_resources()
4777 if (ud->bchan_cnt) { in bcdma_setup_resources()
4778 rm_res = tisci_rm->rm_ranges[RM_RANGE_BCHAN]; in bcdma_setup_resources()
4780 bitmap_zero(ud->bchan_map, ud->bchan_cnt); in bcdma_setup_resources()
4783 bitmap_fill(ud->bchan_map, ud->bchan_cnt); in bcdma_setup_resources()
4784 for (i = 0; i < rm_res->sets; i++) in bcdma_setup_resources()
4785 udma_mark_resource_ranges(ud, ud->bchan_map, in bcdma_setup_resources()
4786 &rm_res->desc[i], in bcdma_setup_resources()
4788 irq_res.sets += rm_res->sets; in bcdma_setup_resources()
4793 if (ud->tchan_cnt) { in bcdma_setup_resources()
4794 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN]; in bcdma_setup_resources()
4796 bitmap_zero(ud->tchan_map, ud->tchan_cnt); in bcdma_setup_resources()
4799 bitmap_fill(ud->tchan_map, ud->tchan_cnt); in bcdma_setup_resources()
4800 for (i = 0; i < rm_res->sets; i++) in bcdma_setup_resources()
4801 udma_mark_resource_ranges(ud, ud->tchan_map, in bcdma_setup_resources()
4802 &rm_res->desc[i], in bcdma_setup_resources()
4804 irq_res.sets += rm_res->sets * 2; in bcdma_setup_resources()
4808 /* rchan ranges */ in bcdma_setup_resources()
4809 if (ud->rchan_cnt) { in bcdma_setup_resources()
4810 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN]; in bcdma_setup_resources()
4812 bitmap_zero(ud->rchan_map, ud->rchan_cnt); in bcdma_setup_resources()
4815 bitmap_fill(ud->rchan_map, ud->rchan_cnt); in bcdma_setup_resources()
4816 for (i = 0; i < rm_res->sets; i++) in bcdma_setup_resources()
4817 udma_mark_resource_ranges(ud, ud->rchan_map, in bcdma_setup_resources()
4818 &rm_res->desc[i], in bcdma_setup_resources()
4819 "rchan"); in bcdma_setup_resources()
4820 irq_res.sets += rm_res->sets * 2; in bcdma_setup_resources()
4826 return -ENOMEM; in bcdma_setup_resources()
4827 if (ud->bchan_cnt) { in bcdma_setup_resources()
4828 rm_res = tisci_rm->rm_ranges[RM_RANGE_BCHAN]; in bcdma_setup_resources()
4830 irq_res.desc[0].start = oes->bcdma_bchan_ring; in bcdma_setup_resources()
4831 irq_res.desc[0].num = ud->bchan_cnt; in bcdma_setup_resources()
4834 for (i = 0; i < rm_res->sets; i++) { in bcdma_setup_resources()
4835 irq_res.desc[i].start = rm_res->desc[i].start + in bcdma_setup_resources()
4836 oes->bcdma_bchan_ring; in bcdma_setup_resources()
4837 irq_res.desc[i].num = rm_res->desc[i].num; in bcdma_setup_resources()
4844 if (ud->tchan_cnt) { in bcdma_setup_resources()
4845 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN]; in bcdma_setup_resources()
4847 irq_res.desc[i].start = oes->bcdma_tchan_data; in bcdma_setup_resources()
4848 irq_res.desc[i].num = ud->tchan_cnt; in bcdma_setup_resources()
4849 irq_res.desc[i + 1].start = oes->bcdma_tchan_ring; in bcdma_setup_resources()
4850 irq_res.desc[i + 1].num = ud->tchan_cnt; in bcdma_setup_resources()
4853 for (j = 0; j < rm_res->sets; j++, i += 2) { in bcdma_setup_resources()
4854 irq_res.desc[i].start = rm_res->desc[j].start + in bcdma_setup_resources()
4855 oes->bcdma_tchan_data; in bcdma_setup_resources()
4856 irq_res.desc[i].num = rm_res->desc[j].num; in bcdma_setup_resources()
4858 irq_res.desc[i + 1].start = rm_res->desc[j].start + in bcdma_setup_resources()
4859 oes->bcdma_tchan_ring; in bcdma_setup_resources()
4860 irq_res.desc[i + 1].num = rm_res->desc[j].num; in bcdma_setup_resources()
4864 if (ud->rchan_cnt) { in bcdma_setup_resources()
4865 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN]; in bcdma_setup_resources()
4867 irq_res.desc[i].start = oes->bcdma_rchan_data; in bcdma_setup_resources()
4868 irq_res.desc[i].num = ud->rchan_cnt; in bcdma_setup_resources()
4869 irq_res.desc[i + 1].start = oes->bcdma_rchan_ring; in bcdma_setup_resources()
4870 irq_res.desc[i + 1].num = ud->rchan_cnt; in bcdma_setup_resources()
4873 for (j = 0; j < rm_res->sets; j++, i += 2) { in bcdma_setup_resources()
4874 irq_res.desc[i].start = rm_res->desc[j].start + in bcdma_setup_resources()
4875 oes->bcdma_rchan_data; in bcdma_setup_resources()
4876 irq_res.desc[i].num = rm_res->desc[j].num; in bcdma_setup_resources()
4878 irq_res.desc[i + 1].start = rm_res->desc[j].start + in bcdma_setup_resources()
4879 oes->bcdma_rchan_ring; in bcdma_setup_resources()
4880 irq_res.desc[i + 1].num = rm_res->desc[j].num; in bcdma_setup_resources()
4885 ret = ti_sci_inta_msi_domain_alloc_irqs(ud->dev, &irq_res); in bcdma_setup_resources()
4888 dev_err(ud->dev, "Failed to allocate MSI interrupts\n"); in bcdma_setup_resources()
4898 struct device *dev = ud->dev; in pktdma_setup_resources()
4900 struct udma_tisci_rm *tisci_rm = &ud->tisci_rm; in pktdma_setup_resources()
4901 const struct udma_oes_offsets *oes = &ud->soc_data->oes; in pktdma_setup_resources()
4905 cap3 = udma_read(ud->mmrs[MMR_GCFG], 0x2c); in pktdma_setup_resources()
4907 ud->tchan_tpl.levels = 3; in pktdma_setup_resources()
4908 ud->tchan_tpl.start_idx[1] = UDMA_CAP3_UCHAN_CNT(cap3); in pktdma_setup_resources()
4909 ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); in pktdma_setup_resources()
4911 ud->tchan_tpl.levels = 2; in pktdma_setup_resources()
4912 ud->tchan_tpl.start_idx[0] = UDMA_CAP3_HCHAN_CNT(cap3); in pktdma_setup_resources()
4914 ud->tchan_tpl.levels = 1; in pktdma_setup_resources()
4917 ud->rchan_tpl.levels = ud->tchan_tpl.levels; in pktdma_setup_resources()
4918 ud->rchan_tpl.start_idx[0] = ud->tchan_tpl.start_idx[0]; in pktdma_setup_resources()
4919 ud->rchan_tpl.start_idx[1] = ud->tchan_tpl.start_idx[1]; in pktdma_setup_resources()
4921 ud->tchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tchan_cnt), in pktdma_setup_resources()
4923 ud->tchans = devm_kcalloc(dev, ud->tchan_cnt, sizeof(*ud->tchans), in pktdma_setup_resources()
4925 ud->rchan_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->rchan_cnt), in pktdma_setup_resources()
4927 ud->rchans = devm_kcalloc(dev, ud->rchan_cnt, sizeof(*ud->rchans), in pktdma_setup_resources()
4929 ud->rflow_in_use = devm_kcalloc(dev, BITS_TO_LONGS(ud->rflow_cnt), in pktdma_setup_resources()
4932 ud->rflows = devm_kcalloc(dev, ud->rflow_cnt, sizeof(*ud->rflows), in pktdma_setup_resources()
4934 ud->tflow_map = devm_kmalloc_array(dev, BITS_TO_LONGS(ud->tflow_cnt), in pktdma_setup_resources()
4937 if (!ud->tchan_map || !ud->rchan_map || !ud->tflow_map || !ud->tchans || in pktdma_setup_resources()
4938 !ud->rchans || !ud->rflows || !ud->rflow_in_use) in pktdma_setup_resources()
4939 return -ENOMEM; in pktdma_setup_resources()
4946 tisci_rm->rm_ranges[i] = in pktdma_setup_resources()
4947 devm_ti_sci_get_of_resource(tisci_rm->tisci, dev, in pktdma_setup_resources()
4948 tisci_rm->tisci_dev_id, in pktdma_setup_resources()
4953 rm_res = tisci_rm->rm_ranges[RM_RANGE_TCHAN]; in pktdma_setup_resources()
4955 bitmap_zero(ud->tchan_map, ud->tchan_cnt); in pktdma_setup_resources()
4957 bitmap_fill(ud->tchan_map, ud->tchan_cnt); in pktdma_setup_resources()
4958 for (i = 0; i < rm_res->sets; i++) in pktdma_setup_resources()
4959 udma_mark_resource_ranges(ud, ud->tchan_map, in pktdma_setup_resources()
4960 &rm_res->desc[i], "tchan"); in pktdma_setup_resources()
4963 /* rchan ranges */ in pktdma_setup_resources()
4964 rm_res = tisci_rm->rm_ranges[RM_RANGE_RCHAN]; in pktdma_setup_resources()
4966 bitmap_zero(ud->rchan_map, ud->rchan_cnt); in pktdma_setup_resources()
4968 bitmap_fill(ud->rchan_map, ud->rchan_cnt); in pktdma_setup_resources()
4969 for (i = 0; i < rm_res->sets; i++) in pktdma_setup_resources()
4970 udma_mark_resource_ranges(ud, ud->rchan_map, in pktdma_setup_resources()
4971 &rm_res->desc[i], "rchan"); in pktdma_setup_resources()
4975 rm_res = tisci_rm->rm_ranges[RM_RANGE_RFLOW]; in pktdma_setup_resources()
4978 bitmap_zero(ud->rflow_in_use, ud->rflow_cnt); in pktdma_setup_resources()
4981 bitmap_fill(ud->rflow_in_use, ud->rflow_cnt); in pktdma_setup_resources()
4982 for (i = 0; i < rm_res->sets; i++) in pktdma_setup_resources()
4983 udma_mark_resource_ranges(ud, ud->rflow_in_use, in pktdma_setup_resources()
4984 &rm_res->desc[i], "rflow"); in pktdma_setup_resources()
4985 irq_res.sets = rm_res->sets; in pktdma_setup_resources()
4989 rm_res = tisci_rm->rm_ranges[RM_RANGE_TFLOW]; in pktdma_setup_resources()
4992 bitmap_zero(ud->tflow_map, ud->tflow_cnt); in pktdma_setup_resources()
4995 bitmap_fill(ud->tflow_map, ud->tflow_cnt); in pktdma_setup_resources()
4996 for (i = 0; i < rm_res->sets; i++) in pktdma_setup_resources()
4997 udma_mark_resource_ranges(ud, ud->tflow_map, in pktdma_setup_resources()
4998 &rm_res->desc[i], "tflow"); in pktdma_setup_resources()
4999 irq_res.sets += rm_res->sets; in pktdma_setup_resources()
5004 return -ENOMEM; in pktdma_setup_resources()
5005 rm_res = tisci_rm->rm_ranges[RM_RANGE_TFLOW]; in pktdma_setup_resources()
5007 irq_res.desc[0].start = oes->pktdma_tchan_flow; in pktdma_setup_resources()
5008 irq_res.desc[0].num = ud->tflow_cnt; in pktdma_setup_resources()
5011 for (i = 0; i < rm_res->sets; i++) { in pktdma_setup_resources()
5012 irq_res.desc[i].start = rm_res->desc[i].start + in pktdma_setup_resources()
5013 oes->pktdma_tchan_flow; in pktdma_setup_resources()
5014 irq_res.desc[i].num = rm_res->desc[i].num; in pktdma_setup_resources()
5017 rm_res = tisci_rm->rm_ranges[RM_RANGE_RFLOW]; in pktdma_setup_resources()
5019 irq_res.desc[i].start = oes->pktdma_rchan_flow; in pktdma_setup_resources()
5020 irq_res.desc[i].num = ud->rflow_cnt; in pktdma_setup_resources()
5022 for (j = 0; j < rm_res->sets; j++, i++) { in pktdma_setup_resources()
5023 irq_res.desc[i].start = rm_res->desc[j].start + in pktdma_setup_resources()
5024 oes->pktdma_rchan_flow; in pktdma_setup_resources()
5025 irq_res.desc[i].num = rm_res->desc[j].num; in pktdma_setup_resources()
5028 ret = ti_sci_inta_msi_domain_alloc_irqs(ud->dev, &irq_res); in pktdma_setup_resources()
5031 dev_err(ud->dev, "Failed to allocate MSI interrupts\n"); in pktdma_setup_resources()
5040 struct device *dev = ud->dev; in setup_resources()
5043 switch (ud->match_data->type) { in setup_resources()
5054 return -EINVAL; in setup_resources()
5060 ch_count = ud->bchan_cnt + ud->tchan_cnt + ud->rchan_cnt; in setup_resources()
5061 if (ud->bchan_cnt) in setup_resources()
5062 ch_count -= bitmap_weight(ud->bchan_map, ud->bchan_cnt); in setup_resources()
5063 ch_count -= bitmap_weight(ud->tchan_map, ud->tchan_cnt); in setup_resources()
5064 ch_count -= bitmap_weight(ud->rchan_map, ud->rchan_cnt); in setup_resources()
5066 return -ENODEV; in setup_resources()
5068 ud->channels = devm_kcalloc(dev, ch_count, sizeof(*ud->channels), in setup_resources()
5070 if (!ud->channels) in setup_resources()
5071 return -ENOMEM; in setup_resources()
5073 switch (ud->match_data->type) { in setup_resources()
5076 "Channels: %d (tchan: %u, rchan: %u, gp-rflow: %u)\n", in setup_resources()
5078 ud->tchan_cnt - bitmap_weight(ud->tchan_map, in setup_resources()
5079 ud->tchan_cnt), in setup_resources()
5080 ud->rchan_cnt - bitmap_weight(ud->rchan_map, in setup_resources()
5081 ud->rchan_cnt), in setup_resources()
5082 ud->rflow_cnt - bitmap_weight(ud->rflow_gp_map, in setup_resources()
5083 ud->rflow_cnt)); in setup_resources()
5087 "Channels: %d (bchan: %u, tchan: %u, rchan: %u)\n", in setup_resources()
5089 ud->bchan_cnt - bitmap_weight(ud->bchan_map, in setup_resources()
5090 ud->bchan_cnt), in setup_resources()
5091 ud->tchan_cnt - bitmap_weight(ud->tchan_map, in setup_resources()
5092 ud->tchan_cnt), in setup_resources()
5093 ud->rchan_cnt - bitmap_weight(ud->rchan_map, in setup_resources()
5094 ud->rchan_cnt)); in setup_resources()
5098 "Channels: %d (tchan: %u, rchan: %u)\n", in setup_resources()
5100 ud->tchan_cnt - bitmap_weight(ud->tchan_map, in setup_resources()
5101 ud->tchan_cnt), in setup_resources()
5102 ud->rchan_cnt - bitmap_weight(ud->rchan_map, in setup_resources()
5103 ud->rchan_cnt)); in setup_resources()
5114 struct udma_rx_flush *rx_flush = &ud->rx_flush; in udma_setup_rx_flush()
5118 struct device *dev = ud->dev; in udma_setup_rx_flush()
5123 rx_flush->buffer_size = SZ_1K; in udma_setup_rx_flush()
5124 rx_flush->buffer_vaddr = devm_kzalloc(dev, rx_flush->buffer_size, in udma_setup_rx_flush()
5126 if (!rx_flush->buffer_vaddr) in udma_setup_rx_flush()
5127 return -ENOMEM; in udma_setup_rx_flush()
5129 rx_flush->buffer_paddr = dma_map_single(dev, rx_flush->buffer_vaddr, in udma_setup_rx_flush()
5130 rx_flush->buffer_size, in udma_setup_rx_flush()
5132 if (dma_mapping_error(dev, rx_flush->buffer_paddr)) in udma_setup_rx_flush()
5133 return -ENOMEM; in udma_setup_rx_flush()
5136 hwdesc = &rx_flush->hwdescs[0]; in udma_setup_rx_flush()
5138 hwdesc->cppi5_desc_size = cppi5_trdesc_calc_size(tr_size, 1); in udma_setup_rx_flush()
5139 hwdesc->cppi5_desc_size = ALIGN(hwdesc->cppi5_desc_size, in udma_setup_rx_flush()
5140 ud->desc_align); in udma_setup_rx_flush()
5142 hwdesc->cppi5_desc_vaddr = devm_kzalloc(dev, hwdesc->cppi5_desc_size, in udma_setup_rx_flush()
5144 if (!hwdesc->cppi5_desc_vaddr) in udma_setup_rx_flush()
5145 return -ENOMEM; in udma_setup_rx_flush()
5147 hwdesc->cppi5_desc_paddr = dma_map_single(dev, hwdesc->cppi5_desc_vaddr, in udma_setup_rx_flush()
5148 hwdesc->cppi5_desc_size, in udma_setup_rx_flush()
5150 if (dma_mapping_error(dev, hwdesc->cppi5_desc_paddr)) in udma_setup_rx_flush()
5151 return -ENOMEM; in udma_setup_rx_flush()
5154 hwdesc->tr_req_base = hwdesc->cppi5_desc_vaddr + tr_size; in udma_setup_rx_flush()
5156 hwdesc->tr_resp_base = hwdesc->tr_req_base + tr_size; in udma_setup_rx_flush()
5158 tr_desc = hwdesc->cppi5_desc_vaddr; in udma_setup_rx_flush()
5163 tr_req = hwdesc->tr_req_base; in udma_setup_rx_flush()
5164 cppi5_tr_init(&tr_req->flags, CPPI5_TR_TYPE1, false, false, in udma_setup_rx_flush()
5166 cppi5_tr_csf_set(&tr_req->flags, CPPI5_TR_CSF_SUPR_EVT); in udma_setup_rx_flush()
5168 tr_req->addr = rx_flush->buffer_paddr; in udma_setup_rx_flush()
5169 tr_req->icnt0 = rx_flush->buffer_size; in udma_setup_rx_flush()
5170 tr_req->icnt1 = 1; in udma_setup_rx_flush()
5172 dma_sync_single_for_device(dev, hwdesc->cppi5_desc_paddr, in udma_setup_rx_flush()
5173 hwdesc->cppi5_desc_size, DMA_TO_DEVICE); in udma_setup_rx_flush()
5176 hwdesc = &rx_flush->hwdescs[1]; in udma_setup_rx_flush()
5177 hwdesc->cppi5_desc_size = ALIGN(sizeof(struct cppi5_host_desc_t) + in udma_setup_rx_flush()
5180 ud->desc_align); in udma_setup_rx_flush()
5182 hwdesc->cppi5_desc_vaddr = devm_kzalloc(dev, hwdesc->cppi5_desc_size, in udma_setup_rx_flush()
5184 if (!hwdesc->cppi5_desc_vaddr) in udma_setup_rx_flush()
5185 return -ENOMEM; in udma_setup_rx_flush()
5187 hwdesc->cppi5_desc_paddr = dma_map_single(dev, hwdesc->cppi5_desc_vaddr, in udma_setup_rx_flush()
5188 hwdesc->cppi5_desc_size, in udma_setup_rx_flush()
5190 if (dma_mapping_error(dev, hwdesc->cppi5_desc_paddr)) in udma_setup_rx_flush()
5191 return -ENOMEM; in udma_setup_rx_flush()
5193 desc = hwdesc->cppi5_desc_vaddr; in udma_setup_rx_flush()
5195 cppi5_desc_set_pktids(&desc->hdr, 0, CPPI5_INFO1_DESC_FLOWID_DEFAULT); in udma_setup_rx_flush()
5196 cppi5_desc_set_retpolicy(&desc->hdr, 0, 0); in udma_setup_rx_flush()
5199 rx_flush->buffer_paddr, rx_flush->buffer_size, in udma_setup_rx_flush()
5200 rx_flush->buffer_paddr, rx_flush->buffer_size); in udma_setup_rx_flush()
5202 dma_sync_single_for_device(dev, hwdesc->cppi5_desc_paddr, in udma_setup_rx_flush()
5203 hwdesc->cppi5_desc_size, DMA_TO_DEVICE); in udma_setup_rx_flush()
5212 struct udma_chan_config *ucc = &uc->config; in udma_dbg_summary_show_chan()
5214 seq_printf(s, " %-13s| %s", dma_chan_name(chan), in udma_dbg_summary_show_chan()
5215 chan->dbg_client_name ?: "in-use"); in udma_dbg_summary_show_chan()
5216 if (ucc->tr_trigger_type) in udma_dbg_summary_show_chan()
5220 dmaengine_get_direction_text(uc->config.dir)); in udma_dbg_summary_show_chan()
5222 switch (uc->config.dir) { in udma_dbg_summary_show_chan()
5224 if (uc->ud->match_data->type == DMA_TYPE_BCDMA) { in udma_dbg_summary_show_chan()
5225 seq_printf(s, "bchan%d)\n", uc->bchan->id); in udma_dbg_summary_show_chan()
5229 seq_printf(s, "chan%d pair [0x%04x -> 0x%04x], ", uc->tchan->id, in udma_dbg_summary_show_chan()
5230 ucc->src_thread, ucc->dst_thread); in udma_dbg_summary_show_chan()
5233 seq_printf(s, "rchan%d [0x%04x -> 0x%04x], ", uc->rchan->id, in udma_dbg_summary_show_chan()
5234 ucc->src_thread, ucc->dst_thread); in udma_dbg_summary_show_chan()
5235 if (uc->ud->match_data->type == DMA_TYPE_PKTDMA) in udma_dbg_summary_show_chan()
5236 seq_printf(s, "rflow%d, ", uc->rflow->id); in udma_dbg_summary_show_chan()
5239 seq_printf(s, "tchan%d [0x%04x -> 0x%04x], ", uc->tchan->id, in udma_dbg_summary_show_chan()
5240 ucc->src_thread, ucc->dst_thread); in udma_dbg_summary_show_chan()
5241 if (uc->ud->match_data->type == DMA_TYPE_PKTDMA) in udma_dbg_summary_show_chan()
5242 seq_printf(s, "tflow%d, ", uc->tchan->tflow_id); in udma_dbg_summary_show_chan()
5249 if (ucc->ep_type == PSIL_EP_NATIVE) { in udma_dbg_summary_show_chan()
5250 seq_printf(s, "PSI-L Native"); in udma_dbg_summary_show_chan()
5251 if (ucc->metadata_size) { in udma_dbg_summary_show_chan()
5252 seq_printf(s, "[%s", ucc->needs_epib ? " EPIB" : ""); in udma_dbg_summary_show_chan()
5253 if (ucc->psd_size) in udma_dbg_summary_show_chan()
5254 seq_printf(s, " PSDsize:%u", ucc->psd_size); in udma_dbg_summary_show_chan()
5259 if (ucc->enable_acc32 || ucc->enable_burst) in udma_dbg_summary_show_chan()
5261 ucc->enable_acc32 ? " ACC32" : "", in udma_dbg_summary_show_chan()
5262 ucc->enable_burst ? " BURST" : ""); in udma_dbg_summary_show_chan()
5265 seq_printf(s, ", %s)\n", ucc->pkt_mode ? "Packet mode" : "TR mode"); in udma_dbg_summary_show_chan()
5273 list_for_each_entry(chan, &dma_dev->channels, device_node) { in udma_dbg_summary_show()
5274 if (chan->client_count) in udma_dbg_summary_show()
5282 const struct udma_match_data *match_data = ud->match_data; in udma_get_copy_align()
5285 if (!match_data->enable_memcpy_support) in udma_get_copy_align()
5289 if (ud->bchan_cnt) in udma_get_copy_align()
5290 tpl = udma_get_chan_tpl_index(&ud->bchan_tpl, 0); in udma_get_copy_align()
5291 else if (ud->tchan_cnt) in udma_get_copy_align()
5292 tpl = udma_get_chan_tpl_index(&ud->tchan_tpl, 0); in udma_get_copy_align()
5296 switch (match_data->burst_size[tpl]) { in udma_get_copy_align()
5316 struct device_node *navss_node = pdev->dev.parent->of_node; in udma_probe()
5318 struct device *dev = &pdev->dev; in udma_probe()
5330 return -ENOMEM; in udma_probe()
5332 match = of_match_node(udma_of_match, dev->of_node); in udma_probe()
5335 return -ENODEV; in udma_probe()
5337 ud->match_data = match->data; in udma_probe()
5339 ud->soc_data = ud->match_data->soc_data; in udma_probe()
5340 if (!ud->soc_data) { in udma_probe()
5344 return -ENODEV; in udma_probe()
5346 ud->soc_data = soc->data; in udma_probe()
5353 ud->tisci_rm.tisci = ti_sci_get_by_phandle(dev->of_node, "ti,sci"); in udma_probe()
5354 if (IS_ERR(ud->tisci_rm.tisci)) in udma_probe()
5355 return PTR_ERR(ud->tisci_rm.tisci); in udma_probe()
5357 ret = of_property_read_u32(dev->of_node, "ti,sci-dev-id", in udma_probe()
5358 &ud->tisci_rm.tisci_dev_id); in udma_probe()
5360 dev_err(dev, "ti,sci-dev-id read failure %d\n", ret); in udma_probe()
5363 pdev->id = ud->tisci_rm.tisci_dev_id; in udma_probe()
5365 ret = of_property_read_u32(navss_node, "ti,sci-dev-id", in udma_probe()
5366 &ud->tisci_rm.tisci_navss_dev_id); in udma_probe()
5368 dev_err(dev, "NAVSS ti,sci-dev-id read failure %d\n", ret); in udma_probe()
5372 if (ud->match_data->type == DMA_TYPE_UDMA) { in udma_probe()
5373 ret = of_property_read_u32(dev->of_node, "ti,udma-atype", in udma_probe()
5374 &ud->atype); in udma_probe()
5375 if (!ret && ud->atype > 2) { in udma_probe()
5376 dev_err(dev, "Invalid atype: %u\n", ud->atype); in udma_probe()
5377 return -EINVAL; in udma_probe()
5380 ret = of_property_read_u32(dev->of_node, "ti,asel", in udma_probe()
5381 &ud->asel); in udma_probe()
5382 if (!ret && ud->asel > 15) { in udma_probe()
5383 dev_err(dev, "Invalid asel: %u\n", ud->asel); in udma_probe()
5384 return -EINVAL; in udma_probe()
5388 ud->tisci_rm.tisci_udmap_ops = &ud->tisci_rm.tisci->ops.rm_udmap_ops; in udma_probe()
5389 ud->tisci_rm.tisci_psil_ops = &ud->tisci_rm.tisci->ops.rm_psil_ops; in udma_probe()
5391 if (ud->match_data->type == DMA_TYPE_UDMA) { in udma_probe()
5392 ud->ringacc = of_k3_ringacc_get_by_phandle(dev->of_node, "ti,ringacc"); in udma_probe()
5396 ring_init_data.tisci = ud->tisci_rm.tisci; in udma_probe()
5397 ring_init_data.tisci_dev_id = ud->tisci_rm.tisci_dev_id; in udma_probe()
5398 if (ud->match_data->type == DMA_TYPE_BCDMA) { in udma_probe()
5399 ring_init_data.num_rings = ud->bchan_cnt + in udma_probe()
5400 ud->tchan_cnt + in udma_probe()
5401 ud->rchan_cnt; in udma_probe()
5403 ring_init_data.num_rings = ud->rflow_cnt + in udma_probe()
5404 ud->tflow_cnt; in udma_probe()
5407 ud->ringacc = k3_ringacc_dmarings_init(pdev, &ring_init_data); in udma_probe()
5410 if (IS_ERR(ud->ringacc)) in udma_probe()
5411 return PTR_ERR(ud->ringacc); in udma_probe()
5413 dev->msi.domain = of_msi_get_domain(dev, dev->of_node, in udma_probe()
5415 if (!dev->msi.domain) { in udma_probe()
5416 return -EPROBE_DEFER; in udma_probe()
5419 dma_cap_set(DMA_SLAVE, ud->ddev.cap_mask); in udma_probe()
5421 if (ud->match_data->type != DMA_TYPE_PKTDMA) { in udma_probe()
5422 dma_cap_set(DMA_CYCLIC, ud->ddev.cap_mask); in udma_probe()
5423 ud->ddev.device_prep_dma_cyclic = udma_prep_dma_cyclic; in udma_probe()
5426 ud->ddev.device_config = udma_slave_config; in udma_probe()
5427 ud->ddev.device_prep_slave_sg = udma_prep_slave_sg; in udma_probe()
5428 ud->ddev.device_issue_pending = udma_issue_pending; in udma_probe()
5429 ud->ddev.device_tx_status = udma_tx_status; in udma_probe()
5430 ud->ddev.device_pause = udma_pause; in udma_probe()
5431 ud->ddev.device_resume = udma_resume; in udma_probe()
5432 ud->ddev.device_terminate_all = udma_terminate_all; in udma_probe()
5433 ud->ddev.device_synchronize = udma_synchronize; in udma_probe()
5435 ud->ddev.dbg_summary_show = udma_dbg_summary_show; in udma_probe()
5438 switch (ud->match_data->type) { in udma_probe()
5440 ud->ddev.device_alloc_chan_resources = in udma_probe()
5444 ud->ddev.device_alloc_chan_resources = in udma_probe()
5446 ud->ddev.device_router_config = bcdma_router_config; in udma_probe()
5449 ud->ddev.device_alloc_chan_resources = in udma_probe()
5453 return -EINVAL; in udma_probe()
5455 ud->ddev.device_free_chan_resources = udma_free_chan_resources; in udma_probe()
5457 ud->ddev.src_addr_widths = TI_UDMAC_BUSWIDTHS; in udma_probe()
5458 ud->ddev.dst_addr_widths = TI_UDMAC_BUSWIDTHS; in udma_probe()
5459 ud->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); in udma_probe()
5460 ud->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; in udma_probe()
5461 ud->ddev.desc_metadata_modes = DESC_METADATA_CLIENT | in udma_probe()
5463 if (ud->match_data->enable_memcpy_support && in udma_probe()
5464 !(ud->match_data->type == DMA_TYPE_BCDMA && ud->bchan_cnt == 0)) { in udma_probe()
5465 dma_cap_set(DMA_MEMCPY, ud->ddev.cap_mask); in udma_probe()
5466 ud->ddev.device_prep_dma_memcpy = udma_prep_dma_memcpy; in udma_probe()
5467 ud->ddev.directions |= BIT(DMA_MEM_TO_MEM); in udma_probe()
5470 ud->ddev.dev = dev; in udma_probe()
5471 ud->dev = dev; in udma_probe()
5472 ud->psil_base = ud->match_data->psil_base; in udma_probe()
5474 INIT_LIST_HEAD(&ud->ddev.channels); in udma_probe()
5475 INIT_LIST_HEAD(&ud->desc_to_purge); in udma_probe()
5481 spin_lock_init(&ud->lock); in udma_probe()
5482 INIT_WORK(&ud->purge_work, udma_purge_desc_work); in udma_probe()
5484 ud->desc_align = 64; in udma_probe()
5485 if (ud->desc_align < dma_get_cache_alignment()) in udma_probe()
5486 ud->desc_align = dma_get_cache_alignment(); in udma_probe()
5492 for (i = 0; i < ud->bchan_cnt; i++) { in udma_probe()
5493 struct udma_bchan *bchan = &ud->bchans[i]; in udma_probe()
5495 bchan->id = i; in udma_probe()
5496 bchan->reg_rt = ud->mmrs[MMR_BCHANRT] + i * 0x1000; in udma_probe()
5499 for (i = 0; i < ud->tchan_cnt; i++) { in udma_probe()
5500 struct udma_tchan *tchan = &ud->tchans[i]; in udma_probe()
5502 tchan->id = i; in udma_probe()
5503 tchan->reg_rt = ud->mmrs[MMR_TCHANRT] + i * 0x1000; in udma_probe()
5506 for (i = 0; i < ud->rchan_cnt; i++) { in udma_probe()
5507 struct udma_rchan *rchan = &ud->rchans[i]; in udma_probe() local
5509 rchan->id = i; in udma_probe()
5510 rchan->reg_rt = ud->mmrs[MMR_RCHANRT] + i * 0x1000; in udma_probe()
5513 for (i = 0; i < ud->rflow_cnt; i++) { in udma_probe()
5514 struct udma_rflow *rflow = &ud->rflows[i]; in udma_probe()
5516 rflow->id = i; in udma_probe()
5520 struct udma_chan *uc = &ud->channels[i]; in udma_probe()
5522 uc->ud = ud; in udma_probe()
5523 uc->vc.desc_free = udma_desc_free; in udma_probe()
5524 uc->id = i; in udma_probe()
5525 uc->bchan = NULL; in udma_probe()
5526 uc->tchan = NULL; in udma_probe()
5527 uc->rchan = NULL; in udma_probe()
5528 uc->config.remote_thread_id = -1; in udma_probe()
5529 uc->config.mapped_channel_id = -1; in udma_probe()
5530 uc->config.default_flow_id = -1; in udma_probe()
5531 uc->config.dir = DMA_MEM_TO_MEM; in udma_probe()
5532 uc->name = devm_kasprintf(dev, GFP_KERNEL, "%s chan%d", in udma_probe()
5535 vchan_init(&uc->vc, &ud->ddev); in udma_probe()
5537 tasklet_setup(&uc->vc.task, udma_vchan_complete); in udma_probe()
5538 init_completion(&uc->teardown_completed); in udma_probe()
5539 INIT_DELAYED_WORK(&uc->tx_drain.work, udma_check_tx_completion); in udma_probe()
5543 ud->ddev.copy_align = udma_get_copy_align(ud); in udma_probe()
5545 ret = dma_async_device_register(&ud->ddev); in udma_probe()
5553 ret = of_dma_controller_register(dev->of_node, udma_of_xlate, ud); in udma_probe()
5556 dma_async_device_unregister(&ud->ddev); in udma_probe()
5565 struct dma_device *dma_dev = &ud->ddev; in udma_pm_suspend()
5569 list_for_each_entry(chan, &dma_dev->channels, device_node) { in udma_pm_suspend()
5570 if (chan->client_count) { in udma_pm_suspend()
5573 memcpy(&uc->backup_config, &uc->config, in udma_pm_suspend()
5577 ud->ddev.device_free_chan_resources(chan); in udma_pm_suspend()
5587 struct dma_device *dma_dev = &ud->ddev; in udma_pm_resume()
5592 list_for_each_entry(chan, &dma_dev->channels, device_node) { in udma_pm_resume()
5593 if (chan->client_count) { in udma_pm_resume()
5596 memcpy(&uc->config, &uc->backup_config, in udma_pm_resume()
5600 ret = ud->ddev.device_alloc_chan_resources(chan); in udma_pm_resume()
5615 .name = "ti-udma",
5627 #include "k3-udma-private.c"