New upstream version 18.02
[deb_dpdk.git] / drivers / net / enic / enic_rxtx.c
index a3663d5..2fe5a3f 100644 (file)
@@ -1,37 +1,11 @@
-/* Copyright 2008-2016 Cisco Systems, Inc.  All rights reserved.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
- *
- * Copyright (c) 2014, Cisco Systems, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include <rte_mbuf.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
+#include <rte_net.h>
 #include <rte_prefetch.h>
 
 #include "enic_compat.h"
 #include <rte_ip.h>
 #include <rte_tcp.h>
 
+#define        ENIC_TX_OFFLOAD_MASK (                   \
+               PKT_TX_VLAN_PKT |                \
+               PKT_TX_IP_CKSUM |                \
+               PKT_TX_L4_MASK |                 \
+               PKT_TX_TCP_SEG)
+
+#define        ENIC_TX_OFFLOAD_NOTSUP_MASK \
+       (PKT_TX_OFFLOAD_MASK ^ ENIC_TX_OFFLOAD_MASK)
+
 #define RTE_PMD_USE_PREFETCH
 
 #ifdef RTE_PMD_USE_PREFETCH
@@ -132,59 +115,6 @@ enic_cq_rx_desc_n_bytes(struct cq_desc *cqd)
                CQ_ENET_RQ_DESC_BYTES_WRITTEN_MASK;
 }
 
-/* Find the offset to L5. This is needed by enic TSO implementation.
- * Return 0 if not a TCP packet or can't figure out the length.
- */
-static inline uint8_t tso_header_len(struct rte_mbuf *mbuf)
-{
-       struct ether_hdr *eh;
-       struct vlan_hdr *vh;
-       struct ipv4_hdr *ip4;
-       struct ipv6_hdr *ip6;
-       struct tcp_hdr *th;
-       uint8_t hdr_len;
-       uint16_t ether_type;
-
-       /* offset past Ethernet header */
-       eh = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
-       ether_type = eh->ether_type;
-       hdr_len = sizeof(struct ether_hdr);
-       if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_VLAN)) {
-               vh = rte_pktmbuf_mtod_offset(mbuf, struct vlan_hdr *, hdr_len);
-               ether_type = vh->eth_proto;
-               hdr_len += sizeof(struct vlan_hdr);
-       }
-
-       /* offset past IP header */
-       switch (rte_be_to_cpu_16(ether_type)) {
-       case ETHER_TYPE_IPv4:
-               ip4 = rte_pktmbuf_mtod_offset(mbuf, struct ipv4_hdr *, hdr_len);
-               if (ip4->next_proto_id != IPPROTO_TCP)
-                       return 0;
-               hdr_len += (ip4->version_ihl & 0xf) * 4;
-               break;
-       case ETHER_TYPE_IPv6:
-               ip6 = rte_pktmbuf_mtod_offset(mbuf, struct ipv6_hdr *, hdr_len);
-               if (ip6->proto != IPPROTO_TCP)
-                       return 0;
-               hdr_len += sizeof(struct ipv6_hdr);
-               break;
-       default:
-               return 0;
-       }
-
-       if ((hdr_len + sizeof(struct tcp_hdr)) > mbuf->pkt_len)
-               return 0;
-
-       /* offset past TCP header */
-       th = rte_pktmbuf_mtod_offset(mbuf, struct tcp_hdr *, hdr_len);
-       hdr_len += (th->data_off >> 4) * 4;
-
-       if (hdr_len > mbuf->pkt_len)
-               return 0;
-
-       return hdr_len;
-}
 
 static inline uint8_t
 enic_cq_rx_check_err(struct cq_desc *cqd)
