1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 HiSilicon Limited
8 #include <rte_byteorder.h>
9 #include <rte_common.h>
11 #define BIT(x) (1ul << (x))
12 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
13 #define GENMASK(h, l) \
14 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
15 #define BF_SHF(x) (__builtin_ffsll(x) - 1)
16 #define FIELD_GET(mask, reg) \
17 ((typeof(mask))(((reg) & (mask)) >> BF_SHF(mask)))
19 #define PCI_VENDOR_ID_HUAWEI 0x19e5
20 #define HISI_DMA_DEVICE_ID 0xA122
21 #define HISI_DMA_PCI_REVISION_ID_REG 0x08
22 #define HISI_DMA_REVISION_HIP08B 0x21
24 #define HISI_DMA_MAX_HW_QUEUES 4
27 * The HIP08B(HiSilicon IP08) and later Chip(e.g. HiSilicon IP09) are DMA iEPs,
28 * they have the same pci device id but with different pci revision.
29 * Unfortunately, they have different register layouts, so the layout
30 * enumerations are defined.
33 HISI_DMA_REG_LAYOUT_INVALID = 0,
34 HISI_DMA_REG_LAYOUT_HIP08
38 * Hardware PCI bar register MAP:
43 * -------------- -> Queue base
49 * | Queue-1 | Queue region
59 * As described above, a single queue register is continuous and occupies the
60 * length of queue-region. The global offset for a single queue register is
62 * offset = queue-base + (queue-id * queue-region) + reg-offset-in-region.
64 * The first part of queue region is basically the same for HIP08 and later chip
65 * register layouts, therefore, HISI_QUEUE_* registers are defined for it.
67 #define HISI_DMA_QUEUE_SQ_BASE_L_REG 0x0
68 #define HISI_DMA_QUEUE_SQ_BASE_H_REG 0x4
69 #define HISI_DMA_QUEUE_SQ_DEPTH_REG 0x8
70 #define HISI_DMA_QUEUE_SQ_TAIL_REG 0xC
71 #define HISI_DMA_QUEUE_CQ_BASE_L_REG 0x10
72 #define HISI_DMA_QUEUE_CQ_BASE_H_REG 0x14
73 #define HISI_DMA_QUEUE_CQ_DEPTH_REG 0x18
74 #define HISI_DMA_QUEUE_CQ_HEAD_REG 0x1C
75 #define HISI_DMA_QUEUE_CTRL0_REG 0x20
76 #define HISI_DMA_QUEUE_CTRL0_EN_B 0
77 #define HISI_DMA_QUEUE_CTRL0_PAUSE_B 4
78 #define HISI_DMA_QUEUE_CTRL1_REG 0x24
79 #define HISI_DMA_QUEUE_CTRL1_RESET_B 0
80 #define HISI_DMA_QUEUE_FSM_REG 0x30
81 #define HISI_DMA_QUEUE_FSM_STS_M GENMASK(3, 0)
82 #define HISI_DMA_QUEUE_INT_STATUS_REG 0x40
83 #define HISI_DMA_QUEUE_ERR_INT_NUM0_REG 0x84
84 #define HISI_DMA_QUEUE_ERR_INT_NUM1_REG 0x88
85 #define HISI_DMA_QUEUE_ERR_INT_NUM2_REG 0x8C
86 #define HISI_DMA_QUEUE_REGION_SIZE 0x100
89 * HiSilicon IP08 DMA register and field define:
91 #define HISI_DMA_HIP08_QUEUE_BASE 0x0
92 #define HISI_DMA_HIP08_QUEUE_CTRL0_ERR_ABORT_B 2
93 #define HISI_DMA_HIP08_QUEUE_INT_MASK_REG 0x44
94 #define HISI_DMA_HIP08_QUEUE_INT_MASK_M GENMASK(14, 0)
95 #define HISI_DMA_HIP08_QUEUE_ERR_INT_NUM3_REG 0x90
96 #define HISI_DMA_HIP08_QUEUE_ERR_INT_NUM4_REG 0x94
97 #define HISI_DMA_HIP08_QUEUE_ERR_INT_NUM5_REG 0x98
98 #define HISI_DMA_HIP08_QUEUE_ERR_INT_NUM6_REG 0x48
99 #define HISI_DMA_HIP08_MODE_REG 0x217C
100 #define HISI_DMA_HIP08_MODE_SEL_B 0
101 #define HISI_DMA_HIP08_DUMP_START_REG 0x2000
102 #define HISI_DMA_HIP08_DUMP_END_REG 0x2280
105 * In fact, there are multiple states, but it need to pay attention to
106 * the following two states for the driver:
109 HISI_DMA_STATE_IDLE = 0,
113 struct hisi_dma_dev {
114 struct rte_dma_dev_data *data;
115 uint8_t revision; /**< PCI revision. */
116 uint8_t reg_layout; /**< hardware register layout. */
118 uint8_t queue_id; /**< hardware DMA queue index. */
121 #endif /* HISI_DMADEV_H */