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