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