New upstream version 18.02
[deb_dpdk.git] / drivers / net / sfc / base / efx_filter.c
index ba31026..b92541a 100644 (file)
@@ -1,31 +1,7 @@
-/*
- * Copyright (c) 2007-2016 Solarflare Communications Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
  *
- * The views and conclusions contained in the software and documentation are
- * those of the authors and should not be interpreted as representing official
- * policies, either expressed or implied, of the FreeBSD Project.
+ * Copyright (c) 2007-2018 Solarflare Communications Inc.
+ * All rights reserved.
  */
 
 #include "efx.h"
@@ -117,10 +93,6 @@ efx_filter_remove(
        EFSYS_ASSERT3P(spec, !=, NULL);
        EFSYS_ASSERT3U(spec->efs_flags, &, EFX_FILTER_FLAG_RX);
 
-#if EFSYS_OPT_RX_SCALE
-       spec->efs_rss_context = enp->en_rss_context;
-#endif
-
        return (efop->efo_delete(enp, spec));
 }
 
@@ -302,7 +274,7 @@ efx_filter_spec_init_rx(
        memset(spec, 0, sizeof (*spec));
        spec->efs_priority = priority;
        spec->efs_flags = EFX_FILTER_FLAG_RX | flags;
-       spec->efs_rss_context = EFX_FILTER_SPEC_RSS_CONTEXT_DEFAULT;
+       spec->efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
        spec->efs_dmaq_id = (uint16_t)erp->er_index;
 }
 
@@ -396,6 +368,17 @@ efx_filter_spec_set_eth_local(
        return (0);
 }
 
+                       void
+efx_filter_spec_set_ether_type(
+       __inout         efx_filter_spec_t *spec,
+       __in            uint16_t ether_type)
+{
+       EFSYS_ASSERT3P(spec, !=, NULL);
+
+       spec->efs_ether_type = ether_type;
+       spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
+}
+
 /*
  * Specify matching otherwise-unmatched unicast in a filter specification
  */
@@ -423,6 +406,88 @@ efx_filter_spec_set_mc_def(
 }
 
 
+__checkReturn          efx_rc_t
+efx_filter_spec_set_encap_type(
+       __inout         efx_filter_spec_t *spec,
+       __in            efx_tunnel_protocol_t encap_type,
+       __in            efx_filter_inner_frame_match_t inner_frame_match)
+{
+       uint32_t match_flags = 0;
+       uint8_t ip_proto;
+       efx_rc_t rc;
+
+       EFSYS_ASSERT3P(spec, !=, NULL);
+
+       switch (encap_type) {
+       case EFX_TUNNEL_PROTOCOL_VXLAN:
+       case EFX_TUNNEL_PROTOCOL_GENEVE:
+               ip_proto = EFX_IPPROTO_UDP;
+               break;
+       case EFX_TUNNEL_PROTOCOL_NVGRE:
+               ip_proto = EFX_IPPROTO_GRE;
+               break;
+       default:
+               EFSYS_ASSERT(0);
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       switch (inner_frame_match) {
+       case EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_MCAST_DST:
+               match_flags |= EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
+               break;
+       case EFX_FILTER_INNER_FRAME_MATCH_UNKNOWN_UCAST_DST:
+               match_flags |= EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST;
+               break;
+       case EFX_FILTER_INNER_FRAME_MATCH_OTHER:
+               /* This is for when specific inner frames are to be matched. */
+               break;
+       default:
+               EFSYS_ASSERT(0);
+               rc = EINVAL;
+               goto fail2;
+       }
+
+       spec->efs_encap_type = encap_type;
+       spec->efs_ip_proto = ip_proto;
+       spec->efs_match_flags |= (match_flags | EFX_FILTER_MATCH_IP_PROTO);
+
+       return (0);
+
+fail2:
+       EFSYS_PROBE(fail2);
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+       return (rc);
+}
+
+#if EFSYS_OPT_RX_SCALE
+       __checkReturn   efx_rc_t
+efx_filter_spec_set_rss_context(
+       __inout         efx_filter_spec_t *spec,
+       __in            uint32_t rss_context)
+{
+       efx_rc_t rc;
+
+       EFSYS_ASSERT3P(spec, !=, NULL);
+
+       /* The filter must have been created with EFX_FILTER_FLAG_RX_RSS. */
+       if ((spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) == 0) {
+               rc = EINVAL;
+               goto fail1;
+       }
+
+       spec->efs_rss_context = rss_context;
+
+       return (0);
+
+fail1:
+       EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+       return (rc);
+}
+#endif
 
 #if EFSYS_OPT_SIENA
 
@@ -454,9 +519,9 @@ siena_filter_spec_from_gen_spec(
        else
                EFSYS_ASSERT3U(gen_spec->efs_flags, &, EFX_FILTER_FLAG_RX);
 
-       /* Falconsiena only has one RSS context */
+       /* Siena only has one RSS context */
        if ((gen_spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) &&
-           gen_spec->efs_rss_context != 0) {
+           gen_spec->efs_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
                rc = EINVAL;
                goto fail1;
        }