net/enic: heed the requested max Rx packet size
[dpdk.git] / drivers / net / enic / enic_main.c
index bf9b051..c3796c5 100644 (file)
@@ -1,35 +1,6 @@
-/*
- * Copyright 2008-2014 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 <stdio.h>
 #include <libgen.h>
 
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
 #include <rte_string_fns.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 
 #include "enic_compat.h"
 #include "enic.h"
@@ -97,11 +69,6 @@ enic_rxmbuf_queue_release(__rte_unused struct enic *enic, struct vnic_rq *rq)
        }
 }
 
-void enic_set_hdr_split_size(struct enic *enic, u16 split_hdr_size)
-{
-       vnic_set_hdr_split_size(enic->vdev, split_hdr_size);
-}
-
 static void enic_free_wq_buf(struct vnic_wq_buf *buf)
 {
        struct rte_mbuf *mbuf = (struct rte_mbuf *)buf->mb;
@@ -137,6 +104,7 @@ static void enic_clear_soft_stats(struct enic *enic)
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        rte_atomic64_clear(&soft_stats->rx_nombuf);
        rte_atomic64_clear(&soft_stats->rx_packet_errors);
+       rte_atomic64_clear(&soft_stats->tx_oversized);
 }
 
 static void enic_init_soft_stats(struct enic *enic)
@@ -144,6 +112,7 @@ static void enic_init_soft_stats(struct enic *enic)
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        rte_atomic64_init(&soft_stats->rx_nombuf);
        rte_atomic64_init(&soft_stats->rx_packet_errors);
+       rte_atomic64_init(&soft_stats->tx_oversized);
        enic_clear_soft_stats(enic);
 }
 
@@ -154,16 +123,17 @@ void enic_dev_stats_clear(struct enic *enic)
        enic_clear_soft_stats(enic);
 }
 
-void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
+int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
 {
        struct vnic_stats *stats;
        struct enic_soft_stats *soft_stats = &enic->soft_stats;
        int64_t rx_truncated;
        uint64_t rx_packet_errors;
+       int ret = vnic_dev_stats_dump(enic->vdev, &stats);
 
-       if (vnic_dev_stats_dump(enic->vdev, &stats)) {
+       if (ret) {
                dev_err(enic, "Error in getting stats\n");
-               return;
+               return ret;
        }
 
        /* The number of truncated packets can only be calculated by
@@ -183,42 +153,37 @@ void enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
        r_stats->obytes = stats->tx.tx_bytes_ok;
 
        r_stats->ierrors = stats->rx.rx_errors + stats->rx.rx_drop;
-       r_stats->oerrors = stats->tx.tx_errors;
+       r_stats->oerrors = stats->tx.tx_errors
+                          + rte_atomic64_read(&soft_stats->tx_oversized);
 
        r_stats->imissed = stats->rx.rx_no_bufs + rx_truncated;
 
        r_stats->rx_nombuf = rte_atomic64_read(&soft_stats->rx_nombuf);
+       return 0;
 }
 
-void enic_del_mac_address(struct enic *enic)
+void enic_del_mac_address(struct enic *enic, int mac_index)
 {
-       if (vnic_dev_del_addr(enic->vdev, enic->mac_addr))
+       struct rte_eth_dev *eth_dev = enic->rte_dev;
+       uint8_t *mac_addr = eth_dev->data->mac_addrs[mac_index].addr_bytes;
+
+       if (vnic_dev_del_addr(enic->vdev, mac_addr))
                dev_err(enic, "del mac addr failed\n");
 }
 
-void enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
+int enic_set_mac_address(struct enic *enic, uint8_t *mac_addr)
 {
        int err;
 
        if (!is_eth_addr_valid(mac_addr)) {
                dev_err(enic, "invalid mac address\n");
-               return;
-       }
-
-       err = vnic_dev_del_addr(enic->vdev, enic->mac_addr);
-       if (err) {
-               dev_err(enic, "del mac addr failed\n");
-               return;
+               return -EINVAL;
        }
 
-       ether_addr_copy((struct ether_addr *)mac_addr,
-               (struct ether_addr *)enic->mac_addr);
-
        err = vnic_dev_add_addr(enic->vdev, mac_addr);
-       if (err) {
+       if (err)
                dev_err(enic, "add mac addr failed\n");
-               return;
-       }
+       return err;
 }
 
 static void
@@ -228,7 +193,7 @@ enic_free_rq_buf(struct rte_mbuf **mbuf)
                return;
 
        rte_pktmbuf_free(*mbuf);
-       mbuf = NULL;
+       *mbuf = NULL;
 }
 
 void enic_init_vnic_resources(struct enic *enic)
@@ -284,7 +249,7 @@ void enic_init_vnic_resources(struct enic *enic)
                        0 /* cq_entry_enable */,
                        1 /* cq_message_enable */,
                        0 /* interrupt offset */,
