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);
75 EFSYS_PROBE1(fail1, efx_rc_t, rc);
79 static __checkReturn efx_rc_t
80 efx_mae_get_outer_rule_caps(
82 __in unsigned int field_ncaps,
83 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
86 EFX_MCDI_DECLARE_BUF(payload,
87 MC_CMD_MAE_GET_OR_CAPS_IN_LEN,
88 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2);
89 unsigned int mcdi_field_ncaps;
93 if (MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps) >
94 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2) {
99 req.emr_cmd = MC_CMD_MAE_GET_OR_CAPS;
100 req.emr_in_buf = payload;
101 req.emr_in_length = MC_CMD_MAE_GET_OR_CAPS_IN_LEN;
102 req.emr_out_buf = payload;
103 req.emr_out_length = MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps);
105 efx_mcdi_execute(enp, &req);
107 if (req.emr_rc != 0) {
112 if (req.emr_out_length_used < MC_CMD_MAE_GET_OR_CAPS_OUT_LENMIN) {
117 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
119 if (req.emr_out_length_used <
120 MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
125 if (mcdi_field_ncaps > field_ncaps) {
130 for (i = 0; i < mcdi_field_ncaps; ++i) {
134 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
135 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
136 MAE_FIELD_FLAGS_SUPPORT_STATUS);
138 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
139 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
140 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
142 field_caps[i].emfc_match_affects_class =
143 (match_flag != 0) ? B_TRUE : B_FALSE;
145 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
146 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
147 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
149 field_caps[i].emfc_mask_affects_class =
150 (mask_flag != 0) ? B_TRUE : B_FALSE;
164 EFSYS_PROBE1(fail1, efx_rc_t, rc);
168 static __checkReturn efx_rc_t
169 efx_mae_get_action_rule_caps(
171 __in unsigned int field_ncaps,
172 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
175 EFX_MCDI_DECLARE_BUF(payload,
176 MC_CMD_MAE_GET_AR_CAPS_IN_LEN,
177 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2);
178 unsigned int mcdi_field_ncaps;
182 if (MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps) >
183 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2) {
188 req.emr_cmd = MC_CMD_MAE_GET_AR_CAPS;
189 req.emr_in_buf = payload;
190 req.emr_in_length = MC_CMD_MAE_GET_AR_CAPS_IN_LEN;
191 req.emr_out_buf = payload;
192 req.emr_out_length = MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps);
194 efx_mcdi_execute(enp, &req);
196 if (req.emr_rc != 0) {
201 if (req.emr_out_length_used < MC_CMD_MAE_GET_AR_CAPS_OUT_LENMIN) {
206 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_AR_CAPS_OUT_COUNT);
208 if (req.emr_out_length_used <
209 MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
214 if (mcdi_field_ncaps > field_ncaps) {
219 for (i = 0; i < mcdi_field_ncaps; ++i) {
223 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
224 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
225 MAE_FIELD_FLAGS_SUPPORT_STATUS);
227 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
228 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
229 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
231 field_caps[i].emfc_match_affects_class =
232 (match_flag != 0) ? B_TRUE : B_FALSE;
234 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
235 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
236 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
238 field_caps[i].emfc_mask_affects_class =
239 (mask_flag != 0) ? B_TRUE : B_FALSE;
253 EFSYS_PROBE1(fail1, efx_rc_t, rc);
257 __checkReturn efx_rc_t
261 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
262 efx_mae_field_cap_t *or_fcaps;
263 size_t or_fcaps_size;
264 efx_mae_field_cap_t *ar_fcaps;
265 size_t ar_fcaps_size;
269 if (encp->enc_mae_supported == B_FALSE) {
274 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*maep), maep);
282 rc = efx_mae_get_capabilities(enp);
286 or_fcaps_size = maep->em_max_nfields * sizeof (*or_fcaps);
287 EFSYS_KMEM_ALLOC(enp->en_esip, or_fcaps_size, or_fcaps);
288 if (or_fcaps == NULL) {
293 maep->em_outer_rule_field_caps_size = or_fcaps_size;
294 maep->em_outer_rule_field_caps = or_fcaps;
296 rc = efx_mae_get_outer_rule_caps(enp, maep->em_max_nfields, or_fcaps);
300 ar_fcaps_size = maep->em_max_nfields * sizeof (*ar_fcaps);
301 EFSYS_KMEM_ALLOC(enp->en_esip, ar_fcaps_size, ar_fcaps);
302 if (ar_fcaps == NULL) {
307 maep->em_action_rule_field_caps_size = ar_fcaps_size;
308 maep->em_action_rule_field_caps = ar_fcaps;
310 rc = efx_mae_get_action_rule_caps(enp, maep->em_max_nfields, ar_fcaps);
318 EFSYS_KMEM_FREE(enp->en_esip, ar_fcaps_size, ar_fcaps);
323 EFSYS_KMEM_FREE(enp->en_esip, or_fcaps_size, or_fcaps);
328 EFSYS_KMEM_FREE(enp->en_esip, sizeof (struct efx_mae_s), enp->en_maep);
333 EFSYS_PROBE1(fail1, efx_rc_t, rc);
341 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
342 efx_mae_t *maep = enp->en_maep;
344 if (encp->enc_mae_supported == B_FALSE)
347 EFSYS_KMEM_FREE(enp->en_esip, maep->em_action_rule_field_caps_size,
348 maep->em_action_rule_field_caps);
349 EFSYS_KMEM_FREE(enp->en_esip, maep->em_outer_rule_field_caps_size,
350 maep->em_outer_rule_field_caps);
351 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*maep), maep);
355 __checkReturn efx_rc_t
358 __out efx_mae_limits_t *emlp)
360 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
361 struct efx_mae_s *maep = enp->en_maep;
364 if (encp->enc_mae_supported == B_FALSE) {
369 emlp->eml_max_n_outer_prios = maep->em_max_n_outer_prios;
370 emlp->eml_max_n_action_prios = maep->em_max_n_action_prios;
371 emlp->eml_encap_types_supported = maep->em_encap_types_supported;
372 emlp->eml_encap_header_size_limit =
373 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2;
378 EFSYS_PROBE1(fail1, efx_rc_t, rc);
382 __checkReturn efx_rc_t
383 efx_mae_match_spec_init(
385 __in efx_mae_rule_type_t type,
387 __out efx_mae_match_spec_t **specp)
389 efx_mae_match_spec_t *spec;
393 case EFX_MAE_RULE_OUTER:
395 case EFX_MAE_RULE_ACTION:
402 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
408 spec->emms_type = type;
409 spec->emms_prio = prio;
418 EFSYS_PROBE1(fail1, efx_rc_t, rc);
423 efx_mae_match_spec_fini(
425 __in efx_mae_match_spec_t *spec)
427 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
430 /* Named identifiers which are valid indices to efx_mae_field_cap_t */
431 typedef enum efx_mae_field_cap_id_e {
432 EFX_MAE_FIELD_ID_INGRESS_MPORT_SELECTOR = MAE_FIELD_INGRESS_PORT,
433 EFX_MAE_FIELD_ID_ETHER_TYPE_BE = MAE_FIELD_ETHER_TYPE,
434 EFX_MAE_FIELD_ID_ETH_SADDR_BE = MAE_FIELD_ETH_SADDR,
435 EFX_MAE_FIELD_ID_ETH_DADDR_BE = MAE_FIELD_ETH_DADDR,
436 EFX_MAE_FIELD_ID_VLAN0_TCI_BE = MAE_FIELD_VLAN0_TCI,
437 EFX_MAE_FIELD_ID_VLAN0_PROTO_BE = MAE_FIELD_VLAN0_PROTO,
438 EFX_MAE_FIELD_ID_VLAN1_TCI_BE = MAE_FIELD_VLAN1_TCI,
439 EFX_MAE_FIELD_ID_VLAN1_PROTO_BE = MAE_FIELD_VLAN1_PROTO,
440 EFX_MAE_FIELD_ID_SRC_IP4_BE = MAE_FIELD_SRC_IP4,
441 EFX_MAE_FIELD_ID_DST_IP4_BE = MAE_FIELD_DST_IP4,
442 EFX_MAE_FIELD_ID_IP_PROTO = MAE_FIELD_IP_PROTO,
443 EFX_MAE_FIELD_ID_IP_TOS = MAE_FIELD_IP_TOS,
444 EFX_MAE_FIELD_ID_IP_TTL = MAE_FIELD_IP_TTL,
445 EFX_MAE_FIELD_ID_SRC_IP6_BE = MAE_FIELD_SRC_IP6,
446 EFX_MAE_FIELD_ID_DST_IP6_BE = MAE_FIELD_DST_IP6,
447 EFX_MAE_FIELD_ID_L4_SPORT_BE = MAE_FIELD_L4_SPORT,
448 EFX_MAE_FIELD_ID_L4_DPORT_BE = MAE_FIELD_L4_DPORT,
449 EFX_MAE_FIELD_ID_TCP_FLAGS_BE = MAE_FIELD_TCP_FLAGS,
450 EFX_MAE_FIELD_ID_ENC_ETHER_TYPE_BE = MAE_FIELD_ENC_ETHER_TYPE,
451 EFX_MAE_FIELD_ID_ENC_ETH_SADDR_BE = MAE_FIELD_ENC_ETH_SADDR,
452 EFX_MAE_FIELD_ID_ENC_ETH_DADDR_BE = MAE_FIELD_ENC_ETH_DADDR,
453 EFX_MAE_FIELD_ID_ENC_VLAN0_TCI_BE = MAE_FIELD_ENC_VLAN0_TCI,
454 EFX_MAE_FIELD_ID_ENC_VLAN0_PROTO_BE = MAE_FIELD_ENC_VLAN0_PROTO,
455 EFX_MAE_FIELD_ID_ENC_VLAN1_TCI_BE = MAE_FIELD_ENC_VLAN1_TCI,
456 EFX_MAE_FIELD_ID_ENC_VLAN1_PROTO_BE = MAE_FIELD_ENC_VLAN1_PROTO,
457 EFX_MAE_FIELD_ID_ENC_SRC_IP4_BE = MAE_FIELD_ENC_SRC_IP4,
458 EFX_MAE_FIELD_ID_ENC_DST_IP4_BE = MAE_FIELD_ENC_DST_IP4,
459 EFX_MAE_FIELD_ID_ENC_IP_PROTO = MAE_FIELD_ENC_IP_PROTO,
460 EFX_MAE_FIELD_ID_ENC_IP_TOS = MAE_FIELD_ENC_IP_TOS,
461 EFX_MAE_FIELD_ID_ENC_IP_TTL = MAE_FIELD_ENC_IP_TTL,
462 EFX_MAE_FIELD_ID_ENC_SRC_IP6_BE = MAE_FIELD_ENC_SRC_IP6,
463 EFX_MAE_FIELD_ID_ENC_DST_IP6_BE = MAE_FIELD_ENC_DST_IP6,
464 EFX_MAE_FIELD_ID_ENC_L4_SPORT_BE = MAE_FIELD_ENC_L4_SPORT,
465 EFX_MAE_FIELD_ID_ENC_L4_DPORT_BE = MAE_FIELD_ENC_L4_DPORT,
466 EFX_MAE_FIELD_ID_ENC_VNET_ID_BE = MAE_FIELD_ENC_VNET_ID,
467 EFX_MAE_FIELD_ID_OUTER_RULE_ID = MAE_FIELD_OUTER_RULE_ID,
468 EFX_MAE_FIELD_ID_HAS_OVLAN = MAE_FIELD_HAS_OVLAN,
469 EFX_MAE_FIELD_ID_HAS_IVLAN = MAE_FIELD_HAS_IVLAN,
470 EFX_MAE_FIELD_ID_ENC_HAS_OVLAN = MAE_FIELD_ENC_HAS_OVLAN,
471 EFX_MAE_FIELD_ID_ENC_HAS_IVLAN = MAE_FIELD_ENC_HAS_IVLAN,
473 EFX_MAE_FIELD_CAP_NIDS
474 } efx_mae_field_cap_id_t;
476 typedef enum efx_mae_field_endianness_e {
477 EFX_MAE_FIELD_LE = 0,
480 EFX_MAE_FIELD_ENDIANNESS_NTYPES
481 } efx_mae_field_endianness_t;
484 * The following structure is a means to describe an MAE field.
485 * The information in it is meant to be used internally by
486 * APIs for addressing a given field in a mask-value pairs
487 * structure and for validation purposes.
489 * A field may have an alternative one. This structure
490 * has additional members to reference the alternative
491 * field's mask. See efx_mae_match_spec_is_valid().
493 typedef struct efx_mae_mv_desc_s {
494 efx_mae_field_cap_id_t emmd_field_cap_id;
496 size_t emmd_value_size;
497 size_t emmd_value_offset;
498 size_t emmd_mask_size;
499 size_t emmd_mask_offset;
502 * Having the alternative field's mask size set to 0
503 * means that there's no alternative field specified.
505 size_t emmd_alt_mask_size;
506 size_t emmd_alt_mask_offset;
508 /* Primary field and the alternative one are of the same endianness. */
509 efx_mae_field_endianness_t emmd_endianness;
512 /* Indices to this array are provided by efx_mae_field_id_t */
513 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
514 #define EFX_MAE_MV_DESC(_name, _endianness) \
515 [EFX_MAE_FIELD_##_name] = \
517 EFX_MAE_FIELD_ID_##_name, \
518 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
519 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
520 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
521 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
522 0, 0 /* no alternative field */, \
526 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
527 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
528 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
529 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
530 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
531 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
532 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
533 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
534 EFX_MAE_MV_DESC(SRC_IP4_BE, EFX_MAE_FIELD_BE),
535 EFX_MAE_MV_DESC(DST_IP4_BE, EFX_MAE_FIELD_BE),
536 EFX_MAE_MV_DESC(IP_PROTO, EFX_MAE_FIELD_BE),
537 EFX_MAE_MV_DESC(IP_TOS, EFX_MAE_FIELD_BE),
538 EFX_MAE_MV_DESC(IP_TTL, EFX_MAE_FIELD_BE),
539 EFX_MAE_MV_DESC(SRC_IP6_BE, EFX_MAE_FIELD_BE),
540 EFX_MAE_MV_DESC(DST_IP6_BE, EFX_MAE_FIELD_BE),
541 EFX_MAE_MV_DESC(L4_SPORT_BE, EFX_MAE_FIELD_BE),
542 EFX_MAE_MV_DESC(L4_DPORT_BE, EFX_MAE_FIELD_BE),
543 EFX_MAE_MV_DESC(TCP_FLAGS_BE, EFX_MAE_FIELD_BE),
544 EFX_MAE_MV_DESC(ENC_VNET_ID_BE, EFX_MAE_FIELD_BE),
545 EFX_MAE_MV_DESC(OUTER_RULE_ID, EFX_MAE_FIELD_LE),
547 #undef EFX_MAE_MV_DESC
550 /* Indices to this array are provided by efx_mae_field_id_t */
551 static const efx_mae_mv_desc_t __efx_mae_outer_rule_mv_desc_set[] = {
552 #define EFX_MAE_MV_DESC(_name, _endianness) \
553 [EFX_MAE_FIELD_##_name] = \
555 EFX_MAE_FIELD_ID_##_name, \
556 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
557 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
558 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
559 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
560 0, 0 /* no alternative field */, \
564 /* Same as EFX_MAE_MV_DESC(), but also indicates an alternative field. */
565 #define EFX_MAE_MV_DESC_ALT(_name, _alt_name, _endianness) \
566 [EFX_MAE_FIELD_##_name] = \
568 EFX_MAE_FIELD_ID_##_name, \
569 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
570 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
571 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
572 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
573 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_LEN, \
574 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_OFST, \
578 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
579 EFX_MAE_MV_DESC(ENC_ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
580 EFX_MAE_MV_DESC(ENC_ETH_SADDR_BE, EFX_MAE_FIELD_BE),
581 EFX_MAE_MV_DESC(ENC_ETH_DADDR_BE, EFX_MAE_FIELD_BE),
582 EFX_MAE_MV_DESC(ENC_VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
583 EFX_MAE_MV_DESC(ENC_VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
584 EFX_MAE_MV_DESC(ENC_VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
585 EFX_MAE_MV_DESC(ENC_VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
586 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP4_BE, ENC_SRC_IP6_BE, EFX_MAE_FIELD_BE),
587 EFX_MAE_MV_DESC_ALT(ENC_DST_IP4_BE, ENC_DST_IP6_BE, EFX_MAE_FIELD_BE),
588 EFX_MAE_MV_DESC(ENC_IP_PROTO, EFX_MAE_FIELD_BE),
589 EFX_MAE_MV_DESC(ENC_IP_TOS, EFX_MAE_FIELD_BE),
590 EFX_MAE_MV_DESC(ENC_IP_TTL, EFX_MAE_FIELD_BE),
591 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP6_BE, ENC_SRC_IP4_BE, EFX_MAE_FIELD_BE),
592 EFX_MAE_MV_DESC_ALT(ENC_DST_IP6_BE, ENC_DST_IP4_BE, EFX_MAE_FIELD_BE),
593 EFX_MAE_MV_DESC(ENC_L4_SPORT_BE, EFX_MAE_FIELD_BE),
594 EFX_MAE_MV_DESC(ENC_L4_DPORT_BE, EFX_MAE_FIELD_BE),
596 #undef EFX_MAE_MV_DESC_ALT
597 #undef EFX_MAE_MV_DESC
601 * The following structure is a means to describe an MAE bit.
602 * The information in it is meant to be used internally by
603 * APIs for addressing a given flag in a mask-value pairs
604 * structure and for validation purposes.
606 typedef struct efx_mae_mv_bit_desc_s {
608 * Arrays using this struct are indexed by field IDs.
609 * Fields which aren't meant to be referenced by these
610 * arrays comprise gaps (invalid entries). Below field
611 * helps to identify such entries.
613 boolean_t emmbd_entry_is_valid;
614 efx_mae_field_cap_id_t emmbd_bit_cap_id;
615 size_t emmbd_value_ofst;
616 unsigned int emmbd_value_lbn;
617 size_t emmbd_mask_ofst;
618 unsigned int emmbd_mask_lbn;
619 } efx_mae_mv_bit_desc_t;
621 static const efx_mae_mv_bit_desc_t __efx_mae_outer_rule_mv_bit_desc_set[] = {
622 #define EFX_MAE_MV_BIT_DESC(_name) \
623 [EFX_MAE_FIELD_##_name] = \
626 EFX_MAE_FIELD_ID_##_name, \
627 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
628 MAE_ENC_FIELD_PAIRS_##_name##_LBN, \
629 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
630 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LBN, \
633 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
634 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
636 #undef EFX_MAE_MV_BIT_DESC
639 static const efx_mae_mv_bit_desc_t __efx_mae_action_rule_mv_bit_desc_set[] = {
640 #define EFX_MAE_MV_BIT_DESC(_name) \
641 [EFX_MAE_FIELD_##_name] = \
644 EFX_MAE_FIELD_ID_##_name, \
645 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_OFST, \
646 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
647 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_MASK_OFST, \
648 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
651 EFX_MAE_MV_BIT_DESC(HAS_OVLAN),
652 EFX_MAE_MV_BIT_DESC(HAS_IVLAN),
653 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
654 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
656 #undef EFX_MAE_MV_BIT_DESC
659 __checkReturn efx_rc_t
660 efx_mae_mport_by_phy_port(
661 __in uint32_t phy_port,
662 __out efx_mport_sel_t *mportp)
667 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
672 EFX_POPULATE_DWORD_2(dword,
673 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
674 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
676 memset(mportp, 0, sizeof (*mportp));
678 * The constructed DWORD is little-endian,
679 * but the resulting value is meant to be
680 * passed to MCDIs, where it will undergo
681 * host-order to little endian conversion.
683 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
688 EFSYS_PROBE1(fail1, efx_rc_t, rc);
692 __checkReturn efx_rc_t
693 efx_mae_mport_by_pcie_function(
696 __out efx_mport_sel_t *mportp)
701 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
702 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
704 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_PF_ID)) {
709 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
714 EFX_POPULATE_DWORD_3(dword,
715 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_FUNC,
716 MAE_MPORT_SELECTOR_FUNC_PF_ID, pf,
717 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
719 memset(mportp, 0, sizeof (*mportp));
721 * The constructed DWORD is little-endian,
722 * but the resulting value is meant to be
723 * passed to MCDIs, where it will undergo
724 * host-order to little endian conversion.
726 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
733 EFSYS_PROBE1(fail1, efx_rc_t, rc);
737 __checkReturn efx_rc_t
738 efx_mae_match_spec_field_set(
739 __in efx_mae_match_spec_t *spec,
740 __in efx_mae_field_id_t field_id,
741 __in size_t value_size,
742 __in_bcount(value_size) const uint8_t *value,
743 __in size_t mask_size,
744 __in_bcount(mask_size) const uint8_t *mask)
746 const efx_mae_mv_desc_t *descp;
747 unsigned int desc_set_nentries;
751 switch (spec->emms_type) {
752 case EFX_MAE_RULE_OUTER:
754 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
755 descp = &__efx_mae_outer_rule_mv_desc_set[field_id];
756 mvp = spec->emms_mask_value_pairs.outer;
758 case EFX_MAE_RULE_ACTION:
760 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
761 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
762 mvp = spec->emms_mask_value_pairs.action;
769 if ((unsigned int)field_id >= desc_set_nentries) {
774 if (descp->emmd_mask_size == 0) {
775 /* The ID points to a gap in the array of field descriptors. */
780 if (value_size != descp->emmd_value_size) {
785 if (mask_size != descp->emmd_mask_size) {
790 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
794 * The mask/value are in network (big endian) order.
795 * The MCDI request field is also big endian.
798 EFSYS_ASSERT3U(value_size, ==, mask_size);
800 for (i = 0; i < value_size; ++i) {
801 uint8_t *v_bytep = mvp + descp->emmd_value_offset + i;
802 uint8_t *m_bytep = mvp + descp->emmd_mask_offset + i;
805 * Apply the mask (which may be all-zeros) to the value.
807 * If this API is provided with some value to set for a
808 * given field in one specification and with some other
809 * value to set for this field in another specification,
810 * then, if the two masks are all-zeros, the field will
811 * avoid being counted as a mismatch when comparing the
812 * specifications using efx_mae_match_specs_equal() API.
814 *v_bytep = value[i] & mask[i];
821 * The mask/value are in host byte order.
822 * The MCDI request field is little endian.
824 switch (value_size) {
826 EFX_POPULATE_DWORD_1(dword,
827 EFX_DWORD_0, *(const uint32_t *)value);
829 memcpy(mvp + descp->emmd_value_offset,
830 &dword, sizeof (dword));
833 EFSYS_ASSERT(B_FALSE);
838 EFX_POPULATE_DWORD_1(dword,
839 EFX_DWORD_0, *(const uint32_t *)mask);
841 memcpy(mvp + descp->emmd_mask_offset,
842 &dword, sizeof (dword));
845 EFSYS_ASSERT(B_FALSE);
860 EFSYS_PROBE1(fail1, efx_rc_t, rc);
864 __checkReturn efx_rc_t
865 efx_mae_match_spec_bit_set(
866 __in efx_mae_match_spec_t *spec,
867 __in efx_mae_field_id_t field_id,
868 __in boolean_t value)
870 const efx_mae_mv_bit_desc_t *bit_descp;
871 unsigned int bit_desc_set_nentries;
872 unsigned int byte_idx;
873 unsigned int bit_idx;
877 switch (spec->emms_type) {
878 case EFX_MAE_RULE_OUTER:
879 bit_desc_set_nentries =
880 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
881 bit_descp = &__efx_mae_outer_rule_mv_bit_desc_set[field_id];
882 mvp = spec->emms_mask_value_pairs.outer;
884 case EFX_MAE_RULE_ACTION:
885 bit_desc_set_nentries =
886 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
887 bit_descp = &__efx_mae_action_rule_mv_bit_desc_set[field_id];
888 mvp = spec->emms_mask_value_pairs.action;
895 if ((unsigned int)field_id >= bit_desc_set_nentries) {
900 if (bit_descp->emmbd_entry_is_valid == B_FALSE) {
905 byte_idx = bit_descp->emmbd_value_ofst + bit_descp->emmbd_value_lbn / 8;
906 bit_idx = bit_descp->emmbd_value_lbn % 8;
908 if (value != B_FALSE)
909 mvp[byte_idx] |= (1U << bit_idx);
911 mvp[byte_idx] &= ~(1U << bit_idx);
913 byte_idx = bit_descp->emmbd_mask_ofst + bit_descp->emmbd_mask_lbn / 8;
914 bit_idx = bit_descp->emmbd_mask_lbn % 8;
915 mvp[byte_idx] |= (1U << bit_idx);
924 EFSYS_PROBE1(fail1, efx_rc_t, rc);
928 __checkReturn efx_rc_t
929 efx_mae_match_spec_mport_set(
930 __in efx_mae_match_spec_t *spec,
931 __in const efx_mport_sel_t *valuep,
932 __in_opt const efx_mport_sel_t *maskp)
934 uint32_t full_mask = UINT32_MAX;
939 if (valuep == NULL) {
944 vp = (const uint8_t *)&valuep->sel;
946 mp = (const uint8_t *)&maskp->sel;
948 mp = (const uint8_t *)&full_mask;
950 rc = efx_mae_match_spec_field_set(spec,
951 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
952 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
961 EFSYS_PROBE1(fail1, efx_rc_t, rc);
965 __checkReturn boolean_t
966 efx_mae_match_specs_equal(
967 __in const efx_mae_match_spec_t *left,
968 __in const efx_mae_match_spec_t *right)
970 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
973 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
974 ((_mask)[(_bit) / (_mask_page_nbits)] & \
975 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
979 __in size_t mask_nbytes,
980 __in_bcount(mask_nbytes) const uint8_t *maskp)
982 boolean_t prev_bit_is_set = B_TRUE;
985 for (i = 0; i < 8 * mask_nbytes; ++i) {
986 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
988 if (!prev_bit_is_set && bit_is_set)
991 prev_bit_is_set = bit_is_set;
998 efx_mask_is_all_ones(
999 __in size_t mask_nbytes,
1000 __in_bcount(mask_nbytes) const uint8_t *maskp)
1005 for (i = 0; i < mask_nbytes; ++i)
1008 return (t == (uint8_t)(~0));
1012 efx_mask_is_all_zeros(
1013 __in size_t mask_nbytes,
1014 __in_bcount(mask_nbytes) const uint8_t *maskp)
1019 for (i = 0; i < mask_nbytes; ++i)
1025 __checkReturn boolean_t
1026 efx_mae_match_spec_is_valid(
1027 __in efx_nic_t *enp,
1028 __in const efx_mae_match_spec_t *spec)
1030 efx_mae_t *maep = enp->en_maep;
1031 unsigned int field_ncaps = maep->em_max_nfields;
1032 const efx_mae_field_cap_t *field_caps;
1033 const efx_mae_mv_desc_t *desc_setp;
1034 unsigned int desc_set_nentries;
1035 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1036 unsigned int bit_desc_set_nentries;
1037 boolean_t is_valid = B_TRUE;
1038 efx_mae_field_id_t field_id;
1041 switch (spec->emms_type) {
1042 case EFX_MAE_RULE_OUTER:
1043 field_caps = maep->em_outer_rule_field_caps;
1044 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1046 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1047 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1048 bit_desc_set_nentries =
1049 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1050 mvp = spec->emms_mask_value_pairs.outer;
1052 case EFX_MAE_RULE_ACTION:
1053 field_caps = maep->em_action_rule_field_caps;
1054 desc_setp = __efx_mae_action_rule_mv_desc_set;
1056 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1057 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1058 bit_desc_set_nentries =
1059 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1060 mvp = spec->emms_mask_value_pairs.action;
1066 if (field_caps == NULL)
1069 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1071 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1072 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1073 const uint8_t *alt_m_buf = mvp + descp->emmd_alt_mask_offset;
1074 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
1075 size_t alt_m_size = descp->emmd_alt_mask_size;
1076 size_t m_size = descp->emmd_mask_size;
1079 continue; /* Skip array gap */
1081 if ((unsigned int)field_cap_id >= field_ncaps) {
1083 * The FW has not reported capability status for
1084 * this field. Make sure that its mask is zeroed.
1086 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1087 if (is_valid != B_FALSE)
1093 switch (field_caps[field_cap_id].emfc_support) {
1094 case MAE_FIELD_SUPPORTED_MATCH_MASK:
1097 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
1098 is_valid = efx_mask_is_prefix(m_size, m_buf);
1100 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1101 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
1102 efx_mask_is_all_zeros(m_size, m_buf));
1104 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1105 is_valid = efx_mask_is_all_ones(m_size, m_buf);
1107 if ((is_valid == B_FALSE) && (alt_m_size != 0)) {
1109 * This field has an alternative one. The FW
1110 * reports ALWAYS for both implying that one
1111 * of them is required to have all-ones mask.
1113 * The primary field's mask is incorrect; go
1114 * on to check that of the alternative field.
1116 is_valid = efx_mask_is_all_ones(alt_m_size,
1120 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1121 case MAE_FIELD_UNSUPPORTED:
1123 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1127 if (is_valid == B_FALSE)
1131 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1133 const efx_mae_mv_bit_desc_t *bit_descp =
1134 &bit_desc_setp[field_id];
1135 unsigned int byte_idx =
1136 bit_descp->emmbd_mask_ofst +
1137 bit_descp->emmbd_mask_lbn / 8;
1138 unsigned int bit_idx =
1139 bit_descp->emmbd_mask_lbn % 8;
1140 efx_mae_field_cap_id_t bit_cap_id =
1141 bit_descp->emmbd_bit_cap_id;
1143 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1144 continue; /* Skip array gap */
1146 if ((unsigned int)bit_cap_id >= field_ncaps) {
1147 /* No capability for this bit = unsupported. */
1148 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1149 if (is_valid == B_FALSE)
1155 switch (field_caps[bit_cap_id].emfc_support) {
1156 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1159 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1160 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) != 0);
1162 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1163 case MAE_FIELD_UNSUPPORTED:
1165 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1169 if (is_valid == B_FALSE)
1176 __checkReturn efx_rc_t
1177 efx_mae_action_set_spec_init(
1178 __in efx_nic_t *enp,
1179 __out efx_mae_actions_t **specp)
1181 efx_mae_actions_t *spec;
1184 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
1190 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1197 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1202 efx_mae_action_set_spec_fini(
1203 __in efx_nic_t *enp,
1204 __in efx_mae_actions_t *spec)
1206 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1209 static __checkReturn efx_rc_t
1210 efx_mae_action_set_add_decap(
1211 __in efx_mae_actions_t *spec,
1212 __in size_t arg_size,
1213 __in_bcount(arg_size) const uint8_t *arg)
1217 _NOTE(ARGUNUSED(spec))
1219 if (arg_size != 0) {
1229 /* This action does not have any arguments, so do nothing here. */
1236 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1240 static __checkReturn efx_rc_t
1241 efx_mae_action_set_add_vlan_pop(
1242 __in efx_mae_actions_t *spec,
1243 __in size_t arg_size,
1244 __in_bcount(arg_size) const uint8_t *arg)
1248 if (arg_size != 0) {
1258 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
1263 ++spec->ema_n_vlan_tags_to_pop;
1272 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1276 static __checkReturn efx_rc_t
1277 efx_mae_action_set_add_vlan_push(
1278 __in efx_mae_actions_t *spec,
1279 __in size_t arg_size,
1280 __in_bcount(arg_size) const uint8_t *arg)
1282 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
1285 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
1295 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1300 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
1301 ++(spec->ema_n_vlan_tags_to_push);
1310 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1314 static __checkReturn efx_rc_t
1315 efx_mae_action_set_add_encap(
1316 __in efx_mae_actions_t *spec,
1317 __in size_t arg_size,
1318 __in_bcount(arg_size) const uint8_t *arg)
1323 * Adding this specific action to an action set spec and setting encap.
1324 * header ID in the spec are two individual steps. This design allows
1325 * the client driver to avoid encap. header allocation when it simply
1326 * needs to check the order of actions submitted by user ("validate"),
1327 * without actually allocating an action set and inserting a rule.
1329 * For now, mark encap. header ID as invalid; the caller will invoke
1330 * efx_mae_action_set_fill_in_eh_id() to override the field prior
1331 * to action set allocation; otherwise, the allocation will fail.
1333 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1336 * As explained above, there are no arguments to handle here.
1337 * efx_mae_action_set_fill_in_eh_id() will take care of them.
1339 if (arg_size != 0) {
1354 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1358 static __checkReturn efx_rc_t
1359 efx_mae_action_set_add_flag(
1360 __in efx_mae_actions_t *spec,
1361 __in size_t arg_size,
1362 __in_bcount(arg_size) const uint8_t *arg)
1366 _NOTE(ARGUNUSED(spec))
1368 if (arg_size != 0) {
1378 /* This action does not have any arguments, so do nothing here. */
1385 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1389 static __checkReturn efx_rc_t
1390 efx_mae_action_set_add_mark(
1391 __in efx_mae_actions_t *spec,
1392 __in size_t arg_size,
1393 __in_bcount(arg_size) const uint8_t *arg)
1397 if (arg_size != sizeof (spec->ema_mark_value)) {
1407 memcpy(&spec->ema_mark_value, arg, arg_size);
1414 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1418 static __checkReturn efx_rc_t
1419 efx_mae_action_set_add_deliver(
1420 __in efx_mae_actions_t *spec,
1421 __in size_t arg_size,
1422 __in_bcount(arg_size) const uint8_t *arg)
1426 if (arg_size != sizeof (spec->ema_deliver_mport)) {
1436 memcpy(&spec->ema_deliver_mport, arg, arg_size);
1443 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1447 typedef struct efx_mae_action_desc_s {
1448 /* Action specific handler */
1449 efx_rc_t (*emad_add)(efx_mae_actions_t *,
1450 size_t, const uint8_t *);
1451 } efx_mae_action_desc_t;
1453 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
1454 [EFX_MAE_ACTION_DECAP] = {
1455 .emad_add = efx_mae_action_set_add_decap
1457 [EFX_MAE_ACTION_VLAN_POP] = {
1458 .emad_add = efx_mae_action_set_add_vlan_pop
1460 [EFX_MAE_ACTION_VLAN_PUSH] = {
1461 .emad_add = efx_mae_action_set_add_vlan_push
1463 [EFX_MAE_ACTION_ENCAP] = {
1464 .emad_add = efx_mae_action_set_add_encap
1466 [EFX_MAE_ACTION_FLAG] = {
1467 .emad_add = efx_mae_action_set_add_flag
1469 [EFX_MAE_ACTION_MARK] = {
1470 .emad_add = efx_mae_action_set_add_mark
1472 [EFX_MAE_ACTION_DELIVER] = {
1473 .emad_add = efx_mae_action_set_add_deliver
1477 static const uint32_t efx_mae_action_ordered_map =
1478 (1U << EFX_MAE_ACTION_DECAP) |
1479 (1U << EFX_MAE_ACTION_VLAN_POP) |
1480 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1481 (1U << EFX_MAE_ACTION_ENCAP) |
1482 (1U << EFX_MAE_ACTION_FLAG) |
1483 (1U << EFX_MAE_ACTION_MARK) |
1484 (1U << EFX_MAE_ACTION_DELIVER);
1487 * These actions must not be added after DELIVER, but
1488 * they can have any place among the rest of
1489 * strictly ordered actions.
1491 static const uint32_t efx_mae_action_nonstrict_map =
1492 (1U << EFX_MAE_ACTION_FLAG) |
1493 (1U << EFX_MAE_ACTION_MARK);
1495 static const uint32_t efx_mae_action_repeat_map =
1496 (1U << EFX_MAE_ACTION_VLAN_POP) |
1497 (1U << EFX_MAE_ACTION_VLAN_PUSH);
1500 * Add an action to an action set.
1502 * This has to be invoked in the desired action order.
1503 * An out-of-order action request will be turned down.
1505 static __checkReturn efx_rc_t
1506 efx_mae_action_set_spec_populate(
1507 __in efx_mae_actions_t *spec,
1508 __in efx_mae_action_t type,
1509 __in size_t arg_size,
1510 __in_bcount(arg_size) const uint8_t *arg)
1512 uint32_t action_mask;
1515 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1516 (sizeof (efx_mae_action_ordered_map) * 8));
1517 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1518 (sizeof (efx_mae_action_repeat_map) * 8));
1520 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
1521 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
1522 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
1524 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
1529 action_mask = (1U << type);
1531 if ((spec->ema_actions & action_mask) != 0) {
1532 /* The action set already contains this action. */
1533 if ((efx_mae_action_repeat_map & action_mask) == 0) {
1534 /* Cannot add another non-repeatable action. */
1540 if ((efx_mae_action_ordered_map & action_mask) != 0) {
1541 uint32_t strict_ordered_map =
1542 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
1543 uint32_t later_actions_mask =
1544 strict_ordered_map & ~(action_mask | (action_mask - 1));
1546 if ((spec->ema_actions & later_actions_mask) != 0) {
1547 /* Cannot add an action after later ordered actions. */
1553 if (efx_mae_actions[type].emad_add != NULL) {
1554 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
1559 spec->ema_actions |= action_mask;
1570 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1574 __checkReturn efx_rc_t
1575 efx_mae_action_set_populate_decap(
1576 __in efx_mae_actions_t *spec)
1578 return (efx_mae_action_set_spec_populate(spec,
1579 EFX_MAE_ACTION_DECAP, 0, NULL));
1582 __checkReturn efx_rc_t
1583 efx_mae_action_set_populate_vlan_pop(
1584 __in efx_mae_actions_t *spec)
1586 return (efx_mae_action_set_spec_populate(spec,
1587 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1590 __checkReturn efx_rc_t
1591 efx_mae_action_set_populate_vlan_push(
1592 __in efx_mae_actions_t *spec,
1593 __in uint16_t tpid_be,
1594 __in uint16_t tci_be)
1596 efx_mae_action_vlan_push_t action;
1597 const uint8_t *arg = (const uint8_t *)&action;
1599 action.emavp_tpid_be = tpid_be;
1600 action.emavp_tci_be = tci_be;
1602 return (efx_mae_action_set_spec_populate(spec,
1603 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1606 __checkReturn efx_rc_t
1607 efx_mae_action_set_populate_encap(
1608 __in efx_mae_actions_t *spec)
1611 * There is no argument to pass encap. header ID, thus, one does not
1612 * need to allocate an encap. header while parsing application input.
1613 * This is useful since building an action set may be done simply to
1614 * validate a rule, whilst resource allocation usually consumes time.
1616 return (efx_mae_action_set_spec_populate(spec,
1617 EFX_MAE_ACTION_ENCAP, 0, NULL));
1620 __checkReturn efx_rc_t
1621 efx_mae_action_set_populate_flag(
1622 __in efx_mae_actions_t *spec)
1624 return (efx_mae_action_set_spec_populate(spec,
1625 EFX_MAE_ACTION_FLAG, 0, NULL));
1628 __checkReturn efx_rc_t
1629 efx_mae_action_set_populate_mark(
1630 __in efx_mae_actions_t *spec,
1631 __in uint32_t mark_value)
1633 const uint8_t *arg = (const uint8_t *)&mark_value;
1635 return (efx_mae_action_set_spec_populate(spec,
1636 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1639 __checkReturn efx_rc_t
1640 efx_mae_action_set_populate_deliver(
1641 __in efx_mae_actions_t *spec,
1642 __in const efx_mport_sel_t *mportp)
1647 if (mportp == NULL) {
1652 arg = (const uint8_t *)&mportp->sel;
1654 return (efx_mae_action_set_spec_populate(spec,
1655 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1658 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1662 __checkReturn efx_rc_t
1663 efx_mae_action_set_populate_drop(
1664 __in efx_mae_actions_t *spec)
1666 efx_mport_sel_t mport;
1670 EFX_POPULATE_DWORD_1(dword,
1671 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1674 * The constructed DWORD is little-endian,
1675 * but the resulting value is meant to be
1676 * passed to MCDIs, where it will undergo
1677 * host-order to little endian conversion.
1679 mport.sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
1681 arg = (const uint8_t *)&mport.sel;
1683 return (efx_mae_action_set_spec_populate(spec,
1684 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1687 __checkReturn boolean_t
1688 efx_mae_action_set_specs_equal(
1689 __in const efx_mae_actions_t *left,
1690 __in const efx_mae_actions_t *right)
1692 size_t cmp_size = EFX_FIELD_OFFSET(efx_mae_actions_t, ema_rsrc);
1695 * An action set specification consists of two parts. The first part
1696 * indicates what actions are included in the action set, as well as
1697 * extra quantitative values (in example, the number of VLAN tags to
1698 * push). The second part comprises resource IDs used by the actions.
1700 * A resource, in example, a counter, is allocated from the hardware
1701 * by the client, and it's the client who is responsible for keeping
1702 * track of allocated resources and comparing resource IDs if needed.
1704 * In this API, don't compare resource IDs in the two specifications.
1707 return ((memcmp(left, right, cmp_size) == 0) ? B_TRUE : B_FALSE);
1710 __checkReturn efx_rc_t
1711 efx_mae_match_specs_class_cmp(
1712 __in efx_nic_t *enp,
1713 __in const efx_mae_match_spec_t *left,
1714 __in const efx_mae_match_spec_t *right,
1715 __out boolean_t *have_same_classp)
1717 efx_mae_t *maep = enp->en_maep;
1718 unsigned int field_ncaps = maep->em_max_nfields;
1719 const efx_mae_field_cap_t *field_caps;
1720 const efx_mae_mv_desc_t *desc_setp;
1721 unsigned int desc_set_nentries;
1722 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1723 unsigned int bit_desc_set_nentries;
1724 boolean_t have_same_class = B_TRUE;
1725 efx_mae_field_id_t field_id;
1726 const uint8_t *mvpl;
1727 const uint8_t *mvpr;
1730 switch (left->emms_type) {
1731 case EFX_MAE_RULE_OUTER:
1732 field_caps = maep->em_outer_rule_field_caps;
1733 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1735 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1736 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1737 bit_desc_set_nentries =
1738 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1739 mvpl = left->emms_mask_value_pairs.outer;
1740 mvpr = right->emms_mask_value_pairs.outer;
1742 case EFX_MAE_RULE_ACTION:
1743 field_caps = maep->em_action_rule_field_caps;
1744 desc_setp = __efx_mae_action_rule_mv_desc_set;
1746 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1747 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1748 bit_desc_set_nentries =
1749 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1750 mvpl = left->emms_mask_value_pairs.action;
1751 mvpr = right->emms_mask_value_pairs.action;
1758 if (field_caps == NULL) {
1763 if (left->emms_type != right->emms_type ||
1764 left->emms_prio != right->emms_prio) {
1766 * Rules of different types can never map to the same class.
1768 * The FW can support some set of match criteria for one
1769 * priority and not support the very same set for
1770 * another priority. Thus, two rules which have
1771 * different priorities can never map to
1774 *have_same_classp = B_FALSE;
1778 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1780 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1781 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1782 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1783 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1784 size_t mask_size = descp->emmd_mask_size;
1785 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1786 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1787 size_t value_size = descp->emmd_value_size;
1790 continue; /* Skip array gap */
1792 if ((unsigned int)field_cap_id >= field_ncaps) {
1794 * The FW has not reported capability status for this
1795 * field. It's unknown whether any difference between
1796 * the two masks / values affects the class. The only
1797 * case when the class must be the same is when these
1798 * mask-value pairs match. Otherwise, report mismatch.
1800 if ((memcmp(lmaskp, rmaskp, mask_size) == 0) &&
1801 (memcmp(lvalp, rvalp, value_size) == 0))
1807 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1808 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1809 have_same_class = B_FALSE;
1814 if (field_caps[field_cap_id].emfc_match_affects_class) {
1815 if (memcmp(lvalp, rvalp, value_size) != 0) {
1816 have_same_class = B_FALSE;
1822 if (have_same_class == B_FALSE)
1825 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1827 const efx_mae_mv_bit_desc_t *bit_descp =
1828 &bit_desc_setp[field_id];
1829 efx_mae_field_cap_id_t bit_cap_id =
1830 bit_descp->emmbd_bit_cap_id;
1831 unsigned int byte_idx;
1832 unsigned int bit_idx;
1834 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1835 continue; /* Skip array gap */
1837 if ((unsigned int)bit_cap_id >= field_ncaps)
1841 bit_descp->emmbd_mask_ofst +
1842 bit_descp->emmbd_mask_lbn / 8;
1844 bit_descp->emmbd_mask_lbn % 8;
1846 if (field_caps[bit_cap_id].emfc_mask_affects_class &&
1847 (mvpl[byte_idx] & (1U << bit_idx)) !=
1848 (mvpr[byte_idx] & (1U << bit_idx))) {
1849 have_same_class = B_FALSE;
1854 bit_descp->emmbd_value_ofst +
1855 bit_descp->emmbd_value_lbn / 8;
1857 bit_descp->emmbd_value_lbn % 8;
1859 if (field_caps[bit_cap_id].emfc_match_affects_class &&
1860 (mvpl[byte_idx] & (1U << bit_idx)) !=
1861 (mvpr[byte_idx] & (1U << bit_idx))) {
1862 have_same_class = B_FALSE;
1868 *have_same_classp = have_same_class;
1875 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1879 __checkReturn efx_rc_t
1880 efx_mae_outer_rule_insert(
1881 __in efx_nic_t *enp,
1882 __in const efx_mae_match_spec_t *spec,
1883 __in efx_tunnel_protocol_t encap_type,
1884 __out efx_mae_rule_id_t *or_idp)
1886 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1888 EFX_MCDI_DECLARE_BUF(payload,
1889 MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2,
1890 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
1891 uint32_t encap_type_mcdi;
1892 efx_mae_rule_id_t or_id;
1896 EFX_STATIC_ASSERT(sizeof (or_idp->id) ==
1897 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OR_ID_LEN);
1899 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1900 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL);
1902 if (encp->enc_mae_supported == B_FALSE) {
1907 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
1912 switch (encap_type) {
1913 case EFX_TUNNEL_PROTOCOL_NONE:
1914 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
1916 case EFX_TUNNEL_PROTOCOL_VXLAN:
1917 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
1919 case EFX_TUNNEL_PROTOCOL_GENEVE:
1920 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
1922 case EFX_TUNNEL_PROTOCOL_NVGRE:
1923 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
1930 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_INSERT;
1931 req.emr_in_buf = payload;
1932 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2;
1933 req.emr_out_buf = payload;
1934 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN;
1936 MCDI_IN_SET_DWORD(req,
1937 MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, encap_type_mcdi);
1939 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_INSERT_IN_PRIO, spec->emms_prio);
1942 * Mask-value pairs have been stored in the byte order needed for the
1943 * MCDI request and are thus safe to be copied directly to the buffer.
1944 * The library cares about byte order in efx_mae_match_spec_field_set().
1946 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.outer) >=
1947 MAE_ENC_FIELD_PAIRS_LEN);
1948 offset = MC_CMD_MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA_OFST;
1949 memcpy(payload + offset, spec->emms_mask_value_pairs.outer,
1950 MAE_ENC_FIELD_PAIRS_LEN);
1952 efx_mcdi_execute(enp, &req);
1954 if (req.emr_rc != 0) {
1959 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN) {
1964 or_id.id = MCDI_OUT_DWORD(req, MAE_OUTER_RULE_INSERT_OUT_OR_ID);
1965 if (or_id.id == EFX_MAE_RSRC_ID_INVALID) {
1970 or_idp->id = or_id.id;
1985 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1989 __checkReturn efx_rc_t
1990 efx_mae_outer_rule_remove(
1991 __in efx_nic_t *enp,
1992 __in const efx_mae_rule_id_t *or_idp)
1994 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1996 EFX_MCDI_DECLARE_BUF(payload,
1997 MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1),
1998 MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
2001 if (encp->enc_mae_supported == B_FALSE) {
2006 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_REMOVE;
2007 req.emr_in_buf = payload;
2008 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1);
2009 req.emr_out_buf = payload;
2010 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1);
2012 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_REMOVE_IN_OR_ID, or_idp->id);
2014 efx_mcdi_execute(enp, &req);
2016 if (req.emr_rc != 0) {
2021 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LENMIN) {
2026 if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
2028 /* Firmware failed to remove the outer rule. */
2042 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2046 __checkReturn efx_rc_t
2047 efx_mae_match_spec_outer_rule_id_set(
2048 __in efx_mae_match_spec_t *spec,
2049 __in const efx_mae_rule_id_t *or_idp)
2051 uint32_t full_mask = UINT32_MAX;
2054 if (spec->emms_type != EFX_MAE_RULE_ACTION) {
2059 if (or_idp == NULL) {
2064 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_OUTER_RULE_ID,
2065 sizeof (or_idp->id), (const uint8_t *)&or_idp->id,
2066 sizeof (full_mask), (const uint8_t *)&full_mask);
2077 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2081 __checkReturn efx_rc_t
2082 efx_mae_encap_header_alloc(
2083 __in efx_nic_t *enp,
2084 __in efx_tunnel_protocol_t encap_type,
2085 __in_bcount(header_size) uint8_t *header_data,
2086 __in size_t header_size,
2087 __out efx_mae_eh_id_t *eh_idp)
2089 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2091 EFX_MCDI_DECLARE_BUF(payload,
2092 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LENMAX_MCDI2,
2093 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
2094 uint32_t encap_type_mcdi;
2095 efx_mae_eh_id_t eh_id;
2098 EFX_STATIC_ASSERT(sizeof (eh_idp->id) ==
2099 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_LEN);
2101 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2102 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL);
2104 if (encp->enc_mae_supported == B_FALSE) {
2109 switch (encap_type) {
2110 case EFX_TUNNEL_PROTOCOL_NONE:
2111 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2113 case EFX_TUNNEL_PROTOCOL_VXLAN:
2114 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2116 case EFX_TUNNEL_PROTOCOL_GENEVE:
2117 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2119 case EFX_TUNNEL_PROTOCOL_NVGRE:
2120 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2128 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2) {
2133 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_ALLOC;
2134 req.emr_in_buf = payload;
2135 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(header_size);
2136 req.emr_out_buf = payload;
2137 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN;
2139 MCDI_IN_SET_DWORD(req,
2140 MAE_ENCAP_HEADER_ALLOC_IN_ENCAP_TYPE, encap_type_mcdi);
2142 memcpy(payload + MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_OFST,
2143 header_data, header_size);
2145 efx_mcdi_execute(enp, &req);
2147 if (req.emr_rc != 0) {
2152 if (req.emr_out_length_used < MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN) {
2157 eh_id.id = MCDI_OUT_DWORD(req,
2158 MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID);
2160 if (eh_id.id == EFX_MAE_RSRC_ID_INVALID) {
2165 eh_idp->id = eh_id.id;
2180 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2184 __checkReturn efx_rc_t
2185 efx_mae_encap_header_free(
2186 __in efx_nic_t *enp,
2187 __in const efx_mae_eh_id_t *eh_idp)
2189 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2191 EFX_MCDI_DECLARE_BUF(payload,
2192 MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1),
2193 MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
2196 if (encp->enc_mae_supported == B_FALSE) {
2201 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_FREE;
2202 req.emr_in_buf = payload;
2203 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1);
2204 req.emr_out_buf = payload;
2205 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1);
2207 MCDI_IN_SET_DWORD(req, MAE_ENCAP_HEADER_FREE_IN_EH_ID, eh_idp->id);
2209 efx_mcdi_execute(enp, &req);
2211 if (req.emr_rc != 0) {
2216 if (MCDI_OUT_DWORD(req, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) !=
2218 /* Firmware failed to remove the encap. header. */
2230 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2234 __checkReturn efx_rc_t
2235 efx_mae_action_set_fill_in_eh_id(
2236 __in efx_mae_actions_t *spec,
2237 __in const efx_mae_eh_id_t *eh_idp)
2241 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_ENCAP)) == 0) {
2243 * The caller has not intended to have action ENCAP originally,
2244 * hence, this attempt to indicate encap. header ID is invalid.
2250 if (spec->ema_rsrc.emar_eh_id.id != EFX_MAE_RSRC_ID_INVALID) {
2251 /* The caller attempts to indicate encap. header ID twice. */
2256 if (eh_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2261 spec->ema_rsrc.emar_eh_id.id = eh_idp->id;
2270 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2274 __checkReturn efx_rc_t
2275 efx_mae_action_set_alloc(
2276 __in efx_nic_t *enp,
2277 __in const efx_mae_actions_t *spec,
2278 __out efx_mae_aset_id_t *aset_idp)
2280 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2282 EFX_MCDI_DECLARE_BUF(payload,
2283 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
2284 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
2285 efx_mae_aset_id_t aset_id;
2288 if (encp->enc_mae_supported == B_FALSE) {
2293 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
2294 req.emr_in_buf = payload;
2295 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
2296 req.emr_out_buf = payload;
2297 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
2300 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
2301 * corresponding resource types are supported by the implementation.
2302 * Use proper resource ID assignments instead.
2304 MCDI_IN_SET_DWORD(req,
2305 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
2306 MCDI_IN_SET_DWORD(req,
2307 MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
2309 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_DECAP)) != 0) {
2310 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2311 MAE_ACTION_SET_ALLOC_IN_DECAP, 1);
2314 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2315 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
2317 if (spec->ema_n_vlan_tags_to_push > 0) {
2318 unsigned int outer_tag_idx;
2320 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2321 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
2322 spec->ema_n_vlan_tags_to_push);
2324 if (spec->ema_n_vlan_tags_to_push ==
2325 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
2326 MCDI_IN_SET_WORD(req,
2327 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
2328 spec->ema_vlan_push_descs[0].emavp_tpid_be);
2329 MCDI_IN_SET_WORD(req,
2330 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
2331 spec->ema_vlan_push_descs[0].emavp_tci_be);
2334 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
2336 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
2337 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
2338 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
2339 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
2342 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
2343 spec->ema_rsrc.emar_eh_id.id);
2345 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
2346 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2347 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
2350 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
2351 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2352 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
2354 MCDI_IN_SET_DWORD(req,
2355 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
2358 MCDI_IN_SET_DWORD(req,
2359 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
2361 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
2362 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2363 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
2364 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2366 efx_mcdi_execute(enp, &req);
2368 if (req.emr_rc != 0) {
2373 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
2378 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
2379 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
2384 aset_idp->id = aset_id.id;
2395 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2399 __checkReturn efx_rc_t
2400 efx_mae_action_set_free(
2401 __in efx_nic_t *enp,
2402 __in const efx_mae_aset_id_t *aset_idp)
2404 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2406 EFX_MCDI_DECLARE_BUF(payload,
2407 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
2408 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
2411 if (encp->enc_mae_supported == B_FALSE) {
2416 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
2417 req.emr_in_buf = payload;
2418 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
2419 req.emr_out_buf = payload;
2420 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
2422 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
2424 efx_mcdi_execute(enp, &req);
2426 if (req.emr_rc != 0) {
2431 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_FREE_OUT_LENMIN) {
2436 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
2438 /* Firmware failed to free the action set. */
2452 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2456 __checkReturn efx_rc_t
2457 efx_mae_action_rule_insert(
2458 __in efx_nic_t *enp,
2459 __in const efx_mae_match_spec_t *spec,
2460 __in const efx_mae_aset_list_id_t *asl_idp,
2461 __in const efx_mae_aset_id_t *as_idp,
2462 __out efx_mae_rule_id_t *ar_idp)
2464 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2466 EFX_MCDI_DECLARE_BUF(payload,
2467 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
2468 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
2469 efx_oword_t *rule_response;
2470 efx_mae_rule_id_t ar_id;
2474 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
2475 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
2477 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2478 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
2480 if (encp->enc_mae_supported == B_FALSE) {
2485 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
2486 (asl_idp != NULL && as_idp != NULL) ||
2487 (asl_idp == NULL && as_idp == NULL)) {
2492 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
2493 req.emr_in_buf = payload;
2494 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
2495 req.emr_out_buf = payload;
2496 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
2498 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
2499 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
2500 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
2501 rule_response = (efx_oword_t *)(payload + offset);
2502 EFX_POPULATE_OWORD_3(*rule_response,
2503 MAE_ACTION_RULE_RESPONSE_ASL_ID,
2504 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
2505 MAE_ACTION_RULE_RESPONSE_AS_ID,
2506 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
2507 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
2509 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
2512 * Mask-value pairs have been stored in the byte order needed for the
2513 * MCDI request and are thus safe to be copied directly to the buffer.
2515 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
2516 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
2517 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
2518 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
2519 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
2521 efx_mcdi_execute(enp, &req);
2523 if (req.emr_rc != 0) {
2528 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
2533 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
2534 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
2539 ar_idp->id = ar_id.id;
2552 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2556 __checkReturn efx_rc_t
2557 efx_mae_action_rule_remove(
2558 __in efx_nic_t *enp,
2559 __in const efx_mae_rule_id_t *ar_idp)
2561 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2563 EFX_MCDI_DECLARE_BUF(payload,
2564 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
2565 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
2568 if (encp->enc_mae_supported == B_FALSE) {
2573 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
2574 req.emr_in_buf = payload;
2575 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
2576 req.emr_out_buf = payload;
2577 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
2579 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
2581 efx_mcdi_execute(enp, &req);
2583 if (req.emr_rc != 0) {
2588 if (req.emr_out_length_used <
2589 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LENMIN) {
2594 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
2596 /* Firmware failed to delete the action rule. */
2610 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2614 #endif /* EFSYS_OPT_MAE */