Lines Matching +full:smmu +full:- +full:v2

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2015-2016 Marvell International Ltd.
8 #include <linux/dma-mapping.h>
95 * struct mv_xor_v2_descriptor - DMA HW descriptor
101 * @fill_pattern_src_addr: Fill-Pattern or Source-Address and
102 * AW-Attributes
117 #define DESC_OP_MODE_MEMCPY 1 /* Pure-DMA operation */
118 #define DESC_OP_MODE_MEMSET 2 /* Mem-Fill operation */
119 #define DESC_OP_MODE_MEMINIT 3 /* Mem-Init operation */
120 #define DESC_OP_MODE_MEM_COMPARE 4 /* Mem-Compare operation */
123 #define DESC_OP_MODE_RAID6 7 /* RAID6 P&Q-generation */
136 * struct mv_xor_v2_device - implements a xor device
142 * @irq_tasklet: tasklet used for IRQ handling call-backs
175 * struct mv_xor_v2_sw_desc - implements a xor SW descriptor
203 * First word: Buffer-DX-Address-Low[31:0] in mv_xor_v2_set_data_buffers()
204 * Second word: Buffer-DX+1-Address-Low[31:0] in mv_xor_v2_set_data_buffers()
205 * Third word: DX+1-Buffer-Address-High[47:32] [31:16] in mv_xor_v2_set_data_buffers()
206 * DX-Buffer-Address-High[47:32] [15:0] in mv_xor_v2_set_data_buffers()
209 desc->data_buff_addr[arr_index] = lower_32_bits(src); in mv_xor_v2_set_data_buffers()
211 desc->data_buff_addr[arr_index + 2] &= ~0xFFFF; in mv_xor_v2_set_data_buffers()
212 desc->data_buff_addr[arr_index + 2] |= in mv_xor_v2_set_data_buffers()
215 desc->data_buff_addr[arr_index + 1] = in mv_xor_v2_set_data_buffers()
218 desc->data_buff_addr[arr_index + 2] &= ~0xFFFF0000; in mv_xor_v2_set_data_buffers()
219 desc->data_buff_addr[arr_index + 2] |= in mv_xor_v2_set_data_buffers()
231 writel(num_of_desc, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_ADD_OFF); in mv_xor_v2_add_desc_to_desq()
241 writel(num_of_desc, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_DEALLOC_OFF); in mv_xor_v2_free_desc_from_desq()
251 xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_CTRL_OFF); in mv_xor_v2_set_desc_size()
265 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_THRD_OFF); in mv_xor_v2_enable_imsg_thrd()
269 writel(reg, xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_THRD_OFF); in mv_xor_v2_enable_imsg_thrd()
272 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_TMOT); in mv_xor_v2_enable_imsg_thrd()
275 writel(reg, xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_TMOT); in mv_xor_v2_enable_imsg_thrd()
284 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_DONE_OFF); in mv_xor_v2_interrupt_handler()
294 tasklet_schedule(&xor_dev->irq_tasklet); in mv_xor_v2_interrupt_handler()
310 container_of(tx->chan, struct mv_xor_v2_device, dmachan); in mv_xor_v2_tx_submit()
312 dev_dbg(xor_dev->dmadev.dev, in mv_xor_v2_tx_submit()
314 __func__, sw_desc, &sw_desc->async_tx); in mv_xor_v2_tx_submit()
317 spin_lock_bh(&xor_dev->lock); in mv_xor_v2_tx_submit()
321 dest_hw_desc = xor_dev->hw_desq_virt + xor_dev->hw_queue_idx; in mv_xor_v2_tx_submit()
323 memcpy(dest_hw_desc, &sw_desc->hw_desc, xor_dev->desc_size); in mv_xor_v2_tx_submit()
325 xor_dev->npendings++; in mv_xor_v2_tx_submit()
326 xor_dev->hw_queue_idx++; in mv_xor_v2_tx_submit()
327 if (xor_dev->hw_queue_idx >= MV_XOR_V2_DESC_NUM) in mv_xor_v2_tx_submit()
328 xor_dev->hw_queue_idx = 0; in mv_xor_v2_tx_submit()
330 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_tx_submit()
345 spin_lock_bh(&xor_dev->lock); in mv_xor_v2_prep_sw_desc()
347 if (list_empty(&xor_dev->free_sw_desc)) { in mv_xor_v2_prep_sw_desc()
348 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_prep_sw_desc()
350 tasklet_schedule(&xor_dev->irq_tasklet); in mv_xor_v2_prep_sw_desc()
354 list_for_each_entry(sw_desc, &xor_dev->free_sw_desc, free_list) { in mv_xor_v2_prep_sw_desc()
355 if (async_tx_test_ack(&sw_desc->async_tx)) { in mv_xor_v2_prep_sw_desc()
362 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_prep_sw_desc()
366 list_del(&sw_desc->free_list); in mv_xor_v2_prep_sw_desc()
369 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_prep_sw_desc()
387 dev_dbg(xor_dev->dmadev.dev, in mv_xor_v2_prep_dma_memcpy()
395 sw_desc->async_tx.flags = flags; in mv_xor_v2_prep_dma_memcpy()
398 hw_descriptor = &sw_desc->hw_desc; in mv_xor_v2_prep_dma_memcpy()
401 hw_descriptor->desc_id = sw_desc->idx; in mv_xor_v2_prep_dma_memcpy()
404 hw_descriptor->desc_ctrl = in mv_xor_v2_prep_dma_memcpy()
408 hw_descriptor->desc_ctrl |= DESC_IOD; in mv_xor_v2_prep_dma_memcpy()
411 hw_descriptor->fill_pattern_src_addr[0] = lower_32_bits(src); in mv_xor_v2_prep_dma_memcpy()
412 hw_descriptor->fill_pattern_src_addr[1] = in mv_xor_v2_prep_dma_memcpy()
416 hw_descriptor->fill_pattern_src_addr[2] = lower_32_bits(dest); in mv_xor_v2_prep_dma_memcpy()
417 hw_descriptor->fill_pattern_src_addr[3] = in mv_xor_v2_prep_dma_memcpy()
421 hw_descriptor->buff_size = len; in mv_xor_v2_prep_dma_memcpy()
424 return &sw_desc->async_tx; in mv_xor_v2_prep_dma_memcpy()
443 dev_dbg(xor_dev->dmadev.dev, in mv_xor_v2_prep_dma_xor()
451 sw_desc->async_tx.flags = flags; in mv_xor_v2_prep_dma_xor()
454 hw_descriptor = &sw_desc->hw_desc; in mv_xor_v2_prep_dma_xor()
457 hw_descriptor->desc_id = sw_desc->idx; in mv_xor_v2_prep_dma_xor()
460 hw_descriptor->desc_ctrl = in mv_xor_v2_prep_dma_xor()
462 hw_descriptor->desc_ctrl |= DESC_P_BUFFER_ENABLE; in mv_xor_v2_prep_dma_xor()
465 hw_descriptor->desc_ctrl |= DESC_IOD; in mv_xor_v2_prep_dma_xor()
471 hw_descriptor->desc_ctrl |= in mv_xor_v2_prep_dma_xor()
475 hw_descriptor->fill_pattern_src_addr[2] = lower_32_bits(dest); in mv_xor_v2_prep_dma_xor()
476 hw_descriptor->fill_pattern_src_addr[3] = in mv_xor_v2_prep_dma_xor()
480 hw_descriptor->buff_size = len; in mv_xor_v2_prep_dma_xor()
483 return &sw_desc->async_tx; in mv_xor_v2_prep_dma_xor()
502 hw_descriptor = &sw_desc->hw_desc; in mv_xor_v2_prep_dma_interrupt()
505 hw_descriptor->desc_id = sw_desc->idx; in mv_xor_v2_prep_dma_interrupt()
508 hw_descriptor->desc_ctrl = in mv_xor_v2_prep_dma_interrupt()
510 hw_descriptor->desc_ctrl |= DESC_IOD; in mv_xor_v2_prep_dma_interrupt()
513 return &sw_desc->async_tx; in mv_xor_v2_prep_dma_interrupt()
524 spin_lock_bh(&xor_dev->lock); in mv_xor_v2_issue_pending()
530 mv_xor_v2_add_desc_to_desq(xor_dev, xor_dev->npendings); in mv_xor_v2_issue_pending()
531 xor_dev->npendings = 0; in mv_xor_v2_issue_pending()
533 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_issue_pending()
542 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_DONE_OFF); in mv_xor_v2_get_pending_params()
563 dev_dbg(xor_dev->dmadev.dev, "%s %d\n", __func__, __LINE__); in mv_xor_v2_tasklet()
571 xor_dev->hw_desq_virt + pending_ptr; in mv_xor_v2_tasklet()
575 &xor_dev->sw_desq[next_pending_hw_desc->desc_id]; in mv_xor_v2_tasklet()
578 if (next_pending_sw_desc->async_tx.cookie > 0) { in mv_xor_v2_tasklet()
580 * update the channel's completed cookie - no in mv_xor_v2_tasklet()
584 dma_cookie_complete(&next_pending_sw_desc->async_tx); in mv_xor_v2_tasklet()
586 dma_descriptor_unmap(&next_pending_sw_desc->async_tx); in mv_xor_v2_tasklet()
588 &next_pending_sw_desc->async_tx, NULL); in mv_xor_v2_tasklet()
591 dma_run_dependencies(&next_pending_sw_desc->async_tx); in mv_xor_v2_tasklet()
594 spin_lock_bh(&xor_dev->lock); in mv_xor_v2_tasklet()
597 list_add(&next_pending_sw_desc->free_list, in mv_xor_v2_tasklet()
598 &xor_dev->free_sw_desc); in mv_xor_v2_tasklet()
601 spin_unlock_bh(&xor_dev->lock); in mv_xor_v2_tasklet()
616 * Set DMA Interrupt-message (IMSG) parameters
620 struct mv_xor_v2_device *xor_dev = dev_get_drvdata(desc->dev); in mv_xor_v2_set_msi_msg()
622 writel(msg->address_lo, in mv_xor_v2_set_msi_msg()
623 xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_BALR_OFF); in mv_xor_v2_set_msi_msg()
624 writel(msg->address_hi & 0xFFFF, in mv_xor_v2_set_msi_msg()
625 xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_BAHR_OFF); in mv_xor_v2_set_msi_msg()
626 writel(msg->data, in mv_xor_v2_set_msi_msg()
627 xor_dev->dma_base + MV_XOR_V2_DMA_IMSG_CDAT_OFF); in mv_xor_v2_set_msi_msg()
636 xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_SIZE_OFF); in mv_xor_v2_descq_init()
639 writel(lower_32_bits(xor_dev->hw_desq), in mv_xor_v2_descq_init()
640 xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_BALR_OFF); in mv_xor_v2_descq_init()
641 writel(upper_32_bits(xor_dev->hw_desq), in mv_xor_v2_descq_init()
642 xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_BAHR_OFF); in mv_xor_v2_descq_init()
646 * SMMU. Set the attributes for reading & writing data buffers in mv_xor_v2_descq_init()
649 * - OuterShareable - Snoops will be performed on CPU caches in mv_xor_v2_descq_init()
650 * - Enable cacheable - Bufferable, Modifiable, Other Allocate in mv_xor_v2_descq_init()
653 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_ARATTR_OFF); in mv_xor_v2_descq_init()
657 writel(reg, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_ARATTR_OFF); in mv_xor_v2_descq_init()
659 reg = readl(xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_AWATTR_OFF); in mv_xor_v2_descq_init()
663 writel(reg, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_AWATTR_OFF); in mv_xor_v2_descq_init()
665 /* BW CTRL - set values to optimize the XOR performance: in mv_xor_v2_descq_init()
667 * - Set WrBurstLen & RdBurstLen - the unit will issue in mv_xor_v2_descq_init()
669 * - Limit the number of outstanding write & read data in mv_xor_v2_descq_init()
680 writel(reg, xor_dev->glob_base + MV_XOR_V2_GLOB_BW_CTRL); in mv_xor_v2_descq_init()
683 reg = readl(xor_dev->glob_base + MV_XOR_V2_GLOB_PAUSE); in mv_xor_v2_descq_init()
685 writel(reg, xor_dev->glob_base + MV_XOR_V2_GLOB_PAUSE); in mv_xor_v2_descq_init()
688 writel(0, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_STOP_OFF); in mv_xor_v2_descq_init()
698 writel(0x1, xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_STOP_OFF); in mv_xor_v2_suspend()
726 xor_dev = devm_kzalloc(&pdev->dev, sizeof(*xor_dev), GFP_KERNEL); in mv_xor_v2_probe()
728 return -ENOMEM; in mv_xor_v2_probe()
731 xor_dev->dma_base = devm_ioremap_resource(&pdev->dev, res); in mv_xor_v2_probe()
732 if (IS_ERR(xor_dev->dma_base)) in mv_xor_v2_probe()
733 return PTR_ERR(xor_dev->dma_base); in mv_xor_v2_probe()
736 xor_dev->glob_base = devm_ioremap_resource(&pdev->dev, res); in mv_xor_v2_probe()
737 if (IS_ERR(xor_dev->glob_base)) in mv_xor_v2_probe()
738 return PTR_ERR(xor_dev->glob_base); in mv_xor_v2_probe()
742 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); in mv_xor_v2_probe()
746 xor_dev->reg_clk = devm_clk_get(&pdev->dev, "reg"); in mv_xor_v2_probe()
747 if (PTR_ERR(xor_dev->reg_clk) != -ENOENT) { in mv_xor_v2_probe()
748 if (!IS_ERR(xor_dev->reg_clk)) { in mv_xor_v2_probe()
749 ret = clk_prepare_enable(xor_dev->reg_clk); in mv_xor_v2_probe()
753 return PTR_ERR(xor_dev->reg_clk); in mv_xor_v2_probe()
757 xor_dev->clk = devm_clk_get(&pdev->dev, NULL); in mv_xor_v2_probe()
758 if (PTR_ERR(xor_dev->clk) == -EPROBE_DEFER) { in mv_xor_v2_probe()
762 if (!IS_ERR(xor_dev->clk)) { in mv_xor_v2_probe()
763 ret = clk_prepare_enable(xor_dev->clk); in mv_xor_v2_probe()
768 ret = platform_msi_domain_alloc_irqs(&pdev->dev, 1, in mv_xor_v2_probe()
773 msi_desc = first_msi_entry(&pdev->dev); in mv_xor_v2_probe()
776 xor_dev->msi_desc = msi_desc; in mv_xor_v2_probe()
778 ret = devm_request_irq(&pdev->dev, msi_desc->irq, in mv_xor_v2_probe()
780 dev_name(&pdev->dev), xor_dev); in mv_xor_v2_probe()
784 tasklet_setup(&xor_dev->irq_tasklet, mv_xor_v2_tasklet); in mv_xor_v2_probe()
786 xor_dev->desc_size = mv_xor_v2_set_desc_size(xor_dev); in mv_xor_v2_probe()
788 dma_cookie_init(&xor_dev->dmachan); in mv_xor_v2_probe()
795 xor_dev->hw_desq_virt = in mv_xor_v2_probe()
796 dma_alloc_coherent(&pdev->dev, in mv_xor_v2_probe()
797 xor_dev->desc_size * MV_XOR_V2_DESC_NUM, in mv_xor_v2_probe()
798 &xor_dev->hw_desq, GFP_KERNEL); in mv_xor_v2_probe()
799 if (!xor_dev->hw_desq_virt) { in mv_xor_v2_probe()
800 ret = -ENOMEM; in mv_xor_v2_probe()
805 xor_dev->sw_desq = devm_kcalloc(&pdev->dev, in mv_xor_v2_probe()
808 if (!xor_dev->sw_desq) { in mv_xor_v2_probe()
809 ret = -ENOMEM; in mv_xor_v2_probe()
813 spin_lock_init(&xor_dev->lock); in mv_xor_v2_probe()
816 INIT_LIST_HEAD(&xor_dev->free_sw_desc); in mv_xor_v2_probe()
821 xor_dev->sw_desq + i; in mv_xor_v2_probe()
822 sw_desc->idx = i; in mv_xor_v2_probe()
823 dma_async_tx_descriptor_init(&sw_desc->async_tx, in mv_xor_v2_probe()
824 &xor_dev->dmachan); in mv_xor_v2_probe()
825 sw_desc->async_tx.tx_submit = mv_xor_v2_tx_submit; in mv_xor_v2_probe()
826 async_tx_ack(&sw_desc->async_tx); in mv_xor_v2_probe()
828 list_add(&sw_desc->free_list, in mv_xor_v2_probe()
829 &xor_dev->free_sw_desc); in mv_xor_v2_probe()
832 dma_dev = &xor_dev->dmadev; in mv_xor_v2_probe()
835 dma_cap_zero(dma_dev->cap_mask); in mv_xor_v2_probe()
836 dma_cap_set(DMA_MEMCPY, dma_dev->cap_mask); in mv_xor_v2_probe()
837 dma_cap_set(DMA_XOR, dma_dev->cap_mask); in mv_xor_v2_probe()
838 dma_cap_set(DMA_INTERRUPT, dma_dev->cap_mask); in mv_xor_v2_probe()
841 INIT_LIST_HEAD(&dma_dev->channels); in mv_xor_v2_probe()
844 dma_dev->device_tx_status = dma_cookie_status; in mv_xor_v2_probe()
845 dma_dev->device_issue_pending = mv_xor_v2_issue_pending; in mv_xor_v2_probe()
846 dma_dev->dev = &pdev->dev; in mv_xor_v2_probe()
848 dma_dev->device_prep_dma_memcpy = mv_xor_v2_prep_dma_memcpy; in mv_xor_v2_probe()
849 dma_dev->device_prep_dma_interrupt = mv_xor_v2_prep_dma_interrupt; in mv_xor_v2_probe()
850 dma_dev->max_xor = 8; in mv_xor_v2_probe()
851 dma_dev->device_prep_dma_xor = mv_xor_v2_prep_dma_xor; in mv_xor_v2_probe()
853 xor_dev->dmachan.device = dma_dev; in mv_xor_v2_probe()
855 list_add_tail(&xor_dev->dmachan.device_node, in mv_xor_v2_probe()
856 &dma_dev->channels); in mv_xor_v2_probe()
866 dev_notice(&pdev->dev, "Marvell Version 2 XOR driver\n"); in mv_xor_v2_probe()
871 dma_free_coherent(&pdev->dev, in mv_xor_v2_probe()
872 xor_dev->desc_size * MV_XOR_V2_DESC_NUM, in mv_xor_v2_probe()
873 xor_dev->hw_desq_virt, xor_dev->hw_desq); in mv_xor_v2_probe()
875 platform_msi_domain_free_irqs(&pdev->dev); in mv_xor_v2_probe()
877 clk_disable_unprepare(xor_dev->clk); in mv_xor_v2_probe()
879 clk_disable_unprepare(xor_dev->reg_clk); in mv_xor_v2_probe()
887 dma_async_device_unregister(&xor_dev->dmadev); in mv_xor_v2_remove()
889 dma_free_coherent(&pdev->dev, in mv_xor_v2_remove()
890 xor_dev->desc_size * MV_XOR_V2_DESC_NUM, in mv_xor_v2_remove()
891 xor_dev->hw_desq_virt, xor_dev->hw_desq); in mv_xor_v2_remove()
893 devm_free_irq(&pdev->dev, xor_dev->msi_desc->irq, xor_dev); in mv_xor_v2_remove()
895 platform_msi_domain_free_irqs(&pdev->dev); in mv_xor_v2_remove()
897 tasklet_kill(&xor_dev->irq_tasklet); in mv_xor_v2_remove()
899 clk_disable_unprepare(xor_dev->clk); in mv_xor_v2_remove()
906 { .compatible = "marvell,xor-v2", },