Skip to contentSkip to conversation

Add NVIDIA Tegra GPC-DMA driver

PATCH Superseded Akhil R 3 participants 17 messages Jan 10, 2022 – Jan 27, 2022

Subsystems (4)

v16 of 22 Superseded Latest is v22 →

lore
Share & tools
lore

Akhil R

author
#0 lore raw

v16 cover Add NVIDIA Tegra GPC-DMA driver

Add support for NVIDIA Tegra general purpose DMA driver for Tegra186 and Tegra194 platform.

v15 -> v16:
* Added cyclic mode support
* Added device pause and resume
* Added sg_req array to handle multiple sgs
* Request irq only when a dma chan is allocated
* Removed locks and busy flag
* Updates in terminate_all callback

v15 - https://lkml.org/lkml/2021/12/16/905

The additional changes were added to align with the features that got added in the interim.
Keeping "Reviewed-by: Jon Hunter <[email protected]>" as the changes were reviewed internally.

Akhil R (4):
dt-bindings: dmaengine: Add doc for tegra gpcdma
dmaengine: tegra: Add tegra gpcdma driver
arm64: defconfig: tegra: Enable GPCDMA
arm64: tegra: Add GPCDMA node for tegra186 and tegra194

 .../bindings/dma/nvidia,tegra186-gpc-dma.yaml      |  110 ++
 arch/arm64/boot/dts/nvidia/tegra186.dtsi           |   42 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi           |   43 +
 arch/arm64/configs/defconfig                       |    1 +
 drivers/dma/Kconfig                                |   11 +
 drivers/dma/Makefile                               |    1 +
 drivers/dma/tegra186-gpc-dma.c                     | 1464 ++++++++++++++++++++
 7 files changed, 1672 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml
 create mode 100644 drivers/dma/tegra186-gpc-dma.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v16 1/4 dt-bindings: dmaengine: Add doc for tegra gpcdma

Add DT binding document for Nvidia Tegra GPCDMA controller.

---
 .../bindings/dma/nvidia,tegra186-gpc-dma.yaml      | 110 +++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml
Documentation/devicetree/bindings/dma/nvidia,tegra186-gpc-dma.yaml new file +110 -0
new file mode 100644
index 0000000..9dd1476
@@ -0,0 +1,110 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/nvidia,tegra186-gpc-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NVIDIA Tegra GPC DMA Controller Device Tree Bindings
+
+description: |
+  The Tegra General Purpose Central (GPC) DMA controller is used for faster
+  data transfers between memory to memory, memory to device and device to
+  memory.
+
+maintainers:
+  - Jon Hunter <[email protected]>
+  - Rajesh Gumasta <[email protected]>
+
+allOf:
+  - $ref: "dma-controller.yaml#"
+
+properties:
+  compatible:
+    oneOf:
+      - const: nvidia,tegra186-gpcdma
+      - items:
+          - const: nvidia,tegra194-gpcdma
+          - const: nvidia,tegra186-gpcdma
+
+  "#dma-cells":
+    const: 1
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description:
+      Should contain all of the per-channel DMA interrupts in
+      ascending order with respect to the DMA channel index.
+    minItems: 1
+    maxItems: 31
+
+  resets:
+    maxItems: 1
+
+  reset-names:
+    const: gpcdma
+
+  iommus:
+    maxItems: 1
+
+  dma-coherent: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - resets
+  - reset-names
+  - "#dma-cells"
+  - iommus
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/memory/tegra186-mc.h>
+    #include <dt-bindings/reset/tegra186-reset.h>
+
+    dma-controller@2600000 {
+        compatible = "nvidia,tegra186-gpcdma";
+        reg = <0x2600000 0x210000>;
+        resets = <&bpmp TEGRA186_RESET_GPCDMA>;
+        reset-names = "gpcdma";
+        interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 83 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 99 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
+        #dma-cells = <1>;
+        iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
+        dma-coherent;
+    };
+...
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v16 2/4 dmaengine: tegra: Add tegra gpcdma driver

In reply to Akhil R

Adding GPC DMA controller driver for Tegra186 and Tegra194. The driver supports dma transfers between memory to memory, IO peripheral to memory and memory to IO peripheral.

---
 drivers/dma/Kconfig            |   11 +
 drivers/dma/Makefile           |    1 +
 drivers/dma/tegra186-gpc-dma.c | 1464 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1476 insertions(+)
 create mode 100644 drivers/dma/tegra186-gpc-dma.c
