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(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_VXLAN) == 1) {
50 maep->em_encap_types_supported |=
51 (1U << EFX_TUNNEL_PROTOCOL_VXLAN);
54 if (MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_GENEVE) == 1) {
55 maep->em_encap_types_supported |=
56 (1U << EFX_TUNNEL_PROTOCOL_GENEVE);
59 if (MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ENCAP_TYPE_NVGRE) == 1) {
60 maep->em_encap_types_supported |=
61 (1U << EFX_TUNNEL_PROTOCOL_NVGRE);
64 maep->em_max_nfields =
65 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_MATCH_FIELD_COUNT);
72 EFSYS_PROBE1(fail1, efx_rc_t, rc);
76 static __checkReturn efx_rc_t
77 efx_mae_get_outer_rule_caps(
79 __in unsigned int field_ncaps,
80 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
83 EFX_MCDI_DECLARE_BUF(payload,
84 MC_CMD_MAE_GET_OR_CAPS_IN_LEN,
85 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2);
86 unsigned int mcdi_field_ncaps;
90 if (MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps) >
91 MC_CMD_MAE_GET_OR_CAPS_OUT_LENMAX_MCDI2) {
96 req.emr_cmd = MC_CMD_MAE_GET_OR_CAPS;
97 req.emr_in_buf = payload;
98 req.emr_in_length = MC_CMD_MAE_GET_OR_CAPS_IN_LEN;
99 req.emr_out_buf = payload;
100 req.emr_out_length = MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(field_ncaps);
102 efx_mcdi_execute(enp, &req);
104 if (req.emr_rc != 0) {
109 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
111 if (req.emr_out_length_used <
112 MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
117 if (mcdi_field_ncaps > field_ncaps) {
122 for (i = 0; i < mcdi_field_ncaps; ++i) {
126 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
127 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
128 MAE_FIELD_FLAGS_SUPPORT_STATUS);
130 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
131 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
132 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
134 field_caps[i].emfc_match_affects_class =
135 (match_flag != 0) ? B_TRUE : B_FALSE;
137 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
138 MAE_GET_OR_CAPS_OUT_FIELD_FLAGS, i,
139 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
141 field_caps[i].emfc_mask_affects_class =
142 (mask_flag != 0) ? B_TRUE : B_FALSE;
154 EFSYS_PROBE1(fail1, efx_rc_t, rc);
158 static __checkReturn efx_rc_t
159 efx_mae_get_action_rule_caps(
161 __in unsigned int field_ncaps,
162 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
165 EFX_MCDI_DECLARE_BUF(payload,
166 MC_CMD_MAE_GET_AR_CAPS_IN_LEN,
167 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2);
168 unsigned int mcdi_field_ncaps;
172 if (MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps) >
173 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2) {
178 req.emr_cmd = MC_CMD_MAE_GET_AR_CAPS;
179 req.emr_in_buf = payload;
180 req.emr_in_length = MC_CMD_MAE_GET_AR_CAPS_IN_LEN;
181 req.emr_out_buf = payload;
182 req.emr_out_length = MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps);
184 efx_mcdi_execute(enp, &req);
186 if (req.emr_rc != 0) {
191 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
193 if (req.emr_out_length_used <
194 MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
199 if (mcdi_field_ncaps > field_ncaps) {
204 for (i = 0; i < mcdi_field_ncaps; ++i) {
208 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
209 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
210 MAE_FIELD_FLAGS_SUPPORT_STATUS);
212 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
213 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
214 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
216 field_caps[i].emfc_match_affects_class =
217 (match_flag != 0) ? B_TRUE : B_FALSE;
219 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
220 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
221 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
223 field_caps[i].emfc_mask_affects_class =
224 (mask_flag != 0) ? B_TRUE : B_FALSE;
236 EFSYS_PROBE1(fail1, efx_rc_t, rc);
240 __checkReturn efx_rc_t
244 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
245 efx_mae_field_cap_t *or_fcaps;
246 size_t or_fcaps_size;
247 efx_mae_field_cap_t *ar_fcaps;
248 size_t ar_fcaps_size;
252 if (encp->enc_mae_supported == B_FALSE) {
257 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*maep), maep);
265 rc = efx_mae_get_capabilities(enp);
269 or_fcaps_size = maep->em_max_nfields * sizeof (*or_fcaps);
270 EFSYS_KMEM_ALLOC(enp->en_esip, or_fcaps_size, or_fcaps);
271 if (or_fcaps == NULL) {
276 maep->em_outer_rule_field_caps_size = or_fcaps_size;
277 maep->em_outer_rule_field_caps = or_fcaps;
279 rc = efx_mae_get_outer_rule_caps(enp, maep->em_max_nfields, or_fcaps);
283 ar_fcaps_size = maep->em_max_nfields * sizeof (*ar_fcaps);
284 EFSYS_KMEM_ALLOC(enp->en_esip, ar_fcaps_size, ar_fcaps);
285 if (ar_fcaps == NULL) {
290 maep->em_action_rule_field_caps_size = ar_fcaps_size;
291 maep->em_action_rule_field_caps = ar_fcaps;
293 rc = efx_mae_get_action_rule_caps(enp, maep->em_max_nfields, ar_fcaps);
301 EFSYS_KMEM_FREE(enp->en_esip, ar_fcaps_size, ar_fcaps);
306 EFSYS_KMEM_FREE(enp->en_esip, or_fcaps_size, or_fcaps);
311 EFSYS_KMEM_FREE(enp->en_esip, sizeof (struct efx_mae_s), enp->en_maep);
316 EFSYS_PROBE1(fail1, efx_rc_t, rc);
324 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
325 efx_mae_t *maep = enp->en_maep;
327 if (encp->enc_mae_supported == B_FALSE)
330 EFSYS_KMEM_FREE(enp->en_esip, maep->em_action_rule_field_caps_size,
331 maep->em_action_rule_field_caps);
332 EFSYS_KMEM_FREE(enp->en_esip, maep->em_outer_rule_field_caps_size,
333 maep->em_outer_rule_field_caps);
334 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*maep), maep);
338 __checkReturn efx_rc_t
341 __out efx_mae_limits_t *emlp)
343 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
344 struct efx_mae_s *maep = enp->en_maep;
347 if (encp->enc_mae_supported == B_FALSE) {
352 emlp->eml_max_n_outer_prios = maep->em_max_n_outer_prios;
353 emlp->eml_max_n_action_prios = maep->em_max_n_action_prios;
354 emlp->eml_encap_types_supported = maep->em_encap_types_supported;
355 emlp->eml_encap_header_size_limit =
356 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2;
361 EFSYS_PROBE1(fail1, efx_rc_t, rc);
365 __checkReturn efx_rc_t
366 efx_mae_match_spec_init(
368 __in efx_mae_rule_type_t type,
370 __out efx_mae_match_spec_t **specp)
372 efx_mae_match_spec_t *spec;
376 case EFX_MAE_RULE_OUTER:
378 case EFX_MAE_RULE_ACTION:
385 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
391 spec->emms_type = type;
392 spec->emms_prio = prio;
401 EFSYS_PROBE1(fail1, efx_rc_t, rc);
406 efx_mae_match_spec_fini(
408 __in efx_mae_match_spec_t *spec)
410 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
413 /* Named identifiers which are valid indices to efx_mae_field_cap_t */
414 typedef enum efx_mae_field_cap_id_e {
415 EFX_MAE_FIELD_ID_INGRESS_MPORT_SELECTOR = MAE_FIELD_INGRESS_PORT,
416 EFX_MAE_FIELD_ID_ETHER_TYPE_BE = MAE_FIELD_ETHER_TYPE,
417 EFX_MAE_FIELD_ID_ETH_SADDR_BE = MAE_FIELD_ETH_SADDR,
418 EFX_MAE_FIELD_ID_ETH_DADDR_BE = MAE_FIELD_ETH_DADDR,
419 EFX_MAE_FIELD_ID_VLAN0_TCI_BE = MAE_FIELD_VLAN0_TCI,
420 EFX_MAE_FIELD_ID_VLAN0_PROTO_BE = MAE_FIELD_VLAN0_PROTO,
421 EFX_MAE_FIELD_ID_VLAN1_TCI_BE = MAE_FIELD_VLAN1_TCI,
422 EFX_MAE_FIELD_ID_VLAN1_PROTO_BE = MAE_FIELD_VLAN1_PROTO,
423 EFX_MAE_FIELD_ID_SRC_IP4_BE = MAE_FIELD_SRC_IP4,
424 EFX_MAE_FIELD_ID_DST_IP4_BE = MAE_FIELD_DST_IP4,
425 EFX_MAE_FIELD_ID_IP_PROTO = MAE_FIELD_IP_PROTO,
426 EFX_MAE_FIELD_ID_IP_TOS = MAE_FIELD_IP_TOS,
427 EFX_MAE_FIELD_ID_IP_TTL = MAE_FIELD_IP_TTL,
428 EFX_MAE_FIELD_ID_SRC_IP6_BE = MAE_FIELD_SRC_IP6,
429 EFX_MAE_FIELD_ID_DST_IP6_BE = MAE_FIELD_DST_IP6,
430 EFX_MAE_FIELD_ID_L4_SPORT_BE = MAE_FIELD_L4_SPORT,
431 EFX_MAE_FIELD_ID_L4_DPORT_BE = MAE_FIELD_L4_DPORT,
432 EFX_MAE_FIELD_ID_TCP_FLAGS_BE = MAE_FIELD_TCP_FLAGS,
433 EFX_MAE_FIELD_ID_ENC_ETHER_TYPE_BE = MAE_FIELD_ENC_ETHER_TYPE,
434 EFX_MAE_FIELD_ID_ENC_ETH_SADDR_BE = MAE_FIELD_ENC_ETH_SADDR,
435 EFX_MAE_FIELD_ID_ENC_ETH_DADDR_BE = MAE_FIELD_ENC_ETH_DADDR,
436 EFX_MAE_FIELD_ID_ENC_VLAN0_TCI_BE = MAE_FIELD_ENC_VLAN0_TCI,
437 EFX_MAE_FIELD_ID_ENC_VLAN0_PROTO_BE = MAE_FIELD_ENC_VLAN0_PROTO,
438 EFX_MAE_FIELD_ID_ENC_VLAN1_TCI_BE = MAE_FIELD_ENC_VLAN1_TCI,
439 EFX_MAE_FIELD_ID_ENC_VLAN1_PROTO_BE = MAE_FIELD_ENC_VLAN1_PROTO,
440 EFX_MAE_FIELD_ID_ENC_SRC_IP4_BE = MAE_FIELD_ENC_SRC_IP4,
441 EFX_MAE_FIELD_ID_ENC_DST_IP4_BE = MAE_FIELD_ENC_DST_IP4,
442 EFX_MAE_FIELD_ID_ENC_IP_PROTO = MAE_FIELD_ENC_IP_PROTO,
443 EFX_MAE_FIELD_ID_ENC_IP_TOS = MAE_FIELD_ENC_IP_TOS,
444 EFX_MAE_FIELD_ID_ENC_IP_TTL = MAE_FIELD_ENC_IP_TTL,
445 EFX_MAE_FIELD_ID_ENC_SRC_IP6_BE = MAE_FIELD_ENC_SRC_IP6,
446 EFX_MAE_FIELD_ID_ENC_DST_IP6_BE = MAE_FIELD_ENC_DST_IP6,
447 EFX_MAE_FIELD_ID_ENC_L4_SPORT_BE = MAE_FIELD_ENC_L4_SPORT,
448 EFX_MAE_FIELD_ID_ENC_L4_DPORT_BE = MAE_FIELD_ENC_L4_DPORT,
449 EFX_MAE_FIELD_ID_ENC_VNET_ID_BE = MAE_FIELD_ENC_VNET_ID,
450 EFX_MAE_FIELD_ID_OUTER_RULE_ID = MAE_FIELD_OUTER_RULE_ID,
452 EFX_MAE_FIELD_CAP_NIDS
453 } efx_mae_field_cap_id_t;
455 typedef enum efx_mae_field_endianness_e {
456 EFX_MAE_FIELD_LE = 0,
459 EFX_MAE_FIELD_ENDIANNESS_NTYPES
460 } efx_mae_field_endianness_t;
463 * The following structure is a means to describe an MAE field.
464 * The information in it is meant to be used internally by
465 * APIs for addressing a given field in a mask-value pairs
466 * structure and for validation purposes.
468 * A field may have an alternative one. This structure
469 * has additional members to reference the alternative
470 * field's mask. See efx_mae_match_spec_is_valid().
472 typedef struct efx_mae_mv_desc_s {
473 efx_mae_field_cap_id_t emmd_field_cap_id;
475 size_t emmd_value_size;
476 size_t emmd_value_offset;
477 size_t emmd_mask_size;
478 size_t emmd_mask_offset;
481 * Having the alternative field's mask size set to 0
482 * means that there's no alternative field specified.
484 size_t emmd_alt_mask_size;
485 size_t emmd_alt_mask_offset;
487 /* Primary field and the alternative one are of the same endianness. */
488 efx_mae_field_endianness_t emmd_endianness;
491 /* Indices to this array are provided by efx_mae_field_id_t */
492 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
493 #define EFX_MAE_MV_DESC(_name, _endianness) \
494 [EFX_MAE_FIELD_##_name] = \
496 EFX_MAE_FIELD_ID_##_name, \
497 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
498 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
499 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
500 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
501 0, 0 /* no alternative field */, \
505 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
506 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
507 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
508 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
509 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
510 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
511 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
512 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
513 EFX_MAE_MV_DESC(SRC_IP4_BE, EFX_MAE_FIELD_BE),
514 EFX_MAE_MV_DESC(DST_IP4_BE, EFX_MAE_FIELD_BE),
515 EFX_MAE_MV_DESC(IP_PROTO, EFX_MAE_FIELD_BE),
516 EFX_MAE_MV_DESC(IP_TOS, EFX_MAE_FIELD_BE),
517 EFX_MAE_MV_DESC(IP_TTL, EFX_MAE_FIELD_BE),
518 EFX_MAE_MV_DESC(SRC_IP6_BE, EFX_MAE_FIELD_BE),
519 EFX_MAE_MV_DESC(DST_IP6_BE, EFX_MAE_FIELD_BE),
520 EFX_MAE_MV_DESC(L4_SPORT_BE, EFX_MAE_FIELD_BE),
521 EFX_MAE_MV_DESC(L4_DPORT_BE, EFX_MAE_FIELD_BE),
522 EFX_MAE_MV_DESC(TCP_FLAGS_BE, EFX_MAE_FIELD_BE),
523 EFX_MAE_MV_DESC(ENC_VNET_ID_BE, EFX_MAE_FIELD_BE),
524 EFX_MAE_MV_DESC(OUTER_RULE_ID, EFX_MAE_FIELD_LE),
526 #undef EFX_MAE_MV_DESC
529 /* Indices to this array are provided by efx_mae_field_id_t */
530 static const efx_mae_mv_desc_t __efx_mae_outer_rule_mv_desc_set[] = {
531 #define EFX_MAE_MV_DESC(_name, _endianness) \
532 [EFX_MAE_FIELD_##_name] = \
534 EFX_MAE_FIELD_ID_##_name, \
535 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
536 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
537 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
538 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
539 0, 0 /* no alternative field */, \
543 /* Same as EFX_MAE_MV_DESC(), but also indicates an alternative field. */
544 #define EFX_MAE_MV_DESC_ALT(_name, _alt_name, _endianness) \
545 [EFX_MAE_FIELD_##_name] = \
547 EFX_MAE_FIELD_ID_##_name, \
548 MAE_ENC_FIELD_PAIRS_##_name##_LEN, \
549 MAE_ENC_FIELD_PAIRS_##_name##_OFST, \
550 MAE_ENC_FIELD_PAIRS_##_name##_MASK_LEN, \
551 MAE_ENC_FIELD_PAIRS_##_name##_MASK_OFST, \
552 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_LEN, \
553 MAE_ENC_FIELD_PAIRS_##_alt_name##_MASK_OFST, \
557 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
558 EFX_MAE_MV_DESC(ENC_ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
559 EFX_MAE_MV_DESC(ENC_ETH_SADDR_BE, EFX_MAE_FIELD_BE),
560 EFX_MAE_MV_DESC(ENC_ETH_DADDR_BE, EFX_MAE_FIELD_BE),
561 EFX_MAE_MV_DESC(ENC_VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
562 EFX_MAE_MV_DESC(ENC_VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
563 EFX_MAE_MV_DESC(ENC_VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
564 EFX_MAE_MV_DESC(ENC_VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
565 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP4_BE, ENC_SRC_IP6_BE, EFX_MAE_FIELD_BE),
566 EFX_MAE_MV_DESC_ALT(ENC_DST_IP4_BE, ENC_DST_IP6_BE, EFX_MAE_FIELD_BE),
567 EFX_MAE_MV_DESC(ENC_IP_PROTO, EFX_MAE_FIELD_BE),
568 EFX_MAE_MV_DESC(ENC_IP_TOS, EFX_MAE_FIELD_BE),
569 EFX_MAE_MV_DESC(ENC_IP_TTL, EFX_MAE_FIELD_BE),
570 EFX_MAE_MV_DESC_ALT(ENC_SRC_IP6_BE, ENC_SRC_IP4_BE, EFX_MAE_FIELD_BE),
571 EFX_MAE_MV_DESC_ALT(ENC_DST_IP6_BE, ENC_DST_IP4_BE, EFX_MAE_FIELD_BE),
572 EFX_MAE_MV_DESC(ENC_L4_SPORT_BE, EFX_MAE_FIELD_BE),
573 EFX_MAE_MV_DESC(ENC_L4_DPORT_BE, EFX_MAE_FIELD_BE),
575 #undef EFX_MAE_MV_DESC_ALT
576 #undef EFX_MAE_MV_DESC
579 __checkReturn efx_rc_t
580 efx_mae_mport_by_phy_port(
581 __in uint32_t phy_port,
582 __out efx_mport_sel_t *mportp)
587 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
592 EFX_POPULATE_DWORD_2(dword,
593 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
594 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
596 memset(mportp, 0, sizeof (*mportp));
598 * The constructed DWORD is little-endian,
599 * but the resulting value is meant to be
600 * passed to MCDIs, where it will undergo
601 * host-order to little endian conversion.
603 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
608 EFSYS_PROBE1(fail1, efx_rc_t, rc);
612 __checkReturn efx_rc_t
613 efx_mae_mport_by_pcie_function(
616 __out efx_mport_sel_t *mportp)
621 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
622 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
624 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_PF_ID)) {
629 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
634 EFX_POPULATE_DWORD_3(dword,
635 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_FUNC,
636 MAE_MPORT_SELECTOR_FUNC_PF_ID, pf,
637 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
639 memset(mportp, 0, sizeof (*mportp));
641 * The constructed DWORD is little-endian,
642 * but the resulting value is meant to be
643 * passed to MCDIs, where it will undergo
644 * host-order to little endian conversion.
646 mportp->sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
653 EFSYS_PROBE1(fail1, efx_rc_t, rc);
657 __checkReturn efx_rc_t
658 efx_mae_match_spec_field_set(
659 __in efx_mae_match_spec_t *spec,
660 __in efx_mae_field_id_t field_id,
661 __in size_t value_size,
662 __in_bcount(value_size) const uint8_t *value,
663 __in size_t mask_size,
664 __in_bcount(mask_size) const uint8_t *mask)
666 const efx_mae_mv_desc_t *descp;
667 unsigned int desc_set_nentries;
671 switch (spec->emms_type) {
672 case EFX_MAE_RULE_OUTER:
674 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
675 descp = &__efx_mae_outer_rule_mv_desc_set[field_id];
676 mvp = spec->emms_mask_value_pairs.outer;
678 case EFX_MAE_RULE_ACTION:
680 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
681 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
682 mvp = spec->emms_mask_value_pairs.action;
689 if ((unsigned int)field_id >= desc_set_nentries) {
694 if (descp->emmd_mask_size == 0) {
695 /* The ID points to a gap in the array of field descriptors. */
700 if (value_size != descp->emmd_value_size) {
705 if (mask_size != descp->emmd_mask_size) {
710 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
714 * The mask/value are in network (big endian) order.
715 * The MCDI request field is also big endian.
718 EFSYS_ASSERT3U(value_size, ==, mask_size);
720 for (i = 0; i < value_size; ++i) {
721 uint8_t *v_bytep = mvp + descp->emmd_value_offset + i;
722 uint8_t *m_bytep = mvp + descp->emmd_mask_offset + i;
725 * Apply the mask (which may be all-zeros) to the value.
727 * If this API is provided with some value to set for a
728 * given field in one specification and with some other
729 * value to set for this field in another specification,
730 * then, if the two masks are all-zeros, the field will
731 * avoid being counted as a mismatch when comparing the
732 * specifications using efx_mae_match_specs_equal() API.
734 *v_bytep = value[i] & mask[i];
741 * The mask/value are in host byte order.
742 * The MCDI request field is little endian.
744 switch (value_size) {
746 EFX_POPULATE_DWORD_1(dword,
747 EFX_DWORD_0, *(const uint32_t *)value);
749 memcpy(mvp + descp->emmd_value_offset,
750 &dword, sizeof (dword));
753 EFSYS_ASSERT(B_FALSE);
758 EFX_POPULATE_DWORD_1(dword,
759 EFX_DWORD_0, *(const uint32_t *)mask);
761 memcpy(mvp + descp->emmd_mask_offset,
762 &dword, sizeof (dword));
765 EFSYS_ASSERT(B_FALSE);
780 EFSYS_PROBE1(fail1, efx_rc_t, rc);
784 __checkReturn efx_rc_t
785 efx_mae_match_spec_mport_set(
786 __in efx_mae_match_spec_t *spec,
787 __in const efx_mport_sel_t *valuep,
788 __in_opt const efx_mport_sel_t *maskp)
790 uint32_t full_mask = UINT32_MAX;
795 if (valuep == NULL) {
800 vp = (const uint8_t *)&valuep->sel;
802 mp = (const uint8_t *)&maskp->sel;
804 mp = (const uint8_t *)&full_mask;
806 rc = efx_mae_match_spec_field_set(spec,
807 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
808 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
817 EFSYS_PROBE1(fail1, efx_rc_t, rc);
821 __checkReturn boolean_t
822 efx_mae_match_specs_equal(
823 __in const efx_mae_match_spec_t *left,
824 __in const efx_mae_match_spec_t *right)
826 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
829 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
830 ((_mask)[(_bit) / (_mask_page_nbits)] & \
831 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
835 __in size_t mask_nbytes,
836 __in_bcount(mask_nbytes) const uint8_t *maskp)
838 boolean_t prev_bit_is_set = B_TRUE;
841 for (i = 0; i < 8 * mask_nbytes; ++i) {
842 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
844 if (!prev_bit_is_set && bit_is_set)
847 prev_bit_is_set = bit_is_set;
854 efx_mask_is_all_ones(
855 __in size_t mask_nbytes,
856 __in_bcount(mask_nbytes) const uint8_t *maskp)
861 for (i = 0; i < mask_nbytes; ++i)
864 return (t == (uint8_t)(~0));
868 efx_mask_is_all_zeros(
869 __in size_t mask_nbytes,
870 __in_bcount(mask_nbytes) const uint8_t *maskp)
875 for (i = 0; i < mask_nbytes; ++i)
881 __checkReturn boolean_t
882 efx_mae_match_spec_is_valid(
884 __in const efx_mae_match_spec_t *spec)
886 efx_mae_t *maep = enp->en_maep;
887 unsigned int field_ncaps = maep->em_max_nfields;
888 const efx_mae_field_cap_t *field_caps;
889 const efx_mae_mv_desc_t *desc_setp;
890 unsigned int desc_set_nentries;
891 boolean_t is_valid = B_TRUE;
892 efx_mae_field_id_t field_id;
895 switch (spec->emms_type) {
896 case EFX_MAE_RULE_OUTER:
897 field_caps = maep->em_outer_rule_field_caps;
898 desc_setp = __efx_mae_outer_rule_mv_desc_set;
900 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
901 mvp = spec->emms_mask_value_pairs.outer;
903 case EFX_MAE_RULE_ACTION:
904 field_caps = maep->em_action_rule_field_caps;
905 desc_setp = __efx_mae_action_rule_mv_desc_set;
907 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
908 mvp = spec->emms_mask_value_pairs.action;
914 if (field_caps == NULL)
917 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
919 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
920 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
921 const uint8_t *alt_m_buf = mvp + descp->emmd_alt_mask_offset;
922 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
923 size_t alt_m_size = descp->emmd_alt_mask_size;
924 size_t m_size = descp->emmd_mask_size;
927 continue; /* Skip array gap */
929 if ((unsigned int)field_cap_id >= field_ncaps) {
931 * The FW has not reported capability status for
932 * this field. Make sure that its mask is zeroed.
934 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
935 if (is_valid != B_FALSE)
941 switch (field_caps[field_cap_id].emfc_support) {
942 case MAE_FIELD_SUPPORTED_MATCH_MASK:
945 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
946 is_valid = efx_mask_is_prefix(m_size, m_buf);
948 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
949 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
950 efx_mask_is_all_zeros(m_size, m_buf));
952 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
953 is_valid = efx_mask_is_all_ones(m_size, m_buf);
955 if ((is_valid == B_FALSE) && (alt_m_size != 0)) {
957 * This field has an alternative one. The FW
958 * reports ALWAYS for both implying that one
959 * of them is required to have all-ones mask.
961 * The primary field's mask is incorrect; go
962 * on to check that of the alternative field.
964 is_valid = efx_mask_is_all_ones(alt_m_size,
968 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
969 case MAE_FIELD_UNSUPPORTED:
971 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
975 if (is_valid == B_FALSE)
982 __checkReturn efx_rc_t
983 efx_mae_action_set_spec_init(
985 __out efx_mae_actions_t **specp)
987 efx_mae_actions_t *spec;
990 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
1001 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1006 efx_mae_action_set_spec_fini(
1007 __in efx_nic_t *enp,
1008 __in efx_mae_actions_t *spec)
1010 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
1013 static __checkReturn efx_rc_t
1014 efx_mae_action_set_add_vlan_pop(
1015 __in efx_mae_actions_t *spec,
1016 __in size_t arg_size,
1017 __in_bcount(arg_size) const uint8_t *arg)
1021 if (arg_size != 0) {
1031 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
1036 ++spec->ema_n_vlan_tags_to_pop;
1045 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1049 static __checkReturn efx_rc_t
1050 efx_mae_action_set_add_vlan_push(
1051 __in efx_mae_actions_t *spec,
1052 __in size_t arg_size,
1053 __in_bcount(arg_size) const uint8_t *arg)
1055 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
1058 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
1068 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1073 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
1074 ++(spec->ema_n_vlan_tags_to_push);
1083 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1087 static __checkReturn efx_rc_t
1088 efx_mae_action_set_add_flag(
1089 __in efx_mae_actions_t *spec,
1090 __in size_t arg_size,
1091 __in_bcount(arg_size) const uint8_t *arg)
1095 _NOTE(ARGUNUSED(spec))
1097 if (arg_size != 0) {
1107 /* This action does not have any arguments, so do nothing here. */
1114 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1118 static __checkReturn efx_rc_t
1119 efx_mae_action_set_add_mark(
1120 __in efx_mae_actions_t *spec,
1121 __in size_t arg_size,
1122 __in_bcount(arg_size) const uint8_t *arg)
1126 if (arg_size != sizeof (spec->ema_mark_value)) {
1136 memcpy(&spec->ema_mark_value, arg, arg_size);
1143 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1147 static __checkReturn efx_rc_t
1148 efx_mae_action_set_add_deliver(
1149 __in efx_mae_actions_t *spec,
1150 __in size_t arg_size,
1151 __in_bcount(arg_size) const uint8_t *arg)
1155 if (arg_size != sizeof (spec->ema_deliver_mport)) {
1165 memcpy(&spec->ema_deliver_mport, arg, arg_size);
1172 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1176 typedef struct efx_mae_action_desc_s {
1177 /* Action specific handler */
1178 efx_rc_t (*emad_add)(efx_mae_actions_t *,
1179 size_t, const uint8_t *);
1180 } efx_mae_action_desc_t;
1182 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
1183 [EFX_MAE_ACTION_VLAN_POP] = {
1184 .emad_add = efx_mae_action_set_add_vlan_pop
1186 [EFX_MAE_ACTION_VLAN_PUSH] = {
1187 .emad_add = efx_mae_action_set_add_vlan_push
1189 [EFX_MAE_ACTION_FLAG] = {
1190 .emad_add = efx_mae_action_set_add_flag
1192 [EFX_MAE_ACTION_MARK] = {
1193 .emad_add = efx_mae_action_set_add_mark
1195 [EFX_MAE_ACTION_DELIVER] = {
1196 .emad_add = efx_mae_action_set_add_deliver
1200 static const uint32_t efx_mae_action_ordered_map =
1201 (1U << EFX_MAE_ACTION_VLAN_POP) |
1202 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
1203 (1U << EFX_MAE_ACTION_FLAG) |
1204 (1U << EFX_MAE_ACTION_MARK) |
1205 (1U << EFX_MAE_ACTION_DELIVER);
1208 * These actions must not be added after DELIVER, but
1209 * they can have any place among the rest of
1210 * strictly ordered actions.
1212 static const uint32_t efx_mae_action_nonstrict_map =
1213 (1U << EFX_MAE_ACTION_FLAG) |
1214 (1U << EFX_MAE_ACTION_MARK);
1216 static const uint32_t efx_mae_action_repeat_map =
1217 (1U << EFX_MAE_ACTION_VLAN_POP) |
1218 (1U << EFX_MAE_ACTION_VLAN_PUSH);
1221 * Add an action to an action set.
1223 * This has to be invoked in the desired action order.
1224 * An out-of-order action request will be turned down.
1226 static __checkReturn efx_rc_t
1227 efx_mae_action_set_spec_populate(
1228 __in efx_mae_actions_t *spec,
1229 __in efx_mae_action_t type,
1230 __in size_t arg_size,
1231 __in_bcount(arg_size) const uint8_t *arg)
1233 uint32_t action_mask;
1236 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1237 (sizeof (efx_mae_action_ordered_map) * 8));
1238 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
1239 (sizeof (efx_mae_action_repeat_map) * 8));
1241 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
1242 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
1243 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
1245 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
1250 action_mask = (1U << type);
1252 if ((spec->ema_actions & action_mask) != 0) {
1253 /* The action set already contains this action. */
1254 if ((efx_mae_action_repeat_map & action_mask) == 0) {
1255 /* Cannot add another non-repeatable action. */
1261 if ((efx_mae_action_ordered_map & action_mask) != 0) {
1262 uint32_t strict_ordered_map =
1263 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
1264 uint32_t later_actions_mask =
1265 strict_ordered_map & ~(action_mask | (action_mask - 1));
1267 if ((spec->ema_actions & later_actions_mask) != 0) {
1268 /* Cannot add an action after later ordered actions. */
1274 if (efx_mae_actions[type].emad_add != NULL) {
1275 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
1280 spec->ema_actions |= action_mask;
1291 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1295 __checkReturn efx_rc_t
1296 efx_mae_action_set_populate_vlan_pop(
1297 __in efx_mae_actions_t *spec)
1299 return (efx_mae_action_set_spec_populate(spec,
1300 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1303 __checkReturn efx_rc_t
1304 efx_mae_action_set_populate_vlan_push(
1305 __in efx_mae_actions_t *spec,
1306 __in uint16_t tpid_be,
1307 __in uint16_t tci_be)
1309 efx_mae_action_vlan_push_t action;
1310 const uint8_t *arg = (const uint8_t *)&action;
1312 action.emavp_tpid_be = tpid_be;
1313 action.emavp_tci_be = tci_be;
1315 return (efx_mae_action_set_spec_populate(spec,
1316 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1319 __checkReturn efx_rc_t
1320 efx_mae_action_set_populate_flag(
1321 __in efx_mae_actions_t *spec)
1323 return (efx_mae_action_set_spec_populate(spec,
1324 EFX_MAE_ACTION_FLAG, 0, NULL));
1327 __checkReturn efx_rc_t
1328 efx_mae_action_set_populate_mark(
1329 __in efx_mae_actions_t *spec,
1330 __in uint32_t mark_value)
1332 const uint8_t *arg = (const uint8_t *)&mark_value;
1334 return (efx_mae_action_set_spec_populate(spec,
1335 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1338 __checkReturn efx_rc_t
1339 efx_mae_action_set_populate_deliver(
1340 __in efx_mae_actions_t *spec,
1341 __in const efx_mport_sel_t *mportp)
1346 if (mportp == NULL) {
1351 arg = (const uint8_t *)&mportp->sel;
1353 return (efx_mae_action_set_spec_populate(spec,
1354 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1357 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1361 __checkReturn efx_rc_t
1362 efx_mae_action_set_populate_drop(
1363 __in efx_mae_actions_t *spec)
1365 efx_mport_sel_t mport;
1369 EFX_POPULATE_DWORD_1(dword,
1370 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1373 * The constructed DWORD is little-endian,
1374 * but the resulting value is meant to be
1375 * passed to MCDIs, where it will undergo
1376 * host-order to little endian conversion.
1378 mport.sel = EFX_DWORD_FIELD(dword, EFX_DWORD_0);
1380 arg = (const uint8_t *)&mport.sel;
1382 return (efx_mae_action_set_spec_populate(spec,
1383 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1386 __checkReturn boolean_t
1387 efx_mae_action_set_specs_equal(
1388 __in const efx_mae_actions_t *left,
1389 __in const efx_mae_actions_t *right)
1391 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1394 __checkReturn efx_rc_t
1395 efx_mae_match_specs_class_cmp(
1396 __in efx_nic_t *enp,
1397 __in const efx_mae_match_spec_t *left,
1398 __in const efx_mae_match_spec_t *right,
1399 __out boolean_t *have_same_classp)
1401 efx_mae_t *maep = enp->en_maep;
1402 unsigned int field_ncaps = maep->em_max_nfields;
1403 const efx_mae_field_cap_t *field_caps;
1404 const efx_mae_mv_desc_t *desc_setp;
1405 unsigned int desc_set_nentries;
1406 boolean_t have_same_class = B_TRUE;
1407 efx_mae_field_id_t field_id;
1408 const uint8_t *mvpl;
1409 const uint8_t *mvpr;
1412 switch (left->emms_type) {
1413 case EFX_MAE_RULE_OUTER:
1414 field_caps = maep->em_outer_rule_field_caps;
1415 desc_setp = __efx_mae_outer_rule_mv_desc_set;
1417 EFX_ARRAY_SIZE(__efx_mae_outer_rule_mv_desc_set);
1418 mvpl = left->emms_mask_value_pairs.outer;
1419 mvpr = right->emms_mask_value_pairs.outer;
1421 case EFX_MAE_RULE_ACTION:
1422 field_caps = maep->em_action_rule_field_caps;
1423 desc_setp = __efx_mae_action_rule_mv_desc_set;
1425 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1426 mvpl = left->emms_mask_value_pairs.action;
1427 mvpr = right->emms_mask_value_pairs.action;
1434 if (field_caps == NULL) {
1439 if (left->emms_type != right->emms_type ||
1440 left->emms_prio != right->emms_prio) {
1442 * Rules of different types can never map to the same class.
1444 * The FW can support some set of match criteria for one
1445 * priority and not support the very same set for
1446 * another priority. Thus, two rules which have
1447 * different priorities can never map to
1450 *have_same_classp = B_FALSE;
1454 for (field_id = 0; (unsigned int)field_id < desc_set_nentries;
1456 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1457 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1458 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1459 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1460 size_t mask_size = descp->emmd_mask_size;
1461 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1462 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1463 size_t value_size = descp->emmd_value_size;
1466 continue; /* Skip array gap */
1468 if ((unsigned int)field_cap_id >= field_ncaps) {
1470 * The FW has not reported capability status for this
1471 * field. It's unknown whether any difference between
1472 * the two masks / values affects the class. The only
1473 * case when the class must be the same is when these
1474 * mask-value pairs match. Otherwise, report mismatch.
1476 if ((memcmp(lmaskp, rmaskp, mask_size) == 0) &&
1477 (memcmp(lvalp, rvalp, value_size) == 0))
1483 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1484 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1485 have_same_class = B_FALSE;
1490 if (field_caps[field_cap_id].emfc_match_affects_class) {
1491 if (memcmp(lvalp, rvalp, value_size) != 0) {
1492 have_same_class = B_FALSE;
1498 *have_same_classp = have_same_class;
1505 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1509 __checkReturn efx_rc_t
1510 efx_mae_outer_rule_insert(
1511 __in efx_nic_t *enp,
1512 __in const efx_mae_match_spec_t *spec,
1513 __in efx_tunnel_protocol_t encap_type,
1514 __out efx_mae_rule_id_t *or_idp)
1516 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1518 EFX_MCDI_DECLARE_BUF(payload,
1519 MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2,
1520 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
1521 uint32_t encap_type_mcdi;
1522 efx_mae_rule_id_t or_id;
1526 EFX_STATIC_ASSERT(sizeof (or_idp->id) ==
1527 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OR_ID_LEN);
1529 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1530 MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL);
1532 if (encp->enc_mae_supported == B_FALSE) {
1537 if (spec->emms_type != EFX_MAE_RULE_OUTER) {
1542 switch (encap_type) {
1543 case EFX_TUNNEL_PROTOCOL_NONE:
1544 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
1546 case EFX_TUNNEL_PROTOCOL_VXLAN:
1547 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
1549 case EFX_TUNNEL_PROTOCOL_GENEVE:
1550 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
1552 case EFX_TUNNEL_PROTOCOL_NVGRE:
1553 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
1560 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_INSERT;
1561 req.emr_in_buf = payload;
1562 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_INSERT_IN_LENMAX_MCDI2;
1563 req.emr_out_buf = payload;
1564 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN;
1566 MCDI_IN_SET_DWORD(req,
1567 MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, encap_type_mcdi);
1569 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_INSERT_IN_PRIO, spec->emms_prio);
1572 * Mask-value pairs have been stored in the byte order needed for the
1573 * MCDI request and are thus safe to be copied directly to the buffer.
1574 * The library cares about byte order in efx_mae_match_spec_field_set().
1576 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.outer) >=
1577 MAE_ENC_FIELD_PAIRS_LEN);
1578 offset = MC_CMD_MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA_OFST;
1579 memcpy(payload + offset, spec->emms_mask_value_pairs.outer,
1580 MAE_ENC_FIELD_PAIRS_LEN);
1582 efx_mcdi_execute(enp, &req);
1584 if (req.emr_rc != 0) {
1589 if (req.emr_out_length_used < MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN) {
1594 or_id.id = MCDI_OUT_DWORD(req, MAE_OUTER_RULE_INSERT_OUT_OR_ID);
1595 if (or_id.id == EFX_MAE_RSRC_ID_INVALID) {
1600 or_idp->id = or_id.id;
1615 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1619 __checkReturn efx_rc_t
1620 efx_mae_outer_rule_remove(
1621 __in efx_nic_t *enp,
1622 __in const efx_mae_rule_id_t *or_idp)
1624 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1626 EFX_MCDI_DECLARE_BUF(payload,
1627 MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1),
1628 MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
1631 if (encp->enc_mae_supported == B_FALSE) {
1636 req.emr_cmd = MC_CMD_MAE_OUTER_RULE_REMOVE;
1637 req.emr_in_buf = payload;
1638 req.emr_in_length = MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1);
1639 req.emr_out_buf = payload;
1640 req.emr_out_length = MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1);
1642 MCDI_IN_SET_DWORD(req, MAE_OUTER_RULE_REMOVE_IN_OR_ID, or_idp->id);
1644 efx_mcdi_execute(enp, &req);
1646 if (req.emr_rc != 0) {
1651 if (MCDI_OUT_DWORD(req, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) !=
1653 /* Firmware failed to remove the outer rule. */
1665 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1669 __checkReturn efx_rc_t
1670 efx_mae_match_spec_outer_rule_id_set(
1671 __in efx_mae_match_spec_t *spec,
1672 __in const efx_mae_rule_id_t *or_idp)
1674 uint32_t full_mask = UINT32_MAX;
1677 if (spec->emms_type != EFX_MAE_RULE_ACTION) {
1682 if (or_idp == NULL) {
1687 rc = efx_mae_match_spec_field_set(spec, EFX_MAE_FIELD_OUTER_RULE_ID,
1688 sizeof (or_idp->id), (const uint8_t *)&or_idp->id,
1689 sizeof (full_mask), (const uint8_t *)&full_mask);
1700 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1704 __checkReturn efx_rc_t
1705 efx_mae_encap_header_alloc(
1706 __in efx_nic_t *enp,
1707 __in efx_tunnel_protocol_t encap_type,
1708 __in_bcount(header_size) uint8_t *header_data,
1709 __in size_t header_size,
1710 __out efx_mae_eh_id_t *eh_idp)
1712 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1714 EFX_MCDI_DECLARE_BUF(payload,
1715 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LENMAX_MCDI2,
1716 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
1717 uint32_t encap_type_mcdi;
1718 efx_mae_eh_id_t eh_id;
1721 EFX_STATIC_ASSERT(sizeof (eh_idp->id) ==
1722 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_LEN);
1724 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1725 MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL);
1727 if (encp->enc_mae_supported == B_FALSE) {
1732 switch (encap_type) {
1733 case EFX_TUNNEL_PROTOCOL_NONE:
1734 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NONE;
1736 case EFX_TUNNEL_PROTOCOL_VXLAN:
1737 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_VXLAN;
1739 case EFX_TUNNEL_PROTOCOL_GENEVE:
1740 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_GENEVE;
1742 case EFX_TUNNEL_PROTOCOL_NVGRE:
1743 encap_type_mcdi = MAE_MCDI_ENCAP_TYPE_NVGRE;
1751 MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_MAXNUM_MCDI2) {
1756 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_ALLOC;
1757 req.emr_in_buf = payload;
1758 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(header_size);
1759 req.emr_out_buf = payload;
1760 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN;
1762 MCDI_IN_SET_DWORD(req,
1763 MAE_ENCAP_HEADER_ALLOC_IN_ENCAP_TYPE, encap_type_mcdi);
1765 memcpy(payload + MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_HDR_DATA_OFST,
1766 header_data, header_size);
1768 efx_mcdi_execute(enp, &req);
1770 if (req.emr_rc != 0) {
1775 if (req.emr_out_length_used < MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN) {
1780 eh_id.id = MCDI_OUT_DWORD(req,
1781 MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID);
1783 if (eh_id.id == EFX_MAE_RSRC_ID_INVALID) {
1788 eh_idp->id = eh_id.id;
1803 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1807 __checkReturn efx_rc_t
1808 efx_mae_encap_header_free(
1809 __in efx_nic_t *enp,
1810 __in const efx_mae_eh_id_t *eh_idp)
1812 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1814 EFX_MCDI_DECLARE_BUF(payload,
1815 MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1),
1816 MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
1819 if (encp->enc_mae_supported == B_FALSE) {
1824 req.emr_cmd = MC_CMD_MAE_ENCAP_HEADER_FREE;
1825 req.emr_in_buf = payload;
1826 req.emr_in_length = MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1);
1827 req.emr_out_buf = payload;
1828 req.emr_out_length = MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1);
1830 MCDI_IN_SET_DWORD(req, MAE_ENCAP_HEADER_FREE_IN_EH_ID, eh_idp->id);
1832 efx_mcdi_execute(enp, &req);
1834 if (req.emr_rc != 0) {
1839 if (MCDI_OUT_DWORD(req, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) !=
1841 /* Firmware failed to remove the encap. header. */
1853 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1857 __checkReturn efx_rc_t
1858 efx_mae_action_set_alloc(
1859 __in efx_nic_t *enp,
1860 __in const efx_mae_actions_t *spec,
1861 __out efx_mae_aset_id_t *aset_idp)
1863 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1865 EFX_MCDI_DECLARE_BUF(payload,
1866 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
1867 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
1868 efx_mae_aset_id_t aset_id;
1871 if (encp->enc_mae_supported == B_FALSE) {
1876 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
1877 req.emr_in_buf = payload;
1878 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
1879 req.emr_out_buf = payload;
1880 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
1883 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
1884 * corresponding resource types are supported by the implementation.
1885 * Use proper resource ID assignments instead.
1887 MCDI_IN_SET_DWORD(req,
1888 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
1889 MCDI_IN_SET_DWORD(req,
1890 MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1891 MCDI_IN_SET_DWORD(req,
1892 MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, EFX_MAE_RSRC_ID_INVALID);
1894 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1895 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
1897 if (spec->ema_n_vlan_tags_to_push > 0) {
1898 unsigned int outer_tag_idx;
1900 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1901 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
1902 spec->ema_n_vlan_tags_to_push);
1904 if (spec->ema_n_vlan_tags_to_push ==
1905 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1906 MCDI_IN_SET_WORD(req,
1907 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
1908 spec->ema_vlan_push_descs[0].emavp_tpid_be);
1909 MCDI_IN_SET_WORD(req,
1910 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
1911 spec->ema_vlan_push_descs[0].emavp_tci_be);
1914 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
1916 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
1917 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
1918 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
1919 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
1922 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
1923 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1924 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
1927 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
1928 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1929 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
1931 MCDI_IN_SET_DWORD(req,
1932 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
1935 MCDI_IN_SET_DWORD(req,
1936 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
1938 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
1939 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1940 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
1941 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1943 efx_mcdi_execute(enp, &req);
1945 if (req.emr_rc != 0) {
1950 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
1955 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
1956 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
1961 aset_idp->id = aset_id.id;
1972 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1976 __checkReturn efx_rc_t
1977 efx_mae_action_set_free(
1978 __in efx_nic_t *enp,
1979 __in const efx_mae_aset_id_t *aset_idp)
1981 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1983 EFX_MCDI_DECLARE_BUF(payload,
1984 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
1985 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
1988 if (encp->enc_mae_supported == B_FALSE) {
1993 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
1994 req.emr_in_buf = payload;
1995 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
1996 req.emr_out_buf = payload;
1997 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
1999 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
2001 efx_mcdi_execute(enp, &req);
2003 if (req.emr_rc != 0) {
2008 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
2010 /* Firmware failed to free the action set. */
2022 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2026 __checkReturn efx_rc_t
2027 efx_mae_action_rule_insert(
2028 __in efx_nic_t *enp,
2029 __in const efx_mae_match_spec_t *spec,
2030 __in const efx_mae_aset_list_id_t *asl_idp,
2031 __in const efx_mae_aset_id_t *as_idp,
2032 __out efx_mae_rule_id_t *ar_idp)
2034 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2036 EFX_MCDI_DECLARE_BUF(payload,
2037 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
2038 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
2039 efx_oword_t *rule_response;
2040 efx_mae_rule_id_t ar_id;
2044 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
2045 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
2047 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
2048 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
2050 if (encp->enc_mae_supported == B_FALSE) {
2055 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
2056 (asl_idp != NULL && as_idp != NULL) ||
2057 (asl_idp == NULL && as_idp == NULL)) {
2062 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
2063 req.emr_in_buf = payload;
2064 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
2065 req.emr_out_buf = payload;
2066 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
2068 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
2069 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
2070 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
2071 rule_response = (efx_oword_t *)(payload + offset);
2072 EFX_POPULATE_OWORD_3(*rule_response,
2073 MAE_ACTION_RULE_RESPONSE_ASL_ID,
2074 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
2075 MAE_ACTION_RULE_RESPONSE_AS_ID,
2076 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
2077 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
2079 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
2082 * Mask-value pairs have been stored in the byte order needed for the
2083 * MCDI request and are thus safe to be copied directly to the buffer.
2085 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
2086 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
2087 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
2088 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
2089 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
2091 efx_mcdi_execute(enp, &req);
2093 if (req.emr_rc != 0) {
2098 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
2103 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
2104 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
2109 ar_idp->id = ar_id.id;
2122 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2126 __checkReturn efx_rc_t
2127 efx_mae_action_rule_remove(
2128 __in efx_nic_t *enp,
2129 __in const efx_mae_rule_id_t *ar_idp)
2131 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
2133 EFX_MCDI_DECLARE_BUF(payload,
2134 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
2135 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
2138 if (encp->enc_mae_supported == B_FALSE) {
2143 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
2144 req.emr_in_buf = payload;
2145 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
2146 req.emr_out_buf = payload;
2147 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
2149 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
2151 efx_mcdi_execute(enp, &req);
2153 if (req.emr_rc != 0) {
2158 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
2160 /* Firmware failed to delete the action rule. */
2172 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2176 #endif /* EFSYS_OPT_MAE */