From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dispatch1-us1.ppe-hosted.com (dispatch1-us1.ppe-hosted.com [67.231.154.164]) by dpdk.org (Postfix) with ESMTP id 2D534D08E for ; Thu, 19 Apr 2018 18:42:15 +0200 (CEST) X-Virus-Scanned: Proofpoint Essentials engine Received: from webmail.solarflare.com (webmail.solarflare.com [12.187.104.26]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1-us3.ppe-hosted.com (Proofpoint Essentials ESMTP Server) with ESMTPS id DF145B8005A; Thu, 19 Apr 2018 16:42:13 +0000 (UTC) Received: from sfocexch01r.SolarFlarecom.com (10.20.40.34) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 19 Apr 2018 09:42:11 -0700 Received: from ocex03.SolarFlarecom.com (10.20.40.36) by sfocexch01r.SolarFlarecom.com (10.20.40.34) with Microsoft SMTP Server (TLS) id 15.0.1044.25; Thu, 19 Apr 2018 09:42:00 -0700 Received: from opal.uk.solarflarecom.com (10.17.10.1) by ocex03.SolarFlarecom.com (10.20.40.36) with Microsoft SMTP Server (TLS) id 15.0.1044.25 via Frontend Transport; Thu, 19 Apr 2018 09:41:59 -0700 Received: from uklogin.uk.solarflarecom.com (uklogin.uk.solarflarecom.com [10.17.10.10]) by opal.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w3JGfwiG016195; Thu, 19 Apr 2018 17:41:58 +0100 Received: from uklogin.uk.solarflarecom.com (localhost.localdomain [127.0.0.1]) by uklogin.uk.solarflarecom.com (8.13.8/8.13.8) with ESMTP id w3JGfwn8028658; Thu, 19 Apr 2018 17:41:58 +0100 From: Andrew Rybchenko To: CC: Ivan Malov Date: Thu, 19 Apr 2018 17:41:52 +0100 Message-ID: <1524156112-28615-9-git-send-email-arybchenko@solarflare.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1524156112-28615-1-git-send-email-arybchenko@solarflare.com> References: <1523035280-24873-1-git-send-email-arybchenko@solarflare.com> <1524156112-28615-1-git-send-email-arybchenko@solarflare.com> MIME-Version: 1.0 Content-Type: text/plain X-MDID: 1524156134-1HsaiVNtAbvT Subject: [dpdk-dev] [PATCH v2 8/8] net/sfc: convert to the advanced EFX RSS interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Apr 2018 16:42:15 -0000 From: Ivan Malov 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 Signed-off-by: Andrew Rybchenko --- drivers/net/sfc/sfc.c | 24 ++++-- drivers/net/sfc/sfc.h | 12 ++- drivers/net/sfc/sfc_ethdev.c | 23 +++--- drivers/net/sfc/sfc_flow.c | 23 ++++-- drivers/net/sfc/sfc_rx.c | 191 ++++++++++++++++++++++++++++++++++--------- drivers/net/sfc/sfc_rx.h | 8 +- 6 files changed, 217 insertions(+), 64 deletions(-) diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index 1066a5e..37248bc 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -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 @@ sfc_set_rss_defaults(struct sfc_adapter *sa) 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); diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 9c76d7f..3a5f6dc 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -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]; diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 359d6d2..35a8301 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -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 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev, sfc_err(sa, "failed to restore RSS mode"); fail_scale_mode_set: +fail_rx_hf_rte_to_efx: sfc_adapter_unlock(sa); return -rc; } diff --git a/drivers/net/sfc/sfc_flow.c b/drivers/net/sfc/sfc_flow.c index f664cfa..55226f1 100644 --- a/drivers/net/sfc/sfc_flow.c +++ b/drivers/net/sfc/sfc_flow.c @@ -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; diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 816436a..a4aae1b 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -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; diff --git a/drivers/net/sfc/sfc_rx.h b/drivers/net/sfc/sfc_rx.h index ea911be..d9e7b0b 100644 --- a/drivers/net/sfc/sfc_rx.h +++ b/drivers/net/sfc/sfc_rx.h @@ -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 } -- 2.7.4