xref: /freebsd/sys/dev/sfxge/common/medford_nic.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
15f5c71ccSAndrew Rybchenko /*-
2929c7febSAndrew Rybchenko  * Copyright (c) 2015-2016 Solarflare Communications Inc.
35f5c71ccSAndrew Rybchenko  * All rights reserved.
45f5c71ccSAndrew Rybchenko  *
55f5c71ccSAndrew Rybchenko  * Redistribution and use in source and binary forms, with or without
65f5c71ccSAndrew Rybchenko  * modification, are permitted provided that the following conditions are met:
75f5c71ccSAndrew Rybchenko  *
85f5c71ccSAndrew Rybchenko  * 1. Redistributions of source code must retain the above copyright notice,
95f5c71ccSAndrew Rybchenko  *    this list of conditions and the following disclaimer.
105f5c71ccSAndrew Rybchenko  * 2. Redistributions in binary form must reproduce the above copyright notice,
115f5c71ccSAndrew Rybchenko  *    this list of conditions and the following disclaimer in the documentation
125f5c71ccSAndrew Rybchenko  *    and/or other materials provided with the distribution.
135f5c71ccSAndrew Rybchenko  *
145f5c71ccSAndrew Rybchenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
155f5c71ccSAndrew Rybchenko  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
165f5c71ccSAndrew Rybchenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
175f5c71ccSAndrew Rybchenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
185f5c71ccSAndrew Rybchenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
195f5c71ccSAndrew Rybchenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
205f5c71ccSAndrew Rybchenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
215f5c71ccSAndrew Rybchenko  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
225f5c71ccSAndrew Rybchenko  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
235f5c71ccSAndrew Rybchenko  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
245f5c71ccSAndrew Rybchenko  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255f5c71ccSAndrew Rybchenko  *
265f5c71ccSAndrew Rybchenko  * The views and conclusions contained in the software and documentation are
275f5c71ccSAndrew Rybchenko  * those of the authors and should not be interpreted as representing official
285f5c71ccSAndrew Rybchenko  * policies, either expressed or implied, of the FreeBSD Project.
295f5c71ccSAndrew Rybchenko  */
305f5c71ccSAndrew Rybchenko 
315f5c71ccSAndrew Rybchenko #include <sys/cdefs.h>
325f5c71ccSAndrew Rybchenko #include "efx.h"
335f5c71ccSAndrew Rybchenko #include "efx_impl.h"
34dcb49ebaSAndrew Rybchenko 
355f5c71ccSAndrew Rybchenko #if EFSYS_OPT_MEDFORD
365f5c71ccSAndrew Rybchenko 
376de7c598SAndrew Rybchenko static	__checkReturn	efx_rc_t
medford_nic_get_required_pcie_bandwidth(__in efx_nic_t * enp,__out uint32_t * bandwidth_mbpsp)38f6d61784SAndrew Rybchenko medford_nic_get_required_pcie_bandwidth(
39f6d61784SAndrew Rybchenko 	__in		efx_nic_t *enp,
40f6d61784SAndrew Rybchenko 	__out		uint32_t *bandwidth_mbpsp)
41f6d61784SAndrew Rybchenko {
42f6d61784SAndrew Rybchenko 	uint32_t bandwidth;
43f6d61784SAndrew Rybchenko 	efx_rc_t rc;
44f6d61784SAndrew Rybchenko 
45*c42b6a35SAndrew Rybchenko 	if ((rc = ef10_nic_get_port_mode_bandwidth(enp,
46f6d61784SAndrew Rybchenko 						    &bandwidth)) != 0)
47f6d61784SAndrew Rybchenko 		goto fail1;
48f6d61784SAndrew Rybchenko 
49f6d61784SAndrew Rybchenko 	*bandwidth_mbpsp = bandwidth;
50f6d61784SAndrew Rybchenko 
51f6d61784SAndrew Rybchenko 	return (0);
52f6d61784SAndrew Rybchenko 
53f6d61784SAndrew Rybchenko fail1:
54f6d61784SAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
55f6d61784SAndrew Rybchenko 
56f6d61784SAndrew Rybchenko 	return (rc);
57f6d61784SAndrew Rybchenko }
58f6d61784SAndrew Rybchenko 
59cfa023ebSAndrew Rybchenko 	__checkReturn	efx_rc_t
medford_board_cfg(__in efx_nic_t * enp)60cfa023ebSAndrew Rybchenko medford_board_cfg(
61cfa023ebSAndrew Rybchenko 	__in		efx_nic_t *enp)
62cfa023ebSAndrew Rybchenko {
63cfa023ebSAndrew Rybchenko 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
6478e5c87cSAndrew Rybchenko 	uint32_t sysclk, dpcpu_clk;
656de7c598SAndrew Rybchenko 	uint32_t end_padding;
66f6d61784SAndrew Rybchenko 	uint32_t bandwidth;
67cfa023ebSAndrew Rybchenko 	efx_rc_t rc;
685f5c71ccSAndrew Rybchenko 
69cfa023ebSAndrew Rybchenko 	/*
70e26f5dacSAndrew Rybchenko 	 * Enable firmware workarounds for hardware errata.
71e26f5dacSAndrew Rybchenko 	 * Expected responses are:
72e26f5dacSAndrew Rybchenko 	 *  - 0 (zero):
73e26f5dacSAndrew Rybchenko 	 *	Success: workaround enabled or disabled as requested.
74e26f5dacSAndrew Rybchenko 	 *  - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
75e26f5dacSAndrew Rybchenko 	 *	Firmware does not support the MC_CMD_WORKAROUND request.
76e26f5dacSAndrew Rybchenko 	 *	(assume that the workaround is not supported).
77e26f5dacSAndrew Rybchenko 	 *  - MC_CMD_ERR_ENOENT (reported as ENOENT):
78e26f5dacSAndrew Rybchenko 	 *	Firmware does not support the requested workaround.
79e26f5dacSAndrew Rybchenko 	 *  - MC_CMD_ERR_EPERM  (reported as EACCES):
80e26f5dacSAndrew Rybchenko 	 *	Unprivileged function cannot enable/disable workarounds.
81e26f5dacSAndrew Rybchenko 	 *
82e26f5dacSAndrew Rybchenko 	 * See efx_mcdi_request_errcode() for MCDI error translations.
83e26f5dacSAndrew Rybchenko 	 */
84e26f5dacSAndrew Rybchenko 
85cfa023ebSAndrew Rybchenko 	if (EFX_PCI_FUNCTION_IS_VF(encp)) {
86cfa023ebSAndrew Rybchenko 		/*
871c057dc0SAndrew Rybchenko 		 * Interrupt testing does not work for VFs. See bug50084 and
881c057dc0SAndrew Rybchenko 		 * bug71432 comment 21.
89cfa023ebSAndrew Rybchenko 		 */
90cfa023ebSAndrew Rybchenko 		encp->enc_bug41750_workaround = B_TRUE;
91cfa023ebSAndrew Rybchenko 	}
92cfa023ebSAndrew Rybchenko 
93cfa023ebSAndrew Rybchenko 	/* Chained multicast is always enabled on Medford */
94cfa023ebSAndrew Rybchenko 	encp->enc_bug26807_workaround = B_TRUE;
95cfa023ebSAndrew Rybchenko 
96e26f5dacSAndrew Rybchenko 	/*
97e26f5dacSAndrew Rybchenko 	 * If the bug61265 workaround is enabled, then interrupt holdoff timers
98e26f5dacSAndrew Rybchenko 	 * cannot be controlled by timer table writes, so MCDI must be used
99e26f5dacSAndrew Rybchenko 	 * (timer table writes can still be used for wakeup timers).
100e26f5dacSAndrew Rybchenko 	 */
101e26f5dacSAndrew Rybchenko 	rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG61265, B_TRUE,
102e26f5dacSAndrew Rybchenko 	    NULL);
103e26f5dacSAndrew Rybchenko 	if ((rc == 0) || (rc == EACCES))
104e26f5dacSAndrew Rybchenko 		encp->enc_bug61265_workaround = B_TRUE;
105e26f5dacSAndrew Rybchenko 	else if ((rc == ENOTSUP) || (rc == ENOENT))
106e26f5dacSAndrew Rybchenko 		encp->enc_bug61265_workaround = B_FALSE;
107e26f5dacSAndrew Rybchenko 	else
108e5f6f32fSAndrew Rybchenko 		goto fail1;
109e26f5dacSAndrew Rybchenko 
1105037810fSAndrew Rybchenko 	/* Checksums for TSO sends can be incorrect on Medford. */
1115037810fSAndrew Rybchenko 	encp->enc_bug61297_workaround = B_TRUE;
1125037810fSAndrew Rybchenko 
11378e5c87cSAndrew Rybchenko 	/* Get clock frequencies (in MHz). */
11478e5c87cSAndrew Rybchenko 	if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
115e5f6f32fSAndrew Rybchenko 		goto fail2;
116cfa023ebSAndrew Rybchenko 
117cfa023ebSAndrew Rybchenko 	/*
11878e5c87cSAndrew Rybchenko 	 * The Medford timer quantum is 1536 dpcpu_clk cycles, documented for
11978e5c87cSAndrew Rybchenko 	 * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
120cfa023ebSAndrew Rybchenko 	 */
12178e5c87cSAndrew Rybchenko 	encp->enc_evq_timer_quantum_ns = 1536000UL / dpcpu_clk; /* 1536 cycles */
122cfa023ebSAndrew Rybchenko 	encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
123cfa023ebSAndrew Rybchenko 		    FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
124cfa023ebSAndrew Rybchenko 
125cfa023ebSAndrew Rybchenko 	/* Alignment for receive packet DMA buffers */
126cfa023ebSAndrew Rybchenko 	encp->enc_rx_buf_align_start = 1;
127cfa023ebSAndrew Rybchenko 
1286de7c598SAndrew Rybchenko 	/* Get the RX DMA end padding alignment configuration */
129ab72be51SAndrew Rybchenko 	if ((rc = efx_mcdi_get_rxdp_config(enp, &end_padding)) != 0) {
130ab72be51SAndrew Rybchenko 		if (rc != EACCES)
131deeaf87fSAndrew Rybchenko 			goto fail3;
132ab72be51SAndrew Rybchenko 
133ab72be51SAndrew Rybchenko 		/* Assume largest tail padding size supported by hardware */
134ab72be51SAndrew Rybchenko 		end_padding = 256;
135ab72be51SAndrew Rybchenko 	}
1366de7c598SAndrew Rybchenko 	encp->enc_rx_buf_align_end = end_padding;
137cfa023ebSAndrew Rybchenko 
138cfa023ebSAndrew Rybchenko 	/*
139d343a7f4SAndrew Rybchenko 	 * The maximum supported transmit queue size is 2048. TXQs with 4096
140d343a7f4SAndrew Rybchenko 	 * descriptors are not supported as the top bit is used for vfifo
141d343a7f4SAndrew Rybchenko 	 * stuffing.
142d343a7f4SAndrew Rybchenko 	 */
143d343a7f4SAndrew Rybchenko 	encp->enc_txq_max_ndescs = 2048;
144d343a7f4SAndrew Rybchenko 
1454f58306cSAndrew Rybchenko 	EFX_STATIC_ASSERT(MEDFORD_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
146cfa023ebSAndrew Rybchenko 	encp->enc_piobuf_limit = MEDFORD_PIOBUF_NBUFS;
147cfa023ebSAndrew Rybchenko 	encp->enc_piobuf_size = MEDFORD_PIOBUF_SIZE;
148cfa023ebSAndrew Rybchenko 	encp->enc_piobuf_min_alloc_size = MEDFORD_MIN_PIO_ALLOC_SIZE;
149cfa023ebSAndrew Rybchenko 
150cfa023ebSAndrew Rybchenko 	/*
151739ebba6SAndrew Rybchenko 	 * Medford stores a single global copy of VPD, not per-PF as on
152739ebba6SAndrew Rybchenko 	 * Huntington.
153739ebba6SAndrew Rybchenko 	 */
154739ebba6SAndrew Rybchenko 	encp->enc_vpd_is_global = B_TRUE;
155739ebba6SAndrew Rybchenko 
156f6d61784SAndrew Rybchenko 	rc = medford_nic_get_required_pcie_bandwidth(enp, &bandwidth);
157f6d61784SAndrew Rybchenko 	if (rc != 0)
15826fcca57SAndrew Rybchenko 		goto fail4;
159f6d61784SAndrew Rybchenko 	encp->enc_required_pcie_bandwidth_mbps = bandwidth;
160f6d61784SAndrew Rybchenko 	encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
161f6d61784SAndrew Rybchenko 
162cfa023ebSAndrew Rybchenko 	return (0);
163cfa023ebSAndrew Rybchenko 
164cfa023ebSAndrew Rybchenko fail4:
165cfa023ebSAndrew Rybchenko 	EFSYS_PROBE(fail4);
166cfa023ebSAndrew Rybchenko fail3:
167cfa023ebSAndrew Rybchenko 	EFSYS_PROBE(fail3);
168cfa023ebSAndrew Rybchenko fail2:
169cfa023ebSAndrew Rybchenko 	EFSYS_PROBE(fail2);
170cfa023ebSAndrew Rybchenko fail1:
171cfa023ebSAndrew Rybchenko 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
172cfa023ebSAndrew Rybchenko 
173cfa023ebSAndrew Rybchenko 	return (rc);
174cfa023ebSAndrew Rybchenko }
1755f5c71ccSAndrew Rybchenko 
1765f5c71ccSAndrew Rybchenko #endif	/* EFSYS_OPT_MEDFORD */
177