drivers/dma/Kconfig +11 -0
index 6bcdb4e..dbe7664 100644
@@ -629,6 +629,17 @@ config TXX9_DMAC
 	  Support the TXx9 SoC internal DMA controller.  This can be
 	  integrated in chips such as the Toshiba TX4927/38/39.
 
+config TEGRA186_GPC_DMA
+	tristate "NVIDIA Tegra GPC DMA support"
+	depends on ARCH_TEGRA || COMPILE_TEST
+	select DMA_ENGINE
+	help
+	  Support for the NVIDIA Tegra General Purpose Central DMA controller.
+	  The DMA controller has multiple DMA channels which can be configured
+	  for different peripherals like UART, SPI, etc which are on APB bus.
+	  This DMA controller transfers data from memory to peripheral FIFO
+	  or vice versa. It also supports memory to memory data transfer.
+
 config TEGRA20_APB_DMA
 	tristate "NVIDIA Tegra20 APB DMA support"
 	depends on ARCH_TEGRA || COMPILE_TEST
drivers/dma/Makefile +1 -0
index 616d926..2f1b87f 100644
@@ -72,6 +72,7 @@ obj-$(CONFIG_STM32_MDMA) += stm32-mdma.o
 obj-$(CONFIG_SPRD_DMA) += sprd-dma.o
 obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o
 obj-$(CONFIG_TXX9_DMAC) += txx9dmac.o
+obj-$(CONFIG_TEGRA186_GPC_DMA) += tegra186-gpc-dma.o
 obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o
 obj-$(CONFIG_TEGRA210_ADMA) += tegra210-adma.o
 obj-$(CONFIG_TIMB_DMA) += timb_dma.o
drivers/dma/tegra186-gpc-dma.c new file +1464 -0

1,464 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Thank you for the patch! Perhaps something to improve:

Hi Akhil,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on vkoul-dmaengine/next]
[also build test WARNING on robh/for-next arm64/for-next/core v5.16 next-20220110] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Akhil-R/Add-NVIDIA-Tegra-GPC-DMA-driver/20220111-000734
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20220111/202201110405.jnZaAyE4-lkp(a)intel.com/config)
compiler: hppa-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c8498ed60baaec5b689dbe5d3882342c88981eb3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Akhil-R/Add-NVIDIA-Tegra-GPC-DMA-driver/20220111-000734
git checkout c8498ed60baaec5b689dbe5d3882342c88981eb3
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=parisc SHELL=/bin/bash drivers/dma/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from <command-line>:
drivers/dma/tegra186-gpc-dma.c: In function 'tegra_dma_prep_dma_memset':

>> drivers/dma/tegra186-gpc-dma.c:861:74: warning: right shift count >= width of type [-Wshift-count-overflow]
     861 |                         FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                                                                          ^~
   include/linux/compiler_types.h:315:23: note: in definition of macro '__compiletime_assert'
     315 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:335:9: note: in expansion of macro '_compiletime_assert'
     335 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/dma/tegra186-gpc-dma.c:861:25: note: in expansion of macro 'FIELD_PREP'
     861 |                         FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                         ^~~~~~~~~~
   In file included from drivers/dma/tegra186-gpc-dma.c:8:
