1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
8 #ifndef _DPAA2_HW_PVT_H_
9 #define _DPAA2_HW_PVT_H_
11 #include <rte_eventdev.h>
13 #include <mc/fsl_mc_sys.h>
14 #include <fsl_qbman_portal.h>
22 #define lower_32_bits(x) ((uint32_t)(x))
23 #define upper_32_bits(x) ((uint32_t)(((x) >> 16) >> 16))
25 #define SVR_LS1080A 0x87030000
26 #define SVR_LS2080A 0x87010000
27 #define SVR_LS2088A 0x87090000
28 #define SVR_LX2160A 0x87360000
31 #define VLAN_TAG_SIZE 4 /** < Vlan Header Length */
34 #define MAX_TX_RING_SLOTS 8
35 /** <Maximum number of slots available in TX ring*/
37 #define DPAA2_DQRR_RING_SIZE 16
38 /** <Maximum number of slots available in RX ring*/
40 #define MC_PORTAL_INDEX 0
41 #define NUM_DPIO_REGIONS 2
42 #define NUM_DQS_PER_QUEUE 2
44 /* Maximum release/acquire from QBMAN */
45 #define DPAA2_MBUF_MAX_ACQ_REL 7
47 #define DPAA2_MEMPOOL_OPS_NAME "dpaa2"
50 #define DPAA2_MBUF_HW_ANNOTATION 64
51 #define DPAA2_FD_PTA_SIZE 0
53 #if (DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) > RTE_PKTMBUF_HEADROOM
54 #error "Annotation requirement is more than RTE_PKTMBUF_HEADROOM"
57 /* we will re-use the HEADROOM for annotation in RX */
58 #define DPAA2_HW_BUF_RESERVE 0
59 #define DPAA2_PACKET_LAYOUT_ALIGN 64 /*changing from 256 */
61 #define DPAA2_DPCI_MAX_QUEUES 2
63 struct dpaa2_dpio_dev {
64 TAILQ_ENTRY(dpaa2_dpio_dev) next;
65 /**< Pointer to Next device instance */
66 uint16_t index; /**< Index of a instance in the list */
67 rte_atomic16_t ref_count;
68 /**< How many thread contexts are sharing this.*/
69 struct fsl_mc_io *dpio; /** handle to DPIO portal object */
71 struct qbman_swp *sw_portal; /** SW portal object */
72 const struct qbman_result *dqrr[4];
73 /**< DQRR Entry for this SW portal */
74 void *mc_portal; /**< MC Portal for configuring this device */
75 uintptr_t qbman_portal_ce_paddr;
76 /**< Physical address of Cache Enabled Area */
77 uintptr_t ce_size; /**< Size of the CE region */
78 uintptr_t qbman_portal_ci_paddr;
79 /**< Physical address of Cache Inhibit Area */
80 uintptr_t ci_size; /**< Size of the CI region */
81 struct rte_intr_handle intr_handle; /* Interrupt related info */
82 int32_t epoll_fd; /**< File descriptor created for interrupt polling */
83 int32_t hw_id; /**< An unique ID of this DPIO device instance */
86 struct dpaa2_dpbp_dev {
87 TAILQ_ENTRY(dpaa2_dpbp_dev) next;
88 /**< Pointer to Next device instance */
89 struct fsl_mc_io dpbp; /** handle to DPBP portal object */
91 rte_atomic16_t in_use;
92 uint32_t dpbp_id; /*HW ID for DPBP object */
95 struct queue_storage_info_t {
96 struct qbman_result *dq_storage[NUM_DQS_PER_QUEUE];
97 struct qbman_result *active_dqs;
98 uint8_t active_dpio_id;
100 uint8_t last_num_pkts;
105 typedef void (dpaa2_queue_cb_dqrr_t)(struct qbman_swp *swp,
106 const struct qbman_fd *fd,
107 const struct qbman_result *dq,
108 struct dpaa2_queue *rxq,
109 struct rte_event *ev);
112 struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
114 int32_t eventfd; /*!< Event Fd of this queue */
115 uint32_t fqid; /*!< Unique ID of this queue */
116 uint8_t tc_index; /*!< traffic class identifier */
117 uint16_t flow_id; /*!< To be used by DPAA2 frmework */
122 struct queue_storage_info_t *q_storage;
123 struct qbman_result *cscn;
126 dpaa2_queue_cb_dqrr_t *cb;
129 struct swp_active_dqs {
130 struct qbman_result *global_active_dqs;
131 uint64_t reserved[7];
134 #define NUM_MAX_SWP 64
136 extern struct swp_active_dqs rte_global_active_dqs_list[NUM_MAX_SWP];
138 struct dpaa2_dpci_dev {
139 TAILQ_ENTRY(dpaa2_dpci_dev) next;
140 /**< Pointer to Next device instance */
141 struct fsl_mc_io dpci; /** handle to DPCI portal object */
143 rte_atomic16_t in_use;
144 uint32_t dpci_id; /*HW ID for DPCI object */
145 struct dpaa2_queue queue[DPAA2_DPCI_MAX_QUEUES];
148 /*! Global MCP list */
149 extern void *(*rte_mcp_ptr_list);
151 /* Refer to Table 7-3 in SEC BG */
156 /* FMT must be 00, MSB is final bit */
157 uint32_t fin_bpid_offset;
159 uint32_t reserved[3]; /* Not used currently */
166 uint32_t fin_bpid_offset;
169 /* There are three types of frames: Single, Scatter Gather and Frame Lists */
170 enum qbman_fd_format {
175 /*Macros to define operations on FD*/
176 #define DPAA2_SET_FD_ADDR(fd, addr) do { \
177 (fd)->simple.addr_lo = lower_32_bits((uint64_t)(addr)); \
178 (fd)->simple.addr_hi = upper_32_bits((uint64_t)(addr)); \
180 #define DPAA2_SET_FD_LEN(fd, length) ((fd)->simple.len = length)
181 #define DPAA2_SET_FD_BPID(fd, bpid) ((fd)->simple.bpid_offset |= bpid)
182 #define DPAA2_SET_ONLY_FD_BPID(fd, bpid) \
183 ((fd)->simple.bpid_offset = bpid)
184 #define DPAA2_SET_FD_IVP(fd) (((fd)->simple.bpid_offset |= 0x00004000))
185 #define DPAA2_SET_FD_OFFSET(fd, offset) \
186 (((fd)->simple.bpid_offset |= (uint32_t)(offset) << 16))
187 #define DPAA2_SET_FD_INTERNAL_JD(fd, len) \
188 ((fd)->simple.frc = (0x80000000 | (len)))
189 #define DPAA2_GET_FD_FRC_PARSE_SUM(fd) \
190 ((uint16_t)(((fd)->simple.frc & 0xffff0000) >> 16))
191 #define DPAA2_SET_FD_FRC(fd, frc) ((fd)->simple.frc = frc)
192 #define DPAA2_RESET_FD_CTRL(fd) ((fd)->simple.ctrl = 0)
194 #define DPAA2_SET_FD_ASAL(fd, asal) ((fd)->simple.ctrl |= (asal << 16))
195 #define DPAA2_SET_FD_FLC(fd, addr) do { \
196 (fd)->simple.flc_lo = lower_32_bits((uint64_t)(addr)); \
197 (fd)->simple.flc_hi = upper_32_bits((uint64_t)(addr)); \
199 #define DPAA2_SET_FLE_INTERNAL_JD(fle, len) ((fle)->frc = (0x80000000 | (len)))
200 #define DPAA2_GET_FLE_ADDR(fle) \
201 (uint64_t)((((uint64_t)((fle)->addr_hi)) << 32) + (fle)->addr_lo)
202 #define DPAA2_SET_FLE_ADDR(fle, addr) do { \
203 (fle)->addr_lo = lower_32_bits((uint64_t)addr); \
204 (fle)->addr_hi = upper_32_bits((uint64_t)addr); \
206 #define DPAA2_GET_FLE_CTXT(fle) \
207 (uint64_t)((((uint64_t)((fle)->reserved[1])) << 32) + \
209 #define DPAA2_FLE_SAVE_CTXT(fle, addr) do { \
210 (fle)->reserved[0] = lower_32_bits((uint64_t)addr); \
211 (fle)->reserved[1] = upper_32_bits((uint64_t)addr); \
213 #define DPAA2_SET_FLE_OFFSET(fle, offset) \
214 ((fle)->fin_bpid_offset |= (uint32_t)(offset) << 16)
215 #define DPAA2_SET_FLE_BPID(fle, bpid) ((fle)->fin_bpid_offset |= (uint64_t)bpid)
216 #define DPAA2_GET_FLE_BPID(fle) ((fle)->fin_bpid_offset & 0x000000ff)
217 #define DPAA2_SET_FLE_FIN(fle) ((fle)->fin_bpid_offset |= (uint64_t)1 << 31)
218 #define DPAA2_SET_FLE_IVP(fle) (((fle)->fin_bpid_offset |= 0x00004000))
219 #define DPAA2_SET_FD_COMPOUND_FMT(fd) \
220 ((fd)->simple.bpid_offset |= (uint32_t)1 << 28)
221 #define DPAA2_GET_FD_ADDR(fd) \
222 ((uint64_t)((((uint64_t)((fd)->simple.addr_hi)) << 32) + (fd)->simple.addr_lo))
224 #define DPAA2_GET_FD_LEN(fd) ((fd)->simple.len)
225 #define DPAA2_GET_FD_BPID(fd) (((fd)->simple.bpid_offset & 0x00003FFF))
226 #define DPAA2_GET_FD_IVP(fd) (((fd)->simple.bpid_offset & 0x00004000) >> 14)
227 #define DPAA2_GET_FD_OFFSET(fd) (((fd)->simple.bpid_offset & 0x0FFF0000) >> 16)
228 #define DPAA2_GET_FLE_OFFSET(fle) (((fle)->fin_bpid_offset & 0x0FFF0000) >> 16)
229 #define DPAA2_SET_FLE_SG_EXT(fle) ((fle)->fin_bpid_offset |= (uint64_t)1 << 29)
230 #define DPAA2_IS_SET_FLE_SG_EXT(fle) \
231 (((fle)->fin_bpid_offset & ((uint64_t)1 << 29)) ? 1 : 0)
233 #define DPAA2_INLINE_MBUF_FROM_BUF(buf, meta_data_size) \
234 ((struct rte_mbuf *)((uint64_t)(buf) - (meta_data_size)))
236 #define DPAA2_ASAL_VAL (DPAA2_MBUF_HW_ANNOTATION / 64)
238 #define DPAA2_FD_SET_FORMAT(fd, format) do { \
239 (fd)->simple.bpid_offset &= 0xCFFFFFFF; \
240 (fd)->simple.bpid_offset |= (uint32_t)format << 28; \
242 #define DPAA2_FD_GET_FORMAT(fd) (((fd)->simple.bpid_offset >> 28) & 0x3)
244 #define DPAA2_SG_SET_FINAL(sg, fin) do { \
245 (sg)->fin_bpid_offset &= 0x7FFFFFFF; \
246 (sg)->fin_bpid_offset |= (uint32_t)fin << 31; \
248 #define DPAA2_SG_IS_FINAL(sg) (!!((sg)->fin_bpid_offset >> 31))
249 /* Only Enqueue Error responses will be
250 * pushed on FQID_ERR of Enqueue FQ
252 #define DPAA2_EQ_RESP_ERR_FQ 0
253 /* All Enqueue responses will be pushed on address
254 * set with qbman_eq_desc_set_response
256 #define DPAA2_EQ_RESP_ALWAYS 1
258 #ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
259 extern uint8_t dpaa2_virt_mode;
260 static void *dpaa2_mem_ptov(phys_addr_t paddr) __attribute__((unused));
261 /* todo - this is costly, need to write a fast coversion routine */
262 static void *dpaa2_mem_ptov(phys_addr_t paddr)
264 const struct rte_memseg *memseg;
268 return (void *)paddr;
270 memseg = rte_eal_get_physmem_layout();
272 for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
273 if (paddr >= memseg[i].iova &&
274 (char *)paddr < (char *)memseg[i].iova + memseg[i].len)
275 return (void *)(memseg[i].addr_64
276 + (paddr - memseg[i].iova));
281 static phys_addr_t dpaa2_mem_vtop(uint64_t vaddr) __attribute__((unused));
282 static phys_addr_t dpaa2_mem_vtop(uint64_t vaddr)
284 const struct rte_memseg *memseg;
290 memseg = rte_eal_get_physmem_layout();
292 for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
293 if (vaddr >= memseg[i].addr_64 &&
294 vaddr < memseg[i].addr_64 + memseg[i].len)
295 return memseg[i].iova
296 + (vaddr - memseg[i].addr_64);
298 return (phys_addr_t)(NULL);
302 * When we are using Physical addresses as IO Virtual Addresses,
303 * Need to call conversion routines dpaa2_mem_vtop & dpaa2_mem_ptov
305 * These routines are called with help of below MACRO's
308 #define DPAA2_MBUF_VADDR_TO_IOVA(mbuf) ((mbuf)->buf_iova)
309 #define DPAA2_OP_VADDR_TO_IOVA(op) (op->phys_addr)
312 * macro to convert Virtual address to IOVA
314 #define DPAA2_VADDR_TO_IOVA(_vaddr) dpaa2_mem_vtop((uint64_t)(_vaddr))
317 * macro to convert IOVA to Virtual address
319 #define DPAA2_IOVA_TO_VADDR(_iova) dpaa2_mem_ptov((phys_addr_t)(_iova))
322 * macro to convert modify the memory containing IOVA to Virtual address
324 #define DPAA2_MODIFY_IOVA_TO_VADDR(_mem, _type) \
325 {_mem = (_type)(dpaa2_mem_ptov((phys_addr_t)(_mem))); }
327 #else /* RTE_LIBRTE_DPAA2_USE_PHYS_IOVA */
329 #define DPAA2_MBUF_VADDR_TO_IOVA(mbuf) ((mbuf)->buf_addr)
330 #define DPAA2_OP_VADDR_TO_IOVA(op) (op)
331 #define DPAA2_VADDR_TO_IOVA(_vaddr) (_vaddr)
332 #define DPAA2_IOVA_TO_VADDR(_iova) (_iova)
333 #define DPAA2_MODIFY_IOVA_TO_VADDR(_mem, _type)
335 #endif /* RTE_LIBRTE_DPAA2_USE_PHYS_IOVA */
338 int check_swp_active_dqs(uint16_t dpio_index)
340 if (rte_global_active_dqs_list[dpio_index].global_active_dqs != NULL)
346 void clear_swp_active_dqs(uint16_t dpio_index)
348 rte_global_active_dqs_list[dpio_index].global_active_dqs = NULL;
352 struct qbman_result *get_swp_active_dqs(uint16_t dpio_index)
354 return rte_global_active_dqs_list[dpio_index].global_active_dqs;
358 void set_swp_active_dqs(uint16_t dpio_index, struct qbman_result *dqs)
360 rte_global_active_dqs_list[dpio_index].global_active_dqs = dqs;
362 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void);
363 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp);
364 int dpaa2_dpbp_supported(void);
366 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void);
367 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci);