Commit | Line | Data |
---|---|---|
8127d661 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare network controllers and boards | |
3 | * Copyright 2012-2013 Solarflare Communications Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 as published | |
7 | * by the Free Software Foundation, incorporated herein by reference. | |
8 | */ | |
9 | ||
10 | #include "net_driver.h" | |
11 | #include "ef10_regs.h" | |
12 | #include "io.h" | |
13 | #include "mcdi.h" | |
14 | #include "mcdi_pcol.h" | |
15 | #include "nic.h" | |
16 | #include "workarounds.h" | |
74cd60a4 | 17 | #include "selftest.h" |
7fa8d547 | 18 | #include "ef10_sriov.h" |
8127d661 BH |
19 | #include <linux/in.h> |
20 | #include <linux/jhash.h> | |
21 | #include <linux/wait.h> | |
22 | #include <linux/workqueue.h> | |
23 | ||
24 | /* Hardware control for EF10 architecture including 'Huntington'. */ | |
25 | ||
26 | #define EFX_EF10_DRVGEN_EV 7 | |
27 | enum { | |
28 | EFX_EF10_TEST = 1, | |
29 | EFX_EF10_REFILL, | |
30 | }; | |
31 | ||
32 | /* The reserved RSS context value */ | |
33 | #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff | |
34 | ||
35 | /* The filter table(s) are managed by firmware and we have write-only | |
36 | * access. When removing filters we must identify them to the | |
37 | * firmware by a 64-bit handle, but this is too wide for Linux kernel | |
38 | * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to | |
39 | * be able to tell in advance whether a requested insertion will | |
40 | * replace an existing filter. Therefore we maintain a software hash | |
41 | * table, which should be at least as large as the hardware hash | |
42 | * table. | |
43 | * | |
44 | * Huntington has a single 8K filter table shared between all filter | |
45 | * types and both ports. | |
46 | */ | |
47 | #define HUNT_FILTER_TBL_ROWS 8192 | |
48 | ||
49 | struct efx_ef10_filter_table { | |
50 | /* The RX match field masks supported by this fw & hw, in order of priority */ | |
51 | enum efx_filter_match_flags rx_match_flags[ | |
52 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM]; | |
53 | unsigned int rx_match_count; | |
54 | ||
55 | struct { | |
56 | unsigned long spec; /* pointer to spec plus flag bits */ | |
b59e6ef8 BH |
57 | /* BUSY flag indicates that an update is in progress. AUTO_OLD is |
58 | * used to mark and sweep MAC filters for the device address lists. | |
8127d661 BH |
59 | */ |
60 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL | |
b59e6ef8 | 61 | #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL |
8127d661 BH |
62 | #define EFX_EF10_FILTER_FLAGS 3UL |
63 | u64 handle; /* firmware handle */ | |
64 | } *entry; | |
65 | wait_queue_head_t waitq; | |
66 | /* Shadow of net_device address lists, guarded by mac_lock */ | |
b59e6ef8 BH |
67 | #define EFX_EF10_FILTER_DEV_UC_MAX 32 |
68 | #define EFX_EF10_FILTER_DEV_MC_MAX 256 | |
8127d661 BH |
69 | struct { |
70 | u8 addr[ETH_ALEN]; | |
71 | u16 id; | |
b59e6ef8 BH |
72 | } dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX], |
73 | dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; | |
74 | int dev_uc_count; /* negative for PROMISC */ | |
75 | int dev_mc_count; /* negative for PROMISC/ALLMULTI */ | |
8127d661 BH |
76 | }; |
77 | ||
78 | /* An arbitrary search limit for the software hash table */ | |
79 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 | |
80 | ||
d43050c0 | 81 | static void efx_ef10_rx_push_rss_config(struct efx_nic *efx); |
8127d661 BH |
82 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); |
83 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); | |
84 | ||
85 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) | |
86 | { | |
87 | efx_dword_t reg; | |
88 | ||
89 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); | |
90 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? | |
91 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; | |
92 | } | |
93 | ||
94 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) | |
95 | { | |
02246a7f SS |
96 | int bar; |
97 | ||
98 | bar = efx->type->mem_bar; | |
99 | return resource_size(&efx->pci_dev->resource[bar]); | |
8127d661 BH |
100 | } |
101 | ||
1cd9ecbb DP |
102 | static int efx_ef10_get_pf_index(struct efx_nic *efx) |
103 | { | |
104 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); | |
105 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
106 | size_t outlen; | |
107 | int rc; | |
108 | ||
109 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, | |
110 | sizeof(outbuf), &outlen); | |
111 | if (rc) | |
112 | return rc; | |
113 | if (outlen < sizeof(outbuf)) | |
114 | return -EIO; | |
115 | ||
116 | nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); | |
117 | return 0; | |
118 | } | |
119 | ||
e5a2538a | 120 | static int efx_ef10_init_datapath_caps(struct efx_nic *efx) |
8127d661 BH |
121 | { |
122 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN); | |
123 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
124 | size_t outlen; | |
125 | int rc; | |
126 | ||
127 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); | |
128 | ||
129 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, | |
130 | outbuf, sizeof(outbuf), &outlen); | |
131 | if (rc) | |
132 | return rc; | |
e5a2538a BH |
133 | if (outlen < sizeof(outbuf)) { |
134 | netif_err(efx, drv, efx->net_dev, | |
135 | "unable to read datapath firmware capabilities\n"); | |
136 | return -EIO; | |
137 | } | |
138 | ||
139 | nic_data->datapath_caps = | |
140 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); | |
8127d661 | 141 | |
8d9f9dd4 DP |
142 | /* record the DPCPU firmware IDs to determine VEB vswitching support. |
143 | */ | |
144 | nic_data->rx_dpcpu_fw_id = | |
145 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID); | |
146 | nic_data->tx_dpcpu_fw_id = | |
147 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID); | |
148 | ||
e5a2538a BH |
149 | if (!(nic_data->datapath_caps & |
150 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) { | |
151 | netif_err(efx, drv, efx->net_dev, | |
152 | "current firmware does not support TSO\n"); | |
153 | return -ENODEV; | |
154 | } | |
155 | ||
156 | if (!(nic_data->datapath_caps & | |
157 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { | |
158 | netif_err(efx, probe, efx->net_dev, | |
159 | "current firmware does not support an RX prefix\n"); | |
160 | return -ENODEV; | |
8127d661 BH |
161 | } |
162 | ||
163 | return 0; | |
164 | } | |
165 | ||
166 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) | |
167 | { | |
168 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); | |
169 | int rc; | |
170 | ||
171 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, | |
172 | outbuf, sizeof(outbuf), NULL); | |
173 | if (rc) | |
174 | return rc; | |
175 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); | |
176 | return rc > 0 ? rc : -ERANGE; | |
177 | } | |
178 | ||
179 | static int efx_ef10_get_mac_address(struct efx_nic *efx, u8 *mac_address) | |
180 | { | |
181 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); | |
182 | size_t outlen; | |
183 | int rc; | |
184 | ||
185 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); | |
186 | ||
187 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, | |
188 | outbuf, sizeof(outbuf), &outlen); | |
189 | if (rc) | |
190 | return rc; | |
191 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) | |
192 | return -EIO; | |
193 | ||
cd84ff4d EC |
194 | ether_addr_copy(mac_address, |
195 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); | |
8127d661 BH |
196 | return 0; |
197 | } | |
198 | ||
199 | static int efx_ef10_probe(struct efx_nic *efx) | |
200 | { | |
201 | struct efx_ef10_nic_data *nic_data; | |
202 | int i, rc; | |
203 | ||
aa3930ee BH |
204 | /* We can have one VI for each 8K region. However, until we |
205 | * use TX option descriptors we need two TX queues per channel. | |
8127d661 BH |
206 | */ |
207 | efx->max_channels = | |
208 | min_t(unsigned int, | |
209 | EFX_MAX_CHANNELS, | |
02246a7f | 210 | efx_ef10_mem_map_size(efx) / |
8127d661 | 211 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); |
9fd3d3a4 EC |
212 | if (WARN_ON(efx->max_channels == 0)) |
213 | return -EIO; | |
8127d661 BH |
214 | |
215 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); | |
216 | if (!nic_data) | |
217 | return -ENOMEM; | |
218 | efx->nic_data = nic_data; | |
219 | ||
220 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, | |
221 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); | |
222 | if (rc) | |
223 | goto fail1; | |
224 | ||
225 | /* Get the MC's warm boot count. In case it's rebooting right | |
226 | * now, be prepared to retry. | |
227 | */ | |
228 | i = 0; | |
229 | for (;;) { | |
230 | rc = efx_ef10_get_warm_boot_count(efx); | |
231 | if (rc >= 0) | |
232 | break; | |
233 | if (++i == 5) | |
234 | goto fail2; | |
235 | ssleep(1); | |
236 | } | |
237 | nic_data->warm_boot_count = rc; | |
238 | ||
239 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
240 | ||
45b2449e DP |
241 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
242 | ||
8127d661 BH |
243 | /* In case we're recovering from a crash (kexec), we want to |
244 | * cancel any outstanding request by the previous user of this | |
245 | * function. We send a special message using the least | |
246 | * significant bits of the 'high' (doorbell) register. | |
247 | */ | |
248 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); | |
249 | ||
250 | rc = efx_mcdi_init(efx); | |
251 | if (rc) | |
252 | goto fail2; | |
253 | ||
254 | /* Reset (most) configuration for this function */ | |
255 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); | |
256 | if (rc) | |
257 | goto fail3; | |
258 | ||
259 | /* Enable event logging */ | |
260 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); | |
261 | if (rc) | |
262 | goto fail3; | |
263 | ||
1cd9ecbb DP |
264 | rc = efx_ef10_get_pf_index(efx); |
265 | if (rc) | |
266 | goto fail3; | |
267 | ||
e5a2538a | 268 | rc = efx_ef10_init_datapath_caps(efx); |
8127d661 BH |
269 | if (rc < 0) |
270 | goto fail3; | |
271 | ||
272 | efx->rx_packet_len_offset = | |
273 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; | |
274 | ||
8127d661 BH |
275 | rc = efx_mcdi_port_get_number(efx); |
276 | if (rc < 0) | |
277 | goto fail3; | |
278 | efx->port_num = rc; | |
279 | ||
280 | rc = efx_ef10_get_mac_address(efx, efx->net_dev->perm_addr); | |
281 | if (rc) | |
282 | goto fail3; | |
283 | ||
284 | rc = efx_ef10_get_sysclk_freq(efx); | |
285 | if (rc < 0) | |
286 | goto fail3; | |
287 | efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */ | |
288 | ||
267d9d73 EC |
289 | /* Check whether firmware supports bug 35388 workaround. |
290 | * First try to enable it, then if we get EPERM, just | |
291 | * ask if it's already enabled | |
292 | */ | |
8127d661 BH |
293 | rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true); |
294 | if (rc == 0) | |
295 | nic_data->workaround_35388 = true; | |
267d9d73 EC |
296 | else if (rc == -EPERM) { |
297 | unsigned int enabled; | |
298 | ||
299 | rc = efx_mcdi_get_workarounds(efx, NULL, &enabled); | |
300 | if (rc) | |
301 | goto fail3; | |
302 | nic_data->workaround_35388 = enabled & | |
303 | MC_CMD_GET_WORKAROUNDS_OUT_BUG35388; | |
304 | } | |
8127d661 BH |
305 | else if (rc != -ENOSYS && rc != -ENOENT) |
306 | goto fail3; | |
307 | netif_dbg(efx, probe, efx->net_dev, | |
308 | "workaround for bug 35388 is %sabled\n", | |
309 | nic_data->workaround_35388 ? "en" : "dis"); | |
310 | ||
311 | rc = efx_mcdi_mon_probe(efx); | |
267d9d73 | 312 | if (rc && rc != -EPERM) |
8127d661 BH |
313 | goto fail3; |
314 | ||
9aecda95 BH |
315 | efx_ptp_probe(efx, NULL); |
316 | ||
8127d661 BH |
317 | return 0; |
318 | ||
319 | fail3: | |
320 | efx_mcdi_fini(efx); | |
321 | fail2: | |
322 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
323 | fail1: | |
324 | kfree(nic_data); | |
325 | efx->nic_data = NULL; | |
326 | return rc; | |
327 | } | |
328 | ||
02246a7f SS |
329 | static int efx_ef10_probe_pf(struct efx_nic *efx) |
330 | { | |
331 | return efx_ef10_probe(efx); | |
332 | } | |
333 | ||
334 | #ifdef CONFIG_SFC_SRIOV | |
335 | static int efx_ef10_probe_vf(struct efx_nic *efx) | |
336 | { | |
337 | return efx_ef10_probe(efx); | |
338 | } | |
339 | #else | |
340 | static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused))) | |
341 | { | |
342 | return 0; | |
343 | } | |
344 | #endif | |
345 | ||
8127d661 BH |
346 | static int efx_ef10_free_vis(struct efx_nic *efx) |
347 | { | |
1e0b8120 EC |
348 | MCDI_DECLARE_BUF_OUT_OR_ERR(outbuf, 0); |
349 | size_t outlen; | |
350 | int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0, | |
351 | outbuf, sizeof(outbuf), &outlen); | |
8127d661 BH |
352 | |
353 | /* -EALREADY means nothing to free, so ignore */ | |
354 | if (rc == -EALREADY) | |
355 | rc = 0; | |
1e0b8120 EC |
356 | if (rc) |
357 | efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen, | |
358 | rc); | |
8127d661 BH |
359 | return rc; |
360 | } | |
361 | ||
183233be BH |
362 | #ifdef EFX_USE_PIO |
363 | ||
364 | static void efx_ef10_free_piobufs(struct efx_nic *efx) | |
365 | { | |
366 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
367 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN); | |
368 | unsigned int i; | |
369 | int rc; | |
370 | ||
371 | BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0); | |
372 | ||
373 | for (i = 0; i < nic_data->n_piobufs; i++) { | |
374 | MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE, | |
375 | nic_data->piobuf_handle[i]); | |
376 | rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf), | |
377 | NULL, 0, NULL); | |
378 | WARN_ON(rc); | |
379 | } | |
380 | ||
381 | nic_data->n_piobufs = 0; | |
382 | } | |
383 | ||
384 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) | |
385 | { | |
386 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
387 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN); | |
388 | unsigned int i; | |
389 | size_t outlen; | |
390 | int rc = 0; | |
391 | ||
392 | BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0); | |
393 | ||
394 | for (i = 0; i < n; i++) { | |
395 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0, | |
396 | outbuf, sizeof(outbuf), &outlen); | |
397 | if (rc) | |
398 | break; | |
399 | if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) { | |
400 | rc = -EIO; | |
401 | break; | |
402 | } | |
403 | nic_data->piobuf_handle[i] = | |
404 | MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE); | |
405 | netif_dbg(efx, probe, efx->net_dev, | |
406 | "allocated PIO buffer %u handle %x\n", i, | |
407 | nic_data->piobuf_handle[i]); | |
408 | } | |
409 | ||
410 | nic_data->n_piobufs = i; | |
411 | if (rc) | |
412 | efx_ef10_free_piobufs(efx); | |
413 | return rc; | |
414 | } | |
415 | ||
416 | static int efx_ef10_link_piobufs(struct efx_nic *efx) | |
417 | { | |
418 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
419 | MCDI_DECLARE_BUF(inbuf, | |
420 | max(MC_CMD_LINK_PIOBUF_IN_LEN, | |
421 | MC_CMD_UNLINK_PIOBUF_IN_LEN)); | |
422 | struct efx_channel *channel; | |
423 | struct efx_tx_queue *tx_queue; | |
424 | unsigned int offset, index; | |
425 | int rc; | |
426 | ||
427 | BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0); | |
428 | BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0); | |
429 | ||
430 | /* Link a buffer to each VI in the write-combining mapping */ | |
431 | for (index = 0; index < nic_data->n_piobufs; ++index) { | |
432 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE, | |
433 | nic_data->piobuf_handle[index]); | |
434 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE, | |
435 | nic_data->pio_write_vi_base + index); | |
436 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, | |
437 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, | |
438 | NULL, 0, NULL); | |
439 | if (rc) { | |
440 | netif_err(efx, drv, efx->net_dev, | |
441 | "failed to link VI %u to PIO buffer %u (%d)\n", | |
442 | nic_data->pio_write_vi_base + index, index, | |
443 | rc); | |
444 | goto fail; | |
445 | } | |
446 | netif_dbg(efx, probe, efx->net_dev, | |
447 | "linked VI %u to PIO buffer %u\n", | |
448 | nic_data->pio_write_vi_base + index, index); | |
449 | } | |
450 | ||
451 | /* Link a buffer to each TX queue */ | |
452 | efx_for_each_channel(channel, efx) { | |
453 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
454 | /* We assign the PIO buffers to queues in | |
455 | * reverse order to allow for the following | |
456 | * special case. | |
457 | */ | |
458 | offset = ((efx->tx_channel_offset + efx->n_tx_channels - | |
459 | tx_queue->channel->channel - 1) * | |
460 | efx_piobuf_size); | |
461 | index = offset / ER_DZ_TX_PIOBUF_SIZE; | |
462 | offset = offset % ER_DZ_TX_PIOBUF_SIZE; | |
463 | ||
464 | /* When the host page size is 4K, the first | |
465 | * host page in the WC mapping may be within | |
466 | * the same VI page as the last TX queue. We | |
467 | * can only link one buffer to each VI. | |
468 | */ | |
469 | if (tx_queue->queue == nic_data->pio_write_vi_base) { | |
470 | BUG_ON(index != 0); | |
471 | rc = 0; | |
472 | } else { | |
473 | MCDI_SET_DWORD(inbuf, | |
474 | LINK_PIOBUF_IN_PIOBUF_HANDLE, | |
475 | nic_data->piobuf_handle[index]); | |
476 | MCDI_SET_DWORD(inbuf, | |
477 | LINK_PIOBUF_IN_TXQ_INSTANCE, | |
478 | tx_queue->queue); | |
479 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, | |
480 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, | |
481 | NULL, 0, NULL); | |
482 | } | |
483 | ||
484 | if (rc) { | |
485 | /* This is non-fatal; the TX path just | |
486 | * won't use PIO for this queue | |
487 | */ | |
488 | netif_err(efx, drv, efx->net_dev, | |
489 | "failed to link VI %u to PIO buffer %u (%d)\n", | |
490 | tx_queue->queue, index, rc); | |
491 | tx_queue->piobuf = NULL; | |
492 | } else { | |
493 | tx_queue->piobuf = | |
494 | nic_data->pio_write_base + | |
495 | index * EFX_VI_PAGE_SIZE + offset; | |
496 | tx_queue->piobuf_offset = offset; | |
497 | netif_dbg(efx, probe, efx->net_dev, | |
498 | "linked VI %u to PIO buffer %u offset %x addr %p\n", | |
499 | tx_queue->queue, index, | |
500 | tx_queue->piobuf_offset, | |
501 | tx_queue->piobuf); | |
502 | } | |
503 | } | |
504 | } | |
505 | ||
506 | return 0; | |
507 | ||
508 | fail: | |
509 | while (index--) { | |
510 | MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE, | |
511 | nic_data->pio_write_vi_base + index); | |
512 | efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF, | |
513 | inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN, | |
514 | NULL, 0, NULL); | |
515 | } | |
516 | return rc; | |
517 | } | |
518 | ||
519 | #else /* !EFX_USE_PIO */ | |
520 | ||
521 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) | |
522 | { | |
523 | return n == 0 ? 0 : -ENOBUFS; | |
524 | } | |
525 | ||
526 | static int efx_ef10_link_piobufs(struct efx_nic *efx) | |
527 | { | |
528 | return 0; | |
529 | } | |
530 | ||
531 | static void efx_ef10_free_piobufs(struct efx_nic *efx) | |
532 | { | |
533 | } | |
534 | ||
535 | #endif /* EFX_USE_PIO */ | |
536 | ||
8127d661 BH |
537 | static void efx_ef10_remove(struct efx_nic *efx) |
538 | { | |
539 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
540 | int rc; | |
541 | ||
9aecda95 BH |
542 | efx_ptp_remove(efx); |
543 | ||
8127d661 BH |
544 | efx_mcdi_mon_remove(efx); |
545 | ||
8127d661 BH |
546 | efx_ef10_rx_free_indir_table(efx); |
547 | ||
183233be BH |
548 | if (nic_data->wc_membase) |
549 | iounmap(nic_data->wc_membase); | |
550 | ||
8127d661 BH |
551 | rc = efx_ef10_free_vis(efx); |
552 | WARN_ON(rc != 0); | |
553 | ||
183233be BH |
554 | if (!nic_data->must_restore_piobufs) |
555 | efx_ef10_free_piobufs(efx); | |
556 | ||
8127d661 BH |
557 | efx_mcdi_fini(efx); |
558 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
559 | kfree(nic_data); | |
560 | } | |
561 | ||
562 | static int efx_ef10_alloc_vis(struct efx_nic *efx, | |
563 | unsigned int min_vis, unsigned int max_vis) | |
564 | { | |
565 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); | |
566 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); | |
567 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
568 | size_t outlen; | |
569 | int rc; | |
570 | ||
571 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); | |
572 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); | |
573 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), | |
574 | outbuf, sizeof(outbuf), &outlen); | |
575 | if (rc != 0) | |
576 | return rc; | |
577 | ||
578 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) | |
579 | return -EIO; | |
580 | ||
581 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", | |
582 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); | |
583 | ||
584 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); | |
585 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); | |
586 | return 0; | |
587 | } | |
588 | ||
183233be BH |
589 | /* Note that the failure path of this function does not free |
590 | * resources, as this will be done by efx_ef10_remove(). | |
591 | */ | |
8127d661 BH |
592 | static int efx_ef10_dimension_resources(struct efx_nic *efx) |
593 | { | |
183233be BH |
594 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
595 | unsigned int uc_mem_map_size, wc_mem_map_size; | |
596 | unsigned int min_vis, pio_write_vi_base, max_vis; | |
597 | void __iomem *membase; | |
598 | int rc; | |
599 | ||
600 | min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); | |
8127d661 | 601 | |
183233be BH |
602 | #ifdef EFX_USE_PIO |
603 | /* Try to allocate PIO buffers if wanted and if the full | |
604 | * number of PIO buffers would be sufficient to allocate one | |
605 | * copy-buffer per TX channel. Failure is non-fatal, as there | |
606 | * are only a small number of PIO buffers shared between all | |
607 | * functions of the controller. | |
608 | */ | |
609 | if (efx_piobuf_size != 0 && | |
610 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >= | |
611 | efx->n_tx_channels) { | |
612 | unsigned int n_piobufs = | |
613 | DIV_ROUND_UP(efx->n_tx_channels, | |
614 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size); | |
615 | ||
616 | rc = efx_ef10_alloc_piobufs(efx, n_piobufs); | |
617 | if (rc) | |
618 | netif_err(efx, probe, efx->net_dev, | |
619 | "failed to allocate PIO buffers (%d)\n", rc); | |
620 | else | |
621 | netif_dbg(efx, probe, efx->net_dev, | |
622 | "allocated %u PIO buffers\n", n_piobufs); | |
623 | } | |
624 | #else | |
625 | nic_data->n_piobufs = 0; | |
626 | #endif | |
627 | ||
628 | /* PIO buffers should be mapped with write-combining enabled, | |
629 | * and we want to make single UC and WC mappings rather than | |
630 | * several of each (in fact that's the only option if host | |
631 | * page size is >4K). So we may allocate some extra VIs just | |
632 | * for writing PIO buffers through. | |
52ad762b DP |
633 | * |
634 | * The UC mapping contains (min_vis - 1) complete VIs and the | |
635 | * first half of the next VI. Then the WC mapping begins with | |
636 | * the second half of this last VI. | |
183233be BH |
637 | */ |
638 | uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE + | |
639 | ER_DZ_TX_PIOBUF); | |
640 | if (nic_data->n_piobufs) { | |
52ad762b DP |
641 | /* pio_write_vi_base rounds down to give the number of complete |
642 | * VIs inside the UC mapping. | |
643 | */ | |
183233be BH |
644 | pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE; |
645 | wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base + | |
646 | nic_data->n_piobufs) * | |
647 | EFX_VI_PAGE_SIZE) - | |
648 | uc_mem_map_size); | |
649 | max_vis = pio_write_vi_base + nic_data->n_piobufs; | |
650 | } else { | |
651 | pio_write_vi_base = 0; | |
652 | wc_mem_map_size = 0; | |
653 | max_vis = min_vis; | |
654 | } | |
655 | ||
656 | /* In case the last attached driver failed to free VIs, do it now */ | |
657 | rc = efx_ef10_free_vis(efx); | |
658 | if (rc != 0) | |
659 | return rc; | |
660 | ||
661 | rc = efx_ef10_alloc_vis(efx, min_vis, max_vis); | |
662 | if (rc != 0) | |
663 | return rc; | |
664 | ||
665 | /* If we didn't get enough VIs to map all the PIO buffers, free the | |
666 | * PIO buffers | |
667 | */ | |
668 | if (nic_data->n_piobufs && | |
669 | nic_data->n_allocated_vis < | |
670 | pio_write_vi_base + nic_data->n_piobufs) { | |
671 | netif_dbg(efx, probe, efx->net_dev, | |
672 | "%u VIs are not sufficient to map %u PIO buffers\n", | |
673 | nic_data->n_allocated_vis, nic_data->n_piobufs); | |
674 | efx_ef10_free_piobufs(efx); | |
675 | } | |
676 | ||
677 | /* Shrink the original UC mapping of the memory BAR */ | |
678 | membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size); | |
679 | if (!membase) { | |
680 | netif_err(efx, probe, efx->net_dev, | |
681 | "could not shrink memory BAR to %x\n", | |
682 | uc_mem_map_size); | |
683 | return -ENOMEM; | |
684 | } | |
685 | iounmap(efx->membase); | |
686 | efx->membase = membase; | |
687 | ||
688 | /* Set up the WC mapping if needed */ | |
689 | if (wc_mem_map_size) { | |
690 | nic_data->wc_membase = ioremap_wc(efx->membase_phys + | |
691 | uc_mem_map_size, | |
692 | wc_mem_map_size); | |
693 | if (!nic_data->wc_membase) { | |
694 | netif_err(efx, probe, efx->net_dev, | |
695 | "could not allocate WC mapping of size %x\n", | |
696 | wc_mem_map_size); | |
697 | return -ENOMEM; | |
698 | } | |
699 | nic_data->pio_write_vi_base = pio_write_vi_base; | |
700 | nic_data->pio_write_base = | |
701 | nic_data->wc_membase + | |
702 | (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF - | |
703 | uc_mem_map_size); | |
704 | ||
705 | rc = efx_ef10_link_piobufs(efx); | |
706 | if (rc) | |
707 | efx_ef10_free_piobufs(efx); | |
708 | } | |
709 | ||
710 | netif_dbg(efx, probe, efx->net_dev, | |
711 | "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", | |
712 | &efx->membase_phys, efx->membase, uc_mem_map_size, | |
713 | nic_data->wc_membase, wc_mem_map_size); | |
714 | ||
715 | return 0; | |
8127d661 BH |
716 | } |
717 | ||
718 | static int efx_ef10_init_nic(struct efx_nic *efx) | |
719 | { | |
720 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
721 | int rc; | |
722 | ||
a915ccc9 BH |
723 | if (nic_data->must_check_datapath_caps) { |
724 | rc = efx_ef10_init_datapath_caps(efx); | |
725 | if (rc) | |
726 | return rc; | |
727 | nic_data->must_check_datapath_caps = false; | |
728 | } | |
729 | ||
8127d661 BH |
730 | if (nic_data->must_realloc_vis) { |
731 | /* We cannot let the number of VIs change now */ | |
732 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, | |
733 | nic_data->n_allocated_vis); | |
734 | if (rc) | |
735 | return rc; | |
736 | nic_data->must_realloc_vis = false; | |
737 | } | |
738 | ||
183233be BH |
739 | if (nic_data->must_restore_piobufs && nic_data->n_piobufs) { |
740 | rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs); | |
741 | if (rc == 0) { | |
742 | rc = efx_ef10_link_piobufs(efx); | |
743 | if (rc) | |
744 | efx_ef10_free_piobufs(efx); | |
745 | } | |
746 | ||
747 | /* Log an error on failure, but this is non-fatal */ | |
748 | if (rc) | |
749 | netif_err(efx, drv, efx->net_dev, | |
750 | "failed to restore PIO buffers (%d)\n", rc); | |
751 | nic_data->must_restore_piobufs = false; | |
752 | } | |
753 | ||
d43050c0 | 754 | efx_ef10_rx_push_rss_config(efx); |
8127d661 BH |
755 | return 0; |
756 | } | |
757 | ||
3e336261 JC |
758 | static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) |
759 | { | |
760 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
761 | ||
762 | /* All our allocations have been reset */ | |
763 | nic_data->must_realloc_vis = true; | |
764 | nic_data->must_restore_filters = true; | |
765 | nic_data->must_restore_piobufs = true; | |
766 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
767 | } | |
768 | ||
8127d661 BH |
769 | static int efx_ef10_map_reset_flags(u32 *flags) |
770 | { | |
771 | enum { | |
772 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << | |
773 | ETH_RESET_SHARED_SHIFT), | |
774 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | | |
775 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | | |
776 | ETH_RESET_PHY | ETH_RESET_MGMT) << | |
777 | ETH_RESET_SHARED_SHIFT) | |
778 | }; | |
779 | ||
780 | /* We assume for now that our PCI function is permitted to | |
781 | * reset everything. | |
782 | */ | |
783 | ||
784 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { | |
785 | *flags &= ~EF10_RESET_MC; | |
786 | return RESET_TYPE_WORLD; | |
787 | } | |
788 | ||
789 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { | |
790 | *flags &= ~EF10_RESET_PORT; | |
791 | return RESET_TYPE_ALL; | |
792 | } | |
793 | ||
794 | /* no invisible reset implemented */ | |
795 | ||
796 | return -EINVAL; | |
797 | } | |
798 | ||
3e336261 JC |
799 | static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type) |
800 | { | |
801 | int rc = efx_mcdi_reset(efx, reset_type); | |
802 | ||
803 | /* If it was a port reset, trigger reallocation of MC resources. | |
804 | * Note that on an MC reset nothing needs to be done now because we'll | |
805 | * detect the MC reset later and handle it then. | |
e283546c EC |
806 | * For an FLR, we never get an MC reset event, but the MC has reset all |
807 | * resources assigned to us, so we have to trigger reallocation now. | |
3e336261 | 808 | */ |
e283546c EC |
809 | if ((reset_type == RESET_TYPE_ALL || |
810 | reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc) | |
3e336261 JC |
811 | efx_ef10_reset_mc_allocations(efx); |
812 | return rc; | |
813 | } | |
814 | ||
8127d661 BH |
815 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ |
816 | [EF10_STAT_ ## ext_name] = \ | |
817 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
818 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ | |
819 | [EF10_STAT_ ## int_name] = \ | |
820 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
821 | #define EF10_OTHER_STAT(ext_name) \ | |
822 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } | |
e4d112e4 EC |
823 | #define GENERIC_SW_STAT(ext_name) \ |
824 | [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 } | |
8127d661 BH |
825 | |
826 | static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = { | |
827 | EF10_DMA_STAT(tx_bytes, TX_BYTES), | |
828 | EF10_DMA_STAT(tx_packets, TX_PKTS), | |
829 | EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS), | |
830 | EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS), | |
831 | EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS), | |
832 | EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS), | |
833 | EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS), | |
834 | EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS), | |
835 | EF10_DMA_STAT(tx_64, TX_64_PKTS), | |
836 | EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS), | |
837 | EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS), | |
838 | EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS), | |
839 | EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS), | |
840 | EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), | |
841 | EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), | |
842 | EF10_DMA_STAT(rx_bytes, RX_BYTES), | |
843 | EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES), | |
844 | EF10_OTHER_STAT(rx_good_bytes), | |
845 | EF10_OTHER_STAT(rx_bad_bytes), | |
846 | EF10_DMA_STAT(rx_packets, RX_PKTS), | |
847 | EF10_DMA_STAT(rx_good, RX_GOOD_PKTS), | |
848 | EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS), | |
849 | EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS), | |
850 | EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS), | |
851 | EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS), | |
852 | EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS), | |
853 | EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS), | |
854 | EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS), | |
855 | EF10_DMA_STAT(rx_64, RX_64_PKTS), | |
856 | EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS), | |
857 | EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS), | |
858 | EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS), | |
859 | EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS), | |
860 | EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), | |
861 | EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), | |
862 | EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS), | |
863 | EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS), | |
864 | EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS), | |
865 | EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS), | |
866 | EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS), | |
867 | EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS), | |
e4d112e4 EC |
868 | GENERIC_SW_STAT(rx_nodesc_trunc), |
869 | GENERIC_SW_STAT(rx_noskb_drops), | |
568d7a00 EC |
870 | EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW), |
871 | EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW), | |
872 | EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL), | |
873 | EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL), | |
874 | EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB), | |
875 | EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB), | |
876 | EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING), | |
877 | EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS), | |
878 | EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS), | |
879 | EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS), | |
79ac47ae SS |
880 | EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS), |
881 | EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS), | |
8127d661 BH |
882 | }; |
883 | ||
884 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \ | |
885 | (1ULL << EF10_STAT_tx_packets) | \ | |
886 | (1ULL << EF10_STAT_tx_pause) | \ | |
887 | (1ULL << EF10_STAT_tx_unicast) | \ | |
888 | (1ULL << EF10_STAT_tx_multicast) | \ | |
889 | (1ULL << EF10_STAT_tx_broadcast) | \ | |
890 | (1ULL << EF10_STAT_rx_bytes) | \ | |
891 | (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \ | |
892 | (1ULL << EF10_STAT_rx_good_bytes) | \ | |
893 | (1ULL << EF10_STAT_rx_bad_bytes) | \ | |
894 | (1ULL << EF10_STAT_rx_packets) | \ | |
895 | (1ULL << EF10_STAT_rx_good) | \ | |
896 | (1ULL << EF10_STAT_rx_bad) | \ | |
897 | (1ULL << EF10_STAT_rx_pause) | \ | |
898 | (1ULL << EF10_STAT_rx_control) | \ | |
899 | (1ULL << EF10_STAT_rx_unicast) | \ | |
900 | (1ULL << EF10_STAT_rx_multicast) | \ | |
901 | (1ULL << EF10_STAT_rx_broadcast) | \ | |
902 | (1ULL << EF10_STAT_rx_lt64) | \ | |
903 | (1ULL << EF10_STAT_rx_64) | \ | |
904 | (1ULL << EF10_STAT_rx_65_to_127) | \ | |
905 | (1ULL << EF10_STAT_rx_128_to_255) | \ | |
906 | (1ULL << EF10_STAT_rx_256_to_511) | \ | |
907 | (1ULL << EF10_STAT_rx_512_to_1023) | \ | |
908 | (1ULL << EF10_STAT_rx_1024_to_15xx) | \ | |
909 | (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \ | |
910 | (1ULL << EF10_STAT_rx_gtjumbo) | \ | |
911 | (1ULL << EF10_STAT_rx_bad_gtjumbo) | \ | |
912 | (1ULL << EF10_STAT_rx_overflow) | \ | |
e4d112e4 EC |
913 | (1ULL << EF10_STAT_rx_nodesc_drops) | \ |
914 | (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \ | |
915 | (1ULL << GENERIC_STAT_rx_noskb_drops)) | |
8127d661 BH |
916 | |
917 | /* These statistics are only provided by the 10G MAC. For a 10G/40G | |
918 | * switchable port we do not expose these because they might not | |
919 | * include all the packets they should. | |
920 | */ | |
921 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \ | |
922 | (1ULL << EF10_STAT_tx_lt64) | \ | |
923 | (1ULL << EF10_STAT_tx_64) | \ | |
924 | (1ULL << EF10_STAT_tx_65_to_127) | \ | |
925 | (1ULL << EF10_STAT_tx_128_to_255) | \ | |
926 | (1ULL << EF10_STAT_tx_256_to_511) | \ | |
927 | (1ULL << EF10_STAT_tx_512_to_1023) | \ | |
928 | (1ULL << EF10_STAT_tx_1024_to_15xx) | \ | |
929 | (1ULL << EF10_STAT_tx_15xx_to_jumbo)) | |
930 | ||
931 | /* These statistics are only provided by the 40G MAC. For a 10G/40G | |
932 | * switchable port we do expose these because the errors will otherwise | |
933 | * be silent. | |
934 | */ | |
935 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \ | |
936 | (1ULL << EF10_STAT_rx_length_error)) | |
937 | ||
568d7a00 EC |
938 | /* These statistics are only provided if the firmware supports the |
939 | * capability PM_AND_RXDP_COUNTERS. | |
940 | */ | |
941 | #define HUNT_PM_AND_RXDP_STAT_MASK ( \ | |
942 | (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \ | |
943 | (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \ | |
944 | (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \ | |
945 | (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \ | |
946 | (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \ | |
947 | (1ULL << EF10_STAT_rx_pm_discard_qbb) | \ | |
948 | (1ULL << EF10_STAT_rx_pm_discard_mapping) | \ | |
949 | (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \ | |
950 | (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \ | |
951 | (1ULL << EF10_STAT_rx_dp_streaming_packets) | \ | |
79ac47ae SS |
952 | (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \ |
953 | (1ULL << EF10_STAT_rx_dp_hlb_wait)) | |
568d7a00 | 954 | |
4bae913b | 955 | static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx) |
8127d661 | 956 | { |
4bae913b | 957 | u64 raw_mask = HUNT_COMMON_STAT_MASK; |
8127d661 | 958 | u32 port_caps = efx_mcdi_phy_get_caps(efx); |
568d7a00 | 959 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
960 | |
961 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) | |
4bae913b | 962 | raw_mask |= HUNT_40G_EXTRA_STAT_MASK; |
8127d661 | 963 | else |
4bae913b | 964 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
568d7a00 EC |
965 | |
966 | if (nic_data->datapath_caps & | |
967 | (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN)) | |
968 | raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK; | |
969 | ||
4bae913b EC |
970 | return raw_mask; |
971 | } | |
972 | ||
973 | static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask) | |
974 | { | |
975 | u64 raw_mask = efx_ef10_raw_stat_mask(efx); | |
976 | ||
977 | #if BITS_PER_LONG == 64 | |
978 | mask[0] = raw_mask; | |
979 | #else | |
980 | mask[0] = raw_mask & 0xffffffff; | |
981 | mask[1] = raw_mask >> 32; | |
982 | #endif | |
8127d661 BH |
983 | } |
984 | ||
985 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) | |
986 | { | |
4bae913b EC |
987 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
988 | ||
989 | efx_ef10_get_stat_mask(efx, mask); | |
8127d661 | 990 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
4bae913b | 991 | mask, names); |
8127d661 BH |
992 | } |
993 | ||
994 | static int efx_ef10_try_update_nic_stats(struct efx_nic *efx) | |
995 | { | |
996 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
4bae913b | 997 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
8127d661 BH |
998 | __le64 generation_start, generation_end; |
999 | u64 *stats = nic_data->stats; | |
1000 | __le64 *dma_stats; | |
1001 | ||
4bae913b EC |
1002 | efx_ef10_get_stat_mask(efx, mask); |
1003 | ||
8127d661 BH |
1004 | dma_stats = efx->stats_buffer.addr; |
1005 | nic_data = efx->nic_data; | |
1006 | ||
1007 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
1008 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) | |
1009 | return 0; | |
1010 | rmb(); | |
4bae913b | 1011 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
8127d661 | 1012 | stats, efx->stats_buffer.addr, false); |
d546a893 | 1013 | rmb(); |
8127d661 BH |
1014 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
1015 | if (generation_end != generation_start) | |
1016 | return -EAGAIN; | |
1017 | ||
1018 | /* Update derived statistics */ | |
f8f3b5ae | 1019 | efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]); |
8127d661 BH |
1020 | stats[EF10_STAT_rx_good_bytes] = |
1021 | stats[EF10_STAT_rx_bytes] - | |
1022 | stats[EF10_STAT_rx_bytes_minus_good_bytes]; | |
1023 | efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes], | |
1024 | stats[EF10_STAT_rx_bytes_minus_good_bytes]); | |
e4d112e4 | 1025 | efx_update_sw_stats(efx, stats); |
8127d661 BH |
1026 | return 0; |
1027 | } | |
1028 | ||
1029 | ||
1030 | static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats, | |
1031 | struct rtnl_link_stats64 *core_stats) | |
1032 | { | |
4bae913b | 1033 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
8127d661 BH |
1034 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
1035 | u64 *stats = nic_data->stats; | |
1036 | size_t stats_count = 0, index; | |
1037 | int retry; | |
1038 | ||
4bae913b EC |
1039 | efx_ef10_get_stat_mask(efx, mask); |
1040 | ||
8127d661 BH |
1041 | /* If we're unlucky enough to read statistics during the DMA, wait |
1042 | * up to 10ms for it to finish (typically takes <500us) | |
1043 | */ | |
1044 | for (retry = 0; retry < 100; ++retry) { | |
1045 | if (efx_ef10_try_update_nic_stats(efx) == 0) | |
1046 | break; | |
1047 | udelay(100); | |
1048 | } | |
1049 | ||
1050 | if (full_stats) { | |
1051 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { | |
1052 | if (efx_ef10_stat_desc[index].name) { | |
1053 | *full_stats++ = stats[index]; | |
1054 | ++stats_count; | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | ||
1059 | if (core_stats) { | |
1060 | core_stats->rx_packets = stats[EF10_STAT_rx_packets]; | |
1061 | core_stats->tx_packets = stats[EF10_STAT_tx_packets]; | |
1062 | core_stats->rx_bytes = stats[EF10_STAT_rx_bytes]; | |
1063 | core_stats->tx_bytes = stats[EF10_STAT_tx_bytes]; | |
e4d112e4 EC |
1064 | core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] + |
1065 | stats[GENERIC_STAT_rx_nodesc_trunc] + | |
1066 | stats[GENERIC_STAT_rx_noskb_drops]; | |
8127d661 BH |
1067 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
1068 | core_stats->rx_length_errors = | |
1069 | stats[EF10_STAT_rx_gtjumbo] + | |
1070 | stats[EF10_STAT_rx_length_error]; | |
1071 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; | |
1072 | core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error]; | |
1073 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; | |
1074 | core_stats->rx_errors = (core_stats->rx_length_errors + | |
1075 | core_stats->rx_crc_errors + | |
1076 | core_stats->rx_frame_errors); | |
1077 | } | |
1078 | ||
1079 | return stats_count; | |
1080 | } | |
1081 | ||
1082 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) | |
1083 | { | |
1084 | struct efx_nic *efx = channel->efx; | |
1085 | unsigned int mode, value; | |
1086 | efx_dword_t timer_cmd; | |
1087 | ||
1088 | if (channel->irq_moderation) { | |
1089 | mode = 3; | |
1090 | value = channel->irq_moderation - 1; | |
1091 | } else { | |
1092 | mode = 0; | |
1093 | value = 0; | |
1094 | } | |
1095 | ||
1096 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
1097 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, | |
1098 | EFE_DD_EVQ_IND_TIMER_FLAGS, | |
1099 | ERF_DD_EVQ_IND_TIMER_MODE, mode, | |
1100 | ERF_DD_EVQ_IND_TIMER_VAL, value); | |
1101 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, | |
1102 | channel->channel); | |
1103 | } else { | |
1104 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, | |
1105 | ERF_DZ_TC_TIMER_VAL, value); | |
1106 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, | |
1107 | channel->channel); | |
1108 | } | |
1109 | } | |
1110 | ||
02246a7f SS |
1111 | static void efx_ef10_get_wol_vf(struct efx_nic *efx, |
1112 | struct ethtool_wolinfo *wol) {} | |
1113 | ||
1114 | static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type) | |
1115 | { | |
1116 | return -EOPNOTSUPP; | |
1117 | } | |
1118 | ||
8127d661 BH |
1119 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
1120 | { | |
1121 | wol->supported = 0; | |
1122 | wol->wolopts = 0; | |
1123 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
1124 | } | |
1125 | ||
1126 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) | |
1127 | { | |
1128 | if (type != 0) | |
1129 | return -EINVAL; | |
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | static void efx_ef10_mcdi_request(struct efx_nic *efx, | |
1134 | const efx_dword_t *hdr, size_t hdr_len, | |
1135 | const efx_dword_t *sdu, size_t sdu_len) | |
1136 | { | |
1137 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1138 | u8 *pdu = nic_data->mcdi_buf.addr; | |
1139 | ||
1140 | memcpy(pdu, hdr, hdr_len); | |
1141 | memcpy(pdu + hdr_len, sdu, sdu_len); | |
1142 | wmb(); | |
1143 | ||
1144 | /* The hardware provides 'low' and 'high' (doorbell) registers | |
1145 | * for passing the 64-bit address of an MCDI request to | |
1146 | * firmware. However the dwords are swapped by firmware. The | |
1147 | * least significant bits of the doorbell are then 0 for all | |
1148 | * MCDI requests due to alignment. | |
1149 | */ | |
1150 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), | |
1151 | ER_DZ_MC_DB_LWRD); | |
1152 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), | |
1153 | ER_DZ_MC_DB_HWRD); | |
1154 | } | |
1155 | ||
1156 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) | |
1157 | { | |
1158 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1159 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; | |
1160 | ||
1161 | rmb(); | |
1162 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); | |
1163 | } | |
1164 | ||
1165 | static void | |
1166 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, | |
1167 | size_t offset, size_t outlen) | |
1168 | { | |
1169 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1170 | const u8 *pdu = nic_data->mcdi_buf.addr; | |
1171 | ||
1172 | memcpy(outbuf, pdu + offset, outlen); | |
1173 | } | |
1174 | ||
1175 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) | |
1176 | { | |
1177 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1178 | int rc; | |
1179 | ||
1180 | rc = efx_ef10_get_warm_boot_count(efx); | |
1181 | if (rc < 0) { | |
1182 | /* The firmware is presumably in the process of | |
1183 | * rebooting. However, we are supposed to report each | |
1184 | * reboot just once, so we must only do that once we | |
1185 | * can read and store the updated warm boot count. | |
1186 | */ | |
1187 | return 0; | |
1188 | } | |
1189 | ||
1190 | if (rc == nic_data->warm_boot_count) | |
1191 | return 0; | |
1192 | ||
1193 | nic_data->warm_boot_count = rc; | |
1194 | ||
1195 | /* All our allocations have been reset */ | |
3e336261 | 1196 | efx_ef10_reset_mc_allocations(efx); |
8127d661 | 1197 | |
6d8aaaf6 DP |
1198 | /* Driver-created vswitches and vports must be re-created */ |
1199 | nic_data->must_probe_vswitching = true; | |
1200 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; | |
1201 | ||
a915ccc9 BH |
1202 | /* The datapath firmware might have been changed */ |
1203 | nic_data->must_check_datapath_caps = true; | |
1204 | ||
869070c5 BH |
1205 | /* MAC statistics have been cleared on the NIC; clear the local |
1206 | * statistic that we update with efx_update_diff_stat(). | |
1207 | */ | |
1208 | nic_data->stats[EF10_STAT_rx_bad_bytes] = 0; | |
1209 | ||
8127d661 BH |
1210 | return -EIO; |
1211 | } | |
1212 | ||
1213 | /* Handle an MSI interrupt | |
1214 | * | |
1215 | * Handle an MSI hardware interrupt. This routine schedules event | |
1216 | * queue processing. No interrupt acknowledgement cycle is necessary. | |
1217 | * Also, we never need to check that the interrupt is for us, since | |
1218 | * MSI interrupts cannot be shared. | |
1219 | */ | |
1220 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) | |
1221 | { | |
1222 | struct efx_msi_context *context = dev_id; | |
1223 | struct efx_nic *efx = context->efx; | |
1224 | ||
1225 | netif_vdbg(efx, intr, efx->net_dev, | |
1226 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); | |
1227 | ||
1228 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { | |
1229 | /* Note test interrupts */ | |
1230 | if (context->index == efx->irq_level) | |
1231 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1232 | ||
1233 | /* Schedule processing of the channel */ | |
1234 | efx_schedule_channel_irq(efx->channel[context->index]); | |
1235 | } | |
1236 | ||
1237 | return IRQ_HANDLED; | |
1238 | } | |
1239 | ||
1240 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) | |
1241 | { | |
1242 | struct efx_nic *efx = dev_id; | |
1243 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); | |
1244 | struct efx_channel *channel; | |
1245 | efx_dword_t reg; | |
1246 | u32 queues; | |
1247 | ||
1248 | /* Read the ISR which also ACKs the interrupts */ | |
1249 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); | |
1250 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); | |
1251 | ||
1252 | if (queues == 0) | |
1253 | return IRQ_NONE; | |
1254 | ||
1255 | if (likely(soft_enabled)) { | |
1256 | /* Note test interrupts */ | |
1257 | if (queues & (1U << efx->irq_level)) | |
1258 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1259 | ||
1260 | efx_for_each_channel(channel, efx) { | |
1261 | if (queues & 1) | |
1262 | efx_schedule_channel_irq(channel); | |
1263 | queues >>= 1; | |
1264 | } | |
1265 | } | |
1266 | ||
1267 | netif_vdbg(efx, intr, efx->net_dev, | |
1268 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", | |
1269 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); | |
1270 | ||
1271 | return IRQ_HANDLED; | |
1272 | } | |
1273 | ||
1274 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) | |
1275 | { | |
1276 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); | |
1277 | ||
1278 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); | |
1279 | ||
1280 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); | |
1281 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, | |
1282 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
1283 | } | |
1284 | ||
1285 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) | |
1286 | { | |
1287 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, | |
1288 | (tx_queue->ptr_mask + 1) * | |
1289 | sizeof(efx_qword_t), | |
1290 | GFP_KERNEL); | |
1291 | } | |
1292 | ||
1293 | /* This writes to the TX_DESC_WPTR and also pushes data */ | |
1294 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, | |
1295 | const efx_qword_t *txd) | |
1296 | { | |
1297 | unsigned int write_ptr; | |
1298 | efx_oword_t reg; | |
1299 | ||
1300 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1301 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); | |
1302 | reg.qword[0] = *txd; | |
1303 | efx_writeo_page(tx_queue->efx, ®, | |
1304 | ER_DZ_TX_DESC_UPD, tx_queue->queue); | |
1305 | } | |
1306 | ||
1307 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) | |
1308 | { | |
1309 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1310 | EFX_BUF_SIZE)); | |
1311 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_TXQ_OUT_LEN); | |
1312 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; | |
1313 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; | |
1314 | struct efx_channel *channel = tx_queue->channel; | |
1315 | struct efx_nic *efx = tx_queue->efx; | |
45b2449e | 1316 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
1317 | size_t inlen, outlen; |
1318 | dma_addr_t dma_addr; | |
1319 | efx_qword_t *txd; | |
1320 | int rc; | |
1321 | int i; | |
1322 | ||
1323 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); | |
1324 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); | |
1325 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); | |
1326 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); | |
1327 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, | |
1328 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, | |
1329 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); | |
1330 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); | |
45b2449e | 1331 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
1332 | |
1333 | dma_addr = tx_queue->txd.buf.dma_addr; | |
1334 | ||
1335 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", | |
1336 | tx_queue->queue, entries, (u64)dma_addr); | |
1337 | ||
1338 | for (i = 0; i < entries; ++i) { | |
1339 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); | |
1340 | dma_addr += EFX_BUF_SIZE; | |
1341 | } | |
1342 | ||
1343 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); | |
1344 | ||
1345 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, | |
1346 | outbuf, sizeof(outbuf), &outlen); | |
1347 | if (rc) | |
1348 | goto fail; | |
1349 | ||
1350 | /* A previous user of this TX queue might have set us up the | |
1351 | * bomb by writing a descriptor to the TX push collector but | |
1352 | * not the doorbell. (Each collector belongs to a port, not a | |
1353 | * queue or function, so cannot easily be reset.) We must | |
1354 | * attempt to push a no-op descriptor in its place. | |
1355 | */ | |
1356 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; | |
1357 | tx_queue->insert_count = 1; | |
1358 | txd = efx_tx_desc(tx_queue, 0); | |
1359 | EFX_POPULATE_QWORD_4(*txd, | |
1360 | ESF_DZ_TX_DESC_IS_OPT, true, | |
1361 | ESF_DZ_TX_OPTION_TYPE, | |
1362 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, | |
1363 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, | |
1364 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); | |
1365 | tx_queue->write_count = 1; | |
1366 | wmb(); | |
1367 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1368 | ||
1369 | return; | |
1370 | ||
1371 | fail: | |
48ce5634 BH |
1372 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
1373 | tx_queue->queue); | |
8127d661 BH |
1374 | } |
1375 | ||
1376 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) | |
1377 | { | |
1378 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); | |
1379 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_TXQ_OUT_LEN); | |
1380 | struct efx_nic *efx = tx_queue->efx; | |
1381 | size_t outlen; | |
1382 | int rc; | |
1383 | ||
1384 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, | |
1385 | tx_queue->queue); | |
1386 | ||
1e0b8120 | 1387 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
1388 | outbuf, sizeof(outbuf), &outlen); |
1389 | ||
1390 | if (rc && rc != -EALREADY) | |
1391 | goto fail; | |
1392 | ||
1393 | return; | |
1394 | ||
1395 | fail: | |
1e0b8120 EC |
1396 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
1397 | outbuf, outlen, rc); | |
8127d661 BH |
1398 | } |
1399 | ||
1400 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) | |
1401 | { | |
1402 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); | |
1403 | } | |
1404 | ||
1405 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | |
1406 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) | |
1407 | { | |
1408 | unsigned int write_ptr; | |
1409 | efx_dword_t reg; | |
1410 | ||
1411 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1412 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); | |
1413 | efx_writed_page(tx_queue->efx, ®, | |
1414 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); | |
1415 | } | |
1416 | ||
1417 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) | |
1418 | { | |
1419 | unsigned int old_write_count = tx_queue->write_count; | |
1420 | struct efx_tx_buffer *buffer; | |
1421 | unsigned int write_ptr; | |
1422 | efx_qword_t *txd; | |
1423 | ||
1424 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); | |
1425 | ||
1426 | do { | |
1427 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1428 | buffer = &tx_queue->buffer[write_ptr]; | |
1429 | txd = efx_tx_desc(tx_queue, write_ptr); | |
1430 | ++tx_queue->write_count; | |
1431 | ||
1432 | /* Create TX descriptor ring entry */ | |
1433 | if (buffer->flags & EFX_TX_BUF_OPTION) { | |
1434 | *txd = buffer->option; | |
1435 | } else { | |
1436 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); | |
1437 | EFX_POPULATE_QWORD_3( | |
1438 | *txd, | |
1439 | ESF_DZ_TX_KER_CONT, | |
1440 | buffer->flags & EFX_TX_BUF_CONT, | |
1441 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, | |
1442 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); | |
1443 | } | |
1444 | } while (tx_queue->write_count != tx_queue->insert_count); | |
1445 | ||
1446 | wmb(); /* Ensure descriptors are written before they are fetched */ | |
1447 | ||
1448 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { | |
1449 | txd = efx_tx_desc(tx_queue, | |
1450 | old_write_count & tx_queue->ptr_mask); | |
1451 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1452 | ++tx_queue->pushes; | |
1453 | } else { | |
1454 | efx_ef10_notify_tx_desc(tx_queue); | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context) | |
1459 | { | |
1460 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); | |
1461 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); | |
45b2449e | 1462 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
1463 | size_t outlen; |
1464 | int rc; | |
1465 | ||
1466 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, | |
45b2449e | 1467 | nic_data->vport_id); |
8127d661 BH |
1468 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, |
1469 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE); | |
1470 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, | |
1471 | EFX_MAX_CHANNELS); | |
1472 | ||
1473 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), | |
1474 | outbuf, sizeof(outbuf), &outlen); | |
1475 | if (rc != 0) | |
1476 | return rc; | |
1477 | ||
1478 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) | |
1479 | return -EIO; | |
1480 | ||
1481 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); | |
1482 | ||
1483 | return 0; | |
1484 | } | |
1485 | ||
1486 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) | |
1487 | { | |
1488 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); | |
1489 | int rc; | |
1490 | ||
1491 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, | |
1492 | context); | |
1493 | ||
1494 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), | |
1495 | NULL, 0, NULL); | |
1496 | WARN_ON(rc != 0); | |
1497 | } | |
1498 | ||
1499 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context) | |
1500 | { | |
1501 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); | |
1502 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); | |
1503 | int i, rc; | |
1504 | ||
1505 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, | |
1506 | context); | |
1507 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != | |
1508 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); | |
1509 | ||
1510 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) | |
1511 | MCDI_PTR(tablebuf, | |
1512 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = | |
1513 | (u8) efx->rx_indir_table[i]; | |
1514 | ||
1515 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, | |
1516 | sizeof(tablebuf), NULL, 0, NULL); | |
1517 | if (rc != 0) | |
1518 | return rc; | |
1519 | ||
1520 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, | |
1521 | context); | |
1522 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != | |
1523 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); | |
1524 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) | |
1525 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = | |
1526 | efx->rx_hash_key[i]; | |
1527 | ||
1528 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, | |
1529 | sizeof(keybuf), NULL, 0, NULL); | |
1530 | } | |
1531 | ||
1532 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) | |
1533 | { | |
1534 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1535 | ||
1536 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1537 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); | |
1538 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1539 | } | |
1540 | ||
d43050c0 | 1541 | static void efx_ef10_rx_push_rss_config(struct efx_nic *efx) |
8127d661 BH |
1542 | { |
1543 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1544 | int rc; | |
1545 | ||
d43050c0 | 1546 | netif_dbg(efx, drv, efx->net_dev, "pushing RSS config\n"); |
8127d661 BH |
1547 | |
1548 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID) { | |
1549 | rc = efx_ef10_alloc_rss_context(efx, &nic_data->rx_rss_context); | |
1550 | if (rc != 0) | |
1551 | goto fail; | |
1552 | } | |
1553 | ||
1554 | rc = efx_ef10_populate_rss_table(efx, nic_data->rx_rss_context); | |
1555 | if (rc != 0) | |
1556 | goto fail; | |
1557 | ||
1558 | return; | |
1559 | ||
1560 | fail: | |
1561 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1562 | } | |
1563 | ||
1564 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) | |
1565 | { | |
1566 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, | |
1567 | (rx_queue->ptr_mask + 1) * | |
1568 | sizeof(efx_qword_t), | |
1569 | GFP_KERNEL); | |
1570 | } | |
1571 | ||
1572 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) | |
1573 | { | |
1574 | MCDI_DECLARE_BUF(inbuf, | |
1575 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1576 | EFX_BUF_SIZE)); | |
1577 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_RXQ_OUT_LEN); | |
1578 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
1579 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; | |
1580 | struct efx_nic *efx = rx_queue->efx; | |
45b2449e | 1581 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
1582 | size_t inlen, outlen; |
1583 | dma_addr_t dma_addr; | |
1584 | int rc; | |
1585 | int i; | |
1586 | ||
1587 | rx_queue->scatter_n = 0; | |
1588 | rx_queue->scatter_len = 0; | |
1589 | ||
1590 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); | |
1591 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); | |
1592 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); | |
1593 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, | |
1594 | efx_rx_queue_index(rx_queue)); | |
bd9a265d JC |
1595 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
1596 | INIT_RXQ_IN_FLAG_PREFIX, 1, | |
1597 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); | |
8127d661 | 1598 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
45b2449e | 1599 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
1600 | |
1601 | dma_addr = rx_queue->rxd.buf.dma_addr; | |
1602 | ||
1603 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", | |
1604 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); | |
1605 | ||
1606 | for (i = 0; i < entries; ++i) { | |
1607 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); | |
1608 | dma_addr += EFX_BUF_SIZE; | |
1609 | } | |
1610 | ||
1611 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); | |
1612 | ||
1613 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, | |
1614 | outbuf, sizeof(outbuf), &outlen); | |
48ce5634 BH |
1615 | if (rc) |
1616 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", | |
1617 | efx_rx_queue_index(rx_queue)); | |
8127d661 BH |
1618 | } |
1619 | ||
1620 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) | |
1621 | { | |
1622 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); | |
1623 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_RXQ_OUT_LEN); | |
1624 | struct efx_nic *efx = rx_queue->efx; | |
1625 | size_t outlen; | |
1626 | int rc; | |
1627 | ||
1628 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, | |
1629 | efx_rx_queue_index(rx_queue)); | |
1630 | ||
1e0b8120 | 1631 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
1632 | outbuf, sizeof(outbuf), &outlen); |
1633 | ||
1634 | if (rc && rc != -EALREADY) | |
1635 | goto fail; | |
1636 | ||
1637 | return; | |
1638 | ||
1639 | fail: | |
1e0b8120 EC |
1640 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
1641 | outbuf, outlen, rc); | |
8127d661 BH |
1642 | } |
1643 | ||
1644 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) | |
1645 | { | |
1646 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); | |
1647 | } | |
1648 | ||
1649 | /* This creates an entry in the RX descriptor queue */ | |
1650 | static inline void | |
1651 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | |
1652 | { | |
1653 | struct efx_rx_buffer *rx_buf; | |
1654 | efx_qword_t *rxd; | |
1655 | ||
1656 | rxd = efx_rx_desc(rx_queue, index); | |
1657 | rx_buf = efx_rx_buffer(rx_queue, index); | |
1658 | EFX_POPULATE_QWORD_2(*rxd, | |
1659 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, | |
1660 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); | |
1661 | } | |
1662 | ||
1663 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) | |
1664 | { | |
1665 | struct efx_nic *efx = rx_queue->efx; | |
1666 | unsigned int write_count; | |
1667 | efx_dword_t reg; | |
1668 | ||
1669 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ | |
1670 | write_count = rx_queue->added_count & ~7; | |
1671 | if (rx_queue->notified_count == write_count) | |
1672 | return; | |
1673 | ||
1674 | do | |
1675 | efx_ef10_build_rx_desc( | |
1676 | rx_queue, | |
1677 | rx_queue->notified_count & rx_queue->ptr_mask); | |
1678 | while (++rx_queue->notified_count != write_count); | |
1679 | ||
1680 | wmb(); | |
1681 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, | |
1682 | write_count & rx_queue->ptr_mask); | |
1683 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, | |
1684 | efx_rx_queue_index(rx_queue)); | |
1685 | } | |
1686 | ||
1687 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; | |
1688 | ||
1689 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) | |
1690 | { | |
1691 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
1692 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
1693 | efx_qword_t event; | |
1694 | ||
1695 | EFX_POPULATE_QWORD_2(event, | |
1696 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
1697 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); | |
1698 | ||
1699 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
1700 | ||
1701 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
1702 | * already swapped the data to little-endian order. | |
1703 | */ | |
1704 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
1705 | sizeof(efx_qword_t)); | |
1706 | ||
1707 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, | |
1708 | inbuf, sizeof(inbuf), 0, | |
1709 | efx_ef10_rx_defer_refill_complete, 0); | |
1710 | } | |
1711 | ||
1712 | static void | |
1713 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, | |
1714 | int rc, efx_dword_t *outbuf, | |
1715 | size_t outlen_actual) | |
1716 | { | |
1717 | /* nothing to do */ | |
1718 | } | |
1719 | ||
1720 | static int efx_ef10_ev_probe(struct efx_channel *channel) | |
1721 | { | |
1722 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, | |
1723 | (channel->eventq_mask + 1) * | |
1724 | sizeof(efx_qword_t), | |
1725 | GFP_KERNEL); | |
1726 | } | |
1727 | ||
1728 | static int efx_ef10_ev_init(struct efx_channel *channel) | |
1729 | { | |
1730 | MCDI_DECLARE_BUF(inbuf, | |
1731 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / | |
1732 | EFX_BUF_SIZE)); | |
1733 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); | |
1734 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; | |
1735 | struct efx_nic *efx = channel->efx; | |
1736 | struct efx_ef10_nic_data *nic_data; | |
1737 | bool supports_rx_merge; | |
1738 | size_t inlen, outlen; | |
1739 | dma_addr_t dma_addr; | |
1740 | int rc; | |
1741 | int i; | |
1742 | ||
1743 | nic_data = efx->nic_data; | |
1744 | supports_rx_merge = | |
1745 | !!(nic_data->datapath_caps & | |
1746 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); | |
1747 | ||
1748 | /* Fill event queue with all ones (i.e. empty events) */ | |
1749 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); | |
1750 | ||
1751 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); | |
1752 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); | |
1753 | /* INIT_EVQ expects index in vector table, not absolute */ | |
1754 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); | |
1755 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, | |
1756 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, | |
1757 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, | |
1758 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, | |
1759 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); | |
1760 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, | |
1761 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); | |
1762 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); | |
1763 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); | |
1764 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, | |
1765 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); | |
1766 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); | |
1767 | ||
1768 | dma_addr = channel->eventq.buf.dma_addr; | |
1769 | for (i = 0; i < entries; ++i) { | |
1770 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); | |
1771 | dma_addr += EFX_BUF_SIZE; | |
1772 | } | |
1773 | ||
1774 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); | |
1775 | ||
1776 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, | |
1777 | outbuf, sizeof(outbuf), &outlen); | |
8127d661 | 1778 | /* IRQ return is ignored */ |
8127d661 BH |
1779 | return rc; |
1780 | } | |
1781 | ||
1782 | static void efx_ef10_ev_fini(struct efx_channel *channel) | |
1783 | { | |
1784 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); | |
1785 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_EVQ_OUT_LEN); | |
1786 | struct efx_nic *efx = channel->efx; | |
1787 | size_t outlen; | |
1788 | int rc; | |
1789 | ||
1790 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); | |
1791 | ||
1e0b8120 | 1792 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
8127d661 BH |
1793 | outbuf, sizeof(outbuf), &outlen); |
1794 | ||
1795 | if (rc && rc != -EALREADY) | |
1796 | goto fail; | |
1797 | ||
1798 | return; | |
1799 | ||
1800 | fail: | |
1e0b8120 EC |
1801 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
1802 | outbuf, outlen, rc); | |
8127d661 BH |
1803 | } |
1804 | ||
1805 | static void efx_ef10_ev_remove(struct efx_channel *channel) | |
1806 | { | |
1807 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); | |
1808 | } | |
1809 | ||
1810 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, | |
1811 | unsigned int rx_queue_label) | |
1812 | { | |
1813 | struct efx_nic *efx = rx_queue->efx; | |
1814 | ||
1815 | netif_info(efx, hw, efx->net_dev, | |
1816 | "rx event arrived on queue %d labeled as queue %u\n", | |
1817 | efx_rx_queue_index(rx_queue), rx_queue_label); | |
1818 | ||
1819 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
1820 | } | |
1821 | ||
1822 | static void | |
1823 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, | |
1824 | unsigned int actual, unsigned int expected) | |
1825 | { | |
1826 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; | |
1827 | struct efx_nic *efx = rx_queue->efx; | |
1828 | ||
1829 | netif_info(efx, hw, efx->net_dev, | |
1830 | "dropped %d events (index=%d expected=%d)\n", | |
1831 | dropped, actual, expected); | |
1832 | ||
1833 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
1834 | } | |
1835 | ||
1836 | /* partially received RX was aborted. clean up. */ | |
1837 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) | |
1838 | { | |
1839 | unsigned int rx_desc_ptr; | |
1840 | ||
8127d661 BH |
1841 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
1842 | "scattered RX aborted (dropping %u buffers)\n", | |
1843 | rx_queue->scatter_n); | |
1844 | ||
1845 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; | |
1846 | ||
1847 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, | |
1848 | 0, EFX_RX_PKT_DISCARD); | |
1849 | ||
1850 | rx_queue->removed_count += rx_queue->scatter_n; | |
1851 | rx_queue->scatter_n = 0; | |
1852 | rx_queue->scatter_len = 0; | |
1853 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; | |
1854 | } | |
1855 | ||
1856 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, | |
1857 | const efx_qword_t *event) | |
1858 | { | |
1859 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; | |
1860 | unsigned int n_descs, n_packets, i; | |
1861 | struct efx_nic *efx = channel->efx; | |
1862 | struct efx_rx_queue *rx_queue; | |
1863 | bool rx_cont; | |
1864 | u16 flags = 0; | |
1865 | ||
1866 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
1867 | return 0; | |
1868 | ||
1869 | /* Basic packet information */ | |
1870 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); | |
1871 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); | |
1872 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); | |
1873 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); | |
1874 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); | |
1875 | ||
48ce5634 BH |
1876 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
1877 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" | |
1878 | EFX_QWORD_FMT "\n", | |
1879 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
1880 | |
1881 | rx_queue = efx_channel_get_rx_queue(channel); | |
1882 | ||
1883 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) | |
1884 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); | |
1885 | ||
1886 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & | |
1887 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
1888 | ||
1889 | if (n_descs != rx_queue->scatter_n + 1) { | |
92a04168 BH |
1890 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
1891 | ||
8127d661 BH |
1892 | /* detect rx abort */ |
1893 | if (unlikely(n_descs == rx_queue->scatter_n)) { | |
48ce5634 BH |
1894 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
1895 | netdev_WARN(efx->net_dev, | |
1896 | "invalid RX abort: scatter_n=%u event=" | |
1897 | EFX_QWORD_FMT "\n", | |
1898 | rx_queue->scatter_n, | |
1899 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
1900 | efx_ef10_handle_rx_abort(rx_queue); |
1901 | return 0; | |
1902 | } | |
1903 | ||
92a04168 BH |
1904 | /* Check that RX completion merging is valid, i.e. |
1905 | * the current firmware supports it and this is a | |
1906 | * non-scattered packet. | |
1907 | */ | |
1908 | if (!(nic_data->datapath_caps & | |
1909 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || | |
1910 | rx_queue->scatter_n != 0 || rx_cont) { | |
8127d661 BH |
1911 | efx_ef10_handle_rx_bad_lbits( |
1912 | rx_queue, next_ptr_lbits, | |
1913 | (rx_queue->removed_count + | |
1914 | rx_queue->scatter_n + 1) & | |
1915 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
1916 | return 0; | |
1917 | } | |
1918 | ||
1919 | /* Merged completion for multiple non-scattered packets */ | |
1920 | rx_queue->scatter_n = 1; | |
1921 | rx_queue->scatter_len = 0; | |
1922 | n_packets = n_descs; | |
1923 | ++channel->n_rx_merge_events; | |
1924 | channel->n_rx_merge_packets += n_packets; | |
1925 | flags |= EFX_RX_PKT_PREFIX_LEN; | |
1926 | } else { | |
1927 | ++rx_queue->scatter_n; | |
1928 | rx_queue->scatter_len += rx_bytes; | |
1929 | if (rx_cont) | |
1930 | return 0; | |
1931 | n_packets = 1; | |
1932 | } | |
1933 | ||
1934 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) | |
1935 | flags |= EFX_RX_PKT_DISCARD; | |
1936 | ||
1937 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { | |
1938 | channel->n_rx_ip_hdr_chksum_err += n_packets; | |
1939 | } else if (unlikely(EFX_QWORD_FIELD(*event, | |
1940 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { | |
1941 | channel->n_rx_tcp_udp_chksum_err += n_packets; | |
1942 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || | |
1943 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { | |
1944 | flags |= EFX_RX_PKT_CSUMMED; | |
1945 | } | |
1946 | ||
1947 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) | |
1948 | flags |= EFX_RX_PKT_TCP; | |
1949 | ||
1950 | channel->irq_mod_score += 2 * n_packets; | |
1951 | ||
1952 | /* Handle received packet(s) */ | |
1953 | for (i = 0; i < n_packets; i++) { | |
1954 | efx_rx_packet(rx_queue, | |
1955 | rx_queue->removed_count & rx_queue->ptr_mask, | |
1956 | rx_queue->scatter_n, rx_queue->scatter_len, | |
1957 | flags); | |
1958 | rx_queue->removed_count += rx_queue->scatter_n; | |
1959 | } | |
1960 | ||
1961 | rx_queue->scatter_n = 0; | |
1962 | rx_queue->scatter_len = 0; | |
1963 | ||
1964 | return n_packets; | |
1965 | } | |
1966 | ||
1967 | static int | |
1968 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) | |
1969 | { | |
1970 | struct efx_nic *efx = channel->efx; | |
1971 | struct efx_tx_queue *tx_queue; | |
1972 | unsigned int tx_ev_desc_ptr; | |
1973 | unsigned int tx_ev_q_label; | |
1974 | int tx_descs = 0; | |
1975 | ||
1976 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
1977 | return 0; | |
1978 | ||
1979 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) | |
1980 | return 0; | |
1981 | ||
1982 | /* Transmit completion */ | |
1983 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); | |
1984 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); | |
1985 | tx_queue = efx_channel_get_tx_queue(channel, | |
1986 | tx_ev_q_label % EFX_TXQ_TYPES); | |
1987 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & | |
1988 | tx_queue->ptr_mask); | |
1989 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); | |
1990 | ||
1991 | return tx_descs; | |
1992 | } | |
1993 | ||
1994 | static void | |
1995 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) | |
1996 | { | |
1997 | struct efx_nic *efx = channel->efx; | |
1998 | int subcode; | |
1999 | ||
2000 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); | |
2001 | ||
2002 | switch (subcode) { | |
2003 | case ESE_DZ_DRV_TIMER_EV: | |
2004 | case ESE_DZ_DRV_WAKE_UP_EV: | |
2005 | break; | |
2006 | case ESE_DZ_DRV_START_UP_EV: | |
2007 | /* event queue init complete. ok. */ | |
2008 | break; | |
2009 | default: | |
2010 | netif_err(efx, hw, efx->net_dev, | |
2011 | "channel %d unknown driver event type %d" | |
2012 | " (data " EFX_QWORD_FMT ")\n", | |
2013 | channel->channel, subcode, | |
2014 | EFX_QWORD_VAL(*event)); | |
2015 | ||
2016 | } | |
2017 | } | |
2018 | ||
2019 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, | |
2020 | efx_qword_t *event) | |
2021 | { | |
2022 | struct efx_nic *efx = channel->efx; | |
2023 | u32 subcode; | |
2024 | ||
2025 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); | |
2026 | ||
2027 | switch (subcode) { | |
2028 | case EFX_EF10_TEST: | |
2029 | channel->event_test_cpu = raw_smp_processor_id(); | |
2030 | break; | |
2031 | case EFX_EF10_REFILL: | |
2032 | /* The queue must be empty, so we won't receive any rx | |
2033 | * events, so efx_process_channel() won't refill the | |
2034 | * queue. Refill it here | |
2035 | */ | |
cce28794 | 2036 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
8127d661 BH |
2037 | break; |
2038 | default: | |
2039 | netif_err(efx, hw, efx->net_dev, | |
2040 | "channel %d unknown driver event type %u" | |
2041 | " (data " EFX_QWORD_FMT ")\n", | |
2042 | channel->channel, (unsigned) subcode, | |
2043 | EFX_QWORD_VAL(*event)); | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) | |
2048 | { | |
2049 | struct efx_nic *efx = channel->efx; | |
2050 | efx_qword_t event, *p_event; | |
2051 | unsigned int read_ptr; | |
2052 | int ev_code; | |
2053 | int tx_descs = 0; | |
2054 | int spent = 0; | |
2055 | ||
75363a46 EB |
2056 | if (quota <= 0) |
2057 | return spent; | |
2058 | ||
8127d661 BH |
2059 | read_ptr = channel->eventq_read_ptr; |
2060 | ||
2061 | for (;;) { | |
2062 | p_event = efx_event(channel, read_ptr); | |
2063 | event = *p_event; | |
2064 | ||
2065 | if (!efx_event_present(&event)) | |
2066 | break; | |
2067 | ||
2068 | EFX_SET_QWORD(*p_event); | |
2069 | ||
2070 | ++read_ptr; | |
2071 | ||
2072 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); | |
2073 | ||
2074 | netif_vdbg(efx, drv, efx->net_dev, | |
2075 | "processing event on %d " EFX_QWORD_FMT "\n", | |
2076 | channel->channel, EFX_QWORD_VAL(event)); | |
2077 | ||
2078 | switch (ev_code) { | |
2079 | case ESE_DZ_EV_CODE_MCDI_EV: | |
2080 | efx_mcdi_process_event(channel, &event); | |
2081 | break; | |
2082 | case ESE_DZ_EV_CODE_RX_EV: | |
2083 | spent += efx_ef10_handle_rx_event(channel, &event); | |
2084 | if (spent >= quota) { | |
2085 | /* XXX can we split a merged event to | |
2086 | * avoid going over-quota? | |
2087 | */ | |
2088 | spent = quota; | |
2089 | goto out; | |
2090 | } | |
2091 | break; | |
2092 | case ESE_DZ_EV_CODE_TX_EV: | |
2093 | tx_descs += efx_ef10_handle_tx_event(channel, &event); | |
2094 | if (tx_descs > efx->txq_entries) { | |
2095 | spent = quota; | |
2096 | goto out; | |
2097 | } else if (++spent == quota) { | |
2098 | goto out; | |
2099 | } | |
2100 | break; | |
2101 | case ESE_DZ_EV_CODE_DRIVER_EV: | |
2102 | efx_ef10_handle_driver_event(channel, &event); | |
2103 | if (++spent == quota) | |
2104 | goto out; | |
2105 | break; | |
2106 | case EFX_EF10_DRVGEN_EV: | |
2107 | efx_ef10_handle_driver_generated_event(channel, &event); | |
2108 | break; | |
2109 | default: | |
2110 | netif_err(efx, hw, efx->net_dev, | |
2111 | "channel %d unknown event type %d" | |
2112 | " (data " EFX_QWORD_FMT ")\n", | |
2113 | channel->channel, ev_code, | |
2114 | EFX_QWORD_VAL(event)); | |
2115 | } | |
2116 | } | |
2117 | ||
2118 | out: | |
2119 | channel->eventq_read_ptr = read_ptr; | |
2120 | return spent; | |
2121 | } | |
2122 | ||
2123 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) | |
2124 | { | |
2125 | struct efx_nic *efx = channel->efx; | |
2126 | efx_dword_t rptr; | |
2127 | ||
2128 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
2129 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < | |
2130 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2131 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > | |
2132 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2133 | ||
2134 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2135 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, | |
2136 | ERF_DD_EVQ_IND_RPTR, | |
2137 | (channel->eventq_read_ptr & | |
2138 | channel->eventq_mask) >> | |
2139 | ERF_DD_EVQ_IND_RPTR_WIDTH); | |
2140 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2141 | channel->channel); | |
2142 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2143 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, | |
2144 | ERF_DD_EVQ_IND_RPTR, | |
2145 | channel->eventq_read_ptr & | |
2146 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); | |
2147 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2148 | channel->channel); | |
2149 | } else { | |
2150 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, | |
2151 | channel->eventq_read_ptr & | |
2152 | channel->eventq_mask); | |
2153 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); | |
2154 | } | |
2155 | } | |
2156 | ||
2157 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) | |
2158 | { | |
2159 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
2160 | struct efx_nic *efx = channel->efx; | |
2161 | efx_qword_t event; | |
2162 | int rc; | |
2163 | ||
2164 | EFX_POPULATE_QWORD_2(event, | |
2165 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
2166 | ESF_DZ_EV_DATA, EFX_EF10_TEST); | |
2167 | ||
2168 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
2169 | ||
2170 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
2171 | * already swapped the data to little-endian order. | |
2172 | */ | |
2173 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
2174 | sizeof(efx_qword_t)); | |
2175 | ||
2176 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), | |
2177 | NULL, 0, NULL); | |
2178 | if (rc != 0) | |
2179 | goto fail; | |
2180 | ||
2181 | return; | |
2182 | ||
2183 | fail: | |
2184 | WARN_ON(true); | |
2185 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
2186 | } | |
2187 | ||
2188 | void efx_ef10_handle_drain_event(struct efx_nic *efx) | |
2189 | { | |
2190 | if (atomic_dec_and_test(&efx->active_queues)) | |
2191 | wake_up(&efx->flush_wq); | |
2192 | ||
2193 | WARN_ON(atomic_read(&efx->active_queues) < 0); | |
2194 | } | |
2195 | ||
2196 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) | |
2197 | { | |
2198 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2199 | struct efx_channel *channel; | |
2200 | struct efx_tx_queue *tx_queue; | |
2201 | struct efx_rx_queue *rx_queue; | |
2202 | int pending; | |
2203 | ||
2204 | /* If the MC has just rebooted, the TX/RX queues will have already been | |
2205 | * torn down, but efx->active_queues needs to be set to zero. | |
2206 | */ | |
2207 | if (nic_data->must_realloc_vis) { | |
2208 | atomic_set(&efx->active_queues, 0); | |
2209 | return 0; | |
2210 | } | |
2211 | ||
2212 | /* Do not attempt to write to the NIC during EEH recovery */ | |
2213 | if (efx->state != STATE_RECOVERY) { | |
2214 | efx_for_each_channel(channel, efx) { | |
2215 | efx_for_each_channel_rx_queue(rx_queue, channel) | |
2216 | efx_ef10_rx_fini(rx_queue); | |
2217 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
2218 | efx_ef10_tx_fini(tx_queue); | |
2219 | } | |
2220 | ||
2221 | wait_event_timeout(efx->flush_wq, | |
2222 | atomic_read(&efx->active_queues) == 0, | |
2223 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); | |
2224 | pending = atomic_read(&efx->active_queues); | |
2225 | if (pending) { | |
2226 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", | |
2227 | pending); | |
2228 | return -ETIMEDOUT; | |
2229 | } | |
2230 | } | |
2231 | ||
2232 | return 0; | |
2233 | } | |
2234 | ||
e283546c EC |
2235 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
2236 | { | |
2237 | atomic_set(&efx->active_queues, 0); | |
2238 | } | |
2239 | ||
8127d661 BH |
2240 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
2241 | const struct efx_filter_spec *right) | |
2242 | { | |
2243 | if ((left->match_flags ^ right->match_flags) | | |
2244 | ((left->flags ^ right->flags) & | |
2245 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) | |
2246 | return false; | |
2247 | ||
2248 | return memcmp(&left->outer_vid, &right->outer_vid, | |
2249 | sizeof(struct efx_filter_spec) - | |
2250 | offsetof(struct efx_filter_spec, outer_vid)) == 0; | |
2251 | } | |
2252 | ||
2253 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) | |
2254 | { | |
2255 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); | |
2256 | return jhash2((const u32 *)&spec->outer_vid, | |
2257 | (sizeof(struct efx_filter_spec) - | |
2258 | offsetof(struct efx_filter_spec, outer_vid)) / 4, | |
2259 | 0); | |
2260 | /* XXX should we randomise the initval? */ | |
2261 | } | |
2262 | ||
2263 | /* Decide whether a filter should be exclusive or else should allow | |
2264 | * delivery to additional recipients. Currently we decide that | |
2265 | * filters for specific local unicast MAC and IP addresses are | |
2266 | * exclusive. | |
2267 | */ | |
2268 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) | |
2269 | { | |
2270 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && | |
2271 | !is_multicast_ether_addr(spec->loc_mac)) | |
2272 | return true; | |
2273 | ||
2274 | if ((spec->match_flags & | |
2275 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == | |
2276 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { | |
2277 | if (spec->ether_type == htons(ETH_P_IP) && | |
2278 | !ipv4_is_multicast(spec->loc_host[0])) | |
2279 | return true; | |
2280 | if (spec->ether_type == htons(ETH_P_IPV6) && | |
2281 | ((const u8 *)spec->loc_host)[0] != 0xff) | |
2282 | return true; | |
2283 | } | |
2284 | ||
2285 | return false; | |
2286 | } | |
2287 | ||
2288 | static struct efx_filter_spec * | |
2289 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, | |
2290 | unsigned int filter_idx) | |
2291 | { | |
2292 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & | |
2293 | ~EFX_EF10_FILTER_FLAGS); | |
2294 | } | |
2295 | ||
2296 | static unsigned int | |
2297 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, | |
2298 | unsigned int filter_idx) | |
2299 | { | |
2300 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; | |
2301 | } | |
2302 | ||
2303 | static void | |
2304 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, | |
2305 | unsigned int filter_idx, | |
2306 | const struct efx_filter_spec *spec, | |
2307 | unsigned int flags) | |
2308 | { | |
2309 | table->entry[filter_idx].spec = (unsigned long)spec | flags; | |
2310 | } | |
2311 | ||
2312 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, | |
2313 | const struct efx_filter_spec *spec, | |
2314 | efx_dword_t *inbuf, u64 handle, | |
2315 | bool replacing) | |
2316 | { | |
2317 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2318 | ||
2319 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); | |
2320 | ||
2321 | if (replacing) { | |
2322 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2323 | MC_CMD_FILTER_OP_IN_OP_REPLACE); | |
2324 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); | |
2325 | } else { | |
2326 | u32 match_fields = 0; | |
2327 | ||
2328 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2329 | efx_ef10_filter_is_exclusive(spec) ? | |
2330 | MC_CMD_FILTER_OP_IN_OP_INSERT : | |
2331 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); | |
2332 | ||
2333 | /* Convert match flags and values. Unlike almost | |
2334 | * everything else in MCDI, these fields are in | |
2335 | * network byte order. | |
2336 | */ | |
2337 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) | |
2338 | match_fields |= | |
2339 | is_multicast_ether_addr(spec->loc_mac) ? | |
2340 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : | |
2341 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; | |
2342 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ | |
2343 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ | |
2344 | match_fields |= \ | |
2345 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
2346 | mcdi_field ## _LBN; \ | |
2347 | BUILD_BUG_ON( \ | |
2348 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ | |
2349 | sizeof(spec->gen_field)); \ | |
2350 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ | |
2351 | &spec->gen_field, sizeof(spec->gen_field)); \ | |
2352 | } | |
2353 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); | |
2354 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); | |
2355 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); | |
2356 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); | |
2357 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); | |
2358 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); | |
2359 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); | |
2360 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); | |
2361 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); | |
2362 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); | |
2363 | #undef COPY_FIELD | |
2364 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, | |
2365 | match_fields); | |
2366 | } | |
2367 | ||
45b2449e | 2368 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
2369 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
2370 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2371 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : | |
2372 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); | |
e3d36293 | 2373 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
8127d661 BH |
2374 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
2375 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); | |
a0bc3487 BH |
2376 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
2377 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2378 | 0 : spec->dmaq_id); | |
8127d661 BH |
2379 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
2380 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? | |
2381 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : | |
2382 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); | |
2383 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) | |
2384 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, | |
2385 | spec->rss_context != | |
2386 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? | |
2387 | spec->rss_context : nic_data->rx_rss_context); | |
2388 | } | |
2389 | ||
2390 | static int efx_ef10_filter_push(struct efx_nic *efx, | |
2391 | const struct efx_filter_spec *spec, | |
2392 | u64 *handle, bool replacing) | |
2393 | { | |
2394 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2395 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); | |
2396 | int rc; | |
2397 | ||
2398 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); | |
2399 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2400 | outbuf, sizeof(outbuf), NULL); | |
2401 | if (rc == 0) | |
2402 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
065e64c4 BH |
2403 | if (rc == -ENOSPC) |
2404 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ | |
8127d661 BH |
2405 | return rc; |
2406 | } | |
2407 | ||
2408 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, | |
2409 | enum efx_filter_match_flags match_flags) | |
2410 | { | |
2411 | unsigned int match_pri; | |
2412 | ||
2413 | for (match_pri = 0; | |
2414 | match_pri < table->rx_match_count; | |
2415 | match_pri++) | |
2416 | if (table->rx_match_flags[match_pri] == match_flags) | |
2417 | return match_pri; | |
2418 | ||
2419 | return -EPROTONOSUPPORT; | |
2420 | } | |
2421 | ||
2422 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, | |
2423 | struct efx_filter_spec *spec, | |
2424 | bool replace_equal) | |
2425 | { | |
2426 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2427 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2428 | struct efx_filter_spec *saved_spec; | |
2429 | unsigned int match_pri, hash; | |
2430 | unsigned int priv_flags; | |
2431 | bool replacing = false; | |
2432 | int ins_index = -1; | |
2433 | DEFINE_WAIT(wait); | |
2434 | bool is_mc_recip; | |
2435 | s32 rc; | |
2436 | ||
2437 | /* For now, only support RX filters */ | |
2438 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != | |
2439 | EFX_FILTER_FLAG_RX) | |
2440 | return -EINVAL; | |
2441 | ||
2442 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); | |
2443 | if (rc < 0) | |
2444 | return rc; | |
2445 | match_pri = rc; | |
2446 | ||
2447 | hash = efx_ef10_filter_hash(spec); | |
2448 | is_mc_recip = efx_filter_is_mc_recipient(spec); | |
2449 | if (is_mc_recip) | |
2450 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2451 | ||
2452 | /* Find any existing filters with the same match tuple or | |
2453 | * else a free slot to insert at. If any of them are busy, | |
2454 | * we have to wait and retry. | |
2455 | */ | |
2456 | for (;;) { | |
2457 | unsigned int depth = 1; | |
2458 | unsigned int i; | |
2459 | ||
2460 | spin_lock_bh(&efx->filter_lock); | |
2461 | ||
2462 | for (;;) { | |
2463 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2464 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2465 | ||
2466 | if (!saved_spec) { | |
2467 | if (ins_index < 0) | |
2468 | ins_index = i; | |
2469 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
2470 | if (table->entry[i].spec & | |
2471 | EFX_EF10_FILTER_FLAG_BUSY) | |
2472 | break; | |
2473 | if (spec->priority < saved_spec->priority && | |
7665d1ab | 2474 | spec->priority != EFX_FILTER_PRI_AUTO) { |
8127d661 BH |
2475 | rc = -EPERM; |
2476 | goto out_unlock; | |
2477 | } | |
2478 | if (!is_mc_recip) { | |
2479 | /* This is the only one */ | |
2480 | if (spec->priority == | |
2481 | saved_spec->priority && | |
2482 | !replace_equal) { | |
2483 | rc = -EEXIST; | |
2484 | goto out_unlock; | |
2485 | } | |
2486 | ins_index = i; | |
2487 | goto found; | |
2488 | } else if (spec->priority > | |
2489 | saved_spec->priority || | |
2490 | (spec->priority == | |
2491 | saved_spec->priority && | |
2492 | replace_equal)) { | |
2493 | if (ins_index < 0) | |
2494 | ins_index = i; | |
2495 | else | |
2496 | __set_bit(depth, mc_rem_map); | |
2497 | } | |
2498 | } | |
2499 | ||
2500 | /* Once we reach the maximum search depth, use | |
2501 | * the first suitable slot or return -EBUSY if | |
2502 | * there was none | |
2503 | */ | |
2504 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
2505 | if (ins_index < 0) { | |
2506 | rc = -EBUSY; | |
2507 | goto out_unlock; | |
2508 | } | |
2509 | goto found; | |
2510 | } | |
2511 | ||
2512 | ++depth; | |
2513 | } | |
2514 | ||
2515 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2516 | spin_unlock_bh(&efx->filter_lock); | |
2517 | schedule(); | |
2518 | } | |
2519 | ||
2520 | found: | |
2521 | /* Create a software table entry if necessary, and mark it | |
2522 | * busy. We might yet fail to insert, but any attempt to | |
2523 | * insert a conflicting filter while we're waiting for the | |
2524 | * firmware must find the busy entry. | |
2525 | */ | |
2526 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2527 | if (saved_spec) { | |
7665d1ab BH |
2528 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
2529 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { | |
8127d661 | 2530 | /* Just make sure it won't be removed */ |
7665d1ab BH |
2531 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
2532 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2533 | table->entry[ins_index].spec &= |
b59e6ef8 | 2534 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
8127d661 BH |
2535 | rc = ins_index; |
2536 | goto out_unlock; | |
2537 | } | |
2538 | replacing = true; | |
2539 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); | |
2540 | } else { | |
2541 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2542 | if (!saved_spec) { | |
2543 | rc = -ENOMEM; | |
2544 | goto out_unlock; | |
2545 | } | |
2546 | *saved_spec = *spec; | |
2547 | priv_flags = 0; | |
2548 | } | |
2549 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2550 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); | |
2551 | ||
2552 | /* Mark lower-priority multicast recipients busy prior to removal */ | |
2553 | if (is_mc_recip) { | |
2554 | unsigned int depth, i; | |
2555 | ||
2556 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2557 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2558 | if (test_bit(depth, mc_rem_map)) | |
2559 | table->entry[i].spec |= | |
2560 | EFX_EF10_FILTER_FLAG_BUSY; | |
2561 | } | |
2562 | } | |
2563 | ||
2564 | spin_unlock_bh(&efx->filter_lock); | |
2565 | ||
2566 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, | |
2567 | replacing); | |
2568 | ||
2569 | /* Finalise the software table entry */ | |
2570 | spin_lock_bh(&efx->filter_lock); | |
2571 | if (rc == 0) { | |
2572 | if (replacing) { | |
2573 | /* Update the fields that may differ */ | |
7665d1ab BH |
2574 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
2575 | saved_spec->flags |= | |
2576 | EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2577 | saved_spec->priority = spec->priority; |
7665d1ab | 2578 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
8127d661 BH |
2579 | saved_spec->flags |= spec->flags; |
2580 | saved_spec->rss_context = spec->rss_context; | |
2581 | saved_spec->dmaq_id = spec->dmaq_id; | |
2582 | } | |
2583 | } else if (!replacing) { | |
2584 | kfree(saved_spec); | |
2585 | saved_spec = NULL; | |
2586 | } | |
2587 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); | |
2588 | ||
2589 | /* Remove and finalise entries for lower-priority multicast | |
2590 | * recipients | |
2591 | */ | |
2592 | if (is_mc_recip) { | |
2593 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2594 | unsigned int depth, i; | |
2595 | ||
2596 | memset(inbuf, 0, sizeof(inbuf)); | |
2597 | ||
2598 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2599 | if (!test_bit(depth, mc_rem_map)) | |
2600 | continue; | |
2601 | ||
2602 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2603 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2604 | priv_flags = efx_ef10_filter_entry_flags(table, i); | |
2605 | ||
2606 | if (rc == 0) { | |
2607 | spin_unlock_bh(&efx->filter_lock); | |
2608 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2609 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2610 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2611 | table->entry[i].handle); | |
2612 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
2613 | inbuf, sizeof(inbuf), | |
2614 | NULL, 0, NULL); | |
2615 | spin_lock_bh(&efx->filter_lock); | |
2616 | } | |
2617 | ||
2618 | if (rc == 0) { | |
2619 | kfree(saved_spec); | |
2620 | saved_spec = NULL; | |
2621 | priv_flags = 0; | |
2622 | } else { | |
2623 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
2624 | } | |
2625 | efx_ef10_filter_set_entry(table, i, saved_spec, | |
2626 | priv_flags); | |
2627 | } | |
2628 | } | |
2629 | ||
2630 | /* If successful, return the inserted filter ID */ | |
2631 | if (rc == 0) | |
2632 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; | |
2633 | ||
2634 | wake_up_all(&table->waitq); | |
2635 | out_unlock: | |
2636 | spin_unlock_bh(&efx->filter_lock); | |
2637 | finish_wait(&table->waitq, &wait); | |
2638 | return rc; | |
2639 | } | |
2640 | ||
9fd8095d | 2641 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
8127d661 BH |
2642 | { |
2643 | /* no need to do anything here on EF10 */ | |
2644 | } | |
2645 | ||
2646 | /* Remove a filter. | |
b59e6ef8 BH |
2647 | * If !by_index, remove by ID |
2648 | * If by_index, remove by index | |
8127d661 BH |
2649 | * Filter ID may come from userland and must be range-checked. |
2650 | */ | |
2651 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, | |
fbd79120 | 2652 | unsigned int priority_mask, |
b59e6ef8 | 2653 | u32 filter_id, bool by_index) |
8127d661 BH |
2654 | { |
2655 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
2656 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2657 | MCDI_DECLARE_BUF(inbuf, | |
2658 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
2659 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
2660 | struct efx_filter_spec *spec; | |
2661 | DEFINE_WAIT(wait); | |
2662 | int rc; | |
2663 | ||
2664 | /* Find the software table entry and mark it busy. Don't | |
2665 | * remove it yet; any attempt to update while we're waiting | |
2666 | * for the firmware must find the busy entry. | |
2667 | */ | |
2668 | for (;;) { | |
2669 | spin_lock_bh(&efx->filter_lock); | |
2670 | if (!(table->entry[filter_idx].spec & | |
2671 | EFX_EF10_FILTER_FLAG_BUSY)) | |
2672 | break; | |
2673 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2674 | spin_unlock_bh(&efx->filter_lock); | |
2675 | schedule(); | |
2676 | } | |
7665d1ab | 2677 | |
8127d661 | 2678 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
7665d1ab | 2679 | if (!spec || |
b59e6ef8 | 2680 | (!by_index && |
8127d661 BH |
2681 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != |
2682 | filter_id / HUNT_FILTER_TBL_ROWS)) { | |
2683 | rc = -ENOENT; | |
2684 | goto out_unlock; | |
2685 | } | |
7665d1ab BH |
2686 | |
2687 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && | |
fbd79120 | 2688 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
7665d1ab BH |
2689 | /* Just remove flags */ |
2690 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; | |
b59e6ef8 | 2691 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
7665d1ab BH |
2692 | rc = 0; |
2693 | goto out_unlock; | |
2694 | } | |
2695 | ||
fbd79120 | 2696 | if (!(priority_mask & (1U << spec->priority))) { |
7665d1ab BH |
2697 | rc = -ENOENT; |
2698 | goto out_unlock; | |
2699 | } | |
2700 | ||
8127d661 BH |
2701 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
2702 | spin_unlock_bh(&efx->filter_lock); | |
2703 | ||
7665d1ab | 2704 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
b59e6ef8 | 2705 | /* Reset to an automatic filter */ |
8127d661 BH |
2706 | |
2707 | struct efx_filter_spec new_spec = *spec; | |
2708 | ||
7665d1ab | 2709 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
8127d661 | 2710 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
7665d1ab | 2711 | EFX_FILTER_FLAG_RX_RSS); |
8127d661 BH |
2712 | new_spec.dmaq_id = 0; |
2713 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; | |
2714 | rc = efx_ef10_filter_push(efx, &new_spec, | |
2715 | &table->entry[filter_idx].handle, | |
2716 | true); | |
2717 | ||
2718 | spin_lock_bh(&efx->filter_lock); | |
2719 | if (rc == 0) | |
2720 | *spec = new_spec; | |
2721 | } else { | |
2722 | /* Really remove the filter */ | |
2723 | ||
2724 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2725 | efx_ef10_filter_is_exclusive(spec) ? | |
2726 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
2727 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2728 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2729 | table->entry[filter_idx].handle); | |
2730 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
2731 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
2732 | ||
2733 | spin_lock_bh(&efx->filter_lock); | |
2734 | if (rc == 0) { | |
2735 | kfree(spec); | |
2736 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
2737 | } | |
2738 | } | |
7665d1ab | 2739 | |
8127d661 BH |
2740 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
2741 | wake_up_all(&table->waitq); | |
2742 | out_unlock: | |
2743 | spin_unlock_bh(&efx->filter_lock); | |
2744 | finish_wait(&table->waitq, &wait); | |
2745 | return rc; | |
2746 | } | |
2747 | ||
2748 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, | |
2749 | enum efx_filter_priority priority, | |
2750 | u32 filter_id) | |
2751 | { | |
fbd79120 BH |
2752 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
2753 | filter_id, false); | |
8127d661 BH |
2754 | } |
2755 | ||
2756 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, | |
2757 | enum efx_filter_priority priority, | |
2758 | u32 filter_id, struct efx_filter_spec *spec) | |
2759 | { | |
2760 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
2761 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2762 | const struct efx_filter_spec *saved_spec; | |
2763 | int rc; | |
2764 | ||
2765 | spin_lock_bh(&efx->filter_lock); | |
2766 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2767 | if (saved_spec && saved_spec->priority == priority && | |
2768 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == | |
2769 | filter_id / HUNT_FILTER_TBL_ROWS) { | |
2770 | *spec = *saved_spec; | |
2771 | rc = 0; | |
2772 | } else { | |
2773 | rc = -ENOENT; | |
2774 | } | |
2775 | spin_unlock_bh(&efx->filter_lock); | |
2776 | return rc; | |
2777 | } | |
2778 | ||
fbd79120 | 2779 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
8127d661 BH |
2780 | enum efx_filter_priority priority) |
2781 | { | |
fbd79120 BH |
2782 | unsigned int priority_mask; |
2783 | unsigned int i; | |
2784 | int rc; | |
2785 | ||
2786 | priority_mask = (((1U << (priority + 1)) - 1) & | |
2787 | ~(1U << EFX_FILTER_PRI_AUTO)); | |
2788 | ||
2789 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
2790 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, | |
2791 | i, true); | |
2792 | if (rc && rc != -ENOENT) | |
2793 | return rc; | |
2794 | } | |
2795 | ||
2796 | return 0; | |
8127d661 BH |
2797 | } |
2798 | ||
2799 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, | |
2800 | enum efx_filter_priority priority) | |
2801 | { | |
2802 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2803 | unsigned int filter_idx; | |
2804 | s32 count = 0; | |
2805 | ||
2806 | spin_lock_bh(&efx->filter_lock); | |
2807 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2808 | if (table->entry[filter_idx].spec && | |
2809 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == | |
2810 | priority) | |
2811 | ++count; | |
2812 | } | |
2813 | spin_unlock_bh(&efx->filter_lock); | |
2814 | return count; | |
2815 | } | |
2816 | ||
2817 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) | |
2818 | { | |
2819 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2820 | ||
2821 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; | |
2822 | } | |
2823 | ||
2824 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, | |
2825 | enum efx_filter_priority priority, | |
2826 | u32 *buf, u32 size) | |
2827 | { | |
2828 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2829 | struct efx_filter_spec *spec; | |
2830 | unsigned int filter_idx; | |
2831 | s32 count = 0; | |
2832 | ||
2833 | spin_lock_bh(&efx->filter_lock); | |
2834 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2835 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2836 | if (spec && spec->priority == priority) { | |
2837 | if (count == size) { | |
2838 | count = -EMSGSIZE; | |
2839 | break; | |
2840 | } | |
2841 | buf[count++] = (efx_ef10_filter_rx_match_pri( | |
2842 | table, spec->match_flags) * | |
2843 | HUNT_FILTER_TBL_ROWS + | |
2844 | filter_idx); | |
2845 | } | |
2846 | } | |
2847 | spin_unlock_bh(&efx->filter_lock); | |
2848 | return count; | |
2849 | } | |
2850 | ||
2851 | #ifdef CONFIG_RFS_ACCEL | |
2852 | ||
2853 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; | |
2854 | ||
2855 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, | |
2856 | struct efx_filter_spec *spec) | |
2857 | { | |
2858 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2859 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2860 | struct efx_filter_spec *saved_spec; | |
2861 | unsigned int hash, i, depth = 1; | |
2862 | bool replacing = false; | |
2863 | int ins_index = -1; | |
2864 | u64 cookie; | |
2865 | s32 rc; | |
2866 | ||
2867 | /* Must be an RX filter without RSS and not for a multicast | |
2868 | * destination address (RFS only works for connected sockets). | |
2869 | * These restrictions allow us to pass only a tiny amount of | |
2870 | * data through to the completion function. | |
2871 | */ | |
2872 | EFX_WARN_ON_PARANOID(spec->flags != | |
2873 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); | |
2874 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); | |
2875 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); | |
2876 | ||
2877 | hash = efx_ef10_filter_hash(spec); | |
2878 | ||
2879 | spin_lock_bh(&efx->filter_lock); | |
2880 | ||
2881 | /* Find any existing filter with the same match tuple or else | |
2882 | * a free slot to insert at. If an existing filter is busy, | |
2883 | * we have to give up. | |
2884 | */ | |
2885 | for (;;) { | |
2886 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2887 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2888 | ||
2889 | if (!saved_spec) { | |
2890 | if (ins_index < 0) | |
2891 | ins_index = i; | |
2892 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
2893 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { | |
2894 | rc = -EBUSY; | |
2895 | goto fail_unlock; | |
2896 | } | |
8127d661 BH |
2897 | if (spec->priority < saved_spec->priority) { |
2898 | rc = -EPERM; | |
2899 | goto fail_unlock; | |
2900 | } | |
2901 | ins_index = i; | |
2902 | break; | |
2903 | } | |
2904 | ||
2905 | /* Once we reach the maximum search depth, use the | |
2906 | * first suitable slot or return -EBUSY if there was | |
2907 | * none | |
2908 | */ | |
2909 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
2910 | if (ins_index < 0) { | |
2911 | rc = -EBUSY; | |
2912 | goto fail_unlock; | |
2913 | } | |
2914 | break; | |
2915 | } | |
2916 | ||
2917 | ++depth; | |
2918 | } | |
2919 | ||
2920 | /* Create a software table entry if necessary, and mark it | |
2921 | * busy. We might yet fail to insert, but any attempt to | |
2922 | * insert a conflicting filter while we're waiting for the | |
2923 | * firmware must find the busy entry. | |
2924 | */ | |
2925 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2926 | if (saved_spec) { | |
2927 | replacing = true; | |
2928 | } else { | |
2929 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2930 | if (!saved_spec) { | |
2931 | rc = -ENOMEM; | |
2932 | goto fail_unlock; | |
2933 | } | |
2934 | *saved_spec = *spec; | |
2935 | } | |
2936 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2937 | EFX_EF10_FILTER_FLAG_BUSY); | |
2938 | ||
2939 | spin_unlock_bh(&efx->filter_lock); | |
2940 | ||
2941 | /* Pack up the variables needed on completion */ | |
2942 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; | |
2943 | ||
2944 | efx_ef10_filter_push_prep(efx, spec, inbuf, | |
2945 | table->entry[ins_index].handle, replacing); | |
2946 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2947 | MC_CMD_FILTER_OP_OUT_LEN, | |
2948 | efx_ef10_filter_rfs_insert_complete, cookie); | |
2949 | ||
2950 | return ins_index; | |
2951 | ||
2952 | fail_unlock: | |
2953 | spin_unlock_bh(&efx->filter_lock); | |
2954 | return rc; | |
2955 | } | |
2956 | ||
2957 | static void | |
2958 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, | |
2959 | int rc, efx_dword_t *outbuf, | |
2960 | size_t outlen_actual) | |
2961 | { | |
2962 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2963 | unsigned int ins_index, dmaq_id; | |
2964 | struct efx_filter_spec *spec; | |
2965 | bool replacing; | |
2966 | ||
2967 | /* Unpack the cookie */ | |
2968 | replacing = cookie >> 31; | |
2969 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); | |
2970 | dmaq_id = cookie & 0xffff; | |
2971 | ||
2972 | spin_lock_bh(&efx->filter_lock); | |
2973 | spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2974 | if (rc == 0) { | |
2975 | table->entry[ins_index].handle = | |
2976 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
2977 | if (replacing) | |
2978 | spec->dmaq_id = dmaq_id; | |
2979 | } else if (!replacing) { | |
2980 | kfree(spec); | |
2981 | spec = NULL; | |
2982 | } | |
2983 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); | |
2984 | spin_unlock_bh(&efx->filter_lock); | |
2985 | ||
2986 | wake_up_all(&table->waitq); | |
2987 | } | |
2988 | ||
2989 | static void | |
2990 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
2991 | unsigned long filter_idx, | |
2992 | int rc, efx_dword_t *outbuf, | |
2993 | size_t outlen_actual); | |
2994 | ||
2995 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, | |
2996 | unsigned int filter_idx) | |
2997 | { | |
2998 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2999 | struct efx_filter_spec *spec = | |
3000 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3001 | MCDI_DECLARE_BUF(inbuf, | |
3002 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
3003 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
3004 | ||
3005 | if (!spec || | |
3006 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || | |
3007 | spec->priority != EFX_FILTER_PRI_HINT || | |
3008 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, | |
3009 | flow_id, filter_idx)) | |
3010 | return false; | |
3011 | ||
3012 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3013 | MC_CMD_FILTER_OP_IN_OP_REMOVE); | |
3014 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3015 | table->entry[filter_idx].handle); | |
3016 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, | |
3017 | efx_ef10_filter_rfs_expire_complete, filter_idx)) | |
3018 | return false; | |
3019 | ||
3020 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3021 | return true; | |
3022 | } | |
3023 | ||
3024 | static void | |
3025 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
3026 | unsigned long filter_idx, | |
3027 | int rc, efx_dword_t *outbuf, | |
3028 | size_t outlen_actual) | |
3029 | { | |
3030 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3031 | struct efx_filter_spec *spec = | |
3032 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3033 | ||
3034 | spin_lock_bh(&efx->filter_lock); | |
3035 | if (rc == 0) { | |
3036 | kfree(spec); | |
3037 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3038 | } | |
3039 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
3040 | wake_up_all(&table->waitq); | |
3041 | spin_unlock_bh(&efx->filter_lock); | |
3042 | } | |
3043 | ||
3044 | #endif /* CONFIG_RFS_ACCEL */ | |
3045 | ||
3046 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) | |
3047 | { | |
3048 | int match_flags = 0; | |
3049 | ||
3050 | #define MAP_FLAG(gen_flag, mcdi_field) { \ | |
3051 | u32 old_mcdi_flags = mcdi_flags; \ | |
3052 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
3053 | mcdi_field ## _LBN); \ | |
3054 | if (mcdi_flags != old_mcdi_flags) \ | |
3055 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ | |
3056 | } | |
3057 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); | |
3058 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); | |
3059 | MAP_FLAG(REM_HOST, SRC_IP); | |
3060 | MAP_FLAG(LOC_HOST, DST_IP); | |
3061 | MAP_FLAG(REM_MAC, SRC_MAC); | |
3062 | MAP_FLAG(REM_PORT, SRC_PORT); | |
3063 | MAP_FLAG(LOC_MAC, DST_MAC); | |
3064 | MAP_FLAG(LOC_PORT, DST_PORT); | |
3065 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); | |
3066 | MAP_FLAG(INNER_VID, INNER_VLAN); | |
3067 | MAP_FLAG(OUTER_VID, OUTER_VLAN); | |
3068 | MAP_FLAG(IP_PROTO, IP_PROTO); | |
3069 | #undef MAP_FLAG | |
3070 | ||
3071 | /* Did we map them all? */ | |
3072 | if (mcdi_flags) | |
3073 | return -EINVAL; | |
3074 | ||
3075 | return match_flags; | |
3076 | } | |
3077 | ||
3078 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) | |
3079 | { | |
3080 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); | |
3081 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); | |
3082 | unsigned int pd_match_pri, pd_match_count; | |
3083 | struct efx_ef10_filter_table *table; | |
3084 | size_t outlen; | |
3085 | int rc; | |
3086 | ||
3087 | table = kzalloc(sizeof(*table), GFP_KERNEL); | |
3088 | if (!table) | |
3089 | return -ENOMEM; | |
3090 | ||
3091 | /* Find out which RX filter types are supported, and their priorities */ | |
3092 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, | |
3093 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); | |
3094 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, | |
3095 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), | |
3096 | &outlen); | |
3097 | if (rc) | |
3098 | goto fail; | |
3099 | pd_match_count = MCDI_VAR_ARRAY_LEN( | |
3100 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); | |
3101 | table->rx_match_count = 0; | |
3102 | ||
3103 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { | |
3104 | u32 mcdi_flags = | |
3105 | MCDI_ARRAY_DWORD( | |
3106 | outbuf, | |
3107 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, | |
3108 | pd_match_pri); | |
3109 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); | |
3110 | if (rc < 0) { | |
3111 | netif_dbg(efx, probe, efx->net_dev, | |
3112 | "%s: fw flags %#x pri %u not supported in driver\n", | |
3113 | __func__, mcdi_flags, pd_match_pri); | |
3114 | } else { | |
3115 | netif_dbg(efx, probe, efx->net_dev, | |
3116 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", | |
3117 | __func__, mcdi_flags, pd_match_pri, | |
3118 | rc, table->rx_match_count); | |
3119 | table->rx_match_flags[table->rx_match_count++] = rc; | |
3120 | } | |
3121 | } | |
3122 | ||
3123 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); | |
3124 | if (!table->entry) { | |
3125 | rc = -ENOMEM; | |
3126 | goto fail; | |
3127 | } | |
3128 | ||
3129 | efx->filter_state = table; | |
3130 | init_waitqueue_head(&table->waitq); | |
3131 | return 0; | |
3132 | ||
3133 | fail: | |
3134 | kfree(table); | |
3135 | return rc; | |
3136 | } | |
3137 | ||
3138 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) | |
3139 | { | |
3140 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3141 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
3142 | struct efx_filter_spec *spec; | |
3143 | unsigned int filter_idx; | |
3144 | bool failed = false; | |
3145 | int rc; | |
3146 | ||
3147 | if (!nic_data->must_restore_filters) | |
3148 | return; | |
3149 | ||
3150 | spin_lock_bh(&efx->filter_lock); | |
3151 | ||
3152 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3153 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3154 | if (!spec) | |
3155 | continue; | |
3156 | ||
3157 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3158 | spin_unlock_bh(&efx->filter_lock); | |
3159 | ||
3160 | rc = efx_ef10_filter_push(efx, spec, | |
3161 | &table->entry[filter_idx].handle, | |
3162 | false); | |
3163 | if (rc) | |
3164 | failed = true; | |
3165 | ||
3166 | spin_lock_bh(&efx->filter_lock); | |
3167 | if (rc) { | |
3168 | kfree(spec); | |
3169 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3170 | } else { | |
3171 | table->entry[filter_idx].spec &= | |
3172 | ~EFX_EF10_FILTER_FLAG_BUSY; | |
3173 | } | |
3174 | } | |
3175 | ||
3176 | spin_unlock_bh(&efx->filter_lock); | |
3177 | ||
3178 | if (failed) | |
3179 | netif_err(efx, hw, efx->net_dev, | |
3180 | "unable to restore all filters\n"); | |
3181 | else | |
3182 | nic_data->must_restore_filters = false; | |
3183 | } | |
3184 | ||
3185 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) | |
3186 | { | |
3187 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3188 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
3189 | struct efx_filter_spec *spec; | |
3190 | unsigned int filter_idx; | |
3191 | int rc; | |
3192 | ||
3193 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3194 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3195 | if (!spec) | |
3196 | continue; | |
3197 | ||
3198 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3199 | efx_ef10_filter_is_exclusive(spec) ? | |
3200 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
3201 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3202 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3203 | table->entry[filter_idx].handle); | |
3204 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
3205 | NULL, 0, NULL); | |
48ce5634 BH |
3206 | if (rc) |
3207 | netdev_WARN(efx->net_dev, | |
3208 | "filter_idx=%#x handle=%#llx\n", | |
3209 | filter_idx, | |
3210 | table->entry[filter_idx].handle); | |
8127d661 BH |
3211 | kfree(spec); |
3212 | } | |
3213 | ||
3214 | vfree(table->entry); | |
3215 | kfree(table); | |
3216 | } | |
3217 | ||
3218 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) | |
3219 | { | |
3220 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3221 | struct net_device *net_dev = efx->net_dev; | |
3222 | struct efx_filter_spec spec; | |
3223 | bool remove_failed = false; | |
3224 | struct netdev_hw_addr *uc; | |
3225 | struct netdev_hw_addr *mc; | |
3226 | unsigned int filter_idx; | |
3227 | int i, n, rc; | |
3228 | ||
3229 | if (!efx_dev_registered(efx)) | |
3230 | return; | |
3231 | ||
3232 | /* Mark old filters that may need to be removed */ | |
3233 | spin_lock_bh(&efx->filter_lock); | |
b59e6ef8 | 3234 | n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count; |
8127d661 | 3235 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3236 | filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3237 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 | 3238 | } |
b59e6ef8 | 3239 | n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count; |
8127d661 | 3240 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3241 | filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3242 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 BH |
3243 | } |
3244 | spin_unlock_bh(&efx->filter_lock); | |
3245 | ||
3246 | /* Copy/convert the address lists; add the primary station | |
3247 | * address and broadcast address | |
3248 | */ | |
3249 | netif_addr_lock_bh(net_dev); | |
3250 | if (net_dev->flags & IFF_PROMISC || | |
b59e6ef8 BH |
3251 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) { |
3252 | table->dev_uc_count = -1; | |
8127d661 | 3253 | } else { |
b59e6ef8 | 3254 | table->dev_uc_count = 1 + netdev_uc_count(net_dev); |
cd84ff4d | 3255 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
8127d661 BH |
3256 | i = 1; |
3257 | netdev_for_each_uc_addr(uc, net_dev) { | |
cd84ff4d | 3258 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
8127d661 BH |
3259 | i++; |
3260 | } | |
3261 | } | |
3262 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) || | |
b59e6ef8 BH |
3263 | netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) { |
3264 | table->dev_mc_count = -1; | |
8127d661 | 3265 | } else { |
b59e6ef8 BH |
3266 | table->dev_mc_count = 1 + netdev_mc_count(net_dev); |
3267 | eth_broadcast_addr(table->dev_mc_list[0].addr); | |
8127d661 BH |
3268 | i = 1; |
3269 | netdev_for_each_mc_addr(mc, net_dev) { | |
cd84ff4d | 3270 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
8127d661 BH |
3271 | i++; |
3272 | } | |
3273 | } | |
3274 | netif_addr_unlock_bh(net_dev); | |
3275 | ||
3276 | /* Insert/renew unicast filters */ | |
b59e6ef8 BH |
3277 | if (table->dev_uc_count >= 0) { |
3278 | for (i = 0; i < table->dev_uc_count; i++) { | |
7665d1ab BH |
3279 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3280 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3281 | 0); |
3282 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3283 | table->dev_uc_list[i].addr); |
8127d661 BH |
3284 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3285 | if (rc < 0) { | |
3286 | /* Fall back to unicast-promisc */ | |
3287 | while (i--) | |
3288 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3289 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3290 | table->dev_uc_list[i].id); |
3291 | table->dev_uc_count = -1; | |
8127d661 BH |
3292 | break; |
3293 | } | |
b59e6ef8 | 3294 | table->dev_uc_list[i].id = rc; |
8127d661 BH |
3295 | } |
3296 | } | |
b59e6ef8 | 3297 | if (table->dev_uc_count < 0) { |
7665d1ab BH |
3298 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3299 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3300 | 0); |
3301 | efx_filter_set_uc_def(&spec); | |
3302 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3303 | if (rc < 0) { | |
3304 | WARN_ON(1); | |
b59e6ef8 | 3305 | table->dev_uc_count = 0; |
8127d661 | 3306 | } else { |
b59e6ef8 | 3307 | table->dev_uc_list[0].id = rc; |
8127d661 BH |
3308 | } |
3309 | } | |
3310 | ||
3311 | /* Insert/renew multicast filters */ | |
b59e6ef8 BH |
3312 | if (table->dev_mc_count >= 0) { |
3313 | for (i = 0; i < table->dev_mc_count; i++) { | |
7665d1ab BH |
3314 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3315 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3316 | 0); |
3317 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3318 | table->dev_mc_list[i].addr); |
8127d661 BH |
3319 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3320 | if (rc < 0) { | |
3321 | /* Fall back to multicast-promisc */ | |
3322 | while (i--) | |
3323 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3324 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3325 | table->dev_mc_list[i].id); |
3326 | table->dev_mc_count = -1; | |
8127d661 BH |
3327 | break; |
3328 | } | |
b59e6ef8 | 3329 | table->dev_mc_list[i].id = rc; |
8127d661 BH |
3330 | } |
3331 | } | |
b59e6ef8 | 3332 | if (table->dev_mc_count < 0) { |
7665d1ab BH |
3333 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3334 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3335 | 0); |
3336 | efx_filter_set_mc_def(&spec); | |
3337 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3338 | if (rc < 0) { | |
3339 | WARN_ON(1); | |
b59e6ef8 | 3340 | table->dev_mc_count = 0; |
8127d661 | 3341 | } else { |
b59e6ef8 | 3342 | table->dev_mc_list[0].id = rc; |
8127d661 BH |
3343 | } |
3344 | } | |
3345 | ||
3346 | /* Remove filters that weren't renewed. Since nothing else | |
b59e6ef8 | 3347 | * changes the AUTO_OLD flag or removes these filters, we |
8127d661 BH |
3348 | * don't need to hold the filter_lock while scanning for |
3349 | * these filters. | |
3350 | */ | |
3351 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
3352 | if (ACCESS_ONCE(table->entry[i].spec) & | |
b59e6ef8 | 3353 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
7665d1ab | 3354 | if (efx_ef10_filter_remove_internal( |
fbd79120 BH |
3355 | efx, 1U << EFX_FILTER_PRI_AUTO, |
3356 | i, true) < 0) | |
8127d661 BH |
3357 | remove_failed = true; |
3358 | } | |
3359 | } | |
3360 | WARN_ON(remove_failed); | |
3361 | } | |
3362 | ||
3363 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) | |
3364 | { | |
3365 | efx_ef10_filter_sync_rx_mode(efx); | |
3366 | ||
3367 | return efx_mcdi_set_mac(efx); | |
3368 | } | |
3369 | ||
74cd60a4 JC |
3370 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
3371 | { | |
3372 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); | |
3373 | ||
3374 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); | |
3375 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), | |
3376 | NULL, 0, NULL); | |
3377 | } | |
3378 | ||
3379 | /* MC BISTs follow a different poll mechanism to phy BISTs. | |
3380 | * The BIST is done in the poll handler on the MC, and the MCDI command | |
3381 | * will block until the BIST is done. | |
3382 | */ | |
3383 | static int efx_ef10_poll_bist(struct efx_nic *efx) | |
3384 | { | |
3385 | int rc; | |
3386 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); | |
3387 | size_t outlen; | |
3388 | u32 result; | |
3389 | ||
3390 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, | |
3391 | outbuf, sizeof(outbuf), &outlen); | |
3392 | if (rc != 0) | |
3393 | return rc; | |
3394 | ||
3395 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) | |
3396 | return -EIO; | |
3397 | ||
3398 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); | |
3399 | switch (result) { | |
3400 | case MC_CMD_POLL_BIST_PASSED: | |
3401 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); | |
3402 | return 0; | |
3403 | case MC_CMD_POLL_BIST_TIMEOUT: | |
3404 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); | |
3405 | return -EIO; | |
3406 | case MC_CMD_POLL_BIST_FAILED: | |
3407 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); | |
3408 | return -EIO; | |
3409 | default: | |
3410 | netif_err(efx, hw, efx->net_dev, | |
3411 | "BIST returned unknown result %u", result); | |
3412 | return -EIO; | |
3413 | } | |
3414 | } | |
3415 | ||
3416 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) | |
3417 | { | |
3418 | int rc; | |
3419 | ||
3420 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); | |
3421 | ||
3422 | rc = efx_ef10_start_bist(efx, bist_type); | |
3423 | if (rc != 0) | |
3424 | return rc; | |
3425 | ||
3426 | return efx_ef10_poll_bist(efx); | |
3427 | } | |
3428 | ||
3429 | static int | |
3430 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) | |
3431 | { | |
3432 | int rc, rc2; | |
3433 | ||
3434 | efx_reset_down(efx, RESET_TYPE_WORLD); | |
3435 | ||
3436 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, | |
3437 | NULL, 0, NULL, 0, NULL); | |
3438 | if (rc != 0) | |
3439 | goto out; | |
3440 | ||
3441 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; | |
3442 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; | |
3443 | ||
3444 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); | |
3445 | ||
3446 | out: | |
3447 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); | |
3448 | return rc ? rc : rc2; | |
3449 | } | |
3450 | ||
8127d661 BH |
3451 | #ifdef CONFIG_SFC_MTD |
3452 | ||
3453 | struct efx_ef10_nvram_type_info { | |
3454 | u16 type, type_mask; | |
3455 | u8 port; | |
3456 | const char *name; | |
3457 | }; | |
3458 | ||
3459 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { | |
3460 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, | |
3461 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, | |
3462 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, | |
3463 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, | |
3464 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, | |
3465 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, | |
3466 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, | |
3467 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, | |
3468 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, | |
a84f3bf9 | 3469 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
8127d661 BH |
3470 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
3471 | }; | |
3472 | ||
3473 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, | |
3474 | struct efx_mcdi_mtd_partition *part, | |
3475 | unsigned int type) | |
3476 | { | |
3477 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); | |
3478 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); | |
3479 | const struct efx_ef10_nvram_type_info *info; | |
3480 | size_t size, erase_size, outlen; | |
3481 | bool protected; | |
3482 | int rc; | |
3483 | ||
3484 | for (info = efx_ef10_nvram_types; ; info++) { | |
3485 | if (info == | |
3486 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) | |
3487 | return -ENODEV; | |
3488 | if ((type & ~info->type_mask) == info->type) | |
3489 | break; | |
3490 | } | |
3491 | if (info->port != efx_port_num(efx)) | |
3492 | return -ENODEV; | |
3493 | ||
3494 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); | |
3495 | if (rc) | |
3496 | return rc; | |
3497 | if (protected) | |
3498 | return -ENODEV; /* hide it */ | |
3499 | ||
3500 | part->nvram_type = type; | |
3501 | ||
3502 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); | |
3503 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), | |
3504 | outbuf, sizeof(outbuf), &outlen); | |
3505 | if (rc) | |
3506 | return rc; | |
3507 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) | |
3508 | return -EIO; | |
3509 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & | |
3510 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) | |
3511 | part->fw_subtype = MCDI_DWORD(outbuf, | |
3512 | NVRAM_METADATA_OUT_SUBTYPE); | |
3513 | ||
3514 | part->common.dev_type_name = "EF10 NVRAM manager"; | |
3515 | part->common.type_name = info->name; | |
3516 | ||
3517 | part->common.mtd.type = MTD_NORFLASH; | |
3518 | part->common.mtd.flags = MTD_CAP_NORFLASH; | |
3519 | part->common.mtd.size = size; | |
3520 | part->common.mtd.erasesize = erase_size; | |
3521 | ||
3522 | return 0; | |
3523 | } | |
3524 | ||
3525 | static int efx_ef10_mtd_probe(struct efx_nic *efx) | |
3526 | { | |
3527 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); | |
3528 | struct efx_mcdi_mtd_partition *parts; | |
3529 | size_t outlen, n_parts_total, i, n_parts; | |
3530 | unsigned int type; | |
3531 | int rc; | |
3532 | ||
3533 | ASSERT_RTNL(); | |
3534 | ||
3535 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); | |
3536 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, | |
3537 | outbuf, sizeof(outbuf), &outlen); | |
3538 | if (rc) | |
3539 | return rc; | |
3540 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) | |
3541 | return -EIO; | |
3542 | ||
3543 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); | |
3544 | if (n_parts_total > | |
3545 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) | |
3546 | return -EIO; | |
3547 | ||
3548 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); | |
3549 | if (!parts) | |
3550 | return -ENOMEM; | |
3551 | ||
3552 | n_parts = 0; | |
3553 | for (i = 0; i < n_parts_total; i++) { | |
3554 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, | |
3555 | i); | |
3556 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); | |
3557 | if (rc == 0) | |
3558 | n_parts++; | |
3559 | else if (rc != -ENODEV) | |
3560 | goto fail; | |
3561 | } | |
3562 | ||
3563 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); | |
3564 | fail: | |
3565 | if (rc) | |
3566 | kfree(parts); | |
3567 | return rc; | |
3568 | } | |
3569 | ||
3570 | #endif /* CONFIG_SFC_MTD */ | |
3571 | ||
3572 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) | |
3573 | { | |
3574 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); | |
3575 | } | |
3576 | ||
02246a7f SS |
3577 | static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx, |
3578 | u32 host_time) {} | |
3579 | ||
bd9a265d JC |
3580 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
3581 | bool temp) | |
3582 | { | |
3583 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); | |
3584 | int rc; | |
3585 | ||
3586 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || | |
3587 | channel->sync_events_state == SYNC_EVENTS_VALID || | |
3588 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) | |
3589 | return 0; | |
3590 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; | |
3591 | ||
3592 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); | |
3593 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
3594 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, | |
3595 | channel->channel); | |
3596 | ||
3597 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
3598 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
3599 | ||
3600 | if (rc != 0) | |
3601 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
3602 | SYNC_EVENTS_DISABLED; | |
3603 | ||
3604 | return rc; | |
3605 | } | |
3606 | ||
3607 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, | |
3608 | bool temp) | |
3609 | { | |
3610 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); | |
3611 | int rc; | |
3612 | ||
3613 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || | |
3614 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) | |
3615 | return 0; | |
3616 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { | |
3617 | channel->sync_events_state = SYNC_EVENTS_DISABLED; | |
3618 | return 0; | |
3619 | } | |
3620 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
3621 | SYNC_EVENTS_DISABLED; | |
3622 | ||
3623 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); | |
3624 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
3625 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, | |
3626 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); | |
3627 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, | |
3628 | channel->channel); | |
3629 | ||
3630 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
3631 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
3632 | ||
3633 | return rc; | |
3634 | } | |
3635 | ||
3636 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, | |
3637 | bool temp) | |
3638 | { | |
3639 | int (*set)(struct efx_channel *channel, bool temp); | |
3640 | struct efx_channel *channel; | |
3641 | ||
3642 | set = en ? | |
3643 | efx_ef10_rx_enable_timestamping : | |
3644 | efx_ef10_rx_disable_timestamping; | |
3645 | ||
3646 | efx_for_each_channel(channel, efx) { | |
3647 | int rc = set(channel, temp); | |
3648 | if (en && rc != 0) { | |
3649 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); | |
3650 | return rc; | |
3651 | } | |
3652 | } | |
3653 | ||
3654 | return 0; | |
3655 | } | |
3656 | ||
02246a7f SS |
3657 | static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx, |
3658 | struct hwtstamp_config *init) | |
3659 | { | |
3660 | return -EOPNOTSUPP; | |
3661 | } | |
3662 | ||
bd9a265d JC |
3663 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
3664 | struct hwtstamp_config *init) | |
3665 | { | |
3666 | int rc; | |
3667 | ||
3668 | switch (init->rx_filter) { | |
3669 | case HWTSTAMP_FILTER_NONE: | |
3670 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); | |
3671 | /* if TX timestamping is still requested then leave PTP on */ | |
3672 | return efx_ptp_change_mode(efx, | |
3673 | init->tx_type != HWTSTAMP_TX_OFF, 0); | |
3674 | case HWTSTAMP_FILTER_ALL: | |
3675 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | |
3676 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: | |
3677 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | |
3678 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | |
3679 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
3680 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
3681 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | |
3682 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
3683 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
3684 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | |
3685 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
3686 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
3687 | init->rx_filter = HWTSTAMP_FILTER_ALL; | |
3688 | rc = efx_ptp_change_mode(efx, true, 0); | |
3689 | if (!rc) | |
3690 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); | |
3691 | if (rc) | |
3692 | efx_ptp_change_mode(efx, false, 0); | |
3693 | return rc; | |
3694 | default: | |
3695 | return -ERANGE; | |
3696 | } | |
3697 | } | |
3698 | ||
02246a7f SS |
3699 | const struct efx_nic_type efx_hunt_a0_vf_nic_type = { |
3700 | .mem_bar = EFX_MEM_VF_BAR, | |
3701 | .mem_map_size = efx_ef10_mem_map_size, | |
3702 | .probe = efx_ef10_probe_vf, | |
3703 | .remove = efx_ef10_remove, | |
3704 | .dimension_resources = efx_ef10_dimension_resources, | |
3705 | .init = efx_ef10_init_nic, | |
3706 | .fini = efx_port_dummy_op_void, | |
3707 | .map_reset_reason = efx_mcdi_map_reset_reason, | |
3708 | .map_reset_flags = efx_ef10_map_reset_flags, | |
3709 | .reset = efx_ef10_reset, | |
3710 | .probe_port = efx_mcdi_port_probe, | |
3711 | .remove_port = efx_mcdi_port_remove, | |
3712 | .fini_dmaq = efx_ef10_fini_dmaq, | |
3713 | .prepare_flr = efx_ef10_prepare_flr, | |
3714 | .finish_flr = efx_port_dummy_op_void, | |
3715 | .describe_stats = efx_ef10_describe_stats, | |
3716 | .update_stats = efx_ef10_update_stats, | |
3717 | .start_stats = efx_port_dummy_op_void, | |
3718 | .pull_stats = efx_port_dummy_op_void, | |
3719 | .stop_stats = efx_port_dummy_op_void, | |
3720 | .set_id_led = efx_mcdi_set_id_led, | |
3721 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
3722 | .reconfigure_mac = efx_ef10_mac_reconfigure, | |
3723 | .check_mac_fault = efx_mcdi_mac_check_fault, | |
3724 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
3725 | .get_wol = efx_ef10_get_wol_vf, | |
3726 | .set_wol = efx_ef10_set_wol_vf, | |
3727 | .resume_wol = efx_port_dummy_op_void, | |
3728 | .mcdi_request = efx_ef10_mcdi_request, | |
3729 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
3730 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
3731 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
3732 | .irq_enable_master = efx_port_dummy_op_void, | |
3733 | .irq_test_generate = efx_ef10_irq_test_generate, | |
3734 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
3735 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
3736 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
3737 | .tx_probe = efx_ef10_tx_probe, | |
3738 | .tx_init = efx_ef10_tx_init, | |
3739 | .tx_remove = efx_ef10_tx_remove, | |
3740 | .tx_write = efx_ef10_tx_write, | |
3741 | .rx_push_rss_config = efx_ef10_rx_push_rss_config, | |
3742 | .rx_probe = efx_ef10_rx_probe, | |
3743 | .rx_init = efx_ef10_rx_init, | |
3744 | .rx_remove = efx_ef10_rx_remove, | |
3745 | .rx_write = efx_ef10_rx_write, | |
3746 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
3747 | .ev_probe = efx_ef10_ev_probe, | |
3748 | .ev_init = efx_ef10_ev_init, | |
3749 | .ev_fini = efx_ef10_ev_fini, | |
3750 | .ev_remove = efx_ef10_ev_remove, | |
3751 | .ev_process = efx_ef10_ev_process, | |
3752 | .ev_read_ack = efx_ef10_ev_read_ack, | |
3753 | .ev_test_generate = efx_ef10_ev_test_generate, | |
3754 | .filter_table_probe = efx_ef10_filter_table_probe, | |
3755 | .filter_table_restore = efx_ef10_filter_table_restore, | |
3756 | .filter_table_remove = efx_ef10_filter_table_remove, | |
3757 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
3758 | .filter_insert = efx_ef10_filter_insert, | |
3759 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
3760 | .filter_get_safe = efx_ef10_filter_get_safe, | |
3761 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
3762 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
3763 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
3764 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
3765 | #ifdef CONFIG_RFS_ACCEL | |
3766 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
3767 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
3768 | #endif | |
3769 | #ifdef CONFIG_SFC_MTD | |
3770 | .mtd_probe = efx_port_dummy_op_int, | |
3771 | #endif | |
3772 | .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf, | |
3773 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf, | |
3774 | #ifdef CONFIG_SFC_SRIOV | |
7b8c7b54 SS |
3775 | .vswitching_probe = efx_ef10_vswitching_probe_vf, |
3776 | .vswitching_restore = efx_ef10_vswitching_restore_vf, | |
3777 | .vswitching_remove = efx_ef10_vswitching_remove_vf, | |
02246a7f SS |
3778 | #endif |
3779 | .revision = EFX_REV_HUNT_A0, | |
3780 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
3781 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
3782 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
3783 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, | |
3784 | .can_rx_scatter = true, | |
3785 | .always_rx_scatter = true, | |
3786 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
3787 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
3788 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
3789 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
3790 | .mcdi_max_ver = 2, | |
3791 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
3792 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | | |
3793 | 1 << HWTSTAMP_FILTER_ALL, | |
3794 | }; | |
3795 | ||
8127d661 | 3796 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
02246a7f | 3797 | .mem_bar = EFX_MEM_BAR, |
8127d661 | 3798 | .mem_map_size = efx_ef10_mem_map_size, |
02246a7f | 3799 | .probe = efx_ef10_probe_pf, |
8127d661 BH |
3800 | .remove = efx_ef10_remove, |
3801 | .dimension_resources = efx_ef10_dimension_resources, | |
3802 | .init = efx_ef10_init_nic, | |
3803 | .fini = efx_port_dummy_op_void, | |
3804 | .map_reset_reason = efx_mcdi_map_reset_reason, | |
3805 | .map_reset_flags = efx_ef10_map_reset_flags, | |
3e336261 | 3806 | .reset = efx_ef10_reset, |
8127d661 BH |
3807 | .probe_port = efx_mcdi_port_probe, |
3808 | .remove_port = efx_mcdi_port_remove, | |
3809 | .fini_dmaq = efx_ef10_fini_dmaq, | |
e283546c EC |
3810 | .prepare_flr = efx_ef10_prepare_flr, |
3811 | .finish_flr = efx_port_dummy_op_void, | |
8127d661 BH |
3812 | .describe_stats = efx_ef10_describe_stats, |
3813 | .update_stats = efx_ef10_update_stats, | |
3814 | .start_stats = efx_mcdi_mac_start_stats, | |
f8f3b5ae | 3815 | .pull_stats = efx_mcdi_mac_pull_stats, |
8127d661 BH |
3816 | .stop_stats = efx_mcdi_mac_stop_stats, |
3817 | .set_id_led = efx_mcdi_set_id_led, | |
3818 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
3819 | .reconfigure_mac = efx_ef10_mac_reconfigure, | |
3820 | .check_mac_fault = efx_mcdi_mac_check_fault, | |
3821 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
3822 | .get_wol = efx_ef10_get_wol, | |
3823 | .set_wol = efx_ef10_set_wol, | |
3824 | .resume_wol = efx_port_dummy_op_void, | |
74cd60a4 | 3825 | .test_chip = efx_ef10_test_chip, |
8127d661 BH |
3826 | .test_nvram = efx_mcdi_nvram_test_all, |
3827 | .mcdi_request = efx_ef10_mcdi_request, | |
3828 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
3829 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
3830 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
3831 | .irq_enable_master = efx_port_dummy_op_void, | |
3832 | .irq_test_generate = efx_ef10_irq_test_generate, | |
3833 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
3834 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
3835 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
3836 | .tx_probe = efx_ef10_tx_probe, | |
3837 | .tx_init = efx_ef10_tx_init, | |
3838 | .tx_remove = efx_ef10_tx_remove, | |
3839 | .tx_write = efx_ef10_tx_write, | |
d43050c0 | 3840 | .rx_push_rss_config = efx_ef10_rx_push_rss_config, |
8127d661 BH |
3841 | .rx_probe = efx_ef10_rx_probe, |
3842 | .rx_init = efx_ef10_rx_init, | |
3843 | .rx_remove = efx_ef10_rx_remove, | |
3844 | .rx_write = efx_ef10_rx_write, | |
3845 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
3846 | .ev_probe = efx_ef10_ev_probe, | |
3847 | .ev_init = efx_ef10_ev_init, | |
3848 | .ev_fini = efx_ef10_ev_fini, | |
3849 | .ev_remove = efx_ef10_ev_remove, | |
3850 | .ev_process = efx_ef10_ev_process, | |
3851 | .ev_read_ack = efx_ef10_ev_read_ack, | |
3852 | .ev_test_generate = efx_ef10_ev_test_generate, | |
3853 | .filter_table_probe = efx_ef10_filter_table_probe, | |
3854 | .filter_table_restore = efx_ef10_filter_table_restore, | |
3855 | .filter_table_remove = efx_ef10_filter_table_remove, | |
3856 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
3857 | .filter_insert = efx_ef10_filter_insert, | |
3858 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
3859 | .filter_get_safe = efx_ef10_filter_get_safe, | |
3860 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
3861 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
3862 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
3863 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
3864 | #ifdef CONFIG_RFS_ACCEL | |
3865 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
3866 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
3867 | #endif | |
3868 | #ifdef CONFIG_SFC_MTD | |
3869 | .mtd_probe = efx_ef10_mtd_probe, | |
3870 | .mtd_rename = efx_mcdi_mtd_rename, | |
3871 | .mtd_read = efx_mcdi_mtd_read, | |
3872 | .mtd_erase = efx_mcdi_mtd_erase, | |
3873 | .mtd_write = efx_mcdi_mtd_write, | |
3874 | .mtd_sync = efx_mcdi_mtd_sync, | |
3875 | #endif | |
3876 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, | |
bd9a265d JC |
3877 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
3878 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, | |
7fa8d547 | 3879 | #ifdef CONFIG_SFC_SRIOV |
834e23dd | 3880 | .sriov_configure = efx_ef10_sriov_configure, |
d98a4ffe SS |
3881 | .sriov_init = efx_ef10_sriov_init, |
3882 | .sriov_fini = efx_ef10_sriov_fini, | |
3883 | .sriov_mac_address_changed = efx_ef10_sriov_mac_address_changed, | |
3884 | .sriov_wanted = efx_ef10_sriov_wanted, | |
3885 | .sriov_reset = efx_ef10_sriov_reset, | |
7fa8d547 SS |
3886 | .sriov_flr = efx_ef10_sriov_flr, |
3887 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, | |
3888 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, | |
3889 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, | |
3890 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, | |
7b8c7b54 SS |
3891 | .vswitching_probe = efx_ef10_vswitching_probe_pf, |
3892 | .vswitching_restore = efx_ef10_vswitching_restore_pf, | |
3893 | .vswitching_remove = efx_ef10_vswitching_remove_pf, | |
7fa8d547 | 3894 | #endif |
8127d661 BH |
3895 | |
3896 | .revision = EFX_REV_HUNT_A0, | |
3897 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
3898 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
3899 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
bd9a265d | 3900 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
8127d661 BH |
3901 | .can_rx_scatter = true, |
3902 | .always_rx_scatter = true, | |
3903 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
3904 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
3905 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
3906 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
3907 | .mcdi_max_ver = 2, | |
3908 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
bd9a265d JC |
3909 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
3910 | 1 << HWTSTAMP_FILTER_ALL, | |
8127d661 | 3911 | }; |