blob: e8450bbd292d6071b61609055df99b6fc4dc493a [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);
2295 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2296 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002297 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2298 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2299 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002300 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2301 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2302 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2303 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2304 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2305 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2306 spec->rss_context !=
2307 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2308 spec->rss_context : nic_data->rx_rss_context);
2309}
2310
2311static int efx_ef10_filter_push(struct efx_nic *efx,
2312 const struct efx_filter_spec *spec,
2313 u64 *handle, bool replacing)
2314{
2315 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2316 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2317 int rc;
2318
2319 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2320 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2321 outbuf, sizeof(outbuf), NULL);
2322 if (rc == 0)
2323 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002324 if (rc == -ENOSPC)
2325 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002326 return rc;
2327}
2328
2329static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2330 enum efx_filter_match_flags match_flags)
2331{
2332 unsigned int match_pri;
2333
2334 for (match_pri = 0;
2335 match_pri < table->rx_match_count;
2336 match_pri++)
2337 if (table->rx_match_flags[match_pri] == match_flags)
2338 return match_pri;
2339
2340 return -EPROTONOSUPPORT;
2341}
2342
2343static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2344 struct efx_filter_spec *spec,
2345 bool replace_equal)
2346{
2347 struct efx_ef10_filter_table *table = efx->filter_state;
2348 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2349 struct efx_filter_spec *saved_spec;
2350 unsigned int match_pri, hash;
2351 unsigned int priv_flags;
2352 bool replacing = false;
2353 int ins_index = -1;
2354 DEFINE_WAIT(wait);
2355 bool is_mc_recip;
2356 s32 rc;
2357
2358 /* For now, only support RX filters */
2359 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2360 EFX_FILTER_FLAG_RX)
2361 return -EINVAL;
2362
2363 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2364 if (rc < 0)
2365 return rc;
2366 match_pri = rc;
2367
2368 hash = efx_ef10_filter_hash(spec);
2369 is_mc_recip = efx_filter_is_mc_recipient(spec);
2370 if (is_mc_recip)
2371 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2372
2373 /* Find any existing filters with the same match tuple or
2374 * else a free slot to insert at. If any of them are busy,
2375 * we have to wait and retry.
2376 */
2377 for (;;) {
2378 unsigned int depth = 1;
2379 unsigned int i;
2380
2381 spin_lock_bh(&efx->filter_lock);
2382
2383 for (;;) {
2384 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2385 saved_spec = efx_ef10_filter_entry_spec(table, i);
2386
2387 if (!saved_spec) {
2388 if (ins_index < 0)
2389 ins_index = i;
2390 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2391 if (table->entry[i].spec &
2392 EFX_EF10_FILTER_FLAG_BUSY)
2393 break;
2394 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002395 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002396 rc = -EPERM;
2397 goto out_unlock;
2398 }
2399 if (!is_mc_recip) {
2400 /* This is the only one */
2401 if (spec->priority ==
2402 saved_spec->priority &&
2403 !replace_equal) {
2404 rc = -EEXIST;
2405 goto out_unlock;
2406 }
2407 ins_index = i;
2408 goto found;
2409 } else if (spec->priority >
2410 saved_spec->priority ||
2411 (spec->priority ==
2412 saved_spec->priority &&
2413 replace_equal)) {
2414 if (ins_index < 0)
2415 ins_index = i;
2416 else
2417 __set_bit(depth, mc_rem_map);
2418 }
2419 }
2420
2421 /* Once we reach the maximum search depth, use
2422 * the first suitable slot or return -EBUSY if
2423 * there was none
2424 */
2425 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2426 if (ins_index < 0) {
2427 rc = -EBUSY;
2428 goto out_unlock;
2429 }
2430 goto found;
2431 }
2432
2433 ++depth;
2434 }
2435
2436 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2437 spin_unlock_bh(&efx->filter_lock);
2438 schedule();
2439 }
2440
2441found:
2442 /* Create a software table entry if necessary, and mark it
2443 * busy. We might yet fail to insert, but any attempt to
2444 * insert a conflicting filter while we're waiting for the
2445 * firmware must find the busy entry.
2446 */
2447 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2448 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002449 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2450 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002451 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002452 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2453 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002454 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002455 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002456 rc = ins_index;
2457 goto out_unlock;
2458 }
2459 replacing = true;
2460 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2461 } else {
2462 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2463 if (!saved_spec) {
2464 rc = -ENOMEM;
2465 goto out_unlock;
2466 }
2467 *saved_spec = *spec;
2468 priv_flags = 0;
2469 }
2470 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2471 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2472
2473 /* Mark lower-priority multicast recipients busy prior to removal */
2474 if (is_mc_recip) {
2475 unsigned int depth, i;
2476
2477 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2478 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2479 if (test_bit(depth, mc_rem_map))
2480 table->entry[i].spec |=
2481 EFX_EF10_FILTER_FLAG_BUSY;
2482 }
2483 }
2484
2485 spin_unlock_bh(&efx->filter_lock);
2486
2487 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2488 replacing);
2489
2490 /* Finalise the software table entry */
2491 spin_lock_bh(&efx->filter_lock);
2492 if (rc == 0) {
2493 if (replacing) {
2494 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002495 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2496 saved_spec->flags |=
2497 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002498 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002499 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002500 saved_spec->flags |= spec->flags;
2501 saved_spec->rss_context = spec->rss_context;
2502 saved_spec->dmaq_id = spec->dmaq_id;
2503 }
2504 } else if (!replacing) {
2505 kfree(saved_spec);
2506 saved_spec = NULL;
2507 }
2508 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2509
2510 /* Remove and finalise entries for lower-priority multicast
2511 * recipients
2512 */
2513 if (is_mc_recip) {
2514 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2515 unsigned int depth, i;
2516
2517 memset(inbuf, 0, sizeof(inbuf));
2518
2519 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2520 if (!test_bit(depth, mc_rem_map))
2521 continue;
2522
2523 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2524 saved_spec = efx_ef10_filter_entry_spec(table, i);
2525 priv_flags = efx_ef10_filter_entry_flags(table, i);
2526
2527 if (rc == 0) {
2528 spin_unlock_bh(&efx->filter_lock);
2529 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2530 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2531 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2532 table->entry[i].handle);
2533 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2534 inbuf, sizeof(inbuf),
2535 NULL, 0, NULL);
2536 spin_lock_bh(&efx->filter_lock);
2537 }
2538
2539 if (rc == 0) {
2540 kfree(saved_spec);
2541 saved_spec = NULL;
2542 priv_flags = 0;
2543 } else {
2544 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
2545 }
2546 efx_ef10_filter_set_entry(table, i, saved_spec,
2547 priv_flags);
2548 }
2549 }
2550
2551 /* If successful, return the inserted filter ID */
2552 if (rc == 0)
2553 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
2554
2555 wake_up_all(&table->waitq);
2556out_unlock:
2557 spin_unlock_bh(&efx->filter_lock);
2558 finish_wait(&table->waitq, &wait);
2559 return rc;
2560}
2561
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08002562static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002563{
2564 /* no need to do anything here on EF10 */
2565}
2566
2567/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002568 * If !by_index, remove by ID
2569 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01002570 * Filter ID may come from userland and must be range-checked.
2571 */
2572static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002573 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002574 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01002575{
2576 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2577 struct efx_ef10_filter_table *table = efx->filter_state;
2578 MCDI_DECLARE_BUF(inbuf,
2579 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2580 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2581 struct efx_filter_spec *spec;
2582 DEFINE_WAIT(wait);
2583 int rc;
2584
2585 /* Find the software table entry and mark it busy. Don't
2586 * remove it yet; any attempt to update while we're waiting
2587 * for the firmware must find the busy entry.
2588 */
2589 for (;;) {
2590 spin_lock_bh(&efx->filter_lock);
2591 if (!(table->entry[filter_idx].spec &
2592 EFX_EF10_FILTER_FLAG_BUSY))
2593 break;
2594 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2595 spin_unlock_bh(&efx->filter_lock);
2596 schedule();
2597 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002598
Ben Hutchings8127d662013-08-29 19:19:29 +01002599 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002600 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002601 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01002602 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
2603 filter_id / HUNT_FILTER_TBL_ROWS)) {
2604 rc = -ENOENT;
2605 goto out_unlock;
2606 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002607
2608 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002609 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002610 /* Just remove flags */
2611 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002612 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002613 rc = 0;
2614 goto out_unlock;
2615 }
2616
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002617 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002618 rc = -ENOENT;
2619 goto out_unlock;
2620 }
2621
Ben Hutchings8127d662013-08-29 19:19:29 +01002622 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2623 spin_unlock_bh(&efx->filter_lock);
2624
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002625 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002626 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01002627
2628 struct efx_filter_spec new_spec = *spec;
2629
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002630 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002631 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002632 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01002633 new_spec.dmaq_id = 0;
2634 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
2635 rc = efx_ef10_filter_push(efx, &new_spec,
2636 &table->entry[filter_idx].handle,
2637 true);
2638
2639 spin_lock_bh(&efx->filter_lock);
2640 if (rc == 0)
2641 *spec = new_spec;
2642 } else {
2643 /* Really remove the filter */
2644
2645 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2646 efx_ef10_filter_is_exclusive(spec) ?
2647 MC_CMD_FILTER_OP_IN_OP_REMOVE :
2648 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2649 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2650 table->entry[filter_idx].handle);
2651 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2652 inbuf, sizeof(inbuf), NULL, 0, NULL);
2653
2654 spin_lock_bh(&efx->filter_lock);
2655 if (rc == 0) {
2656 kfree(spec);
2657 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2658 }
2659 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002660
Ben Hutchings8127d662013-08-29 19:19:29 +01002661 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2662 wake_up_all(&table->waitq);
2663out_unlock:
2664 spin_unlock_bh(&efx->filter_lock);
2665 finish_wait(&table->waitq, &wait);
2666 return rc;
2667}
2668
2669static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
2670 enum efx_filter_priority priority,
2671 u32 filter_id)
2672{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002673 return efx_ef10_filter_remove_internal(efx, 1U << priority,
2674 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01002675}
2676
2677static int efx_ef10_filter_get_safe(struct efx_nic *efx,
2678 enum efx_filter_priority priority,
2679 u32 filter_id, struct efx_filter_spec *spec)
2680{
2681 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2682 struct efx_ef10_filter_table *table = efx->filter_state;
2683 const struct efx_filter_spec *saved_spec;
2684 int rc;
2685
2686 spin_lock_bh(&efx->filter_lock);
2687 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
2688 if (saved_spec && saved_spec->priority == priority &&
2689 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
2690 filter_id / HUNT_FILTER_TBL_ROWS) {
2691 *spec = *saved_spec;
2692 rc = 0;
2693 } else {
2694 rc = -ENOENT;
2695 }
2696 spin_unlock_bh(&efx->filter_lock);
2697 return rc;
2698}
2699
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002700static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01002701 enum efx_filter_priority priority)
2702{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002703 unsigned int priority_mask;
2704 unsigned int i;
2705 int rc;
2706
2707 priority_mask = (((1U << (priority + 1)) - 1) &
2708 ~(1U << EFX_FILTER_PRI_AUTO));
2709
2710 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
2711 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
2712 i, true);
2713 if (rc && rc != -ENOENT)
2714 return rc;
2715 }
2716
2717 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002718}
2719
2720static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
2721 enum efx_filter_priority priority)
2722{
2723 struct efx_ef10_filter_table *table = efx->filter_state;
2724 unsigned int filter_idx;
2725 s32 count = 0;
2726
2727 spin_lock_bh(&efx->filter_lock);
2728 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
2729 if (table->entry[filter_idx].spec &&
2730 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
2731 priority)
2732 ++count;
2733 }
2734 spin_unlock_bh(&efx->filter_lock);
2735 return count;
2736}
2737
2738static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
2739{
2740 struct efx_ef10_filter_table *table = efx->filter_state;
2741
2742 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
2743}
2744
2745static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
2746 enum efx_filter_priority priority,
2747 u32 *buf, u32 size)
2748{
2749 struct efx_ef10_filter_table *table = efx->filter_state;
2750 struct efx_filter_spec *spec;
2751 unsigned int filter_idx;
2752 s32 count = 0;
2753
2754 spin_lock_bh(&efx->filter_lock);
2755 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
2756 spec = efx_ef10_filter_entry_spec(table, filter_idx);
2757 if (spec && spec->priority == priority) {
2758 if (count == size) {
2759 count = -EMSGSIZE;
2760 break;
2761 }
2762 buf[count++] = (efx_ef10_filter_rx_match_pri(
2763 table, spec->match_flags) *
2764 HUNT_FILTER_TBL_ROWS +
2765 filter_idx);
2766 }
2767 }
2768 spin_unlock_bh(&efx->filter_lock);
2769 return count;
2770}
2771
2772#ifdef CONFIG_RFS_ACCEL
2773
2774static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
2775
2776static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
2777 struct efx_filter_spec *spec)
2778{
2779 struct efx_ef10_filter_table *table = efx->filter_state;
2780 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2781 struct efx_filter_spec *saved_spec;
2782 unsigned int hash, i, depth = 1;
2783 bool replacing = false;
2784 int ins_index = -1;
2785 u64 cookie;
2786 s32 rc;
2787
2788 /* Must be an RX filter without RSS and not for a multicast
2789 * destination address (RFS only works for connected sockets).
2790 * These restrictions allow us to pass only a tiny amount of
2791 * data through to the completion function.
2792 */
2793 EFX_WARN_ON_PARANOID(spec->flags !=
2794 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
2795 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
2796 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
2797
2798 hash = efx_ef10_filter_hash(spec);
2799
2800 spin_lock_bh(&efx->filter_lock);
2801
2802 /* Find any existing filter with the same match tuple or else
2803 * a free slot to insert at. If an existing filter is busy,
2804 * we have to give up.
2805 */
2806 for (;;) {
2807 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2808 saved_spec = efx_ef10_filter_entry_spec(table, i);
2809
2810 if (!saved_spec) {
2811 if (ins_index < 0)
2812 ins_index = i;
2813 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2814 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
2815 rc = -EBUSY;
2816 goto fail_unlock;
2817 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002818 if (spec->priority < saved_spec->priority) {
2819 rc = -EPERM;
2820 goto fail_unlock;
2821 }
2822 ins_index = i;
2823 break;
2824 }
2825
2826 /* Once we reach the maximum search depth, use the
2827 * first suitable slot or return -EBUSY if there was
2828 * none
2829 */
2830 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2831 if (ins_index < 0) {
2832 rc = -EBUSY;
2833 goto fail_unlock;
2834 }
2835 break;
2836 }
2837
2838 ++depth;
2839 }
2840
2841 /* Create a software table entry if necessary, and mark it
2842 * busy. We might yet fail to insert, but any attempt to
2843 * insert a conflicting filter while we're waiting for the
2844 * firmware must find the busy entry.
2845 */
2846 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2847 if (saved_spec) {
2848 replacing = true;
2849 } else {
2850 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2851 if (!saved_spec) {
2852 rc = -ENOMEM;
2853 goto fail_unlock;
2854 }
2855 *saved_spec = *spec;
2856 }
2857 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2858 EFX_EF10_FILTER_FLAG_BUSY);
2859
2860 spin_unlock_bh(&efx->filter_lock);
2861
2862 /* Pack up the variables needed on completion */
2863 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
2864
2865 efx_ef10_filter_push_prep(efx, spec, inbuf,
2866 table->entry[ins_index].handle, replacing);
2867 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2868 MC_CMD_FILTER_OP_OUT_LEN,
2869 efx_ef10_filter_rfs_insert_complete, cookie);
2870
2871 return ins_index;
2872
2873fail_unlock:
2874 spin_unlock_bh(&efx->filter_lock);
2875 return rc;
2876}
2877
2878static void
2879efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
2880 int rc, efx_dword_t *outbuf,
2881 size_t outlen_actual)
2882{
2883 struct efx_ef10_filter_table *table = efx->filter_state;
2884 unsigned int ins_index, dmaq_id;
2885 struct efx_filter_spec *spec;
2886 bool replacing;
2887
2888 /* Unpack the cookie */
2889 replacing = cookie >> 31;
2890 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
2891 dmaq_id = cookie & 0xffff;
2892
2893 spin_lock_bh(&efx->filter_lock);
2894 spec = efx_ef10_filter_entry_spec(table, ins_index);
2895 if (rc == 0) {
2896 table->entry[ins_index].handle =
2897 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
2898 if (replacing)
2899 spec->dmaq_id = dmaq_id;
2900 } else if (!replacing) {
2901 kfree(spec);
2902 spec = NULL;
2903 }
2904 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
2905 spin_unlock_bh(&efx->filter_lock);
2906
2907 wake_up_all(&table->waitq);
2908}
2909
2910static void
2911efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
2912 unsigned long filter_idx,
2913 int rc, efx_dword_t *outbuf,
2914 size_t outlen_actual);
2915
2916static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
2917 unsigned int filter_idx)
2918{
2919 struct efx_ef10_filter_table *table = efx->filter_state;
2920 struct efx_filter_spec *spec =
2921 efx_ef10_filter_entry_spec(table, filter_idx);
2922 MCDI_DECLARE_BUF(inbuf,
2923 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2924 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2925
2926 if (!spec ||
2927 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
2928 spec->priority != EFX_FILTER_PRI_HINT ||
2929 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
2930 flow_id, filter_idx))
2931 return false;
2932
2933 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2934 MC_CMD_FILTER_OP_IN_OP_REMOVE);
2935 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2936 table->entry[filter_idx].handle);
2937 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
2938 efx_ef10_filter_rfs_expire_complete, filter_idx))
2939 return false;
2940
2941 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2942 return true;
2943}
2944
2945static void
2946efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
2947 unsigned long filter_idx,
2948 int rc, efx_dword_t *outbuf,
2949 size_t outlen_actual)
2950{
2951 struct efx_ef10_filter_table *table = efx->filter_state;
2952 struct efx_filter_spec *spec =
2953 efx_ef10_filter_entry_spec(table, filter_idx);
2954
2955 spin_lock_bh(&efx->filter_lock);
2956 if (rc == 0) {
2957 kfree(spec);
2958 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2959 }
2960 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2961 wake_up_all(&table->waitq);
2962 spin_unlock_bh(&efx->filter_lock);
2963}
2964
2965#endif /* CONFIG_RFS_ACCEL */
2966
2967static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
2968{
2969 int match_flags = 0;
2970
2971#define MAP_FLAG(gen_flag, mcdi_field) { \
2972 u32 old_mcdi_flags = mcdi_flags; \
2973 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2974 mcdi_field ## _LBN); \
2975 if (mcdi_flags != old_mcdi_flags) \
2976 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
2977 }
2978 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
2979 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
2980 MAP_FLAG(REM_HOST, SRC_IP);
2981 MAP_FLAG(LOC_HOST, DST_IP);
2982 MAP_FLAG(REM_MAC, SRC_MAC);
2983 MAP_FLAG(REM_PORT, SRC_PORT);
2984 MAP_FLAG(LOC_MAC, DST_MAC);
2985 MAP_FLAG(LOC_PORT, DST_PORT);
2986 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
2987 MAP_FLAG(INNER_VID, INNER_VLAN);
2988 MAP_FLAG(OUTER_VID, OUTER_VLAN);
2989 MAP_FLAG(IP_PROTO, IP_PROTO);
2990#undef MAP_FLAG
2991
2992 /* Did we map them all? */
2993 if (mcdi_flags)
2994 return -EINVAL;
2995
2996 return match_flags;
2997}
2998
2999static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3000{
3001 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3002 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3003 unsigned int pd_match_pri, pd_match_count;
3004 struct efx_ef10_filter_table *table;
3005 size_t outlen;
3006 int rc;
3007
3008 table = kzalloc(sizeof(*table), GFP_KERNEL);
3009 if (!table)
3010 return -ENOMEM;
3011
3012 /* Find out which RX filter types are supported, and their priorities */
3013 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3014 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3015 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3016 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3017 &outlen);
3018 if (rc)
3019 goto fail;
3020 pd_match_count = MCDI_VAR_ARRAY_LEN(
3021 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3022 table->rx_match_count = 0;
3023
3024 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3025 u32 mcdi_flags =
3026 MCDI_ARRAY_DWORD(
3027 outbuf,
3028 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3029 pd_match_pri);
3030 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3031 if (rc < 0) {
3032 netif_dbg(efx, probe, efx->net_dev,
3033 "%s: fw flags %#x pri %u not supported in driver\n",
3034 __func__, mcdi_flags, pd_match_pri);
3035 } else {
3036 netif_dbg(efx, probe, efx->net_dev,
3037 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3038 __func__, mcdi_flags, pd_match_pri,
3039 rc, table->rx_match_count);
3040 table->rx_match_flags[table->rx_match_count++] = rc;
3041 }
3042 }
3043
3044 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3045 if (!table->entry) {
3046 rc = -ENOMEM;
3047 goto fail;
3048 }
3049
3050 efx->filter_state = table;
3051 init_waitqueue_head(&table->waitq);
3052 return 0;
3053
3054fail:
3055 kfree(table);
3056 return rc;
3057}
3058
3059static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3060{
3061 struct efx_ef10_filter_table *table = efx->filter_state;
3062 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3063 struct efx_filter_spec *spec;
3064 unsigned int filter_idx;
3065 bool failed = false;
3066 int rc;
3067
3068 if (!nic_data->must_restore_filters)
3069 return;
3070
3071 spin_lock_bh(&efx->filter_lock);
3072
3073 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3074 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3075 if (!spec)
3076 continue;
3077
3078 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3079 spin_unlock_bh(&efx->filter_lock);
3080
3081 rc = efx_ef10_filter_push(efx, spec,
3082 &table->entry[filter_idx].handle,
3083 false);
3084 if (rc)
3085 failed = true;
3086
3087 spin_lock_bh(&efx->filter_lock);
3088 if (rc) {
3089 kfree(spec);
3090 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3091 } else {
3092 table->entry[filter_idx].spec &=
3093 ~EFX_EF10_FILTER_FLAG_BUSY;
3094 }
3095 }
3096
3097 spin_unlock_bh(&efx->filter_lock);
3098
3099 if (failed)
3100 netif_err(efx, hw, efx->net_dev,
3101 "unable to restore all filters\n");
3102 else
3103 nic_data->must_restore_filters = false;
3104}
3105
3106static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3107{
3108 struct efx_ef10_filter_table *table = efx->filter_state;
3109 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3110 struct efx_filter_spec *spec;
3111 unsigned int filter_idx;
3112 int rc;
3113
3114 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3115 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3116 if (!spec)
3117 continue;
3118
3119 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3120 efx_ef10_filter_is_exclusive(spec) ?
3121 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3122 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3123 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3124 table->entry[filter_idx].handle);
3125 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3126 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003127 if (rc)
3128 netdev_WARN(efx->net_dev,
3129 "filter_idx=%#x handle=%#llx\n",
3130 filter_idx,
3131 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003132 kfree(spec);
3133 }
3134
3135 vfree(table->entry);
3136 kfree(table);
3137}
3138
3139static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3140{
3141 struct efx_ef10_filter_table *table = efx->filter_state;
3142 struct net_device *net_dev = efx->net_dev;
3143 struct efx_filter_spec spec;
3144 bool remove_failed = false;
3145 struct netdev_hw_addr *uc;
3146 struct netdev_hw_addr *mc;
3147 unsigned int filter_idx;
3148 int i, n, rc;
3149
3150 if (!efx_dev_registered(efx))
3151 return;
3152
3153 /* Mark old filters that may need to be removed */
3154 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003155 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003156 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003157 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3158 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003159 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003160 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003161 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003162 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3163 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003164 }
3165 spin_unlock_bh(&efx->filter_lock);
3166
3167 /* Copy/convert the address lists; add the primary station
3168 * address and broadcast address
3169 */
3170 netif_addr_lock_bh(net_dev);
3171 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003172 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3173 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003174 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003175 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003176 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003177 i = 1;
3178 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003179 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003180 i++;
3181 }
3182 }
3183 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003184 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3185 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003186 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003187 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3188 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003189 i = 1;
3190 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003191 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003192 i++;
3193 }
3194 }
3195 netif_addr_unlock_bh(net_dev);
3196
3197 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003198 if (table->dev_uc_count >= 0) {
3199 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003200 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3201 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003202 0);
3203 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003204 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003205 rc = efx_ef10_filter_insert(efx, &spec, true);
3206 if (rc < 0) {
3207 /* Fall back to unicast-promisc */
3208 while (i--)
3209 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003210 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003211 table->dev_uc_list[i].id);
3212 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003213 break;
3214 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003215 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003216 }
3217 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003218 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003219 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3220 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003221 0);
3222 efx_filter_set_uc_def(&spec);
3223 rc = efx_ef10_filter_insert(efx, &spec, true);
3224 if (rc < 0) {
3225 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003226 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003227 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003228 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003229 }
3230 }
3231
3232 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003233 if (table->dev_mc_count >= 0) {
3234 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003235 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3236 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003237 0);
3238 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003239 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003240 rc = efx_ef10_filter_insert(efx, &spec, true);
3241 if (rc < 0) {
3242 /* Fall back to multicast-promisc */
3243 while (i--)
3244 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003245 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003246 table->dev_mc_list[i].id);
3247 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003248 break;
3249 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003250 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003251 }
3252 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003253 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003254 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3255 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003256 0);
3257 efx_filter_set_mc_def(&spec);
3258 rc = efx_ef10_filter_insert(efx, &spec, true);
3259 if (rc < 0) {
3260 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003261 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003262 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003263 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003264 }
3265 }
3266
3267 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003268 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003269 * don't need to hold the filter_lock while scanning for
3270 * these filters.
3271 */
3272 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3273 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003274 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003275 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003276 efx, 1U << EFX_FILTER_PRI_AUTO,
3277 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003278 remove_failed = true;
3279 }
3280 }
3281 WARN_ON(remove_failed);
3282}
3283
3284static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3285{
3286 efx_ef10_filter_sync_rx_mode(efx);
3287
3288 return efx_mcdi_set_mac(efx);
3289}
3290
Jon Cooper74cd60a2013-09-16 14:18:51 +01003291static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3292{
3293 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3294
3295 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3296 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3297 NULL, 0, NULL);
3298}
3299
3300/* MC BISTs follow a different poll mechanism to phy BISTs.
3301 * The BIST is done in the poll handler on the MC, and the MCDI command
3302 * will block until the BIST is done.
3303 */
3304static int efx_ef10_poll_bist(struct efx_nic *efx)
3305{
3306 int rc;
3307 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3308 size_t outlen;
3309 u32 result;
3310
3311 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3312 outbuf, sizeof(outbuf), &outlen);
3313 if (rc != 0)
3314 return rc;
3315
3316 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3317 return -EIO;
3318
3319 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3320 switch (result) {
3321 case MC_CMD_POLL_BIST_PASSED:
3322 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3323 return 0;
3324 case MC_CMD_POLL_BIST_TIMEOUT:
3325 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3326 return -EIO;
3327 case MC_CMD_POLL_BIST_FAILED:
3328 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3329 return -EIO;
3330 default:
3331 netif_err(efx, hw, efx->net_dev,
3332 "BIST returned unknown result %u", result);
3333 return -EIO;
3334 }
3335}
3336
3337static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3338{
3339 int rc;
3340
3341 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3342
3343 rc = efx_ef10_start_bist(efx, bist_type);
3344 if (rc != 0)
3345 return rc;
3346
3347 return efx_ef10_poll_bist(efx);
3348}
3349
3350static int
3351efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3352{
3353 int rc, rc2;
3354
3355 efx_reset_down(efx, RESET_TYPE_WORLD);
3356
3357 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3358 NULL, 0, NULL, 0, NULL);
3359 if (rc != 0)
3360 goto out;
3361
3362 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3363 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3364
3365 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3366
3367out:
3368 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3369 return rc ? rc : rc2;
3370}
3371
Ben Hutchings8127d662013-08-29 19:19:29 +01003372#ifdef CONFIG_SFC_MTD
3373
3374struct efx_ef10_nvram_type_info {
3375 u16 type, type_mask;
3376 u8 port;
3377 const char *name;
3378};
3379
3380static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3381 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3382 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3383 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3384 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3385 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3386 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3387 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3388 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3389 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003390 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003391 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3392};
3393
3394static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3395 struct efx_mcdi_mtd_partition *part,
3396 unsigned int type)
3397{
3398 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3399 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3400 const struct efx_ef10_nvram_type_info *info;
3401 size_t size, erase_size, outlen;
3402 bool protected;
3403 int rc;
3404
3405 for (info = efx_ef10_nvram_types; ; info++) {
3406 if (info ==
3407 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3408 return -ENODEV;
3409 if ((type & ~info->type_mask) == info->type)
3410 break;
3411 }
3412 if (info->port != efx_port_num(efx))
3413 return -ENODEV;
3414
3415 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3416 if (rc)
3417 return rc;
3418 if (protected)
3419 return -ENODEV; /* hide it */
3420
3421 part->nvram_type = type;
3422
3423 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3424 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3425 outbuf, sizeof(outbuf), &outlen);
3426 if (rc)
3427 return rc;
3428 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3429 return -EIO;
3430 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3431 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3432 part->fw_subtype = MCDI_DWORD(outbuf,
3433 NVRAM_METADATA_OUT_SUBTYPE);
3434
3435 part->common.dev_type_name = "EF10 NVRAM manager";
3436 part->common.type_name = info->name;
3437
3438 part->common.mtd.type = MTD_NORFLASH;
3439 part->common.mtd.flags = MTD_CAP_NORFLASH;
3440 part->common.mtd.size = size;
3441 part->common.mtd.erasesize = erase_size;
3442
3443 return 0;
3444}
3445
3446static int efx_ef10_mtd_probe(struct efx_nic *efx)
3447{
3448 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
3449 struct efx_mcdi_mtd_partition *parts;
3450 size_t outlen, n_parts_total, i, n_parts;
3451 unsigned int type;
3452 int rc;
3453
3454 ASSERT_RTNL();
3455
3456 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
3457 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
3458 outbuf, sizeof(outbuf), &outlen);
3459 if (rc)
3460 return rc;
3461 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
3462 return -EIO;
3463
3464 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
3465 if (n_parts_total >
3466 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
3467 return -EIO;
3468
3469 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
3470 if (!parts)
3471 return -ENOMEM;
3472
3473 n_parts = 0;
3474 for (i = 0; i < n_parts_total; i++) {
3475 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
3476 i);
3477 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
3478 if (rc == 0)
3479 n_parts++;
3480 else if (rc != -ENODEV)
3481 goto fail;
3482 }
3483
3484 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
3485fail:
3486 if (rc)
3487 kfree(parts);
3488 return rc;
3489}
3490
3491#endif /* CONFIG_SFC_MTD */
3492
3493static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
3494{
3495 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
3496}
3497
Jon Cooperbd9a2652013-11-18 12:54:41 +00003498static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
3499 bool temp)
3500{
3501 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
3502 int rc;
3503
3504 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
3505 channel->sync_events_state == SYNC_EVENTS_VALID ||
3506 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
3507 return 0;
3508 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
3509
3510 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
3511 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3512 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
3513 channel->channel);
3514
3515 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3516 inbuf, sizeof(inbuf), NULL, 0, NULL);
3517
3518 if (rc != 0)
3519 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3520 SYNC_EVENTS_DISABLED;
3521
3522 return rc;
3523}
3524
3525static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
3526 bool temp)
3527{
3528 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
3529 int rc;
3530
3531 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
3532 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
3533 return 0;
3534 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
3535 channel->sync_events_state = SYNC_EVENTS_DISABLED;
3536 return 0;
3537 }
3538 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3539 SYNC_EVENTS_DISABLED;
3540
3541 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
3542 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3543 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
3544 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
3545 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
3546 channel->channel);
3547
3548 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3549 inbuf, sizeof(inbuf), NULL, 0, NULL);
3550
3551 return rc;
3552}
3553
3554static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
3555 bool temp)
3556{
3557 int (*set)(struct efx_channel *channel, bool temp);
3558 struct efx_channel *channel;
3559
3560 set = en ?
3561 efx_ef10_rx_enable_timestamping :
3562 efx_ef10_rx_disable_timestamping;
3563
3564 efx_for_each_channel(channel, efx) {
3565 int rc = set(channel, temp);
3566 if (en && rc != 0) {
3567 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
3568 return rc;
3569 }
3570 }
3571
3572 return 0;
3573}
3574
3575static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
3576 struct hwtstamp_config *init)
3577{
3578 int rc;
3579
3580 switch (init->rx_filter) {
3581 case HWTSTAMP_FILTER_NONE:
3582 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
3583 /* if TX timestamping is still requested then leave PTP on */
3584 return efx_ptp_change_mode(efx,
3585 init->tx_type != HWTSTAMP_TX_OFF, 0);
3586 case HWTSTAMP_FILTER_ALL:
3587 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3588 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3589 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3590 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3591 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3592 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3593 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3594 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3595 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3596 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3597 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3598 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3599 init->rx_filter = HWTSTAMP_FILTER_ALL;
3600 rc = efx_ptp_change_mode(efx, true, 0);
3601 if (!rc)
3602 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
3603 if (rc)
3604 efx_ptp_change_mode(efx, false, 0);
3605 return rc;
3606 default:
3607 return -ERANGE;
3608 }
3609}
3610
Ben Hutchings8127d662013-08-29 19:19:29 +01003611const struct efx_nic_type efx_hunt_a0_nic_type = {
3612 .mem_map_size = efx_ef10_mem_map_size,
3613 .probe = efx_ef10_probe,
3614 .remove = efx_ef10_remove,
3615 .dimension_resources = efx_ef10_dimension_resources,
3616 .init = efx_ef10_init_nic,
3617 .fini = efx_port_dummy_op_void,
3618 .map_reset_reason = efx_mcdi_map_reset_reason,
3619 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00003620 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01003621 .probe_port = efx_mcdi_port_probe,
3622 .remove_port = efx_mcdi_port_remove,
3623 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01003624 .prepare_flr = efx_ef10_prepare_flr,
3625 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01003626 .describe_stats = efx_ef10_describe_stats,
3627 .update_stats = efx_ef10_update_stats,
3628 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01003629 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01003630 .stop_stats = efx_mcdi_mac_stop_stats,
3631 .set_id_led = efx_mcdi_set_id_led,
3632 .push_irq_moderation = efx_ef10_push_irq_moderation,
3633 .reconfigure_mac = efx_ef10_mac_reconfigure,
3634 .check_mac_fault = efx_mcdi_mac_check_fault,
3635 .reconfigure_port = efx_mcdi_port_reconfigure,
3636 .get_wol = efx_ef10_get_wol,
3637 .set_wol = efx_ef10_set_wol,
3638 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01003639 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01003640 .test_nvram = efx_mcdi_nvram_test_all,
3641 .mcdi_request = efx_ef10_mcdi_request,
3642 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
3643 .mcdi_read_response = efx_ef10_mcdi_read_response,
3644 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
3645 .irq_enable_master = efx_port_dummy_op_void,
3646 .irq_test_generate = efx_ef10_irq_test_generate,
3647 .irq_disable_non_ev = efx_port_dummy_op_void,
3648 .irq_handle_msi = efx_ef10_msi_interrupt,
3649 .irq_handle_legacy = efx_ef10_legacy_interrupt,
3650 .tx_probe = efx_ef10_tx_probe,
3651 .tx_init = efx_ef10_tx_init,
3652 .tx_remove = efx_ef10_tx_remove,
3653 .tx_write = efx_ef10_tx_write,
Andrew Rybchenkod43050c2013-11-14 09:00:27 +04003654 .rx_push_rss_config = efx_ef10_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01003655 .rx_probe = efx_ef10_rx_probe,
3656 .rx_init = efx_ef10_rx_init,
3657 .rx_remove = efx_ef10_rx_remove,
3658 .rx_write = efx_ef10_rx_write,
3659 .rx_defer_refill = efx_ef10_rx_defer_refill,
3660 .ev_probe = efx_ef10_ev_probe,
3661 .ev_init = efx_ef10_ev_init,
3662 .ev_fini = efx_ef10_ev_fini,
3663 .ev_remove = efx_ef10_ev_remove,
3664 .ev_process = efx_ef10_ev_process,
3665 .ev_read_ack = efx_ef10_ev_read_ack,
3666 .ev_test_generate = efx_ef10_ev_test_generate,
3667 .filter_table_probe = efx_ef10_filter_table_probe,
3668 .filter_table_restore = efx_ef10_filter_table_restore,
3669 .filter_table_remove = efx_ef10_filter_table_remove,
3670 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
3671 .filter_insert = efx_ef10_filter_insert,
3672 .filter_remove_safe = efx_ef10_filter_remove_safe,
3673 .filter_get_safe = efx_ef10_filter_get_safe,
3674 .filter_clear_rx = efx_ef10_filter_clear_rx,
3675 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
3676 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
3677 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
3678#ifdef CONFIG_RFS_ACCEL
3679 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
3680 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
3681#endif
3682#ifdef CONFIG_SFC_MTD
3683 .mtd_probe = efx_ef10_mtd_probe,
3684 .mtd_rename = efx_mcdi_mtd_rename,
3685 .mtd_read = efx_mcdi_mtd_read,
3686 .mtd_erase = efx_mcdi_mtd_erase,
3687 .mtd_write = efx_mcdi_mtd_write,
3688 .mtd_sync = efx_mcdi_mtd_sync,
3689#endif
3690 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00003691 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
3692 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01003693#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01003694 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00003695 .sriov_init = efx_ef10_sriov_init,
3696 .sriov_fini = efx_ef10_sriov_fini,
3697 .sriov_mac_address_changed = efx_ef10_sriov_mac_address_changed,
3698 .sriov_wanted = efx_ef10_sriov_wanted,
3699 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01003700 .sriov_flr = efx_ef10_sriov_flr,
3701 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
3702 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
3703 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
3704 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
3705#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01003706
3707 .revision = EFX_REV_HUNT_A0,
3708 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
3709 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
3710 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00003711 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01003712 .can_rx_scatter = true,
3713 .always_rx_scatter = true,
3714 .max_interrupt_mode = EFX_INT_MODE_MSIX,
3715 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
3716 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3717 NETIF_F_RXHASH | NETIF_F_NTUPLE),
3718 .mcdi_max_ver = 2,
3719 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00003720 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
3721 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01003722};