bus/fslmc: support check of dpbp presence
[dpdk.git] / drivers / bus / fslmc / portal / dpaa2_hw_pvt.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright 2016 NXP.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Freescale Semiconductor, Inc nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _DPAA2_HW_PVT_H_
35 #define _DPAA2_HW_PVT_H_
36
37 #include <rte_eventdev.h>
38
39 #include <mc/fsl_mc_sys.h>
40 #include <fsl_qbman_portal.h>
41
42 #ifndef false
43 #define false      0
44 #endif
45 #ifndef true
46 #define true       1
47 #endif
48 #define lower_32_bits(x) ((uint32_t)(x))
49 #define upper_32_bits(x) ((uint32_t)(((x) >> 16) >> 16))
50
51 #define SVR_LS1080A             0x87030000
52 #define SVR_LS2080A             0x87010000
53 #define SVR_LS2088A             0x87090000
54 #define SVR_LX2160A             0x87360000
55
56 #ifndef ETH_VLAN_HLEN
57 #define ETH_VLAN_HLEN   4 /** < Vlan Header Length */
58 #endif
59
60 #define MAX_TX_RING_SLOTS       8
61         /** <Maximum number of slots available in TX ring*/
62
63 #define DPAA2_DQRR_RING_SIZE    16
64         /** <Maximum number of slots available in RX ring*/
65
66 #define MC_PORTAL_INDEX         0
67 #define NUM_DPIO_REGIONS        2
68 #define NUM_DQS_PER_QUEUE       2
69
70 /* Maximum release/acquire from QBMAN */
71 #define DPAA2_MBUF_MAX_ACQ_REL  7
72
73 #define MAX_BPID 256
74 #define DPAA2_MBUF_HW_ANNOTATION        64
75 #define DPAA2_FD_PTA_SIZE               0
76
77 #if (DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) > RTE_PKTMBUF_HEADROOM
78 #error "Annotation requirement is more than RTE_PKTMBUF_HEADROOM"
79 #endif
80
81 /* we will re-use the HEADROOM for annotation in RX */
82 #define DPAA2_HW_BUF_RESERVE    0
83 #define DPAA2_PACKET_LAYOUT_ALIGN       64 /*changing from 256 */
84
85 #define DPAA2_DPCI_MAX_QUEUES 2
86
87 struct dpaa2_dpio_dev {
88         TAILQ_ENTRY(dpaa2_dpio_dev) next;
89                 /**< Pointer to Next device instance */
90         uint16_t index; /**< Index of a instance in the list */
91         rte_atomic16_t ref_count;
92                 /**< How many thread contexts are sharing this.*/
93         struct fsl_mc_io *dpio; /** handle to DPIO portal object */
94         uint16_t token;
95         struct qbman_swp *sw_portal; /** SW portal object */
96         const struct qbman_result *dqrr[4];
97                 /**< DQRR Entry for this SW portal */
98         void *mc_portal; /**< MC Portal for configuring this device */
99         uintptr_t qbman_portal_ce_paddr;
100                 /**< Physical address of Cache Enabled Area */
101         uintptr_t ce_size; /**< Size of the CE region */
102         uintptr_t qbman_portal_ci_paddr;
103                 /**< Physical address of Cache Inhibit Area */
104         uintptr_t ci_size; /**< Size of the CI region */
105         struct rte_intr_handle intr_handle; /* Interrupt related info */
106         int32_t epoll_fd; /**< File descriptor created for interrupt polling */
107         int32_t hw_id; /**< An unique ID of this DPIO device instance */
108         uint64_t dqrr_held;
109         uint8_t dqrr_size;
110 };
111
112 struct dpaa2_dpbp_dev {
113         TAILQ_ENTRY(dpaa2_dpbp_dev) next;
114                 /**< Pointer to Next device instance */
115         struct fsl_mc_io dpbp;  /** handle to DPBP portal object */
116         uint16_t token;
117         rte_atomic16_t in_use;
118         uint32_t dpbp_id; /*HW ID for DPBP object */
119 };
120
121 struct queue_storage_info_t {
122         struct qbman_result *dq_storage[NUM_DQS_PER_QUEUE];
123         struct qbman_result *active_dqs;
124         int active_dpio_id;
125         int toggle;
126 };
127
128 typedef void (dpaa2_queue_cb_dqrr_t)(struct qbman_swp *swp,
129                 const struct qbman_fd *fd,
130                 const struct qbman_result *dq,
131                 struct rte_event *ev);
132
133 struct dpaa2_queue {
134         struct rte_mempool *mb_pool; /**< mbuf pool to populate RX ring. */
135         void *dev;
136         int32_t eventfd;        /*!< Event Fd of this queue */
137         uint32_t fqid;          /*!< Unique ID of this queue */
138         uint8_t tc_index;       /*!< traffic class identifier */
139         uint16_t flow_id;       /*!< To be used by DPAA2 frmework */
140         uint64_t rx_pkts;
141         uint64_t tx_pkts;
142         uint64_t err_pkts;
143         union {
144                 struct queue_storage_info_t *q_storage;
145                 struct qbman_result *cscn;
146         };
147         dpaa2_queue_cb_dqrr_t *cb;
148 };
149
150 struct swp_active_dqs {
151         struct qbman_result *global_active_dqs;
152         uint64_t reserved[7];
153 };
154
155 #define NUM_MAX_SWP 64
156
157 extern struct swp_active_dqs rte_global_active_dqs_list[NUM_MAX_SWP];
158
159 struct dpaa2_dpci_dev {
160         TAILQ_ENTRY(dpaa2_dpci_dev) next;
161                 /**< Pointer to Next device instance */
162         struct fsl_mc_io dpci;  /** handle to DPCI portal object */
163         uint16_t token;
164         rte_atomic16_t in_use;
165         uint32_t dpci_id; /*HW ID for DPCI object */
166         struct dpaa2_queue queue[DPAA2_DPCI_MAX_QUEUES];
167 };
168
169 /*! Global MCP list */
170 extern void *(*rte_mcp_ptr_list);
171
172 /* Refer to Table 7-3 in SEC BG */
173 struct qbman_fle {
174         uint32_t addr_lo;
175         uint32_t addr_hi;
176         uint32_t length;
177         /* FMT must be 00, MSB is final bit  */
178         uint32_t fin_bpid_offset;
179         uint32_t frc;
180         uint32_t reserved[3]; /* Not used currently */
181 };
182
183 struct qbman_sge {
184         uint32_t addr_lo;
185         uint32_t addr_hi;
186         uint32_t length;
187         uint32_t fin_bpid_offset;
188 };
189
190 /* There are three types of frames: Single, Scatter Gather and Frame Lists */
191 enum qbman_fd_format {
192         qbman_fd_single = 0,
193         qbman_fd_list,
194         qbman_fd_sg
195 };
196 /*Macros to define operations on FD*/
197 #define DPAA2_SET_FD_ADDR(fd, addr) do {                        \
198         fd->simple.addr_lo = lower_32_bits((uint64_t)(addr));   \
199         fd->simple.addr_hi = upper_32_bits((uint64_t)(addr));   \
200 } while (0)
201 #define DPAA2_SET_FD_LEN(fd, length)    (fd)->simple.len = length
202 #define DPAA2_SET_FD_BPID(fd, bpid)     ((fd)->simple.bpid_offset |= bpid)
203 #define DPAA2_SET_FD_IVP(fd)   ((fd->simple.bpid_offset |= 0x00004000))
204 #define DPAA2_SET_FD_OFFSET(fd, offset) \
205         ((fd->simple.bpid_offset |= (uint32_t)(offset) << 16))
206 #define DPAA2_SET_FD_INTERNAL_JD(fd, len) fd->simple.frc = (0x80000000 | (len))
207 #define DPAA2_SET_FD_FRC(fd, frc)       fd->simple.frc = frc
208 #define DPAA2_RESET_FD_CTRL(fd) (fd)->simple.ctrl = 0
209
210 #define DPAA2_SET_FD_ASAL(fd, asal)     ((fd)->simple.ctrl |= (asal << 16))
211 #define DPAA2_SET_FD_FLC(fd, addr)      do { \
212         fd->simple.flc_lo = lower_32_bits((uint64_t)(addr));    \
213         fd->simple.flc_hi = upper_32_bits((uint64_t)(addr));    \
214 } while (0)
215 #define DPAA2_SET_FLE_INTERNAL_JD(fle, len) (fle->frc = (0x80000000 | (len)))
216 #define DPAA2_GET_FLE_ADDR(fle)                                 \
217         (uint64_t)((((uint64_t)(fle->addr_hi)) << 32) + fle->addr_lo)
218 #define DPAA2_SET_FLE_ADDR(fle, addr) do { \
219         fle->addr_lo = lower_32_bits((uint64_t)addr);     \
220         fle->addr_hi = upper_32_bits((uint64_t)addr);     \
221 } while (0)
222 #define DPAA2_GET_FLE_CTXT(fle)                                 \
223         (uint64_t)((((uint64_t)((fle)->reserved[1])) << 32) + \
224                         (fle)->reserved[0])
225 #define DPAA2_FLE_SAVE_CTXT(fle, addr) do { \
226         fle->reserved[0] = lower_32_bits((uint64_t)addr);     \
227         fle->reserved[1] = upper_32_bits((uint64_t)addr);         \
228 } while (0)
229 #define DPAA2_SET_FLE_OFFSET(fle, offset) \
230         ((fle)->fin_bpid_offset |= (uint32_t)(offset) << 16)
231 #define DPAA2_SET_FLE_BPID(fle, bpid) ((fle)->fin_bpid_offset |= (uint64_t)bpid)
232 #define DPAA2_GET_FLE_BPID(fle) ((fle)->fin_bpid_offset & 0x000000ff)
233 #define DPAA2_SET_FLE_FIN(fle)  (fle->fin_bpid_offset |= (uint64_t)1 << 31)
234 #define DPAA2_SET_FLE_IVP(fle)   (((fle)->fin_bpid_offset |= 0x00004000))
235 #define DPAA2_SET_FD_COMPOUND_FMT(fd)   \
236         (fd->simple.bpid_offset |= (uint32_t)1 << 28)
237 #define DPAA2_GET_FD_ADDR(fd)   \
238 ((uint64_t)((((uint64_t)((fd)->simple.addr_hi)) << 32) + (fd)->simple.addr_lo))
239
240 #define DPAA2_GET_FD_LEN(fd)    ((fd)->simple.len)
241 #define DPAA2_GET_FD_BPID(fd)   (((fd)->simple.bpid_offset & 0x00003FFF))
242 #define DPAA2_GET_FD_IVP(fd)   ((fd->simple.bpid_offset & 0x00004000) >> 14)
243 #define DPAA2_GET_FD_OFFSET(fd) (((fd)->simple.bpid_offset & 0x0FFF0000) >> 16)
244 #define DPAA2_GET_FLE_OFFSET(fle) (((fle)->fin_bpid_offset & 0x0FFF0000) >> 16)
245 #define DPAA2_SET_FLE_SG_EXT(fle) (fle->fin_bpid_offset |= (uint64_t)1 << 29)
246 #define DPAA2_IS_SET_FLE_SG_EXT(fle)    \
247         ((fle->fin_bpid_offset & ((uint64_t)1 << 29)) ? 1 : 0)
248
249 #define DPAA2_INLINE_MBUF_FROM_BUF(buf, meta_data_size) \
250         ((struct rte_mbuf *)((uint64_t)(buf) - (meta_data_size)))
251
252 #define DPAA2_ASAL_VAL (DPAA2_MBUF_HW_ANNOTATION / 64)
253
254 #define DPAA2_FD_SET_FORMAT(fd, format) do {                            \
255                 (fd)->simple.bpid_offset &= 0xCFFFFFFF;                 \
256                 (fd)->simple.bpid_offset |= (uint32_t)format << 28;     \
257 } while (0)
258 #define DPAA2_FD_GET_FORMAT(fd) (((fd)->simple.bpid_offset >> 28) & 0x3)
259
260 #define DPAA2_SG_SET_FINAL(sg, fin)     do {                            \
261                 (sg)->fin_bpid_offset &= 0x7FFFFFFF;                    \
262                 (sg)->fin_bpid_offset |= (uint32_t)fin << 31;           \
263 } while (0)
264 #define DPAA2_SG_IS_FINAL(sg) (!!((sg)->fin_bpid_offset >> 31))
265 /* Only Enqueue Error responses will be
266  * pushed on FQID_ERR of Enqueue FQ
267  */
268 #define DPAA2_EQ_RESP_ERR_FQ            0
269 /* All Enqueue responses will be pushed on address
270  * set with qbman_eq_desc_set_response
271  */
272 #define DPAA2_EQ_RESP_ALWAYS            1
273
274 #ifdef RTE_LIBRTE_DPAA2_USE_PHYS_IOVA
275 static void *dpaa2_mem_ptov(phys_addr_t paddr) __attribute__((unused));
276 /* todo - this is costly, need to write a fast coversion routine */
277 static void *dpaa2_mem_ptov(phys_addr_t paddr)
278 {
279         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
280         int i;
281
282         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
283                 if (paddr >= memseg[i].phys_addr &&
284                    (char *)paddr < (char *)memseg[i].phys_addr + memseg[i].len)
285                         return (void *)(memseg[i].addr_64
286                                 + (paddr - memseg[i].phys_addr));
287         }
288         return NULL;
289 }
290
291 static phys_addr_t dpaa2_mem_vtop(uint64_t vaddr) __attribute__((unused));
292 static phys_addr_t dpaa2_mem_vtop(uint64_t vaddr)
293 {
294         const struct rte_memseg *memseg = rte_eal_get_physmem_layout();
295         int i;
296
297         for (i = 0; i < RTE_MAX_MEMSEG && memseg[i].addr_64 != 0; i++) {
298                 if (vaddr >= memseg[i].addr_64 &&
299                     vaddr < memseg[i].addr_64 + memseg[i].len)
300                         return memseg[i].phys_addr
301                                 + (vaddr - memseg[i].addr_64);
302         }
303         return (phys_addr_t)(NULL);
304 }
305
306 /**
307  * When we are using Physical addresses as IO Virtual Addresses,
308  * Need to call conversion routines dpaa2_mem_vtop & dpaa2_mem_ptov
309  * wherever required.
310  * These routines are called with help of below MACRO's
311  */
312
313 #define DPAA2_MBUF_VADDR_TO_IOVA(mbuf) ((mbuf)->buf_physaddr)
314 #define DPAA2_OP_VADDR_TO_IOVA(op) (op->phys_addr)
315
316 /**
317  * macro to convert Virtual address to IOVA
318  */
319 #define DPAA2_VADDR_TO_IOVA(_vaddr) dpaa2_mem_vtop((uint64_t)(_vaddr))
320
321 /**
322  * macro to convert IOVA to Virtual address
323  */
324 #define DPAA2_IOVA_TO_VADDR(_iova) dpaa2_mem_ptov((phys_addr_t)(_iova))
325
326 /**
327  * macro to convert modify the memory containing IOVA to Virtual address
328  */
329 #define DPAA2_MODIFY_IOVA_TO_VADDR(_mem, _type) \
330         {_mem = (_type)(dpaa2_mem_ptov((phys_addr_t)(_mem))); }
331
332 #else   /* RTE_LIBRTE_DPAA2_USE_PHYS_IOVA */
333
334 #define DPAA2_MBUF_VADDR_TO_IOVA(mbuf) ((mbuf)->buf_addr)
335 #define DPAA2_OP_VADDR_TO_IOVA(op) (op)
336 #define DPAA2_VADDR_TO_IOVA(_vaddr) (_vaddr)
337 #define DPAA2_IOVA_TO_VADDR(_iova) (_iova)
338 #define DPAA2_MODIFY_IOVA_TO_VADDR(_mem, _type)
339
340 #endif /* RTE_LIBRTE_DPAA2_USE_PHYS_IOVA */
341
342 static inline
343 int check_swp_active_dqs(uint16_t dpio_index)
344 {
345         if (rte_global_active_dqs_list[dpio_index].global_active_dqs != NULL)
346                 return 1;
347         return 0;
348 }
349
350 static inline
351 void clear_swp_active_dqs(uint16_t dpio_index)
352 {
353         rte_global_active_dqs_list[dpio_index].global_active_dqs = NULL;
354 }
355
356 static inline
357 struct qbman_result *get_swp_active_dqs(uint16_t dpio_index)
358 {
359         return rte_global_active_dqs_list[dpio_index].global_active_dqs;
360 }
361
362 static inline
363 void set_swp_active_dqs(uint16_t dpio_index, struct qbman_result *dqs)
364 {
365         rte_global_active_dqs_list[dpio_index].global_active_dqs = dqs;
366 }
367 struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void);
368 void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp);
369 int dpaa2_dpbp_supported(void);
370
371 struct dpaa2_dpci_dev *rte_dpaa2_alloc_dpci_dev(void);
372 void rte_dpaa2_free_dpci_dev(struct dpaa2_dpci_dev *dpci);
373
374 #endif