eal: add function to create control threads
[dpdk.git] / drivers / net / enic / enic_res.c
index 12a337c..9b5baf3 100644 (file)
@@ -1,40 +1,10 @@
-/*
- * Copyright 2008-2010 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.
- *
  */
-#ident "$Id: enic_res.c 171146 2014-05-02 07:08:20Z ssujith $"
 
 #include "enic_compat.h"
-#include "rte_ethdev.h"
+#include "rte_ethdev_driver.h"
 #include "wq_enet_desc.h"
 #include "rq_enet_desc.h"
 #include "cq_enet_desc.h"
@@ -63,6 +33,7 @@ int enic_get_vnic_config(struct enic *enic)
                return err;
        }
 
+
 #define GET_CONFIG(m) \
        do { \
                err = vnic_dev_spec(enic->vdev, \
@@ -84,6 +55,45 @@ int enic_get_vnic_config(struct enic *enic)
        GET_CONFIG(intr_timer_usec);
        GET_CONFIG(loop_tag);
        GET_CONFIG(num_arfs);
+       GET_CONFIG(max_pkt_size);
+
+       /* max packet size is only defined in newer VIC firmware
+        * and will be 0 for legacy firmware and VICs
+        */
+       if (c->max_pkt_size > ENIC_DEFAULT_RX_MAX_PKT_SIZE)
+               enic->max_mtu = c->max_pkt_size - (ETHER_HDR_LEN + 4);
+       else
+               enic->max_mtu = ENIC_DEFAULT_RX_MAX_PKT_SIZE
+                               - (ETHER_HDR_LEN + 4);
+       if (c->mtu == 0)
+               c->mtu = 1500;
+
+       enic->rte_dev->data->mtu = min_t(u16, enic->max_mtu,
+                                        max_t(u16, ENIC_MIN_MTU, c->mtu));
+
+       enic->adv_filters = vnic_dev_capable_adv_filters(enic->vdev);
+       dev_info(enic, "Advanced Filters %savailable\n", ((enic->adv_filters)
+                ? "" : "not "));
+
+       err = vnic_dev_capable_filter_mode(enic->vdev, &enic->flow_filter_mode,
+                                          &enic->filter_actions);
+       if (err) {
+               dev_err(enic_get_dev(enic),
+                       "Error getting filter modes, %d\n", err);
+               return err;
+       }
+
+       dev_info(enic, "Flow api filter mode: %s Actions: %s%s%s\n",
+               ((enic->flow_filter_mode == FILTER_DPDK_1) ? "DPDK" :
+               ((enic->flow_filter_mode == FILTER_USNIC_IP) ? "USNIC" :
+               ((enic->flow_filter_mode == FILTER_IPV4_5TUPLE) ? "5TUPLE" :
+               "NONE"))),
+               ((enic->filter_actions & FILTER_ACTION_RQ_STEERING_FLAG) ?
+                "steer " : ""),
+               ((enic->filter_actions & FILTER_ACTION_FILTER_ID_FLAG) ?
+                "tag " : ""),
+               ((enic->filter_actions & FILTER_ACTION_DROP_FLAG) ?
+                "drop " : ""));
 
        c->wq_desc_count =
                min_t(u32, ENIC_MAX_WQ_DESCS,
@@ -97,21 +107,16 @@ int enic_get_vnic_config(struct enic *enic)
                c->rq_desc_count));
        c->rq_desc_count &= 0xffffffe0; /* must be aligned to groups of 32 */
 
-       if (c->mtu == 0)
-               c->mtu = 1500;
-       c->mtu = min_t(u16, ENIC_MAX_MTU,
-               max_t(u16, ENIC_MIN_MTU,
-               c->mtu));
-
        c->intr_timer_usec = min_t(u32, c->intr_timer_usec,
                vnic_dev_get_intr_coal_timer_max(enic->vdev));
 
        dev_info(enic_get_dev(enic),
                "vNIC MAC addr %02x:%02x:%02x:%02x:%02x:%02x "
-               "wq/rq %d/%d mtu %d\n",
+               "wq/rq %d/%d mtu %d, max mtu:%d\n",
                enic->mac_addr[0], enic->mac_addr[1], enic->mac_addr[2],
                enic->mac_addr[3], enic->mac_addr[4], enic->mac_addr[5],
-               c->wq_desc_count, c->rq_desc_count, c->mtu);
+               c->wq_desc_count, c->rq_desc_count,
+               enic->rte_dev->data->mtu, enic->max_mtu);
        dev_info(enic_get_dev(enic), "vNIC csum tx/rx %s/%s "
                "rss %s intr mode %s type %s timer %d usec "
                "loopback tag 0x%04x\n",
@@ -128,6 +133,31 @@ int enic_get_vnic_config(struct enic *enic)
                c->intr_timer_usec,
                c->loop_tag);
 