>> drivers/dma/tegra186-gpc-dma.c:861:74: warning: right shift count >= width of type [-Wshift-count-overflow]
     861 |                         FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                                                                          ^~
   include/linux/bitfield.h:95:34: note: in definition of macro 'FIELD_PREP'
      95 |                 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask);   \
         |                                  ^~~~
   In file included from <command-line>:
   drivers/dma/tegra186-gpc-dma.c: In function 'tegra_dma_prep_dma_memcpy':
   drivers/dma/tegra186-gpc-dma.c:929:65: warning: right shift count >= width of type [-Wshift-count-overflow]
     929 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (src >> 32));
         |                                                                 ^~
   include/linux/compiler_types.h:315:23: note: in definition of macro '__compiletime_assert'
     315 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:335:9: note: in expansion of macro '_compiletime_assert'
     335 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/dma/tegra186-gpc-dma.c:929:17: note: in expansion of macro 'FIELD_PREP'
     929 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (src >> 32));
         |                 ^~~~~~~~~~
   In file included from drivers/dma/tegra186-gpc-dma.c:8:
   drivers/dma/tegra186-gpc-dma.c:929:65: warning: right shift count >= width of type [-Wshift-count-overflow]
     929 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (src >> 32));
         |                                                                 ^~
   include/linux/bitfield.h:95:34: note: in definition of macro 'FIELD_PREP'
      95 |                 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask);   \
         |                                  ^~~~
   In file included from <command-line>:
   drivers/dma/tegra186-gpc-dma.c:931:66: warning: right shift count >= width of type [-Wshift-count-overflow]
     931 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                                                                  ^~
   include/linux/compiler_types.h:315:23: note: in definition of macro '__compiletime_assert'
     315 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:335:9: note: in expansion of macro '_compiletime_assert'
     335 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/dma/tegra186-gpc-dma.c:931:17: note: in expansion of macro 'FIELD_PREP'
     931 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                 ^~~~~~~~~~
   In file included from drivers/dma/tegra186-gpc-dma.c:8:
   drivers/dma/tegra186-gpc-dma.c:931:66: warning: right shift count >= width of type [-Wshift-count-overflow]
     931 |                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));
         |                                                                  ^~
   include/linux/bitfield.h:95:34: note: in definition of macro 'FIELD_PREP'
      95 |                 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask);   \
         |                                  ^~~~
   In file included from <command-line>:
   drivers/dma/tegra186-gpc-dma.c: In function 'tegra_dma_prep_slave_sg':
   drivers/dma/tegra186-gpc-dma.c:1040:81: warning: right shift count >= width of type [-Wshift-count-overflow]
    1040 |                                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (mem >> 32));
         |                                                                                 ^~
   include/linux/compiler_types.h:315:23: note: in definition of macro '__compiletime_assert'
     315 |                 if (!(condition))                                       \
         |                       ^~~~~~~~~
   include/linux/compiler_types.h:335:9: note: in expansion of macro '_compiletime_assert'
     335 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/bitfield.h:49:17: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      49 |                 BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ?           \
         |                 ^~~~~~~~~~~~~~~~
   include/linux/bitfield.h:94:17: note: in expansion of macro '__BF_FIELD_CHECK'
      94 |                 __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: ");    \
         |                 ^~~~~~~~~~~~~~~~
   drivers/dma/tegra186-gpc-dma.c:1040:33: note: in expansion of macro 'FIELD_PREP'
    1040 |                                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (mem >> 32));
         |                                 ^~~~~~~~~~
   In file included from drivers/dma/tegra186-gpc-dma.c:8:
   drivers/dma/tegra186-gpc-dma.c:1040:81: warning: right shift count >= width of type [-Wshift-count-overflow]
    1040 |                                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_SRC_PTR, (mem >> 32));
         |                                                                                 ^~
   include/linux/bitfield.h:95:34: note: in definition of macro 'FIELD_PREP'
      95 |                 ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask);   \
         |                                  ^~~~
   In file included from <command-line>:
   drivers/dma/tegra186-gpc-dma.c:1045:81: warning: right shift count >= width of type [-Wshift-count-overflow]
    1045 |                                 FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (mem >> 32));
         |                                                                                 ^~
   include/linux/compiler_types.h:315:23: note: in definition of macro '__compiletime_assert'
     315 |                 if (!(condition))                                       \

vim +861 drivers/dma/tegra186-gpc-dma.c

