1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019 Xilinx, Inc. All rights reserved.
13 static __checkReturn efx_rc_t
14 efx_mae_get_capabilities(
18 EFX_MCDI_DECLARE_BUF(payload,
19 MC_CMD_MAE_GET_CAPS_IN_LEN,
20 MC_CMD_MAE_GET_CAPS_OUT_LEN);
21 struct efx_mae_s *maep = enp->en_maep;
24 req.emr_cmd = MC_CMD_MAE_GET_CAPS;
25 req.emr_in_buf = payload;
26 req.emr_in_length = MC_CMD_MAE_GET_CAPS_IN_LEN;
27 req.emr_out_buf = payload;
28 req.emr_out_length = MC_CMD_MAE_GET_CAPS_OUT_LEN;
30 efx_mcdi_execute(enp, &req);
32 if (req.emr_rc != 0) {
37 if (req.emr_out_length_used < MC_CMD_MAE_GET_CAPS_OUT_LEN) {
42 maep->em_max_n_action_prios =
43 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ACTION_PRIOS);
45 maep->em_max_nfields =
46 MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_MATCH_FIELD_COUNT);
53 EFSYS_PROBE1(fail1, efx_rc_t, rc);
57 static __checkReturn efx_rc_t
58 efx_mae_get_action_rule_caps(
60 __in unsigned int field_ncaps,
61 __out_ecount(field_ncaps) efx_mae_field_cap_t *field_caps)
64 EFX_MCDI_DECLARE_BUF(payload,
65 MC_CMD_MAE_GET_AR_CAPS_IN_LEN,
66 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2);
67 unsigned int mcdi_field_ncaps;
71 if (MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps) >
72 MC_CMD_MAE_GET_AR_CAPS_OUT_LENMAX_MCDI2) {
77 req.emr_cmd = MC_CMD_MAE_GET_AR_CAPS;
78 req.emr_in_buf = payload;
79 req.emr_in_length = MC_CMD_MAE_GET_AR_CAPS_IN_LEN;
80 req.emr_out_buf = payload;
81 req.emr_out_length = MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(field_ncaps);
83 efx_mcdi_execute(enp, &req);
85 if (req.emr_rc != 0) {
90 mcdi_field_ncaps = MCDI_OUT_DWORD(req, MAE_GET_OR_CAPS_OUT_COUNT);
92 if (req.emr_out_length_used <
93 MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(mcdi_field_ncaps)) {
98 if (mcdi_field_ncaps > field_ncaps) {
103 for (i = 0; i < mcdi_field_ncaps; ++i) {
107 field_caps[i].emfc_support = MCDI_OUT_INDEXED_DWORD_FIELD(req,
108 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
109 MAE_FIELD_FLAGS_SUPPORT_STATUS);
111 match_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
112 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
113 MAE_FIELD_FLAGS_MATCH_AFFECTS_CLASS);
115 field_caps[i].emfc_match_affects_class =
116 (match_flag != 0) ? B_TRUE : B_FALSE;
118 mask_flag = MCDI_OUT_INDEXED_DWORD_FIELD(req,
119 MAE_GET_AR_CAPS_OUT_FIELD_FLAGS, i,
120 MAE_FIELD_FLAGS_MASK_AFFECTS_CLASS);
122 field_caps[i].emfc_mask_affects_class =
123 (mask_flag != 0) ? B_TRUE : B_FALSE;
135 EFSYS_PROBE1(fail1, efx_rc_t, rc);
139 __checkReturn efx_rc_t
143 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
144 efx_mae_field_cap_t *ar_fcaps;
145 size_t ar_fcaps_size;
149 if (encp->enc_mae_supported == B_FALSE) {
154 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*maep), maep);
162 rc = efx_mae_get_capabilities(enp);
166 ar_fcaps_size = maep->em_max_nfields * sizeof (*ar_fcaps);
167 EFSYS_KMEM_ALLOC(enp->en_esip, ar_fcaps_size, ar_fcaps);
168 if (ar_fcaps == NULL) {
173 maep->em_action_rule_field_caps_size = ar_fcaps_size;
174 maep->em_action_rule_field_caps = ar_fcaps;
176 rc = efx_mae_get_action_rule_caps(enp, maep->em_max_nfields, ar_fcaps);
184 EFSYS_KMEM_FREE(enp->en_esip, ar_fcaps_size, ar_fcaps);
189 EFSYS_KMEM_FREE(enp->en_esip, sizeof (struct efx_mae_s), enp->en_maep);
194 EFSYS_PROBE1(fail1, efx_rc_t, rc);
202 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
203 efx_mae_t *maep = enp->en_maep;
205 if (encp->enc_mae_supported == B_FALSE)
208 EFSYS_KMEM_FREE(enp->en_esip, maep->em_action_rule_field_caps_size,
209 maep->em_action_rule_field_caps);
210 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*maep), maep);
214 __checkReturn efx_rc_t
217 __out efx_mae_limits_t *emlp)
219 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
220 struct efx_mae_s *maep = enp->en_maep;
223 if (encp->enc_mae_supported == B_FALSE) {
228 emlp->eml_max_n_action_prios = maep->em_max_n_action_prios;
233 EFSYS_PROBE1(fail1, efx_rc_t, rc);
237 __checkReturn efx_rc_t
238 efx_mae_match_spec_init(
240 __in efx_mae_rule_type_t type,
242 __out efx_mae_match_spec_t **specp)
244 efx_mae_match_spec_t *spec;
248 case EFX_MAE_RULE_ACTION:
255 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
261 spec->emms_type = type;
262 spec->emms_prio = prio;
271 EFSYS_PROBE1(fail1, efx_rc_t, rc);
276 efx_mae_match_spec_fini(
278 __in efx_mae_match_spec_t *spec)
280 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
283 /* Named identifiers which are valid indices to efx_mae_field_cap_t */
284 typedef enum efx_mae_field_cap_id_e {
285 EFX_MAE_FIELD_ID_INGRESS_MPORT_SELECTOR = MAE_FIELD_INGRESS_PORT,
286 EFX_MAE_FIELD_ID_ETHER_TYPE_BE = MAE_FIELD_ETHER_TYPE,
287 EFX_MAE_FIELD_ID_ETH_SADDR_BE = MAE_FIELD_ETH_SADDR,
288 EFX_MAE_FIELD_ID_ETH_DADDR_BE = MAE_FIELD_ETH_DADDR,
290 EFX_MAE_FIELD_CAP_NIDS
291 } efx_mae_field_cap_id_t;
293 typedef enum efx_mae_field_endianness_e {
294 EFX_MAE_FIELD_LE = 0,
297 EFX_MAE_FIELD_ENDIANNESS_NTYPES
298 } efx_mae_field_endianness_t;
301 * The following structure is a means to describe an MAE field.
302 * The information in it is meant to be used internally by
303 * APIs for addressing a given field in a mask-value pairs
304 * structure and for validation purposes.
306 typedef struct efx_mae_mv_desc_s {
307 efx_mae_field_cap_id_t emmd_field_cap_id;
309 size_t emmd_value_size;
310 size_t emmd_value_offset;
311 size_t emmd_mask_size;
312 size_t emmd_mask_offset;
314 efx_mae_field_endianness_t emmd_endianness;
317 /* Indices to this array are provided by efx_mae_field_id_t */
318 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
319 #define EFX_MAE_MV_DESC(_name, _endianness) \
320 [EFX_MAE_FIELD_##_name] = \
322 EFX_MAE_FIELD_ID_##_name, \
323 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
324 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
325 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
326 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
330 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
331 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
332 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
333 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
335 #undef EFX_MAE_MV_DESC
338 __checkReturn efx_rc_t
339 efx_mae_mport_by_phy_port(
340 __in uint32_t phy_port,
341 __out efx_mport_sel_t *mportp)
346 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
351 EFX_POPULATE_DWORD_2(dword,
352 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
353 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
355 memset(mportp, 0, sizeof (*mportp));
356 mportp->sel = dword.ed_u32[0];
361 EFSYS_PROBE1(fail1, efx_rc_t, rc);
365 __checkReturn efx_rc_t
366 efx_mae_match_spec_field_set(
367 __in efx_mae_match_spec_t *spec,
368 __in efx_mae_field_id_t field_id,
369 __in size_t value_size,
370 __in_bcount(value_size) const uint8_t *value,
371 __in size_t mask_size,
372 __in_bcount(mask_size) const uint8_t *mask)
374 const efx_mae_mv_desc_t *descp;
378 if (field_id >= EFX_MAE_FIELD_NIDS) {
383 switch (spec->emms_type) {
384 case EFX_MAE_RULE_ACTION:
385 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
386 mvp = spec->emms_mask_value_pairs.action;
393 if (value_size != descp->emmd_value_size) {
398 if (mask_size != descp->emmd_mask_size) {
403 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
405 * The mask/value are in network (big endian) order.
406 * The MCDI request field is also big endian.
408 memcpy(mvp + descp->emmd_value_offset, value, value_size);
409 memcpy(mvp + descp->emmd_mask_offset, mask, mask_size);
414 * The mask/value are in host byte order.
415 * The MCDI request field is little endian.
417 switch (value_size) {
419 EFX_POPULATE_DWORD_1(dword,
420 EFX_DWORD_0, *(const uint32_t *)value);
422 memcpy(mvp + descp->emmd_value_offset,
423 &dword, sizeof (dword));
426 EFSYS_ASSERT(B_FALSE);
431 EFX_POPULATE_DWORD_1(dword,
432 EFX_DWORD_0, *(const uint32_t *)mask);
434 memcpy(mvp + descp->emmd_mask_offset,
435 &dword, sizeof (dword));
438 EFSYS_ASSERT(B_FALSE);
451 EFSYS_PROBE1(fail1, efx_rc_t, rc);
455 __checkReturn efx_rc_t
456 efx_mae_match_spec_mport_set(
457 __in efx_mae_match_spec_t *spec,
458 __in const efx_mport_sel_t *valuep,
459 __in_opt const efx_mport_sel_t *maskp)
461 uint32_t full_mask = UINT32_MAX;
466 if (valuep == NULL) {
471 vp = (const uint8_t *)&valuep->sel;
473 mp = (const uint8_t *)&maskp->sel;
475 mp = (const uint8_t *)&full_mask;
477 rc = efx_mae_match_spec_field_set(spec,
478 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
479 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
488 EFSYS_PROBE1(fail1, efx_rc_t, rc);
492 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
493 ((_mask)[(_bit) / (_mask_page_nbits)] & \
494 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
496 static inline boolean_t
498 __in size_t mask_nbytes,
499 __in_bcount(mask_nbytes) const uint8_t *maskp)
501 boolean_t prev_bit_is_set = B_TRUE;
504 for (i = 0; i < 8 * mask_nbytes; ++i) {
505 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
507 if (!prev_bit_is_set && bit_is_set)
510 prev_bit_is_set = bit_is_set;
516 static inline boolean_t
517 efx_mask_is_all_ones(
518 __in size_t mask_nbytes,
519 __in_bcount(mask_nbytes) const uint8_t *maskp)
524 for (i = 0; i < mask_nbytes; ++i)
527 return (t == (uint8_t)(~0));
530 static inline boolean_t
531 efx_mask_is_all_zeros(
532 __in size_t mask_nbytes,
533 __in_bcount(mask_nbytes) const uint8_t *maskp)
538 for (i = 0; i < mask_nbytes; ++i)
544 __checkReturn boolean_t
545 efx_mae_match_spec_is_valid(
547 __in const efx_mae_match_spec_t *spec)
549 efx_mae_t *maep = enp->en_maep;
550 unsigned int field_ncaps = maep->em_max_nfields;
551 const efx_mae_field_cap_t *field_caps;
552 const efx_mae_mv_desc_t *desc_setp;
553 unsigned int desc_set_nentries;
554 boolean_t is_valid = B_TRUE;
555 efx_mae_field_id_t field_id;
558 switch (spec->emms_type) {
559 case EFX_MAE_RULE_ACTION:
560 field_caps = maep->em_action_rule_field_caps;
561 desc_setp = __efx_mae_action_rule_mv_desc_set;
563 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
564 mvp = spec->emms_mask_value_pairs.action;
570 if (field_caps == NULL)
573 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
574 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
575 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
576 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
577 size_t m_size = descp->emmd_mask_size;
580 continue; /* Skip array gap */
582 if (field_cap_id >= field_ncaps)
585 switch (field_caps[field_cap_id].emfc_support) {
586 case MAE_FIELD_SUPPORTED_MATCH_MASK:
589 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
590 is_valid = efx_mask_is_prefix(m_size, m_buf);
592 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
593 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
594 efx_mask_is_all_zeros(m_size, m_buf));
596 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
597 is_valid = efx_mask_is_all_ones(m_size, m_buf);
599 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
600 case MAE_FIELD_UNSUPPORTED:
602 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
606 if (is_valid == B_FALSE)
613 __checkReturn efx_rc_t
614 efx_mae_action_set_spec_init(
616 __out efx_mae_actions_t **specp)
618 efx_mae_actions_t *spec;
621 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
632 EFSYS_PROBE1(fail1, efx_rc_t, rc);
637 efx_mae_action_set_spec_fini(
639 __in efx_mae_actions_t *spec)
641 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
644 static __checkReturn efx_rc_t
645 efx_mae_action_set_add_vlan_pop(
646 __in efx_mae_actions_t *spec,
647 __in size_t arg_size,
648 __in_bcount(arg_size) const uint8_t *arg)
662 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
667 ++spec->ema_n_vlan_tags_to_pop;
676 EFSYS_PROBE1(fail1, efx_rc_t, rc);
680 static __checkReturn efx_rc_t
681 efx_mae_action_set_add_vlan_push(
682 __in efx_mae_actions_t *spec,
683 __in size_t arg_size,
684 __in_bcount(arg_size) const uint8_t *arg)
686 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
689 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
699 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
704 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
705 ++(spec->ema_n_vlan_tags_to_push);
714 EFSYS_PROBE1(fail1, efx_rc_t, rc);
718 static __checkReturn efx_rc_t
719 efx_mae_action_set_add_flag(
720 __in efx_mae_actions_t *spec,
721 __in size_t arg_size,
722 __in_bcount(arg_size) const uint8_t *arg)
726 _NOTE(ARGUNUSED(spec))
738 /* This action does not have any arguments, so do nothing here. */
745 EFSYS_PROBE1(fail1, efx_rc_t, rc);
749 static __checkReturn efx_rc_t
750 efx_mae_action_set_add_deliver(
751 __in efx_mae_actions_t *spec,
752 __in size_t arg_size,
753 __in_bcount(arg_size) const uint8_t *arg)
757 if (arg_size != sizeof (spec->ema_deliver_mport)) {
767 memcpy(&spec->ema_deliver_mport, arg, arg_size);
774 EFSYS_PROBE1(fail1, efx_rc_t, rc);
778 typedef struct efx_mae_action_desc_s {
779 /* Action specific handler */
780 efx_rc_t (*emad_add)(efx_mae_actions_t *,
781 size_t, const uint8_t *);
782 } efx_mae_action_desc_t;
784 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
785 [EFX_MAE_ACTION_VLAN_POP] = {
786 .emad_add = efx_mae_action_set_add_vlan_pop
788 [EFX_MAE_ACTION_VLAN_PUSH] = {
789 .emad_add = efx_mae_action_set_add_vlan_push
791 [EFX_MAE_ACTION_FLAG] = {
792 .emad_add = efx_mae_action_set_add_flag
794 [EFX_MAE_ACTION_DELIVER] = {
795 .emad_add = efx_mae_action_set_add_deliver
799 static const uint32_t efx_mae_action_ordered_map =
800 (1U << EFX_MAE_ACTION_VLAN_POP) |
801 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
802 (1U << EFX_MAE_ACTION_FLAG) |
803 (1U << EFX_MAE_ACTION_DELIVER);
806 * These actions must not be added after DELIVER, but
807 * they can have any place among the rest of
808 * strictly ordered actions.
810 static const uint32_t efx_mae_action_nonstrict_map =
811 (1U << EFX_MAE_ACTION_FLAG);
813 static const uint32_t efx_mae_action_repeat_map =
814 (1U << EFX_MAE_ACTION_VLAN_POP) |
815 (1U << EFX_MAE_ACTION_VLAN_PUSH);
818 * Add an action to an action set.
820 * This has to be invoked in the desired action order.
821 * An out-of-order action request will be turned down.
823 static __checkReturn efx_rc_t
824 efx_mae_action_set_spec_populate(
825 __in efx_mae_actions_t *spec,
826 __in efx_mae_action_t type,
827 __in size_t arg_size,
828 __in_bcount(arg_size) const uint8_t *arg)
830 uint32_t action_mask;
833 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
834 (sizeof (efx_mae_action_ordered_map) * 8));
835 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
836 (sizeof (efx_mae_action_repeat_map) * 8));
838 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
839 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_DELIVER);
841 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
846 action_mask = (1U << type);
848 if ((spec->ema_actions & action_mask) != 0) {
849 /* The action set already contains this action. */
850 if ((efx_mae_action_repeat_map & action_mask) == 0) {
851 /* Cannot add another non-repeatable action. */
857 if ((efx_mae_action_ordered_map & action_mask) != 0) {
858 uint32_t strict_ordered_map =
859 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
860 uint32_t later_actions_mask =
861 strict_ordered_map & ~(action_mask | (action_mask - 1));
863 if ((spec->ema_actions & later_actions_mask) != 0) {
864 /* Cannot add an action after later ordered actions. */
870 if (efx_mae_actions[type].emad_add != NULL) {
871 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
876 spec->ema_actions |= action_mask;
887 EFSYS_PROBE1(fail1, efx_rc_t, rc);
891 __checkReturn efx_rc_t
892 efx_mae_action_set_populate_vlan_pop(
893 __in efx_mae_actions_t *spec)
895 return (efx_mae_action_set_spec_populate(spec,
896 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
899 __checkReturn efx_rc_t
900 efx_mae_action_set_populate_vlan_push(
901 __in efx_mae_actions_t *spec,
902 __in uint16_t tpid_be,
903 __in uint16_t tci_be)
905 efx_mae_action_vlan_push_t action;
906 const uint8_t *arg = (const uint8_t *)&action;
908 action.emavp_tpid_be = tpid_be;
909 action.emavp_tci_be = tci_be;
911 return (efx_mae_action_set_spec_populate(spec,
912 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
915 __checkReturn efx_rc_t
916 efx_mae_action_set_populate_flag(
917 __in efx_mae_actions_t *spec)
919 return (efx_mae_action_set_spec_populate(spec,
920 EFX_MAE_ACTION_FLAG, 0, NULL));
923 __checkReturn efx_rc_t
924 efx_mae_action_set_populate_deliver(
925 __in efx_mae_actions_t *spec,
926 __in const efx_mport_sel_t *mportp)
931 if (mportp == NULL) {
936 arg = (const uint8_t *)&mportp->sel;
938 return (efx_mae_action_set_spec_populate(spec,
939 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
942 EFSYS_PROBE1(fail1, efx_rc_t, rc);
946 __checkReturn boolean_t
947 efx_mae_action_set_specs_equal(
948 __in const efx_mae_actions_t *left,
949 __in const efx_mae_actions_t *right)
951 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
954 __checkReturn efx_rc_t
955 efx_mae_match_specs_class_cmp(
957 __in const efx_mae_match_spec_t *left,
958 __in const efx_mae_match_spec_t *right,
959 __out boolean_t *have_same_classp)
961 efx_mae_t *maep = enp->en_maep;
962 unsigned int field_ncaps = maep->em_max_nfields;
963 const efx_mae_field_cap_t *field_caps;
964 const efx_mae_mv_desc_t *desc_setp;
965 unsigned int desc_set_nentries;
966 boolean_t have_same_class = B_TRUE;
967 efx_mae_field_id_t field_id;
972 switch (left->emms_type) {
973 case EFX_MAE_RULE_ACTION:
974 field_caps = maep->em_action_rule_field_caps;
975 desc_setp = __efx_mae_action_rule_mv_desc_set;
977 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
978 mvpl = left->emms_mask_value_pairs.action;
979 mvpr = right->emms_mask_value_pairs.action;
986 if (field_caps == NULL) {
991 if (left->emms_type != right->emms_type ||
992 left->emms_prio != right->emms_prio) {
994 * Rules of different types can never map to the same class.
996 * The FW can support some set of match criteria for one
997 * priority and not support the very same set for
998 * another priority. Thus, two rules which have
999 * different priorities can never map to
1002 *have_same_classp = B_FALSE;
1006 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
1007 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1008 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1010 if (descp->emmd_mask_size == 0)
1011 continue; /* Skip array gap */
1013 if (field_cap_id >= field_ncaps)
1016 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1017 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1018 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1019 size_t mask_size = descp->emmd_mask_size;
1021 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1022 have_same_class = B_FALSE;
1027 if (field_caps[field_cap_id].emfc_match_affects_class) {
1028 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1029 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1030 size_t value_size = descp->emmd_value_size;
1032 if (memcmp(lvalp, rvalp, value_size) != 0) {
1033 have_same_class = B_FALSE;
1039 *have_same_classp = have_same_class;
1046 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1050 __checkReturn efx_rc_t
1051 efx_mae_action_set_alloc(
1052 __in efx_nic_t *enp,
1053 __in const efx_mae_actions_t *spec,
1054 __out efx_mae_aset_id_t *aset_idp)
1056 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1058 EFX_MCDI_DECLARE_BUF(payload,
1059 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
1060 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
1061 efx_mae_aset_id_t aset_id;
1064 if (encp->enc_mae_supported == B_FALSE) {
1069 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
1070 req.emr_in_buf = payload;
1071 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
1072 req.emr_out_buf = payload;
1073 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
1076 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
1077 * corresponding resource types are supported by the implementation.
1078 * Use proper resource ID assignments instead.
1080 MCDI_IN_SET_DWORD(req,
1081 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
1082 MCDI_IN_SET_DWORD(req,
1083 MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1084 MCDI_IN_SET_DWORD(req,
1085 MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, EFX_MAE_RSRC_ID_INVALID);
1087 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1088 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
1090 if (spec->ema_n_vlan_tags_to_push > 0) {
1091 unsigned int outer_tag_idx;
1093 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1094 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
1095 spec->ema_n_vlan_tags_to_push);
1097 if (spec->ema_n_vlan_tags_to_push ==
1098 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1099 MCDI_IN_SET_WORD(req,
1100 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
1101 spec->ema_vlan_push_descs[0].emavp_tpid_be);
1102 MCDI_IN_SET_WORD(req,
1103 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
1104 spec->ema_vlan_push_descs[0].emavp_tci_be);
1107 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
1109 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
1110 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
1111 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
1112 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
1115 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
1116 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1117 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
1120 MCDI_IN_SET_DWORD(req,
1121 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
1123 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
1124 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1125 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
1126 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1128 efx_mcdi_execute(enp, &req);
1130 if (req.emr_rc != 0) {
1135 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
1140 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
1141 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
1146 aset_idp->id = aset_id.id;
1157 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1161 __checkReturn efx_rc_t
1162 efx_mae_action_set_free(
1163 __in efx_nic_t *enp,
1164 __in const efx_mae_aset_id_t *aset_idp)
1166 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1168 EFX_MCDI_DECLARE_BUF(payload,
1169 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
1170 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
1173 if (encp->enc_mae_supported == B_FALSE) {
1178 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
1179 req.emr_in_buf = payload;
1180 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
1181 req.emr_out_buf = payload;
1182 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
1184 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
1186 efx_mcdi_execute(enp, &req);
1188 if (req.emr_rc != 0) {
1193 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
1195 /* Firmware failed to free the action set. */
1207 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1211 __checkReturn efx_rc_t
1212 efx_mae_action_rule_insert(
1213 __in efx_nic_t *enp,
1214 __in const efx_mae_match_spec_t *spec,
1215 __in const efx_mae_aset_list_id_t *asl_idp,
1216 __in const efx_mae_aset_id_t *as_idp,
1217 __out efx_mae_rule_id_t *ar_idp)
1219 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1221 EFX_MCDI_DECLARE_BUF(payload,
1222 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
1223 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
1224 efx_oword_t *rule_response;
1225 efx_mae_rule_id_t ar_id;
1229 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
1230 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
1232 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1233 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
1235 if (encp->enc_mae_supported == B_FALSE) {
1240 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
1241 (asl_idp != NULL && as_idp != NULL) ||
1242 (asl_idp == NULL && as_idp == NULL)) {
1247 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
1248 req.emr_in_buf = payload;
1249 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
1250 req.emr_out_buf = payload;
1251 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
1253 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
1254 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
1255 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
1256 rule_response = (efx_oword_t *)(payload + offset);
1257 EFX_POPULATE_OWORD_3(*rule_response,
1258 MAE_ACTION_RULE_RESPONSE_ASL_ID,
1259 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
1260 MAE_ACTION_RULE_RESPONSE_AS_ID,
1261 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
1262 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1264 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
1267 * Mask-value pairs have been stored in the byte order needed for the
1268 * MCDI request and are thus safe to be copied directly to the buffer.
1270 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
1271 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1272 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
1273 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
1274 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1276 efx_mcdi_execute(enp, &req);
1278 if (req.emr_rc != 0) {
1283 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
1288 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
1289 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
1294 ar_idp->id = ar_id.id;
1307 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1311 __checkReturn efx_rc_t
1312 efx_mae_action_rule_remove(
1313 __in efx_nic_t *enp,
1314 __in const efx_mae_rule_id_t *ar_idp)
1316 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1318 EFX_MCDI_DECLARE_BUF(payload,
1319 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
1320 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
1323 if (encp->enc_mae_supported == B_FALSE) {
1328 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
1329 req.emr_in_buf = payload;
1330 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
1331 req.emr_out_buf = payload;
1332 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
1334 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
1336 efx_mcdi_execute(enp, &req);
1338 if (req.emr_rc != 0) {
1343 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
1345 /* Firmware failed to delete the action rule. */
1357 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1361 #endif /* EFSYS_OPT_MAE */