+       /* RSS settings from vNIC */
+       enic->reta_size = ENIC_RSS_RETA_SIZE;
+       enic->hash_key_size = ENIC_RSS_HASH_KEY_SIZE;
+       enic->flow_type_rss_offloads = 0;
+       if (ENIC_SETTING(enic, RSSHASH_IPV4))
+               enic->flow_type_rss_offloads |= ETH_RSS_IPV4;
+       if (ENIC_SETTING(enic, RSSHASH_TCPIPV4))
+               enic->flow_type_rss_offloads |= ETH_RSS_NONFRAG_IPV4_TCP;
+       if (ENIC_SETTING(enic, RSSHASH_IPV6))
+               enic->flow_type_rss_offloads |= ETH_RSS_IPV6;
+       if (ENIC_SETTING(enic, RSSHASH_TCPIPV6))
+               enic->flow_type_rss_offloads |= ETH_RSS_NONFRAG_IPV6_TCP;
+       if (ENIC_SETTING(enic, RSSHASH_IPV6_EX))
+               enic->flow_type_rss_offloads |= ETH_RSS_IPV6_EX;
+       if (ENIC_SETTING(enic, RSSHASH_TCPIPV6_EX))
+               enic->flow_type_rss_offloads |= ETH_RSS_IPV6_TCP_EX;
+       if (vnic_dev_capable_udp_rss(enic->vdev)) {
+               enic->flow_type_rss_offloads |=
+                       ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
+       }
+
+       /* Zero offloads if RSS is not enabled */
+       if (!ENIC_SETTING(enic, RSS))
+               enic->flow_type_rss_offloads = 0;
+
        return 0;
 }
 
@@ -197,23 +227,25 @@ void enic_free_vnic_resources(struct enic *enic)
 
        for (i = 0; i < enic->wq_count; i++)
                vnic_wq_free(&enic->wq[i]);
-       for (i = 0; i < enic->rq_count; i++)
-               vnic_rq_free(&enic->rq[i]);
+       for (i = 0; i < enic_vnic_rq_count(enic); i++)
+               if (enic->rq[i].in_use)
+                       vnic_rq_free(&enic->rq[i]);
        for (i = 0; i < enic->cq_count; i++)
                vnic_cq_free(&enic->cq[i]);
-       vnic_intr_free(&enic->intr);
+       for (i = 0; i < enic->intr_count; i++)
+               vnic_intr_free(&enic->intr[i]);
 }
 
 void enic_get_res_counts(struct enic *enic)
 {
-       enic->wq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_WQ);
-       enic->rq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_RQ);
-       enic->cq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_CQ);
-       enic->intr_count = vnic_dev_get_res_count(enic->vdev,
+       enic->conf_wq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_WQ);
+       enic->conf_rq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_RQ);
+       enic->conf_cq_count = vnic_dev_get_res_count(enic->vdev, RES_TYPE_CQ);
+       enic->conf_intr_count = vnic_dev_get_res_count(enic->vdev,
                RES_TYPE_INTR_CTRL);
 
        dev_info(enic_get_dev(enic),
                "vNIC resources avail: wq %d rq %d cq %d intr %d\n",
-               enic->wq_count, enic->rq_count,
-               enic->cq_count, enic->intr_count);
+               enic->conf_wq_count, enic->conf_rq_count,
+               enic->conf_cq_count, enic->conf_intr_count);
 }