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