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_invalid(
665 __out efx_mport_sel_t *mportp)
670 if (mportp == NULL) {
675 EFX_POPULATE_DWORD_1(dword,
676 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_INVALID);
678 memset(mportp, 0, sizeof (*mportp));
679 mportp->sel = dword.ed_u32[0];
684 EFSYS_PROBE1(fail1, efx_rc_t, rc);
688 __checkReturn efx_rc_t
689 efx_mae_mport_by_phy_port(
690 __in uint32_t phy_port,
691 __out efx_mport_sel_t *mportp)
696 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
701 EFX_POPULATE_DWORD_2(dword,
702 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
703 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
705 memset(mportp, 0, sizeof (*mportp));
707 * The constructed DWORD is little-endian,
708 * but the resulting value is meant to be
709 * passed to MCDIs, where it will undergo
710 * host-order to little endian conversion.
712 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
717 EFSYS_PROBE1(fail1, efx_rc_t, rc);
721 __checkReturn efx_rc_t
722 efx_mae_mport_by_pcie_function(
725 __out efx_mport_sel_t *mportp)
730 rc = efx_mae_mport_by_pcie_mh_function(EFX_PCIE_INTERFACE_CALLER,
738 EFSYS_PROBE1(fail1, efx_rc_t, rc);
742 static __checkReturn efx_rc_t
743 efx_mae_intf_to_selector(
744 __in efx_pcie_interface_t intf,
745 __out uint32_t *selector_intfp)
750 case EFX_PCIE_INTERFACE_HOST_PRIMARY:
751 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_HOST_PRIMARY <=
752 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
753 *selector_intfp = MAE_MPORT_SELECTOR_HOST_PRIMARY;
755 case EFX_PCIE_INTERFACE_NIC_EMBEDDED:
756 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_NIC_EMBEDDED <=
757 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
758 *selector_intfp = MAE_MPORT_SELECTOR_NIC_EMBEDDED;
760 case EFX_PCIE_INTERFACE_CALLER:
761 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_CALLER_INTF <=
762 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
763 *selector_intfp = MAE_MPORT_SELECTOR_CALLER_INTF;
773 EFSYS_PROBE1(fail1, efx_rc_t, rc);
777 __checkReturn efx_rc_t
778 efx_mae_mport_by_pcie_mh_function(
779 __in efx_pcie_interface_t intf,
782 __out efx_mport_sel_t *mportp)
784 uint32_t selector_intf;
788 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
789 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
791 rc = efx_mae_intf_to_selector(intf, &selector_intf);
795 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_MH_PF_ID)) {
800 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
806 EFX_POPULATE_DWORD_4(dword,
807 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_MH_FUNC,
808 MAE_MPORT_SELECTOR_FUNC_INTF_ID, selector_intf,
809 MAE_MPORT_SELECTOR_FUNC_MH_PF_ID, pf,
810 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
812 memset(mportp, 0, sizeof (*mportp));
813 mportp->sel = dword.ed_u32[0];
822 EFSYS_PROBE1(fail1, efx_rc_t, rc);
826 static __checkReturn efx_rc_t
827 efx_mcdi_mae_mport_lookup(
829 __in const efx_mport_sel_t *mport_selectorp,
830 __out efx_mport_id_t *mport_idp)
833 EFX_MCDI_DECLARE_BUF(payload,
834 MC_CMD_MAE_MPORT_LOOKUP_IN_LEN,
835 MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN);
838 req.emr_cmd = MC_CMD_MAE_MPORT_LOOKUP;
839 req.emr_in_buf = payload;
840 req.emr_in_length = MC_CMD_MAE_MPORT_LOOKUP_IN_LEN;
841 req.emr_out_buf = payload;
842 req.emr_out_length = MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN;
844 MCDI_IN_SET_DWORD(req, MAE_MPORT_LOOKUP_IN_MPORT_SELECTOR,
845 mport_selectorp->sel);
847 efx_mcdi_execute(enp, &req);
849 if (req.emr_rc != 0) {
854 mport_idp->id = MCDI_OUT_DWORD(req, MAE_MPORT_LOOKUP_OUT_MPORT_ID);
859 EFSYS_PROBE1(fail1, efx_rc_t, rc);
863 __checkReturn efx_rc_t
864 efx_mae_mport_id_by_selector(
866 __in const efx_mport_sel_t *mport_selectorp,
867 __out efx_mport_id_t *mport_idp)
869 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
872 if (encp->enc_mae_supported == B_FALSE) {
877 rc = efx_mcdi_mae_mport_lookup(enp, mport_selectorp, mport_idp);
886 EFSYS_PROBE1(fail1, efx_rc_t, rc);
890 __checkReturn efx_rc_t
892 __in const efx_mport_id_t *mport_idp,
893 __out efx_mport_sel_t *mportp)
897 EFX_POPULATE_DWORD_2(dword,
898 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_MPORT_ID,
899 MAE_MPORT_SELECTOR_MPORT_ID, mport_idp->id);
901 memset(mportp, 0, sizeof (*mportp));
902 mportp->sel = __LE_TO_CPU_32(dword.ed_u32[0]);
907 __checkReturn efx_rc_t
908 efx_mae_match_spec_field_set(
909 __in efx_mae_match_spec_t *spec,
910 __in efx_mae_field_id_t field_id,
911 __in size_t value_size,
912 __in_bcount(value_size) const uint8_t *value,
913 __in size_t mask_size,
914 __in_bcount(mask_size) const uint8_t *mask)
916 const efx_mae_mv_desc_t *descp;
917 unsigned int desc_set_nentries;
921 switch (spec->emms_type) {
922 case EFX_MAE_RULE_OUTER:
924 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
925 descp = &__efx_mae_outer_rule_mv_desc_set[field_id];
926 mvp = spec->emms_mask_value_pairs.outer;
928 case EFX_MAE_RULE_ACTION:
930 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
931 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
932 mvp = spec->emms_mask_value_pairs.action;
939 if ((unsigned int)field_id >= desc_set_nentries) {
944 if (descp->emmd_mask_size == 0) {
945 /* The ID points to a gap in the array of field descriptors. */
950 if (value_size != descp->emmd_value_size) {
955 if (mask_size != descp->emmd_mask_size) {
960 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
964 * The mask/value are in network (big endian) order.
965 * The MCDI request field is also big endian.
968 EFSYS_ASSERT3U(value_size, ==, mask_size);
970 for (i = 0; i < value_size; ++i) {
971 uint8_t *v_bytep = mvp + descp->emmd_value_offset + i;
972 uint8_t *m_bytep = mvp + descp->emmd_mask_offset + i;
975 * Apply the mask (which may be all-zeros) to the value.
977 * If this API is provided with some value to set for a
978 * given field in one specification and with some other
979 * value to set for this field in another specification,
980 * then, if the two masks are all-zeros, the field will
981 * avoid being counted as a mismatch when comparing the
982 * specifications using efx_mae_match_specs_equal() API.
984 *v_bytep = value[i] & mask[i];
991 * The mask/value are in host byte order.
992 * The MCDI request field is little endian.
994 switch (value_size) {
996 EFX_POPULATE_DWORD_1(dword,
997 EFX_DWORD_0, *(const uint32_t *)value);
999 memcpy(mvp + descp->emmd_value_offset,
1000 &dword, sizeof (dword));
1003 EFSYS_ASSERT(B_FALSE);
1006 switch (mask_size) {
1008 EFX_POPULATE_DWORD_1(dword,
1009 EFX_DWORD_0, *(const uint32_t *)mask);
1011 memcpy(mvp + descp->emmd_mask_offset,
1012 &dword, sizeof (dword));
1015 EFSYS_ASSERT(B_FALSE);
1030 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1034 __checkReturn efx_rc_t
1035 efx_mae_match_spec_bit_set(
1036 __in efx_mae_match_spec_t *spec,
1037 __in efx_mae_field_id_t field_id,
1038 __in boolean_t value)
1040 const efx_mae_mv_bit_desc_t *bit_descp;
1041 unsigned int bit_desc_set_nentries;
1042 unsigned int byte_idx;
1043 unsigned int bit_idx;
1047 switch (spec->emms_type) {
1048 case EFX_MAE_RULE_OUTER:
1049 bit_desc_set_nentries =
1050 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1051 bit_descp = &__efx_mae_outer_rule_mv_bit_desc_set[field_id];
1052 mvp = spec->emms_mask_value_pairs.outer;
1054 case EFX_MAE_RULE_ACTION:
1055 bit_desc_set_nentries =
1056 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1057 bit_descp = &__efx_mae_action_rule_mv_bit_desc_set[field_id];
1058 mvp = spec->emms_mask_value_pairs.action;
1065 if ((unsigned int)field_id >= bit_desc_set_nentries) {
1070 if (bit_descp->emmbd_entry_is_valid == B_FALSE) {
1075 byte_idx = bit_descp->emmbd_value_ofst + bit_descp->emmbd_value_lbn / 8;
1076 bit_idx = bit_descp->emmbd_value_lbn % 8;
1078 if (value != B_FALSE)
1079 mvp[byte_idx] |= (1U << bit_idx);
1081 mvp[byte_idx] &= ~(1U << bit_idx);
1083 byte_idx = bit_descp->emmbd_mask_ofst + bit_descp->emmbd_mask_lbn / 8;
1084 bit_idx = bit_descp->emmbd_mask_lbn % 8;
1085 mvp[byte_idx] |= (1U << bit_idx);
1094 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1098 __checkReturn efx_rc_t
1099 efx_mae_match_spec_mport_set(
1100 __in efx_mae_match_spec_t *spec,
1101 __in const efx_mport_sel_t *valuep,
1102 __in_opt const efx_mport_sel_t *maskp)
1104 uint32_t full_mask = UINT32_MAX;
1109 if (valuep == NULL) {
1114 vp = (const uint8_t *)&valuep->sel;
1116 mp = (const uint8_t *)&maskp->sel;
1118 mp = (const uint8_t *)&full_mask;
1120 rc = efx_mae_match_spec_field_set(spec,
1121 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
1122 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
1131 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1135 __checkReturn boolean_t
1136 efx_mae_match_specs_equal(
1137 __in const efx_mae_match_spec_t *left,
1138 __in const efx_mae_match_spec_t *right)
1140 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1143 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
1144 ((_mask)[(_bit) / (_mask_page_nbits)] & \
1145 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
1149 __in size_t mask_nbytes,
1150 __in_bcount(mask_nbytes) const uint8_t *maskp)
1152 boolean_t prev_bit_is_set = B_TRUE;
1155 for (i = 0; i < 8 * mask_nbytes; ++i) {
1156 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
1158 if (!prev_bit_is_set && bit_is_set)
1161 prev_bit_is_set = bit_is_set;
1168 efx_mask_is_all_ones(
1169 __in size_t mask_nbytes,
1170 __in_bcount(mask_nbytes) const uint8_t *maskp)
1175 for (i = 0; i < mask_nbytes; ++i)
1178 return (t == (uint8_t)(~0));
1182 efx_mask_is_all_zeros(
1183 __in size_t mask_nbytes,
1184 __in_bcount(mask_nbytes) const uint8_t *maskp)
1189 for (i = 0; i < mask_nbytes; ++i)
1195 __checkReturn boolean_t
1196 efx_mae_match_spec_is_valid(
1197 __in efx_nic_t *enp,
1198 __in const efx_mae_match_spec_t *spec)
1200 efx_mae_t *maep = enp->en_maep;
1201 unsigned int field_ncaps = maep->em_max_nfields;
1202 const efx_mae_field_cap_t *field_caps;
1203 const efx_mae_mv_desc_t *desc_setp;
1204 unsigned int desc_set_nentries;
1205 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1206 unsigned int bit_desc_set_nentries;
1207 boolean_t is_valid = B_TRUE;
1208 efx_mae_field_id_t field_id;
1211 switch (spec->emms_type) {
1212 case EFX_MAE_RULE_OUTER:
1213 field_caps = maep->em_outer_rule_field_caps;
1214 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1216 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1217 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1218 bit_desc_set_nentries =
1219 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1220 mvp = spec->emms_mask_value_pairs.outer;
1222 case EFX_MAE_RULE_ACTION:
1223 field_caps = maep->em_action_rule_field_caps;
1224 desc_setp = __efx_mae_action_rule_mv_desc_set;
1226 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1227 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1228 bit_desc_set_nentries =
1229 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1230 mvp = spec->emms_mask_value_pairs.action;
1236 if (field_caps == NULL)
1239 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1241 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1242 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1243 const uint8_t *alt_m_buf = mvp + descp->emmd_alt_mask_offset;
1244 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
1245 size_t alt_m_size = descp->emmd_alt_mask_size;
1246 size_t m_size = descp->emmd_mask_size;
1249 continue; /* Skip array gap */
1251 if ((unsigned int)field_cap_id >= field_ncaps) {
1253 * The FW has not reported capability status for
1254 * this field. Make sure that its mask is zeroed.
1256 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1257 if (is_valid != B_FALSE)
1263 switch (field_caps[field_cap_id].emfc_support) {
1264 case MAE_FIELD_SUPPORTED_MATCH_MASK:
1267 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
1268 is_valid = efx_mask_is_prefix(m_size, m_buf);
1270 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1271 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
1272 efx_mask_is_all_zeros(m_size, m_buf));
1274 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1275 is_valid = efx_mask_is_all_ones(m_size, m_buf);
1277 if ((is_valid == B_FALSE) && (alt_m_size != 0)) {
1279 * This field has an alternative one. The FW
1280 * reports ALWAYS for both implying that one
1281 * of them is required to have all-ones mask.
1283 * The primary field's mask is incorrect; go
1284 * on to check that of the alternative field.
1286 is_valid = efx_mask_is_all_ones(alt_m_size,
1290 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1291 case MAE_FIELD_UNSUPPORTED:
1293 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1297 if (is_valid == B_FALSE)
1301 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1303 const efx_mae_mv_bit_desc_t *bit_descp =
1304 &bit_desc_setp[field_id];
1305 unsigned int byte_idx =
1306 bit_descp->emmbd_mask_ofst +
1307 bit_descp->emmbd_mask_lbn / 8;
1308 unsigned int bit_idx =
1309 bit_descp->emmbd_mask_lbn % 8;
1310 efx_mae_field_cap_id_t bit_cap_id =
1311 bit_descp->emmbd_bit_cap_id;
1313 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1314 continue; /* Skip array gap */
1316 if ((unsigned int)bit_cap_id >= field_ncaps) {
1317 /* No capability for this bit = unsupported. */
1318 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1319 if (is_valid == B_FALSE)
1325 switch (field_caps[bit_cap_id].emfc_support) {
1326 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1329 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1330 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) != 0);
1332 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1333 case MAE_FIELD_UNSUPPORTED:
1335 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1339 if (is_valid == B_FALSE)
1346 __checkReturn efx_rc_t
1347 efx_mae_action_set_spec_init(
1348 __in efx_nic_t *enp,
1349 __out efx_mae_actions_t **specp)
1351 efx_mae_actions_t *spec;
1354 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
1360 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1361 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1368 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1373 efx_mae_action_set_spec_fini(
1374 __in efx_nic_t *enp,
1375 __in efx_mae_actions_t *spec)
1377 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1380 static __checkReturn efx_rc_t
1381 efx_mae_action_set_add_decap(
1382 __in efx_mae_actions_t *spec,
1383 __in size_t arg_size,
1384 __in_bcount(arg_size) const uint8_t *arg)
1388 _NOTE(ARGUNUSED(spec))
1390 if (arg_size != 0) {
1400 /* This action does not have any arguments, so do nothing here. */
1407 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1411 static __checkReturn efx_rc_t
1412 efx_mae_action_set_add_vlan_pop(
1413 __in efx_mae_actions_t *spec,
1414 __in size_t arg_size,
1415 __in_bcount(arg_size) const uint8_t *arg)
1419 if (arg_size != 0) {
1429 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
1434 ++spec->ema_n_vlan_tags_to_pop;
1443 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1447 static __checkReturn efx_rc_t
1448 efx_mae_action_set_add_vlan_push(
1449 __in efx_mae_actions_t *spec,
1450 __in size_t arg_size,
1451 __in_bcount(arg_size) const uint8_t *arg)
1453 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
1456 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
1466 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1471 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
1472 ++(spec->ema_n_vlan_tags_to_push);
1481 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1485 static __checkReturn efx_rc_t
1486 efx_mae_action_set_add_encap(
1487 __in efx_mae_actions_t *spec,
1488 __in size_t arg_size,
1489 __in_bcount(arg_size) const uint8_t *arg)
1494 * Adding this specific action to an action set spec and setting encap.
1495 * header ID in the spec are two individual steps. This design allows
1496 * the client driver to avoid encap. header allocation when it simply
1497 * needs to check the order of actions submitted by user ("validate"),
1498 * without actually allocating an action set and inserting a rule.
1500 * For now, mark encap. header ID as invalid; the caller will invoke
1501 * efx_mae_action_set_fill_in_eh_id() to override the field prior
1502 * to action set allocation; otherwise, the allocation will fail.
1504 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1507 * As explained above, there are no arguments to handle here.
1508 * efx_mae_action_set_fill_in_eh_id() will take care of them.
1510 if (arg_size != 0) {
1525 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1529 static __checkReturn efx_rc_t
1530 efx_mae_action_set_add_count(
1531 __in efx_mae_actions_t *spec,
1532 __in size_t arg_size,
1533 __in_bcount(arg_size) const uint8_t *arg)
1537 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1538 MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL);
1541 * Preparing an action set spec to update a counter requires
1542 * two steps: first add this action to the action spec, and then
1543 * add the counter ID to the spec. This allows validity checking
1544 * and resource allocation to be done separately.
1545 * Mark the counter ID as invalid in the spec to ensure that the
1546 * caller must also invoke efx_mae_action_set_fill_in_counter_id()
1547 * before action set allocation.
1549 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1551 /* Nothing else is supposed to take place over here. */
1552 if (arg_size != 0) {
1562 ++(spec->ema_n_count_actions);
1569 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1573 static __checkReturn efx_rc_t
1574 efx_mae_action_set_add_flag(
1575 __in efx_mae_actions_t *spec,
1576 __in size_t arg_size,
1577 __in_bcount(arg_size) const uint8_t *arg)
1581 _NOTE(ARGUNUSED(spec))
1583 if (arg_size != 0) {
1593 /* This action does not have any arguments, so do nothing here. */
1600 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1604 static __checkReturn efx_rc_t
1605 efx_mae_action_set_add_mark(
1606 __in efx_mae_actions_t *spec,
1607 __in size_t arg_size,
1608 __in_bcount(arg_size) const uint8_t *arg)
1612 if (arg_size != sizeof (spec->ema_mark_value)) {
1622 memcpy(&spec->ema_mark_value, arg, arg_size);
1629 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1633 static __checkReturn efx_rc_t
1634 efx_mae_action_set_add_deliver(
1635 __in efx_mae_actions_t *spec,
1636 __in size_t arg_size,
1637 __in_bcount(arg_size) const uint8_t *arg)
1641 if (arg_size != sizeof (spec->ema_deliver_mport)) {
1651 memcpy(&spec->ema_deliver_mport, arg, arg_size);
1658 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1662 typedef struct efx_mae_action_desc_s {
1663 /* Action specific handler */
1664 efx_rc_t (*emad_add)(efx_mae_actions_t *,
1665 size_t, const uint8_t *);
1666 } efx_mae_action_desc_t;
1668 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
1669 [EFX_MAE_ACTION_DECAP] = {
1670 .emad_add = efx_mae_action_set_add_decap
1672 [EFX_MAE_ACTION_VLAN_POP] = {
1673 .emad_add = efx_mae_action_set_add_vlan_pop
1675 [EFX_MAE_ACTION_VLAN_PUSH] = {
1676 .emad_add = efx_mae_action_set_add_vlan_push
1678 [EFX_MAE_ACTION_ENCAP] = {
1679 .emad_add = efx_mae_action_set_add_encap
1681 [EFX_MAE_ACTION_COUNT] = {
1682 .emad_add = efx_mae_action_set_add_count
1684 [EFX_MAE_ACTION_FLAG] = {
1685 .emad_add = efx_mae_action_set_add_flag
1687 [EFX_MAE_ACTION_MARK] = {
1688 .emad_add = efx_mae_action_set_add_mark
1690 [EFX_MAE_ACTION_DELIVER] = {
1691 .emad_add = efx_mae_action_set_add_deliver
1695 static const uint32_t efx_mae_action_ordered_map =
1696 (1U << EFX_MAE_ACTION_DECAP) |
1697 (1U << EFX_MAE_ACTION_VLAN_POP) |
1698 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1700 * HW will conduct action COUNT after
1701 * the matching packet has been modified by
1702 * length-affecting actions except for ENCAP.
1704 (1U << EFX_MAE_ACTION_COUNT) |
1705 (1U << EFX_MAE_ACTION_ENCAP) |
1706 (1U << EFX_MAE_ACTION_FLAG) |
1707 (1U << EFX_MAE_ACTION_MARK) |
1708 (1U << EFX_MAE_ACTION_DELIVER);
1711 * These actions must not be added after DELIVER, but
1712 * they can have any place among the rest of
1713 * strictly ordered actions.
1715 static const uint32_t efx_mae_action_nonstrict_map =
1716 (1U << EFX_MAE_ACTION_COUNT) |
1717 (1U << EFX_MAE_ACTION_FLAG) |
1718 (1U << EFX_MAE_ACTION_MARK);
1720 static const uint32_t efx_mae_action_repeat_map =
1721 (1U << EFX_MAE_ACTION_VLAN_POP) |
1722 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1723 (1U << EFX_MAE_ACTION_COUNT);
1726 * Add an action to an action set.
1728 * This has to be invoked in the desired action order.
1729 * An out-of-order action request will be turned down.
1731 static __checkReturn efx_rc_t
1732 efx_mae_action_set_spec_populate(
1733 __in efx_mae_actions_t *spec,
1734 __in efx_mae_action_t type,
1735 __in size_t arg_size,
1736 __in_bcount(arg_size) const uint8_t *arg)
1738 uint32_t action_mask;
1741 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1742 (sizeof (efx_mae_action_ordered_map) * 8));
1743 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1744 (sizeof (efx_mae_action_repeat_map) * 8));
1746 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
1747 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
1748 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
1750 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
1755 action_mask = (1U << type);
1757 if ((spec->ema_actions & action_mask) != 0) {
1758 /* The action set already contains this action. */
1759 if ((efx_mae_action_repeat_map & action_mask) == 0) {
1760 /* Cannot add another non-repeatable action. */
1766 if ((efx_mae_action_ordered_map & action_mask) != 0) {
1767 uint32_t strict_ordered_map =
1768 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
1769 uint32_t later_actions_mask =
1770 strict_ordered_map & ~(action_mask | (action_mask - 1));
1772 if ((spec->ema_actions & later_actions_mask) != 0) {
1773 /* Cannot add an action after later ordered actions. */
1779 if (efx_mae_actions[type].emad_add != NULL) {
1780 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
1785 spec->ema_actions |= action_mask;
1796 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1800 __checkReturn efx_rc_t
1801 efx_mae_action_set_populate_decap(
1802 __in efx_mae_actions_t *spec)
1804 return (efx_mae_action_set_spec_populate(spec,
1805 EFX_MAE_ACTION_DECAP, 0, NULL));
1808 __checkReturn efx_rc_t
1809 efx_mae_action_set_populate_vlan_pop(
1810 __in efx_mae_actions_t *spec)
1812 return (efx_mae_action_set_spec_populate(spec,
1813 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1816 __checkReturn efx_rc_t
1817 efx_mae_action_set_populate_vlan_push(
1818 __in efx_mae_actions_t *spec,
1819 __in uint16_t tpid_be,
1820 __in uint16_t tci_be)
1822 efx_mae_action_vlan_push_t action;
1823 const uint8_t *arg = (const uint8_t *)&action;
1825 action.emavp_tpid_be = tpid_be;
1826 action.emavp_tci_be = tci_be;
1828 return (efx_mae_action_set_spec_populate(spec,
1829 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1832 __checkReturn efx_rc_t
1833 efx_mae_action_set_populate_encap(
1834 __in efx_mae_actions_t *spec)
1837 * There is no argument to pass encap. header ID, thus, one does not
1838 * need to allocate an encap. header while parsing application input.
1839 * This is useful since building an action set may be done simply to
1840 * validate a rule, whilst resource allocation usually consumes time.
1842 return (efx_mae_action_set_spec_populate(spec,
1843 EFX_MAE_ACTION_ENCAP, 0, NULL));
1846 __checkReturn efx_rc_t
1847 efx_mae_action_set_populate_count(
1848 __in efx_mae_actions_t *spec)
1851 * There is no argument to pass counter ID, thus, one does not
1852 * need to allocate a counter while parsing application input.
1853 * This is useful since building an action set may be done simply to
1854 * validate a rule, whilst resource allocation usually consumes time.
1856 return (efx_mae_action_set_spec_populate(spec,
1857 EFX_MAE_ACTION_COUNT, 0, NULL));
1860 __checkReturn efx_rc_t
1861 efx_mae_action_set_populate_flag(
1862 __in efx_mae_actions_t *spec)
1864 return (efx_mae_action_set_spec_populate(spec,
1865 EFX_MAE_ACTION_FLAG, 0, NULL));
1868 __checkReturn efx_rc_t
1869 efx_mae_action_set_populate_mark(
1870 __in efx_mae_actions_t *spec,
1871 __in uint32_t mark_value)
1873 const uint8_t *arg = (const uint8_t *)&mark_value;
1875 return (efx_mae_action_set_spec_populate(spec,
1876 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1879 __checkReturn efx_rc_t
1880 efx_mae_action_set_populate_deliver(
1881 __in efx_mae_actions_t *spec,
1882 __in const efx_mport_sel_t *mportp)
1887 if (mportp == NULL) {
1892 arg = (const uint8_t *)&mportp->sel;
1894 return (efx_mae_action_set_spec_populate(spec,
1895 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1898 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1902 __checkReturn efx_rc_t
1903 efx_mae_action_set_populate_drop(
1904 __in efx_mae_actions_t *spec)
1906 efx_mport_sel_t mport;
1910 EFX_POPULATE_DWORD_1(dword,
1911 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1914 * The constructed DWORD is little-endian,
1915 * but the resulting value is meant to be
1916 * passed to MCDIs, where it will undergo
1917 * host-order to little endian conversion.
1919 mport.sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
1921 arg = (const uint8_t *)&mport.sel;
1923 return (efx_mae_action_set_spec_populate(spec,
1924 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1927 __checkReturn boolean_t
1928 efx_mae_action_set_specs_equal(
1929 __in const efx_mae_actions_t *left,
1930 __in const efx_mae_actions_t *right)
1932 size_t cmp_size = EFX_FIELD_OFFSET(efx_mae_actions_t, ema_rsrc);
1935 * An action set specification consists of two parts. The first part
1936 * indicates what actions are included in the action set, as well as
1937 * extra quantitative values (in example, the number of VLAN tags to
1938 * push). The second part comprises resource IDs used by the actions.
1940 * A resource, in example, a counter, is allocated from the hardware
1941 * by the client, and it's the client who is responsible for keeping
1942 * track of allocated resources and comparing resource IDs if needed.
1944 * In this API, don't compare resource IDs in the two specifications.
1947 return ((memcmp(left, right, cmp_size) == 0) ? B_TRUE : B_FALSE);
1950 __checkReturn efx_rc_t
1951 efx_mae_match_specs_class_cmp(
1952 __in efx_nic_t *enp,
1953 __in const efx_mae_match_spec_t *left,
1954 __in const efx_mae_match_spec_t *right,
1955 __out boolean_t *have_same_classp)
1957 efx_mae_t *maep = enp->en_maep;
1958 unsigned int field_ncaps = maep->em_max_nfields;
1959 const efx_mae_field_cap_t *field_caps;
1960 const efx_mae_mv_desc_t *desc_setp;
1961 unsigned int desc_set_nentries;
1962 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1963 unsigned int bit_desc_set_nentries;
1964 boolean_t have_same_class = B_TRUE;
1965 efx_mae_field_id_t field_id;
1966 const uint8_t *mvpl;
1967 const uint8_t *mvpr;
1970 switch (left->emms_type) {
1971 case EFX_MAE_RULE_OUTER:
1972 field_caps = maep->em_outer_rule_field_caps;
1973 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1975 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1976 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1977 bit_desc_set_nentries =
1978 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1979 mvpl = left->emms_mask_value_pairs.outer;
1980 mvpr = right->emms_mask_value_pairs.outer;
1982 case EFX_MAE_RULE_ACTION:
1983 field_caps = maep->em_action_rule_field_caps;
1984 desc_setp = __efx_mae_action_rule_mv_desc_set;
1986 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1987 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1988 bit_desc_set_nentries =
1989 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1990 mvpl = left->emms_mask_value_pairs.action;
1991 mvpr = right->emms_mask_value_pairs.action;
1998 if (field_caps == NULL) {
2003 if (left->emms_type != right->emms_type ||
2004 left->emms_prio != right->emms_prio) {
2006 * Rules of different types can never map to the same class.
2008 * The FW can support some set of match criteria for one
2009 * priority and not support the very same set for
2010 * another priority. Thus, two rules which have
2011 * different priorities can never map to
2014 *have_same_classp = B_FALSE;
2018 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
2020 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
2021 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
2022 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
2023 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
2024 size_t mask_size = descp->emmd_mask_size;
2025 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
2026 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
2027 size_t value_size = descp->emmd_value_size;
2030 continue; /* Skip array gap */
2032 if ((unsigned int)field_cap_id >= field_ncaps) {
2034 * The FW has not reported capability status for this
2035 * field. It's unknown whether any difference between
2036 * the two masks / values affects the class. The only
2037 * case when the class must be the same is when these
2038 * mask-value pairs match. Otherwise, report mismatch.
2040 if ((memcmp(lmaskp, rmaskp, mask_size) == 0) &&
2041 (memcmp(lvalp, rvalp, value_size) == 0))
2047 if (field_caps[field_cap_id].emfc_mask_affects_class) {
2048 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
2049 have_same_class = B_FALSE;
2054 if (field_caps[field_cap_id].emfc_match_affects_class) {
2055 if (memcmp(lvalp, rvalp, value_size) != 0) {
2056 have_same_class = B_FALSE;
2062 if (have_same_class == B_FALSE)
2065 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
2067 const efx_mae_mv_bit_desc_t *bit_descp =
2068 &bit_desc_setp[field_id];
2069 efx_mae_field_cap_id_t bit_cap_id =
2070 bit_descp->emmbd_bit_cap_id;
2071 unsigned int byte_idx;
2072 unsigned int bit_idx;
2074 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
2075 continue; /* Skip array gap */
2077 if ((unsigned int)bit_cap_id >= field_ncaps)
2081 bit_descp->emmbd_mask_ofst +
2082 bit_descp->emmbd_mask_lbn / 8;
2084 bit_descp->emmbd_mask_lbn % 8;
2086 if (field_caps[bit_cap_id].emfc_mask_affects_class &&
2087 (mvpl[byte_idx] & (1U << bit_idx)) !=
2088 (mvpr[byte_idx] & (1U << bit_idx))) {
2089 have_same_class = B_FALSE;
2094 bit_descp->emmbd_value_ofst +
2095 bit_descp->emmbd_value_lbn / 8;
2097 bit_descp->emmbd_value_lbn % 8;
2099 if (field_caps[bit_cap_id].emfc_match_affects_class &&
2100 (mvpl[byte_idx] & (1U << bit_idx)) !=
2101 (mvpr[byte_idx] & (1U << bit_idx))) {
2102 have_same_class = B_FALSE;
2108 *have_same_classp = have_same_class;
2115 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2119 __checkReturn efx_rc_t
2120 efx_mae_outer_rule_insert(
2121 __in efx_nic_t *enp,
2122 __in const efx_mae_match_spec_t *spec,
2123 __in efx_tunnel_protocol_t encap_type,
2124 __out efx_mae_rule_id_t *or_idp)
2126 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2128 EFX_MCDI_DECLARE_BUF(payload,
2129 MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2,
2130 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
2131 uint32_t encap_type_mcdi;
2132 efx_mae_rule_id_t or_id;
2136 EFX_STATIC_ASSERT(sizeof (or_idp->id) ==
2137 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OR_ID_LEN);
2139 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2140 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL);
2142 if (encp->enc_mae_supported == B_FALSE) {
2147 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
2152 switch (encap_type) {
2153 case EFX_TUNNEL_PROTOCOL_NONE:
2154 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2156 case EFX_TUNNEL_PROTOCOL_VXLAN:
2157 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2159 case EFX_TUNNEL_PROTOCOL_GENEVE:
2160 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2162 case EFX_TUNNEL_PROTOCOL_NVGRE:
2163 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2170 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_INSERT;
2171 req.emr_in_buf = payload;
2172 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2;
2173 req.emr_out_buf = payload;
2174 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN;
2176 MCDI_IN_SET_DWORD(req,
2177 MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, encap_type_mcdi);
2179 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_INSERT_IN_PRIO, spec->emms_prio);
2182 * Mask-value pairs have been stored in the byte order needed for the
2183 * MCDI request and are thus safe to be copied directly to the buffer.
2184 * The library cares about byte order in efx_mae_match_spec_field_set().
2186 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.outer) >=
2187 MAE_ENC_FIELD_PAIRS_LEN);
2188 offset = MC_CMD_MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA_OFST;
2189 memcpy(payload + offset, spec->emms_mask_value_pairs.outer,
2190 MAE_ENC_FIELD_PAIRS_LEN);
2192 efx_mcdi_execute(enp, &req);
2194 if (req.emr_rc != 0) {
2199 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN) {
2204 or_id.id = MCDI_OUT_DWORD(req, MAE_OUTER_RULE_INSERT_OUT_OR_ID);
2205 if (or_id.id == EFX_MAE_RSRC_ID_INVALID) {
2210 or_idp->id = or_id.id;
2225 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2229 __checkReturn efx_rc_t
2230 efx_mae_outer_rule_remove(
2231 __in efx_nic_t *enp,
2232 __in const efx_mae_rule_id_t *or_idp)
2234 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2236 EFX_MCDI_DECLARE_BUF(payload,
2237 MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1),
2238 MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
2241 if (encp->enc_mae_supported == B_FALSE) {
2246 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_REMOVE;
2247 req.emr_in_buf = payload;
2248 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1);
2249 req.emr_out_buf = payload;
2250 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1);
2252 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_REMOVE_IN_OR_ID, or_idp->id);
2254 efx_mcdi_execute(enp, &req);
2256 if (req.emr_rc != 0) {
2261 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LENMIN) {
2266 if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
2268 /* Firmware failed to remove the outer rule. */
2282 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2286 __checkReturn efx_rc_t
2287 efx_mae_match_spec_outer_rule_id_set(
2288 __in efx_mae_match_spec_t *spec,
2289 __in const efx_mae_rule_id_t *or_idp)
2291 uint32_t full_mask = UINT32_MAX;
2294 if (spec->emms_type != EFX_MAE_RULE_ACTION) {
2299 if (or_idp == NULL) {
2304 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_OUTER_RULE_ID,
2305 sizeof (or_idp->id), (const uint8_t *)&or_idp->id,
2306 sizeof (full_mask), (const uint8_t *)&full_mask);
2317 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2321 __checkReturn efx_rc_t
2322 efx_mae_encap_header_alloc(
2323 __in efx_nic_t *enp,
2324 __in efx_tunnel_protocol_t encap_type,
2325 __in_bcount(header_size) uint8_t *header_data,
2326 __in size_t header_size,
2327 __out efx_mae_eh_id_t *eh_idp)
2329 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2331 EFX_MCDI_DECLARE_BUF(payload,
2332 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LENMAX_MCDI2,
2333 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
2334 uint32_t encap_type_mcdi;
2335 efx_mae_eh_id_t eh_id;
2338 EFX_STATIC_ASSERT(sizeof (eh_idp->id) ==
2339 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_LEN);
2341 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2342 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL);
2344 if (encp->enc_mae_supported == B_FALSE) {
2349 switch (encap_type) {
2350 case EFX_TUNNEL_PROTOCOL_NONE:
2351 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2353 case EFX_TUNNEL_PROTOCOL_VXLAN:
2354 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2356 case EFX_TUNNEL_PROTOCOL_GENEVE:
2357 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2359 case EFX_TUNNEL_PROTOCOL_NVGRE:
2360 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2368 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2) {
2373 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_ALLOC;
2374 req.emr_in_buf = payload;
2375 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(header_size);
2376 req.emr_out_buf = payload;
2377 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN;
2379 MCDI_IN_SET_DWORD(req,
2380 MAE_ENCAP_HEADER_ALLOC_IN_ENCAP_TYPE, encap_type_mcdi);
2382 memcpy(payload + MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_OFST,
2383 header_data, header_size);
2385 efx_mcdi_execute(enp, &req);
2387 if (req.emr_rc != 0) {
2392 if (req.emr_out_length_used < MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN) {
2397 eh_id.id = MCDI_OUT_DWORD(req,
2398 MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID);
2400 if (eh_id.id == EFX_MAE_RSRC_ID_INVALID) {
2405 eh_idp->id = eh_id.id;
2420 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2424 __checkReturn efx_rc_t
2425 efx_mae_encap_header_free(
2426 __in efx_nic_t *enp,
2427 __in const efx_mae_eh_id_t *eh_idp)
2429 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2431 EFX_MCDI_DECLARE_BUF(payload,
2432 MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1),
2433 MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
2436 if (encp->enc_mae_supported == B_FALSE) {
2441 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_FREE;
2442 req.emr_in_buf = payload;
2443 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1);
2444 req.emr_out_buf = payload;
2445 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1);
2447 MCDI_IN_SET_DWORD(req, MAE_ENCAP_HEADER_FREE_IN_EH_ID, eh_idp->id);
2449 efx_mcdi_execute(enp, &req);
2451 if (req.emr_rc != 0) {
2456 if (MCDI_OUT_DWORD(req, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) !=
2458 /* Firmware failed to remove the encap. header. */
2470 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2474 __checkReturn efx_rc_t
2475 efx_mae_action_set_fill_in_eh_id(
2476 __in efx_mae_actions_t *spec,
2477 __in const efx_mae_eh_id_t *eh_idp)
2481 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_ENCAP)) == 0) {
2483 * The caller has not intended to have action ENCAP originally,
2484 * hence, this attempt to indicate encap. header ID is invalid.
2490 if (spec->ema_rsrc.emar_eh_id.id != EFX_MAE_RSRC_ID_INVALID) {
2491 /* The caller attempts to indicate encap. header ID twice. */
2496 if (eh_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2501 spec->ema_rsrc.emar_eh_id.id = eh_idp->id;
2510 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2514 __checkReturn efx_rc_t
2515 efx_mae_action_set_alloc(
2516 __in efx_nic_t *enp,
2517 __in const efx_mae_actions_t *spec,
2518 __out efx_mae_aset_id_t *aset_idp)
2520 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2522 EFX_MCDI_DECLARE_BUF(payload,
2523 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
2524 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
2525 efx_mae_aset_id_t aset_id;
2528 if (encp->enc_mae_supported == B_FALSE) {
2533 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
2534 req.emr_in_buf = payload;
2535 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
2536 req.emr_out_buf = payload;
2537 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
2540 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
2541 * corresponding resource types are supported by the implementation.
2542 * Use proper resource ID assignments instead.
2544 MCDI_IN_SET_DWORD(req,
2545 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
2547 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_DECAP)) != 0) {
2548 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2549 MAE_ACTION_SET_ALLOC_IN_DECAP, 1);
2552 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2553 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
2555 if (spec->ema_n_vlan_tags_to_push > 0) {
2556 unsigned int outer_tag_idx;
2558 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2559 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
2560 spec->ema_n_vlan_tags_to_push);
2562 if (spec->ema_n_vlan_tags_to_push ==
2563 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
2564 MCDI_IN_SET_WORD(req,
2565 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
2566 spec->ema_vlan_push_descs[0].emavp_tpid_be);
2567 MCDI_IN_SET_WORD(req,
2568 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
2569 spec->ema_vlan_push_descs[0].emavp_tci_be);
2572 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
2574 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
2575 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
2576 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
2577 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
2580 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
2581 spec->ema_rsrc.emar_eh_id.id);
2582 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID,
2583 spec->ema_rsrc.emar_counter_id.id);
2585 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
2586 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2587 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
2590 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
2591 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2592 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
2594 MCDI_IN_SET_DWORD(req,
2595 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
2598 MCDI_IN_SET_DWORD(req,
2599 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
2601 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
2602 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2603 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
2604 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2606 efx_mcdi_execute(enp, &req);
2608 if (req.emr_rc != 0) {
2613 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
2618 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
2619 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
2624 aset_idp->id = aset_id.id;
2635 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2639 __checkReturn unsigned int
2640 efx_mae_action_set_get_nb_count(
2641 __in const efx_mae_actions_t *spec)
2643 return (spec->ema_n_count_actions);
2646 __checkReturn efx_rc_t
2647 efx_mae_action_set_fill_in_counter_id(
2648 __in efx_mae_actions_t *spec,
2649 __in const efx_counter_t *counter_idp)
2653 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_COUNT)) == 0) {
2655 * Invalid to add counter ID if spec does not have COUNT action.
2661 if (spec->ema_n_count_actions != 1) {
2663 * Having multiple COUNT actions in the spec requires a counter
2664 * list to be used. This API must only be used for a single
2665 * counter per spec. Turn down the request as inappropriate.
2671 if (spec->ema_rsrc.emar_counter_id.id != EFX_MAE_RSRC_ID_INVALID) {
2672 /* The caller attempts to indicate counter ID twice. */
2677 if (counter_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2682 spec->ema_rsrc.emar_counter_id.id = counter_idp->id;
2693 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2697 __checkReturn efx_rc_t
2698 efx_mae_counters_alloc(
2699 __in efx_nic_t *enp,
2700 __in uint32_t n_counters,
2701 __out uint32_t *n_allocatedp,
2702 __out_ecount(n_counters) efx_counter_t *countersp,
2703 __out_opt uint32_t *gen_countp)
2705 EFX_MCDI_DECLARE_BUF(payload,
2706 MC_CMD_MAE_COUNTER_ALLOC_IN_LEN,
2707 MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMAX_MCDI2);
2708 efx_mae_t *maep = enp->en_maep;
2709 uint32_t n_allocated;
2714 if (n_counters > maep->em_max_ncounters ||
2715 n_counters < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM ||
2716 n_counters > MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MAXNUM_MCDI2) {
2721 req.emr_cmd = MC_CMD_MAE_COUNTER_ALLOC;
2722 req.emr_in_buf = payload;
2723 req.emr_in_length = MC_CMD_MAE_COUNTER_ALLOC_IN_LEN;
2724 req.emr_out_buf = payload;
2725 req.emr_out_length = MC_CMD_MAE_COUNTER_ALLOC_OUT_LEN(n_counters);
2727 MCDI_IN_SET_DWORD(req, MAE_COUNTER_ALLOC_IN_REQUESTED_COUNT,
2730 efx_mcdi_execute(enp, &req);
2732 if (req.emr_rc != 0) {
2737 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMIN) {
2742 n_allocated = MCDI_OUT_DWORD(req,
2743 MAE_COUNTER_ALLOC_OUT_COUNTER_ID_COUNT);
2744 if (n_allocated < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM) {
2749 for (i = 0; i < n_allocated; i++) {
2750 countersp[i].id = MCDI_OUT_INDEXED_DWORD(req,
2751 MAE_COUNTER_ALLOC_OUT_COUNTER_ID, i);
2754 if (gen_countp != NULL) {
2755 *gen_countp = MCDI_OUT_DWORD(req,
2756 MAE_COUNTER_ALLOC_OUT_GENERATION_COUNT);
2759 *n_allocatedp = n_allocated;
2770 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2775 __checkReturn efx_rc_t
2776 efx_mae_counters_free(
2777 __in efx_nic_t *enp,
2778 __in uint32_t n_counters,
2779 __out uint32_t *n_freedp,
2780 __in_ecount(n_counters) const efx_counter_t *countersp,
2781 __out_opt uint32_t *gen_countp)
2783 EFX_MCDI_DECLARE_BUF(payload,
2784 MC_CMD_MAE_COUNTER_FREE_IN_LENMAX_MCDI2,
2785 MC_CMD_MAE_COUNTER_FREE_OUT_LENMAX_MCDI2);
2786 efx_mae_t *maep = enp->en_maep;
2792 if (n_counters > maep->em_max_ncounters ||
2793 n_counters < MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MINNUM ||
2795 MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MAXNUM_MCDI2) {
2800 req.emr_cmd = MC_CMD_MAE_COUNTER_FREE;
2801 req.emr_in_buf = payload;
2802 req.emr_in_length = MC_CMD_MAE_COUNTER_FREE_IN_LEN(n_counters);
2803 req.emr_out_buf = payload;
2804 req.emr_out_length = MC_CMD_MAE_COUNTER_FREE_OUT_LEN(n_counters);
2806 for (i = 0; i < n_counters; i++) {
2807 MCDI_IN_SET_INDEXED_DWORD(req,
2808 MAE_COUNTER_FREE_IN_FREE_COUNTER_ID, i, countersp[i].id);
2810 MCDI_IN_SET_DWORD(req, MAE_COUNTER_FREE_IN_COUNTER_ID_COUNT,
2813 efx_mcdi_execute(enp, &req);
2815 if (req.emr_rc != 0) {
2820 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_FREE_OUT_LENMIN) {
2825 n_freed = MCDI_OUT_DWORD(req, MAE_COUNTER_FREE_OUT_COUNTER_ID_COUNT);
2827 if (n_freed < MC_CMD_MAE_COUNTER_FREE_OUT_FREED_COUNTER_ID_MINNUM) {
2832 if (gen_countp != NULL) {
2833 *gen_countp = MCDI_OUT_DWORD(req,
2834 MAE_COUNTER_FREE_OUT_GENERATION_COUNT);
2837 *n_freedp = n_freed;
2848 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2853 __checkReturn efx_rc_t
2854 efx_mae_counters_stream_start(
2855 __in efx_nic_t *enp,
2856 __in uint16_t rxq_id,
2857 __in uint16_t packet_size,
2858 __in uint32_t flags_in,
2859 __out uint32_t *flags_out)
2862 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN,
2863 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN);
2866 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_IN_ZERO_SQUASH_DISABLE ==
2867 1U << MC_CMD_MAE_COUNTERS_STREAM_START_IN_ZERO_SQUASH_DISABLE_LBN);
2869 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_OUT_USES_CREDITS ==
2870 1U << MC_CMD_MAE_COUNTERS_STREAM_START_OUT_USES_CREDITS_LBN);
2872 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_START;
2873 req.emr_in_buf = payload;
2874 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN;
2875 req.emr_out_buf = payload;
2876 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN;
2878 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_QID, rxq_id);
2879 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_PACKET_SIZE,
2881 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_START_IN_FLAGS, flags_in);
2883 efx_mcdi_execute(enp, &req);
2885 if (req.emr_rc != 0) {
2890 if (req.emr_out_length_used <
2891 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN) {
2896 *flags_out = MCDI_OUT_DWORD(req, MAE_COUNTERS_STREAM_START_OUT_FLAGS);
2903 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2908 __checkReturn efx_rc_t
2909 efx_mae_counters_stream_stop(
2910 __in efx_nic_t *enp,
2911 __in uint16_t rxq_id,
2912 __out_opt uint32_t *gen_countp)
2915 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN,
2916 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN);
2919 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_STOP;
2920 req.emr_in_buf = payload;
2921 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN;
2922 req.emr_out_buf = payload;
2923 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN;
2925 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_STOP_IN_QID, rxq_id);
2927 efx_mcdi_execute(enp, &req);
2929 if (req.emr_rc != 0) {
2934 if (req.emr_out_length_used <
2935 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN) {
2940 if (gen_countp != NULL) {
2941 *gen_countp = MCDI_OUT_DWORD(req,
2942 MAE_COUNTERS_STREAM_STOP_OUT_GENERATION_COUNT);
2950 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2955 __checkReturn efx_rc_t
2956 efx_mae_counters_stream_give_credits(
2957 __in efx_nic_t *enp,
2958 __in uint32_t n_credits)
2961 EFX_MCDI_DECLARE_BUF(payload,
2962 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN,
2963 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN);
2966 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS;
2967 req.emr_in_buf = payload;
2968 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN;
2969 req.emr_out_buf = payload;
2970 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN;
2972 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_NUM_CREDITS,
2975 efx_mcdi_execute(enp, &req);
2977 if (req.emr_rc != 0) {
2985 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2990 __checkReturn efx_rc_t
2991 efx_mae_action_set_free(
2992 __in efx_nic_t *enp,
2993 __in const efx_mae_aset_id_t *aset_idp)
2995 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2997 EFX_MCDI_DECLARE_BUF(payload,
2998 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
2999 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
3002 if (encp->enc_mae_supported == B_FALSE) {
3007 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
3008 req.emr_in_buf = payload;
3009 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
3010 req.emr_out_buf = payload;
3011 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
3013 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
3015 efx_mcdi_execute(enp, &req);
3017 if (req.emr_rc != 0) {
3022 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_FREE_OUT_LENMIN) {
3027 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
3029 /* Firmware failed to free the action set. */
3043 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3047 __checkReturn efx_rc_t
3048 efx_mae_action_rule_insert(
3049 __in efx_nic_t *enp,
3050 __in const efx_mae_match_spec_t *spec,
3051 __in const efx_mae_aset_list_id_t *asl_idp,
3052 __in const efx_mae_aset_id_t *as_idp,
3053 __out efx_mae_rule_id_t *ar_idp)
3055 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3057 EFX_MCDI_DECLARE_BUF(payload,
3058 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
3059 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
3060 efx_oword_t *rule_response;
3061 efx_mae_rule_id_t ar_id;
3065 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
3066 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
3068 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
3069 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
3071 if (encp->enc_mae_supported == B_FALSE) {
3076 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
3077 (asl_idp != NULL && as_idp != NULL) ||
3078 (asl_idp == NULL && as_idp == NULL)) {
3083 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
3084 req.emr_in_buf = payload;
3085 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
3086 req.emr_out_buf = payload;
3087 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
3089 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
3090 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
3091 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
3092 rule_response = (efx_oword_t *)(payload + offset);
3093 EFX_POPULATE_OWORD_3(*rule_response,
3094 MAE_ACTION_RULE_RESPONSE_ASL_ID,
3095 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
3096 MAE_ACTION_RULE_RESPONSE_AS_ID,
3097 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
3098 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
3100 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
3103 * Mask-value pairs have been stored in the byte order needed for the
3104 * MCDI request and are thus safe to be copied directly to the buffer.
3106 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
3107 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3108 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
3109 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
3110 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3112 efx_mcdi_execute(enp, &req);
3114 if (req.emr_rc != 0) {
3119 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
3124 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
3125 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
3130 ar_idp->id = ar_id.id;
3143 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3147 __checkReturn efx_rc_t
3148 efx_mae_action_rule_remove(
3149 __in efx_nic_t *enp,
3150 __in const efx_mae_rule_id_t *ar_idp)
3152 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3154 EFX_MCDI_DECLARE_BUF(payload,
3155 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
3156 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
3159 if (encp->enc_mae_supported == B_FALSE) {
3164 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
3165 req.emr_in_buf = payload;
3166 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
3167 req.emr_out_buf = payload;
3168 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
3170 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
3172 efx_mcdi_execute(enp, &req);
3174 if (req.emr_rc != 0) {
3179 if (req.emr_out_length_used <
3180 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LENMIN) {
3185 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
3187 /* Firmware failed to delete the action rule. */
3201 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3205 __checkReturn efx_rc_t
3206 efx_mcdi_mport_alloc_alias(
3207 __in efx_nic_t *enp,
3208 __out efx_mport_id_t *mportp,
3209 __out_opt uint32_t *labelp)
3211 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3213 EFX_MCDI_DECLARE_BUF(payload,
3214 MC_CMD_MAE_MPORT_ALLOC_ALIAS_IN_LEN,
3215 MC_CMD_MAE_MPORT_ALLOC_ALIAS_OUT_LEN);
3218 if (encp->enc_mae_supported == B_FALSE) {
3223 req.emr_cmd = MC_CMD_MAE_MPORT_ALLOC;
3224 req.emr_in_buf = payload;
3225 req.emr_in_length = MC_CMD_MAE_MPORT_ALLOC_ALIAS_IN_LEN;
3226 req.emr_out_buf = payload;
3227 req.emr_out_length = MC_CMD_MAE_MPORT_ALLOC_ALIAS_OUT_LEN;
3229 MCDI_IN_SET_DWORD(req, MAE_MPORT_ALLOC_IN_TYPE,
3230 MC_CMD_MAE_MPORT_ALLOC_IN_MPORT_TYPE_ALIAS);
3231 MCDI_IN_SET_DWORD(req, MAE_MPORT_ALLOC_ALIAS_IN_DELIVER_MPORT,
3232 MAE_MPORT_SELECTOR_ASSIGNED);
3234 efx_mcdi_execute(enp, &req);
3236 if (req.emr_rc != 0) {
3241 mportp->id = MCDI_OUT_DWORD(req, MAE_MPORT_ALLOC_OUT_MPORT_ID);
3243 *labelp = MCDI_OUT_DWORD(req, MAE_MPORT_ALLOC_ALIAS_OUT_LABEL);
3250 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3254 __checkReturn efx_rc_t
3256 __in efx_nic_t *enp,
3257 __in const efx_mport_id_t *mportp)
3259 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3261 EFX_MCDI_DECLARE_BUF(payload,
3262 MC_CMD_MAE_MPORT_FREE_IN_LEN,
3263 MC_CMD_MAE_MPORT_FREE_OUT_LEN);
3266 if (encp->enc_mae_supported == B_FALSE) {
3271 req.emr_cmd = MC_CMD_MAE_MPORT_FREE;
3272 req.emr_in_buf = payload;
3273 req.emr_in_length = MC_CMD_MAE_MPORT_FREE_IN_LEN;
3274 req.emr_out_buf = payload;
3275 req.emr_out_length = MC_CMD_MAE_MPORT_FREE_OUT_LEN;
3277 MCDI_IN_SET_DWORD(req, MAE_MPORT_FREE_IN_MPORT_ID, mportp->id);
3279 efx_mcdi_execute(enp, &req);
3281 if (req.emr_rc != 0) {
3291 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3295 static __checkReturn efx_rc_t
3296 efx_mae_read_mport_journal_single(
3297 __in uint8_t *entry_buf,
3298 __out efx_mport_desc_t *desc)
3303 memset(desc, 0, sizeof (*desc));
3305 desc->emd_id.id = MCDI_STRUCT_DWORD(entry_buf,
3306 MAE_MPORT_DESC_V2_MPORT_ID);
3308 desc->emd_can_receive_on = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3309 MAE_MPORT_DESC_V2_FLAGS,
3310 MAE_MPORT_DESC_V2_CAN_RECEIVE_ON);
3312 desc->emd_can_deliver_to = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3313 MAE_MPORT_DESC_V2_FLAGS,
3314 MAE_MPORT_DESC_V2_CAN_DELIVER_TO);
3316 desc->emd_can_delete = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3317 MAE_MPORT_DESC_V2_FLAGS,
3318 MAE_MPORT_DESC_V2_CAN_DELETE);
3320 desc->emd_zombie = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3321 MAE_MPORT_DESC_V2_FLAGS,
3322 MAE_MPORT_DESC_V2_IS_ZOMBIE);
3324 desc->emd_type = MCDI_STRUCT_DWORD(entry_buf,
3325 MAE_MPORT_DESC_V2_MPORT_TYPE);
3328 * We can't check everything here. If some additional checks are
3329 * required, they should be performed by the callback function.
3331 switch (desc->emd_type) {
3332 case EFX_MPORT_TYPE_NET_PORT:
3333 desc->emd_net_port.ep_index =
3334 MCDI_STRUCT_DWORD(entry_buf,
3335 MAE_MPORT_DESC_V2_NET_PORT_IDX);
3337 case EFX_MPORT_TYPE_ALIAS:
3338 desc->emd_alias.ea_target_mport_id.id =
3339 MCDI_STRUCT_DWORD(entry_buf,
3340 MAE_MPORT_DESC_V2_ALIAS_DELIVER_MPORT_ID);
3342 case EFX_MPORT_TYPE_VNIC:
3343 desc->emd_vnic.ev_client_type =
3344 MCDI_STRUCT_DWORD(entry_buf,
3345 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE);
3346 if (desc->emd_vnic.ev_client_type !=
3347 EFX_MPORT_VNIC_CLIENT_FUNCTION)
3350 pcie_intf = MCDI_STRUCT_DWORD(entry_buf,
3351 MAE_MPORT_DESC_V2_VNIC_FUNCTION_INTERFACE);
3352 rc = efx_mcdi_intf_from_pcie(pcie_intf,
3353 &desc->emd_vnic.ev_intf);
3357 desc->emd_vnic.ev_pf = MCDI_STRUCT_WORD(entry_buf,
3358 MAE_MPORT_DESC_V2_VNIC_FUNCTION_PF_IDX);
3359 desc->emd_vnic.ev_vf = MCDI_STRUCT_WORD(entry_buf,
3360 MAE_MPORT_DESC_V2_VNIC_FUNCTION_VF_IDX);
3361 desc->emd_vnic.ev_handle = MCDI_STRUCT_DWORD(entry_buf,
3362 MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE);
3374 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3378 static __checkReturn efx_rc_t
3379 efx_mae_read_mport_journal_batch(
3380 __in efx_nic_t *enp,
3381 __in efx_mae_read_mport_journal_cb *cbp,
3382 __in void *cb_datap,
3383 __out uint32_t *morep)
3386 EFX_MCDI_DECLARE_BUF(payload,
3387 MC_CMD_MAE_MPORT_READ_JOURNAL_IN_LEN,
3388 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMAX_MCDI2);
3395 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_NET_PORT ==
3396 MAE_MPORT_DESC_V2_MPORT_TYPE_NET_PORT);
3397 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_ALIAS ==
3398 MAE_MPORT_DESC_V2_MPORT_TYPE_ALIAS);
3399 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_VNIC ==
3400 MAE_MPORT_DESC_V2_MPORT_TYPE_VNIC);
3402 EFX_STATIC_ASSERT(EFX_MPORT_VNIC_CLIENT_FUNCTION ==
3403 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE_FUNCTION);
3404 EFX_STATIC_ASSERT(EFX_MPORT_VNIC_CLIENT_PLUGIN ==
3405 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE_PLUGIN);
3412 req.emr_cmd = MC_CMD_MAE_MPORT_READ_JOURNAL;
3413 req.emr_in_buf = payload;
3414 req.emr_in_length = MC_CMD_MAE_MPORT_READ_JOURNAL_IN_LEN;
3415 req.emr_out_buf = payload;
3416 req.emr_out_length = MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMAX_MCDI2;
3418 MCDI_IN_SET_DWORD(req, MAE_MPORT_READ_JOURNAL_IN_FLAGS, 0);
3420 efx_mcdi_execute(enp, &req);
3422 if (req.emr_rc != 0) {
3427 if (req.emr_out_length_used <
3428 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMIN) {
3433 if (morep != NULL) {
3434 *morep = MCDI_OUT_DWORD_FIELD(req,
3435 MAE_MPORT_READ_JOURNAL_OUT_FLAGS,
3436 MAE_MPORT_READ_JOURNAL_OUT_MORE);
3438 n_entries = MCDI_OUT_DWORD(req,
3439 MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_COUNT);
3440 entry_sz = MCDI_OUT_DWORD(req,
3441 MAE_MPORT_READ_JOURNAL_OUT_SIZEOF_MPORT_DESC);
3442 entry_buf = MCDI_OUT2(req, uint8_t,
3443 MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA);
3445 if (entry_sz < MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE_OFST +
3446 MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE_LEN) {
3450 if (n_entries * entry_sz / entry_sz != n_entries) {
3454 if (req.emr_out_length_used !=
3455 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMIN + n_entries * entry_sz) {
3460 for (i = 0; i < n_entries; i++) {
3461 efx_mport_desc_t desc;
3463 rc = efx_mae_read_mport_journal_single(entry_buf, &desc);
3467 (*cbp)(cb_datap, &desc, sizeof (desc));
3468 entry_buf += entry_sz;
3484 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3488 __checkReturn efx_rc_t
3489 efx_mae_read_mport_journal(
3490 __in efx_nic_t *enp,
3491 __in efx_mae_read_mport_journal_cb *cbp,
3492 __in void *cb_datap)
3494 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3498 if (encp->enc_mae_supported == B_FALSE) {
3504 rc = efx_mae_read_mport_journal_batch(enp, cbp, cb_datap,
3508 } while (more != 0);
3515 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3519 #endif /* EFSYS_OPT_MAE */