Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2026 Advanced Micro Devices, Inc. All rights reserved. 3 : : */ 4 : : 5 : : #ifndef AE4DMA_INTERNAL_H 6 : : #define AE4DMA_INTERNAL_H 7 : : 8 : : #include <stdint.h> 9 : : 10 : : #include <rte_byteorder.h> 11 : : #include <rte_dmadev.h> 12 : : #include <rte_io.h> 13 : : #include <rte_memzone.h> 14 : : 15 : : #include "ae4dma_hw_defs.h" 16 : : 17 : : /* Return bits 32-63 of a 64-bit number. */ 18 : : #define upper_32_bits(n) ((uint32_t)(((n) >> 16) >> 16)) 19 : : 20 : : /* Return bits 0-31 of a 64-bit number. */ 21 : : #define lower_32_bits(n) ((uint32_t)((n) & 0xffffffff)) 22 : : 23 : : /* 24 : : * Hardware ring depth (slots per queue); fixed at 32 per the AE4DMA * spec and 25 : : * must be a power of two. 26 : : * The engine reserves one slot to tell a full ring from an empty one 27 : : * (full when (write + 1) % max == read), 28 : : * so at most nb_desc - 1 (31) descriptors can be outstanding. 29 : : */ 30 : : #define AE4DMA_DESCRIPTORS_PER_CMDQ 32 31 : : #define AE4DMA_QUEUE_DESC_SIZE sizeof(struct ae4dma_desc) 32 : : #define AE4DMA_QUEUE_SIZE(n) (AE4DMA_DESCRIPTORS_PER_CMDQ * (n)) 33 : : 34 : : /* AE4DMA registers Write/Read */ 35 : : static inline void ae4dma_pci_reg_write(void *base, int offset, uint32_t value) 36 : : { 37 : : volatile void *reg_addr = ((uint8_t *)base + offset); 38 : : 39 : : rte_write32((rte_cpu_to_le_32(value)), reg_addr); 40 : 0 : } 41 : : 42 : : static inline uint32_t ae4dma_pci_reg_read(void *base, int offset) 43 : : { 44 : : volatile void *reg_addr = ((uint8_t *)base + offset); 45 : : 46 : : return rte_le_to_cpu_32(rte_read32(reg_addr)); 47 : : } 48 : : 49 : : #define AE4DMA_READ_REG_OFFSET(hw_addr, reg_offset) \ 50 : : ae4dma_pci_reg_read(hw_addr, reg_offset) 51 : : 52 : : #define AE4DMA_WRITE_REG_OFFSET(hw_addr, reg_offset, value) \ 53 : : ae4dma_pci_reg_write(hw_addr, reg_offset, value) 54 : : 55 : : #define AE4DMA_READ_REG(hw_addr) \ 56 : : ae4dma_pci_reg_read((void *)(uintptr_t)(hw_addr), 0) 57 : : 58 : : #define AE4DMA_WRITE_REG(hw_addr, value) \ 59 : : ae4dma_pci_reg_write((void *)(uintptr_t)(hw_addr), 0, value) 60 : : 61 : : /* A structure describing an AE4DMA command queue. */ 62 : : struct __rte_cache_aligned ae4dma_cmd_queue { 63 : : char memz_name[RTE_MEMZONE_NAMESIZE]; 64 : : const struct rte_memzone *mz; 65 : : volatile struct ae4dma_hwq_regs *hwq_regs; 66 : : 67 : : struct rte_dma_vchan_conf qcfg; 68 : : struct rte_dma_stats stats; 69 : : /* Queue address */ 70 : : struct ae4dma_desc *qbase_desc; 71 : : void *qbase_addr; 72 : : rte_iova_t qbase_phys_addr; 73 : : /* Queue identifier */ 74 : : uint64_t id; /* queue id */ 75 : : uint64_t qidx; /* queue index */ 76 : : uint64_t qsize; /* queue size */ 77 : : /* 78 : : * Free-running 16-bit ring indices (wrap at 2^16), as required by the 79 : : * dmadev API. The HW ring slot is derived as ((hw_base + idx) & 80 : : * (nb_desc - 1)), which is why nb_desc is rounded up to a power of two. 81 : : */ 82 : : uint16_t next_read; /* ring_idx of the next completion to reap */ 83 : : uint16_t next_write; /* ring_idx assigned to the next enqueue */ 84 : : uint16_t last_write; /* next_write at last submit; for submitted stat */ 85 : : /* 86 : : * HW ring slot that free-running index 0 maps to. read_idx is HW-owned 87 : : * (read-only), so on start we anchor to wherever the HW consumer sits 88 : : * instead of forcing the HW indices to 0. 89 : : */ 90 : : uint16_t hw_base; 91 : : }; 92 : : 93 : : /* 94 : : * One dmadev per AE4DMA hardware channel: probe creates AE4DMA_MAX_HW_QUEUES 95 : : * dmadevs per PCI function, each owning a single HW command queue. 96 : : */ 97 : : struct ae4dma_dmadev { 98 : : void *io_regs; 99 : : struct ae4dma_cmd_queue cmd_q; /* single HW queue owned by this dmadev */ 100 : : }; 101 : : 102 : : extern int ae4dma_pmd_logtype; 103 : : #define RTE_LOGTYPE_AE4DMA_PMD ae4dma_pmd_logtype 104 : : 105 : : #define AE4DMA_PMD_LOG(level, ...) \ 106 : : RTE_LOG_LINE_PREFIX(level, AE4DMA_PMD, "%s(): ", __func__, __VA_ARGS__) 107 : : 108 : : #define AE4DMA_PMD_DEBUG(...) AE4DMA_PMD_LOG(DEBUG, __VA_ARGS__) 109 : : #define AE4DMA_PMD_INFO(...) AE4DMA_PMD_LOG(INFO, __VA_ARGS__) 110 : : #define AE4DMA_PMD_ERR(...) AE4DMA_PMD_LOG(ERR, __VA_ARGS__) 111 : : #define AE4DMA_PMD_WARN(...) AE4DMA_PMD_LOG(WARNING, __VA_ARGS__) 112 : : 113 : : #endif /* AE4DMA_INTERNAL_H */