net/sfc: convert to the advanced EFX RSS interface
authorIvan Malov <ivan.malov@oktetlabs.ru>
Wed, 25 Apr 2018 17:51:44 +0000 (18:51 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 27 Apr 2018 17:00:55 +0000 (18:00 +0100)
The current code has the following drawbacks:
 - It is assumed that TCP 4-tuple hash is
   always supported, which is untrue in
   the case of packed stream FW variant.
 - The driver is unaware of UDP hash support
   available with latest firmware.

In order to cope with the mentioned issues, this
patch implements the new approach to handle hash
settings using the advanced EFX RSS interface.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
drivers/net/sfc/sfc.c
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_flow.c
drivers/net/sfc/sfc_rx.c
drivers/net/sfc/sfc_rx.h

index 1066a5e..37248bc 100644 (file)
@@ -638,7 +638,7 @@ static const uint8_t default_rss_key[EFX_RSS_KEY_SIZE] = {
 };
 
 static int
-sfc_set_rss_defaults(struct sfc_adapter *sa)
+sfc_rss_attach(struct sfc_adapter *sa)
 {
        struct sfc_rss *rss = &sa->rss;
        int rc;
@@ -663,16 +663,19 @@ sfc_set_rss_defaults(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_hash_support_get;
 
+       rc = sfc_rx_hash_init(sa);
+       if (rc != 0)
+               goto fail_rx_hash_init;
+
        efx_rx_fini(sa->nic);
        efx_ev_fini(sa->nic);
        efx_intr_fini(sa->nic);
 
-       rss->hash_types = sfc_rte_to_efx_hash_type(SFC_RSS_OFFLOADS);
-
        rte_memcpy(rss->key, default_rss_key, sizeof(rss->key));
 
        return 0;
 
+fail_rx_hash_init:
 fail_hash_support_get:
 fail_scale_support_get:
        efx_rx_fini(sa->nic);
@@ -687,6 +690,12 @@ fail_intr_init:
        return rc;
 }
 
+static void
+sfc_rss_detach(struct sfc_adapter *sa)
+{
+       sfc_rx_hash_fini(sa);
+}
+
 int
 sfc_attach(struct sfc_adapter *sa)
 {
@@ -744,9 +753,9 @@ sfc_attach(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_port_attach;
 
-       rc = sfc_set_rss_defaults(sa);
+       rc = sfc_rss_attach(sa);
        if (rc != 0)
-               goto fail_set_rss_defaults;
+               goto fail_rss_attach;
 
        rc = sfc_filter_attach(sa);
        if (rc != 0)
@@ -763,7 +772,9 @@ sfc_attach(struct sfc_adapter *sa)
        return 0;
 
 fail_filter_attach:
-fail_set_rss_defaults:
+       sfc_rss_detach(sa);
+
+fail_rss_attach:
        sfc_port_detach(sa);
 
 fail_port_attach:
@@ -795,6 +806,7 @@ sfc_detach(struct sfc_adapter *sa)
        sfc_flow_fini(sa);
 
        sfc_filter_detach(sa);
+       sfc_rss_detach(sa);
        sfc_port_detach(sa);
        sfc_ev_detach(sa);
        sfc_intr_detach(sa);
index 9c76d7f..3a5f6dc 100644 (file)
@@ -27,9 +27,6 @@
 extern "C" {
 #endif
 
-/** RSS hash offloads mask */
-#define SFC_RSS_OFFLOADS       (ETH_RSS_IP | ETH_RSS_TCP)
-
 /*
  * +---------------+
  * | UNINITIALIZED |<-----------+
@@ -154,10 +151,19 @@ struct sfc_port {
        uint32_t                mac_stats_mask[EFX_MAC_STATS_MASK_NPAGES];
 };
 
+struct sfc_rss_hf_rte_to_efx {
+       uint64_t                        rte;
+       efx_rx_hash_type_t              efx;
+};
+
 struct sfc_rss {
        unsigned int                    channels;
        efx_rx_scale_context_type_t     context_type;
        efx_rx_hash_support_t           hash_support;
+       efx_rx_hash_alg_t               hash_alg;
+       unsigned int                    hf_map_nb_entries;
+       struct sfc_rss_hf_rte_to_efx    *hf_map;
+
        efx_rx_hash_type_t              hash_types;
        unsigned int                    tbl[EFX_RSS_TBL_SIZE];
        uint8_t                         key[EFX_RSS_KEY_SIZE];
index 359d6d2..35a8301 100644 (file)
@@ -153,9 +153,15 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOREFCOUNT;
 
        if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
+               uint64_t rte_hf = 0;
+               unsigned int i;
+
+               for (i = 0; i < rss->hf_map_nb_entries; ++i)
+                       rte_hf |= rss->hf_map[i].rte;
+
                dev_info->reta_size = EFX_RSS_TBL_SIZE;
                dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
-               dev_info->flow_type_rss_offloads = SFC_RSS_OFFLOADS;
+               dev_info->flow_type_rss_offloads = rte_hf;
        }
 
        /* Initialize to hardware limits */
@@ -1378,7 +1384,7 @@ sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
         * flags which corresponds to the active EFX configuration stored
         * locally in 'sfc_adapter' and kept up-to-date
         */
-       rss_conf->rss_hf = sfc_efx_to_rte_hash_type(rss->hash_types);
+       rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(sa, rss->hash_types);
        rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
        if (rss_conf->rss_key != NULL)
                rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
@@ -1418,18 +1424,14 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
                return -EINVAL;
        }
 
-       if ((rss_conf->rss_hf & ~SFC_RSS_OFFLOADS) != 0) {
-               sfc_err(sa, "unsupported hash functions requested");
-               return -EINVAL;
-       }
-
        sfc_adapter_lock(sa);
 
-       efx_hash_types = sfc_rte_to_efx_hash_type(rss_conf->rss_hf);
+       rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
+       if (rc != 0)
+               goto fail_rx_hf_rte_to_efx;
 
        rc = efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
-                                  EFX_RX_HASHALG_TOEPLITZ,
-                                  efx_hash_types, B_TRUE);
+                                  rss->hash_alg, efx_hash_types, B_TRUE);
        if (rc != 0)
                goto fail_scale_mode_set;
 
@@ -1459,6 +1461,7 @@ fail_scale_key_set:
                sfc_err(sa, "failed to restore RSS mode");
 
 fail_scale_mode_set:
+fail_rx_hf_rte_to_efx:
        sfc_adapter_unlock(sa);
        return -rc;
 }
index f664cfa..55226f1 100644 (file)
@@ -1258,7 +1258,7 @@ sfc_flow_parse_rss(struct sfc_adapter *sa,
        struct sfc_rxq *rxq;
        unsigned int rxq_hw_index_min;
        unsigned int rxq_hw_index_max;
-       uint64_t rss_hf;
+       efx_rx_hash_type_t efx_hash_types;
        const uint8_t *rss_key;
        struct sfc_flow_rss *sfc_rss_conf = &flow->rss_conf;
        unsigned int i;
@@ -1297,9 +1297,20 @@ sfc_flow_parse_rss(struct sfc_adapter *sa,
        if (action_rss->level)
                return -EINVAL;
 
-       rss_hf = action_rss->types;
-       if ((rss_hf & ~SFC_RSS_OFFLOADS) != 0)
-               return -EINVAL;
+       if (action_rss->types) {
+               int rc;
+
+               rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
+                                         &efx_hash_types);
+               if (rc != 0)
+                       return -rc;
+       } else {
+               unsigned int i;
+
+               efx_hash_types = 0;
+               for (i = 0; i < rss->hf_map_nb_entries; ++i)
+                       efx_hash_types |= rss->hf_map[i].efx;
+       }
 
        if (action_rss->key_len) {
                if (action_rss->key_len != sizeof(rss->key))
@@ -1314,7 +1325,7 @@ sfc_flow_parse_rss(struct sfc_adapter *sa,
 
        sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
        sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
-       sfc_rss_conf->rss_hash_types = sfc_rte_to_efx_hash_type(rss_hf);
+       sfc_rss_conf->rss_hash_types = efx_hash_types;
        rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
 
        for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
@@ -1395,7 +1406,7 @@ sfc_flow_filter_insert(struct sfc_adapter *sa,
                        goto fail_scale_context_alloc;
 
                rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
-                                          EFX_RX_HASHALG_TOEPLITZ,
+                                          rss->hash_alg,
                                           flow_rss->rss_hash_types, B_TRUE);
                if (rc != 0)
                        goto fail_scale_mode_set;
index 816436a..a4aae1b 100644 (file)
@@ -1132,48 +1132,166 @@ sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index)
        rte_free(rxq);
 }
 
-efx_rx_hash_type_t
-sfc_rte_to_efx_hash_type(uint64_t rss_hf)
+/*
+ * Mapping between RTE RSS hash functions and their EFX counterparts.
+ */
+struct sfc_rss_hf_rte_to_efx sfc_rss_hf_map[] = {
+       { ETH_RSS_NONFRAG_IPV4_TCP,
+         EFX_RX_HASH(IPV4_TCP, 4TUPLE) },
+       { ETH_RSS_NONFRAG_IPV4_UDP,
+         EFX_RX_HASH(IPV4_UDP, 4TUPLE) },
+       { ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX,
+         EFX_RX_HASH(IPV6_TCP, 4TUPLE) },
+       { ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_IPV6_UDP_EX,
+         EFX_RX_HASH(IPV6_UDP, 4TUPLE) },
+       { ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | ETH_RSS_NONFRAG_IPV4_OTHER,
+         EFX_RX_HASH(IPV4_TCP, 2TUPLE) | EFX_RX_HASH(IPV4_UDP, 2TUPLE) |
+         EFX_RX_HASH(IPV4, 2TUPLE) },
+       { ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 | ETH_RSS_NONFRAG_IPV6_OTHER |
+         ETH_RSS_IPV6_EX,
+         EFX_RX_HASH(IPV6_TCP, 2TUPLE) | EFX_RX_HASH(IPV6_UDP, 2TUPLE) |
+         EFX_RX_HASH(IPV6, 2TUPLE) }
+};
+
+static efx_rx_hash_type_t
+sfc_rx_hash_types_mask_supp(efx_rx_hash_type_t hash_type,
+                           unsigned int *hash_type_flags_supported,
+                           unsigned int nb_hash_type_flags_supported)
 {
-       efx_rx_hash_type_t efx_hash_types = 0;
+       efx_rx_hash_type_t hash_type_masked = 0;
+       unsigned int i, j;
+
+       for (i = 0; i < nb_hash_type_flags_supported; ++i) {
+               unsigned int class_tuple_lbn[] = {
+                       EFX_RX_CLASS_IPV4_TCP_LBN,
+                       EFX_RX_CLASS_IPV4_UDP_LBN,
+                       EFX_RX_CLASS_IPV4_LBN,
+                       EFX_RX_CLASS_IPV6_TCP_LBN,
+                       EFX_RX_CLASS_IPV6_UDP_LBN,
+                       EFX_RX_CLASS_IPV6_LBN
+               };
+
+               for (j = 0; j < RTE_DIM(class_tuple_lbn); ++j) {
+                       unsigned int tuple_mask = EFX_RX_CLASS_HASH_4TUPLE;
+                       unsigned int flag;
+
+                       tuple_mask <<= class_tuple_lbn[j];
+                       flag = hash_type & tuple_mask;
+
+                       if (flag == hash_type_flags_supported[i])
+                               hash_type_masked |= flag;
+               }
+       }
+
+       return hash_type_masked;
+}
+
+int
+sfc_rx_hash_init(struct sfc_adapter *sa)
+{
+       struct sfc_rss *rss = &sa->rss;
+       const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
+       uint32_t alg_mask = encp->enc_rx_scale_hash_alg_mask;
+       efx_rx_hash_alg_t alg;
+       unsigned int flags_supp[EFX_RX_HASH_NFLAGS];
+       unsigned int nb_flags_supp;
+       struct sfc_rss_hf_rte_to_efx *hf_map;
+       struct sfc_rss_hf_rte_to_efx *entry;
+       efx_rx_hash_type_t efx_hash_types;
+       unsigned int i;
+       int rc;
 
-       if ((rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
-                      ETH_RSS_NONFRAG_IPV4_OTHER)) != 0)
-               efx_hash_types |= EFX_RX_HASH_IPV4;
+       if (alg_mask & (1U << EFX_RX_HASHALG_TOEPLITZ))
+               alg = EFX_RX_HASHALG_TOEPLITZ;
+       else if (alg_mask & (1U << EFX_RX_HASHALG_PACKED_STREAM))
+               alg = EFX_RX_HASHALG_PACKED_STREAM;
+       else
+               return EINVAL;
 
-       if ((rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) != 0)
-               efx_hash_types |= EFX_RX_HASH_TCPIPV4;
+       rc = efx_rx_scale_hash_flags_get(sa->nic, alg, flags_supp,
+                                        &nb_flags_supp);
+       if (rc != 0)
+               return rc;
 
-       if ((rss_hf & (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
-                       ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX)) != 0)
-               efx_hash_types |= EFX_RX_HASH_IPV6;
+       hf_map = rte_calloc_socket("sfc-rss-hf-map",
+                                  RTE_DIM(sfc_rss_hf_map),
+                                  sizeof(*hf_map), 0, sa->socket_id);
+       if (hf_map == NULL)
+               return ENOMEM;
+
+       entry = hf_map;
+       efx_hash_types = 0;
+       for (i = 0; i < RTE_DIM(sfc_rss_hf_map); ++i) {
+               efx_rx_hash_type_t ht;
+
+               ht = sfc_rx_hash_types_mask_supp(sfc_rss_hf_map[i].efx,
+                                                flags_supp, nb_flags_supp);
+               if (ht != 0) {
+                       entry->rte = sfc_rss_hf_map[i].rte;
+                       entry->efx = ht;
+                       efx_hash_types |= ht;
+                       ++entry;
+               }
+       }
 
-       if ((rss_hf & (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX)) != 0)
-               efx_hash_types |= EFX_RX_HASH_TCPIPV6;
+       rss->hash_alg = alg;
+       rss->hf_map_nb_entries = (unsigned int)(entry - hf_map);
+       rss->hf_map = hf_map;
+       rss->hash_types = efx_hash_types;
 
-       return efx_hash_types;
+       return 0;
 }
 
-uint64_t
-sfc_efx_to_rte_hash_type(efx_rx_hash_type_t efx_hash_types)
+void
+sfc_rx_hash_fini(struct sfc_adapter *sa)
 {
-       uint64_t rss_hf = 0;
+       struct sfc_rss *rss = &sa->rss;
 
-       if ((efx_hash_types & EFX_RX_HASH_IPV4) != 0)
-               rss_hf |= (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
-                          ETH_RSS_NONFRAG_IPV4_OTHER);
+       rte_free(rss->hf_map);
+}
 
-       if ((efx_hash_types & EFX_RX_HASH_TCPIPV4) != 0)
-               rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
+int
+sfc_rx_hf_rte_to_efx(struct sfc_adapter *sa, uint64_t rte,
+                    efx_rx_hash_type_t *efx)
+{
+       struct sfc_rss *rss = &sa->rss;
+       efx_rx_hash_type_t hash_types = 0;
+       unsigned int i;
 
-       if ((efx_hash_types & EFX_RX_HASH_IPV6) != 0)
-               rss_hf |= (ETH_RSS_IPV6 | ETH_RSS_FRAG_IPV6 |
-                          ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_IPV6_EX);
+       for (i = 0; i < rss->hf_map_nb_entries; ++i) {
+               uint64_t rte_mask = rss->hf_map[i].rte;
 
-       if ((efx_hash_types & EFX_RX_HASH_TCPIPV6) != 0)
-               rss_hf |= (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX);
+               if ((rte & rte_mask) != 0) {
+                       rte &= ~rte_mask;
+                       hash_types |= rss->hf_map[i].efx;
+               }
+       }
+
+       if (rte != 0) {
+               sfc_err(sa, "unsupported hash functions requested");
+               return EINVAL;
+       }
 
-       return rss_hf;
+       *efx = hash_types;
+
+       return 0;
+}
+
+uint64_t
+sfc_rx_hf_efx_to_rte(struct sfc_adapter *sa, efx_rx_hash_type_t efx)
+{
+       struct sfc_rss *rss = &sa->rss;
+       uint64_t rte = 0;
+       unsigned int i;
+
+       for (i = 0; i < rss->hf_map_nb_entries; ++i) {
+               efx_rx_hash_type_t hash_type = rss->hf_map[i].efx;
+
+               if ((efx & hash_type) == hash_type)
+                       rte |= rss->hf_map[i].rte;
+       }
+
+       return rte;
 }
 
 static int
@@ -1182,20 +1300,19 @@ sfc_rx_process_adv_conf_rss(struct sfc_adapter *sa,
 {
        struct sfc_rss *rss = &sa->rss;
        efx_rx_hash_type_t efx_hash_types = rss->hash_types;
+       uint64_t rss_hf = sfc_rx_hf_efx_to_rte(sa, efx_hash_types);
+       int rc;
 
        if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
-               if ((conf->rss_hf != 0 && conf->rss_hf != SFC_RSS_OFFLOADS) ||
+               if ((conf->rss_hf != 0 && conf->rss_hf != rss_hf) ||
                    conf->rss_key != NULL)
                        return EINVAL;
        }
 
        if (conf->rss_hf != 0) {
-               if ((conf->rss_hf & ~SFC_RSS_OFFLOADS) != 0) {
-                       sfc_err(sa, "unsupported hash functions requested");
-                       return EINVAL;
-               }
-
-               efx_hash_types = sfc_rte_to_efx_hash_type(conf->rss_hf);
+               rc = sfc_rx_hf_rte_to_efx(sa, conf->rss_hf, &efx_hash_types);
+               if (rc != 0)
+                       return rc;
        }
 
        if (conf->rss_key != NULL) {
@@ -1220,8 +1337,8 @@ sfc_rx_rss_config(struct sfc_adapter *sa)
 
        if (rss->channels > 0) {
                rc = efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
-                                          EFX_RX_HASHALG_TOEPLITZ,
-                                          rss->hash_types, B_TRUE);
+                                          rss->hash_alg, rss->hash_types,
+                                          B_TRUE);
                if (rc != 0)
                        goto finish;
 
index ea911be..d9e7b0b 100644 (file)
@@ -152,8 +152,12 @@ unsigned int sfc_rx_qdesc_npending(struct sfc_adapter *sa,
                                   unsigned int sw_index);
 int sfc_rx_qdesc_done(struct sfc_dp_rxq *dp_rxq, unsigned int offset);
 
-efx_rx_hash_type_t sfc_rte_to_efx_hash_type(uint64_t rss_hf);
-uint64_t sfc_efx_to_rte_hash_type(efx_rx_hash_type_t efx_hash_types);
+int sfc_rx_hash_init(struct sfc_adapter *sa);
+void sfc_rx_hash_fini(struct sfc_adapter *sa);
+int sfc_rx_hf_rte_to_efx(struct sfc_adapter *sa, uint64_t rte,
+                        efx_rx_hash_type_t *efx);
+uint64_t sfc_rx_hf_efx_to_rte(struct sfc_adapter *sa,
+                             efx_rx_hash_type_t efx);
 
 #ifdef __cplusplus
 }