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,
293 EFX_MAE_FIELD_ID_SRC_IP4_BE = MAE_FIELD_SRC_IP4,
294 EFX_MAE_FIELD_ID_DST_IP4_BE = MAE_FIELD_DST_IP4,
295 EFX_MAE_FIELD_ID_IP_PROTO = MAE_FIELD_IP_PROTO,
296 EFX_MAE_FIELD_ID_IP_TOS = MAE_FIELD_IP_TOS,
297 EFX_MAE_FIELD_ID_IP_TTL = MAE_FIELD_IP_TTL,
298 EFX_MAE_FIELD_ID_SRC_IP6_BE = MAE_FIELD_SRC_IP6,
299 EFX_MAE_FIELD_ID_DST_IP6_BE = MAE_FIELD_DST_IP6,
300 EFX_MAE_FIELD_ID_L4_SPORT_BE = MAE_FIELD_L4_SPORT,
301 EFX_MAE_FIELD_ID_L4_DPORT_BE = MAE_FIELD_L4_DPORT,
302 EFX_MAE_FIELD_ID_TCP_FLAGS_BE = MAE_FIELD_TCP_FLAGS,
304 EFX_MAE_FIELD_CAP_NIDS
305 } efx_mae_field_cap_id_t;
307 typedef enum efx_mae_field_endianness_e {
308 EFX_MAE_FIELD_LE = 0,
311 EFX_MAE_FIELD_ENDIANNESS_NTYPES
312 } efx_mae_field_endianness_t;
315 * The following structure is a means to describe an MAE field.
316 * The information in it is meant to be used internally by
317 * APIs for addressing a given field in a mask-value pairs
318 * structure and for validation purposes.
320 typedef struct efx_mae_mv_desc_s {
321 efx_mae_field_cap_id_t emmd_field_cap_id;
323 size_t emmd_value_size;
324 size_t emmd_value_offset;
325 size_t emmd_mask_size;
326 size_t emmd_mask_offset;
328 efx_mae_field_endianness_t emmd_endianness;
331 /* Indices to this array are provided by efx_mae_field_id_t */
332 static const efx_mae_mv_desc_t __efx_mae_action_rule_mv_desc_set[] = {
333 #define EFX_MAE_MV_DESC(_name, _endianness) \
334 [EFX_MAE_FIELD_##_name] = \
336 EFX_MAE_FIELD_ID_##_name, \
337 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_LEN, \
338 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_OFST, \
339 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_LEN, \
340 MAE_FIELD_MASK_VALUE_PAIRS_##_name##_MASK_OFST, \
344 EFX_MAE_MV_DESC(INGRESS_MPORT_SELECTOR, EFX_MAE_FIELD_LE),
345 EFX_MAE_MV_DESC(ETHER_TYPE_BE, EFX_MAE_FIELD_BE),
346 EFX_MAE_MV_DESC(ETH_SADDR_BE, EFX_MAE_FIELD_BE),
347 EFX_MAE_MV_DESC(ETH_DADDR_BE, EFX_MAE_FIELD_BE),
348 EFX_MAE_MV_DESC(VLAN0_TCI_BE, EFX_MAE_FIELD_BE),
349 EFX_MAE_MV_DESC(VLAN0_PROTO_BE, EFX_MAE_FIELD_BE),
350 EFX_MAE_MV_DESC(VLAN1_TCI_BE, EFX_MAE_FIELD_BE),
351 EFX_MAE_MV_DESC(VLAN1_PROTO_BE, EFX_MAE_FIELD_BE),
352 EFX_MAE_MV_DESC(SRC_IP4_BE, EFX_MAE_FIELD_BE),
353 EFX_MAE_MV_DESC(DST_IP4_BE, EFX_MAE_FIELD_BE),
354 EFX_MAE_MV_DESC(IP_PROTO, EFX_MAE_FIELD_BE),
355 EFX_MAE_MV_DESC(IP_TOS, EFX_MAE_FIELD_BE),
356 EFX_MAE_MV_DESC(IP_TTL, EFX_MAE_FIELD_BE),
357 EFX_MAE_MV_DESC(SRC_IP6_BE, EFX_MAE_FIELD_BE),
358 EFX_MAE_MV_DESC(DST_IP6_BE, EFX_MAE_FIELD_BE),
359 EFX_MAE_MV_DESC(L4_SPORT_BE, EFX_MAE_FIELD_BE),
360 EFX_MAE_MV_DESC(L4_DPORT_BE, EFX_MAE_FIELD_BE),
361 EFX_MAE_MV_DESC(TCP_FLAGS_BE, EFX_MAE_FIELD_BE),
363 #undef EFX_MAE_MV_DESC
366 __checkReturn efx_rc_t
367 efx_mae_mport_by_phy_port(
368 __in uint32_t phy_port,
369 __out efx_mport_sel_t *mportp)
374 if (phy_port > EFX_MASK32(MAE_MPORT_SELECTOR_PPORT_ID)) {
379 EFX_POPULATE_DWORD_2(dword,
380 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_PPORT,
381 MAE_MPORT_SELECTOR_PPORT_ID, phy_port);
383 memset(mportp, 0, sizeof (*mportp));
384 mportp->sel = dword.ed_u32[0];
389 EFSYS_PROBE1(fail1, efx_rc_t, rc);
393 __checkReturn efx_rc_t
394 efx_mae_mport_by_pcie_function(
397 __out efx_mport_sel_t *mportp)
402 EFX_STATIC_ASSERT(EFX_PCI_VF_INVALID ==
403 MAE_MPORT_SELECTOR_FUNC_VF_ID_NULL);
405 if (pf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_PF_ID)) {
410 if (vf > EFX_MASK32(MAE_MPORT_SELECTOR_FUNC_VF_ID)) {
415 EFX_POPULATE_DWORD_3(dword,
416 MAE_MPORT_SELECTOR_TYPE, MAE_MPORT_SELECTOR_TYPE_FUNC,
417 MAE_MPORT_SELECTOR_FUNC_PF_ID, pf,
418 MAE_MPORT_SELECTOR_FUNC_VF_ID, vf);
420 memset(mportp, 0, sizeof (*mportp));
421 mportp->sel = dword.ed_u32[0];
428 EFSYS_PROBE1(fail1, efx_rc_t, rc);
432 __checkReturn efx_rc_t
433 efx_mae_match_spec_field_set(
434 __in efx_mae_match_spec_t *spec,
435 __in efx_mae_field_id_t field_id,
436 __in size_t value_size,
437 __in_bcount(value_size) const uint8_t *value,
438 __in size_t mask_size,
439 __in_bcount(mask_size) const uint8_t *mask)
441 const efx_mae_mv_desc_t *descp;
445 if (field_id >= EFX_MAE_FIELD_NIDS) {
450 switch (spec->emms_type) {
451 case EFX_MAE_RULE_ACTION:
452 descp = &__efx_mae_action_rule_mv_desc_set[field_id];
453 mvp = spec->emms_mask_value_pairs.action;
460 if (value_size != descp->emmd_value_size) {
465 if (mask_size != descp->emmd_mask_size) {
470 if (descp->emmd_endianness == EFX_MAE_FIELD_BE) {
472 * The mask/value are in network (big endian) order.
473 * The MCDI request field is also big endian.
475 memcpy(mvp + descp->emmd_value_offset, value, value_size);
476 memcpy(mvp + descp->emmd_mask_offset, mask, mask_size);
481 * The mask/value are in host byte order.
482 * The MCDI request field is little endian.
484 switch (value_size) {
486 EFX_POPULATE_DWORD_1(dword,
487 EFX_DWORD_0, *(const uint32_t *)value);
489 memcpy(mvp + descp->emmd_value_offset,
490 &dword, sizeof (dword));
493 EFSYS_ASSERT(B_FALSE);
498 EFX_POPULATE_DWORD_1(dword,
499 EFX_DWORD_0, *(const uint32_t *)mask);
501 memcpy(mvp + descp->emmd_mask_offset,
502 &dword, sizeof (dword));
505 EFSYS_ASSERT(B_FALSE);
518 EFSYS_PROBE1(fail1, efx_rc_t, rc);
522 __checkReturn efx_rc_t
523 efx_mae_match_spec_mport_set(
524 __in efx_mae_match_spec_t *spec,
525 __in const efx_mport_sel_t *valuep,
526 __in_opt const efx_mport_sel_t *maskp)
528 uint32_t full_mask = UINT32_MAX;
533 if (valuep == NULL) {
538 vp = (const uint8_t *)&valuep->sel;
540 mp = (const uint8_t *)&maskp->sel;
542 mp = (const uint8_t *)&full_mask;
544 rc = efx_mae_match_spec_field_set(spec,
545 EFX_MAE_FIELD_INGRESS_MPORT_SELECTOR,
546 sizeof (valuep->sel), vp, sizeof (maskp->sel), mp);
555 EFSYS_PROBE1(fail1, efx_rc_t, rc);
559 #define EFX_MASK_BIT_IS_SET(_mask, _mask_page_nbits, _bit) \
560 ((_mask)[(_bit) / (_mask_page_nbits)] & \
561 (1ULL << ((_bit) & ((_mask_page_nbits) - 1))))
563 static inline boolean_t
565 __in size_t mask_nbytes,
566 __in_bcount(mask_nbytes) const uint8_t *maskp)
568 boolean_t prev_bit_is_set = B_TRUE;
571 for (i = 0; i < 8 * mask_nbytes; ++i) {
572 boolean_t bit_is_set = EFX_MASK_BIT_IS_SET(maskp, 8, i);
574 if (!prev_bit_is_set && bit_is_set)
577 prev_bit_is_set = bit_is_set;
583 static inline boolean_t
584 efx_mask_is_all_ones(
585 __in size_t mask_nbytes,
586 __in_bcount(mask_nbytes) const uint8_t *maskp)
591 for (i = 0; i < mask_nbytes; ++i)
594 return (t == (uint8_t)(~0));
597 static inline boolean_t
598 efx_mask_is_all_zeros(
599 __in size_t mask_nbytes,
600 __in_bcount(mask_nbytes) const uint8_t *maskp)
605 for (i = 0; i < mask_nbytes; ++i)
611 __checkReturn boolean_t
612 efx_mae_match_spec_is_valid(
614 __in const efx_mae_match_spec_t *spec)
616 efx_mae_t *maep = enp->en_maep;
617 unsigned int field_ncaps = maep->em_max_nfields;
618 const efx_mae_field_cap_t *field_caps;
619 const efx_mae_mv_desc_t *desc_setp;
620 unsigned int desc_set_nentries;
621 boolean_t is_valid = B_TRUE;
622 efx_mae_field_id_t field_id;
625 switch (spec->emms_type) {
626 case EFX_MAE_RULE_ACTION:
627 field_caps = maep->em_action_rule_field_caps;
628 desc_setp = __efx_mae_action_rule_mv_desc_set;
630 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
631 mvp = spec->emms_mask_value_pairs.action;
637 if (field_caps == NULL)
640 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
641 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
642 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
643 const uint8_t *m_buf = mvp + descp->emmd_mask_offset;
644 size_t m_size = descp->emmd_mask_size;
647 continue; /* Skip array gap */
649 if (field_cap_id >= field_ncaps)
652 switch (field_caps[field_cap_id].emfc_support) {
653 case MAE_FIELD_SUPPORTED_MATCH_MASK:
656 case MAE_FIELD_SUPPORTED_MATCH_PREFIX:
657 is_valid = efx_mask_is_prefix(m_size, m_buf);
659 case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL:
660 is_valid = (efx_mask_is_all_ones(m_size, m_buf) ||
661 efx_mask_is_all_zeros(m_size, m_buf));
663 case MAE_FIELD_SUPPORTED_MATCH_ALWAYS:
664 is_valid = efx_mask_is_all_ones(m_size, m_buf);
666 case MAE_FIELD_SUPPORTED_MATCH_NEVER:
667 case MAE_FIELD_UNSUPPORTED:
669 is_valid = efx_mask_is_all_zeros(m_size, m_buf);
673 if (is_valid == B_FALSE)
680 __checkReturn efx_rc_t
681 efx_mae_action_set_spec_init(
683 __out efx_mae_actions_t **specp)
685 efx_mae_actions_t *spec;
688 EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), spec);
699 EFSYS_PROBE1(fail1, efx_rc_t, rc);
704 efx_mae_action_set_spec_fini(
706 __in efx_mae_actions_t *spec)
708 EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
711 static __checkReturn efx_rc_t
712 efx_mae_action_set_add_vlan_pop(
713 __in efx_mae_actions_t *spec,
714 __in size_t arg_size,
715 __in_bcount(arg_size) const uint8_t *arg)
729 if (spec->ema_n_vlan_tags_to_pop == EFX_MAE_VLAN_POP_MAX_NTAGS) {
734 ++spec->ema_n_vlan_tags_to_pop;
743 EFSYS_PROBE1(fail1, efx_rc_t, rc);
747 static __checkReturn efx_rc_t
748 efx_mae_action_set_add_vlan_push(
749 __in efx_mae_actions_t *spec,
750 __in size_t arg_size,
751 __in_bcount(arg_size) const uint8_t *arg)
753 unsigned int n_tags = spec->ema_n_vlan_tags_to_push;
756 if (arg_size != sizeof (*spec->ema_vlan_push_descs)) {
766 if (n_tags == EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
771 memcpy(&spec->ema_vlan_push_descs[n_tags], arg, arg_size);
772 ++(spec->ema_n_vlan_tags_to_push);
781 EFSYS_PROBE1(fail1, efx_rc_t, rc);
785 static __checkReturn efx_rc_t
786 efx_mae_action_set_add_flag(
787 __in efx_mae_actions_t *spec,
788 __in size_t arg_size,
789 __in_bcount(arg_size) const uint8_t *arg)
793 _NOTE(ARGUNUSED(spec))
805 /* This action does not have any arguments, so do nothing here. */
812 EFSYS_PROBE1(fail1, efx_rc_t, rc);
816 static __checkReturn efx_rc_t
817 efx_mae_action_set_add_mark(
818 __in efx_mae_actions_t *spec,
819 __in size_t arg_size,
820 __in_bcount(arg_size) const uint8_t *arg)
824 if (arg_size != sizeof (spec->ema_mark_value)) {
834 memcpy(&spec->ema_mark_value, arg, arg_size);
841 EFSYS_PROBE1(fail1, efx_rc_t, rc);
845 static __checkReturn efx_rc_t
846 efx_mae_action_set_add_deliver(
847 __in efx_mae_actions_t *spec,
848 __in size_t arg_size,
849 __in_bcount(arg_size) const uint8_t *arg)
853 if (arg_size != sizeof (spec->ema_deliver_mport)) {
863 memcpy(&spec->ema_deliver_mport, arg, arg_size);
870 EFSYS_PROBE1(fail1, efx_rc_t, rc);
874 typedef struct efx_mae_action_desc_s {
875 /* Action specific handler */
876 efx_rc_t (*emad_add)(efx_mae_actions_t *,
877 size_t, const uint8_t *);
878 } efx_mae_action_desc_t;
880 static const efx_mae_action_desc_t efx_mae_actions[EFX_MAE_NACTIONS] = {
881 [EFX_MAE_ACTION_VLAN_POP] = {
882 .emad_add = efx_mae_action_set_add_vlan_pop
884 [EFX_MAE_ACTION_VLAN_PUSH] = {
885 .emad_add = efx_mae_action_set_add_vlan_push
887 [EFX_MAE_ACTION_FLAG] = {
888 .emad_add = efx_mae_action_set_add_flag
890 [EFX_MAE_ACTION_MARK] = {
891 .emad_add = efx_mae_action_set_add_mark
893 [EFX_MAE_ACTION_DELIVER] = {
894 .emad_add = efx_mae_action_set_add_deliver
898 static const uint32_t efx_mae_action_ordered_map =
899 (1U << EFX_MAE_ACTION_VLAN_POP) |
900 (1U << EFX_MAE_ACTION_VLAN_PUSH) |
901 (1U << EFX_MAE_ACTION_FLAG) |
902 (1U << EFX_MAE_ACTION_MARK) |
903 (1U << EFX_MAE_ACTION_DELIVER);
906 * These actions must not be added after DELIVER, but
907 * they can have any place among the rest of
908 * strictly ordered actions.
910 static const uint32_t efx_mae_action_nonstrict_map =
911 (1U << EFX_MAE_ACTION_FLAG) |
912 (1U << EFX_MAE_ACTION_MARK);
914 static const uint32_t efx_mae_action_repeat_map =
915 (1U << EFX_MAE_ACTION_VLAN_POP) |
916 (1U << EFX_MAE_ACTION_VLAN_PUSH);
919 * Add an action to an action set.
921 * This has to be invoked in the desired action order.
922 * An out-of-order action request will be turned down.
924 static __checkReturn efx_rc_t
925 efx_mae_action_set_spec_populate(
926 __in efx_mae_actions_t *spec,
927 __in efx_mae_action_t type,
928 __in size_t arg_size,
929 __in_bcount(arg_size) const uint8_t *arg)
931 uint32_t action_mask;
934 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
935 (sizeof (efx_mae_action_ordered_map) * 8));
936 EFX_STATIC_ASSERT(EFX_MAE_NACTIONS <=
937 (sizeof (efx_mae_action_repeat_map) * 8));
939 EFX_STATIC_ASSERT(EFX_MAE_ACTION_DELIVER + 1 == EFX_MAE_NACTIONS);
940 EFX_STATIC_ASSERT(EFX_MAE_ACTION_FLAG + 1 == EFX_MAE_ACTION_MARK);
941 EFX_STATIC_ASSERT(EFX_MAE_ACTION_MARK + 1 == EFX_MAE_ACTION_DELIVER);
943 if (type >= EFX_ARRAY_SIZE(efx_mae_actions)) {
948 action_mask = (1U << type);
950 if ((spec->ema_actions & action_mask) != 0) {
951 /* The action set already contains this action. */
952 if ((efx_mae_action_repeat_map & action_mask) == 0) {
953 /* Cannot add another non-repeatable action. */
959 if ((efx_mae_action_ordered_map & action_mask) != 0) {
960 uint32_t strict_ordered_map =
961 efx_mae_action_ordered_map & ~efx_mae_action_nonstrict_map;
962 uint32_t later_actions_mask =
963 strict_ordered_map & ~(action_mask | (action_mask - 1));
965 if ((spec->ema_actions & later_actions_mask) != 0) {
966 /* Cannot add an action after later ordered actions. */
972 if (efx_mae_actions[type].emad_add != NULL) {
973 rc = efx_mae_actions[type].emad_add(spec, arg_size, arg);
978 spec->ema_actions |= action_mask;
989 EFSYS_PROBE1(fail1, efx_rc_t, rc);
993 __checkReturn efx_rc_t
994 efx_mae_action_set_populate_vlan_pop(
995 __in efx_mae_actions_t *spec)
997 return (efx_mae_action_set_spec_populate(spec,
998 EFX_MAE_ACTION_VLAN_POP, 0, NULL));
1001 __checkReturn efx_rc_t
1002 efx_mae_action_set_populate_vlan_push(
1003 __in efx_mae_actions_t *spec,
1004 __in uint16_t tpid_be,
1005 __in uint16_t tci_be)
1007 efx_mae_action_vlan_push_t action;
1008 const uint8_t *arg = (const uint8_t *)&action;
1010 action.emavp_tpid_be = tpid_be;
1011 action.emavp_tci_be = tci_be;
1013 return (efx_mae_action_set_spec_populate(spec,
1014 EFX_MAE_ACTION_VLAN_PUSH, sizeof (action), arg));
1017 __checkReturn efx_rc_t
1018 efx_mae_action_set_populate_flag(
1019 __in efx_mae_actions_t *spec)
1021 return (efx_mae_action_set_spec_populate(spec,
1022 EFX_MAE_ACTION_FLAG, 0, NULL));
1025 __checkReturn efx_rc_t
1026 efx_mae_action_set_populate_mark(
1027 __in efx_mae_actions_t *spec,
1028 __in uint32_t mark_value)
1030 const uint8_t *arg = (const uint8_t *)&mark_value;
1032 return (efx_mae_action_set_spec_populate(spec,
1033 EFX_MAE_ACTION_MARK, sizeof (mark_value), arg));
1036 __checkReturn efx_rc_t
1037 efx_mae_action_set_populate_deliver(
1038 __in efx_mae_actions_t *spec,
1039 __in const efx_mport_sel_t *mportp)
1044 if (mportp == NULL) {
1049 arg = (const uint8_t *)&mportp->sel;
1051 return (efx_mae_action_set_spec_populate(spec,
1052 EFX_MAE_ACTION_DELIVER, sizeof (mportp->sel), arg));
1055 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1059 __checkReturn efx_rc_t
1060 efx_mae_action_set_populate_drop(
1061 __in efx_mae_actions_t *spec)
1063 efx_mport_sel_t mport;
1067 EFX_POPULATE_DWORD_1(dword,
1068 MAE_MPORT_SELECTOR_FLAT, MAE_MPORT_SELECTOR_NULL);
1070 mport.sel = dword.ed_u32[0];
1072 arg = (const uint8_t *)&mport.sel;
1074 return (efx_mae_action_set_spec_populate(spec,
1075 EFX_MAE_ACTION_DELIVER, sizeof (mport.sel), arg));
1078 __checkReturn boolean_t
1079 efx_mae_action_set_specs_equal(
1080 __in const efx_mae_actions_t *left,
1081 __in const efx_mae_actions_t *right)
1083 return ((memcmp(left, right, sizeof (*left)) == 0) ? B_TRUE : B_FALSE);
1086 __checkReturn efx_rc_t
1087 efx_mae_match_specs_class_cmp(
1088 __in efx_nic_t *enp,
1089 __in const efx_mae_match_spec_t *left,
1090 __in const efx_mae_match_spec_t *right,
1091 __out boolean_t *have_same_classp)
1093 efx_mae_t *maep = enp->en_maep;
1094 unsigned int field_ncaps = maep->em_max_nfields;
1095 const efx_mae_field_cap_t *field_caps;
1096 const efx_mae_mv_desc_t *desc_setp;
1097 unsigned int desc_set_nentries;
1098 boolean_t have_same_class = B_TRUE;
1099 efx_mae_field_id_t field_id;
1100 const uint8_t *mvpl;
1101 const uint8_t *mvpr;
1104 switch (left->emms_type) {
1105 case EFX_MAE_RULE_ACTION:
1106 field_caps = maep->em_action_rule_field_caps;
1107 desc_setp = __efx_mae_action_rule_mv_desc_set;
1109 EFX_ARRAY_SIZE(__efx_mae_action_rule_mv_desc_set);
1110 mvpl = left->emms_mask_value_pairs.action;
1111 mvpr = right->emms_mask_value_pairs.action;
1118 if (field_caps == NULL) {
1123 if (left->emms_type != right->emms_type ||
1124 left->emms_prio != right->emms_prio) {
1126 * Rules of different types can never map to the same class.
1128 * The FW can support some set of match criteria for one
1129 * priority and not support the very same set for
1130 * another priority. Thus, two rules which have
1131 * different priorities can never map to
1134 *have_same_classp = B_FALSE;
1138 for (field_id = 0; field_id < desc_set_nentries; ++field_id) {
1139 const efx_mae_mv_desc_t *descp = &desc_setp[field_id];
1140 efx_mae_field_cap_id_t field_cap_id = descp->emmd_field_cap_id;
1142 if (descp->emmd_mask_size == 0)
1143 continue; /* Skip array gap */
1145 if (field_cap_id >= field_ncaps)
1148 if (field_caps[field_cap_id].emfc_mask_affects_class) {
1149 const uint8_t *lmaskp = mvpl + descp->emmd_mask_offset;
1150 const uint8_t *rmaskp = mvpr + descp->emmd_mask_offset;
1151 size_t mask_size = descp->emmd_mask_size;
1153 if (memcmp(lmaskp, rmaskp, mask_size) != 0) {
1154 have_same_class = B_FALSE;
1159 if (field_caps[field_cap_id].emfc_match_affects_class) {
1160 const uint8_t *lvalp = mvpl + descp->emmd_value_offset;
1161 const uint8_t *rvalp = mvpr + descp->emmd_value_offset;
1162 size_t value_size = descp->emmd_value_size;
1164 if (memcmp(lvalp, rvalp, value_size) != 0) {
1165 have_same_class = B_FALSE;
1171 *have_same_classp = have_same_class;
1178 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1182 __checkReturn efx_rc_t
1183 efx_mae_action_set_alloc(
1184 __in efx_nic_t *enp,
1185 __in const efx_mae_actions_t *spec,
1186 __out efx_mae_aset_id_t *aset_idp)
1188 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1190 EFX_MCDI_DECLARE_BUF(payload,
1191 MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN,
1192 MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
1193 efx_mae_aset_id_t aset_id;
1196 if (encp->enc_mae_supported == B_FALSE) {
1201 req.emr_cmd = MC_CMD_MAE_ACTION_SET_ALLOC;
1202 req.emr_in_buf = payload;
1203 req.emr_in_length = MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN;
1204 req.emr_out_buf = payload;
1205 req.emr_out_length = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN;
1208 * TODO: Remove these EFX_MAE_RSRC_ID_INVALID assignments once the
1209 * corresponding resource types are supported by the implementation.
1210 * Use proper resource ID assignments instead.
1212 MCDI_IN_SET_DWORD(req,
1213 MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID, EFX_MAE_RSRC_ID_INVALID);
1214 MCDI_IN_SET_DWORD(req,
1215 MAE_ACTION_SET_ALLOC_IN_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1216 MCDI_IN_SET_DWORD(req,
1217 MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID, EFX_MAE_RSRC_ID_INVALID);
1219 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1220 MAE_ACTION_SET_ALLOC_IN_VLAN_POP, spec->ema_n_vlan_tags_to_pop);
1222 if (spec->ema_n_vlan_tags_to_push > 0) {
1223 unsigned int outer_tag_idx;
1225 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1226 MAE_ACTION_SET_ALLOC_IN_VLAN_PUSH,
1227 spec->ema_n_vlan_tags_to_push);
1229 if (spec->ema_n_vlan_tags_to_push ==
1230 EFX_MAE_VLAN_PUSH_MAX_NTAGS) {
1231 MCDI_IN_SET_WORD(req,
1232 MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
1233 spec->ema_vlan_push_descs[0].emavp_tpid_be);
1234 MCDI_IN_SET_WORD(req,
1235 MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
1236 spec->ema_vlan_push_descs[0].emavp_tci_be);
1239 outer_tag_idx = spec->ema_n_vlan_tags_to_push - 1;
1241 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
1242 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tpid_be);
1243 MCDI_IN_SET_WORD(req, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
1244 spec->ema_vlan_push_descs[outer_tag_idx].emavp_tci_be);
1247 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_FLAG)) != 0) {
1248 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1249 MAE_ACTION_SET_ALLOC_IN_FLAG, 1);
1252 if ((spec->ema_actions & (1U << EFX_MAE_ACTION_MARK)) != 0) {
1253 MCDI_IN_SET_DWORD_FIELD(req, MAE_ACTION_SET_ALLOC_IN_FLAGS,
1254 MAE_ACTION_SET_ALLOC_IN_MARK, 1);
1256 MCDI_IN_SET_DWORD(req,
1257 MAE_ACTION_SET_ALLOC_IN_MARK_VALUE, spec->ema_mark_value);
1260 MCDI_IN_SET_DWORD(req,
1261 MAE_ACTION_SET_ALLOC_IN_DELIVER, spec->ema_deliver_mport.sel);
1263 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
1264 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1265 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
1266 MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
1268 efx_mcdi_execute(enp, &req);
1270 if (req.emr_rc != 0) {
1275 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN) {
1280 aset_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_SET_ALLOC_OUT_AS_ID);
1281 if (aset_id.id == EFX_MAE_RSRC_ID_INVALID) {
1286 aset_idp->id = aset_id.id;
1297 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1301 __checkReturn efx_rc_t
1302 efx_mae_action_set_free(
1303 __in efx_nic_t *enp,
1304 __in const efx_mae_aset_id_t *aset_idp)
1306 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1308 EFX_MCDI_DECLARE_BUF(payload,
1309 MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1),
1310 MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
1313 if (encp->enc_mae_supported == B_FALSE) {
1318 req.emr_cmd = MC_CMD_MAE_ACTION_SET_FREE;
1319 req.emr_in_buf = payload;
1320 req.emr_in_length = MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1);
1321 req.emr_out_buf = payload;
1322 req.emr_out_length = MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1);
1324 MCDI_IN_SET_DWORD(req, MAE_ACTION_SET_FREE_IN_AS_ID, aset_idp->id);
1326 efx_mcdi_execute(enp, &req);
1328 if (req.emr_rc != 0) {
1333 if (MCDI_OUT_DWORD(req, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) !=
1335 /* Firmware failed to free the action set. */
1347 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1351 __checkReturn efx_rc_t
1352 efx_mae_action_rule_insert(
1353 __in efx_nic_t *enp,
1354 __in const efx_mae_match_spec_t *spec,
1355 __in const efx_mae_aset_list_id_t *asl_idp,
1356 __in const efx_mae_aset_id_t *as_idp,
1357 __out efx_mae_rule_id_t *ar_idp)
1359 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1361 EFX_MCDI_DECLARE_BUF(payload,
1362 MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2,
1363 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN);
1364 efx_oword_t *rule_response;
1365 efx_mae_rule_id_t ar_id;
1369 EFX_STATIC_ASSERT(sizeof (ar_idp->id) ==
1370 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_AR_ID_LEN);
1372 EFX_STATIC_ASSERT(EFX_MAE_RSRC_ID_INVALID ==
1373 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
1375 if (encp->enc_mae_supported == B_FALSE) {
1380 if (spec->emms_type != EFX_MAE_RULE_ACTION ||
1381 (asl_idp != NULL && as_idp != NULL) ||
1382 (asl_idp == NULL && as_idp == NULL)) {
1387 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_INSERT;
1388 req.emr_in_buf = payload;
1389 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_INSERT_IN_LENMAX_MCDI2;
1390 req.emr_out_buf = payload;
1391 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN;
1393 EFX_STATIC_ASSERT(sizeof (*rule_response) <=
1394 MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_LEN);
1395 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_RESPONSE_OFST;
1396 rule_response = (efx_oword_t *)(payload + offset);
1397 EFX_POPULATE_OWORD_3(*rule_response,
1398 MAE_ACTION_RULE_RESPONSE_ASL_ID,
1399 (asl_idp != NULL) ? asl_idp->id : EFX_MAE_RSRC_ID_INVALID,
1400 MAE_ACTION_RULE_RESPONSE_AS_ID,
1401 (as_idp != NULL) ? as_idp->id : EFX_MAE_RSRC_ID_INVALID,
1402 MAE_ACTION_RULE_RESPONSE_COUNTER_ID, EFX_MAE_RSRC_ID_INVALID);
1404 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_INSERT_IN_PRIO, spec->emms_prio);
1407 * Mask-value pairs have been stored in the byte order needed for the
1408 * MCDI request and are thus safe to be copied directly to the buffer.
1410 EFX_STATIC_ASSERT(sizeof (spec->emms_mask_value_pairs.action) >=
1411 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1412 offset = MC_CMD_MAE_ACTION_RULE_INSERT_IN_MATCH_CRITERIA_OFST;
1413 memcpy(payload + offset, spec->emms_mask_value_pairs.action,
1414 MAE_FIELD_MASK_VALUE_PAIRS_LEN);
1416 efx_mcdi_execute(enp, &req);
1418 if (req.emr_rc != 0) {
1423 if (req.emr_out_length_used < MC_CMD_MAE_ACTION_RULE_INSERT_OUT_LEN) {
1428 ar_id.id = MCDI_OUT_DWORD(req, MAE_ACTION_RULE_INSERT_OUT_AR_ID);
1429 if (ar_id.id == EFX_MAE_RSRC_ID_INVALID) {
1434 ar_idp->id = ar_id.id;
1447 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1451 __checkReturn efx_rc_t
1452 efx_mae_action_rule_remove(
1453 __in efx_nic_t *enp,
1454 __in const efx_mae_rule_id_t *ar_idp)
1456 const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
1458 EFX_MCDI_DECLARE_BUF(payload,
1459 MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1),
1460 MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1));
1463 if (encp->enc_mae_supported == B_FALSE) {
1468 req.emr_cmd = MC_CMD_MAE_ACTION_RULE_DELETE;
1469 req.emr_in_buf = payload;
1470 req.emr_in_length = MC_CMD_MAE_ACTION_RULE_DELETE_IN_LEN(1);
1471 req.emr_out_buf = payload;
1472 req.emr_out_length = MC_CMD_MAE_ACTION_RULE_DELETE_OUT_LEN(1);
1474 MCDI_IN_SET_DWORD(req, MAE_ACTION_RULE_DELETE_IN_AR_ID, ar_idp->id);
1476 efx_mcdi_execute(enp, &req);
1478 if (req.emr_rc != 0) {
1483 if (MCDI_OUT_DWORD(req, MAE_ACTION_RULE_DELETE_OUT_DELETED_AR_ID) !=
1485 /* Firmware failed to delete the action rule. */
1497 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1501 #endif /* EFSYS_OPT_MAE */