Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 : : * Copyright 2016-2024 NXP
5 : : *
6 : : */
7 : :
8 : : #include <time.h>
9 : : #include <net/if.h>
10 : :
11 : : #include <eal_export.h>
12 : : #include <rte_mbuf.h>
13 : : #include <ethdev_driver.h>
14 : : #include <rte_malloc.h>
15 : : #include <rte_memcpy.h>
16 : : #include <rte_string_fns.h>
17 : : #include <dev_driver.h>
18 : : #include <rte_hexdump.h>
19 : :
20 : : #include <bus_fslmc_driver.h>
21 : : #include <fslmc_vfio.h>
22 : : #include <dpaa2_hw_pvt.h>
23 : : #include <dpaa2_hw_dpio.h>
24 : : #include <dpaa2_hw_mempool.h>
25 : :
26 : : #include "dpaa2_pmd_logs.h"
27 : : #include "dpaa2_ethdev.h"
28 : : #include "base/dpaa2_hw_dpni_annot.h"
29 : : #include "dpaa2_parse_dump.h"
30 : :
31 : : static inline uint32_t __rte_hot
32 : : dpaa2_dev_rx_parse_slow(struct rte_mbuf *mbuf,
33 : : struct dpaa2_annot_hdr *annotation);
34 : :
35 : : static void enable_tx_tstamp(struct qbman_fd *fd) __rte_unused;
36 : :
37 : : static inline rte_mbuf_timestamp_t *
38 : : dpaa2_timestamp_dynfield(struct rte_mbuf *mbuf)
39 : : {
40 : 0 : return RTE_MBUF_DYNFIELD(mbuf,
41 : : dpaa2_timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
42 : : }
43 : :
44 : : #define DPAA2_MBUF_TO_CONTIG_FD(_mbuf, _fd, _bpid) do { \
45 : : DPAA2_SET_FD_ADDR(_fd, DPAA2_MBUF_VADDR_TO_IOVA(_mbuf)); \
46 : : DPAA2_SET_FD_LEN(_fd, _mbuf->data_len); \
47 : : DPAA2_SET_ONLY_FD_BPID(_fd, _bpid); \
48 : : DPAA2_SET_FD_OFFSET(_fd, _mbuf->data_off); \
49 : : DPAA2_SET_FD_FRC(_fd, 0); \
50 : : DPAA2_RESET_FD_CTRL(_fd); \
51 : : DPAA2_RESET_FD_FLC(_fd); \
52 : : } while (0)
53 : :
54 : : static inline void __rte_hot
55 : 0 : dpaa2_dev_rx_parse_new(struct rte_mbuf *m, const struct qbman_fd *fd,
56 : : void *hw_annot_addr)
57 : : {
58 : 0 : uint16_t frc = DPAA2_GET_FD_FRC_PARSE_SUM(fd);
59 : : struct dpaa2_annot_hdr *annotation =
60 : : (struct dpaa2_annot_hdr *)hw_annot_addr;
61 : :
62 [ # # ]: 0 : if (unlikely(dpaa2_print_parser_result))
63 : 0 : dpaa2_print_parse_result(annotation);
64 : :
65 : 0 : m->packet_type = RTE_PTYPE_UNKNOWN;
66 [ # # # # : 0 : switch (frc) {
# # # # #
# # # #
# ]
67 : 0 : case DPAA2_PKT_TYPE_ETHER:
68 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER;
69 : 0 : break;
70 : 0 : case DPAA2_PKT_TYPE_IPV4:
71 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
72 : : RTE_PTYPE_L3_IPV4;
73 : 0 : break;
74 : 0 : case DPAA2_PKT_TYPE_IPV6:
75 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
76 : : RTE_PTYPE_L3_IPV6;
77 : 0 : break;
78 : 0 : case DPAA2_PKT_TYPE_IPV4_EXT:
79 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
80 : : RTE_PTYPE_L3_IPV4_EXT;
81 : 0 : break;
82 : 0 : case DPAA2_PKT_TYPE_IPV6_EXT:
83 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
84 : : RTE_PTYPE_L3_IPV6_EXT;
85 : 0 : break;
86 : 0 : case DPAA2_PKT_TYPE_IPV4_TCP:
87 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
88 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP;
89 : 0 : break;
90 : 0 : case DPAA2_PKT_TYPE_IPV6_TCP:
91 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
92 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
93 : 0 : break;
94 : 0 : case DPAA2_PKT_TYPE_IPV4_UDP:
95 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
96 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP;
97 : 0 : break;
98 : 0 : case DPAA2_PKT_TYPE_IPV6_UDP:
99 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
100 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
101 : 0 : break;
102 : 0 : case DPAA2_PKT_TYPE_IPV4_SCTP:
103 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
104 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP;
105 : 0 : break;
106 : 0 : case DPAA2_PKT_TYPE_IPV6_SCTP:
107 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
108 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_SCTP;
109 : 0 : break;
110 : 0 : case DPAA2_PKT_TYPE_IPV4_ICMP:
111 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
112 : : RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_ICMP;
113 : 0 : break;
114 : 0 : case DPAA2_PKT_TYPE_IPV6_ICMP:
115 : 0 : m->packet_type = RTE_PTYPE_L2_ETHER |
116 : : RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_ICMP;
117 : 0 : break;
118 : 0 : default:
119 : 0 : m->packet_type = dpaa2_dev_rx_parse_slow(m, annotation);
120 : : }
121 : 0 : m->hash.rss = fd->simple.flc_hi;
122 : 0 : m->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
123 : :
124 [ # # ]: 0 : if (dpaa2_enable_ts[m->port]) {
125 : 0 : *dpaa2_timestamp_dynfield(m) = annotation->word2;
126 : 0 : m->ol_flags |= dpaa2_timestamp_rx_dynflag;
127 : : DPAA2_PMD_DP_DEBUG("pkt timestamp:0x%" PRIx64 "",
128 : : *dpaa2_timestamp_dynfield(m));
129 : : }
130 : :
131 : : DPAA2_PMD_DP_DEBUG("HW frc = 0x%x\t packet type =0x%x "
132 : : "ol_flags =0x%" PRIx64 "",
133 : : frc, m->packet_type, m->ol_flags);
134 : 0 : }
135 : :
136 : : static inline uint32_t __rte_hot
137 : 0 : dpaa2_dev_rx_parse_slow(struct rte_mbuf *mbuf,
138 : : struct dpaa2_annot_hdr *annotation)
139 : : {
140 : : uint32_t pkt_type = RTE_PTYPE_UNKNOWN;
141 : : uint16_t *vlan_tci;
142 : :
143 : : DPAA2_PMD_DP_DEBUG("(slow parse)annotation(3)=0x%" PRIx64 "\t"
144 : : "(4)=0x%" PRIx64 "\t",
145 : : annotation->word3, annotation->word4);
146 : :
147 : : #if defined(RTE_LIBRTE_IEEE1588)
148 : : if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_PTP)) {
149 : : mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
150 : : mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_TMST;
151 : : }
152 : : #endif
153 : :
154 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word3, L2_VLAN_1_PRESENT)) {
155 : 0 : vlan_tci = rte_pktmbuf_mtod_offset(mbuf, uint16_t *,
156 : : (VLAN_TCI_OFFSET_1(annotation->word5) >> 16));
157 [ # # ]: 0 : mbuf->vlan_tci = rte_be_to_cpu_16(*vlan_tci);
158 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN;
159 : : pkt_type |= RTE_PTYPE_L2_ETHER_VLAN;
160 [ # # ]: 0 : } else if (BIT_ISSET_AT_POS(annotation->word3, L2_VLAN_N_PRESENT)) {
161 : 0 : vlan_tci = rte_pktmbuf_mtod_offset(mbuf, uint16_t *,
162 : : (VLAN_TCI_OFFSET_1(annotation->word5) >> 16));
163 [ # # ]: 0 : mbuf->vlan_tci = rte_be_to_cpu_16(*vlan_tci);
164 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_QINQ;
165 : : pkt_type |= RTE_PTYPE_L2_ETHER_QINQ;
166 : : }
167 : :
168 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word3, L2_ARP_PRESENT)) {
169 : 0 : pkt_type |= RTE_PTYPE_L2_ETHER_ARP;
170 : 0 : goto parse_done;
171 [ # # ]: 0 : } else if (BIT_ISSET_AT_POS(annotation->word3, L2_ETH_MAC_PRESENT)) {
172 : 0 : pkt_type |= RTE_PTYPE_L2_ETHER;
173 : : } else {
174 : 0 : goto parse_done;
175 : : }
176 : :
177 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word3, L2_MPLS_1_PRESENT |
178 : : L2_MPLS_N_PRESENT))
179 : 0 : pkt_type |= RTE_PTYPE_L2_ETHER_MPLS;
180 : :
181 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_IPV4_1_PRESENT |
182 : : L3_IPV4_N_PRESENT)) {
183 : 0 : pkt_type |= RTE_PTYPE_L3_IPV4;
184 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_IP_1_OPT_PRESENT |
185 : : L3_IP_N_OPT_PRESENT))
186 : 0 : pkt_type |= RTE_PTYPE_L3_IPV4_EXT;
187 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_IPSEC_ESP_PRESENT |
188 : : L3_PROTO_ESP_PRESENT))
189 : 0 : pkt_type |= RTE_PTYPE_TUNNEL_ESP;
190 : :
191 [ # # ]: 0 : } else if (BIT_ISSET_AT_POS(annotation->word4, L3_IPV6_1_PRESENT |
192 : : L3_IPV6_N_PRESENT)) {
193 : 0 : pkt_type |= RTE_PTYPE_L3_IPV6;
194 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_IP_1_OPT_PRESENT |
195 : : L3_IP_N_OPT_PRESENT))
196 : 0 : pkt_type |= RTE_PTYPE_L3_IPV6_EXT;
197 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_IPSEC_ESP_PRESENT |
198 : : L3_PROTO_ESP_PRESENT))
199 : 0 : pkt_type |= RTE_PTYPE_TUNNEL_ESP;
200 : : } else {
201 : 0 : goto parse_done;
202 : : }
203 : :
204 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L3CE))
205 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
206 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L3CV))
207 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
208 : :
209 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L4CE))
210 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
211 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L4CV))
212 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
213 : :
214 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_IP_1_FIRST_FRAGMENT |
215 : : L3_IP_1_MORE_FRAGMENT |
216 : : L3_IP_N_FIRST_FRAGMENT |
217 : : L3_IP_N_MORE_FRAGMENT)) {
218 : 0 : pkt_type |= RTE_PTYPE_L4_FRAG;
219 : 0 : goto parse_done;
220 : : }
221 : :
222 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_UDP_PRESENT))
223 : 0 : pkt_type |= RTE_PTYPE_L4_UDP;
224 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_TCP_PRESENT))
225 : 0 : pkt_type |= RTE_PTYPE_L4_TCP;
226 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_SCTP_PRESENT))
227 : 0 : pkt_type |= RTE_PTYPE_L4_SCTP;
228 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word4, L3_PROTO_ICMP_PRESENT))
229 : 0 : pkt_type |= RTE_PTYPE_L4_ICMP;
230 : : else
231 : 0 : pkt_type |= RTE_PTYPE_L4_NONFRAG;
232 : :
233 : 0 : parse_done:
234 : 0 : return pkt_type;
235 : : }
236 : :
237 : : static inline uint32_t __rte_hot
238 : 0 : dpaa2_dev_rx_parse(struct rte_mbuf *mbuf, void *hw_annot_addr)
239 : : {
240 : : struct dpaa2_annot_hdr *annotation =
241 : : (struct dpaa2_annot_hdr *)hw_annot_addr;
242 : :
243 : : DPAA2_PMD_DP_DEBUG("(fast parse) Annotation = 0x%" PRIx64 "\t",
244 : : annotation->word4);
245 : :
246 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L3CE))
247 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
248 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L3CV))
249 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
250 : :
251 [ # # ]: 0 : if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L4CE))
252 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
253 [ # # ]: 0 : else if (BIT_ISSET_AT_POS(annotation->word1, DPAA2_ETH_FAS_L4CV))
254 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
255 : :
256 [ # # ]: 0 : if (unlikely(dpaa2_print_parser_result))
257 : 0 : dpaa2_print_parse_result(annotation);
258 : :
259 [ # # ]: 0 : if (dpaa2_enable_ts[mbuf->port]) {
260 : 0 : *dpaa2_timestamp_dynfield(mbuf) = annotation->word2;
261 : 0 : mbuf->ol_flags |= dpaa2_timestamp_rx_dynflag;
262 : : DPAA2_PMD_DP_DEBUG("pkt timestamp: 0x%" PRIx64 "",
263 : : *dpaa2_timestamp_dynfield(mbuf));
264 : : }
265 : :
266 : : /* Check detailed parsing requirement */
267 [ # # ]: 0 : if (annotation->word3 & 0x7FFFFC3FFFF)
268 : 0 : return dpaa2_dev_rx_parse_slow(mbuf, annotation);
269 : :
270 : : /* Return some common types from parse processing */
271 [ # # # # : 0 : switch (annotation->word4) {
# # # ]
272 : : case DPAA2_L3_IPv4:
273 : : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
274 : 0 : case DPAA2_L3_IPv6:
275 : 0 : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
276 : 0 : case DPAA2_L3_IPv4_TCP:
277 : 0 : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 |
278 : : RTE_PTYPE_L4_TCP;
279 : 0 : case DPAA2_L3_IPv4_UDP:
280 : 0 : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 |
281 : : RTE_PTYPE_L4_UDP;
282 : 0 : case DPAA2_L3_IPv6_TCP:
283 : 0 : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6 |
284 : : RTE_PTYPE_L4_TCP;
285 : 0 : case DPAA2_L3_IPv6_UDP:
286 : 0 : return RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6 |
287 : : RTE_PTYPE_L4_UDP;
288 : : default:
289 : : break;
290 : : }
291 : :
292 : 0 : return dpaa2_dev_rx_parse_slow(mbuf, annotation);
293 : : }
294 : :
295 : : static inline struct rte_mbuf *__rte_hot
296 : 0 : eth_sg_fd_to_mbuf(const struct qbman_fd *fd,
297 : : int port_id)
298 : : {
299 : : struct qbman_sge *sgt, *sge;
300 : : size_t sg_addr, fd_addr;
301 : : int i = 0;
302 : : void *hw_annot_addr;
303 : : struct rte_mbuf *first_seg, *next_seg, *cur_seg, *temp;
304 : :
305 : 0 : fd_addr = (size_t)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
306 : : hw_annot_addr = (void *)(fd_addr + DPAA2_FD_PTA_SIZE);
307 : :
308 : : /* Get Scatter gather table address */
309 : 0 : sgt = (struct qbman_sge *)(fd_addr + DPAA2_GET_FD_OFFSET(fd));
310 : :
311 : : sge = &sgt[i++];
312 : 0 : sg_addr = (size_t)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FLE_ADDR(sge));
313 : :
314 : : /* First Scatter gather entry */
315 : 0 : first_seg = DPAA2_INLINE_MBUF_FROM_BUF(sg_addr,
316 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
317 : : /* Prepare all the metadata for first segment */
318 : 0 : first_seg->buf_addr = (uint8_t *)sg_addr;
319 : 0 : first_seg->ol_flags = 0;
320 : 0 : first_seg->data_off = DPAA2_GET_FLE_OFFSET(sge);
321 : 0 : first_seg->data_len = sge->length & 0x1FFFF;
322 : 0 : first_seg->pkt_len = DPAA2_GET_FD_LEN(fd);
323 : 0 : first_seg->nb_segs = 1;
324 : 0 : first_seg->next = NULL;
325 : 0 : first_seg->port = port_id;
326 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LX2160A)
327 : 0 : dpaa2_dev_rx_parse_new(first_seg, fd, hw_annot_addr);
328 : : else
329 : 0 : first_seg->packet_type =
330 : 0 : dpaa2_dev_rx_parse(first_seg, hw_annot_addr);
331 : :
332 : : rte_mbuf_refcnt_set(first_seg, 1);
333 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
334 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)first_seg),
335 : : (void **)&first_seg, 1, 1);
336 : : #endif
337 : : cur_seg = first_seg;
338 [ # # # # ]: 0 : while (!DPAA2_SG_IS_FINAL(sge) && i < DPAA2_MAX_SGS) {
339 : 0 : sge = &sgt[i++];
340 : 0 : sg_addr = (size_t)DPAA2_IOVA_TO_VADDR(
341 : : DPAA2_GET_FLE_ADDR(sge));
342 : 0 : next_seg = DPAA2_INLINE_MBUF_FROM_BUF(sg_addr,
343 : : rte_dpaa2_bpid_info[DPAA2_GET_FLE_BPID(sge)].meta_data_size);
344 : 0 : next_seg->buf_addr = (uint8_t *)sg_addr;
345 : 0 : next_seg->data_off = DPAA2_GET_FLE_OFFSET(sge);
346 : 0 : next_seg->data_len = sge->length & 0x1FFFF;
347 : 0 : first_seg->nb_segs += 1;
348 : : rte_mbuf_refcnt_set(next_seg, 1);
349 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
350 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)next_seg),
351 : : (void **)&next_seg, 1, 1);
352 : : #endif
353 : 0 : cur_seg->next = next_seg;
354 : 0 : next_seg->next = NULL;
355 : : cur_seg = next_seg;
356 : : }
357 [ # # ]: 0 : temp = DPAA2_INLINE_MBUF_FROM_BUF(fd_addr,
358 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
359 : : rte_mbuf_refcnt_set(temp, 1);
360 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
361 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)temp),
362 : : (void **)&temp, 1, 1);
363 : : #endif
364 : : rte_pktmbuf_free_seg(temp);
365 : :
366 : 0 : return (void *)first_seg;
367 : : }
368 : :
369 : : static inline struct rte_mbuf *__rte_hot
370 : 0 : eth_fd_to_mbuf(const struct qbman_fd *fd,
371 : : int port_id)
372 : : {
373 : 0 : void *v_addr = DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
374 : : void *hw_annot_addr = (void *)((size_t)v_addr + DPAA2_FD_PTA_SIZE);
375 : 0 : struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(v_addr,
376 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
377 : :
378 : : /* need to repopulated some of the fields,
379 : : * as they may have changed in last transmission
380 : : */
381 : 0 : mbuf->nb_segs = 1;
382 : 0 : mbuf->ol_flags = 0;
383 : 0 : mbuf->data_off = DPAA2_GET_FD_OFFSET(fd);
384 : 0 : mbuf->data_len = DPAA2_GET_FD_LEN(fd);
385 : 0 : mbuf->pkt_len = mbuf->data_len;
386 : 0 : mbuf->port = port_id;
387 : 0 : mbuf->next = NULL;
388 [ # # ]: 0 : mbuf->hash.sched.color = DPAA2_GET_FD_DROPP(fd);
389 : : rte_mbuf_refcnt_set(mbuf, 1);
390 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
391 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)mbuf),
392 : : (void **)&mbuf, 1, 1);
393 : : #endif
394 : :
395 : : /* Parse the packet */
396 : : /* parse results for LX2 are there in FRC field of FD.
397 : : * For other DPAA2 platforms , parse results are after
398 : : * the private - sw annotation area
399 : : */
400 : :
401 [ # # ]: 0 : if (dpaa2_svr_family == SVR_LX2160A)
402 : 0 : dpaa2_dev_rx_parse_new(mbuf, fd, hw_annot_addr);
403 : : else
404 : 0 : mbuf->packet_type = dpaa2_dev_rx_parse(mbuf, hw_annot_addr);
405 : :
406 : : DPAA2_PMD_DP_DEBUG("to mbuf - mbuf =%p, mbuf->buf_addr =%p, off = %d,"
407 : : "fd_off=%d fd =%" PRIx64 ", meta = %d bpid =%d, len=%d",
408 : : mbuf, mbuf->buf_addr, mbuf->data_off,
409 : : DPAA2_GET_FD_OFFSET(fd), DPAA2_GET_FD_ADDR(fd),
410 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
411 : : DPAA2_GET_FD_BPID(fd), DPAA2_GET_FD_LEN(fd));
412 : :
413 : 0 : return mbuf;
414 : : }
415 : :
416 : : static int __rte_noinline __rte_hot
417 : 0 : eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf,
418 : : struct qbman_fd *fd,
419 : : struct sw_buf_free *free_buf,
420 : : uint32_t *free_count,
421 : : uint32_t pkt_id,
422 : : uint16_t bpid)
423 : : {
424 : : struct rte_mbuf *cur_seg = mbuf, *mi, *temp;
425 : : struct qbman_sge *sgt, *sge = NULL;
426 : : int i, offset = 0;
427 : :
428 : : #ifdef RTE_LIBRTE_IEEE1588
429 : : /* annotation area for timestamp in first buffer */
430 : : offset = 0x64;
431 : : #endif
432 [ # # ]: 0 : if (RTE_MBUF_DIRECT(mbuf) &&
433 [ # # ]: 0 : (mbuf->data_off > (mbuf->nb_segs * sizeof(struct qbman_sge)
434 : : + offset))) {
435 : : temp = mbuf;
436 [ # # ]: 0 : if (rte_mbuf_refcnt_read(temp) > 1) {
437 : : /* If refcnt > 1, invalid bpid is set to ensure
438 : : * buffer is not freed by HW
439 : : */
440 : : fd->simple.bpid_offset = 0;
441 : 0 : DPAA2_SET_FD_IVP(fd);
442 : 0 : rte_mbuf_refcnt_update(temp, -1);
443 : : } else {
444 : 0 : DPAA2_SET_ONLY_FD_BPID(fd, bpid);
445 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
446 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)temp),
447 : : (void **)&temp, 1, 0);
448 : : #endif
449 : : }
450 : 0 : DPAA2_SET_FD_OFFSET(fd, offset);
451 : : } else {
452 : 0 : temp = rte_pktmbuf_alloc(dpaa2_tx_sg_pool);
453 [ # # ]: 0 : if (temp == NULL) {
454 : : DPAA2_PMD_DP_DEBUG("No memory to allocate S/G table");
455 : : return -ENOMEM;
456 : : }
457 : 0 : DPAA2_SET_ONLY_FD_BPID(fd, mempool_to_bpid(dpaa2_tx_sg_pool));
458 : 0 : DPAA2_SET_FD_OFFSET(fd, temp->data_off);
459 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
460 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)temp),
461 : : (void **)&temp, 1, 0);
462 : : #endif
463 : : }
464 : 0 : DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(temp));
465 : 0 : DPAA2_SET_FD_LEN(fd, mbuf->pkt_len);
466 : 0 : DPAA2_FD_SET_FORMAT(fd, qbman_fd_sg);
467 : 0 : DPAA2_RESET_FD_FRC(fd);
468 : 0 : DPAA2_RESET_FD_CTRL(fd);
469 : 0 : DPAA2_RESET_FD_FLC(fd);
470 : : /*Set Scatter gather table and Scatter gather entries*/
471 : 0 : sgt = (struct qbman_sge *)(
472 : 0 : (size_t)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd))
473 : 0 : + DPAA2_GET_FD_OFFSET(fd));
474 : :
475 [ # # ]: 0 : for (i = 0; i < mbuf->nb_segs; i++) {
476 : 0 : sge = &sgt[i];
477 : : /*Resetting the buffer pool id and offset field*/
478 [ # # ]: 0 : sge->fin_bpid_offset = 0;
479 : 0 : DPAA2_SET_FLE_ADDR(sge, rte_pktmbuf_iova(cur_seg));
480 : 0 : sge->length = cur_seg->data_len;
481 [ # # ]: 0 : if (RTE_MBUF_DIRECT(cur_seg)) {
482 : : /* if we are using inline SGT in same buffers
483 : : * set the FLE FMT as Frame Data Section
484 : : */
485 [ # # ]: 0 : if (temp == cur_seg) {
486 : : DPAA2_SG_SET_FORMAT(sge, qbman_fd_list);
487 : 0 : DPAA2_SET_FLE_IVP(sge);
488 : : } else {
489 [ # # ]: 0 : if (rte_mbuf_refcnt_read(cur_seg) > 1) {
490 : : /* If refcnt > 1, invalid bpid is set to ensure
491 : : * buffer is not freed by HW
492 : : */
493 : 0 : DPAA2_SET_FLE_IVP(sge);
494 : 0 : rte_mbuf_refcnt_update(cur_seg, -1);
495 : : } else {
496 : 0 : DPAA2_SET_FLE_BPID(sge,
497 : : mempool_to_bpid(cur_seg->pool));
498 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
499 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)cur_seg),
500 : : (void **)&cur_seg, 1, 0);
501 : : #endif
502 : : }
503 : : }
504 [ # # ]: 0 : } else if (RTE_MBUF_HAS_EXTBUF(cur_seg)) {
505 : 0 : free_buf[*free_count].seg = cur_seg;
506 : 0 : free_buf[*free_count].pkt_id = pkt_id;
507 : 0 : ++*free_count;
508 : 0 : DPAA2_SET_FLE_IVP(sge);
509 : : } else {
510 : : /* Get owner MBUF from indirect buffer */
511 : : mi = rte_mbuf_from_indirect(cur_seg);
512 [ # # ]: 0 : if (rte_mbuf_refcnt_read(mi) > 1) {
513 : : /* If refcnt > 1, invalid bpid is set to ensure
514 : : * owner buffer is not freed by HW
515 : : */
516 : 0 : DPAA2_SET_FLE_IVP(sge);
517 : : } else {
518 : 0 : DPAA2_SET_FLE_BPID(sge,
519 : : mempool_to_bpid(mi->pool));
520 : 0 : rte_mbuf_refcnt_update(mi, 1);
521 : : }
522 : 0 : free_buf[*free_count].seg = cur_seg;
523 : 0 : free_buf[*free_count].pkt_id = pkt_id;
524 : 0 : ++*free_count;
525 : : }
526 : 0 : cur_seg = cur_seg->next;
527 : : }
528 : 0 : DPAA2_SG_SET_FINAL(sge, true);
529 : 0 : return 0;
530 : : }
531 : :
532 : : static inline void
533 : 0 : dpaa2_dev_prefetch_next_psr(const struct qbman_result *dq)
534 : : {
535 : : const struct qbman_fd *fd;
536 : : const struct dpaa2_annot_hdr *annotation;
537 : : uint64_t annot_iova;
538 : :
539 : 0 : dq++;
540 : :
541 : 0 : fd = qbman_result_DQ_fd(dq);
542 : 0 : annot_iova = DPAA2_GET_FD_ADDR(fd) + DPAA2_FD_PTA_SIZE;
543 : : annotation = DPAA2_IOVA_TO_VADDR(annot_iova);
544 : :
545 : : /** Prefetch from word3 to parse next header.*/
546 : 0 : rte_prefetch0(&annotation->word3);
547 : 0 : }
548 : :
549 : : static void
550 : : eth_mbuf_to_fd(struct rte_mbuf *mbuf,
551 : : struct qbman_fd *fd,
552 : : struct sw_buf_free *buf_to_free,
553 : : uint32_t *free_count,
554 : : uint32_t pkt_id,
555 : : uint16_t bpid) __rte_unused;
556 : :
557 : : static void __rte_noinline __rte_hot
558 : 0 : eth_mbuf_to_fd(struct rte_mbuf *mbuf,
559 : : struct qbman_fd *fd,
560 : : struct sw_buf_free *buf_to_free,
561 : : uint32_t *free_count,
562 : : uint32_t pkt_id,
563 : : uint16_t bpid)
564 : : {
565 : 0 : DPAA2_MBUF_TO_CONTIG_FD(mbuf, fd, bpid);
566 : :
567 : : DPAA2_PMD_DP_DEBUG("mbuf =%p, mbuf->buf_addr =%p, off = %d,"
568 : : "fd_off=%d fd =%" PRIx64 ", meta = %d bpid =%d, len=%d",
569 : : mbuf, mbuf->buf_addr, mbuf->data_off,
570 : : DPAA2_GET_FD_OFFSET(fd), DPAA2_GET_FD_ADDR(fd),
571 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
572 : : DPAA2_GET_FD_BPID(fd), DPAA2_GET_FD_LEN(fd));
573 [ # # ]: 0 : if (RTE_MBUF_DIRECT(mbuf)) {
574 [ # # ]: 0 : if (rte_mbuf_refcnt_read(mbuf) > 1) {
575 : 0 : DPAA2_SET_FD_IVP(fd);
576 : 0 : rte_mbuf_refcnt_update(mbuf, -1);
577 : : }
578 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
579 : : else
580 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)mbuf),
581 : : (void **)&mbuf, 1, 0);
582 : : #endif
583 [ # # ]: 0 : } else if (RTE_MBUF_HAS_EXTBUF(mbuf)) {
584 : 0 : buf_to_free[*free_count].seg = mbuf;
585 : 0 : buf_to_free[*free_count].pkt_id = pkt_id;
586 : 0 : ++*free_count;
587 : 0 : DPAA2_SET_FD_IVP(fd);
588 : : } else {
589 : : struct rte_mbuf *mi;
590 : :
591 : : mi = rte_mbuf_from_indirect(mbuf);
592 [ # # ]: 0 : if (rte_mbuf_refcnt_read(mi) > 1)
593 : 0 : DPAA2_SET_FD_IVP(fd);
594 : : else
595 : 0 : rte_mbuf_refcnt_update(mi, 1);
596 : :
597 : 0 : buf_to_free[*free_count].seg = mbuf;
598 : 0 : buf_to_free[*free_count].pkt_id = pkt_id;
599 : 0 : ++*free_count;
600 : : }
601 : 0 : }
602 : :
603 : : static inline int __rte_hot
604 : 0 : eth_copy_mbuf_to_fd(struct rte_mbuf *mbuf,
605 : : struct qbman_fd *fd, uint16_t bpid)
606 : : {
607 : : struct rte_mbuf *m;
608 : 0 : void *mb = NULL;
609 : :
610 [ # # ]: 0 : if (rte_dpaa2_mbuf_alloc_bulk(
611 : 0 : rte_dpaa2_bpid_info[bpid].bp_list->mp, &mb, 1)) {
612 : : DPAA2_PMD_DP_DEBUG("Unable to allocated DPAA2 buffer");
613 : : return -1;
614 : : }
615 : 0 : m = (struct rte_mbuf *)mb;
616 : 0 : memcpy((char *)m->buf_addr + mbuf->data_off,
617 : 0 : (void *)((char *)mbuf->buf_addr + mbuf->data_off),
618 : 0 : mbuf->pkt_len);
619 : :
620 : : /* Copy required fields */
621 : 0 : m->data_off = mbuf->data_off;
622 : 0 : m->ol_flags = mbuf->ol_flags;
623 : 0 : m->packet_type = mbuf->packet_type;
624 : 0 : m->tx_offload = mbuf->tx_offload;
625 : :
626 : 0 : DPAA2_MBUF_TO_CONTIG_FD(m, fd, bpid);
627 : :
628 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
629 : : rte_mempool_check_cookies(rte_mempool_from_obj((void *)m),
630 : : (void **)&m, 1, 0);
631 : : #endif
632 : : DPAA2_PMD_DP_DEBUG(
633 : : "mbuf: %p, BMAN buf addr: %p, fdaddr: %" PRIx64 ", bpid: %d,"
634 : : " meta: %d, off: %d, len: %d",
635 : : (void *)mbuf,
636 : : mbuf->buf_addr,
637 : : DPAA2_GET_FD_ADDR(fd),
638 : : DPAA2_GET_FD_BPID(fd),
639 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
640 : : DPAA2_GET_FD_OFFSET(fd),
641 : : DPAA2_GET_FD_LEN(fd));
642 : :
643 : 0 : return 0;
644 : : }
645 : :
646 : : static void
647 : 0 : dump_err_pkts(struct dpaa2_queue *dpaa2_q)
648 : : {
649 : : /* Function receive frames for a given device and VQ */
650 : : struct qbman_result *dq_storage;
651 : 0 : uint32_t fqid = dpaa2_q->fqid;
652 : : int ret, num_rx = 0;
653 : : uint8_t pending, status;
654 : : struct qbman_swp *swp;
655 : : const struct qbman_fd *fd;
656 : : struct qbman_pull_desc pulldesc;
657 [ # # ]: 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
658 : : uint32_t lcore_id = rte_lcore_id();
659 : : void *v_addr, *hw_annot_addr;
660 : : struct dpaa2_fas *fas;
661 : : struct rte_mbuf *mbuf;
662 : : char title[32];
663 : :
664 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
665 : 0 : ret = dpaa2_affine_qbman_swp();
666 [ # # ]: 0 : if (ret) {
667 : 0 : DPAA2_PMD_ERR("Failed to allocate IO portal, tid: %d",
668 : : rte_gettid());
669 : 0 : return;
670 : : }
671 : : }
672 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
673 : :
674 : 0 : dq_storage = dpaa2_q->q_storage[lcore_id]->dq_storage[0];
675 : 0 : qbman_pull_desc_clear(&pulldesc);
676 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
677 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
678 : : (size_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
679 : 0 : qbman_pull_desc_set_numframes(&pulldesc, dpaa2_dqrr_size);
680 : :
681 : : while (1) {
682 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
683 : : DPAA2_PMD_DP_DEBUG("VDQ command is not issued.QBMAN is busy");
684 : : /* Portal was busy, try again */
685 : : continue;
686 : : }
687 : : break;
688 : : }
689 : :
690 : : /* Check if the previous issued command is completed. */
691 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
692 : : ;
693 : :
694 : : pending = 1;
695 : : do {
696 : : /* Loop until the dq_storage is updated with
697 : : * new token by QBMAN
698 : : */
699 [ # # ]: 0 : while (!qbman_check_new_result(dq_storage))
700 : : ;
701 : :
702 : : /* Check whether Last Pull command is Expired and
703 : : * setting Condition for Loop termination
704 : : */
705 [ # # ]: 0 : if (qbman_result_DQ_is_pull_complete(dq_storage)) {
706 : : pending = 0;
707 : : /* Check for valid frame. */
708 : 0 : status = qbman_result_DQ_flags(dq_storage);
709 [ # # ]: 0 : if (unlikely((status &
710 : : QBMAN_DQ_STAT_VALIDFRAME) == 0))
711 : 0 : continue;
712 : : }
713 : 0 : fd = qbman_result_DQ_fd(dq_storage);
714 : 0 : v_addr = DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
715 : : hw_annot_addr = (void *)((size_t)v_addr + DPAA2_FD_PTA_SIZE);
716 : : fas = hw_annot_addr;
717 : :
718 [ # # ]: 0 : if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_sg)
719 : 0 : mbuf = eth_sg_fd_to_mbuf(fd, eth_data->port_id);
720 : : else
721 : 0 : mbuf = eth_fd_to_mbuf(fd, eth_data->port_id);
722 : :
723 [ # # ]: 0 : if (!dpaa2_print_parser_result) {
724 : : /** Don't print parse result twice.*/
725 : 0 : dpaa2_print_parse_result(hw_annot_addr);
726 : : }
727 : :
728 : 0 : DPAA2_PMD_ERR("Err pkt on port[%d]:", eth_data->port_id);
729 : 0 : DPAA2_PMD_ERR("FD offset: %d, FD err: %x, FAS status: %x",
730 : : DPAA2_GET_FD_OFFSET(fd), DPAA2_GET_FD_ERR(fd),
731 : : fas->status);
732 : :
733 [ # # ]: 0 : if (mbuf) {
734 : : __rte_mbuf_sanity_check(mbuf, 1);
735 [ # # ]: 0 : if (mbuf->nb_segs > 1) {
736 : : struct rte_mbuf *seg = mbuf;
737 : : int i = 0;
738 : :
739 [ # # ]: 0 : while (seg) {
740 : : sprintf(title, "Payload seg[%d]", i);
741 : 0 : rte_hexdump(stderr, title,
742 : 0 : (char *)seg->buf_addr + seg->data_off,
743 : 0 : seg->data_len);
744 : 0 : seg = seg->next;
745 : 0 : i++;
746 : : }
747 : : } else {
748 : 0 : rte_hexdump(stderr, "Payload",
749 : 0 : (char *)mbuf->buf_addr + mbuf->data_off,
750 : 0 : mbuf->data_len);
751 : : }
752 : 0 : rte_pktmbuf_free(mbuf);
753 : : }
754 : 0 : dq_storage++;
755 : 0 : num_rx++;
756 [ # # ]: 0 : } while (pending);
757 : :
758 : 0 : dpaa2_q->err_pkts += num_rx;
759 : : }
760 : :
761 : : /* This function assumes that caller will be keep the same value for nb_pkts
762 : : * across calls per queue, if that is not the case, better use non-prefetch
763 : : * version of rx call.
764 : : * It will return the packets as requested in previous call without honoring
765 : : * the current nb_pkts or bufs space.
766 : : */
767 : : uint16_t
768 : 0 : dpaa2_dev_prefetch_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
769 : : {
770 : : /* Function receive frames for a given device and VQ*/
771 : : struct dpaa2_queue *dpaa2_q = queue;
772 : : struct qbman_result *dq_storage, *dq_storage1 = NULL;
773 : 0 : uint32_t fqid = dpaa2_q->fqid;
774 : : int ret, num_rx = 0, pull_size;
775 : : uint8_t pending, status;
776 : : struct qbman_swp *swp;
777 : : const struct qbman_fd *fd;
778 : : struct qbman_pull_desc pulldesc;
779 : : struct queue_storage_info_t *q_storage;
780 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
781 [ # # ]: 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
782 : :
783 : 0 : q_storage = dpaa2_q->q_storage[rte_lcore_id()];
784 : :
785 [ # # ]: 0 : if (unlikely(priv->flags & DPAAX_RX_ERROR_QUEUE_FLAG))
786 : 0 : dump_err_pkts(priv->rx_err_vq);
787 : :
788 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_ETHRX_DPIO)) {
789 : 0 : ret = dpaa2_affine_qbman_ethrx_swp();
790 [ # # ]: 0 : if (ret) {
791 : 0 : DPAA2_PMD_ERR("Failure in affining portal");
792 : 0 : return 0;
793 : : }
794 : : }
795 : :
796 [ # # # # ]: 0 : if (unlikely(!rte_dpaa2_bpid_info &&
797 : : rte_eal_process_type() == RTE_PROC_SECONDARY))
798 : 0 : rte_dpaa2_bpid_info = dpaa2_q->bp_array;
799 : :
800 : 0 : swp = DPAA2_PER_LCORE_ETHRX_PORTAL;
801 [ # # ]: 0 : pull_size = (nb_pkts > dpaa2_dqrr_size) ? dpaa2_dqrr_size : nb_pkts;
802 [ # # ]: 0 : if (unlikely(!q_storage->active_dqs)) {
803 : 0 : q_storage->toggle = 0;
804 : 0 : dq_storage = q_storage->dq_storage[q_storage->toggle];
805 : 0 : q_storage->last_num_pkts = pull_size;
806 : 0 : qbman_pull_desc_clear(&pulldesc);
807 : 0 : qbman_pull_desc_set_numframes(&pulldesc,
808 : 0 : q_storage->last_num_pkts);
809 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
810 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
811 : : (uint64_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
812 [ # # ]: 0 : if (check_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)) {
813 [ # # ]: 0 : while (!qbman_check_command_complete(
814 : : get_swp_active_dqs(
815 : 0 : DPAA2_PER_LCORE_ETHRX_DPIO->index)))
816 : : ;
817 : 0 : clear_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index);
818 : : }
819 : : while (1) {
820 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
821 : : DPAA2_PMD_DP_DEBUG("VDQ command is not issued."
822 : : " QBMAN is busy (1)");
823 : : /* Portal was busy, try again */
824 : : continue;
825 : : }
826 : : break;
827 : : }
828 : 0 : q_storage->active_dqs = dq_storage;
829 : 0 : q_storage->active_dpio_id = DPAA2_PER_LCORE_ETHRX_DPIO->index;
830 : 0 : set_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index,
831 : : dq_storage);
832 : : }
833 : :
834 : 0 : dq_storage = q_storage->active_dqs;
835 : : rte_prefetch0((void *)(size_t)(dq_storage));
836 : 0 : rte_prefetch0((void *)(size_t)(dq_storage + 1));
837 : :
838 : : /* Prepare next pull descriptor. This will give space for the
839 : : * prefetching done on DQRR entries
840 : : */
841 : 0 : q_storage->toggle ^= 1;
842 : 0 : dq_storage1 = q_storage->dq_storage[q_storage->toggle];
843 : 0 : qbman_pull_desc_clear(&pulldesc);
844 : 0 : qbman_pull_desc_set_numframes(&pulldesc, pull_size);
845 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
846 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage1,
847 : : (uint64_t)(DPAA2_VADDR_TO_IOVA(dq_storage1)), 1);
848 : :
849 : : /* Check if the previous issued command is completed.
850 : : * Also seems like the SWP is shared between the Ethernet Driver
851 : : * and the SEC driver.
852 : : */
853 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
854 : : ;
855 [ # # ]: 0 : if (dq_storage == get_swp_active_dqs(q_storage->active_dpio_id))
856 : : clear_swp_active_dqs(q_storage->active_dpio_id);
857 : :
858 : : pending = 1;
859 : :
860 : : do {
861 : : /* Loop until the dq_storage is updated with
862 : : * new token by QBMAN
863 : : */
864 [ # # ]: 0 : while (!qbman_check_new_result(dq_storage))
865 : : ;
866 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 2)));
867 : : /* Check whether Last Pull command is Expired and
868 : : * setting Condition for Loop termination
869 : : */
870 [ # # ]: 0 : if (qbman_result_DQ_is_pull_complete(dq_storage)) {
871 : : pending = 0;
872 : : /* Check for valid frame. */
873 : 0 : status = qbman_result_DQ_flags(dq_storage);
874 [ # # ]: 0 : if (unlikely((status & QBMAN_DQ_STAT_VALIDFRAME) == 0))
875 : 0 : continue;
876 : : }
877 [ # # ]: 0 : if (dpaa2_svr_family != SVR_LX2160A)
878 : : /** Packet type is parsed from FRC for LX2160A.*/
879 : 0 : dpaa2_dev_prefetch_next_psr(dq_storage);
880 : :
881 : 0 : fd = qbman_result_DQ_fd(dq_storage);
882 [ # # ]: 0 : if (unlikely(DPAA2_FD_GET_FORMAT(fd) == qbman_fd_sg))
883 : 0 : bufs[num_rx] = eth_sg_fd_to_mbuf(fd, eth_data->port_id);
884 : : else
885 : 0 : bufs[num_rx] = eth_fd_to_mbuf(fd, eth_data->port_id);
886 : : #if defined(RTE_LIBRTE_IEEE1588)
887 : : if (bufs[num_rx]->ol_flags & RTE_MBUF_F_RX_IEEE1588_TMST) {
888 : : priv->rx_timestamp =
889 : : *dpaa2_timestamp_dynfield(bufs[num_rx]);
890 : : }
891 : : #endif
892 : :
893 [ # # ]: 0 : if (eth_data->dev_conf.rxmode.offloads &
894 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
895 : 0 : rte_vlan_strip(bufs[num_rx]);
896 : :
897 : 0 : dq_storage++;
898 : 0 : num_rx++;
899 [ # # ]: 0 : } while (pending);
900 : :
901 [ # # ]: 0 : if (check_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)) {
902 [ # # ]: 0 : while (!qbman_check_command_complete(
903 : 0 : get_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)))
904 : : ;
905 : 0 : clear_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index);
906 : : }
907 : : /* issue a volatile dequeue command for next pull */
908 : : while (1) {
909 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
910 : : DPAA2_PMD_DP_DEBUG("VDQ command is not issued."
911 : : "QBMAN is busy (2)");
912 : : continue;
913 : : }
914 : : break;
915 : : }
916 : 0 : q_storage->active_dqs = dq_storage1;
917 : 0 : q_storage->active_dpio_id = DPAA2_PER_LCORE_ETHRX_DPIO->index;
918 : 0 : set_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index, dq_storage1);
919 : :
920 : 0 : dpaa2_q->rx_pkts += num_rx;
921 : :
922 : 0 : return num_rx;
923 : : }
924 : :
925 : : void __rte_hot
926 : 0 : dpaa2_dev_process_parallel_event(struct qbman_swp *swp,
927 : : const struct qbman_fd *fd,
928 : : const struct qbman_result *dq,
929 : : struct dpaa2_queue *rxq,
930 : : struct rte_event *ev)
931 : : {
932 : 0 : rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd) +
933 : : DPAA2_FD_PTA_SIZE + 16));
934 : :
935 : 0 : ev->flow_id = rxq->ev.flow_id;
936 : 0 : ev->sub_event_type = rxq->ev.sub_event_type;
937 : 0 : ev->event_type = RTE_EVENT_TYPE_ETHDEV;
938 : 0 : ev->op = RTE_EVENT_OP_NEW;
939 : 0 : ev->sched_type = rxq->ev.sched_type;
940 : 0 : ev->queue_id = rxq->ev.queue_id;
941 : 0 : ev->priority = rxq->ev.priority;
942 : :
943 : 0 : ev->mbuf = eth_fd_to_mbuf(fd, rxq->eth_data->port_id);
944 : :
945 : 0 : qbman_swp_dqrr_consume(swp, dq);
946 : 0 : }
947 : :
948 : : void __rte_hot
949 : 0 : dpaa2_dev_process_atomic_event(struct qbman_swp *swp __rte_unused,
950 : : const struct qbman_fd *fd,
951 : : const struct qbman_result *dq,
952 : : struct dpaa2_queue *rxq,
953 : : struct rte_event *ev)
954 : : {
955 : : uint8_t dqrr_index;
956 : :
957 : 0 : rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd) +
958 : : DPAA2_FD_PTA_SIZE + 16));
959 : :
960 : 0 : ev->flow_id = rxq->ev.flow_id;
961 : 0 : ev->sub_event_type = rxq->ev.sub_event_type;
962 : 0 : ev->event_type = RTE_EVENT_TYPE_ETHDEV;
963 : 0 : ev->op = RTE_EVENT_OP_NEW;
964 : 0 : ev->sched_type = rxq->ev.sched_type;
965 : 0 : ev->queue_id = rxq->ev.queue_id;
966 : 0 : ev->priority = rxq->ev.priority;
967 : :
968 : 0 : ev->mbuf = eth_fd_to_mbuf(fd, rxq->eth_data->port_id);
969 : :
970 : 0 : dqrr_index = qbman_get_dqrr_idx(dq);
971 : 0 : *dpaa2_seqn(ev->mbuf) = dqrr_index + 1;
972 : 0 : DPAA2_PER_LCORE_DQRR_SIZE++;
973 : 0 : DPAA2_PER_LCORE_DQRR_HELD |= UINT64_C(1) << dqrr_index;
974 : 0 : DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = ev->mbuf;
975 : 0 : }
976 : :
977 : : void __rte_hot
978 : 0 : dpaa2_dev_process_ordered_event(struct qbman_swp *swp,
979 : : const struct qbman_fd *fd,
980 : : const struct qbman_result *dq,
981 : : struct dpaa2_queue *rxq,
982 : : struct rte_event *ev)
983 : : {
984 : 0 : rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd) +
985 : : DPAA2_FD_PTA_SIZE + 16));
986 : :
987 : 0 : ev->flow_id = rxq->ev.flow_id;
988 : 0 : ev->sub_event_type = rxq->ev.sub_event_type;
989 : 0 : ev->event_type = RTE_EVENT_TYPE_ETHDEV;
990 : 0 : ev->op = RTE_EVENT_OP_NEW;
991 : 0 : ev->sched_type = rxq->ev.sched_type;
992 : 0 : ev->queue_id = rxq->ev.queue_id;
993 : 0 : ev->priority = rxq->ev.priority;
994 : :
995 : 0 : ev->mbuf = eth_fd_to_mbuf(fd, rxq->eth_data->port_id);
996 : :
997 : 0 : *dpaa2_seqn(ev->mbuf) = DPAA2_ENQUEUE_FLAG_ORP;
998 : 0 : *dpaa2_seqn(ev->mbuf) |= qbman_result_DQ_odpid(dq) << DPAA2_EQCR_OPRID_SHIFT;
999 : 0 : *dpaa2_seqn(ev->mbuf) |= qbman_result_DQ_seqnum(dq) << DPAA2_EQCR_SEQNUM_SHIFT;
1000 : :
1001 : 0 : qbman_swp_dqrr_consume(swp, dq);
1002 : 0 : }
1003 : :
1004 : : uint16_t
1005 : 0 : dpaa2_dev_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
1006 : : {
1007 : : /* Function receive frames for a given device and VQ */
1008 : : struct dpaa2_queue *dpaa2_q = queue;
1009 : : struct qbman_result *dq_storage;
1010 : 0 : uint32_t fqid = dpaa2_q->fqid;
1011 : 0 : int ret, num_rx = 0, next_pull = nb_pkts, num_pulled;
1012 : : uint8_t pending, status;
1013 : : struct qbman_swp *swp;
1014 : : const struct qbman_fd *fd;
1015 : : struct qbman_pull_desc pulldesc;
1016 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
1017 : 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
1018 : :
1019 [ # # ]: 0 : if (unlikely(priv->flags & DPAAX_RX_ERROR_QUEUE_FLAG))
1020 : 0 : dump_err_pkts(priv->rx_err_vq);
1021 : :
1022 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1023 : 0 : ret = dpaa2_affine_qbman_swp();
1024 [ # # ]: 0 : if (ret) {
1025 : 0 : DPAA2_PMD_ERR(
1026 : : "Failed to allocate IO portal, tid: %d",
1027 : : rte_gettid());
1028 : 0 : return 0;
1029 : : }
1030 : : }
1031 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1032 : :
1033 : : do {
1034 : 0 : dq_storage = dpaa2_q->q_storage[0]->dq_storage[0];
1035 : 0 : qbman_pull_desc_clear(&pulldesc);
1036 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
1037 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1038 : : (size_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
1039 : :
1040 [ # # ]: 0 : if (next_pull > dpaa2_dqrr_size) {
1041 : 0 : qbman_pull_desc_set_numframes(&pulldesc,
1042 : : dpaa2_dqrr_size);
1043 : 0 : next_pull -= dpaa2_dqrr_size;
1044 : : } else {
1045 : 0 : qbman_pull_desc_set_numframes(&pulldesc, next_pull);
1046 : : next_pull = 0;
1047 : : }
1048 : :
1049 : : while (1) {
1050 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
1051 : : DPAA2_PMD_DP_DEBUG(
1052 : : "VDQ command is not issued.QBMAN is busy");
1053 : : /* Portal was busy, try again */
1054 : : continue;
1055 : : }
1056 : : break;
1057 : : }
1058 : :
1059 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 1)));
1060 : : /* Check if the previous issued command is completed. */
1061 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
1062 : : ;
1063 : :
1064 : : num_pulled = 0;
1065 : : pending = 1;
1066 : : do {
1067 : : /* Loop until the dq_storage is updated with
1068 : : * new token by QBMAN
1069 : : */
1070 [ # # ]: 0 : while (!qbman_check_new_result(dq_storage))
1071 : : ;
1072 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 2)));
1073 : : /* Check whether Last Pull command is Expired and
1074 : : * setting Condition for Loop termination
1075 : : */
1076 [ # # ]: 0 : if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1077 : : pending = 0;
1078 : : /* Check for valid frame. */
1079 : 0 : status = qbman_result_DQ_flags(dq_storage);
1080 [ # # ]: 0 : if (unlikely((status &
1081 : : QBMAN_DQ_STAT_VALIDFRAME) == 0))
1082 : 0 : continue;
1083 : : }
1084 [ # # ]: 0 : if (dpaa2_svr_family != SVR_LX2160A)
1085 : : /** Packet type is parsed from FRC for LX2160A.*/
1086 : 0 : dpaa2_dev_prefetch_next_psr(dq_storage);
1087 : :
1088 : 0 : fd = qbman_result_DQ_fd(dq_storage);
1089 [ # # ]: 0 : if (unlikely(DPAA2_FD_GET_FORMAT(fd) == qbman_fd_sg))
1090 : 0 : bufs[num_rx] = eth_sg_fd_to_mbuf(fd,
1091 : 0 : eth_data->port_id);
1092 : : else
1093 : 0 : bufs[num_rx] = eth_fd_to_mbuf(fd,
1094 : 0 : eth_data->port_id);
1095 : :
1096 : : #if defined(RTE_LIBRTE_IEEE1588)
1097 : : if (bufs[num_rx]->ol_flags & RTE_MBUF_F_RX_IEEE1588_TMST) {
1098 : : priv->rx_timestamp =
1099 : : *dpaa2_timestamp_dynfield(bufs[num_rx]);
1100 : : }
1101 : : #endif
1102 : :
1103 [ # # ]: 0 : if (eth_data->dev_conf.rxmode.offloads &
1104 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
1105 : 0 : rte_vlan_strip(bufs[num_rx]);
1106 : : }
1107 : :
1108 : 0 : dq_storage++;
1109 : 0 : num_rx++;
1110 : 0 : num_pulled++;
1111 [ # # ]: 0 : } while (pending);
1112 : : /* Last VDQ provided all packets and more packets are requested */
1113 [ # # # # ]: 0 : } while (next_pull && num_pulled == dpaa2_dqrr_size);
1114 : :
1115 : 0 : dpaa2_q->rx_pkts += num_rx;
1116 : :
1117 : 0 : return num_rx;
1118 : : }
1119 : :
1120 : 0 : uint16_t dpaa2_dev_tx_conf(void *queue)
1121 : : {
1122 : : /* Function receive frames for a given device and VQ */
1123 : : struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
1124 : : struct qbman_result *dq_storage;
1125 : 0 : uint32_t fqid = dpaa2_q->fqid;
1126 : : int ret, num_tx_conf = 0, num_pulled;
1127 : : uint8_t pending, status;
1128 : : struct qbman_swp *swp;
1129 : : const struct qbman_fd *fd;
1130 : : struct qbman_pull_desc pulldesc;
1131 : : struct qbman_release_desc releasedesc;
1132 : : uint32_t bpid;
1133 : : uint64_t buf;
1134 : : #if defined(RTE_LIBRTE_IEEE1588)
1135 : : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
1136 : : struct dpaa2_dev_priv *priv = eth_data->dev_private;
1137 : : struct dpaa2_annot_hdr *annotation;
1138 : : void *v_addr;
1139 : : struct rte_mbuf *mbuf;
1140 : : #endif
1141 : :
1142 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1143 : 0 : ret = dpaa2_affine_qbman_swp();
1144 [ # # ]: 0 : if (ret) {
1145 : 0 : DPAA2_PMD_ERR(
1146 : : "Failed to allocate IO portal, tid: %d",
1147 : : rte_gettid());
1148 : 0 : return 0;
1149 : : }
1150 : : }
1151 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1152 : :
1153 : : do {
1154 : 0 : dq_storage = dpaa2_q->q_storage[0]->dq_storage[0];
1155 : 0 : qbman_pull_desc_clear(&pulldesc);
1156 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
1157 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1158 : : (size_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
1159 : :
1160 : 0 : qbman_pull_desc_set_numframes(&pulldesc, dpaa2_dqrr_size);
1161 : :
1162 : : while (1) {
1163 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
1164 : : DPAA2_PMD_DP_DEBUG("VDQ command is not issued."
1165 : : "QBMAN is busy");
1166 : : /* Portal was busy, try again */
1167 : : continue;
1168 : : }
1169 : : break;
1170 : : }
1171 : :
1172 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 1)));
1173 : : /* Check if the previous issued command is completed. */
1174 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
1175 : : ;
1176 : :
1177 : : num_pulled = 0;
1178 : : pending = 1;
1179 : : do {
1180 : : /* Loop until the dq_storage is updated with
1181 : : * new token by QBMAN
1182 : : */
1183 [ # # ]: 0 : while (!qbman_check_new_result(dq_storage))
1184 : : ;
1185 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 2)));
1186 : : /* Check whether Last Pull command is Expired and
1187 : : * setting Condition for Loop termination
1188 : : */
1189 [ # # ]: 0 : if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1190 : : pending = 0;
1191 : : /* Check for valid frame. */
1192 : 0 : status = qbman_result_DQ_flags(dq_storage);
1193 [ # # ]: 0 : if (unlikely((status &
1194 : : QBMAN_DQ_STAT_VALIDFRAME) == 0))
1195 : 0 : continue;
1196 : : }
1197 [ # # ]: 0 : if (dpaa2_svr_family != SVR_LX2160A)
1198 : : /** Packet type is parsed from FRC for LX2160A.*/
1199 : 0 : dpaa2_dev_prefetch_next_psr(dq_storage);
1200 : :
1201 : 0 : fd = qbman_result_DQ_fd(dq_storage);
1202 : 0 : bpid = DPAA2_GET_FD_BPID(fd);
1203 : :
1204 : : /* Create a release descriptor required for releasing
1205 : : * buffers into QBMAN
1206 : : */
1207 : 0 : qbman_release_desc_clear(&releasedesc);
1208 : 0 : qbman_release_desc_set_bpid(&releasedesc, bpid);
1209 : :
1210 : 0 : buf = DPAA2_GET_FD_ADDR(fd);
1211 : : /* feed them to bman */
1212 : : do {
1213 : 0 : ret = qbman_swp_release(swp, &releasedesc,
1214 : : &buf, 1);
1215 [ # # ]: 0 : } while (ret == -EBUSY);
1216 : :
1217 : 0 : dq_storage++;
1218 : 0 : num_tx_conf++;
1219 : 0 : num_pulled++;
1220 : : #if defined(RTE_LIBRTE_IEEE1588)
1221 : : v_addr = DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1222 : : mbuf = DPAA2_INLINE_MBUF_FROM_BUF(v_addr,
1223 : : rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1224 : :
1225 : : if (mbuf->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) {
1226 : : annotation = (struct dpaa2_annot_hdr *)((size_t)
1227 : : DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)) +
1228 : : DPAA2_FD_PTA_SIZE);
1229 : : priv->tx_timestamp = annotation->word2;
1230 : : }
1231 : : #endif
1232 [ # # ]: 0 : } while (pending);
1233 : :
1234 : : /* Last VDQ provided all packets and more packets are requested */
1235 [ # # ]: 0 : } while (num_pulled == dpaa2_dqrr_size);
1236 : :
1237 : 0 : dpaa2_q->rx_pkts += num_tx_conf;
1238 : :
1239 : 0 : return num_tx_conf;
1240 : : }
1241 : :
1242 : : /* Configure the egress frame annotation for timestamp update */
1243 : : static void enable_tx_tstamp(struct qbman_fd *fd)
1244 : : {
1245 : : struct dpaa2_faead *fd_faead;
1246 : :
1247 : : /* Set frame annotation status field as valid */
1248 : : (fd)->simple.frc |= DPAA2_FD_FRC_FASV;
1249 : :
1250 : : /* Set frame annotation egress action descriptor as valid */
1251 : : (fd)->simple.frc |= DPAA2_FD_FRC_FAEADV;
1252 : :
1253 : : /* Set Annotation Length as 128B */
1254 : : (fd)->simple.ctrl |= DPAA2_FD_CTRL_ASAL;
1255 : :
1256 : : /* enable update of confirmation frame annotation */
1257 : : fd_faead = (struct dpaa2_faead *)((size_t)
1258 : : DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)) +
1259 : : DPAA2_FD_PTA_SIZE + DPAA2_FD_HW_ANNOT_FAEAD_OFFSET);
1260 : : fd_faead->ctrl = DPAA2_ANNOT_FAEAD_A2V | DPAA2_ANNOT_FAEAD_UPDV |
1261 : : DPAA2_ANNOT_FAEAD_UPD;
1262 : : }
1263 : :
1264 : : /*
1265 : : * Callback to handle sending packets through WRIOP based interface
1266 : : */
1267 : : uint16_t
1268 : 0 : dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
1269 : 0 : {
1270 : : /* Function to transmit the frames to given device and VQ*/
1271 : : uint32_t loop, retry_count;
1272 : : int32_t ret;
1273 : : struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1274 : : struct rte_mbuf *mi;
1275 : : uint32_t frames_to_send;
1276 : : struct rte_mempool *mp;
1277 : : struct qbman_eq_desc eqdesc;
1278 : : struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
1279 : : struct qbman_swp *swp;
1280 : : uint16_t num_tx = 0;
1281 : : uint16_t bpid;
1282 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
1283 : 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
1284 : 0 : uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1285 : 0 : struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size];
1286 : 0 : uint32_t free_count = 0;
1287 : :
1288 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1289 : 0 : ret = dpaa2_affine_qbman_swp();
1290 [ # # ]: 0 : if (ret) {
1291 : 0 : DPAA2_PMD_ERR(
1292 : : "Failed to allocate IO portal, tid: %d",
1293 : : rte_gettid());
1294 : 0 : return 0;
1295 : : }
1296 : : }
1297 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1298 : :
1299 : : DPAA2_PMD_DP_DEBUG("===> eth_data =%p, fqid =%d",
1300 : : eth_data, dpaa2_q->fqid);
1301 : :
1302 : : #ifdef RTE_LIBRTE_IEEE1588
1303 : : /* IEEE1588 driver need pointer to tx confirmation queue
1304 : : * corresponding to last packet transmitted for reading
1305 : : * the timestamp
1306 : : */
1307 : : if ((*bufs)->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) {
1308 : : priv->next_tx_conf_queue = dpaa2_q->tx_conf_queue;
1309 : : dpaa2_dev_tx_conf(dpaa2_q->tx_conf_queue);
1310 : : priv->tx_timestamp = 0;
1311 : : }
1312 : : #endif
1313 : :
1314 : : /*Prepare enqueue descriptor*/
1315 : 0 : qbman_eq_desc_clear(&eqdesc);
1316 : 0 : qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1317 : 0 : qbman_eq_desc_set_fq(&eqdesc, dpaa2_q->fqid);
1318 : :
1319 : : /*Clear the unused FD fields before sending*/
1320 [ # # ]: 0 : while (nb_pkts) {
1321 : : /*Check if the queue is congested*/
1322 : : retry_count = 0;
1323 [ # # ]: 0 : while (qbman_result_SCN_state(dpaa2_q->cscn)) {
1324 : 0 : retry_count++;
1325 : : /* Retry for some time before giving up */
1326 [ # # ]: 0 : if (retry_count > CONG_RETRY_COUNT) {
1327 [ # # ]: 0 : if (dpaa2_q->tm_sw_td)
1328 : 0 : goto sw_td;
1329 : 0 : goto skip_tx;
1330 : : }
1331 : : }
1332 : :
1333 : 0 : frames_to_send = (nb_pkts > dpaa2_eqcr_size) ?
1334 [ # # ]: 0 : dpaa2_eqcr_size : nb_pkts;
1335 : :
1336 [ # # ]: 0 : for (loop = 0; loop < frames_to_send; loop++) {
1337 [ # # ]: 0 : if (*dpaa2_seqn(*bufs)) {
1338 : 0 : uint8_t dqrr_index = *dpaa2_seqn(*bufs) - 1;
1339 : :
1340 : 0 : flags[loop] = QBMAN_ENQUEUE_FLAG_DCA |
1341 : : dqrr_index;
1342 : 0 : DPAA2_PER_LCORE_DQRR_SIZE--;
1343 : 0 : DPAA2_PER_LCORE_DQRR_HELD &= ~(UINT64_C(1) << dqrr_index);
1344 : 0 : *dpaa2_seqn(*bufs) = DPAA2_INVALID_MBUF_SEQN;
1345 : : }
1346 : :
1347 [ # # ]: 0 : if (likely(RTE_MBUF_DIRECT(*bufs))) {
1348 : 0 : mp = (*bufs)->pool;
1349 : : /* Check the basic scenario and set
1350 : : * the FD appropriately here itself.
1351 : : */
1352 [ # # # # : 0 : if (likely(mp && mp->ops_index ==
# # # # ]
1353 : : priv->bp_list->dpaa2_ops_index &&
1354 : : (*bufs)->nb_segs == 1 &&
1355 : : rte_mbuf_refcnt_read((*bufs)) == 1)) {
1356 [ # # ]: 0 : if (unlikely((*bufs)->ol_flags
1357 : : & RTE_MBUF_F_TX_VLAN)) {
1358 : 0 : ret = rte_vlan_insert(bufs);
1359 [ # # ]: 0 : if (ret)
1360 : 0 : goto send_n_return;
1361 : : }
1362 : 0 : DPAA2_MBUF_TO_CONTIG_FD((*bufs),
1363 : : &fd_arr[loop], mempool_to_bpid(mp));
1364 : : #ifdef RTE_LIBRTE_MEMPOOL_DEBUG
1365 : : rte_mempool_check_cookies
1366 : : (rte_mempool_from_obj((void *)*bufs),
1367 : : (void **)bufs, 1, 0);
1368 : : #endif
1369 : 0 : bufs++;
1370 : : #ifdef RTE_LIBRTE_IEEE1588
1371 : : enable_tx_tstamp(&fd_arr[loop]);
1372 : : #endif
1373 : 0 : continue;
1374 : : }
1375 : : } else {
1376 : : mi = rte_mbuf_from_indirect(*bufs);
1377 : 0 : mp = mi->pool;
1378 : : }
1379 : :
1380 [ # # ]: 0 : if (unlikely(RTE_MBUF_HAS_EXTBUF(*bufs))) {
1381 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1382 : 0 : mp = (*bufs)->pool;
1383 [ # # ]: 0 : if (eth_mbuf_to_sg_fd(*bufs,
1384 : : &fd_arr[loop],
1385 : : buf_to_free,
1386 : : &free_count,
1387 : : loop,
1388 : 0 : mempool_to_bpid(mp)))
1389 : 0 : goto send_n_return;
1390 : : } else {
1391 : 0 : eth_mbuf_to_fd(*bufs,
1392 : : &fd_arr[loop],
1393 : : buf_to_free,
1394 : : &free_count,
1395 : : loop, 0);
1396 : : }
1397 : 0 : bufs++;
1398 : : #ifdef RTE_LIBRTE_IEEE1588
1399 : : enable_tx_tstamp(&fd_arr[loop]);
1400 : : #endif
1401 : 0 : continue;
1402 : : }
1403 : :
1404 : : /* Not a hw_pkt pool allocated frame */
1405 [ # # # # ]: 0 : if (unlikely(!mp || !priv->bp_list)) {
1406 : 0 : DPAA2_PMD_ERR("Err: No buffer pool attached");
1407 : 0 : goto send_n_return;
1408 : : }
1409 : :
1410 [ # # ]: 0 : if (unlikely((*bufs)->ol_flags & RTE_MBUF_F_TX_VLAN)) {
1411 : 0 : int ret = rte_vlan_insert(bufs);
1412 [ # # ]: 0 : if (ret)
1413 : 0 : goto send_n_return;
1414 : : }
1415 [ # # ]: 0 : if (mp->ops_index != priv->bp_list->dpaa2_ops_index) {
1416 : 0 : DPAA2_PMD_WARN("Non DPAA2 buffer pool");
1417 : : /* alloc should be from the default buffer pool
1418 : : * attached to this interface
1419 : : */
1420 : 0 : bpid = priv->bp_list->buf_pool.bpid;
1421 : :
1422 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1423 : 0 : DPAA2_PMD_ERR("S/G support not added"
1424 : : " for non hw offload buffer");
1425 : 0 : goto send_n_return;
1426 : : }
1427 [ # # ]: 0 : if (eth_copy_mbuf_to_fd(*bufs,
1428 : : &fd_arr[loop], bpid)) {
1429 : 0 : goto send_n_return;
1430 : : }
1431 : : /* free the original packet */
1432 : 0 : rte_pktmbuf_free(*bufs);
1433 : : } else {
1434 : 0 : bpid = mempool_to_bpid(mp);
1435 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1436 [ # # ]: 0 : if (eth_mbuf_to_sg_fd(*bufs,
1437 : : &fd_arr[loop],
1438 : : buf_to_free,
1439 : : &free_count,
1440 : : loop,
1441 : : bpid))
1442 : 0 : goto send_n_return;
1443 : : } else {
1444 : 0 : eth_mbuf_to_fd(*bufs,
1445 : : &fd_arr[loop],
1446 : : buf_to_free,
1447 : : &free_count,
1448 : : loop, bpid);
1449 : : }
1450 : : }
1451 : : #ifdef RTE_LIBRTE_IEEE1588
1452 : : enable_tx_tstamp(&fd_arr[loop]);
1453 : : #endif
1454 : 0 : bufs++;
1455 : : }
1456 : :
1457 : : loop = 0;
1458 : : retry_count = 0;
1459 [ # # ]: 0 : while (loop < frames_to_send) {
1460 : 0 : ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1461 : 0 : &fd_arr[loop], &flags[loop],
1462 : 0 : frames_to_send - loop);
1463 [ # # ]: 0 : if (unlikely(ret < 0)) {
1464 : 0 : retry_count++;
1465 [ # # ]: 0 : if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1466 : 0 : num_tx += loop;
1467 : : nb_pkts -= loop;
1468 : 0 : goto send_n_return;
1469 : : }
1470 : : } else {
1471 : 0 : loop += ret;
1472 : : retry_count = 0;
1473 : : }
1474 : : }
1475 : :
1476 : 0 : num_tx += loop;
1477 : 0 : nb_pkts -= loop;
1478 : : }
1479 : 0 : dpaa2_q->tx_pkts += num_tx;
1480 : :
1481 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1482 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1483 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1484 : : }
1485 : :
1486 : : return num_tx;
1487 : :
1488 : 0 : send_n_return:
1489 : : /* send any already prepared fd */
1490 [ # # ]: 0 : if (loop) {
1491 : : unsigned int i = 0;
1492 : :
1493 : : retry_count = 0;
1494 [ # # ]: 0 : while (i < loop) {
1495 : 0 : ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1496 : 0 : &fd_arr[i],
1497 : : &flags[i],
1498 : 0 : loop - i);
1499 [ # # ]: 0 : if (unlikely(ret < 0)) {
1500 : 0 : retry_count++;
1501 [ # # ]: 0 : if (retry_count > DPAA2_MAX_TX_RETRY_COUNT)
1502 : : break;
1503 : : } else {
1504 : 0 : i += ret;
1505 : : retry_count = 0;
1506 : : }
1507 : : }
1508 : 0 : num_tx += i;
1509 : : }
1510 : 0 : skip_tx:
1511 : 0 : dpaa2_q->tx_pkts += num_tx;
1512 : :
1513 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1514 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1515 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1516 : : }
1517 : :
1518 : : return num_tx;
1519 : : sw_td:
1520 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1521 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1522 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1523 : : }
1524 : :
1525 : : /* free the pending buffers */
1526 : 0 : rte_pktmbuf_free_bulk(bufs, nb_pkts);
1527 : :
1528 : 0 : num_tx += nb_pkts;
1529 : 0 : dpaa2_q->tx_pkts += num_tx;
1530 : :
1531 : 0 : return num_tx;
1532 : : }
1533 : :
1534 : : void
1535 : 0 : dpaa2_dev_free_eqresp_buf(uint16_t eqresp_ci,
1536 : : __rte_unused struct dpaa2_queue *dpaa2_q)
1537 : : {
1538 : 0 : struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1539 : : struct qbman_fd *fd;
1540 : : struct rte_mbuf *m;
1541 : :
1542 : 0 : fd = qbman_result_eqresp_fd(&dpio_dev->eqresp[eqresp_ci]);
1543 : :
1544 : : /* Setting port id does not matter as we are to free the mbuf */
1545 : 0 : m = eth_fd_to_mbuf(fd, 0);
1546 : 0 : rte_pktmbuf_free(m);
1547 : 0 : }
1548 : :
1549 : : static void
1550 : 0 : dpaa2_set_enqueue_descriptor(struct dpaa2_queue *dpaa2_q,
1551 : : struct rte_mbuf *m,
1552 : : struct qbman_eq_desc *eqdesc)
1553 : : {
1554 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
1555 : 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
1556 : 0 : struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1557 : : struct eqresp_metadata *eqresp_meta;
1558 : : uint16_t orpid, seqnum;
1559 : : uint8_t dq_idx;
1560 : :
1561 : 0 : qbman_eq_desc_set_fq(eqdesc, dpaa2_q->fqid);
1562 : :
1563 [ # # ]: 0 : if (*dpaa2_seqn(m) & DPAA2_ENQUEUE_FLAG_ORP) {
1564 : 0 : orpid = (*dpaa2_seqn(m) & DPAA2_EQCR_OPRID_MASK) >>
1565 : : DPAA2_EQCR_OPRID_SHIFT;
1566 : : seqnum = (*dpaa2_seqn(m) & DPAA2_EQCR_SEQNUM_MASK) >>
1567 : : DPAA2_EQCR_SEQNUM_SHIFT;
1568 : :
1569 [ # # ]: 0 : if (!priv->en_loose_ordered) {
1570 : 0 : qbman_eq_desc_set_orp(eqdesc, 1, orpid, seqnum, 0);
1571 : 0 : qbman_eq_desc_set_response(eqdesc, (uint64_t)
1572 : 0 : DPAA2_VADDR_TO_IOVA(&dpio_dev->eqresp[
1573 : : dpio_dev->eqresp_pi]), 1);
1574 : 0 : qbman_eq_desc_set_token(eqdesc, 1);
1575 : :
1576 : 0 : eqresp_meta = &dpio_dev->eqresp_meta[
1577 : 0 : dpio_dev->eqresp_pi];
1578 : 0 : eqresp_meta->dpaa2_q = dpaa2_q;
1579 : 0 : eqresp_meta->mp = m->pool;
1580 : :
1581 : : dpio_dev->eqresp_pi + 1 < MAX_EQ_RESP_ENTRIES ?
1582 [ # # ]: 0 : dpio_dev->eqresp_pi++ :
1583 : 0 : (dpio_dev->eqresp_pi = 0);
1584 : : } else {
1585 : 0 : qbman_eq_desc_set_orp(eqdesc, 0, orpid, seqnum, 0);
1586 : : }
1587 : : } else {
1588 : 0 : dq_idx = *dpaa2_seqn(m) - 1;
1589 : 0 : qbman_eq_desc_set_dca(eqdesc, 1, dq_idx, 0);
1590 : 0 : DPAA2_PER_LCORE_DQRR_SIZE--;
1591 : 0 : DPAA2_PER_LCORE_DQRR_HELD &= ~(UINT64_C(1) << dq_idx);
1592 : : }
1593 : 0 : *dpaa2_seqn(m) = DPAA2_INVALID_MBUF_SEQN;
1594 : 0 : }
1595 : :
1596 : : RTE_EXPORT_INTERNAL_SYMBOL(dpaa2_dev_tx_multi_txq_ordered)
1597 : : uint16_t
1598 : 0 : dpaa2_dev_tx_multi_txq_ordered(void **queue,
1599 : : struct rte_mbuf **bufs, uint16_t nb_pkts)
1600 : 0 : {
1601 : : /* Function to transmit the frames to multiple queues respectively.*/
1602 : : uint32_t loop, i, retry_count;
1603 : : int32_t ret;
1604 : : struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1605 : : uint32_t frames_to_send, num_free_eq_desc = 0;
1606 : : struct rte_mempool *mp;
1607 : : struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
1608 : : struct dpaa2_queue *dpaa2_q[MAX_TX_RING_SLOTS];
1609 : : struct qbman_swp *swp;
1610 : : uint16_t bpid;
1611 : : struct rte_mbuf *mi;
1612 : : struct rte_eth_dev_data *eth_data;
1613 : : struct dpaa2_dev_priv *priv;
1614 : : struct dpaa2_queue *order_sendq;
1615 : 0 : struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size];
1616 : 0 : uint32_t free_count = 0;
1617 : :
1618 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1619 : 0 : ret = dpaa2_affine_qbman_swp();
1620 [ # # ]: 0 : if (ret) {
1621 : 0 : DPAA2_PMD_ERR(
1622 : : "Failed to allocate IO portal, tid: %d",
1623 : : rte_gettid());
1624 : 0 : return 0;
1625 : : }
1626 : : }
1627 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1628 : :
1629 : 0 : frames_to_send = (nb_pkts > dpaa2_eqcr_size) ?
1630 [ # # ]: 0 : dpaa2_eqcr_size : nb_pkts;
1631 : :
1632 [ # # ]: 0 : for (loop = 0; loop < frames_to_send; loop++) {
1633 : 0 : dpaa2_q[loop] = (struct dpaa2_queue *)queue[loop];
1634 : 0 : eth_data = dpaa2_q[loop]->eth_data;
1635 : 0 : priv = eth_data->dev_private;
1636 [ # # ]: 0 : if (!priv->en_loose_ordered) {
1637 [ # # ]: 0 : if (*dpaa2_seqn(*bufs) & DPAA2_ENQUEUE_FLAG_ORP) {
1638 [ # # ]: 0 : if (!num_free_eq_desc) {
1639 : 0 : num_free_eq_desc = dpaa2_free_eq_descriptors();
1640 [ # # ]: 0 : if (!num_free_eq_desc)
1641 : 0 : goto send_frames;
1642 : : }
1643 : 0 : num_free_eq_desc--;
1644 : : }
1645 : : }
1646 : :
1647 : : DPAA2_PMD_DP_DEBUG("===> eth_data =%p, fqid =%d",
1648 : : eth_data, dpaa2_q[loop]->fqid);
1649 : :
1650 : : /* Check if the queue is congested */
1651 : : retry_count = 0;
1652 [ # # ]: 0 : while (qbman_result_SCN_state(dpaa2_q[loop]->cscn)) {
1653 : 0 : retry_count++;
1654 : : /* Retry for some time before giving up */
1655 [ # # ]: 0 : if (retry_count > CONG_RETRY_COUNT)
1656 : 0 : goto send_frames;
1657 : : }
1658 : :
1659 : : /* Prepare enqueue descriptor */
1660 : 0 : qbman_eq_desc_clear(&eqdesc[loop]);
1661 : :
1662 [ # # # # ]: 0 : if (*dpaa2_seqn(*bufs) && priv->en_ordered) {
1663 : 0 : order_sendq = (struct dpaa2_queue *)priv->tx_vq[0];
1664 : 0 : dpaa2_set_enqueue_descriptor(order_sendq,
1665 : : (*bufs),
1666 : : &eqdesc[loop]);
1667 : : } else {
1668 : 0 : qbman_eq_desc_set_no_orp(&eqdesc[loop],
1669 : : DPAA2_EQ_RESP_ERR_FQ);
1670 : 0 : qbman_eq_desc_set_fq(&eqdesc[loop],
1671 : : dpaa2_q[loop]->fqid);
1672 : : }
1673 : :
1674 [ # # ]: 0 : if (likely(RTE_MBUF_DIRECT(*bufs))) {
1675 : 0 : mp = (*bufs)->pool;
1676 : : /* Check the basic scenario and set
1677 : : * the FD appropriately here itself.
1678 : : */
1679 [ # # # # : 0 : if (likely(mp && mp->ops_index ==
# # # # ]
1680 : : priv->bp_list->dpaa2_ops_index &&
1681 : : (*bufs)->nb_segs == 1 &&
1682 : : rte_mbuf_refcnt_read((*bufs)) == 1)) {
1683 [ # # ]: 0 : if (unlikely((*bufs)->ol_flags
1684 : : & RTE_MBUF_F_TX_VLAN)) {
1685 : 0 : ret = rte_vlan_insert(bufs);
1686 [ # # ]: 0 : if (ret)
1687 : 0 : goto send_frames;
1688 : : }
1689 : 0 : DPAA2_MBUF_TO_CONTIG_FD((*bufs),
1690 : : &fd_arr[loop],
1691 : : mempool_to_bpid(mp));
1692 : 0 : bufs++;
1693 : 0 : continue;
1694 : : }
1695 : : } else {
1696 : : mi = rte_mbuf_from_indirect(*bufs);
1697 : 0 : mp = mi->pool;
1698 : : }
1699 : : /* Not a hw_pkt pool allocated frame */
1700 [ # # # # ]: 0 : if (unlikely(!mp || !priv->bp_list)) {
1701 : 0 : DPAA2_PMD_ERR("Err: No buffer pool attached");
1702 : 0 : goto send_frames;
1703 : : }
1704 : :
1705 [ # # ]: 0 : if (mp->ops_index != priv->bp_list->dpaa2_ops_index) {
1706 : 0 : DPAA2_PMD_WARN("Non DPAA2 buffer pool");
1707 : : /* alloc should be from the default buffer pool
1708 : : * attached to this interface
1709 : : */
1710 : 0 : bpid = priv->bp_list->buf_pool.bpid;
1711 : :
1712 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1713 : 0 : DPAA2_PMD_ERR(
1714 : : "S/G not supp for non hw offload buffer");
1715 : 0 : goto send_frames;
1716 : : }
1717 [ # # ]: 0 : if (eth_copy_mbuf_to_fd(*bufs,
1718 : : &fd_arr[loop], bpid)) {
1719 : 0 : goto send_frames;
1720 : : }
1721 : : /* free the original packet */
1722 : 0 : rte_pktmbuf_free(*bufs);
1723 : : } else {
1724 : 0 : bpid = mempool_to_bpid(mp);
1725 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1726 [ # # ]: 0 : if (eth_mbuf_to_sg_fd(*bufs,
1727 : : &fd_arr[loop],
1728 : : buf_to_free,
1729 : : &free_count,
1730 : : loop,
1731 : : bpid))
1732 : 0 : goto send_frames;
1733 : : } else {
1734 : 0 : eth_mbuf_to_fd(*bufs,
1735 : : &fd_arr[loop],
1736 : : buf_to_free,
1737 : : &free_count,
1738 : : loop, bpid);
1739 : : }
1740 : : }
1741 : :
1742 : 0 : bufs++;
1743 : : }
1744 : :
1745 : 0 : send_frames:
1746 : : frames_to_send = loop;
1747 : : loop = 0;
1748 : : retry_count = 0;
1749 [ # # ]: 0 : while (loop < frames_to_send) {
1750 : 0 : ret = qbman_swp_enqueue_multiple_desc(swp, &eqdesc[loop],
1751 : 0 : &fd_arr[loop],
1752 : 0 : frames_to_send - loop);
1753 [ # # ]: 0 : if (likely(ret > 0)) {
1754 : 0 : loop += ret;
1755 : : retry_count = 0;
1756 : : } else {
1757 : 0 : retry_count++;
1758 [ # # ]: 0 : if (retry_count > DPAA2_MAX_TX_RETRY_COUNT)
1759 : : break;
1760 : : }
1761 : : }
1762 : :
1763 [ # # ]: 0 : for (i = 0; i < free_count; i++) {
1764 [ # # ]: 0 : if (buf_to_free[i].pkt_id < loop)
1765 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[i].seg);
1766 : : }
1767 : 0 : return loop;
1768 : : }
1769 : :
1770 : : /* Callback to handle sending ordered packets through WRIOP based interface */
1771 : : uint16_t
1772 : 0 : dpaa2_dev_tx_ordered(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
1773 : 0 : {
1774 : : /* Function to transmit the frames to given device and VQ*/
1775 : : struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
1776 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
1777 : 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
1778 : 0 : struct dpaa2_queue *order_sendq = (struct dpaa2_queue *)priv->tx_vq[0];
1779 : : struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1780 : : struct rte_mbuf *mi;
1781 : : struct rte_mempool *mp;
1782 : : struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
1783 : : struct qbman_swp *swp;
1784 : : uint32_t frames_to_send, num_free_eq_desc;
1785 : : uint32_t loop, retry_count;
1786 : : int32_t ret;
1787 : : uint16_t num_tx = 0;
1788 : : uint16_t bpid;
1789 : 0 : struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size];
1790 : 0 : uint32_t free_count = 0;
1791 : :
1792 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1793 : 0 : ret = dpaa2_affine_qbman_swp();
1794 [ # # ]: 0 : if (ret) {
1795 : 0 : DPAA2_PMD_ERR(
1796 : : "Failed to allocate IO portal, tid: %d",
1797 : : rte_gettid());
1798 : 0 : return 0;
1799 : : }
1800 : : }
1801 : 0 : swp = DPAA2_PER_LCORE_PORTAL;
1802 : :
1803 : : DPAA2_PMD_DP_DEBUG("===> eth_data =%p, fqid =%d",
1804 : : eth_data, dpaa2_q->fqid);
1805 : :
1806 : : /* This would also handle normal and atomic queues as any type
1807 : : * of packet can be enqueued when ordered queues are being used.
1808 : : */
1809 [ # # ]: 0 : while (nb_pkts) {
1810 : : /*Check if the queue is congested*/
1811 : : retry_count = 0;
1812 [ # # ]: 0 : while (qbman_result_SCN_state(dpaa2_q->cscn)) {
1813 : 0 : retry_count++;
1814 : : /* Retry for some time before giving up */
1815 [ # # ]: 0 : if (retry_count > CONG_RETRY_COUNT) {
1816 [ # # ]: 0 : if (dpaa2_q->tm_sw_td)
1817 : 0 : goto sw_td;
1818 : 0 : goto skip_tx;
1819 : : }
1820 : : }
1821 : :
1822 : 0 : frames_to_send = (nb_pkts > dpaa2_eqcr_size) ?
1823 [ # # ]: 0 : dpaa2_eqcr_size : nb_pkts;
1824 : :
1825 [ # # ]: 0 : if (!priv->en_loose_ordered) {
1826 [ # # ]: 0 : if (*dpaa2_seqn(*bufs) & DPAA2_ENQUEUE_FLAG_ORP) {
1827 : 0 : num_free_eq_desc = dpaa2_free_eq_descriptors();
1828 : : if (num_free_eq_desc < frames_to_send)
1829 : : frames_to_send = num_free_eq_desc;
1830 : : }
1831 : : }
1832 : :
1833 [ # # ]: 0 : for (loop = 0; loop < frames_to_send; loop++) {
1834 : : /*Prepare enqueue descriptor*/
1835 : 0 : qbman_eq_desc_clear(&eqdesc[loop]);
1836 : :
1837 [ # # ]: 0 : if (*dpaa2_seqn(*bufs)) {
1838 : : /* Use only queue 0 for Tx in case of atomic/
1839 : : * ordered packets as packets can get unordered
1840 : : * when being transmitted out from the interface
1841 : : */
1842 : 0 : dpaa2_set_enqueue_descriptor(order_sendq,
1843 : : (*bufs),
1844 : : &eqdesc[loop]);
1845 : : } else {
1846 : 0 : qbman_eq_desc_set_no_orp(&eqdesc[loop],
1847 : : DPAA2_EQ_RESP_ERR_FQ);
1848 : 0 : qbman_eq_desc_set_fq(&eqdesc[loop],
1849 : : dpaa2_q->fqid);
1850 : : }
1851 : :
1852 [ # # ]: 0 : if (likely(RTE_MBUF_DIRECT(*bufs))) {
1853 : 0 : mp = (*bufs)->pool;
1854 : : /* Check the basic scenario and set
1855 : : * the FD appropriately here itself.
1856 : : */
1857 [ # # # # : 0 : if (likely(mp && mp->ops_index ==
# # # # ]
1858 : : priv->bp_list->dpaa2_ops_index &&
1859 : : (*bufs)->nb_segs == 1 &&
1860 : : rte_mbuf_refcnt_read((*bufs)) == 1)) {
1861 [ # # ]: 0 : if (unlikely((*bufs)->ol_flags
1862 : : & RTE_MBUF_F_TX_VLAN)) {
1863 : 0 : ret = rte_vlan_insert(bufs);
1864 [ # # ]: 0 : if (ret)
1865 : 0 : goto send_n_return;
1866 : : }
1867 : 0 : DPAA2_MBUF_TO_CONTIG_FD((*bufs),
1868 : : &fd_arr[loop],
1869 : : mempool_to_bpid(mp));
1870 : 0 : bufs++;
1871 : 0 : continue;
1872 : : }
1873 : : } else {
1874 : : mi = rte_mbuf_from_indirect(*bufs);
1875 : 0 : mp = mi->pool;
1876 : : }
1877 : : /* Not a hw_pkt pool allocated frame */
1878 [ # # # # ]: 0 : if (unlikely(!mp || !priv->bp_list)) {
1879 : 0 : DPAA2_PMD_ERR("Err: No buffer pool attached");
1880 : 0 : goto send_n_return;
1881 : : }
1882 : :
1883 [ # # ]: 0 : if (mp->ops_index != priv->bp_list->dpaa2_ops_index) {
1884 : 0 : DPAA2_PMD_WARN("Non DPAA2 buffer pool");
1885 : : /* alloc should be from the default buffer pool
1886 : : * attached to this interface
1887 : : */
1888 : 0 : bpid = priv->bp_list->buf_pool.bpid;
1889 : :
1890 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1891 : 0 : DPAA2_PMD_ERR(
1892 : : "S/G not supp for non hw offload buffer");
1893 : 0 : goto send_n_return;
1894 : : }
1895 [ # # ]: 0 : if (eth_copy_mbuf_to_fd(*bufs,
1896 : : &fd_arr[loop], bpid)) {
1897 : 0 : goto send_n_return;
1898 : : }
1899 : : /* free the original packet */
1900 : 0 : rte_pktmbuf_free(*bufs);
1901 : : } else {
1902 : 0 : bpid = mempool_to_bpid(mp);
1903 [ # # ]: 0 : if (unlikely((*bufs)->nb_segs > 1)) {
1904 [ # # ]: 0 : if (eth_mbuf_to_sg_fd(*bufs,
1905 : : &fd_arr[loop],
1906 : : buf_to_free,
1907 : : &free_count,
1908 : : loop,
1909 : : bpid))
1910 : 0 : goto send_n_return;
1911 : : } else {
1912 : 0 : eth_mbuf_to_fd(*bufs,
1913 : : &fd_arr[loop],
1914 : : buf_to_free,
1915 : : &free_count,
1916 : : loop, bpid);
1917 : : }
1918 : : }
1919 : 0 : bufs++;
1920 : : }
1921 : :
1922 : : loop = 0;
1923 : : retry_count = 0;
1924 [ # # ]: 0 : while (loop < frames_to_send) {
1925 : 0 : ret = qbman_swp_enqueue_multiple_desc(swp,
1926 : 0 : &eqdesc[loop], &fd_arr[loop],
1927 : 0 : frames_to_send - loop);
1928 [ # # ]: 0 : if (unlikely(ret < 0)) {
1929 : 0 : retry_count++;
1930 [ # # ]: 0 : if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1931 : 0 : num_tx += loop;
1932 : : nb_pkts -= loop;
1933 : 0 : goto send_n_return;
1934 : : }
1935 : : } else {
1936 : 0 : loop += ret;
1937 : : retry_count = 0;
1938 : : }
1939 : : }
1940 : :
1941 : 0 : num_tx += loop;
1942 : 0 : nb_pkts -= loop;
1943 : : }
1944 : 0 : dpaa2_q->tx_pkts += num_tx;
1945 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1946 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1947 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1948 : : }
1949 : :
1950 : : return num_tx;
1951 : :
1952 : 0 : send_n_return:
1953 : : /* send any already prepared fd */
1954 [ # # ]: 0 : if (loop) {
1955 : : unsigned int i = 0;
1956 : :
1957 : : retry_count = 0;
1958 [ # # ]: 0 : while (i < loop) {
1959 : 0 : ret = qbman_swp_enqueue_multiple_desc(swp,
1960 : 0 : &eqdesc[i], &fd_arr[i], loop - i);
1961 [ # # ]: 0 : if (unlikely(ret < 0)) {
1962 : 0 : retry_count++;
1963 [ # # ]: 0 : if (retry_count > DPAA2_MAX_TX_RETRY_COUNT)
1964 : : break;
1965 : : } else {
1966 : 0 : i += ret;
1967 : : retry_count = 0;
1968 : : }
1969 : : }
1970 : 0 : num_tx += i;
1971 : : }
1972 : 0 : skip_tx:
1973 : 0 : dpaa2_q->tx_pkts += num_tx;
1974 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1975 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1976 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1977 : : }
1978 : :
1979 : : return num_tx;
1980 : : sw_td:
1981 [ # # ]: 0 : for (loop = 0; loop < free_count; loop++) {
1982 [ # # ]: 0 : if (buf_to_free[loop].pkt_id < num_tx)
1983 [ # # ]: 0 : rte_pktmbuf_free_seg(buf_to_free[loop].seg);
1984 : : }
1985 : :
1986 : : /* free the pending buffers */
1987 : 0 : rte_pktmbuf_free_bulk(bufs, nb_pkts);
1988 : :
1989 : 0 : num_tx += nb_pkts;
1990 : 0 : dpaa2_q->tx_pkts += num_tx;
1991 : :
1992 : 0 : return num_tx;
1993 : : }
1994 : :
1995 : : /* This function loopbacks all the received packets.*/
1996 : : uint16_t
1997 : 0 : dpaa2_dev_loopback_rx(void *queue,
1998 : : struct rte_mbuf **bufs __rte_unused,
1999 : : uint16_t nb_pkts)
2000 : : {
2001 : : /* Function receive frames for a given device and VQ*/
2002 : : struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)queue;
2003 : : struct qbman_result *dq_storage, *dq_storage1 = NULL;
2004 : 0 : uint32_t fqid = dpaa2_q->fqid;
2005 : : int ret, num_rx = 0, num_tx = 0, pull_size;
2006 : : uint8_t pending, status;
2007 : : struct qbman_swp *swp;
2008 : : struct qbman_fd *fd[DPAA2_LX2_DQRR_RING_SIZE];
2009 : : struct qbman_pull_desc pulldesc;
2010 : : struct qbman_eq_desc eqdesc;
2011 : : struct queue_storage_info_t *q_storage;
2012 : 0 : struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data;
2013 : 0 : struct dpaa2_dev_priv *priv = eth_data->dev_private;
2014 [ # # ]: 0 : struct dpaa2_queue *tx_q = priv->tx_vq[0];
2015 : : /* todo - currently we are using 1st TX queue only for loopback*/
2016 : :
2017 : 0 : q_storage = dpaa2_q->q_storage[rte_lcore_id()];
2018 [ # # ]: 0 : if (unlikely(!DPAA2_PER_LCORE_ETHRX_DPIO)) {
2019 : 0 : ret = dpaa2_affine_qbman_ethrx_swp();
2020 [ # # ]: 0 : if (ret) {
2021 : 0 : DPAA2_PMD_ERR("Failure in affining portal");
2022 : 0 : return 0;
2023 : : }
2024 : : }
2025 : 0 : swp = DPAA2_PER_LCORE_ETHRX_PORTAL;
2026 [ # # ]: 0 : pull_size = (nb_pkts > dpaa2_dqrr_size) ? dpaa2_dqrr_size : nb_pkts;
2027 [ # # ]: 0 : if (unlikely(!q_storage->active_dqs)) {
2028 : 0 : q_storage->toggle = 0;
2029 : 0 : dq_storage = q_storage->dq_storage[q_storage->toggle];
2030 : 0 : q_storage->last_num_pkts = pull_size;
2031 : 0 : qbman_pull_desc_clear(&pulldesc);
2032 : 0 : qbman_pull_desc_set_numframes(&pulldesc,
2033 : 0 : q_storage->last_num_pkts);
2034 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
2035 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage,
2036 : : (size_t)(DPAA2_VADDR_TO_IOVA(dq_storage)), 1);
2037 [ # # ]: 0 : if (check_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)) {
2038 [ # # ]: 0 : while (!qbman_check_command_complete(
2039 : : get_swp_active_dqs(
2040 : 0 : DPAA2_PER_LCORE_ETHRX_DPIO->index)))
2041 : : ;
2042 : 0 : clear_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index);
2043 : : }
2044 : : while (1) {
2045 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
2046 : : DPAA2_PMD_DP_DEBUG(
2047 : : "VDQ command not issued.QBMAN busy");
2048 : : /* Portal was busy, try again */
2049 : : continue;
2050 : : }
2051 : : break;
2052 : : }
2053 : 0 : q_storage->active_dqs = dq_storage;
2054 : 0 : q_storage->active_dpio_id = DPAA2_PER_LCORE_ETHRX_DPIO->index;
2055 : 0 : set_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index,
2056 : : dq_storage);
2057 : : }
2058 : :
2059 : 0 : dq_storage = q_storage->active_dqs;
2060 : : rte_prefetch0((void *)(size_t)(dq_storage));
2061 : 0 : rte_prefetch0((void *)(size_t)(dq_storage + 1));
2062 : :
2063 : : /* Prepare next pull descriptor. This will give space for the
2064 : : * prefetching done on DQRR entries
2065 : : */
2066 : 0 : q_storage->toggle ^= 1;
2067 : 0 : dq_storage1 = q_storage->dq_storage[q_storage->toggle];
2068 : 0 : qbman_pull_desc_clear(&pulldesc);
2069 : 0 : qbman_pull_desc_set_numframes(&pulldesc, pull_size);
2070 : 0 : qbman_pull_desc_set_fq(&pulldesc, fqid);
2071 : 0 : qbman_pull_desc_set_storage(&pulldesc, dq_storage1,
2072 : : (size_t)(DPAA2_VADDR_TO_IOVA(dq_storage1)), 1);
2073 : :
2074 : : /*Prepare enqueue descriptor*/
2075 : 0 : qbman_eq_desc_clear(&eqdesc);
2076 : 0 : qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
2077 : 0 : qbman_eq_desc_set_response(&eqdesc, 0, 0);
2078 : 0 : qbman_eq_desc_set_fq(&eqdesc, tx_q->fqid);
2079 : :
2080 : : /* Check if the previous issued command is completed.
2081 : : * Also seems like the SWP is shared between the Ethernet Driver
2082 : : * and the SEC driver.
2083 : : */
2084 [ # # ]: 0 : while (!qbman_check_command_complete(dq_storage))
2085 : : ;
2086 [ # # ]: 0 : if (dq_storage == get_swp_active_dqs(q_storage->active_dpio_id))
2087 : : clear_swp_active_dqs(q_storage->active_dpio_id);
2088 : :
2089 : : pending = 1;
2090 : :
2091 : : do {
2092 : : /* Loop until the dq_storage is updated with
2093 : : * new token by QBMAN
2094 : : */
2095 [ # # ]: 0 : while (!qbman_check_new_result(dq_storage))
2096 : : ;
2097 : 0 : rte_prefetch0((void *)((size_t)(dq_storage + 2)));
2098 : : /* Check whether Last Pull command is Expired and
2099 : : * setting Condition for Loop termination
2100 : : */
2101 [ # # ]: 0 : if (qbman_result_DQ_is_pull_complete(dq_storage)) {
2102 : : pending = 0;
2103 : : /* Check for valid frame. */
2104 : 0 : status = qbman_result_DQ_flags(dq_storage);
2105 [ # # ]: 0 : if (unlikely((status & QBMAN_DQ_STAT_VALIDFRAME) == 0))
2106 : 0 : continue;
2107 : : }
2108 : 0 : fd[num_rx] = RTE_PTR_UNQUAL(qbman_result_DQ_fd(dq_storage));
2109 : :
2110 : 0 : dq_storage++;
2111 : 0 : num_rx++;
2112 [ # # ]: 0 : } while (pending);
2113 : :
2114 [ # # ]: 0 : while (num_tx < num_rx) {
2115 : 0 : num_tx += qbman_swp_enqueue_multiple_fd(swp, &eqdesc,
2116 : : &fd[num_tx], 0, num_rx - num_tx);
2117 : : }
2118 : :
2119 [ # # ]: 0 : if (check_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)) {
2120 [ # # ]: 0 : while (!qbman_check_command_complete(
2121 : 0 : get_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index)))
2122 : : ;
2123 : 0 : clear_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index);
2124 : : }
2125 : : /* issue a volatile dequeue command for next pull */
2126 : : while (1) {
2127 [ # # ]: 0 : if (qbman_swp_pull(swp, &pulldesc)) {
2128 : : DPAA2_PMD_DP_DEBUG("VDQ command is not issued."
2129 : : "QBMAN is busy (2)");
2130 : : continue;
2131 : : }
2132 : : break;
2133 : : }
2134 : 0 : q_storage->active_dqs = dq_storage1;
2135 : 0 : q_storage->active_dpio_id = DPAA2_PER_LCORE_ETHRX_DPIO->index;
2136 : 0 : set_swp_active_dqs(DPAA2_PER_LCORE_ETHRX_DPIO->index, dq_storage1);
2137 : :
2138 : 0 : dpaa2_q->rx_pkts += num_rx;
2139 : 0 : dpaa2_q->tx_pkts += num_tx;
2140 : :
2141 : 0 : return 0;
2142 : : }
|