1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2012-2019 Solarflare Communications Inc.
13 #if EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10()
15 #include "ef10_tlv_layout.h"
17 __checkReturn efx_rc_t
18 efx_mcdi_get_port_assignment(
20 __out uint32_t *portp)
23 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PORT_ASSIGNMENT_IN_LEN,
24 MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN);
27 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
29 req.emr_cmd = MC_CMD_GET_PORT_ASSIGNMENT;
30 req.emr_in_buf = payload;
31 req.emr_in_length = MC_CMD_GET_PORT_ASSIGNMENT_IN_LEN;
32 req.emr_out_buf = payload;
33 req.emr_out_length = MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN;
35 efx_mcdi_execute(enp, &req);
37 if (req.emr_rc != 0) {
42 if (req.emr_out_length_used < MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN) {
47 *portp = MCDI_OUT_DWORD(req, GET_PORT_ASSIGNMENT_OUT_PORT);
54 EFSYS_PROBE1(fail1, efx_rc_t, rc);
59 __checkReturn efx_rc_t
60 efx_mcdi_get_port_modes(
62 __out uint32_t *modesp,
63 __out_opt uint32_t *current_modep,
64 __out_opt uint32_t *default_modep)
67 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PORT_MODES_IN_LEN,
68 MC_CMD_GET_PORT_MODES_OUT_LEN);
71 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
73 req.emr_cmd = MC_CMD_GET_PORT_MODES;
74 req.emr_in_buf = payload;
75 req.emr_in_length = MC_CMD_GET_PORT_MODES_IN_LEN;
76 req.emr_out_buf = payload;
77 req.emr_out_length = MC_CMD_GET_PORT_MODES_OUT_LEN;
79 efx_mcdi_execute(enp, &req);
81 if (req.emr_rc != 0) {
87 * Require only Modes and DefaultMode fields, unless the current mode
88 * was requested (CurrentMode field was added for Medford).
90 if (req.emr_out_length_used <
91 MC_CMD_GET_PORT_MODES_OUT_CURRENT_MODE_OFST) {
95 if ((current_modep != NULL) && (req.emr_out_length_used <
96 MC_CMD_GET_PORT_MODES_OUT_CURRENT_MODE_OFST + 4)) {
101 *modesp = MCDI_OUT_DWORD(req, GET_PORT_MODES_OUT_MODES);
103 if (current_modep != NULL) {
104 *current_modep = MCDI_OUT_DWORD(req,
105 GET_PORT_MODES_OUT_CURRENT_MODE);
108 if (default_modep != NULL) {
109 *default_modep = MCDI_OUT_DWORD(req,
110 GET_PORT_MODES_OUT_DEFAULT_MODE);
120 EFSYS_PROBE1(fail1, efx_rc_t, rc);
125 __checkReturn efx_rc_t
126 ef10_nic_get_port_mode_bandwidth(
128 __out uint32_t *bandwidth_mbpsp)
131 uint32_t current_mode;
132 efx_port_t *epp = &(enp->en_port);
134 uint32_t single_lane;
140 if ((rc = efx_mcdi_get_port_modes(enp, &port_modes,
141 ¤t_mode, NULL)) != 0) {
142 /* No port mode info available. */
146 if (epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_25000FDX))
151 if (epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_50000FDX))
156 if (epp->ep_phy_cap_mask & (1 << EFX_PHY_CAP_100000FDX))
161 switch (current_mode) {
162 case TLV_PORT_MODE_1x1_NA: /* mode 0 */
163 bandwidth = single_lane;
165 case TLV_PORT_MODE_1x2_NA: /* mode 10 */
166 case TLV_PORT_MODE_NA_1x2: /* mode 11 */
167 bandwidth = dual_lane;
169 case TLV_PORT_MODE_1x1_1x1: /* mode 2 */
170 bandwidth = single_lane + single_lane;
172 case TLV_PORT_MODE_4x1_NA: /* mode 4 */
173 case TLV_PORT_MODE_NA_4x1: /* mode 8 */
174 bandwidth = 4 * single_lane;
176 case TLV_PORT_MODE_2x1_2x1: /* mode 5 */
177 bandwidth = (2 * single_lane) + (2 * single_lane);
179 case TLV_PORT_MODE_1x2_1x2: /* mode 12 */
180 bandwidth = dual_lane + dual_lane;
182 case TLV_PORT_MODE_1x2_2x1: /* mode 17 */
183 case TLV_PORT_MODE_2x1_1x2: /* mode 18 */
184 bandwidth = dual_lane + (2 * single_lane);
186 /* Legacy Medford-only mode. Do not use (see bug63270) */
187 case TLV_PORT_MODE_10G_10G_10G_10G_Q1_Q2: /* mode 9 */
188 bandwidth = 4 * single_lane;
190 case TLV_PORT_MODE_1x4_NA: /* mode 1 */
191 case TLV_PORT_MODE_NA_1x4: /* mode 22 */
192 bandwidth = quad_lane;
194 case TLV_PORT_MODE_2x2_NA: /* mode 13 */
195 case TLV_PORT_MODE_NA_2x2: /* mode 14 */
196 bandwidth = 2 * dual_lane;
198 case TLV_PORT_MODE_1x4_2x1: /* mode 6 */
199 case TLV_PORT_MODE_2x1_1x4: /* mode 7 */
200 bandwidth = quad_lane + (2 * single_lane);
202 case TLV_PORT_MODE_1x4_1x2: /* mode 15 */
203 case TLV_PORT_MODE_1x2_1x4: /* mode 16 */
204 bandwidth = quad_lane + dual_lane;
206 case TLV_PORT_MODE_1x4_1x4: /* mode 3 */
207 bandwidth = quad_lane + quad_lane;
214 *bandwidth_mbpsp = bandwidth;
221 EFSYS_PROBE1(fail1, efx_rc_t, rc);
226 #endif /* EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10() */
230 __checkReturn efx_rc_t
231 efx_mcdi_vadaptor_alloc(
233 __in uint32_t port_id)
236 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VADAPTOR_ALLOC_IN_LEN,
237 MC_CMD_VADAPTOR_ALLOC_OUT_LEN);
240 req.emr_cmd = MC_CMD_VADAPTOR_ALLOC;
241 req.emr_in_buf = payload;
242 req.emr_in_length = MC_CMD_VADAPTOR_ALLOC_IN_LEN;
243 req.emr_out_buf = payload;
244 req.emr_out_length = MC_CMD_VADAPTOR_ALLOC_OUT_LEN;
246 MCDI_IN_SET_DWORD(req, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
247 MCDI_IN_POPULATE_DWORD_1(req, VADAPTOR_ALLOC_IN_FLAGS,
248 VADAPTOR_ALLOC_IN_FLAG_PERMIT_SET_MAC_WHEN_FILTERS_INSTALLED,
249 enp->en_nic_cfg.enc_allow_set_mac_with_installed_filters ? 1 : 0);
251 efx_mcdi_execute(enp, &req);
253 if (req.emr_rc != 0) {
261 EFSYS_PROBE1(fail1, efx_rc_t, rc);
266 __checkReturn efx_rc_t
267 efx_mcdi_vadaptor_free(
269 __in uint32_t port_id)
272 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VADAPTOR_FREE_IN_LEN,
273 MC_CMD_VADAPTOR_FREE_OUT_LEN);
276 req.emr_cmd = MC_CMD_VADAPTOR_FREE;
277 req.emr_in_buf = payload;
278 req.emr_in_length = MC_CMD_VADAPTOR_FREE_IN_LEN;
279 req.emr_out_buf = payload;
280 req.emr_out_length = MC_CMD_VADAPTOR_FREE_OUT_LEN;
282 MCDI_IN_SET_DWORD(req, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
284 efx_mcdi_execute(enp, &req);
286 if (req.emr_rc != 0) {
294 EFSYS_PROBE1(fail1, efx_rc_t, rc);
299 #endif /* EFX_OPTS_EF10() */
301 #if EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10()
303 __checkReturn efx_rc_t
304 efx_mcdi_get_mac_address_pf(
306 __out_ecount_opt(6) uint8_t mac_addrp[6])
309 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_MAC_ADDRESSES_IN_LEN,
310 MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
313 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
315 req.emr_cmd = MC_CMD_GET_MAC_ADDRESSES;
316 req.emr_in_buf = payload;
317 req.emr_in_length = MC_CMD_GET_MAC_ADDRESSES_IN_LEN;
318 req.emr_out_buf = payload;
319 req.emr_out_length = MC_CMD_GET_MAC_ADDRESSES_OUT_LEN;
321 efx_mcdi_execute(enp, &req);
323 if (req.emr_rc != 0) {
328 if (req.emr_out_length_used < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) {
333 if (MCDI_OUT_DWORD(req, GET_MAC_ADDRESSES_OUT_MAC_COUNT) < 1) {
338 if (mac_addrp != NULL) {
341 addrp = MCDI_OUT2(req, uint8_t,
342 GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE);
344 EFX_MAC_ADDR_COPY(mac_addrp, addrp);
354 EFSYS_PROBE1(fail1, efx_rc_t, rc);
359 __checkReturn efx_rc_t
360 efx_mcdi_get_mac_address_vf(
362 __out_ecount_opt(6) uint8_t mac_addrp[6])
365 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN,
366 MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
369 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
371 req.emr_cmd = MC_CMD_VPORT_GET_MAC_ADDRESSES;
372 req.emr_in_buf = payload;
373 req.emr_in_length = MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN;
374 req.emr_out_buf = payload;
375 req.emr_out_length = MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX;
377 MCDI_IN_SET_DWORD(req, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
378 EVB_PORT_ID_ASSIGNED);
380 efx_mcdi_execute(enp, &req);
382 if (req.emr_rc != 0) {
387 if (req.emr_out_length_used <
388 MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN) {
393 if (MCDI_OUT_DWORD(req,
394 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT) < 1) {
399 if (mac_addrp != NULL) {
402 addrp = MCDI_OUT2(req, uint8_t,
403 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR);
405 EFX_MAC_ADDR_COPY(mac_addrp, addrp);
415 EFSYS_PROBE1(fail1, efx_rc_t, rc);
420 __checkReturn efx_rc_t
423 __out uint32_t *sys_freqp,
424 __out uint32_t *dpcpu_freqp)
427 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_CLOCK_IN_LEN,
428 MC_CMD_GET_CLOCK_OUT_LEN);
431 EFSYS_ASSERT(EFX_FAMILY_IS_EF100(enp) || EFX_FAMILY_IS_EF10(enp));
433 req.emr_cmd = MC_CMD_GET_CLOCK;
434 req.emr_in_buf = payload;
435 req.emr_in_length = MC_CMD_GET_CLOCK_IN_LEN;
436 req.emr_out_buf = payload;
437 req.emr_out_length = MC_CMD_GET_CLOCK_OUT_LEN;
439 efx_mcdi_execute(enp, &req);
441 if (req.emr_rc != 0) {
446 if (req.emr_out_length_used < MC_CMD_GET_CLOCK_OUT_LEN) {
451 *sys_freqp = MCDI_OUT_DWORD(req, GET_CLOCK_OUT_SYS_FREQ);
452 if (*sys_freqp == 0) {
456 *dpcpu_freqp = MCDI_OUT_DWORD(req, GET_CLOCK_OUT_DPCPU_FREQ);
457 if (*dpcpu_freqp == 0) {
471 EFSYS_PROBE1(fail1, efx_rc_t, rc);
476 __checkReturn efx_rc_t
477 efx_mcdi_get_rxdp_config(
479 __out uint32_t *end_paddingp)
482 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_RXDP_CONFIG_IN_LEN,
483 MC_CMD_GET_RXDP_CONFIG_OUT_LEN);
484 uint32_t end_padding;
487 req.emr_cmd = MC_CMD_GET_RXDP_CONFIG;
488 req.emr_in_buf = payload;
489 req.emr_in_length = MC_CMD_GET_RXDP_CONFIG_IN_LEN;
490 req.emr_out_buf = payload;
491 req.emr_out_length = MC_CMD_GET_RXDP_CONFIG_OUT_LEN;
493 efx_mcdi_execute(enp, &req);
495 if (req.emr_rc != 0) {
500 if (req.emr_out_length_used < MC_CMD_GET_RXDP_CONFIG_OUT_LEN) {
505 if (MCDI_OUT_DWORD_FIELD(req, GET_RXDP_CONFIG_OUT_DATA,
506 GET_RXDP_CONFIG_OUT_PAD_HOST_DMA) == 0) {
507 /* RX DMA end padding is disabled */
510 switch (MCDI_OUT_DWORD_FIELD(req, GET_RXDP_CONFIG_OUT_DATA,
511 GET_RXDP_CONFIG_OUT_PAD_HOST_LEN)) {
512 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_64:
515 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_128:
518 case MC_CMD_SET_RXDP_CONFIG_IN_PAD_HOST_256:
527 *end_paddingp = end_padding;
536 EFSYS_PROBE1(fail1, efx_rc_t, rc);
541 __checkReturn efx_rc_t
542 efx_mcdi_get_vector_cfg(
544 __out_opt uint32_t *vec_basep,
545 __out_opt uint32_t *pf_nvecp,
546 __out_opt uint32_t *vf_nvecp)
549 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_VECTOR_CFG_IN_LEN,
550 MC_CMD_GET_VECTOR_CFG_OUT_LEN);
553 req.emr_cmd = MC_CMD_GET_VECTOR_CFG;
554 req.emr_in_buf = payload;
555 req.emr_in_length = MC_CMD_GET_VECTOR_CFG_IN_LEN;
556 req.emr_out_buf = payload;
557 req.emr_out_length = MC_CMD_GET_VECTOR_CFG_OUT_LEN;
559 efx_mcdi_execute(enp, &req);
561 if (req.emr_rc != 0) {
566 if (req.emr_out_length_used < MC_CMD_GET_VECTOR_CFG_OUT_LEN) {
571 if (vec_basep != NULL)
572 *vec_basep = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VEC_BASE);
573 if (pf_nvecp != NULL)
574 *pf_nvecp = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VECS_PER_PF);
575 if (vf_nvecp != NULL)
576 *vf_nvecp = MCDI_OUT_DWORD(req, GET_VECTOR_CFG_OUT_VECS_PER_VF);
583 EFSYS_PROBE1(fail1, efx_rc_t, rc);
588 __checkReturn efx_rc_t
591 __in uint32_t min_vi_count,
592 __in uint32_t max_vi_count,
593 __out uint32_t *vi_basep,
594 __out uint32_t *vi_countp,
595 __out uint32_t *vi_shiftp)
598 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_ALLOC_VIS_IN_LEN,
599 MC_CMD_ALLOC_VIS_EXT_OUT_LEN);
602 if (vi_countp == NULL) {
607 req.emr_cmd = MC_CMD_ALLOC_VIS;
608 req.emr_in_buf = payload;
609 req.emr_in_length = MC_CMD_ALLOC_VIS_IN_LEN;
610 req.emr_out_buf = payload;
611 req.emr_out_length = MC_CMD_ALLOC_VIS_EXT_OUT_LEN;
613 MCDI_IN_SET_DWORD(req, ALLOC_VIS_IN_MIN_VI_COUNT, min_vi_count);
614 MCDI_IN_SET_DWORD(req, ALLOC_VIS_IN_MAX_VI_COUNT, max_vi_count);
616 efx_mcdi_execute(enp, &req);
618 if (req.emr_rc != 0) {
623 if (req.emr_out_length_used < MC_CMD_ALLOC_VIS_OUT_LEN) {
628 *vi_basep = MCDI_OUT_DWORD(req, ALLOC_VIS_OUT_VI_BASE);
629 *vi_countp = MCDI_OUT_DWORD(req, ALLOC_VIS_OUT_VI_COUNT);
631 /* Report VI_SHIFT if available (always zero for Huntington) */
632 if (req.emr_out_length_used < MC_CMD_ALLOC_VIS_EXT_OUT_LEN)
635 *vi_shiftp = MCDI_OUT_DWORD(req, ALLOC_VIS_EXT_OUT_VI_SHIFT);
644 EFSYS_PROBE1(fail1, efx_rc_t, rc);
650 __checkReturn efx_rc_t
657 EFX_STATIC_ASSERT(MC_CMD_FREE_VIS_IN_LEN == 0);
658 EFX_STATIC_ASSERT(MC_CMD_FREE_VIS_OUT_LEN == 0);
660 req.emr_cmd = MC_CMD_FREE_VIS;
661 req.emr_in_buf = NULL;
662 req.emr_in_length = 0;
663 req.emr_out_buf = NULL;
664 req.emr_out_length = 0;
666 efx_mcdi_execute_quiet(enp, &req);
668 /* Ignore ELREADY (no allocated VIs, so nothing to free) */
669 if ((req.emr_rc != 0) && (req.emr_rc != EALREADY)) {
677 EFSYS_PROBE1(fail1, efx_rc_t, rc);
682 #endif /* EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10() */
686 static __checkReturn efx_rc_t
687 efx_mcdi_alloc_piobuf(
689 __out efx_piobuf_handle_t *handlep)
692 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_ALLOC_PIOBUF_IN_LEN,
693 MC_CMD_ALLOC_PIOBUF_OUT_LEN);
696 if (handlep == NULL) {
701 req.emr_cmd = MC_CMD_ALLOC_PIOBUF;
702 req.emr_in_buf = payload;
703 req.emr_in_length = MC_CMD_ALLOC_PIOBUF_IN_LEN;
704 req.emr_out_buf = payload;
705 req.emr_out_length = MC_CMD_ALLOC_PIOBUF_OUT_LEN;
707 efx_mcdi_execute_quiet(enp, &req);
709 if (req.emr_rc != 0) {
714 if (req.emr_out_length_used < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
719 *handlep = MCDI_OUT_DWORD(req, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
728 EFSYS_PROBE1(fail1, efx_rc_t, rc);
733 static __checkReturn efx_rc_t
734 efx_mcdi_free_piobuf(
736 __in efx_piobuf_handle_t handle)
739 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_FREE_PIOBUF_IN_LEN,
740 MC_CMD_FREE_PIOBUF_OUT_LEN);
743 req.emr_cmd = MC_CMD_FREE_PIOBUF;
744 req.emr_in_buf = payload;
745 req.emr_in_length = MC_CMD_FREE_PIOBUF_IN_LEN;
746 req.emr_out_buf = payload;
747 req.emr_out_length = MC_CMD_FREE_PIOBUF_OUT_LEN;
749 MCDI_IN_SET_DWORD(req, FREE_PIOBUF_IN_PIOBUF_HANDLE, handle);
751 efx_mcdi_execute_quiet(enp, &req);
753 if (req.emr_rc != 0) {
761 EFSYS_PROBE1(fail1, efx_rc_t, rc);
766 static __checkReturn efx_rc_t
767 efx_mcdi_link_piobuf(
769 __in uint32_t vi_index,
770 __in efx_piobuf_handle_t handle)
773 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_LINK_PIOBUF_IN_LEN,
774 MC_CMD_LINK_PIOBUF_OUT_LEN);
777 req.emr_cmd = MC_CMD_LINK_PIOBUF;
778 req.emr_in_buf = payload;
779 req.emr_in_length = MC_CMD_LINK_PIOBUF_IN_LEN;
780 req.emr_out_buf = payload;
781 req.emr_out_length = MC_CMD_LINK_PIOBUF_OUT_LEN;
783 MCDI_IN_SET_DWORD(req, LINK_PIOBUF_IN_PIOBUF_HANDLE, handle);
784 MCDI_IN_SET_DWORD(req, LINK_PIOBUF_IN_TXQ_INSTANCE, vi_index);
786 efx_mcdi_execute(enp, &req);
788 if (req.emr_rc != 0) {
796 EFSYS_PROBE1(fail1, efx_rc_t, rc);
801 static __checkReturn efx_rc_t
802 efx_mcdi_unlink_piobuf(
804 __in uint32_t vi_index)
807 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_UNLINK_PIOBUF_IN_LEN,
808 MC_CMD_UNLINK_PIOBUF_OUT_LEN);
811 req.emr_cmd = MC_CMD_UNLINK_PIOBUF;
812 req.emr_in_buf = payload;
813 req.emr_in_length = MC_CMD_UNLINK_PIOBUF_IN_LEN;
814 req.emr_out_buf = payload;
815 req.emr_out_length = MC_CMD_UNLINK_PIOBUF_OUT_LEN;
817 MCDI_IN_SET_DWORD(req, UNLINK_PIOBUF_IN_TXQ_INSTANCE, vi_index);
819 efx_mcdi_execute_quiet(enp, &req);
821 if (req.emr_rc != 0) {
829 EFSYS_PROBE1(fail1, efx_rc_t, rc);
835 ef10_nic_alloc_piobufs(
837 __in uint32_t max_piobuf_count)
839 efx_piobuf_handle_t *handlep;
842 EFSYS_ASSERT3U(max_piobuf_count, <=,
843 EFX_ARRAY_SIZE(enp->en_arch.ef10.ena_piobuf_handle));
845 enp->en_arch.ef10.ena_piobuf_count = 0;
847 for (i = 0; i < max_piobuf_count; i++) {
848 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
850 if (efx_mcdi_alloc_piobuf(enp, handlep) != 0)
853 enp->en_arch.ef10.ena_pio_alloc_map[i] = 0;
854 enp->en_arch.ef10.ena_piobuf_count++;
860 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
861 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
863 (void) efx_mcdi_free_piobuf(enp, *handlep);
864 *handlep = EFX_PIOBUF_HANDLE_INVALID;
866 enp->en_arch.ef10.ena_piobuf_count = 0;
871 ef10_nic_free_piobufs(
874 efx_piobuf_handle_t *handlep;
877 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
878 handlep = &enp->en_arch.ef10.ena_piobuf_handle[i];
880 (void) efx_mcdi_free_piobuf(enp, *handlep);
881 *handlep = EFX_PIOBUF_HANDLE_INVALID;
883 enp->en_arch.ef10.ena_piobuf_count = 0;
886 /* Sub-allocate a block from a piobuf */
887 __checkReturn efx_rc_t
889 __inout efx_nic_t *enp,
890 __out uint32_t *bufnump,
891 __out efx_piobuf_handle_t *handlep,
892 __out uint32_t *blknump,
893 __out uint32_t *offsetp,
896 efx_nic_cfg_t *encp = &enp->en_nic_cfg;
897 efx_drv_cfg_t *edcp = &enp->en_drv_cfg;
898 uint32_t blk_per_buf;
902 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
903 EFSYS_ASSERT(bufnump);
904 EFSYS_ASSERT(handlep);
905 EFSYS_ASSERT(blknump);
906 EFSYS_ASSERT(offsetp);
909 if ((edcp->edc_pio_alloc_size == 0) ||
910 (enp->en_arch.ef10.ena_piobuf_count == 0)) {
914 blk_per_buf = encp->enc_piobuf_size / edcp->edc_pio_alloc_size;
916 for (buf = 0; buf < enp->en_arch.ef10.ena_piobuf_count; buf++) {
917 uint32_t *map = &enp->en_arch.ef10.ena_pio_alloc_map[buf];
922 EFSYS_ASSERT3U(blk_per_buf, <=, (8 * sizeof (*map)));
923 for (blk = 0; blk < blk_per_buf; blk++) {
924 if ((*map & (1u << blk)) == 0) {
934 *handlep = enp->en_arch.ef10.ena_piobuf_handle[buf];
937 *sizep = edcp->edc_pio_alloc_size;
938 *offsetp = blk * (*sizep);
945 EFSYS_PROBE1(fail1, efx_rc_t, rc);
950 /* Free a piobuf sub-allocated block */
951 __checkReturn efx_rc_t
953 __inout efx_nic_t *enp,
954 __in uint32_t bufnum,
955 __in uint32_t blknum)
960 if ((bufnum >= enp->en_arch.ef10.ena_piobuf_count) ||
961 (blknum >= (8 * sizeof (*map)))) {
966 map = &enp->en_arch.ef10.ena_pio_alloc_map[bufnum];
967 if ((*map & (1u << blknum)) == 0) {
971 *map &= ~(1u << blknum);
978 EFSYS_PROBE1(fail1, efx_rc_t, rc);
983 __checkReturn efx_rc_t
985 __inout efx_nic_t *enp,
986 __in uint32_t vi_index,
987 __in efx_piobuf_handle_t handle)
989 return (efx_mcdi_link_piobuf(enp, vi_index, handle));
992 __checkReturn efx_rc_t
994 __inout efx_nic_t *enp,
995 __in uint32_t vi_index)
997 return (efx_mcdi_unlink_piobuf(enp, vi_index));
1000 #endif /* EFX_OPTS_EF10() */
1002 #if EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10()
1004 static __checkReturn efx_rc_t
1005 ef10_mcdi_get_pf_count(
1006 __in efx_nic_t *enp,
1007 __out uint32_t *pf_countp)
1010 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_PF_COUNT_IN_LEN,
1011 MC_CMD_GET_PF_COUNT_OUT_LEN);
1014 req.emr_cmd = MC_CMD_GET_PF_COUNT;
1015 req.emr_in_buf = payload;
1016 req.emr_in_length = MC_CMD_GET_PF_COUNT_IN_LEN;
1017 req.emr_out_buf = payload;
1018 req.emr_out_length = MC_CMD_GET_PF_COUNT_OUT_LEN;
1020 efx_mcdi_execute(enp, &req);
1022 if (req.emr_rc != 0) {
1027 if (req.emr_out_length_used < MC_CMD_GET_PF_COUNT_OUT_LEN) {
1032 *pf_countp = *MCDI_OUT(req, uint8_t,
1033 MC_CMD_GET_PF_COUNT_OUT_PF_COUNT_OFST);
1035 EFSYS_ASSERT(*pf_countp != 0);
1042 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1047 static __checkReturn efx_rc_t
1048 ef10_get_datapath_caps(
1049 __in efx_nic_t *enp)
1051 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1053 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_CAPABILITIES_IN_LEN,
1054 MC_CMD_GET_CAPABILITIES_V7_OUT_LEN);
1057 req.emr_cmd = MC_CMD_GET_CAPABILITIES;
1058 req.emr_in_buf = payload;
1059 req.emr_in_length = MC_CMD_GET_CAPABILITIES_IN_LEN;
1060 req.emr_out_buf = payload;
1061 req.emr_out_length = MC_CMD_GET_CAPABILITIES_V7_OUT_LEN;
1063 efx_mcdi_execute_quiet(enp, &req);
1065 if (req.emr_rc != 0) {
1070 if (req.emr_out_length_used < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
1075 #define CAP_FLAGS1(_req, _flag) \
1076 (MCDI_OUT_DWORD((_req), GET_CAPABILITIES_OUT_FLAGS1) & \
1077 (1u << (MC_CMD_GET_CAPABILITIES_V2_OUT_ ## _flag ## _LBN)))
1079 #define CAP_FLAGS2(_req, _flag) \
1080 (((_req).emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) && \
1081 (MCDI_OUT_DWORD((_req), GET_CAPABILITIES_V2_OUT_FLAGS2) & \
1082 (1u << (MC_CMD_GET_CAPABILITIES_V2_OUT_ ## _flag ## _LBN))))
1084 #define CAP_FLAGS3(_req, _flag) \
1085 (((_req).emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V7_OUT_LEN) && \
1086 (MCDI_OUT_DWORD((_req), GET_CAPABILITIES_V7_OUT_FLAGS3) & \
1087 (1u << (MC_CMD_GET_CAPABILITIES_V7_OUT_ ## _flag ## _LBN))))
1089 /* Check if RXDP firmware inserts 14 byte prefix */
1090 if (CAP_FLAGS1(req, RX_PREFIX_LEN_14))
1091 encp->enc_rx_prefix_size = 14;
1093 encp->enc_rx_prefix_size = 0;
1095 #if EFSYS_OPT_RX_SCALE
1096 /* Check if the firmware supports additional RSS modes */
1097 if (CAP_FLAGS1(req, ADDITIONAL_RSS_MODES))
1098 encp->enc_rx_scale_additional_modes_supported = B_TRUE;
1100 encp->enc_rx_scale_additional_modes_supported = B_FALSE;
1101 #endif /* EFSYS_OPT_RX_SCALE */
1103 /* Check if the firmware supports TSO */
1104 if (CAP_FLAGS1(req, TX_TSO))
1105 encp->enc_fw_assisted_tso_enabled = B_TRUE;
1107 encp->enc_fw_assisted_tso_enabled = B_FALSE;
1109 /* Check if the firmware supports FATSOv2 */
1110 if (CAP_FLAGS2(req, TX_TSO_V2)) {
1111 encp->enc_fw_assisted_tso_v2_enabled = B_TRUE;
1112 encp->enc_fw_assisted_tso_v2_n_contexts = MCDI_OUT_WORD(req,
1113 GET_CAPABILITIES_V2_OUT_TX_TSO_V2_N_CONTEXTS);
1115 encp->enc_fw_assisted_tso_v2_enabled = B_FALSE;
1116 encp->enc_fw_assisted_tso_v2_n_contexts = 0;
1119 /* Check if the firmware supports FATSOv2 encap */
1120 if (CAP_FLAGS2(req, TX_TSO_V2_ENCAP))
1121 encp->enc_fw_assisted_tso_v2_encap_enabled = B_TRUE;
1123 encp->enc_fw_assisted_tso_v2_encap_enabled = B_FALSE;
1125 /* Check if TSOv3 is supported */
1126 if (CAP_FLAGS2(req, TX_TSO_V3))
1127 encp->enc_tso_v3_enabled = B_TRUE;
1129 encp->enc_tso_v3_enabled = B_FALSE;
1131 /* Check if the firmware has vadapter/vport/vswitch support */
1132 if (CAP_FLAGS1(req, EVB))
1133 encp->enc_datapath_cap_evb = B_TRUE;
1135 encp->enc_datapath_cap_evb = B_FALSE;
1137 /* Check if the firmware supports vport reconfiguration */
1138 if (CAP_FLAGS1(req, VPORT_RECONFIGURE))
1139 encp->enc_vport_reconfigure_supported = B_TRUE;
1141 encp->enc_vport_reconfigure_supported = B_FALSE;
1143 /* Check if the firmware supports VLAN insertion */
1144 if (CAP_FLAGS1(req, TX_VLAN_INSERTION))
1145 encp->enc_hw_tx_insert_vlan_enabled = B_TRUE;
1147 encp->enc_hw_tx_insert_vlan_enabled = B_FALSE;
1149 /* Check if the firmware supports RX event batching */
1150 if (CAP_FLAGS1(req, RX_BATCHING))
1151 encp->enc_rx_batching_enabled = B_TRUE;
1153 encp->enc_rx_batching_enabled = B_FALSE;
1156 * Even if batching isn't reported as supported, we may still get
1157 * batched events (see bug61153).
1159 encp->enc_rx_batch_max = 16;
1161 /* Check if the firmware supports disabling scatter on RXQs */
1162 if (CAP_FLAGS1(req, RX_DISABLE_SCATTER))
1163 encp->enc_rx_disable_scatter_supported = B_TRUE;
1165 encp->enc_rx_disable_scatter_supported = B_FALSE;
1167 /* No limit on maximum number of Rx scatter elements per packet. */
1168 encp->enc_rx_scatter_max = -1;
1170 /* Check if the firmware supports packed stream mode */
1171 if (CAP_FLAGS1(req, RX_PACKED_STREAM))
1172 encp->enc_rx_packed_stream_supported = B_TRUE;
1174 encp->enc_rx_packed_stream_supported = B_FALSE;
1177 * Check if the firmware supports configurable buffer sizes
1178 * for packed stream mode (otherwise buffer size is 1Mbyte)
1180 if (CAP_FLAGS1(req, RX_PACKED_STREAM_VAR_BUFFERS))
1181 encp->enc_rx_var_packed_stream_supported = B_TRUE;
1183 encp->enc_rx_var_packed_stream_supported = B_FALSE;
1185 /* Check if the firmware supports equal stride super-buffer mode */
1186 if (CAP_FLAGS2(req, EQUAL_STRIDE_SUPER_BUFFER))
1187 encp->enc_rx_es_super_buffer_supported = B_TRUE;
1189 encp->enc_rx_es_super_buffer_supported = B_FALSE;
1191 /* Check if the firmware supports FW subvariant w/o Tx checksumming */
1192 if (CAP_FLAGS2(req, FW_SUBVARIANT_NO_TX_CSUM))
1193 encp->enc_fw_subvariant_no_tx_csum_supported = B_TRUE;
1195 encp->enc_fw_subvariant_no_tx_csum_supported = B_FALSE;
1197 /* Check if the firmware supports set mac with running filters */
1198 if (CAP_FLAGS1(req, VADAPTOR_PERMIT_SET_MAC_WHEN_FILTERS_INSTALLED))
1199 encp->enc_allow_set_mac_with_installed_filters = B_TRUE;
1201 encp->enc_allow_set_mac_with_installed_filters = B_FALSE;
1204 * Check if firmware supports the extended MC_CMD_SET_MAC, which allows
1205 * specifying which parameters to configure.
1207 if (CAP_FLAGS1(req, SET_MAC_ENHANCED))
1208 encp->enc_enhanced_set_mac_supported = B_TRUE;
1210 encp->enc_enhanced_set_mac_supported = B_FALSE;
1213 * Check if firmware supports version 2 of MC_CMD_INIT_EVQ, which allows
1214 * us to let the firmware choose the settings to use on an EVQ.
1216 if (CAP_FLAGS2(req, INIT_EVQ_V2))
1217 encp->enc_init_evq_v2_supported = B_TRUE;
1219 encp->enc_init_evq_v2_supported = B_FALSE;
1222 * Check if firmware supports extended width event queues, which have
1223 * a different event descriptor layout.
1225 if (CAP_FLAGS3(req, EXTENDED_WIDTH_EVQS_SUPPORTED))
1226 encp->enc_init_evq_extended_width_supported = B_TRUE;
1228 encp->enc_init_evq_extended_width_supported = B_FALSE;
1231 * Check if the NO_CONT_EV mode for RX events is supported.
1233 if (CAP_FLAGS2(req, INIT_RXQ_NO_CONT_EV))
1234 encp->enc_no_cont_ev_mode_supported = B_TRUE;
1236 encp->enc_no_cont_ev_mode_supported = B_FALSE;
1239 * Check if buffer size may and must be specified on INIT_RXQ.
1240 * It may be always specified to efx_rx_qcreate(), but will be
1241 * just kept libefx internal if MCDI does not support it.
1243 if (CAP_FLAGS2(req, INIT_RXQ_WITH_BUFFER_SIZE))
1244 encp->enc_init_rxq_with_buffer_size = B_TRUE;
1246 encp->enc_init_rxq_with_buffer_size = B_FALSE;
1249 * Check if firmware-verified NVRAM updates must be used.
1251 * The firmware trusted installer requires all NVRAM updates to use
1252 * version 2 of MC_CMD_NVRAM_UPDATE_START (to enable verified update)
1253 * and version 2 of MC_CMD_NVRAM_UPDATE_FINISH (to verify the updated
1254 * partition and report the result).
1256 if (CAP_FLAGS2(req, NVRAM_UPDATE_REPORT_VERIFY_RESULT))
1257 encp->enc_nvram_update_verify_result_supported = B_TRUE;
1259 encp->enc_nvram_update_verify_result_supported = B_FALSE;
1261 if (CAP_FLAGS2(req, NVRAM_UPDATE_POLL_VERIFY_RESULT))
1262 encp->enc_nvram_update_poll_verify_result_supported = B_TRUE;
1264 encp->enc_nvram_update_poll_verify_result_supported = B_FALSE;
1267 * Check if firmware update via the BUNDLE partition is supported
1269 if (CAP_FLAGS2(req, BUNDLE_UPDATE))
1270 encp->enc_nvram_bundle_update_supported = B_TRUE;
1272 encp->enc_nvram_bundle_update_supported = B_FALSE;
1275 * Check if firmware provides packet memory and Rx datapath
1278 if (CAP_FLAGS1(req, PM_AND_RXDP_COUNTERS))
1279 encp->enc_pm_and_rxdp_counters = B_TRUE;
1281 encp->enc_pm_and_rxdp_counters = B_FALSE;
1284 * Check if the 40G MAC hardware is capable of reporting
1285 * statistics for Tx size bins.
1287 if (CAP_FLAGS2(req, MAC_STATS_40G_TX_SIZE_BINS))
1288 encp->enc_mac_stats_40g_tx_size_bins = B_TRUE;
1290 encp->enc_mac_stats_40g_tx_size_bins = B_FALSE;
1293 * Check if firmware supports VXLAN and NVGRE tunnels.
1294 * The capability indicates Geneve protocol support as well.
1296 if (CAP_FLAGS1(req, VXLAN_NVGRE)) {
1297 encp->enc_tunnel_encapsulations_supported =
1298 (1u << EFX_TUNNEL_PROTOCOL_VXLAN) |
1299 (1u << EFX_TUNNEL_PROTOCOL_GENEVE) |
1300 (1u << EFX_TUNNEL_PROTOCOL_NVGRE);
1302 EFX_STATIC_ASSERT(EFX_TUNNEL_MAXNENTRIES ==
1303 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
1304 encp->enc_tunnel_config_udp_entries_max =
1305 EFX_TUNNEL_MAXNENTRIES;
1307 encp->enc_tunnel_config_udp_entries_max = 0;
1311 * Check if firmware reports the VI window mode.
1312 * Medford2 has a variable VI window size (8K, 16K or 64K).
1313 * Medford and Huntington have a fixed 8K VI window size.
1315 if (req.emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
1317 MCDI_OUT_BYTE(req, GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
1320 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
1321 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
1323 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
1324 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_16K;
1326 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
1327 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_64K;
1330 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_INVALID;
1333 } else if ((enp->en_family == EFX_FAMILY_HUNTINGTON) ||
1334 (enp->en_family == EFX_FAMILY_MEDFORD)) {
1335 /* Huntington and Medford have fixed 8K window size */
1336 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
1338 encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_INVALID;
1341 /* Check if firmware supports extended MAC stats. */
1342 if (req.emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
1343 /* Extended stats buffer supported */
1344 encp->enc_mac_stats_nstats = MCDI_OUT_WORD(req,
1345 GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
1347 /* Use Siena-compatible legacy MAC stats */
1348 encp->enc_mac_stats_nstats = MC_CMD_MAC_NSTATS;
1351 if (encp->enc_mac_stats_nstats >= MC_CMD_MAC_NSTATS_V2)
1352 encp->enc_fec_counters = B_TRUE;
1354 encp->enc_fec_counters = B_FALSE;
1356 /* Check if the firmware provides head-of-line blocking counters */
1357 if (CAP_FLAGS2(req, RXDP_HLB_IDLE))
1358 encp->enc_hlb_counters = B_TRUE;
1360 encp->enc_hlb_counters = B_FALSE;
1362 #if EFSYS_OPT_RX_SCALE
1363 if (CAP_FLAGS1(req, RX_RSS_LIMITED)) {
1364 /* Only one exclusive RSS context is available per port. */
1365 encp->enc_rx_scale_max_exclusive_contexts = 1;
1367 switch (enp->en_family) {
1368 case EFX_FAMILY_MEDFORD2:
1369 encp->enc_rx_scale_hash_alg_mask =
1370 (1U << EFX_RX_HASHALG_TOEPLITZ);
1373 case EFX_FAMILY_MEDFORD:
1374 case EFX_FAMILY_HUNTINGTON:
1376 * Packed stream firmware variant maintains a
1377 * non-standard algorithm for hash computation.
1378 * It implies explicit XORing together
1379 * source + destination IP addresses (or last
1380 * four bytes in the case of IPv6) and using the
1381 * resulting value as the input to a Toeplitz hash.
1383 encp->enc_rx_scale_hash_alg_mask =
1384 (1U << EFX_RX_HASHALG_PACKED_STREAM);
1392 /* Port numbers cannot contribute to the hash value */
1393 encp->enc_rx_scale_l4_hash_supported = B_FALSE;
1396 * Maximum number of exclusive RSS contexts.
1397 * EF10 hardware supports 64 in total, but 6 are reserved
1398 * for shared contexts. They are a global resource so
1399 * not all may be available.
1401 encp->enc_rx_scale_max_exclusive_contexts = 64 - 6;
1403 encp->enc_rx_scale_hash_alg_mask =
1404 (1U << EFX_RX_HASHALG_TOEPLITZ);
1407 * It is possible to use port numbers as
1408 * the input data for hash computation.
1410 encp->enc_rx_scale_l4_hash_supported = B_TRUE;
1412 #endif /* EFSYS_OPT_RX_SCALE */
1414 /* Check if the firmware supports "FLAG" and "MARK" filter actions */
1415 if (CAP_FLAGS2(req, FILTER_ACTION_FLAG))
1416 encp->enc_filter_action_flag_supported = B_TRUE;
1418 encp->enc_filter_action_flag_supported = B_FALSE;
1420 if (CAP_FLAGS2(req, FILTER_ACTION_MARK))
1421 encp->enc_filter_action_mark_supported = B_TRUE;
1423 encp->enc_filter_action_mark_supported = B_FALSE;
1425 /* Get maximum supported value for "MARK" filter action */
1426 if (req.emr_out_length_used >= MC_CMD_GET_CAPABILITIES_V5_OUT_LEN)
1427 encp->enc_filter_action_mark_max = MCDI_OUT_DWORD(req,
1428 GET_CAPABILITIES_V5_OUT_FILTER_ACTION_MARK_MAX);
1430 encp->enc_filter_action_mark_max = 0;
1434 * Check support for EF100 Match Action Engine (MAE).
1435 * MAE hardware is present on Riverhead boards (from R2),
1436 * and on Keystone, and requires support in firmware.
1438 * MAE control operations require MAE control privilege,
1439 * which is not available for VFs.
1441 * Privileges can change dynamically at runtime: we assume
1442 * MAE support requires the privilege is granted initially,
1443 * and ignore later dynamic changes.
1445 if (CAP_FLAGS3(req, MAE_SUPPORTED)) {
1446 encp->enc_mae_supported = B_TRUE;
1447 if (EFX_MCDI_HAVE_PRIVILEGE(encp->enc_privilege_mask, MAE))
1448 encp->enc_mae_admin = B_TRUE;
1450 encp->enc_mae_admin = B_FALSE;
1452 encp->enc_mae_supported = B_FALSE;
1453 encp->enc_mae_admin = B_FALSE;
1457 * Check support for MAE action set v2 features.
1458 * These provide support for packet edits.
1460 if (CAP_FLAGS3(req, MAE_ACTION_SET_ALLOC_V2_SUPPORTED))
1461 encp->enc_mae_aset_v2_supported = B_TRUE;
1463 encp->enc_mae_aset_v2_supported = B_FALSE;
1465 encp->enc_mae_supported = B_FALSE;
1466 encp->enc_mae_admin = B_FALSE;
1467 #endif /* EFSYS_OPT_MAE */
1475 #if EFSYS_OPT_RX_SCALE
1478 #endif /* EFSYS_OPT_RX_SCALE */
1482 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1488 #define EF10_LEGACY_PF_PRIVILEGE_MASK \
1489 (MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN | \
1490 MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK | \
1491 MC_CMD_PRIVILEGE_MASK_IN_GRP_ONLOAD | \
1492 MC_CMD_PRIVILEGE_MASK_IN_GRP_PTP | \
1493 MC_CMD_PRIVILEGE_MASK_IN_GRP_INSECURE_FILTERS | \
1494 MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING | \
1495 MC_CMD_PRIVILEGE_MASK_IN_GRP_UNICAST | \
1496 MC_CMD_PRIVILEGE_MASK_IN_GRP_MULTICAST | \
1497 MC_CMD_PRIVILEGE_MASK_IN_GRP_BROADCAST | \
1498 MC_CMD_PRIVILEGE_MASK_IN_GRP_ALL_MULTICAST | \
1499 MC_CMD_PRIVILEGE_MASK_IN_GRP_PROMISCUOUS)
1501 #define EF10_LEGACY_VF_PRIVILEGE_MASK 0
1504 __checkReturn efx_rc_t
1505 ef10_get_privilege_mask(
1506 __in efx_nic_t *enp,
1507 __out uint32_t *maskp)
1509 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1513 if ((rc = efx_mcdi_privilege_mask(enp, encp->enc_pf, encp->enc_vf,
1518 /* Fallback for old firmware without privilege mask support */
1519 if (EFX_PCI_FUNCTION_IS_PF(encp)) {
1520 /* Assume PF has admin privilege */
1521 mask = EF10_LEGACY_PF_PRIVILEGE_MASK;
1523 /* VF is always unprivileged by default */
1524 mask = EF10_LEGACY_VF_PRIVILEGE_MASK;
1533 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1539 #define EFX_EXT_PORT_MAX 4
1540 #define EFX_EXT_PORT_NA 0xFF
1543 * Table of mapping schemes from port number to external number.
1545 * Each port number ultimately corresponds to a connector: either as part of
1546 * a cable assembly attached to a module inserted in an SFP+/QSFP+ cage on
1547 * the board, or fixed to the board (e.g. 10GBASE-T magjack on SFN5121T
1548 * "Salina"). In general:
1550 * Port number (0-based)
1552 * port mapping (n:1)
1555 * External port number (1-based)
1557 * fixed (1:1) or cable assembly (1:m)
1562 * The external numbering refers to the cages or magjacks on the board,
1563 * as visibly annotated on the board or back panel. This table describes
1564 * how to determine which external cage/magjack corresponds to the port
1565 * numbers used by the driver.
1567 * The count of consecutive port numbers that map to each external number,
1568 * is determined by the chip family and the current port mode.
1570 * For the Huntington family, the current port mode cannot be discovered,
1571 * but a single mapping is used by all modes for a given chip variant,
1572 * so the mapping used is instead the last match in the table to the full
1573 * set of port modes to which the NIC can be configured. Therefore the
1574 * ordering of entries in the mapping table is significant.
1576 static struct ef10_external_port_map_s {
1577 efx_family_t family;
1578 uint32_t modes_mask;
1579 uint8_t base_port[EFX_EXT_PORT_MAX];
1580 } __ef10_external_port_mappings[] = {
1582 * Modes used by Huntington family controllers where each port
1583 * number maps to a separate cage.
1584 * SFN7x22F (Torino):
1594 EFX_FAMILY_HUNTINGTON,
1595 (1U << TLV_PORT_MODE_10G) | /* mode 0 */
1596 (1U << TLV_PORT_MODE_10G_10G) | /* mode 2 */
1597 (1U << TLV_PORT_MODE_10G_10G_10G_10G), /* mode 4 */
1601 * Modes which for Huntington identify a chip variant where 2
1602 * adjacent port numbers map to each cage.
1610 EFX_FAMILY_HUNTINGTON,
1611 (1U << TLV_PORT_MODE_40G) | /* mode 1 */
1612 (1U << TLV_PORT_MODE_40G_40G) | /* mode 3 */
1613 (1U << TLV_PORT_MODE_40G_10G_10G) | /* mode 6 */
1614 (1U << TLV_PORT_MODE_10G_10G_40G), /* mode 7 */
1615 { 0, 2, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1618 * Modes that on Medford allocate each port number to a separate
1627 (1U << TLV_PORT_MODE_1x1_NA) | /* mode 0 */
1628 (1U << TLV_PORT_MODE_1x4_NA) | /* mode 1 */
1629 (1U << TLV_PORT_MODE_1x1_1x1), /* mode 2 */
1633 * Modes that on Medford allocate 2 adjacent port numbers to each
1642 (1U << TLV_PORT_MODE_1x4_1x4) | /* mode 3 */
1643 (1U << TLV_PORT_MODE_2x1_2x1) | /* mode 5 */
1644 (1U << TLV_PORT_MODE_1x4_2x1) | /* mode 6 */
1645 (1U << TLV_PORT_MODE_2x1_1x4) | /* mode 7 */
1646 /* Do not use 10G_10G_10G_10G_Q1_Q2 (see bug63270) */
1647 (1U << TLV_PORT_MODE_10G_10G_10G_10G_Q1_Q2), /* mode 9 */
1648 { 0, 2, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1651 * Modes that on Medford allocate 4 adjacent port numbers to
1660 /* Do not use 10G_10G_10G_10G_Q1 (see bug63270) */
1661 (1U << TLV_PORT_MODE_4x1_NA), /* mode 4 */
1662 { 0, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1665 * Modes that on Medford allocate 4 adjacent port numbers to
1674 (1U << TLV_PORT_MODE_NA_4x1), /* mode 8 */
1675 { EFX_EXT_PORT_NA, 0, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1678 * Modes that on Medford2 allocate each port number to a separate
1686 EFX_FAMILY_MEDFORD2,
1687 (1U << TLV_PORT_MODE_1x1_NA) | /* mode 0 */
1688 (1U << TLV_PORT_MODE_1x4_NA) | /* mode 1 */
1689 (1U << TLV_PORT_MODE_1x1_1x1) | /* mode 2 */
1690 (1U << TLV_PORT_MODE_1x4_1x4) | /* mode 3 */
1691 (1U << TLV_PORT_MODE_1x2_NA) | /* mode 10 */
1692 (1U << TLV_PORT_MODE_1x2_1x2) | /* mode 12 */
1693 (1U << TLV_PORT_MODE_1x4_1x2) | /* mode 15 */
1694 (1U << TLV_PORT_MODE_1x2_1x4), /* mode 16 */
1698 * Modes that on Medford2 allocate 1 port to cage 1 and the rest
1705 EFX_FAMILY_MEDFORD2,
1706 (1U << TLV_PORT_MODE_1x2_2x1) | /* mode 17 */
1707 (1U << TLV_PORT_MODE_1x4_2x1), /* mode 6 */
1708 { 0, 1, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1711 * Modes that on Medford2 allocate 2 adjacent port numbers to cage 1
1712 * and the rest to cage 2.
1719 EFX_FAMILY_MEDFORD2,
1720 (1U << TLV_PORT_MODE_2x1_2x1) | /* mode 4 */
1721 (1U << TLV_PORT_MODE_2x1_1x4) | /* mode 7 */
1722 (1U << TLV_PORT_MODE_2x2_NA) | /* mode 13 */
1723 (1U << TLV_PORT_MODE_2x1_1x2), /* mode 18 */
1724 { 0, 2, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1727 * Modes that on Medford2 allocate up to 4 adjacent port numbers
1735 EFX_FAMILY_MEDFORD2,
1736 (1U << TLV_PORT_MODE_4x1_NA), /* mode 5 */
1737 { 0, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1740 * Modes that on Medford2 allocate up to 4 adjacent port numbers
1748 EFX_FAMILY_MEDFORD2,
1749 (1U << TLV_PORT_MODE_NA_4x1) | /* mode 8 */
1750 (1U << TLV_PORT_MODE_NA_1x2) | /* mode 11 */
1751 (1U << TLV_PORT_MODE_NA_2x2), /* mode 14 */
1752 { EFX_EXT_PORT_NA, 0, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1755 * Modes that on Riverhead allocate each port number to a separate
1761 EFX_FAMILY_RIVERHEAD,
1762 (1U << TLV_PORT_MODE_1x1_NA) | /* mode 0 */
1763 (1U << TLV_PORT_MODE_1x4_NA) | /* mode 1 */
1764 (1U << TLV_PORT_MODE_1x1_1x1), /* mode 2 */
1765 { 0, 1, EFX_EXT_PORT_NA, EFX_EXT_PORT_NA }
1769 static __checkReturn efx_rc_t
1770 ef10_external_port_mapping(
1771 __in efx_nic_t *enp,
1773 __out uint8_t *external_portp)
1777 uint32_t port_modes;
1780 struct ef10_external_port_map_s *mapp = NULL;
1781 int ext_index = port; /* Default 1-1 mapping */
1783 if ((rc = efx_mcdi_get_port_modes(enp, &port_modes, ¤t,
1786 * No current port mode information (i.e. Huntington)
1787 * - infer mapping from available modes
1789 if ((rc = efx_mcdi_get_port_modes(enp,
1790 &port_modes, NULL, NULL)) != 0) {
1792 * No port mode information available
1793 * - use default mapping
1798 /* Only need to scan the current mode */
1799 port_modes = 1 << current;
1803 * Infer the internal port -> external number mapping from
1804 * the possible port modes for this NIC.
1806 for (i = 0; i < EFX_ARRAY_SIZE(__ef10_external_port_mappings); ++i) {
1807 struct ef10_external_port_map_s *eepmp =
1808 &__ef10_external_port_mappings[i];
1809 if (eepmp->family != enp->en_family)
1811 matches = (eepmp->modes_mask & port_modes);
1814 * Some modes match. For some Huntington boards
1815 * there will be multiple matches. The mapping on the
1816 * last match is used.
1819 port_modes &= ~matches;
1823 if (port_modes != 0) {
1824 /* Some advertised modes are not supported */
1832 * External ports are assigned a sequence of consecutive
1833 * port numbers, so find the one with the closest base_port.
1835 uint32_t delta = EFX_EXT_PORT_NA;
1837 for (i = 0; i < EFX_EXT_PORT_MAX; i++) {
1838 uint32_t base = mapp->base_port[i];
1839 if ((base != EFX_EXT_PORT_NA) && (base <= port)) {
1840 if ((port - base) < delta) {
1841 delta = (port - base);
1847 *external_portp = (uint8_t)(ext_index + 1);
1852 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1857 static __checkReturn efx_rc_t
1858 efx_mcdi_get_nic_addr_caps(
1859 __in efx_nic_t *enp)
1861 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1862 uint32_t mapping_type;
1865 rc = efx_mcdi_get_nic_addr_info(enp, &mapping_type);
1867 if (rc == ENOTSUP) {
1868 encp->enc_dma_mapping = EFX_NIC_DMA_MAPPING_FLAT;
1874 switch (mapping_type) {
1875 case MC_CMD_GET_DESC_ADDR_INFO_OUT_MAPPING_FLAT:
1876 encp->enc_dma_mapping = EFX_NIC_DMA_MAPPING_FLAT;
1878 case MC_CMD_GET_DESC_ADDR_INFO_OUT_MAPPING_REGIONED:
1879 encp->enc_dma_mapping = EFX_NIC_DMA_MAPPING_REGIONED;
1880 rc = efx_mcdi_get_nic_addr_regions(enp,
1881 &enp->en_dma.end_u.endu_region_info);
1897 EFSYS_PROBE1(fail1, efx_rc_t, rc);
1902 __checkReturn efx_rc_t
1903 efx_mcdi_nic_board_cfg(
1904 __in efx_nic_t *enp)
1906 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
1907 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
1908 ef10_link_state_t els;
1909 efx_port_t *epp = &(enp->en_port);
1910 efx_pcie_interface_t intf;
1911 uint32_t board_type = 0;
1912 uint32_t base, nvec;
1917 uint8_t mac_addr[6] = { 0 };
1920 /* Get the (zero-based) MCDI port number */
1921 if ((rc = efx_mcdi_get_port_assignment(enp, &port)) != 0)
1924 /* EFX MCDI interface uses one-based port numbers */
1925 emip->emi_port = port + 1;
1927 encp->enc_assigned_port = port;
1929 if ((rc = ef10_external_port_mapping(enp, port,
1930 &encp->enc_external_port)) != 0)
1934 * Get PCIe function number from firmware (used for
1935 * per-function privilege and dynamic config info).
1936 * - PCIe PF: pf = PF number, vf = 0xffff.
1937 * - PCIe VF: pf = parent PF, vf = VF number.
1939 if ((rc = efx_mcdi_get_function_info(enp, &pf, &vf, &intf)) != 0)
1944 encp->enc_intf = intf;
1946 if ((rc = ef10_mcdi_get_pf_count(enp, &encp->enc_hw_pf_count)) != 0)
1949 /* MAC address for this function */
1950 if (EFX_PCI_FUNCTION_IS_PF(encp)) {
1951 rc = efx_mcdi_get_mac_address_pf(enp, mac_addr);
1952 #if EFSYS_OPT_ALLOW_UNCONFIGURED_NIC
1954 * Disable static config checking, ONLY for manufacturing test
1955 * and setup at the factory, to allow the static config to be
1958 #else /* EFSYS_OPT_ALLOW_UNCONFIGURED_NIC */
1959 if ((rc == 0) && (mac_addr[0] & 0x02)) {
1961 * If the static config does not include a global MAC
1962 * address pool then the board may return a locally
1963 * administered MAC address (this should only happen on
1964 * incorrectly programmed boards).
1968 #endif /* EFSYS_OPT_ALLOW_UNCONFIGURED_NIC */
1970 rc = efx_mcdi_get_mac_address_vf(enp, mac_addr);
1975 EFX_MAC_ADDR_COPY(encp->enc_mac_addr, mac_addr);
1978 * Get the current privilege mask. Note that this may be modified
1979 * dynamically, so for most cases the value is informational only.
1980 * If the privilege being discovered can't be granted dynamically,
1981 * it's fine to rely on the value. In all other cases, DO NOT use
1982 * the privilege mask to check for sufficient privileges, as that
1983 * can result in time-of-check/time-of-use bugs.
1985 if ((rc = ef10_get_privilege_mask(enp, &mask)) != 0)
1987 encp->enc_privilege_mask = mask;
1989 /* Board configuration (legacy) */
1990 rc = efx_mcdi_get_board_cfg(enp, &board_type, NULL, NULL);
1992 /* Unprivileged functions may not be able to read board cfg */
1999 encp->enc_board_type = board_type;
2001 /* Fill out fields in enp->en_port and enp->en_nic_cfg from MCDI */
2002 if ((rc = efx_mcdi_get_phy_cfg(enp)) != 0)
2006 * Firmware with support for *_FEC capability bits does not
2007 * report that the corresponding *_FEC_REQUESTED bits are supported.
2008 * Add them here so that drivers understand that they are supported.
2010 if (epp->ep_phy_cap_mask & (1u << EFX_PHY_CAP_BASER_FEC))
2011 epp->ep_phy_cap_mask |=
2012 (1u << EFX_PHY_CAP_BASER_FEC_REQUESTED);
2013 if (epp->ep_phy_cap_mask & (1u << EFX_PHY_CAP_RS_FEC))
2014 epp->ep_phy_cap_mask |=
2015 (1u << EFX_PHY_CAP_RS_FEC_REQUESTED);
2016 if (epp->ep_phy_cap_mask & (1u << EFX_PHY_CAP_25G_BASER_FEC))
2017 epp->ep_phy_cap_mask |=
2018 (1u << EFX_PHY_CAP_25G_BASER_FEC_REQUESTED);
2020 /* Obtain the default PHY advertised capabilities */
2021 if ((rc = ef10_phy_get_link(enp, &els)) != 0)
2023 epp->ep_default_adv_cap_mask = els.epls.epls_adv_cap_mask;
2024 epp->ep_adv_cap_mask = els.epls.epls_adv_cap_mask;
2026 /* Check capabilities of running datapath firmware */
2027 if ((rc = ef10_get_datapath_caps(enp)) != 0)
2030 /* Get interrupt vector limits */
2031 if ((rc = efx_mcdi_get_vector_cfg(enp, &base, &nvec, NULL)) != 0) {
2032 if (EFX_PCI_FUNCTION_IS_PF(encp))
2035 /* Ignore error (cannot query vector limits from a VF). */
2039 encp->enc_intr_vec_base = base;
2040 encp->enc_intr_limit = nvec;
2042 rc = efx_mcdi_get_nic_addr_caps(enp);
2049 EFSYS_PROBE(fail12);
2051 EFSYS_PROBE(fail11);
2053 EFSYS_PROBE(fail10);
2071 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2076 __checkReturn efx_rc_t
2077 efx_mcdi_entity_reset(
2078 __in efx_nic_t *enp)
2081 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_ENTITY_RESET_IN_LEN,
2082 MC_CMD_ENTITY_RESET_OUT_LEN);
2085 req.emr_cmd = MC_CMD_ENTITY_RESET;
2086 req.emr_in_buf = payload;
2087 req.emr_in_length = MC_CMD_ENTITY_RESET_IN_LEN;
2088 req.emr_out_buf = payload;
2089 req.emr_out_length = MC_CMD_ENTITY_RESET_OUT_LEN;
2091 MCDI_IN_POPULATE_DWORD_1(req, ENTITY_RESET_IN_FLAG,
2092 ENTITY_RESET_IN_FUNCTION_RESOURCE_RESET, 1);
2094 efx_mcdi_execute(enp, &req);
2096 if (req.emr_rc != 0) {
2104 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2109 #endif /* EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10() */
2113 static __checkReturn efx_rc_t
2114 ef10_set_workaround_bug26807(
2115 __in efx_nic_t *enp)
2117 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2122 * If the bug26807 workaround is enabled, then firmware has enabled
2123 * support for chained multicast filters. Firmware will reset (FLR)
2124 * functions which have filters in the hardware filter table when the
2125 * workaround is enabled/disabled.
2127 * We must recheck if the workaround is enabled after inserting the
2128 * first hardware filter, in case it has been changed since this check.
2130 rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG26807,
2133 encp->enc_bug26807_workaround = B_TRUE;
2134 if (flags & (1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN)) {
2136 * Other functions had installed filters before the
2137 * workaround was enabled, and they have been reset
2140 EFSYS_PROBE(bug26807_workaround_flr_done);
2141 /* FIXME: bump MC warm boot count ? */
2143 } else if (rc == EACCES) {
2145 * Unprivileged functions cannot enable the workaround in older
2148 encp->enc_bug26807_workaround = B_FALSE;
2149 } else if ((rc == ENOTSUP) || (rc == ENOENT)) {
2150 encp->enc_bug26807_workaround = B_FALSE;
2158 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2163 static __checkReturn efx_rc_t
2165 __in efx_nic_t *enp)
2167 const efx_nic_ops_t *enop = enp->en_enop;
2168 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2171 if ((rc = efx_mcdi_nic_board_cfg(enp)) != 0)
2175 * Huntington RXDP firmware inserts a 0 or 14 byte prefix.
2176 * We only support the 14 byte prefix here.
2178 if (encp->enc_rx_prefix_size != 14) {
2183 encp->enc_clk_mult = 1; /* not used for EF10 */
2185 /* Alignment for WPTR updates */
2186 encp->enc_rx_push_align = EF10_RX_WPTR_ALIGN;
2188 encp->enc_tx_dma_desc_size_max = EFX_MASK32(ESF_DZ_RX_KER_BYTE_CNT);
2189 /* No boundary crossing limits */
2190 encp->enc_tx_dma_desc_boundary = 0;
2193 * Maximum number of bytes into the frame the TCP header can start for
2194 * firmware assisted TSO to work.
2196 encp->enc_tx_tso_tcp_header_offset_limit = EF10_TCP_HEADER_OFFSET_LIMIT;
2198 /* EF10 TSO engine demands that packet header be contiguous. */
2199 encp->enc_tx_tso_max_header_ndescs = 1;
2201 /* The overall TSO header length is not limited. */
2202 encp->enc_tx_tso_max_header_length = UINT32_MAX;
2205 * There are no specific limitations on the number of
2206 * TSO payload descriptors.
2208 encp->enc_tx_tso_max_payload_ndescs = UINT32_MAX;
2210 /* TSO superframe payload length is not limited. */
2211 encp->enc_tx_tso_max_payload_length = UINT32_MAX;
2214 * Limitation on the maximum number of outgoing packets per
2215 * TSO transaction described in SF-108452-SW.
2217 encp->enc_tx_tso_max_nframes = 32767;
2220 * Set resource limits for MC_CMD_ALLOC_VIS. Note that we cannot use
2221 * MC_CMD_GET_RESOURCE_LIMITS here as that reports the available
2222 * resources (allocated to this PCIe function), which is zero until
2223 * after we have allocated VIs.
2225 encp->enc_evq_limit = 1024;
2226 encp->enc_rxq_limit = EFX_RXQ_LIMIT_TARGET;
2227 encp->enc_txq_limit = EFX_TXQ_LIMIT_TARGET;
2229 encp->enc_buftbl_limit = UINT32_MAX;
2231 if ((rc = ef10_set_workaround_bug26807(enp)) != 0)
2234 /* Get remaining controller-specific board config */
2235 if ((rc = enop->eno_board_cfg(enp)) != 0)
2248 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2253 __checkReturn efx_rc_t
2255 __in efx_nic_t *enp)
2257 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2258 efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
2261 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
2263 /* Read and clear any assertion state */
2264 if ((rc = efx_mcdi_read_assertion(enp)) != 0)
2267 /* Exit the assertion handler */
2268 if ((rc = efx_mcdi_exit_assertion_handler(enp)) != 0)
2272 if ((rc = efx_mcdi_drv_attach(enp, B_TRUE)) != 0)
2275 if ((rc = ef10_nic_board_cfg(enp)) != 0)
2279 * Set default driver config limits (based on board config).
2281 * FIXME: For now allocate a fixed number of VIs which is likely to be
2282 * sufficient and small enough to allow multiple functions on the same
2285 edcp->edc_min_vi_count = edcp->edc_max_vi_count =
2286 MIN(128, MAX(encp->enc_rxq_limit, encp->enc_txq_limit));
2288 /* The client driver must configure and enable PIO buffer support */
2289 edcp->edc_max_piobuf_count = 0;
2290 edcp->edc_pio_alloc_size = 0;
2292 #if EFSYS_OPT_MAC_STATS
2293 /* Wipe the MAC statistics */
2294 if ((rc = efx_mcdi_mac_stats_clear(enp)) != 0)
2298 #if EFSYS_OPT_LOOPBACK
2299 if ((rc = efx_mcdi_get_loopback_modes(enp)) != 0)
2303 #if EFSYS_OPT_MON_STATS
2304 if ((rc = mcdi_mon_cfg_build(enp)) != 0) {
2305 /* Unprivileged functions do not have access to sensors */
2313 #if EFSYS_OPT_MON_STATS
2317 #if EFSYS_OPT_LOOPBACK
2321 #if EFSYS_OPT_MAC_STATS
2332 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2337 __checkReturn efx_rc_t
2338 ef10_nic_set_drv_limits(
2339 __inout efx_nic_t *enp,
2340 __in efx_drv_limits_t *edlp)
2342 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
2343 efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
2344 uint32_t min_evq_count, max_evq_count;
2345 uint32_t min_rxq_count, max_rxq_count;
2346 uint32_t min_txq_count, max_txq_count;
2354 /* Get minimum required and maximum usable VI limits */
2355 min_evq_count = MIN(edlp->edl_min_evq_count, encp->enc_evq_limit);
2356 min_rxq_count = MIN(edlp->edl_min_rxq_count, encp->enc_rxq_limit);
2357 min_txq_count = MIN(edlp->edl_min_txq_count, encp->enc_txq_limit);
2359 edcp->edc_min_vi_count =
2360 MAX(min_evq_count, MAX(min_rxq_count, min_txq_count));
2362 max_evq_count = MIN(edlp->edl_max_evq_count, encp->enc_evq_limit);
2363 max_rxq_count = MIN(edlp->edl_max_rxq_count, encp->enc_rxq_limit);
2364 max_txq_count = MIN(edlp->edl_max_txq_count, encp->enc_txq_limit);
2366 edcp->edc_max_vi_count =
2367 MAX(max_evq_count, MAX(max_rxq_count, max_txq_count));
2370 * Check limits for sub-allocated piobuf blocks.
2371 * PIO is optional, so don't fail if the limits are incorrect.
2373 if ((encp->enc_piobuf_size == 0) ||
2374 (encp->enc_piobuf_limit == 0) ||
2375 (edlp->edl_min_pio_alloc_size == 0) ||
2376 (edlp->edl_min_pio_alloc_size > encp->enc_piobuf_size)) {
2378 edcp->edc_max_piobuf_count = 0;
2379 edcp->edc_pio_alloc_size = 0;
2381 uint32_t blk_size, blk_count, blks_per_piobuf;
2384 MAX(edlp->edl_min_pio_alloc_size,
2385 encp->enc_piobuf_min_alloc_size);
2387 blks_per_piobuf = encp->enc_piobuf_size / blk_size;
2388 EFSYS_ASSERT3U(blks_per_piobuf, <=, 32);
2390 blk_count = (encp->enc_piobuf_limit * blks_per_piobuf);
2392 /* A zero max pio alloc count means unlimited */
2393 if ((edlp->edl_max_pio_alloc_count > 0) &&
2394 (edlp->edl_max_pio_alloc_count < blk_count)) {
2395 blk_count = edlp->edl_max_pio_alloc_count;
2398 edcp->edc_pio_alloc_size = blk_size;
2399 edcp->edc_max_piobuf_count =
2400 (blk_count + (blks_per_piobuf - 1)) / blks_per_piobuf;
2406 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2412 __checkReturn efx_rc_t
2414 __in efx_nic_t *enp)
2418 /* ef10_nic_reset() is called to recover from BADASSERT failures. */
2419 if ((rc = efx_mcdi_read_assertion(enp)) != 0)
2421 if ((rc = efx_mcdi_exit_assertion_handler(enp)) != 0)
2424 if ((rc = efx_mcdi_entity_reset(enp)) != 0)
2427 /* Clear RX/TX DMA queue errors */
2428 enp->en_reset_flags &= ~(EFX_RESET_RXQ_ERR | EFX_RESET_TXQ_ERR);
2437 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2442 #endif /* EFX_OPTS_EF10() */
2444 #if EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10()
2446 __checkReturn efx_rc_t
2447 ef10_upstream_port_vadaptor_alloc(
2448 __in efx_nic_t *enp)
2455 * On a VF, this may fail with MC_CMD_ERR_NO_EVB_PORT (ENOENT) if the PF
2456 * driver has yet to bring up the EVB port. See bug 56147. In this case,
2457 * retry the request several times after waiting a while. The wait time
2458 * between retries starts small (10ms) and exponentially increases.
2459 * Total wait time is a little over two seconds. Retry logic in the
2460 * client driver may mean this whole loop is repeated if it continues to
2465 while ((rc = efx_mcdi_vadaptor_alloc(enp, EVB_PORT_ID_ASSIGNED)) != 0) {
2466 if (EFX_PCI_FUNCTION_IS_PF(&enp->en_nic_cfg) ||
2469 * Do not retry alloc for PF, or for other errors on
2475 /* VF startup before PF is ready. Retry allocation. */
2477 /* Too many attempts */
2481 EFSYS_PROBE1(mcdi_no_evb_port_retry, int, retry);
2482 EFSYS_SLEEP(delay_us);
2484 if (delay_us < 500000)
2493 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2498 #endif /* EFSYS_OPT_RIVERHEAD || EFX_OPTS_EF10() */
2502 __checkReturn efx_rc_t
2504 __in efx_nic_t *enp)
2506 efx_drv_cfg_t *edcp = &(enp->en_drv_cfg);
2507 uint32_t min_vi_count, max_vi_count;
2508 uint32_t vi_count, vi_base, vi_shift;
2510 uint32_t vi_window_size;
2512 boolean_t alloc_vadaptor = B_TRUE;
2514 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
2516 /* Enable reporting of some events (e.g. link change) */
2517 if ((rc = efx_mcdi_log_ctrl(enp)) != 0)
2520 /* Allocate (optional) on-chip PIO buffers */
2521 ef10_nic_alloc_piobufs(enp, edcp->edc_max_piobuf_count);
2524 * For best performance, PIO writes should use a write-combined
2525 * (WC) memory mapping. Using a separate WC mapping for the PIO
2526 * aperture of each VI would be a burden to drivers (and not
2527 * possible if the host page size is >4Kbyte).
2529 * To avoid this we use a single uncached (UC) mapping for VI
2530 * register access, and a single WC mapping for extra VIs used
2533 * Each piobuf must be linked to a VI in the WC mapping, and to
2534 * each VI that is using a sub-allocated block from the piobuf.
2536 min_vi_count = edcp->edc_min_vi_count;
2538 edcp->edc_max_vi_count + enp->en_arch.ef10.ena_piobuf_count;
2540 /* Ensure that the previously attached driver's VIs are freed */
2541 if ((rc = efx_mcdi_free_vis(enp)) != 0)
2545 * Reserve VI resources (EVQ+RXQ+TXQ) for this PCIe function. If this
2546 * fails then retrying the request for fewer VI resources may succeed.
2549 if ((rc = efx_mcdi_alloc_vis(enp, min_vi_count, max_vi_count,
2550 &vi_base, &vi_count, &vi_shift)) != 0)
2553 EFSYS_PROBE2(vi_alloc, uint32_t, vi_base, uint32_t, vi_count);
2555 if (vi_count < min_vi_count) {
2560 enp->en_arch.ef10.ena_vi_base = vi_base;
2561 enp->en_arch.ef10.ena_vi_count = vi_count;
2562 enp->en_arch.ef10.ena_vi_shift = vi_shift;
2564 if (vi_count < min_vi_count + enp->en_arch.ef10.ena_piobuf_count) {
2565 /* Not enough extra VIs to map piobufs */
2566 ef10_nic_free_piobufs(enp);
2569 enp->en_arch.ef10.ena_pio_write_vi_base =
2570 vi_count - enp->en_arch.ef10.ena_piobuf_count;
2572 EFSYS_ASSERT3U(enp->en_nic_cfg.enc_vi_window_shift, !=,
2573 EFX_VI_WINDOW_SHIFT_INVALID);
2574 EFSYS_ASSERT3U(enp->en_nic_cfg.enc_vi_window_shift, <=,
2575 EFX_VI_WINDOW_SHIFT_64K);
2576 vi_window_size = 1U << enp->en_nic_cfg.enc_vi_window_shift;
2578 /* Save UC memory mapping details */
2579 enp->en_arch.ef10.ena_uc_mem_map_offset = 0;
2580 if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2581 enp->en_arch.ef10.ena_uc_mem_map_size =
2583 enp->en_arch.ef10.ena_pio_write_vi_base);
2585 enp->en_arch.ef10.ena_uc_mem_map_size =
2587 enp->en_arch.ef10.ena_vi_count);
2590 /* Save WC memory mapping details */
2591 enp->en_arch.ef10.ena_wc_mem_map_offset =
2592 enp->en_arch.ef10.ena_uc_mem_map_offset +
2593 enp->en_arch.ef10.ena_uc_mem_map_size;
2595 enp->en_arch.ef10.ena_wc_mem_map_size =
2597 enp->en_arch.ef10.ena_piobuf_count);
2599 /* Link piobufs to extra VIs in WC mapping */
2600 if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2601 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
2602 rc = efx_mcdi_link_piobuf(enp,
2603 enp->en_arch.ef10.ena_pio_write_vi_base + i,
2604 enp->en_arch.ef10.ena_piobuf_handle[i]);
2611 * For SR-IOV use case, vAdaptor is allocated for PF and associated VFs
2612 * during NIC initialization when vSwitch is created and vports are
2613 * allocated. Hence, skip vAdaptor allocation for EVB and update vport
2614 * id in NIC structure with the one allocated for PF.
2617 enp->en_vport_id = EVB_PORT_ID_ASSIGNED;
2619 if ((enp->en_vswitchp != NULL) && (enp->en_vswitchp->ev_evcp != NULL)) {
2620 /* For EVB use vport allocated on vswitch */
2621 enp->en_vport_id = enp->en_vswitchp->ev_evcp->evc_vport_id;
2622 alloc_vadaptor = B_FALSE;
2625 if (alloc_vadaptor != B_FALSE) {
2626 /* Allocate a vAdaptor attached to our upstream vPort/pPort */
2627 if ((rc = ef10_upstream_port_vadaptor_alloc(enp)) != 0)
2630 enp->en_nic_cfg.enc_mcdi_max_payload_length = MCDI_CTL_SDU_LEN_MAX_V2;
2643 ef10_nic_free_piobufs(enp);
2646 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2651 __checkReturn efx_rc_t
2652 ef10_nic_get_vi_pool(
2653 __in efx_nic_t *enp,
2654 __out uint32_t *vi_countp)
2656 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
2659 * Report VIs that the client driver can use.
2660 * Do not include VIs used for PIO buffer writes.
2662 *vi_countp = enp->en_arch.ef10.ena_pio_write_vi_base;
2667 __checkReturn efx_rc_t
2668 ef10_nic_get_bar_region(
2669 __in efx_nic_t *enp,
2670 __in efx_nic_region_t region,
2671 __out uint32_t *offsetp,
2672 __out size_t *sizep)
2676 EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
2679 * TODO: Specify host memory mapping alignment and granularity
2680 * in efx_drv_limits_t so that they can be taken into account
2681 * when allocating extra VIs for PIO writes.
2685 /* UC mapped memory BAR region for VI registers */
2686 *offsetp = enp->en_arch.ef10.ena_uc_mem_map_offset;
2687 *sizep = enp->en_arch.ef10.ena_uc_mem_map_size;
2690 case EFX_REGION_PIO_WRITE_VI:
2691 /* WC mapped memory BAR region for piobuf writes */
2692 *offsetp = enp->en_arch.ef10.ena_wc_mem_map_offset;
2693 *sizep = enp->en_arch.ef10.ena_wc_mem_map_size;
2704 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2709 __checkReturn boolean_t
2710 ef10_nic_hw_unavailable(
2711 __in efx_nic_t *enp)
2715 if (enp->en_reset_flags & EFX_RESET_HW_UNAVAIL)
2718 EFX_BAR_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, &dword, B_FALSE);
2719 if (EFX_DWORD_FIELD(dword, EFX_DWORD_0) == 0xffffffff)
2725 ef10_nic_set_hw_unavailable(enp);
2731 ef10_nic_set_hw_unavailable(
2732 __in efx_nic_t *enp)
2734 EFSYS_PROBE(hw_unavail);
2735 enp->en_reset_flags |= EFX_RESET_HW_UNAVAIL;
2741 __in efx_nic_t *enp)
2745 boolean_t do_vadaptor_free = B_TRUE;
2748 if (enp->en_vswitchp != NULL) {
2750 * For SR-IOV the vAdaptor is freed with the vswitch,
2751 * so do not free it here.
2753 do_vadaptor_free = B_FALSE;
2756 if (do_vadaptor_free != B_FALSE) {
2757 (void) efx_mcdi_vadaptor_free(enp, enp->en_vport_id);
2758 enp->en_vport_id = EVB_PORT_ID_NULL;
2761 /* Unlink piobufs from extra VIs in WC mapping */
2762 if (enp->en_arch.ef10.ena_piobuf_count > 0) {
2763 for (i = 0; i < enp->en_arch.ef10.ena_piobuf_count; i++) {
2764 rc = efx_mcdi_unlink_piobuf(enp,
2765 enp->en_arch.ef10.ena_pio_write_vi_base + i);
2771 ef10_nic_free_piobufs(enp);
2773 (void) efx_mcdi_free_vis(enp);
2774 enp->en_arch.ef10.ena_vi_count = 0;
2779 __in efx_nic_t *enp)
2781 #if EFSYS_OPT_MON_STATS
2782 mcdi_mon_cfg_free(enp);
2783 #endif /* EFSYS_OPT_MON_STATS */
2784 (void) efx_mcdi_drv_attach(enp, B_FALSE);
2789 __checkReturn efx_rc_t
2790 ef10_nic_register_test(
2791 __in efx_nic_t *enp)
2796 _NOTE(ARGUNUSED(enp))
2797 _NOTE(CONSTANTCONDITION)
2807 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2812 #endif /* EFSYS_OPT_DIAG */
2814 #if EFSYS_OPT_FW_SUBVARIANT_AWARE
2816 __checkReturn efx_rc_t
2817 efx_mcdi_get_nic_global(
2818 __in efx_nic_t *enp,
2820 __out uint32_t *valuep)
2823 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_GET_NIC_GLOBAL_IN_LEN,
2824 MC_CMD_GET_NIC_GLOBAL_OUT_LEN);
2827 req.emr_cmd = MC_CMD_GET_NIC_GLOBAL;
2828 req.emr_in_buf = payload;
2829 req.emr_in_length = MC_CMD_GET_NIC_GLOBAL_IN_LEN;
2830 req.emr_out_buf = payload;
2831 req.emr_out_length = MC_CMD_GET_NIC_GLOBAL_OUT_LEN;
2833 MCDI_IN_SET_DWORD(req, GET_NIC_GLOBAL_IN_KEY, key);
2835 efx_mcdi_execute(enp, &req);
2837 if (req.emr_rc != 0) {
2842 if (req.emr_out_length_used != MC_CMD_GET_NIC_GLOBAL_OUT_LEN) {
2847 *valuep = MCDI_OUT_DWORD(req, GET_NIC_GLOBAL_OUT_VALUE);
2854 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2859 __checkReturn efx_rc_t
2860 efx_mcdi_set_nic_global(
2861 __in efx_nic_t *enp,
2863 __in uint32_t value)
2866 EFX_MCDI_DECLARE_BUF(payload, MC_CMD_SET_NIC_GLOBAL_IN_LEN, 0);
2869 req.emr_cmd = MC_CMD_SET_NIC_GLOBAL;
2870 req.emr_in_buf = payload;
2871 req.emr_in_length = MC_CMD_SET_NIC_GLOBAL_IN_LEN;
2872 req.emr_out_buf = NULL;
2873 req.emr_out_length = 0;
2875 MCDI_IN_SET_DWORD(req, SET_NIC_GLOBAL_IN_KEY, key);
2876 MCDI_IN_SET_DWORD(req, SET_NIC_GLOBAL_IN_VALUE, value);
2878 efx_mcdi_execute(enp, &req);
2880 if (req.emr_rc != 0) {
2888 EFSYS_PROBE1(fail1, efx_rc_t, rc);
2893 #endif /* EFSYS_OPT_FW_SUBVARIANT_AWARE */
2895 #endif /* EFX_OPTS_EF10() */