-                       (u64)enic->wq[index].cqmsg_rz->phys_addr);
+                       (u64)enic->wq[index].cqmsg_rz->iova);
        }
 
        vnic_intr_init(&enic->intr,
@@ -301,6 +266,8 @@ enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
        struct rq_enet_desc *rqd = rq->ring.descs;
        unsigned i;
        dma_addr_t dma_addr;
+       uint32_t max_rx_pkt_len;
+       uint16_t rq_buf_len;
 
        if (!rq->in_use)
                return 0;
@@ -308,6 +275,18 @@ enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
        dev_debug(enic, "queue %u, allocating %u rx queue mbufs\n", rq->index,
                  rq->ring.desc_count);
 
+       /*
+        * If *not* using scatter and the mbuf size is smaller than the
+        * requested max packet size (max_rx_pkt_len), then reduce the
+        * posted buffer size to max_rx_pkt_len. HW still receives packets
+        * larger than max_rx_pkt_len, but they will be truncated, which we
+        * drop in the rx handler. Not ideal, but better than returning
+        * large packets when the user is not expecting them.
+        */
+       max_rx_pkt_len = enic->rte_dev->data->dev_conf.rxmode.max_rx_pkt_len;
+       rq_buf_len = rte_pktmbuf_data_room_size(rq->mp) - RTE_PKTMBUF_HEADROOM;
+       if (max_rx_pkt_len < rq_buf_len && !rq->data_queue_enable)
+               rq_buf_len = max_rx_pkt_len;
        for (i = 0; i < rq->ring.desc_count; i++, rqd++) {
                mb = rte_mbuf_raw_alloc(rq->mp);
                if (mb == NULL) {
@@ -317,12 +296,12 @@ enic_alloc_rx_queue_mbufs(struct enic *enic, struct vnic_rq *rq)
                }
 
                mb->data_off = RTE_PKTMBUF_HEADROOM;
-               dma_addr = (dma_addr_t)(mb->buf_physaddr
+               dma_addr = (dma_addr_t)(mb->buf_iova
                           + RTE_PKTMBUF_HEADROOM);
                rq_enet_desc_enc(rqd, dma_addr,
                                (rq->is_sop ? RQ_ENET_TYPE_ONLY_SOP
                                : RQ_ENET_TYPE_NOT_SOP),
-                               mb->buf_len - RTE_PKTMBUF_HEADROOM);
+                               rq_buf_len);
                rq->mbuf_ring[i] = mb;
        }
 
@@ -363,7 +342,7 @@ enic_alloc_consistent(void *priv, size_t size,
        }
 
        vaddr = rz->addr;
-       *dma_handle = (dma_addr_t)rz->phys_addr;
+       *dma_handle = (dma_addr_t)rz->iova;
 
        mze = rte_malloc("enic memzone entry",
                         sizeof(struct enic_memzone_entry), 0);
@@ -372,6 +351,7 @@ enic_alloc_consistent(void *priv, size_t size,
                pr_err("%s : Failed to allocate memory for memzone list\n",
                       __func__);
                rte_memzone_free(rz);
+               return NULL;
        }
 
        mze->rz = rz;
@@ -395,7 +375,7 @@ enic_free_consistent(void *priv,
        rte_spinlock_lock(&enic->memzone_list_lock);
        LIST_FOREACH(mze, &enic->memzone_list, entries) {
                if (mze->rz->addr == vaddr &&
-                   mze->rz->phys_addr == dma_handle)
+                   mze->rz->iova == dma_handle)
                        break;
        }
        if (mze == NULL) {
@@ -426,8 +406,7 @@ int enic_link_update(struct enic *enic)
 }
 
 static void
-enic_intr_handler(__rte_unused struct rte_intr_handle *handle,
-       void *arg)
+enic_intr_handler(void *arg)
 {
        struct rte_eth_dev *dev = (struct rte_eth_dev *)arg;
        struct enic *enic = pmd_priv(dev);
@@ -606,7 +585,7 @@ int enic_stop_rq(struct enic *enic, uint16_t queue_idx)
 
 int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
        unsigned int socket_id, struct rte_mempool *mp,
-       uint16_t nb_desc)
+       uint16_t nb_desc, uint16_t free_thresh)
 {
        int rc;
        uint16_t sop_queue_idx = enic_rte_rq_idx_to_sop_idx(queue_idx);
@@ -616,7 +595,7 @@ int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
        unsigned int mbuf_size, mbufs_per_pkt;
        unsigned int nb_sop_desc, nb_data_desc;
        uint16_t min_sop, max_sop, min_data, max_data;
-       uint16_t mtu = enic->rte_dev->data->mtu;
+       uint32_t max_rx_pkt_len;
 
        rq_sop->is_sop = 1;
        rq_sop->data_queue_idx = data_queue_idx;
@@ -627,24 +606,49 @@ int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
        rq_data->socket_id = socket_id;
        rq_data->mp = mp;
        rq_sop->in_use = 1;
+       rq_sop->rx_free_thresh = free_thresh;
+       rq_data->rx_free_thresh = free_thresh;
+       dev_debug(enic, "Set queue_id:%u free thresh:%u\n", queue_idx,
+                 free_thresh);
 
        mbuf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
                               RTE_PKTMBUF_HEADROOM);