806
807 static struct dma_async_tx_descriptor *
808 tegra_dma_prep_dma_memset(struct dma_chan *dc, dma_addr_t dest, int value,
809 size_t len, unsigned long flags)
810 {
811 struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
812 unsigned int max_dma_count = tdc->tdma->chip_data->max_dma_count;
813 struct tegra_dma_sg_req *sg_req;
814 struct tegra_dma_desc *dma_desc;
815 unsigned long csr, mc_seq;
816
817 if ((len & 3) || (dest & 3) || len > max_dma_count) {
818 dev_err(tdc2dev(tdc),
819 "DMA length/memory address is not supported\n");
820 return NULL;
821 }
822
823 /* Set dma mode to fixed pattern */
824 csr = TEGRA_GPCDMA_CSR_DMA_FIXED_PAT;
825 /* Enable once or continuous mode */
826 csr |= TEGRA_GPCDMA_CSR_ONCE;
827 /* Enable IRQ mask */
828 csr |= TEGRA_GPCDMA_CSR_IRQ_MASK;
829 /* Enable the dma interrupt */
830 if (flags & DMA_PREP_INTERRUPT)
831 csr |= TEGRA_GPCDMA_CSR_IE_EOC;
832 /* Configure default priority weight for the channel */
833 csr |= FIELD_PREP(TEGRA_GPCDMA_CSR_WEIGHT, 1);
834
835 mc_seq = tdc_read(tdc, TEGRA_GPCDMA_CHAN_MCSEQ);
836 /* retain stream-id and clean rest */
837 mc_seq &= TEGRA_GPCDMA_MCSEQ_STREAM_ID0_MASK;
838
839 /* Set the address wrapping */
840 mc_seq |= FIELD_PREP(TEGRA_GPCDMA_MCSEQ_WRAP0,
841 TEGRA_GPCDMA_MCSEQ_WRAP_NONE);
842 mc_seq |= FIELD_PREP(TEGRA_GPCDMA_MCSEQ_WRAP1,
843 TEGRA_GPCDMA_MCSEQ_WRAP_NONE);
844
845 /* Program outstanding MC requests */
846 mc_seq |= FIELD_PREP(TEGRA_GPCDMA_MCSEQ_REQ_COUNT, 1);
847 /* Set burst size */
848 mc_seq |= TEGRA_GPCDMA_MCSEQ_BURST_16;
849
850 dma_desc = kzalloc(struct_size(dma_desc, sg_req, 1), GFP_NOWAIT);
851 if (!dma_desc)
852 return NULL;
853
854 dma_desc->bytes_requested = len;
855 dma_desc->sg_count = 1;
856 sg_req = dma_desc->sg_req;
857
858 sg_req[0].ch_regs.src_ptr = 0;
859 sg_req[0].ch_regs.dst_ptr = dest;
860 sg_req[0].ch_regs.high_addr_ptr =

 > 861				FIELD_PREP(TEGRA_GPCDMA_HIGH_ADDR_DST_PTR, (dest >> 32));

862 sg_req[0].ch_regs.fixed_pattern = value;
863 /* Word count reg takes value as (N +1) words */
864 sg_req[0].ch_regs.wcount = ((len - 4) >> 2);
865 sg_req[0].ch_regs.csr = csr;
866 sg_req[0].ch_regs.mmio_seq = 0;
867 sg_req[0].ch_regs.mc_seq = mc_seq;
868 sg_req[0].len = len;
869
870 dma_desc->cyclic = false;
871 return vchan_tx_prep(&tdc->vc, &dma_desc->vd, flags);
872 }
873

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

In reply to Akhil R

10.01.2022 19:05, Akhil R пишет:

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+	unsigned long flags;
+	LIST_HEAD(head);
+	int err;
+
+	if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

author
#5 lore raw

RE: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Quoted 11 lines

10.01.2022 19:05, Akhil R пишет:

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

Thanks,
Akhil

--
nvpublic

#6 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

17.01.2022 10:02, Akhil R пишет:

Quoted 11 lines
Quoted 11 lines

10.01.2022 19:05, Akhil R пишет:

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

author
#7 lore raw

RE: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Quoted 12 lines

17.01.2022 10:02, Akhil R пишет:

Quoted 11 lines
Quoted 11 lines

10.01.2022 19:05, Akhil R пишет:

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

+ wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+ tdc->dma_desc->bytes_transferred +=
+ tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Thanks,
Akhil

#8 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

18.01.2022 08:36, Akhil R пишет:

Quoted 27 lines
Quoted 12 lines

17.01.2022 10:02, Akhil R пишет:

Quoted 11 lines
Quoted 11 lines

10.01.2022 19:05, Akhil R пишет:

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

drivers/dma/tegra186-gpc-dma.c new file +3 -0
+	wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+	tdc->dma_desc->bytes_transferred +=
+			tdc->dma_desc->bytes_requested - (wcount * 4);
Quoted 2 lines

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

author
#9 lore raw

RE: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Quoted 25 lines
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

drivers/dma/tegra186-gpc-dma.c line 684

Quoted 8 lines
drivers/dma/tegra186-gpc-dma.c new file +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

drivers/dma/tegra186-gpc-dma.c new file +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);
Quoted 6 lines
Quoted 2 lines

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

+static int tegra_dma_terminate_all(struct dma_chan *dc) +{

+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;

+
+ err = tegra_dma_stop_client(tdc);
+ if (err)
+ return err;
+
+ tegra_dma_stop(tdc);
+

+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;

+
+ vchan_get_all_descriptors(&tdc->vc, &head);
+ spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+ vchan_dma_desc_free_list(&tdc->vc, &head);
+
+ return 0;
+}

