net/sfc/base: fix a typo in unicast filter insertion comment
[dpdk.git] / drivers / net / sfc / base / ef10_filter.c
index e93dc13..afe4064 100644 (file)
@@ -172,17 +172,23 @@ efx_mcdi_filter_op_add(
        __inout         ef10_filter_handle_t *handle)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
-                           MC_CMD_FILTER_OP_EXT_OUT_LEN)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_V3_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));
        req.emr_cmd = MC_CMD_FILTER_OP;
        req.emr_in_buf = payload;
-       req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
+       req.emr_in_length = MC_CMD_FILTER_OP_V3_IN_LEN;
        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,
@@ -203,11 +209,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) {
@@ -304,16 +315,37 @@ efx_mcdi_filter_op_add(
                    spec->efs_ifrm_loc_mac, EFX_MAC_ADDR_LEN);
        }
 
+       /*
+        * Set the "MARK" or "FLAG" action for all packets matching this filter
+        * if necessary (only useful with equal stride packed stream Rx mode
+        * which provide the information in pseudo-header).
+        * These actions require MC_CMD_FILTER_OP_V3_IN msgrequest.
+        */
+       if ((spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) &&
+           (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG)) {
+               rc = EINVAL;
+               goto fail3;
+       }
+       if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_MARK) {
+               MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
+                   MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_MARK);
+               MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_MARK_VALUE,
+                   spec->efs_mark);
+       } else if (spec->efs_flags & EFX_FILTER_FLAG_ACTION_FLAG) {
+               MCDI_IN_SET_DWORD(req, FILTER_OP_V3_IN_MATCH_ACTION,
+                   MC_CMD_FILTER_OP_V3_IN_MATCH_ACTION_FLAG);
+       }
+
        efx_mcdi_execute(enp, &req);
 
        if (req.emr_rc != 0) {
                rc = req.emr_rc;
-               goto fail3;
+               goto fail4;
        }
 
        if (req.emr_out_length_used < MC_CMD_FILTER_OP_EXT_OUT_LEN) {
                rc = EMSGSIZE;
-               goto fail4;
+               goto fail5;
        }
 
        handle->efh_lo = MCDI_OUT_DWORD(req, FILTER_OP_EXT_OUT_HANDLE_LO);
@@ -321,6 +353,8 @@ efx_mcdi_filter_op_add(
 
        return (0);
 
+fail5:
+       EFSYS_PROBE(fail5);
 fail4:
        EFSYS_PROBE(fail4);
 fail3:
@@ -341,11 +375,10 @@ efx_mcdi_filter_op_delete(
        __inout         ef10_filter_handle_t *handle)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_FILTER_OP_EXT_IN_LEN,
-                           MC_CMD_FILTER_OP_EXT_OUT_LEN)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FILTER_OP_EXT_IN_LEN,
+               MC_CMD_FILTER_OP_EXT_OUT_LEN);
        efx_rc_t rc;
 
-       memset(payload, 0, sizeof (payload));
        req.emr_cmd = MC_CMD_FILTER_OP;
        req.emr_in_buf = payload;
        req.emr_in_length = MC_CMD_FILTER_OP_EXT_IN_LEN;
