net/sfc/base: move vector config to ef10 NIC board config
[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, NULL)) != 0) {
34                 /* No port mode info available */
35                 bandwidth = 0;
36                 goto out;
37         }
38
39         if (port_modes & (1 << TLV_PORT_MODE_40G_40G)) {
40                 /*
41                  * This needs the full PCIe bandwidth (and could use
42                  * more) - roughly 64 Gbit/s for 8 lanes of Gen3.
43                  */
44                 if ((rc = efx_nic_calculate_pcie_link_bandwidth(8,
45                             EFX_PCIE_LINK_SPEED_GEN3, &bandwidth)) != 0)
46                         goto fail1;
47         } else {
48                 if (port_modes & (1 << TLV_PORT_MODE_40G)) {
49                         max_port_mode = TLV_PORT_MODE_40G;
50                 } else if (port_modes & (1 << TLV_PORT_MODE_10G_10G_10G_10G)) {
51                         max_port_mode = TLV_PORT_MODE_10G_10G_10G_10G;
52                 } else {
53                         /* Assume two 10G ports */
54                         max_port_mode = TLV_PORT_MODE_10G_10G;
55                 }
56
57                 if ((rc = ef10_nic_get_port_mode_bandwidth(max_port_mode,
58                                                             &bandwidth)) != 0)
59                         goto fail2;
60         }
61
62 out:
63         *bandwidth_mbpsp = bandwidth;
64
65         return (0);
66
67 fail2:
68         EFSYS_PROBE(fail2);
69 fail1:
70         EFSYS_PROBE1(fail1, efx_rc_t, rc);
71
72         return (rc);
73 }
74
75         __checkReturn   efx_rc_t
76 hunt_board_cfg(
77         __in            efx_nic_t *enp)
78 {
79         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
80         efx_port_t *epp = &(enp->en_port);
81         uint32_t mask;
82         uint32_t flags;
83         uint32_t sysclk, dpcpu_clk;
84         uint32_t bandwidth;
85         efx_rc_t rc;
86
87         /* Huntington has a fixed 8Kbyte VI window size */
88         EFX_STATIC_ASSERT(ER_DZ_EVQ_RPTR_REG_STEP       == 8192);
89         EFX_STATIC_ASSERT(ER_DZ_EVQ_TMR_REG_STEP        == 8192);
90         EFX_STATIC_ASSERT(ER_DZ_RX_DESC_UPD_REG_STEP    == 8192);
91         EFX_STATIC_ASSERT(ER_DZ_TX_DESC_UPD_REG_STEP    == 8192);
92         EFX_STATIC_ASSERT(ER_DZ_TX_PIOBUF_STEP          == 8192);
93
94         EFX_STATIC_ASSERT(1U << EFX_VI_WINDOW_SHIFT_8K  == 8192);
95         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
96
97         /*
98          * Enable firmware workarounds for hardware errata.
99          * Expected responses are:
100          *  - 0 (zero):
101          *      Success: workaround enabled or disabled as requested.
102          *  - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
103          *      Firmware does not support the MC_CMD_WORKAROUND request.
104          *      (assume that the workaround is not supported).
105          *  - MC_CMD_ERR_ENOENT (reported as ENOENT):
106          *      Firmware does not support the requested workaround.
107          *  - MC_CMD_ERR_EPERM  (reported as EACCES):
108          *      Unprivileged function cannot enable/disable workarounds.
109          *
110          * See efx_mcdi_request_errcode() for MCDI error translations.
111          */
112
113         /*
114          * If the bug35388 workaround is enabled, then use an indirect access
115          * method to avoid unsafe EVQ writes.
116          */
117         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG35388, B_TRUE,
118             NULL);
119         if ((rc == 0) || (rc == EACCES))
120                 encp->enc_bug35388_workaround = B_TRUE;
121         else if ((rc == ENOTSUP) || (rc == ENOENT))
122                 encp->enc_bug35388_workaround = B_FALSE;
123         else
124                 goto fail1;
125
126         /*
127          * If the bug41750 workaround is enabled, then do not test interrupts,
128          * as the test will fail (seen with Greenport controllers).
129          */
130         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG41750, B_TRUE,
131             NULL);
132         if (rc == 0) {
133                 encp->enc_bug41750_workaround = B_TRUE;
134         } else if (rc == EACCES) {
135                 /* Assume a controller with 40G ports needs the workaround. */
136                 if (epp->ep_default_adv_cap_mask & EFX_PHY_CAP_40000FDX)
137                         encp->enc_bug41750_workaround = B_TRUE;
138                 else
139                         encp->enc_bug41750_workaround = B_FALSE;
140         } else if ((rc == ENOTSUP) || (rc == ENOENT)) {
141                 encp->enc_bug41750_workaround = B_FALSE;
142         } else {
143                 goto fail2;
144         }
145         if (EFX_PCI_FUNCTION_IS_VF(encp)) {
146                 /* Interrupt testing does not work for VFs. See bug50084. */
147                 encp->enc_bug41750_workaround = B_TRUE;
148         }
149
150         /*
151          * If the bug26807 workaround is enabled, then firmware has enabled
152          * support for chained multicast filters. Firmware will reset (FLR)
153          * functions which have filters in the hardware filter table when the
154          * workaround is enabled/disabled.
155          *
156          * We must recheck if the workaround is enabled after inserting the
157          * first hardware filter, in case it has been changed since this check.
158          */
159         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG26807,
160             B_TRUE, &flags);
161         if (rc == 0) {
162                 encp->enc_bug26807_workaround = B_TRUE;
163                 if (flags & (1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN)) {
164                         /*
165                          * Other functions had installed filters before the
166                          * workaround was enabled, and they have been reset
167                          * by firmware.
168                          */
169                         EFSYS_PROBE(bug26807_workaround_flr_done);
170                         /* FIXME: bump MC warm boot count ? */
171                 }
172         } else if (rc == EACCES) {
173                 /*
174                  * Unprivileged functions cannot enable the workaround in older
175                  * firmware.
176                  */
177                 encp->enc_bug26807_workaround = B_FALSE;
178         } else if ((rc == ENOTSUP) || (rc == ENOENT)) {
179                 encp->enc_bug26807_workaround = B_FALSE;
180         } else {
181                 goto fail3;
182         }
183
184         /* Get clock frequencies (in MHz). */
185         if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
186                 goto fail4;
187
188         /*
189          * The Huntington timer quantum is 1536 sysclk cycles, documented for
190          * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
191          */
192         encp->enc_evq_timer_quantum_ns = 1536000UL / sysclk; /* 1536 cycles */
193         if (encp->enc_bug35388_workaround) {
194                 encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
195                 ERF_DD_EVQ_IND_TIMER_VAL_WIDTH) / 1000;
196         } else {
197                 encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
198                 FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
199         }
200
201         encp->enc_bug61265_workaround = B_FALSE; /* Medford only */
202
203         /* Alignment for receive packet DMA buffers */
204         encp->enc_rx_buf_align_start = 1;
205         encp->enc_rx_buf_align_end = 64; /* RX DMA end padding */
206
207         /*
208          * The workaround for bug35388 uses the top bit of transmit queue
209          * descriptor writes, preventing the use of 4096 descriptor TXQs.
210          */
211         encp->enc_txq_max_ndescs = encp->enc_bug35388_workaround ? 2048 : 4096;
212
213         EFX_STATIC_ASSERT(HUNT_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
214         encp->enc_piobuf_limit = HUNT_PIOBUF_NBUFS;
215         encp->enc_piobuf_size = HUNT_PIOBUF_SIZE;
216         encp->enc_piobuf_min_alloc_size = HUNT_MIN_PIO_ALLOC_SIZE;
217
218         /*
219          * Get the current privilege mask. Note that this may be modified
220          * dynamically, so this value is informational only. DO NOT use
221          * the privilege mask to check for sufficient privileges, as that
222          * can result in time-of-check/time-of-use bugs.
223          */
224         if ((rc = ef10_get_privilege_mask(enp, &mask)) != 0)
225                 goto fail5;
226         encp->enc_privilege_mask = mask;
227
228         if ((rc = hunt_nic_get_required_pcie_bandwidth(enp, &bandwidth)) != 0)
229                 goto fail6;
230         encp->enc_required_pcie_bandwidth_mbps = bandwidth;
231
232         /* All Huntington devices have a PCIe Gen3, 8 lane connector */
233         encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
234
235         return (0);
236
237 fail6:
238         EFSYS_PROBE(fail6);
239 fail5:
240         EFSYS_PROBE(fail5);
241 fail4:
242         EFSYS_PROBE(fail4);
243 fail3:
244         EFSYS_PROBE(fail3);
245 fail2:
246         EFSYS_PROBE(fail2);
247 fail1:
248         EFSYS_PROBE1(fail1, efx_rc_t, rc);
249
250         return (rc);
251 }
252
253
254 #endif  /* EFSYS_OPT_HUNTINGTON */