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,
289 EFX_MAE_FIELD_ID_VLAN0_TCI_BE = MAE_FIELD_VLAN0_TCI,
290 EFX_MAE_FIELD_ID_VLAN0_PROTO_BE = MAE_FIELD_VLAN0_PROTO,
291 EFX_MAE_FIELD_ID_VLAN1_TCI_BE = MAE_FIELD_VLAN1_TCI,
292 EFX_MAE_FIELD_ID_VLAN1_PROTO_BE = MAE_FIELD_VLAN1_PROTO,
294 EFX_MAE_FIELD_CAP_NIDS
295 } efx_mae_field_cap_id_t;
297 typedef enum efx_mae_field_endianness_e {
298 EFX_MAE_FIELD_LE = 0,
301 EFX_MAE_FIELD_ENDIANNESS_NTYPES
302 } efx_mae_field_endianness_t;
305 * The following structure is a means to describe an MAE field.
306 * The information in it is meant to be used internally by
307 * APIs for addressing a given field in a mask-value pairs
308 * structure and for validation purposes.
310 typedef struct efx_mae_mv_desc_s {
311 efx_mae_field_cap_id_t emmd_field_cap_id;
313 size_t emmd_value_size;
314 size_t emmd_value_offset;
315 size_t emmd_mask_size;
316 size_t emmd_mask_offset;
318 efx_mae_field_endianness_t emmd_endianness;
321 /* Indices to this array are provided by efx_mae_field_id_t */
322 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
323 #define EFX_MAE_MV_DESC(_name, _endianness) \
324 [EFX_MAE_FIELD_##_name] = \
326 EFX_MAE_FIELD_ID_##_name, \
327 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
328 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
329 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
330 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
334 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
335 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
336 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
337 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
338 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
339 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
340 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
341 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
343 #undef EFX_MAE_MV_DESC
346 __checkReturn efx_rc_t
347 efx_mae_mport_by_phy_port(
348 __in uint32_t phy_port,
349 __out efx_mport_sel_t *mportp)
354 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
359 EFX_POPULATE_DWORD_2(dword,
360 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
361 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
363 memset(mportp, 0, sizeof (*mportp));
364 mportp->sel = dword.ed_u32[0];
369 EFSYS_PROBE1(fail1, efx_rc_t, rc);
373 __checkReturn efx_rc_t
374 efx_mae_mport_by_pcie_function(
377 __out efx_mport_sel_t *mportp)
382 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
383 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
385 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_PF_ID)) {
390 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
395 EFX_POPULATE_DWORD_3(dword,
396 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_FUNC,
397 MAE_MPORT_SELECTOR_FUNC_PF_ID, pf,
398 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
400 memset(mportp, 0, sizeof (*mportp));
401 mportp->sel = dword.ed_u32[0];
408 EFSYS_PROBE1(fail1, efx_rc_t, rc);
412 __checkReturn efx_rc_t
413 efx_mae_match_spec_field_set(
414 __in efx_mae_match_spec_t *spec,
415 __in efx_mae_field_id_t field_id,
416 __in size_t value_size,
417 __in_bcount(value_size) const uint8_t *value,
418 __in size_t mask_size,
419 __in_bcount(mask_size) const uint8_t *mask)
421 const efx_mae_mv_desc_t *descp;
425 if (field_id >= EFX_MAE_FIELD_NIDS) {
430 switch (spec->emms_type) {
431 case EFX_MAE_RULE_ACTION:
432 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
433 mvp = spec->emms_mask_value_pairs.action;
440 if (value_size != descp->emmd_value_size) {
445 if (mask_size != descp->emmd_mask_size) {
450 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
452 * The mask/value are in network (big endian) order.
453 * The MCDI request field is also big endian.
455 memcpy(mvp + descp->emmd_value_offset, value, value_size);
456 memcpy(mvp + descp->emmd_mask_offset, mask, mask_size);
461 * The mask/value are in host byte order.
462 * The MCDI request field is little endian.
464 switch (value_size) {
466 EFX_POPULATE_DWORD_1(dword,
467 EFX_DWORD_0, *(const uint32_t *)value);
469 memcpy(mvp + descp->emmd_value_offset,
470 &dword, sizeof (dword));
473 EFSYS_ASSERT(B_FALSE);
478 EFX_POPULATE_DWORD_1(dword,
479 EFX_DWORD_0, *(const uint32_t *)mask);
481 memcpy(mvp + descp->emmd_mask_offset,
482 &dword, sizeof (dword));
485 EFSYS_ASSERT(B_FALSE);
498 EFSYS_PROBE1(fail1, efx_rc_t, rc);
502 __checkReturn efx_rc_t
503 efx_mae_match_spec_mport_set(
504 __in efx_mae_match_spec_t *spec,
505 __in const efx_mport_sel_t *valuep,
506 __in_opt const efx_mport_sel_t *maskp)
508 uint32_t full_mask = UINT32_MAX;
513 if (valuep == NULL) {
518 vp = (const uint8_t *)&valuep->sel;
520 mp = (const uint8_t *)&maskp->sel;
522 mp = (const uint8_t *)&full_mask;
524 rc = efx_mae_match_spec_field_set(spec,
525 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
526 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
535 EFSYS_PROBE1(fail1, efx_rc_t, rc);
539 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
540 ((_mask)[(_bit) / (_mask_page_nbits)] & \
541 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
543 static inline boolean_t
545 __in size_t mask_nbytes,
546 __in_bcount(mask_nbytes) const uint8_t *maskp)
548 boolean_t prev_bit_is_set = B_TRUE;
551 for (i = 0; i < 8 * mask_nbytes; ++i) {
552 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
554 if (!prev_bit_is_set && bit_is_set)
557 prev_bit_is_set = bit_is_set;
563 static inline boolean_t
564 efx_mask_is_all_ones(
565 __in size_t mask_nbytes,
566 __in_bcount(mask_nbytes) const uint8_t *maskp)
571 for (i = 0; i < mask_nbytes; ++i)
574 return (t == (uint8_t)(~0));
577 static inline boolean_t
578 efx_mask_is_all_zeros(
579 __in size_t mask_nbytes,
580 __in_bcount(mask_nbytes) const uint8_t *maskp)
585 for (i = 0; i < mask_nbytes; ++i)
591 __checkReturn boolean_t
592 efx_mae_match_spec_is_valid(
594 __in const efx_mae_match_spec_t *spec)
596 efx_mae_t *maep = enp->en_maep;
597 unsigned int field_ncaps = maep->em_max_nfields;
598 const efx_mae_field_cap_t *field_caps;
599 const efx_mae_mv_desc_t *desc_setp;
600 unsigned int desc_set_nentries;
601 boolean_t is_valid = B_TRUE;
602 efx_mae_field_id_t field_id;
605 switch (spec->emms_type) {
606 case EFX_MAE_RULE_ACTION:
607 field_caps = maep->em_action_rule_field_caps;
608 desc_setp = __efx_mae_action_rule_mv_desc_set;
610 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
611 mvp = spec->emms_mask_value_pairs.action;
617 if (field_caps == NULL)
620 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
621 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
622 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
623 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
624 size_t m_size = descp->emmd_mask_size;
627 continue; /* Skip array gap */
629 if (field_cap_id >= field_ncaps)
632 switch (field_caps[field_cap_id].emfc_support) {
633 case MAE_FIELD_SUPPORTED_MATCH_MASK:
636 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
637 is_valid = efx_mask_is_prefix(m_size, m_buf);
639 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
640 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
641 efx_mask_is_all_zeros(m_size, m_buf));
643 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
644 is_valid = efx_mask_is_all_ones(m_size, m_buf);
646 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
647 case MAE_FIELD_UNSUPPORTED:
649 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
653 if (is_valid == B_FALSE)
660 __checkReturn efx_rc_t
661 efx_mae_action_set_spec_init(
663 __out efx_mae_actions_t **specp)
665 efx_mae_actions_t *spec;
668 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
679 EFSYS_PROBE1(fail1, efx_rc_t, rc);
684 efx_mae_action_set_spec_fini(
686 __in efx_mae_actions_t *spec)
688 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
691 static __checkReturn efx_rc_t
692 efx_mae_action_set_add_vlan_pop(
693 __in efx_mae_actions_t *spec,
694 __in size_t arg_size,
695 __in_bcount(arg_size) const uint8_t *arg)
709 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
714 ++spec->ema_n_vlan_tags_to_pop;
723 EFSYS_PROBE1(fail1, efx_rc_t, rc);
727 static __checkReturn efx_rc_t
728 efx_mae_action_set_add_vlan_push(
729 __in efx_mae_actions_t *spec,
730 __in size_t arg_size,
731 __in_bcount(arg_size) const uint8_t *arg)
733 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
736 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
746 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
751 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
752 ++(spec->ema_n_vlan_tags_to_push);
761 EFSYS_PROBE1(fail1, efx_rc_t, rc);
765 static __checkReturn efx_rc_t
766 efx_mae_action_set_add_flag(
767 __in efx_mae_actions_t *spec,
768 __in size_t arg_size,
769 __in_bcount(arg_size) const uint8_t *arg)
773 _NOTE(ARGUNUSED(spec))
785 /* This action does not have any arguments, so do nothing here. */
792 EFSYS_PROBE1(fail1, efx_rc_t, rc);
796 static __checkReturn efx_rc_t
797 efx_mae_action_set_add_mark(
798 __in efx_mae_actions_t *spec,
799 __in size_t arg_size,
800 __in_bcount(arg_size) const uint8_t *arg)
804 if (arg_size != sizeof (spec->ema_mark_value)) {
814 memcpy(&spec->ema_mark_value, arg, arg_size);
821 EFSYS_PROBE1(fail1, efx_rc_t, rc);
825 static __checkReturn efx_rc_t
826 efx_mae_action_set_add_deliver(
827 __in efx_mae_actions_t *spec,
828 __in size_t arg_size,
829 __in_bcount(arg_size) const uint8_t *arg)
833 if (arg_size != sizeof (spec->ema_deliver_mport)) {
843 memcpy(&spec->ema_deliver_mport, arg, arg_size);
850 EFSYS_PROBE1(fail1, efx_rc_t, rc);
854 typedef struct efx_mae_action_desc_s {
855 /* Action specific handler */
856 efx_rc_t (*emad_add)(efx_mae_actions_t *,
857 size_t, const uint8_t *);
858 } efx_mae_action_desc_t;
860 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
861 [EFX_MAE_ACTION_VLAN_POP] = {
862 .emad_add = efx_mae_action_set_add_vlan_pop
864 [EFX_MAE_ACTION_VLAN_PUSH] = {
865 .emad_add = efx_mae_action_set_add_vlan_push
867 [EFX_MAE_ACTION_FLAG] = {
868 .emad_add = efx_mae_action_set_add_flag
870 [EFX_MAE_ACTION_MARK] = {
871 .emad_add = efx_mae_action_set_add_mark
873 [EFX_MAE_ACTION_DELIVER] = {
874 .emad_add = efx_mae_action_set_add_deliver
878 static const uint32_t efx_mae_action_ordered_map =
879 (1U << EFX_MAE_ACTION_VLAN_POP) |
880 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
881 (1U << EFX_MAE_ACTION_FLAG) |
882 (1U << EFX_MAE_ACTION_MARK) |
883 (1U << EFX_MAE_ACTION_DELIVER);
886 * These actions must not be added after DELIVER, but
887 * they can have any place among the rest of
888 * strictly ordered actions.
890 static const uint32_t efx_mae_action_nonstrict_map =
891 (1U << EFX_MAE_ACTION_FLAG) |
892 (1U << EFX_MAE_ACTION_MARK);
894 static const uint32_t efx_mae_action_repeat_map =
895 (1U << EFX_MAE_ACTION_VLAN_POP) |
896 (1U << EFX_MAE_ACTION_VLAN_PUSH);
899 * Add an action to an action set.
901 * This has to be invoked in the desired action order.
902 * An out-of-order action request will be turned down.
904 static __checkReturn efx_rc_t
905 efx_mae_action_set_spec_populate(
906 __in efx_mae_actions_t *spec,
907 __in efx_mae_action_t type,
908 __in size_t arg_size,
909 __in_bcount(arg_size) const uint8_t *arg)
911 uint32_t action_mask;
914 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
915 (sizeof (efx_mae_action_ordered_map) * 8));
916 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
917 (sizeof (efx_mae_action_repeat_map) * 8));
919 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
920 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
921 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
923 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
928 action_mask = (1U << type);
930 if ((spec->ema_actions & action_mask) != 0) {
931 /* The action set already contains this action. */
932 if ((efx_mae_action_repeat_map & action_mask) == 0) {
933 /* Cannot add another non-repeatable action. */
939 if ((efx_mae_action_ordered_map & action_mask) != 0) {
940 uint32_t strict_ordered_map =
941 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
942 uint32_t later_actions_mask =
943 strict_ordered_map & ~(action_mask | (action_mask - 1));
945 if ((spec->ema_actions & later_actions_mask) != 0) {
946 /* Cannot add an action after later ordered actions. */
952 if (efx_mae_actions[type].emad_add != NULL) {
953 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
958 spec->ema_actions |= action_mask;
969 EFSYS_PROBE1(fail1, efx_rc_t, rc);
973 __checkReturn efx_rc_t
974 efx_mae_action_set_populate_vlan_pop(
975 __in efx_mae_actions_t *spec)
977 return (efx_mae_action_set_spec_populate(spec,
978 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
981 __checkReturn efx_rc_t
982 efx_mae_action_set_populate_vlan_push(
983 __in efx_mae_actions_t *spec,
984 __in uint16_t tpid_be,
985 __in uint16_t tci_be)
987 efx_mae_action_vlan_push_t action;
988 const uint8_t *arg = (const uint8_t *)&action;
990 action.emavp_tpid_be = tpid_be;
991 action.emavp_tci_be = tci_be;
993 return (efx_mae_action_set_spec_populate(spec,
994 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
997 __checkReturn efx_rc_t
998 efx_mae_action_set_populate_flag(
999 __in efx_mae_actions_t *spec)
1001 return (efx_mae_action_set_spec_populate(spec,
1002 EFX_MAE_ACTION_FLAG, 0, NULL));
1005 __checkReturn efx_rc_t
1006 efx_mae_action_set_populate_mark(
1007 __in efx_mae_actions_t *spec,
1008 __in uint32_t mark_value)
1010 const uint8_t *arg = (const uint8_t *)&mark_value;
1012 return (efx_mae_action_set_spec_populate(spec,
1013 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1016 __checkReturn efx_rc_t
1017 efx_mae_action_set_populate_deliver(
1018 __in efx_mae_actions_t *spec,
1019 __in const efx_mport_sel_t *mportp)
1024 if (mportp == NULL) {
1029 arg = (const uint8_t *)&mportp->sel;
1031 return (efx_mae_action_set_spec_populate(spec,
1032 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1035 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1039 __checkReturn efx_rc_t
1040 efx_mae_action_set_populate_drop(
1041 __in efx_mae_actions_t *spec)
1043 efx_mport_sel_t mport;
1047 EFX_POPULATE_DWORD_1(dword,
1048 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1050 mport.sel = dword.ed_u32[0];
1052 arg = (const uint8_t *)&mport.sel;
1054 return (efx_mae_action_set_spec_populate(spec,
1055 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1058 __checkReturn boolean_t
1059 efx_mae_action_set_specs_equal(
1060 __in const efx_mae_actions_t *left,
1061 __in const efx_mae_actions_t *right)
1063 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1066 __checkReturn efx_rc_t
1067 efx_mae_match_specs_class_cmp(
1068 __in efx_nic_t *enp,
1069 __in const efx_mae_match_spec_t *left,
1070 __in const efx_mae_match_spec_t *right,
1071 __out boolean_t *have_same_classp)
1073 efx_mae_t *maep = enp->en_maep;
1074 unsigned int field_ncaps = maep->em_max_nfields;
1075 const efx_mae_field_cap_t *field_caps;
1076 const efx_mae_mv_desc_t *desc_setp;
1077 unsigned int desc_set_nentries;
1078 boolean_t have_same_class = B_TRUE;
1079 efx_mae_field_id_t field_id;
1080 const uint8_t *mvpl;
1081 const uint8_t *mvpr;
1084 switch (left->emms_type) {
1085 case EFX_MAE_RULE_ACTION:
1086 field_caps = maep->em_action_rule_field_caps;
1087 desc_setp = __efx_mae_action_rule_mv_desc_set;
1089 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1090 mvpl = left->emms_mask_value_pairs.action;
1091 mvpr = right->emms_mask_value_pairs.action;
1098 if (field_caps == NULL) {
1103 if (left->emms_type != right->emms_type ||
1104 left->emms_prio != right->emms_prio) {
1106 * Rules of different types can never map to the same class.
1108 * The FW can support some set of match criteria for one
1109 * priority and not support the very same set for
1110 * another priority. Thus, two rules which have
1111 * different priorities can never map to
1114 *have_same_classp = B_FALSE;
1118 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
1119 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1120 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1122 if (descp->emmd_mask_size == 0)
1123 continue; /* Skip array gap */
1125 if (field_cap_id >= field_ncaps)
1128 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1129 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1130 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1131 size_t mask_size = descp->emmd_mask_size;
1133 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1134 have_same_class = B_FALSE;
1139 if (field_caps[field_cap_id].emfc_match_affects_class) {
1140 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1141 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1142 size_t value_size = descp->emmd_value_size;
1144 if (memcmp(lvalp, rvalp, value_size) != 0) {
1145 have_same_class = B_FALSE;
1151 *have_same_classp = have_same_class;
1158 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1162 __checkReturn efx_rc_t
1163 efx_mae_action_set_alloc(
1164 __in efx_nic_t *enp,
1165 __in const efx_mae_actions_t *spec,
1166 __out efx_mae_aset_id_t *aset_idp)
1168 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1170 EFX_MCDI_DECLARE_BUF(payload,
1171 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
1172 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
1173 efx_mae_aset_id_t aset_id;
1176 if (encp->enc_mae_supported == B_FALSE) {
1181 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
1182 req.emr_in_buf = payload;
1183 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
1184 req.emr_out_buf = payload;
1185 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
1188 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
1189 * corresponding resource types are supported by the implementation.
1190 * Use proper resource ID assignments instead.
1192 MCDI_IN_SET_DWORD(req,
1193 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
1194 MCDI_IN_SET_DWORD(req,
1195 MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1196 MCDI_IN_SET_DWORD(req,
1197 MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, EFX_MAE_RSRC_ID_INVALID);
1199 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1200 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
1202 if (spec->ema_n_vlan_tags_to_push > 0) {
1203 unsigned int outer_tag_idx;
1205 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1206 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
1207 spec->ema_n_vlan_tags_to_push);
1209 if (spec->ema_n_vlan_tags_to_push ==
1210 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1211 MCDI_IN_SET_WORD(req,
1212 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
1213 spec->ema_vlan_push_descs[0].emavp_tpid_be);
1214 MCDI_IN_SET_WORD(req,
1215 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
1216 spec->ema_vlan_push_descs[0].emavp_tci_be);
1219 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
1221 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
1222 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
1223 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
1224 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
1227 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
1228 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1229 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
1232 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
1233 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1234 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
1236 MCDI_IN_SET_DWORD(req,
1237 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
1240 MCDI_IN_SET_DWORD(req,
1241 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
1243 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
1244 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1245 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
1246 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1248 efx_mcdi_execute(enp, &req);
1250 if (req.emr_rc != 0) {
1255 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
1260 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
1261 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
1266 aset_idp->id = aset_id.id;
1277 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1281 __checkReturn efx_rc_t
1282 efx_mae_action_set_free(
1283 __in efx_nic_t *enp,
1284 __in const efx_mae_aset_id_t *aset_idp)
1286 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1288 EFX_MCDI_DECLARE_BUF(payload,
1289 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
1290 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
1293 if (encp->enc_mae_supported == B_FALSE) {
1298 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
1299 req.emr_in_buf = payload;
1300 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
1301 req.emr_out_buf = payload;
1302 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
1304 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
1306 efx_mcdi_execute(enp, &req);
1308 if (req.emr_rc != 0) {
1313 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
1315 /* Firmware failed to free the action set. */
1327 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1331 __checkReturn efx_rc_t
1332 efx_mae_action_rule_insert(
1333 __in efx_nic_t *enp,
1334 __in const efx_mae_match_spec_t *spec,
1335 __in const efx_mae_aset_list_id_t *asl_idp,
1336 __in const efx_mae_aset_id_t *as_idp,
1337 __out efx_mae_rule_id_t *ar_idp)
1339 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1341 EFX_MCDI_DECLARE_BUF(payload,
1342 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
1343 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
1344 efx_oword_t *rule_response;
1345 efx_mae_rule_id_t ar_id;
1349 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
1350 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
1352 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1353 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
1355 if (encp->enc_mae_supported == B_FALSE) {
1360 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
1361 (asl_idp != NULL && as_idp != NULL) ||
1362 (asl_idp == NULL && as_idp == NULL)) {
1367 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
1368 req.emr_in_buf = payload;
1369 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
1370 req.emr_out_buf = payload;
1371 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
1373 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
1374 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
1375 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
1376 rule_response = (efx_oword_t *)(payload + offset);
1377 EFX_POPULATE_OWORD_3(*rule_response,
1378 MAE_ACTION_RULE_RESPONSE_ASL_ID,
1379 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
1380 MAE_ACTION_RULE_RESPONSE_AS_ID,
1381 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
1382 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1384 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
1387 * Mask-value pairs have been stored in the byte order needed for the
1388 * MCDI request and are thus safe to be copied directly to the buffer.
1390 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
1391 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1392 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
1393 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
1394 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1396 efx_mcdi_execute(enp, &req);
1398 if (req.emr_rc != 0) {
1403 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
1408 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
1409 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
1414 ar_idp->id = ar_id.id;
1427 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1431 __checkReturn efx_rc_t
1432 efx_mae_action_rule_remove(
1433 __in efx_nic_t *enp,
1434 __in const efx_mae_rule_id_t *ar_idp)
1436 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1438 EFX_MCDI_DECLARE_BUF(payload,
1439 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
1440 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
1443 if (encp->enc_mae_supported == B_FALSE) {
1448 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
1449 req.emr_in_buf = payload;
1450 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
1451 req.emr_out_buf = payload;
1452 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
1454 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
1456 efx_mcdi_execute(enp, &req);
1458 if (req.emr_rc != 0) {
1463 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
1465 /* Firmware failed to delete the action rule. */
1477 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1481 #endif /* EFSYS_OPT_MAE */