+       /* max_rx_pkt_len includes the ethernet header and CRC. */
+       max_rx_pkt_len = enic->rte_dev->data->dev_conf.rxmode.max_rx_pkt_len;
 
-       if (enic->rte_dev->data->dev_conf.rxmode.enable_scatter) {
+       if (enic->rte_dev->data->dev_conf.rxmode.offloads &
+           DEV_RX_OFFLOAD_SCATTER) {
                dev_info(enic, "Rq %u Scatter rx mode enabled\n", queue_idx);
-               /* ceil((mtu + ETHER_HDR_LEN + 4)/mbuf_size) */
-               mbufs_per_pkt = ((mtu + ETHER_HDR_LEN + 4) +
-                                (mbuf_size - 1)) / mbuf_size;
+               /* ceil((max pkt len)/mbuf_size) */
+               mbufs_per_pkt = (max_rx_pkt_len + mbuf_size - 1) / mbuf_size;
        } else {
                dev_info(enic, "Scatter rx mode disabled\n");
                mbufs_per_pkt = 1;
+               if (max_rx_pkt_len > mbuf_size) {
+                       dev_warning(enic, "The maximum Rx packet size (%u) is"
+                                   " larger than the mbuf size (%u), and"
+                                   " scatter is disabled. Larger packets will"
+                                   " be truncated.\n",
+                                   max_rx_pkt_len, mbuf_size);
+               }
        }
 
        if (mbufs_per_pkt > 1) {
                dev_info(enic, "Rq %u Scatter rx mode in use\n", queue_idx);
                rq_sop->data_queue_enable = 1;
                rq_data->in_use = 1;
+               /*
+                * HW does not directly support rxmode.max_rx_pkt_len. HW always
+                * receives packet sizes up to the "max" MTU.
+                * If not using scatter, we can achieve the effect of dropping
+                * larger packets by reducing the size of posted buffers.
+                * See enic_alloc_rx_queue_mbufs().
+                */
+               if (max_rx_pkt_len <
+                   enic_mtu_to_max_rx_pktlen(enic->rte_dev->data->mtu)) {
+                       dev_warning(enic, "rxmode.max_rx_pkt_len is ignored"
+                                   " when scatter rx mode is in use.\n");
+               }
        } else {
                dev_info(enic, "Rq %u Scatter rx mode not being used\n",
                         queue_idx);
@@ -684,8 +688,9 @@ int enic_alloc_rq(struct enic *enic, uint16_t queue_idx,
                nb_data_desc = max_data;
        }
        if (mbufs_per_pkt > 1) {
-               dev_info(enic, "For mtu %d and mbuf size %d valid rx descriptor range is %d to %d\n",
-                        mtu, mbuf_size, min_sop + min_data,
+               dev_info(enic, "For max packet size %u and mbuf size %u valid"
+                        " rx descriptor range is %u to %u\n",
+                        max_rx_pkt_len, mbuf_size, min_sop + min_data,
                         max_sop + max_data);
        }
        dev_info(enic, "Using %d rx descriptors (sop %d, data %d)\n",
@@ -919,44 +924,42 @@ static int enic_dev_open(struct enic *enic)
        return err;
 }
 
-static int enic_set_rsskey(struct enic *enic)
+static int enic_set_rsskey(struct enic *enic, uint8_t *user_key)
 {
        dma_addr_t rss_key_buf_pa;
        union vnic_rss_key *rss_key_buf_va = NULL;
-       static union vnic_rss_key rss_key = {
-               .key = {
-                       [0] = {.b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101}},
-                       [1] = {.b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101}},
-                       [2] = {.b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115}},
-                       [3] = {.b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108}},
-               }
-       };
-       int err;
+       int err, i;
        u8 name[NAME_MAX];
 
