1ae64ac93SAndrew Rybchenko /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3ae64ac93SAndrew Rybchenko *
4ae64ac93SAndrew Rybchenko * Copyright (c) 2015-2018 Solarflare Communications Inc.
5ae64ac93SAndrew Rybchenko * All rights reserved.
6ae64ac93SAndrew Rybchenko *
7ae64ac93SAndrew Rybchenko * Redistribution and use in source and binary forms, with or without
8ae64ac93SAndrew Rybchenko * modification, are permitted provided that the following conditions are met:
9ae64ac93SAndrew Rybchenko *
10ae64ac93SAndrew Rybchenko * 1. Redistributions of source code must retain the above copyright notice,
11ae64ac93SAndrew Rybchenko * this list of conditions and the following disclaimer.
12ae64ac93SAndrew Rybchenko * 2. Redistributions in binary form must reproduce the above copyright notice,
13ae64ac93SAndrew Rybchenko * this list of conditions and the following disclaimer in the documentation
14ae64ac93SAndrew Rybchenko * and/or other materials provided with the distribution.
15ae64ac93SAndrew Rybchenko *
16ae64ac93SAndrew Rybchenko * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17ae64ac93SAndrew Rybchenko * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18ae64ac93SAndrew Rybchenko * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19ae64ac93SAndrew Rybchenko * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20ae64ac93SAndrew Rybchenko * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21ae64ac93SAndrew Rybchenko * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22ae64ac93SAndrew Rybchenko * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23ae64ac93SAndrew Rybchenko * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24ae64ac93SAndrew Rybchenko * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25ae64ac93SAndrew Rybchenko * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26ae64ac93SAndrew Rybchenko * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27ae64ac93SAndrew Rybchenko *
28ae64ac93SAndrew Rybchenko * The views and conclusions contained in the software and documentation are
29ae64ac93SAndrew Rybchenko * those of the authors and should not be interpreted as representing official
30ae64ac93SAndrew Rybchenko * policies, either expressed or implied, of the FreeBSD Project.
31ae64ac93SAndrew Rybchenko */
32ae64ac93SAndrew Rybchenko
33ae64ac93SAndrew Rybchenko #include <sys/cdefs.h>
34ae64ac93SAndrew Rybchenko #include "efx.h"
35ae64ac93SAndrew Rybchenko #include "efx_impl.h"
36ae64ac93SAndrew Rybchenko
37ae64ac93SAndrew Rybchenko #if EFSYS_OPT_MEDFORD2
38ae64ac93SAndrew Rybchenko
39ae64ac93SAndrew Rybchenko static __checkReturn efx_rc_t
medford2_nic_get_required_pcie_bandwidth(__in efx_nic_t * enp,__out uint32_t * bandwidth_mbpsp)40ae64ac93SAndrew Rybchenko medford2_nic_get_required_pcie_bandwidth(
41ae64ac93SAndrew Rybchenko __in efx_nic_t *enp,
42ae64ac93SAndrew Rybchenko __out uint32_t *bandwidth_mbpsp)
43ae64ac93SAndrew Rybchenko {
44ae64ac93SAndrew Rybchenko uint32_t bandwidth;
45ae64ac93SAndrew Rybchenko efx_rc_t rc;
46ae64ac93SAndrew Rybchenko
47ae64ac93SAndrew Rybchenko /* FIXME: support new Medford2 dynamic port modes */
48ae64ac93SAndrew Rybchenko
49c42b6a35SAndrew Rybchenko if ((rc = ef10_nic_get_port_mode_bandwidth(enp,
50ae64ac93SAndrew Rybchenko &bandwidth)) != 0)
51ae64ac93SAndrew Rybchenko goto fail1;
52ae64ac93SAndrew Rybchenko
53ae64ac93SAndrew Rybchenko *bandwidth_mbpsp = bandwidth;
54ae64ac93SAndrew Rybchenko
55ae64ac93SAndrew Rybchenko return (0);
56ae64ac93SAndrew Rybchenko
57ae64ac93SAndrew Rybchenko fail1:
58ae64ac93SAndrew Rybchenko EFSYS_PROBE1(fail1, efx_rc_t, rc);
59ae64ac93SAndrew Rybchenko
60ae64ac93SAndrew Rybchenko return (rc);
61ae64ac93SAndrew Rybchenko }
62ae64ac93SAndrew Rybchenko
63ae64ac93SAndrew Rybchenko __checkReturn efx_rc_t
medford2_board_cfg(__in efx_nic_t * enp)64ae64ac93SAndrew Rybchenko medford2_board_cfg(
65ae64ac93SAndrew Rybchenko __in efx_nic_t *enp)
66ae64ac93SAndrew Rybchenko {
67ae64ac93SAndrew Rybchenko efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
68ae64ac93SAndrew Rybchenko uint32_t sysclk, dpcpu_clk;
69ae64ac93SAndrew Rybchenko uint32_t end_padding;
70ae64ac93SAndrew Rybchenko uint32_t bandwidth;
71ae64ac93SAndrew Rybchenko efx_rc_t rc;
72ae64ac93SAndrew Rybchenko
73ae64ac93SAndrew Rybchenko /*
74ae64ac93SAndrew Rybchenko * Enable firmware workarounds for hardware errata.
75ae64ac93SAndrew Rybchenko * Expected responses are:
76ae64ac93SAndrew Rybchenko * - 0 (zero):
77ae64ac93SAndrew Rybchenko * Success: workaround enabled or disabled as requested.
78ae64ac93SAndrew Rybchenko * - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
79ae64ac93SAndrew Rybchenko * Firmware does not support the MC_CMD_WORKAROUND request.
80ae64ac93SAndrew Rybchenko * (assume that the workaround is not supported).
81ae64ac93SAndrew Rybchenko * - MC_CMD_ERR_ENOENT (reported as ENOENT):
82ae64ac93SAndrew Rybchenko * Firmware does not support the requested workaround.
83ae64ac93SAndrew Rybchenko * - MC_CMD_ERR_EPERM (reported as EACCES):
84ae64ac93SAndrew Rybchenko * Unprivileged function cannot enable/disable workarounds.
85ae64ac93SAndrew Rybchenko *
86ae64ac93SAndrew Rybchenko * See efx_mcdi_request_errcode() for MCDI error translations.
87ae64ac93SAndrew Rybchenko */
88ae64ac93SAndrew Rybchenko
89ae64ac93SAndrew Rybchenko if (EFX_PCI_FUNCTION_IS_VF(encp)) {
90ae64ac93SAndrew Rybchenko /*
911c057dc0SAndrew Rybchenko * Interrupt testing does not work for VFs on Medford2.
921c057dc0SAndrew Rybchenko * See bug50084 and bug71432 comment 21.
93ae64ac93SAndrew Rybchenko */
94ae64ac93SAndrew Rybchenko encp->enc_bug41750_workaround = B_TRUE;
95ae64ac93SAndrew Rybchenko }
96ae64ac93SAndrew Rybchenko
97ae64ac93SAndrew Rybchenko /* Chained multicast is always enabled on Medford2 */
98ae64ac93SAndrew Rybchenko encp->enc_bug26807_workaround = B_TRUE;
99ae64ac93SAndrew Rybchenko
100ae64ac93SAndrew Rybchenko /*
101ae64ac93SAndrew Rybchenko * If the bug61265 workaround is enabled, then interrupt holdoff timers
102ae64ac93SAndrew Rybchenko * cannot be controlled by timer table writes, so MCDI must be used
103ae64ac93SAndrew Rybchenko * (timer table writes can still be used for wakeup timers).
104ae64ac93SAndrew Rybchenko */
105ae64ac93SAndrew Rybchenko rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG61265, B_TRUE,
106ae64ac93SAndrew Rybchenko NULL);
107ae64ac93SAndrew Rybchenko if ((rc == 0) || (rc == EACCES))
108ae64ac93SAndrew Rybchenko encp->enc_bug61265_workaround = B_TRUE;
109ae64ac93SAndrew Rybchenko else if ((rc == ENOTSUP) || (rc == ENOENT))
110ae64ac93SAndrew Rybchenko encp->enc_bug61265_workaround = B_FALSE;
111ae64ac93SAndrew Rybchenko else
11276ecd4a3SAndrew Rybchenko goto fail1;
113ae64ac93SAndrew Rybchenko
1145037810fSAndrew Rybchenko /* Checksums for TSO sends should always be correct on Medford2. */
1155037810fSAndrew Rybchenko encp->enc_bug61297_workaround = B_FALSE;
1165037810fSAndrew Rybchenko
117ae64ac93SAndrew Rybchenko /* Get clock frequencies (in MHz). */
118ae64ac93SAndrew Rybchenko if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
11976ecd4a3SAndrew Rybchenko goto fail2;
120ae64ac93SAndrew Rybchenko
121ae64ac93SAndrew Rybchenko /*
122ae64ac93SAndrew Rybchenko * The Medford2 timer quantum is 1536 dpcpu_clk cycles, documented for
123ae64ac93SAndrew Rybchenko * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
124ae64ac93SAndrew Rybchenko */
125ae64ac93SAndrew Rybchenko encp->enc_evq_timer_quantum_ns = 1536000UL / dpcpu_clk; /* 1536 cycles */
126ae64ac93SAndrew Rybchenko encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
127ae64ac93SAndrew Rybchenko FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
128ae64ac93SAndrew Rybchenko
129ae64ac93SAndrew Rybchenko /* Alignment for receive packet DMA buffers */
130ae64ac93SAndrew Rybchenko encp->enc_rx_buf_align_start = 1;
131ae64ac93SAndrew Rybchenko
132ae64ac93SAndrew Rybchenko /* Get the RX DMA end padding alignment configuration */
133ae64ac93SAndrew Rybchenko if ((rc = efx_mcdi_get_rxdp_config(enp, &end_padding)) != 0) {
134ae64ac93SAndrew Rybchenko if (rc != EACCES)
13576ecd4a3SAndrew Rybchenko goto fail3;
136ae64ac93SAndrew Rybchenko
137ae64ac93SAndrew Rybchenko /* Assume largest tail padding size supported by hardware */
138ae64ac93SAndrew Rybchenko end_padding = 256;
139ae64ac93SAndrew Rybchenko }
140ae64ac93SAndrew Rybchenko encp->enc_rx_buf_align_end = end_padding;
141ae64ac93SAndrew Rybchenko
142ae64ac93SAndrew Rybchenko /*
143ae64ac93SAndrew Rybchenko * The maximum supported transmit queue size is 2048. TXQs with 4096
144ae64ac93SAndrew Rybchenko * descriptors are not supported as the top bit is used for vfifo
145ae64ac93SAndrew Rybchenko * stuffing.
146ae64ac93SAndrew Rybchenko */
147ae64ac93SAndrew Rybchenko encp->enc_txq_max_ndescs = 2048;
148ae64ac93SAndrew Rybchenko
1494f58306cSAndrew Rybchenko EFX_STATIC_ASSERT(MEDFORD2_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
150ae64ac93SAndrew Rybchenko encp->enc_piobuf_limit = MEDFORD2_PIOBUF_NBUFS;
151ae64ac93SAndrew Rybchenko encp->enc_piobuf_size = MEDFORD2_PIOBUF_SIZE;
152ae64ac93SAndrew Rybchenko encp->enc_piobuf_min_alloc_size = MEDFORD2_MIN_PIO_ALLOC_SIZE;
153ae64ac93SAndrew Rybchenko
154ae64ac93SAndrew Rybchenko /*
155ae64ac93SAndrew Rybchenko * Medford2 stores a single global copy of VPD, not per-PF as on
156ae64ac93SAndrew Rybchenko * Huntington.
157ae64ac93SAndrew Rybchenko */
158ae64ac93SAndrew Rybchenko encp->enc_vpd_is_global = B_TRUE;
159ae64ac93SAndrew Rybchenko
160ae64ac93SAndrew Rybchenko rc = medford2_nic_get_required_pcie_bandwidth(enp, &bandwidth);
161ae64ac93SAndrew Rybchenko if (rc != 0)
16276ecd4a3SAndrew Rybchenko goto fail4;
163ae64ac93SAndrew Rybchenko encp->enc_required_pcie_bandwidth_mbps = bandwidth;
164ae64ac93SAndrew Rybchenko encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
165ae64ac93SAndrew Rybchenko
166ae64ac93SAndrew Rybchenko return (0);
167ae64ac93SAndrew Rybchenko
168ae64ac93SAndrew Rybchenko fail4:
169ae64ac93SAndrew Rybchenko EFSYS_PROBE(fail4);
170ae64ac93SAndrew Rybchenko fail3:
171ae64ac93SAndrew Rybchenko EFSYS_PROBE(fail3);
172ae64ac93SAndrew Rybchenko fail2:
173ae64ac93SAndrew Rybchenko EFSYS_PROBE(fail2);
174ae64ac93SAndrew Rybchenko fail1:
175ae64ac93SAndrew Rybchenko EFSYS_PROBE1(fail1, efx_rc_t, rc);
176ae64ac93SAndrew Rybchenko
177ae64ac93SAndrew Rybchenko return (rc);
178ae64ac93SAndrew Rybchenko }
179ae64ac93SAndrew Rybchenko
180ae64ac93SAndrew Rybchenko #endif /* EFSYS_OPT_MEDFORD2 */
181