4 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <rte_byteorder.h>
43 #include <rte_common.h>
44 #include <rte_interrupts.h>
46 #include <rte_debug.h>
48 #include <rte_atomic.h>
49 #include <rte_branch_prediction.h>
50 #include <rte_memory.h>
51 #include <rte_memzone.h>
52 #include <rte_tailq.h>
54 #include <rte_alarm.h>
55 #include <rte_ether.h>
56 #include <rte_ethdev.h>
57 #include <rte_malloc.h>
63 #include "dpaa_ethdev.h"
64 #include "dpaa_rxtx.h"
65 #include <rte_dpaa_bus.h>
66 #include <dpaa_mempool.h>
74 #define DPAA_MBUF_TO_CONTIG_FD(_mbuf, _fd, _bpid) \
77 (_fd)->opaque_addr = 0; \
78 (_fd)->opaque = QM_FD_CONTIG << DPAA_FD_FORMAT_SHIFT; \
79 (_fd)->opaque |= ((_mbuf)->data_off) << DPAA_FD_OFFSET_SHIFT; \
80 (_fd)->opaque |= (_mbuf)->pkt_len; \
81 (_fd)->addr = (_mbuf)->buf_physaddr; \
82 (_fd)->bpid = _bpid; \
85 #if (defined RTE_LIBRTE_DPAA_DEBUG_DRIVER)
86 void dpaa_display_frame(const struct qm_fd *fd)
91 printf("%s::bpid %x addr %08x%08x, format %d off %d, len %d stat %x\n",
92 __func__, fd->bpid, fd->addr_hi, fd->addr_lo, fd->format,
93 fd->offset, fd->length20, fd->status);
95 ptr = (char *)rte_dpaa_mem_ptov(fd->addr);
97 printf("%02x ", *ptr);
98 for (ii = 1; ii < fd->length20; ii++) {
99 printf("%02x ", *ptr);
107 #define dpaa_display_frame(a)
110 static inline void dpaa_slow_parsing(struct rte_mbuf *m __rte_unused,
111 uint64_t prs __rte_unused)
113 DPAA_DP_LOG(DEBUG, "Slow parsing");
114 /*TBD:XXX: to be implemented*/
117 static inline void dpaa_eth_packet_info(struct rte_mbuf *m,
118 uint64_t fd_virt_addr)
120 struct annotations_t *annot = GET_ANNOTATIONS(fd_virt_addr);
121 uint64_t prs = *((uint64_t *)(&annot->parse)) & DPAA_PARSE_MASK;
123 DPAA_DP_LOG(DEBUG, " Parsing mbuf: %p with annotations: %p", m, annot);
126 case DPAA_PKT_TYPE_NONE:
129 case DPAA_PKT_TYPE_ETHER:
130 m->packet_type = RTE_PTYPE_L2_ETHER;
132 case DPAA_PKT_TYPE_IPV4:
133 m->packet_type = RTE_PTYPE_L2_ETHER |
136 case DPAA_PKT_TYPE_IPV6:
137 m->packet_type = RTE_PTYPE_L2_ETHER |
140 case DPAA_PKT_TYPE_IPV4_FRAG:
141 case DPAA_PKT_TYPE_IPV4_FRAG_UDP:
142 case DPAA_PKT_TYPE_IPV4_FRAG_TCP:
143 case DPAA_PKT_TYPE_IPV4_FRAG_SCTP:
144 m->packet_type = RTE_PTYPE_L2_ETHER |
145 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_FRAG;
147 case DPAA_PKT_TYPE_IPV6_FRAG:
148 case DPAA_PKT_TYPE_IPV6_FRAG_UDP:
149 case DPAA_PKT_TYPE_IPV6_FRAG_TCP:
150 case DPAA_PKT_TYPE_IPV6_FRAG_SCTP:
151 m->packet_type = RTE_PTYPE_L2_ETHER |
152 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_FRAG;
154 case DPAA_PKT_TYPE_IPV4_EXT:
155 m->packet_type = RTE_PTYPE_L2_ETHER |
156 RTE_PTYPE_L3_IPV4_EXT;
158 case DPAA_PKT_TYPE_IPV6_EXT:
159 m->packet_type = RTE_PTYPE_L2_ETHER |
160 RTE_PTYPE_L3_IPV6_EXT;
162 case DPAA_PKT_TYPE_IPV4_TCP:
163 m->packet_type = RTE_PTYPE_L2_ETHER |
164 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP;
166 case DPAA_PKT_TYPE_IPV6_TCP:
167 m->packet_type = RTE_PTYPE_L2_ETHER |
168 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP;
170 case DPAA_PKT_TYPE_IPV4_UDP:
171 m->packet_type = RTE_PTYPE_L2_ETHER |
172 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP;
174 case DPAA_PKT_TYPE_IPV6_UDP:
175 m->packet_type = RTE_PTYPE_L2_ETHER |
176 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP;
178 case DPAA_PKT_TYPE_IPV4_EXT_UDP:
179 m->packet_type = RTE_PTYPE_L2_ETHER |
180 RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_UDP;
182 case DPAA_PKT_TYPE_IPV6_EXT_UDP:
183 m->packet_type = RTE_PTYPE_L2_ETHER |
184 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP;
186 case DPAA_PKT_TYPE_IPV4_EXT_TCP:
187 m->packet_type = RTE_PTYPE_L2_ETHER |
188 RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_TCP;
190 case DPAA_PKT_TYPE_IPV6_EXT_TCP:
191 m->packet_type = RTE_PTYPE_L2_ETHER |
192 RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP;
194 case DPAA_PKT_TYPE_IPV4_SCTP:
195 m->packet_type = RTE_PTYPE_L2_ETHER |
196 RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP;
198 case DPAA_PKT_TYPE_IPV6_SCTP:
199 m->packet_type = RTE_PTYPE_L2_ETHER |
200 RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_SCTP;
202 /* More switch cases can be added */
204 dpaa_slow_parsing(m, prs);
207 m->tx_offload = annot->parse.ip_off[0];
208 m->tx_offload |= (annot->parse.l4_off - annot->parse.ip_off[0])
209 << DPAA_PKT_L3_LEN_SHIFT;
211 /* Set the hash values */
212 m->hash.rss = (uint32_t)(rte_be_to_cpu_64(annot->hash));
213 m->ol_flags = PKT_RX_RSS_HASH;
214 /* All packets with Bad checksum are dropped by interface (and
215 * corresponding notification issued to RX error queues).
217 m->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
219 /* Check if Vlan is present */
220 if (prs & DPAA_PARSE_VLAN_MASK)
221 m->ol_flags |= PKT_RX_VLAN;
222 /* Packet received without stripping the vlan */
225 static inline void dpaa_checksum(struct rte_mbuf *mbuf)
227 struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
228 char *l3_hdr = (char *)eth_hdr + mbuf->l2_len;
229 struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
230 struct ipv6_hdr *ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
232 DPAA_DP_LOG(DEBUG, "Calculating checksum for mbuf: %p", mbuf);
234 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
235 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
236 RTE_PTYPE_L3_IPV4_EXT)) {
237 ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
238 ipv4_hdr->hdr_checksum = 0;
239 ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
240 } else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
241 RTE_PTYPE_L3_IPV6) ||
242 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
243 RTE_PTYPE_L3_IPV6_EXT))
244 ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
246 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP) {
247 struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(l3_hdr +
250 if (eth_hdr->ether_type == htons(ETHER_TYPE_IPv4))
251 tcp_hdr->cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
253 else /* assume ethertype == ETHER_TYPE_IPv6 */
254 tcp_hdr->cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
256 } else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) ==
258 struct udp_hdr *udp_hdr = (struct udp_hdr *)(l3_hdr +
260 udp_hdr->dgram_cksum = 0;
261 if (eth_hdr->ether_type == htons(ETHER_TYPE_IPv4))
262 udp_hdr->dgram_cksum = rte_ipv4_udptcp_cksum(ipv4_hdr,
264 else /* assume ethertype == ETHER_TYPE_IPv6 */
265 udp_hdr->dgram_cksum = rte_ipv6_udptcp_cksum(ipv6_hdr,
270 static inline void dpaa_checksum_offload(struct rte_mbuf *mbuf,
271 struct qm_fd *fd, char *prs_buf)
273 struct dpaa_eth_parse_results_t *prs;
275 DPAA_DP_LOG(DEBUG, " Offloading checksum for mbuf: %p", mbuf);
277 prs = GET_TX_PRS(prs_buf);
280 if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) == RTE_PTYPE_L3_IPV4) ||
281 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
282 RTE_PTYPE_L3_IPV4_EXT))
283 prs->l3r = DPAA_L3_PARSE_RESULT_IPV4;
284 else if (((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
285 RTE_PTYPE_L3_IPV6) ||
286 ((mbuf->packet_type & RTE_PTYPE_L3_MASK) ==
287 RTE_PTYPE_L3_IPV6_EXT))
288 prs->l3r = DPAA_L3_PARSE_RESULT_IPV6;
290 if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP)
291 prs->l4r = DPAA_L4_PARSE_RESULT_TCP;
292 else if ((mbuf->packet_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_UDP)
293 prs->l4r = DPAA_L4_PARSE_RESULT_UDP;
295 prs->ip_off[0] = mbuf->l2_len;
296 prs->l4_off = mbuf->l3_len + mbuf->l2_len;
297 /* Enable L3 (and L4, if TCP or UDP) HW checksum*/
298 fd->cmd = DPAA_FD_CMD_RPD | DPAA_FD_CMD_DTC;
302 dpaa_eth_sg_to_mbuf(struct qm_fd *fd, uint32_t ifid)
304 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
305 struct rte_mbuf *first_seg, *prev_seg, *cur_seg, *temp;
306 struct qm_sg_entry *sgt, *sg_temp;
307 void *vaddr, *sg_vaddr;
309 uint8_t fd_offset = fd->offset;
311 DPAA_DP_LOG(DEBUG, "Received an SG frame");
313 vaddr = rte_dpaa_mem_ptov(qm_fd_addr(fd));
315 DPAA_PMD_ERR("unable to convert physical address");
318 sgt = vaddr + fd_offset;
320 hw_sg_to_cpu(sg_temp);
321 temp = (struct rte_mbuf *)((char *)vaddr - bp_info->meta_data_size);
322 sg_vaddr = rte_dpaa_mem_ptov(qm_sg_entry_get64(sg_temp));
324 first_seg = (struct rte_mbuf *)((char *)sg_vaddr -
325 bp_info->meta_data_size);
326 first_seg->data_off = sg_temp->offset;
327 first_seg->data_len = sg_temp->length;
328 first_seg->pkt_len = sg_temp->length;
329 rte_mbuf_refcnt_set(first_seg, 1);
331 first_seg->port = ifid;
332 first_seg->nb_segs = 1;
333 first_seg->ol_flags = 0;
334 prev_seg = first_seg;
335 while (i < DPAA_SGT_MAX_ENTRIES) {
337 hw_sg_to_cpu(sg_temp);
338 sg_vaddr = rte_dpaa_mem_ptov(qm_sg_entry_get64(sg_temp));
339 cur_seg = (struct rte_mbuf *)((char *)sg_vaddr -
340 bp_info->meta_data_size);
341 cur_seg->data_off = sg_temp->offset;
342 cur_seg->data_len = sg_temp->length;
343 first_seg->pkt_len += sg_temp->length;
344 first_seg->nb_segs += 1;
345 rte_mbuf_refcnt_set(cur_seg, 1);
346 prev_seg->next = cur_seg;
347 if (sg_temp->final) {
348 cur_seg->next = NULL;
354 dpaa_eth_packet_info(first_seg, (uint64_t)vaddr);
355 rte_pktmbuf_free_seg(temp);
360 static inline struct rte_mbuf *dpaa_eth_fd_to_mbuf(struct qm_fd *fd,
363 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid);
364 struct rte_mbuf *mbuf;
367 (fd->opaque & DPAA_FD_FORMAT_MASK) >> DPAA_FD_FORMAT_SHIFT;
369 (fd->opaque & DPAA_FD_OFFSET_MASK) >> DPAA_FD_OFFSET_SHIFT;
370 uint32_t length = fd->opaque & DPAA_FD_LENGTH_MASK;
372 DPAA_DP_LOG(DEBUG, " FD--->MBUF");
374 if (unlikely(format == qm_fd_sg))
375 return dpaa_eth_sg_to_mbuf(fd, ifid);
377 /* Ignoring case when format != qm_fd_contig */
378 dpaa_display_frame(fd);
379 ptr = rte_dpaa_mem_ptov(fd->addr);
380 /* Ignoring case when ptr would be NULL. That is only possible incase
381 * of a corrupted packet
384 mbuf = (struct rte_mbuf *)((char *)ptr - bp_info->meta_data_size);
385 /* Prefetch the Parse results and packet data to L1 */
386 rte_prefetch0((void *)((uint8_t *)ptr + DEFAULT_RX_ICEOF));
387 rte_prefetch0((void *)((uint8_t *)ptr + offset));
389 mbuf->data_off = offset;
390 mbuf->data_len = length;
391 mbuf->pkt_len = length;
397 rte_mbuf_refcnt_set(mbuf, 1);
398 dpaa_eth_packet_info(mbuf, (uint64_t)mbuf->buf_addr);
403 uint16_t dpaa_eth_queue_rx(void *q,
404 struct rte_mbuf **bufs,
407 struct qman_fq *fq = q;
408 struct qm_dqrr_entry *dq;
409 uint32_t num_rx = 0, ifid = ((struct dpaa_if *)fq->dpaa_intf)->ifid;
412 ret = rte_dpaa_portal_init((void *)0);
414 DPAA_PMD_ERR("Failure in affining portal");
418 ret = qman_set_vdq(fq, (nb_bufs > DPAA_MAX_DEQUEUE_NUM_FRAMES) ?
419 DPAA_MAX_DEQUEUE_NUM_FRAMES : nb_bufs);
424 dq = qman_dequeue(fq);
427 bufs[num_rx++] = dpaa_eth_fd_to_mbuf(&dq->fd, ifid);
428 qman_dqrr_consume(fq, dq);
429 } while (fq->flags & QMAN_FQ_STATE_VDQCR);
434 static void *dpaa_get_pktbuf(struct dpaa_bp_info *bp_info)
438 struct bm_buffer bufs;
440 ret = bman_acquire(bp_info->bp, &bufs, 1, 0);
442 DPAA_PMD_WARN("Failed to allocate buffers %d", ret);
446 DPAA_DP_LOG(DEBUG, "got buffer 0x%lx from pool %d",
447 (uint64_t)bufs.addr, bufs.bpid);
449 buf = (uint64_t)rte_dpaa_mem_ptov(bufs.addr) - bp_info->meta_data_size;
457 static struct rte_mbuf *dpaa_get_dmable_mbuf(struct rte_mbuf *mbuf,
458 struct dpaa_if *dpaa_intf)
460 struct rte_mbuf *dpaa_mbuf;
462 /* allocate pktbuffer on bpid for dpaa port */
463 dpaa_mbuf = dpaa_get_pktbuf(dpaa_intf->bp_info);
467 memcpy((uint8_t *)(dpaa_mbuf->buf_addr) + mbuf->data_off, (void *)
468 ((uint8_t *)(mbuf->buf_addr) + mbuf->data_off), mbuf->pkt_len);
470 /* Copy only the required fields */
471 dpaa_mbuf->data_off = mbuf->data_off;
472 dpaa_mbuf->pkt_len = mbuf->pkt_len;
473 dpaa_mbuf->ol_flags = mbuf->ol_flags;
474 dpaa_mbuf->packet_type = mbuf->packet_type;
475 dpaa_mbuf->tx_offload = mbuf->tx_offload;
476 rte_pktmbuf_free(mbuf);
481 dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf,
485 struct rte_mbuf *cur_seg = mbuf, *prev_seg = NULL;
486 struct dpaa_bp_info *bp_info = DPAA_BPID_TO_POOL_INFO(bpid);
487 struct rte_mbuf *temp, *mi;
488 struct qm_sg_entry *sg_temp, *sgt;
491 DPAA_DP_LOG(DEBUG, "Creating SG FD to transmit");
493 temp = rte_pktmbuf_alloc(bp_info->mp);
495 DPAA_PMD_ERR("Failure in allocation of mbuf");
498 if (temp->buf_len < ((mbuf->nb_segs * sizeof(struct qm_sg_entry))
500 DPAA_PMD_ERR("Insufficient space in mbuf for SG entries");
507 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK) {
508 if (temp->data_off < DEFAULT_TX_ICEOF
509 + sizeof(struct dpaa_eth_parse_results_t))
510 temp->data_off = DEFAULT_TX_ICEOF
511 + sizeof(struct dpaa_eth_parse_results_t);
512 dcbz_64(temp->buf_addr);
513 dpaa_checksum_offload(mbuf, fd, temp->buf_addr);
516 sgt = temp->buf_addr + temp->data_off;
517 fd->format = QM_FD_SG;
518 fd->addr = temp->buf_physaddr;
519 fd->offset = temp->data_off;
521 fd->length20 = mbuf->pkt_len;
523 while (i < DPAA_SGT_MAX_ENTRIES) {
527 sg_temp->addr = cur_seg->buf_physaddr;
528 sg_temp->offset = cur_seg->data_off;
529 sg_temp->length = cur_seg->data_len;
530 if (RTE_MBUF_DIRECT(cur_seg)) {
531 if (rte_mbuf_refcnt_read(cur_seg) > 1) {
532 /*If refcnt > 1, invalid bpid is set to ensure
533 * buffer is not freed by HW.
535 sg_temp->bpid = 0xff;
536 rte_mbuf_refcnt_update(cur_seg, -1);
539 DPAA_MEMPOOL_TO_BPID(cur_seg->pool);
541 cur_seg = cur_seg->next;
543 /* Get owner MBUF from indirect buffer */
544 mi = rte_mbuf_from_indirect(cur_seg);
545 if (rte_mbuf_refcnt_read(mi) > 1) {
546 /*If refcnt > 1, invalid bpid is set to ensure
547 * owner buffer is not freed by HW.
549 sg_temp->bpid = 0xff;
551 sg_temp->bpid = DPAA_MEMPOOL_TO_BPID(mi->pool);
552 rte_mbuf_refcnt_update(mi, 1);
555 cur_seg = cur_seg->next;
556 prev_seg->next = NULL;
557 rte_pktmbuf_free(prev_seg);
559 if (cur_seg == NULL) {
561 cpu_to_hw_sg(sg_temp);
564 cpu_to_hw_sg(sg_temp);
569 /* Handle mbufs which are not segmented (non SG) */
571 tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf,
572 struct dpaa_bp_info *bp_info,
573 struct qm_fd *fd_arr)
575 struct rte_mbuf *mi = NULL;
577 if (RTE_MBUF_DIRECT(mbuf)) {
578 if (rte_mbuf_refcnt_read(mbuf) > 1) {
579 /* In case of direct mbuf and mbuf being cloned,
580 * BMAN should _not_ release buffer.
582 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
583 /* Buffer should be releasd by EAL */
584 rte_mbuf_refcnt_update(mbuf, -1);
586 /* In case of direct mbuf and no cloning, mbuf can be
589 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
592 /* This is data-containing core mbuf: 'mi' */
593 mi = rte_mbuf_from_indirect(mbuf);
594 if (rte_mbuf_refcnt_read(mi) > 1) {
595 /* In case of indirect mbuf, and mbuf being cloned,
596 * BMAN should _not_ release it and let EAL release
597 * it through pktmbuf_free below.
599 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, 0xff);
601 /* In case of indirect mbuf, and no cloning, core mbuf
602 * should be released by BMAN.
603 * Increate refcnt of core mbuf so that when
604 * pktmbuf_free is called and mbuf is released, EAL
605 * doesn't try to release core mbuf which would have
606 * been released by BMAN.
608 rte_mbuf_refcnt_update(mi, 1);
609 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid);
611 rte_pktmbuf_free(mbuf);
614 if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK) {
615 if (mbuf->data_off < (DEFAULT_TX_ICEOF +
616 sizeof(struct dpaa_eth_parse_results_t))) {
617 DPAA_DP_LOG(DEBUG, "Checksum offload Err: "
618 "Not enough Headroom "
619 "space for correct Checksum offload."
620 "So Calculating checksum in Software.");
623 dpaa_checksum_offload(mbuf, fd_arr, mbuf->buf_addr);
628 /* Handle all mbufs on dpaa BMAN managed pool */
629 static inline uint16_t
630 tx_on_dpaa_pool(struct rte_mbuf *mbuf,
631 struct dpaa_bp_info *bp_info,
632 struct qm_fd *fd_arr)
634 DPAA_DP_LOG(DEBUG, "BMAN offloaded buffer, mbuf: %p", mbuf);
636 if (mbuf->nb_segs == 1) {
637 /* Case for non-segmented buffers */
638 tx_on_dpaa_pool_unsegmented(mbuf, bp_info, fd_arr);
639 } else if (mbuf->nb_segs > 1 &&
640 mbuf->nb_segs <= DPAA_SGT_MAX_ENTRIES) {
641 if (dpaa_eth_mbuf_to_sg_fd(mbuf, fd_arr, bp_info->bpid)) {
642 DPAA_PMD_DEBUG("Unable to create Scatter Gather FD");
646 DPAA_PMD_DEBUG("Number of Segments not supported");
653 /* Handle all mbufs on an external pool (non-dpaa) */
654 static inline uint16_t
655 tx_on_external_pool(struct qman_fq *txq, struct rte_mbuf *mbuf,
656 struct qm_fd *fd_arr)
658 struct dpaa_if *dpaa_intf = txq->dpaa_intf;
659 struct rte_mbuf *dmable_mbuf;
661 DPAA_DP_LOG(DEBUG, "Non-BMAN offloaded buffer."
662 "Allocating an offloaded buffer");
663 dmable_mbuf = dpaa_get_dmable_mbuf(mbuf, dpaa_intf);
665 DPAA_DP_LOG(DEBUG, "no dpaa buffers.");
669 DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, dpaa_intf->bp_info->bpid);
675 dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
677 struct rte_mbuf *mbuf, *mi = NULL;
678 struct rte_mempool *mp;
679 struct dpaa_bp_info *bp_info;
680 struct qm_fd fd_arr[MAX_TX_RING_SLOTS];
681 uint32_t frames_to_send, loop, i = 0;
685 ret = rte_dpaa_portal_init((void *)0);
687 DPAA_PMD_ERR("Failure in affining portal");
691 DPAA_DP_LOG(DEBUG, "Transmitting %d buffers on queue: %p", nb_bufs, q);
694 frames_to_send = (nb_bufs >> 3) ? MAX_TX_RING_SLOTS : nb_bufs;
695 for (loop = 0; loop < frames_to_send; loop++, i++) {
697 if (RTE_MBUF_DIRECT(mbuf)) {
700 mi = rte_mbuf_from_indirect(mbuf);
704 bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
705 if (likely(mp->ops_index == bp_info->dpaa_ops_index)) {
706 state = tx_on_dpaa_pool(mbuf, bp_info,
708 if (unlikely(state)) {
709 /* Set frames_to_send & nb_bufs so
710 * that packets are transmitted till
713 frames_to_send = loop;
718 state = tx_on_external_pool(q, mbuf,
720 if (unlikely(state)) {
721 /* Set frames_to_send & nb_bufs so
722 * that packets are transmitted till
725 frames_to_send = loop;
734 while (loop < frames_to_send) {
735 loop += qman_enqueue_multi(q, &fd_arr[loop],
736 frames_to_send - loop);
738 nb_bufs -= frames_to_send;
741 DPAA_DP_LOG(DEBUG, "Transmitted %d buffers on queue: %p", i, q);
746 uint16_t dpaa_eth_tx_drop_all(void *q __rte_unused,
747 struct rte_mbuf **bufs __rte_unused,
748 uint16_t nb_bufs __rte_unused)
750 DPAA_DP_LOG(DEBUG, "Drop all packets");
752 /* Drop all incoming packets. No need to free packets here
753 * because the rte_eth f/w frees up the packets through tx_buffer
754 * callback in case this functions returns count less than nb_bufs