1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
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 ether_hdr *eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
202 char *l3_hdr = (char *)eth_hdr + mbuf->l2_len;
203 struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
204 struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
206 DPAA_DP_LOG(DEBUG, "Calculating checksum for mbuf: %p", mbuf);
208 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
209 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
210 RTE_PTYPE_L3_IPV4_EXT)) {
211 ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
212 ipv4_hdr->hdr_checksum = 0;
213 ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
214 } else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
215 RTE_PTYPE_L3_IPV6) ||
216 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
217 RTE_PTYPE_L3_IPV6_EXT))
218 ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
220 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) {
221 struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(l3_hdr +
224 if (eth_hdr->ether_type == htons(ETHER_TYPE_IPv4))
225 tcp_hdr->cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
227 else /* assume ethertype == ETHER_TYPE_IPv6 */
228 tcp_hdr->cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
230 } else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) ==
232 struct udp_hdr *udp_hdr = (struct udp_hdr *)(l3_hdr +
234 udp_hdr->dgram_cksum = 0;
235 if (eth_hdr->ether_type == htons(ETHER_TYPE_IPv4))
236 udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
238 else /* assume ethertype == ETHER_TYPE_IPv6 */
239 udp_hdr->dgram_cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
244 static inline void dpaa_checksum_offload(struct rte_mbuf *mbuf,
245 struct qm_fd *fd, char *prs_buf)
247 struct dpaa_eth_parse_results_t *prs;
249 DPAA_DP_LOG(DEBUG, " Offloading checksum for mbuf: %p", mbuf);
251 prs = GET_TX_PRS(prs_buf);
254 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
255 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
256 RTE_PTYPE_L3_IPV4_EXT))
257 prs->l3r = DPAA_L3_PARSE_RESULT_IPV4;
258 else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
259 RTE_PTYPE_L3_IPV6) ||
260 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
261 RTE_PTYPE_L3_IPV6_EXT))
262 prs->l3r = DPAA_L3_PARSE_RESULT_IPV6;
264 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP)
265 prs->l4r = DPAA_L4_PARSE_RESULT_TCP;
266 else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP)
267 prs->l4r = DPAA_L4_PARSE_RESULT_UDP;
269 prs->ip_off[0] = mbuf->l2_len;
270 prs->l4_off = mbuf->l3_len + mbuf->l2_len;
271 /* Enable L3 (and L4, if TCP or UDP) HW checksum*/
272 fd->cmd = DPAA_FD_CMD_RPD | DPAA_FD_CMD_DTC;
276 dpaa_unsegmented_checksum(struct rte_mbuf *mbuf, struct qm_fd *fd_arr)
278 if (!mbuf->packet_type) {
279 struct rte_net_hdr_lens hdr_lens;
281 mbuf->packet_type = rte_net_get_ptype(mbuf, &hdr_lens,
282 RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
283 | RTE_PTYPE_L4_MASK);
284 mbuf->l2_len = hdr_lens.l2_len;
285 mbuf->l3_len = hdr_lens.l3_len;
287 if (mbuf->data_off < (DEFAULT_TX_ICEOF +
288 sizeof(struct dpaa_eth_parse_results_t))) {
289 DPAA_DP_LOG(DEBUG, "Checksum offload Err: "
290 "Not enough Headroom "
291 "space for correct Checksum offload."
292 "So Calculating checksum in Software.");
295 dpaa_checksum_offload(mbuf, fd_arr, mbuf->buf_addr);
300 dpaa_eth_sg_to_mbuf(const struct qm_fd *fd, uint32_t ifid)
302 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
303 struct rte_mbuf *first_seg, *prev_seg, *cur_seg, *temp;
304 struct qm_sg_entry *sgt, *sg_temp;
305 void *vaddr, *sg_vaddr;
307 uint8_t fd_offset = fd->offset;
309 DPAA_DP_LOG(DEBUG, "Received an SG frame");
311 vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_fd_addr(fd));
313 DPAA_PMD_ERR("unable to convert physical address");
316 sgt = vaddr + fd_offset;
318 hw_sg_to_cpu(sg_temp);
319 temp = (struct rte_mbuf *)((char *)vaddr - bp_info->meta_data_size);
320 sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_sg_entry_get64(sg_temp));
322 first_seg = (struct rte_mbuf *)((char *)sg_vaddr -
323 bp_info->meta_data_size);
324 first_seg->data_off = sg_temp->offset;
325 first_seg->data_len = sg_temp->length;
326 first_seg->pkt_len = sg_temp->length;
327 rte_mbuf_refcnt_set(first_seg, 1);
329 first_seg->port = ifid;
330 first_seg->nb_segs = 1;
331 first_seg->ol_flags = 0;
332 prev_seg = first_seg;
333 while (i < DPAA_SGT_MAX_ENTRIES) {
335 hw_sg_to_cpu(sg_temp);
336 sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info,
337 qm_sg_entry_get64(sg_temp));
338 cur_seg = (struct rte_mbuf *)((char *)sg_vaddr -
339 bp_info->meta_data_size);
340 cur_seg->data_off = sg_temp->offset;
341 cur_seg->data_len = sg_temp->length;
342 first_seg->pkt_len += sg_temp->length;
343 first_seg->nb_segs += 1;
344 rte_mbuf_refcnt_set(cur_seg, 1);
345 prev_seg->next = cur_seg;
346 if (sg_temp->final) {
347 cur_seg->next = NULL;
353 dpaa_eth_packet_info(first_seg, vaddr);
354 rte_pktmbuf_free_seg(temp);
359 static inline struct rte_mbuf *
360 dpaa_eth_fd_to_mbuf(const struct qm_fd *fd, uint32_t ifid)
362 struct rte_mbuf *mbuf;
363 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
366 (fd->opaque & DPAA_FD_FORMAT_MASK) >> DPAA_FD_FORMAT_SHIFT;
370 DPAA_DP_LOG(DEBUG, " FD--->MBUF");
372 if (unlikely(format == qm_fd_sg))
373 return dpaa_eth_sg_to_mbuf(fd, ifid);
375 ptr = DPAA_MEMPOOL_PTOV(bp_info, qm_fd_addr(fd));
377 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
379 offset = (fd->opaque & DPAA_FD_OFFSET_MASK) >> DPAA_FD_OFFSET_SHIFT;
380 length = fd->opaque & DPAA_FD_LENGTH_MASK;
382 /* Ignoring case when format != qm_fd_contig */
383 dpaa_display_frame(fd);
385 mbuf = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
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);
402 dpaa_rx_cb(struct qman_fq **fq, struct qm_dqrr_entry **dqrr,
403 void **bufs, int num_bufs)
405 struct rte_mbuf *mbuf;
406 struct dpaa_bp_info *bp_info;
407 const struct qm_fd *fd;
409 struct dpaa_if *dpaa_intf;
414 if (dpaa_svr_family != SVR_LS1046A_FAMILY) {
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 -
419 bp_info->meta_data_size);
422 for (i = 0; i < num_bufs; i++) {
423 if (dpaa_svr_family != SVR_LS1046A_FAMILY &&
425 bp_info = DPAA_BPID_TO_POOL_INFO(dqrr[i + 1]->fd.bpid);
426 ptr = rte_dpaa_mem_ptov(qm_fd_addr(&dqrr[i + 1]->fd));
427 rte_prefetch0((void *)((uint8_t *)ptr +
429 bufs[i + 1] = (struct rte_mbuf *)((char *)ptr -
430 bp_info->meta_data_size);
434 dpaa_intf = fq[0]->dpaa_intf;
436 format = (fd->opaque & DPAA_FD_FORMAT_MASK) >>
437 DPAA_FD_FORMAT_SHIFT;
438 if (unlikely(format == qm_fd_sg)) {
439 bufs[i] = dpaa_eth_sg_to_mbuf(fd, dpaa_intf->ifid);
443 offset = (fd->opaque & DPAA_FD_OFFSET_MASK) >>
444 DPAA_FD_OFFSET_SHIFT;
445 length = fd->opaque & DPAA_FD_LENGTH_MASK;
448 mbuf->data_off = offset;
449 mbuf->data_len = length;
450 mbuf->pkt_len = length;
451 mbuf->port = dpaa_intf->ifid;
456 rte_mbuf_refcnt_set(mbuf, 1);
457 dpaa_eth_packet_info(mbuf, mbuf->buf_addr);
461 void dpaa_rx_cb_prepare(struct qm_dqrr_entry *dq, void **bufs)
463 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(dq->fd.bpid);
464 void *ptr = rte_dpaa_mem_ptov(qm_fd_addr(&dq->fd));
466 /* In case of LS1046, annotation stashing is disabled due to L2 cache
467 * being bottleneck in case of multicore scanario for this platform.
468 * So we prefetch the annoation beforehand, so that it is available
469 * in cache when accessed.
471 if (dpaa_svr_family == SVR_LS1046A_FAMILY)
472 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
474 *bufs = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
478 dpaa_eth_queue_portal_rx(struct qman_fq *fq,
479 struct rte_mbuf **bufs,
484 if (unlikely(fq->qp == NULL)) {
485 ret = rte_dpaa_portal_fq_init((void *)0, fq);
487 DPAA_PMD_ERR("Failure in affining portal %d", ret);
492 return qman_portal_poll_rx(nb_bufs, (void **)bufs, fq->qp);
495 enum qman_cb_dqrr_result
496 dpaa_rx_cb_parallel(void *event,
497 struct qman_portal *qm __always_unused,
499 const struct qm_dqrr_entry *dqrr,
502 u32 ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
503 struct rte_mbuf *mbuf;
504 struct rte_event *ev = (struct rte_event *)event;
506 mbuf = dpaa_eth_fd_to_mbuf(&dqrr->fd, ifid);
507 ev->event_ptr = (void *)mbuf;
508 ev->flow_id = fq->ev.flow_id;
509 ev->sub_event_type = fq->ev.sub_event_type;
510 ev->event_type = RTE_EVENT_TYPE_ETHDEV;
511 ev->op = RTE_EVENT_OP_NEW;
512 ev->sched_type = fq->ev.sched_type;
513 ev->queue_id = fq->ev.queue_id;
514 ev->priority = fq->ev.priority;
515 ev->impl_opaque = (uint8_t)DPAA_INVALID_MBUF_SEQN;
516 mbuf->seqn = DPAA_INVALID_MBUF_SEQN;
519 return qman_cb_dqrr_consume;
522 enum qman_cb_dqrr_result
523 dpaa_rx_cb_atomic(void *event,
524 struct qman_portal *qm __always_unused,
526 const struct qm_dqrr_entry *dqrr,
530 u32 ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
531 struct rte_mbuf *mbuf;
532 struct rte_event *ev = (struct rte_event *)event;
534 mbuf = dpaa_eth_fd_to_mbuf(&dqrr->fd, ifid);
535 ev->event_ptr = (void *)mbuf;
536 ev->flow_id = fq->ev.flow_id;
537 ev->sub_event_type = fq->ev.sub_event_type;
538 ev->event_type = RTE_EVENT_TYPE_ETHDEV;
539 ev->op = RTE_EVENT_OP_NEW;
540 ev->sched_type = fq->ev.sched_type;
541 ev->queue_id = fq->ev.queue_id;
542 ev->priority = fq->ev.priority;
544 /* Save active dqrr entries */
545 index = DQRR_PTR2IDX(dqrr);
546 DPAA_PER_LCORE_DQRR_SIZE++;
547 DPAA_PER_LCORE_DQRR_HELD |= 1 << index;
548 DPAA_PER_LCORE_DQRR_MBUF(index) = mbuf;
549 ev->impl_opaque = index + 1;
550 mbuf->seqn = (uint32_t)index + 1;
553 return qman_cb_dqrr_defer;
556 uint16_t dpaa_eth_queue_rx(void *q,
557 struct rte_mbuf **bufs,
560 struct qman_fq *fq = q;
561 struct qm_dqrr_entry *dq;
562 uint32_t num_rx = 0, ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
565 if (likely(fq->is_static))
566 return dpaa_eth_queue_portal_rx(fq, bufs, nb_bufs);
568 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
569 ret = rte_dpaa_portal_init((void *)0);
571 DPAA_PMD_ERR("Failure in affining portal");
576 ret = qman_set_vdq(fq, (nb_bufs > DPAA_MAX_DEQUEUE_NUM_FRAMES) ?
577 DPAA_MAX_DEQUEUE_NUM_FRAMES : nb_bufs);
582 dq = qman_dequeue(fq);
585 bufs[num_rx++] = dpaa_eth_fd_to_mbuf(&dq->fd, ifid);
586 qman_dqrr_consume(fq, dq);
587 } while (fq->flags & QMAN_FQ_STATE_VDQCR);
592 static void *dpaa_get_pktbuf(struct dpaa_bp_info *bp_info)
596 struct bm_buffer bufs;
598 ret = bman_acquire(bp_info->bp, &bufs, 1, 0);
600 DPAA_PMD_WARN("Failed to allocate buffers %d", ret);
604 DPAA_DP_LOG(DEBUG, "got buffer 0x%" PRIx64 " from pool %d",
605 (uint64_t)bufs.addr, bufs.bpid);
607 buf = (size_t)DPAA_MEMPOOL_PTOV(bp_info, bufs.addr)
608 - bp_info->meta_data_size;
616 static struct rte_mbuf *dpaa_get_dmable_mbuf(struct rte_mbuf *mbuf,
617 struct dpaa_if *dpaa_intf)
619 struct rte_mbuf *dpaa_mbuf;
621 /* allocate pktbuffer on bpid for dpaa port */
622 dpaa_mbuf = dpaa_get_pktbuf(dpaa_intf->bp_info);
626 memcpy((uint8_t *)(dpaa_mbuf->buf_addr) + RTE_PKTMBUF_HEADROOM, (void *)
627 ((uint8_t *)(mbuf->buf_addr) + mbuf->data_off), mbuf->pkt_len);
629 /* Copy only the required fields */
630 dpaa_mbuf->data_off = RTE_PKTMBUF_HEADROOM;
631 dpaa_mbuf->pkt_len = mbuf->pkt_len;
632 dpaa_mbuf->ol_flags = mbuf->ol_flags;
633 dpaa_mbuf->packet_type = mbuf->packet_type;
634 dpaa_mbuf->tx_offload = mbuf->tx_offload;
635 rte_pktmbuf_free(mbuf);
640 dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf,
644 struct rte_mbuf *cur_seg = mbuf, *prev_seg = NULL;
645 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(bpid);
646 struct rte_mbuf *temp, *mi;
647 struct qm_sg_entry *sg_temp, *sgt;
650 DPAA_DP_LOG(DEBUG, "Creating SG FD to transmit");
652 temp = rte_pktmbuf_alloc(bp_info->mp);
654 DPAA_PMD_ERR("Failure in allocation of mbuf");
657 if (temp->buf_len < ((mbuf->nb_segs * sizeof(struct qm_sg_entry))
659 DPAA_PMD_ERR("Insufficient space in mbuf for SG entries");
666 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK) {
667 if (!mbuf->packet_type) {
668 struct rte_net_hdr_lens hdr_lens;
670 mbuf->packet_type = rte_net_get_ptype(mbuf, &hdr_lens,
671 RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK
672 | RTE_PTYPE_L4_MASK);
673 mbuf->l2_len = hdr_lens.l2_len;
674 mbuf->l3_len = hdr_lens.l3_len;
676 if (temp->data_off < DEFAULT_TX_ICEOF
677 + sizeof(struct dpaa_eth_parse_results_t))
678 temp->data_off = DEFAULT_TX_ICEOF
679 + sizeof(struct dpaa_eth_parse_results_t);
680 dcbz_64(temp->buf_addr);
681 dpaa_checksum_offload(mbuf, fd, temp->buf_addr);
684 sgt = temp->buf_addr + temp->data_off;
685 fd->format = QM_FD_SG;
686 fd->addr = temp->buf_iova;
687 fd->offset = temp->data_off;
689 fd->length20 = mbuf->pkt_len;
691 while (i < DPAA_SGT_MAX_ENTRIES) {
695 sg_temp->addr = cur_seg->buf_iova;
696 sg_temp->offset = cur_seg->data_off;
697 sg_temp->length = cur_seg->data_len;
698 if (RTE_MBUF_DIRECT(cur_seg)) {
699 if (rte_mbuf_refcnt_read(cur_seg) > 1) {
700 /*If refcnt > 1, invalid bpid is set to ensure
701 * buffer is not freed by HW.
703 sg_temp->bpid = 0xff;
704 rte_mbuf_refcnt_update(cur_seg, -1);
707 DPAA_MEMPOOL_TO_BPID(cur_seg->pool);
709 cur_seg = cur_seg->next;
711 /* Get owner MBUF from indirect buffer */
712 mi = rte_mbuf_from_indirect(cur_seg);
713 if (rte_mbuf_refcnt_read(mi) > 1) {
714 /*If refcnt > 1, invalid bpid is set to ensure
715 * owner buffer is not freed by HW.
717 sg_temp->bpid = 0xff;
719 sg_temp->bpid = DPAA_MEMPOOL_TO_BPID(mi->pool);
720 rte_mbuf_refcnt_update(mi, 1);
723 cur_seg = cur_seg->next;
724 prev_seg->next = NULL;
725 rte_pktmbuf_free(prev_seg);
727 if (cur_seg == NULL) {
729 cpu_to_hw_sg(sg_temp);
732 cpu_to_hw_sg(sg_temp);
737 /* Handle mbufs which are not segmented (non SG) */
739 tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf,
740 struct dpaa_bp_info *bp_info,
741 struct qm_fd *fd_arr)
743 struct rte_mbuf *mi = NULL;
745 if (RTE_MBUF_DIRECT(mbuf)) {
746 if (rte_mbuf_refcnt_read(mbuf) > 1) {
747 /* In case of direct mbuf and mbuf being cloned,
748 * BMAN should _not_ release buffer.
750 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
751 /* Buffer should be releasd by EAL */
752 rte_mbuf_refcnt_update(mbuf, -1);
754 /* In case of direct mbuf and no cloning, mbuf can be
757 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
760 /* This is data-containing core mbuf: 'mi' */
761 mi = rte_mbuf_from_indirect(mbuf);
762 if (rte_mbuf_refcnt_read(mi) > 1) {
763 /* In case of indirect mbuf, and mbuf being cloned,
764 * BMAN should _not_ release it and let EAL release
765 * it through pktmbuf_free below.
767 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
769 /* In case of indirect mbuf, and no cloning, core mbuf
770 * should be released by BMAN.
771 * Increate refcnt of core mbuf so that when
772 * pktmbuf_free is called and mbuf is released, EAL
773 * doesn't try to release core mbuf which would have
774 * been released by BMAN.
776 rte_mbuf_refcnt_update(mi, 1);
777 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
779 rte_pktmbuf_free(mbuf);
782 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK)
783 dpaa_unsegmented_checksum(mbuf, fd_arr);
786 /* Handle all mbufs on dpaa BMAN managed pool */
787 static inline uint16_t
788 tx_on_dpaa_pool(struct rte_mbuf *mbuf,
789 struct dpaa_bp_info *bp_info,
790 struct qm_fd *fd_arr)
792 DPAA_DP_LOG(DEBUG, "BMAN offloaded buffer, mbuf: %p", mbuf);
794 if (mbuf->nb_segs == 1) {
795 /* Case for non-segmented buffers */
796 tx_on_dpaa_pool_unsegmented(mbuf, bp_info, fd_arr);
797 } else if (mbuf->nb_segs > 1 &&
798 mbuf->nb_segs <= DPAA_SGT_MAX_ENTRIES) {
799 if (dpaa_eth_mbuf_to_sg_fd(mbuf, fd_arr, bp_info->bpid)) {
800 DPAA_PMD_DEBUG("Unable to create Scatter Gather FD");
804 DPAA_PMD_DEBUG("Number of Segments not supported");
811 /* Handle all mbufs on an external pool (non-dpaa) */
812 static inline uint16_t
813 tx_on_external_pool(struct qman_fq *txq, struct rte_mbuf *mbuf,
814 struct qm_fd *fd_arr)
816 struct dpaa_if *dpaa_intf = txq->dpaa_intf;
817 struct rte_mbuf *dmable_mbuf;
819 DPAA_DP_LOG(DEBUG, "Non-BMAN offloaded buffer."
820 "Allocating an offloaded buffer");
821 dmable_mbuf = dpaa_get_dmable_mbuf(mbuf, dpaa_intf);
823 DPAA_DP_LOG(DEBUG, "no dpaa buffers.");
827 DPAA_MBUF_TO_CONTIG_FD(dmable_mbuf, fd_arr, dpaa_intf->bp_info->bpid);
828 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK)
829 dpaa_unsegmented_checksum(mbuf, fd_arr);
835 dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
837 struct rte_mbuf *mbuf, *mi = NULL;
838 struct rte_mempool *mp;
839 struct dpaa_bp_info *bp_info;
840 struct qm_fd fd_arr[DPAA_TX_BURST_SIZE];
841 uint32_t frames_to_send, loop, sent = 0;
844 uint32_t seqn, index, flags[DPAA_TX_BURST_SIZE] = {0};
846 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
847 ret = rte_dpaa_portal_init((void *)0);
849 DPAA_PMD_ERR("Failure in affining portal");
854 DPAA_DP_LOG(DEBUG, "Transmitting %d buffers on queue: %p", nb_bufs, q);
857 frames_to_send = (nb_bufs > DPAA_TX_BURST_SIZE) ?
858 DPAA_TX_BURST_SIZE : nb_bufs;
859 for (loop = 0; loop < frames_to_send; loop++) {
861 if (likely(RTE_MBUF_DIRECT(mbuf))) {
863 bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
864 if (likely(mp->ops_index ==
865 bp_info->dpaa_ops_index &&
866 mbuf->nb_segs == 1 &&
867 rte_mbuf_refcnt_read(mbuf) == 1)) {
868 DPAA_MBUF_TO_CONTIG_FD(mbuf,
869 &fd_arr[loop], bp_info->bpid);
871 DPAA_TX_CKSUM_OFFLOAD_MASK)
872 dpaa_unsegmented_checksum(mbuf,
877 mi = rte_mbuf_from_indirect(mbuf);
881 bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
882 if (likely(mp->ops_index == bp_info->dpaa_ops_index)) {
883 state = tx_on_dpaa_pool(mbuf, bp_info,
885 if (unlikely(state)) {
886 /* Set frames_to_send & nb_bufs so
887 * that packets are transmitted till
890 frames_to_send = loop;
895 state = tx_on_external_pool(q, mbuf,
897 if (unlikely(state)) {
898 /* Set frames_to_send & nb_bufs so
899 * that packets are transmitted till
902 frames_to_send = loop;
908 if (seqn != DPAA_INVALID_MBUF_SEQN) {
910 if (DPAA_PER_LCORE_DQRR_HELD & (1 << index)) {
912 ((index & QM_EQCR_DCA_IDXMASK) << 8);
913 flags[loop] |= QMAN_ENQUEUE_FLAG_DCA;
914 DPAA_PER_LCORE_DQRR_SIZE--;
915 DPAA_PER_LCORE_DQRR_HELD &=
923 while (loop < frames_to_send) {
924 loop += qman_enqueue_multi(q, &fd_arr[loop],
926 frames_to_send - loop);
928 nb_bufs -= frames_to_send;
929 sent += frames_to_send;
932 DPAA_DP_LOG(DEBUG, "Transmitted %d buffers on queue: %p", sent, q);
937 uint16_t dpaa_eth_tx_drop_all(void *q __rte_unused,
938 struct rte_mbuf **bufs __rte_unused,
939 uint16_t nb_bufs __rte_unused)
941 DPAA_DP_LOG(DEBUG, "Drop all packets");
943 /* Drop all incoming packets. No need to free packets here
944 * because the rte_eth f/w frees up the packets through tx_buffer
945 * callback in case this functions returns count less than nb_bufs