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