net/enic: allow to change RSS settings
authorHyong Youb Kim <hyonkim@cisco.com>
Thu, 8 Mar 2018 02:46:54 +0000 (18:46 -0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 30 Mar 2018 12:08:43 +0000 (14:08 +0200)
Currently, when more than 1 receive queues are configured, the driver
always enables RSS with the driver's own default hash type, key, and
RETA. The user is unable to change any of the RSS settings. Address
this by implementing the ethdev RSS API as follows.

Correctly report the RETA size, key size, and supported hash types
through rte_eth_dev_info.

During dev_configure(), initialize RSS according to the device's
mq_mode and rss_conf. Start with the default RETA, and use the default
key unless a custom key is provided.

Add the RETA and rss_conf query/set handlers to let the user change
RSS settings after the initial configuration. The hardware is able to
change hash type, key, and RETA individually. So, the handlers change
only the affected settings.

Refactor/rename several functions in order to make their intentions
clear. For example, remove all traces of RSS from
enicpmd_vlan_offload_set() as it is confusing.

Signed-off-by: Hyong Youb Kim <hyonkim@cisco.com>
Reviewed-by: John Daley <johndale@cisco.com>
doc/guides/nics/features/enic.ini
drivers/net/enic/enic.h
drivers/net/enic/enic_ethdev.c
drivers/net/enic/enic_main.c
drivers/net/enic/enic_res.c
drivers/net/enic/enic_res.h

index 498341f..e79d727 100644 (file)
@@ -15,6 +15,8 @@ Promiscuous mode     = Y
 Unicast MAC filter   = Y
 Multicast MAC filter = Y
 RSS hash             = Y
+RSS key update       = Y
+RSS reta update      = Y
 SR-IOV               = Y
 VLAN filter          = Y
 CRC offload          = Y
index e88af6b..d29939c 100644 (file)
@@ -146,6 +146,20 @@ struct enic {
 
        LIST_HEAD(enic_flows, rte_flow) flows;
        rte_spinlock_t flows_lock;
+
+       /* RSS */
+       uint16_t reta_size;
+       uint8_t hash_key_size;
+       uint64_t flow_type_rss_offloads; /* 0 indicates RSS not supported */
+       /*
+        * Keep a copy of current RSS config for queries, as we cannot retrieve
+        * it from the NIC.
+        */
+       uint8_t rss_hash_type; /* NIC_CFG_RSS_HASH_TYPE flags */
+       uint8_t rss_enable;
+       uint64_t rss_hf; /* ETH_RSS flags */
+       union vnic_rss_key rss_key;
+       union vnic_rss_cpu rss_cpu;
 };
 
 /* Get the CQ index from a Start of Packet(SOP) RQ index */
@@ -239,8 +253,12 @@ void enic_free_rq(void *rxq);
 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 free_thresh);
-int enic_set_rss_nic_cfg(struct enic *enic);
 int enic_set_vnic_res(struct enic *enic);
+int enic_init_rss_nic_cfg(struct enic *enic);
+int enic_set_rss_conf(struct enic *enic,
+                     struct rte_eth_rss_conf *rss_conf);
+int enic_set_rss_reta(struct enic *enic, union vnic_rss_cpu *rss_cpu);
+int enic_set_vlan_strip(struct enic *enic);
 int enic_enable(struct enic *enic);
 int enic_disable(struct enic *enic);
 void enic_remove(struct enic *enic);
index d84714e..cbab702 100644 (file)
@@ -345,8 +345,6 @@ static int enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
                else
                        enic->ig_vlan_strip_en = 0;
        }
-       enic_set_rss_nic_cfg(enic);
-
 
        if (mask & ETH_VLAN_FILTER_MASK) {
                dev_warning(enic,
@@ -358,7 +356,7 @@ static int enicpmd_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
                        "Configuration of extended VLAN is not supported\n");
        }
 
