2bd3d83e8e5e17a14df0f854113a84d4a39c97d0
[dpdk.git] / drivers / net / sfc / base / medford2_nic.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2015-2018 Solarflare Communications Inc.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9
10
11 #if EFSYS_OPT_MEDFORD2
12
13 static  __checkReturn   efx_rc_t
14 medford2_nic_get_required_pcie_bandwidth(
15         __in            efx_nic_t *enp,
16         __out           uint32_t *bandwidth_mbpsp)
17 {
18         uint32_t port_modes;
19         uint32_t current_mode;
20         uint32_t bandwidth;
21         efx_rc_t rc;
22
23         /* FIXME: support new Medford2 dynamic port modes */
24
25         if ((rc = efx_mcdi_get_port_modes(enp, &port_modes,
26                                     &current_mode)) != 0) {
27                 /* No port mode info available. */
28                 bandwidth = 0;
29                 goto out;
30         }
31
32         if ((rc = ef10_nic_get_port_mode_bandwidth(current_mode,
33                                                     &bandwidth)) != 0)
34                 goto fail1;
35
36 out:
37         *bandwidth_mbpsp = bandwidth;
38
39         return (0);
40
41 fail1:
42         EFSYS_PROBE1(fail1, efx_rc_t, rc);
43
44         return (rc);
45 }
46
47         __checkReturn   efx_rc_t
48 medford2_board_cfg(
49         __in            efx_nic_t *enp)
50 {
51         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
52         ef10_link_state_t els;
53         efx_port_t *epp = &(enp->en_port);
54         uint32_t mask;
55         uint32_t sysclk, dpcpu_clk;
56         uint32_t base, nvec;
57         uint32_t end_padding;
58         uint32_t bandwidth;
59         uint32_t vi_window_shift;
60         efx_rc_t rc;
61
62         /*
63          * FIXME: Likely to be incomplete and incorrect.
64          * Parts of this should be shared with Huntington.
65          */
66
67         /* Medford2 has a variable VI window size (8K, 16K or 64K) */
68         if ((rc = ef10_get_vi_window_shift(enp, &vi_window_shift)) != 0)
69                 goto fail1;
70
71         EFSYS_ASSERT3U(vi_window_shift, <=, EFX_VI_WINDOW_SHIFT_64K);
72         encp->enc_vi_window_shift = vi_window_shift;
73
74
75         /* Fill out fields in enp->en_port and enp->en_nic_cfg from MCDI */
76         if ((rc = efx_mcdi_get_phy_cfg(enp)) != 0)
77                 goto fail2;
78
79         /* Obtain the default PHY advertised capabilities */
80         if ((rc = ef10_phy_get_link(enp, &els)) != 0)
81                 goto fail3;
82         epp->ep_default_adv_cap_mask = els.els_adv_cap_mask;
83         epp->ep_adv_cap_mask = els.els_adv_cap_mask;
84
85         /*
86          * Enable firmware workarounds for hardware errata.
87          * Expected responses are:
88          *  - 0 (zero):
89          *      Success: workaround enabled or disabled as requested.
90          *  - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
91          *      Firmware does not support the MC_CMD_WORKAROUND request.
92          *      (assume that the workaround is not supported).
93          *  - MC_CMD_ERR_ENOENT (reported as ENOENT):
94          *      Firmware does not support the requested workaround.
95          *  - MC_CMD_ERR_EPERM  (reported as EACCES):
96          *      Unprivileged function cannot enable/disable workarounds.
97          *
98          * See efx_mcdi_request_errcode() for MCDI error translations.
99          */
100
101
102         if (EFX_PCI_FUNCTION_IS_VF(encp)) {
103                 /*
104                  * Interrupt testing does not work for VFs on Medford2.
105                  * See bug50084 and bug71432 comment 21.
106                  */
107                 encp->enc_bug41750_workaround = B_TRUE;
108         }
109
110         /* Chained multicast is always enabled on Medford2 */
111         encp->enc_bug26807_workaround = B_TRUE;
112
113         /*
114          * If the bug61265 workaround is enabled, then interrupt holdoff timers
115          * cannot be controlled by timer table writes, so MCDI must be used
116          * (timer table writes can still be used for wakeup timers).
117          */
118         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG61265, B_TRUE,
119             NULL);
120         if ((rc == 0) || (rc == EACCES))
121                 encp->enc_bug61265_workaround = B_TRUE;
122         else if ((rc == ENOTSUP) || (rc == ENOENT))
123                 encp->enc_bug61265_workaround = B_FALSE;
124         else
125                 goto fail4;
126
127         /* Get clock frequencies (in MHz). */
128         if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
129                 goto fail5;
130
131         /*
132          * The Medford2 timer quantum is 1536 dpcpu_clk cycles, documented for
133          * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
134          */
135         encp->enc_evq_timer_quantum_ns = 1536000UL / dpcpu_clk; /* 1536 cycles */
136         encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
137                     FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
138
139         /* Check capabilities of running datapath firmware */
140         if ((rc = ef10_get_datapath_caps(enp)) != 0)
141                 goto fail6;
142
143         /* Alignment for receive packet DMA buffers */
144         encp->enc_rx_buf_align_start = 1;
145
146         /* Get the RX DMA end padding alignment configuration */
147         if ((rc = efx_mcdi_get_rxdp_config(enp, &end_padding)) != 0) {
148                 if (rc != EACCES)
149                         goto fail7;
150
151                 /* Assume largest tail padding size supported by hardware */
152                 end_padding = 256;
153         }
154         encp->enc_rx_buf_align_end = end_padding;
155
156         /* Alignment for WPTR updates */
157         encp->enc_rx_push_align = EF10_RX_WPTR_ALIGN;
158
159         /*
160          * Maximum number of exclusive RSS contexts which can be allocated. The
161          * hardware supports 64, but 6 are reserved for shared contexts. They
162          * are a global resource so not all may be available.
163          */
164         encp->enc_rx_scale_max_exclusive_contexts = 58;
165
166         encp->enc_tx_dma_desc_size_max = EFX_MASK32(ESF_DZ_RX_KER_BYTE_CNT);
167         /* No boundary crossing limits */
168         encp->enc_tx_dma_desc_boundary = 0;
169
170         /*
171          * Set resource limits for MC_CMD_ALLOC_VIS. Note that we cannot use
172          * MC_CMD_GET_RESOURCE_LIMITS here as that reports the available
173          * resources (allocated to this PCIe function), which is zero until
174          * after we have allocated VIs.
175          */
176         encp->enc_evq_limit = 1024;
177         encp->enc_rxq_limit = EFX_RXQ_LIMIT_TARGET;
178         encp->enc_txq_limit = EFX_TXQ_LIMIT_TARGET;
179
180         /*
181          * The maximum supported transmit queue size is 2048. TXQs with 4096
182          * descriptors are not supported as the top bit is used for vfifo
183          * stuffing.
184          */
185         encp->enc_txq_max_ndescs = 2048;
186
187         encp->enc_buftbl_limit = 0xFFFFFFFF;
188
189         EFX_STATIC_ASSERT(MEDFORD2_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
190         encp->enc_piobuf_limit = MEDFORD2_PIOBUF_NBUFS;
191         encp->enc_piobuf_size = MEDFORD2_PIOBUF_SIZE;
192         encp->enc_piobuf_min_alloc_size = MEDFORD2_MIN_PIO_ALLOC_SIZE;
193
194         /*
195          * Get the current privilege mask. Note that this may be modified
196          * dynamically, so this value is informational only. DO NOT use
197          * the privilege mask to check for sufficient privileges, as that
198          * can result in time-of-check/time-of-use bugs.
199          */
200         if ((rc = ef10_get_privilege_mask(enp, &mask)) != 0)
201                 goto fail8;
202         encp->enc_privilege_mask = mask;
203
204         /* Get interrupt vector limits */
205         if ((rc = efx_mcdi_get_vector_cfg(enp, &base, &nvec, NULL)) != 0) {
206                 if (EFX_PCI_FUNCTION_IS_PF(encp))
207                         goto fail9;
208
209                 /* Ignore error (cannot query vector limits from a VF). */
210                 base = 0;
211                 nvec = 1024;
212         }
213         encp->enc_intr_vec_base = base;
214         encp->enc_intr_limit = nvec;
215
216         /*
217          * Maximum number of bytes into the frame the TCP header can start for
218          * firmware assisted TSO to work.
219          */
220         encp->enc_tx_tso_tcp_header_offset_limit = EF10_TCP_HEADER_OFFSET_LIMIT;
221
222         /*
223          * Medford2 stores a single global copy of VPD, not per-PF as on
224          * Huntington.
225          */
226         encp->enc_vpd_is_global = B_TRUE;
227
228         rc = medford2_nic_get_required_pcie_bandwidth(enp, &bandwidth);
229         if (rc != 0)
230                 goto fail10;
231         encp->enc_required_pcie_bandwidth_mbps = bandwidth;
232         encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
233
234         return (0);
235
236 fail10:
237         EFSYS_PROBE(fail10);
238 fail9:
239         EFSYS_PROBE(fail9);
240 fail8:
241         EFSYS_PROBE(fail8);
242 fail7:
243         EFSYS_PROBE(fail7);
244 fail6:
245         EFSYS_PROBE(fail6);
246 fail5:
247         EFSYS_PROBE(fail5);
248 fail4:
249         EFSYS_PROBE(fail4);
250 fail3:
251         EFSYS_PROBE(fail3);
252 fail2:
253         EFSYS_PROBE(fail2);
254 fail1:
255         EFSYS_PROBE1(fail1, efx_rc_t, rc);
256
257         return (rc);
258 }
259
260 #endif  /* EFSYS_OPT_MEDFORD2 */