+       RTE_ASSERT(user_key != NULL);
        snprintf((char *)name, NAME_MAX, "rss_key-%s", enic->bdf_name);
        rss_key_buf_va = enic_alloc_consistent(enic, sizeof(union vnic_rss_key),
                &rss_key_buf_pa, name);
        if (!rss_key_buf_va)
                return -ENOMEM;
 
-       rte_memcpy(rss_key_buf_va, &rss_key, sizeof(union vnic_rss_key));
+       for (i = 0; i < ENIC_RSS_HASH_KEY_SIZE; i++)
+               rss_key_buf_va->key[i / 10].b[i % 10] = user_key[i];
 
        err = enic_set_rss_key(enic,
                rss_key_buf_pa,
                sizeof(union vnic_rss_key));
 
+       /* Save for later queries */
+       if (!err) {
+               rte_memcpy(&enic->rss_key, rss_key_buf_va,
+                          sizeof(union vnic_rss_key));
+       }
        enic_free_consistent(enic, sizeof(union vnic_rss_key),
                rss_key_buf_va, rss_key_buf_pa);
 
        return err;
 }
 
-static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits)
+int enic_set_rss_reta(struct enic *enic, union vnic_rss_cpu *rss_cpu)
 {
        dma_addr_t rss_cpu_buf_pa;
        union vnic_rss_cpu *rss_cpu_buf_va = NULL;
-       int i;
        int err;
        u8 name[NAME_MAX];
 
@@ -966,9 +969,7 @@ static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits)
        if (!rss_cpu_buf_va)
                return -ENOMEM;
 
