net/sfc/base: add equal stride super-buffer prefix layout
[dpdk.git] / drivers / net / sfc / base / ef10_filter.c
index 2dd823b..bf4992e 100644 (file)
@@ -1,37 +1,13 @@
-/*
- * 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"
 #include "efx_impl.h"
 
-#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD
+#if EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2
 
 #if EFSYS_OPT_FILTER
 
@@ -119,7 +95,8 @@ ef10_filter_init(
        ef10_filter_table_t *eftp;
 
        EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
-                   enp->en_family == EFX_FAMILY_MEDFORD);
+           enp->en_family == EFX_FAMILY_MEDFORD ||
+           enp->en_family == EFX_FAMILY_MEDFORD2);
 
 #define        MATCH_MASK(match) (EFX_MASK32(match) << EFX_LOW_BIT(match))
        EFX_STATIC_ASSERT(EFX_FILTER_MATCH_REM_HOST ==
@@ -142,6 +119,10 @@ ef10_filter_init(
            MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_OUTER_VLAN));
        EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IP_PROTO ==
            MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO));
+       EFX_STATIC_ASSERT(EFX_FILTER_MATCH_VNI_OR_VSID ==
+           MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_VNI_OR_VSID));
+       EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_LOC_MAC ==
+           MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_DST_MAC));
        EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST ==
            MATCH_MASK(MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST));
        EFX_STATIC_ASSERT(EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST ==
@@ -174,7 +155,8 @@ ef10_filter_fini(
        __in            efx_nic_t *enp)
 {
        EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
-                   enp->en_family == EFX_FAMILY_MEDFORD);
+           enp->en_family == EFX_FAMILY_MEDFORD ||
+           enp->en_family == EFX_FAMILY_MEDFORD2);
 
        if (enp->en_filter.ef_ef10_filter_table != NULL) {
                EFSYS_KMEM_FREE(enp->en_esip, sizeof (ef10_filter_table_t),
@@ -192,6 +174,7 @@ efx_mcdi_filter_op_add(
        efx_mcdi_req_t req;
        uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
                            MC_CMD_FILTER_OP_EXT_OUT_LEN)];
+       efx_filter_match_flags_t match_flags;
        efx_rc_t rc;
 
        memset(payload, 0, sizeof (payload));
@@ -201,6 +184,12 @@ efx_mcdi_filter_op_add(
        req.emr_out_buf = payload;
        req.emr_out_length = MC_CMD_FILTER_OP_EXT_OUT_LEN;
 
+       /*
+        * Remove match flag for encapsulated filters that does not correspond
+        * to the MCDI match flags
+        */
+       match_flags = spec->efs_match_flags & ~EFX_FILTER_MATCH_ENCAP_TYPE;
+
        switch (filter_op) {
        case MC_CMD_FILTER_OP_IN_OP_REPLACE:
                MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_HANDLE_LO,
@@ -221,11 +210,16 @@ efx_mcdi_filter_op_add(
        MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_PORT_ID,
            EVB_PORT_ID_ASSIGNED);
        MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_MATCH_FIELDS,
-           spec->efs_match_flags);
-       MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
-           MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
-       MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
-           spec->efs_dmaq_id);
+           match_flags);
+       if (spec->efs_dmaq_id == EFX_FILTER_SPEC_RX_DMAQ_ID_DROP) {
+               MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
+                   MC_CMD_FILTER_OP_EXT_IN_RX_DEST_DROP);
+       } else {
+               MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_DEST,
+                   MC_CMD_FILTER_OP_EXT_IN_RX_DEST_HOST);
+               MCDI_IN_SET_DWORD(req, FILTER_OP_EXT_IN_RX_QUEUE,
+                   spec->efs_dmaq_id);
+       }
 
 #if EFSYS_OPT_RX_SCALE
        if (spec->efs_flags & EFX_FILTER_FLAG_RX_RSS) {
@@ -314,6 +308,12 @@ efx_mcdi_filter_op_add(
                        rc = EINVAL;
                        goto fail2;
                }
+
+               memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_VNI_OR_VSID),
+                   spec->efs_vni_or_vsid, EFX_VNI_OR_VSID_LEN);
+
+               memcpy(MCDI_IN2(req, uint8_t, FILTER_OP_EXT_IN_IFRM_DST_MAC),
+                   spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
        }
 
        efx_mcdi_execute(enp, &req);
@@ -437,6 +437,12 @@ ef10_filter_equal(
                return (B_FALSE);
        if (left->efs_encap_type != right->efs_encap_type)
                return (B_FALSE);
+       if (memcmp(left->efs_vni_or_vsid, right->efs_vni_or_vsid,
+           EFX_VNI_OR_VSID_LEN))
+               return (B_FALSE);
+       if (memcmp(left->efs_ifrm_loc_mac, right->efs_ifrm_loc_mac,
+           EFX_MAC_ADDR_LEN))
+               return (B_FALSE);
 
        return (B_TRUE);
 
@@ -519,7 +525,8 @@ ef10_filter_restore(
        efx_rc_t rc;
 
        EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
-                   enp->en_family == EFX_FAMILY_MEDFORD);
+           enp->en_family == EFX_FAMILY_MEDFORD ||
+           enp->en_family == EFX_FAMILY_MEDFORD2);
 
        for (tbl_id = 0; tbl_id < EFX_EF10_FILTER_TBL_ROWS; tbl_id++) {
 
@@ -594,7 +601,8 @@ ef10_filter_add_internal(
        boolean_t locked = B_FALSE;
 
        EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
-                   enp->en_family == EFX_FAMILY_MEDFORD);
+           enp->en_family == EFX_FAMILY_MEDFORD ||
+           enp->en_family == EFX_FAMILY_MEDFORD2);
 
        hash = ef10_filter_hash(spec);
 