+static irqreturn_t tegra_dma_isr(int irq, void *dev_id) +{

+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);

+ }
+
+ status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+ if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
+ return IRQ_HANDLED;
+
+ tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+ TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+ spin_lock(&tdc->vc.lock);
+ if (!dma_desc)
+ goto irq_done;
+
+ sg_req = dma_desc->sg_req;
+ dma_desc->bytes_transferred += sg_req[dma_desc->sg_idx - 1].len;
+
+ if (dma_desc->sg_idx == dma_desc->sg_count) {
+ tegra_dma_xfer_complete(tdc);
+ } else if (dma_desc->cyclic) {
+ vchan_cyclic_callback(&dma_desc->vd);
+ tegra_dma_configure_next_sg(tdc);
+ } else {
+ tegra_dma_start(tdc);
+ }
+
+irq_done:
+ spin_unlock(&tdc->vc.lock);
+ return IRQ_HANDLED;
+}

Thanks,
Akhil

#10 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

21.01.2022 19:24, Akhil R пишет:

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

(quoted diff) +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Quoted 6 lines
Quoted 3 lines

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

Stop shall not race with the start.

Quoted 39 lines
(quoted diff) +38 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc)
+{
+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;
+
+       err = tegra_dma_stop_client(tdc);
+       if (err)
+               return err;
+
+       tegra_dma_stop(tdc);
+
+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;
+
+       vchan_get_all_descriptors(&tdc->vc, &head);
+       spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+       vchan_dma_desc_free_list(&tdc->vc, &head);
+
+       return 0;
+}
 
+static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
+{
+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);
+       }

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+       if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
+               return IRQ_HANDLED;
+
+       tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+                 TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+       spin_lock(&tdc->vc.lock);
+       if (!dma_desc)

All checks and assignments must be done inside of critical section.

Quoted 1 line

+ goto irq_done;

author
#11 lore raw

RE: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Quoted 77 lines

21.01.2022 19:24, Akhil R пишет:

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

(quoted diff) +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Quoted 6 lines
Quoted 3 lines

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

Stop shall not race with the start.

Quoted 40 lines
(quoted diff) +39 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;
+
+       err = tegra_dma_stop_client(tdc);
+       if (err)
+               return err;
+
+       tegra_dma_stop(tdc);
+
+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;
+
+       vchan_get_all_descriptors(&tdc->vc, &head);
+       spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+       vchan_dma_desc_free_list(&tdc->vc, &head);
+
+       return 0;
+}
 
+static irqreturn_t tegra_dma_isr(int irq, void *dev_id) {
+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);
+       }
+
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+       if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+               return IRQ_HANDLED;
+
+       tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+                 TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+       spin_lock(&tdc->vc.lock);
+       if (!dma_desc)

All checks and assignments must be done inside of critical section.

Okay. So, the lock should be held throughout the function. Do you think tegra_dma_pause should also hold a lock and remove irq_synchronize? That function also writes to CSR register.

Regards,
Akhil

#12 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

23.01.2022 19:49, Akhil R пишет:

Quoted 86 lines
Quoted 77 lines

21.01.2022 19:24, Akhil R пишет:

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

(quoted diff) +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Quoted 6 lines
Quoted 3 lines

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

Stop shall not race with the start.

Quoted 40 lines
(quoted diff) +39 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;
+
+       err = tegra_dma_stop_client(tdc);
+       if (err)
+               return err;
+
+       tegra_dma_stop(tdc);
+
+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;
+
+       vchan_get_all_descriptors(&tdc->vc, &head);
+       spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+       vchan_dma_desc_free_list(&tdc->vc, &head);
+
+       return 0;
+}
 
+static irqreturn_t tegra_dma_isr(int irq, void *dev_id) {
+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);
+       }
+
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+       if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+               return IRQ_HANDLED;
+
+       tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+                 TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+       spin_lock(&tdc->vc.lock);
+       if (!dma_desc)

All checks and assignments must be done inside of critical section.

Quoted 4 lines

Okay. So, the lock should be held throughout the function. Do you think tegra_dma_pause should also hold a lock and remove irq_synchronize? That function also writes to CSR register.

Interrupt handler shall not unpause channel in a case of race condition, it should handle completed transfer and check whether channel is paused before issuing next transfer.
So yes, pause also needs a lock.

