Lines Matching +full:chan +full:- +full:name
20 #include <linux/dma-direction.h>
108 char name[32]; member
132 #define chan_number(ch) ((ch->direction == DMA_MEM_TO_DEV) ? \
133 ch->channel : ch->flow)
144 static bool check_config(struct knav_dma_chan *chan, struct knav_dma_cfg *cfg) in check_config() argument
146 if (!memcmp(&chan->cfg, cfg, sizeof(*cfg))) in check_config()
152 static int chan_start(struct knav_dma_chan *chan, in chan_start() argument
157 spin_lock(&chan->lock); in chan_start()
158 if ((chan->direction == DMA_MEM_TO_DEV) && chan->reg_chan) { in chan_start()
159 if (cfg->u.tx.filt_pswords) in chan_start()
161 if (cfg->u.tx.filt_einfo) in chan_start()
163 writel_relaxed(v, &chan->reg_chan->mode); in chan_start()
164 writel_relaxed(DMA_ENABLE, &chan->reg_chan->control); in chan_start()
167 if (chan->reg_tx_sched) in chan_start()
168 writel_relaxed(cfg->u.tx.priority, &chan->reg_tx_sched->prio); in chan_start()
170 if (chan->reg_rx_flow) { in chan_start()
173 if (cfg->u.rx.einfo_present) in chan_start()
175 if (cfg->u.rx.psinfo_present) in chan_start()
177 if (cfg->u.rx.err_mode == DMA_RETRY) in chan_start()
179 v |= (cfg->u.rx.desc_type & DESC_TYPE_MASK) << DESC_TYPE_SHIFT; in chan_start()
180 if (cfg->u.rx.psinfo_at_sop) in chan_start()
182 v |= (cfg->u.rx.sop_offset & CHAN_SOP_OFF_MASK) in chan_start()
184 v |= cfg->u.rx.dst_q & CHAN_QNUM_MASK; in chan_start()
186 writel_relaxed(v, &chan->reg_rx_flow->control); in chan_start()
187 writel_relaxed(0, &chan->reg_rx_flow->tags); in chan_start()
188 writel_relaxed(0, &chan->reg_rx_flow->tag_sel); in chan_start()
190 v = cfg->u.rx.fdq[0] << 16; in chan_start()
191 v |= cfg->u.rx.fdq[1] & CHAN_QNUM_MASK; in chan_start()
192 writel_relaxed(v, &chan->reg_rx_flow->fdq_sel[0]); in chan_start()
194 v = cfg->u.rx.fdq[2] << 16; in chan_start()
195 v |= cfg->u.rx.fdq[3] & CHAN_QNUM_MASK; in chan_start()
196 writel_relaxed(v, &chan->reg_rx_flow->fdq_sel[1]); in chan_start()
198 writel_relaxed(0, &chan->reg_rx_flow->thresh[0]); in chan_start()
199 writel_relaxed(0, &chan->reg_rx_flow->thresh[1]); in chan_start()
200 writel_relaxed(0, &chan->reg_rx_flow->thresh[2]); in chan_start()
204 memcpy(&chan->cfg, cfg, sizeof(*cfg)); in chan_start()
205 spin_unlock(&chan->lock); in chan_start()
210 static int chan_teardown(struct knav_dma_chan *chan) in chan_teardown() argument
214 if (!chan->reg_chan) in chan_teardown()
218 writel_relaxed(DMA_TEARDOWN, &chan->reg_chan->control); in chan_teardown()
223 value = readl_relaxed(&chan->reg_chan->control); in chan_teardown()
228 if (readl_relaxed(&chan->reg_chan->control) & DMA_ENABLE) { in chan_teardown()
229 dev_err(kdev->dev, "timeout waiting for teardown\n"); in chan_teardown()
230 return -ETIMEDOUT; in chan_teardown()
236 static void chan_stop(struct knav_dma_chan *chan) in chan_stop() argument
238 spin_lock(&chan->lock); in chan_stop()
239 if (chan->reg_rx_flow) { in chan_stop()
241 writel_relaxed(0, &chan->reg_rx_flow->fdq_sel[0]); in chan_stop()
242 writel_relaxed(0, &chan->reg_rx_flow->fdq_sel[1]); in chan_stop()
243 writel_relaxed(0, &chan->reg_rx_flow->thresh[0]); in chan_stop()
244 writel_relaxed(0, &chan->reg_rx_flow->thresh[1]); in chan_stop()
245 writel_relaxed(0, &chan->reg_rx_flow->thresh[2]); in chan_stop()
249 chan_teardown(chan); in chan_stop()
252 if (chan->reg_rx_flow) { in chan_stop()
253 writel_relaxed(0, &chan->reg_rx_flow->control); in chan_stop()
254 writel_relaxed(0, &chan->reg_rx_flow->tags); in chan_stop()
255 writel_relaxed(0, &chan->reg_rx_flow->tag_sel); in chan_stop()
258 memset(&chan->cfg, 0, sizeof(struct knav_dma_cfg)); in chan_stop()
259 spin_unlock(&chan->lock); in chan_stop()
261 dev_dbg(kdev->dev, "channel stopped\n"); in chan_stop()
268 for (i = 0; i < dma->max_tx_chan; i++) { in dma_hw_enable_all()
269 writel_relaxed(0, &dma->reg_tx_chan[i].mode); in dma_hw_enable_all()
270 writel_relaxed(DMA_ENABLE, &dma->reg_tx_chan[i].control); in dma_hw_enable_all()
280 spin_lock(&dma->lock); in knav_dma_hw_init()
281 v = dma->loopback ? DMA_LOOPBACK : 0; in knav_dma_hw_init()
282 writel_relaxed(v, &dma->reg_global->emulation_control); in knav_dma_hw_init()
284 v = readl_relaxed(&dma->reg_global->perf_control); in knav_dma_hw_init()
285 v |= ((dma->rx_timeout & DMA_RX_TIMEOUT_MASK) << DMA_RX_TIMEOUT_SHIFT); in knav_dma_hw_init()
286 writel_relaxed(v, &dma->reg_global->perf_control); in knav_dma_hw_init()
288 v = ((dma->tx_priority << DMA_TX_PRIO_SHIFT) | in knav_dma_hw_init()
289 (dma->rx_priority << DMA_RX_PRIO_SHIFT)); in knav_dma_hw_init()
291 writel_relaxed(v, &dma->reg_global->priority_control); in knav_dma_hw_init()
294 for (i = 0; i < dma->max_rx_chan; i++) in knav_dma_hw_init()
295 writel_relaxed(DMA_ENABLE, &dma->reg_rx_chan[i].control); in knav_dma_hw_init()
297 for (i = 0; i < dma->logical_queue_managers; i++) in knav_dma_hw_init()
298 writel_relaxed(dma->qm_base_address[i], in knav_dma_hw_init()
299 &dma->reg_global->qm_base_address[i]); in knav_dma_hw_init()
300 spin_unlock(&dma->lock); in knav_dma_hw_init()
308 spin_lock(&dma->lock); in knav_dma_hw_destroy()
311 for (i = 0; i < dma->max_rx_chan; i++) in knav_dma_hw_destroy()
312 writel_relaxed(v, &dma->reg_rx_chan[i].control); in knav_dma_hw_destroy()
314 for (i = 0; i < dma->max_tx_chan; i++) in knav_dma_hw_destroy()
315 writel_relaxed(v, &dma->reg_tx_chan[i].control); in knav_dma_hw_destroy()
316 spin_unlock(&dma->lock); in knav_dma_hw_destroy()
320 struct knav_dma_chan *chan) in dma_debug_show_channels() argument
325 ((chan->direction == DMA_MEM_TO_DEV) ? "tx chan" : "rx flow"), in dma_debug_show_channels()
326 chan_number(chan)); in dma_debug_show_channels()
328 if (chan->direction == DMA_MEM_TO_DEV) { in dma_debug_show_channels()
329 seq_printf(s, "einfo - %d, pswords - %d, priority - %d\n", in dma_debug_show_channels()
330 chan->cfg.u.tx.filt_einfo, in dma_debug_show_channels()
331 chan->cfg.u.tx.filt_pswords, in dma_debug_show_channels()
332 chan->cfg.u.tx.priority); in dma_debug_show_channels()
334 seq_printf(s, "einfo - %d, psinfo - %d, desc_type - %d\n", in dma_debug_show_channels()
335 chan->cfg.u.rx.einfo_present, in dma_debug_show_channels()
336 chan->cfg.u.rx.psinfo_present, in dma_debug_show_channels()
337 chan->cfg.u.rx.desc_type); in dma_debug_show_channels()
339 chan->cfg.u.rx.dst_q, in dma_debug_show_channels()
340 chan->cfg.u.rx.thresh); in dma_debug_show_channels()
342 seq_printf(s, "[%d]", chan->cfg.u.rx.fdq[i]); in dma_debug_show_channels()
350 struct knav_dma_chan *chan; in dma_debug_show_devices() local
352 list_for_each_entry(chan, &dma->chan_list, list) { in dma_debug_show_devices()
353 if (atomic_read(&chan->ref_count)) in dma_debug_show_devices()
354 dma_debug_show_channels(s, chan); in dma_debug_show_devices()
362 list_for_each_entry(dma, &kdev->list, list) { in knav_dma_debug_show()
363 if (atomic_read(&dma->ref_count)) { in knav_dma_debug_show()
365 dma->name, dma->max_tx_chan, dma->max_rx_flow); in knav_dma_debug_show()
375 static int of_channel_match_helper(struct device_node *np, const char *name, in of_channel_match_helper() argument
382 dma_node = of_parse_phandle(np, "ti,navigator-dmas", 0); in of_channel_match_helper()
384 return -ENODEV; in of_channel_match_helper()
386 *dma_instance = dma_node->name; in of_channel_match_helper()
387 index = of_property_match_string(np, "ti,navigator-dma-names", name); in of_channel_match_helper()
389 dev_err(kdev->dev, "No 'ti,navigator-dma-names' property\n"); in of_channel_match_helper()
390 return -ENODEV; in of_channel_match_helper()
393 if (of_parse_phandle_with_fixed_args(np, "ti,navigator-dmas", in of_channel_match_helper()
395 dev_err(kdev->dev, "Missing the phandle args name %s\n", name); in of_channel_match_helper()
396 return -ENODEV; in of_channel_match_helper()
400 dev_err(kdev->dev, "Missing args for %s\n", name); in of_channel_match_helper()
401 return -ENODEV; in of_channel_match_helper()
408 * knav_dma_open_channel() - try to setup an exclusive slave channel
410 * @name: slave channel name
415 void *knav_dma_open_channel(struct device *dev, const char *name, in knav_dma_open_channel() argument
418 struct knav_dma_chan *chan; in knav_dma_open_channel() local
421 int chan_num = -1; in knav_dma_open_channel()
425 pr_err("keystone-navigator-dma driver not registered\n"); in knav_dma_open_channel()
426 return (void *)-EINVAL; in knav_dma_open_channel()
429 chan_num = of_channel_match_helper(dev->of_node, name, &instance); in knav_dma_open_channel()
431 dev_err(kdev->dev, "No DMA instance with name %s\n", name); in knav_dma_open_channel()
432 return (void *)-EINVAL; in knav_dma_open_channel()
435 dev_dbg(kdev->dev, "initializing %s channel %d from DMA %s\n", in knav_dma_open_channel()
436 config->direction == DMA_MEM_TO_DEV ? "transmit" : in knav_dma_open_channel()
437 config->direction == DMA_DEV_TO_MEM ? "receive" : in knav_dma_open_channel()
440 if (config->direction != DMA_MEM_TO_DEV && in knav_dma_open_channel()
441 config->direction != DMA_DEV_TO_MEM) { in knav_dma_open_channel()
442 dev_err(kdev->dev, "bad direction\n"); in knav_dma_open_channel()
443 return (void *)-EINVAL; in knav_dma_open_channel()
447 list_for_each_entry(dma, &kdev->list, list) { in knav_dma_open_channel()
448 if (!strcmp(dma->name, instance)) { in knav_dma_open_channel()
454 dev_err(kdev->dev, "No DMA instance with name %s\n", instance); in knav_dma_open_channel()
455 return (void *)-EINVAL; in knav_dma_open_channel()
460 list_for_each_entry(chan, &dma->chan_list, list) { in knav_dma_open_channel()
461 if (config->direction == DMA_MEM_TO_DEV) { in knav_dma_open_channel()
462 if (chan->channel == chan_num) { in knav_dma_open_channel()
467 if (chan->flow == chan_num) { in knav_dma_open_channel()
474 dev_err(kdev->dev, "channel %d is not in DMA %s\n", in knav_dma_open_channel()
476 return (void *)-EINVAL; in knav_dma_open_channel()
479 if (atomic_read(&chan->ref_count) >= 1) { in knav_dma_open_channel()
480 if (!check_config(chan, config)) { in knav_dma_open_channel()
481 dev_err(kdev->dev, "channel %d config miss-match\n", in knav_dma_open_channel()
483 return (void *)-EINVAL; in knav_dma_open_channel()
487 if (atomic_inc_return(&chan->dma->ref_count) <= 1) in knav_dma_open_channel()
488 knav_dma_hw_init(chan->dma); in knav_dma_open_channel()
490 if (atomic_inc_return(&chan->ref_count) <= 1) in knav_dma_open_channel()
491 chan_start(chan, config); in knav_dma_open_channel()
493 dev_dbg(kdev->dev, "channel %d opened from DMA %s\n", in knav_dma_open_channel()
496 return chan; in knav_dma_open_channel()
501 * knav_dma_close_channel() - Destroy a dma channel
508 struct knav_dma_chan *chan = channel; in knav_dma_close_channel() local
511 pr_err("keystone-navigator-dma driver not registered\n"); in knav_dma_close_channel()
515 if (atomic_dec_return(&chan->ref_count) <= 0) in knav_dma_close_channel()
516 chan_stop(chan); in knav_dma_close_channel()
518 if (atomic_dec_return(&chan->dma->ref_count) <= 0) in knav_dma_close_channel()
519 knav_dma_hw_destroy(chan->dma); in knav_dma_close_channel()
521 dev_dbg(kdev->dev, "channel %d or flow %d closed from DMA %s\n", in knav_dma_close_channel()
522 chan->channel, chan->flow, chan->dma->name); in knav_dma_close_channel()
530 struct device *dev = kdev->dev; in pktdma_get_regs()
542 regs = devm_ioremap_resource(kdev->dev, &res); in pktdma_get_regs()
552 static int pktdma_init_rx_chan(struct knav_dma_chan *chan, u32 flow) in pktdma_init_rx_chan() argument
554 struct knav_dma_device *dma = chan->dma; in pktdma_init_rx_chan()
556 chan->flow = flow; in pktdma_init_rx_chan()
557 chan->reg_rx_flow = dma->reg_rx_flow + flow; in pktdma_init_rx_chan()
558 chan->channel = DMA_INVALID_ID; in pktdma_init_rx_chan()
559 dev_dbg(kdev->dev, "rx flow(%d) (%p)\n", chan->flow, chan->reg_rx_flow); in pktdma_init_rx_chan()
564 static int pktdma_init_tx_chan(struct knav_dma_chan *chan, u32 channel) in pktdma_init_tx_chan() argument
566 struct knav_dma_device *dma = chan->dma; in pktdma_init_tx_chan()
568 chan->channel = channel; in pktdma_init_tx_chan()
569 chan->reg_chan = dma->reg_tx_chan + channel; in pktdma_init_tx_chan()
570 chan->reg_tx_sched = dma->reg_tx_sched + channel; in pktdma_init_tx_chan()
571 chan->flow = DMA_INVALID_ID; in pktdma_init_tx_chan()
572 dev_dbg(kdev->dev, "tx channel(%d) (%p)\n", chan->channel, chan->reg_chan); in pktdma_init_tx_chan()
581 struct device *dev = kdev->dev; in pktdma_init_chan()
582 struct knav_dma_chan *chan; in pktdma_init_chan() local
583 int ret = -EINVAL; in pktdma_init_chan()
585 chan = devm_kzalloc(dev, sizeof(*chan), GFP_KERNEL); in pktdma_init_chan()
586 if (!chan) in pktdma_init_chan()
587 return -ENOMEM; in pktdma_init_chan()
589 INIT_LIST_HEAD(&chan->list); in pktdma_init_chan()
590 chan->dma = dma; in pktdma_init_chan()
591 chan->direction = DMA_TRANS_NONE; in pktdma_init_chan()
592 atomic_set(&chan->ref_count, 0); in pktdma_init_chan()
593 spin_lock_init(&chan->lock); in pktdma_init_chan()
596 chan->direction = dir; in pktdma_init_chan()
597 ret = pktdma_init_tx_chan(chan, chan_num); in pktdma_init_chan()
599 chan->direction = dir; in pktdma_init_chan()
600 ret = pktdma_init_rx_chan(chan, chan_num); in pktdma_init_chan()
605 list_add_tail(&chan->list, &dma->chan_list); in pktdma_init_chan()
620 dma = devm_kzalloc(kdev->dev, sizeof(*dma), GFP_KERNEL); in dma_init()
622 dev_err(kdev->dev, "could not allocate driver mem\n"); in dma_init()
623 return -ENOMEM; in dma_init()
625 INIT_LIST_HEAD(&dma->list); in dma_init()
626 INIT_LIST_HEAD(&dma->chan_list); in dma_init()
628 if (!of_find_property(cloud, "ti,navigator-cloud-address", &len)) { in dma_init()
629 dev_err(kdev->dev, "unspecified navigator cloud addresses\n"); in dma_init()
630 return -ENODEV; in dma_init()
633 dma->logical_queue_managers = len / sizeof(u32); in dma_init()
634 if (dma->logical_queue_managers > DMA_MAX_QMS) { in dma_init()
635 dev_warn(kdev->dev, "too many queue mgrs(>%d) rest ignored\n", in dma_init()
636 dma->logical_queue_managers); in dma_init()
637 dma->logical_queue_managers = DMA_MAX_QMS; in dma_init()
640 ret = of_property_read_u32_array(cloud, "ti,navigator-cloud-address", in dma_init()
641 dma->qm_base_address, in dma_init()
642 dma->logical_queue_managers); in dma_init()
644 dev_err(kdev->dev, "invalid navigator cloud addresses\n"); in dma_init()
645 return -ENODEV; in dma_init()
648 dma->reg_global = pktdma_get_regs(dma, node, 0, &size); in dma_init()
649 if (!dma->reg_global) in dma_init()
650 return -ENODEV; in dma_init()
652 dev_err(kdev->dev, "bad size %pa for global regs\n", &size); in dma_init()
653 return -ENODEV; in dma_init()
656 dma->reg_tx_chan = pktdma_get_regs(dma, node, 1, &size); in dma_init()
657 if (!dma->reg_tx_chan) in dma_init()
658 return -ENODEV; in dma_init()
661 dma->reg_rx_chan = pktdma_get_regs(dma, node, 2, &size); in dma_init()
662 if (!dma->reg_rx_chan) in dma_init()
663 return -ENODEV; in dma_init()
666 dma->reg_tx_sched = pktdma_get_regs(dma, node, 3, &size); in dma_init()
667 if (!dma->reg_tx_sched) in dma_init()
668 return -ENODEV; in dma_init()
671 dma->reg_rx_flow = pktdma_get_regs(dma, node, 4, &size); in dma_init()
672 if (!dma->reg_rx_flow) in dma_init()
673 return -ENODEV; in dma_init()
676 dma->rx_priority = DMA_PRIO_DEFAULT; in dma_init()
677 dma->tx_priority = DMA_PRIO_DEFAULT; in dma_init()
679 dma->enable_all = (of_get_property(node, "ti,enable-all", NULL) != NULL); in dma_init()
680 dma->loopback = (of_get_property(node, "ti,loop-back", NULL) != NULL); in dma_init()
682 ret = of_property_read_u32(node, "ti,rx-retry-timeout", &timeout); in dma_init()
684 dev_dbg(kdev->dev, "unspecified rx timeout using value %d\n", in dma_init()
689 dma->rx_timeout = timeout; in dma_init()
690 dma->max_rx_chan = max_rx_chan; in dma_init()
691 dma->max_rx_flow = max_rx_flow; in dma_init()
692 dma->max_tx_chan = min(max_tx_chan, max_tx_sched); in dma_init()
693 atomic_set(&dma->ref_count, 0); in dma_init()
694 strcpy(dma->name, node->name); in dma_init()
695 spin_lock_init(&dma->lock); in dma_init()
697 for (i = 0; i < dma->max_tx_chan; i++) { in dma_init()
702 for (i = 0; i < dma->max_rx_flow; i++) { in dma_init()
707 list_add_tail(&dma->list, &kdev->list); in dma_init()
713 if (dma->enable_all) { in dma_init()
714 atomic_inc(&dma->ref_count); in dma_init()
719 …dev_info(kdev->dev, "DMA %s registered %d logical channels, flows %d, tx chans: %d, rx chans: %d%s… in dma_init()
720 dma->name, num_chan, dma->max_rx_flow, in dma_init()
721 dma->max_tx_chan, dma->max_rx_chan, in dma_init()
722 dma->loopback ? ", loopback" : ""); in dma_init()
729 struct device *dev = &pdev->dev; in knav_dma_probe()
730 struct device_node *node = pdev->dev.of_node; in knav_dma_probe()
735 dev_err(&pdev->dev, "could not find device info\n"); in knav_dma_probe()
736 return -EINVAL; in knav_dma_probe()
743 return -ENOMEM; in knav_dma_probe()
746 kdev->dev = dev; in knav_dma_probe()
747 INIT_LIST_HEAD(&kdev->list); in knav_dma_probe()
749 pm_runtime_enable(kdev->dev); in knav_dma_probe()
750 ret = pm_runtime_get_sync(kdev->dev); in knav_dma_probe()
752 pm_runtime_put_noidle(kdev->dev); in knav_dma_probe()
753 dev_err(kdev->dev, "unable to enable pktdma, err %d\n", ret); in knav_dma_probe()
761 dev_err(&pdev->dev, "init failed with %d\n", ret); in knav_dma_probe()
766 if (list_empty(&kdev->list)) { in knav_dma_probe()
768 ret = -ENODEV; in knav_dma_probe()
779 pm_runtime_put_sync(kdev->dev); in knav_dma_probe()
781 pm_runtime_disable(kdev->dev); in knav_dma_probe()
790 list_for_each_entry(dma, &kdev->list, list) { in knav_dma_remove()
791 if (atomic_dec_return(&dma->ref_count) == 0) in knav_dma_remove()
795 pm_runtime_put_sync(&pdev->dev); in knav_dma_remove()
796 pm_runtime_disable(&pdev->dev); in knav_dma_remove()
802 { .compatible = "ti,keystone-navigator-dma", },
812 .name = "keystone-navigator-dma",