@@ -915,13 +948,12 @@ efx_mcdi_get_parser_disp_info(
        __out                           size_t *list_lengthp)
 {
        efx_mcdi_req_t req;
-       uint8_t payload[MAX(MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
-                           MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX)];
+       EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN,
+               MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
        size_t matches_count;
        size_t list_size;
        efx_rc_t rc;
 
-       (void) memset(payload, 0, sizeof (payload));
        req.emr_cmd = MC_CMD_GET_PARSER_DISP_INFO;
        req.emr_in_buf = payload;
        req.emr_in_length = MC_CMD_GET_PARSER_DISP_INFO_IN_LEN;
@@ -1008,13 +1040,17 @@ ef10_filter_supported_filters(
            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);
 
        /*
         * 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.
+        * 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);
@@ -1042,6 +1078,10 @@ ef10_filter_supported_filters(
                                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;
                }
        } else {
                mcdi_encap_list_length = 0;
@@ -1101,12 +1141,15 @@ ef10_filter_insert_unicast(
        efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
            filter_flags,
            eftp->eft_default_rxq);
-       efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC, addr);
+       rc = efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
+           addr);
+       if (rc != 0)
+               goto fail1;
 
        rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
            &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
        if (rc != 0)
-               goto fail1;
+               goto fail2;
 
        eftp->eft_unicst_filter_count++;
        EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
@@ -1114,6 +1157,8 @@ ef10_filter_insert_unicast(
 
        return (0);
 
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
        return (rc);
@@ -1132,11 +1177,13 @@ ef10_filter_insert_all_unicast(
        efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
            filter_flags,
            eftp->eft_default_rxq);
-       efx_filter_spec_set_uc_def(&spec);
+       rc = efx_filter_spec_set_uc_def(&spec);
+       if (rc != 0)
+               goto fail1;
        rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
            &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
        if (rc != 0)
-               goto fail1;
+               goto fail2;
 
        eftp->eft_unicst_filter_count++;
        EFSYS_ASSERT(eftp->eft_unicst_filter_count <=
@@ -1144,6 +1191,8 @@ ef10_filter_insert_all_unicast(
 
        return (0);
 
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
        return (rc);
@@ -1185,9 +1234,21 @@ ef10_filter_insert_multicast_list(
                    filter_flags,
                    eftp->eft_default_rxq);
 
-               efx_filter_spec_set_eth_local(&spec,
+               rc = efx_filter_spec_set_eth_local(&spec,
                    EFX_FILTER_SPEC_VID_UNSPEC,
                    &addrs[i * EFX_MAC_ADDR_LEN]);
+               if (rc != 0) {
+                       if (rollback == B_TRUE) {
+                               /* Only stop upon failure if told to rollback */
+                               goto rollback;
+                       } else {
+                               /*
+                                * Don't try to add a filter with a corrupt
+                                * specification.
+                                */
+                               continue;
+                       }
+               }
 
                rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
                                            &filter_index);
@@ -1210,8 +1271,12 @@ ef10_filter_insert_multicast_list(
                    eftp->eft_default_rxq);
 
                EFX_MAC_BROADCAST_ADDR_SET(addr);
-               efx_filter_spec_set_eth_local(&spec, EFX_FILTER_SPEC_VID_UNSPEC,
-                   addr);
+               rc = efx_filter_spec_set_eth_local(&spec,
+                   EFX_FILTER_SPEC_VID_UNSPEC, addr);
+               if ((rc != 0) && (rollback == B_TRUE)) {
+                       /* Only stop upon failure if told to rollback */
+                       goto rollback;
+               }
 
                rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
                                            &filter_index);
@@ -1259,12 +1324,14 @@ ef10_filter_insert_all_multicast(
        efx_filter_spec_init_rx(&spec, EFX_FILTER_PRI_AUTO,
            filter_flags,
            eftp->eft_default_rxq);
-       efx_filter_spec_set_mc_def(&spec);
+       rc = efx_filter_spec_set_mc_def(&spec);
+       if (rc != 0)
+               goto fail1;
 
        rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
            &eftp->eft_mulcst_filter_indexes[0]);
        if (rc != 0)
-               goto fail1;
+               goto fail2;
 
        eftp->eft_mulcst_filter_count = 1;
        eftp->eft_using_all_mulcst = B_TRUE;
@@ -1275,6 +1342,8 @@ ef10_filter_insert_all_multicast(
 
        return (0);
 
+fail2:
+       EFSYS_PROBE(fail2);
 fail1:
        EFSYS_PROBE1(fail1, efx_rc_t, rc);
 
@@ -1509,7 +1578,7 @@ ef10_filter_reconfigure(
        /*
         * Insert or renew unicast filters.
         *
-        * Frimware does not perform chaining on unicast filters. As traffic is
+        * Firmware does not perform chaining on unicast filters. As traffic is
         * therefore only delivered to the first matching filter, we should
         * always insert the specific filter for our MAC address, to try and
         * ensure we get that traffic.