@@ -866,7 +874,8 @@ ef10_filter_delete(
        boolean_t locked = B_FALSE;
 
        EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON ||
-                   enp->en_family == EFX_FAMILY_MEDFORD);
+           enp->en_family == EFX_FAMILY_MEDFORD ||
+           enp->en_family == EFX_FAMILY_MEDFORD2);
 
        hash = ef10_filter_hash(spec);
 
@@ -914,6 +923,7 @@ efx_mcdi_get_parser_disp_info(
        __in                            efx_nic_t *enp,
        __out_ecount(buffer_length)     uint32_t *buffer,
        __in                            size_t buffer_length,
+       __in                            boolean_t encap,
        __out                           size_t *list_lengthp)
 {
        efx_mcdi_req_t req;
@@ -930,7 +940,8 @@ efx_mcdi_get_parser_disp_info(
        req.emr_out_buf = payload;
        req.emr_out_length = MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX;
 
-       MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP,
+       MCDI_IN_SET_DWORD(req, GET_PARSER_DISP_INFO_OUT_OP, encap ?
+           MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
            MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
 
        efx_mcdi_execute(enp, &req);
@@ -990,28 +1001,76 @@ ef10_filter_supported_filters(
        __in                            size_t buffer_length,
        __out                           size_t *list_lengthp)
 {
-
+       efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
        size_t mcdi_list_length;
+       size_t mcdi_encap_list_length;
        size_t list_length;
        uint32_t i;
+       uint32_t next_buf_idx;
+       size_t next_buf_length;
        efx_rc_t rc;
-       uint32_t all_filter_flags =
+       boolean_t no_space = B_FALSE;
+       efx_filter_match_flags_t all_filter_flags =
            (EFX_FILTER_MATCH_REM_HOST | EFX_FILTER_MATCH_LOC_HOST |
            EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_REM_PORT |
            EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_PORT |
            EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_INNER_VID |
            EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_IP_PROTO |
+           EFX_FILTER_MATCH_VNI_OR_VSID |
+           EFX_FILTER_MATCH_IFRM_LOC_MAC |
+           EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST |
+           EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST |
+           EFX_FILTER_MATCH_ENCAP_TYPE |
            EFX_FILTER_MATCH_UNKNOWN_MCAST_DST |
            EFX_FILTER_MATCH_UNKNOWN_UCAST_DST);
 
-       rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length,
-                                           &mcdi_list_length);
+       /*
+        * Two calls to MC_CMD_GET_PARSER_DISP_INFO are needed: one to get the
+        * list of supported filters for ordinary packets, and then another to
+        * get the list of supported filters for encapsulated packets. To
+        * distinguish the second list from the first, the
+        * EFX_FILTER_MATCH_ENCAP_TYPE flag is added to each filter for
+        * encapsulated packets.
+        */
+       rc = efx_mcdi_get_parser_disp_info(enp, buffer, buffer_length, B_FALSE,
+           &mcdi_list_length);
        if (rc != 0) {
-               if (rc == ENOSPC) {
-                       /* Pass through mcdi_list_length for the list length */
-                       *list_lengthp = mcdi_list_length;
+               if (rc == ENOSPC)
+                       no_space = B_TRUE;
+               else
+                       goto fail1;
+       }
+
+       if (no_space) {
+               next_buf_idx = 0;
+               next_buf_length = 0;
+       } else {
+               EFSYS_ASSERT(mcdi_list_length <= buffer_length);
+               next_buf_idx = mcdi_list_length;
+               next_buf_length = buffer_length - mcdi_list_length;
+       }
+
+       if (encp->enc_tunnel_encapsulations_supported != 0) {
+               rc = efx_mcdi_get_parser_disp_info(enp, &buffer[next_buf_idx],
+                   next_buf_length, B_TRUE, &mcdi_encap_list_length);
+               if (rc != 0) {
+                       if (rc == ENOSPC)
+                               no_space = B_TRUE;
+                       else
+                               goto fail2;
+               } else {
+                       for (i = next_buf_idx;
+                           i < next_buf_idx + mcdi_encap_list_length; i++)
+                               buffer[i] |= EFX_FILTER_MATCH_ENCAP_TYPE;
                }
-               goto fail1;
+       } else {
+               mcdi_encap_list_length = 0;
+       }
+
+       if (no_space) {
+               *list_lengthp = mcdi_list_length + mcdi_encap_list_length;
+               rc = ENOSPC;
+               goto fail3;
        }
 
        /*
@@ -1024,9 +1083,10 @@ ef10_filter_supported_filters(
         * of the matches is preserved as they are ordered from highest to
         * lowest priority.
         */
-       EFSYS_ASSERT(mcdi_list_length <= buffer_length);
+       EFSYS_ASSERT(mcdi_list_length + mcdi_encap_list_length <=
+           buffer_length);
        list_length = 0;
-       for (i = 0; i < mcdi_list_length; i++) {
+       for (i = 0; i < mcdi_list_length + mcdi_encap_list_length; i++) {
                if ((buffer[i] & ~all_filter_flags) == 0) {
                        buffer[list_length] = buffer[i];
                        list_length++;
@@ -1037,6 +1097,10 @@ ef10_filter_supported_filters(
 
        return (0);
 
+fail3:
+       EFSYS_PROBE(fail3);
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
@@ -1660,4 +1724,4 @@ ef10_filter_default_rxq_clear(
 
 #endif /* EFSYS_OPT_FILTER */
 
-#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD */
+#endif /* EFSYS_OPT_HUNTINGTON || EFSYS_OPT_MEDFORD || EFSYS_OPT_MEDFORD2 */