70c042f3ffa4c3b65d0e13dac51acdfce28de70c
[dpdk.git] / drivers / net / sfc / base / hunt_nic.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2012-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9 #if EFSYS_OPT_MON_MCDI
10 #include "mcdi_mon.h"
11 #endif
12
13 #if EFSYS_OPT_HUNTINGTON
14
15 #include "ef10_tlv_layout.h"
16
17 static  __checkReturn   efx_rc_t
18 hunt_nic_get_required_pcie_bandwidth(
19         __in            efx_nic_t *enp,
20         __out           uint32_t *bandwidth_mbpsp)
21 {
22         uint32_t port_modes;
23         uint32_t max_port_mode;
24         uint32_t bandwidth;
25         efx_rc_t rc;
26
27         /*
28          * On Huntington, the firmware may not give us the current port mode, so
29          * we need to go by the set of available port modes and assume the most
30          * capable mode is in use.
31          */
32
33         if ((rc = efx_mcdi_get_port_modes(enp, &port_modes,
34                     NULL, NULL)) != 0) {
35                 /* No port mode info available */
36                 bandwidth = 0;
37                 goto out;
38         }
39
40         if (port_modes & (1U << TLV_PORT_MODE_40G_40G)) {
41                 /*
42                  * This needs the full PCIe bandwidth (and could use
43                  * more) - roughly 64 Gbit/s for 8 lanes of Gen3.
44                  */
45                 if ((rc = efx_nic_calculate_pcie_link_bandwidth(8,
46                             EFX_PCIE_LINK_SPEED_GEN3, &bandwidth)) != 0)
47                         goto fail1;
48         } else {
49                 if (port_modes & (1U << TLV_PORT_MODE_40G)) {
50                         max_port_mode = TLV_PORT_MODE_40G;
51                 } else if (port_modes & (1U << TLV_PORT_MODE_10G_10G_10G_10G)) {
52                         max_port_mode = TLV_PORT_MODE_10G_10G_10G_10G;
53                 } else {
54                         /* Assume two 10G ports */
55                         max_port_mode = TLV_PORT_MODE_10G_10G;
56                 }
57
58                 if ((rc = ef10_nic_get_port_mode_bandwidth(max_port_mode,
59                                                             &bandwidth)) != 0)
60                         goto fail2;
61         }
62
63 out:
64         *bandwidth_mbpsp = bandwidth;
65
66         return (0);
67
68 fail2:
69         EFSYS_PROBE(fail2);
70 fail1:
71         EFSYS_PROBE1(fail1, efx_rc_t, rc);
72
73         return (rc);
74 }
75
76         __checkReturn   efx_rc_t
77 hunt_board_cfg(
78         __in            efx_nic_t *enp)
79 {
80         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
81         efx_port_t *epp = &(enp->en_port);
82         uint32_t flags;
83         uint32_t sysclk, dpcpu_clk;
84         uint32_t bandwidth;
85         efx_rc_t rc;
86
87         /*
88          * Enable firmware workarounds for hardware errata.
89          * Expected responses are:
90          *  - 0 (zero):
91          *      Success: workaround enabled or disabled as requested.
92          *  - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
93          *      Firmware does not support the MC_CMD_WORKAROUND request.
94          *      (assume that the workaround is not supported).
95          *  - MC_CMD_ERR_ENOENT (reported as ENOENT):
96          *      Firmware does not support the requested workaround.
97          *  - MC_CMD_ERR_EPERM  (reported as EACCES):
98          *      Unprivileged function cannot enable/disable workarounds.
99          *
100          * See efx_mcdi_request_errcode() for MCDI error translations.
101          */
102
103         /*
104          * If the bug35388 workaround is enabled, then use an indirect access
105          * method to avoid unsafe EVQ writes.
106          */
107         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG35388, B_TRUE,
108             NULL);
109         if ((rc == 0) || (rc == EACCES))
110                 encp->enc_bug35388_workaround = B_TRUE;
111         else if ((rc == ENOTSUP) || (rc == ENOENT))
112                 encp->enc_bug35388_workaround = B_FALSE;
113         else
114                 goto fail1;
115
116         /*
117          * If the bug41750 workaround is enabled, then do not test interrupts,
118          * as the test will fail (seen with Greenport controllers).
119          */
120         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG41750, B_TRUE,
121             NULL);
122         if (rc == 0) {
123                 encp->enc_bug41750_workaround = B_TRUE;
124         } else if (rc == EACCES) {
125                 /* Assume a controller with 40G ports needs the workaround. */
126                 if (epp->ep_default_adv_cap_mask & EFX_PHY_CAP_40000FDX)
127                         encp->enc_bug41750_workaround = B_TRUE;
128                 else
129                         encp->enc_bug41750_workaround = B_FALSE;
130         } else if ((rc == ENOTSUP) || (rc == ENOENT)) {
131                 encp->enc_bug41750_workaround = B_FALSE;
132         } else {
133                 goto fail2;
134         }
135         if (EFX_PCI_FUNCTION_IS_VF(encp)) {
136                 /* Interrupt testing does not work for VFs. See bug50084. */
137                 encp->enc_bug41750_workaround = B_TRUE;
138         }
139
140         /*
141          * If the bug26807 workaround is enabled, then firmware has enabled
142          * support for chained multicast filters. Firmware will reset (FLR)
143          * functions which have filters in the hardware filter table when the
144          * workaround is enabled/disabled.
145          *
146          * We must recheck if the workaround is enabled after inserting the
147          * first hardware filter, in case it has been changed since this check.
148          */
149         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG26807,
150             B_TRUE, &flags);
151         if (rc == 0) {
152                 encp->enc_bug26807_workaround = B_TRUE;
153                 if (flags & (1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN)) {
154                         /*
155                          * Other functions had installed filters before the
156                          * workaround was enabled, and they have been reset
157                          * by firmware.
158                          */
159                         EFSYS_PROBE(bug26807_workaround_flr_done);
160                         /* FIXME: bump MC warm boot count ? */
161                 }
162         } else if (rc == EACCES) {
163                 /*
164                  * Unprivileged functions cannot enable the workaround in older
165                  * firmware.
166                  */
167                 encp->enc_bug26807_workaround = B_FALSE;
168         } else if ((rc == ENOTSUP) || (rc == ENOENT)) {
169                 encp->enc_bug26807_workaround = B_FALSE;
170         } else {
171                 goto fail3;
172         }
173
174         /* Get clock frequencies (in MHz). */
175         if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
176                 goto fail4;
177
178         /*
179          * The Huntington timer quantum is 1536 sysclk cycles, documented for
180          * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
181          */
182         encp->enc_evq_timer_quantum_ns = 1536000UL / sysclk; /* 1536 cycles */
183         if (encp->enc_bug35388_workaround) {
184                 encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
185                 ERF_DD_EVQ_IND_TIMER_VAL_WIDTH) / 1000;
186         } else {
187                 encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
188                 FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
189         }
190
191         encp->enc_bug61265_workaround = B_FALSE; /* Medford only */
192
193         /* Checksums for TSO sends can be incorrect on Huntington. */
194         encp->enc_bug61297_workaround = B_TRUE;
195
196         /* Alignment for receive packet DMA buffers */
197         encp->enc_rx_buf_align_start = 1;
198         encp->enc_rx_buf_align_end = 64; /* RX DMA end padding */
199
200         /*
201          * The workaround for bug35388 uses the top bit of transmit queue
202          * descriptor writes, preventing the use of 4096 descriptor TXQs.
203          */
204         encp->enc_txq_max_ndescs = encp->enc_bug35388_workaround ? 2048 : 4096;
205
206         EFX_STATIC_ASSERT(HUNT_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
207         encp->enc_piobuf_limit = HUNT_PIOBUF_NBUFS;
208         encp->enc_piobuf_size = HUNT_PIOBUF_SIZE;
209         encp->enc_piobuf_min_alloc_size = HUNT_MIN_PIO_ALLOC_SIZE;
210
211         if ((rc = hunt_nic_get_required_pcie_bandwidth(enp, &bandwidth)) != 0)
212                 goto fail5;
213         encp->enc_required_pcie_bandwidth_mbps = bandwidth;
214
215         /* All Huntington devices have a PCIe Gen3, 8 lane connector */
216         encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
217
218         return (0);
219
220 fail5:
221         EFSYS_PROBE(fail5);
222 fail4:
223         EFSYS_PROBE(fail4);
224 fail3:
225         EFSYS_PROBE(fail3);
226 fail2:
227         EFSYS_PROBE(fail2);
228 fail1:
229         EFSYS_PROBE1(fail1, efx_rc_t, rc);
230
231         return (rc);
232 }
233
234
235 #endif  /* EFSYS_OPT_HUNTINGTON */