blob: a547cebff4e27a3c4a91d770098bb77f2074b908 [file] [log] [blame]
Ben Hutchings8127d662013-08-29 19:19:29 +01001/****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2012-2013 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include "net_driver.h"
11#include "ef10_regs.h"
12#include "io.h"
13#include "mcdi.h"
14#include "mcdi_pcol.h"
15#include "nic.h"
16#include "workarounds.h"
Jon Cooper74cd60a2013-09-16 14:18:51 +010017#include "selftest.h"
Shradha Shah7fa8d542015-05-06 00:55:13 +010018#include "ef10_sriov.h"
Ben Hutchings8127d662013-08-29 19:19:29 +010019#include <linux/in.h>
20#include <linux/jhash.h>
21#include <linux/wait.h>
22#include <linux/workqueue.h>
23
24/* Hardware control for EF10 architecture including 'Huntington'. */
25
26#define EFX_EF10_DRVGEN_EV 7
27enum {
28 EFX_EF10_TEST = 1,
29 EFX_EF10_REFILL,
30};
31
32/* The reserved RSS context value */
33#define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff
Jon Cooper267c0152015-05-06 00:59:38 +010034/* The maximum size of a shared RSS context */
35/* TODO: this should really be from the mcdi protocol export */
36#define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL
Ben Hutchings8127d662013-08-29 19:19:29 +010037
38/* The filter table(s) are managed by firmware and we have write-only
39 * access. When removing filters we must identify them to the
40 * firmware by a 64-bit handle, but this is too wide for Linux kernel
41 * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to
42 * be able to tell in advance whether a requested insertion will
43 * replace an existing filter. Therefore we maintain a software hash
44 * table, which should be at least as large as the hardware hash
45 * table.
46 *
47 * Huntington has a single 8K filter table shared between all filter
48 * types and both ports.
49 */
50#define HUNT_FILTER_TBL_ROWS 8192
51
52struct efx_ef10_filter_table {
53/* The RX match field masks supported by this fw & hw, in order of priority */
54 enum efx_filter_match_flags rx_match_flags[
55 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM];
56 unsigned int rx_match_count;
57
58 struct {
59 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000060/* BUSY flag indicates that an update is in progress. AUTO_OLD is
61 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +010062 */
63#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000064#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +010065#define EFX_EF10_FILTER_FLAGS 3UL
66 u64 handle; /* firmware handle */
67 } *entry;
68 wait_queue_head_t waitq;
69/* Shadow of net_device address lists, guarded by mac_lock */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000070#define EFX_EF10_FILTER_DEV_UC_MAX 32
71#define EFX_EF10_FILTER_DEV_MC_MAX 256
Ben Hutchings8127d662013-08-29 19:19:29 +010072 struct {
73 u8 addr[ETH_ALEN];
74 u16 id;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +000075 } dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX],
76 dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
77 int dev_uc_count; /* negative for PROMISC */
78 int dev_mc_count; /* negative for PROMISC/ALLMULTI */
Ben Hutchings8127d662013-08-29 19:19:29 +010079};
80
81/* An arbitrary search limit for the software hash table */
82#define EFX_EF10_FILTER_SEARCH_LIMIT 200
83
Ben Hutchings8127d662013-08-29 19:19:29 +010084static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
85static void efx_ef10_filter_table_remove(struct efx_nic *efx);
86
87static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
88{
89 efx_dword_t reg;
90
91 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
92 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
93 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
94}
95
96static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
97{
Shradha Shah02246a72015-05-06 00:58:14 +010098 int bar;
99
100 bar = efx->type->mem_bar;
101 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100102}
103
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100104static int efx_ef10_get_pf_index(struct efx_nic *efx)
105{
106 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
107 struct efx_ef10_nic_data *nic_data = efx->nic_data;
108 size_t outlen;
109 int rc;
110
111 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
112 sizeof(outbuf), &outlen);
113 if (rc)
114 return rc;
115 if (outlen < sizeof(outbuf))
116 return -EIO;
117
118 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
119 return 0;
120}
121
Shradha Shah88a37de2015-05-20 11:09:15 +0100122#ifdef CONFIG_SFC_SRIOV
123static int efx_ef10_get_vf_index(struct efx_nic *efx)
124{
125 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
126 struct efx_ef10_nic_data *nic_data = efx->nic_data;
127 size_t outlen;
128 int rc;
129
130 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
131 sizeof(outbuf), &outlen);
132 if (rc)
133 return rc;
134 if (outlen < sizeof(outbuf))
135 return -EIO;
136
137 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
138 return 0;
139}
140#endif
141
Ben Hutchingse5a25382013-09-05 22:50:59 +0100142static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100143{
144 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN);
145 struct efx_ef10_nic_data *nic_data = efx->nic_data;
146 size_t outlen;
147 int rc;
148
149 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
150
151 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
152 outbuf, sizeof(outbuf), &outlen);
153 if (rc)
154 return rc;
Ben Hutchingse5a25382013-09-05 22:50:59 +0100155 if (outlen < sizeof(outbuf)) {
156 netif_err(efx, drv, efx->net_dev,
157 "unable to read datapath firmware capabilities\n");
158 return -EIO;
159 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100160
Ben Hutchingse5a25382013-09-05 22:50:59 +0100161 nic_data->datapath_caps =
162 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
163
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100164 /* record the DPCPU firmware IDs to determine VEB vswitching support.
165 */
166 nic_data->rx_dpcpu_fw_id =
167 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
168 nic_data->tx_dpcpu_fw_id =
169 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
170
Ben Hutchingse5a25382013-09-05 22:50:59 +0100171 if (!(nic_data->datapath_caps &
172 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) {
173 netif_err(efx, drv, efx->net_dev,
174 "current firmware does not support TSO\n");
175 return -ENODEV;
176 }
177
178 if (!(nic_data->datapath_caps &
179 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
180 netif_err(efx, probe, efx->net_dev,
181 "current firmware does not support an RX prefix\n");
182 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100183 }
184
185 return 0;
186}
187
188static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
189{
190 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
191 int rc;
192
193 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
194 outbuf, sizeof(outbuf), NULL);
195 if (rc)
196 return rc;
197 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
198 return rc > 0 ? rc : -ERANGE;
199}
200
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100201static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100202{
203 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
204 size_t outlen;
205 int rc;
206
207 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
208
209 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
210 outbuf, sizeof(outbuf), &outlen);
211 if (rc)
212 return rc;
213 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
214 return -EIO;
215
Edward Creecd84ff42014-03-07 18:27:41 +0000216 ether_addr_copy(mac_address,
217 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100218 return 0;
219}
220
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100221static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
222{
223 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
224 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
225 size_t outlen;
226 int num_addrs, rc;
227
228 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
229 EVB_PORT_ID_ASSIGNED);
230 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
231 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
232
233 if (rc)
234 return rc;
235 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
236 return -EIO;
237
238 num_addrs = MCDI_DWORD(outbuf,
239 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
240
241 WARN_ON(num_addrs != 1);
242
243 ether_addr_copy(mac_address,
244 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
245
246 return 0;
247}
248
Ben Hutchings8127d662013-08-29 19:19:29 +0100249static int efx_ef10_probe(struct efx_nic *efx)
250{
251 struct efx_ef10_nic_data *nic_data;
252 int i, rc;
253
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000254 /* We can have one VI for each 8K region. However, until we
255 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100256 */
257 efx->max_channels =
258 min_t(unsigned int,
259 EFX_MAX_CHANNELS,
Shradha Shah02246a72015-05-06 00:58:14 +0100260 efx_ef10_mem_map_size(efx) /
Ben Hutchings8127d662013-08-29 19:19:29 +0100261 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000262 if (WARN_ON(efx->max_channels == 0))
263 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100264
265 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
266 if (!nic_data)
267 return -ENOMEM;
268 efx->nic_data = nic_data;
269
270 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
271 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
272 if (rc)
273 goto fail1;
274
275 /* Get the MC's warm boot count. In case it's rebooting right
276 * now, be prepared to retry.
277 */
278 i = 0;
279 for (;;) {
280 rc = efx_ef10_get_warm_boot_count(efx);
281 if (rc >= 0)
282 break;
283 if (++i == 5)
284 goto fail2;
285 ssleep(1);
286 }
287 nic_data->warm_boot_count = rc;
288
289 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
290
Daniel Pieczko45b24492015-05-06 00:57:14 +0100291 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
292
Ben Hutchings8127d662013-08-29 19:19:29 +0100293 /* In case we're recovering from a crash (kexec), we want to
294 * cancel any outstanding request by the previous user of this
295 * function. We send a special message using the least
296 * significant bits of the 'high' (doorbell) register.
297 */
298 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
299
300 rc = efx_mcdi_init(efx);
301 if (rc)
302 goto fail2;
303
304 /* Reset (most) configuration for this function */
305 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
306 if (rc)
307 goto fail3;
308
309 /* Enable event logging */
310 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
311 if (rc)
312 goto fail3;
313
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100314 rc = efx_ef10_get_pf_index(efx);
315 if (rc)
316 goto fail3;
317
Ben Hutchingse5a25382013-09-05 22:50:59 +0100318 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100319 if (rc < 0)
320 goto fail3;
321
322 efx->rx_packet_len_offset =
323 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
324
Ben Hutchings8127d662013-08-29 19:19:29 +0100325 rc = efx_mcdi_port_get_number(efx);
326 if (rc < 0)
327 goto fail3;
328 efx->port_num = rc;
329
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100330 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100331 if (rc)
332 goto fail3;
333
334 rc = efx_ef10_get_sysclk_freq(efx);
335 if (rc < 0)
336 goto fail3;
337 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
338
Edward Cree267d9d72015-05-06 00:59:18 +0100339 /* Check whether firmware supports bug 35388 workaround.
340 * First try to enable it, then if we get EPERM, just
341 * ask if it's already enabled
342 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100343 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true);
344 if (rc == 0)
345 nic_data->workaround_35388 = true;
Edward Cree267d9d72015-05-06 00:59:18 +0100346 else if (rc == -EPERM) {
347 unsigned int enabled;
348
349 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
350 if (rc)
351 goto fail3;
352 nic_data->workaround_35388 = enabled &
353 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
354 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100355 else if (rc != -ENOSYS && rc != -ENOENT)
356 goto fail3;
357 netif_dbg(efx, probe, efx->net_dev,
358 "workaround for bug 35388 is %sabled\n",
359 nic_data->workaround_35388 ? "en" : "dis");
360
361 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100362 if (rc && rc != -EPERM)
Ben Hutchings8127d662013-08-29 19:19:29 +0100363 goto fail3;
364
Ben Hutchings9aecda92013-12-05 21:28:42 +0000365 efx_ptp_probe(efx, NULL);
366
Ben Hutchings8127d662013-08-29 19:19:29 +0100367 return 0;
368
369fail3:
370 efx_mcdi_fini(efx);
371fail2:
372 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
373fail1:
374 kfree(nic_data);
375 efx->nic_data = NULL;
376 return rc;
377}
378
379static int efx_ef10_free_vis(struct efx_nic *efx)
380{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100381 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100382 size_t outlen;
383 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
384 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100385
386 /* -EALREADY means nothing to free, so ignore */
387 if (rc == -EALREADY)
388 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100389 if (rc)
390 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
391 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100392 return rc;
393}
394
Ben Hutchings183233b2013-06-28 21:47:12 +0100395#ifdef EFX_USE_PIO
396
397static void efx_ef10_free_piobufs(struct efx_nic *efx)
398{
399 struct efx_ef10_nic_data *nic_data = efx->nic_data;
400 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
401 unsigned int i;
402 int rc;
403
404 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
405
406 for (i = 0; i < nic_data->n_piobufs; i++) {
407 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
408 nic_data->piobuf_handle[i]);
409 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
410 NULL, 0, NULL);
411 WARN_ON(rc);
412 }
413
414 nic_data->n_piobufs = 0;
415}
416
417static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
418{
419 struct efx_ef10_nic_data *nic_data = efx->nic_data;
420 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
421 unsigned int i;
422 size_t outlen;
423 int rc = 0;
424
425 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
426
427 for (i = 0; i < n; i++) {
428 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
429 outbuf, sizeof(outbuf), &outlen);
430 if (rc)
431 break;
432 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
433 rc = -EIO;
434 break;
435 }
436 nic_data->piobuf_handle[i] =
437 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
438 netif_dbg(efx, probe, efx->net_dev,
439 "allocated PIO buffer %u handle %x\n", i,
440 nic_data->piobuf_handle[i]);
441 }
442
443 nic_data->n_piobufs = i;
444 if (rc)
445 efx_ef10_free_piobufs(efx);
446 return rc;
447}
448
449static int efx_ef10_link_piobufs(struct efx_nic *efx)
450{
451 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100452 _MCDI_DECLARE_BUF(inbuf,
453 max(MC_CMD_LINK_PIOBUF_IN_LEN,
454 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100455 struct efx_channel *channel;
456 struct efx_tx_queue *tx_queue;
457 unsigned int offset, index;
458 int rc;
459
460 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
461 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
462
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100463 memset(inbuf, 0, sizeof(inbuf));
464
Ben Hutchings183233b2013-06-28 21:47:12 +0100465 /* Link a buffer to each VI in the write-combining mapping */
466 for (index = 0; index < nic_data->n_piobufs; ++index) {
467 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
468 nic_data->piobuf_handle[index]);
469 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
470 nic_data->pio_write_vi_base + index);
471 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
472 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
473 NULL, 0, NULL);
474 if (rc) {
475 netif_err(efx, drv, efx->net_dev,
476 "failed to link VI %u to PIO buffer %u (%d)\n",
477 nic_data->pio_write_vi_base + index, index,
478 rc);
479 goto fail;
480 }
481 netif_dbg(efx, probe, efx->net_dev,
482 "linked VI %u to PIO buffer %u\n",
483 nic_data->pio_write_vi_base + index, index);
484 }
485
486 /* Link a buffer to each TX queue */
487 efx_for_each_channel(channel, efx) {
488 efx_for_each_channel_tx_queue(tx_queue, channel) {
489 /* We assign the PIO buffers to queues in
490 * reverse order to allow for the following
491 * special case.
492 */
493 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
494 tx_queue->channel->channel - 1) *
495 efx_piobuf_size);
496 index = offset / ER_DZ_TX_PIOBUF_SIZE;
497 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
498
499 /* When the host page size is 4K, the first
500 * host page in the WC mapping may be within
501 * the same VI page as the last TX queue. We
502 * can only link one buffer to each VI.
503 */
504 if (tx_queue->queue == nic_data->pio_write_vi_base) {
505 BUG_ON(index != 0);
506 rc = 0;
507 } else {
508 MCDI_SET_DWORD(inbuf,
509 LINK_PIOBUF_IN_PIOBUF_HANDLE,
510 nic_data->piobuf_handle[index]);
511 MCDI_SET_DWORD(inbuf,
512 LINK_PIOBUF_IN_TXQ_INSTANCE,
513 tx_queue->queue);
514 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
515 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
516 NULL, 0, NULL);
517 }
518
519 if (rc) {
520 /* This is non-fatal; the TX path just
521 * won't use PIO for this queue
522 */
523 netif_err(efx, drv, efx->net_dev,
524 "failed to link VI %u to PIO buffer %u (%d)\n",
525 tx_queue->queue, index, rc);
526 tx_queue->piobuf = NULL;
527 } else {
528 tx_queue->piobuf =
529 nic_data->pio_write_base +
530 index * EFX_VI_PAGE_SIZE + offset;
531 tx_queue->piobuf_offset = offset;
532 netif_dbg(efx, probe, efx->net_dev,
533 "linked VI %u to PIO buffer %u offset %x addr %p\n",
534 tx_queue->queue, index,
535 tx_queue->piobuf_offset,
536 tx_queue->piobuf);
537 }
538 }
539 }
540
541 return 0;
542
543fail:
544 while (index--) {
545 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
546 nic_data->pio_write_vi_base + index);
547 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
548 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
549 NULL, 0, NULL);
550 }
551 return rc;
552}
553
554#else /* !EFX_USE_PIO */
555
556static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
557{
558 return n == 0 ? 0 : -ENOBUFS;
559}
560
561static int efx_ef10_link_piobufs(struct efx_nic *efx)
562{
563 return 0;
564}
565
566static void efx_ef10_free_piobufs(struct efx_nic *efx)
567{
568}
569
570#endif /* EFX_USE_PIO */
571
Ben Hutchings8127d662013-08-29 19:19:29 +0100572static void efx_ef10_remove(struct efx_nic *efx)
573{
574 struct efx_ef10_nic_data *nic_data = efx->nic_data;
575 int rc;
576
Shradha Shahf1122a32015-05-20 11:09:46 +0100577#ifdef CONFIG_SFC_SRIOV
578 struct efx_ef10_nic_data *nic_data_pf;
579 struct pci_dev *pci_dev_pf;
580 struct efx_nic *efx_pf;
581 struct ef10_vf *vf;
582
583 if (efx->pci_dev->is_virtfn) {
584 pci_dev_pf = efx->pci_dev->physfn;
585 if (pci_dev_pf) {
586 efx_pf = pci_get_drvdata(pci_dev_pf);
587 nic_data_pf = efx_pf->nic_data;
588 vf = nic_data_pf->vf + nic_data->vf_index;
589 vf->efx = NULL;
590 } else
591 netif_info(efx, drv, efx->net_dev,
592 "Could not get the PF id from VF\n");
593 }
594#endif
595
Ben Hutchings9aecda92013-12-05 21:28:42 +0000596 efx_ptp_remove(efx);
597
Ben Hutchings8127d662013-08-29 19:19:29 +0100598 efx_mcdi_mon_remove(efx);
599
Ben Hutchings8127d662013-08-29 19:19:29 +0100600 efx_ef10_rx_free_indir_table(efx);
601
Ben Hutchings183233b2013-06-28 21:47:12 +0100602 if (nic_data->wc_membase)
603 iounmap(nic_data->wc_membase);
604
Ben Hutchings8127d662013-08-29 19:19:29 +0100605 rc = efx_ef10_free_vis(efx);
606 WARN_ON(rc != 0);
607
Ben Hutchings183233b2013-06-28 21:47:12 +0100608 if (!nic_data->must_restore_piobufs)
609 efx_ef10_free_piobufs(efx);
610
Ben Hutchings8127d662013-08-29 19:19:29 +0100611 efx_mcdi_fini(efx);
612 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
613 kfree(nic_data);
614}
615
Shradha Shah88a37de2015-05-20 11:09:15 +0100616static int efx_ef10_probe_pf(struct efx_nic *efx)
617{
618 return efx_ef10_probe(efx);
619}
620
621#ifdef CONFIG_SFC_SRIOV
622static int efx_ef10_probe_vf(struct efx_nic *efx)
623{
624 int rc;
625
626 rc = efx_ef10_probe(efx);
627 if (rc)
628 return rc;
629
630 rc = efx_ef10_get_vf_index(efx);
631 if (rc)
632 goto fail;
633
Shradha Shahf1122a32015-05-20 11:09:46 +0100634 if (efx->pci_dev->is_virtfn) {
635 if (efx->pci_dev->physfn) {
636 struct efx_nic *efx_pf =
637 pci_get_drvdata(efx->pci_dev->physfn);
638 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
639 struct efx_ef10_nic_data *nic_data = efx->nic_data;
640
641 nic_data_p->vf[nic_data->vf_index].efx = efx;
642 } else
643 netif_info(efx, drv, efx->net_dev,
644 "Could not get the PF id from VF\n");
645 }
646
Shradha Shah88a37de2015-05-20 11:09:15 +0100647 return 0;
648
649fail:
650 efx_ef10_remove(efx);
651 return rc;
652}
653#else
654static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
655{
656 return 0;
657}
658#endif
659
Ben Hutchings8127d662013-08-29 19:19:29 +0100660static int efx_ef10_alloc_vis(struct efx_nic *efx,
661 unsigned int min_vis, unsigned int max_vis)
662{
663 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
664 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
665 struct efx_ef10_nic_data *nic_data = efx->nic_data;
666 size_t outlen;
667 int rc;
668
669 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
670 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
671 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
672 outbuf, sizeof(outbuf), &outlen);
673 if (rc != 0)
674 return rc;
675
676 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
677 return -EIO;
678
679 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
680 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
681
682 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
683 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
684 return 0;
685}
686
Ben Hutchings183233b2013-06-28 21:47:12 +0100687/* Note that the failure path of this function does not free
688 * resources, as this will be done by efx_ef10_remove().
689 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100690static int efx_ef10_dimension_resources(struct efx_nic *efx)
691{
Ben Hutchings183233b2013-06-28 21:47:12 +0100692 struct efx_ef10_nic_data *nic_data = efx->nic_data;
693 unsigned int uc_mem_map_size, wc_mem_map_size;
694 unsigned int min_vis, pio_write_vi_base, max_vis;
695 void __iomem *membase;
696 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100697
Ben Hutchings183233b2013-06-28 21:47:12 +0100698 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
699
700#ifdef EFX_USE_PIO
701 /* Try to allocate PIO buffers if wanted and if the full
702 * number of PIO buffers would be sufficient to allocate one
703 * copy-buffer per TX channel. Failure is non-fatal, as there
704 * are only a small number of PIO buffers shared between all
705 * functions of the controller.
706 */
707 if (efx_piobuf_size != 0 &&
708 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
709 efx->n_tx_channels) {
710 unsigned int n_piobufs =
711 DIV_ROUND_UP(efx->n_tx_channels,
712 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
713
714 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
715 if (rc)
716 netif_err(efx, probe, efx->net_dev,
717 "failed to allocate PIO buffers (%d)\n", rc);
718 else
719 netif_dbg(efx, probe, efx->net_dev,
720 "allocated %u PIO buffers\n", n_piobufs);
721 }
722#else
723 nic_data->n_piobufs = 0;
724#endif
725
726 /* PIO buffers should be mapped with write-combining enabled,
727 * and we want to make single UC and WC mappings rather than
728 * several of each (in fact that's the only option if host
729 * page size is >4K). So we may allocate some extra VIs just
730 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100731 *
732 * The UC mapping contains (min_vis - 1) complete VIs and the
733 * first half of the next VI. Then the WC mapping begins with
734 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100735 */
736 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
737 ER_DZ_TX_PIOBUF);
738 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100739 /* pio_write_vi_base rounds down to give the number of complete
740 * VIs inside the UC mapping.
741 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100742 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
743 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
744 nic_data->n_piobufs) *
745 EFX_VI_PAGE_SIZE) -
746 uc_mem_map_size);
747 max_vis = pio_write_vi_base + nic_data->n_piobufs;
748 } else {
749 pio_write_vi_base = 0;
750 wc_mem_map_size = 0;
751 max_vis = min_vis;
752 }
753
754 /* In case the last attached driver failed to free VIs, do it now */
755 rc = efx_ef10_free_vis(efx);
756 if (rc != 0)
757 return rc;
758
759 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
760 if (rc != 0)
761 return rc;
762
763 /* If we didn't get enough VIs to map all the PIO buffers, free the
764 * PIO buffers
765 */
766 if (nic_data->n_piobufs &&
767 nic_data->n_allocated_vis <
768 pio_write_vi_base + nic_data->n_piobufs) {
769 netif_dbg(efx, probe, efx->net_dev,
770 "%u VIs are not sufficient to map %u PIO buffers\n",
771 nic_data->n_allocated_vis, nic_data->n_piobufs);
772 efx_ef10_free_piobufs(efx);
773 }
774
775 /* Shrink the original UC mapping of the memory BAR */
776 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
777 if (!membase) {
778 netif_err(efx, probe, efx->net_dev,
779 "could not shrink memory BAR to %x\n",
780 uc_mem_map_size);
781 return -ENOMEM;
782 }
783 iounmap(efx->membase);
784 efx->membase = membase;
785
786 /* Set up the WC mapping if needed */
787 if (wc_mem_map_size) {
788 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
789 uc_mem_map_size,
790 wc_mem_map_size);
791 if (!nic_data->wc_membase) {
792 netif_err(efx, probe, efx->net_dev,
793 "could not allocate WC mapping of size %x\n",
794 wc_mem_map_size);
795 return -ENOMEM;
796 }
797 nic_data->pio_write_vi_base = pio_write_vi_base;
798 nic_data->pio_write_base =
799 nic_data->wc_membase +
800 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
801 uc_mem_map_size);
802
803 rc = efx_ef10_link_piobufs(efx);
804 if (rc)
805 efx_ef10_free_piobufs(efx);
806 }
807
808 netif_dbg(efx, probe, efx->net_dev,
809 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
810 &efx->membase_phys, efx->membase, uc_mem_map_size,
811 nic_data->wc_membase, wc_mem_map_size);
812
813 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100814}
815
816static int efx_ef10_init_nic(struct efx_nic *efx)
817{
818 struct efx_ef10_nic_data *nic_data = efx->nic_data;
819 int rc;
820
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100821 if (nic_data->must_check_datapath_caps) {
822 rc = efx_ef10_init_datapath_caps(efx);
823 if (rc)
824 return rc;
825 nic_data->must_check_datapath_caps = false;
826 }
827
Ben Hutchings8127d662013-08-29 19:19:29 +0100828 if (nic_data->must_realloc_vis) {
829 /* We cannot let the number of VIs change now */
830 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
831 nic_data->n_allocated_vis);
832 if (rc)
833 return rc;
834 nic_data->must_realloc_vis = false;
835 }
836
Ben Hutchings183233b2013-06-28 21:47:12 +0100837 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
838 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
839 if (rc == 0) {
840 rc = efx_ef10_link_piobufs(efx);
841 if (rc)
842 efx_ef10_free_piobufs(efx);
843 }
844
845 /* Log an error on failure, but this is non-fatal */
846 if (rc)
847 netif_err(efx, drv, efx->net_dev,
848 "failed to restore PIO buffers (%d)\n", rc);
849 nic_data->must_restore_piobufs = false;
850 }
851
Jon Cooper267c0152015-05-06 00:59:38 +0100852 /* don't fail init if RSS setup doesn't work */
853 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
854
Ben Hutchings8127d662013-08-29 19:19:29 +0100855 return 0;
856}
857
Jon Cooper3e336262014-01-17 19:48:06 +0000858static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
859{
860 struct efx_ef10_nic_data *nic_data = efx->nic_data;
861
862 /* All our allocations have been reset */
863 nic_data->must_realloc_vis = true;
864 nic_data->must_restore_filters = true;
865 nic_data->must_restore_piobufs = true;
866 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
867}
868
Jon Cooper087e9022015-05-20 11:11:35 +0100869static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
870{
871 if (reason == RESET_TYPE_MC_FAILURE)
872 return RESET_TYPE_DATAPATH;
873
874 return efx_mcdi_map_reset_reason(reason);
875}
876
Ben Hutchings8127d662013-08-29 19:19:29 +0100877static int efx_ef10_map_reset_flags(u32 *flags)
878{
879 enum {
880 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
881 ETH_RESET_SHARED_SHIFT),
882 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
883 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
884 ETH_RESET_PHY | ETH_RESET_MGMT) <<
885 ETH_RESET_SHARED_SHIFT)
886 };
887
888 /* We assume for now that our PCI function is permitted to
889 * reset everything.
890 */
891
892 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
893 *flags &= ~EF10_RESET_MC;
894 return RESET_TYPE_WORLD;
895 }
896
897 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
898 *flags &= ~EF10_RESET_PORT;
899 return RESET_TYPE_ALL;
900 }
901
902 /* no invisible reset implemented */
903
904 return -EINVAL;
905}
906
Jon Cooper3e336262014-01-17 19:48:06 +0000907static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
908{
909 int rc = efx_mcdi_reset(efx, reset_type);
910
911 /* If it was a port reset, trigger reallocation of MC resources.
912 * Note that on an MC reset nothing needs to be done now because we'll
913 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +0100914 * For an FLR, we never get an MC reset event, but the MC has reset all
915 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +0000916 */
Edward Creee2835462014-04-16 19:27:48 +0100917 if ((reset_type == RESET_TYPE_ALL ||
918 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +0000919 efx_ef10_reset_mc_allocations(efx);
920 return rc;
921}
922
Ben Hutchings8127d662013-08-29 19:19:29 +0100923#define EF10_DMA_STAT(ext_name, mcdi_name) \
924 [EF10_STAT_ ## ext_name] = \
925 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
926#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
927 [EF10_STAT_ ## int_name] = \
928 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
929#define EF10_OTHER_STAT(ext_name) \
930 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +0100931#define GENERIC_SW_STAT(ext_name) \
932 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100933
934static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
935 EF10_DMA_STAT(tx_bytes, TX_BYTES),
936 EF10_DMA_STAT(tx_packets, TX_PKTS),
937 EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS),
938 EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS),
939 EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS),
940 EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS),
941 EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS),
942 EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS),
943 EF10_DMA_STAT(tx_64, TX_64_PKTS),
944 EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS),
945 EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS),
946 EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS),
947 EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS),
948 EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
949 EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
950 EF10_DMA_STAT(rx_bytes, RX_BYTES),
951 EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES),
952 EF10_OTHER_STAT(rx_good_bytes),
953 EF10_OTHER_STAT(rx_bad_bytes),
954 EF10_DMA_STAT(rx_packets, RX_PKTS),
955 EF10_DMA_STAT(rx_good, RX_GOOD_PKTS),
956 EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS),
957 EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS),
958 EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS),
959 EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS),
960 EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS),
961 EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS),
962 EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS),
963 EF10_DMA_STAT(rx_64, RX_64_PKTS),
964 EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS),
965 EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS),
966 EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS),
967 EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS),
968 EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
969 EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
970 EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS),
971 EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS),
972 EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS),
973 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
974 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
975 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +0100976 GENERIC_SW_STAT(rx_nodesc_trunc),
977 GENERIC_SW_STAT(rx_noskb_drops),
Edward Cree568d7a02013-09-25 17:32:09 +0100978 EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
979 EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
980 EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
981 EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
982 EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB),
983 EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB),
984 EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING),
985 EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
986 EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
987 EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
Shradha Shah79ac47a2013-11-28 18:48:49 +0000988 EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS),
989 EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS),
Ben Hutchings8127d662013-08-29 19:19:29 +0100990};
991
992#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \
993 (1ULL << EF10_STAT_tx_packets) | \
994 (1ULL << EF10_STAT_tx_pause) | \
995 (1ULL << EF10_STAT_tx_unicast) | \
996 (1ULL << EF10_STAT_tx_multicast) | \
997 (1ULL << EF10_STAT_tx_broadcast) | \
998 (1ULL << EF10_STAT_rx_bytes) | \
999 (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \
1000 (1ULL << EF10_STAT_rx_good_bytes) | \
1001 (1ULL << EF10_STAT_rx_bad_bytes) | \
1002 (1ULL << EF10_STAT_rx_packets) | \
1003 (1ULL << EF10_STAT_rx_good) | \
1004 (1ULL << EF10_STAT_rx_bad) | \
1005 (1ULL << EF10_STAT_rx_pause) | \
1006 (1ULL << EF10_STAT_rx_control) | \
1007 (1ULL << EF10_STAT_rx_unicast) | \
1008 (1ULL << EF10_STAT_rx_multicast) | \
1009 (1ULL << EF10_STAT_rx_broadcast) | \
1010 (1ULL << EF10_STAT_rx_lt64) | \
1011 (1ULL << EF10_STAT_rx_64) | \
1012 (1ULL << EF10_STAT_rx_65_to_127) | \
1013 (1ULL << EF10_STAT_rx_128_to_255) | \
1014 (1ULL << EF10_STAT_rx_256_to_511) | \
1015 (1ULL << EF10_STAT_rx_512_to_1023) | \
1016 (1ULL << EF10_STAT_rx_1024_to_15xx) | \
1017 (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \
1018 (1ULL << EF10_STAT_rx_gtjumbo) | \
1019 (1ULL << EF10_STAT_rx_bad_gtjumbo) | \
1020 (1ULL << EF10_STAT_rx_overflow) | \
Edward Creee4d112e2014-07-15 11:58:12 +01001021 (1ULL << EF10_STAT_rx_nodesc_drops) | \
1022 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1023 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001024
1025/* These statistics are only provided by the 10G MAC. For a 10G/40G
1026 * switchable port we do not expose these because they might not
1027 * include all the packets they should.
1028 */
1029#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \
1030 (1ULL << EF10_STAT_tx_lt64) | \
1031 (1ULL << EF10_STAT_tx_64) | \
1032 (1ULL << EF10_STAT_tx_65_to_127) | \
1033 (1ULL << EF10_STAT_tx_128_to_255) | \
1034 (1ULL << EF10_STAT_tx_256_to_511) | \
1035 (1ULL << EF10_STAT_tx_512_to_1023) | \
1036 (1ULL << EF10_STAT_tx_1024_to_15xx) | \
1037 (1ULL << EF10_STAT_tx_15xx_to_jumbo))
1038
1039/* These statistics are only provided by the 40G MAC. For a 10G/40G
1040 * switchable port we do expose these because the errors will otherwise
1041 * be silent.
1042 */
1043#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \
1044 (1ULL << EF10_STAT_rx_length_error))
1045
Edward Cree568d7a02013-09-25 17:32:09 +01001046/* These statistics are only provided if the firmware supports the
1047 * capability PM_AND_RXDP_COUNTERS.
1048 */
1049#define HUNT_PM_AND_RXDP_STAT_MASK ( \
1050 (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \
1051 (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \
1052 (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \
1053 (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \
1054 (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \
1055 (1ULL << EF10_STAT_rx_pm_discard_qbb) | \
1056 (1ULL << EF10_STAT_rx_pm_discard_mapping) | \
1057 (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \
1058 (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \
1059 (1ULL << EF10_STAT_rx_dp_streaming_packets) | \
Shradha Shah79ac47a2013-11-28 18:48:49 +00001060 (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \
1061 (1ULL << EF10_STAT_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001062
Edward Cree4bae9132013-09-27 18:52:49 +01001063static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001064{
Edward Cree4bae9132013-09-27 18:52:49 +01001065 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001066 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001067 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001068
1069 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001070 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001071 else
Edward Cree4bae9132013-09-27 18:52:49 +01001072 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001073
1074 if (nic_data->datapath_caps &
1075 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1076 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1077
Edward Cree4bae9132013-09-27 18:52:49 +01001078 return raw_mask;
1079}
1080
1081static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1082{
1083 u64 raw_mask = efx_ef10_raw_stat_mask(efx);
1084
1085#if BITS_PER_LONG == 64
1086 mask[0] = raw_mask;
1087#else
1088 mask[0] = raw_mask & 0xffffffff;
1089 mask[1] = raw_mask >> 32;
1090#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001091}
1092
1093static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1094{
Edward Cree4bae9132013-09-27 18:52:49 +01001095 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1096
1097 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001098 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001099 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001100}
1101
1102static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
1103{
1104 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001105 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001106 __le64 generation_start, generation_end;
1107 u64 *stats = nic_data->stats;
1108 __le64 *dma_stats;
1109
Edward Cree4bae9132013-09-27 18:52:49 +01001110 efx_ef10_get_stat_mask(efx, mask);
1111
Ben Hutchings8127d662013-08-29 19:19:29 +01001112 dma_stats = efx->stats_buffer.addr;
1113 nic_data = efx->nic_data;
1114
1115 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1116 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1117 return 0;
1118 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001119 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001120 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001121 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001122 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1123 if (generation_end != generation_start)
1124 return -EAGAIN;
1125
1126 /* Update derived statistics */
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001127 efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]);
Ben Hutchings8127d662013-08-29 19:19:29 +01001128 stats[EF10_STAT_rx_good_bytes] =
1129 stats[EF10_STAT_rx_bytes] -
1130 stats[EF10_STAT_rx_bytes_minus_good_bytes];
1131 efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes],
1132 stats[EF10_STAT_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001133 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001134 return 0;
1135}
1136
1137
1138static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats,
1139 struct rtnl_link_stats64 *core_stats)
1140{
Edward Cree4bae9132013-09-27 18:52:49 +01001141 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001142 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1143 u64 *stats = nic_data->stats;
1144 size_t stats_count = 0, index;
1145 int retry;
1146
Edward Cree4bae9132013-09-27 18:52:49 +01001147 efx_ef10_get_stat_mask(efx, mask);
1148
Ben Hutchings8127d662013-08-29 19:19:29 +01001149 /* If we're unlucky enough to read statistics during the DMA, wait
1150 * up to 10ms for it to finish (typically takes <500us)
1151 */
1152 for (retry = 0; retry < 100; ++retry) {
1153 if (efx_ef10_try_update_nic_stats(efx) == 0)
1154 break;
1155 udelay(100);
1156 }
1157
1158 if (full_stats) {
1159 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1160 if (efx_ef10_stat_desc[index].name) {
1161 *full_stats++ = stats[index];
1162 ++stats_count;
1163 }
1164 }
1165 }
1166
1167 if (core_stats) {
1168 core_stats->rx_packets = stats[EF10_STAT_rx_packets];
1169 core_stats->tx_packets = stats[EF10_STAT_tx_packets];
1170 core_stats->rx_bytes = stats[EF10_STAT_rx_bytes];
1171 core_stats->tx_bytes = stats[EF10_STAT_tx_bytes];
Edward Creee4d112e2014-07-15 11:58:12 +01001172 core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] +
1173 stats[GENERIC_STAT_rx_nodesc_trunc] +
1174 stats[GENERIC_STAT_rx_noskb_drops];
Ben Hutchings8127d662013-08-29 19:19:29 +01001175 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1176 core_stats->rx_length_errors =
1177 stats[EF10_STAT_rx_gtjumbo] +
1178 stats[EF10_STAT_rx_length_error];
1179 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1180 core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error];
1181 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1182 core_stats->rx_errors = (core_stats->rx_length_errors +
1183 core_stats->rx_crc_errors +
1184 core_stats->rx_frame_errors);
1185 }
1186
1187 return stats_count;
1188}
1189
1190static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1191{
1192 struct efx_nic *efx = channel->efx;
1193 unsigned int mode, value;
1194 efx_dword_t timer_cmd;
1195
1196 if (channel->irq_moderation) {
1197 mode = 3;
1198 value = channel->irq_moderation - 1;
1199 } else {
1200 mode = 0;
1201 value = 0;
1202 }
1203
1204 if (EFX_EF10_WORKAROUND_35388(efx)) {
1205 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1206 EFE_DD_EVQ_IND_TIMER_FLAGS,
1207 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1208 ERF_DD_EVQ_IND_TIMER_VAL, value);
1209 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1210 channel->channel);
1211 } else {
1212 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1213 ERF_DZ_TC_TIMER_VAL, value);
1214 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1215 channel->channel);
1216 }
1217}
1218
Shradha Shah02246a72015-05-06 00:58:14 +01001219static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1220 struct ethtool_wolinfo *wol) {}
1221
1222static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1223{
1224 return -EOPNOTSUPP;
1225}
1226
Ben Hutchings8127d662013-08-29 19:19:29 +01001227static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1228{
1229 wol->supported = 0;
1230 wol->wolopts = 0;
1231 memset(&wol->sopass, 0, sizeof(wol->sopass));
1232}
1233
1234static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1235{
1236 if (type != 0)
1237 return -EINVAL;
1238 return 0;
1239}
1240
1241static void efx_ef10_mcdi_request(struct efx_nic *efx,
1242 const efx_dword_t *hdr, size_t hdr_len,
1243 const efx_dword_t *sdu, size_t sdu_len)
1244{
1245 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1246 u8 *pdu = nic_data->mcdi_buf.addr;
1247
1248 memcpy(pdu, hdr, hdr_len);
1249 memcpy(pdu + hdr_len, sdu, sdu_len);
1250 wmb();
1251
1252 /* The hardware provides 'low' and 'high' (doorbell) registers
1253 * for passing the 64-bit address of an MCDI request to
1254 * firmware. However the dwords are swapped by firmware. The
1255 * least significant bits of the doorbell are then 0 for all
1256 * MCDI requests due to alignment.
1257 */
1258 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1259 ER_DZ_MC_DB_LWRD);
1260 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1261 ER_DZ_MC_DB_HWRD);
1262}
1263
1264static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1265{
1266 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1267 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1268
1269 rmb();
1270 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1271}
1272
1273static void
1274efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1275 size_t offset, size_t outlen)
1276{
1277 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1278 const u8 *pdu = nic_data->mcdi_buf.addr;
1279
1280 memcpy(outbuf, pdu + offset, outlen);
1281}
1282
1283static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1284{
1285 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1286 int rc;
1287
1288 rc = efx_ef10_get_warm_boot_count(efx);
1289 if (rc < 0) {
1290 /* The firmware is presumably in the process of
1291 * rebooting. However, we are supposed to report each
1292 * reboot just once, so we must only do that once we
1293 * can read and store the updated warm boot count.
1294 */
1295 return 0;
1296 }
1297
1298 if (rc == nic_data->warm_boot_count)
1299 return 0;
1300
1301 nic_data->warm_boot_count = rc;
1302
1303 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001304 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001305
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001306 /* Driver-created vswitches and vports must be re-created */
1307 nic_data->must_probe_vswitching = true;
1308 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1309
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001310 /* The datapath firmware might have been changed */
1311 nic_data->must_check_datapath_caps = true;
1312
Ben Hutchings869070c2013-09-05 22:46:10 +01001313 /* MAC statistics have been cleared on the NIC; clear the local
1314 * statistic that we update with efx_update_diff_stat().
1315 */
1316 nic_data->stats[EF10_STAT_rx_bad_bytes] = 0;
1317
Ben Hutchings8127d662013-08-29 19:19:29 +01001318 return -EIO;
1319}
1320
1321/* Handle an MSI interrupt
1322 *
1323 * Handle an MSI hardware interrupt. This routine schedules event
1324 * queue processing. No interrupt acknowledgement cycle is necessary.
1325 * Also, we never need to check that the interrupt is for us, since
1326 * MSI interrupts cannot be shared.
1327 */
1328static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1329{
1330 struct efx_msi_context *context = dev_id;
1331 struct efx_nic *efx = context->efx;
1332
1333 netif_vdbg(efx, intr, efx->net_dev,
1334 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1335
1336 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1337 /* Note test interrupts */
1338 if (context->index == efx->irq_level)
1339 efx->last_irq_cpu = raw_smp_processor_id();
1340
1341 /* Schedule processing of the channel */
1342 efx_schedule_channel_irq(efx->channel[context->index]);
1343 }
1344
1345 return IRQ_HANDLED;
1346}
1347
1348static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1349{
1350 struct efx_nic *efx = dev_id;
1351 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1352 struct efx_channel *channel;
1353 efx_dword_t reg;
1354 u32 queues;
1355
1356 /* Read the ISR which also ACKs the interrupts */
1357 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1358 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1359
1360 if (queues == 0)
1361 return IRQ_NONE;
1362
1363 if (likely(soft_enabled)) {
1364 /* Note test interrupts */
1365 if (queues & (1U << efx->irq_level))
1366 efx->last_irq_cpu = raw_smp_processor_id();
1367
1368 efx_for_each_channel(channel, efx) {
1369 if (queues & 1)
1370 efx_schedule_channel_irq(channel);
1371 queues >>= 1;
1372 }
1373 }
1374
1375 netif_vdbg(efx, intr, efx->net_dev,
1376 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1377 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1378
1379 return IRQ_HANDLED;
1380}
1381
1382static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1383{
1384 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1385
1386 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1387
1388 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1389 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1390 inbuf, sizeof(inbuf), NULL, 0, NULL);
1391}
1392
1393static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1394{
1395 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1396 (tx_queue->ptr_mask + 1) *
1397 sizeof(efx_qword_t),
1398 GFP_KERNEL);
1399}
1400
1401/* This writes to the TX_DESC_WPTR and also pushes data */
1402static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1403 const efx_qword_t *txd)
1404{
1405 unsigned int write_ptr;
1406 efx_oword_t reg;
1407
1408 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1409 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1410 reg.qword[0] = *txd;
1411 efx_writeo_page(tx_queue->efx, &reg,
1412 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1413}
1414
1415static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1416{
1417 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1418 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001419 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1420 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1421 struct efx_channel *channel = tx_queue->channel;
1422 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001423 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001424 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001425 dma_addr_t dma_addr;
1426 efx_qword_t *txd;
1427 int rc;
1428 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001429 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001430
1431 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1432 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1433 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1434 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1435 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1436 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1437 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1438 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001439 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001440
1441 dma_addr = tx_queue->txd.buf.dma_addr;
1442
1443 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1444 tx_queue->queue, entries, (u64)dma_addr);
1445
1446 for (i = 0; i < entries; ++i) {
1447 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1448 dma_addr += EFX_BUF_SIZE;
1449 }
1450
1451 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1452
1453 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001454 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001455 if (rc)
1456 goto fail;
1457
1458 /* A previous user of this TX queue might have set us up the
1459 * bomb by writing a descriptor to the TX push collector but
1460 * not the doorbell. (Each collector belongs to a port, not a
1461 * queue or function, so cannot easily be reset.) We must
1462 * attempt to push a no-op descriptor in its place.
1463 */
1464 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1465 tx_queue->insert_count = 1;
1466 txd = efx_tx_desc(tx_queue, 0);
1467 EFX_POPULATE_QWORD_4(*txd,
1468 ESF_DZ_TX_DESC_IS_OPT, true,
1469 ESF_DZ_TX_OPTION_TYPE,
1470 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1471 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1472 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1473 tx_queue->write_count = 1;
1474 wmb();
1475 efx_ef10_push_tx_desc(tx_queue, txd);
1476
1477 return;
1478
1479fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001480 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1481 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001482}
1483
1484static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1485{
1486 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001487 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001488 struct efx_nic *efx = tx_queue->efx;
1489 size_t outlen;
1490 int rc;
1491
1492 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1493 tx_queue->queue);
1494
Edward Cree1e0b8122013-05-31 18:36:12 +01001495 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001496 outbuf, sizeof(outbuf), &outlen);
1497
1498 if (rc && rc != -EALREADY)
1499 goto fail;
1500
1501 return;
1502
1503fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001504 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1505 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001506}
1507
1508static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1509{
1510 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1511}
1512
1513/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1514static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1515{
1516 unsigned int write_ptr;
1517 efx_dword_t reg;
1518
1519 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1520 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1521 efx_writed_page(tx_queue->efx, &reg,
1522 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1523}
1524
1525static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1526{
1527 unsigned int old_write_count = tx_queue->write_count;
1528 struct efx_tx_buffer *buffer;
1529 unsigned int write_ptr;
1530 efx_qword_t *txd;
1531
1532 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1533
1534 do {
1535 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1536 buffer = &tx_queue->buffer[write_ptr];
1537 txd = efx_tx_desc(tx_queue, write_ptr);
1538 ++tx_queue->write_count;
1539
1540 /* Create TX descriptor ring entry */
1541 if (buffer->flags & EFX_TX_BUF_OPTION) {
1542 *txd = buffer->option;
1543 } else {
1544 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1545 EFX_POPULATE_QWORD_3(
1546 *txd,
1547 ESF_DZ_TX_KER_CONT,
1548 buffer->flags & EFX_TX_BUF_CONT,
1549 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1550 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1551 }
1552 } while (tx_queue->write_count != tx_queue->insert_count);
1553
1554 wmb(); /* Ensure descriptors are written before they are fetched */
1555
1556 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1557 txd = efx_tx_desc(tx_queue,
1558 old_write_count & tx_queue->ptr_mask);
1559 efx_ef10_push_tx_desc(tx_queue, txd);
1560 ++tx_queue->pushes;
1561 } else {
1562 efx_ef10_notify_tx_desc(tx_queue);
1563 }
1564}
1565
Jon Cooper267c0152015-05-06 00:59:38 +01001566static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1567 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001568{
1569 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1570 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001571 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001572 size_t outlen;
1573 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001574 u32 alloc_type = exclusive ?
1575 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1576 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1577 unsigned rss_spread = exclusive ?
1578 efx->rss_spread :
1579 min(rounddown_pow_of_two(efx->rss_spread),
1580 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1581
1582 if (!exclusive && rss_spread == 1) {
1583 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1584 if (context_size)
1585 *context_size = 1;
1586 return 0;
1587 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001588
1589 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001590 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001591 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1592 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001593
1594 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1595 outbuf, sizeof(outbuf), &outlen);
1596 if (rc != 0)
1597 return rc;
1598
1599 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1600 return -EIO;
1601
1602 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1603
Jon Cooper267c0152015-05-06 00:59:38 +01001604 if (context_size)
1605 *context_size = rss_spread;
1606
Ben Hutchings8127d662013-08-29 19:19:29 +01001607 return 0;
1608}
1609
1610static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1611{
1612 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1613 int rc;
1614
1615 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1616 context);
1617
1618 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1619 NULL, 0, NULL);
1620 WARN_ON(rc != 0);
1621}
1622
Jon Cooper267c0152015-05-06 00:59:38 +01001623static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1624 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001625{
1626 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1627 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1628 int i, rc;
1629
1630 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1631 context);
1632 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1633 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1634
1635 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1636 MCDI_PTR(tablebuf,
1637 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001638 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001639
1640 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1641 sizeof(tablebuf), NULL, 0, NULL);
1642 if (rc != 0)
1643 return rc;
1644
1645 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1646 context);
1647 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1648 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1649 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1650 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1651 efx->rx_hash_key[i];
1652
1653 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1654 sizeof(keybuf), NULL, 0, NULL);
1655}
1656
1657static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1658{
1659 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1660
1661 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1662 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1663 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1664}
1665
Jon Cooper267c0152015-05-06 00:59:38 +01001666static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1667 unsigned *context_size)
1668{
1669 u32 new_rx_rss_context;
1670 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1671 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1672 false, context_size);
1673
1674 if (rc != 0)
1675 return rc;
1676
1677 nic_data->rx_rss_context = new_rx_rss_context;
1678 nic_data->rx_rss_context_exclusive = false;
1679 efx_set_default_rx_indir_table(efx);
1680 return 0;
1681}
1682
1683static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1684 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001685{
1686 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1687 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001688 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001689
Jon Cooper267c0152015-05-06 00:59:38 +01001690 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1691 !nic_data->rx_rss_context_exclusive) {
1692 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1693 true, NULL);
1694 if (rc == -EOPNOTSUPP)
1695 return rc;
1696 else if (rc != 0)
1697 goto fail1;
1698 } else {
1699 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001700 }
1701
Jon Cooper267c0152015-05-06 00:59:38 +01001702 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1703 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001704 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001705 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001706
Jon Cooper267c0152015-05-06 00:59:38 +01001707 if (nic_data->rx_rss_context != new_rx_rss_context)
1708 efx_ef10_rx_free_indir_table(efx);
1709 nic_data->rx_rss_context = new_rx_rss_context;
1710 nic_data->rx_rss_context_exclusive = true;
1711 if (rx_indir_table != efx->rx_indir_table)
1712 memcpy(efx->rx_indir_table, rx_indir_table,
1713 sizeof(efx->rx_indir_table));
1714 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001715
Jon Cooper267c0152015-05-06 00:59:38 +01001716fail2:
1717 if (new_rx_rss_context != nic_data->rx_rss_context)
1718 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1719fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001720 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001721 return rc;
1722}
1723
1724static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1725 const u32 *rx_indir_table)
1726{
1727 int rc;
1728
1729 if (efx->rss_spread == 1)
1730 return 0;
1731
1732 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1733
1734 if (rc == -ENOBUFS && !user) {
1735 unsigned context_size;
1736 bool mismatch = false;
1737 size_t i;
1738
1739 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1740 i++)
1741 mismatch = rx_indir_table[i] !=
1742 ethtool_rxfh_indir_default(i, efx->rss_spread);
1743
1744 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1745 if (rc == 0) {
1746 if (context_size != efx->rss_spread)
1747 netif_warn(efx, probe, efx->net_dev,
1748 "Could not allocate an exclusive RSS"
1749 " context; allocated a shared one of"
1750 " different size."
1751 " Wanted %u, got %u.\n",
1752 efx->rss_spread, context_size);
1753 else if (mismatch)
1754 netif_warn(efx, probe, efx->net_dev,
1755 "Could not allocate an exclusive RSS"
1756 " context; allocated a shared one but"
1757 " could not apply custom"
1758 " indirection.\n");
1759 else
1760 netif_info(efx, probe, efx->net_dev,
1761 "Could not allocate an exclusive RSS"
1762 " context; allocated a shared one.\n");
1763 }
1764 }
1765 return rc;
1766}
1767
1768static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1769 const u32 *rx_indir_table
1770 __attribute__ ((unused)))
1771{
1772 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1773
1774 if (user)
1775 return -EOPNOTSUPP;
1776 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1777 return 0;
1778 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001779}
1780
1781static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1782{
1783 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1784 (rx_queue->ptr_mask + 1) *
1785 sizeof(efx_qword_t),
1786 GFP_KERNEL);
1787}
1788
1789static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1790{
1791 MCDI_DECLARE_BUF(inbuf,
1792 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1793 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001794 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1795 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1796 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001797 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001798 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001799 dma_addr_t dma_addr;
1800 int rc;
1801 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001802 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001803
1804 rx_queue->scatter_n = 0;
1805 rx_queue->scatter_len = 0;
1806
1807 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1808 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1809 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1810 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1811 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001812 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1813 INIT_RXQ_IN_FLAG_PREFIX, 1,
1814 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001815 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001816 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001817
1818 dma_addr = rx_queue->rxd.buf.dma_addr;
1819
1820 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1821 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1822
1823 for (i = 0; i < entries; ++i) {
1824 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
1825 dma_addr += EFX_BUF_SIZE;
1826 }
1827
1828 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
1829
1830 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001831 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00001832 if (rc)
1833 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
1834 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01001835}
1836
1837static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
1838{
1839 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001840 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001841 struct efx_nic *efx = rx_queue->efx;
1842 size_t outlen;
1843 int rc;
1844
1845 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
1846 efx_rx_queue_index(rx_queue));
1847
Edward Cree1e0b8122013-05-31 18:36:12 +01001848 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001849 outbuf, sizeof(outbuf), &outlen);
1850
1851 if (rc && rc != -EALREADY)
1852 goto fail;
1853
1854 return;
1855
1856fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001857 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
1858 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001859}
1860
1861static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
1862{
1863 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
1864}
1865
1866/* This creates an entry in the RX descriptor queue */
1867static inline void
1868efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
1869{
1870 struct efx_rx_buffer *rx_buf;
1871 efx_qword_t *rxd;
1872
1873 rxd = efx_rx_desc(rx_queue, index);
1874 rx_buf = efx_rx_buffer(rx_queue, index);
1875 EFX_POPULATE_QWORD_2(*rxd,
1876 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
1877 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
1878}
1879
1880static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
1881{
1882 struct efx_nic *efx = rx_queue->efx;
1883 unsigned int write_count;
1884 efx_dword_t reg;
1885
1886 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
1887 write_count = rx_queue->added_count & ~7;
1888 if (rx_queue->notified_count == write_count)
1889 return;
1890
1891 do
1892 efx_ef10_build_rx_desc(
1893 rx_queue,
1894 rx_queue->notified_count & rx_queue->ptr_mask);
1895 while (++rx_queue->notified_count != write_count);
1896
1897 wmb();
1898 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
1899 write_count & rx_queue->ptr_mask);
1900 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
1901 efx_rx_queue_index(rx_queue));
1902}
1903
1904static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
1905
1906static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
1907{
1908 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1909 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
1910 efx_qword_t event;
1911
1912 EFX_POPULATE_QWORD_2(event,
1913 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
1914 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
1915
1916 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
1917
1918 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
1919 * already swapped the data to little-endian order.
1920 */
1921 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
1922 sizeof(efx_qword_t));
1923
1924 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
1925 inbuf, sizeof(inbuf), 0,
1926 efx_ef10_rx_defer_refill_complete, 0);
1927}
1928
1929static void
1930efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
1931 int rc, efx_dword_t *outbuf,
1932 size_t outlen_actual)
1933{
1934 /* nothing to do */
1935}
1936
1937static int efx_ef10_ev_probe(struct efx_channel *channel)
1938{
1939 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
1940 (channel->eventq_mask + 1) *
1941 sizeof(efx_qword_t),
1942 GFP_KERNEL);
1943}
1944
1945static int efx_ef10_ev_init(struct efx_channel *channel)
1946{
1947 MCDI_DECLARE_BUF(inbuf,
1948 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
1949 EFX_BUF_SIZE));
1950 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
1951 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
1952 struct efx_nic *efx = channel->efx;
1953 struct efx_ef10_nic_data *nic_data;
1954 bool supports_rx_merge;
1955 size_t inlen, outlen;
1956 dma_addr_t dma_addr;
1957 int rc;
1958 int i;
1959
1960 nic_data = efx->nic_data;
1961 supports_rx_merge =
1962 !!(nic_data->datapath_caps &
1963 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
1964
1965 /* Fill event queue with all ones (i.e. empty events) */
1966 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
1967
1968 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
1969 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
1970 /* INIT_EVQ expects index in vector table, not absolute */
1971 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
1972 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
1973 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
1974 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
1975 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
1976 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
1977 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
1978 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
1979 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
1980 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
1981 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
1982 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
1983 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
1984
1985 dma_addr = channel->eventq.buf.dma_addr;
1986 for (i = 0; i < entries; ++i) {
1987 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
1988 dma_addr += EFX_BUF_SIZE;
1989 }
1990
1991 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
1992
1993 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
1994 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01001995 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01001996 return rc;
1997}
1998
1999static void efx_ef10_ev_fini(struct efx_channel *channel)
2000{
2001 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002002 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002003 struct efx_nic *efx = channel->efx;
2004 size_t outlen;
2005 int rc;
2006
2007 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2008
Edward Cree1e0b8122013-05-31 18:36:12 +01002009 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002010 outbuf, sizeof(outbuf), &outlen);
2011
2012 if (rc && rc != -EALREADY)
2013 goto fail;
2014
2015 return;
2016
2017fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002018 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2019 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002020}
2021
2022static void efx_ef10_ev_remove(struct efx_channel *channel)
2023{
2024 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2025}
2026
2027static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2028 unsigned int rx_queue_label)
2029{
2030 struct efx_nic *efx = rx_queue->efx;
2031
2032 netif_info(efx, hw, efx->net_dev,
2033 "rx event arrived on queue %d labeled as queue %u\n",
2034 efx_rx_queue_index(rx_queue), rx_queue_label);
2035
2036 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2037}
2038
2039static void
2040efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2041 unsigned int actual, unsigned int expected)
2042{
2043 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2044 struct efx_nic *efx = rx_queue->efx;
2045
2046 netif_info(efx, hw, efx->net_dev,
2047 "dropped %d events (index=%d expected=%d)\n",
2048 dropped, actual, expected);
2049
2050 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2051}
2052
2053/* partially received RX was aborted. clean up. */
2054static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2055{
2056 unsigned int rx_desc_ptr;
2057
Ben Hutchings8127d662013-08-29 19:19:29 +01002058 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2059 "scattered RX aborted (dropping %u buffers)\n",
2060 rx_queue->scatter_n);
2061
2062 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2063
2064 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2065 0, EFX_RX_PKT_DISCARD);
2066
2067 rx_queue->removed_count += rx_queue->scatter_n;
2068 rx_queue->scatter_n = 0;
2069 rx_queue->scatter_len = 0;
2070 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2071}
2072
2073static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2074 const efx_qword_t *event)
2075{
2076 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2077 unsigned int n_descs, n_packets, i;
2078 struct efx_nic *efx = channel->efx;
2079 struct efx_rx_queue *rx_queue;
2080 bool rx_cont;
2081 u16 flags = 0;
2082
2083 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2084 return 0;
2085
2086 /* Basic packet information */
2087 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2088 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2089 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2090 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2091 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2092
Ben Hutchings48ce5632013-11-01 16:42:44 +00002093 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2094 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2095 EFX_QWORD_FMT "\n",
2096 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002097
2098 rx_queue = efx_channel_get_rx_queue(channel);
2099
2100 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2101 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2102
2103 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2104 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2105
2106 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002107 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2108
Ben Hutchings8127d662013-08-29 19:19:29 +01002109 /* detect rx abort */
2110 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002111 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2112 netdev_WARN(efx->net_dev,
2113 "invalid RX abort: scatter_n=%u event="
2114 EFX_QWORD_FMT "\n",
2115 rx_queue->scatter_n,
2116 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002117 efx_ef10_handle_rx_abort(rx_queue);
2118 return 0;
2119 }
2120
Ben Hutchings92a04162013-09-24 23:21:57 +01002121 /* Check that RX completion merging is valid, i.e.
2122 * the current firmware supports it and this is a
2123 * non-scattered packet.
2124 */
2125 if (!(nic_data->datapath_caps &
2126 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2127 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002128 efx_ef10_handle_rx_bad_lbits(
2129 rx_queue, next_ptr_lbits,
2130 (rx_queue->removed_count +
2131 rx_queue->scatter_n + 1) &
2132 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2133 return 0;
2134 }
2135
2136 /* Merged completion for multiple non-scattered packets */
2137 rx_queue->scatter_n = 1;
2138 rx_queue->scatter_len = 0;
2139 n_packets = n_descs;
2140 ++channel->n_rx_merge_events;
2141 channel->n_rx_merge_packets += n_packets;
2142 flags |= EFX_RX_PKT_PREFIX_LEN;
2143 } else {
2144 ++rx_queue->scatter_n;
2145 rx_queue->scatter_len += rx_bytes;
2146 if (rx_cont)
2147 return 0;
2148 n_packets = 1;
2149 }
2150
2151 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2152 flags |= EFX_RX_PKT_DISCARD;
2153
2154 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2155 channel->n_rx_ip_hdr_chksum_err += n_packets;
2156 } else if (unlikely(EFX_QWORD_FIELD(*event,
2157 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2158 channel->n_rx_tcp_udp_chksum_err += n_packets;
2159 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2160 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2161 flags |= EFX_RX_PKT_CSUMMED;
2162 }
2163
2164 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2165 flags |= EFX_RX_PKT_TCP;
2166
2167 channel->irq_mod_score += 2 * n_packets;
2168
2169 /* Handle received packet(s) */
2170 for (i = 0; i < n_packets; i++) {
2171 efx_rx_packet(rx_queue,
2172 rx_queue->removed_count & rx_queue->ptr_mask,
2173 rx_queue->scatter_n, rx_queue->scatter_len,
2174 flags);
2175 rx_queue->removed_count += rx_queue->scatter_n;
2176 }
2177
2178 rx_queue->scatter_n = 0;
2179 rx_queue->scatter_len = 0;
2180
2181 return n_packets;
2182}
2183
2184static int
2185efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2186{
2187 struct efx_nic *efx = channel->efx;
2188 struct efx_tx_queue *tx_queue;
2189 unsigned int tx_ev_desc_ptr;
2190 unsigned int tx_ev_q_label;
2191 int tx_descs = 0;
2192
2193 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2194 return 0;
2195
2196 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2197 return 0;
2198
2199 /* Transmit completion */
2200 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2201 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2202 tx_queue = efx_channel_get_tx_queue(channel,
2203 tx_ev_q_label % EFX_TXQ_TYPES);
2204 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2205 tx_queue->ptr_mask);
2206 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2207
2208 return tx_descs;
2209}
2210
2211static void
2212efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2213{
2214 struct efx_nic *efx = channel->efx;
2215 int subcode;
2216
2217 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2218
2219 switch (subcode) {
2220 case ESE_DZ_DRV_TIMER_EV:
2221 case ESE_DZ_DRV_WAKE_UP_EV:
2222 break;
2223 case ESE_DZ_DRV_START_UP_EV:
2224 /* event queue init complete. ok. */
2225 break;
2226 default:
2227 netif_err(efx, hw, efx->net_dev,
2228 "channel %d unknown driver event type %d"
2229 " (data " EFX_QWORD_FMT ")\n",
2230 channel->channel, subcode,
2231 EFX_QWORD_VAL(*event));
2232
2233 }
2234}
2235
2236static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2237 efx_qword_t *event)
2238{
2239 struct efx_nic *efx = channel->efx;
2240 u32 subcode;
2241
2242 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2243
2244 switch (subcode) {
2245 case EFX_EF10_TEST:
2246 channel->event_test_cpu = raw_smp_processor_id();
2247 break;
2248 case EFX_EF10_REFILL:
2249 /* The queue must be empty, so we won't receive any rx
2250 * events, so efx_process_channel() won't refill the
2251 * queue. Refill it here
2252 */
Jon Coopercce28792013-10-02 11:04:14 +01002253 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002254 break;
2255 default:
2256 netif_err(efx, hw, efx->net_dev,
2257 "channel %d unknown driver event type %u"
2258 " (data " EFX_QWORD_FMT ")\n",
2259 channel->channel, (unsigned) subcode,
2260 EFX_QWORD_VAL(*event));
2261 }
2262}
2263
2264static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2265{
2266 struct efx_nic *efx = channel->efx;
2267 efx_qword_t event, *p_event;
2268 unsigned int read_ptr;
2269 int ev_code;
2270 int tx_descs = 0;
2271 int spent = 0;
2272
Eric W. Biederman75363a42014-03-14 18:11:22 -07002273 if (quota <= 0)
2274 return spent;
2275
Ben Hutchings8127d662013-08-29 19:19:29 +01002276 read_ptr = channel->eventq_read_ptr;
2277
2278 for (;;) {
2279 p_event = efx_event(channel, read_ptr);
2280 event = *p_event;
2281
2282 if (!efx_event_present(&event))
2283 break;
2284
2285 EFX_SET_QWORD(*p_event);
2286
2287 ++read_ptr;
2288
2289 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2290
2291 netif_vdbg(efx, drv, efx->net_dev,
2292 "processing event on %d " EFX_QWORD_FMT "\n",
2293 channel->channel, EFX_QWORD_VAL(event));
2294
2295 switch (ev_code) {
2296 case ESE_DZ_EV_CODE_MCDI_EV:
2297 efx_mcdi_process_event(channel, &event);
2298 break;
2299 case ESE_DZ_EV_CODE_RX_EV:
2300 spent += efx_ef10_handle_rx_event(channel, &event);
2301 if (spent >= quota) {
2302 /* XXX can we split a merged event to
2303 * avoid going over-quota?
2304 */
2305 spent = quota;
2306 goto out;
2307 }
2308 break;
2309 case ESE_DZ_EV_CODE_TX_EV:
2310 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2311 if (tx_descs > efx->txq_entries) {
2312 spent = quota;
2313 goto out;
2314 } else if (++spent == quota) {
2315 goto out;
2316 }
2317 break;
2318 case ESE_DZ_EV_CODE_DRIVER_EV:
2319 efx_ef10_handle_driver_event(channel, &event);
2320 if (++spent == quota)
2321 goto out;
2322 break;
2323 case EFX_EF10_DRVGEN_EV:
2324 efx_ef10_handle_driver_generated_event(channel, &event);
2325 break;
2326 default:
2327 netif_err(efx, hw, efx->net_dev,
2328 "channel %d unknown event type %d"
2329 " (data " EFX_QWORD_FMT ")\n",
2330 channel->channel, ev_code,
2331 EFX_QWORD_VAL(event));
2332 }
2333 }
2334
2335out:
2336 channel->eventq_read_ptr = read_ptr;
2337 return spent;
2338}
2339
2340static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2341{
2342 struct efx_nic *efx = channel->efx;
2343 efx_dword_t rptr;
2344
2345 if (EFX_EF10_WORKAROUND_35388(efx)) {
2346 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2347 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2348 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2349 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2350
2351 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2352 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2353 ERF_DD_EVQ_IND_RPTR,
2354 (channel->eventq_read_ptr &
2355 channel->eventq_mask) >>
2356 ERF_DD_EVQ_IND_RPTR_WIDTH);
2357 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2358 channel->channel);
2359 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2360 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2361 ERF_DD_EVQ_IND_RPTR,
2362 channel->eventq_read_ptr &
2363 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2364 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2365 channel->channel);
2366 } else {
2367 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2368 channel->eventq_read_ptr &
2369 channel->eventq_mask);
2370 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2371 }
2372}
2373
2374static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2375{
2376 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2377 struct efx_nic *efx = channel->efx;
2378 efx_qword_t event;
2379 int rc;
2380
2381 EFX_POPULATE_QWORD_2(event,
2382 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2383 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2384
2385 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2386
2387 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2388 * already swapped the data to little-endian order.
2389 */
2390 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2391 sizeof(efx_qword_t));
2392
2393 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2394 NULL, 0, NULL);
2395 if (rc != 0)
2396 goto fail;
2397
2398 return;
2399
2400fail:
2401 WARN_ON(true);
2402 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2403}
2404
2405void efx_ef10_handle_drain_event(struct efx_nic *efx)
2406{
2407 if (atomic_dec_and_test(&efx->active_queues))
2408 wake_up(&efx->flush_wq);
2409
2410 WARN_ON(atomic_read(&efx->active_queues) < 0);
2411}
2412
2413static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2414{
2415 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2416 struct efx_channel *channel;
2417 struct efx_tx_queue *tx_queue;
2418 struct efx_rx_queue *rx_queue;
2419 int pending;
2420
2421 /* If the MC has just rebooted, the TX/RX queues will have already been
2422 * torn down, but efx->active_queues needs to be set to zero.
2423 */
2424 if (nic_data->must_realloc_vis) {
2425 atomic_set(&efx->active_queues, 0);
2426 return 0;
2427 }
2428
2429 /* Do not attempt to write to the NIC during EEH recovery */
2430 if (efx->state != STATE_RECOVERY) {
2431 efx_for_each_channel(channel, efx) {
2432 efx_for_each_channel_rx_queue(rx_queue, channel)
2433 efx_ef10_rx_fini(rx_queue);
2434 efx_for_each_channel_tx_queue(tx_queue, channel)
2435 efx_ef10_tx_fini(tx_queue);
2436 }
2437
2438 wait_event_timeout(efx->flush_wq,
2439 atomic_read(&efx->active_queues) == 0,
2440 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2441 pending = atomic_read(&efx->active_queues);
2442 if (pending) {
2443 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2444 pending);
2445 return -ETIMEDOUT;
2446 }
2447 }
2448
2449 return 0;
2450}
2451
Edward Creee2835462014-04-16 19:27:48 +01002452static void efx_ef10_prepare_flr(struct efx_nic *efx)
2453{
2454 atomic_set(&efx->active_queues, 0);
2455}
2456
Ben Hutchings8127d662013-08-29 19:19:29 +01002457static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2458 const struct efx_filter_spec *right)
2459{
2460 if ((left->match_flags ^ right->match_flags) |
2461 ((left->flags ^ right->flags) &
2462 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2463 return false;
2464
2465 return memcmp(&left->outer_vid, &right->outer_vid,
2466 sizeof(struct efx_filter_spec) -
2467 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2468}
2469
2470static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2471{
2472 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2473 return jhash2((const u32 *)&spec->outer_vid,
2474 (sizeof(struct efx_filter_spec) -
2475 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2476 0);
2477 /* XXX should we randomise the initval? */
2478}
2479
2480/* Decide whether a filter should be exclusive or else should allow
2481 * delivery to additional recipients. Currently we decide that
2482 * filters for specific local unicast MAC and IP addresses are
2483 * exclusive.
2484 */
2485static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2486{
2487 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2488 !is_multicast_ether_addr(spec->loc_mac))
2489 return true;
2490
2491 if ((spec->match_flags &
2492 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2493 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2494 if (spec->ether_type == htons(ETH_P_IP) &&
2495 !ipv4_is_multicast(spec->loc_host[0]))
2496 return true;
2497 if (spec->ether_type == htons(ETH_P_IPV6) &&
2498 ((const u8 *)spec->loc_host)[0] != 0xff)
2499 return true;
2500 }
2501
2502 return false;
2503}
2504
2505static struct efx_filter_spec *
2506efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2507 unsigned int filter_idx)
2508{
2509 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2510 ~EFX_EF10_FILTER_FLAGS);
2511}
2512
2513static unsigned int
2514efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2515 unsigned int filter_idx)
2516{
2517 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2518}
2519
2520static void
2521efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2522 unsigned int filter_idx,
2523 const struct efx_filter_spec *spec,
2524 unsigned int flags)
2525{
2526 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2527}
2528
2529static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2530 const struct efx_filter_spec *spec,
2531 efx_dword_t *inbuf, u64 handle,
2532 bool replacing)
2533{
2534 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2535
2536 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2537
2538 if (replacing) {
2539 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2540 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2541 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2542 } else {
2543 u32 match_fields = 0;
2544
2545 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2546 efx_ef10_filter_is_exclusive(spec) ?
2547 MC_CMD_FILTER_OP_IN_OP_INSERT :
2548 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2549
2550 /* Convert match flags and values. Unlike almost
2551 * everything else in MCDI, these fields are in
2552 * network byte order.
2553 */
2554 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2555 match_fields |=
2556 is_multicast_ether_addr(spec->loc_mac) ?
2557 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2558 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2559#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2560 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2561 match_fields |= \
2562 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2563 mcdi_field ## _LBN; \
2564 BUILD_BUG_ON( \
2565 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2566 sizeof(spec->gen_field)); \
2567 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2568 &spec->gen_field, sizeof(spec->gen_field)); \
2569 }
2570 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2571 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2572 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2573 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2574 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2575 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2576 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2577 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2578 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2579 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2580#undef COPY_FIELD
2581 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2582 match_fields);
2583 }
2584
Daniel Pieczko45b24492015-05-06 00:57:14 +01002585 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002586 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2587 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2588 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2589 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002590 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002591 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2592 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002593 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2594 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2595 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002596 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2597 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2598 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2599 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2600 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2601 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2602 spec->rss_context !=
2603 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2604 spec->rss_context : nic_data->rx_rss_context);
2605}
2606
2607static int efx_ef10_filter_push(struct efx_nic *efx,
2608 const struct efx_filter_spec *spec,
2609 u64 *handle, bool replacing)
2610{
2611 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2612 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2613 int rc;
2614
2615 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2616 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2617 outbuf, sizeof(outbuf), NULL);
2618 if (rc == 0)
2619 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002620 if (rc == -ENOSPC)
2621 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002622 return rc;
2623}
2624
2625static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2626 enum efx_filter_match_flags match_flags)
2627{
2628 unsigned int match_pri;
2629
2630 for (match_pri = 0;
2631 match_pri < table->rx_match_count;
2632 match_pri++)
2633 if (table->rx_match_flags[match_pri] == match_flags)
2634 return match_pri;
2635
2636 return -EPROTONOSUPPORT;
2637}
2638
2639static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2640 struct efx_filter_spec *spec,
2641 bool replace_equal)
2642{
2643 struct efx_ef10_filter_table *table = efx->filter_state;
2644 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2645 struct efx_filter_spec *saved_spec;
2646 unsigned int match_pri, hash;
2647 unsigned int priv_flags;
2648 bool replacing = false;
2649 int ins_index = -1;
2650 DEFINE_WAIT(wait);
2651 bool is_mc_recip;
2652 s32 rc;
2653
2654 /* For now, only support RX filters */
2655 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2656 EFX_FILTER_FLAG_RX)
2657 return -EINVAL;
2658
2659 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2660 if (rc < 0)
2661 return rc;
2662 match_pri = rc;
2663
2664 hash = efx_ef10_filter_hash(spec);
2665 is_mc_recip = efx_filter_is_mc_recipient(spec);
2666 if (is_mc_recip)
2667 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2668
2669 /* Find any existing filters with the same match tuple or
2670 * else a free slot to insert at. If any of them are busy,
2671 * we have to wait and retry.
2672 */
2673 for (;;) {
2674 unsigned int depth = 1;
2675 unsigned int i;
2676
2677 spin_lock_bh(&efx->filter_lock);
2678
2679 for (;;) {
2680 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2681 saved_spec = efx_ef10_filter_entry_spec(table, i);
2682
2683 if (!saved_spec) {
2684 if (ins_index < 0)
2685 ins_index = i;
2686 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2687 if (table->entry[i].spec &
2688 EFX_EF10_FILTER_FLAG_BUSY)
2689 break;
2690 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002691 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002692 rc = -EPERM;
2693 goto out_unlock;
2694 }
2695 if (!is_mc_recip) {
2696 /* This is the only one */
2697 if (spec->priority ==
2698 saved_spec->priority &&
2699 !replace_equal) {
2700 rc = -EEXIST;
2701 goto out_unlock;
2702 }
2703 ins_index = i;
2704 goto found;
2705 } else if (spec->priority >
2706 saved_spec->priority ||
2707 (spec->priority ==
2708 saved_spec->priority &&
2709 replace_equal)) {
2710 if (ins_index < 0)
2711 ins_index = i;
2712 else
2713 __set_bit(depth, mc_rem_map);
2714 }
2715 }
2716
2717 /* Once we reach the maximum search depth, use
2718 * the first suitable slot or return -EBUSY if
2719 * there was none
2720 */
2721 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2722 if (ins_index < 0) {
2723 rc = -EBUSY;
2724 goto out_unlock;
2725 }
2726 goto found;
2727 }
2728
2729 ++depth;
2730 }
2731
2732 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2733 spin_unlock_bh(&efx->filter_lock);
2734 schedule();
2735 }
2736
2737found:
2738 /* Create a software table entry if necessary, and mark it
2739 * busy. We might yet fail to insert, but any attempt to
2740 * insert a conflicting filter while we're waiting for the
2741 * firmware must find the busy entry.
2742 */
2743 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2744 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002745 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2746 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002747 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002748 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2749 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002750 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002751 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002752 rc = ins_index;
2753 goto out_unlock;
2754 }
2755 replacing = true;
2756 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2757 } else {
2758 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2759 if (!saved_spec) {
2760 rc = -ENOMEM;
2761 goto out_unlock;
2762 }
2763 *saved_spec = *spec;
2764 priv_flags = 0;
2765 }
2766 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2767 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2768
2769 /* Mark lower-priority multicast recipients busy prior to removal */
2770 if (is_mc_recip) {
2771 unsigned int depth, i;
2772
2773 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2774 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2775 if (test_bit(depth, mc_rem_map))
2776 table->entry[i].spec |=
2777 EFX_EF10_FILTER_FLAG_BUSY;
2778 }
2779 }
2780
2781 spin_unlock_bh(&efx->filter_lock);
2782
2783 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2784 replacing);
2785
2786 /* Finalise the software table entry */
2787 spin_lock_bh(&efx->filter_lock);
2788 if (rc == 0) {
2789 if (replacing) {
2790 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002791 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2792 saved_spec->flags |=
2793 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002794 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002795 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002796 saved_spec->flags |= spec->flags;
2797 saved_spec->rss_context = spec->rss_context;
2798 saved_spec->dmaq_id = spec->dmaq_id;
2799 }
2800 } else if (!replacing) {
2801 kfree(saved_spec);
2802 saved_spec = NULL;
2803 }
2804 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2805
2806 /* Remove and finalise entries for lower-priority multicast
2807 * recipients
2808 */
2809 if (is_mc_recip) {
2810 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2811 unsigned int depth, i;
2812
2813 memset(inbuf, 0, sizeof(inbuf));
2814
2815 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2816 if (!test_bit(depth, mc_rem_map))
2817 continue;
2818
2819 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2820 saved_spec = efx_ef10_filter_entry_spec(table, i);
2821 priv_flags = efx_ef10_filter_entry_flags(table, i);
2822
2823 if (rc == 0) {
2824 spin_unlock_bh(&efx->filter_lock);
2825 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2826 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2827 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2828 table->entry[i].handle);
2829 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2830 inbuf, sizeof(inbuf),
2831 NULL, 0, NULL);
2832 spin_lock_bh(&efx->filter_lock);
2833 }
2834
2835 if (rc == 0) {
2836 kfree(saved_spec);
2837 saved_spec = NULL;
2838 priv_flags = 0;
2839 } else {
2840 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
2841 }
2842 efx_ef10_filter_set_entry(table, i, saved_spec,
2843 priv_flags);
2844 }
2845 }
2846
2847 /* If successful, return the inserted filter ID */
2848 if (rc == 0)
2849 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
2850
2851 wake_up_all(&table->waitq);
2852out_unlock:
2853 spin_unlock_bh(&efx->filter_lock);
2854 finish_wait(&table->waitq, &wait);
2855 return rc;
2856}
2857
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08002858static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002859{
2860 /* no need to do anything here on EF10 */
2861}
2862
2863/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002864 * If !by_index, remove by ID
2865 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01002866 * Filter ID may come from userland and must be range-checked.
2867 */
2868static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002869 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002870 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01002871{
2872 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2873 struct efx_ef10_filter_table *table = efx->filter_state;
2874 MCDI_DECLARE_BUF(inbuf,
2875 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2876 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2877 struct efx_filter_spec *spec;
2878 DEFINE_WAIT(wait);
2879 int rc;
2880
2881 /* Find the software table entry and mark it busy. Don't
2882 * remove it yet; any attempt to update while we're waiting
2883 * for the firmware must find the busy entry.
2884 */
2885 for (;;) {
2886 spin_lock_bh(&efx->filter_lock);
2887 if (!(table->entry[filter_idx].spec &
2888 EFX_EF10_FILTER_FLAG_BUSY))
2889 break;
2890 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2891 spin_unlock_bh(&efx->filter_lock);
2892 schedule();
2893 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002894
Ben Hutchings8127d662013-08-29 19:19:29 +01002895 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002896 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002897 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01002898 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
2899 filter_id / HUNT_FILTER_TBL_ROWS)) {
2900 rc = -ENOENT;
2901 goto out_unlock;
2902 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002903
2904 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002905 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002906 /* Just remove flags */
2907 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002908 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002909 rc = 0;
2910 goto out_unlock;
2911 }
2912
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002913 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002914 rc = -ENOENT;
2915 goto out_unlock;
2916 }
2917
Ben Hutchings8127d662013-08-29 19:19:29 +01002918 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2919 spin_unlock_bh(&efx->filter_lock);
2920
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002921 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002922 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01002923
2924 struct efx_filter_spec new_spec = *spec;
2925
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002926 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002927 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002928 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01002929 new_spec.dmaq_id = 0;
2930 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
2931 rc = efx_ef10_filter_push(efx, &new_spec,
2932 &table->entry[filter_idx].handle,
2933 true);
2934
2935 spin_lock_bh(&efx->filter_lock);
2936 if (rc == 0)
2937 *spec = new_spec;
2938 } else {
2939 /* Really remove the filter */
2940
2941 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2942 efx_ef10_filter_is_exclusive(spec) ?
2943 MC_CMD_FILTER_OP_IN_OP_REMOVE :
2944 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2945 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2946 table->entry[filter_idx].handle);
2947 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2948 inbuf, sizeof(inbuf), NULL, 0, NULL);
2949
2950 spin_lock_bh(&efx->filter_lock);
2951 if (rc == 0) {
2952 kfree(spec);
2953 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2954 }
2955 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002956
Ben Hutchings8127d662013-08-29 19:19:29 +01002957 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2958 wake_up_all(&table->waitq);
2959out_unlock:
2960 spin_unlock_bh(&efx->filter_lock);
2961 finish_wait(&table->waitq, &wait);
2962 return rc;
2963}
2964
2965static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
2966 enum efx_filter_priority priority,
2967 u32 filter_id)
2968{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002969 return efx_ef10_filter_remove_internal(efx, 1U << priority,
2970 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01002971}
2972
2973static int efx_ef10_filter_get_safe(struct efx_nic *efx,
2974 enum efx_filter_priority priority,
2975 u32 filter_id, struct efx_filter_spec *spec)
2976{
2977 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2978 struct efx_ef10_filter_table *table = efx->filter_state;
2979 const struct efx_filter_spec *saved_spec;
2980 int rc;
2981
2982 spin_lock_bh(&efx->filter_lock);
2983 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
2984 if (saved_spec && saved_spec->priority == priority &&
2985 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
2986 filter_id / HUNT_FILTER_TBL_ROWS) {
2987 *spec = *saved_spec;
2988 rc = 0;
2989 } else {
2990 rc = -ENOENT;
2991 }
2992 spin_unlock_bh(&efx->filter_lock);
2993 return rc;
2994}
2995
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002996static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01002997 enum efx_filter_priority priority)
2998{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002999 unsigned int priority_mask;
3000 unsigned int i;
3001 int rc;
3002
3003 priority_mask = (((1U << (priority + 1)) - 1) &
3004 ~(1U << EFX_FILTER_PRI_AUTO));
3005
3006 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3007 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3008 i, true);
3009 if (rc && rc != -ENOENT)
3010 return rc;
3011 }
3012
3013 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003014}
3015
3016static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3017 enum efx_filter_priority priority)
3018{
3019 struct efx_ef10_filter_table *table = efx->filter_state;
3020 unsigned int filter_idx;
3021 s32 count = 0;
3022
3023 spin_lock_bh(&efx->filter_lock);
3024 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3025 if (table->entry[filter_idx].spec &&
3026 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3027 priority)
3028 ++count;
3029 }
3030 spin_unlock_bh(&efx->filter_lock);
3031 return count;
3032}
3033
3034static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3035{
3036 struct efx_ef10_filter_table *table = efx->filter_state;
3037
3038 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3039}
3040
3041static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3042 enum efx_filter_priority priority,
3043 u32 *buf, u32 size)
3044{
3045 struct efx_ef10_filter_table *table = efx->filter_state;
3046 struct efx_filter_spec *spec;
3047 unsigned int filter_idx;
3048 s32 count = 0;
3049
3050 spin_lock_bh(&efx->filter_lock);
3051 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3052 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3053 if (spec && spec->priority == priority) {
3054 if (count == size) {
3055 count = -EMSGSIZE;
3056 break;
3057 }
3058 buf[count++] = (efx_ef10_filter_rx_match_pri(
3059 table, spec->match_flags) *
3060 HUNT_FILTER_TBL_ROWS +
3061 filter_idx);
3062 }
3063 }
3064 spin_unlock_bh(&efx->filter_lock);
3065 return count;
3066}
3067
3068#ifdef CONFIG_RFS_ACCEL
3069
3070static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3071
3072static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3073 struct efx_filter_spec *spec)
3074{
3075 struct efx_ef10_filter_table *table = efx->filter_state;
3076 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3077 struct efx_filter_spec *saved_spec;
3078 unsigned int hash, i, depth = 1;
3079 bool replacing = false;
3080 int ins_index = -1;
3081 u64 cookie;
3082 s32 rc;
3083
3084 /* Must be an RX filter without RSS and not for a multicast
3085 * destination address (RFS only works for connected sockets).
3086 * These restrictions allow us to pass only a tiny amount of
3087 * data through to the completion function.
3088 */
3089 EFX_WARN_ON_PARANOID(spec->flags !=
3090 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3091 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3092 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3093
3094 hash = efx_ef10_filter_hash(spec);
3095
3096 spin_lock_bh(&efx->filter_lock);
3097
3098 /* Find any existing filter with the same match tuple or else
3099 * a free slot to insert at. If an existing filter is busy,
3100 * we have to give up.
3101 */
3102 for (;;) {
3103 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3104 saved_spec = efx_ef10_filter_entry_spec(table, i);
3105
3106 if (!saved_spec) {
3107 if (ins_index < 0)
3108 ins_index = i;
3109 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3110 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3111 rc = -EBUSY;
3112 goto fail_unlock;
3113 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003114 if (spec->priority < saved_spec->priority) {
3115 rc = -EPERM;
3116 goto fail_unlock;
3117 }
3118 ins_index = i;
3119 break;
3120 }
3121
3122 /* Once we reach the maximum search depth, use the
3123 * first suitable slot or return -EBUSY if there was
3124 * none
3125 */
3126 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3127 if (ins_index < 0) {
3128 rc = -EBUSY;
3129 goto fail_unlock;
3130 }
3131 break;
3132 }
3133
3134 ++depth;
3135 }
3136
3137 /* Create a software table entry if necessary, and mark it
3138 * busy. We might yet fail to insert, but any attempt to
3139 * insert a conflicting filter while we're waiting for the
3140 * firmware must find the busy entry.
3141 */
3142 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3143 if (saved_spec) {
3144 replacing = true;
3145 } else {
3146 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3147 if (!saved_spec) {
3148 rc = -ENOMEM;
3149 goto fail_unlock;
3150 }
3151 *saved_spec = *spec;
3152 }
3153 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3154 EFX_EF10_FILTER_FLAG_BUSY);
3155
3156 spin_unlock_bh(&efx->filter_lock);
3157
3158 /* Pack up the variables needed on completion */
3159 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3160
3161 efx_ef10_filter_push_prep(efx, spec, inbuf,
3162 table->entry[ins_index].handle, replacing);
3163 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3164 MC_CMD_FILTER_OP_OUT_LEN,
3165 efx_ef10_filter_rfs_insert_complete, cookie);
3166
3167 return ins_index;
3168
3169fail_unlock:
3170 spin_unlock_bh(&efx->filter_lock);
3171 return rc;
3172}
3173
3174static void
3175efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3176 int rc, efx_dword_t *outbuf,
3177 size_t outlen_actual)
3178{
3179 struct efx_ef10_filter_table *table = efx->filter_state;
3180 unsigned int ins_index, dmaq_id;
3181 struct efx_filter_spec *spec;
3182 bool replacing;
3183
3184 /* Unpack the cookie */
3185 replacing = cookie >> 31;
3186 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3187 dmaq_id = cookie & 0xffff;
3188
3189 spin_lock_bh(&efx->filter_lock);
3190 spec = efx_ef10_filter_entry_spec(table, ins_index);
3191 if (rc == 0) {
3192 table->entry[ins_index].handle =
3193 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3194 if (replacing)
3195 spec->dmaq_id = dmaq_id;
3196 } else if (!replacing) {
3197 kfree(spec);
3198 spec = NULL;
3199 }
3200 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3201 spin_unlock_bh(&efx->filter_lock);
3202
3203 wake_up_all(&table->waitq);
3204}
3205
3206static void
3207efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3208 unsigned long filter_idx,
3209 int rc, efx_dword_t *outbuf,
3210 size_t outlen_actual);
3211
3212static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3213 unsigned int filter_idx)
3214{
3215 struct efx_ef10_filter_table *table = efx->filter_state;
3216 struct efx_filter_spec *spec =
3217 efx_ef10_filter_entry_spec(table, filter_idx);
3218 MCDI_DECLARE_BUF(inbuf,
3219 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3220 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3221
3222 if (!spec ||
3223 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3224 spec->priority != EFX_FILTER_PRI_HINT ||
3225 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3226 flow_id, filter_idx))
3227 return false;
3228
3229 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3230 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3231 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3232 table->entry[filter_idx].handle);
3233 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3234 efx_ef10_filter_rfs_expire_complete, filter_idx))
3235 return false;
3236
3237 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3238 return true;
3239}
3240
3241static void
3242efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3243 unsigned long filter_idx,
3244 int rc, efx_dword_t *outbuf,
3245 size_t outlen_actual)
3246{
3247 struct efx_ef10_filter_table *table = efx->filter_state;
3248 struct efx_filter_spec *spec =
3249 efx_ef10_filter_entry_spec(table, filter_idx);
3250
3251 spin_lock_bh(&efx->filter_lock);
3252 if (rc == 0) {
3253 kfree(spec);
3254 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3255 }
3256 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3257 wake_up_all(&table->waitq);
3258 spin_unlock_bh(&efx->filter_lock);
3259}
3260
3261#endif /* CONFIG_RFS_ACCEL */
3262
3263static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3264{
3265 int match_flags = 0;
3266
3267#define MAP_FLAG(gen_flag, mcdi_field) { \
3268 u32 old_mcdi_flags = mcdi_flags; \
3269 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3270 mcdi_field ## _LBN); \
3271 if (mcdi_flags != old_mcdi_flags) \
3272 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3273 }
3274 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3275 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3276 MAP_FLAG(REM_HOST, SRC_IP);
3277 MAP_FLAG(LOC_HOST, DST_IP);
3278 MAP_FLAG(REM_MAC, SRC_MAC);
3279 MAP_FLAG(REM_PORT, SRC_PORT);
3280 MAP_FLAG(LOC_MAC, DST_MAC);
3281 MAP_FLAG(LOC_PORT, DST_PORT);
3282 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3283 MAP_FLAG(INNER_VID, INNER_VLAN);
3284 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3285 MAP_FLAG(IP_PROTO, IP_PROTO);
3286#undef MAP_FLAG
3287
3288 /* Did we map them all? */
3289 if (mcdi_flags)
3290 return -EINVAL;
3291
3292 return match_flags;
3293}
3294
3295static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3296{
3297 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3298 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3299 unsigned int pd_match_pri, pd_match_count;
3300 struct efx_ef10_filter_table *table;
3301 size_t outlen;
3302 int rc;
3303
3304 table = kzalloc(sizeof(*table), GFP_KERNEL);
3305 if (!table)
3306 return -ENOMEM;
3307
3308 /* Find out which RX filter types are supported, and their priorities */
3309 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3310 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3311 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3312 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3313 &outlen);
3314 if (rc)
3315 goto fail;
3316 pd_match_count = MCDI_VAR_ARRAY_LEN(
3317 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3318 table->rx_match_count = 0;
3319
3320 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3321 u32 mcdi_flags =
3322 MCDI_ARRAY_DWORD(
3323 outbuf,
3324 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3325 pd_match_pri);
3326 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3327 if (rc < 0) {
3328 netif_dbg(efx, probe, efx->net_dev,
3329 "%s: fw flags %#x pri %u not supported in driver\n",
3330 __func__, mcdi_flags, pd_match_pri);
3331 } else {
3332 netif_dbg(efx, probe, efx->net_dev,
3333 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3334 __func__, mcdi_flags, pd_match_pri,
3335 rc, table->rx_match_count);
3336 table->rx_match_flags[table->rx_match_count++] = rc;
3337 }
3338 }
3339
3340 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3341 if (!table->entry) {
3342 rc = -ENOMEM;
3343 goto fail;
3344 }
3345
3346 efx->filter_state = table;
3347 init_waitqueue_head(&table->waitq);
3348 return 0;
3349
3350fail:
3351 kfree(table);
3352 return rc;
3353}
3354
Edward Cree0d322412015-05-20 11:10:03 +01003355/* Caller must hold efx->filter_sem for read if race against
3356 * efx_ef10_filter_table_remove() is possible
3357 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003358static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3359{
3360 struct efx_ef10_filter_table *table = efx->filter_state;
3361 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3362 struct efx_filter_spec *spec;
3363 unsigned int filter_idx;
3364 bool failed = false;
3365 int rc;
3366
Edward Cree0d322412015-05-20 11:10:03 +01003367 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3368
Ben Hutchings8127d662013-08-29 19:19:29 +01003369 if (!nic_data->must_restore_filters)
3370 return;
3371
Edward Cree0d322412015-05-20 11:10:03 +01003372 if (!table)
3373 return;
3374
Ben Hutchings8127d662013-08-29 19:19:29 +01003375 spin_lock_bh(&efx->filter_lock);
3376
3377 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3378 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3379 if (!spec)
3380 continue;
3381
3382 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3383 spin_unlock_bh(&efx->filter_lock);
3384
3385 rc = efx_ef10_filter_push(efx, spec,
3386 &table->entry[filter_idx].handle,
3387 false);
3388 if (rc)
3389 failed = true;
3390
3391 spin_lock_bh(&efx->filter_lock);
3392 if (rc) {
3393 kfree(spec);
3394 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3395 } else {
3396 table->entry[filter_idx].spec &=
3397 ~EFX_EF10_FILTER_FLAG_BUSY;
3398 }
3399 }
3400
3401 spin_unlock_bh(&efx->filter_lock);
3402
3403 if (failed)
3404 netif_err(efx, hw, efx->net_dev,
3405 "unable to restore all filters\n");
3406 else
3407 nic_data->must_restore_filters = false;
3408}
3409
Edward Cree0d322412015-05-20 11:10:03 +01003410/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003411static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3412{
3413 struct efx_ef10_filter_table *table = efx->filter_state;
3414 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3415 struct efx_filter_spec *spec;
3416 unsigned int filter_idx;
3417 int rc;
3418
Edward Cree0d322412015-05-20 11:10:03 +01003419 efx->filter_state = NULL;
3420 if (!table)
3421 return;
3422
Ben Hutchings8127d662013-08-29 19:19:29 +01003423 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3424 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3425 if (!spec)
3426 continue;
3427
3428 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3429 efx_ef10_filter_is_exclusive(spec) ?
3430 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3431 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3432 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3433 table->entry[filter_idx].handle);
3434 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3435 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003436 if (rc)
3437 netdev_WARN(efx->net_dev,
3438 "filter_idx=%#x handle=%#llx\n",
3439 filter_idx,
3440 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003441 kfree(spec);
3442 }
3443
3444 vfree(table->entry);
3445 kfree(table);
3446}
3447
Edward Cree0d322412015-05-20 11:10:03 +01003448/* Caller must hold efx->filter_sem for read if race against
3449 * efx_ef10_filter_table_remove() is possible
3450 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003451static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3452{
3453 struct efx_ef10_filter_table *table = efx->filter_state;
3454 struct net_device *net_dev = efx->net_dev;
3455 struct efx_filter_spec spec;
3456 bool remove_failed = false;
3457 struct netdev_hw_addr *uc;
3458 struct netdev_hw_addr *mc;
3459 unsigned int filter_idx;
3460 int i, n, rc;
3461
3462 if (!efx_dev_registered(efx))
3463 return;
3464
Edward Cree0d322412015-05-20 11:10:03 +01003465 if (!table)
3466 return;
3467
Ben Hutchings8127d662013-08-29 19:19:29 +01003468 /* Mark old filters that may need to be removed */
3469 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003470 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003471 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003472 filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS;
3473 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003474 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003475 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003476 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003477 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3478 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003479 }
3480 spin_unlock_bh(&efx->filter_lock);
3481
3482 /* Copy/convert the address lists; add the primary station
3483 * address and broadcast address
3484 */
3485 netif_addr_lock_bh(net_dev);
3486 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003487 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3488 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003489 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003490 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003491 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003492 i = 1;
3493 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003494 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003495 i++;
3496 }
3497 }
3498 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003499 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3500 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003501 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003502 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3503 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003504 i = 1;
3505 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003506 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003507 i++;
3508 }
3509 }
3510 netif_addr_unlock_bh(net_dev);
3511
3512 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003513 if (table->dev_uc_count >= 0) {
3514 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003515 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3516 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003517 0);
3518 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003519 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003520 rc = efx_ef10_filter_insert(efx, &spec, true);
3521 if (rc < 0) {
3522 /* Fall back to unicast-promisc */
3523 while (i--)
3524 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003525 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003526 table->dev_uc_list[i].id);
3527 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003528 break;
3529 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003530 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003531 }
3532 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003533 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003534 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3535 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003536 0);
3537 efx_filter_set_uc_def(&spec);
3538 rc = efx_ef10_filter_insert(efx, &spec, true);
3539 if (rc < 0) {
3540 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003541 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003542 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003543 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003544 }
3545 }
3546
3547 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003548 if (table->dev_mc_count >= 0) {
3549 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003550 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3551 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003552 0);
3553 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003554 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003555 rc = efx_ef10_filter_insert(efx, &spec, true);
3556 if (rc < 0) {
3557 /* Fall back to multicast-promisc */
3558 while (i--)
3559 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003560 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003561 table->dev_mc_list[i].id);
3562 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003563 break;
3564 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003565 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003566 }
3567 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003568 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003569 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3570 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003571 0);
3572 efx_filter_set_mc_def(&spec);
3573 rc = efx_ef10_filter_insert(efx, &spec, true);
3574 if (rc < 0) {
3575 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003576 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003577 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003578 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003579 }
3580 }
3581
3582 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003583 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003584 * don't need to hold the filter_lock while scanning for
3585 * these filters.
3586 */
3587 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3588 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003589 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003590 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003591 efx, 1U << EFX_FILTER_PRI_AUTO,
3592 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003593 remove_failed = true;
3594 }
3595 }
3596 WARN_ON(remove_failed);
3597}
3598
Shradha Shah910c8782015-05-20 11:12:48 +01003599static int efx_ef10_set_mac_address(struct efx_nic *efx)
3600{
3601 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
3602 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3603 bool was_enabled = efx->port_enabled;
3604 int rc;
3605
3606 efx_device_detach_sync(efx);
3607 efx_net_stop(efx->net_dev);
3608 down_write(&efx->filter_sem);
3609 efx_ef10_filter_table_remove(efx);
3610
3611 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
3612 efx->net_dev->dev_addr);
3613 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
3614 nic_data->vport_id);
3615 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
3616 sizeof(inbuf), NULL, 0, NULL);
3617
3618 efx_ef10_filter_table_probe(efx);
3619 up_write(&efx->filter_sem);
3620 if (was_enabled)
3621 efx_net_open(efx->net_dev);
3622 netif_device_attach(efx->net_dev);
3623
3624#if !defined(CONFIG_SFC_SRIOV)
3625 if (rc == -EPERM)
3626 netif_err(efx, drv, efx->net_dev,
3627 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3628 " on this interface\n");
3629#else
3630 if (rc == -EPERM) {
3631 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3632
3633 /* Switch to PF and change MAC address on vport */
3634 if (efx->pci_dev->is_virtfn && pci_dev_pf) {
3635 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3636
3637 if (!efx_ef10_sriov_set_vf_mac(efx_pf,
3638 nic_data->vf_index,
3639 efx->net_dev->dev_addr))
3640 return 0;
3641 }
3642 netif_err(efx, drv, efx->net_dev,
3643 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3644 " on this interface\n");
3645 } else if (efx->pci_dev->is_virtfn) {
3646 /* Successfully changed by VF (with MAC spoofing), so update the
3647 * parent PF if possible.
3648 */
3649 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3650
3651 if (pci_dev_pf) {
3652 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3653 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
3654 unsigned int i;
3655
3656 for (i = 0; i < efx_pf->vf_count; ++i) {
3657 struct ef10_vf *vf = nic_data->vf + i;
3658
3659 if (vf->efx == efx) {
3660 ether_addr_copy(vf->mac,
3661 efx->net_dev->dev_addr);
3662 return 0;
3663 }
3664 }
3665 }
3666 }
3667#endif
3668 return rc;
3669}
3670
Ben Hutchings8127d662013-08-29 19:19:29 +01003671static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3672{
3673 efx_ef10_filter_sync_rx_mode(efx);
3674
3675 return efx_mcdi_set_mac(efx);
3676}
3677
Shradha Shah862f8942015-05-20 11:08:56 +01003678static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3679{
3680 efx_ef10_filter_sync_rx_mode(efx);
3681
3682 return 0;
3683}
3684
Jon Cooper74cd60a2013-09-16 14:18:51 +01003685static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3686{
3687 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3688
3689 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3690 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3691 NULL, 0, NULL);
3692}
3693
3694/* MC BISTs follow a different poll mechanism to phy BISTs.
3695 * The BIST is done in the poll handler on the MC, and the MCDI command
3696 * will block until the BIST is done.
3697 */
3698static int efx_ef10_poll_bist(struct efx_nic *efx)
3699{
3700 int rc;
3701 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3702 size_t outlen;
3703 u32 result;
3704
3705 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3706 outbuf, sizeof(outbuf), &outlen);
3707 if (rc != 0)
3708 return rc;
3709
3710 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3711 return -EIO;
3712
3713 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3714 switch (result) {
3715 case MC_CMD_POLL_BIST_PASSED:
3716 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3717 return 0;
3718 case MC_CMD_POLL_BIST_TIMEOUT:
3719 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3720 return -EIO;
3721 case MC_CMD_POLL_BIST_FAILED:
3722 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3723 return -EIO;
3724 default:
3725 netif_err(efx, hw, efx->net_dev,
3726 "BIST returned unknown result %u", result);
3727 return -EIO;
3728 }
3729}
3730
3731static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3732{
3733 int rc;
3734
3735 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3736
3737 rc = efx_ef10_start_bist(efx, bist_type);
3738 if (rc != 0)
3739 return rc;
3740
3741 return efx_ef10_poll_bist(efx);
3742}
3743
3744static int
3745efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3746{
3747 int rc, rc2;
3748
3749 efx_reset_down(efx, RESET_TYPE_WORLD);
3750
3751 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3752 NULL, 0, NULL, 0, NULL);
3753 if (rc != 0)
3754 goto out;
3755
3756 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3757 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3758
3759 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3760
3761out:
3762 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3763 return rc ? rc : rc2;
3764}
3765
Ben Hutchings8127d662013-08-29 19:19:29 +01003766#ifdef CONFIG_SFC_MTD
3767
3768struct efx_ef10_nvram_type_info {
3769 u16 type, type_mask;
3770 u8 port;
3771 const char *name;
3772};
3773
3774static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3775 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3776 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3777 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3778 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3779 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3780 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3781 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3782 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3783 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003784 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003785 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3786};
3787
3788static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3789 struct efx_mcdi_mtd_partition *part,
3790 unsigned int type)
3791{
3792 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3793 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3794 const struct efx_ef10_nvram_type_info *info;
3795 size_t size, erase_size, outlen;
3796 bool protected;
3797 int rc;
3798
3799 for (info = efx_ef10_nvram_types; ; info++) {
3800 if (info ==
3801 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3802 return -ENODEV;
3803 if ((type & ~info->type_mask) == info->type)
3804 break;
3805 }
3806 if (info->port != efx_port_num(efx))
3807 return -ENODEV;
3808
3809 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3810 if (rc)
3811 return rc;
3812 if (protected)
3813 return -ENODEV; /* hide it */
3814
3815 part->nvram_type = type;
3816
3817 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3818 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3819 outbuf, sizeof(outbuf), &outlen);
3820 if (rc)
3821 return rc;
3822 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3823 return -EIO;
3824 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3825 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3826 part->fw_subtype = MCDI_DWORD(outbuf,
3827 NVRAM_METADATA_OUT_SUBTYPE);
3828
3829 part->common.dev_type_name = "EF10 NVRAM manager";
3830 part->common.type_name = info->name;
3831
3832 part->common.mtd.type = MTD_NORFLASH;
3833 part->common.mtd.flags = MTD_CAP_NORFLASH;
3834 part->common.mtd.size = size;
3835 part->common.mtd.erasesize = erase_size;
3836
3837 return 0;
3838}
3839
3840static int efx_ef10_mtd_probe(struct efx_nic *efx)
3841{
3842 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
3843 struct efx_mcdi_mtd_partition *parts;
3844 size_t outlen, n_parts_total, i, n_parts;
3845 unsigned int type;
3846 int rc;
3847
3848 ASSERT_RTNL();
3849
3850 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
3851 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
3852 outbuf, sizeof(outbuf), &outlen);
3853 if (rc)
3854 return rc;
3855 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
3856 return -EIO;
3857
3858 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
3859 if (n_parts_total >
3860 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
3861 return -EIO;
3862
3863 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
3864 if (!parts)
3865 return -ENOMEM;
3866
3867 n_parts = 0;
3868 for (i = 0; i < n_parts_total; i++) {
3869 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
3870 i);
3871 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
3872 if (rc == 0)
3873 n_parts++;
3874 else if (rc != -ENODEV)
3875 goto fail;
3876 }
3877
3878 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
3879fail:
3880 if (rc)
3881 kfree(parts);
3882 return rc;
3883}
3884
3885#endif /* CONFIG_SFC_MTD */
3886
3887static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
3888{
3889 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
3890}
3891
Shradha Shah02246a72015-05-06 00:58:14 +01003892static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
3893 u32 host_time) {}
3894
Jon Cooperbd9a2652013-11-18 12:54:41 +00003895static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
3896 bool temp)
3897{
3898 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
3899 int rc;
3900
3901 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
3902 channel->sync_events_state == SYNC_EVENTS_VALID ||
3903 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
3904 return 0;
3905 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
3906
3907 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
3908 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3909 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
3910 channel->channel);
3911
3912 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3913 inbuf, sizeof(inbuf), NULL, 0, NULL);
3914
3915 if (rc != 0)
3916 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3917 SYNC_EVENTS_DISABLED;
3918
3919 return rc;
3920}
3921
3922static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
3923 bool temp)
3924{
3925 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
3926 int rc;
3927
3928 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
3929 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
3930 return 0;
3931 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
3932 channel->sync_events_state = SYNC_EVENTS_DISABLED;
3933 return 0;
3934 }
3935 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3936 SYNC_EVENTS_DISABLED;
3937
3938 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
3939 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3940 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
3941 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
3942 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
3943 channel->channel);
3944
3945 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3946 inbuf, sizeof(inbuf), NULL, 0, NULL);
3947
3948 return rc;
3949}
3950
3951static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
3952 bool temp)
3953{
3954 int (*set)(struct efx_channel *channel, bool temp);
3955 struct efx_channel *channel;
3956
3957 set = en ?
3958 efx_ef10_rx_enable_timestamping :
3959 efx_ef10_rx_disable_timestamping;
3960
3961 efx_for_each_channel(channel, efx) {
3962 int rc = set(channel, temp);
3963 if (en && rc != 0) {
3964 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
3965 return rc;
3966 }
3967 }
3968
3969 return 0;
3970}
3971
Shradha Shah02246a72015-05-06 00:58:14 +01003972static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
3973 struct hwtstamp_config *init)
3974{
3975 return -EOPNOTSUPP;
3976}
3977
Jon Cooperbd9a2652013-11-18 12:54:41 +00003978static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
3979 struct hwtstamp_config *init)
3980{
3981 int rc;
3982
3983 switch (init->rx_filter) {
3984 case HWTSTAMP_FILTER_NONE:
3985 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
3986 /* if TX timestamping is still requested then leave PTP on */
3987 return efx_ptp_change_mode(efx,
3988 init->tx_type != HWTSTAMP_TX_OFF, 0);
3989 case HWTSTAMP_FILTER_ALL:
3990 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3991 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3992 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3993 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3994 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3995 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3996 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3997 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3998 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3999 case HWTSTAMP_FILTER_PTP_V2_EVENT:
4000 case HWTSTAMP_FILTER_PTP_V2_SYNC:
4001 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
4002 init->rx_filter = HWTSTAMP_FILTER_ALL;
4003 rc = efx_ptp_change_mode(efx, true, 0);
4004 if (!rc)
4005 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
4006 if (rc)
4007 efx_ptp_change_mode(efx, false, 0);
4008 return rc;
4009 default:
4010 return -ERANGE;
4011 }
4012}
4013
Shradha Shah02246a72015-05-06 00:58:14 +01004014const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004015 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01004016 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01004017 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01004018 .probe = efx_ef10_probe_vf,
4019 .remove = efx_ef10_remove,
4020 .dimension_resources = efx_ef10_dimension_resources,
4021 .init = efx_ef10_init_nic,
4022 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004023 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01004024 .map_reset_flags = efx_ef10_map_reset_flags,
4025 .reset = efx_ef10_reset,
4026 .probe_port = efx_mcdi_port_probe,
4027 .remove_port = efx_mcdi_port_remove,
4028 .fini_dmaq = efx_ef10_fini_dmaq,
4029 .prepare_flr = efx_ef10_prepare_flr,
4030 .finish_flr = efx_port_dummy_op_void,
4031 .describe_stats = efx_ef10_describe_stats,
4032 .update_stats = efx_ef10_update_stats,
4033 .start_stats = efx_port_dummy_op_void,
4034 .pull_stats = efx_port_dummy_op_void,
4035 .stop_stats = efx_port_dummy_op_void,
4036 .set_id_led = efx_mcdi_set_id_led,
4037 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01004038 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004039 .check_mac_fault = efx_mcdi_mac_check_fault,
4040 .reconfigure_port = efx_mcdi_port_reconfigure,
4041 .get_wol = efx_ef10_get_wol_vf,
4042 .set_wol = efx_ef10_set_wol_vf,
4043 .resume_wol = efx_port_dummy_op_void,
4044 .mcdi_request = efx_ef10_mcdi_request,
4045 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4046 .mcdi_read_response = efx_ef10_mcdi_read_response,
4047 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4048 .irq_enable_master = efx_port_dummy_op_void,
4049 .irq_test_generate = efx_ef10_irq_test_generate,
4050 .irq_disable_non_ev = efx_port_dummy_op_void,
4051 .irq_handle_msi = efx_ef10_msi_interrupt,
4052 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4053 .tx_probe = efx_ef10_tx_probe,
4054 .tx_init = efx_ef10_tx_init,
4055 .tx_remove = efx_ef10_tx_remove,
4056 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004057 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01004058 .rx_probe = efx_ef10_rx_probe,
4059 .rx_init = efx_ef10_rx_init,
4060 .rx_remove = efx_ef10_rx_remove,
4061 .rx_write = efx_ef10_rx_write,
4062 .rx_defer_refill = efx_ef10_rx_defer_refill,
4063 .ev_probe = efx_ef10_ev_probe,
4064 .ev_init = efx_ef10_ev_init,
4065 .ev_fini = efx_ef10_ev_fini,
4066 .ev_remove = efx_ef10_ev_remove,
4067 .ev_process = efx_ef10_ev_process,
4068 .ev_read_ack = efx_ef10_ev_read_ack,
4069 .ev_test_generate = efx_ef10_ev_test_generate,
4070 .filter_table_probe = efx_ef10_filter_table_probe,
4071 .filter_table_restore = efx_ef10_filter_table_restore,
4072 .filter_table_remove = efx_ef10_filter_table_remove,
4073 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4074 .filter_insert = efx_ef10_filter_insert,
4075 .filter_remove_safe = efx_ef10_filter_remove_safe,
4076 .filter_get_safe = efx_ef10_filter_get_safe,
4077 .filter_clear_rx = efx_ef10_filter_clear_rx,
4078 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4079 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4080 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4081#ifdef CONFIG_RFS_ACCEL
4082 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4083 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4084#endif
4085#ifdef CONFIG_SFC_MTD
4086 .mtd_probe = efx_port_dummy_op_int,
4087#endif
4088 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4089 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4090#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004091 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4092 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4093 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004094#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004095 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01004096 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004097
Shradha Shah02246a72015-05-06 00:58:14 +01004098 .revision = EFX_REV_HUNT_A0,
4099 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4100 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4101 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4102 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4103 .can_rx_scatter = true,
4104 .always_rx_scatter = true,
4105 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4106 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4107 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4108 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4109 .mcdi_max_ver = 2,
4110 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4111 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4112 1 << HWTSTAMP_FILTER_ALL,
4113};
4114
4115const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004116 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004117 .mem_bar = EFX_MEM_BAR,
4118 .mem_map_size = efx_ef10_mem_map_size,
4119 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004120 .remove = efx_ef10_remove,
4121 .dimension_resources = efx_ef10_dimension_resources,
4122 .init = efx_ef10_init_nic,
4123 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004124 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01004125 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004126 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004127 .probe_port = efx_mcdi_port_probe,
4128 .remove_port = efx_mcdi_port_remove,
4129 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004130 .prepare_flr = efx_ef10_prepare_flr,
4131 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004132 .describe_stats = efx_ef10_describe_stats,
4133 .update_stats = efx_ef10_update_stats,
4134 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004135 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004136 .stop_stats = efx_mcdi_mac_stop_stats,
4137 .set_id_led = efx_mcdi_set_id_led,
4138 .push_irq_moderation = efx_ef10_push_irq_moderation,
4139 .reconfigure_mac = efx_ef10_mac_reconfigure,
4140 .check_mac_fault = efx_mcdi_mac_check_fault,
4141 .reconfigure_port = efx_mcdi_port_reconfigure,
4142 .get_wol = efx_ef10_get_wol,
4143 .set_wol = efx_ef10_set_wol,
4144 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004145 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004146 .test_nvram = efx_mcdi_nvram_test_all,
4147 .mcdi_request = efx_ef10_mcdi_request,
4148 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4149 .mcdi_read_response = efx_ef10_mcdi_read_response,
4150 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4151 .irq_enable_master = efx_port_dummy_op_void,
4152 .irq_test_generate = efx_ef10_irq_test_generate,
4153 .irq_disable_non_ev = efx_port_dummy_op_void,
4154 .irq_handle_msi = efx_ef10_msi_interrupt,
4155 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4156 .tx_probe = efx_ef10_tx_probe,
4157 .tx_init = efx_ef10_tx_init,
4158 .tx_remove = efx_ef10_tx_remove,
4159 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004160 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004161 .rx_probe = efx_ef10_rx_probe,
4162 .rx_init = efx_ef10_rx_init,
4163 .rx_remove = efx_ef10_rx_remove,
4164 .rx_write = efx_ef10_rx_write,
4165 .rx_defer_refill = efx_ef10_rx_defer_refill,
4166 .ev_probe = efx_ef10_ev_probe,
4167 .ev_init = efx_ef10_ev_init,
4168 .ev_fini = efx_ef10_ev_fini,
4169 .ev_remove = efx_ef10_ev_remove,
4170 .ev_process = efx_ef10_ev_process,
4171 .ev_read_ack = efx_ef10_ev_read_ack,
4172 .ev_test_generate = efx_ef10_ev_test_generate,
4173 .filter_table_probe = efx_ef10_filter_table_probe,
4174 .filter_table_restore = efx_ef10_filter_table_restore,
4175 .filter_table_remove = efx_ef10_filter_table_remove,
4176 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4177 .filter_insert = efx_ef10_filter_insert,
4178 .filter_remove_safe = efx_ef10_filter_remove_safe,
4179 .filter_get_safe = efx_ef10_filter_get_safe,
4180 .filter_clear_rx = efx_ef10_filter_clear_rx,
4181 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4182 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4183 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4184#ifdef CONFIG_RFS_ACCEL
4185 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4186 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4187#endif
4188#ifdef CONFIG_SFC_MTD
4189 .mtd_probe = efx_ef10_mtd_probe,
4190 .mtd_rename = efx_mcdi_mtd_rename,
4191 .mtd_read = efx_mcdi_mtd_read,
4192 .mtd_erase = efx_mcdi_mtd_erase,
4193 .mtd_write = efx_mcdi_mtd_write,
4194 .mtd_sync = efx_mcdi_mtd_sync,
4195#endif
4196 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004197 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4198 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004199#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004200 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004201 .sriov_init = efx_ef10_sriov_init,
4202 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004203 .sriov_wanted = efx_ef10_sriov_wanted,
4204 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004205 .sriov_flr = efx_ef10_sriov_flr,
4206 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4207 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4208 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4209 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01004210 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004211 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4212 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4213 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004214#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004215 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004216 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01004217
4218 .revision = EFX_REV_HUNT_A0,
4219 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4220 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4221 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004222 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004223 .can_rx_scatter = true,
4224 .always_rx_scatter = true,
4225 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4226 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4227 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4228 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4229 .mcdi_max_ver = 2,
4230 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004231 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4232 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004233};