-       return 0;
+       return enic_set_vlan_strip(enic);
 }
 
 static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
@@ -379,8 +377,16 @@ static int enicpmd_dev_configure(struct rte_eth_dev *eth_dev)
        enic->hw_ip_checksum = !!(eth_dev->data->dev_conf.rxmode.offloads &
                                  DEV_RX_OFFLOAD_CHECKSUM);
        ret = enicpmd_vlan_offload_set(eth_dev, ETH_VLAN_STRIP_MASK);
-
-       return ret;
+       if (ret) {
+               dev_err(enic, "Failed to configure VLAN offloads\n");
+               return ret;
+       }
+       /*
+        * Initialize RSS with the default reta and key. If the user key is
+        * given (rx_adv_conf.rss_conf.rss_key), will use that instead of the
+        * default key.
+        */
+       return enic_init_rss_nic_cfg(enic);
 }
 
 /* Start the device.
@@ -480,6 +486,9 @@ static void enicpmd_dev_info_get(struct rte_eth_dev *eth_dev,
        device_info->default_rxconf = (struct rte_eth_rxconf) {
                .rx_free_thresh = ENIC_DEFAULT_RX_FREE_THRESH
        };
+       device_info->reta_size = enic->reta_size;
+       device_info->hash_key_size = enic->hash_key_size;
+       device_info->flow_type_rss_offloads = enic->flow_type_rss_offloads;
 }
 
 static const uint32_t *enicpmd_dev_supported_ptypes_get(struct rte_eth_dev *dev)
@@ -582,6 +591,100 @@ static int enicpmd_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
        return enic_set_mtu(enic, mtu);
 }
 
+static int enicpmd_dev_rss_reta_query(struct rte_eth_dev *dev,
+                                     struct rte_eth_rss_reta_entry64
+                                     *reta_conf,
+                                     uint16_t reta_size)
+{
+       struct enic *enic = pmd_priv(dev);
+       uint16_t i, idx, shift;
+
+       ENICPMD_FUNC_TRACE();
+       if (reta_size != ENIC_RSS_RETA_SIZE) {
+               dev_err(enic, "reta_query: wrong reta_size. given=%u expected=%u\n",
+                       reta_size, ENIC_RSS_RETA_SIZE);
+               return -EINVAL;
+       }
+
+       for (i = 0; i < reta_size; i++) {
+               idx = i / RTE_RETA_GROUP_SIZE;
+               shift = i % RTE_RETA_GROUP_SIZE;
+               if (reta_conf[idx].mask & (1ULL << shift))
+                       reta_conf[idx].reta[shift] = enic_sop_rq_idx_to_rte_idx(
+                               enic->rss_cpu.cpu[i / 4].b[i % 4]);
+       }
+
+       return 0;
+}
+
+static int enicpmd_dev_rss_reta_update(struct rte_eth_dev *dev,
+                                      struct rte_eth_rss_reta_entry64
+                                      *reta_conf,
+                                      uint16_t reta_size)
+{
+       struct enic *enic = pmd_priv(dev);
+       union vnic_rss_cpu rss_cpu;
+       uint16_t i, idx, shift;
+
+       ENICPMD_FUNC_TRACE();
+       if (reta_size != ENIC_RSS_RETA_SIZE) {
+               dev_err(enic, "reta_update: wrong reta_size. given=%u"
+                       " expected=%u\n",
+                       reta_size, ENIC_RSS_RETA_SIZE);
+               return -EINVAL;
+       }
+       /*
+        * Start with the current reta and modify it per reta_conf, as we
+        * need to push the entire reta even if we only modify one entry.
+        */
+       rss_cpu = enic->rss_cpu;
+       for (i = 0; i < reta_size; i++) {
+               idx = i / RTE_RETA_GROUP_SIZE;
+               shift = i % RTE_RETA_GROUP_SIZE;
+               if (reta_conf[idx].mask & (1ULL << shift))
+                       rss_cpu.cpu[i / 4].b[i % 4] =
+                               enic_rte_rq_idx_to_sop_idx(
+                                       reta_conf[idx].reta[shift]);
+       }
+       return enic_set_rss_reta(enic, &rss_cpu);
+}
+
+static int enicpmd_dev_rss_hash_update(struct rte_eth_dev *dev,
+                                      struct rte_eth_rss_conf *rss_conf)
+{
+       struct enic *enic = pmd_priv(dev);
+
+       ENICPMD_FUNC_TRACE();
+       return enic_set_rss_conf(enic, rss_conf);
+}
+
+static int enicpmd_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
+                                        struct rte_eth_rss_conf *rss_conf)
+{
+       struct enic *enic = pmd_priv(dev);
+
+       ENICPMD_FUNC_TRACE();
+       if (rss_conf == NULL)
+               return -EINVAL;
+       if (rss_conf->rss_key != NULL &&
+           rss_conf->rss_key_len < ENIC_RSS_HASH_KEY_SIZE) {
+               dev_err(enic, "rss_hash_conf_get: wrong rss_key_len. given=%u"
+                       " expected=%u+\n",
+                       rss_conf->rss_key_len, ENIC_RSS_HASH_KEY_SIZE);
+               return -EINVAL;
+       }
+       rss_conf->rss_hf = enic->rss_hf;
+       if (rss_conf->rss_key != NULL) {
+               int i;
+               for (i = 0; i < ENIC_RSS_HASH_KEY_SIZE; i++) {
+                       rss_conf->rss_key[i] =
+                               enic->rss_key.key[i / 10].b[i % 10];
+               }
+               rss_conf->rss_key_len = ENIC_RSS_HASH_KEY_SIZE;
+       }
+       return 0;
+}
+
 static const struct eth_dev_ops enicpmd_eth_dev_ops = {
        .dev_configure        = enicpmd_dev_configure,
        .dev_start            = enicpmd_dev_start,
@@ -622,6 +725,10 @@ static const struct eth_dev_ops enicpmd_eth_dev_ops = {
        .mac_addr_add         = enicpmd_add_mac_addr,
        .mac_addr_remove      = enicpmd_remove_mac_addr,
        .filter_ctrl          = enicpmd_dev_filter_ctrl,
+       .reta_query           = enicpmd_dev_rss_reta_query,
+       .reta_update          = enicpmd_dev_rss_reta_update,
+       .rss_hash_conf_get    = enicpmd_dev_rss_hash_conf_get,
+       .rss_hash_update      = enicpmd_dev_rss_hash_update,
 };
 
 struct enic *enicpmd_list_head = NULL;
index ec9d343..bd565be 100644 (file)
@@ -889,44 +889,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];
 
@@ -936,9 +934,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,
@@ -947,6 +943,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;
 }
 
@@ -956,8 +955,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,
@@ -967,47 +964,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  */,
@@ -1022,6 +1022,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 */
index c99d618..d8f7892 100644 (file)
@@ -128,6 +128,26 @@ 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;
+       /* Zero offloads if RSS is not enabled */
+       if (!ENIC_SETTING(enic, RSS))
+               enic->flow_type_rss_offloads = 0;
+
        return 0;
 }
 
index cf3a6fd..e68f130 100644 (file)
 #define ENIC_DEFAULT_RX_FREE_THRESH    32
 #define ENIC_TX_XMIT_MAX               64
 
+#define ENIC_RSS_DEFAULT_CPU    0
+#define ENIC_RSS_BASE_CPU       0
+#define ENIC_RSS_HASH_BITS      7
+#define ENIC_RSS_RETA_SIZE      (1 << ENIC_RSS_HASH_BITS)
+#define ENIC_RSS_HASH_KEY_SIZE  40
+
 #define ENIC_SETTING(enic, f) ((enic->config.flags & VENETF_##f) ? 1 : 0)