Lines Matching +full:chan +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/dma-direction.h>
100 char name[32]; member
124 #define chan_number(ch) ((ch->direction == DMA_MEM_TO_DEV) ? \
125 ch->channel : ch->flow)
136 static bool check_config(struct knav_dma_chan *chan, struct knav_dma_cfg *cfg) in check_config() argument
138 if (!memcmp(&chan->cfg, cfg, sizeof(*cfg))) in check_config()
144 static int chan_start(struct knav_dma_chan *chan, in chan_start() argument
149 spin_lock(&chan->lock); in chan_start()
150 if ((chan->direction == DMA_MEM_TO_DEV) && chan->reg_chan) { in chan_start()
151 if (cfg->u.tx.filt_pswords) in chan_start()
153 if (cfg->u.tx.filt_einfo) in chan_start()
155 writel_relaxed(v, &chan->reg_chan->mode); in chan_start()
156 writel_relaxed(DMA_ENABLE, &chan->reg_chan->control); in chan_start()
159 if (chan->reg_tx_sched) in chan_start()
160 writel_relaxed(cfg->u.tx.priority, &chan->reg_tx_sched->prio); in chan_start()
162 if (chan->reg_rx_flow) { in chan_start()
165 if (cfg->u.rx.einfo_present) in chan_start()
167 if (cfg->u.rx.psinfo_present) in chan_start()
169 if (cfg->u.rx.err_mode == DMA_RETRY) in chan_start()
171 v |= (cfg->u.rx.desc_type & DESC_TYPE_MASK) << DESC_TYPE_SHIFT; in chan_start()
172 if (cfg->u.rx.psinfo_at_sop) in chan_start()
174 v |= (cfg->u.rx.sop_offset & CHAN_SOP_OFF_MASK) in chan_start()
176 v |= cfg->u.rx.dst_q & CHAN_QNUM_MASK; in chan_start()
178 writel_relaxed(v, &chan->reg_rx_flow->control); in chan_start()
179 writel_relaxed(0, &chan->reg_rx_flow->tags); in chan_start()
180 writel_relaxed(0, &chan->reg_rx_flow->tag_sel); in chan_start()
182 v = cfg->u.rx.fdq[0] << 16; in chan_start()
183 v |= cfg->u.rx.fdq[1] & CHAN_QNUM_MASK; in chan_start()
184 writel_relaxed(v, &chan->reg_rx_flow->fdq_sel[0]); in chan_start()
186 v = cfg->u.rx.fdq[2] << 16; in chan_start()
187 v |= cfg->u.rx.fdq[3] & CHAN_QNUM_MASK; in chan_start()
188 writel_relaxed(v, &chan->reg_rx_flow->fdq_sel[1]); in chan_start()
190 writel_relaxed(0, &chan->reg_rx_flow->thresh[0]); in chan_start()
191 writel_relaxed(0, &chan->reg_rx_flow->thresh[1]); in chan_start()
192 writel_relaxed(0, &chan->reg_rx_flow->thresh[2]); in chan_start()
196 memcpy(&chan->cfg, cfg, sizeof(*cfg)); in chan_start()
197 spin_unlock(&chan->lock); in chan_start()
202 static int chan_teardown(struct knav_dma_chan *chan) in chan_teardown() argument
206 if (!chan->reg_chan) in chan_teardown()
210 writel_relaxed(DMA_TEARDOWN, &chan->reg_chan->control); in chan_teardown()
215 value = readl_relaxed(&chan->reg_chan->control); in chan_teardown()
220 if (readl_relaxed(&chan->reg_chan->control) & DMA_ENABLE) { in chan_teardown()
221 dev_err(kdev->dev, "timeout waiting for teardown\n"); in chan_teardown()
222 return -ETIMEDOUT; in chan_teardown()
228 static void chan_stop(struct knav_dma_chan *chan) in chan_stop() argument
230 spin_lock(&chan->lock); in chan_stop()
231 if (chan->reg_rx_flow) { in chan_stop()
233 writel_relaxed(0, &chan->reg_rx_flow->fdq_sel[0]); in chan_stop()
234 writel_relaxed(0, &chan->reg_rx_flow->fdq_sel[1]); in chan_stop()
235 writel_relaxed(0, &chan->reg_rx_flow->thresh[0]); in chan_stop()
236 writel_relaxed(0, &chan->reg_rx_flow->thresh[1]); in chan_stop()
237 writel_relaxed(0, &chan->reg_rx_flow->thresh[2]); in chan_stop()
241 chan_teardown(chan); in chan_stop()
244 if (chan->reg_rx_flow) { in chan_stop()
245 writel_relaxed(0, &chan->reg_rx_flow->control); in chan_stop()
246 writel_relaxed(0, &chan->reg_rx_flow->tags); in chan_stop()
247 writel_relaxed(0, &chan->reg_rx_flow->tag_sel); in chan_stop()
250 memset(&chan->cfg, 0, sizeof(struct knav_dma_cfg)); in chan_stop()
251 spin_unlock(&chan->lock); in chan_stop()
253 dev_dbg(kdev->dev, "channel stopped\n"); in chan_stop()
260 for (i = 0; i < dma->max_tx_chan; i++) { in dma_hw_enable_all()
261 writel_relaxed(0, &dma->reg_tx_chan[i].mode); in dma_hw_enable_all()
262 writel_relaxed(DMA_ENABLE, &dma->reg_tx_chan[i].control); in dma_hw_enable_all()
272 spin_lock(&dma->lock); in knav_dma_hw_init()
273 v = dma->loopback ? DMA_LOOPBACK : 0; in knav_dma_hw_init()
274 writel_relaxed(v, &dma->reg_global->emulation_control); in knav_dma_hw_init()
276 v = readl_relaxed(&dma->reg_global->perf_control); in knav_dma_hw_init()
277 v |= ((dma->rx_timeout & DMA_RX_TIMEOUT_MASK) << DMA_RX_TIMEOUT_SHIFT); in knav_dma_hw_init()
278 writel_relaxed(v, &dma->reg_global->perf_control); in knav_dma_hw_init()
280 v = ((dma->tx_priority << DMA_TX_PRIO_SHIFT) | in knav_dma_hw_init()
281 (dma->rx_priority << DMA_RX_PRIO_SHIFT)); in knav_dma_hw_init()
283 writel_relaxed(v, &dma->reg_global->priority_control); in knav_dma_hw_init()
286 for (i = 0; i < dma->max_rx_chan; i++) in knav_dma_hw_init()
287 writel_relaxed(DMA_ENABLE, &dma->reg_rx_chan[i].control); in knav_dma_hw_init()
289 for (i = 0; i < dma->logical_queue_managers; i++) in knav_dma_hw_init()
290 writel_relaxed(dma->qm_base_address[i], in knav_dma_hw_init()
291 &dma->reg_global->qm_base_address[i]); in knav_dma_hw_init()
292 spin_unlock(&dma->lock); in knav_dma_hw_init()
300 spin_lock(&dma->lock); in knav_dma_hw_destroy()
303 for (i = 0; i < dma->max_rx_chan; i++) in knav_dma_hw_destroy()
304 writel_relaxed(v, &dma->reg_rx_chan[i].control); in knav_dma_hw_destroy()
306 for (i = 0; i < dma->max_tx_chan; i++) in knav_dma_hw_destroy()
307 writel_relaxed(v, &dma->reg_tx_chan[i].control); in knav_dma_hw_destroy()
308 spin_unlock(&dma->lock); in knav_dma_hw_destroy()
312 struct knav_dma_chan *chan) in dma_debug_show_channels() argument
317 ((chan->direction == DMA_MEM_TO_DEV) ? "tx chan" : "rx flow"), in dma_debug_show_channels()
318 chan_number(chan)); in dma_debug_show_channels()
320 if (chan->direction == DMA_MEM_TO_DEV) { in dma_debug_show_channels()
321 seq_printf(s, "einfo - %d, pswords - %d, priority - %d\n", in dma_debug_show_channels()
322 chan->cfg.u.tx.filt_einfo, in dma_debug_show_channels()
323 chan->cfg.u.tx.filt_pswords, in dma_debug_show_channels()
324 chan->cfg.u.tx.priority); in dma_debug_show_channels()
326 seq_printf(s, "einfo - %d, psinfo - %d, desc_type - %d\n", in dma_debug_show_channels()
327 chan->cfg.u.rx.einfo_present, in dma_debug_show_channels()
328 chan->cfg.u.rx.psinfo_present, in dma_debug_show_channels()
329 chan->cfg.u.rx.desc_type); in dma_debug_show_channels()
331 chan->cfg.u.rx.dst_q, in dma_debug_show_channels()
332 chan->cfg.u.rx.thresh); in dma_debug_show_channels()
334 seq_printf(s, "[%d]", chan->cfg.u.rx.fdq[i]); in dma_debug_show_channels()
342 struct knav_dma_chan *chan; in dma_debug_show_devices() local
344 list_for_each_entry(chan, &dma->chan_list, list) { in dma_debug_show_devices()
345 if (atomic_read(&chan->ref_count)) in dma_debug_show_devices()
346 dma_debug_show_channels(s, chan); in dma_debug_show_devices()
354 list_for_each_entry(dma, &kdev->list, list) { in knav_dma_debug_show()
355 if (atomic_read(&dma->ref_count)) { in knav_dma_debug_show()
357 dma->name, dma->max_tx_chan, dma->max_rx_flow); in knav_dma_debug_show()
367 static int of_channel_match_helper(struct device_node *np, const char *name, in of_channel_match_helper() argument
374 dma_node = of_parse_phandle(np, "ti,navigator-dmas", 0); in of_channel_match_helper()
376 return -ENODEV; in of_channel_match_helper()
378 *dma_instance = dma_node->name; in of_channel_match_helper()
379 index = of_property_match_string(np, "ti,navigator-dma-names", name); in of_channel_match_helper()
381 dev_err(kdev->dev, "No 'ti,navigator-dma-names' property\n"); in of_channel_match_helper()
382 return -ENODEV; in of_channel_match_helper()
385 if (of_parse_phandle_with_fixed_args(np, "ti,navigator-dmas", in of_channel_match_helper()
387 dev_err(kdev->dev, "Missing the phandle args name %s\n", name); in of_channel_match_helper()
388 return -ENODEV; in of_channel_match_helper()
392 dev_err(kdev->dev, "Missing args for %s\n", name); in of_channel_match_helper()
393 return -ENODEV; in of_channel_match_helper()
400 * knav_dma_open_channel() - try to setup an exclusive slave channel
402 * @name: slave channel name
407 void *knav_dma_open_channel(struct device *dev, const char *name, in knav_dma_open_channel() argument
411 struct knav_dma_chan *chan = NULL, *iter2; in knav_dma_open_channel() local
412 int chan_num = -1; in knav_dma_open_channel()
416 pr_err("keystone-navigator-dma driver not registered\n"); in knav_dma_open_channel()
417 return (void *)-EINVAL; in knav_dma_open_channel()
420 chan_num = of_channel_match_helper(dev->of_node, name, &instance); in knav_dma_open_channel()
422 dev_err(kdev->dev, "No DMA instance with name %s\n", name); in knav_dma_open_channel()
423 return (void *)-EINVAL; in knav_dma_open_channel()
426 dev_dbg(kdev->dev, "initializing %s channel %d from DMA %s\n", in knav_dma_open_channel()
427 config->direction == DMA_MEM_TO_DEV ? "transmit" : in knav_dma_open_channel()
428 config->direction == DMA_DEV_TO_MEM ? "receive" : in knav_dma_open_channel()
431 if (config->direction != DMA_MEM_TO_DEV && in knav_dma_open_channel()
432 config->direction != DMA_DEV_TO_MEM) { in knav_dma_open_channel()
433 dev_err(kdev->dev, "bad direction\n"); in knav_dma_open_channel()
434 return (void *)-EINVAL; in knav_dma_open_channel()
438 list_for_each_entry(iter1, &kdev->list, list) { in knav_dma_open_channel()
439 if (!strcmp(iter1->name, instance)) { in knav_dma_open_channel()
445 dev_err(kdev->dev, "No DMA instance with name %s\n", instance); in knav_dma_open_channel()
446 return (void *)-EINVAL; in knav_dma_open_channel()
450 list_for_each_entry(iter2, &dma->chan_list, list) { in knav_dma_open_channel()
451 if (config->direction == DMA_MEM_TO_DEV) { in knav_dma_open_channel()
452 if (iter2->channel == chan_num) { in knav_dma_open_channel()
453 chan = iter2; in knav_dma_open_channel()
457 if (iter2->flow == chan_num) { in knav_dma_open_channel()
458 chan = iter2; in knav_dma_open_channel()
463 if (!chan) { in knav_dma_open_channel()
464 dev_err(kdev->dev, "channel %d is not in DMA %s\n", in knav_dma_open_channel()
466 return (void *)-EINVAL; in knav_dma_open_channel()
469 if (atomic_read(&chan->ref_count) >= 1) { in knav_dma_open_channel()
470 if (!check_config(chan, config)) { in knav_dma_open_channel()
471 dev_err(kdev->dev, "channel %d config miss-match\n", in knav_dma_open_channel()
473 return (void *)-EINVAL; in knav_dma_open_channel()
477 if (atomic_inc_return(&chan->dma->ref_count) <= 1) in knav_dma_open_channel()
478 knav_dma_hw_init(chan->dma); in knav_dma_open_channel()
480 if (atomic_inc_return(&chan->ref_count) <= 1) in knav_dma_open_channel()
481 chan_start(chan, config); in knav_dma_open_channel()
483 dev_dbg(kdev->dev, "channel %d opened from DMA %s\n", in knav_dma_open_channel()
486 return chan; in knav_dma_open_channel()
491 * knav_dma_close_channel() - Destroy a dma channel
498 struct knav_dma_chan *chan = channel; in knav_dma_close_channel() local
501 pr_err("keystone-navigator-dma driver not registered\n"); in knav_dma_close_channel()
505 if (atomic_dec_return(&chan->ref_count) <= 0) in knav_dma_close_channel()
506 chan_stop(chan); in knav_dma_close_channel()
508 if (atomic_dec_return(&chan->dma->ref_count) <= 0) in knav_dma_close_channel()
509 knav_dma_hw_destroy(chan->dma); in knav_dma_close_channel()
511 dev_dbg(kdev->dev, "channel %d or flow %d closed from DMA %s\n", in knav_dma_close_channel()
512 chan->channel, chan->flow, chan->dma->name); in knav_dma_close_channel()
520 struct device *dev = kdev->dev; in pktdma_get_regs()
532 regs = devm_ioremap_resource(kdev->dev, &res); in pktdma_get_regs()
542 static int pktdma_init_rx_chan(struct knav_dma_chan *chan, u32 flow) in pktdma_init_rx_chan() argument
544 struct knav_dma_device *dma = chan->dma; in pktdma_init_rx_chan()
546 chan->flow = flow; in pktdma_init_rx_chan()
547 chan->reg_rx_flow = dma->reg_rx_flow + flow; in pktdma_init_rx_chan()
548 chan->channel = DMA_INVALID_ID; in pktdma_init_rx_chan()
549 dev_dbg(kdev->dev, "rx flow(%d) (%p)\n", chan->flow, chan->reg_rx_flow); in pktdma_init_rx_chan()
554 static int pktdma_init_tx_chan(struct knav_dma_chan *chan, u32 channel) in pktdma_init_tx_chan() argument
556 struct knav_dma_device *dma = chan->dma; in pktdma_init_tx_chan()
558 chan->channel = channel; in pktdma_init_tx_chan()
559 chan->reg_chan = dma->reg_tx_chan + channel; in pktdma_init_tx_chan()
560 chan->reg_tx_sched = dma->reg_tx_sched + channel; in pktdma_init_tx_chan()
561 chan->flow = DMA_INVALID_ID; in pktdma_init_tx_chan()
562 dev_dbg(kdev->dev, "tx channel(%d) (%p)\n", chan->channel, chan->reg_chan); in pktdma_init_tx_chan()
571 struct device *dev = kdev->dev; in pktdma_init_chan()
572 struct knav_dma_chan *chan; in pktdma_init_chan() local
573 int ret = -EINVAL; in pktdma_init_chan()
575 chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL); in pktdma_init_chan()
576 if (!chan) in pktdma_init_chan()
577 return -ENOMEM; in pktdma_init_chan()
579 INIT_LIST_HEAD(&chan->list); in pktdma_init_chan()
580 chan->dma = dma; in pktdma_init_chan()
581 chan->direction = DMA_TRANS_NONE; in pktdma_init_chan()
582 atomic_set(&chan->ref_count, 0); in pktdma_init_chan()
583 spin_lock_init(&chan->lock); in pktdma_init_chan()
586 chan->direction = dir; in pktdma_init_chan()
587 ret = pktdma_init_tx_chan(chan, chan_num); in pktdma_init_chan()
589 chan->direction = dir; in pktdma_init_chan()
590 ret = pktdma_init_rx_chan(chan, chan_num); in pktdma_init_chan()
595 list_add_tail(&chan->list, &dma->chan_list); in pktdma_init_chan()
610 dma = devm_kzalloc(kdev->dev, sizeof(*dma), GFP_KERNEL); in dma_init()
612 dev_err(kdev->dev, "could not allocate driver mem\n"); in dma_init()
613 return -ENOMEM; in dma_init()
615 INIT_LIST_HEAD(&dma->list); in dma_init()
616 INIT_LIST_HEAD(&dma->chan_list); in dma_init()
618 if (!of_find_property(cloud, "ti,navigator-cloud-address", &len)) { in dma_init()
619 dev_err(kdev->dev, "unspecified navigator cloud addresses\n"); in dma_init()
620 return -ENODEV; in dma_init()
623 dma->logical_queue_managers = len / sizeof(u32); in dma_init()
624 if (dma->logical_queue_managers > DMA_MAX_QMS) { in dma_init()
625 dev_warn(kdev->dev, "too many queue mgrs(>%d) rest ignored\n", in dma_init()
626 dma->logical_queue_managers); in dma_init()
627 dma->logical_queue_managers = DMA_MAX_QMS; in dma_init()
630 ret = of_property_read_u32_array(cloud, "ti,navigator-cloud-address", in dma_init()
631 dma->qm_base_address, in dma_init()
632 dma->logical_queue_managers); in dma_init()
634 dev_err(kdev->dev, "invalid navigator cloud addresses\n"); in dma_init()
635 return -ENODEV; in dma_init()
638 dma->reg_global = pktdma_get_regs(dma, node, 0, &size); in dma_init()
639 if (IS_ERR(dma->reg_global)) in dma_init()
640 return PTR_ERR(dma->reg_global); in dma_init()
642 dev_err(kdev->dev, "bad size %pa for global regs\n", &size); in dma_init()
643 return -ENODEV; in dma_init()
646 dma->reg_tx_chan = pktdma_get_regs(dma, node, 1, &size); in dma_init()
647 if (IS_ERR(dma->reg_tx_chan)) in dma_init()
648 return PTR_ERR(dma->reg_tx_chan); in dma_init()
651 dma->reg_rx_chan = pktdma_get_regs(dma, node, 2, &size); in dma_init()
652 if (IS_ERR(dma->reg_rx_chan)) in dma_init()
653 return PTR_ERR(dma->reg_rx_chan); in dma_init()
656 dma->reg_tx_sched = pktdma_get_regs(dma, node, 3, &size); in dma_init()
657 if (IS_ERR(dma->reg_tx_sched)) in dma_init()
658 return PTR_ERR(dma->reg_tx_sched); in dma_init()
661 dma->reg_rx_flow = pktdma_get_regs(dma, node, 4, &size); in dma_init()
662 if (IS_ERR(dma->reg_rx_flow)) in dma_init()
663 return PTR_ERR(dma->reg_rx_flow); in dma_init()
666 dma->rx_priority = DMA_PRIO_DEFAULT; in dma_init()
667 dma->tx_priority = DMA_PRIO_DEFAULT; in dma_init()
669 dma->enable_all = (of_get_property(node, "ti,enable-all", NULL) != NULL); in dma_init()
670 dma->loopback = (of_get_property(node, "ti,loop-back", NULL) != NULL); in dma_init()
672 ret = of_property_read_u32(node, "ti,rx-retry-timeout", &timeout); in dma_init()
674 dev_dbg(kdev->dev, "unspecified rx timeout using value %d\n", in dma_init()
679 dma->rx_timeout = timeout; in dma_init()
680 dma->max_rx_chan = max_rx_chan; in dma_init()
681 dma->max_rx_flow = max_rx_flow; in dma_init()
682 dma->max_tx_chan = min(max_tx_chan, max_tx_sched); in dma_init()
683 atomic_set(&dma->ref_count, 0); in dma_init()
684 strcpy(dma->name, node->name); in dma_init()
685 spin_lock_init(&dma->lock); in dma_init()
687 for (i = 0; i < dma->max_tx_chan; i++) { in dma_init()
692 for (i = 0; i < dma->max_rx_flow; i++) { in dma_init()
697 list_add_tail(&dma->list, &kdev->list); in dma_init()
703 if (dma->enable_all) { in dma_init()
704 atomic_inc(&dma->ref_count); in dma_init()
709 …dev_info(kdev->dev, "DMA %s registered %d logical channels, flows %d, tx chans: %d, rx chans: %d%s… in dma_init()
710 dma->name, num_chan, dma->max_rx_flow, in dma_init()
711 dma->max_tx_chan, dma->max_rx_chan, in dma_init()
712 dma->loopback ? ", loopback" : ""); in dma_init()
719 struct device *dev = &pdev->dev; in knav_dma_probe()
720 struct device_node *node = pdev->dev.of_node; in knav_dma_probe()
725 dev_err(&pdev->dev, "could not find device info\n"); in knav_dma_probe()
726 return -EINVAL; in knav_dma_probe()
733 return -ENOMEM; in knav_dma_probe()
736 kdev->dev = dev; in knav_dma_probe()
737 INIT_LIST_HEAD(&kdev->list); in knav_dma_probe()
739 pm_runtime_enable(kdev->dev); in knav_dma_probe()
740 ret = pm_runtime_resume_and_get(kdev->dev); in knav_dma_probe()
742 dev_err(kdev->dev, "unable to enable pktdma, err %d\n", ret); in knav_dma_probe()
751 dev_err(&pdev->dev, "init failed with %d\n", ret); in knav_dma_probe()
756 if (list_empty(&kdev->list)) { in knav_dma_probe()
758 ret = -ENODEV; in knav_dma_probe()
769 pm_runtime_put_sync(kdev->dev); in knav_dma_probe()
771 pm_runtime_disable(kdev->dev); in knav_dma_probe()
780 list_for_each_entry(dma, &kdev->list, list) { in knav_dma_remove()
781 if (atomic_dec_return(&dma->ref_count) == 0) in knav_dma_remove()
785 pm_runtime_put_sync(&pdev->dev); in knav_dma_remove()
786 pm_runtime_disable(&pdev->dev); in knav_dma_remove()
792 { .compatible = "ti,keystone-navigator-dma", },
802 .name = "keystone-navigator-dma",