Skip to content

BDMA XOR User Guide


REVISION HISTORY

Revision No.
Description
Date
1.0
  • Initial release
  • 01/29/2026

    1. Overview

    In RAID5/RAID6 applications, a large amount of XOR computation is required. If the CPU is used for XOR computation, it will consume significant CPU resources and reduce system performance. Using BDMA XOR hardware for XOR computation can free the CPU from XOR calculations and reduce CPU load.

    The BDMA XOR driver is based on the Linux standard DMA engine subsystem framework and is primarily used for storage application scenarios that require XOR computation, such as RAID5/RAID6, improving data processing efficiency through hardware acceleration.

    Key Features:

    • Support for DMA_MEMCPY and DMA_XOR operations
    • Support for XOR operations with up to 8 source buffers
    • Support for Scatter-Gather Lists, enabling batch processing of multiple descriptors
    • Support for ACP (Accelerator Coherency Port)
    • Based on Linux DMA engine framework, compatible with standard async transfer APIs

    2. Key Terms

    • BDMA (Byte-aligned data transfer DMA engine)

      Mainly used for high-speed data transfer between peripherals and memory, or between memory and memory, without CPU involvement.

    • XOR Computation

      Exclusive OR operation, used in storage systems such as RAID5/RAID6 to calculate and verify data. For example: for n source buffers, XOR computation performs bitwise exclusive OR on all source data and writes the result to the destination buffer.

    • Scatter-Gather List

      A scatter-gather list allows the DMA controller to process multiple non-contiguous memory regions in a single operation.

    • ACP (Accelerator Coherency Port)

      Accelerator Coherency Port, used to implement coherent memory access between external accelerators (such as DMA controllers) and CPU caches. When ACP is enabled, manual cache flush operations can be reduced, improving performance.

    3. Functional Description

    3.1 Hardware Features

    Parameter Name Specification Description
    Maximum Source Buffer Count 8 Supports up to 8 source buffers for single XOR computation
    Descriptor Queue Depth 1024 Supports up to 1024 pending hardware descriptors
    Scatter-Gather List Size 16KB Used for storing scatter-gather table entries
    Data Transfer Size Range 1 byte - 4096 bytes Data size range for single operation
    Burst Length Supports 16 and 32 bytes Configurable DMA transfer burst length

    3.2 Operating Modes

    The BDMA XOR driver supports the following operating modes:

    1. ACP Mode

      • ACP enabled
      • Automatically handles cache coherency, no manual cache flushing required
      • Configuration: Set acp-enable = <1>; in DTS
    2. Non-ACP Mode

      • Manual cache coherency management
      • Need to flush source data cache before transfer
      • Need to invalidate destination data cache after transfer
      • Configuration: Set acp-enable = <0>; in DTS

    3.3 Supported Operations

    Operation Type Description API Interface
    DMA_MEMCPY Memory-to-memory copy operation device_prep_dma_memcpy
    DMA_XOR Multi-source buffer XOR operation device_prep_dma_xor

    4. Kernel Usage Guide

    4.1. Kernel Config Configuration

    The following configuration needs to be selected when compiling the Kernel:

        Device Drivers  --->
            [*] Sgs SoC platform drivers  --->
                [*] Sgs BDMA XOR driver
    

    Kconfig Configuration Details:

    config SGS_BDMA_XOR
        bool "Sgs BDMA XOR driver"
        select DMADEVICES
        select DMA_ENGINE
        select DMA_VIRTUAL_CHANNELS
        select DMA_ENGINE_RAID
        select ASYNC_TX_DMA
        select ASYNC_TX_ENABLE_CHANNEL_SWITCH
        select ASYNC_CORE
        select ASYNC_XOR
        select ASYNC_MEMCPY
        default y if ARCH_MHERA
        help
            Sgs BDMA XOR driver function
    

    4.2. DTS Configuration

    The BDMA XOR driver can be configured in the dtsi file. Example:

        bdma_xor {
            compatible = "sgs,bdma_xor";
            interrupts = <GIC_SPI INT_IRQ_BDMA3 IRQ_TYPE_LEVEL_HIGH>;
            reg = <0x0 0x1F201800 0x100>,  /* BDMA register base address */
                  <0x0 0x1F220C00 0x100>;  /* XOR register base address */
            acp-enable = <1>;              /* ACP enable flag: 1=enable, 0=disable */
            clocks = <&xtal>;              /* Clock source */
            status = "okay";               /* Status: okay=enable, disabled=disable */
        };
    

    Parameter Description:

    Parameter Meaning Notes
    compatible Driver compatibility string for matching driver Must be "sgs,bdma_xor"
    interrupts Interrupt number and interrupt trigger type Use GIC SPI interrupt, level-triggered
    reg Register base address and size First is BDMA base address, second is XOR base address
    acp-enable ACP Accelerator Coherency Port enable 1 means enable, 0 means disable, default enabled
    clocks Clock source reference Points to xtal clock
    status Device status okay means enabled, disabled means disabled

    4.3. Usage Method

    After enabling the BDMA XOR driver, the Kernel startup log will show the following prints, indicating that the BDMA XOR driver initialized successfully. During RAID5 read/write operations, the system will automatically use BDMA XOR hardware to perform DMA_MEMCPY and DMA_XOR calculations.

        sgs,bdma_xor 1f201800.bdma_xor: DMA use 64-bit address mask
        sgs,bdma_xor 1f201800.bdma_xor: sg_list_virt:0xffffffc009195000
        sgs,bdma_xor 1f201800.bdma_xor: acp enabled
    

    5. RAID5 Performance Testing

    This section introduces the RAID5 performance testing method, including how to configure Kernel Config, and commands for testing RAID5.

    The Kernel Config related to RAID5 mainly consists of three parts:

    • Enable RAID5 Config configuration
    • Configure devices to build RAID5
    • Configure hardware for DMA_MEMCPY/DMA_XOR calculation

    5.1.1 Enable RAID5 Config Configuration

        Device Drivers  --->
            [*] Multiple devices driver support (RAID and LVM)  --->
                <*>   RAID support
                [*]     Autodetect RAID arrays during kernel boot
                <*>     RAID-4/RAID-5/RAID-6 mode
    

    5.1.2 Configure Devices to Build RAID5

    You can use SATA hard drives to build RAID5. If you don't have SATA hard drives, you can also use RAM block devices to build RAID5 for testing.

    5.1.2.1 Enable SATA Config Configuration

    For specific configuration options, please refer to SATA-related documentation.

    5.1.2.2 Enable RAM Block Device Config Configuration
        Device Drivers  --->
            [*] Block devices  --->
                <*>   RAM block device support
                (4)     Default number of RAM disks       /* Configure 4 RAM block devices */
                (102400) Default RAM disk size (kbytes)   /* Configure each RAM block device size to 100MB */
    

    5.1.3 Configure Hardware for DMA_MEMCPY/DMA_XOR Calculation

    During RAID5 read/write operations, there will be a large amount of DMA_MEMCPY/DMA_XOR calculations. When the BDMA XOR driver is enabled, these calculations will be performed by the BDMA XOR hardware. When the BDMA XOR driver is disabled, these calculations will be performed by the CPU.

    For methods to enable the BDMA XOR driver, please refer to the previous section.

    5.2. Test RAID5 Performance

    Step 1. Use mdadm tool to build RAID, please refer to relevant documentation for specific command parameters

    ## Use SATA hard drive partitions /dev/sda1~/dev/sda4 to build RAID5
    ./mdadm -C /dev/md1 -l5 -c128 -binternal -n4 /dev/sda[1-4] --assume-clean
    

    Or

    ## Use RAM block devices /dev/ram0~/dev/ram3 to build RAID5
    ./mdadm -C /dev/md1 -l5 -c128 -binternal -n4 /dev/ram[0-3] --assume-clean
    

    Step 2. Generate random data and write to RAID5

    dd if=/dev/random of=/tmp/data.bin bs=4096 count=80000
    dd if=/tmp/data.bin of=/dev/md1 bs=4096 count=80000
    

    Step 3. Read data from RAID5

    dd if=/dev/md1 of=/tmp/data1.bin bs=4096 count=80000
    

    Step 4. Verify whether the original data and data in RAID5 are consistent

    md5sum /tmp/data.bin
    md5sum /tmp/data1.bin