-       for (i = 0; i < (1 << rss_hash_bits); i++)
-               (*rss_cpu_buf_va).cpu[i / 4].b[i % 4] =
-                       enic_rte_rq_idx_to_sop_idx(i % enic->rq_count);
+       rte_memcpy(rss_cpu_buf_va, rss_cpu, sizeof(union vnic_rss_cpu));
 
        err = enic_set_rss_cpu(enic,
                rss_cpu_buf_pa,
@@ -977,6 +978,9 @@ static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits)
        enic_free_consistent(enic, sizeof(union vnic_rss_cpu),
                rss_cpu_buf_va, rss_cpu_buf_pa);
 
+       /* Save for later queries */
+       if (!err)
+               rte_memcpy(&enic->rss_cpu, rss_cpu, sizeof(union vnic_rss_cpu));
        return err;
 }
 
@@ -986,8 +990,6 @@ static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu,
        const u8 tso_ipid_split_en = 0;
        int err;
 
-       /* Enable VLAN tag stripping */
-
        err = enic_set_nic_cfg(enic,
                rss_default_cpu, rss_hash_type,
                rss_hash_bits, rss_base_cpu,
@@ -997,47 +999,50 @@ static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu,
        return err;
 }
 
-int enic_set_rss_nic_cfg(struct enic *enic)
+/* Initialize RSS with defaults, called from dev_configure */
+int enic_init_rss_nic_cfg(struct enic *enic)
 {
-       const u8 rss_default_cpu = 0;
-       const u8 rss_hash_type = NIC_CFG_RSS_HASH_TYPE_IPV4 |
-           NIC_CFG_RSS_HASH_TYPE_TCP_IPV4 |
-           NIC_CFG_RSS_HASH_TYPE_IPV6 |
-           NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
-       const u8 rss_hash_bits = 7;
-       const u8 rss_base_cpu = 0;
-       u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1);
-
-       if (rss_enable) {
-               if (!enic_set_rsskey(enic)) {
-                       if (enic_set_rsscpu(enic, rss_hash_bits)) {
-                               rss_enable = 0;
-                               dev_warning(enic, "RSS disabled, "\
-                                       "Failed to set RSS cpu indirection table.");
-                       }
-               } else {
-                       rss_enable = 0;
-                       dev_warning(enic,
-                               "RSS disabled, Failed to set RSS key.\n");
+       static uint8_t default_rss_key[] = {
+               85, 67, 83, 97, 119, 101, 115, 111, 109, 101,
+               80, 65, 76, 79, 117, 110, 105, 113, 117, 101,
+               76, 73, 78, 85, 88, 114, 111, 99, 107, 115,
+               69, 78, 73, 67, 105, 115, 99, 111, 111, 108,
+       };
+       struct rte_eth_rss_conf rss_conf;
+       union vnic_rss_cpu rss_cpu;
+       int ret, i;
+
+       rss_conf = enic->rte_dev->data->dev_conf.rx_adv_conf.rss_conf;
+       /*
+        * If setting key for the first time, and the user gives us none, then
+        * push the default key to NIC.
+        */
+       if (rss_conf.rss_key == NULL) {
+               rss_conf.rss_key = default_rss_key;
+               rss_conf.rss_key_len = ENIC_RSS_HASH_KEY_SIZE;
+       }
+       ret = enic_set_rss_conf(enic, &rss_conf);
+       if (ret) {
+               dev_err(enic, "Failed to configure RSS\n");
+               return ret;
+       }
+       if (enic->rss_enable) {
+               /* If enabling RSS, use the default reta */
+               for (i = 0; i < ENIC_RSS_RETA_SIZE; i++) {
+                       rss_cpu.cpu[i / 4].b[i % 4] =
+                               enic_rte_rq_idx_to_sop_idx(i % enic->rq_count);
                }
+               ret = enic_set_rss_reta(enic, &rss_cpu);
+               if (ret)
+                       dev_err(enic, "Failed to set RSS indirection table\n");
        }
-
-       return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
-               rss_hash_bits, rss_base_cpu, rss_enable);
+       return ret;
 }
 
 int enic_setup_finish(struct enic *enic)
 {
-       int ret;
-
        enic_init_soft_stats(enic);
 
-       ret = enic_set_rss_nic_cfg(enic);
-       if (ret) {
-               dev_err(enic, "Failed to config nic, aborting.\n");
-               return -1;
-       }
-
        /* Default conf */
        vnic_dev_packet_filter(enic->vdev,
                1 /* directed  */,
@@ -1052,6 +1057,98 @@ int enic_setup_finish(struct enic *enic)
        return 0;
 }
 
+static int enic_rss_conf_valid(struct enic *enic,
+                              struct rte_eth_rss_conf *rss_conf)
+{
+       /* RSS is disabled per VIC settings. Ignore rss_conf. */
+       if (enic->flow_type_rss_offloads == 0)
+               return 0;
+       if (rss_conf->rss_key != NULL &&
+           rss_conf->rss_key_len != ENIC_RSS_HASH_KEY_SIZE) {
+               dev_err(enic, "Given rss_key is %d bytes, it must be %d\n",
+                       rss_conf->rss_key_len, ENIC_RSS_HASH_KEY_SIZE);
+               return -EINVAL;
+       }
+       if (rss_conf->rss_hf != 0 &&
+           (rss_conf->rss_hf & enic->flow_type_rss_offloads) == 0) {
+               dev_err(enic, "Given rss_hf contains none of the supported"
+                       " types\n");
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/* Set hash type and key according to rss_conf */
+int enic_set_rss_conf(struct enic *enic, struct rte_eth_rss_conf *rss_conf)
+{
+       struct rte_eth_dev *eth_dev;
+       uint64_t rss_hf;
+       u8 rss_hash_type;
+       u8 rss_enable;
+       int ret;
+
+       RTE_ASSERT(rss_conf != NULL);
+       ret = enic_rss_conf_valid(enic, rss_conf);
+       if (ret) {
+               dev_err(enic, "RSS configuration (rss_conf) is invalid\n");
+               return ret;
+       }
+
+       eth_dev = enic->rte_dev;
+       rss_hash_type = 0;
+       rss_hf = rss_conf->rss_hf & enic->flow_type_rss_offloads;
+       if (enic->rq_count > 1 &&
+           (eth_dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) &&
+           rss_hf != 0) {
+               rss_enable = 1;
+               if (rss_hf & ETH_RSS_IPV4)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_IPV4;
+               if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV4;
+               if (rss_hf & ETH_RSS_IPV6)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_IPV6;
+               if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
+               if (rss_hf & ETH_RSS_IPV6_EX)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_IPV6_EX;
+               if (rss_hf & ETH_RSS_IPV6_TCP_EX)
+                       rss_hash_type |= NIC_CFG_RSS_HASH_TYPE_TCP_IPV6_EX;
+       } else {
+               rss_enable = 0;
+               rss_hf = 0;
+       }
+
+       /* Set the hash key if provided */
+       if (rss_enable && rss_conf->rss_key) {
+               ret = enic_set_rsskey(enic, rss_conf->rss_key);
+               if (ret) {
+                       dev_err(enic, "Failed to set RSS key\n");
+                       return ret;
+               }
+       }
+
+       ret = enic_set_niccfg(enic, ENIC_RSS_DEFAULT_CPU, rss_hash_type,
+                             ENIC_RSS_HASH_BITS, ENIC_RSS_BASE_CPU,
+                             rss_enable);
+       if (!ret) {
+               enic->rss_hf = rss_hf;
+               enic->rss_hash_type = rss_hash_type;
+               enic->rss_enable = rss_enable;
+       }
+       return 0;
+}
+
+int enic_set_vlan_strip(struct enic *enic)
+{
+       /*
+        * Unfortunately, VLAN strip on/off and RSS on/off are configured
+        * together. So, re-do niccfg, preserving the current RSS settings.
+        */
+       return enic_set_niccfg(enic, ENIC_RSS_DEFAULT_CPU, enic->rss_hash_type,
+                              ENIC_RSS_HASH_BITS, ENIC_RSS_BASE_CPU,
+                              enic->rss_enable);
+}
+
 void enic_add_packet_filter(struct enic *enic)
 {
        /* Args -> directed, multicast, broadcast, promisc, allmulti */
@@ -1072,6 +1169,9 @@ static void enic_dev_deinit(struct enic *enic)
        vnic_dev_notify_unset(enic->vdev);
 
        rte_free(eth_dev->data->mac_addrs);
+       rte_free(enic->cq);
+       rte_free(enic->rq);
+       rte_free(enic->wq);
 }
 
 
@@ -1079,27 +1179,28 @@ int enic_set_vnic_res(struct enic *enic)
 {
        struct rte_eth_dev *eth_dev = enic->rte_dev;
        int rc = 0;
+       unsigned int required_rq, required_wq, required_cq;
 
-       /* With Rx scatter support, two RQs are now used per RQ used by
-        * the application.
-        */
-       if (enic->conf_rq_count < eth_dev->data->nb_rx_queues) {
+       /* Always use two vNIC RQs per eth_dev RQ, regardless of Rx scatter. */
+       required_rq = eth_dev->data->nb_rx_queues * 2;
+       required_wq = eth_dev->data->nb_tx_queues;
+       required_cq = eth_dev->data->nb_rx_queues + eth_dev->data->nb_tx_queues;
+
+       if (enic->conf_rq_count < required_rq) {
                dev_err(dev, "Not enough Receive queues. Requested:%u which uses %d RQs on VIC, Configured:%u\n",
                        eth_dev->data->nb_rx_queues,
-                       eth_dev->data->nb_rx_queues * 2, enic->conf_rq_count);
+                       required_rq, enic->conf_rq_count);
                rc = -EINVAL;
        }
-       if (enic->conf_wq_count < eth_dev->data->nb_tx_queues) {
+       if (enic->conf_wq_count < required_wq) {
                dev_err(dev, "Not enough Transmit queues. Requested:%u, Configured:%u\n",
                        eth_dev->data->nb_tx_queues, enic->conf_wq_count);
                rc = -EINVAL;
        }
 
-       if (enic->conf_cq_count < (eth_dev->data->nb_rx_queues +
-                                  eth_dev->data->nb_tx_queues)) {
+       if (enic->conf_cq_count < required_cq) {
                dev_err(dev, "Not enough Completion queues. Required:%u, Configured:%u\n",
-                       (eth_dev->data->nb_rx_queues +
-                        eth_dev->data->nb_tx_queues), enic->conf_cq_count);
+                       required_cq, enic->conf_cq_count);
                rc = -EINVAL;
        }
 
@@ -1117,11 +1218,12 @@ static int
 enic_reinit_rq(struct enic *enic, unsigned int rq_idx)
 {
        struct vnic_rq *sop_rq, *data_rq;
-       unsigned int cq_idx = enic_cq_rq(enic, rq_idx);
+       unsigned int cq_idx;
        int rc = 0;
 
        sop_rq = &enic->rq[enic_rte_rq_idx_to_sop_idx(rq_idx)];
        data_rq = &enic->rq[enic_rte_rq_idx_to_data_idx(rq_idx)];
+       cq_idx = rq_idx;
 
        vnic_cq_clean(&enic->cq[cq_idx]);
        vnic_cq_init(&enic->cq[cq_idx],
@@ -1181,6 +1283,9 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
        old_mtu = eth_dev->data->mtu;
        config_mtu = enic->config.mtu;
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return -E_RTE_SECONDARY;
+
        if (new_mtu > enic->max_mtu) {
                dev_err(enic,
                        "MTU not updated: requested (%u) greater than max (%u)\n",
@@ -1201,7 +1306,8 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
        /* The easy case is when scatter is disabled. However if the MTU
         * becomes greater than the mbuf data size, packet drops will ensue.
         */
-       if (!enic->rte_dev->data->dev_conf.rxmode.enable_scatter) {
+       if (!(enic->rte_dev->data->dev_conf.rxmode.offloads &
+             DEV_RX_OFFLOAD_SCATTER)) {
                eth_dev->data->mtu = new_mtu;
                goto set_mtu_done;
        }
@@ -1226,7 +1332,7 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
                }
        }
 
-       /* replace Rx funciton with a no-op to avoid getting stale pkts */
+       /* replace Rx function with a no-op to avoid getting stale pkts */
        eth_dev->rx_pkt_burst = enic_dummy_recv_pkts;
        rte_mb();
 
@@ -1244,7 +1350,7 @@ int enic_set_mtu(struct enic *enic, uint16_t new_mtu)
 
                enic_free_rq(rq);
                rc = enic_alloc_rq(enic, rq_idx, rq->socket_id, rq->mp,
-                                  rq->tot_nb_desc);
+                                  rq->tot_nb_desc, rq->rx_free_thresh);
                if (rc) {
                        dev_err(enic,
                                "Fatal MTU alloc error- No traffic will pass\n");
@@ -1300,20 +1406,43 @@ static int enic_dev_init(struct enic *enic)
                dev_err(enic, "See the ENIC PMD guide for more information.\n");
                return -EINVAL;
        }
+       /* Queue counts may be zeros. rte_zmalloc returns NULL in that case. */
+       enic->cq = rte_zmalloc("enic_vnic_cq", sizeof(struct vnic_cq) *
+                              enic->conf_cq_count, 8);
+       enic->rq = rte_zmalloc("enic_vnic_rq", sizeof(struct vnic_rq) *
+                              enic->conf_rq_count, 8);
+       enic->wq = rte_zmalloc("enic_vnic_wq", sizeof(struct vnic_wq) *
+                              enic->conf_wq_count, 8);
+       if (enic->conf_cq_count > 0 && enic->cq == NULL) {
+               dev_err(enic, "failed to allocate vnic_cq, aborting.\n");
+               return -1;
+       }
+       if (enic->conf_rq_count > 0 && enic->rq == NULL) {
+               dev_err(enic, "failed to allocate vnic_rq, aborting.\n");
+               return -1;
+       }
+       if (enic->conf_wq_count > 0 && enic->wq == NULL) {
+               dev_err(enic, "failed to allocate vnic_wq, aborting.\n");
+               return -1;
+       }
 
        /* Get the supported filters */
        enic_fdir_info(enic);
 
-       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN, 0);
+       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN
+                                               * ENIC_MAX_MAC_ADDR, 0);
        if (!eth_dev->data->mac_addrs) {
                dev_err(enic, "mac addr storage alloc failed, aborting.\n");
                return -1;
        }
        ether_addr_copy((struct ether_addr *) enic->mac_addr,
-               &eth_dev->data->mac_addrs[0]);
+                       eth_dev->data->mac_addrs);
 
        vnic_dev_set_reset_flag(enic->vdev, 0);
 
+       LIST_INIT(&enic->flows);
+       rte_spinlock_init(&enic->flows_lock);
+
        /* set up link status checking */
        vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
 
@@ -1328,6 +1457,10 @@ int enic_probe(struct enic *enic)
 
        dev_debug(enic, " Initializing ENIC PMD\n");
 
+       /* if this is a secondary process the hardware is already initialized */
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return 0;
+
        enic->bar0.vaddr = (void *)pdev->mem_resource[0].addr;
        enic->bar0.len = pdev->mem_resource[0].len;