add0af0d9d46ef7788966f4992da15cecaed7913
[dpdk.git] / drivers / net / sfc / base / medford_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_MEDFORD
12
13 static  __checkReturn   efx_rc_t
14 medford_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         if ((rc = efx_mcdi_get_port_modes(enp, &port_modes,
24                                     &current_mode)) != 0) {
25                 /* No port mode info available. */
26                 bandwidth = 0;
27                 goto out;
28         }
29
30         if ((rc = ef10_nic_get_port_mode_bandwidth(current_mode,
31                                                     &bandwidth)) != 0)
32                 goto fail1;
33
34 out:
35         *bandwidth_mbpsp = bandwidth;
36
37         return (0);
38
39 fail1:
40         EFSYS_PROBE1(fail1, efx_rc_t, rc);
41
42         return (rc);
43 }
44
45         __checkReturn   efx_rc_t
46 medford_board_cfg(
47         __in            efx_nic_t *enp)
48 {
49         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
50         uint32_t mask;
51         uint32_t sysclk, dpcpu_clk;
52         uint32_t base, nvec;
53         uint32_t end_padding;
54         uint32_t bandwidth;
55         efx_rc_t rc;
56
57         /*
58          * FIXME: Likely to be incomplete and incorrect.
59          * Parts of this should be shared with Huntington.
60          */
61
62         /* Medford has a fixed 8Kbyte VI window size */
63         EFX_STATIC_ASSERT(ER_DZ_EVQ_RPTR_REG_STEP       == 8192);
64         EFX_STATIC_ASSERT(ER_DZ_EVQ_TMR_REG_STEP        == 8192);
65         EFX_STATIC_ASSERT(ER_DZ_RX_DESC_UPD_REG_STEP    == 8192);
66         EFX_STATIC_ASSERT(ER_DZ_TX_DESC_UPD_REG_STEP    == 8192);
67         EFX_STATIC_ASSERT(ER_DZ_TX_PIOBUF_STEP          == 8192);
68
69         EFX_STATIC_ASSERT(1U << EFX_VI_WINDOW_SHIFT_8K  == 8192);
70         encp->enc_vi_window_shift = EFX_VI_WINDOW_SHIFT_8K;
71
72         /*
73          * Enable firmware workarounds for hardware errata.
74          * Expected responses are:
75          *  - 0 (zero):
76          *      Success: workaround enabled or disabled as requested.
77          *  - MC_CMD_ERR_ENOSYS (reported as ENOTSUP):
78          *      Firmware does not support the MC_CMD_WORKAROUND request.
79          *      (assume that the workaround is not supported).
80          *  - MC_CMD_ERR_ENOENT (reported as ENOENT):
81          *      Firmware does not support the requested workaround.
82          *  - MC_CMD_ERR_EPERM  (reported as EACCES):
83          *      Unprivileged function cannot enable/disable workarounds.
84          *
85          * See efx_mcdi_request_errcode() for MCDI error translations.
86          */
87
88
89         if (EFX_PCI_FUNCTION_IS_VF(encp)) {
90                 /*
91                  * Interrupt testing does not work for VFs. See bug50084 and
92                  * bug71432 comment 21.
93                  */
94                 encp->enc_bug41750_workaround = B_TRUE;
95         }
96
97         /* Chained multicast is always enabled on Medford */
98         encp->enc_bug26807_workaround = B_TRUE;
99
100         /*
101          * If the bug61265 workaround is enabled, then interrupt holdoff timers
102          * cannot be controlled by timer table writes, so MCDI must be used
103          * (timer table writes can still be used for wakeup timers).
104          */
105         rc = efx_mcdi_set_workaround(enp, MC_CMD_WORKAROUND_BUG61265, B_TRUE,
106             NULL);
107         if ((rc == 0) || (rc == EACCES))
108                 encp->enc_bug61265_workaround = B_TRUE;
109         else if ((rc == ENOTSUP) || (rc == ENOENT))
110                 encp->enc_bug61265_workaround = B_FALSE;
111         else
112                 goto fail1;
113
114         /* Get clock frequencies (in MHz). */
115         if ((rc = efx_mcdi_get_clock(enp, &sysclk, &dpcpu_clk)) != 0)
116                 goto fail2;
117
118         /*
119          * The Medford timer quantum is 1536 dpcpu_clk cycles, documented for
120          * the EV_TMR_VAL field of EV_TIMER_TBL. Scale for MHz and ns units.
121          */
122         encp->enc_evq_timer_quantum_ns = 1536000UL / dpcpu_clk; /* 1536 cycles */
123         encp->enc_evq_timer_max_us = (encp->enc_evq_timer_quantum_ns <<
124                     FRF_CZ_TC_TIMER_VAL_WIDTH) / 1000;
125
126         /* Alignment for receive packet DMA buffers */
127         encp->enc_rx_buf_align_start = 1;
128
129         /* Get the RX DMA end padding alignment configuration */
130         if ((rc = efx_mcdi_get_rxdp_config(enp, &end_padding)) != 0) {
131                 if (rc != EACCES)
132                         goto fail3;
133
134                 /* Assume largest tail padding size supported by hardware */
135                 end_padding = 256;
136         }
137         encp->enc_rx_buf_align_end = end_padding;
138
139         encp->enc_tx_dma_desc_size_max = EFX_MASK32(ESF_DZ_RX_KER_BYTE_CNT);
140         /* No boundary crossing limits */
141         encp->enc_tx_dma_desc_boundary = 0;
142
143         /*
144          * Set resource limits for MC_CMD_ALLOC_VIS. Note that we cannot use
145          * MC_CMD_GET_RESOURCE_LIMITS here as that reports the available
146          * resources (allocated to this PCIe function), which is zero until
147          * after we have allocated VIs.
148          */
149         encp->enc_evq_limit = 1024;
150         encp->enc_rxq_limit = EFX_RXQ_LIMIT_TARGET;
151         encp->enc_txq_limit = EFX_TXQ_LIMIT_TARGET;
152
153         /*
154          * The maximum supported transmit queue size is 2048. TXQs with 4096
155          * descriptors are not supported as the top bit is used for vfifo
156          * stuffing.
157          */
158         encp->enc_txq_max_ndescs = 2048;
159
160         encp->enc_buftbl_limit = 0xFFFFFFFF;
161
162         EFX_STATIC_ASSERT(MEDFORD_PIOBUF_NBUFS <= EF10_MAX_PIOBUF_NBUFS);
163         encp->enc_piobuf_limit = MEDFORD_PIOBUF_NBUFS;
164         encp->enc_piobuf_size = MEDFORD_PIOBUF_SIZE;
165         encp->enc_piobuf_min_alloc_size = MEDFORD_MIN_PIO_ALLOC_SIZE;
166
167         /*
168          * Get the current privilege mask. Note that this may be modified
169          * dynamically, so this value is informational only. DO NOT use
170          * the privilege mask to check for sufficient privileges, as that
171          * can result in time-of-check/time-of-use bugs.
172          */
173         if ((rc = ef10_get_privilege_mask(enp, &mask)) != 0)
174                 goto fail4;
175         encp->enc_privilege_mask = mask;
176
177         /* Get interrupt vector limits */
178         if ((rc = efx_mcdi_get_vector_cfg(enp, &base, &nvec, NULL)) != 0) {
179                 if (EFX_PCI_FUNCTION_IS_PF(encp))
180                         goto fail5;
181
182                 /* Ignore error (cannot query vector limits from a VF). */
183                 base = 0;
184                 nvec = 1024;
185         }
186         encp->enc_intr_vec_base = base;
187         encp->enc_intr_limit = nvec;
188
189         /*
190          * Maximum number of bytes into the frame the TCP header can start for
191          * firmware assisted TSO to work.
192          */
193         encp->enc_tx_tso_tcp_header_offset_limit = EF10_TCP_HEADER_OFFSET_LIMIT;
194
195         /*
196          * Medford stores a single global copy of VPD, not per-PF as on
197          * Huntington.
198          */
199         encp->enc_vpd_is_global = B_TRUE;
200
201         rc = medford_nic_get_required_pcie_bandwidth(enp, &bandwidth);
202         if (rc != 0)
203                 goto fail6;
204         encp->enc_required_pcie_bandwidth_mbps = bandwidth;
205         encp->enc_max_pcie_link_gen = EFX_PCIE_LINK_SPEED_GEN3;
206
207         return (0);
208
209 fail6:
210         EFSYS_PROBE(fail6);
211 fail5:
212         EFSYS_PROBE(fail5);
213 fail4:
214         EFSYS_PROBE(fail4);
215 fail3:
216         EFSYS_PROBE(fail3);
217 fail2:
218         EFSYS_PROBE(fail2);
219 fail1:
220         EFSYS_PROBE1(fail1, efx_rc_t, rc);
221
222         return (rc);
223 }
224
225 #endif  /* EFSYS_OPT_MEDFORD */