net/sfc: add missing BSD license line and update year
[dpdk.git] / drivers / net / sfc / sfc_rx.c
index 36a7d71..214e640 100644 (file)
@@ -1,5 +1,7 @@
 /*-
- * Copyright (c) 2016 Solarflare Communications Inc.
+ *   BSD LICENSE
+ *
+ * Copyright (c) 2016-2017 Solarflare Communications Inc.
  * All rights reserved.
  *
  * This software was jointly developed between OKTET Labs (under contract
@@ -185,6 +187,28 @@ sfc_rx_desc_flags_to_packet_type(const unsigned int desc_flags)
                ((desc_flags & EFX_PKT_UDP) ? RTE_PTYPE_L4_UDP : 0);
 }
 
+static void
+sfc_rx_set_rss_hash(struct sfc_rxq *rxq, unsigned int flags, struct rte_mbuf *m)
+{
+#if EFSYS_OPT_RX_SCALE
+       uint8_t *mbuf_data;
+
+
+       if ((rxq->flags & SFC_RXQ_RSS_HASH) == 0)
+               return;
+
+       mbuf_data = rte_pktmbuf_mtod(m, uint8_t *);
+
+       if (flags & (EFX_PKT_IPV4 | EFX_PKT_IPV6)) {
+               m->hash.rss = efx_pseudo_hdr_hash_get(rxq->common,
+                                                     EFX_RX_HASHALG_TOEPLITZ,
+                                                     mbuf_data);
+
+               m->ol_flags |= PKT_RX_RSS_HASH;
+       }
+#endif
+}
+
 uint16_t
 sfc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 {
@@ -231,7 +255,6 @@ sfc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                        seg_len = rxd->size - prefix_size;
                }
 
-               m->data_off += prefix_size;
                rte_pktmbuf_data_len(m) = seg_len;
                rte_pktmbuf_pkt_len(m) = seg_len;
 
@@ -261,6 +284,14 @@ sfc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                m->ol_flags = sfc_rx_desc_flags_to_offload_flags(desc_flags);
                m->packet_type = sfc_rx_desc_flags_to_packet_type(desc_flags);
 
+               /*
+                * Extract RSS hash from the packet prefix and
+                * set the corresponding field (if needed and possible)
+                */
+               sfc_rx_set_rss_hash(rxq, desc_flags, m);
+
+               m->data_off += prefix_size;
+
                *rx_pkts++ = m;
                done_pkts++;
                continue;
@@ -372,6 +403,56 @@ sfc_rx_qflush(struct sfc_adapter *sa, unsigned int sw_index)
        sfc_rx_qpurge(rxq);
 }
 
+static int
+sfc_rx_default_rxq_set_filter(struct sfc_adapter *sa, struct sfc_rxq *rxq)
+{
+       boolean_t rss = (sa->rss_channels > 1) ? B_TRUE : B_FALSE;
+       struct sfc_port *port = &sa->port;
+       int rc;
+
+       /*
+        * If promiscuous or all-multicast mode has been requested, setting
+        * filter for the default Rx queue might fail, in particular, while
+        * running over PCI function which is not a member of corresponding
+        * privilege groups; if this occurs, few iterations will be made to
+        * repeat this step without promiscuous and all-multicast flags set
+        */
+retry:
+       rc = efx_mac_filter_default_rxq_set(sa->nic, rxq->common, rss);
+       if (rc == 0)
+               return 0;
+       else if (rc != EOPNOTSUPP)
+               return rc;
+
+       if (port->promisc) {
+               sfc_warn(sa, "promiscuous mode has been requested, "
+                            "but the HW rejects it");
+               sfc_warn(sa, "promiscuous mode will be disabled");
+
+               port->promisc = B_FALSE;
+               rc = sfc_set_rx_mode(sa);
+               if (rc != 0)
+                       return rc;
+
+               goto retry;
+       }
+
+       if (port->allmulti) {
+               sfc_warn(sa, "all-multicast mode has been requested, "
+                            "but the HW rejects it");
+               sfc_warn(sa, "all-multicast mode will be disabled");
+
+               port->allmulti = B_FALSE;
+               rc = sfc_set_rx_mode(sa);
+               if (rc != 0)
+                       return rc;
+
+               goto retry;
+       }
+
+       return rc;
+}
+
 int
 sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
 {
@@ -410,9 +491,7 @@ sfc_rx_qstart(struct sfc_adapter *sa, unsigned int sw_index)
        sfc_rx_qrefill(rxq);
 
        if (sw_index == 0) {
-               rc = efx_mac_filter_default_rxq_set(sa->nic, rxq->common,
-                                                   (sa->rss_channels > 1) ?
-                                                   B_TRUE : B_FALSE);
+               rc = sfc_rx_default_rxq_set_filter(sa, rxq);
                if (rc != 0)
                        goto fail_mac_filter_default_rxq_set;
        }
@@ -756,6 +835,28 @@ sfc_rte_to_efx_hash_type(uint64_t rss_hf)
 
        return efx_hash_types;
 }
+
+uint64_t
+sfc_efx_to_rte_hash_type(efx_rx_hash_type_t efx_hash_types)
+{
+       uint64_t rss_hf = 0;
+
+       if ((efx_hash_types & EFX_RX_HASH_IPV4) != 0)
+               rss_hf |= (ETH_RSS_IPV4 | ETH_RSS_FRAG_IPV4 |
+                          ETH_RSS_NONFRAG_IPV4_OTHER);
+
+       if ((efx_hash_types & EFX_RX_HASH_TCPIPV4) != 0)
+               rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
+
+       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);
+
+       if ((efx_hash_types & EFX_RX_HASH_TCPIPV6) != 0)
+               rss_hf |= (ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_IPV6_TCP_EX);
+
+       return rss_hf;
+}
 #endif
 
 static int