author
#13 lore raw

RE: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

Quoted 92 lines

23.01.2022 19:49, Akhil R пишет:

Quoted 86 lines
Quoted 77 lines

21.01.2022 19:24, Akhil R пишет:

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

(quoted diff) +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Quoted 6 lines
Quoted 3 lines

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

Stop shall not race with the start.

Quoted 40 lines
(quoted diff) +39 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;
+
+       err = tegra_dma_stop_client(tdc);
+       if (err)
+               return err;
+
+       tegra_dma_stop(tdc);
+
+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;
+
+       vchan_get_all_descriptors(&tdc->vc, &head);
+       spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+       vchan_dma_desc_free_list(&tdc->vc, &head);
+
+       return 0;
+}
 
+static irqreturn_t tegra_dma_isr(int irq, void *dev_id) {
+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);
+       }
+
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+       if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+               return IRQ_HANDLED;
+
+       tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+                 TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+       spin_lock(&tdc->vc.lock);
+       if (!dma_desc)

All checks and assignments must be done inside of critical section.

Quoted 4 lines

Okay. So, the lock should be held throughout the function. Do you think tegra_dma_pause should also hold a lock and remove irq_synchronize? That function also writes to CSR register.

Quoted 4 lines

Interrupt handler shall not unpause channel in a case of race condition, it should handle completed transfer and check whether channel is paused before issuing next transfer.
So yes, pause also needs a lock.

Thanks for the points. I collected more details on this scenario and found that DMA can only be paused if there is an in-flight transfer (i.e no interrupt will be pending). And there cannot be an interrupt after DMA is paused. Hence, there is no case of ISR unpausing a paused transfer. So, I guess, the check or a lock might not be required there.

One thing I am thinking of is to wait for DMA to be busy so that it can be paused. I would add these changes and send out a new patch.

Thanks,
Akhil

#14 lore raw

Re: [PATCH v16 2/4] dmaengine: tegra: Add tegra gpcdma driver

27.01.2022 19:29, Akhil R пишет:

Quoted 96 lines
Quoted 92 lines

23.01.2022 19:49, Akhil R пишет:

Quoted 86 lines
Quoted 77 lines

