net/sfc: add basic stubs for RSS support on driver attach
authorIvan Malov <ivan.malov@oktetlabs.ru>
Thu, 15 Dec 2016 12:51:17 +0000 (12:51 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 17 Jan 2017 18:40:50 +0000 (19:40 +0100)
Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
Reviewed-by: Robert Stonehouse <rstonehouse@solarflare.com>
doc/guides/nics/sfc_efx.rst
drivers/net/sfc/efsys.h
drivers/net/sfc/sfc.c
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_rx.c
drivers/net/sfc/sfc_rx.h

index 2244e7a..17e81dd 100644 (file)
@@ -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
index 0f941e6..fb2f3b5 100644 (file)
@@ -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
index f884a21..22426fa 100644 (file)
@@ -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");
index 26958db..3344519 100644 (file)
@@ -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
 };
 
 /*
index 47ccd16..ed2d9e0 100644 (file)
@@ -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
index 3bfce1c..36a7d71 100644 (file)
@@ -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:
index 4aa6aea..c0cb17a 100644 (file)
@@ -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