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,
476 EFX_MAE_FIELD_ID_RECIRC_ID = MAE_FIELD_RECIRC_ID,
478 EFX_MAE_FIELD_CAP_NIDS
479 } efx_mae_field_cap_id_t;
481 typedef enum efx_mae_field_endianness_e {
482 EFX_MAE_FIELD_LE = 0,
485 EFX_MAE_FIELD_ENDIANNESS_NTYPES
486 } efx_mae_field_endianness_t;
489 * The following structure is a means to describe an MAE field.
490 * The information in it is meant to be used internally by
491 * APIs for addressing a given field in a mask-value pairs
492 * structure and for validation purposes.
494 * A field may have an alternative one. This structure
495 * has additional members to reference the alternative
496 * field's mask. See efx_mae_match_spec_is_valid().
498 typedef struct efx_mae_mv_desc_s {
499 efx_mae_field_cap_id_t emmd_field_cap_id;
501 size_t emmd_value_size;
502 size_t emmd_value_offset;
503 size_t emmd_mask_size;
504 size_t emmd_mask_offset;
507 * Having the alternative field's mask size set to 0
508 * means that there's no alternative field specified.
510 size_t emmd_alt_mask_size;
511 size_t emmd_alt_mask_offset;
513 /* Primary field and the alternative one are of the same endianness. */
514 efx_mae_field_endianness_t emmd_endianness;
517 /* Indices to this array are provided by efx_mae_field_id_t */
518 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
519 #define EFX_MAE_MV_DESC(_name, _endianness) \
520 [EFX_MAE_FIELD_##_name] = \
522 EFX_MAE_FIELD_ID_##_name, \
523 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LEN, \
524 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_OFST, \
525 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_MASK_LEN, \
526 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_MASK_OFST, \
527 0, 0 /* no alternative field */, \
531 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
532 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
533 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
534 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
535 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
536 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
537 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
538 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
539 EFX_MAE_MV_DESC(SRC_IP4_BE, EFX_MAE_FIELD_BE),
540 EFX_MAE_MV_DESC(DST_IP4_BE, EFX_MAE_FIELD_BE),
541 EFX_MAE_MV_DESC(IP_PROTO, EFX_MAE_FIELD_BE),
542 EFX_MAE_MV_DESC(IP_TOS, EFX_MAE_FIELD_BE),
543 EFX_MAE_MV_DESC(IP_TTL, EFX_MAE_FIELD_BE),
544 EFX_MAE_MV_DESC(SRC_IP6_BE, EFX_MAE_FIELD_BE),
545 EFX_MAE_MV_DESC(DST_IP6_BE, EFX_MAE_FIELD_BE),
546 EFX_MAE_MV_DESC(L4_SPORT_BE, EFX_MAE_FIELD_BE),
547 EFX_MAE_MV_DESC(L4_DPORT_BE, EFX_MAE_FIELD_BE),
548 EFX_MAE_MV_DESC(TCP_FLAGS_BE, EFX_MAE_FIELD_BE),
549 EFX_MAE_MV_DESC(ENC_VNET_ID_BE, EFX_MAE_FIELD_BE),
550 EFX_MAE_MV_DESC(OUTER_RULE_ID, EFX_MAE_FIELD_LE),
551 EFX_MAE_MV_DESC(RECIRC_ID, EFX_MAE_FIELD_LE),
553 #undef EFX_MAE_MV_DESC
556 /* Indices to this array are provided by efx_mae_field_id_t */
557 static const efx_mae_mv_desc_t __efx_mae_outer_rule_mv_desc_set[] = {
558 #define EFX_MAE_MV_DESC(_name, _endianness) \
559 [EFX_MAE_FIELD_##_name] = \
561 EFX_MAE_FIELD_ID_##_name, \
562 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
563 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
564 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
565 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
566 0, 0 /* no alternative field */, \
570 /* Same as EFX_MAE_MV_DESC(), but also indicates an alternative field. */
571 #define EFX_MAE_MV_DESC_ALT(_name, _alt_name, _endianness) \
572 [EFX_MAE_FIELD_##_name] = \
574 EFX_MAE_FIELD_ID_##_name, \
575 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
576 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
577 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
578 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
579 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_LEN, \
580 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_OFST, \
584 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
585 EFX_MAE_MV_DESC(ENC_ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
586 EFX_MAE_MV_DESC(ENC_ETH_SADDR_BE, EFX_MAE_FIELD_BE),
587 EFX_MAE_MV_DESC(ENC_ETH_DADDR_BE, EFX_MAE_FIELD_BE),
588 EFX_MAE_MV_DESC(ENC_VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
589 EFX_MAE_MV_DESC(ENC_VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
590 EFX_MAE_MV_DESC(ENC_VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
591 EFX_MAE_MV_DESC(ENC_VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
592 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP4_BE, ENC_SRC_IP6_BE, EFX_MAE_FIELD_BE),
593 EFX_MAE_MV_DESC_ALT(ENC_DST_IP4_BE, ENC_DST_IP6_BE, EFX_MAE_FIELD_BE),
594 EFX_MAE_MV_DESC(ENC_IP_PROTO, EFX_MAE_FIELD_BE),
595 EFX_MAE_MV_DESC(ENC_IP_TOS, EFX_MAE_FIELD_BE),
596 EFX_MAE_MV_DESC(ENC_IP_TTL, EFX_MAE_FIELD_BE),
597 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP6_BE, ENC_SRC_IP4_BE, EFX_MAE_FIELD_BE),
598 EFX_MAE_MV_DESC_ALT(ENC_DST_IP6_BE, ENC_DST_IP4_BE, EFX_MAE_FIELD_BE),
599 EFX_MAE_MV_DESC(ENC_L4_SPORT_BE, EFX_MAE_FIELD_BE),
600 EFX_MAE_MV_DESC(ENC_L4_DPORT_BE, EFX_MAE_FIELD_BE),
602 #undef EFX_MAE_MV_DESC_ALT
603 #undef EFX_MAE_MV_DESC
607 * The following structure is a means to describe an MAE bit.
608 * The information in it is meant to be used internally by
609 * APIs for addressing a given flag in a mask-value pairs
610 * structure and for validation purposes.
612 typedef struct efx_mae_mv_bit_desc_s {
614 * Arrays using this struct are indexed by field IDs.
615 * Fields which aren't meant to be referenced by these
616 * arrays comprise gaps (invalid entries). Below field
617 * helps to identify such entries.
619 boolean_t emmbd_entry_is_valid;
620 efx_mae_field_cap_id_t emmbd_bit_cap_id;
621 size_t emmbd_value_ofst;
622 unsigned int emmbd_value_lbn;
623 size_t emmbd_mask_ofst;
624 unsigned int emmbd_mask_lbn;
625 } efx_mae_mv_bit_desc_t;
627 static const efx_mae_mv_bit_desc_t __efx_mae_outer_rule_mv_bit_desc_set[] = {
628 #define EFX_MAE_MV_BIT_DESC(_name) \
629 [EFX_MAE_FIELD_##_name] = \
632 EFX_MAE_FIELD_ID_##_name, \
633 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
634 MAE_ENC_FIELD_PAIRS_##_name##_LBN, \
635 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
636 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LBN, \
639 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
640 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
642 #undef EFX_MAE_MV_BIT_DESC
645 static const efx_mae_mv_bit_desc_t __efx_mae_action_rule_mv_bit_desc_set[] = {
646 #define EFX_MAE_MV_BIT_DESC(_name) \
647 [EFX_MAE_FIELD_##_name] = \
650 EFX_MAE_FIELD_ID_##_name, \
651 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_OFST, \
652 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
653 MAE_FIELD_MASK_VALUE_PAIRS_V2_FLAGS_MASK_OFST, \
654 MAE_FIELD_MASK_VALUE_PAIRS_V2_##_name##_LBN, \
657 EFX_MAE_MV_BIT_DESC(HAS_OVLAN),
658 EFX_MAE_MV_BIT_DESC(HAS_IVLAN),
659 EFX_MAE_MV_BIT_DESC(ENC_HAS_OVLAN),
660 EFX_MAE_MV_BIT_DESC(ENC_HAS_IVLAN),
662 #undef EFX_MAE_MV_BIT_DESC
665 __checkReturn efx_rc_t
666 efx_mae_mport_invalid(
667 __out efx_mport_sel_t *mportp)
672 if (mportp == NULL) {
677 EFX_POPULATE_DWORD_1(dword,
678 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_INVALID);
680 memset(mportp, 0, sizeof (*mportp));
681 mportp->sel = dword.ed_u32[0];
686 EFSYS_PROBE1(fail1, efx_rc_t, rc);
690 __checkReturn efx_rc_t
691 efx_mae_mport_by_phy_port(
692 __in uint32_t phy_port,
693 __out efx_mport_sel_t *mportp)
698 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
703 EFX_POPULATE_DWORD_2(dword,
704 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
705 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
707 memset(mportp, 0, sizeof (*mportp));
709 * The constructed DWORD is little-endian,
710 * but the resulting value is meant to be
711 * passed to MCDIs, where it will undergo
712 * host-order to little endian conversion.
714 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
719 EFSYS_PROBE1(fail1, efx_rc_t, rc);
723 __checkReturn efx_rc_t
724 efx_mae_mport_by_pcie_function(
727 __out efx_mport_sel_t *mportp)
732 rc = efx_mae_mport_by_pcie_mh_function(EFX_PCIE_INTERFACE_CALLER,
740 EFSYS_PROBE1(fail1, efx_rc_t, rc);
744 static __checkReturn efx_rc_t
745 efx_mae_intf_to_selector(
746 __in efx_pcie_interface_t intf,
747 __out uint32_t *selector_intfp)
752 case EFX_PCIE_INTERFACE_HOST_PRIMARY:
753 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_HOST_PRIMARY <=
754 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
755 *selector_intfp = MAE_MPORT_SELECTOR_HOST_PRIMARY;
757 case EFX_PCIE_INTERFACE_NIC_EMBEDDED:
758 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_NIC_EMBEDDED <=
759 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
760 *selector_intfp = MAE_MPORT_SELECTOR_NIC_EMBEDDED;
762 case EFX_PCIE_INTERFACE_CALLER:
763 EFX_STATIC_ASSERT(MAE_MPORT_SELECTOR_CALLER_INTF <=
764 EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_INTF_ID));
765 *selector_intfp = MAE_MPORT_SELECTOR_CALLER_INTF;
775 EFSYS_PROBE1(fail1, efx_rc_t, rc);
779 __checkReturn efx_rc_t
780 efx_mae_mport_by_pcie_mh_function(
781 __in efx_pcie_interface_t intf,
784 __out efx_mport_sel_t *mportp)
786 uint32_t selector_intf;
790 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
791 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
793 rc = efx_mae_intf_to_selector(intf, &selector_intf);
797 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_MH_PF_ID)) {
802 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
808 EFX_POPULATE_DWORD_4(dword,
809 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_MH_FUNC,
810 MAE_MPORT_SELECTOR_FUNC_INTF_ID, selector_intf,
811 MAE_MPORT_SELECTOR_FUNC_MH_PF_ID, pf,
812 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
814 memset(mportp, 0, sizeof (*mportp));
815 mportp->sel = dword.ed_u32[0];
824 EFSYS_PROBE1(fail1, efx_rc_t, rc);
828 static __checkReturn efx_rc_t
829 efx_mcdi_mae_mport_lookup(
831 __in const efx_mport_sel_t *mport_selectorp,
832 __out efx_mport_id_t *mport_idp)
835 EFX_MCDI_DECLARE_BUF(payload,
836 MC_CMD_MAE_MPORT_LOOKUP_IN_LEN,
837 MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN);
840 req.emr_cmd = MC_CMD_MAE_MPORT_LOOKUP;
841 req.emr_in_buf = payload;
842 req.emr_in_length = MC_CMD_MAE_MPORT_LOOKUP_IN_LEN;
843 req.emr_out_buf = payload;
844 req.emr_out_length = MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN;
846 MCDI_IN_SET_DWORD(req, MAE_MPORT_LOOKUP_IN_MPORT_SELECTOR,
847 mport_selectorp->sel);
849 efx_mcdi_execute(enp, &req);
851 if (req.emr_rc != 0) {
856 mport_idp->id = MCDI_OUT_DWORD(req, MAE_MPORT_LOOKUP_OUT_MPORT_ID);
861 EFSYS_PROBE1(fail1, efx_rc_t, rc);
865 __checkReturn efx_rc_t
866 efx_mae_mport_id_by_selector(
868 __in const efx_mport_sel_t *mport_selectorp,
869 __out efx_mport_id_t *mport_idp)
871 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
874 if (encp->enc_mae_supported == B_FALSE) {
879 rc = efx_mcdi_mae_mport_lookup(enp, mport_selectorp, mport_idp);
888 EFSYS_PROBE1(fail1, efx_rc_t, rc);
892 __checkReturn efx_rc_t
893 efx_mae_match_spec_recirc_id_set(
894 __in efx_mae_match_spec_t *spec,
895 __in uint8_t recirc_id)
897 uint8_t full_mask = UINT8_MAX;
902 vp = (const uint8_t *)&recirc_id;
903 mp = (const uint8_t *)&full_mask;
905 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_RECIRC_ID,
906 sizeof (recirc_id), vp,
907 sizeof (full_mask), mp);
914 EFSYS_PROBE1(fail1, efx_rc_t, rc);
918 __checkReturn efx_rc_t
920 __in const efx_mport_id_t *mport_idp,
921 __out efx_mport_sel_t *mportp)
925 EFX_POPULATE_DWORD_2(dword,
926 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_MPORT_ID,
927 MAE_MPORT_SELECTOR_MPORT_ID, mport_idp->id);
929 memset(mportp, 0, sizeof (*mportp));
930 mportp->sel = __LE_TO_CPU_32(dword.ed_u32[0]);
935 __checkReturn efx_rc_t
936 efx_mae_match_spec_field_set(
937 __in efx_mae_match_spec_t *spec,
938 __in efx_mae_field_id_t field_id,
939 __in size_t value_size,
940 __in_bcount(value_size) const uint8_t *value,
941 __in size_t mask_size,
942 __in_bcount(mask_size) const uint8_t *mask)
944 const efx_mae_mv_desc_t *descp;
945 unsigned int desc_set_nentries;
949 switch (spec->emms_type) {
950 case EFX_MAE_RULE_OUTER:
952 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
953 descp = &__efx_mae_outer_rule_mv_desc_set[field_id];
954 mvp = spec->emms_mask_value_pairs.outer;
956 case EFX_MAE_RULE_ACTION:
958 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
959 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
960 mvp = spec->emms_mask_value_pairs.action;
967 if ((unsigned int)field_id >= desc_set_nentries) {
972 if (descp->emmd_mask_size == 0) {
973 /* The ID points to a gap in the array of field descriptors. */
978 if (value_size != descp->emmd_value_size) {
983 if (mask_size != descp->emmd_mask_size) {
988 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
992 * The mask/value are in network (big endian) order.
993 * The MCDI request field is also big endian.
996 EFSYS_ASSERT3U(value_size, ==, mask_size);
998 for (i = 0; i < value_size; ++i) {
999 uint8_t *v_bytep = mvp + descp->emmd_value_offset + i;
1000 uint8_t *m_bytep = mvp + descp->emmd_mask_offset + i;
1003 * Apply the mask (which may be all-zeros) to the value.
1005 * If this API is provided with some value to set for a
1006 * given field in one specification and with some other
1007 * value to set for this field in another specification,
1008 * then, if the two masks are all-zeros, the field will
1009 * avoid being counted as a mismatch when comparing the
1010 * specifications using efx_mae_match_specs_equal() API.
1012 *v_bytep = value[i] & mask[i];
1019 * The mask/value are in host byte order.
1020 * The MCDI request field is little endian.
1022 switch (value_size) {
1024 EFX_POPULATE_DWORD_1(dword,
1025 EFX_DWORD_0, *(const uint32_t *)value);
1027 memcpy(mvp + descp->emmd_value_offset,
1028 &dword, sizeof (dword));
1031 EFSYS_ASSERT(B_FALSE);
1034 switch (mask_size) {
1036 EFX_POPULATE_DWORD_1(dword,
1037 EFX_DWORD_0, *(const uint32_t *)mask);
1039 memcpy(mvp + descp->emmd_mask_offset,
1040 &dword, sizeof (dword));
1043 EFSYS_ASSERT(B_FALSE);
1058 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1062 __checkReturn efx_rc_t
1063 efx_mae_match_spec_bit_set(
1064 __in efx_mae_match_spec_t *spec,
1065 __in efx_mae_field_id_t field_id,
1066 __in boolean_t value)
1068 const efx_mae_mv_bit_desc_t *bit_descp;
1069 unsigned int bit_desc_set_nentries;
1070 unsigned int byte_idx;
1071 unsigned int bit_idx;
1075 switch (spec->emms_type) {
1076 case EFX_MAE_RULE_OUTER:
1077 bit_desc_set_nentries =
1078 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1079 bit_descp = &__efx_mae_outer_rule_mv_bit_desc_set[field_id];
1080 mvp = spec->emms_mask_value_pairs.outer;
1082 case EFX_MAE_RULE_ACTION:
1083 bit_desc_set_nentries =
1084 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1085 bit_descp = &__efx_mae_action_rule_mv_bit_desc_set[field_id];
1086 mvp = spec->emms_mask_value_pairs.action;
1093 if ((unsigned int)field_id >= bit_desc_set_nentries) {
1098 if (bit_descp->emmbd_entry_is_valid == B_FALSE) {
1103 byte_idx = bit_descp->emmbd_value_ofst + bit_descp->emmbd_value_lbn / 8;
1104 bit_idx = bit_descp->emmbd_value_lbn % 8;
1106 if (value != B_FALSE)
1107 mvp[byte_idx] |= (1U << bit_idx);
1109 mvp[byte_idx] &= ~(1U << bit_idx);
1111 byte_idx = bit_descp->emmbd_mask_ofst + bit_descp->emmbd_mask_lbn / 8;
1112 bit_idx = bit_descp->emmbd_mask_lbn % 8;
1113 mvp[byte_idx] |= (1U << bit_idx);
1122 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1126 __checkReturn efx_rc_t
1127 efx_mae_match_spec_mport_set(
1128 __in efx_mae_match_spec_t *spec,
1129 __in const efx_mport_sel_t *valuep,
1130 __in_opt const efx_mport_sel_t *maskp)
1132 uint32_t full_mask = UINT32_MAX;
1137 if (valuep == NULL) {
1142 vp = (const uint8_t *)&valuep->sel;
1144 mp = (const uint8_t *)&maskp->sel;
1146 mp = (const uint8_t *)&full_mask;
1148 rc = efx_mae_match_spec_field_set(spec,
1149 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
1150 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
1159 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1163 __checkReturn boolean_t
1164 efx_mae_match_specs_equal(
1165 __in const efx_mae_match_spec_t *left,
1166 __in const efx_mae_match_spec_t *right)
1168 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1171 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
1172 ((_mask)[(_bit) / (_mask_page_nbits)] & \
1173 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
1177 __in size_t mask_nbytes,
1178 __in_bcount(mask_nbytes) const uint8_t *maskp)
1180 boolean_t prev_bit_is_set = B_TRUE;
1183 for (i = 0; i < 8 * mask_nbytes; ++i) {
1184 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
1186 if (!prev_bit_is_set && bit_is_set)
1189 prev_bit_is_set = bit_is_set;
1196 efx_mask_is_all_ones(
1197 __in size_t mask_nbytes,
1198 __in_bcount(mask_nbytes) const uint8_t *maskp)
1203 for (i = 0; i < mask_nbytes; ++i)
1206 return (t == (uint8_t)(~0));
1210 efx_mask_is_all_zeros(
1211 __in size_t mask_nbytes,
1212 __in_bcount(mask_nbytes) const uint8_t *maskp)
1217 for (i = 0; i < mask_nbytes; ++i)
1223 __checkReturn boolean_t
1224 efx_mae_match_spec_is_valid(
1225 __in efx_nic_t *enp,
1226 __in const efx_mae_match_spec_t *spec)
1228 efx_mae_t *maep = enp->en_maep;
1229 unsigned int field_ncaps = maep->em_max_nfields;
1230 const efx_mae_field_cap_t *field_caps;
1231 const efx_mae_mv_desc_t *desc_setp;
1232 unsigned int desc_set_nentries;
1233 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1234 unsigned int bit_desc_set_nentries;
1235 boolean_t is_valid = B_TRUE;
1236 efx_mae_field_id_t field_id;
1239 switch (spec->emms_type) {
1240 case EFX_MAE_RULE_OUTER:
1241 field_caps = maep->em_outer_rule_field_caps;
1242 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1244 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1245 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
1246 bit_desc_set_nentries =
1247 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
1248 mvp = spec->emms_mask_value_pairs.outer;
1250 case EFX_MAE_RULE_ACTION:
1251 field_caps = maep->em_action_rule_field_caps;
1252 desc_setp = __efx_mae_action_rule_mv_desc_set;
1254 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1255 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
1256 bit_desc_set_nentries =
1257 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
1258 mvp = spec->emms_mask_value_pairs.action;
1264 if (field_caps == NULL)
1267 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1269 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1270 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1271 const uint8_t *alt_m_buf = mvp + descp->emmd_alt_mask_offset;
1272 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
1273 size_t alt_m_size = descp->emmd_alt_mask_size;
1274 size_t m_size = descp->emmd_mask_size;
1277 continue; /* Skip array gap */
1279 if ((unsigned int)field_cap_id >= field_ncaps) {
1281 * The FW has not reported capability status for
1282 * this field. Make sure that its mask is zeroed.
1284 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1285 if (is_valid != B_FALSE)
1291 switch (field_caps[field_cap_id].emfc_support) {
1292 case MAE_FIELD_SUPPORTED_MATCH_MASK:
1295 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
1296 is_valid = efx_mask_is_prefix(m_size, m_buf);
1298 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1299 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
1300 efx_mask_is_all_zeros(m_size, m_buf));
1302 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1303 is_valid = efx_mask_is_all_ones(m_size, m_buf);
1305 if ((is_valid == B_FALSE) && (alt_m_size != 0)) {
1307 * This field has an alternative one. The FW
1308 * reports ALWAYS for both implying that one
1309 * of them is required to have all-ones mask.
1311 * The primary field's mask is incorrect; go
1312 * on to check that of the alternative field.
1314 is_valid = efx_mask_is_all_ones(alt_m_size,
1318 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1319 case MAE_FIELD_UNSUPPORTED:
1321 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
1325 if (is_valid == B_FALSE)
1329 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
1331 const efx_mae_mv_bit_desc_t *bit_descp =
1332 &bit_desc_setp[field_id];
1333 unsigned int byte_idx =
1334 bit_descp->emmbd_mask_ofst +
1335 bit_descp->emmbd_mask_lbn / 8;
1336 unsigned int bit_idx =
1337 bit_descp->emmbd_mask_lbn % 8;
1338 efx_mae_field_cap_id_t bit_cap_id =
1339 bit_descp->emmbd_bit_cap_id;
1341 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
1342 continue; /* Skip array gap */
1344 if ((unsigned int)bit_cap_id >= field_ncaps) {
1345 /* No capability for this bit = unsupported. */
1346 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1347 if (is_valid == B_FALSE)
1353 switch (field_caps[bit_cap_id].emfc_support) {
1354 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
1357 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
1358 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) != 0);
1360 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
1361 case MAE_FIELD_UNSUPPORTED:
1363 is_valid = ((mvp[byte_idx] & (1U << bit_idx)) == 0);
1367 if (is_valid == B_FALSE)
1374 __checkReturn efx_rc_t
1375 efx_mae_action_set_spec_init(
1376 __in efx_nic_t *enp,
1377 __out efx_mae_actions_t **specp)
1379 efx_mae_actions_t *spec;
1382 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
1388 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1389 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1396 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1401 efx_mae_action_set_spec_fini(
1402 __in efx_nic_t *enp,
1403 __in efx_mae_actions_t *spec)
1405 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1408 static __checkReturn efx_rc_t
1409 efx_mae_action_set_add_decap(
1410 __in efx_mae_actions_t *spec,
1411 __in size_t arg_size,
1412 __in_bcount(arg_size) const uint8_t *arg)
1416 _NOTE(ARGUNUSED(spec))
1418 if (arg_size != 0) {
1428 /* This action does not have any arguments, so do nothing here. */
1435 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1439 static __checkReturn efx_rc_t
1440 efx_mae_action_set_add_vlan_pop(
1441 __in efx_mae_actions_t *spec,
1442 __in size_t arg_size,
1443 __in_bcount(arg_size) const uint8_t *arg)
1447 if (arg_size != 0) {
1457 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
1462 ++spec->ema_n_vlan_tags_to_pop;
1471 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1475 static __checkReturn efx_rc_t
1476 efx_mae_action_set_add_vlan_push(
1477 __in efx_mae_actions_t *spec,
1478 __in size_t arg_size,
1479 __in_bcount(arg_size) const uint8_t *arg)
1481 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
1484 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
1494 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1499 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
1500 ++(spec->ema_n_vlan_tags_to_push);
1509 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1513 static __checkReturn efx_rc_t
1514 efx_mae_action_set_add_encap(
1515 __in efx_mae_actions_t *spec,
1516 __in size_t arg_size,
1517 __in_bcount(arg_size) const uint8_t *arg)
1522 * Adding this specific action to an action set spec and setting encap.
1523 * header ID in the spec are two individual steps. This design allows
1524 * the client driver to avoid encap. header allocation when it simply
1525 * needs to check the order of actions submitted by user ("validate"),
1526 * without actually allocating an action set and inserting a rule.
1528 * For now, mark encap. header ID as invalid; the caller will invoke
1529 * efx_mae_action_set_fill_in_eh_id() to override the field prior
1530 * to action set allocation; otherwise, the allocation will fail.
1532 spec->ema_rsrc.emar_eh_id.id = EFX_MAE_RSRC_ID_INVALID;
1535 * As explained above, there are no arguments to handle here.
1536 * efx_mae_action_set_fill_in_eh_id() will take care of them.
1538 if (arg_size != 0) {
1553 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1557 static __checkReturn efx_rc_t
1558 efx_mae_action_set_add_count(
1559 __in efx_mae_actions_t *spec,
1560 __in size_t arg_size,
1561 __in_bcount(arg_size) const uint8_t *arg)
1565 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1566 MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL);
1569 * Preparing an action set spec to update a counter requires
1570 * two steps: first add this action to the action spec, and then
1571 * add the counter ID to the spec. This allows validity checking
1572 * and resource allocation to be done separately.
1573 * Mark the counter ID as invalid in the spec to ensure that the
1574 * caller must also invoke efx_mae_action_set_fill_in_counter_id()
1575 * before action set allocation.
1577 spec->ema_rsrc.emar_counter_id.id = EFX_MAE_RSRC_ID_INVALID;
1579 /* Nothing else is supposed to take place over here. */
1580 if (arg_size != 0) {
1590 ++(spec->ema_n_count_actions);
1597 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1601 static __checkReturn efx_rc_t
1602 efx_mae_action_set_add_flag(
1603 __in efx_mae_actions_t *spec,
1604 __in size_t arg_size,
1605 __in_bcount(arg_size) const uint8_t *arg)
1609 _NOTE(ARGUNUSED(spec))
1611 if (arg_size != 0) {
1621 /* This action does not have any arguments, so do nothing here. */
1628 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1632 static __checkReturn efx_rc_t
1633 efx_mae_action_set_add_mark(
1634 __in efx_mae_actions_t *spec,
1635 __in size_t arg_size,
1636 __in_bcount(arg_size) const uint8_t *arg)
1640 if (arg_size != sizeof (spec->ema_mark_value)) {
1650 memcpy(&spec->ema_mark_value, arg, arg_size);
1657 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1661 static __checkReturn efx_rc_t
1662 efx_mae_action_set_add_deliver(
1663 __in efx_mae_actions_t *spec,
1664 __in size_t arg_size,
1665 __in_bcount(arg_size) const uint8_t *arg)
1669 if (arg_size != sizeof (spec->ema_deliver_mport)) {
1679 memcpy(&spec->ema_deliver_mport, arg, arg_size);
1686 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1690 typedef struct efx_mae_action_desc_s {
1691 /* Action specific handler */
1692 efx_rc_t (*emad_add)(efx_mae_actions_t *,
1693 size_t, const uint8_t *);
1694 } efx_mae_action_desc_t;
1696 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
1697 [EFX_MAE_ACTION_DECAP] = {
1698 .emad_add = efx_mae_action_set_add_decap
1700 [EFX_MAE_ACTION_VLAN_POP] = {
1701 .emad_add = efx_mae_action_set_add_vlan_pop
1703 [EFX_MAE_ACTION_VLAN_PUSH] = {
1704 .emad_add = efx_mae_action_set_add_vlan_push
1706 [EFX_MAE_ACTION_ENCAP] = {
1707 .emad_add = efx_mae_action_set_add_encap
1709 [EFX_MAE_ACTION_COUNT] = {
1710 .emad_add = efx_mae_action_set_add_count
1712 [EFX_MAE_ACTION_FLAG] = {
1713 .emad_add = efx_mae_action_set_add_flag
1715 [EFX_MAE_ACTION_MARK] = {
1716 .emad_add = efx_mae_action_set_add_mark
1718 [EFX_MAE_ACTION_DELIVER] = {
1719 .emad_add = efx_mae_action_set_add_deliver
1723 static const uint32_t efx_mae_action_ordered_map =
1724 (1U << EFX_MAE_ACTION_DECAP) |
1725 (1U << EFX_MAE_ACTION_VLAN_POP) |
1726 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1728 * HW will conduct action COUNT after
1729 * the matching packet has been modified by
1730 * length-affecting actions except for ENCAP.
1732 (1U << EFX_MAE_ACTION_COUNT) |
1733 (1U << EFX_MAE_ACTION_ENCAP) |
1734 (1U << EFX_MAE_ACTION_FLAG) |
1735 (1U << EFX_MAE_ACTION_MARK) |
1736 (1U << EFX_MAE_ACTION_DELIVER);
1739 * These actions must not be added after DELIVER, but
1740 * they can have any place among the rest of
1741 * strictly ordered actions.
1743 static const uint32_t efx_mae_action_nonstrict_map =
1744 (1U << EFX_MAE_ACTION_COUNT) |
1745 (1U << EFX_MAE_ACTION_FLAG) |
1746 (1U << EFX_MAE_ACTION_MARK);
1748 static const uint32_t efx_mae_action_repeat_map =
1749 (1U << EFX_MAE_ACTION_VLAN_POP) |
1750 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1751 (1U << EFX_MAE_ACTION_COUNT);
1754 * Add an action to an action set.
1756 * This has to be invoked in the desired action order.
1757 * An out-of-order action request will be turned down.
1759 static __checkReturn efx_rc_t
1760 efx_mae_action_set_spec_populate(
1761 __in efx_mae_actions_t *spec,
1762 __in efx_mae_action_t type,
1763 __in size_t arg_size,
1764 __in_bcount(arg_size) const uint8_t *arg)
1766 uint32_t action_mask;
1769 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1770 (sizeof (efx_mae_action_ordered_map) * 8));
1771 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1772 (sizeof (efx_mae_action_repeat_map) * 8));
1774 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
1775 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
1776 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
1778 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
1783 action_mask = (1U << type);
1785 if ((spec->ema_actions & action_mask) != 0) {
1786 /* The action set already contains this action. */
1787 if ((efx_mae_action_repeat_map & action_mask) == 0) {
1788 /* Cannot add another non-repeatable action. */
1794 if ((efx_mae_action_ordered_map & action_mask) != 0) {
1795 uint32_t strict_ordered_map =
1796 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
1797 uint32_t later_actions_mask =
1798 strict_ordered_map & ~(action_mask | (action_mask - 1));
1800 if ((spec->ema_actions & later_actions_mask) != 0) {
1801 /* Cannot add an action after later ordered actions. */
1807 if (efx_mae_actions[type].emad_add != NULL) {
1808 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
1813 spec->ema_actions |= action_mask;
1824 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1828 __checkReturn efx_rc_t
1829 efx_mae_action_set_populate_decap(
1830 __in efx_mae_actions_t *spec)
1832 return (efx_mae_action_set_spec_populate(spec,
1833 EFX_MAE_ACTION_DECAP, 0, NULL));
1836 __checkReturn efx_rc_t
1837 efx_mae_action_set_populate_vlan_pop(
1838 __in efx_mae_actions_t *spec)
1840 return (efx_mae_action_set_spec_populate(spec,
1841 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1844 __checkReturn efx_rc_t
1845 efx_mae_action_set_populate_vlan_push(
1846 __in efx_mae_actions_t *spec,
1847 __in uint16_t tpid_be,
1848 __in uint16_t tci_be)
1850 efx_mae_action_vlan_push_t action;
1851 const uint8_t *arg = (const uint8_t *)&action;
1853 action.emavp_tpid_be = tpid_be;
1854 action.emavp_tci_be = tci_be;
1856 return (efx_mae_action_set_spec_populate(spec,
1857 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1860 __checkReturn efx_rc_t
1861 efx_mae_action_set_populate_encap(
1862 __in efx_mae_actions_t *spec)
1865 * There is no argument to pass encap. header ID, thus, one does not
1866 * need to allocate an encap. header while parsing application input.
1867 * This is useful since building an action set may be done simply to
1868 * validate a rule, whilst resource allocation usually consumes time.
1870 return (efx_mae_action_set_spec_populate(spec,
1871 EFX_MAE_ACTION_ENCAP, 0, NULL));
1874 __checkReturn efx_rc_t
1875 efx_mae_action_set_populate_count(
1876 __in efx_mae_actions_t *spec)
1879 * There is no argument to pass counter ID, thus, one does not
1880 * need to allocate a counter while parsing application input.
1881 * This is useful since building an action set may be done simply to
1882 * validate a rule, whilst resource allocation usually consumes time.
1884 return (efx_mae_action_set_spec_populate(spec,
1885 EFX_MAE_ACTION_COUNT, 0, NULL));
1888 __checkReturn efx_rc_t
1889 efx_mae_action_set_populate_flag(
1890 __in efx_mae_actions_t *spec)
1892 return (efx_mae_action_set_spec_populate(spec,
1893 EFX_MAE_ACTION_FLAG, 0, NULL));
1896 __checkReturn efx_rc_t
1897 efx_mae_action_set_populate_mark(
1898 __in efx_mae_actions_t *spec,
1899 __in uint32_t mark_value)
1901 const uint8_t *arg = (const uint8_t *)&mark_value;
1903 return (efx_mae_action_set_spec_populate(spec,
1904 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1907 __checkReturn efx_rc_t
1908 efx_mae_action_set_populate_deliver(
1909 __in efx_mae_actions_t *spec,
1910 __in const efx_mport_sel_t *mportp)
1915 if (mportp == NULL) {
1920 arg = (const uint8_t *)&mportp->sel;
1922 return (efx_mae_action_set_spec_populate(spec,
1923 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1926 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1930 __checkReturn efx_rc_t
1931 efx_mae_action_set_populate_drop(
1932 __in efx_mae_actions_t *spec)
1934 efx_mport_sel_t mport;
1938 EFX_POPULATE_DWORD_1(dword,
1939 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1942 * The constructed DWORD is little-endian,
1943 * but the resulting value is meant to be
1944 * passed to MCDIs, where it will undergo
1945 * host-order to little endian conversion.
1947 mport.sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
1949 arg = (const uint8_t *)&mport.sel;
1951 return (efx_mae_action_set_spec_populate(spec,
1952 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1955 __checkReturn boolean_t
1956 efx_mae_action_set_specs_equal(
1957 __in const efx_mae_actions_t *left,
1958 __in const efx_mae_actions_t *right)
1960 size_t cmp_size = EFX_FIELD_OFFSET(efx_mae_actions_t, ema_rsrc);
1963 * An action set specification consists of two parts. The first part
1964 * indicates what actions are included in the action set, as well as
1965 * extra quantitative values (in example, the number of VLAN tags to
1966 * push). The second part comprises resource IDs used by the actions.
1968 * A resource, in example, a counter, is allocated from the hardware
1969 * by the client, and it's the client who is responsible for keeping
1970 * track of allocated resources and comparing resource IDs if needed.
1972 * In this API, don't compare resource IDs in the two specifications.
1975 return ((memcmp(left, right, cmp_size) == 0) ? B_TRUE : B_FALSE);
1978 __checkReturn efx_rc_t
1979 efx_mae_match_specs_class_cmp(
1980 __in efx_nic_t *enp,
1981 __in const efx_mae_match_spec_t *left,
1982 __in const efx_mae_match_spec_t *right,
1983 __out boolean_t *have_same_classp)
1985 efx_mae_t *maep = enp->en_maep;
1986 unsigned int field_ncaps = maep->em_max_nfields;
1987 const efx_mae_field_cap_t *field_caps;
1988 const efx_mae_mv_desc_t *desc_setp;
1989 unsigned int desc_set_nentries;
1990 const efx_mae_mv_bit_desc_t *bit_desc_setp;
1991 unsigned int bit_desc_set_nentries;
1992 boolean_t have_same_class = B_TRUE;
1993 efx_mae_field_id_t field_id;
1994 const uint8_t *mvpl;
1995 const uint8_t *mvpr;
1998 switch (left->emms_type) {
1999 case EFX_MAE_RULE_OUTER:
2000 field_caps = maep->em_outer_rule_field_caps;
2001 desc_setp = __efx_mae_outer_rule_mv_desc_set;
2003 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
2004 bit_desc_setp = __efx_mae_outer_rule_mv_bit_desc_set;
2005 bit_desc_set_nentries =
2006 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_bit_desc_set);
2007 mvpl = left->emms_mask_value_pairs.outer;
2008 mvpr = right->emms_mask_value_pairs.outer;
2010 case EFX_MAE_RULE_ACTION:
2011 field_caps = maep->em_action_rule_field_caps;
2012 desc_setp = __efx_mae_action_rule_mv_desc_set;
2014 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
2015 bit_desc_setp = __efx_mae_action_rule_mv_bit_desc_set;
2016 bit_desc_set_nentries =
2017 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_bit_desc_set);
2018 mvpl = left->emms_mask_value_pairs.action;
2019 mvpr = right->emms_mask_value_pairs.action;
2026 if (field_caps == NULL) {
2031 if (left->emms_type != right->emms_type ||
2032 left->emms_prio != right->emms_prio) {
2034 * Rules of different types can never map to the same class.
2036 * The FW can support some set of match criteria for one
2037 * priority and not support the very same set for
2038 * another priority. Thus, two rules which have
2039 * different priorities can never map to
2042 *have_same_classp = B_FALSE;
2046 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
2048 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
2049 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
2050 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
2051 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
2052 size_t mask_size = descp->emmd_mask_size;
2053 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
2054 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
2055 size_t value_size = descp->emmd_value_size;
2058 continue; /* Skip array gap */
2060 if ((unsigned int)field_cap_id >= field_ncaps) {
2062 * The FW has not reported capability status for this
2063 * field. It's unknown whether any difference between
2064 * the two masks / values affects the class. The only
2065 * case when the class must be the same is when these
2066 * mask-value pairs match. Otherwise, report mismatch.
2068 if ((memcmp(lmaskp, rmaskp, mask_size) == 0) &&
2069 (memcmp(lvalp, rvalp, value_size) == 0))
2075 if (field_caps[field_cap_id].emfc_mask_affects_class) {
2076 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
2077 have_same_class = B_FALSE;
2082 if (field_caps[field_cap_id].emfc_match_affects_class) {
2083 if (memcmp(lvalp, rvalp, value_size) != 0) {
2084 have_same_class = B_FALSE;
2090 if (have_same_class == B_FALSE)
2093 for (field_id = 0; (unsigned int)field_id < bit_desc_set_nentries;
2095 const efx_mae_mv_bit_desc_t *bit_descp =
2096 &bit_desc_setp[field_id];
2097 efx_mae_field_cap_id_t bit_cap_id =
2098 bit_descp->emmbd_bit_cap_id;
2099 unsigned int byte_idx;
2100 unsigned int bit_idx;
2102 if (bit_descp->emmbd_entry_is_valid == B_FALSE)
2103 continue; /* Skip array gap */
2105 if ((unsigned int)bit_cap_id >= field_ncaps)
2109 bit_descp->emmbd_mask_ofst +
2110 bit_descp->emmbd_mask_lbn / 8;
2112 bit_descp->emmbd_mask_lbn % 8;
2114 if (field_caps[bit_cap_id].emfc_mask_affects_class &&
2115 (mvpl[byte_idx] & (1U << bit_idx)) !=
2116 (mvpr[byte_idx] & (1U << bit_idx))) {
2117 have_same_class = B_FALSE;
2122 bit_descp->emmbd_value_ofst +
2123 bit_descp->emmbd_value_lbn / 8;
2125 bit_descp->emmbd_value_lbn % 8;
2127 if (field_caps[bit_cap_id].emfc_match_affects_class &&
2128 (mvpl[byte_idx] & (1U << bit_idx)) !=
2129 (mvpr[byte_idx] & (1U << bit_idx))) {
2130 have_same_class = B_FALSE;
2136 *have_same_classp = have_same_class;
2143 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2147 __checkReturn efx_rc_t
2148 efx_mae_outer_rule_recirc_id_set(
2149 __in efx_mae_match_spec_t *spec,
2150 __in uint8_t recirc_id)
2154 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
2159 spec->emms_outer_rule_recirc_id = recirc_id;
2164 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2168 __checkReturn efx_rc_t
2169 efx_mae_outer_rule_insert(
2170 __in efx_nic_t *enp,
2171 __in const efx_mae_match_spec_t *spec,
2172 __in efx_tunnel_protocol_t encap_type,
2173 __out efx_mae_rule_id_t *or_idp)
2175 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2177 EFX_MCDI_DECLARE_BUF(payload,
2178 MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2,
2179 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
2180 uint32_t encap_type_mcdi;
2181 efx_mae_rule_id_t or_id;
2185 EFX_STATIC_ASSERT(sizeof (or_idp->id) ==
2186 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OR_ID_LEN);
2188 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2189 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL);
2191 if (encp->enc_mae_supported == B_FALSE) {
2196 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
2201 switch (encap_type) {
2202 case EFX_TUNNEL_PROTOCOL_NONE:
2203 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2205 case EFX_TUNNEL_PROTOCOL_VXLAN:
2206 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2208 case EFX_TUNNEL_PROTOCOL_GENEVE:
2209 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2211 case EFX_TUNNEL_PROTOCOL_NVGRE:
2212 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2219 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_INSERT;
2220 req.emr_in_buf = payload;
2221 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2;
2222 req.emr_out_buf = payload;
2223 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN;
2225 MCDI_IN_SET_DWORD(req,
2226 MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, encap_type_mcdi);
2228 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_INSERT_IN_PRIO, spec->emms_prio);
2231 * Mask-value pairs have been stored in the byte order needed for the
2232 * MCDI request and are thus safe to be copied directly to the buffer.
2233 * The library cares about byte order in efx_mae_match_spec_field_set().
2235 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.outer) >=
2236 MAE_ENC_FIELD_PAIRS_LEN);
2237 offset = MC_CMD_MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA_OFST;
2238 memcpy(payload + offset, spec->emms_mask_value_pairs.outer,
2239 MAE_ENC_FIELD_PAIRS_LEN);
2241 MCDI_IN_SET_BYTE(req, MAE_OUTER_RULE_INSERT_IN_RECIRC_ID,
2242 spec->emms_outer_rule_recirc_id);
2244 efx_mcdi_execute(enp, &req);
2246 if (req.emr_rc != 0) {
2251 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN) {
2256 or_id.id = MCDI_OUT_DWORD(req, MAE_OUTER_RULE_INSERT_OUT_OR_ID);
2257 if (or_id.id == EFX_MAE_RSRC_ID_INVALID) {
2262 or_idp->id = or_id.id;
2277 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2281 __checkReturn efx_rc_t
2282 efx_mae_outer_rule_remove(
2283 __in efx_nic_t *enp,
2284 __in const efx_mae_rule_id_t *or_idp)
2286 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2288 EFX_MCDI_DECLARE_BUF(payload,
2289 MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1),
2290 MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
2293 if (encp->enc_mae_supported == B_FALSE) {
2298 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_REMOVE;
2299 req.emr_in_buf = payload;
2300 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1);
2301 req.emr_out_buf = payload;
2302 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1);
2304 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_REMOVE_IN_OR_ID, or_idp->id);
2306 efx_mcdi_execute(enp, &req);
2308 if (req.emr_rc != 0) {
2313 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LENMIN) {
2318 if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
2320 /* Firmware failed to remove the outer rule. */
2334 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2338 __checkReturn efx_rc_t
2339 efx_mae_match_spec_outer_rule_id_set(
2340 __in efx_mae_match_spec_t *spec,
2341 __in const efx_mae_rule_id_t *or_idp)
2343 uint32_t full_mask = UINT32_MAX;
2346 if (spec->emms_type != EFX_MAE_RULE_ACTION) {
2351 if (or_idp == NULL) {
2356 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_OUTER_RULE_ID,
2357 sizeof (or_idp->id), (const uint8_t *)&or_idp->id,
2358 sizeof (full_mask), (const uint8_t *)&full_mask);
2369 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2373 __checkReturn efx_rc_t
2374 efx_mae_encap_header_alloc(
2375 __in efx_nic_t *enp,
2376 __in efx_tunnel_protocol_t encap_type,
2377 __in_bcount(header_size) uint8_t *header_data,
2378 __in size_t header_size,
2379 __out efx_mae_eh_id_t *eh_idp)
2381 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2383 EFX_MCDI_DECLARE_BUF(payload,
2384 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LENMAX_MCDI2,
2385 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
2386 uint32_t encap_type_mcdi;
2387 efx_mae_eh_id_t eh_id;
2390 EFX_STATIC_ASSERT(sizeof (eh_idp->id) ==
2391 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_LEN);
2393 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2394 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL);
2396 if (encp->enc_mae_supported == B_FALSE) {
2401 switch (encap_type) {
2402 case EFX_TUNNEL_PROTOCOL_NONE:
2403 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
2405 case EFX_TUNNEL_PROTOCOL_VXLAN:
2406 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
2408 case EFX_TUNNEL_PROTOCOL_GENEVE:
2409 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
2411 case EFX_TUNNEL_PROTOCOL_NVGRE:
2412 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
2420 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2) {
2425 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_ALLOC;
2426 req.emr_in_buf = payload;
2427 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(header_size);
2428 req.emr_out_buf = payload;
2429 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN;
2431 MCDI_IN_SET_DWORD(req,
2432 MAE_ENCAP_HEADER_ALLOC_IN_ENCAP_TYPE, encap_type_mcdi);
2434 memcpy(payload + MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_OFST,
2435 header_data, header_size);
2437 efx_mcdi_execute(enp, &req);
2439 if (req.emr_rc != 0) {
2444 if (req.emr_out_length_used < MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN) {
2449 eh_id.id = MCDI_OUT_DWORD(req,
2450 MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID);
2452 if (eh_id.id == EFX_MAE_RSRC_ID_INVALID) {
2457 eh_idp->id = eh_id.id;
2472 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2476 __checkReturn efx_rc_t
2477 efx_mae_encap_header_free(
2478 __in efx_nic_t *enp,
2479 __in const efx_mae_eh_id_t *eh_idp)
2481 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2483 EFX_MCDI_DECLARE_BUF(payload,
2484 MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1),
2485 MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
2488 if (encp->enc_mae_supported == B_FALSE) {
2493 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_FREE;
2494 req.emr_in_buf = payload;
2495 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1);
2496 req.emr_out_buf = payload;
2497 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1);
2499 MCDI_IN_SET_DWORD(req, MAE_ENCAP_HEADER_FREE_IN_EH_ID, eh_idp->id);
2501 efx_mcdi_execute(enp, &req);
2503 if (req.emr_rc != 0) {
2508 if (MCDI_OUT_DWORD(req, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) !=
2510 /* Firmware failed to remove the encap. header. */
2522 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2526 __checkReturn efx_rc_t
2527 efx_mae_action_set_fill_in_eh_id(
2528 __in efx_mae_actions_t *spec,
2529 __in const efx_mae_eh_id_t *eh_idp)
2533 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_ENCAP)) == 0) {
2535 * The caller has not intended to have action ENCAP originally,
2536 * hence, this attempt to indicate encap. header ID is invalid.
2542 if (spec->ema_rsrc.emar_eh_id.id != EFX_MAE_RSRC_ID_INVALID) {
2543 /* The caller attempts to indicate encap. header ID twice. */
2548 if (eh_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2553 spec->ema_rsrc.emar_eh_id.id = eh_idp->id;
2562 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2566 __checkReturn efx_rc_t
2567 efx_mae_action_set_alloc(
2568 __in efx_nic_t *enp,
2569 __in const efx_mae_actions_t *spec,
2570 __out efx_mae_aset_id_t *aset_idp)
2572 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2574 EFX_MCDI_DECLARE_BUF(payload,
2575 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
2576 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
2577 efx_mae_aset_id_t aset_id;
2580 if (encp->enc_mae_supported == B_FALSE) {
2585 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
2586 req.emr_in_buf = payload;
2587 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
2588 req.emr_out_buf = payload;
2589 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
2592 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
2593 * corresponding resource types are supported by the implementation.
2594 * Use proper resource ID assignments instead.
2596 MCDI_IN_SET_DWORD(req,
2597 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
2599 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_DECAP)) != 0) {
2600 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2601 MAE_ACTION_SET_ALLOC_IN_DECAP, 1);
2604 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2605 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
2607 if (spec->ema_n_vlan_tags_to_push > 0) {
2608 unsigned int outer_tag_idx;
2610 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2611 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
2612 spec->ema_n_vlan_tags_to_push);
2614 if (spec->ema_n_vlan_tags_to_push ==
2615 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
2616 MCDI_IN_SET_WORD(req,
2617 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
2618 spec->ema_vlan_push_descs[0].emavp_tpid_be);
2619 MCDI_IN_SET_WORD(req,
2620 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
2621 spec->ema_vlan_push_descs[0].emavp_tci_be);
2624 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
2626 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
2627 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
2628 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
2629 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
2632 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
2633 spec->ema_rsrc.emar_eh_id.id);
2634 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID,
2635 spec->ema_rsrc.emar_counter_id.id);
2637 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
2638 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2639 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
2642 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
2643 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
2644 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
2646 MCDI_IN_SET_DWORD(req,
2647 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
2650 MCDI_IN_SET_DWORD(req,
2651 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
2653 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
2654 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2655 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
2656 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
2658 efx_mcdi_execute(enp, &req);
2660 if (req.emr_rc != 0) {
2665 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
2670 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
2671 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
2676 aset_idp->id = aset_id.id;
2687 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2691 __checkReturn unsigned int
2692 efx_mae_action_set_get_nb_count(
2693 __in const efx_mae_actions_t *spec)
2695 return (spec->ema_n_count_actions);
2698 __checkReturn efx_rc_t
2699 efx_mae_action_set_fill_in_counter_id(
2700 __in efx_mae_actions_t *spec,
2701 __in const efx_counter_t *counter_idp)
2705 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_COUNT)) == 0) {
2707 * Invalid to add counter ID if spec does not have COUNT action.
2713 if (spec->ema_n_count_actions != 1) {
2715 * Having multiple COUNT actions in the spec requires a counter
2716 * list to be used. This API must only be used for a single
2717 * counter per spec. Turn down the request as inappropriate.
2723 if (spec->ema_rsrc.emar_counter_id.id != EFX_MAE_RSRC_ID_INVALID) {
2724 /* The caller attempts to indicate counter ID twice. */
2729 if (counter_idp->id == EFX_MAE_RSRC_ID_INVALID) {
2734 spec->ema_rsrc.emar_counter_id.id = counter_idp->id;
2745 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2749 __checkReturn efx_rc_t
2750 efx_mae_counters_alloc(
2751 __in efx_nic_t *enp,
2752 __in uint32_t n_counters,
2753 __out uint32_t *n_allocatedp,
2754 __out_ecount(n_counters) efx_counter_t *countersp,
2755 __out_opt uint32_t *gen_countp)
2757 EFX_MCDI_DECLARE_BUF(payload,
2758 MC_CMD_MAE_COUNTER_ALLOC_IN_LEN,
2759 MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMAX_MCDI2);
2760 efx_mae_t *maep = enp->en_maep;
2761 uint32_t n_allocated;
2766 if (n_counters > maep->em_max_ncounters ||
2767 n_counters < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM ||
2768 n_counters > MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MAXNUM_MCDI2) {
2773 req.emr_cmd = MC_CMD_MAE_COUNTER_ALLOC;
2774 req.emr_in_buf = payload;
2775 req.emr_in_length = MC_CMD_MAE_COUNTER_ALLOC_IN_LEN;
2776 req.emr_out_buf = payload;
2777 req.emr_out_length = MC_CMD_MAE_COUNTER_ALLOC_OUT_LEN(n_counters);
2779 MCDI_IN_SET_DWORD(req, MAE_COUNTER_ALLOC_IN_REQUESTED_COUNT,
2782 efx_mcdi_execute(enp, &req);
2784 if (req.emr_rc != 0) {
2789 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_ALLOC_OUT_LENMIN) {
2794 n_allocated = MCDI_OUT_DWORD(req,
2795 MAE_COUNTER_ALLOC_OUT_COUNTER_ID_COUNT);
2796 if (n_allocated < MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_MINNUM) {
2801 for (i = 0; i < n_allocated; i++) {
2802 countersp[i].id = MCDI_OUT_INDEXED_DWORD(req,
2803 MAE_COUNTER_ALLOC_OUT_COUNTER_ID, i);
2806 if (gen_countp != NULL) {
2807 *gen_countp = MCDI_OUT_DWORD(req,
2808 MAE_COUNTER_ALLOC_OUT_GENERATION_COUNT);
2811 *n_allocatedp = n_allocated;
2822 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2827 __checkReturn efx_rc_t
2828 efx_mae_counters_free(
2829 __in efx_nic_t *enp,
2830 __in uint32_t n_counters,
2831 __out uint32_t *n_freedp,
2832 __in_ecount(n_counters) const efx_counter_t *countersp,
2833 __out_opt uint32_t *gen_countp)
2835 EFX_MCDI_DECLARE_BUF(payload,
2836 MC_CMD_MAE_COUNTER_FREE_IN_LENMAX_MCDI2,
2837 MC_CMD_MAE_COUNTER_FREE_OUT_LENMAX_MCDI2);
2838 efx_mae_t *maep = enp->en_maep;
2844 if (n_counters > maep->em_max_ncounters ||
2845 n_counters < MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MINNUM ||
2847 MC_CMD_MAE_COUNTER_FREE_IN_FREE_COUNTER_ID_MAXNUM_MCDI2) {
2852 req.emr_cmd = MC_CMD_MAE_COUNTER_FREE;
2853 req.emr_in_buf = payload;
2854 req.emr_in_length = MC_CMD_MAE_COUNTER_FREE_IN_LEN(n_counters);
2855 req.emr_out_buf = payload;
2856 req.emr_out_length = MC_CMD_MAE_COUNTER_FREE_OUT_LEN(n_counters);
2858 for (i = 0; i < n_counters; i++) {
2859 MCDI_IN_SET_INDEXED_DWORD(req,
2860 MAE_COUNTER_FREE_IN_FREE_COUNTER_ID, i, countersp[i].id);
2862 MCDI_IN_SET_DWORD(req, MAE_COUNTER_FREE_IN_COUNTER_ID_COUNT,
2865 efx_mcdi_execute(enp, &req);
2867 if (req.emr_rc != 0) {
2872 if (req.emr_out_length_used < MC_CMD_MAE_COUNTER_FREE_OUT_LENMIN) {
2877 n_freed = MCDI_OUT_DWORD(req, MAE_COUNTER_FREE_OUT_COUNTER_ID_COUNT);
2879 if (n_freed < MC_CMD_MAE_COUNTER_FREE_OUT_FREED_COUNTER_ID_MINNUM) {
2884 if (gen_countp != NULL) {
2885 *gen_countp = MCDI_OUT_DWORD(req,
2886 MAE_COUNTER_FREE_OUT_GENERATION_COUNT);
2889 *n_freedp = n_freed;
2900 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2905 __checkReturn efx_rc_t
2906 efx_mae_counters_stream_start(
2907 __in efx_nic_t *enp,
2908 __in uint16_t rxq_id,
2909 __in uint16_t packet_size,
2910 __in uint32_t flags_in,
2911 __out uint32_t *flags_out)
2914 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN,
2915 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN);
2918 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_IN_ZERO_SQUASH_DISABLE ==
2919 1U << MC_CMD_MAE_COUNTERS_STREAM_START_IN_ZERO_SQUASH_DISABLE_LBN);
2921 EFX_STATIC_ASSERT(EFX_MAE_COUNTERS_STREAM_OUT_USES_CREDITS ==
2922 1U << MC_CMD_MAE_COUNTERS_STREAM_START_OUT_USES_CREDITS_LBN);
2924 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_START;
2925 req.emr_in_buf = payload;
2926 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_START_IN_LEN;
2927 req.emr_out_buf = payload;
2928 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN;
2930 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_QID, rxq_id);
2931 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_START_IN_PACKET_SIZE,
2933 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_START_IN_FLAGS, flags_in);
2935 efx_mcdi_execute(enp, &req);
2937 if (req.emr_rc != 0) {
2942 if (req.emr_out_length_used <
2943 MC_CMD_MAE_COUNTERS_STREAM_START_OUT_LEN) {
2948 *flags_out = MCDI_OUT_DWORD(req, MAE_COUNTERS_STREAM_START_OUT_FLAGS);
2955 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2960 __checkReturn efx_rc_t
2961 efx_mae_counters_stream_stop(
2962 __in efx_nic_t *enp,
2963 __in uint16_t rxq_id,
2964 __out_opt uint32_t *gen_countp)
2967 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN,
2968 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN);
2971 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_STOP;
2972 req.emr_in_buf = payload;
2973 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_IN_LEN;
2974 req.emr_out_buf = payload;
2975 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN;
2977 MCDI_IN_SET_WORD(req, MAE_COUNTERS_STREAM_STOP_IN_QID, rxq_id);
2979 efx_mcdi_execute(enp, &req);
2981 if (req.emr_rc != 0) {
2986 if (req.emr_out_length_used <
2987 MC_CMD_MAE_COUNTERS_STREAM_STOP_OUT_LEN) {
2992 if (gen_countp != NULL) {
2993 *gen_countp = MCDI_OUT_DWORD(req,
2994 MAE_COUNTERS_STREAM_STOP_OUT_GENERATION_COUNT);
3002 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3007 __checkReturn efx_rc_t
3008 efx_mae_counters_stream_give_credits(
3009 __in efx_nic_t *enp,
3010 __in uint32_t n_credits)
3013 EFX_MCDI_DECLARE_BUF(payload,
3014 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN,
3015 MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN);
3018 req.emr_cmd = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS;
3019 req.emr_in_buf = payload;
3020 req.emr_in_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_LEN;
3021 req.emr_out_buf = payload;
3022 req.emr_out_length = MC_CMD_MAE_COUNTERS_STREAM_GIVE_CREDITS_OUT_LEN;
3024 MCDI_IN_SET_DWORD(req, MAE_COUNTERS_STREAM_GIVE_CREDITS_IN_NUM_CREDITS,
3027 efx_mcdi_execute(enp, &req);
3029 if (req.emr_rc != 0) {
3037 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3042 __checkReturn efx_rc_t
3043 efx_mae_action_set_free(
3044 __in efx_nic_t *enp,
3045 __in const efx_mae_aset_id_t *aset_idp)
3047 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3049 EFX_MCDI_DECLARE_BUF(payload,
3050 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
3051 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
3054 if (encp->enc_mae_supported == B_FALSE) {
3059 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
3060 req.emr_in_buf = payload;
3061 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
3062 req.emr_out_buf = payload;
3063 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
3065 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
3067 efx_mcdi_execute(enp, &req);
3069 if (req.emr_rc != 0) {
3074 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_FREE_OUT_LENMIN) {
3079 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
3081 /* Firmware failed to free the action set. */
3095 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3099 __checkReturn efx_rc_t
3100 efx_mae_action_rule_insert(
3101 __in efx_nic_t *enp,
3102 __in const efx_mae_match_spec_t *spec,
3103 __in const efx_mae_aset_list_id_t *asl_idp,
3104 __in const efx_mae_aset_id_t *as_idp,
3105 __out efx_mae_rule_id_t *ar_idp)
3107 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3109 EFX_MCDI_DECLARE_BUF(payload,
3110 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
3111 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
3112 efx_oword_t *rule_response;
3113 efx_mae_rule_id_t ar_id;
3117 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
3118 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
3120 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
3121 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
3123 if (encp->enc_mae_supported == B_FALSE) {
3128 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
3129 (asl_idp != NULL && as_idp != NULL) ||
3130 (asl_idp == NULL && as_idp == NULL)) {
3135 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
3136 req.emr_in_buf = payload;
3137 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
3138 req.emr_out_buf = payload;
3139 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
3141 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
3142 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
3143 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
3144 rule_response = (efx_oword_t *)(payload + offset);
3145 EFX_POPULATE_OWORD_3(*rule_response,
3146 MAE_ACTION_RULE_RESPONSE_ASL_ID,
3147 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
3148 MAE_ACTION_RULE_RESPONSE_AS_ID,
3149 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
3150 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
3152 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
3155 * Mask-value pairs have been stored in the byte order needed for the
3156 * MCDI request and are thus safe to be copied directly to the buffer.
3158 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
3159 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3160 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
3161 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
3162 MAE_FIELD_MASK_VALUE_PAIRS_V2_LEN);
3164 efx_mcdi_execute(enp, &req);
3166 if (req.emr_rc != 0) {
3171 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
3176 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
3177 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
3182 ar_idp->id = ar_id.id;
3195 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3199 __checkReturn efx_rc_t
3200 efx_mae_action_rule_remove(
3201 __in efx_nic_t *enp,
3202 __in const efx_mae_rule_id_t *ar_idp)
3204 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3206 EFX_MCDI_DECLARE_BUF(payload,
3207 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
3208 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
3211 if (encp->enc_mae_supported == B_FALSE) {
3216 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
3217 req.emr_in_buf = payload;
3218 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
3219 req.emr_out_buf = payload;
3220 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
3222 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
3224 efx_mcdi_execute(enp, &req);
3226 if (req.emr_rc != 0) {
3231 if (req.emr_out_length_used <
3232 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LENMIN) {
3237 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
3239 /* Firmware failed to delete the action rule. */
3253 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3257 __checkReturn efx_rc_t
3258 efx_mcdi_mport_alloc_alias(
3259 __in efx_nic_t *enp,
3260 __out efx_mport_id_t *mportp,
3261 __out_opt uint32_t *labelp)
3263 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3265 EFX_MCDI_DECLARE_BUF(payload,
3266 MC_CMD_MAE_MPORT_ALLOC_ALIAS_IN_LEN,
3267 MC_CMD_MAE_MPORT_ALLOC_ALIAS_OUT_LEN);
3270 if (encp->enc_mae_supported == B_FALSE) {
3275 req.emr_cmd = MC_CMD_MAE_MPORT_ALLOC;
3276 req.emr_in_buf = payload;
3277 req.emr_in_length = MC_CMD_MAE_MPORT_ALLOC_ALIAS_IN_LEN;
3278 req.emr_out_buf = payload;
3279 req.emr_out_length = MC_CMD_MAE_MPORT_ALLOC_ALIAS_OUT_LEN;
3281 MCDI_IN_SET_DWORD(req, MAE_MPORT_ALLOC_IN_TYPE,
3282 MC_CMD_MAE_MPORT_ALLOC_IN_MPORT_TYPE_ALIAS);
3283 MCDI_IN_SET_DWORD(req, MAE_MPORT_ALLOC_ALIAS_IN_DELIVER_MPORT,
3284 MAE_MPORT_SELECTOR_ASSIGNED);
3286 efx_mcdi_execute(enp, &req);
3288 if (req.emr_rc != 0) {
3293 mportp->id = MCDI_OUT_DWORD(req, MAE_MPORT_ALLOC_OUT_MPORT_ID);
3295 *labelp = MCDI_OUT_DWORD(req, MAE_MPORT_ALLOC_ALIAS_OUT_LABEL);
3302 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3306 __checkReturn efx_rc_t
3308 __in efx_nic_t *enp,
3309 __in const efx_mport_id_t *mportp)
3311 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3313 EFX_MCDI_DECLARE_BUF(payload,
3314 MC_CMD_MAE_MPORT_FREE_IN_LEN,
3315 MC_CMD_MAE_MPORT_FREE_OUT_LEN);
3318 if (encp->enc_mae_supported == B_FALSE) {
3323 req.emr_cmd = MC_CMD_MAE_MPORT_FREE;
3324 req.emr_in_buf = payload;
3325 req.emr_in_length = MC_CMD_MAE_MPORT_FREE_IN_LEN;
3326 req.emr_out_buf = payload;
3327 req.emr_out_length = MC_CMD_MAE_MPORT_FREE_OUT_LEN;
3329 MCDI_IN_SET_DWORD(req, MAE_MPORT_FREE_IN_MPORT_ID, mportp->id);
3331 efx_mcdi_execute(enp, &req);
3333 if (req.emr_rc != 0) {
3343 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3347 static __checkReturn efx_rc_t
3348 efx_mae_read_mport_journal_single(
3349 __in uint8_t *entry_buf,
3350 __out efx_mport_desc_t *desc)
3355 memset(desc, 0, sizeof (*desc));
3357 desc->emd_id.id = MCDI_STRUCT_DWORD(entry_buf,
3358 MAE_MPORT_DESC_V2_MPORT_ID);
3360 desc->emd_can_receive_on = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3361 MAE_MPORT_DESC_V2_FLAGS,
3362 MAE_MPORT_DESC_V2_CAN_RECEIVE_ON);
3364 desc->emd_can_deliver_to = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3365 MAE_MPORT_DESC_V2_FLAGS,
3366 MAE_MPORT_DESC_V2_CAN_DELIVER_TO);
3368 desc->emd_can_delete = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3369 MAE_MPORT_DESC_V2_FLAGS,
3370 MAE_MPORT_DESC_V2_CAN_DELETE);
3372 desc->emd_zombie = MCDI_STRUCT_DWORD_FIELD(entry_buf,
3373 MAE_MPORT_DESC_V2_FLAGS,
3374 MAE_MPORT_DESC_V2_IS_ZOMBIE);
3376 desc->emd_type = MCDI_STRUCT_DWORD(entry_buf,
3377 MAE_MPORT_DESC_V2_MPORT_TYPE);
3380 * We can't check everything here. If some additional checks are
3381 * required, they should be performed by the callback function.
3383 switch (desc->emd_type) {
3384 case EFX_MPORT_TYPE_NET_PORT:
3385 desc->emd_net_port.ep_index =
3386 MCDI_STRUCT_DWORD(entry_buf,
3387 MAE_MPORT_DESC_V2_NET_PORT_IDX);
3389 case EFX_MPORT_TYPE_ALIAS:
3390 desc->emd_alias.ea_target_mport_id.id =
3391 MCDI_STRUCT_DWORD(entry_buf,
3392 MAE_MPORT_DESC_V2_ALIAS_DELIVER_MPORT_ID);
3394 case EFX_MPORT_TYPE_VNIC:
3395 desc->emd_vnic.ev_client_type =
3396 MCDI_STRUCT_DWORD(entry_buf,
3397 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE);
3398 if (desc->emd_vnic.ev_client_type !=
3399 EFX_MPORT_VNIC_CLIENT_FUNCTION)
3402 pcie_intf = MCDI_STRUCT_DWORD(entry_buf,
3403 MAE_MPORT_DESC_V2_VNIC_FUNCTION_INTERFACE);
3404 rc = efx_mcdi_intf_from_pcie(pcie_intf,
3405 &desc->emd_vnic.ev_intf);
3409 desc->emd_vnic.ev_pf = MCDI_STRUCT_WORD(entry_buf,
3410 MAE_MPORT_DESC_V2_VNIC_FUNCTION_PF_IDX);
3411 desc->emd_vnic.ev_vf = MCDI_STRUCT_WORD(entry_buf,
3412 MAE_MPORT_DESC_V2_VNIC_FUNCTION_VF_IDX);
3413 desc->emd_vnic.ev_handle = MCDI_STRUCT_DWORD(entry_buf,
3414 MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE);
3426 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3430 static __checkReturn efx_rc_t
3431 efx_mae_read_mport_journal_batch(
3432 __in efx_nic_t *enp,
3433 __in efx_mae_read_mport_journal_cb *cbp,
3434 __in void *cb_datap,
3435 __out uint32_t *morep)
3438 EFX_MCDI_DECLARE_BUF(payload,
3439 MC_CMD_MAE_MPORT_READ_JOURNAL_IN_LEN,
3440 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMAX_MCDI2);
3447 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_NET_PORT ==
3448 MAE_MPORT_DESC_V2_MPORT_TYPE_NET_PORT);
3449 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_ALIAS ==
3450 MAE_MPORT_DESC_V2_MPORT_TYPE_ALIAS);
3451 EFX_STATIC_ASSERT(EFX_MPORT_TYPE_VNIC ==
3452 MAE_MPORT_DESC_V2_MPORT_TYPE_VNIC);
3454 EFX_STATIC_ASSERT(EFX_MPORT_VNIC_CLIENT_FUNCTION ==
3455 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE_FUNCTION);
3456 EFX_STATIC_ASSERT(EFX_MPORT_VNIC_CLIENT_PLUGIN ==
3457 MAE_MPORT_DESC_V2_VNIC_CLIENT_TYPE_PLUGIN);
3464 req.emr_cmd = MC_CMD_MAE_MPORT_READ_JOURNAL;
3465 req.emr_in_buf = payload;
3466 req.emr_in_length = MC_CMD_MAE_MPORT_READ_JOURNAL_IN_LEN;
3467 req.emr_out_buf = payload;
3468 req.emr_out_length = MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMAX_MCDI2;
3470 MCDI_IN_SET_DWORD(req, MAE_MPORT_READ_JOURNAL_IN_FLAGS, 0);
3472 efx_mcdi_execute(enp, &req);
3474 if (req.emr_rc != 0) {
3479 if (req.emr_out_length_used <
3480 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMIN) {
3485 if (morep != NULL) {
3486 *morep = MCDI_OUT_DWORD_FIELD(req,
3487 MAE_MPORT_READ_JOURNAL_OUT_FLAGS,
3488 MAE_MPORT_READ_JOURNAL_OUT_MORE);
3490 n_entries = MCDI_OUT_DWORD(req,
3491 MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_COUNT);
3492 entry_sz = MCDI_OUT_DWORD(req,
3493 MAE_MPORT_READ_JOURNAL_OUT_SIZEOF_MPORT_DESC);
3494 entry_buf = MCDI_OUT2(req, uint8_t,
3495 MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA);
3497 if (entry_sz < MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE_OFST +
3498 MAE_MPORT_DESC_V2_VNIC_CLIENT_HANDLE_LEN) {
3502 if (n_entries * entry_sz / entry_sz != n_entries) {
3506 if (req.emr_out_length_used !=
3507 MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMIN + n_entries * entry_sz) {
3512 for (i = 0; i < n_entries; i++) {
3513 efx_mport_desc_t desc;
3515 rc = efx_mae_read_mport_journal_single(entry_buf, &desc);
3519 (*cbp)(cb_datap, &desc, sizeof (desc));
3520 entry_buf += entry_sz;
3536 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3540 __checkReturn efx_rc_t
3541 efx_mae_read_mport_journal(
3542 __in efx_nic_t *enp,
3543 __in efx_mae_read_mport_journal_cb *cbp,
3544 __in void *cb_datap)
3546 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
3550 if (encp->enc_mae_supported == B_FALSE) {
3556 rc = efx_mae_read_mport_journal_batch(enp, cbp, cb_datap,
3560 } while (more != 0);
3567 EFSYS_PROBE1(fail1, efx_rc_t, rc);
3571 #endif /* EFSYS_OPT_MAE */