@@ -230,17 +160,10 @@ static inline void
 enic_cq_rx_to_pkt_flags(struct cq_desc *cqd, struct rte_mbuf *mbuf)
 {
        struct cq_enet_rq_desc *cqrd = (struct cq_enet_rq_desc *)cqd;
-       uint16_t ciflags, bwflags, pkt_flags = 0, vlan_tci;
-       ciflags = enic_cq_rx_desc_ciflags(cqrd);
+       uint16_t bwflags, pkt_flags = 0, vlan_tci;
        bwflags = enic_cq_rx_desc_bwflags(cqrd);
        vlan_tci = enic_cq_rx_desc_vlan(cqrd);
 
-       mbuf->ol_flags = 0;
-
-       /* flags are meaningless if !EOP */
-       if (unlikely(!enic_cq_rx_desc_eop(ciflags)))
-               goto mbuf_flags_done;
-
        /* VLAN STRIPPED flag. The L2 packet type updated here also */
        if (bwflags & CQ_ENET_RQ_DESC_FLAGS_VLAN_STRIPPED) {
                pkt_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
@@ -272,20 +195,18 @@ enic_cq_rx_to_pkt_flags(struct cq_desc *cqd, struct rte_mbuf *mbuf)
        }
 
        /* checksum flags */
-       if (mbuf->packet_type & RTE_PTYPE_L3_IPV4) {
-               if (enic_cq_rx_desc_csum_not_calc(cqrd))
-                       pkt_flags |= (PKT_RX_IP_CKSUM_UNKNOWN &
-                                    PKT_RX_L4_CKSUM_UNKNOWN);
-               else {
+       if (mbuf->packet_type & (RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L3_IPV6)) {
+               if (!enic_cq_rx_desc_csum_not_calc(cqrd)) {
                        uint32_t l4_flags;
                        l4_flags = mbuf->packet_type & RTE_PTYPE_L4_MASK;
 
                        if (enic_cq_rx_desc_ipv4_csum_ok(cqrd))
                                pkt_flags |= PKT_RX_IP_CKSUM_GOOD;
-                       else
+                       else if (mbuf->packet_type & RTE_PTYPE_L3_IPV4)
                                pkt_flags |= PKT_RX_IP_CKSUM_BAD;
 
-                       if (l4_flags & (RTE_PTYPE_L4_UDP | RTE_PTYPE_L4_TCP)) {
+                       if (l4_flags == RTE_PTYPE_L4_UDP ||
+                           l4_flags == RTE_PTYPE_L4_TCP) {
                                if (enic_cq_rx_desc_tcp_udp_csum_ok(cqrd))
                                        pkt_flags |= PKT_RX_L4_CKSUM_GOOD;
                                else
@@ -294,7 +215,6 @@ enic_cq_rx_to_pkt_flags(struct cq_desc *cqd, struct rte_mbuf *mbuf)
                }
        }
 
- mbuf_flags_done:
        mbuf->ol_flags = pkt_flags;
 }
 
@@ -337,7 +257,6 @@ enic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 
        while (nb_rx < nb_pkts) {
                volatile struct rq_enet_desc *rqd_ptr;
-               dma_addr_t dma_addr;
                struct cq_desc cqd;
                uint8_t packet_error;
                uint16_t ciflags;
@@ -386,12 +305,13 @@ enic_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 
                /* Push descriptor for newly allocated mbuf */
                nmb->data_off = RTE_PKTMBUF_HEADROOM;
-               dma_addr = (dma_addr_t)(nmb->buf_iova +
-                                       RTE_PKTMBUF_HEADROOM);
-               rq_enet_desc_enc(rqd_ptr, dma_addr,
-                               (rq->is_sop ? RQ_ENET_TYPE_ONLY_SOP
-                               : RQ_ENET_TYPE_NOT_SOP),
-                               nmb->buf_len - RTE_PKTMBUF_HEADROOM);
+               /*
+                * Only the address needs to be refilled. length_type of the
+                * descriptor it set during initialization
+                * (enic_alloc_rx_queue_mbufs) and does not change.
+                */
+               rqd_ptr->address = rte_cpu_to_le_64(nmb->buf_iova +
+                                                   RTE_PKTMBUF_HEADROOM);
 
                /* Fill in the rest of the mbuf */
                seg_length = enic_cq_rx_desc_n_bytes(&cqd);
@@ -523,6 +443,38 @@ unsigned int enic_cleanup_wq(__rte_unused struct enic *enic, struct vnic_wq *wq)
        return 0;
 }
 
+uint16_t enic_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
+                       uint16_t nb_pkts)
+{
+       int32_t ret;
+       uint16_t i;
+       uint64_t ol_flags;
+       struct rte_mbuf *m;
+
+       for (i = 0; i != nb_pkts; i++) {
+               m = tx_pkts[i];
+               ol_flags = m->ol_flags;
+               if (ol_flags & ENIC_TX_OFFLOAD_NOTSUP_MASK) {
+                       rte_errno = -ENOTSUP;
+                       return i;
+               }
+#ifdef RTE_LIBRTE_ETHDEV_DEBUG
+               ret = rte_validate_tx_offload(m);
+               if (ret != 0) {
+                       rte_errno = ret;
+                       return i;
+               }
+#endif
+               ret = rte_net_intel_cksum_prepare(m);
+               if (ret != 0) {
+                       rte_errno = ret;
+                       return i;
+               }
+       }
+
+       return i;
+}
+
 uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
        uint16_t nb_pkts)
 {
@@ -580,8 +532,8 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                }
 
                mss = 0;
-               vlan_id = 0;
-               vlan_tag_insert = 0;
+               vlan_id = tx_pkt->vlan_tci;
+               vlan_tag_insert = !!(ol_flags & PKT_TX_VLAN_PKT);
                bus_addr = (dma_addr_t)
                           (tx_pkt->buf_iova + tx_pkt->data_off);
 
@@ -593,7 +545,8 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                header_len = 0;
 
                if (tso) {
-                       header_len = tso_header_len(tx_pkt);
+                       header_len = tx_pkt->l2_len + tx_pkt->l3_len +
+                                    tx_pkt->l4_len;
 
                        /* Drop if non-TCP packet or TSO seg size is too big */
                        if (unlikely(header_len == 0 || ((tx_pkt->tso_segsz +
@@ -620,10 +573,6 @@ uint16_t enic_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                        }
                }
 
-               if (ol_flags & PKT_TX_VLAN_PKT) {
-                       vlan_tag_insert = 1;
-                       vlan_id = tx_pkt->vlan_tci;
-               }
 
                wq_enet_desc_enc(&desc_tmp, bus_addr, data_len, mss, header_len,
                                 offload_mode, eop, eop, 0, vlan_tag_insert,