21.01.2022 19:24, Akhil R пишет:

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+     struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+     unsigned long flags;
+     LIST_HEAD(head);
+     int err;
+
+     if (tdc->dma_desc) {

Needs locking protection against racing with the interrupt handler.

Quoted 7 lines
Quoted 3 lines

tegra_dma_stop_client() waits for the in-flight transfer to complete and prevents any additional transfer to start. Wouldn't it manage the race? Do you see any potential issue there?

You should consider interrupt handler like a process running in a parallel thread. The interrupt handler sets tdc->dma_desc to NULL, hence you'll get NULL dereference in tegra_dma_stop_client().

Is it better if I remove the below part from tegra_dma_stop_client() so that dma_desc is not accessed at all?

(quoted diff) +3 -0
+     wcount = tdc_read(tdc, TEGRA_GPCDMA_CHAN_XFER_COUNT);
+     tdc->dma_desc->bytes_transferred +=
+                     tdc->dma_desc->bytes_requested - (wcount * 4);

Because I don't see a point in updating the value there. dma_desc is set to NULL in the next step in terminate_all() anyway.

Quoted 6 lines
Quoted 3 lines

That isn't going help you much because you also can't release DMA descriptor while interrupt handler still may be running and using that descriptor.

Does the below functions look good to resolve the issue, provided tegra_dma_stop_client() doesn't access dma_desc?

Stop shall not race with the start.

Quoted 40 lines
(quoted diff) +39 -0
+static int tegra_dma_terminate_all(struct dma_chan *dc) {
+       struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+       unsigned long flags;
+       LIST_HEAD(head);
+       int err;
+
+       err = tegra_dma_stop_client(tdc);
+       if (err)
+               return err;
+
+       tegra_dma_stop(tdc);
+
+       spin_lock_irqsave(&tdc->vc.lock, flags);
+       tegra_dma_sid_free(tdc);
+       tdc->dma_desc = NULL;
+
+       vchan_get_all_descriptors(&tdc->vc, &head);
+       spin_unlock_irqrestore(&tdc->vc.lock, flags);
+
+       vchan_dma_desc_free_list(&tdc->vc, &head);
+
+       return 0;
+}
 
+static irqreturn_t tegra_dma_isr(int irq, void *dev_id) {
+       struct tegra_dma_channel *tdc = dev_id;
+       struct tegra_dma_desc *dma_desc = tdc->dma_desc;
+       struct tegra_dma_sg_req *sg_req;
+       u32 status;
+
+       /* Check channel error status register */
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS);
+       if (status) {
+               tegra_dma_chan_decode_error(tdc, status);
+               tegra_dma_dump_chan_regs(tdc);
+               tdc_write(tdc, TEGRA_GPCDMA_CHAN_ERR_STATUS, 0xFFFFFFFF);
+       }
+
+       status = tdc_read(tdc, TEGRA_GPCDMA_CHAN_STATUS);
+       if (!(status & TEGRA_GPCDMA_STATUS_ISE_EOC))
Quoted 8 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+               return IRQ_HANDLED;
+
+       tdc_write(tdc, TEGRA_GPCDMA_CHAN_STATUS,
+                 TEGRA_GPCDMA_STATUS_ISE_EOC);
+
+       spin_lock(&tdc->vc.lock);
+       if (!dma_desc)

All checks and assignments must be done inside of critical section.

Quoted 4 lines

Okay. So, the lock should be held throughout the function. Do you think tegra_dma_pause should also hold a lock and remove irq_synchronize? That function also writes to CSR register.

Quoted 4 lines

Interrupt handler shall not unpause channel in a case of race condition, it should handle completed transfer and check whether channel is paused before issuing next transfer.
So yes, pause also needs a lock.

Quoted 5 lines

Thanks for the points. I collected more details on this scenario and found that DMA can only be paused if there is an in-flight transfer (i.e no interrupt will be pending). And there cannot be an interrupt after DMA is paused. Hence, there is no case of ISR unpausing a paused transfer. So, I guess, the check or a lock might not be required there.

If there is in-flight transfer, then interrupt may fire at any time. All CSRE modifications must be protected.

Quoted 2 lines

One thing I am thinking of is to wait for DMA to be busy so that it can be paused. I would add these changes and send out a new patch.

You should assume that interrupt handler may run with a delay. Then pause() will see that channel isn't busy, but delayed interrupt will start the next transfer.

Also, the tegra_dma_pause() will crash if tdc->dma_desc=NULL.

Everything must be done under lock.

author
#15 lore raw

PATCH v16 3/4 arm64: defconfig: tegra: Enable GPCDMA

In reply to Akhil R

Enable TEGRA_GPC_DMA in defconfig for Tegra186 and Tegra196 gpc dma controller driver

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index ee4bd77..96a796d 100644
@@ -956,6 +956,7 @@ CONFIG_MV_XOR=y
 CONFIG_MV_XOR_V2=y
 CONFIG_OWL_DMA=y
 CONFIG_PL330_DMA=y
+CONFIG_TEGRA186_GPC_DMA=m
 CONFIG_TEGRA20_APB_DMA=y
 CONFIG_TEGRA210_ADMA=m
 CONFIG_QCOM_BAM_DMA=y
Signature · 1 line
2.7.4
author
#16 lore raw

PATCH v16 4/4 arm64: tegra: Add GPCDMA node for tegra186 and tegra194

In reply to Akhil R

Add device tree node for GPCDMA controller on Tegra186 target and Tegra194 target.

---
 arch/arm64/boot/dts/nvidia/tegra186.dtsi | 42 +++++++++++++++++++++++++++++++
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 43 ++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
arch/arm64/boot/dts/nvidia/tegra186.dtsi +42 -0
index c91afff..6bec977 100644
@@ -73,6 +73,48 @@
 		snps,rxpbl = <8>;
 	};
 
+	dma-controller@2600000 {
+		compatible = "nvidia,tegra186-gpcdma";
+		reg = <0x0 0x2600000 0x0 0x210000>;
+		resets = <&bpmp TEGRA186_RESET_GPCDMA>;
+		reset-names = "gpcdma";
+		interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 83 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 84 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 94 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 99 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>,
+			     <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
+		#dma-cells = <1>;
+		iommus = <&smmu TEGRA186_SID_GPCDMA_0>;
+		dma-coherent;
+		status = "okay";
+	};
+
 	aconnect@2900000 {
 		compatible = "nvidia,tegra186-aconnect",
 			     "nvidia,tegra210-aconnect";
arch/arm64/boot/dts/nvidia/tegra194.dtsi +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.7.4