blob: 9e2e8e14313be7ac8870e3b839f4698d111c50fc [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
Shradha Shahf1122a32015-05-20 11:09:46 +0100547#ifdef CONFIG_SFC_SRIOV
548 struct efx_ef10_nic_data *nic_data_pf;
549 struct pci_dev *pci_dev_pf;
550 struct efx_nic *efx_pf;
551 struct ef10_vf *vf;
552
553 if (efx->pci_dev->is_virtfn) {
554 pci_dev_pf = efx->pci_dev->physfn;
555 if (pci_dev_pf) {
556 efx_pf = pci_get_drvdata(pci_dev_pf);
557 nic_data_pf = efx_pf->nic_data;
558 vf = nic_data_pf->vf + nic_data->vf_index;
559 vf->efx = NULL;
560 } else
561 netif_info(efx, drv, efx->net_dev,
562 "Could not get the PF id from VF\n");
563 }
564#endif
565
Ben Hutchings9aecda92013-12-05 21:28:42 +0000566 efx_ptp_remove(efx);
567
Ben Hutchings8127d662013-08-29 19:19:29 +0100568 efx_mcdi_mon_remove(efx);
569
Ben Hutchings8127d662013-08-29 19:19:29 +0100570 efx_ef10_rx_free_indir_table(efx);
571
Ben Hutchings183233b2013-06-28 21:47:12 +0100572 if (nic_data->wc_membase)
573 iounmap(nic_data->wc_membase);
574
Ben Hutchings8127d662013-08-29 19:19:29 +0100575 rc = efx_ef10_free_vis(efx);
576 WARN_ON(rc != 0);
577
Ben Hutchings183233b2013-06-28 21:47:12 +0100578 if (!nic_data->must_restore_piobufs)
579 efx_ef10_free_piobufs(efx);
580
Ben Hutchings8127d662013-08-29 19:19:29 +0100581 efx_mcdi_fini(efx);
582 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
583 kfree(nic_data);
584}
585
Shradha Shah88a37de2015-05-20 11:09:15 +0100586static int efx_ef10_probe_pf(struct efx_nic *efx)
587{
588 return efx_ef10_probe(efx);
589}
590
591#ifdef CONFIG_SFC_SRIOV
592static int efx_ef10_probe_vf(struct efx_nic *efx)
593{
594 int rc;
595
596 rc = efx_ef10_probe(efx);
597 if (rc)
598 return rc;
599
600 rc = efx_ef10_get_vf_index(efx);
601 if (rc)
602 goto fail;
603
Shradha Shahf1122a32015-05-20 11:09:46 +0100604 if (efx->pci_dev->is_virtfn) {
605 if (efx->pci_dev->physfn) {
606 struct efx_nic *efx_pf =
607 pci_get_drvdata(efx->pci_dev->physfn);
608 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
609 struct efx_ef10_nic_data *nic_data = efx->nic_data;
610
611 nic_data_p->vf[nic_data->vf_index].efx = efx;
612 } else
613 netif_info(efx, drv, efx->net_dev,
614 "Could not get the PF id from VF\n");
615 }
616
Shradha Shah88a37de2015-05-20 11:09:15 +0100617 return 0;
618
619fail:
620 efx_ef10_remove(efx);
621 return rc;
622}
623#else
624static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
625{
626 return 0;
627}
628#endif
629
Ben Hutchings8127d662013-08-29 19:19:29 +0100630static int efx_ef10_alloc_vis(struct efx_nic *efx,
631 unsigned int min_vis, unsigned int max_vis)
632{
633 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
634 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
635 struct efx_ef10_nic_data *nic_data = efx->nic_data;
636 size_t outlen;
637 int rc;
638
639 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
640 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
641 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
642 outbuf, sizeof(outbuf), &outlen);
643 if (rc != 0)
644 return rc;
645
646 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
647 return -EIO;
648
649 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
650 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
651
652 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
653 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
654 return 0;
655}
656
Ben Hutchings183233b2013-06-28 21:47:12 +0100657/* Note that the failure path of this function does not free
658 * resources, as this will be done by efx_ef10_remove().
659 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100660static int efx_ef10_dimension_resources(struct efx_nic *efx)
661{
Ben Hutchings183233b2013-06-28 21:47:12 +0100662 struct efx_ef10_nic_data *nic_data = efx->nic_data;
663 unsigned int uc_mem_map_size, wc_mem_map_size;
664 unsigned int min_vis, pio_write_vi_base, max_vis;
665 void __iomem *membase;
666 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100667
Ben Hutchings183233b2013-06-28 21:47:12 +0100668 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
669
670#ifdef EFX_USE_PIO
671 /* Try to allocate PIO buffers if wanted and if the full
672 * number of PIO buffers would be sufficient to allocate one
673 * copy-buffer per TX channel. Failure is non-fatal, as there
674 * are only a small number of PIO buffers shared between all
675 * functions of the controller.
676 */
677 if (efx_piobuf_size != 0 &&
678 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
679 efx->n_tx_channels) {
680 unsigned int n_piobufs =
681 DIV_ROUND_UP(efx->n_tx_channels,
682 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
683
684 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
685 if (rc)
686 netif_err(efx, probe, efx->net_dev,
687 "failed to allocate PIO buffers (%d)\n", rc);
688 else
689 netif_dbg(efx, probe, efx->net_dev,
690 "allocated %u PIO buffers\n", n_piobufs);
691 }
692#else
693 nic_data->n_piobufs = 0;
694#endif
695
696 /* PIO buffers should be mapped with write-combining enabled,
697 * and we want to make single UC and WC mappings rather than
698 * several of each (in fact that's the only option if host
699 * page size is >4K). So we may allocate some extra VIs just
700 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100701 *
702 * The UC mapping contains (min_vis - 1) complete VIs and the
703 * first half of the next VI. Then the WC mapping begins with
704 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100705 */
706 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
707 ER_DZ_TX_PIOBUF);
708 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100709 /* pio_write_vi_base rounds down to give the number of complete
710 * VIs inside the UC mapping.
711 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100712 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
713 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
714 nic_data->n_piobufs) *
715 EFX_VI_PAGE_SIZE) -
716 uc_mem_map_size);
717 max_vis = pio_write_vi_base + nic_data->n_piobufs;
718 } else {
719 pio_write_vi_base = 0;
720 wc_mem_map_size = 0;
721 max_vis = min_vis;
722 }
723
724 /* In case the last attached driver failed to free VIs, do it now */
725 rc = efx_ef10_free_vis(efx);
726 if (rc != 0)
727 return rc;
728
729 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
730 if (rc != 0)
731 return rc;
732
733 /* If we didn't get enough VIs to map all the PIO buffers, free the
734 * PIO buffers
735 */
736 if (nic_data->n_piobufs &&
737 nic_data->n_allocated_vis <
738 pio_write_vi_base + nic_data->n_piobufs) {
739 netif_dbg(efx, probe, efx->net_dev,
740 "%u VIs are not sufficient to map %u PIO buffers\n",
741 nic_data->n_allocated_vis, nic_data->n_piobufs);
742 efx_ef10_free_piobufs(efx);
743 }
744
745 /* Shrink the original UC mapping of the memory BAR */
746 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
747 if (!membase) {
748 netif_err(efx, probe, efx->net_dev,
749 "could not shrink memory BAR to %x\n",
750 uc_mem_map_size);
751 return -ENOMEM;
752 }
753 iounmap(efx->membase);
754 efx->membase = membase;
755
756 /* Set up the WC mapping if needed */
757 if (wc_mem_map_size) {
758 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
759 uc_mem_map_size,
760 wc_mem_map_size);
761 if (!nic_data->wc_membase) {
762 netif_err(efx, probe, efx->net_dev,
763 "could not allocate WC mapping of size %x\n",
764 wc_mem_map_size);
765 return -ENOMEM;
766 }
767 nic_data->pio_write_vi_base = pio_write_vi_base;
768 nic_data->pio_write_base =
769 nic_data->wc_membase +
770 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
771 uc_mem_map_size);
772
773 rc = efx_ef10_link_piobufs(efx);
774 if (rc)
775 efx_ef10_free_piobufs(efx);
776 }
777
778 netif_dbg(efx, probe, efx->net_dev,
779 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
780 &efx->membase_phys, efx->membase, uc_mem_map_size,
781 nic_data->wc_membase, wc_mem_map_size);
782
783 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100784}
785
786static int efx_ef10_init_nic(struct efx_nic *efx)
787{
788 struct efx_ef10_nic_data *nic_data = efx->nic_data;
789 int rc;
790
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100791 if (nic_data->must_check_datapath_caps) {
792 rc = efx_ef10_init_datapath_caps(efx);
793 if (rc)
794 return rc;
795 nic_data->must_check_datapath_caps = false;
796 }
797
Ben Hutchings8127d662013-08-29 19:19:29 +0100798 if (nic_data->must_realloc_vis) {
799 /* We cannot let the number of VIs change now */
800 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
801 nic_data->n_allocated_vis);
802 if (rc)
803 return rc;
804 nic_data->must_realloc_vis = false;
805 }
806
Ben Hutchings183233b2013-06-28 21:47:12 +0100807 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
808 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
809 if (rc == 0) {
810 rc = efx_ef10_link_piobufs(efx);
811 if (rc)
812 efx_ef10_free_piobufs(efx);
813 }
814
815 /* Log an error on failure, but this is non-fatal */
816 if (rc)
817 netif_err(efx, drv, efx->net_dev,
818 "failed to restore PIO buffers (%d)\n", rc);
819 nic_data->must_restore_piobufs = false;
820 }
821
Jon Cooper267c0152015-05-06 00:59:38 +0100822 /* don't fail init if RSS setup doesn't work */
823 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
824
Ben Hutchings8127d662013-08-29 19:19:29 +0100825 return 0;
826}
827
Jon Cooper3e336262014-01-17 19:48:06 +0000828static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
829{
830 struct efx_ef10_nic_data *nic_data = efx->nic_data;
831
832 /* All our allocations have been reset */
833 nic_data->must_realloc_vis = true;
834 nic_data->must_restore_filters = true;
835 nic_data->must_restore_piobufs = true;
836 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
837}
838
Ben Hutchings8127d662013-08-29 19:19:29 +0100839static int efx_ef10_map_reset_flags(u32 *flags)
840{
841 enum {
842 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
843 ETH_RESET_SHARED_SHIFT),
844 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
845 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
846 ETH_RESET_PHY | ETH_RESET_MGMT) <<
847 ETH_RESET_SHARED_SHIFT)
848 };
849
850 /* We assume for now that our PCI function is permitted to
851 * reset everything.
852 */
853
854 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
855 *flags &= ~EF10_RESET_MC;
856 return RESET_TYPE_WORLD;
857 }
858
859 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
860 *flags &= ~EF10_RESET_PORT;
861 return RESET_TYPE_ALL;
862 }
863
864 /* no invisible reset implemented */
865
866 return -EINVAL;
867}
868
Jon Cooper3e336262014-01-17 19:48:06 +0000869static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
870{
871 int rc = efx_mcdi_reset(efx, reset_type);
872
873 /* If it was a port reset, trigger reallocation of MC resources.
874 * Note that on an MC reset nothing needs to be done now because we'll
875 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +0100876 * For an FLR, we never get an MC reset event, but the MC has reset all
877 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +0000878 */
Edward Creee2835462014-04-16 19:27:48 +0100879 if ((reset_type == RESET_TYPE_ALL ||
880 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +0000881 efx_ef10_reset_mc_allocations(efx);
882 return rc;
883}
884
Ben Hutchings8127d662013-08-29 19:19:29 +0100885#define EF10_DMA_STAT(ext_name, mcdi_name) \
886 [EF10_STAT_ ## ext_name] = \
887 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
888#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
889 [EF10_STAT_ ## int_name] = \
890 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
891#define EF10_OTHER_STAT(ext_name) \
892 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +0100893#define GENERIC_SW_STAT(ext_name) \
894 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100895
896static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
897 EF10_DMA_STAT(tx_bytes, TX_BYTES),
898 EF10_DMA_STAT(tx_packets, TX_PKTS),
899 EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS),
900 EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS),
901 EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS),
902 EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS),
903 EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS),
904 EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS),
905 EF10_DMA_STAT(tx_64, TX_64_PKTS),
906 EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS),
907 EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS),
908 EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS),
909 EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS),
910 EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
911 EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
912 EF10_DMA_STAT(rx_bytes, RX_BYTES),
913 EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES),
914 EF10_OTHER_STAT(rx_good_bytes),
915 EF10_OTHER_STAT(rx_bad_bytes),
916 EF10_DMA_STAT(rx_packets, RX_PKTS),
917 EF10_DMA_STAT(rx_good, RX_GOOD_PKTS),
918 EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS),
919 EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS),
920 EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS),
921 EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS),
922 EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS),
923 EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS),
924 EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS),
925 EF10_DMA_STAT(rx_64, RX_64_PKTS),
926 EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS),
927 EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS),
928 EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS),
929 EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS),
930 EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
931 EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
932 EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS),
933 EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS),
934 EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS),
935 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
936 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
937 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +0100938 GENERIC_SW_STAT(rx_nodesc_trunc),
939 GENERIC_SW_STAT(rx_noskb_drops),
Edward Cree568d7a02013-09-25 17:32:09 +0100940 EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
941 EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
942 EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
943 EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
944 EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB),
945 EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB),
946 EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING),
947 EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
948 EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
949 EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
Shradha Shah79ac47a2013-11-28 18:48:49 +0000950 EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS),
951 EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS),
Ben Hutchings8127d662013-08-29 19:19:29 +0100952};
953
954#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \
955 (1ULL << EF10_STAT_tx_packets) | \
956 (1ULL << EF10_STAT_tx_pause) | \
957 (1ULL << EF10_STAT_tx_unicast) | \
958 (1ULL << EF10_STAT_tx_multicast) | \
959 (1ULL << EF10_STAT_tx_broadcast) | \
960 (1ULL << EF10_STAT_rx_bytes) | \
961 (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \
962 (1ULL << EF10_STAT_rx_good_bytes) | \
963 (1ULL << EF10_STAT_rx_bad_bytes) | \
964 (1ULL << EF10_STAT_rx_packets) | \
965 (1ULL << EF10_STAT_rx_good) | \
966 (1ULL << EF10_STAT_rx_bad) | \
967 (1ULL << EF10_STAT_rx_pause) | \
968 (1ULL << EF10_STAT_rx_control) | \
969 (1ULL << EF10_STAT_rx_unicast) | \
970 (1ULL << EF10_STAT_rx_multicast) | \
971 (1ULL << EF10_STAT_rx_broadcast) | \
972 (1ULL << EF10_STAT_rx_lt64) | \
973 (1ULL << EF10_STAT_rx_64) | \
974 (1ULL << EF10_STAT_rx_65_to_127) | \
975 (1ULL << EF10_STAT_rx_128_to_255) | \
976 (1ULL << EF10_STAT_rx_256_to_511) | \
977 (1ULL << EF10_STAT_rx_512_to_1023) | \
978 (1ULL << EF10_STAT_rx_1024_to_15xx) | \
979 (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \
980 (1ULL << EF10_STAT_rx_gtjumbo) | \
981 (1ULL << EF10_STAT_rx_bad_gtjumbo) | \
982 (1ULL << EF10_STAT_rx_overflow) | \
Edward Creee4d112e2014-07-15 11:58:12 +0100983 (1ULL << EF10_STAT_rx_nodesc_drops) | \
984 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
985 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +0100986
987/* These statistics are only provided by the 10G MAC. For a 10G/40G
988 * switchable port we do not expose these because they might not
989 * include all the packets they should.
990 */
991#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \
992 (1ULL << EF10_STAT_tx_lt64) | \
993 (1ULL << EF10_STAT_tx_64) | \
994 (1ULL << EF10_STAT_tx_65_to_127) | \
995 (1ULL << EF10_STAT_tx_128_to_255) | \
996 (1ULL << EF10_STAT_tx_256_to_511) | \
997 (1ULL << EF10_STAT_tx_512_to_1023) | \
998 (1ULL << EF10_STAT_tx_1024_to_15xx) | \
999 (1ULL << EF10_STAT_tx_15xx_to_jumbo))
1000
1001/* These statistics are only provided by the 40G MAC. For a 10G/40G
1002 * switchable port we do expose these because the errors will otherwise
1003 * be silent.
1004 */
1005#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \
1006 (1ULL << EF10_STAT_rx_length_error))
1007
Edward Cree568d7a02013-09-25 17:32:09 +01001008/* These statistics are only provided if the firmware supports the
1009 * capability PM_AND_RXDP_COUNTERS.
1010 */
1011#define HUNT_PM_AND_RXDP_STAT_MASK ( \
1012 (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \
1013 (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \
1014 (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \
1015 (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \
1016 (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \
1017 (1ULL << EF10_STAT_rx_pm_discard_qbb) | \
1018 (1ULL << EF10_STAT_rx_pm_discard_mapping) | \
1019 (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \
1020 (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \
1021 (1ULL << EF10_STAT_rx_dp_streaming_packets) | \
Shradha Shah79ac47a2013-11-28 18:48:49 +00001022 (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \
1023 (1ULL << EF10_STAT_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001024
Edward Cree4bae9132013-09-27 18:52:49 +01001025static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001026{
Edward Cree4bae9132013-09-27 18:52:49 +01001027 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001028 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001029 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001030
1031 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001032 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001033 else
Edward Cree4bae9132013-09-27 18:52:49 +01001034 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001035
1036 if (nic_data->datapath_caps &
1037 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1038 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1039
Edward Cree4bae9132013-09-27 18:52:49 +01001040 return raw_mask;
1041}
1042
1043static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1044{
1045 u64 raw_mask = efx_ef10_raw_stat_mask(efx);
1046
1047#if BITS_PER_LONG == 64
1048 mask[0] = raw_mask;
1049#else
1050 mask[0] = raw_mask & 0xffffffff;
1051 mask[1] = raw_mask >> 32;
1052#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001053}
1054
1055static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1056{
Edward Cree4bae9132013-09-27 18:52:49 +01001057 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1058
1059 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001060 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001061 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001062}
1063
1064static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
1065{
1066 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001067 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001068 __le64 generation_start, generation_end;
1069 u64 *stats = nic_data->stats;
1070 __le64 *dma_stats;
1071
Edward Cree4bae9132013-09-27 18:52:49 +01001072 efx_ef10_get_stat_mask(efx, mask);
1073
Ben Hutchings8127d662013-08-29 19:19:29 +01001074 dma_stats = efx->stats_buffer.addr;
1075 nic_data = efx->nic_data;
1076
1077 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1078 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1079 return 0;
1080 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001081 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001082 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001083 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001084 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1085 if (generation_end != generation_start)
1086 return -EAGAIN;
1087
1088 /* Update derived statistics */
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001089 efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]);
Ben Hutchings8127d662013-08-29 19:19:29 +01001090 stats[EF10_STAT_rx_good_bytes] =
1091 stats[EF10_STAT_rx_bytes] -
1092 stats[EF10_STAT_rx_bytes_minus_good_bytes];
1093 efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes],
1094 stats[EF10_STAT_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001095 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001096 return 0;
1097}
1098
1099
1100static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats,
1101 struct rtnl_link_stats64 *core_stats)
1102{
Edward Cree4bae9132013-09-27 18:52:49 +01001103 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001104 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1105 u64 *stats = nic_data->stats;
1106 size_t stats_count = 0, index;
1107 int retry;
1108
Edward Cree4bae9132013-09-27 18:52:49 +01001109 efx_ef10_get_stat_mask(efx, mask);
1110
Ben Hutchings8127d662013-08-29 19:19:29 +01001111 /* If we're unlucky enough to read statistics during the DMA, wait
1112 * up to 10ms for it to finish (typically takes <500us)
1113 */
1114 for (retry = 0; retry < 100; ++retry) {
1115 if (efx_ef10_try_update_nic_stats(efx) == 0)
1116 break;
1117 udelay(100);
1118 }
1119
1120 if (full_stats) {
1121 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1122 if (efx_ef10_stat_desc[index].name) {
1123 *full_stats++ = stats[index];
1124 ++stats_count;
1125 }
1126 }
1127 }
1128
1129 if (core_stats) {
1130 core_stats->rx_packets = stats[EF10_STAT_rx_packets];
1131 core_stats->tx_packets = stats[EF10_STAT_tx_packets];
1132 core_stats->rx_bytes = stats[EF10_STAT_rx_bytes];
1133 core_stats->tx_bytes = stats[EF10_STAT_tx_bytes];
Edward Creee4d112e2014-07-15 11:58:12 +01001134 core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] +
1135 stats[GENERIC_STAT_rx_nodesc_trunc] +
1136 stats[GENERIC_STAT_rx_noskb_drops];
Ben Hutchings8127d662013-08-29 19:19:29 +01001137 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1138 core_stats->rx_length_errors =
1139 stats[EF10_STAT_rx_gtjumbo] +
1140 stats[EF10_STAT_rx_length_error];
1141 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1142 core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error];
1143 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1144 core_stats->rx_errors = (core_stats->rx_length_errors +
1145 core_stats->rx_crc_errors +
1146 core_stats->rx_frame_errors);
1147 }
1148
1149 return stats_count;
1150}
1151
1152static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1153{
1154 struct efx_nic *efx = channel->efx;
1155 unsigned int mode, value;
1156 efx_dword_t timer_cmd;
1157
1158 if (channel->irq_moderation) {
1159 mode = 3;
1160 value = channel->irq_moderation - 1;
1161 } else {
1162 mode = 0;
1163 value = 0;
1164 }
1165
1166 if (EFX_EF10_WORKAROUND_35388(efx)) {
1167 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1168 EFE_DD_EVQ_IND_TIMER_FLAGS,
1169 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1170 ERF_DD_EVQ_IND_TIMER_VAL, value);
1171 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1172 channel->channel);
1173 } else {
1174 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1175 ERF_DZ_TC_TIMER_VAL, value);
1176 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1177 channel->channel);
1178 }
1179}
1180
Shradha Shah02246a72015-05-06 00:58:14 +01001181static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1182 struct ethtool_wolinfo *wol) {}
1183
1184static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1185{
1186 return -EOPNOTSUPP;
1187}
1188
Ben Hutchings8127d662013-08-29 19:19:29 +01001189static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1190{
1191 wol->supported = 0;
1192 wol->wolopts = 0;
1193 memset(&wol->sopass, 0, sizeof(wol->sopass));
1194}
1195
1196static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1197{
1198 if (type != 0)
1199 return -EINVAL;
1200 return 0;
1201}
1202
1203static void efx_ef10_mcdi_request(struct efx_nic *efx,
1204 const efx_dword_t *hdr, size_t hdr_len,
1205 const efx_dword_t *sdu, size_t sdu_len)
1206{
1207 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1208 u8 *pdu = nic_data->mcdi_buf.addr;
1209
1210 memcpy(pdu, hdr, hdr_len);
1211 memcpy(pdu + hdr_len, sdu, sdu_len);
1212 wmb();
1213
1214 /* The hardware provides 'low' and 'high' (doorbell) registers
1215 * for passing the 64-bit address of an MCDI request to
1216 * firmware. However the dwords are swapped by firmware. The
1217 * least significant bits of the doorbell are then 0 for all
1218 * MCDI requests due to alignment.
1219 */
1220 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1221 ER_DZ_MC_DB_LWRD);
1222 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1223 ER_DZ_MC_DB_HWRD);
1224}
1225
1226static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1227{
1228 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1229 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1230
1231 rmb();
1232 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1233}
1234
1235static void
1236efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1237 size_t offset, size_t outlen)
1238{
1239 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1240 const u8 *pdu = nic_data->mcdi_buf.addr;
1241
1242 memcpy(outbuf, pdu + offset, outlen);
1243}
1244
1245static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1246{
1247 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1248 int rc;
1249
1250 rc = efx_ef10_get_warm_boot_count(efx);
1251 if (rc < 0) {
1252 /* The firmware is presumably in the process of
1253 * rebooting. However, we are supposed to report each
1254 * reboot just once, so we must only do that once we
1255 * can read and store the updated warm boot count.
1256 */
1257 return 0;
1258 }
1259
1260 if (rc == nic_data->warm_boot_count)
1261 return 0;
1262
1263 nic_data->warm_boot_count = rc;
1264
1265 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001266 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001267
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001268 /* Driver-created vswitches and vports must be re-created */
1269 nic_data->must_probe_vswitching = true;
1270 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1271
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001272 /* The datapath firmware might have been changed */
1273 nic_data->must_check_datapath_caps = true;
1274
Ben Hutchings869070c2013-09-05 22:46:10 +01001275 /* MAC statistics have been cleared on the NIC; clear the local
1276 * statistic that we update with efx_update_diff_stat().
1277 */
1278 nic_data->stats[EF10_STAT_rx_bad_bytes] = 0;
1279
Ben Hutchings8127d662013-08-29 19:19:29 +01001280 return -EIO;
1281}
1282
1283/* Handle an MSI interrupt
1284 *
1285 * Handle an MSI hardware interrupt. This routine schedules event
1286 * queue processing. No interrupt acknowledgement cycle is necessary.
1287 * Also, we never need to check that the interrupt is for us, since
1288 * MSI interrupts cannot be shared.
1289 */
1290static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1291{
1292 struct efx_msi_context *context = dev_id;
1293 struct efx_nic *efx = context->efx;
1294
1295 netif_vdbg(efx, intr, efx->net_dev,
1296 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1297
1298 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1299 /* Note test interrupts */
1300 if (context->index == efx->irq_level)
1301 efx->last_irq_cpu = raw_smp_processor_id();
1302
1303 /* Schedule processing of the channel */
1304 efx_schedule_channel_irq(efx->channel[context->index]);
1305 }
1306
1307 return IRQ_HANDLED;
1308}
1309
1310static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1311{
1312 struct efx_nic *efx = dev_id;
1313 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1314 struct efx_channel *channel;
1315 efx_dword_t reg;
1316 u32 queues;
1317
1318 /* Read the ISR which also ACKs the interrupts */
1319 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1320 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1321
1322 if (queues == 0)
1323 return IRQ_NONE;
1324
1325 if (likely(soft_enabled)) {
1326 /* Note test interrupts */
1327 if (queues & (1U << efx->irq_level))
1328 efx->last_irq_cpu = raw_smp_processor_id();
1329
1330 efx_for_each_channel(channel, efx) {
1331 if (queues & 1)
1332 efx_schedule_channel_irq(channel);
1333 queues >>= 1;
1334 }
1335 }
1336
1337 netif_vdbg(efx, intr, efx->net_dev,
1338 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1339 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1340
1341 return IRQ_HANDLED;
1342}
1343
1344static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1345{
1346 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1347
1348 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1349
1350 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1351 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1352 inbuf, sizeof(inbuf), NULL, 0, NULL);
1353}
1354
1355static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1356{
1357 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1358 (tx_queue->ptr_mask + 1) *
1359 sizeof(efx_qword_t),
1360 GFP_KERNEL);
1361}
1362
1363/* This writes to the TX_DESC_WPTR and also pushes data */
1364static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1365 const efx_qword_t *txd)
1366{
1367 unsigned int write_ptr;
1368 efx_oword_t reg;
1369
1370 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1371 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1372 reg.qword[0] = *txd;
1373 efx_writeo_page(tx_queue->efx, &reg,
1374 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1375}
1376
1377static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1378{
1379 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1380 EFX_BUF_SIZE));
1381 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_TXQ_OUT_LEN);
1382 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1383 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1384 struct efx_channel *channel = tx_queue->channel;
1385 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001386 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001387 size_t inlen, outlen;
1388 dma_addr_t dma_addr;
1389 efx_qword_t *txd;
1390 int rc;
1391 int i;
1392
1393 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1394 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1395 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1396 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1397 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1398 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1399 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1400 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001401 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001402
1403 dma_addr = tx_queue->txd.buf.dma_addr;
1404
1405 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1406 tx_queue->queue, entries, (u64)dma_addr);
1407
1408 for (i = 0; i < entries; ++i) {
1409 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1410 dma_addr += EFX_BUF_SIZE;
1411 }
1412
1413 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1414
1415 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
1416 outbuf, sizeof(outbuf), &outlen);
1417 if (rc)
1418 goto fail;
1419
1420 /* A previous user of this TX queue might have set us up the
1421 * bomb by writing a descriptor to the TX push collector but
1422 * not the doorbell. (Each collector belongs to a port, not a
1423 * queue or function, so cannot easily be reset.) We must
1424 * attempt to push a no-op descriptor in its place.
1425 */
1426 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1427 tx_queue->insert_count = 1;
1428 txd = efx_tx_desc(tx_queue, 0);
1429 EFX_POPULATE_QWORD_4(*txd,
1430 ESF_DZ_TX_DESC_IS_OPT, true,
1431 ESF_DZ_TX_OPTION_TYPE,
1432 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1433 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1434 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1435 tx_queue->write_count = 1;
1436 wmb();
1437 efx_ef10_push_tx_desc(tx_queue, txd);
1438
1439 return;
1440
1441fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001442 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1443 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001444}
1445
1446static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1447{
1448 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
1449 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_TXQ_OUT_LEN);
1450 struct efx_nic *efx = tx_queue->efx;
1451 size_t outlen;
1452 int rc;
1453
1454 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1455 tx_queue->queue);
1456
Edward Cree1e0b8122013-05-31 18:36:12 +01001457 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001458 outbuf, sizeof(outbuf), &outlen);
1459
1460 if (rc && rc != -EALREADY)
1461 goto fail;
1462
1463 return;
1464
1465fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001466 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1467 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001468}
1469
1470static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1471{
1472 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1473}
1474
1475/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1476static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1477{
1478 unsigned int write_ptr;
1479 efx_dword_t reg;
1480
1481 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1482 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1483 efx_writed_page(tx_queue->efx, &reg,
1484 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1485}
1486
1487static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1488{
1489 unsigned int old_write_count = tx_queue->write_count;
1490 struct efx_tx_buffer *buffer;
1491 unsigned int write_ptr;
1492 efx_qword_t *txd;
1493
1494 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1495
1496 do {
1497 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1498 buffer = &tx_queue->buffer[write_ptr];
1499 txd = efx_tx_desc(tx_queue, write_ptr);
1500 ++tx_queue->write_count;
1501
1502 /* Create TX descriptor ring entry */
1503 if (buffer->flags & EFX_TX_BUF_OPTION) {
1504 *txd = buffer->option;
1505 } else {
1506 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1507 EFX_POPULATE_QWORD_3(
1508 *txd,
1509 ESF_DZ_TX_KER_CONT,
1510 buffer->flags & EFX_TX_BUF_CONT,
1511 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1512 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1513 }
1514 } while (tx_queue->write_count != tx_queue->insert_count);
1515
1516 wmb(); /* Ensure descriptors are written before they are fetched */
1517
1518 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1519 txd = efx_tx_desc(tx_queue,
1520 old_write_count & tx_queue->ptr_mask);
1521 efx_ef10_push_tx_desc(tx_queue, txd);
1522 ++tx_queue->pushes;
1523 } else {
1524 efx_ef10_notify_tx_desc(tx_queue);
1525 }
1526}
1527
Jon Cooper267c0152015-05-06 00:59:38 +01001528static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1529 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001530{
1531 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1532 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001533 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001534 size_t outlen;
1535 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001536 u32 alloc_type = exclusive ?
1537 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1538 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1539 unsigned rss_spread = exclusive ?
1540 efx->rss_spread :
1541 min(rounddown_pow_of_two(efx->rss_spread),
1542 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1543
1544 if (!exclusive && rss_spread == 1) {
1545 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1546 if (context_size)
1547 *context_size = 1;
1548 return 0;
1549 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001550
1551 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001552 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001553 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1554 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001555
1556 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1557 outbuf, sizeof(outbuf), &outlen);
1558 if (rc != 0)
1559 return rc;
1560
1561 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1562 return -EIO;
1563
1564 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1565
Jon Cooper267c0152015-05-06 00:59:38 +01001566 if (context_size)
1567 *context_size = rss_spread;
1568
Ben Hutchings8127d662013-08-29 19:19:29 +01001569 return 0;
1570}
1571
1572static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1573{
1574 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1575 int rc;
1576
1577 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1578 context);
1579
1580 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1581 NULL, 0, NULL);
1582 WARN_ON(rc != 0);
1583}
1584
Jon Cooper267c0152015-05-06 00:59:38 +01001585static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1586 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001587{
1588 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1589 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1590 int i, rc;
1591
1592 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1593 context);
1594 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1595 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1596
1597 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1598 MCDI_PTR(tablebuf,
1599 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001600 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001601
1602 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1603 sizeof(tablebuf), NULL, 0, NULL);
1604 if (rc != 0)
1605 return rc;
1606
1607 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1608 context);
1609 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1610 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1611 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1612 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1613 efx->rx_hash_key[i];
1614
1615 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1616 sizeof(keybuf), NULL, 0, NULL);
1617}
1618
1619static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1620{
1621 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1622
1623 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1624 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1625 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1626}
1627
Jon Cooper267c0152015-05-06 00:59:38 +01001628static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1629 unsigned *context_size)
1630{
1631 u32 new_rx_rss_context;
1632 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1633 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1634 false, context_size);
1635
1636 if (rc != 0)
1637 return rc;
1638
1639 nic_data->rx_rss_context = new_rx_rss_context;
1640 nic_data->rx_rss_context_exclusive = false;
1641 efx_set_default_rx_indir_table(efx);
1642 return 0;
1643}
1644
1645static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1646 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001647{
1648 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1649 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001650 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001651
Jon Cooper267c0152015-05-06 00:59:38 +01001652 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1653 !nic_data->rx_rss_context_exclusive) {
1654 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1655 true, NULL);
1656 if (rc == -EOPNOTSUPP)
1657 return rc;
1658 else if (rc != 0)
1659 goto fail1;
1660 } else {
1661 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001662 }
1663
Jon Cooper267c0152015-05-06 00:59:38 +01001664 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1665 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001666 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001667 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001668
Jon Cooper267c0152015-05-06 00:59:38 +01001669 if (nic_data->rx_rss_context != new_rx_rss_context)
1670 efx_ef10_rx_free_indir_table(efx);
1671 nic_data->rx_rss_context = new_rx_rss_context;
1672 nic_data->rx_rss_context_exclusive = true;
1673 if (rx_indir_table != efx->rx_indir_table)
1674 memcpy(efx->rx_indir_table, rx_indir_table,
1675 sizeof(efx->rx_indir_table));
1676 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001677
Jon Cooper267c0152015-05-06 00:59:38 +01001678fail2:
1679 if (new_rx_rss_context != nic_data->rx_rss_context)
1680 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1681fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001682 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001683 return rc;
1684}
1685
1686static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1687 const u32 *rx_indir_table)
1688{
1689 int rc;
1690
1691 if (efx->rss_spread == 1)
1692 return 0;
1693
1694 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1695
1696 if (rc == -ENOBUFS && !user) {
1697 unsigned context_size;
1698 bool mismatch = false;
1699 size_t i;
1700
1701 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1702 i++)
1703 mismatch = rx_indir_table[i] !=
1704 ethtool_rxfh_indir_default(i, efx->rss_spread);
1705
1706 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1707 if (rc == 0) {
1708 if (context_size != efx->rss_spread)
1709 netif_warn(efx, probe, efx->net_dev,
1710 "Could not allocate an exclusive RSS"
1711 " context; allocated a shared one of"
1712 " different size."
1713 " Wanted %u, got %u.\n",
1714 efx->rss_spread, context_size);
1715 else if (mismatch)
1716 netif_warn(efx, probe, efx->net_dev,
1717 "Could not allocate an exclusive RSS"
1718 " context; allocated a shared one but"
1719 " could not apply custom"
1720 " indirection.\n");
1721 else
1722 netif_info(efx, probe, efx->net_dev,
1723 "Could not allocate an exclusive RSS"
1724 " context; allocated a shared one.\n");
1725 }
1726 }
1727 return rc;
1728}
1729
1730static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1731 const u32 *rx_indir_table
1732 __attribute__ ((unused)))
1733{
1734 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1735
1736 if (user)
1737 return -EOPNOTSUPP;
1738 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1739 return 0;
1740 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001741}
1742
1743static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1744{
1745 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1746 (rx_queue->ptr_mask + 1) *
1747 sizeof(efx_qword_t),
1748 GFP_KERNEL);
1749}
1750
1751static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1752{
1753 MCDI_DECLARE_BUF(inbuf,
1754 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1755 EFX_BUF_SIZE));
1756 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_RXQ_OUT_LEN);
1757 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1758 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1759 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001760 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001761 size_t inlen, outlen;
1762 dma_addr_t dma_addr;
1763 int rc;
1764 int i;
1765
1766 rx_queue->scatter_n = 0;
1767 rx_queue->scatter_len = 0;
1768
1769 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1770 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1771 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1772 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1773 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001774 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1775 INIT_RXQ_IN_FLAG_PREFIX, 1,
1776 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001777 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001778 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001779
1780 dma_addr = rx_queue->rxd.buf.dma_addr;
1781
1782 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1783 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1784
1785 for (i = 0; i < entries; ++i) {
1786 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
1787 dma_addr += EFX_BUF_SIZE;
1788 }
1789
1790 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
1791
1792 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
1793 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings48ce5632013-11-01 16:42:44 +00001794 if (rc)
1795 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
1796 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01001797}
1798
1799static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
1800{
1801 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
1802 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_RXQ_OUT_LEN);
1803 struct efx_nic *efx = rx_queue->efx;
1804 size_t outlen;
1805 int rc;
1806
1807 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
1808 efx_rx_queue_index(rx_queue));
1809
Edward Cree1e0b8122013-05-31 18:36:12 +01001810 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001811 outbuf, sizeof(outbuf), &outlen);
1812
1813 if (rc && rc != -EALREADY)
1814 goto fail;
1815
1816 return;
1817
1818fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001819 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
1820 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001821}
1822
1823static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
1824{
1825 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
1826}
1827
1828/* This creates an entry in the RX descriptor queue */
1829static inline void
1830efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
1831{
1832 struct efx_rx_buffer *rx_buf;
1833 efx_qword_t *rxd;
1834
1835 rxd = efx_rx_desc(rx_queue, index);
1836 rx_buf = efx_rx_buffer(rx_queue, index);
1837 EFX_POPULATE_QWORD_2(*rxd,
1838 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
1839 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
1840}
1841
1842static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
1843{
1844 struct efx_nic *efx = rx_queue->efx;
1845 unsigned int write_count;
1846 efx_dword_t reg;
1847
1848 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
1849 write_count = rx_queue->added_count & ~7;
1850 if (rx_queue->notified_count == write_count)
1851 return;
1852
1853 do
1854 efx_ef10_build_rx_desc(
1855 rx_queue,
1856 rx_queue->notified_count & rx_queue->ptr_mask);
1857 while (++rx_queue->notified_count != write_count);
1858
1859 wmb();
1860 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
1861 write_count & rx_queue->ptr_mask);
1862 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
1863 efx_rx_queue_index(rx_queue));
1864}
1865
1866static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
1867
1868static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
1869{
1870 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1871 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
1872 efx_qword_t event;
1873
1874 EFX_POPULATE_QWORD_2(event,
1875 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
1876 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
1877
1878 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
1879
1880 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
1881 * already swapped the data to little-endian order.
1882 */
1883 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
1884 sizeof(efx_qword_t));
1885
1886 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
1887 inbuf, sizeof(inbuf), 0,
1888 efx_ef10_rx_defer_refill_complete, 0);
1889}
1890
1891static void
1892efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
1893 int rc, efx_dword_t *outbuf,
1894 size_t outlen_actual)
1895{
1896 /* nothing to do */
1897}
1898
1899static int efx_ef10_ev_probe(struct efx_channel *channel)
1900{
1901 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
1902 (channel->eventq_mask + 1) *
1903 sizeof(efx_qword_t),
1904 GFP_KERNEL);
1905}
1906
1907static int efx_ef10_ev_init(struct efx_channel *channel)
1908{
1909 MCDI_DECLARE_BUF(inbuf,
1910 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
1911 EFX_BUF_SIZE));
1912 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
1913 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
1914 struct efx_nic *efx = channel->efx;
1915 struct efx_ef10_nic_data *nic_data;
1916 bool supports_rx_merge;
1917 size_t inlen, outlen;
1918 dma_addr_t dma_addr;
1919 int rc;
1920 int i;
1921
1922 nic_data = efx->nic_data;
1923 supports_rx_merge =
1924 !!(nic_data->datapath_caps &
1925 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
1926
1927 /* Fill event queue with all ones (i.e. empty events) */
1928 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
1929
1930 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
1931 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
1932 /* INIT_EVQ expects index in vector table, not absolute */
1933 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
1934 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
1935 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
1936 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
1937 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
1938 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
1939 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
1940 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
1941 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
1942 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
1943 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
1944 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
1945 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
1946
1947 dma_addr = channel->eventq.buf.dma_addr;
1948 for (i = 0; i < entries; ++i) {
1949 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
1950 dma_addr += EFX_BUF_SIZE;
1951 }
1952
1953 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
1954
1955 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
1956 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01001957 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01001958 return rc;
1959}
1960
1961static void efx_ef10_ev_fini(struct efx_channel *channel)
1962{
1963 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
1964 MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_EVQ_OUT_LEN);
1965 struct efx_nic *efx = channel->efx;
1966 size_t outlen;
1967 int rc;
1968
1969 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
1970
Edward Cree1e0b8122013-05-31 18:36:12 +01001971 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001972 outbuf, sizeof(outbuf), &outlen);
1973
1974 if (rc && rc != -EALREADY)
1975 goto fail;
1976
1977 return;
1978
1979fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001980 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
1981 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001982}
1983
1984static void efx_ef10_ev_remove(struct efx_channel *channel)
1985{
1986 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
1987}
1988
1989static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
1990 unsigned int rx_queue_label)
1991{
1992 struct efx_nic *efx = rx_queue->efx;
1993
1994 netif_info(efx, hw, efx->net_dev,
1995 "rx event arrived on queue %d labeled as queue %u\n",
1996 efx_rx_queue_index(rx_queue), rx_queue_label);
1997
1998 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1999}
2000
2001static void
2002efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2003 unsigned int actual, unsigned int expected)
2004{
2005 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2006 struct efx_nic *efx = rx_queue->efx;
2007
2008 netif_info(efx, hw, efx->net_dev,
2009 "dropped %d events (index=%d expected=%d)\n",
2010 dropped, actual, expected);
2011
2012 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2013}
2014
2015/* partially received RX was aborted. clean up. */
2016static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2017{
2018 unsigned int rx_desc_ptr;
2019
Ben Hutchings8127d662013-08-29 19:19:29 +01002020 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2021 "scattered RX aborted (dropping %u buffers)\n",
2022 rx_queue->scatter_n);
2023
2024 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2025
2026 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2027 0, EFX_RX_PKT_DISCARD);
2028
2029 rx_queue->removed_count += rx_queue->scatter_n;
2030 rx_queue->scatter_n = 0;
2031 rx_queue->scatter_len = 0;
2032 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2033}
2034
2035static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2036 const efx_qword_t *event)
2037{
2038 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2039 unsigned int n_descs, n_packets, i;
2040 struct efx_nic *efx = channel->efx;
2041 struct efx_rx_queue *rx_queue;
2042 bool rx_cont;
2043 u16 flags = 0;
2044
2045 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2046 return 0;
2047
2048 /* Basic packet information */
2049 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2050 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2051 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2052 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2053 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2054
Ben Hutchings48ce5632013-11-01 16:42:44 +00002055 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2056 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2057 EFX_QWORD_FMT "\n",
2058 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002059
2060 rx_queue = efx_channel_get_rx_queue(channel);
2061
2062 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2063 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2064
2065 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2066 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2067
2068 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002069 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2070
Ben Hutchings8127d662013-08-29 19:19:29 +01002071 /* detect rx abort */
2072 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002073 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2074 netdev_WARN(efx->net_dev,
2075 "invalid RX abort: scatter_n=%u event="
2076 EFX_QWORD_FMT "\n",
2077 rx_queue->scatter_n,
2078 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002079 efx_ef10_handle_rx_abort(rx_queue);
2080 return 0;
2081 }
2082
Ben Hutchings92a04162013-09-24 23:21:57 +01002083 /* Check that RX completion merging is valid, i.e.
2084 * the current firmware supports it and this is a
2085 * non-scattered packet.
2086 */
2087 if (!(nic_data->datapath_caps &
2088 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2089 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002090 efx_ef10_handle_rx_bad_lbits(
2091 rx_queue, next_ptr_lbits,
2092 (rx_queue->removed_count +
2093 rx_queue->scatter_n + 1) &
2094 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2095 return 0;
2096 }
2097
2098 /* Merged completion for multiple non-scattered packets */
2099 rx_queue->scatter_n = 1;
2100 rx_queue->scatter_len = 0;
2101 n_packets = n_descs;
2102 ++channel->n_rx_merge_events;
2103 channel->n_rx_merge_packets += n_packets;
2104 flags |= EFX_RX_PKT_PREFIX_LEN;
2105 } else {
2106 ++rx_queue->scatter_n;
2107 rx_queue->scatter_len += rx_bytes;
2108 if (rx_cont)
2109 return 0;
2110 n_packets = 1;
2111 }
2112
2113 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2114 flags |= EFX_RX_PKT_DISCARD;
2115
2116 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2117 channel->n_rx_ip_hdr_chksum_err += n_packets;
2118 } else if (unlikely(EFX_QWORD_FIELD(*event,
2119 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2120 channel->n_rx_tcp_udp_chksum_err += n_packets;
2121 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2122 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2123 flags |= EFX_RX_PKT_CSUMMED;
2124 }
2125
2126 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2127 flags |= EFX_RX_PKT_TCP;
2128
2129 channel->irq_mod_score += 2 * n_packets;
2130
2131 /* Handle received packet(s) */
2132 for (i = 0; i < n_packets; i++) {
2133 efx_rx_packet(rx_queue,
2134 rx_queue->removed_count & rx_queue->ptr_mask,
2135 rx_queue->scatter_n, rx_queue->scatter_len,
2136 flags);
2137 rx_queue->removed_count += rx_queue->scatter_n;
2138 }
2139
2140 rx_queue->scatter_n = 0;
2141 rx_queue->scatter_len = 0;
2142
2143 return n_packets;
2144}
2145
2146static int
2147efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2148{
2149 struct efx_nic *efx = channel->efx;
2150 struct efx_tx_queue *tx_queue;
2151 unsigned int tx_ev_desc_ptr;
2152 unsigned int tx_ev_q_label;
2153 int tx_descs = 0;
2154
2155 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2156 return 0;
2157
2158 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2159 return 0;
2160
2161 /* Transmit completion */
2162 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2163 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2164 tx_queue = efx_channel_get_tx_queue(channel,
2165 tx_ev_q_label % EFX_TXQ_TYPES);
2166 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2167 tx_queue->ptr_mask);
2168 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2169
2170 return tx_descs;
2171}
2172
2173static void
2174efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2175{
2176 struct efx_nic *efx = channel->efx;
2177 int subcode;
2178
2179 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2180
2181 switch (subcode) {
2182 case ESE_DZ_DRV_TIMER_EV:
2183 case ESE_DZ_DRV_WAKE_UP_EV:
2184 break;
2185 case ESE_DZ_DRV_START_UP_EV:
2186 /* event queue init complete. ok. */
2187 break;
2188 default:
2189 netif_err(efx, hw, efx->net_dev,
2190 "channel %d unknown driver event type %d"
2191 " (data " EFX_QWORD_FMT ")\n",
2192 channel->channel, subcode,
2193 EFX_QWORD_VAL(*event));
2194
2195 }
2196}
2197
2198static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2199 efx_qword_t *event)
2200{
2201 struct efx_nic *efx = channel->efx;
2202 u32 subcode;
2203
2204 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2205
2206 switch (subcode) {
2207 case EFX_EF10_TEST:
2208 channel->event_test_cpu = raw_smp_processor_id();
2209 break;
2210 case EFX_EF10_REFILL:
2211 /* The queue must be empty, so we won't receive any rx
2212 * events, so efx_process_channel() won't refill the
2213 * queue. Refill it here
2214 */
Jon Coopercce28792013-10-02 11:04:14 +01002215 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002216 break;
2217 default:
2218 netif_err(efx, hw, efx->net_dev,
2219 "channel %d unknown driver event type %u"
2220 " (data " EFX_QWORD_FMT ")\n",
2221 channel->channel, (unsigned) subcode,
2222 EFX_QWORD_VAL(*event));
2223 }
2224}
2225
2226static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2227{
2228 struct efx_nic *efx = channel->efx;
2229 efx_qword_t event, *p_event;
2230 unsigned int read_ptr;
2231 int ev_code;
2232 int tx_descs = 0;
2233 int spent = 0;
2234
Eric W. Biederman75363a42014-03-14 18:11:22 -07002235 if (quota <= 0)
2236 return spent;
2237
Ben Hutchings8127d662013-08-29 19:19:29 +01002238 read_ptr = channel->eventq_read_ptr;
2239
2240 for (;;) {
2241 p_event = efx_event(channel, read_ptr);
2242 event = *p_event;
2243
2244 if (!efx_event_present(&event))
2245 break;
2246
2247 EFX_SET_QWORD(*p_event);
2248
2249 ++read_ptr;
2250
2251 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2252
2253 netif_vdbg(efx, drv, efx->net_dev,
2254 "processing event on %d " EFX_QWORD_FMT "\n",
2255 channel->channel, EFX_QWORD_VAL(event));
2256
2257 switch (ev_code) {
2258 case ESE_DZ_EV_CODE_MCDI_EV:
2259 efx_mcdi_process_event(channel, &event);
2260 break;
2261 case ESE_DZ_EV_CODE_RX_EV:
2262 spent += efx_ef10_handle_rx_event(channel, &event);
2263 if (spent >= quota) {
2264 /* XXX can we split a merged event to
2265 * avoid going over-quota?
2266 */
2267 spent = quota;
2268 goto out;
2269 }
2270 break;
2271 case ESE_DZ_EV_CODE_TX_EV:
2272 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2273 if (tx_descs > efx->txq_entries) {
2274 spent = quota;
2275 goto out;
2276 } else if (++spent == quota) {
2277 goto out;
2278 }
2279 break;
2280 case ESE_DZ_EV_CODE_DRIVER_EV:
2281 efx_ef10_handle_driver_event(channel, &event);
2282 if (++spent == quota)
2283 goto out;
2284 break;
2285 case EFX_EF10_DRVGEN_EV:
2286 efx_ef10_handle_driver_generated_event(channel, &event);
2287 break;
2288 default:
2289 netif_err(efx, hw, efx->net_dev,
2290 "channel %d unknown event type %d"
2291 " (data " EFX_QWORD_FMT ")\n",
2292 channel->channel, ev_code,
2293 EFX_QWORD_VAL(event));
2294 }
2295 }
2296
2297out:
2298 channel->eventq_read_ptr = read_ptr;
2299 return spent;
2300}
2301
2302static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2303{
2304 struct efx_nic *efx = channel->efx;
2305 efx_dword_t rptr;
2306
2307 if (EFX_EF10_WORKAROUND_35388(efx)) {
2308 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2309 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2310 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2311 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2312
2313 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2314 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2315 ERF_DD_EVQ_IND_RPTR,
2316 (channel->eventq_read_ptr &
2317 channel->eventq_mask) >>
2318 ERF_DD_EVQ_IND_RPTR_WIDTH);
2319 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2320 channel->channel);
2321 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2322 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2323 ERF_DD_EVQ_IND_RPTR,
2324 channel->eventq_read_ptr &
2325 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2326 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2327 channel->channel);
2328 } else {
2329 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2330 channel->eventq_read_ptr &
2331 channel->eventq_mask);
2332 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2333 }
2334}
2335
2336static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2337{
2338 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2339 struct efx_nic *efx = channel->efx;
2340 efx_qword_t event;
2341 int rc;
2342
2343 EFX_POPULATE_QWORD_2(event,
2344 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2345 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2346
2347 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2348
2349 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2350 * already swapped the data to little-endian order.
2351 */
2352 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2353 sizeof(efx_qword_t));
2354
2355 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2356 NULL, 0, NULL);
2357 if (rc != 0)
2358 goto fail;
2359
2360 return;
2361
2362fail:
2363 WARN_ON(true);
2364 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2365}
2366
2367void efx_ef10_handle_drain_event(struct efx_nic *efx)
2368{
2369 if (atomic_dec_and_test(&efx->active_queues))
2370 wake_up(&efx->flush_wq);
2371
2372 WARN_ON(atomic_read(&efx->active_queues) < 0);
2373}
2374
2375static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2376{
2377 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2378 struct efx_channel *channel;
2379 struct efx_tx_queue *tx_queue;
2380 struct efx_rx_queue *rx_queue;
2381 int pending;
2382
2383 /* If the MC has just rebooted, the TX/RX queues will have already been
2384 * torn down, but efx->active_queues needs to be set to zero.
2385 */
2386 if (nic_data->must_realloc_vis) {
2387 atomic_set(&efx->active_queues, 0);
2388 return 0;
2389 }
2390
2391 /* Do not attempt to write to the NIC during EEH recovery */
2392 if (efx->state != STATE_RECOVERY) {
2393 efx_for_each_channel(channel, efx) {
2394 efx_for_each_channel_rx_queue(rx_queue, channel)
2395 efx_ef10_rx_fini(rx_queue);
2396 efx_for_each_channel_tx_queue(tx_queue, channel)
2397 efx_ef10_tx_fini(tx_queue);
2398 }
2399
2400 wait_event_timeout(efx->flush_wq,
2401 atomic_read(&efx->active_queues) == 0,
2402 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2403 pending = atomic_read(&efx->active_queues);
2404 if (pending) {
2405 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2406 pending);
2407 return -ETIMEDOUT;
2408 }
2409 }
2410
2411 return 0;
2412}
2413
Edward Creee2835462014-04-16 19:27:48 +01002414static void efx_ef10_prepare_flr(struct efx_nic *efx)
2415{
2416 atomic_set(&efx->active_queues, 0);
2417}
2418
Ben Hutchings8127d662013-08-29 19:19:29 +01002419static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2420 const struct efx_filter_spec *right)
2421{
2422 if ((left->match_flags ^ right->match_flags) |
2423 ((left->flags ^ right->flags) &
2424 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2425 return false;
2426
2427 return memcmp(&left->outer_vid, &right->outer_vid,
2428 sizeof(struct efx_filter_spec) -
2429 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2430}
2431
2432static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2433{
2434 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2435 return jhash2((const u32 *)&spec->outer_vid,
2436 (sizeof(struct efx_filter_spec) -
2437 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2438 0);
2439 /* XXX should we randomise the initval? */
2440}
2441
2442/* Decide whether a filter should be exclusive or else should allow
2443 * delivery to additional recipients. Currently we decide that
2444 * filters for specific local unicast MAC and IP addresses are
2445 * exclusive.
2446 */
2447static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2448{
2449 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2450 !is_multicast_ether_addr(spec->loc_mac))
2451 return true;
2452
2453 if ((spec->match_flags &
2454 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2455 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2456 if (spec->ether_type == htons(ETH_P_IP) &&
2457 !ipv4_is_multicast(spec->loc_host[0]))
2458 return true;
2459 if (spec->ether_type == htons(ETH_P_IPV6) &&
2460 ((const u8 *)spec->loc_host)[0] != 0xff)
2461 return true;
2462 }
2463
2464 return false;
2465}
2466
2467static struct efx_filter_spec *
2468efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2469 unsigned int filter_idx)
2470{
2471 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2472 ~EFX_EF10_FILTER_FLAGS);
2473}
2474
2475static unsigned int
2476efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2477 unsigned int filter_idx)
2478{
2479 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2480}
2481
2482static void
2483efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2484 unsigned int filter_idx,
2485 const struct efx_filter_spec *spec,
2486 unsigned int flags)
2487{
2488 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2489}
2490
2491static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2492 const struct efx_filter_spec *spec,
2493 efx_dword_t *inbuf, u64 handle,
2494 bool replacing)
2495{
2496 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2497
2498 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2499
2500 if (replacing) {
2501 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2502 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2503 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2504 } else {
2505 u32 match_fields = 0;
2506
2507 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2508 efx_ef10_filter_is_exclusive(spec) ?
2509 MC_CMD_FILTER_OP_IN_OP_INSERT :
2510 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2511
2512 /* Convert match flags and values. Unlike almost
2513 * everything else in MCDI, these fields are in
2514 * network byte order.
2515 */
2516 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2517 match_fields |=
2518 is_multicast_ether_addr(spec->loc_mac) ?
2519 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2520 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2521#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2522 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2523 match_fields |= \
2524 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2525 mcdi_field ## _LBN; \
2526 BUILD_BUG_ON( \
2527 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2528 sizeof(spec->gen_field)); \
2529 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2530 &spec->gen_field, sizeof(spec->gen_field)); \
2531 }
2532 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2533 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2534 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2535 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2536 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2537 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2538 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2539 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2540 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2541 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2542#undef COPY_FIELD
2543 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2544 match_fields);
2545 }
2546
Daniel Pieczko45b24492015-05-06 00:57:14 +01002547 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002548 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2549 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2550 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2551 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002552 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002553 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2554 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002555 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2556 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2557 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002558 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2559 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2560 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2561 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2562 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2563 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2564 spec->rss_context !=
2565 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2566 spec->rss_context : nic_data->rx_rss_context);
2567}
2568
2569static int efx_ef10_filter_push(struct efx_nic *efx,
2570 const struct efx_filter_spec *spec,
2571 u64 *handle, bool replacing)
2572{
2573 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2574 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2575 int rc;
2576
2577 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2578 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2579 outbuf, sizeof(outbuf), NULL);
2580 if (rc == 0)
2581 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002582 if (rc == -ENOSPC)
2583 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002584 return rc;
2585}
2586
2587static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2588 enum efx_filter_match_flags match_flags)
2589{
2590 unsigned int match_pri;
2591
2592 for (match_pri = 0;
2593 match_pri < table->rx_match_count;
2594 match_pri++)
2595 if (table->rx_match_flags[match_pri] == match_flags)
2596 return match_pri;
2597
2598 return -EPROTONOSUPPORT;
2599}
2600
2601static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2602 struct efx_filter_spec *spec,
2603 bool replace_equal)
2604{
2605 struct efx_ef10_filter_table *table = efx->filter_state;
2606 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2607 struct efx_filter_spec *saved_spec;
2608 unsigned int match_pri, hash;
2609 unsigned int priv_flags;
2610 bool replacing = false;
2611 int ins_index = -1;
2612 DEFINE_WAIT(wait);
2613 bool is_mc_recip;
2614 s32 rc;
2615
2616 /* For now, only support RX filters */
2617 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2618 EFX_FILTER_FLAG_RX)
2619 return -EINVAL;
2620
2621 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2622 if (rc < 0)
2623 return rc;
2624 match_pri = rc;
2625
2626 hash = efx_ef10_filter_hash(spec);
2627 is_mc_recip = efx_filter_is_mc_recipient(spec);
2628 if (is_mc_recip)
2629 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2630
2631 /* Find any existing filters with the same match tuple or
2632 * else a free slot to insert at. If any of them are busy,
2633 * we have to wait and retry.
2634 */
2635 for (;;) {
2636 unsigned int depth = 1;
2637 unsigned int i;
2638
2639 spin_lock_bh(&efx->filter_lock);
2640
2641 for (;;) {
2642 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2643 saved_spec = efx_ef10_filter_entry_spec(table, i);
2644
2645 if (!saved_spec) {
2646 if (ins_index < 0)
2647 ins_index = i;
2648 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2649 if (table->entry[i].spec &
2650 EFX_EF10_FILTER_FLAG_BUSY)
2651 break;
2652 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002653 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002654 rc = -EPERM;
2655 goto out_unlock;
2656 }
2657 if (!is_mc_recip) {
2658 /* This is the only one */
2659 if (spec->priority ==
2660 saved_spec->priority &&
2661 !replace_equal) {
2662 rc = -EEXIST;
2663 goto out_unlock;
2664 }
2665 ins_index = i;
2666 goto found;
2667 } else if (spec->priority >
2668 saved_spec->priority ||
2669 (spec->priority ==
2670 saved_spec->priority &&
2671 replace_equal)) {
2672 if (ins_index < 0)
2673 ins_index = i;
2674 else
2675 __set_bit(depth, mc_rem_map);
2676 }
2677 }
2678
2679 /* Once we reach the maximum search depth, use
2680 * the first suitable slot or return -EBUSY if
2681 * there was none
2682 */
2683 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2684 if (ins_index < 0) {
2685 rc = -EBUSY;
2686 goto out_unlock;
2687 }
2688 goto found;
2689 }
2690
2691 ++depth;
2692 }
2693
2694 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2695 spin_unlock_bh(&efx->filter_lock);
2696 schedule();
2697 }
2698
2699found:
2700 /* Create a software table entry if necessary, and mark it
2701 * busy. We might yet fail to insert, but any attempt to
2702 * insert a conflicting filter while we're waiting for the
2703 * firmware must find the busy entry.
2704 */
2705 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2706 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002707 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2708 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002709 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002710 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2711 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002712 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002713 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002714 rc = ins_index;
2715 goto out_unlock;
2716 }
2717 replacing = true;
2718 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2719 } else {
2720 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2721 if (!saved_spec) {
2722 rc = -ENOMEM;
2723 goto out_unlock;
2724 }
2725 *saved_spec = *spec;
2726 priv_flags = 0;
2727 }
2728 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2729 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2730
2731 /* Mark lower-priority multicast recipients busy prior to removal */
2732 if (is_mc_recip) {
2733 unsigned int depth, i;
2734
2735 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2736 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2737 if (test_bit(depth, mc_rem_map))
2738 table->entry[i].spec |=
2739 EFX_EF10_FILTER_FLAG_BUSY;
2740 }
2741 }
2742
2743 spin_unlock_bh(&efx->filter_lock);
2744
2745 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2746 replacing);
2747
2748 /* Finalise the software table entry */
2749 spin_lock_bh(&efx->filter_lock);
2750 if (rc == 0) {
2751 if (replacing) {
2752 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002753 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2754 saved_spec->flags |=
2755 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002756 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002757 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002758 saved_spec->flags |= spec->flags;
2759 saved_spec->rss_context = spec->rss_context;
2760 saved_spec->dmaq_id = spec->dmaq_id;
2761 }
2762 } else if (!replacing) {
2763 kfree(saved_spec);
2764 saved_spec = NULL;
2765 }
2766 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2767
2768 /* Remove and finalise entries for lower-priority multicast
2769 * recipients
2770 */
2771 if (is_mc_recip) {
2772 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2773 unsigned int depth, i;
2774
2775 memset(inbuf, 0, sizeof(inbuf));
2776
2777 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2778 if (!test_bit(depth, mc_rem_map))
2779 continue;
2780
2781 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2782 saved_spec = efx_ef10_filter_entry_spec(table, i);
2783 priv_flags = efx_ef10_filter_entry_flags(table, i);
2784
2785 if (rc == 0) {
2786 spin_unlock_bh(&efx->filter_lock);
2787 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2788 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2789 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2790 table->entry[i].handle);
2791 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2792 inbuf, sizeof(inbuf),
2793 NULL, 0, NULL);
2794 spin_lock_bh(&efx->filter_lock);
2795 }
2796
2797 if (rc == 0) {
2798 kfree(saved_spec);
2799 saved_spec = NULL;
2800 priv_flags = 0;
2801 } else {
2802 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
2803 }
2804 efx_ef10_filter_set_entry(table, i, saved_spec,
2805 priv_flags);
2806 }
2807 }
2808
2809 /* If successful, return the inserted filter ID */
2810 if (rc == 0)
2811 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
2812
2813 wake_up_all(&table->waitq);
2814out_unlock:
2815 spin_unlock_bh(&efx->filter_lock);
2816 finish_wait(&table->waitq, &wait);
2817 return rc;
2818}
2819
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08002820static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002821{
2822 /* no need to do anything here on EF10 */
2823}
2824
2825/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002826 * If !by_index, remove by ID
2827 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01002828 * Filter ID may come from userland and must be range-checked.
2829 */
2830static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002831 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002832 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01002833{
2834 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2835 struct efx_ef10_filter_table *table = efx->filter_state;
2836 MCDI_DECLARE_BUF(inbuf,
2837 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2838 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2839 struct efx_filter_spec *spec;
2840 DEFINE_WAIT(wait);
2841 int rc;
2842
2843 /* Find the software table entry and mark it busy. Don't
2844 * remove it yet; any attempt to update while we're waiting
2845 * for the firmware must find the busy entry.
2846 */
2847 for (;;) {
2848 spin_lock_bh(&efx->filter_lock);
2849 if (!(table->entry[filter_idx].spec &
2850 EFX_EF10_FILTER_FLAG_BUSY))
2851 break;
2852 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2853 spin_unlock_bh(&efx->filter_lock);
2854 schedule();
2855 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002856
Ben Hutchings8127d662013-08-29 19:19:29 +01002857 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002858 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002859 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01002860 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
2861 filter_id / HUNT_FILTER_TBL_ROWS)) {
2862 rc = -ENOENT;
2863 goto out_unlock;
2864 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002865
2866 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002867 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002868 /* Just remove flags */
2869 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002870 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002871 rc = 0;
2872 goto out_unlock;
2873 }
2874
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002875 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002876 rc = -ENOENT;
2877 goto out_unlock;
2878 }
2879
Ben Hutchings8127d662013-08-29 19:19:29 +01002880 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2881 spin_unlock_bh(&efx->filter_lock);
2882
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002883 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002884 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01002885
2886 struct efx_filter_spec new_spec = *spec;
2887
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002888 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002889 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002890 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01002891 new_spec.dmaq_id = 0;
2892 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
2893 rc = efx_ef10_filter_push(efx, &new_spec,
2894 &table->entry[filter_idx].handle,
2895 true);
2896
2897 spin_lock_bh(&efx->filter_lock);
2898 if (rc == 0)
2899 *spec = new_spec;
2900 } else {
2901 /* Really remove the filter */
2902
2903 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2904 efx_ef10_filter_is_exclusive(spec) ?
2905 MC_CMD_FILTER_OP_IN_OP_REMOVE :
2906 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2907 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2908 table->entry[filter_idx].handle);
2909 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2910 inbuf, sizeof(inbuf), NULL, 0, NULL);
2911
2912 spin_lock_bh(&efx->filter_lock);
2913 if (rc == 0) {
2914 kfree(spec);
2915 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2916 }
2917 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002918
Ben Hutchings8127d662013-08-29 19:19:29 +01002919 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2920 wake_up_all(&table->waitq);
2921out_unlock:
2922 spin_unlock_bh(&efx->filter_lock);
2923 finish_wait(&table->waitq, &wait);
2924 return rc;
2925}
2926
2927static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
2928 enum efx_filter_priority priority,
2929 u32 filter_id)
2930{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002931 return efx_ef10_filter_remove_internal(efx, 1U << priority,
2932 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01002933}
2934
2935static int efx_ef10_filter_get_safe(struct efx_nic *efx,
2936 enum efx_filter_priority priority,
2937 u32 filter_id, struct efx_filter_spec *spec)
2938{
2939 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2940 struct efx_ef10_filter_table *table = efx->filter_state;
2941 const struct efx_filter_spec *saved_spec;
2942 int rc;
2943
2944 spin_lock_bh(&efx->filter_lock);
2945 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
2946 if (saved_spec && saved_spec->priority == priority &&
2947 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
2948 filter_id / HUNT_FILTER_TBL_ROWS) {
2949 *spec = *saved_spec;
2950 rc = 0;
2951 } else {
2952 rc = -ENOENT;
2953 }
2954 spin_unlock_bh(&efx->filter_lock);
2955 return rc;
2956}
2957
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002958static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01002959 enum efx_filter_priority priority)
2960{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002961 unsigned int priority_mask;
2962 unsigned int i;
2963 int rc;
2964
2965 priority_mask = (((1U << (priority + 1)) - 1) &
2966 ~(1U << EFX_FILTER_PRI_AUTO));
2967
2968 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
2969 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
2970 i, true);
2971 if (rc && rc != -ENOENT)
2972 return rc;
2973 }
2974
2975 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002976}
2977
2978static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
2979 enum efx_filter_priority priority)
2980{
2981 struct efx_ef10_filter_table *table = efx->filter_state;
2982 unsigned int filter_idx;
2983 s32 count = 0;
2984
2985 spin_lock_bh(&efx->filter_lock);
2986 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
2987 if (table->entry[filter_idx].spec &&
2988 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
2989 priority)
2990 ++count;
2991 }
2992 spin_unlock_bh(&efx->filter_lock);
2993 return count;
2994}
2995
2996static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
2997{
2998 struct efx_ef10_filter_table *table = efx->filter_state;
2999
3000 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3001}
3002
3003static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3004 enum efx_filter_priority priority,
3005 u32 *buf, u32 size)
3006{
3007 struct efx_ef10_filter_table *table = efx->filter_state;
3008 struct efx_filter_spec *spec;
3009 unsigned int filter_idx;
3010 s32 count = 0;
3011
3012 spin_lock_bh(&efx->filter_lock);
3013 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3014 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3015 if (spec && spec->priority == priority) {
3016 if (count == size) {
3017 count = -EMSGSIZE;
3018 break;
3019 }
3020 buf[count++] = (efx_ef10_filter_rx_match_pri(
3021 table, spec->match_flags) *
3022 HUNT_FILTER_TBL_ROWS +
3023 filter_idx);
3024 }
3025 }
3026 spin_unlock_bh(&efx->filter_lock);
3027 return count;
3028}
3029
3030#ifdef CONFIG_RFS_ACCEL
3031
3032static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3033
3034static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3035 struct efx_filter_spec *spec)
3036{
3037 struct efx_ef10_filter_table *table = efx->filter_state;
3038 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3039 struct efx_filter_spec *saved_spec;
3040 unsigned int hash, i, depth = 1;
3041 bool replacing = false;
3042 int ins_index = -1;
3043 u64 cookie;
3044 s32 rc;
3045
3046 /* Must be an RX filter without RSS and not for a multicast
3047 * destination address (RFS only works for connected sockets).
3048 * These restrictions allow us to pass only a tiny amount of
3049 * data through to the completion function.
3050 */
3051 EFX_WARN_ON_PARANOID(spec->flags !=
3052 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3053 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3054 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3055
3056 hash = efx_ef10_filter_hash(spec);
3057
3058 spin_lock_bh(&efx->filter_lock);
3059
3060 /* Find any existing filter with the same match tuple or else
3061 * a free slot to insert at. If an existing filter is busy,
3062 * we have to give up.
3063 */
3064 for (;;) {
3065 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3066 saved_spec = efx_ef10_filter_entry_spec(table, i);
3067
3068 if (!saved_spec) {
3069 if (ins_index < 0)
3070 ins_index = i;
3071 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3072 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3073 rc = -EBUSY;
3074 goto fail_unlock;
3075 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003076 if (spec->priority < saved_spec->priority) {
3077 rc = -EPERM;
3078 goto fail_unlock;
3079 }
3080 ins_index = i;
3081 break;
3082 }
3083
3084 /* Once we reach the maximum search depth, use the
3085 * first suitable slot or return -EBUSY if there was
3086 * none
3087 */
3088 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3089 if (ins_index < 0) {
3090 rc = -EBUSY;
3091 goto fail_unlock;
3092 }
3093 break;
3094 }
3095
3096 ++depth;
3097 }
3098
3099 /* Create a software table entry if necessary, and mark it
3100 * busy. We might yet fail to insert, but any attempt to
3101 * insert a conflicting filter while we're waiting for the
3102 * firmware must find the busy entry.
3103 */
3104 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3105 if (saved_spec) {
3106 replacing = true;
3107 } else {
3108 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3109 if (!saved_spec) {
3110 rc = -ENOMEM;
3111 goto fail_unlock;
3112 }
3113 *saved_spec = *spec;
3114 }
3115 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3116 EFX_EF10_FILTER_FLAG_BUSY);
3117
3118 spin_unlock_bh(&efx->filter_lock);
3119
3120 /* Pack up the variables needed on completion */
3121 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3122
3123 efx_ef10_filter_push_prep(efx, spec, inbuf,
3124 table->entry[ins_index].handle, replacing);
3125 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3126 MC_CMD_FILTER_OP_OUT_LEN,
3127 efx_ef10_filter_rfs_insert_complete, cookie);
3128
3129 return ins_index;
3130
3131fail_unlock:
3132 spin_unlock_bh(&efx->filter_lock);
3133 return rc;
3134}
3135
3136static void
3137efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3138 int rc, efx_dword_t *outbuf,
3139 size_t outlen_actual)
3140{
3141 struct efx_ef10_filter_table *table = efx->filter_state;
3142 unsigned int ins_index, dmaq_id;
3143 struct efx_filter_spec *spec;
3144 bool replacing;
3145
3146 /* Unpack the cookie */
3147 replacing = cookie >> 31;
3148 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3149 dmaq_id = cookie & 0xffff;
3150
3151 spin_lock_bh(&efx->filter_lock);
3152 spec = efx_ef10_filter_entry_spec(table, ins_index);
3153 if (rc == 0) {
3154 table->entry[ins_index].handle =
3155 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3156 if (replacing)
3157 spec->dmaq_id = dmaq_id;
3158 } else if (!replacing) {
3159 kfree(spec);
3160 spec = NULL;
3161 }
3162 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3163 spin_unlock_bh(&efx->filter_lock);
3164
3165 wake_up_all(&table->waitq);
3166}
3167
3168static void
3169efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3170 unsigned long filter_idx,
3171 int rc, efx_dword_t *outbuf,
3172 size_t outlen_actual);
3173
3174static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3175 unsigned int filter_idx)
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 MCDI_DECLARE_BUF(inbuf,
3181 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3182 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3183
3184 if (!spec ||
3185 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3186 spec->priority != EFX_FILTER_PRI_HINT ||
3187 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3188 flow_id, filter_idx))
3189 return false;
3190
3191 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3192 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3193 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3194 table->entry[filter_idx].handle);
3195 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3196 efx_ef10_filter_rfs_expire_complete, filter_idx))
3197 return false;
3198
3199 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3200 return true;
3201}
3202
3203static void
3204efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3205 unsigned long filter_idx,
3206 int rc, efx_dword_t *outbuf,
3207 size_t outlen_actual)
3208{
3209 struct efx_ef10_filter_table *table = efx->filter_state;
3210 struct efx_filter_spec *spec =
3211 efx_ef10_filter_entry_spec(table, filter_idx);
3212
3213 spin_lock_bh(&efx->filter_lock);
3214 if (rc == 0) {
3215 kfree(spec);
3216 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3217 }
3218 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3219 wake_up_all(&table->waitq);
3220 spin_unlock_bh(&efx->filter_lock);
3221}
3222
3223#endif /* CONFIG_RFS_ACCEL */
3224
3225static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3226{
3227 int match_flags = 0;
3228
3229#define MAP_FLAG(gen_flag, mcdi_field) { \
3230 u32 old_mcdi_flags = mcdi_flags; \
3231 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3232 mcdi_field ## _LBN); \
3233 if (mcdi_flags != old_mcdi_flags) \
3234 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3235 }
3236 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3237 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3238 MAP_FLAG(REM_HOST, SRC_IP);
3239 MAP_FLAG(LOC_HOST, DST_IP);
3240 MAP_FLAG(REM_MAC, SRC_MAC);
3241 MAP_FLAG(REM_PORT, SRC_PORT);
3242 MAP_FLAG(LOC_MAC, DST_MAC);
3243 MAP_FLAG(LOC_PORT, DST_PORT);
3244 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3245 MAP_FLAG(INNER_VID, INNER_VLAN);
3246 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3247 MAP_FLAG(IP_PROTO, IP_PROTO);
3248#undef MAP_FLAG
3249
3250 /* Did we map them all? */
3251 if (mcdi_flags)
3252 return -EINVAL;
3253
3254 return match_flags;
3255}
3256
3257static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3258{
3259 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3260 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3261 unsigned int pd_match_pri, pd_match_count;
3262 struct efx_ef10_filter_table *table;
3263 size_t outlen;
3264 int rc;
3265
3266 table = kzalloc(sizeof(*table), GFP_KERNEL);
3267 if (!table)
3268 return -ENOMEM;
3269
3270 /* Find out which RX filter types are supported, and their priorities */
3271 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3272 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3273 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3274 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3275 &outlen);
3276 if (rc)
3277 goto fail;
3278 pd_match_count = MCDI_VAR_ARRAY_LEN(
3279 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3280 table->rx_match_count = 0;
3281
3282 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3283 u32 mcdi_flags =
3284 MCDI_ARRAY_DWORD(
3285 outbuf,
3286 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3287 pd_match_pri);
3288 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3289 if (rc < 0) {
3290 netif_dbg(efx, probe, efx->net_dev,
3291 "%s: fw flags %#x pri %u not supported in driver\n",
3292 __func__, mcdi_flags, pd_match_pri);
3293 } else {
3294 netif_dbg(efx, probe, efx->net_dev,
3295 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3296 __func__, mcdi_flags, pd_match_pri,
3297 rc, table->rx_match_count);
3298 table->rx_match_flags[table->rx_match_count++] = rc;
3299 }
3300 }
3301
3302 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3303 if (!table->entry) {
3304 rc = -ENOMEM;
3305 goto fail;
3306 }
3307
3308 efx->filter_state = table;
3309 init_waitqueue_head(&table->waitq);
3310 return 0;
3311
3312fail:
3313 kfree(table);
3314 return rc;
3315}
3316
Edward Cree0d322412015-05-20 11:10:03 +01003317/* Caller must hold efx->filter_sem for read if race against
3318 * efx_ef10_filter_table_remove() is possible
3319 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003320static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3321{
3322 struct efx_ef10_filter_table *table = efx->filter_state;
3323 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3324 struct efx_filter_spec *spec;
3325 unsigned int filter_idx;
3326 bool failed = false;
3327 int rc;
3328
Edward Cree0d322412015-05-20 11:10:03 +01003329 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3330
Ben Hutchings8127d662013-08-29 19:19:29 +01003331 if (!nic_data->must_restore_filters)
3332 return;
3333
Edward Cree0d322412015-05-20 11:10:03 +01003334 if (!table)
3335 return;
3336
Ben Hutchings8127d662013-08-29 19:19:29 +01003337 spin_lock_bh(&efx->filter_lock);
3338
3339 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3340 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3341 if (!spec)
3342 continue;
3343
3344 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3345 spin_unlock_bh(&efx->filter_lock);
3346
3347 rc = efx_ef10_filter_push(efx, spec,
3348 &table->entry[filter_idx].handle,
3349 false);
3350 if (rc)
3351 failed = true;
3352
3353 spin_lock_bh(&efx->filter_lock);
3354 if (rc) {
3355 kfree(spec);
3356 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3357 } else {
3358 table->entry[filter_idx].spec &=
3359 ~EFX_EF10_FILTER_FLAG_BUSY;
3360 }
3361 }
3362
3363 spin_unlock_bh(&efx->filter_lock);
3364
3365 if (failed)
3366 netif_err(efx, hw, efx->net_dev,
3367 "unable to restore all filters\n");
3368 else
3369 nic_data->must_restore_filters = false;
3370}
3371
Edward Cree0d322412015-05-20 11:10:03 +01003372/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003373static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3374{
3375 struct efx_ef10_filter_table *table = efx->filter_state;
3376 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3377 struct efx_filter_spec *spec;
3378 unsigned int filter_idx;
3379 int rc;
3380
Edward Cree0d322412015-05-20 11:10:03 +01003381 efx->filter_state = NULL;
3382 if (!table)
3383 return;
3384
Ben Hutchings8127d662013-08-29 19:19:29 +01003385 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3386 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3387 if (!spec)
3388 continue;
3389
3390 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3391 efx_ef10_filter_is_exclusive(spec) ?
3392 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3393 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3394 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3395 table->entry[filter_idx].handle);
3396 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3397 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003398 if (rc)
3399 netdev_WARN(efx->net_dev,
3400 "filter_idx=%#x handle=%#llx\n",
3401 filter_idx,
3402 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003403 kfree(spec);
3404 }
3405
3406 vfree(table->entry);
3407 kfree(table);
3408}
3409
Edward Cree0d322412015-05-20 11:10:03 +01003410/* Caller must hold efx->filter_sem for read if race against
3411 * efx_ef10_filter_table_remove() is possible
3412 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003413static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3414{
3415 struct efx_ef10_filter_table *table = efx->filter_state;
3416 struct net_device *net_dev = efx->net_dev;
3417 struct efx_filter_spec spec;
3418 bool remove_failed = false;
3419 struct netdev_hw_addr *uc;
3420 struct netdev_hw_addr *mc;
3421 unsigned int filter_idx;
3422 int i, n, rc;
3423
3424 if (!efx_dev_registered(efx))
3425 return;
3426
Edward Cree0d322412015-05-20 11:10:03 +01003427 if (!table)
3428 return;
3429
Ben Hutchings8127d662013-08-29 19:19:29 +01003430 /* Mark old filters that may need to be removed */
3431 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003432 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003433 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003434 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3435 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003436 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003437 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003438 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003439 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3440 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003441 }
3442 spin_unlock_bh(&efx->filter_lock);
3443
3444 /* Copy/convert the address lists; add the primary station
3445 * address and broadcast address
3446 */
3447 netif_addr_lock_bh(net_dev);
3448 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003449 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3450 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003451 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003452 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003453 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003454 i = 1;
3455 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003456 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003457 i++;
3458 }
3459 }
3460 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003461 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3462 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003463 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003464 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3465 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003466 i = 1;
3467 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003468 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003469 i++;
3470 }
3471 }
3472 netif_addr_unlock_bh(net_dev);
3473
3474 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003475 if (table->dev_uc_count >= 0) {
3476 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003477 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3478 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003479 0);
3480 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003481 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003482 rc = efx_ef10_filter_insert(efx, &spec, true);
3483 if (rc < 0) {
3484 /* Fall back to unicast-promisc */
3485 while (i--)
3486 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003487 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003488 table->dev_uc_list[i].id);
3489 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003490 break;
3491 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003492 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003493 }
3494 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003495 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003496 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3497 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003498 0);
3499 efx_filter_set_uc_def(&spec);
3500 rc = efx_ef10_filter_insert(efx, &spec, true);
3501 if (rc < 0) {
3502 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003503 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003504 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003505 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003506 }
3507 }
3508
3509 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003510 if (table->dev_mc_count >= 0) {
3511 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003512 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3513 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003514 0);
3515 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003516 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003517 rc = efx_ef10_filter_insert(efx, &spec, true);
3518 if (rc < 0) {
3519 /* Fall back to multicast-promisc */
3520 while (i--)
3521 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003522 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003523 table->dev_mc_list[i].id);
3524 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003525 break;
3526 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003527 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003528 }
3529 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003530 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003531 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3532 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003533 0);
3534 efx_filter_set_mc_def(&spec);
3535 rc = efx_ef10_filter_insert(efx, &spec, true);
3536 if (rc < 0) {
3537 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003538 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003539 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003540 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003541 }
3542 }
3543
3544 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003545 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003546 * don't need to hold the filter_lock while scanning for
3547 * these filters.
3548 */
3549 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3550 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003551 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003552 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003553 efx, 1U << EFX_FILTER_PRI_AUTO,
3554 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003555 remove_failed = true;
3556 }
3557 }
3558 WARN_ON(remove_failed);
3559}
3560
3561static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3562{
3563 efx_ef10_filter_sync_rx_mode(efx);
3564
3565 return efx_mcdi_set_mac(efx);
3566}
3567
Shradha Shah862f8942015-05-20 11:08:56 +01003568static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3569{
3570 efx_ef10_filter_sync_rx_mode(efx);
3571
3572 return 0;
3573}
3574
Jon Cooper74cd60a2013-09-16 14:18:51 +01003575static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3576{
3577 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3578
3579 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3580 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3581 NULL, 0, NULL);
3582}
3583
3584/* MC BISTs follow a different poll mechanism to phy BISTs.
3585 * The BIST is done in the poll handler on the MC, and the MCDI command
3586 * will block until the BIST is done.
3587 */
3588static int efx_ef10_poll_bist(struct efx_nic *efx)
3589{
3590 int rc;
3591 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3592 size_t outlen;
3593 u32 result;
3594
3595 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3596 outbuf, sizeof(outbuf), &outlen);
3597 if (rc != 0)
3598 return rc;
3599
3600 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3601 return -EIO;
3602
3603 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3604 switch (result) {
3605 case MC_CMD_POLL_BIST_PASSED:
3606 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3607 return 0;
3608 case MC_CMD_POLL_BIST_TIMEOUT:
3609 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3610 return -EIO;
3611 case MC_CMD_POLL_BIST_FAILED:
3612 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3613 return -EIO;
3614 default:
3615 netif_err(efx, hw, efx->net_dev,
3616 "BIST returned unknown result %u", result);
3617 return -EIO;
3618 }
3619}
3620
3621static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3622{
3623 int rc;
3624
3625 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3626
3627 rc = efx_ef10_start_bist(efx, bist_type);
3628 if (rc != 0)
3629 return rc;
3630
3631 return efx_ef10_poll_bist(efx);
3632}
3633
3634static int
3635efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3636{
3637 int rc, rc2;
3638
3639 efx_reset_down(efx, RESET_TYPE_WORLD);
3640
3641 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3642 NULL, 0, NULL, 0, NULL);
3643 if (rc != 0)
3644 goto out;
3645
3646 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3647 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3648
3649 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3650
3651out:
3652 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3653 return rc ? rc : rc2;
3654}
3655
Ben Hutchings8127d662013-08-29 19:19:29 +01003656#ifdef CONFIG_SFC_MTD
3657
3658struct efx_ef10_nvram_type_info {
3659 u16 type, type_mask;
3660 u8 port;
3661 const char *name;
3662};
3663
3664static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3665 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3666 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3667 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3668 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3669 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3670 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3671 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3672 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3673 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003674 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003675 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3676};
3677
3678static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3679 struct efx_mcdi_mtd_partition *part,
3680 unsigned int type)
3681{
3682 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3683 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3684 const struct efx_ef10_nvram_type_info *info;
3685 size_t size, erase_size, outlen;
3686 bool protected;
3687 int rc;
3688
3689 for (info = efx_ef10_nvram_types; ; info++) {
3690 if (info ==
3691 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3692 return -ENODEV;
3693 if ((type & ~info->type_mask) == info->type)
3694 break;
3695 }
3696 if (info->port != efx_port_num(efx))
3697 return -ENODEV;
3698
3699 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3700 if (rc)
3701 return rc;
3702 if (protected)
3703 return -ENODEV; /* hide it */
3704
3705 part->nvram_type = type;
3706
3707 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3708 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3709 outbuf, sizeof(outbuf), &outlen);
3710 if (rc)
3711 return rc;
3712 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3713 return -EIO;
3714 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3715 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3716 part->fw_subtype = MCDI_DWORD(outbuf,
3717 NVRAM_METADATA_OUT_SUBTYPE);
3718
3719 part->common.dev_type_name = "EF10 NVRAM manager";
3720 part->common.type_name = info->name;
3721
3722 part->common.mtd.type = MTD_NORFLASH;
3723 part->common.mtd.flags = MTD_CAP_NORFLASH;
3724 part->common.mtd.size = size;
3725 part->common.mtd.erasesize = erase_size;
3726
3727 return 0;
3728}
3729
3730static int efx_ef10_mtd_probe(struct efx_nic *efx)
3731{
3732 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
3733 struct efx_mcdi_mtd_partition *parts;
3734 size_t outlen, n_parts_total, i, n_parts;
3735 unsigned int type;
3736 int rc;
3737
3738 ASSERT_RTNL();
3739
3740 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
3741 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
3742 outbuf, sizeof(outbuf), &outlen);
3743 if (rc)
3744 return rc;
3745 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
3746 return -EIO;
3747
3748 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
3749 if (n_parts_total >
3750 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
3751 return -EIO;
3752
3753 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
3754 if (!parts)
3755 return -ENOMEM;
3756
3757 n_parts = 0;
3758 for (i = 0; i < n_parts_total; i++) {
3759 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
3760 i);
3761 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
3762 if (rc == 0)
3763 n_parts++;
3764 else if (rc != -ENODEV)
3765 goto fail;
3766 }
3767
3768 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
3769fail:
3770 if (rc)
3771 kfree(parts);
3772 return rc;
3773}
3774
3775#endif /* CONFIG_SFC_MTD */
3776
3777static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
3778{
3779 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
3780}
3781
Shradha Shah02246a72015-05-06 00:58:14 +01003782static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
3783 u32 host_time) {}
3784
Jon Cooperbd9a2652013-11-18 12:54:41 +00003785static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
3786 bool temp)
3787{
3788 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
3789 int rc;
3790
3791 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
3792 channel->sync_events_state == SYNC_EVENTS_VALID ||
3793 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
3794 return 0;
3795 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
3796
3797 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
3798 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3799 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
3800 channel->channel);
3801
3802 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3803 inbuf, sizeof(inbuf), NULL, 0, NULL);
3804
3805 if (rc != 0)
3806 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3807 SYNC_EVENTS_DISABLED;
3808
3809 return rc;
3810}
3811
3812static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
3813 bool temp)
3814{
3815 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
3816 int rc;
3817
3818 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
3819 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
3820 return 0;
3821 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
3822 channel->sync_events_state = SYNC_EVENTS_DISABLED;
3823 return 0;
3824 }
3825 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3826 SYNC_EVENTS_DISABLED;
3827
3828 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
3829 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3830 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
3831 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
3832 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
3833 channel->channel);
3834
3835 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3836 inbuf, sizeof(inbuf), NULL, 0, NULL);
3837
3838 return rc;
3839}
3840
3841static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
3842 bool temp)
3843{
3844 int (*set)(struct efx_channel *channel, bool temp);
3845 struct efx_channel *channel;
3846
3847 set = en ?
3848 efx_ef10_rx_enable_timestamping :
3849 efx_ef10_rx_disable_timestamping;
3850
3851 efx_for_each_channel(channel, efx) {
3852 int rc = set(channel, temp);
3853 if (en && rc != 0) {
3854 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
3855 return rc;
3856 }
3857 }
3858
3859 return 0;
3860}
3861
Shradha Shah02246a72015-05-06 00:58:14 +01003862static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
3863 struct hwtstamp_config *init)
3864{
3865 return -EOPNOTSUPP;
3866}
3867
Jon Cooperbd9a2652013-11-18 12:54:41 +00003868static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
3869 struct hwtstamp_config *init)
3870{
3871 int rc;
3872
3873 switch (init->rx_filter) {
3874 case HWTSTAMP_FILTER_NONE:
3875 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
3876 /* if TX timestamping is still requested then leave PTP on */
3877 return efx_ptp_change_mode(efx,
3878 init->tx_type != HWTSTAMP_TX_OFF, 0);
3879 case HWTSTAMP_FILTER_ALL:
3880 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3881 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3882 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3883 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3884 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3885 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3886 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3887 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3888 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3889 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3890 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3891 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3892 init->rx_filter = HWTSTAMP_FILTER_ALL;
3893 rc = efx_ptp_change_mode(efx, true, 0);
3894 if (!rc)
3895 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
3896 if (rc)
3897 efx_ptp_change_mode(efx, false, 0);
3898 return rc;
3899 default:
3900 return -ERANGE;
3901 }
3902}
3903
Shradha Shah02246a72015-05-06 00:58:14 +01003904const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01003905 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01003906 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01003907 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01003908 .probe = efx_ef10_probe_vf,
3909 .remove = efx_ef10_remove,
3910 .dimension_resources = efx_ef10_dimension_resources,
3911 .init = efx_ef10_init_nic,
3912 .fini = efx_port_dummy_op_void,
3913 .map_reset_reason = efx_mcdi_map_reset_reason,
3914 .map_reset_flags = efx_ef10_map_reset_flags,
3915 .reset = efx_ef10_reset,
3916 .probe_port = efx_mcdi_port_probe,
3917 .remove_port = efx_mcdi_port_remove,
3918 .fini_dmaq = efx_ef10_fini_dmaq,
3919 .prepare_flr = efx_ef10_prepare_flr,
3920 .finish_flr = efx_port_dummy_op_void,
3921 .describe_stats = efx_ef10_describe_stats,
3922 .update_stats = efx_ef10_update_stats,
3923 .start_stats = efx_port_dummy_op_void,
3924 .pull_stats = efx_port_dummy_op_void,
3925 .stop_stats = efx_port_dummy_op_void,
3926 .set_id_led = efx_mcdi_set_id_led,
3927 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01003928 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01003929 .check_mac_fault = efx_mcdi_mac_check_fault,
3930 .reconfigure_port = efx_mcdi_port_reconfigure,
3931 .get_wol = efx_ef10_get_wol_vf,
3932 .set_wol = efx_ef10_set_wol_vf,
3933 .resume_wol = efx_port_dummy_op_void,
3934 .mcdi_request = efx_ef10_mcdi_request,
3935 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
3936 .mcdi_read_response = efx_ef10_mcdi_read_response,
3937 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
3938 .irq_enable_master = efx_port_dummy_op_void,
3939 .irq_test_generate = efx_ef10_irq_test_generate,
3940 .irq_disable_non_ev = efx_port_dummy_op_void,
3941 .irq_handle_msi = efx_ef10_msi_interrupt,
3942 .irq_handle_legacy = efx_ef10_legacy_interrupt,
3943 .tx_probe = efx_ef10_tx_probe,
3944 .tx_init = efx_ef10_tx_init,
3945 .tx_remove = efx_ef10_tx_remove,
3946 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01003947 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01003948 .rx_probe = efx_ef10_rx_probe,
3949 .rx_init = efx_ef10_rx_init,
3950 .rx_remove = efx_ef10_rx_remove,
3951 .rx_write = efx_ef10_rx_write,
3952 .rx_defer_refill = efx_ef10_rx_defer_refill,
3953 .ev_probe = efx_ef10_ev_probe,
3954 .ev_init = efx_ef10_ev_init,
3955 .ev_fini = efx_ef10_ev_fini,
3956 .ev_remove = efx_ef10_ev_remove,
3957 .ev_process = efx_ef10_ev_process,
3958 .ev_read_ack = efx_ef10_ev_read_ack,
3959 .ev_test_generate = efx_ef10_ev_test_generate,
3960 .filter_table_probe = efx_ef10_filter_table_probe,
3961 .filter_table_restore = efx_ef10_filter_table_restore,
3962 .filter_table_remove = efx_ef10_filter_table_remove,
3963 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
3964 .filter_insert = efx_ef10_filter_insert,
3965 .filter_remove_safe = efx_ef10_filter_remove_safe,
3966 .filter_get_safe = efx_ef10_filter_get_safe,
3967 .filter_clear_rx = efx_ef10_filter_clear_rx,
3968 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
3969 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
3970 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
3971#ifdef CONFIG_RFS_ACCEL
3972 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
3973 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
3974#endif
3975#ifdef CONFIG_SFC_MTD
3976 .mtd_probe = efx_port_dummy_op_int,
3977#endif
3978 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
3979 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
3980#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01003981 .vswitching_probe = efx_ef10_vswitching_probe_vf,
3982 .vswitching_restore = efx_ef10_vswitching_restore_vf,
3983 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01003984#endif
3985 .revision = EFX_REV_HUNT_A0,
3986 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
3987 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
3988 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
3989 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
3990 .can_rx_scatter = true,
3991 .always_rx_scatter = true,
3992 .max_interrupt_mode = EFX_INT_MODE_MSIX,
3993 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
3994 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3995 NETIF_F_RXHASH | NETIF_F_NTUPLE),
3996 .mcdi_max_ver = 2,
3997 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
3998 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
3999 1 << HWTSTAMP_FILTER_ALL,
4000};
4001
4002const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004003 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004004 .mem_bar = EFX_MEM_BAR,
4005 .mem_map_size = efx_ef10_mem_map_size,
4006 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004007 .remove = efx_ef10_remove,
4008 .dimension_resources = efx_ef10_dimension_resources,
4009 .init = efx_ef10_init_nic,
4010 .fini = efx_port_dummy_op_void,
4011 .map_reset_reason = efx_mcdi_map_reset_reason,
4012 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004013 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004014 .probe_port = efx_mcdi_port_probe,
4015 .remove_port = efx_mcdi_port_remove,
4016 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004017 .prepare_flr = efx_ef10_prepare_flr,
4018 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004019 .describe_stats = efx_ef10_describe_stats,
4020 .update_stats = efx_ef10_update_stats,
4021 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004022 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004023 .stop_stats = efx_mcdi_mac_stop_stats,
4024 .set_id_led = efx_mcdi_set_id_led,
4025 .push_irq_moderation = efx_ef10_push_irq_moderation,
4026 .reconfigure_mac = efx_ef10_mac_reconfigure,
4027 .check_mac_fault = efx_mcdi_mac_check_fault,
4028 .reconfigure_port = efx_mcdi_port_reconfigure,
4029 .get_wol = efx_ef10_get_wol,
4030 .set_wol = efx_ef10_set_wol,
4031 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004032 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004033 .test_nvram = efx_mcdi_nvram_test_all,
4034 .mcdi_request = efx_ef10_mcdi_request,
4035 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4036 .mcdi_read_response = efx_ef10_mcdi_read_response,
4037 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4038 .irq_enable_master = efx_port_dummy_op_void,
4039 .irq_test_generate = efx_ef10_irq_test_generate,
4040 .irq_disable_non_ev = efx_port_dummy_op_void,
4041 .irq_handle_msi = efx_ef10_msi_interrupt,
4042 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4043 .tx_probe = efx_ef10_tx_probe,
4044 .tx_init = efx_ef10_tx_init,
4045 .tx_remove = efx_ef10_tx_remove,
4046 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004047 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004048 .rx_probe = efx_ef10_rx_probe,
4049 .rx_init = efx_ef10_rx_init,
4050 .rx_remove = efx_ef10_rx_remove,
4051 .rx_write = efx_ef10_rx_write,
4052 .rx_defer_refill = efx_ef10_rx_defer_refill,
4053 .ev_probe = efx_ef10_ev_probe,
4054 .ev_init = efx_ef10_ev_init,
4055 .ev_fini = efx_ef10_ev_fini,
4056 .ev_remove = efx_ef10_ev_remove,
4057 .ev_process = efx_ef10_ev_process,
4058 .ev_read_ack = efx_ef10_ev_read_ack,
4059 .ev_test_generate = efx_ef10_ev_test_generate,
4060 .filter_table_probe = efx_ef10_filter_table_probe,
4061 .filter_table_restore = efx_ef10_filter_table_restore,
4062 .filter_table_remove = efx_ef10_filter_table_remove,
4063 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4064 .filter_insert = efx_ef10_filter_insert,
4065 .filter_remove_safe = efx_ef10_filter_remove_safe,
4066 .filter_get_safe = efx_ef10_filter_get_safe,
4067 .filter_clear_rx = efx_ef10_filter_clear_rx,
4068 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4069 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4070 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4071#ifdef CONFIG_RFS_ACCEL
4072 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4073 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4074#endif
4075#ifdef CONFIG_SFC_MTD
4076 .mtd_probe = efx_ef10_mtd_probe,
4077 .mtd_rename = efx_mcdi_mtd_rename,
4078 .mtd_read = efx_mcdi_mtd_read,
4079 .mtd_erase = efx_mcdi_mtd_erase,
4080 .mtd_write = efx_mcdi_mtd_write,
4081 .mtd_sync = efx_mcdi_mtd_sync,
4082#endif
4083 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004084 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4085 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004086#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004087 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004088 .sriov_init = efx_ef10_sriov_init,
4089 .sriov_fini = efx_ef10_sriov_fini,
4090 .sriov_mac_address_changed = efx_ef10_sriov_mac_address_changed,
4091 .sriov_wanted = efx_ef10_sriov_wanted,
4092 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004093 .sriov_flr = efx_ef10_sriov_flr,
4094 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4095 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4096 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4097 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004098 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4099 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4100 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004101#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01004102
4103 .revision = EFX_REV_HUNT_A0,
4104 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4105 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4106 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004107 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004108 .can_rx_scatter = true,
4109 .always_rx_scatter = true,
4110 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4111 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4112 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4113 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4114 .mcdi_max_ver = 2,
4115 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004116 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4117 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004118};