From: Ivan Malov Date: Thu, 15 Dec 2016 12:51:17 +0000 (+0000) Subject: net/sfc: add basic stubs for RSS support on driver attach X-Git-Tag: spdx-start~4975 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=4ec1fc3ba881;p=dpdk.git net/sfc: add basic stubs for RSS support on driver attach Signed-off-by: Ivan Malov Signed-off-by: Andrew Rybchenko Reviewed-by: Andrew Lee Reviewed-by: Robert Stonehouse --- diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst index 2244e7a8a6..17e81dd2d1 100644 --- a/doc/guides/nics/sfc_efx.rst +++ b/doc/guides/nics/sfc_efx.rst @@ -69,6 +69,8 @@ SFC EFX PMD has support for: - Received packet type information +- Receive side scaling (RSS) + - Scattered Rx DMA for packet that are larger that a single Rx descriptor - Deferred receive and transmit queue start diff --git a/drivers/net/sfc/efsys.h b/drivers/net/sfc/efsys.h index 0f941e6106..fb2f3b5960 100644 --- a/drivers/net/sfc/efsys.h +++ b/drivers/net/sfc/efsys.h @@ -195,7 +195,7 @@ prefetch_read_once(const volatile void *addr) #define EFSYS_OPT_BOOTCFG 0 #define EFSYS_OPT_DIAG 0 -#define EFSYS_OPT_RX_SCALE 0 +#define EFSYS_OPT_RX_SCALE 1 #define EFSYS_OPT_QSTATS 0 /* Filters support is required for SFN7xxx and SFN8xx */ #define EFSYS_OPT_FILTER 1 diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c index f884a2193e..22426fae73 100644 --- a/drivers/net/sfc/sfc.c +++ b/drivers/net/sfc/sfc.c @@ -484,6 +484,73 @@ sfc_mem_bar_fini(struct sfc_adapter *sa) memset(ebp, 0, sizeof(*ebp)); } +#if EFSYS_OPT_RX_SCALE +/* + * A fixed RSS key which has a property of being symmetric + * (symmetrical flows are distributed to the same CPU) + * and also known to give a uniform distribution + * (a good distribution of traffic between different CPUs) + */ +static const uint8_t default_rss_key[SFC_RSS_KEY_SIZE] = { + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, + 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, 0x6d, 0x5a, +}; +#endif + +static int +sfc_set_rss_defaults(struct sfc_adapter *sa) +{ +#if EFSYS_OPT_RX_SCALE + int rc; + + rc = efx_intr_init(sa->nic, sa->intr.type, NULL); + if (rc != 0) + goto fail_intr_init; + + rc = efx_ev_init(sa->nic); + if (rc != 0) + goto fail_ev_init; + + rc = efx_rx_init(sa->nic); + if (rc != 0) + goto fail_rx_init; + + rc = efx_rx_scale_support_get(sa->nic, &sa->rss_support); + if (rc != 0) + goto fail_scale_support_get; + + rc = efx_rx_hash_support_get(sa->nic, &sa->hash_support); + if (rc != 0) + goto fail_hash_support_get; + + efx_rx_fini(sa->nic); + efx_ev_fini(sa->nic); + efx_intr_fini(sa->nic); + + sa->rss_hash_types = sfc_rte_to_efx_hash_type(SFC_RSS_OFFLOADS); + + rte_memcpy(sa->rss_key, default_rss_key, sizeof(sa->rss_key)); + + return 0; + +fail_hash_support_get: +fail_scale_support_get: +fail_rx_init: + efx_ev_fini(sa->nic); + +fail_ev_init: + efx_intr_fini(sa->nic); + +fail_intr_init: + return rc; +#else + return 0; +#endif +} + int sfc_attach(struct sfc_adapter *sa) { @@ -550,6 +617,10 @@ sfc_attach(struct sfc_adapter *sa) efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_PERM, &sa->port.phy_adv_cap_mask); + rc = sfc_set_rss_defaults(sa); + if (rc != 0) + goto fail_set_rss_defaults; + sfc_log_init(sa, "fini nic"); efx_nic_fini(enp); @@ -558,7 +629,12 @@ sfc_attach(struct sfc_adapter *sa) sfc_log_init(sa, "done"); return 0; +fail_set_rss_defaults: + sfc_intr_detach(sa); + fail_intr_attach: + efx_nic_fini(sa->nic); + fail_estimate_rsrc_limits: fail_nic_reset: sfc_log_init(sa, "unprobe nic"); diff --git a/drivers/net/sfc/sfc.h b/drivers/net/sfc/sfc.h index 26958dbe5d..33445196bc 100644 --- a/drivers/net/sfc/sfc.h +++ b/drivers/net/sfc/sfc.h @@ -45,6 +45,13 @@ extern "C" { #define SFC_DEV_TO_PCI(eth_dev) \ RTE_DEV_TO_PCI((eth_dev)->device) +#if EFSYS_OPT_RX_SCALE +/** RSS key length (bytes) */ +#define SFC_RSS_KEY_SIZE 40 +/** RSS hash offloads mask */ +#define SFC_RSS_OFFLOADS (ETH_RSS_IP | ETH_RSS_TCP) +#endif + /* * +---------------+ * | UNINITIALIZED |<-----------+ @@ -190,6 +197,16 @@ struct sfc_adapter { unsigned int txq_count; struct sfc_txq_info *txq_info; + + unsigned int rss_channels; + +#if EFSYS_OPT_RX_SCALE + efx_rx_scale_support_t rss_support; + efx_rx_hash_support_t hash_support; + efx_rx_hash_type_t rss_hash_types; + unsigned int rss_tbl[EFX_RSS_TBL_SIZE]; + uint8_t rss_key[SFC_RSS_KEY_SIZE]; +#endif }; /* diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c index 47ccd1694c..ed2d9e0053 100644 --- a/drivers/net/sfc/sfc_ethdev.c +++ b/drivers/net/sfc/sfc_ethdev.c @@ -84,6 +84,14 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) else dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_VLAN_INSERT; +#if EFSYS_OPT_RX_SCALE + if (sa->rss_support != EFX_RX_SCALE_UNAVAILABLE) { + dev_info->reta_size = EFX_RSS_TBL_SIZE; + dev_info->hash_key_size = SFC_RSS_KEY_SIZE; + dev_info->flow_type_rss_offloads = SFC_RSS_OFFLOADS; + } +#endif + dev_info->rx_desc_lim.nb_max = EFX_RXQ_MAXNDESCS; dev_info->rx_desc_lim.nb_min = EFX_RXQ_MINNDESCS; /* The RXQ hardware requires that the descriptor count is a power diff --git a/drivers/net/sfc/sfc_rx.c b/drivers/net/sfc/sfc_rx.c index 3bfce1cdd5..36a7d71109 100644 --- a/drivers/net/sfc/sfc_rx.c +++ b/drivers/net/sfc/sfc_rx.c @@ -411,7 +411,8 @@ sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index) if (sw_index == 0) { rc = efx_mac_filter_default_rxq_set(sa->nic, rxq->common, - B_FALSE); + (sa->rss_channels > 1) ? + B_TRUE : B_FALSE); if (rc != 0) goto fail_mac_filter_default_rxq_set; } @@ -683,6 +684,11 @@ sfc_rx_qinit(struct sfc_adapter *sa, unsigned int sw_index, rxq->batch_max = encp->enc_rx_batch_max; rxq->prefix_size = encp->enc_rx_prefix_size; +#if EFSYS_OPT_RX_SCALE + if (sa->hash_support == EFX_RX_HASH_AVAILABLE) + rxq->flags |= SFC_RXQ_RSS_HASH; +#endif + rxq->state = SFC_RXQ_INITIALIZED; rxq_info->rxq = rxq; @@ -728,6 +734,56 @@ sfc_rx_qfini(struct sfc_adapter *sa, unsigned int sw_index) rte_free(rxq); } +#if EFSYS_OPT_RX_SCALE +efx_rx_hash_type_t +sfc_rte_to_efx_hash_type(uint64_t rss_hf) +{ + efx_rx_hash_type_t efx_hash_types = 0; + + if ((rss_hf & (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 | + ETH_RSS_NONFRAG_IPV4_OTHER)) != 0) + efx_hash_types |= EFX_RX_HASH_IPV4; + + if ((rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) != 0) + efx_hash_types |= EFX_RX_HASH_TCPIPV4; + + 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; + + if ((rss_hf & (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX)) != 0) + efx_hash_types |= EFX_RX_HASH_TCPIPV6; + + return efx_hash_types; +} +#endif + +static int +sfc_rx_rss_config(struct sfc_adapter *sa) +{ + int rc = 0; + +#if EFSYS_OPT_RX_SCALE + if (sa->rss_channels > 1) { + rc = efx_rx_scale_mode_set(sa->nic, EFX_RX_HASHALG_TOEPLITZ, + sa->rss_hash_types, B_TRUE); + if (rc != 0) + goto finish; + + rc = efx_rx_scale_key_set(sa->nic, sa->rss_key, + sizeof(sa->rss_key)); + if (rc != 0) + goto finish; + + rc = efx_rx_scale_tbl_set(sa->nic, sa->rss_tbl, + sizeof(sa->rss_tbl)); + } + +finish: +#endif + return rc; +} + int sfc_rx_start(struct sfc_adapter *sa) { @@ -740,6 +796,10 @@ sfc_rx_start(struct sfc_adapter *sa) if (rc != 0) goto fail_rx_init; + rc = sfc_rx_rss_config(sa); + if (rc != 0) + goto fail_rss_config; + for (sw_index = 0; sw_index < sa->rxq_count; ++sw_index) { if ((!sa->rxq_info[sw_index].deferred_start || sa->rxq_info[sw_index].deferred_started)) { @@ -755,6 +815,7 @@ fail_rx_qstart: while (sw_index-- > 0) sfc_rx_qstop(sa, sw_index); +fail_rss_config: efx_rx_fini(sa->nic); fail_rx_init: @@ -801,6 +862,14 @@ sfc_rx_check_mode(struct sfc_adapter *sa, struct rte_eth_rxmode *rxmode) case ETH_MQ_RX_NONE: /* No special checks are required */ break; +#if EFSYS_OPT_RX_SCALE + case ETH_MQ_RX_RSS: + if (sa->rss_support == EFX_RX_SCALE_UNAVAILABLE) { + sfc_err(sa, "RSS is not available"); + rc = EINVAL; + } + break; +#endif default: sfc_err(sa, "Rx multi-queue mode %u not supported", rxmode->mq_mode); @@ -876,6 +945,16 @@ sfc_rx_init(struct sfc_adapter *sa) goto fail_rx_qinit_info; } +#if EFSYS_OPT_RX_SCALE + sa->rss_channels = (dev_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) ? + MIN(sa->rxq_count, EFX_MAXRSS) : 1; + + if (sa->rss_channels > 1) { + for (sw_index = 0; sw_index < EFX_RSS_TBL_SIZE; ++sw_index) + sa->rss_tbl[sw_index] = sw_index % sa->rss_channels; + } +#endif + return 0; fail_rx_qinit_info: diff --git a/drivers/net/sfc/sfc_rx.h b/drivers/net/sfc/sfc_rx.h index 4aa6aeacb9..c0cb17a703 100644 --- a/drivers/net/sfc/sfc_rx.h +++ b/drivers/net/sfc/sfc_rx.h @@ -83,6 +83,10 @@ struct sfc_rxq { unsigned int completed; uint16_t batch_max; uint16_t prefix_size; +#if EFSYS_OPT_RX_SCALE + unsigned int flags; +#define SFC_RXQ_RSS_HASH 0x1 +#endif /* Used on refill */ unsigned int added; @@ -146,6 +150,10 @@ unsigned int sfc_rx_qdesc_npending(struct sfc_adapter *sa, unsigned int sw_index); int sfc_rx_qdesc_done(struct sfc_rxq *rxq, unsigned int offset); +#if EFSYS_OPT_RX_SCALE +efx_rx_hash_type_t sfc_rte_to_efx_hash_type(uint64_t rss_hf); +#endif + #ifdef __cplusplus } #endif