1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2017,2019 NXP
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
18 #include <rte_interrupts.h>
20 #include <rte_debug.h>
22 #include <rte_atomic.h>
23 #include <rte_branch_prediction.h>
24 #include <rte_memory.h>
25 #include <rte_tailq.h>
27 #include <rte_alarm.h>
28 #include <rte_ether.h>
29 #include <rte_ethdev_driver.h>
30 #include <rte_malloc.h>
36 #include <rte_eventdev.h>
38 #include "dpaa_ethdev.h"
39 #include "dpaa_rxtx.h"
40 #include <rte_dpaa_bus.h>
41 #include <dpaa_mempool.h>
50 #define DPAA_MBUF_TO_CONTIG_FD(_mbuf, _fd, _bpid) \
53 (_fd)->opaque_addr = 0; \
54 (_fd)->opaque = QM_FD_CONTIG << DPAA_FD_FORMAT_SHIFT; \
55 (_fd)->opaque |= ((_mbuf)->data_off) << DPAA_FD_OFFSET_SHIFT; \
56 (_fd)->opaque |= (_mbuf)->pkt_len; \
57 (_fd)->addr = (_mbuf)->buf_iova; \
58 (_fd)->bpid = _bpid; \
61 #if (defined RTE_LIBRTE_DPAA_DEBUG_DRIVER)
62 static void dpaa_display_frame(const struct qm_fd *fd)
67 printf("%s::bpid %x addr %08x%08x, format %d off %d, len %d stat %x\n",
68 __func__, fd->bpid, fd->addr_hi, fd->addr_lo, fd->format,
69 fd->offset, fd->length20, fd->status);
71 ptr = (char *)rte_dpaa_mem_ptov(fd->addr);
73 printf("%02x ", *ptr);
74 for (ii = 1; ii < fd->length20; ii++) {
75 printf("%02x ", *ptr);
83 #define dpaa_display_frame(a)
86 static inline void dpaa_slow_parsing(struct rte_mbuf *m __rte_unused,
87 uint64_t prs __rte_unused)
89 DPAA_DP_LOG(DEBUG, "Slow parsing");
90 /*TBD:XXX: to be implemented*/
93 static inline void dpaa_eth_packet_info(struct rte_mbuf *m, void *fd_virt_addr)
95 struct annotations_t *annot = GET_ANNOTATIONS(fd_virt_addr);
96 uint64_t prs = *((uintptr_t *)(&annot->parse)) & DPAA_PARSE_MASK;
98 DPAA_DP_LOG(DEBUG, " Parsing mbuf: %p with annotations: %p", m, annot);
101 case DPAA_PKT_TYPE_IPV4:
102 m->packet_type = RTE_PTYPE_L2_ETHER |
105 case DPAA_PKT_TYPE_IPV6:
106 m->packet_type = RTE_PTYPE_L2_ETHER |
109 case DPAA_PKT_TYPE_ETHER:
110 m->packet_type = RTE_PTYPE_L2_ETHER;
112 case DPAA_PKT_TYPE_IPV4_FRAG:
113 case DPAA_PKT_TYPE_IPV4_FRAG_UDP:
114 case DPAA_PKT_TYPE_IPV4_FRAG_TCP:
115 case DPAA_PKT_TYPE_IPV4_FRAG_SCTP:
116 m->packet_type = RTE_PTYPE_L2_ETHER |
117 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_FRAG;
119 case DPAA_PKT_TYPE_IPV6_FRAG:
120 case DPAA_PKT_TYPE_IPV6_FRAG_UDP:
121 case DPAA_PKT_TYPE_IPV6_FRAG_TCP:
122 case DPAA_PKT_TYPE_IPV6_FRAG_SCTP:
123 m->packet_type = RTE_PTYPE_L2_ETHER |
124 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_FRAG;
126 case DPAA_PKT_TYPE_IPV4_EXT:
127 m->packet_type = RTE_PTYPE_L2_ETHER |
128 RTE_PTYPE_L3_IPV4_EXT;
130 case DPAA_PKT_TYPE_IPV6_EXT:
131 m->packet_type = RTE_PTYPE_L2_ETHER |
132 RTE_PTYPE_L3_IPV6_EXT;
134 case DPAA_PKT_TYPE_IPV4_TCP:
135 m->packet_type = RTE_PTYPE_L2_ETHER |
136 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP;
138 case DPAA_PKT_TYPE_IPV6_TCP:
139 m->packet_type = RTE_PTYPE_L2_ETHER |
140 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
142 case DPAA_PKT_TYPE_IPV4_UDP:
143 m->packet_type = RTE_PTYPE_L2_ETHER |
144 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP;
146 case DPAA_PKT_TYPE_IPV6_UDP:
147 m->packet_type = RTE_PTYPE_L2_ETHER |
148 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
150 case DPAA_PKT_TYPE_IPV4_EXT_UDP:
151 m->packet_type = RTE_PTYPE_L2_ETHER |
152 RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_UDP;
154 case DPAA_PKT_TYPE_IPV6_EXT_UDP:
155 m->packet_type = RTE_PTYPE_L2_ETHER |
156 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP;
158 case DPAA_PKT_TYPE_IPV4_EXT_TCP:
159 m->packet_type = RTE_PTYPE_L2_ETHER |
160 RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_TCP;
162 case DPAA_PKT_TYPE_IPV6_EXT_TCP:
163 m->packet_type = RTE_PTYPE_L2_ETHER |
164 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP;
166 case DPAA_PKT_TYPE_IPV4_SCTP:
167 m->packet_type = RTE_PTYPE_L2_ETHER |
168 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP;
170 case DPAA_PKT_TYPE_IPV6_SCTP:
171 m->packet_type = RTE_PTYPE_L2_ETHER |
172 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_SCTP;
174 case DPAA_PKT_TYPE_NONE:
177 /* More switch cases can be added */
179 dpaa_slow_parsing(m, prs);
182 m->tx_offload = annot->parse.ip_off[0];
183 m->tx_offload |= (annot->parse.l4_off - annot->parse.ip_off[0])
184 << DPAA_PKT_L3_LEN_SHIFT;
186 /* Set the hash values */
187 m->hash.rss = (uint32_t)(annot->hash);
188 /* All packets with Bad checksum are dropped by interface (and
189 * corresponding notification issued to RX error queues).
191 m->ol_flags = PKT_RX_RSS_HASH | PKT_RX_IP_CKSUM_GOOD;
193 /* Check if Vlan is present */
194 if (prs & DPAA_PARSE_VLAN_MASK)
195 m->ol_flags |= PKT_RX_VLAN;
196 /* Packet received without stripping the vlan */
199 static inline void dpaa_checksum(struct rte_mbuf *mbuf)
201 struct rte_ether_hdr *eth_hdr =
202 rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr *);
203 char *l3_hdr = (char *)eth_hdr + mbuf->l2_len;
204 struct rte_ipv4_hdr *ipv4_hdr = (struct rte_ipv4_hdr *)l3_hdr;
205 struct rte_ipv6_hdr *ipv6_hdr = (struct rte_ipv6_hdr *)l3_hdr;
207 DPAA_DP_LOG(DEBUG, "Calculating checksum for mbuf: %p", mbuf);
209 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
210 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
211 RTE_PTYPE_L3_IPV4_EXT)) {
212 ipv4_hdr = (struct rte_ipv4_hdr *)l3_hdr;
213 ipv4_hdr->hdr_checksum = 0;
214 ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
215 } else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
216 RTE_PTYPE_L3_IPV6) ||
217 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
218 RTE_PTYPE_L3_IPV6_EXT))
219 ipv6_hdr = (struct rte_ipv6_hdr *)l3_hdr;
221 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) {
222 struct rte_tcp_hdr *tcp_hdr = (struct rte_tcp_hdr *)(l3_hdr +
225 if (eth_hdr->ether_type == htons(RTE_ETHER_TYPE_IPV4))
226 tcp_hdr->cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
228 else /* assume ethertype == RTE_ETHER_TYPE_IPV6 */
229 tcp_hdr->cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
231 } else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) ==
233 struct rte_udp_hdr *udp_hdr = (struct rte_udp_hdr *)(l3_hdr +
235 udp_hdr->dgram_cksum = 0;
236 if (eth_hdr->ether_type == htons(RTE_ETHER_TYPE_IPV4))
237 udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
239 else /* assume ethertype == RTE_ETHER_TYPE_IPV6 */
240 udp_hdr->dgram_cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
245 static inline void dpaa_checksum_offload(struct rte_mbuf *mbuf,
246 struct qm_fd *fd, char *prs_buf)
248 struct dpaa_eth_parse_results_t *prs;
250 DPAA_DP_LOG(DEBUG, " Offloading checksum for mbuf: %p", mbuf);
252 prs = GET_TX_PRS(prs_buf);
255 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
256 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
257 RTE_PTYPE_L3_IPV4_EXT))
258 prs->l3r = DPAA_L3_PARSE_RESULT_IPV4;
259 else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
260 RTE_PTYPE_L3_IPV6) ||
261 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
262 RTE_PTYPE_L3_IPV6_EXT))
263 prs->l3r = DPAA_L3_PARSE_RESULT_IPV6;
265 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP)
266 prs->l4r = DPAA_L4_PARSE_RESULT_TCP;
267 else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP)
268 prs->l4r = DPAA_L4_PARSE_RESULT_UDP;
270 prs->ip_off[0] = mbuf->l2_len;
271 prs->l4_off = mbuf->l3_len + mbuf->l2_len;
272 /* Enable L3 (and L4, if TCP or UDP) HW checksum*/
273 fd->cmd = DPAA_FD_CMD_RPD | DPAA_FD_CMD_DTC;
277 dpaa_unsegmented_checksum(struct rte_mbuf *mbuf, struct qm_fd *fd_arr)
279 if (!mbuf->packet_type) {
280 struct rte_net_hdr_lens hdr_lens;
282 mbuf->packet_type = rte_net_get_ptype(mbuf, &hdr_lens,
283 RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
284 | RTE_PTYPE_L4_MASK);
285 mbuf->l2_len = hdr_lens.l2_len;
286 mbuf->l3_len = hdr_lens.l3_len;
288 if (mbuf->data_off < (DEFAULT_TX_ICEOF +
289 sizeof(struct dpaa_eth_parse_results_t))) {
290 DPAA_DP_LOG(DEBUG, "Checksum offload Err: "
291 "Not enough Headroom "
292 "space for correct Checksum offload."
293 "So Calculating checksum in Software.");
296 dpaa_checksum_offload(mbuf, fd_arr, mbuf->buf_addr);
301 dpaa_eth_sg_to_mbuf(const struct qm_fd *fd, uint32_t ifid)
303 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
304 struct rte_mbuf *first_seg, *prev_seg, *cur_seg, *temp;
305 struct qm_sg_entry *sgt, *sg_temp;
306 void *vaddr, *sg_vaddr;
308 uint8_t fd_offset = fd->offset;
310 vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_fd_addr(fd));
312 DPAA_PMD_ERR("unable to convert physical address");
315 sgt = vaddr + fd_offset;
317 hw_sg_to_cpu(sg_temp);
318 temp = (struct rte_mbuf *)((char *)vaddr - bp_info->meta_data_size);
319 sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_sg_entry_get64(sg_temp));
321 first_seg = (struct rte_mbuf *)((char *)sg_vaddr -
322 bp_info->meta_data_size);
323 first_seg->data_off = sg_temp->offset;
324 first_seg->data_len = sg_temp->length;
325 first_seg->pkt_len = sg_temp->length;
326 rte_mbuf_refcnt_set(first_seg, 1);
328 first_seg->port = ifid;
329 first_seg->nb_segs = 1;
330 first_seg->ol_flags = 0;
331 prev_seg = first_seg;
332 while (i < DPAA_SGT_MAX_ENTRIES) {
334 hw_sg_to_cpu(sg_temp);
335 sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info,
336 qm_sg_entry_get64(sg_temp));
337 cur_seg = (struct rte_mbuf *)((char *)sg_vaddr -
338 bp_info->meta_data_size);
339 cur_seg->data_off = sg_temp->offset;
340 cur_seg->data_len = sg_temp->length;
341 first_seg->pkt_len += sg_temp->length;
342 first_seg->nb_segs += 1;
343 rte_mbuf_refcnt_set(cur_seg, 1);
344 prev_seg->next = cur_seg;
345 if (sg_temp->final) {
346 cur_seg->next = NULL;
351 DPAA_DP_LOG(DEBUG, "Received an SG frame len =%d, num_sg =%d",
352 first_seg->pkt_len, first_seg->nb_segs);
354 dpaa_eth_packet_info(first_seg, vaddr);
355 rte_pktmbuf_free_seg(temp);
360 static inline struct rte_mbuf *
361 dpaa_eth_fd_to_mbuf(const struct qm_fd *fd, uint32_t ifid)
363 struct rte_mbuf *mbuf;
364 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
367 (fd->opaque & DPAA_FD_FORMAT_MASK) >> DPAA_FD_FORMAT_SHIFT;
371 if (unlikely(format == qm_fd_sg))
372 return dpaa_eth_sg_to_mbuf(fd, ifid);
374 offset = (fd->opaque & DPAA_FD_OFFSET_MASK) >> DPAA_FD_OFFSET_SHIFT;
375 length = fd->opaque & DPAA_FD_LENGTH_MASK;
377 DPAA_DP_LOG(DEBUG, " FD--->MBUF off %d len = %d", offset, length);
379 /* Ignoring case when format != qm_fd_contig */
380 dpaa_display_frame(fd);
381 ptr = DPAA_MEMPOOL_PTOV(bp_info, qm_fd_addr(fd));
383 mbuf = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
384 /* Prefetch the Parse results and packet data to L1 */
385 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
387 mbuf->data_off = offset;
388 mbuf->data_len = length;
389 mbuf->pkt_len = length;
395 rte_mbuf_refcnt_set(mbuf, 1);
396 dpaa_eth_packet_info(mbuf, mbuf->buf_addr);
401 /* Specific for LS1043 */
403 dpaa_rx_cb_no_prefetch(struct qman_fq **fq, struct qm_dqrr_entry **dqrr,
404 void **bufs, int num_bufs)
406 struct rte_mbuf *mbuf;
407 struct dpaa_bp_info *bp_info;
408 const struct qm_fd *fd;
410 struct dpaa_if *dpaa_intf;
415 bp_info = DPAA_BPID_TO_POOL_INFO(dqrr[0]->fd.bpid);
416 ptr = rte_dpaa_mem_ptov(qm_fd_addr(&dqrr[0]->fd));
417 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
418 bufs[0] = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
420 for (i = 0; i < num_bufs; i++) {
421 if (i < num_bufs - 1) {
422 bp_info = DPAA_BPID_TO_POOL_INFO(dqrr[i + 1]->fd.bpid);
423 ptr = rte_dpaa_mem_ptov(qm_fd_addr(&dqrr[i + 1]->fd));
424 rte_prefetch0((void *)((uint8_t *)ptr +
426 bufs[i + 1] = (struct rte_mbuf *)((char *)ptr -
427 bp_info->meta_data_size);
431 dpaa_intf = fq[0]->dpaa_intf;
433 format = (fd->opaque & DPAA_FD_FORMAT_MASK) >>
434 DPAA_FD_FORMAT_SHIFT;
435 if (unlikely(format == qm_fd_sg)) {
436 bufs[i] = dpaa_eth_sg_to_mbuf(fd, dpaa_intf->ifid);
440 offset = (fd->opaque & DPAA_FD_OFFSET_MASK) >>
441 DPAA_FD_OFFSET_SHIFT;
442 length = fd->opaque & DPAA_FD_LENGTH_MASK;
445 mbuf->data_off = offset;
446 mbuf->data_len = length;
447 mbuf->pkt_len = length;
448 mbuf->port = dpaa_intf->ifid;
453 rte_mbuf_refcnt_set(mbuf, 1);
454 dpaa_eth_packet_info(mbuf, mbuf->buf_addr);
459 dpaa_rx_cb(struct qman_fq **fq, struct qm_dqrr_entry **dqrr,
460 void **bufs, int num_bufs)
462 struct rte_mbuf *mbuf;
463 const struct qm_fd *fd;
464 struct dpaa_if *dpaa_intf;
469 for (i = 0; i < num_bufs; i++) {
471 dpaa_intf = fq[0]->dpaa_intf;
473 format = (fd->opaque & DPAA_FD_FORMAT_MASK) >>
474 DPAA_FD_FORMAT_SHIFT;
475 if (unlikely(format == qm_fd_sg)) {
476 bufs[i] = dpaa_eth_sg_to_mbuf(fd, dpaa_intf->ifid);
480 offset = (fd->opaque & DPAA_FD_OFFSET_MASK) >>
481 DPAA_FD_OFFSET_SHIFT;
482 length = fd->opaque & DPAA_FD_LENGTH_MASK;
485 mbuf->data_off = offset;
486 mbuf->data_len = length;
487 mbuf->pkt_len = length;
488 mbuf->port = dpaa_intf->ifid;
493 rte_mbuf_refcnt_set(mbuf, 1);
494 dpaa_eth_packet_info(mbuf, mbuf->buf_addr);
498 void dpaa_rx_cb_prepare(struct qm_dqrr_entry *dq, void **bufs)
500 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(dq->fd.bpid);
501 void *ptr = rte_dpaa_mem_ptov(qm_fd_addr(&dq->fd));
503 /* In case of LS1046, annotation stashing is disabled due to L2 cache
504 * being bottleneck in case of multicore scanario for this platform.
505 * So we prefetch the annoation beforehand, so that it is available
506 * in cache when accessed.
508 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
510 *bufs = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
514 dpaa_eth_queue_portal_rx(struct qman_fq *fq,
515 struct rte_mbuf **bufs,
520 if (unlikely(!fq->qp_initialized)) {
521 ret = rte_dpaa_portal_fq_init((void *)0, fq);
523 DPAA_PMD_ERR("Failure in affining portal %d", ret);
526 fq->qp_initialized = 1;
529 return qman_portal_poll_rx(nb_bufs, (void **)bufs, fq->qp);
532 enum qman_cb_dqrr_result
533 dpaa_rx_cb_parallel(void *event,
534 struct qman_portal *qm __always_unused,
536 const struct qm_dqrr_entry *dqrr,
539 u32 ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
540 struct rte_mbuf *mbuf;
541 struct rte_event *ev = (struct rte_event *)event;
543 mbuf = dpaa_eth_fd_to_mbuf(&dqrr->fd, ifid);
544 ev->event_ptr = (void *)mbuf;
545 ev->flow_id = fq->ev.flow_id;
546 ev->sub_event_type = fq->ev.sub_event_type;
547 ev->event_type = RTE_EVENT_TYPE_ETHDEV;
548 ev->op = RTE_EVENT_OP_NEW;
549 ev->sched_type = fq->ev.sched_type;
550 ev->queue_id = fq->ev.queue_id;
551 ev->priority = fq->ev.priority;
552 ev->impl_opaque = (uint8_t)DPAA_INVALID_MBUF_SEQN;
553 mbuf->seqn = DPAA_INVALID_MBUF_SEQN;
556 return qman_cb_dqrr_consume;
559 enum qman_cb_dqrr_result
560 dpaa_rx_cb_atomic(void *event,
561 struct qman_portal *qm __always_unused,
563 const struct qm_dqrr_entry *dqrr,
567 u32 ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
568 struct rte_mbuf *mbuf;
569 struct rte_event *ev = (struct rte_event *)event;
571 mbuf = dpaa_eth_fd_to_mbuf(&dqrr->fd, ifid);
572 ev->event_ptr = (void *)mbuf;
573 ev->flow_id = fq->ev.flow_id;
574 ev->sub_event_type = fq->ev.sub_event_type;
575 ev->event_type = RTE_EVENT_TYPE_ETHDEV;
576 ev->op = RTE_EVENT_OP_NEW;
577 ev->sched_type = fq->ev.sched_type;
578 ev->queue_id = fq->ev.queue_id;
579 ev->priority = fq->ev.priority;
581 /* Save active dqrr entries */
582 index = DQRR_PTR2IDX(dqrr);
583 DPAA_PER_LCORE_DQRR_SIZE++;
584 DPAA_PER_LCORE_DQRR_HELD |= 1 << index;
585 DPAA_PER_LCORE_DQRR_MBUF(index) = mbuf;
586 ev->impl_opaque = index + 1;
587 mbuf->seqn = (uint32_t)index + 1;
590 return qman_cb_dqrr_defer;
593 uint16_t dpaa_eth_queue_rx(void *q,
594 struct rte_mbuf **bufs,
597 struct qman_fq *fq = q;
598 struct qm_dqrr_entry *dq;
599 uint32_t num_rx = 0, ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
600 int num_rx_bufs, ret;
601 uint32_t vdqcr_flags = 0;
603 if (unlikely(rte_dpaa_bpid_info == NULL &&
604 rte_eal_process_type() == RTE_PROC_SECONDARY))
605 rte_dpaa_bpid_info = fq->bp_array;
607 if (likely(fq->is_static))
608 return dpaa_eth_queue_portal_rx(fq, bufs, nb_bufs);
610 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
611 ret = rte_dpaa_portal_init((void *)0);
613 DPAA_PMD_ERR("Failure in affining portal");
618 /* Until request for four buffers, we provide exact number of buffers.
619 * Otherwise we do not set the QM_VDQCR_EXACT flag.
620 * Not setting QM_VDQCR_EXACT flag can provide two more buffers than
621 * requested, so we request two less in this case.
624 vdqcr_flags = QM_VDQCR_EXACT;
625 num_rx_bufs = nb_bufs;
627 num_rx_bufs = nb_bufs > DPAA_MAX_DEQUEUE_NUM_FRAMES ?
628 (DPAA_MAX_DEQUEUE_NUM_FRAMES - 2) : (nb_bufs - 2);
630 ret = qman_set_vdq(fq, num_rx_bufs, vdqcr_flags);
635 dq = qman_dequeue(fq);
638 bufs[num_rx++] = dpaa_eth_fd_to_mbuf(&dq->fd, ifid);
639 qman_dqrr_consume(fq, dq);
640 } while (fq->flags & QMAN_FQ_STATE_VDQCR);
646 dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf,
650 struct rte_mbuf *cur_seg = mbuf, *prev_seg = NULL;
651 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(bpid);
652 struct rte_mbuf *temp, *mi;
653 struct qm_sg_entry *sg_temp, *sgt;
656 DPAA_DP_LOG(DEBUG, "Creating SG FD to transmit");
658 temp = rte_pktmbuf_alloc(bp_info->mp);
660 DPAA_PMD_ERR("Failure in allocation of mbuf");
663 if (temp->buf_len < ((mbuf->nb_segs * sizeof(struct qm_sg_entry))
665 DPAA_PMD_ERR("Insufficient space in mbuf for SG entries");
672 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK) {
673 if (!mbuf->packet_type) {
674 struct rte_net_hdr_lens hdr_lens;
676 mbuf->packet_type = rte_net_get_ptype(mbuf, &hdr_lens,
677 RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
678 | RTE_PTYPE_L4_MASK);
679 mbuf->l2_len = hdr_lens.l2_len;
680 mbuf->l3_len = hdr_lens.l3_len;
682 if (temp->data_off < DEFAULT_TX_ICEOF
683 + sizeof(struct dpaa_eth_parse_results_t))
684 temp->data_off = DEFAULT_TX_ICEOF
685 + sizeof(struct dpaa_eth_parse_results_t);
686 dcbz_64(temp->buf_addr);
687 dpaa_checksum_offload(mbuf, fd, temp->buf_addr);
690 sgt = temp->buf_addr + temp->data_off;
691 fd->format = QM_FD_SG;
692 fd->addr = temp->buf_iova;
693 fd->offset = temp->data_off;
695 fd->length20 = mbuf->pkt_len;
697 while (i < DPAA_SGT_MAX_ENTRIES) {
701 sg_temp->addr = cur_seg->buf_iova;
702 sg_temp->offset = cur_seg->data_off;
703 sg_temp->length = cur_seg->data_len;
704 if (RTE_MBUF_DIRECT(cur_seg)) {
705 if (rte_mbuf_refcnt_read(cur_seg) > 1) {
706 /*If refcnt > 1, invalid bpid is set to ensure
707 * buffer is not freed by HW.
709 sg_temp->bpid = 0xff;
710 rte_mbuf_refcnt_update(cur_seg, -1);
713 DPAA_MEMPOOL_TO_BPID(cur_seg->pool);
715 cur_seg = cur_seg->next;
717 /* Get owner MBUF from indirect buffer */
718 mi = rte_mbuf_from_indirect(cur_seg);
719 if (rte_mbuf_refcnt_read(mi) > 1) {
720 /*If refcnt > 1, invalid bpid is set to ensure
721 * owner buffer is not freed by HW.
723 sg_temp->bpid = 0xff;
725 sg_temp->bpid = DPAA_MEMPOOL_TO_BPID(mi->pool);
726 rte_mbuf_refcnt_update(mi, 1);
729 cur_seg = cur_seg->next;
730 prev_seg->next = NULL;
731 rte_pktmbuf_free(prev_seg);
733 if (cur_seg == NULL) {
735 cpu_to_hw_sg(sg_temp);
738 cpu_to_hw_sg(sg_temp);
743 /* Handle mbufs which are not segmented (non SG) */
745 tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf,
746 struct dpaa_bp_info *bp_info,
747 struct qm_fd *fd_arr)
749 struct rte_mbuf *mi = NULL;
751 if (RTE_MBUF_DIRECT(mbuf)) {
752 if (rte_mbuf_refcnt_read(mbuf) > 1) {
753 /* In case of direct mbuf and mbuf being cloned,
754 * BMAN should _not_ release buffer.
756 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
757 /* Buffer should be releasd by EAL */
758 rte_mbuf_refcnt_update(mbuf, -1);
760 /* In case of direct mbuf and no cloning, mbuf can be
763 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
766 /* This is data-containing core mbuf: 'mi' */
767 mi = rte_mbuf_from_indirect(mbuf);
768 if (rte_mbuf_refcnt_read(mi) > 1) {
769 /* In case of indirect mbuf, and mbuf being cloned,
770 * BMAN should _not_ release it and let EAL release
771 * it through pktmbuf_free below.
773 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
775 /* In case of indirect mbuf, and no cloning, core mbuf
776 * should be released by BMAN.
777 * Increate refcnt of core mbuf so that when
778 * pktmbuf_free is called and mbuf is released, EAL
779 * doesn't try to release core mbuf which would have
780 * been released by BMAN.
782 rte_mbuf_refcnt_update(mi, 1);
783 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
785 rte_pktmbuf_free(mbuf);
788 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK)
789 dpaa_unsegmented_checksum(mbuf, fd_arr);
792 /* Handle all mbufs on dpaa BMAN managed pool */
793 static inline uint16_t
794 tx_on_dpaa_pool(struct rte_mbuf *mbuf,
795 struct dpaa_bp_info *bp_info,
796 struct qm_fd *fd_arr)
798 DPAA_DP_LOG(DEBUG, "BMAN offloaded buffer, mbuf: %p", mbuf);
800 if (mbuf->nb_segs == 1) {
801 /* Case for non-segmented buffers */
802 tx_on_dpaa_pool_unsegmented(mbuf, bp_info, fd_arr);
803 } else if (mbuf->nb_segs > 1 &&
804 mbuf->nb_segs <= DPAA_SGT_MAX_ENTRIES) {
805 if (dpaa_eth_mbuf_to_sg_fd(mbuf, fd_arr, bp_info->bpid)) {
806 DPAA_PMD_DEBUG("Unable to create Scatter Gather FD");
810 DPAA_PMD_DEBUG("Number of Segments not supported");
817 /* Handle all mbufs on an external pool (non-dpaa) */
818 static inline struct rte_mbuf *
819 reallocate_mbuf(struct qman_fq *txq, struct rte_mbuf *mbuf)
821 struct dpaa_if *dpaa_intf = txq->dpaa_intf;
822 struct dpaa_bp_info *bp_info = dpaa_intf->bp_info;
823 struct rte_mbuf *new_mbufs[DPAA_SGT_MAX_ENTRIES + 1] = {0};
824 struct rte_mbuf *temp_mbuf;
825 int num_new_segs, mbuf_greater, ret, extra_seg = 0, i = 0;
826 uint64_t mbufs_size, bytes_to_copy, offset1 = 0, offset2 = 0;
829 DPAA_DP_LOG(DEBUG, "Reallocating transmit buffer");
831 mbufs_size = bp_info->size -
832 bp_info->meta_data_size - RTE_PKTMBUF_HEADROOM;
833 extra_seg = !!(mbuf->pkt_len % mbufs_size);
834 num_new_segs = (mbuf->pkt_len / mbufs_size) + extra_seg;
836 ret = rte_pktmbuf_alloc_bulk(bp_info->mp, new_mbufs, num_new_segs);
838 DPAA_DP_LOG(DEBUG, "Allocation for new buffers failed");
845 /* If mbuf data is less than new mbuf remaining memory */
846 if ((temp_mbuf->data_len - offset1) < (mbufs_size - offset2)) {
847 bytes_to_copy = temp_mbuf->data_len - offset1;
849 /* If mbuf data is greater than new mbuf remaining memory */
850 } else if ((temp_mbuf->data_len - offset1) >
851 (mbufs_size - offset2)) {
852 bytes_to_copy = mbufs_size - offset2;
854 /* if mbuf data is equal to new mbuf remaining memory */
856 bytes_to_copy = temp_mbuf->data_len - offset1;
861 data = rte_pktmbuf_append(new_mbufs[0], bytes_to_copy);
863 rte_memcpy((uint8_t *)data, rte_pktmbuf_mtod_offset(mbuf,
864 void *, offset1), bytes_to_copy);
866 /* Set new offsets and the temp buffers */
867 if (mbuf_greater == -1) {
869 offset2 += bytes_to_copy;
870 temp_mbuf = temp_mbuf->next;
871 } else if (mbuf_greater == 1) {
873 offset1 += bytes_to_copy;
874 new_mbufs[i]->next = new_mbufs[i + 1];
875 new_mbufs[0]->nb_segs++;
880 temp_mbuf = temp_mbuf->next;
881 new_mbufs[i]->next = new_mbufs[i + 1];
882 if (new_mbufs[i + 1])
883 new_mbufs[0]->nb_segs++;
888 /* Copy other required fields */
889 new_mbufs[0]->ol_flags = mbuf->ol_flags;
890 new_mbufs[0]->packet_type = mbuf->packet_type;
891 new_mbufs[0]->tx_offload = mbuf->tx_offload;
893 rte_pktmbuf_free(mbuf);
899 dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
901 struct rte_mbuf *mbuf, *mi = NULL;
902 struct rte_mempool *mp;
903 struct dpaa_bp_info *bp_info;
904 struct qm_fd fd_arr[DPAA_TX_BURST_SIZE];
905 uint32_t frames_to_send, loop, sent = 0;
907 int ret, realloc_mbuf = 0;
908 uint32_t seqn, index, flags[DPAA_TX_BURST_SIZE] = {0};
910 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
911 ret = rte_dpaa_portal_init((void *)0);
913 DPAA_PMD_ERR("Failure in affining portal");
918 DPAA_DP_LOG(DEBUG, "Transmitting %d buffers on queue: %p", nb_bufs, q);
921 frames_to_send = (nb_bufs > DPAA_TX_BURST_SIZE) ?
922 DPAA_TX_BURST_SIZE : nb_bufs;
923 for (loop = 0; loop < frames_to_send; loop++) {
925 /* In case the data offset is not multiple of 16,
926 * FMAN can stall because of an errata. So reallocate
927 * the buffer in such case.
929 if (dpaa_svr_family == SVR_LS1043A_FAMILY &&
930 (mbuf->data_off & 0x7F) != 0x0)
933 if (seqn != DPAA_INVALID_MBUF_SEQN) {
935 if (DPAA_PER_LCORE_DQRR_HELD & (1 << index)) {
937 ((index & QM_EQCR_DCA_IDXMASK) << 8);
938 flags[loop] |= QMAN_ENQUEUE_FLAG_DCA;
939 DPAA_PER_LCORE_DQRR_SIZE--;
940 DPAA_PER_LCORE_DQRR_HELD &=
945 if (likely(RTE_MBUF_DIRECT(mbuf))) {
947 bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
948 if (likely(mp->ops_index ==
949 bp_info->dpaa_ops_index &&
950 mbuf->nb_segs == 1 &&
952 rte_mbuf_refcnt_read(mbuf) == 1)) {
953 DPAA_MBUF_TO_CONTIG_FD(mbuf,
954 &fd_arr[loop], bp_info->bpid);
956 DPAA_TX_CKSUM_OFFLOAD_MASK)
957 dpaa_unsegmented_checksum(mbuf,
962 mi = rte_mbuf_from_indirect(mbuf);
966 bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
967 if (unlikely(mp->ops_index != bp_info->dpaa_ops_index ||
968 realloc_mbuf == 1)) {
969 struct rte_mbuf *temp_mbuf;
971 temp_mbuf = reallocate_mbuf(q, mbuf);
973 /* Set frames_to_send & nb_bufs so
974 * that packets are transmitted till
977 frames_to_send = loop;
985 state = tx_on_dpaa_pool(mbuf, bp_info,
987 if (unlikely(state)) {
988 /* Set frames_to_send & nb_bufs so
989 * that packets are transmitted till
992 frames_to_send = loop;
1000 while (loop < frames_to_send) {
1001 loop += qman_enqueue_multi(q, &fd_arr[loop],
1003 frames_to_send - loop);
1005 nb_bufs -= frames_to_send;
1006 sent += frames_to_send;
1009 DPAA_DP_LOG(DEBUG, "Transmitted %d buffers on queue: %p", sent, q);
1014 uint16_t dpaa_eth_tx_drop_all(void *q __rte_unused,
1015 struct rte_mbuf **bufs __rte_unused,
1016 uint16_t nb_bufs __rte_unused)
1018 DPAA_DP_LOG(DEBUG, "Drop all packets");
1020 /* Drop all incoming packets. No need to free packets here
1021 * because the rte_eth f/w frees up the packets through tx_buffer
1022 * callback in case this functions returns count less than nb_bufs