1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
12 static __checkReturn efx_rc_t
13 efx_mae_get_capabilities(
17 EFX_MCDI_DECLARE_BUF(payload,
18 MC_CMD_MAE_GET_CAPS_IN_LEN,
19 MC_CMD_MAE_GET_CAPS_OUT_LEN);
20 struct efx_mae_s *maep = enp->en_maep;
23 req.emr_cmd = MC_CMD_MAE_GET_CAPS;
24 req.emr_in_buf = payload;
25 req.emr_in_length = MC_CMD_MAE_GET_CAPS_IN_LEN;
26 req.emr_out_buf = payload;
27 req.emr_out_length = MC_CMD_MAE_GET_CAPS_OUT_LEN;
29 efx_mcdi_execute(enp, &req);
31 if (req.emr_rc != 0) {
36 if (req.emr_out_length_used < MC_CMD_MAE_GET_CAPS_OUT_LEN) {
41 maep->em_max_n_outer_prios =
42 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_OUTER_PRIOS);
44 maep->em_max_n_action_prios =
45 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ACTION_PRIOS);
47 maep->em_encap_types_supported = 0;
49 if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
50 MAE_GET_CAPS_OUT_ENCAP_TYPE_VXLAN) != 0) {
51 maep->em_encap_types_supported |=
52 (1U << EFX_TUNNEL_PROTOCOL_VXLAN);
55 if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
56 MAE_GET_CAPS_OUT_ENCAP_TYPE_GENEVE) != 0) {
57 maep->em_encap_types_supported |=
58 (1U << EFX_TUNNEL_PROTOCOL_GENEVE);
61 if (MCDI_OUT_DWORD_FIELD(req, MAE_GET_CAPS_OUT_ENCAP_TYPES_SUPPORTED,
62 MAE_GET_CAPS_OUT_ENCAP_TYPE_NVGRE) != 0) {
63 maep->em_encap_types_supported |=
64 (1U << EFX_TUNNEL_PROTOCOL_NVGRE);
67 maep->em_max_nfields =
68 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_MATCH_FIELD_COUNT);
70 maep->em_max_ncounters =
71 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_COUNTERS);
78 EFSYS_PROBE1(fail1, efx_rc_t, rc);
82 static __checkReturn efx_rc_t
83 efx_mae_get_outer_rule_caps(
85 __in unsigned int field_ncaps,
86 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
89 EFX_MCDI_DECLARE_BUF(payload,
90 MC_CMD_MAE_GET_OR_CAPS_IN_LEN,
91 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2);
92 unsigned int mcdi_field_ncaps;
96 if (MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps) >
97 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2) {
102 req.emr_cmd = MC_CMD_MAE_GET_OR_CAPS;
103 req.emr_in_buf = payload;
104 req.emr_in_length = MC_CMD_MAE_GET_OR_CAPS_IN_LEN;
105 req.emr_out_buf = payload;
106 req.emr_out_length = MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps);
108 efx_mcdi_execute(enp, &req);
110 if (req.emr_rc != 0) {
115 if (req.emr_out_length_used < MC_CMD_MAE_GET_OR_CAPS_OUT_LENMIN) {
120 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
122 if (req.emr_out_length_used <
123 MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
128 if (mcdi_field_ncaps > field_ncaps) {
133 for (i = 0; i < mcdi_field_ncaps; ++i) {
137 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
138 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
139 MAE_FIELD_FLAGS_SUPPORT_STATUS);
141 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
142 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
143 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
145 field_caps[i].emfc_match_affects_class =
146 (match_flag != 0) ? B_TRUE : B_FALSE;
148 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
149 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
150 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
152 field_caps[i].emfc_mask_affects_class =
153 (mask_flag != 0) ? B_TRUE : B_FALSE;
167 EFSYS_PROBE1(fail1, efx_rc_t, rc);
171 static __checkReturn efx_rc_t
172 efx_mae_get_action_rule_caps(
174 __in unsigned int field_ncaps,
175 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
178 EFX_MCDI_DECLARE_BUF(payload,
179 MC_CMD_MAE_GET_AR_CAPS_IN_LEN,
180 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2);
181 unsigned int mcdi_field_ncaps;
185 if (MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps) >
186 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2) {
191 req.emr_cmd = MC_CMD_MAE_GET_AR_CAPS;
192 req.emr_in_buf = payload;
193 req.emr_in_length = MC_CMD_MAE_GET_AR_CAPS_IN_LEN;
194 req.emr_out_buf = payload;
195 req.emr_out_length = MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps);
197 efx_mcdi_execute(enp, &req);
199 if (req.emr_rc != 0) {
204 if (req.emr_out_length_used < MC_CMD_MAE_GET_AR_CAPS_OUT_LENMIN) {
209 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_AR_CAPS_OUT_COUNT);
211 if (req.emr_out_length_used <
212 MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
217 if (mcdi_field_ncaps > field_ncaps) {
222 for (i = 0; i < mcdi_field_ncaps; ++i) {
226 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
227 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
228 MAE_FIELD_FLAGS_SUPPORT_STATUS);
230 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
231 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
232 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
234 field_caps[i].emfc_match_affects_class =
235 (match_flag != 0) ? B_TRUE : B_FALSE;
237 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
238 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
239 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
241 field_caps[i].emfc_mask_affects_class =
242 (mask_flag != 0) ? B_TRUE : B_FALSE;
256 EFSYS_PROBE1(fail1, efx_rc_t, rc);
260 __checkReturn efx_rc_t
264 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
265 efx_mae_field_cap_t *or_fcaps;
266 size_t or_fcaps_size;
267 efx_mae_field_cap_t *ar_fcaps;
268 size_t ar_fcaps_size;
272 if (encp->enc_mae_supported == B_FALSE) {
277 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*maep), maep);
285 rc = efx_mae_get_capabilities(enp);
289 or_fcaps_size = maep->em_max_nfields * sizeof (*or_fcaps);
290 EFSYS_KMEM_ALLOC(enp->en_esip, or_fcaps_size, or_fcaps);
291 if (or_fcaps == NULL) {
296 maep->em_outer_rule_field_caps_size = or_fcaps_size;
297 maep->em_outer_rule_field_caps = or_fcaps;
299 rc = efx_mae_get_outer_rule_caps(enp, maep->em_max_nfields, or_fcaps);
303 ar_fcaps_size = maep->em_max_nfields * sizeof (*ar_fcaps);
304 EFSYS_KMEM_ALLOC(enp->en_esip, ar_fcaps_size, ar_fcaps);
305 if (ar_fcaps == NULL) {
310 maep->em_action_rule_field_caps_size = ar_fcaps_size;
311 maep->em_action_rule_field_caps = ar_fcaps;
313 rc = efx_mae_get_action_rule_caps(enp, maep->em_max_nfields, ar_fcaps);
321 EFSYS_KMEM_FREE(enp->en_esip, ar_fcaps_size, ar_fcaps);
326 EFSYS_KMEM_FREE(enp->en_esip, or_fcaps_size, or_fcaps);
331 EFSYS_KMEM_FREE(enp->en_esip, sizeof (struct efx_mae_s), enp->en_maep);
336 EFSYS_PROBE1(fail1, efx_rc_t, rc);
344 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
345 efx_mae_t *maep = enp->en_maep;
347 if (encp->enc_mae_supported == B_FALSE)
350 EFSYS_KMEM_FREE(enp->en_esip, maep->em_action_rule_field_caps_size,
351 maep->em_action_rule_field_caps);
352 EFSYS_KMEM_FREE(enp->en_esip, maep->em_outer_rule_field_caps_size,
353 maep->em_outer_rule_field_caps);
354 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*maep), maep);
358 __checkReturn efx_rc_t
361 __out efx_mae_limits_t *emlp)
363 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
364 struct efx_mae_s *maep = enp->en_maep;
367 if (encp->enc_mae_supported == B_FALSE) {
372 emlp->eml_max_n_outer_prios = maep->em_max_n_outer_prios;
373 emlp->eml_max_n_action_prios = maep->em_max_n_action_prios;
374 emlp->eml_encap_types_supported = maep->em_encap_types_supported;
375 emlp->eml_encap_header_size_limit =
376 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2;
377 emlp->eml_max_n_counters = maep->em_max_ncounters;
382 EFSYS_PROBE1(fail1, efx_rc_t, rc);
386 __checkReturn efx_rc_t
387 efx_mae_match_spec_init(
389 __in efx_mae_rule_type_t type,
391 __out efx_mae_match_spec_t **specp)
393 efx_mae_match_spec_t *spec;
397 case EFX_MAE_RULE_OUTER:
399 case EFX_MAE_RULE_ACTION:
406 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
412 spec->emms_type = type;
413 spec->emms_prio = prio;
422 EFSYS_PROBE1(fail1, efx_rc_t, rc);
427 efx_mae_match_spec_fini(
429 __in efx_mae_match_spec_t *spec)
431 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
434 /* Named identifiers which are valid indices to efx_mae_field_cap_t */
435 typedef enum efx_mae_field_cap_id_e {
436 EFX_MAE_FIELD_ID_INGRESS_MPORT_SELECTOR = MAE_FIELD_INGRESS_PORT,
437 EFX_MAE_FIELD_ID_ETHER_TYPE_BE = MAE_FIELD_ETHER_TYPE,
438 EFX_MAE_FIELD_ID_ETH_SADDR_BE = MAE_FIELD_ETH_SADDR,
439 EFX_MAE_FIELD_ID_ETH_DADDR_BE = MAE_FIELD_ETH_DADDR,
440 EFX_MAE_FIELD_ID_VLAN0_TCI_BE = MAE_FIELD_VLAN0_TCI,
441 EFX_MAE_FIELD_ID_VLAN0_PROTO_BE = MAE_FIELD_VLAN0_PROTO,
442 EFX_MAE_FIELD_ID_VLAN1_TCI_BE = MAE_FIELD_VLAN1_TCI,
443 EFX_MAE_FIELD_ID_VLAN1_PROTO_BE = MAE_FIELD_VLAN1_PROTO,
444 EFX_MAE_FIELD_ID_SRC_IP4_BE = MAE_FIELD_SRC_IP4,
445 EFX_MAE_FIELD_ID_DST_IP4_BE = MAE_FIELD_DST_IP4,
446 EFX_MAE_FIELD_ID_IP_PROTO = MAE_FIELD_IP_PROTO,
447 EFX_MAE_FIELD_ID_IP_TOS = MAE_FIELD_IP_TOS,
448 EFX_MAE_FIELD_ID_IP_TTL = MAE_FIELD_IP_TTL,
449 EFX_MAE_FIELD_ID_SRC_IP6_BE = MAE_FIELD_SRC_IP6,
450 EFX_MAE_FIELD_ID_DST_IP6_BE = MAE_FIELD_DST_IP6,
451 EFX_MAE_FIELD_ID_L4_SPORT_BE = MAE_FIELD_L4_SPORT,
452 EFX_MAE_FIELD_ID_L4_DPORT_BE = MAE_FIELD_L4_DPORT,
453 EFX_MAE_FIELD_ID_TCP_FLAGS_BE = MAE_FIELD_TCP_FLAGS,
454 EFX_MAE_FIELD_ID_ENC_ETHER_TYPE_BE = MAE_FIELD_ENC_ETHER_TYPE,
455 EFX_MAE_FIELD_ID_ENC_ETH_SADDR_BE = MAE_FIELD_ENC_ETH_SADDR,
456 EFX_MAE_FIELD_ID_ENC_ETH_DADDR_BE = MAE_FIELD_ENC_ETH_DADDR,
457 EFX_MAE_FIELD_ID_ENC_VLAN0_TCI_BE = MAE_FIELD_ENC_VLAN0_TCI,
458 EFX_MAE_FIELD_ID_ENC_VLAN0_PROTO_BE = MAE_FIELD_ENC_VLAN0_PROTO,
459 EFX_MAE_FIELD_ID_ENC_VLAN1_TCI_BE = MAE_FIELD_ENC_VLAN1_TCI,
460 EFX_MAE_FIELD_ID_ENC_VLAN1_PROTO_BE = MAE_FIELD_ENC_VLAN1_PROTO,
461 EFX_MAE_FIELD_ID_ENC_SRC_IP4_BE = MAE_FIELD_ENC_SRC_IP4,
462 EFX_MAE_FIELD_ID_ENC_DST_IP4_BE = MAE_FIELD_ENC_DST_IP4,
463 EFX_MAE_FIELD_ID_ENC_IP_PROTO = MAE_FIELD_ENC_IP_PROTO,
464 EFX_MAE_FIELD_ID_ENC_IP_TOS = MAE_FIELD_ENC_IP_TOS,
465 EFX_MAE_FIELD_ID_ENC_IP_TTL = MAE_FIELD_ENC_IP_TTL,
466 EFX_MAE_FIELD_ID_ENC_SRC_IP6_BE = MAE_FIELD_ENC_SRC_IP6,
467 EFX_MAE_FIELD_ID_ENC_DST_IP6_BE = MAE_FIELD_ENC_DST_IP6,
468 EFX_MAE_FIELD_ID_ENC_L4_SPORT_BE = MAE_FIELD_ENC_L4_SPORT,
469 EFX_MAE_FIELD_ID_ENC_L4_DPORT_BE = MAE_FIELD_ENC_L4_DPORT,
470 EFX_MAE_FIELD_ID_ENC_VNET_ID_BE = MAE_FIELD_ENC_VNET_ID,
471 EFX_MAE_FIELD_ID_OUTER_RULE_ID = MAE_FIELD_OUTER_RULE_ID,
472 EFX_MAE_FIELD_ID_HAS_OVLAN = MAE_FIELD_HAS_OVLAN,
473 EFX_MAE_FIELD_ID_HAS_IVLAN = MAE_FIELD_HAS_IVLAN,
474 EFX_MAE_FIELD_ID_ENC_HAS_OVLAN = MAE_FIELD_ENC_HAS_OVLAN,
475 EFX_MAE_FIELD_ID_ENC_HAS_IVLAN = MAE_FIELD_ENC_HAS_IVLAN,
477 EFX_MAE_FIELD_CAP_NIDS
478 } efx_mae_field_cap_id_t;
480 typedef enum efx_mae_field_endianness_e {
481 EFX_MAE_FIELD_LE = 0,
484 EFX_MAE_FIELD_ENDIANNESS_NTYPES
485 } efx_mae_field_endianness_t;
488 * The following structure is a means to describe an MAE field.
489 * The information in it is meant to be used internally by
490 * APIs for addressing a given field in a mask-value pairs
491 * structure and for validation purposes.
493 * A field may have an alternative one. This structure
494 * has additional members to reference the alternative
495 * field's mask. See efx_mae_match_spec_is_valid().
497 typedef struct efx_mae_mv_desc_s {
498 efx_mae_field_cap_id_t emmd_field_cap_id;
500 size_t emmd_value_size;
501 size_t emmd_value_offset;
502 size_t emmd_mask_size;
503 size_t emmd_mask_offset;
506 * Having the alternative field's mask size set to 0
507 * means that there's no alternative field specified.
509 size_t emmd_alt_mask_size;
510 size_t emmd_alt_mask_offset;
512 /* Primary field and the alternative one are of the same endianness. */
513 efx_mae_field_endianness_t emmd_endianness;
516 /* Indices to this array are provided by efx_mae_field_id_t */
517 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
518 #define EFX_MAE_MV_DESC(_name, _endianness) \
519 [EFX_MAE_FIELD_##_name] = \
521 EFX_MAE_FIELD_ID_##_name, \
522 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
523 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
524 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
525 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
526 0, 0 /* no alternative field */, \
530 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
531 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
532 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
533 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
534 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
535 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
536 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
537 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
538 EFX_MAE_MV_DESC(SRC_IP4_BE, EFX_MAE_FIELD_BE),
539 EFX_MAE_MV_DESC(DST_IP4_BE, EFX_MAE_FIELD_BE),
540 EFX_MAE_MV_DESC(IP_PROTO, EFX_MAE_FIELD_BE),
541 EFX_MAE_MV_DESC(IP_TOS, EFX_MAE_FIELD_BE),
542 EFX_MAE_MV_DESC(IP_TTL, EFX_MAE_FIELD_BE),
543 EFX_MAE_MV_DESC(SRC_IP6_BE, EFX_MAE_FIELD_BE),
544 EFX_MAE_MV_DESC(DST_IP6_BE, EFX_MAE_FIELD_BE),
545 EFX_MAE_MV_DESC(L4_SPORT_BE, EFX_MAE_FIELD_BE),
546 EFX_MAE_MV_DESC(L4_DPORT_BE, EFX_MAE_FIELD_BE),
547 EFX_MAE_MV_DESC(TCP_FLAGS_BE, EFX_MAE_FIELD_BE),
548 EFX_MAE_MV_DESC(ENC_VNET_ID_BE, EFX_MAE_FIELD_BE),
549 EFX_MAE_MV_DESC(OUTER_RULE_ID, EFX_MAE_FIELD_LE),
551 #undef EFX_MAE_MV_DESC
554 /* Indices to this array are provided by efx_mae_field_id_t */
555 static const efx_mae_mv_desc_t __efx_mae_outer_rule_mv_desc_set[] = {
556 #define EFX_MAE_MV_DESC(_name, _endianness) \
557 [EFX_MAE_FIELD_##_name] = \
559 EFX_MAE_FIELD_ID_##_name, \
560 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
561 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
562 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
563 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
564 0, 0 /* no alternative field */, \
568 /* Same as EFX_MAE_MV_DESC(), but also indicates an alternative field. */
569 #define EFX_MAE_MV_DESC_ALT(_name, _alt_name, _endianness) \
570 [EFX_MAE_FIELD_##_name] = \
572 EFX_MAE_FIELD_ID_##_name, \
573 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
574 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
575 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
576 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
577 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_LEN, \
578 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_OFST, \
582 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
583 EFX_MAE_MV_DESC(ENC_ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
584 EFX_MAE_MV_DESC(ENC_ETH_SADDR_BE, EFX_MAE_FIELD_BE),
585 EFX_MAE_MV_DESC(ENC_ETH_DADDR_BE, EFX_MAE_FIELD_BE),
586 EFX_MAE_MV_DESC(ENC_VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
587 EFX_MAE_MV_DESC(ENC_VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
588 EFX_MAE_MV_DESC(ENC_VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
589 EFX_MAE_MV_DESC(ENC_VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
590 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP4_BE, ENC_SRC_IP6_BE, EFX_MAE_FIELD_BE),
591 EFX_MAE_MV_DESC_ALT(ENC_DST_IP4_BE, ENC_DST_IP6_BE, EFX_MAE_FIELD_BE),
592 EFX_MAE_MV_DESC(ENC_IP_PROTO, EFX_MAE_FIELD_BE),
593 EFX_MAE_MV_DESC(ENC_IP_TOS, EFX_MAE_FIELD_BE),
594 EFX_MAE_MV_DESC(ENC_IP_TTL, EFX_MAE_FIELD_BE),
595 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP6_BE, ENC_SRC_IP4_BE, EFX_MAE_FIELD_BE),
596 EFX_MAE_MV_DESC_ALT(ENC_DST_IP6_BE, ENC_DST_IP4_BE, EFX_MAE_FIELD_BE),
597 EFX_MAE_MV_DESC(ENC_L4_SPORT_BE, EFX_MAE_FIELD_BE),
598 EFX_MAE_MV_DESC(ENC_L4_DPORT_BE, EFX_MAE_FIELD_BE),
600 #undef EFX_MAE_MV_DESC_ALT
601 #undef EFX_MAE_MV_DESC
605 * The following structure is a means to describe an MAE bit.
606 * The information in it is meant to be used internally by
607 * APIs for addressing a given flag in a mask-value pairs
608 * structure and for validation purposes.
610 typedef struct efx_mae_mv_bit_desc_s {
612 * Arrays using this struct are indexed by field IDs.
613 * Fields which aren't meant to be referenced by these
614 * arrays comprise gaps (invalid entries). Below field
615 * helps to identify such entries.
617 boolean_t emmbd_entry_is_valid;
618 efx_mae_field_cap_id_t emmbd_bit_cap_id;
619 size_t emmbd_value_ofst;
620 unsigned int emmbd_value_lbn;
621 size_t emmbd_mask_ofst;
622 unsigned int emmbd_mask_lbn;
623 } efx_mae_mv_bit_desc_t;
625 static const efx_mae_mv_bit_desc_t __efx_mae_outer_rule_mv_bit_desc_set[] = {
626 #define EFX_MAE_MV_BIT_DESC(_name) \
627 [EFX_MAE_FIELD_##_name] = \
630 EFX_MAE_FIELD_ID_##_name, \
631 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
632 MAE_ENC_FIELD_PAIRS_##_name##_LBN, \
633 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
634 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LBN, \
637 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
638 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
640 #undef EFX_MAE_MV_BIT_DESC
643 static const efx_mae_mv_bit_desc_t __efx_mae_action_rule_mv_bit_desc_set[] = {
644 #define EFX_MAE_MV_BIT_DESC(_name) \
645 [EFX_MAE_FIELD_##_name] = \
648 EFX_MAE_FIELD_ID_##_name, \
649 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_OFST, \
650 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
651 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_MASK_OFST, \
652 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
655 EFX_MAE_MV_BIT_DESC(HAS_OVLAN),
656 EFX_MAE_MV_BIT_DESC(HAS_IVLAN),
657 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
658 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
660 #undef EFX_MAE_MV_BIT_DESC
663 __checkReturn efx_rc_t
664 efx_mae_mport_by_phy_port(
665 __in uint32_t phy_port,
666 __out efx_mport_sel_t *mportp)
671 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
676 EFX_POPULATE_DWORD_2(dword,
677 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
678 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
680 memset(mportp, 0, sizeof (*mportp));
682 * The constructed DWORD is little-endian,
683 * but the resulting value is meant to be
684 * passed to MCDIs, where it will undergo
685 * host-order to little endian conversion.
687 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
692 EFSYS_PROBE1(fail1, efx_rc_t, rc);
696 __checkReturn efx_rc_t
697 efx_mae_mport_by_pcie_function(
700 __out efx_mport_sel_t *mportp)
705 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
706 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
708 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_PF_ID)) {
713 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
718 EFX_POPULATE_DWORD_3(dword,
719 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_FUNC,
720 MAE_MPORT_SELECTOR_FUNC_PF_ID, pf,
721 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
723 memset(mportp, 0, sizeof (*mportp));
725 * The constructed DWORD is little-endian,
726 * but the resulting value is meant to be
727 * passed to MCDIs, where it will undergo
728 * host-order to little endian conversion.
730 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
737 EFSYS_PROBE1(fail1, efx_rc_t, rc);
741 static __checkReturn efx_rc_t
742 efx_mcdi_mae_mport_lookup(
744 __in const efx_mport_sel_t *mport_selectorp,
745 __out efx_mport_id_t *mport_idp)
748 EFX_MCDI_DECLARE_BUF(payload,
749 MC_CMD_MAE_MPORT_LOOKUP_IN_LEN,
750 MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN);
753 req.emr_cmd = MC_CMD_MAE_MPORT_LOOKUP;
754 req.emr_in_buf = payload;
755 req.emr_in_length = MC_CMD_MAE_MPORT_LOOKUP_IN_LEN;
756 req.emr_out_buf = payload;
757 req.emr_out_length = MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN;
759 MCDI_IN_SET_DWORD(req, MAE_MPORT_LOOKUP_IN_MPORT_SELECTOR,
760 mport_selectorp->sel);
762 efx_mcdi_execute(enp, &req);
764 if (req.emr_rc != 0) {
769 mport_idp->id = MCDI_OUT_DWORD(req, MAE_MPORT_LOOKUP_OUT_MPORT_ID);
774 EFSYS_PROBE1(fail1, efx_rc_t, rc);
778 __checkReturn efx_rc_t
779 efx_mae_mport_id_by_selector(
781 __in const efx_mport_sel_t *mport_selectorp,
782 __out efx_mport_id_t *mport_idp)
784 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
787 if (encp->enc_mae_supported == B_FALSE) {
792 rc = efx_mcdi_mae_mport_lookup(enp, mport_selectorp, mport_idp);
801 EFSYS_PROBE1(fail1, efx_rc_t, rc);
805 __checkReturn efx_rc_t
806 efx_mae_match_spec_field_set(
807 __in efx_mae_match_spec_t *spec,
808 __in efx_mae_field_id_t field_id,
809 __in size_t value_size,
810 __in_bcount(value_size) const uint8_t *value,
811 __in size_t mask_size,
812 __in_bcount(mask_size) const uint8_t *mask)
814 const efx_mae_mv_desc_t *descp;
815 unsigned int desc_set_nentries;
819 switch (spec->emms_type) {
820 case EFX_MAE_RULE_OUTER:
822 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
823 descp = &__efx_mae_outer_rule_mv_desc_set[field_id];
824 mvp = spec->emms_mask_value_pairs.outer;
826 case EFX_MAE_RULE_ACTION:
828 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
829 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
830 mvp = spec->emms_mask_value_pairs.action;
837 if ((unsigned int)field_id >= desc_set_nentries) {
842 if (descp->emmd_mask_size == 0) {
843 /* The ID points to a gap in the array of field descriptors. */
848 if (value_size != descp->emmd_value_size) {
853 if (mask_size != descp->emmd_mask_size) {
858 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
862 * The mask/value are in network (big endian) order.
863 * The MCDI request field is also big endian.
866 EFSYS_ASSERT3U(value_size, ==, mask_size);
868 for (i = 0; i < value_size; ++i) {
869 uint8_t *v_bytep = mvp + descp->emmd_value_offset + i;
870 uint8_t *m_bytep = mvp + descp->emmd_mask_offset + i;
873 * Apply the mask (which may be all-zeros) to the value.
875 * If this API is provided with some value to set for a
876 * given field in one specification and with some other
877 * value to set for this field in another specification,
878 * then, if the two masks are all-zeros, the field will
879 * avoid being counted as a mismatch when comparing the
880 * specifications using efx_mae_match_specs_equal() API.
882 *v_bytep = value[i] & mask[i];
889 * The mask/value are in host byte order.
890 * The MCDI request field is little endian.
892 switch (value_size) {
894 EFX_POPULATE_DWORD_1(dword,
895 EFX_DWORD_0, *(const uint32_t *)value);
897 memcpy(mvp + descp->emmd_value_offset,
898 &dword, sizeof (dword));
901 EFSYS_ASSERT(B_FALSE);
906 EFX_POPULATE_DWORD_1(dword,
907 EFX_DWORD_0, *(const uint32_t *)mask);
909 memcpy(mvp + descp->emmd_mask_offset,
910 &dword, sizeof (dword));
913 EFSYS_ASSERT(B_FALSE);
928 EFSYS_PROBE1(fail1, efx_rc_t, rc);
932 __checkReturn efx_rc_t
933 efx_mae_match_spec_bit_set(
934 __in efx_mae_match_spec_t *spec,
935 __in efx_mae_field_id_t field_id,
936 __in boolean_t value)
938 const efx_mae_mv_bit_desc_t *bit_descp;
939 unsigned int bit_desc_set_nentries;
940 unsigned int byte_idx;
941 unsigned int bit_idx;
945 switch (spec->emms_type) {
946 case EFX_MAE_RULE_OUTER:
947 bit_desc_set_nentries =
948 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
949 bit_descp = &__efx_mae_outer_rule_mv_bit_desc_set[field_id];
950 mvp = spec->emms_mask_value_pairs.outer;
952 case EFX_MAE_RULE_ACTION:
953 bit_desc_set_nentries =
954 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
955 bit_descp = &__efx_mae_action_rule_mv_bit_desc_set[field_id];
956 mvp = spec->emms_mask_value_pairs.action;
963 if ((unsigned int)field_id >= bit_desc_set_nentries) {
968 if (bit_descp->emmbd_entry_is_valid == B_FALSE) {
973 byte_idx = bit_descp->emmbd_value_ofst + bit_descp->emmbd_value_lbn / 8;
974 bit_idx = bit_descp->emmbd_value_lbn % 8;
976 if (value != B_FALSE)
977 mvp[byte_idx] |= (1U << bit_idx);
979 mvp[byte_idx] &= ~(1U << bit_idx);
981 byte_idx = bit_descp->emmbd_mask_ofst + bit_descp->emmbd_mask_lbn / 8;
982 bit_idx = bit_descp->emmbd_mask_lbn % 8;
983 mvp[byte_idx] |= (1U << bit_idx);
992 EFSYS_PROBE1(fail1, efx_rc_t, rc);
996 __checkReturn efx_rc_t
997 efx_mae_match_spec_mport_set(
998 __in efx_mae_match_spec_t *spec,
999 __in const efx_mport_sel_t *valuep,
1000 __in_opt const efx_mport_sel_t *maskp)
1002 uint32_t full_mask = UINT32_MAX;
1007 if (valuep == NULL) {
1012 vp = (const uint8_t *)&valuep->sel;
1014 mp = (const uint8_t *)&maskp->sel;
1016 mp = (const uint8_t *)&full_mask;
1018 rc = efx_mae_match_spec_field_set(spec,
1019 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
1020 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
1029 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1033 __checkReturn boolean_t
1034 efx_mae_match_specs_equal(
1035 __in const efx_mae_match_spec_t *left,
1036 __in const efx_mae_match_spec_t *right)
1038 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1041 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
1042 ((_mask)[(_bit) / (_mask_page_nbits)] & \
1043 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
1047 __in size_t mask_nbytes,
1048 __in_bcount(mask_nbytes) const uint8_t *maskp)
1050 boolean_t prev_bit_is_set = B_TRUE;
1053 for (i = 0; i < 8 * mask_nbytes; ++i) {
1054 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
1056 if (!prev_bit_is_set && bit_is_set)
1059 prev_bit_is_set = bit_is_set;
1066 efx_mask_is_all_ones(
1067 __in size_t mask_nbytes,
1068 __in_bcount(mask_nbytes) const uint8_t *maskp)
1073 for (i = 0; i < mask_nbytes; ++i)
1076 return (t == (uint8_t)(~0));
1080 efx_mask_is_all_zeros(
1081 __in size_t mask_nbytes,
1082 __in_bcount(mask_nbytes) const uint8_t *maskp)
1087 for (i = 0; i < mask_nbytes; ++i)
1093 __checkReturn boolean_t
1094 efx_mae_match_spec_is_valid(
1095 __in efx_nic_t *enp,
1096 __in const efx_mae_match_spec_t *spec)
1098 efx_mae_t *maep = enp->en_maep;
1099 unsigned int field_ncaps = maep->em_max_nfields;
1100 const efx_mae_field_cap_t *field_caps;
1101 const efx_mae_mv_desc_t *desc_setp;
1102 unsigned int desc_set_nentries;
1103 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1104 unsigned int bit_desc_set_nentries;
1105 boolean_t is_valid = B_TRUE;
1106 efx_mae_field_id_t field_id;
1109 switch (spec->emms_type) {
1110 case EFX_MAE_RULE_OUTER:
1111 field_caps = maep->em_outer_rule_field_caps;
1112 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1114 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1115 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1116 bit_desc_set_nentries =
1117 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1118 mvp = spec->emms_mask_value_pairs.outer;
1120 case EFX_MAE_RULE_ACTION:
1121 field_caps = maep->em_action_rule_field_caps;
1122 desc_setp = __efx_mae_action_rule_mv_desc_set;
1124 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1125 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1126 bit_desc_set_nentries =
1127 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1128 mvp = spec->emms_mask_value_pairs.action;
1134 if (field_caps == NULL)
1137 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1139 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1140 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1141 const uint8_t *alt_m_buf = mvp + descp->emmd_alt_mask_offset;
1142 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
1143 size_t alt_m_size = descp->emmd_alt_mask_size;
1144 size_t m_size = descp->emmd_mask_size;
1147 continue; /* Skip array gap */
1149 if ((unsigned int)field_cap_id >= field_ncaps) {
1151 * The FW has not reported capability status for
1152 * this field. Make sure that its mask is zeroed.
1154 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1155 if (is_valid != B_FALSE)
1161 switch (field_caps[field_cap_id].emfc_support) {
1162 case MAE_FIELD_SUPPORTED_MATCH_MASK:
1165 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
1166 is_valid = efx_mask_is_prefix(m_size, m_buf);
1168 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1169 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
1170 efx_mask_is_all_zeros(m_size, m_buf));
1172 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1173 is_valid = efx_mask_is_all_ones(m_size, m_buf);
1175 if ((is_valid == B_FALSE) && (alt_m_size != 0)) {
1177 * This field has an alternative one. The FW
1178 * reports ALWAYS for both implying that one
1179 * of them is required to have all-ones mask.
1181 * The primary field's mask is incorrect; go
1182 * on to check that of the alternative field.
1184 is_valid = efx_mask_is_all_ones(alt_m_size,
1188 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1189 case MAE_FIELD_UNSUPPORTED:
1191 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1195 if (is_valid == B_FALSE)
1199 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1201 const efx_mae_mv_bit_desc_t *bit_descp =
1202 &bit_desc_setp[field_id];
1203 unsigned int byte_idx =
1204 bit_descp->emmbd_mask_ofst +
1205 bit_descp->emmbd_mask_lbn / 8;
1206 unsigned int bit_idx =
1207 bit_descp->emmbd_mask_lbn % 8;
1208 efx_mae_field_cap_id_t bit_cap_id =
1209 bit_descp->emmbd_bit_cap_id;
1211 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1212 continue; /* Skip array gap */
1214 if ((unsigned int)bit_cap_id >= field_ncaps) {
1215 /* No capability for this bit = unsupported. */
1216 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1217 if (is_valid == B_FALSE)
1223 switch (field_caps[bit_cap_id].emfc_support) {
1224 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1227 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1228 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) != 0);
1230 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1231 case MAE_FIELD_UNSUPPORTED:
1233 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1237 if (is_valid == B_FALSE)
1244 __checkReturn efx_rc_t
1245 efx_mae_action_set_spec_init(
1246 __in efx_nic_t *enp,
1247 __out efx_mae_actions_t **specp)
1249 efx_mae_actions_t *spec;
1252 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
1258 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1259 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1266 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1271 efx_mae_action_set_spec_fini(
1272 __in efx_nic_t *enp,
1273 __in efx_mae_actions_t *spec)
1275 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1278 static __checkReturn efx_rc_t
1279 efx_mae_action_set_add_decap(
1280 __in efx_mae_actions_t *spec,
1281 __in size_t arg_size,
1282 __in_bcount(arg_size) const uint8_t *arg)
1286 _NOTE(ARGUNUSED(spec))
1288 if (arg_size != 0) {
1298 /* This action does not have any arguments, so do nothing here. */
1305 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1309 static __checkReturn efx_rc_t
1310 efx_mae_action_set_add_vlan_pop(
1311 __in efx_mae_actions_t *spec,
1312 __in size_t arg_size,
1313 __in_bcount(arg_size) const uint8_t *arg)
1317 if (arg_size != 0) {
1327 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
1332 ++spec->ema_n_vlan_tags_to_pop;
1341 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1345 static __checkReturn efx_rc_t
1346 efx_mae_action_set_add_vlan_push(
1347 __in efx_mae_actions_t *spec,
1348 __in size_t arg_size,
1349 __in_bcount(arg_size) const uint8_t *arg)
1351 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
1354 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
1364 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1369 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
1370 ++(spec->ema_n_vlan_tags_to_push);
1379 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1383 static __checkReturn efx_rc_t
1384 efx_mae_action_set_add_encap(
1385 __in efx_mae_actions_t *spec,
1386 __in size_t arg_size,
1387 __in_bcount(arg_size) const uint8_t *arg)
1392 * Adding this specific action to an action set spec and setting encap.
1393 * header ID in the spec are two individual steps. This design allows
1394 * the client driver to avoid encap. header allocation when it simply
1395 * needs to check the order of actions submitted by user ("validate"),
1396 * without actually allocating an action set and inserting a rule.
1398 * For now, mark encap. header ID as invalid; the caller will invoke
1399 * efx_mae_action_set_fill_in_eh_id() to override the field prior
1400 * to action set allocation; otherwise, the allocation will fail.
1402 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1405 * As explained above, there are no arguments to handle here.
1406 * efx_mae_action_set_fill_in_eh_id() will take care of them.
1408 if (arg_size != 0) {
1423 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1427 static __checkReturn efx_rc_t
1428 efx_mae_action_set_add_count(
1429 __in efx_mae_actions_t *spec,
1430 __in size_t arg_size,
1431 __in_bcount(arg_size) const uint8_t *arg)
1435 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1436 MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL);
1439 * Preparing an action set spec to update a counter requires
1440 * two steps: first add this action to the action spec, and then
1441 * add the counter ID to the spec. This allows validity checking
1442 * and resource allocation to be done separately.
1443 * Mark the counter ID as invalid in the spec to ensure that the
1444 * caller must also invoke efx_mae_action_set_fill_in_counter_id()
1445 * before action set allocation.
1447 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1449 /* Nothing else is supposed to take place over here. */
1450 if (arg_size != 0) {
1460 ++(spec->ema_n_count_actions);
1467 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1471 static __checkReturn efx_rc_t
1472 efx_mae_action_set_add_flag(
1473 __in efx_mae_actions_t *spec,
1474 __in size_t arg_size,
1475 __in_bcount(arg_size) const uint8_t *arg)
1479 _NOTE(ARGUNUSED(spec))
1481 if (arg_size != 0) {
1491 /* This action does not have any arguments, so do nothing here. */
1498 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1502 static __checkReturn efx_rc_t
1503 efx_mae_action_set_add_mark(
1504 __in efx_mae_actions_t *spec,
1505 __in size_t arg_size,
1506 __in_bcount(arg_size) const uint8_t *arg)
1510 if (arg_size != sizeof (spec->ema_mark_value)) {
1520 memcpy(&spec->ema_mark_value, arg, arg_size);
1527 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1531 static __checkReturn efx_rc_t
1532 efx_mae_action_set_add_deliver(
1533 __in efx_mae_actions_t *spec,
1534 __in size_t arg_size,
1535 __in_bcount(arg_size) const uint8_t *arg)
1539 if (arg_size != sizeof (spec->ema_deliver_mport)) {
1549 memcpy(&spec->ema_deliver_mport, arg, arg_size);
1556 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1560 typedef struct efx_mae_action_desc_s {
1561 /* Action specific handler */
1562 efx_rc_t (*emad_add)(efx_mae_actions_t *,
1563 size_t, const uint8_t *);
1564 } efx_mae_action_desc_t;
1566 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
1567 [EFX_MAE_ACTION_DECAP] = {
1568 .emad_add = efx_mae_action_set_add_decap
1570 [EFX_MAE_ACTION_VLAN_POP] = {
1571 .emad_add = efx_mae_action_set_add_vlan_pop
1573 [EFX_MAE_ACTION_VLAN_PUSH] = {
1574 .emad_add = efx_mae_action_set_add_vlan_push
1576 [EFX_MAE_ACTION_ENCAP] = {
1577 .emad_add = efx_mae_action_set_add_encap
1579 [EFX_MAE_ACTION_COUNT] = {
1580 .emad_add = efx_mae_action_set_add_count
1582 [EFX_MAE_ACTION_FLAG] = {
1583 .emad_add = efx_mae_action_set_add_flag
1585 [EFX_MAE_ACTION_MARK] = {
1586 .emad_add = efx_mae_action_set_add_mark
1588 [EFX_MAE_ACTION_DELIVER] = {
1589 .emad_add = efx_mae_action_set_add_deliver
1593 static const uint32_t efx_mae_action_ordered_map =
1594 (1U << EFX_MAE_ACTION_DECAP) |
1595 (1U << EFX_MAE_ACTION_VLAN_POP) |
1596 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1598 * HW will conduct action COUNT after
1599 * the matching packet has been modified by
1600 * length-affecting actions except for ENCAP.
1602 (1U << EFX_MAE_ACTION_COUNT) |
1603 (1U << EFX_MAE_ACTION_ENCAP) |
1604 (1U << EFX_MAE_ACTION_FLAG) |
1605 (1U << EFX_MAE_ACTION_MARK) |
1606 (1U << EFX_MAE_ACTION_DELIVER);
1609 * These actions must not be added after DELIVER, but
1610 * they can have any place among the rest of
1611 * strictly ordered actions.
1613 static const uint32_t efx_mae_action_nonstrict_map =
1614 (1U << EFX_MAE_ACTION_COUNT) |
1615 (1U << EFX_MAE_ACTION_FLAG) |
1616 (1U << EFX_MAE_ACTION_MARK);
1618 static const uint32_t efx_mae_action_repeat_map =
1619 (1U << EFX_MAE_ACTION_VLAN_POP) |
1620 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1621 (1U << EFX_MAE_ACTION_COUNT);
1624 * Add an action to an action set.
1626 * This has to be invoked in the desired action order.
1627 * An out-of-order action request will be turned down.
1629 static __checkReturn efx_rc_t
1630 efx_mae_action_set_spec_populate(
1631 __in efx_mae_actions_t *spec,
1632 __in efx_mae_action_t type,
1633 __in size_t arg_size,
1634 __in_bcount(arg_size) const uint8_t *arg)
1636 uint32_t action_mask;
1639 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1640 (sizeof (efx_mae_action_ordered_map) * 8));
1641 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1642 (sizeof (efx_mae_action_repeat_map) * 8));
1644 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
1645 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
1646 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
1648 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
1653 action_mask = (1U << type);
1655 if ((spec->ema_actions & action_mask) != 0) {
1656 /* The action set already contains this action. */
1657 if ((efx_mae_action_repeat_map & action_mask) == 0) {
1658 /* Cannot add another non-repeatable action. */
1664 if ((efx_mae_action_ordered_map & action_mask) != 0) {
1665 uint32_t strict_ordered_map =
1666 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
1667 uint32_t later_actions_mask =
1668 strict_ordered_map & ~(action_mask | (action_mask - 1));
1670 if ((spec->ema_actions & later_actions_mask) != 0) {
1671 /* Cannot add an action after later ordered actions. */
1677 if (efx_mae_actions[type].emad_add != NULL) {
1678 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
1683 spec->ema_actions |= action_mask;
1694 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1698 __checkReturn efx_rc_t
1699 efx_mae_action_set_populate_decap(
1700 __in efx_mae_actions_t *spec)
1702 return (efx_mae_action_set_spec_populate(spec,
1703 EFX_MAE_ACTION_DECAP, 0, NULL));
1706 __checkReturn efx_rc_t
1707 efx_mae_action_set_populate_vlan_pop(
1708 __in efx_mae_actions_t *spec)
1710 return (efx_mae_action_set_spec_populate(spec,
1711 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1714 __checkReturn efx_rc_t
1715 efx_mae_action_set_populate_vlan_push(
1716 __in efx_mae_actions_t *spec,
1717 __in uint16_t tpid_be,
1718 __in uint16_t tci_be)
1720 efx_mae_action_vlan_push_t action;
1721 const uint8_t *arg = (const uint8_t *)&action;
1723 action.emavp_tpid_be = tpid_be;
1724 action.emavp_tci_be = tci_be;
1726 return (efx_mae_action_set_spec_populate(spec,
1727 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1730 __checkReturn efx_rc_t
1731 efx_mae_action_set_populate_encap(
1732 __in efx_mae_actions_t *spec)
1735 * There is no argument to pass encap. header ID, thus, one does not
1736 * need to allocate an encap. header while parsing application input.
1737 * This is useful since building an action set may be done simply to
1738 * validate a rule, whilst resource allocation usually consumes time.
1740 return (efx_mae_action_set_spec_populate(spec,
1741 EFX_MAE_ACTION_ENCAP, 0, NULL));
1744 __checkReturn efx_rc_t
1745 efx_mae_action_set_populate_count(
1746 __in efx_mae_actions_t *spec)
1749 * There is no argument to pass counter ID, thus, one does not
1750 * need to allocate a counter while parsing application input.
1751 * This is useful since building an action set may be done simply to
1752 * validate a rule, whilst resource allocation usually consumes time.
1754 return (efx_mae_action_set_spec_populate(spec,
1755 EFX_MAE_ACTION_COUNT, 0, NULL));
1758 __checkReturn efx_rc_t
1759 efx_mae_action_set_populate_flag(
1760 __in efx_mae_actions_t *spec)
1762 return (efx_mae_action_set_spec_populate(spec,
1763 EFX_MAE_ACTION_FLAG, 0, NULL));
1766 __checkReturn efx_rc_t
1767 efx_mae_action_set_populate_mark(
1768 __in efx_mae_actions_t *spec,
1769 __in uint32_t mark_value)
1771 const uint8_t *arg = (const uint8_t *)&mark_value;
1773 return (efx_mae_action_set_spec_populate(spec,
1774 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1777 __checkReturn efx_rc_t
1778 efx_mae_action_set_populate_deliver(
1779 __in efx_mae_actions_t *spec,
1780 __in const efx_mport_sel_t *mportp)
1785 if (mportp == NULL) {
1790 arg = (const uint8_t *)&mportp->sel;
1792 return (efx_mae_action_set_spec_populate(spec,
1793 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1796 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1800 __checkReturn efx_rc_t
1801 efx_mae_action_set_populate_drop(
1802 __in efx_mae_actions_t *spec)
1804 efx_mport_sel_t mport;
1808 EFX_POPULATE_DWORD_1(dword,
1809 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1812 * The constructed DWORD is little-endian,
1813 * but the resulting value is meant to be
1814 * passed to MCDIs, where it will undergo
1815 * host-order to little endian conversion.
1817 mport.sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
1819 arg = (const uint8_t *)&mport.sel;
1821 return (efx_mae_action_set_spec_populate(spec,
1822 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1825 __checkReturn boolean_t
1826 efx_mae_action_set_specs_equal(
1827 __in const efx_mae_actions_t *left,
1828 __in const efx_mae_actions_t *right)
1830 size_t cmp_size = EFX_FIELD_OFFSET(efx_mae_actions_t, ema_rsrc);
1833 * An action set specification consists of two parts. The first part
1834 * indicates what actions are included in the action set, as well as
1835 * extra quantitative values (in example, the number of VLAN tags to
1836 * push). The second part comprises resource IDs used by the actions.
1838 * A resource, in example, a counter, is allocated from the hardware
1839 * by the client, and it's the client who is responsible for keeping
1840 * track of allocated resources and comparing resource IDs if needed.
1842 * In this API, don't compare resource IDs in the two specifications.
1845 return ((memcmp(left, right, cmp_size) == 0) ? B_TRUE : B_FALSE);
1848 __checkReturn efx_rc_t
1849 efx_mae_match_specs_class_cmp(
1850 __in efx_nic_t *enp,
1851 __in const efx_mae_match_spec_t *left,
1852 __in const efx_mae_match_spec_t *right,
1853 __out boolean_t *have_same_classp)
1855 efx_mae_t *maep = enp->en_maep;
1856 unsigned int field_ncaps = maep->em_max_nfields;
1857 const efx_mae_field_cap_t *field_caps;
1858 const efx_mae_mv_desc_t *desc_setp;
1859 unsigned int desc_set_nentries;
1860 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1861 unsigned int bit_desc_set_nentries;
1862 boolean_t have_same_class = B_TRUE;
1863 efx_mae_field_id_t field_id;
1864 const uint8_t *mvpl;
1865 const uint8_t *mvpr;
1868 switch (left->emms_type) {
1869 case EFX_MAE_RULE_OUTER:
1870 field_caps = maep->em_outer_rule_field_caps;
1871 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1873 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1874 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1875 bit_desc_set_nentries =
1876 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1877 mvpl = left->emms_mask_value_pairs.outer;
1878 mvpr = right->emms_mask_value_pairs.outer;
1880 case EFX_MAE_RULE_ACTION:
1881 field_caps = maep->em_action_rule_field_caps;
1882 desc_setp = __efx_mae_action_rule_mv_desc_set;
1884 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1885 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1886 bit_desc_set_nentries =
1887 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1888 mvpl = left->emms_mask_value_pairs.action;
1889 mvpr = right->emms_mask_value_pairs.action;
1896 if (field_caps == NULL) {
1901 if (left->emms_type != right->emms_type ||
1902 left->emms_prio != right->emms_prio) {
1904 * Rules of different types can never map to the same class.
1906 * The FW can support some set of match criteria for one
1907 * priority and not support the very same set for
1908 * another priority. Thus, two rules which have
1909 * different priorities can never map to
1912 *have_same_classp = B_FALSE;
1916 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1918 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1919 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1920 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1921 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1922 size_t mask_size = descp->emmd_mask_size;
1923 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1924 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1925 size_t value_size = descp->emmd_value_size;
1928 continue; /* Skip array gap */
1930 if ((unsigned int)field_cap_id >= field_ncaps) {
1932 * The FW has not reported capability status for this
1933 * field. It's unknown whether any difference between
1934 * the two masks / values affects the class. The only
1935 * case when the class must be the same is when these
1936 * mask-value pairs match. Otherwise, report mismatch.
1938 if ((memcmp(lmaskp, rmaskp, mask_size) == 0) &&
1939 (memcmp(lvalp, rvalp, value_size) == 0))
1945 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1946 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1947 have_same_class = B_FALSE;
1952 if (field_caps[field_cap_id].emfc_match_affects_class) {
1953 if (memcmp(lvalp, rvalp, value_size) != 0) {
1954 have_same_class = B_FALSE;
1960 if (have_same_class == B_FALSE)
1963 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1965 const efx_mae_mv_bit_desc_t *bit_descp =
1966 &bit_desc_setp[field_id];
1967 efx_mae_field_cap_id_t bit_cap_id =
1968 bit_descp->emmbd_bit_cap_id;
1969 unsigned int byte_idx;
1970 unsigned int bit_idx;
1972 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1973 continue; /* Skip array gap */
1975 if ((unsigned int)bit_cap_id >= field_ncaps)
1979 bit_descp->emmbd_mask_ofst +
1980 bit_descp->emmbd_mask_lbn / 8;
1982 bit_descp->emmbd_mask_lbn % 8;
1984 if (field_caps[bit_cap_id].emfc_mask_affects_class &&
1985 (mvpl[byte_idx] & (1U << bit_idx)) !=
1986 (mvpr[byte_idx] & (1U << bit_idx))) {
1987 have_same_class = B_FALSE;
1992 bit_descp->emmbd_value_ofst +
1993 bit_descp->emmbd_value_lbn / 8;
1995 bit_descp->emmbd_value_lbn % 8;
1997 if (field_caps[bit_cap_id].emfc_match_affects_class &&
1998 (mvpl[byte_idx] & (1U << bit_idx)) !=
1999 (mvpr[byte_idx] & (1U << bit_idx))) {
2000 have_same_class = B_FALSE;
2006 *have_same_classp = have_same_class;
2013 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2017 __checkReturn efx_rc_t
2018 efx_mae_outer_rule_insert(
2019 __in efx_nic_t *enp,
2020 __in const efx_mae_match_spec_t *spec,
2021 __in efx_tunnel_protocol_t encap_type,
2022 __out efx_mae_rule_id_t *or_idp)
2024 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2026 EFX_MCDI_DECLARE_BUF(payload,
2027 MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2,
2028 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
2029 uint32_t encap_type_mcdi;
2030 efx_mae_rule_id_t or_id;
2034 EFX_STATIC_ASSERT(sizeof (or_idp->id) ==
2035 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OR_ID_LEN);
2037 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2038 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL);
2040 if (encp->enc_mae_supported == B_FALSE) {
2045 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
2050 switch (encap_type) {
2051 case EFX_TUNNEL_PROTOCOL_NONE:
2052 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2054 case EFX_TUNNEL_PROTOCOL_VXLAN:
2055 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2057 case EFX_TUNNEL_PROTOCOL_GENEVE:
2058 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2060 case EFX_TUNNEL_PROTOCOL_NVGRE:
2061 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2068 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_INSERT;
2069 req.emr_in_buf = payload;
2070 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2;
2071 req.emr_out_buf = payload;
2072 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN;
2074 MCDI_IN_SET_DWORD(req,
2075 MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, encap_type_mcdi);
2077 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_INSERT_IN_PRIO, spec->emms_prio);
2080 * Mask-value pairs have been stored in the byte order needed for the
2081 * MCDI request and are thus safe to be copied directly to the buffer.
2082 * The library cares about byte order in efx_mae_match_spec_field_set().
2084 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.outer) >=
2085 MAE_ENC_FIELD_PAIRS_LEN);
2086 offset = MC_CMD_MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA_OFST;
2087 memcpy(payload + offset, spec->emms_mask_value_pairs.outer,
2088 MAE_ENC_FIELD_PAIRS_LEN);
2090 efx_mcdi_execute(enp, &req);
2092 if (req.emr_rc != 0) {
2097 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN) {
2102 or_id.id = MCDI_OUT_DWORD(req, MAE_OUTER_RULE_INSERT_OUT_OR_ID);
2103 if (or_id.id == EFX_MAE_RSRC_ID_INVALID) {
2108 or_idp->id = or_id.id;
2123 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2127 __checkReturn efx_rc_t
2128 efx_mae_outer_rule_remove(
2129 __in efx_nic_t *enp,
2130 __in const efx_mae_rule_id_t *or_idp)
2132 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2134 EFX_MCDI_DECLARE_BUF(payload,
2135 MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1),
2136 MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
2139 if (encp->enc_mae_supported == B_FALSE) {
2144 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_REMOVE;
2145 req.emr_in_buf = payload;
2146 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1);
2147 req.emr_out_buf = payload;
2148 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1);
2150 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_REMOVE_IN_OR_ID, or_idp->id);
2152 efx_mcdi_execute(enp, &req);
2154 if (req.emr_rc != 0) {
2159 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LENMIN) {
2164 if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
2166 /* Firmware failed to remove the outer rule. */
2180 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2184 __checkReturn efx_rc_t
2185 efx_mae_match_spec_outer_rule_id_set(
2186 __in efx_mae_match_spec_t *spec,
2187 __in const efx_mae_rule_id_t *or_idp)
2189 uint32_t full_mask = UINT32_MAX;
2192 if (spec->emms_type != EFX_MAE_RULE_ACTION) {
2197 if (or_idp == NULL) {
2202 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_OUTER_RULE_ID,
2203 sizeof (or_idp->id), (const uint8_t *)&or_idp->id,
2204 sizeof (full_mask), (const uint8_t *)&full_mask);
2215 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2219 __checkReturn efx_rc_t
2220 efx_mae_encap_header_alloc(
2221 __in efx_nic_t *enp,
2222 __in efx_tunnel_protocol_t encap_type,
2223 __in_bcount(header_size) uint8_t *header_data,
2224 __in size_t header_size,
2225 __out efx_mae_eh_id_t *eh_idp)
2227 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2229 EFX_MCDI_DECLARE_BUF(payload,
2230 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LENMAX_MCDI2,
2231 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
2232 uint32_t encap_type_mcdi;
2233 efx_mae_eh_id_t eh_id;
2236 EFX_STATIC_ASSERT(sizeof (eh_idp->id) ==
2237 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_LEN);
2239 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2240 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL);
2242 if (encp->enc_mae_supported == B_FALSE) {
2247 switch (encap_type) {
2248 case EFX_TUNNEL_PROTOCOL_NONE:
2249 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2251 case EFX_TUNNEL_PROTOCOL_VXLAN:
2252 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2254 case EFX_TUNNEL_PROTOCOL_GENEVE:
2255 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2257 case EFX_TUNNEL_PROTOCOL_NVGRE:
2258 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2266 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2) {
2271 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_ALLOC;
2272 req.emr_in_buf = payload;
2273 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(header_size);
2274 req.emr_out_buf = payload;
2275 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN;
2277 MCDI_IN_SET_DWORD(req,
2278 MAE_ENCAP_HEADER_ALLOC_IN_ENCAP_TYPE, encap_type_mcdi);
2280 memcpy(payload + MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_OFST,
2281 header_data, header_size);
2283 efx_mcdi_execute(enp, &req);
2285 if (req.emr_rc != 0) {
2290 if (req.emr_out_length_used < MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN) {
2295 eh_id.id = MCDI_OUT_DWORD(req,
2296 MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID);
2298 if (eh_id.id == EFX_MAE_RSRC_ID_INVALID) {
2303 eh_idp->id = eh_id.id;
2318 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2322 __checkReturn efx_rc_t
2323 efx_mae_encap_header_free(
2324 __in efx_nic_t *enp,
2325 __in const efx_mae_eh_id_t *eh_idp)
2327 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2329 EFX_MCDI_DECLARE_BUF(payload,
2330 MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1),
2331 MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
2334 if (encp->enc_mae_supported == B_FALSE) {
2339 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_FREE;
2340 req.emr_in_buf = payload;
2341 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1);
2342 req.emr_out_buf = payload;
2343 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1);
2345 MCDI_IN_SET_DWORD(req, MAE_ENCAP_HEADER_FREE_IN_EH_ID, eh_idp->id);
2347 efx_mcdi_execute(enp, &req);
2349 if (req.emr_rc != 0) {
2354 if (MCDI_OUT_DWORD(req, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) !=
2356 /* Firmware failed to remove the encap. header. */
2368 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2372 __checkReturn efx_rc_t
2373 efx_mae_action_set_fill_in_eh_id(
2374 __in efx_mae_actions_t *spec,
2375 __in const efx_mae_eh_id_t *eh_idp)
2379 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_ENCAP)) == 0) {
2381 * The caller has not intended to have action ENCAP originally,
2382 * hence, this attempt to indicate encap. header ID is invalid.
2388 if (spec->ema_rsrc.emar_eh_id.id != EFX_MAE_RSRC_ID_INVALID) {
2389 /* The caller attempts to indicate encap. header ID twice. */
2394 if (eh_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2399 spec->ema_rsrc.emar_eh_id.id = eh_idp->id;
2408 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2412 __checkReturn efx_rc_t
2413 efx_mae_action_set_alloc(
2414 __in efx_nic_t *enp,
2415 __in const efx_mae_actions_t *spec,
2416 __out efx_mae_aset_id_t *aset_idp)
2418 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2420 EFX_MCDI_DECLARE_BUF(payload,
2421 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
2422 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
2423 efx_mae_aset_id_t aset_id;
2426 if (encp->enc_mae_supported == B_FALSE) {
2431 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
2432 req.emr_in_buf = payload;
2433 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
2434 req.emr_out_buf = payload;
2435 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
2438 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
2439 * corresponding resource types are supported by the implementation.
2440 * Use proper resource ID assignments instead.
2442 MCDI_IN_SET_DWORD(req,
2443 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
2445 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_DECAP)) != 0) {
2446 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2447 MAE_ACTION_SET_ALLOC_IN_DECAP, 1);
2450 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2451 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
2453 if (spec->ema_n_vlan_tags_to_push > 0) {
2454 unsigned int outer_tag_idx;
2456 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2457 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
2458 spec->ema_n_vlan_tags_to_push);
2460 if (spec->ema_n_vlan_tags_to_push ==
2461 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
2462 MCDI_IN_SET_WORD(req,
2463 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
2464 spec->ema_vlan_push_descs[0].emavp_tpid_be);
2465 MCDI_IN_SET_WORD(req,
2466 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
2467 spec->ema_vlan_push_descs[0].emavp_tci_be);
2470 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
2472 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
2473 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
2474 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
2475 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
2478 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
2479 spec->ema_rsrc.emar_eh_id.id);
2480 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID,
2481 spec->ema_rsrc.emar_counter_id.id);
2483 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
2484 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2485 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
2488 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
2489 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2490 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
2492 MCDI_IN_SET_DWORD(req,
2493 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
2496 MCDI_IN_SET_DWORD(req,
2497 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
2499 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
2500 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2501 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
2502 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2504 efx_mcdi_execute(enp, &req);
2506 if (req.emr_rc != 0) {
2511 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
2516 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
2517 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
2522 aset_idp->id = aset_id.id;
2533 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2537 __checkReturn unsigned int
2538 efx_mae_action_set_get_nb_count(
2539 __in const efx_mae_actions_t *spec)
2541 return (spec->ema_n_count_actions);
2544 __checkReturn efx_rc_t
2545 efx_mae_action_set_fill_in_counter_id(
2546 __in efx_mae_actions_t *spec,
2547 __in const efx_counter_t *counter_idp)
2551 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_COUNT)) == 0) {
2553 * Invalid to add counter ID if spec does not have COUNT action.
2559 if (spec->ema_n_count_actions != 1) {
2561 * Having multiple COUNT actions in the spec requires a counter
2562 * list to be used. This API must only be used for a single
2563 * counter per spec. Turn down the request as inappropriate.
2569 if (spec->ema_rsrc.emar_counter_id.id != EFX_MAE_RSRC_ID_INVALID) {
2570 /* The caller attempts to indicate counter ID twice. */
2575 if (counter_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2580 spec->ema_rsrc.emar_counter_id.id = counter_idp->id;
2591 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2595 __checkReturn efx_rc_t
2596 efx_mae_counters_alloc(
2597 __in efx_nic_t *enp,
2598 __in uint32_t n_counters,
2599 __out uint32_t *n_allocatedp,
2600 __out_ecount(n_counters) efx_counter_t *countersp,
2601 __out_opt uint32_t *gen_countp)
2603 EFX_MCDI_DECLARE_BUF(payload,
2604 MC_CMD_MAE_COUNTER_ALLOC_IN_LEN,
2605 MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMAX_MCDI2);
2606 efx_mae_t *maep = enp->en_maep;
2607 uint32_t n_allocated;
2612 if (n_counters > maep->em_max_ncounters ||
2613 n_counters < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM ||
2614 n_counters > MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MAXNUM_MCDI2) {
2619 req.emr_cmd = MC_CMD_MAE_COUNTER_ALLOC;
2620 req.emr_in_buf = payload;
2621 req.emr_in_length = MC_CMD_MAE_COUNTER_ALLOC_IN_LEN;
2622 req.emr_out_buf = payload;
2623 req.emr_out_length = MC_CMD_MAE_COUNTER_ALLOC_OUT_LEN(n_counters);
2625 MCDI_IN_SET_DWORD(req, MAE_COUNTER_ALLOC_IN_REQUESTED_COUNT,
2628 efx_mcdi_execute(enp, &req);
2630 if (req.emr_rc != 0) {
2635 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMIN) {
2640 n_allocated = MCDI_OUT_DWORD(req,
2641 MAE_COUNTER_ALLOC_OUT_COUNTER_ID_COUNT);
2642 if (n_allocated < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM) {
2647 for (i = 0; i < n_allocated; i++) {
2648 countersp[i].id = MCDI_OUT_INDEXED_DWORD(req,
2649 MAE_COUNTER_ALLOC_OUT_COUNTER_ID, i);
2652 if (gen_countp != NULL) {
2653 *gen_countp = MCDI_OUT_DWORD(req,
2654 MAE_COUNTER_ALLOC_OUT_GENERATION_COUNT);
2657 *n_allocatedp = n_allocated;
2668 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2673 __checkReturn efx_rc_t
2674 efx_mae_counters_free(
2675 __in efx_nic_t *enp,
2676 __in uint32_t n_counters,
2677 __out uint32_t *n_freedp,
2678 __in_ecount(n_counters) const efx_counter_t *countersp,
2679 __out_opt uint32_t *gen_countp)
2681 EFX_MCDI_DECLARE_BUF(payload,
2682 MC_CMD_MAE_COUNTER_FREE_IN_LENMAX_MCDI2,
2683 MC_CMD_MAE_COUNTER_FREE_OUT_LENMAX_MCDI2);
2684 efx_mae_t *maep = enp->en_maep;
2690 if (n_counters > maep->em_max_ncounters ||
2691 n_counters < MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MINNUM ||
2693 MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MAXNUM_MCDI2) {
2698 req.emr_cmd = MC_CMD_MAE_COUNTER_FREE;
2699 req.emr_in_buf = payload;
2700 req.emr_in_length = MC_CMD_MAE_COUNTER_FREE_IN_LEN(n_counters);
2701 req.emr_out_buf = payload;
2702 req.emr_out_length = MC_CMD_MAE_COUNTER_FREE_OUT_LEN(n_counters);
2704 for (i = 0; i < n_counters; i++) {
2705 MCDI_IN_SET_INDEXED_DWORD(req,
2706 MAE_COUNTER_FREE_IN_FREE_COUNTER_ID, i, countersp[i].id);
2708 MCDI_IN_SET_DWORD(req, MAE_COUNTER_FREE_IN_COUNTER_ID_COUNT,
2711 efx_mcdi_execute(enp, &req);
2713 if (req.emr_rc != 0) {
2718 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_FREE_OUT_LENMIN) {
2723 n_freed = MCDI_OUT_DWORD(req, MAE_COUNTER_FREE_OUT_COUNTER_ID_COUNT);
2725 if (n_freed < MC_CMD_MAE_COUNTER_FREE_OUT_FREED_COUNTER_ID_MINNUM) {
2730 if (gen_countp != NULL) {
2731 *gen_countp = MCDI_OUT_DWORD(req,
2732 MAE_COUNTER_FREE_OUT_GENERATION_COUNT);
2735 *n_freedp = n_freed;
2746 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2751 __checkReturn efx_rc_t
2752 efx_mae_counters_stream_start(
2753 __in efx_nic_t *enp,
2754 __in uint16_t rxq_id,
2755 __in uint16_t packet_size,
2756 __in uint32_t flags_in,
2757 __out uint32_t *flags_out)
2760 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN,
2761 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN);
2764 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_IN_ZERO_SQUASH_DISABLE ==
2765 1U << MC_CMD_MAE_COUNTERS_STREAM_START_IN_ZERO_SQUASH_DISABLE_LBN);
2767 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_OUT_USES_CREDITS ==
2768 1U << MC_CMD_MAE_COUNTERS_STREAM_START_OUT_USES_CREDITS_LBN);
2770 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_START;
2771 req.emr_in_buf = payload;
2772 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN;
2773 req.emr_out_buf = payload;
2774 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN;
2776 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_QID, rxq_id);
2777 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_PACKET_SIZE,
2779 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_START_IN_FLAGS, flags_in);
2781 efx_mcdi_execute(enp, &req);
2783 if (req.emr_rc != 0) {
2788 if (req.emr_out_length_used <
2789 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN) {
2794 *flags_out = MCDI_OUT_DWORD(req, MAE_COUNTERS_STREAM_START_OUT_FLAGS);
2801 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2806 __checkReturn efx_rc_t
2807 efx_mae_counters_stream_stop(
2808 __in efx_nic_t *enp,
2809 __in uint16_t rxq_id,
2810 __out_opt uint32_t *gen_countp)
2813 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN,
2814 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN);
2817 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_STOP;
2818 req.emr_in_buf = payload;
2819 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN;
2820 req.emr_out_buf = payload;
2821 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN;
2823 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_STOP_IN_QID, rxq_id);
2825 efx_mcdi_execute(enp, &req);
2827 if (req.emr_rc != 0) {
2832 if (req.emr_out_length_used <
2833 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN) {
2838 if (gen_countp != NULL) {
2839 *gen_countp = MCDI_OUT_DWORD(req,
2840 MAE_COUNTERS_STREAM_STOP_OUT_GENERATION_COUNT);
2848 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2853 __checkReturn efx_rc_t
2854 efx_mae_counters_stream_give_credits(
2855 __in efx_nic_t *enp,
2856 __in uint32_t n_credits)
2859 EFX_MCDI_DECLARE_BUF(payload,
2860 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN,
2861 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN);
2864 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS;
2865 req.emr_in_buf = payload;
2866 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN;
2867 req.emr_out_buf = payload;
2868 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN;
2870 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_NUM_CREDITS,
2873 efx_mcdi_execute(enp, &req);
2875 if (req.emr_rc != 0) {
2883 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2888 __checkReturn efx_rc_t
2889 efx_mae_action_set_free(
2890 __in efx_nic_t *enp,
2891 __in const efx_mae_aset_id_t *aset_idp)
2893 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2895 EFX_MCDI_DECLARE_BUF(payload,
2896 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
2897 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
2900 if (encp->enc_mae_supported == B_FALSE) {
2905 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
2906 req.emr_in_buf = payload;
2907 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
2908 req.emr_out_buf = payload;
2909 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
2911 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
2913 efx_mcdi_execute(enp, &req);
2915 if (req.emr_rc != 0) {
2920 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_FREE_OUT_LENMIN) {
2925 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
2927 /* Firmware failed to free the action set. */
2941 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2945 __checkReturn efx_rc_t
2946 efx_mae_action_rule_insert(
2947 __in efx_nic_t *enp,
2948 __in const efx_mae_match_spec_t *spec,
2949 __in const efx_mae_aset_list_id_t *asl_idp,
2950 __in const efx_mae_aset_id_t *as_idp,
2951 __out efx_mae_rule_id_t *ar_idp)
2953 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2955 EFX_MCDI_DECLARE_BUF(payload,
2956 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
2957 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
2958 efx_oword_t *rule_response;
2959 efx_mae_rule_id_t ar_id;
2963 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
2964 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
2966 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2967 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
2969 if (encp->enc_mae_supported == B_FALSE) {
2974 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
2975 (asl_idp != NULL && as_idp != NULL) ||
2976 (asl_idp == NULL && as_idp == NULL)) {
2981 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
2982 req.emr_in_buf = payload;
2983 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
2984 req.emr_out_buf = payload;
2985 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
2987 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
2988 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
2989 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
2990 rule_response = (efx_oword_t *)(payload + offset);
2991 EFX_POPULATE_OWORD_3(*rule_response,
2992 MAE_ACTION_RULE_RESPONSE_ASL_ID,
2993 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
2994 MAE_ACTION_RULE_RESPONSE_AS_ID,
2995 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
2996 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
2998 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
3001 * Mask-value pairs have been stored in the byte order needed for the
3002 * MCDI request and are thus safe to be copied directly to the buffer.
3004 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
3005 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3006 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
3007 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
3008 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3010 efx_mcdi_execute(enp, &req);
3012 if (req.emr_rc != 0) {
3017 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
3022 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
3023 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
3028 ar_idp->id = ar_id.id;
3041 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3045 __checkReturn efx_rc_t
3046 efx_mae_action_rule_remove(
3047 __in efx_nic_t *enp,
3048 __in const efx_mae_rule_id_t *ar_idp)
3050 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3052 EFX_MCDI_DECLARE_BUF(payload,
3053 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
3054 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
3057 if (encp->enc_mae_supported == B_FALSE) {
3062 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
3063 req.emr_in_buf = payload;
3064 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
3065 req.emr_out_buf = payload;
3066 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
3068 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
3070 efx_mcdi_execute(enp, &req);
3072 if (req.emr_rc != 0) {
3077 if (req.emr_out_length_used <
3078 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LENMIN) {
3083 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
3085 /* Firmware failed to delete the action rule. */
3099 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3103 #endif /* EFSYS_OPT_MAE */