blob: 06605abbe7c956bed09fcc176cc4bdeb26bb754a [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;
Shradha Shah8be41322015-06-02 11:37:25 +0100252 struct net_device *net_dev = efx->net_dev;
Ben Hutchings8127d662013-08-29 19:19:29 +0100253 int i, rc;
254
Ben Hutchingsaa3930e2014-02-12 18:59:19 +0000255 /* We can have one VI for each 8K region. However, until we
256 * use TX option descriptors we need two TX queues per channel.
Ben Hutchings8127d662013-08-29 19:19:29 +0100257 */
258 efx->max_channels =
259 min_t(unsigned int,
260 EFX_MAX_CHANNELS,
Shradha Shah02246a72015-05-06 00:58:14 +0100261 efx_ef10_mem_map_size(efx) /
Ben Hutchings8127d662013-08-29 19:19:29 +0100262 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
Edward Cree9fd3d3a2014-11-03 14:14:35 +0000263 if (WARN_ON(efx->max_channels == 0))
264 return -EIO;
Ben Hutchings8127d662013-08-29 19:19:29 +0100265
266 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
267 if (!nic_data)
268 return -ENOMEM;
269 efx->nic_data = nic_data;
270
Edward Cree75aba2a2015-05-27 13:13:54 +0100271 /* we assume later that we can copy from this buffer in dwords */
272 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
273
Ben Hutchings8127d662013-08-29 19:19:29 +0100274 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
275 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
276 if (rc)
277 goto fail1;
278
279 /* Get the MC's warm boot count. In case it's rebooting right
280 * now, be prepared to retry.
281 */
282 i = 0;
283 for (;;) {
284 rc = efx_ef10_get_warm_boot_count(efx);
285 if (rc >= 0)
286 break;
287 if (++i == 5)
288 goto fail2;
289 ssleep(1);
290 }
291 nic_data->warm_boot_count = rc;
292
293 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
294
Daniel Pieczko45b24492015-05-06 00:57:14 +0100295 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
296
Ben Hutchings8127d662013-08-29 19:19:29 +0100297 /* In case we're recovering from a crash (kexec), we want to
298 * cancel any outstanding request by the previous user of this
299 * function. We send a special message using the least
300 * significant bits of the 'high' (doorbell) register.
301 */
302 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
303
304 rc = efx_mcdi_init(efx);
305 if (rc)
306 goto fail2;
307
308 /* Reset (most) configuration for this function */
309 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
310 if (rc)
311 goto fail3;
312
313 /* Enable event logging */
314 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
315 if (rc)
316 goto fail3;
317
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100318 rc = efx_ef10_get_pf_index(efx);
319 if (rc)
320 goto fail3;
321
Ben Hutchingse5a25382013-09-05 22:50:59 +0100322 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100323 if (rc < 0)
324 goto fail3;
325
326 efx->rx_packet_len_offset =
327 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
328
Ben Hutchings8127d662013-08-29 19:19:29 +0100329 rc = efx_mcdi_port_get_number(efx);
330 if (rc < 0)
331 goto fail3;
332 efx->port_num = rc;
Shradha Shah8be41322015-06-02 11:37:25 +0100333 net_dev->dev_port = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100334
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100335 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100336 if (rc)
337 goto fail3;
338
339 rc = efx_ef10_get_sysclk_freq(efx);
340 if (rc < 0)
341 goto fail3;
342 efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */
343
Edward Cree267d9d72015-05-06 00:59:18 +0100344 /* Check whether firmware supports bug 35388 workaround.
345 * First try to enable it, then if we get EPERM, just
346 * ask if it's already enabled
347 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100348 rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true);
349 if (rc == 0)
350 nic_data->workaround_35388 = true;
Edward Cree267d9d72015-05-06 00:59:18 +0100351 else if (rc == -EPERM) {
352 unsigned int enabled;
353
354 rc = efx_mcdi_get_workarounds(efx, NULL, &enabled);
355 if (rc)
356 goto fail3;
357 nic_data->workaround_35388 = enabled &
358 MC_CMD_GET_WORKAROUNDS_OUT_BUG35388;
359 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100360 else if (rc != -ENOSYS && rc != -ENOENT)
361 goto fail3;
362 netif_dbg(efx, probe, efx->net_dev,
363 "workaround for bug 35388 is %sabled\n",
364 nic_data->workaround_35388 ? "en" : "dis");
365
366 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100367 if (rc && rc != -EPERM)
Ben Hutchings8127d662013-08-29 19:19:29 +0100368 goto fail3;
369
Ben Hutchings9aecda92013-12-05 21:28:42 +0000370 efx_ptp_probe(efx, NULL);
371
Ben Hutchings8127d662013-08-29 19:19:29 +0100372 return 0;
373
374fail3:
375 efx_mcdi_fini(efx);
376fail2:
377 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
378fail1:
379 kfree(nic_data);
380 efx->nic_data = NULL;
381 return rc;
382}
383
384static int efx_ef10_free_vis(struct efx_nic *efx)
385{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100386 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100387 size_t outlen;
388 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
389 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100390
391 /* -EALREADY means nothing to free, so ignore */
392 if (rc == -EALREADY)
393 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100394 if (rc)
395 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
396 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100397 return rc;
398}
399
Ben Hutchings183233b2013-06-28 21:47:12 +0100400#ifdef EFX_USE_PIO
401
402static void efx_ef10_free_piobufs(struct efx_nic *efx)
403{
404 struct efx_ef10_nic_data *nic_data = efx->nic_data;
405 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
406 unsigned int i;
407 int rc;
408
409 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
410
411 for (i = 0; i < nic_data->n_piobufs; i++) {
412 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
413 nic_data->piobuf_handle[i]);
414 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
415 NULL, 0, NULL);
416 WARN_ON(rc);
417 }
418
419 nic_data->n_piobufs = 0;
420}
421
422static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
423{
424 struct efx_ef10_nic_data *nic_data = efx->nic_data;
425 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
426 unsigned int i;
427 size_t outlen;
428 int rc = 0;
429
430 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
431
432 for (i = 0; i < n; i++) {
433 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
434 outbuf, sizeof(outbuf), &outlen);
435 if (rc)
436 break;
437 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
438 rc = -EIO;
439 break;
440 }
441 nic_data->piobuf_handle[i] =
442 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
443 netif_dbg(efx, probe, efx->net_dev,
444 "allocated PIO buffer %u handle %x\n", i,
445 nic_data->piobuf_handle[i]);
446 }
447
448 nic_data->n_piobufs = i;
449 if (rc)
450 efx_ef10_free_piobufs(efx);
451 return rc;
452}
453
454static int efx_ef10_link_piobufs(struct efx_nic *efx)
455{
456 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100457 _MCDI_DECLARE_BUF(inbuf,
458 max(MC_CMD_LINK_PIOBUF_IN_LEN,
459 MC_CMD_UNLINK_PIOBUF_IN_LEN));
Ben Hutchings183233b2013-06-28 21:47:12 +0100460 struct efx_channel *channel;
461 struct efx_tx_queue *tx_queue;
462 unsigned int offset, index;
463 int rc;
464
465 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
466 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
467
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100468 memset(inbuf, 0, sizeof(inbuf));
469
Ben Hutchings183233b2013-06-28 21:47:12 +0100470 /* Link a buffer to each VI in the write-combining mapping */
471 for (index = 0; index < nic_data->n_piobufs; ++index) {
472 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
473 nic_data->piobuf_handle[index]);
474 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
475 nic_data->pio_write_vi_base + index);
476 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
477 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
478 NULL, 0, NULL);
479 if (rc) {
480 netif_err(efx, drv, efx->net_dev,
481 "failed to link VI %u to PIO buffer %u (%d)\n",
482 nic_data->pio_write_vi_base + index, index,
483 rc);
484 goto fail;
485 }
486 netif_dbg(efx, probe, efx->net_dev,
487 "linked VI %u to PIO buffer %u\n",
488 nic_data->pio_write_vi_base + index, index);
489 }
490
491 /* Link a buffer to each TX queue */
492 efx_for_each_channel(channel, efx) {
493 efx_for_each_channel_tx_queue(tx_queue, channel) {
494 /* We assign the PIO buffers to queues in
495 * reverse order to allow for the following
496 * special case.
497 */
498 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
499 tx_queue->channel->channel - 1) *
500 efx_piobuf_size);
501 index = offset / ER_DZ_TX_PIOBUF_SIZE;
502 offset = offset % ER_DZ_TX_PIOBUF_SIZE;
503
504 /* When the host page size is 4K, the first
505 * host page in the WC mapping may be within
506 * the same VI page as the last TX queue. We
507 * can only link one buffer to each VI.
508 */
509 if (tx_queue->queue == nic_data->pio_write_vi_base) {
510 BUG_ON(index != 0);
511 rc = 0;
512 } else {
513 MCDI_SET_DWORD(inbuf,
514 LINK_PIOBUF_IN_PIOBUF_HANDLE,
515 nic_data->piobuf_handle[index]);
516 MCDI_SET_DWORD(inbuf,
517 LINK_PIOBUF_IN_TXQ_INSTANCE,
518 tx_queue->queue);
519 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
520 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
521 NULL, 0, NULL);
522 }
523
524 if (rc) {
525 /* This is non-fatal; the TX path just
526 * won't use PIO for this queue
527 */
528 netif_err(efx, drv, efx->net_dev,
529 "failed to link VI %u to PIO buffer %u (%d)\n",
530 tx_queue->queue, index, rc);
531 tx_queue->piobuf = NULL;
532 } else {
533 tx_queue->piobuf =
534 nic_data->pio_write_base +
535 index * EFX_VI_PAGE_SIZE + offset;
536 tx_queue->piobuf_offset = offset;
537 netif_dbg(efx, probe, efx->net_dev,
538 "linked VI %u to PIO buffer %u offset %x addr %p\n",
539 tx_queue->queue, index,
540 tx_queue->piobuf_offset,
541 tx_queue->piobuf);
542 }
543 }
544 }
545
546 return 0;
547
548fail:
549 while (index--) {
550 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
551 nic_data->pio_write_vi_base + index);
552 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
553 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
554 NULL, 0, NULL);
555 }
556 return rc;
557}
558
559#else /* !EFX_USE_PIO */
560
561static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
562{
563 return n == 0 ? 0 : -ENOBUFS;
564}
565
566static int efx_ef10_link_piobufs(struct efx_nic *efx)
567{
568 return 0;
569}
570
571static void efx_ef10_free_piobufs(struct efx_nic *efx)
572{
573}
574
575#endif /* EFX_USE_PIO */
576
Ben Hutchings8127d662013-08-29 19:19:29 +0100577static void efx_ef10_remove(struct efx_nic *efx)
578{
579 struct efx_ef10_nic_data *nic_data = efx->nic_data;
580 int rc;
581
Shradha Shahf1122a32015-05-20 11:09:46 +0100582#ifdef CONFIG_SFC_SRIOV
583 struct efx_ef10_nic_data *nic_data_pf;
584 struct pci_dev *pci_dev_pf;
585 struct efx_nic *efx_pf;
586 struct ef10_vf *vf;
587
588 if (efx->pci_dev->is_virtfn) {
589 pci_dev_pf = efx->pci_dev->physfn;
590 if (pci_dev_pf) {
591 efx_pf = pci_get_drvdata(pci_dev_pf);
592 nic_data_pf = efx_pf->nic_data;
593 vf = nic_data_pf->vf + nic_data->vf_index;
594 vf->efx = NULL;
595 } else
596 netif_info(efx, drv, efx->net_dev,
597 "Could not get the PF id from VF\n");
598 }
599#endif
600
Ben Hutchings9aecda92013-12-05 21:28:42 +0000601 efx_ptp_remove(efx);
602
Ben Hutchings8127d662013-08-29 19:19:29 +0100603 efx_mcdi_mon_remove(efx);
604
Ben Hutchings8127d662013-08-29 19:19:29 +0100605 efx_ef10_rx_free_indir_table(efx);
606
Ben Hutchings183233b2013-06-28 21:47:12 +0100607 if (nic_data->wc_membase)
608 iounmap(nic_data->wc_membase);
609
Ben Hutchings8127d662013-08-29 19:19:29 +0100610 rc = efx_ef10_free_vis(efx);
611 WARN_ON(rc != 0);
612
Ben Hutchings183233b2013-06-28 21:47:12 +0100613 if (!nic_data->must_restore_piobufs)
614 efx_ef10_free_piobufs(efx);
615
Ben Hutchings8127d662013-08-29 19:19:29 +0100616 efx_mcdi_fini(efx);
617 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
618 kfree(nic_data);
619}
620
Shradha Shah88a37de2015-05-20 11:09:15 +0100621static int efx_ef10_probe_pf(struct efx_nic *efx)
622{
623 return efx_ef10_probe(efx);
624}
625
626#ifdef CONFIG_SFC_SRIOV
627static int efx_ef10_probe_vf(struct efx_nic *efx)
628{
629 int rc;
630
631 rc = efx_ef10_probe(efx);
632 if (rc)
633 return rc;
634
635 rc = efx_ef10_get_vf_index(efx);
636 if (rc)
637 goto fail;
638
Shradha Shahf1122a32015-05-20 11:09:46 +0100639 if (efx->pci_dev->is_virtfn) {
640 if (efx->pci_dev->physfn) {
641 struct efx_nic *efx_pf =
642 pci_get_drvdata(efx->pci_dev->physfn);
643 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
644 struct efx_ef10_nic_data *nic_data = efx->nic_data;
645
646 nic_data_p->vf[nic_data->vf_index].efx = efx;
647 } else
648 netif_info(efx, drv, efx->net_dev,
649 "Could not get the PF id from VF\n");
650 }
651
Shradha Shah88a37de2015-05-20 11:09:15 +0100652 return 0;
653
654fail:
655 efx_ef10_remove(efx);
656 return rc;
657}
658#else
659static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
660{
661 return 0;
662}
663#endif
664
Ben Hutchings8127d662013-08-29 19:19:29 +0100665static int efx_ef10_alloc_vis(struct efx_nic *efx,
666 unsigned int min_vis, unsigned int max_vis)
667{
668 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
669 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
670 struct efx_ef10_nic_data *nic_data = efx->nic_data;
671 size_t outlen;
672 int rc;
673
674 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
675 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
676 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
677 outbuf, sizeof(outbuf), &outlen);
678 if (rc != 0)
679 return rc;
680
681 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
682 return -EIO;
683
684 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
685 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
686
687 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
688 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
689 return 0;
690}
691
Ben Hutchings183233b2013-06-28 21:47:12 +0100692/* Note that the failure path of this function does not free
693 * resources, as this will be done by efx_ef10_remove().
694 */
Ben Hutchings8127d662013-08-29 19:19:29 +0100695static int efx_ef10_dimension_resources(struct efx_nic *efx)
696{
Ben Hutchings183233b2013-06-28 21:47:12 +0100697 struct efx_ef10_nic_data *nic_data = efx->nic_data;
698 unsigned int uc_mem_map_size, wc_mem_map_size;
699 unsigned int min_vis, pio_write_vi_base, max_vis;
700 void __iomem *membase;
701 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +0100702
Ben Hutchings183233b2013-06-28 21:47:12 +0100703 min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
704
705#ifdef EFX_USE_PIO
706 /* Try to allocate PIO buffers if wanted and if the full
707 * number of PIO buffers would be sufficient to allocate one
708 * copy-buffer per TX channel. Failure is non-fatal, as there
709 * are only a small number of PIO buffers shared between all
710 * functions of the controller.
711 */
712 if (efx_piobuf_size != 0 &&
713 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
714 efx->n_tx_channels) {
715 unsigned int n_piobufs =
716 DIV_ROUND_UP(efx->n_tx_channels,
717 ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size);
718
719 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
720 if (rc)
721 netif_err(efx, probe, efx->net_dev,
722 "failed to allocate PIO buffers (%d)\n", rc);
723 else
724 netif_dbg(efx, probe, efx->net_dev,
725 "allocated %u PIO buffers\n", n_piobufs);
726 }
727#else
728 nic_data->n_piobufs = 0;
729#endif
730
731 /* PIO buffers should be mapped with write-combining enabled,
732 * and we want to make single UC and WC mappings rather than
733 * several of each (in fact that's the only option if host
734 * page size is >4K). So we may allocate some extra VIs just
735 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100736 *
737 * The UC mapping contains (min_vis - 1) complete VIs and the
738 * first half of the next VI. Then the WC mapping begins with
739 * the second half of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +0100740 */
741 uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE +
742 ER_DZ_TX_PIOBUF);
743 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +0100744 /* pio_write_vi_base rounds down to give the number of complete
745 * VIs inside the UC mapping.
746 */
Ben Hutchings183233b2013-06-28 21:47:12 +0100747 pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE;
748 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
749 nic_data->n_piobufs) *
750 EFX_VI_PAGE_SIZE) -
751 uc_mem_map_size);
752 max_vis = pio_write_vi_base + nic_data->n_piobufs;
753 } else {
754 pio_write_vi_base = 0;
755 wc_mem_map_size = 0;
756 max_vis = min_vis;
757 }
758
759 /* In case the last attached driver failed to free VIs, do it now */
760 rc = efx_ef10_free_vis(efx);
761 if (rc != 0)
762 return rc;
763
764 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
765 if (rc != 0)
766 return rc;
767
768 /* If we didn't get enough VIs to map all the PIO buffers, free the
769 * PIO buffers
770 */
771 if (nic_data->n_piobufs &&
772 nic_data->n_allocated_vis <
773 pio_write_vi_base + nic_data->n_piobufs) {
774 netif_dbg(efx, probe, efx->net_dev,
775 "%u VIs are not sufficient to map %u PIO buffers\n",
776 nic_data->n_allocated_vis, nic_data->n_piobufs);
777 efx_ef10_free_piobufs(efx);
778 }
779
780 /* Shrink the original UC mapping of the memory BAR */
781 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
782 if (!membase) {
783 netif_err(efx, probe, efx->net_dev,
784 "could not shrink memory BAR to %x\n",
785 uc_mem_map_size);
786 return -ENOMEM;
787 }
788 iounmap(efx->membase);
789 efx->membase = membase;
790
791 /* Set up the WC mapping if needed */
792 if (wc_mem_map_size) {
793 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
794 uc_mem_map_size,
795 wc_mem_map_size);
796 if (!nic_data->wc_membase) {
797 netif_err(efx, probe, efx->net_dev,
798 "could not allocate WC mapping of size %x\n",
799 wc_mem_map_size);
800 return -ENOMEM;
801 }
802 nic_data->pio_write_vi_base = pio_write_vi_base;
803 nic_data->pio_write_base =
804 nic_data->wc_membase +
805 (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF -
806 uc_mem_map_size);
807
808 rc = efx_ef10_link_piobufs(efx);
809 if (rc)
810 efx_ef10_free_piobufs(efx);
811 }
812
813 netif_dbg(efx, probe, efx->net_dev,
814 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
815 &efx->membase_phys, efx->membase, uc_mem_map_size,
816 nic_data->wc_membase, wc_mem_map_size);
817
818 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +0100819}
820
821static int efx_ef10_init_nic(struct efx_nic *efx)
822{
823 struct efx_ef10_nic_data *nic_data = efx->nic_data;
824 int rc;
825
Ben Hutchingsa915ccc2013-09-05 22:51:55 +0100826 if (nic_data->must_check_datapath_caps) {
827 rc = efx_ef10_init_datapath_caps(efx);
828 if (rc)
829 return rc;
830 nic_data->must_check_datapath_caps = false;
831 }
832
Ben Hutchings8127d662013-08-29 19:19:29 +0100833 if (nic_data->must_realloc_vis) {
834 /* We cannot let the number of VIs change now */
835 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
836 nic_data->n_allocated_vis);
837 if (rc)
838 return rc;
839 nic_data->must_realloc_vis = false;
840 }
841
Ben Hutchings183233b2013-06-28 21:47:12 +0100842 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
843 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
844 if (rc == 0) {
845 rc = efx_ef10_link_piobufs(efx);
846 if (rc)
847 efx_ef10_free_piobufs(efx);
848 }
849
850 /* Log an error on failure, but this is non-fatal */
851 if (rc)
852 netif_err(efx, drv, efx->net_dev,
853 "failed to restore PIO buffers (%d)\n", rc);
854 nic_data->must_restore_piobufs = false;
855 }
856
Jon Cooper267c0152015-05-06 00:59:38 +0100857 /* don't fail init if RSS setup doesn't work */
858 efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table);
859
Ben Hutchings8127d662013-08-29 19:19:29 +0100860 return 0;
861}
862
Jon Cooper3e336262014-01-17 19:48:06 +0000863static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
864{
865 struct efx_ef10_nic_data *nic_data = efx->nic_data;
866
867 /* All our allocations have been reset */
868 nic_data->must_realloc_vis = true;
869 nic_data->must_restore_filters = true;
870 nic_data->must_restore_piobufs = true;
871 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
872}
873
Jon Cooper087e9022015-05-20 11:11:35 +0100874static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
875{
876 if (reason == RESET_TYPE_MC_FAILURE)
877 return RESET_TYPE_DATAPATH;
878
879 return efx_mcdi_map_reset_reason(reason);
880}
881
Ben Hutchings8127d662013-08-29 19:19:29 +0100882static int efx_ef10_map_reset_flags(u32 *flags)
883{
884 enum {
885 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
886 ETH_RESET_SHARED_SHIFT),
887 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
888 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
889 ETH_RESET_PHY | ETH_RESET_MGMT) <<
890 ETH_RESET_SHARED_SHIFT)
891 };
892
893 /* We assume for now that our PCI function is permitted to
894 * reset everything.
895 */
896
897 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
898 *flags &= ~EF10_RESET_MC;
899 return RESET_TYPE_WORLD;
900 }
901
902 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
903 *flags &= ~EF10_RESET_PORT;
904 return RESET_TYPE_ALL;
905 }
906
907 /* no invisible reset implemented */
908
909 return -EINVAL;
910}
911
Jon Cooper3e336262014-01-17 19:48:06 +0000912static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
913{
914 int rc = efx_mcdi_reset(efx, reset_type);
915
916 /* If it was a port reset, trigger reallocation of MC resources.
917 * Note that on an MC reset nothing needs to be done now because we'll
918 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +0100919 * For an FLR, we never get an MC reset event, but the MC has reset all
920 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +0000921 */
Edward Creee2835462014-04-16 19:27:48 +0100922 if ((reset_type == RESET_TYPE_ALL ||
923 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +0000924 efx_ef10_reset_mc_allocations(efx);
925 return rc;
926}
927
Ben Hutchings8127d662013-08-29 19:19:29 +0100928#define EF10_DMA_STAT(ext_name, mcdi_name) \
929 [EF10_STAT_ ## ext_name] = \
930 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
931#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
932 [EF10_STAT_ ## int_name] = \
933 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
934#define EF10_OTHER_STAT(ext_name) \
935 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +0100936#define GENERIC_SW_STAT(ext_name) \
937 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100938
939static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
940 EF10_DMA_STAT(tx_bytes, TX_BYTES),
941 EF10_DMA_STAT(tx_packets, TX_PKTS),
942 EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS),
943 EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS),
944 EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS),
945 EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS),
946 EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS),
947 EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS),
948 EF10_DMA_STAT(tx_64, TX_64_PKTS),
949 EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS),
950 EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS),
951 EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS),
952 EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS),
953 EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
954 EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
955 EF10_DMA_STAT(rx_bytes, RX_BYTES),
956 EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES),
957 EF10_OTHER_STAT(rx_good_bytes),
958 EF10_OTHER_STAT(rx_bad_bytes),
959 EF10_DMA_STAT(rx_packets, RX_PKTS),
960 EF10_DMA_STAT(rx_good, RX_GOOD_PKTS),
961 EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS),
962 EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS),
963 EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS),
964 EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS),
965 EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS),
966 EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS),
967 EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS),
968 EF10_DMA_STAT(rx_64, RX_64_PKTS),
969 EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS),
970 EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS),
971 EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS),
972 EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS),
973 EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
974 EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
975 EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS),
976 EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS),
977 EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS),
978 EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS),
979 EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS),
980 EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +0100981 GENERIC_SW_STAT(rx_nodesc_trunc),
982 GENERIC_SW_STAT(rx_noskb_drops),
Edward Cree568d7a02013-09-25 17:32:09 +0100983 EF10_DMA_STAT(rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
984 EF10_DMA_STAT(rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
985 EF10_DMA_STAT(rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
986 EF10_DMA_STAT(rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
987 EF10_DMA_STAT(rx_pm_trunc_qbb, PM_TRUNC_QBB),
988 EF10_DMA_STAT(rx_pm_discard_qbb, PM_DISCARD_QBB),
989 EF10_DMA_STAT(rx_pm_discard_mapping, PM_DISCARD_MAPPING),
990 EF10_DMA_STAT(rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
991 EF10_DMA_STAT(rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
992 EF10_DMA_STAT(rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
Shradha Shah79ac47a2013-11-28 18:48:49 +0000993 EF10_DMA_STAT(rx_dp_hlb_fetch, RXDP_EMERGENCY_FETCH_CONDITIONS),
994 EF10_DMA_STAT(rx_dp_hlb_wait, RXDP_EMERGENCY_WAIT_CONDITIONS),
Ben Hutchings8127d662013-08-29 19:19:29 +0100995};
996
997#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \
998 (1ULL << EF10_STAT_tx_packets) | \
999 (1ULL << EF10_STAT_tx_pause) | \
1000 (1ULL << EF10_STAT_tx_unicast) | \
1001 (1ULL << EF10_STAT_tx_multicast) | \
1002 (1ULL << EF10_STAT_tx_broadcast) | \
1003 (1ULL << EF10_STAT_rx_bytes) | \
1004 (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \
1005 (1ULL << EF10_STAT_rx_good_bytes) | \
1006 (1ULL << EF10_STAT_rx_bad_bytes) | \
1007 (1ULL << EF10_STAT_rx_packets) | \
1008 (1ULL << EF10_STAT_rx_good) | \
1009 (1ULL << EF10_STAT_rx_bad) | \
1010 (1ULL << EF10_STAT_rx_pause) | \
1011 (1ULL << EF10_STAT_rx_control) | \
1012 (1ULL << EF10_STAT_rx_unicast) | \
1013 (1ULL << EF10_STAT_rx_multicast) | \
1014 (1ULL << EF10_STAT_rx_broadcast) | \
1015 (1ULL << EF10_STAT_rx_lt64) | \
1016 (1ULL << EF10_STAT_rx_64) | \
1017 (1ULL << EF10_STAT_rx_65_to_127) | \
1018 (1ULL << EF10_STAT_rx_128_to_255) | \
1019 (1ULL << EF10_STAT_rx_256_to_511) | \
1020 (1ULL << EF10_STAT_rx_512_to_1023) | \
1021 (1ULL << EF10_STAT_rx_1024_to_15xx) | \
1022 (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \
1023 (1ULL << EF10_STAT_rx_gtjumbo) | \
1024 (1ULL << EF10_STAT_rx_bad_gtjumbo) | \
1025 (1ULL << EF10_STAT_rx_overflow) | \
Edward Creee4d112e2014-07-15 11:58:12 +01001026 (1ULL << EF10_STAT_rx_nodesc_drops) | \
1027 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1028 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001029
1030/* These statistics are only provided by the 10G MAC. For a 10G/40G
1031 * switchable port we do not expose these because they might not
1032 * include all the packets they should.
1033 */
1034#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \
1035 (1ULL << EF10_STAT_tx_lt64) | \
1036 (1ULL << EF10_STAT_tx_64) | \
1037 (1ULL << EF10_STAT_tx_65_to_127) | \
1038 (1ULL << EF10_STAT_tx_128_to_255) | \
1039 (1ULL << EF10_STAT_tx_256_to_511) | \
1040 (1ULL << EF10_STAT_tx_512_to_1023) | \
1041 (1ULL << EF10_STAT_tx_1024_to_15xx) | \
1042 (1ULL << EF10_STAT_tx_15xx_to_jumbo))
1043
1044/* These statistics are only provided by the 40G MAC. For a 10G/40G
1045 * switchable port we do expose these because the errors will otherwise
1046 * be silent.
1047 */
1048#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \
1049 (1ULL << EF10_STAT_rx_length_error))
1050
Edward Cree568d7a02013-09-25 17:32:09 +01001051/* These statistics are only provided if the firmware supports the
1052 * capability PM_AND_RXDP_COUNTERS.
1053 */
1054#define HUNT_PM_AND_RXDP_STAT_MASK ( \
1055 (1ULL << EF10_STAT_rx_pm_trunc_bb_overflow) | \
1056 (1ULL << EF10_STAT_rx_pm_discard_bb_overflow) | \
1057 (1ULL << EF10_STAT_rx_pm_trunc_vfifo_full) | \
1058 (1ULL << EF10_STAT_rx_pm_discard_vfifo_full) | \
1059 (1ULL << EF10_STAT_rx_pm_trunc_qbb) | \
1060 (1ULL << EF10_STAT_rx_pm_discard_qbb) | \
1061 (1ULL << EF10_STAT_rx_pm_discard_mapping) | \
1062 (1ULL << EF10_STAT_rx_dp_q_disabled_packets) | \
1063 (1ULL << EF10_STAT_rx_dp_di_dropped_packets) | \
1064 (1ULL << EF10_STAT_rx_dp_streaming_packets) | \
Shradha Shah79ac47a2013-11-28 18:48:49 +00001065 (1ULL << EF10_STAT_rx_dp_hlb_fetch) | \
1066 (1ULL << EF10_STAT_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001067
Edward Cree4bae9132013-09-27 18:52:49 +01001068static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001069{
Edward Cree4bae9132013-09-27 18:52:49 +01001070 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001071 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001072 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001073
1074 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
Edward Cree4bae9132013-09-27 18:52:49 +01001075 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001076 else
Edward Cree4bae9132013-09-27 18:52:49 +01001077 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree568d7a02013-09-25 17:32:09 +01001078
1079 if (nic_data->datapath_caps &
1080 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1081 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1082
Edward Cree4bae9132013-09-27 18:52:49 +01001083 return raw_mask;
1084}
1085
1086static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1087{
1088 u64 raw_mask = efx_ef10_raw_stat_mask(efx);
1089
1090#if BITS_PER_LONG == 64
1091 mask[0] = raw_mask;
1092#else
1093 mask[0] = raw_mask & 0xffffffff;
1094 mask[1] = raw_mask >> 32;
1095#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001096}
1097
1098static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1099{
Edward Cree4bae9132013-09-27 18:52:49 +01001100 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1101
1102 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001103 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001104 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001105}
1106
1107static int efx_ef10_try_update_nic_stats(struct efx_nic *efx)
1108{
1109 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001110 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001111 __le64 generation_start, generation_end;
1112 u64 *stats = nic_data->stats;
1113 __le64 *dma_stats;
1114
Edward Cree4bae9132013-09-27 18:52:49 +01001115 efx_ef10_get_stat_mask(efx, mask);
1116
Ben Hutchings8127d662013-08-29 19:19:29 +01001117 dma_stats = efx->stats_buffer.addr;
1118 nic_data = efx->nic_data;
1119
1120 generation_end = dma_stats[MC_CMD_MAC_GENERATION_END];
1121 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1122 return 0;
1123 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001124 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001125 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001126 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001127 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1128 if (generation_end != generation_start)
1129 return -EAGAIN;
1130
1131 /* Update derived statistics */
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01001132 efx_nic_fix_nodesc_drop_stat(efx, &stats[EF10_STAT_rx_nodesc_drops]);
Ben Hutchings8127d662013-08-29 19:19:29 +01001133 stats[EF10_STAT_rx_good_bytes] =
1134 stats[EF10_STAT_rx_bytes] -
1135 stats[EF10_STAT_rx_bytes_minus_good_bytes];
1136 efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes],
1137 stats[EF10_STAT_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001138 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001139 return 0;
1140}
1141
1142
1143static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats,
1144 struct rtnl_link_stats64 *core_stats)
1145{
Edward Cree4bae9132013-09-27 18:52:49 +01001146 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001147 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1148 u64 *stats = nic_data->stats;
1149 size_t stats_count = 0, index;
1150 int retry;
1151
Edward Cree4bae9132013-09-27 18:52:49 +01001152 efx_ef10_get_stat_mask(efx, mask);
1153
Ben Hutchings8127d662013-08-29 19:19:29 +01001154 /* If we're unlucky enough to read statistics during the DMA, wait
1155 * up to 10ms for it to finish (typically takes <500us)
1156 */
1157 for (retry = 0; retry < 100; ++retry) {
1158 if (efx_ef10_try_update_nic_stats(efx) == 0)
1159 break;
1160 udelay(100);
1161 }
1162
1163 if (full_stats) {
1164 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1165 if (efx_ef10_stat_desc[index].name) {
1166 *full_stats++ = stats[index];
1167 ++stats_count;
1168 }
1169 }
1170 }
1171
1172 if (core_stats) {
1173 core_stats->rx_packets = stats[EF10_STAT_rx_packets];
1174 core_stats->tx_packets = stats[EF10_STAT_tx_packets];
1175 core_stats->rx_bytes = stats[EF10_STAT_rx_bytes];
1176 core_stats->tx_bytes = stats[EF10_STAT_tx_bytes];
Edward Creee4d112e2014-07-15 11:58:12 +01001177 core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops] +
1178 stats[GENERIC_STAT_rx_nodesc_trunc] +
1179 stats[GENERIC_STAT_rx_noskb_drops];
Ben Hutchings8127d662013-08-29 19:19:29 +01001180 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1181 core_stats->rx_length_errors =
1182 stats[EF10_STAT_rx_gtjumbo] +
1183 stats[EF10_STAT_rx_length_error];
1184 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1185 core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error];
1186 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1187 core_stats->rx_errors = (core_stats->rx_length_errors +
1188 core_stats->rx_crc_errors +
1189 core_stats->rx_frame_errors);
1190 }
1191
1192 return stats_count;
1193}
1194
1195static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
1196{
1197 struct efx_nic *efx = channel->efx;
1198 unsigned int mode, value;
1199 efx_dword_t timer_cmd;
1200
1201 if (channel->irq_moderation) {
1202 mode = 3;
1203 value = channel->irq_moderation - 1;
1204 } else {
1205 mode = 0;
1206 value = 0;
1207 }
1208
1209 if (EFX_EF10_WORKAROUND_35388(efx)) {
1210 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
1211 EFE_DD_EVQ_IND_TIMER_FLAGS,
1212 ERF_DD_EVQ_IND_TIMER_MODE, mode,
1213 ERF_DD_EVQ_IND_TIMER_VAL, value);
1214 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
1215 channel->channel);
1216 } else {
1217 EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
1218 ERF_DZ_TC_TIMER_VAL, value);
1219 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
1220 channel->channel);
1221 }
1222}
1223
Shradha Shah02246a72015-05-06 00:58:14 +01001224static void efx_ef10_get_wol_vf(struct efx_nic *efx,
1225 struct ethtool_wolinfo *wol) {}
1226
1227static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
1228{
1229 return -EOPNOTSUPP;
1230}
1231
Ben Hutchings8127d662013-08-29 19:19:29 +01001232static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
1233{
1234 wol->supported = 0;
1235 wol->wolopts = 0;
1236 memset(&wol->sopass, 0, sizeof(wol->sopass));
1237}
1238
1239static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
1240{
1241 if (type != 0)
1242 return -EINVAL;
1243 return 0;
1244}
1245
1246static void efx_ef10_mcdi_request(struct efx_nic *efx,
1247 const efx_dword_t *hdr, size_t hdr_len,
1248 const efx_dword_t *sdu, size_t sdu_len)
1249{
1250 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1251 u8 *pdu = nic_data->mcdi_buf.addr;
1252
1253 memcpy(pdu, hdr, hdr_len);
1254 memcpy(pdu + hdr_len, sdu, sdu_len);
1255 wmb();
1256
1257 /* The hardware provides 'low' and 'high' (doorbell) registers
1258 * for passing the 64-bit address of an MCDI request to
1259 * firmware. However the dwords are swapped by firmware. The
1260 * least significant bits of the doorbell are then 0 for all
1261 * MCDI requests due to alignment.
1262 */
1263 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
1264 ER_DZ_MC_DB_LWRD);
1265 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
1266 ER_DZ_MC_DB_HWRD);
1267}
1268
1269static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
1270{
1271 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1272 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
1273
1274 rmb();
1275 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
1276}
1277
1278static void
1279efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
1280 size_t offset, size_t outlen)
1281{
1282 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1283 const u8 *pdu = nic_data->mcdi_buf.addr;
1284
1285 memcpy(outbuf, pdu + offset, outlen);
1286}
1287
1288static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
1289{
1290 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1291 int rc;
1292
1293 rc = efx_ef10_get_warm_boot_count(efx);
1294 if (rc < 0) {
1295 /* The firmware is presumably in the process of
1296 * rebooting. However, we are supposed to report each
1297 * reboot just once, so we must only do that once we
1298 * can read and store the updated warm boot count.
1299 */
1300 return 0;
1301 }
1302
1303 if (rc == nic_data->warm_boot_count)
1304 return 0;
1305
1306 nic_data->warm_boot_count = rc;
1307
1308 /* All our allocations have been reset */
Jon Cooper3e336262014-01-17 19:48:06 +00001309 efx_ef10_reset_mc_allocations(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +01001310
Daniel Pieczko6d8aaaf2015-05-06 00:57:34 +01001311 /* Driver-created vswitches and vports must be re-created */
1312 nic_data->must_probe_vswitching = true;
1313 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1314
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001315 /* The datapath firmware might have been changed */
1316 nic_data->must_check_datapath_caps = true;
1317
Ben Hutchings869070c2013-09-05 22:46:10 +01001318 /* MAC statistics have been cleared on the NIC; clear the local
1319 * statistic that we update with efx_update_diff_stat().
1320 */
1321 nic_data->stats[EF10_STAT_rx_bad_bytes] = 0;
1322
Ben Hutchings8127d662013-08-29 19:19:29 +01001323 return -EIO;
1324}
1325
1326/* Handle an MSI interrupt
1327 *
1328 * Handle an MSI hardware interrupt. This routine schedules event
1329 * queue processing. No interrupt acknowledgement cycle is necessary.
1330 * Also, we never need to check that the interrupt is for us, since
1331 * MSI interrupts cannot be shared.
1332 */
1333static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
1334{
1335 struct efx_msi_context *context = dev_id;
1336 struct efx_nic *efx = context->efx;
1337
1338 netif_vdbg(efx, intr, efx->net_dev,
1339 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
1340
1341 if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) {
1342 /* Note test interrupts */
1343 if (context->index == efx->irq_level)
1344 efx->last_irq_cpu = raw_smp_processor_id();
1345
1346 /* Schedule processing of the channel */
1347 efx_schedule_channel_irq(efx->channel[context->index]);
1348 }
1349
1350 return IRQ_HANDLED;
1351}
1352
1353static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
1354{
1355 struct efx_nic *efx = dev_id;
1356 bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
1357 struct efx_channel *channel;
1358 efx_dword_t reg;
1359 u32 queues;
1360
1361 /* Read the ISR which also ACKs the interrupts */
1362 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
1363 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
1364
1365 if (queues == 0)
1366 return IRQ_NONE;
1367
1368 if (likely(soft_enabled)) {
1369 /* Note test interrupts */
1370 if (queues & (1U << efx->irq_level))
1371 efx->last_irq_cpu = raw_smp_processor_id();
1372
1373 efx_for_each_channel(channel, efx) {
1374 if (queues & 1)
1375 efx_schedule_channel_irq(channel);
1376 queues >>= 1;
1377 }
1378 }
1379
1380 netif_vdbg(efx, intr, efx->net_dev,
1381 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1382 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1383
1384 return IRQ_HANDLED;
1385}
1386
1387static void efx_ef10_irq_test_generate(struct efx_nic *efx)
1388{
1389 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
1390
1391 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
1392
1393 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
1394 (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
1395 inbuf, sizeof(inbuf), NULL, 0, NULL);
1396}
1397
1398static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
1399{
1400 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
1401 (tx_queue->ptr_mask + 1) *
1402 sizeof(efx_qword_t),
1403 GFP_KERNEL);
1404}
1405
1406/* This writes to the TX_DESC_WPTR and also pushes data */
1407static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
1408 const efx_qword_t *txd)
1409{
1410 unsigned int write_ptr;
1411 efx_oword_t reg;
1412
1413 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1414 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
1415 reg.qword[0] = *txd;
1416 efx_writeo_page(tx_queue->efx, &reg,
1417 ER_DZ_TX_DESC_UPD, tx_queue->queue);
1418}
1419
1420static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
1421{
1422 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1423 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001424 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
1425 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
1426 struct efx_channel *channel = tx_queue->channel;
1427 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001428 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001429 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001430 dma_addr_t dma_addr;
1431 efx_qword_t *txd;
1432 int rc;
1433 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001434 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001435
1436 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
1437 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
1438 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
1439 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
1440 MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS,
1441 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
1442 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload);
1443 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001444 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001445
1446 dma_addr = tx_queue->txd.buf.dma_addr;
1447
1448 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
1449 tx_queue->queue, entries, (u64)dma_addr);
1450
1451 for (i = 0; i < entries; ++i) {
1452 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
1453 dma_addr += EFX_BUF_SIZE;
1454 }
1455
1456 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
1457
1458 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001459 NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001460 if (rc)
1461 goto fail;
1462
1463 /* A previous user of this TX queue might have set us up the
1464 * bomb by writing a descriptor to the TX push collector but
1465 * not the doorbell. (Each collector belongs to a port, not a
1466 * queue or function, so cannot easily be reset.) We must
1467 * attempt to push a no-op descriptor in its place.
1468 */
1469 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
1470 tx_queue->insert_count = 1;
1471 txd = efx_tx_desc(tx_queue, 0);
1472 EFX_POPULATE_QWORD_4(*txd,
1473 ESF_DZ_TX_DESC_IS_OPT, true,
1474 ESF_DZ_TX_OPTION_TYPE,
1475 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
1476 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
1477 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload);
1478 tx_queue->write_count = 1;
1479 wmb();
1480 efx_ef10_push_tx_desc(tx_queue, txd);
1481
1482 return;
1483
1484fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00001485 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
1486 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01001487}
1488
1489static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
1490{
1491 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001492 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001493 struct efx_nic *efx = tx_queue->efx;
1494 size_t outlen;
1495 int rc;
1496
1497 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
1498 tx_queue->queue);
1499
Edward Cree1e0b8122013-05-31 18:36:12 +01001500 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001501 outbuf, sizeof(outbuf), &outlen);
1502
1503 if (rc && rc != -EALREADY)
1504 goto fail;
1505
1506 return;
1507
1508fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001509 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
1510 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001511}
1512
1513static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
1514{
1515 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
1516}
1517
1518/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
1519static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
1520{
1521 unsigned int write_ptr;
1522 efx_dword_t reg;
1523
1524 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1525 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
1526 efx_writed_page(tx_queue->efx, &reg,
1527 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
1528}
1529
1530static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
1531{
1532 unsigned int old_write_count = tx_queue->write_count;
1533 struct efx_tx_buffer *buffer;
1534 unsigned int write_ptr;
1535 efx_qword_t *txd;
1536
1537 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
1538
1539 do {
1540 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
1541 buffer = &tx_queue->buffer[write_ptr];
1542 txd = efx_tx_desc(tx_queue, write_ptr);
1543 ++tx_queue->write_count;
1544
1545 /* Create TX descriptor ring entry */
1546 if (buffer->flags & EFX_TX_BUF_OPTION) {
1547 *txd = buffer->option;
1548 } else {
1549 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
1550 EFX_POPULATE_QWORD_3(
1551 *txd,
1552 ESF_DZ_TX_KER_CONT,
1553 buffer->flags & EFX_TX_BUF_CONT,
1554 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
1555 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
1556 }
1557 } while (tx_queue->write_count != tx_queue->insert_count);
1558
1559 wmb(); /* Ensure descriptors are written before they are fetched */
1560
1561 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
1562 txd = efx_tx_desc(tx_queue,
1563 old_write_count & tx_queue->ptr_mask);
1564 efx_ef10_push_tx_desc(tx_queue, txd);
1565 ++tx_queue->pushes;
1566 } else {
1567 efx_ef10_notify_tx_desc(tx_queue);
1568 }
1569}
1570
Jon Cooper267c0152015-05-06 00:59:38 +01001571static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
1572 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01001573{
1574 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
1575 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001576 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001577 size_t outlen;
1578 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001579 u32 alloc_type = exclusive ?
1580 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
1581 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
1582 unsigned rss_spread = exclusive ?
1583 efx->rss_spread :
1584 min(rounddown_pow_of_two(efx->rss_spread),
1585 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
1586
1587 if (!exclusive && rss_spread == 1) {
1588 *context = EFX_EF10_RSS_CONTEXT_INVALID;
1589 if (context_size)
1590 *context_size = 1;
1591 return 0;
1592 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001593
1594 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01001595 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01001596 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
1597 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01001598
1599 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
1600 outbuf, sizeof(outbuf), &outlen);
1601 if (rc != 0)
1602 return rc;
1603
1604 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
1605 return -EIO;
1606
1607 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
1608
Jon Cooper267c0152015-05-06 00:59:38 +01001609 if (context_size)
1610 *context_size = rss_spread;
1611
Ben Hutchings8127d662013-08-29 19:19:29 +01001612 return 0;
1613}
1614
1615static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
1616{
1617 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
1618 int rc;
1619
1620 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
1621 context);
1622
1623 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
1624 NULL, 0, NULL);
1625 WARN_ON(rc != 0);
1626}
1627
Jon Cooper267c0152015-05-06 00:59:38 +01001628static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
1629 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001630{
1631 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
1632 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
1633 int i, rc;
1634
1635 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
1636 context);
1637 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
1638 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
1639
1640 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
1641 MCDI_PTR(tablebuf,
1642 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01001643 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01001644
1645 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
1646 sizeof(tablebuf), NULL, 0, NULL);
1647 if (rc != 0)
1648 return rc;
1649
1650 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
1651 context);
1652 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
1653 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
1654 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
1655 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] =
1656 efx->rx_hash_key[i];
1657
1658 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
1659 sizeof(keybuf), NULL, 0, NULL);
1660}
1661
1662static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
1663{
1664 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1665
1666 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1667 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
1668 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
1669}
1670
Jon Cooper267c0152015-05-06 00:59:38 +01001671static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
1672 unsigned *context_size)
1673{
1674 u32 new_rx_rss_context;
1675 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1676 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1677 false, context_size);
1678
1679 if (rc != 0)
1680 return rc;
1681
1682 nic_data->rx_rss_context = new_rx_rss_context;
1683 nic_data->rx_rss_context_exclusive = false;
1684 efx_set_default_rx_indir_table(efx);
1685 return 0;
1686}
1687
1688static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
1689 const u32 *rx_indir_table)
Ben Hutchings8127d662013-08-29 19:19:29 +01001690{
1691 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1692 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01001693 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001694
Jon Cooper267c0152015-05-06 00:59:38 +01001695 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
1696 !nic_data->rx_rss_context_exclusive) {
1697 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
1698 true, NULL);
1699 if (rc == -EOPNOTSUPP)
1700 return rc;
1701 else if (rc != 0)
1702 goto fail1;
1703 } else {
1704 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01001705 }
1706
Jon Cooper267c0152015-05-06 00:59:38 +01001707 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
1708 rx_indir_table);
Ben Hutchings8127d662013-08-29 19:19:29 +01001709 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01001710 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01001711
Jon Cooper267c0152015-05-06 00:59:38 +01001712 if (nic_data->rx_rss_context != new_rx_rss_context)
1713 efx_ef10_rx_free_indir_table(efx);
1714 nic_data->rx_rss_context = new_rx_rss_context;
1715 nic_data->rx_rss_context_exclusive = true;
1716 if (rx_indir_table != efx->rx_indir_table)
1717 memcpy(efx->rx_indir_table, rx_indir_table,
1718 sizeof(efx->rx_indir_table));
1719 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001720
Jon Cooper267c0152015-05-06 00:59:38 +01001721fail2:
1722 if (new_rx_rss_context != nic_data->rx_rss_context)
1723 efx_ef10_free_rss_context(efx, new_rx_rss_context);
1724fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01001725 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01001726 return rc;
1727}
1728
1729static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
1730 const u32 *rx_indir_table)
1731{
1732 int rc;
1733
1734 if (efx->rss_spread == 1)
1735 return 0;
1736
1737 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table);
1738
1739 if (rc == -ENOBUFS && !user) {
1740 unsigned context_size;
1741 bool mismatch = false;
1742 size_t i;
1743
1744 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
1745 i++)
1746 mismatch = rx_indir_table[i] !=
1747 ethtool_rxfh_indir_default(i, efx->rss_spread);
1748
1749 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
1750 if (rc == 0) {
1751 if (context_size != efx->rss_spread)
1752 netif_warn(efx, probe, efx->net_dev,
1753 "Could not allocate an exclusive RSS"
1754 " context; allocated a shared one of"
1755 " different size."
1756 " Wanted %u, got %u.\n",
1757 efx->rss_spread, context_size);
1758 else if (mismatch)
1759 netif_warn(efx, probe, efx->net_dev,
1760 "Could not allocate an exclusive RSS"
1761 " context; allocated a shared one but"
1762 " could not apply custom"
1763 " indirection.\n");
1764 else
1765 netif_info(efx, probe, efx->net_dev,
1766 "Could not allocate an exclusive RSS"
1767 " context; allocated a shared one.\n");
1768 }
1769 }
1770 return rc;
1771}
1772
1773static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
1774 const u32 *rx_indir_table
1775 __attribute__ ((unused)))
1776{
1777 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1778
1779 if (user)
1780 return -EOPNOTSUPP;
1781 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
1782 return 0;
1783 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01001784}
1785
1786static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
1787{
1788 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
1789 (rx_queue->ptr_mask + 1) *
1790 sizeof(efx_qword_t),
1791 GFP_KERNEL);
1792}
1793
1794static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
1795{
1796 MCDI_DECLARE_BUF(inbuf,
1797 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
1798 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01001799 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1800 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
1801 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01001802 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001803 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01001804 dma_addr_t dma_addr;
1805 int rc;
1806 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001807 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01001808
1809 rx_queue->scatter_n = 0;
1810 rx_queue->scatter_len = 0;
1811
1812 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
1813 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
1814 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
1815 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
1816 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00001817 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
1818 INIT_RXQ_IN_FLAG_PREFIX, 1,
1819 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01001820 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01001821 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01001822
1823 dma_addr = rx_queue->rxd.buf.dma_addr;
1824
1825 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
1826 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
1827
1828 for (i = 0; i < entries; ++i) {
1829 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
1830 dma_addr += EFX_BUF_SIZE;
1831 }
1832
1833 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
1834
1835 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001836 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00001837 if (rc)
1838 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
1839 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01001840}
1841
1842static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
1843{
1844 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01001845 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01001846 struct efx_nic *efx = rx_queue->efx;
1847 size_t outlen;
1848 int rc;
1849
1850 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
1851 efx_rx_queue_index(rx_queue));
1852
Edward Cree1e0b8122013-05-31 18:36:12 +01001853 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01001854 outbuf, sizeof(outbuf), &outlen);
1855
1856 if (rc && rc != -EALREADY)
1857 goto fail;
1858
1859 return;
1860
1861fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01001862 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
1863 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01001864}
1865
1866static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
1867{
1868 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
1869}
1870
1871/* This creates an entry in the RX descriptor queue */
1872static inline void
1873efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
1874{
1875 struct efx_rx_buffer *rx_buf;
1876 efx_qword_t *rxd;
1877
1878 rxd = efx_rx_desc(rx_queue, index);
1879 rx_buf = efx_rx_buffer(rx_queue, index);
1880 EFX_POPULATE_QWORD_2(*rxd,
1881 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
1882 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
1883}
1884
1885static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
1886{
1887 struct efx_nic *efx = rx_queue->efx;
1888 unsigned int write_count;
1889 efx_dword_t reg;
1890
1891 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
1892 write_count = rx_queue->added_count & ~7;
1893 if (rx_queue->notified_count == write_count)
1894 return;
1895
1896 do
1897 efx_ef10_build_rx_desc(
1898 rx_queue,
1899 rx_queue->notified_count & rx_queue->ptr_mask);
1900 while (++rx_queue->notified_count != write_count);
1901
1902 wmb();
1903 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
1904 write_count & rx_queue->ptr_mask);
1905 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
1906 efx_rx_queue_index(rx_queue));
1907}
1908
1909static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
1910
1911static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
1912{
1913 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
1914 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
1915 efx_qword_t event;
1916
1917 EFX_POPULATE_QWORD_2(event,
1918 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
1919 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
1920
1921 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
1922
1923 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
1924 * already swapped the data to little-endian order.
1925 */
1926 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
1927 sizeof(efx_qword_t));
1928
1929 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
1930 inbuf, sizeof(inbuf), 0,
1931 efx_ef10_rx_defer_refill_complete, 0);
1932}
1933
1934static void
1935efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
1936 int rc, efx_dword_t *outbuf,
1937 size_t outlen_actual)
1938{
1939 /* nothing to do */
1940}
1941
1942static int efx_ef10_ev_probe(struct efx_channel *channel)
1943{
1944 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
1945 (channel->eventq_mask + 1) *
1946 sizeof(efx_qword_t),
1947 GFP_KERNEL);
1948}
1949
1950static int efx_ef10_ev_init(struct efx_channel *channel)
1951{
1952 MCDI_DECLARE_BUF(inbuf,
1953 MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
1954 EFX_BUF_SIZE));
1955 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN);
1956 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
1957 struct efx_nic *efx = channel->efx;
1958 struct efx_ef10_nic_data *nic_data;
1959 bool supports_rx_merge;
1960 size_t inlen, outlen;
1961 dma_addr_t dma_addr;
1962 int rc;
1963 int i;
1964
1965 nic_data = efx->nic_data;
1966 supports_rx_merge =
1967 !!(nic_data->datapath_caps &
1968 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
1969
1970 /* Fill event queue with all ones (i.e. empty events) */
1971 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
1972
1973 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
1974 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
1975 /* INIT_EVQ expects index in vector table, not absolute */
1976 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
1977 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
1978 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
1979 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
1980 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
1981 INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge);
1982 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
1983 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
1984 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
1985 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
1986 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
1987 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
1988 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
1989
1990 dma_addr = channel->eventq.buf.dma_addr;
1991 for (i = 0; i < entries; ++i) {
1992 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
1993 dma_addr += EFX_BUF_SIZE;
1994 }
1995
1996 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
1997
1998 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
1999 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +01002000 /* IRQ return is ignored */
Ben Hutchings8127d662013-08-29 19:19:29 +01002001 return rc;
2002}
2003
2004static void efx_ef10_ev_fini(struct efx_channel *channel)
2005{
2006 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002007 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002008 struct efx_nic *efx = channel->efx;
2009 size_t outlen;
2010 int rc;
2011
2012 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
2013
Edward Cree1e0b8122013-05-31 18:36:12 +01002014 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002015 outbuf, sizeof(outbuf), &outlen);
2016
2017 if (rc && rc != -EALREADY)
2018 goto fail;
2019
2020 return;
2021
2022fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002023 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
2024 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002025}
2026
2027static void efx_ef10_ev_remove(struct efx_channel *channel)
2028{
2029 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
2030}
2031
2032static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
2033 unsigned int rx_queue_label)
2034{
2035 struct efx_nic *efx = rx_queue->efx;
2036
2037 netif_info(efx, hw, efx->net_dev,
2038 "rx event arrived on queue %d labeled as queue %u\n",
2039 efx_rx_queue_index(rx_queue), rx_queue_label);
2040
2041 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2042}
2043
2044static void
2045efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
2046 unsigned int actual, unsigned int expected)
2047{
2048 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
2049 struct efx_nic *efx = rx_queue->efx;
2050
2051 netif_info(efx, hw, efx->net_dev,
2052 "dropped %d events (index=%d expected=%d)\n",
2053 dropped, actual, expected);
2054
2055 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
2056}
2057
2058/* partially received RX was aborted. clean up. */
2059static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
2060{
2061 unsigned int rx_desc_ptr;
2062
Ben Hutchings8127d662013-08-29 19:19:29 +01002063 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
2064 "scattered RX aborted (dropping %u buffers)\n",
2065 rx_queue->scatter_n);
2066
2067 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
2068
2069 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
2070 0, EFX_RX_PKT_DISCARD);
2071
2072 rx_queue->removed_count += rx_queue->scatter_n;
2073 rx_queue->scatter_n = 0;
2074 rx_queue->scatter_len = 0;
2075 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
2076}
2077
2078static int efx_ef10_handle_rx_event(struct efx_channel *channel,
2079 const efx_qword_t *event)
2080{
2081 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class;
2082 unsigned int n_descs, n_packets, i;
2083 struct efx_nic *efx = channel->efx;
2084 struct efx_rx_queue *rx_queue;
2085 bool rx_cont;
2086 u16 flags = 0;
2087
2088 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2089 return 0;
2090
2091 /* Basic packet information */
2092 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
2093 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
2094 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
2095 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS);
2096 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
2097
Ben Hutchings48ce5632013-11-01 16:42:44 +00002098 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
2099 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
2100 EFX_QWORD_FMT "\n",
2101 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002102
2103 rx_queue = efx_channel_get_rx_queue(channel);
2104
2105 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
2106 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
2107
2108 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
2109 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2110
2111 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01002112 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2113
Ben Hutchings8127d662013-08-29 19:19:29 +01002114 /* detect rx abort */
2115 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00002116 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
2117 netdev_WARN(efx->net_dev,
2118 "invalid RX abort: scatter_n=%u event="
2119 EFX_QWORD_FMT "\n",
2120 rx_queue->scatter_n,
2121 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01002122 efx_ef10_handle_rx_abort(rx_queue);
2123 return 0;
2124 }
2125
Ben Hutchings92a04162013-09-24 23:21:57 +01002126 /* Check that RX completion merging is valid, i.e.
2127 * the current firmware supports it and this is a
2128 * non-scattered packet.
2129 */
2130 if (!(nic_data->datapath_caps &
2131 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
2132 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002133 efx_ef10_handle_rx_bad_lbits(
2134 rx_queue, next_ptr_lbits,
2135 (rx_queue->removed_count +
2136 rx_queue->scatter_n + 1) &
2137 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
2138 return 0;
2139 }
2140
2141 /* Merged completion for multiple non-scattered packets */
2142 rx_queue->scatter_n = 1;
2143 rx_queue->scatter_len = 0;
2144 n_packets = n_descs;
2145 ++channel->n_rx_merge_events;
2146 channel->n_rx_merge_packets += n_packets;
2147 flags |= EFX_RX_PKT_PREFIX_LEN;
2148 } else {
2149 ++rx_queue->scatter_n;
2150 rx_queue->scatter_len += rx_bytes;
2151 if (rx_cont)
2152 return 0;
2153 n_packets = 1;
2154 }
2155
2156 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)))
2157 flags |= EFX_RX_PKT_DISCARD;
2158
2159 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) {
2160 channel->n_rx_ip_hdr_chksum_err += n_packets;
2161 } else if (unlikely(EFX_QWORD_FIELD(*event,
2162 ESF_DZ_RX_TCPUDP_CKSUM_ERR))) {
2163 channel->n_rx_tcp_udp_chksum_err += n_packets;
2164 } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP ||
2165 rx_l4_class == ESE_DZ_L4_CLASS_UDP) {
2166 flags |= EFX_RX_PKT_CSUMMED;
2167 }
2168
2169 if (rx_l4_class == ESE_DZ_L4_CLASS_TCP)
2170 flags |= EFX_RX_PKT_TCP;
2171
2172 channel->irq_mod_score += 2 * n_packets;
2173
2174 /* Handle received packet(s) */
2175 for (i = 0; i < n_packets; i++) {
2176 efx_rx_packet(rx_queue,
2177 rx_queue->removed_count & rx_queue->ptr_mask,
2178 rx_queue->scatter_n, rx_queue->scatter_len,
2179 flags);
2180 rx_queue->removed_count += rx_queue->scatter_n;
2181 }
2182
2183 rx_queue->scatter_n = 0;
2184 rx_queue->scatter_len = 0;
2185
2186 return n_packets;
2187}
2188
2189static int
2190efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
2191{
2192 struct efx_nic *efx = channel->efx;
2193 struct efx_tx_queue *tx_queue;
2194 unsigned int tx_ev_desc_ptr;
2195 unsigned int tx_ev_q_label;
2196 int tx_descs = 0;
2197
2198 if (unlikely(ACCESS_ONCE(efx->reset_pending)))
2199 return 0;
2200
2201 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
2202 return 0;
2203
2204 /* Transmit completion */
2205 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
2206 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
2207 tx_queue = efx_channel_get_tx_queue(channel,
2208 tx_ev_q_label % EFX_TXQ_TYPES);
2209 tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) &
2210 tx_queue->ptr_mask);
2211 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
2212
2213 return tx_descs;
2214}
2215
2216static void
2217efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
2218{
2219 struct efx_nic *efx = channel->efx;
2220 int subcode;
2221
2222 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
2223
2224 switch (subcode) {
2225 case ESE_DZ_DRV_TIMER_EV:
2226 case ESE_DZ_DRV_WAKE_UP_EV:
2227 break;
2228 case ESE_DZ_DRV_START_UP_EV:
2229 /* event queue init complete. ok. */
2230 break;
2231 default:
2232 netif_err(efx, hw, efx->net_dev,
2233 "channel %d unknown driver event type %d"
2234 " (data " EFX_QWORD_FMT ")\n",
2235 channel->channel, subcode,
2236 EFX_QWORD_VAL(*event));
2237
2238 }
2239}
2240
2241static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
2242 efx_qword_t *event)
2243{
2244 struct efx_nic *efx = channel->efx;
2245 u32 subcode;
2246
2247 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
2248
2249 switch (subcode) {
2250 case EFX_EF10_TEST:
2251 channel->event_test_cpu = raw_smp_processor_id();
2252 break;
2253 case EFX_EF10_REFILL:
2254 /* The queue must be empty, so we won't receive any rx
2255 * events, so efx_process_channel() won't refill the
2256 * queue. Refill it here
2257 */
Jon Coopercce28792013-10-02 11:04:14 +01002258 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01002259 break;
2260 default:
2261 netif_err(efx, hw, efx->net_dev,
2262 "channel %d unknown driver event type %u"
2263 " (data " EFX_QWORD_FMT ")\n",
2264 channel->channel, (unsigned) subcode,
2265 EFX_QWORD_VAL(*event));
2266 }
2267}
2268
2269static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
2270{
2271 struct efx_nic *efx = channel->efx;
2272 efx_qword_t event, *p_event;
2273 unsigned int read_ptr;
2274 int ev_code;
2275 int tx_descs = 0;
2276 int spent = 0;
2277
Eric W. Biederman75363a42014-03-14 18:11:22 -07002278 if (quota <= 0)
2279 return spent;
2280
Ben Hutchings8127d662013-08-29 19:19:29 +01002281 read_ptr = channel->eventq_read_ptr;
2282
2283 for (;;) {
2284 p_event = efx_event(channel, read_ptr);
2285 event = *p_event;
2286
2287 if (!efx_event_present(&event))
2288 break;
2289
2290 EFX_SET_QWORD(*p_event);
2291
2292 ++read_ptr;
2293
2294 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
2295
2296 netif_vdbg(efx, drv, efx->net_dev,
2297 "processing event on %d " EFX_QWORD_FMT "\n",
2298 channel->channel, EFX_QWORD_VAL(event));
2299
2300 switch (ev_code) {
2301 case ESE_DZ_EV_CODE_MCDI_EV:
2302 efx_mcdi_process_event(channel, &event);
2303 break;
2304 case ESE_DZ_EV_CODE_RX_EV:
2305 spent += efx_ef10_handle_rx_event(channel, &event);
2306 if (spent >= quota) {
2307 /* XXX can we split a merged event to
2308 * avoid going over-quota?
2309 */
2310 spent = quota;
2311 goto out;
2312 }
2313 break;
2314 case ESE_DZ_EV_CODE_TX_EV:
2315 tx_descs += efx_ef10_handle_tx_event(channel, &event);
2316 if (tx_descs > efx->txq_entries) {
2317 spent = quota;
2318 goto out;
2319 } else if (++spent == quota) {
2320 goto out;
2321 }
2322 break;
2323 case ESE_DZ_EV_CODE_DRIVER_EV:
2324 efx_ef10_handle_driver_event(channel, &event);
2325 if (++spent == quota)
2326 goto out;
2327 break;
2328 case EFX_EF10_DRVGEN_EV:
2329 efx_ef10_handle_driver_generated_event(channel, &event);
2330 break;
2331 default:
2332 netif_err(efx, hw, efx->net_dev,
2333 "channel %d unknown event type %d"
2334 " (data " EFX_QWORD_FMT ")\n",
2335 channel->channel, ev_code,
2336 EFX_QWORD_VAL(event));
2337 }
2338 }
2339
2340out:
2341 channel->eventq_read_ptr = read_ptr;
2342 return spent;
2343}
2344
2345static void efx_ef10_ev_read_ack(struct efx_channel *channel)
2346{
2347 struct efx_nic *efx = channel->efx;
2348 efx_dword_t rptr;
2349
2350 if (EFX_EF10_WORKAROUND_35388(efx)) {
2351 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
2352 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
2353 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
2354 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
2355
2356 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2357 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
2358 ERF_DD_EVQ_IND_RPTR,
2359 (channel->eventq_read_ptr &
2360 channel->eventq_mask) >>
2361 ERF_DD_EVQ_IND_RPTR_WIDTH);
2362 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2363 channel->channel);
2364 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
2365 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
2366 ERF_DD_EVQ_IND_RPTR,
2367 channel->eventq_read_ptr &
2368 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
2369 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
2370 channel->channel);
2371 } else {
2372 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
2373 channel->eventq_read_ptr &
2374 channel->eventq_mask);
2375 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
2376 }
2377}
2378
2379static void efx_ef10_ev_test_generate(struct efx_channel *channel)
2380{
2381 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
2382 struct efx_nic *efx = channel->efx;
2383 efx_qword_t event;
2384 int rc;
2385
2386 EFX_POPULATE_QWORD_2(event,
2387 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
2388 ESF_DZ_EV_DATA, EFX_EF10_TEST);
2389
2390 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
2391
2392 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
2393 * already swapped the data to little-endian order.
2394 */
2395 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
2396 sizeof(efx_qword_t));
2397
2398 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
2399 NULL, 0, NULL);
2400 if (rc != 0)
2401 goto fail;
2402
2403 return;
2404
2405fail:
2406 WARN_ON(true);
2407 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
2408}
2409
2410void efx_ef10_handle_drain_event(struct efx_nic *efx)
2411{
2412 if (atomic_dec_and_test(&efx->active_queues))
2413 wake_up(&efx->flush_wq);
2414
2415 WARN_ON(atomic_read(&efx->active_queues) < 0);
2416}
2417
2418static int efx_ef10_fini_dmaq(struct efx_nic *efx)
2419{
2420 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2421 struct efx_channel *channel;
2422 struct efx_tx_queue *tx_queue;
2423 struct efx_rx_queue *rx_queue;
2424 int pending;
2425
2426 /* If the MC has just rebooted, the TX/RX queues will have already been
2427 * torn down, but efx->active_queues needs to be set to zero.
2428 */
2429 if (nic_data->must_realloc_vis) {
2430 atomic_set(&efx->active_queues, 0);
2431 return 0;
2432 }
2433
2434 /* Do not attempt to write to the NIC during EEH recovery */
2435 if (efx->state != STATE_RECOVERY) {
2436 efx_for_each_channel(channel, efx) {
2437 efx_for_each_channel_rx_queue(rx_queue, channel)
2438 efx_ef10_rx_fini(rx_queue);
2439 efx_for_each_channel_tx_queue(tx_queue, channel)
2440 efx_ef10_tx_fini(tx_queue);
2441 }
2442
2443 wait_event_timeout(efx->flush_wq,
2444 atomic_read(&efx->active_queues) == 0,
2445 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
2446 pending = atomic_read(&efx->active_queues);
2447 if (pending) {
2448 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
2449 pending);
2450 return -ETIMEDOUT;
2451 }
2452 }
2453
2454 return 0;
2455}
2456
Edward Creee2835462014-04-16 19:27:48 +01002457static void efx_ef10_prepare_flr(struct efx_nic *efx)
2458{
2459 atomic_set(&efx->active_queues, 0);
2460}
2461
Ben Hutchings8127d662013-08-29 19:19:29 +01002462static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
2463 const struct efx_filter_spec *right)
2464{
2465 if ((left->match_flags ^ right->match_flags) |
2466 ((left->flags ^ right->flags) &
2467 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
2468 return false;
2469
2470 return memcmp(&left->outer_vid, &right->outer_vid,
2471 sizeof(struct efx_filter_spec) -
2472 offsetof(struct efx_filter_spec, outer_vid)) == 0;
2473}
2474
2475static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
2476{
2477 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
2478 return jhash2((const u32 *)&spec->outer_vid,
2479 (sizeof(struct efx_filter_spec) -
2480 offsetof(struct efx_filter_spec, outer_vid)) / 4,
2481 0);
2482 /* XXX should we randomise the initval? */
2483}
2484
2485/* Decide whether a filter should be exclusive or else should allow
2486 * delivery to additional recipients. Currently we decide that
2487 * filters for specific local unicast MAC and IP addresses are
2488 * exclusive.
2489 */
2490static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
2491{
2492 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
2493 !is_multicast_ether_addr(spec->loc_mac))
2494 return true;
2495
2496 if ((spec->match_flags &
2497 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
2498 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
2499 if (spec->ether_type == htons(ETH_P_IP) &&
2500 !ipv4_is_multicast(spec->loc_host[0]))
2501 return true;
2502 if (spec->ether_type == htons(ETH_P_IPV6) &&
2503 ((const u8 *)spec->loc_host)[0] != 0xff)
2504 return true;
2505 }
2506
2507 return false;
2508}
2509
2510static struct efx_filter_spec *
2511efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
2512 unsigned int filter_idx)
2513{
2514 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
2515 ~EFX_EF10_FILTER_FLAGS);
2516}
2517
2518static unsigned int
2519efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
2520 unsigned int filter_idx)
2521{
2522 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
2523}
2524
2525static void
2526efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
2527 unsigned int filter_idx,
2528 const struct efx_filter_spec *spec,
2529 unsigned int flags)
2530{
2531 table->entry[filter_idx].spec = (unsigned long)spec | flags;
2532}
2533
2534static void efx_ef10_filter_push_prep(struct efx_nic *efx,
2535 const struct efx_filter_spec *spec,
2536 efx_dword_t *inbuf, u64 handle,
2537 bool replacing)
2538{
2539 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2540
2541 memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN);
2542
2543 if (replacing) {
2544 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2545 MC_CMD_FILTER_OP_IN_OP_REPLACE);
2546 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
2547 } else {
2548 u32 match_fields = 0;
2549
2550 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2551 efx_ef10_filter_is_exclusive(spec) ?
2552 MC_CMD_FILTER_OP_IN_OP_INSERT :
2553 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
2554
2555 /* Convert match flags and values. Unlike almost
2556 * everything else in MCDI, these fields are in
2557 * network byte order.
2558 */
2559 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
2560 match_fields |=
2561 is_multicast_ether_addr(spec->loc_mac) ?
2562 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN :
2563 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
2564#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
2565 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
2566 match_fields |= \
2567 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
2568 mcdi_field ## _LBN; \
2569 BUILD_BUG_ON( \
2570 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
2571 sizeof(spec->gen_field)); \
2572 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
2573 &spec->gen_field, sizeof(spec->gen_field)); \
2574 }
2575 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
2576 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
2577 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
2578 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
2579 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
2580 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
2581 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
2582 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
2583 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
2584 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
2585#undef COPY_FIELD
2586 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
2587 match_fields);
2588 }
2589
Daniel Pieczko45b24492015-05-06 00:57:14 +01002590 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002591 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
2592 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2593 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
2594 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01002595 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002596 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
2597 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00002598 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
2599 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
2600 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002601 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
2602 (spec->flags & EFX_FILTER_FLAG_RX_RSS) ?
2603 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
2604 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
2605 if (spec->flags & EFX_FILTER_FLAG_RX_RSS)
2606 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
2607 spec->rss_context !=
2608 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
2609 spec->rss_context : nic_data->rx_rss_context);
2610}
2611
2612static int efx_ef10_filter_push(struct efx_nic *efx,
2613 const struct efx_filter_spec *spec,
2614 u64 *handle, bool replacing)
2615{
2616 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2617 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN);
2618 int rc;
2619
2620 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
2621 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
2622 outbuf, sizeof(outbuf), NULL);
2623 if (rc == 0)
2624 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01002625 if (rc == -ENOSPC)
2626 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01002627 return rc;
2628}
2629
2630static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table,
2631 enum efx_filter_match_flags match_flags)
2632{
2633 unsigned int match_pri;
2634
2635 for (match_pri = 0;
2636 match_pri < table->rx_match_count;
2637 match_pri++)
2638 if (table->rx_match_flags[match_pri] == match_flags)
2639 return match_pri;
2640
2641 return -EPROTONOSUPPORT;
2642}
2643
2644static s32 efx_ef10_filter_insert(struct efx_nic *efx,
2645 struct efx_filter_spec *spec,
2646 bool replace_equal)
2647{
2648 struct efx_ef10_filter_table *table = efx->filter_state;
2649 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2650 struct efx_filter_spec *saved_spec;
2651 unsigned int match_pri, hash;
2652 unsigned int priv_flags;
2653 bool replacing = false;
2654 int ins_index = -1;
2655 DEFINE_WAIT(wait);
2656 bool is_mc_recip;
2657 s32 rc;
2658
2659 /* For now, only support RX filters */
2660 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
2661 EFX_FILTER_FLAG_RX)
2662 return -EINVAL;
2663
2664 rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags);
2665 if (rc < 0)
2666 return rc;
2667 match_pri = rc;
2668
2669 hash = efx_ef10_filter_hash(spec);
2670 is_mc_recip = efx_filter_is_mc_recipient(spec);
2671 if (is_mc_recip)
2672 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
2673
2674 /* Find any existing filters with the same match tuple or
2675 * else a free slot to insert at. If any of them are busy,
2676 * we have to wait and retry.
2677 */
2678 for (;;) {
2679 unsigned int depth = 1;
2680 unsigned int i;
2681
2682 spin_lock_bh(&efx->filter_lock);
2683
2684 for (;;) {
2685 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2686 saved_spec = efx_ef10_filter_entry_spec(table, i);
2687
2688 if (!saved_spec) {
2689 if (ins_index < 0)
2690 ins_index = i;
2691 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
2692 if (table->entry[i].spec &
2693 EFX_EF10_FILTER_FLAG_BUSY)
2694 break;
2695 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002696 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002697 rc = -EPERM;
2698 goto out_unlock;
2699 }
2700 if (!is_mc_recip) {
2701 /* This is the only one */
2702 if (spec->priority ==
2703 saved_spec->priority &&
2704 !replace_equal) {
2705 rc = -EEXIST;
2706 goto out_unlock;
2707 }
2708 ins_index = i;
2709 goto found;
2710 } else if (spec->priority >
2711 saved_spec->priority ||
2712 (spec->priority ==
2713 saved_spec->priority &&
2714 replace_equal)) {
2715 if (ins_index < 0)
2716 ins_index = i;
2717 else
2718 __set_bit(depth, mc_rem_map);
2719 }
2720 }
2721
2722 /* Once we reach the maximum search depth, use
2723 * the first suitable slot or return -EBUSY if
2724 * there was none
2725 */
2726 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
2727 if (ins_index < 0) {
2728 rc = -EBUSY;
2729 goto out_unlock;
2730 }
2731 goto found;
2732 }
2733
2734 ++depth;
2735 }
2736
2737 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2738 spin_unlock_bh(&efx->filter_lock);
2739 schedule();
2740 }
2741
2742found:
2743 /* Create a software table entry if necessary, and mark it
2744 * busy. We might yet fail to insert, but any attempt to
2745 * insert a conflicting filter while we're waiting for the
2746 * firmware must find the busy entry.
2747 */
2748 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
2749 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002750 if (spec->priority == EFX_FILTER_PRI_AUTO &&
2751 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002752 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002753 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
2754 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002755 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002756 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01002757 rc = ins_index;
2758 goto out_unlock;
2759 }
2760 replacing = true;
2761 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
2762 } else {
2763 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
2764 if (!saved_spec) {
2765 rc = -ENOMEM;
2766 goto out_unlock;
2767 }
2768 *saved_spec = *spec;
2769 priv_flags = 0;
2770 }
2771 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
2772 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
2773
2774 /* Mark lower-priority multicast recipients busy prior to removal */
2775 if (is_mc_recip) {
2776 unsigned int depth, i;
2777
2778 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2779 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2780 if (test_bit(depth, mc_rem_map))
2781 table->entry[i].spec |=
2782 EFX_EF10_FILTER_FLAG_BUSY;
2783 }
2784 }
2785
2786 spin_unlock_bh(&efx->filter_lock);
2787
2788 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
2789 replacing);
2790
2791 /* Finalise the software table entry */
2792 spin_lock_bh(&efx->filter_lock);
2793 if (rc == 0) {
2794 if (replacing) {
2795 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002796 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
2797 saved_spec->flags |=
2798 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002799 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002800 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002801 saved_spec->flags |= spec->flags;
2802 saved_spec->rss_context = spec->rss_context;
2803 saved_spec->dmaq_id = spec->dmaq_id;
2804 }
2805 } else if (!replacing) {
2806 kfree(saved_spec);
2807 saved_spec = NULL;
2808 }
2809 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
2810
2811 /* Remove and finalise entries for lower-priority multicast
2812 * recipients
2813 */
2814 if (is_mc_recip) {
2815 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
2816 unsigned int depth, i;
2817
2818 memset(inbuf, 0, sizeof(inbuf));
2819
2820 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
2821 if (!test_bit(depth, mc_rem_map))
2822 continue;
2823
2824 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
2825 saved_spec = efx_ef10_filter_entry_spec(table, i);
2826 priv_flags = efx_ef10_filter_entry_flags(table, i);
2827
2828 if (rc == 0) {
2829 spin_unlock_bh(&efx->filter_lock);
2830 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2831 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2832 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2833 table->entry[i].handle);
2834 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2835 inbuf, sizeof(inbuf),
2836 NULL, 0, NULL);
2837 spin_lock_bh(&efx->filter_lock);
2838 }
2839
2840 if (rc == 0) {
2841 kfree(saved_spec);
2842 saved_spec = NULL;
2843 priv_flags = 0;
2844 } else {
2845 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
2846 }
2847 efx_ef10_filter_set_entry(table, i, saved_spec,
2848 priv_flags);
2849 }
2850 }
2851
2852 /* If successful, return the inserted filter ID */
2853 if (rc == 0)
2854 rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index;
2855
2856 wake_up_all(&table->waitq);
2857out_unlock:
2858 spin_unlock_bh(&efx->filter_lock);
2859 finish_wait(&table->waitq, &wait);
2860 return rc;
2861}
2862
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08002863static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002864{
2865 /* no need to do anything here on EF10 */
2866}
2867
2868/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002869 * If !by_index, remove by ID
2870 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01002871 * Filter ID may come from userland and must be range-checked.
2872 */
2873static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002874 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002875 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01002876{
2877 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2878 struct efx_ef10_filter_table *table = efx->filter_state;
2879 MCDI_DECLARE_BUF(inbuf,
2880 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
2881 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
2882 struct efx_filter_spec *spec;
2883 DEFINE_WAIT(wait);
2884 int rc;
2885
2886 /* Find the software table entry and mark it busy. Don't
2887 * remove it yet; any attempt to update while we're waiting
2888 * for the firmware must find the busy entry.
2889 */
2890 for (;;) {
2891 spin_lock_bh(&efx->filter_lock);
2892 if (!(table->entry[filter_idx].spec &
2893 EFX_EF10_FILTER_FLAG_BUSY))
2894 break;
2895 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
2896 spin_unlock_bh(&efx->filter_lock);
2897 schedule();
2898 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002899
Ben Hutchings8127d662013-08-29 19:19:29 +01002900 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002901 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002902 (!by_index &&
Ben Hutchings8127d662013-08-29 19:19:29 +01002903 efx_ef10_filter_rx_match_pri(table, spec->match_flags) !=
2904 filter_id / HUNT_FILTER_TBL_ROWS)) {
2905 rc = -ENOENT;
2906 goto out_unlock;
2907 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002908
2909 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002910 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002911 /* Just remove flags */
2912 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002913 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002914 rc = 0;
2915 goto out_unlock;
2916 }
2917
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002918 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002919 rc = -ENOENT;
2920 goto out_unlock;
2921 }
2922
Ben Hutchings8127d662013-08-29 19:19:29 +01002923 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
2924 spin_unlock_bh(&efx->filter_lock);
2925
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002926 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00002927 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01002928
2929 struct efx_filter_spec new_spec = *spec;
2930
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002931 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01002932 new_spec.flags = (EFX_FILTER_FLAG_RX |
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002933 EFX_FILTER_FLAG_RX_RSS);
Ben Hutchings8127d662013-08-29 19:19:29 +01002934 new_spec.dmaq_id = 0;
2935 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
2936 rc = efx_ef10_filter_push(efx, &new_spec,
2937 &table->entry[filter_idx].handle,
2938 true);
2939
2940 spin_lock_bh(&efx->filter_lock);
2941 if (rc == 0)
2942 *spec = new_spec;
2943 } else {
2944 /* Really remove the filter */
2945
2946 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
2947 efx_ef10_filter_is_exclusive(spec) ?
2948 MC_CMD_FILTER_OP_IN_OP_REMOVE :
2949 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
2950 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
2951 table->entry[filter_idx].handle);
2952 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
2953 inbuf, sizeof(inbuf), NULL, 0, NULL);
2954
2955 spin_lock_bh(&efx->filter_lock);
2956 if (rc == 0) {
2957 kfree(spec);
2958 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
2959 }
2960 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00002961
Ben Hutchings8127d662013-08-29 19:19:29 +01002962 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
2963 wake_up_all(&table->waitq);
2964out_unlock:
2965 spin_unlock_bh(&efx->filter_lock);
2966 finish_wait(&table->waitq, &wait);
2967 return rc;
2968}
2969
2970static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
2971 enum efx_filter_priority priority,
2972 u32 filter_id)
2973{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00002974 return efx_ef10_filter_remove_internal(efx, 1U << priority,
2975 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01002976}
2977
2978static int efx_ef10_filter_get_safe(struct efx_nic *efx,
2979 enum efx_filter_priority priority,
2980 u32 filter_id, struct efx_filter_spec *spec)
2981{
2982 unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS;
2983 struct efx_ef10_filter_table *table = efx->filter_state;
2984 const struct efx_filter_spec *saved_spec;
2985 int rc;
2986
2987 spin_lock_bh(&efx->filter_lock);
2988 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
2989 if (saved_spec && saved_spec->priority == priority &&
2990 efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) ==
2991 filter_id / HUNT_FILTER_TBL_ROWS) {
2992 *spec = *saved_spec;
2993 rc = 0;
2994 } else {
2995 rc = -ENOENT;
2996 }
2997 spin_unlock_bh(&efx->filter_lock);
2998 return rc;
2999}
3000
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003001static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01003002 enum efx_filter_priority priority)
3003{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003004 unsigned int priority_mask;
3005 unsigned int i;
3006 int rc;
3007
3008 priority_mask = (((1U << (priority + 1)) - 1) &
3009 ~(1U << EFX_FILTER_PRI_AUTO));
3010
3011 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3012 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
3013 i, true);
3014 if (rc && rc != -ENOENT)
3015 return rc;
3016 }
3017
3018 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003019}
3020
3021static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
3022 enum efx_filter_priority priority)
3023{
3024 struct efx_ef10_filter_table *table = efx->filter_state;
3025 unsigned int filter_idx;
3026 s32 count = 0;
3027
3028 spin_lock_bh(&efx->filter_lock);
3029 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3030 if (table->entry[filter_idx].spec &&
3031 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
3032 priority)
3033 ++count;
3034 }
3035 spin_unlock_bh(&efx->filter_lock);
3036 return count;
3037}
3038
3039static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
3040{
3041 struct efx_ef10_filter_table *table = efx->filter_state;
3042
3043 return table->rx_match_count * HUNT_FILTER_TBL_ROWS;
3044}
3045
3046static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
3047 enum efx_filter_priority priority,
3048 u32 *buf, u32 size)
3049{
3050 struct efx_ef10_filter_table *table = efx->filter_state;
3051 struct efx_filter_spec *spec;
3052 unsigned int filter_idx;
3053 s32 count = 0;
3054
3055 spin_lock_bh(&efx->filter_lock);
3056 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3057 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3058 if (spec && spec->priority == priority) {
3059 if (count == size) {
3060 count = -EMSGSIZE;
3061 break;
3062 }
3063 buf[count++] = (efx_ef10_filter_rx_match_pri(
3064 table, spec->match_flags) *
3065 HUNT_FILTER_TBL_ROWS +
3066 filter_idx);
3067 }
3068 }
3069 spin_unlock_bh(&efx->filter_lock);
3070 return count;
3071}
3072
3073#ifdef CONFIG_RFS_ACCEL
3074
3075static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
3076
3077static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
3078 struct efx_filter_spec *spec)
3079{
3080 struct efx_ef10_filter_table *table = efx->filter_state;
3081 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3082 struct efx_filter_spec *saved_spec;
3083 unsigned int hash, i, depth = 1;
3084 bool replacing = false;
3085 int ins_index = -1;
3086 u64 cookie;
3087 s32 rc;
3088
3089 /* Must be an RX filter without RSS and not for a multicast
3090 * destination address (RFS only works for connected sockets).
3091 * These restrictions allow us to pass only a tiny amount of
3092 * data through to the completion function.
3093 */
3094 EFX_WARN_ON_PARANOID(spec->flags !=
3095 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
3096 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
3097 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
3098
3099 hash = efx_ef10_filter_hash(spec);
3100
3101 spin_lock_bh(&efx->filter_lock);
3102
3103 /* Find any existing filter with the same match tuple or else
3104 * a free slot to insert at. If an existing filter is busy,
3105 * we have to give up.
3106 */
3107 for (;;) {
3108 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
3109 saved_spec = efx_ef10_filter_entry_spec(table, i);
3110
3111 if (!saved_spec) {
3112 if (ins_index < 0)
3113 ins_index = i;
3114 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
3115 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
3116 rc = -EBUSY;
3117 goto fail_unlock;
3118 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003119 if (spec->priority < saved_spec->priority) {
3120 rc = -EPERM;
3121 goto fail_unlock;
3122 }
3123 ins_index = i;
3124 break;
3125 }
3126
3127 /* Once we reach the maximum search depth, use the
3128 * first suitable slot or return -EBUSY if there was
3129 * none
3130 */
3131 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
3132 if (ins_index < 0) {
3133 rc = -EBUSY;
3134 goto fail_unlock;
3135 }
3136 break;
3137 }
3138
3139 ++depth;
3140 }
3141
3142 /* Create a software table entry if necessary, and mark it
3143 * busy. We might yet fail to insert, but any attempt to
3144 * insert a conflicting filter while we're waiting for the
3145 * firmware must find the busy entry.
3146 */
3147 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
3148 if (saved_spec) {
3149 replacing = true;
3150 } else {
3151 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
3152 if (!saved_spec) {
3153 rc = -ENOMEM;
3154 goto fail_unlock;
3155 }
3156 *saved_spec = *spec;
3157 }
3158 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
3159 EFX_EF10_FILTER_FLAG_BUSY);
3160
3161 spin_unlock_bh(&efx->filter_lock);
3162
3163 /* Pack up the variables needed on completion */
3164 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
3165
3166 efx_ef10_filter_push_prep(efx, spec, inbuf,
3167 table->entry[ins_index].handle, replacing);
3168 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3169 MC_CMD_FILTER_OP_OUT_LEN,
3170 efx_ef10_filter_rfs_insert_complete, cookie);
3171
3172 return ins_index;
3173
3174fail_unlock:
3175 spin_unlock_bh(&efx->filter_lock);
3176 return rc;
3177}
3178
3179static void
3180efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
3181 int rc, efx_dword_t *outbuf,
3182 size_t outlen_actual)
3183{
3184 struct efx_ef10_filter_table *table = efx->filter_state;
3185 unsigned int ins_index, dmaq_id;
3186 struct efx_filter_spec *spec;
3187 bool replacing;
3188
3189 /* Unpack the cookie */
3190 replacing = cookie >> 31;
3191 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
3192 dmaq_id = cookie & 0xffff;
3193
3194 spin_lock_bh(&efx->filter_lock);
3195 spec = efx_ef10_filter_entry_spec(table, ins_index);
3196 if (rc == 0) {
3197 table->entry[ins_index].handle =
3198 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
3199 if (replacing)
3200 spec->dmaq_id = dmaq_id;
3201 } else if (!replacing) {
3202 kfree(spec);
3203 spec = NULL;
3204 }
3205 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
3206 spin_unlock_bh(&efx->filter_lock);
3207
3208 wake_up_all(&table->waitq);
3209}
3210
3211static void
3212efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3213 unsigned long filter_idx,
3214 int rc, efx_dword_t *outbuf,
3215 size_t outlen_actual);
3216
3217static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
3218 unsigned int filter_idx)
3219{
3220 struct efx_ef10_filter_table *table = efx->filter_state;
3221 struct efx_filter_spec *spec =
3222 efx_ef10_filter_entry_spec(table, filter_idx);
3223 MCDI_DECLARE_BUF(inbuf,
3224 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
3225 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
3226
3227 if (!spec ||
3228 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
3229 spec->priority != EFX_FILTER_PRI_HINT ||
3230 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
3231 flow_id, filter_idx))
3232 return false;
3233
3234 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3235 MC_CMD_FILTER_OP_IN_OP_REMOVE);
3236 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3237 table->entry[filter_idx].handle);
3238 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
3239 efx_ef10_filter_rfs_expire_complete, filter_idx))
3240 return false;
3241
3242 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3243 return true;
3244}
3245
3246static void
3247efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
3248 unsigned long filter_idx,
3249 int rc, efx_dword_t *outbuf,
3250 size_t outlen_actual)
3251{
3252 struct efx_ef10_filter_table *table = efx->filter_state;
3253 struct efx_filter_spec *spec =
3254 efx_ef10_filter_entry_spec(table, filter_idx);
3255
3256 spin_lock_bh(&efx->filter_lock);
3257 if (rc == 0) {
3258 kfree(spec);
3259 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3260 }
3261 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
3262 wake_up_all(&table->waitq);
3263 spin_unlock_bh(&efx->filter_lock);
3264}
3265
3266#endif /* CONFIG_RFS_ACCEL */
3267
3268static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags)
3269{
3270 int match_flags = 0;
3271
3272#define MAP_FLAG(gen_flag, mcdi_field) { \
3273 u32 old_mcdi_flags = mcdi_flags; \
3274 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
3275 mcdi_field ## _LBN); \
3276 if (mcdi_flags != old_mcdi_flags) \
3277 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
3278 }
3279 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
3280 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
3281 MAP_FLAG(REM_HOST, SRC_IP);
3282 MAP_FLAG(LOC_HOST, DST_IP);
3283 MAP_FLAG(REM_MAC, SRC_MAC);
3284 MAP_FLAG(REM_PORT, SRC_PORT);
3285 MAP_FLAG(LOC_MAC, DST_MAC);
3286 MAP_FLAG(LOC_PORT, DST_PORT);
3287 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
3288 MAP_FLAG(INNER_VID, INNER_VLAN);
3289 MAP_FLAG(OUTER_VID, OUTER_VLAN);
3290 MAP_FLAG(IP_PROTO, IP_PROTO);
3291#undef MAP_FLAG
3292
3293 /* Did we map them all? */
3294 if (mcdi_flags)
3295 return -EINVAL;
3296
3297 return match_flags;
3298}
3299
3300static int efx_ef10_filter_table_probe(struct efx_nic *efx)
3301{
3302 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
3303 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
3304 unsigned int pd_match_pri, pd_match_count;
3305 struct efx_ef10_filter_table *table;
3306 size_t outlen;
3307 int rc;
3308
3309 table = kzalloc(sizeof(*table), GFP_KERNEL);
3310 if (!table)
3311 return -ENOMEM;
3312
3313 /* Find out which RX filter types are supported, and their priorities */
3314 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
3315 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
3316 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
3317 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
3318 &outlen);
3319 if (rc)
3320 goto fail;
3321 pd_match_count = MCDI_VAR_ARRAY_LEN(
3322 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
3323 table->rx_match_count = 0;
3324
3325 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
3326 u32 mcdi_flags =
3327 MCDI_ARRAY_DWORD(
3328 outbuf,
3329 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
3330 pd_match_pri);
3331 rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags);
3332 if (rc < 0) {
3333 netif_dbg(efx, probe, efx->net_dev,
3334 "%s: fw flags %#x pri %u not supported in driver\n",
3335 __func__, mcdi_flags, pd_match_pri);
3336 } else {
3337 netif_dbg(efx, probe, efx->net_dev,
3338 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
3339 __func__, mcdi_flags, pd_match_pri,
3340 rc, table->rx_match_count);
3341 table->rx_match_flags[table->rx_match_count++] = rc;
3342 }
3343 }
3344
3345 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
3346 if (!table->entry) {
3347 rc = -ENOMEM;
3348 goto fail;
3349 }
3350
3351 efx->filter_state = table;
3352 init_waitqueue_head(&table->waitq);
3353 return 0;
3354
3355fail:
3356 kfree(table);
3357 return rc;
3358}
3359
Edward Cree0d322412015-05-20 11:10:03 +01003360/* Caller must hold efx->filter_sem for read if race against
3361 * efx_ef10_filter_table_remove() is possible
3362 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003363static void efx_ef10_filter_table_restore(struct efx_nic *efx)
3364{
3365 struct efx_ef10_filter_table *table = efx->filter_state;
3366 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3367 struct efx_filter_spec *spec;
3368 unsigned int filter_idx;
3369 bool failed = false;
3370 int rc;
3371
Edward Cree0d322412015-05-20 11:10:03 +01003372 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
3373
Ben Hutchings8127d662013-08-29 19:19:29 +01003374 if (!nic_data->must_restore_filters)
3375 return;
3376
Edward Cree0d322412015-05-20 11:10:03 +01003377 if (!table)
3378 return;
3379
Ben Hutchings8127d662013-08-29 19:19:29 +01003380 spin_lock_bh(&efx->filter_lock);
3381
3382 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3383 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3384 if (!spec)
3385 continue;
3386
3387 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
3388 spin_unlock_bh(&efx->filter_lock);
3389
3390 rc = efx_ef10_filter_push(efx, spec,
3391 &table->entry[filter_idx].handle,
3392 false);
3393 if (rc)
3394 failed = true;
3395
3396 spin_lock_bh(&efx->filter_lock);
3397 if (rc) {
3398 kfree(spec);
3399 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
3400 } else {
3401 table->entry[filter_idx].spec &=
3402 ~EFX_EF10_FILTER_FLAG_BUSY;
3403 }
3404 }
3405
3406 spin_unlock_bh(&efx->filter_lock);
3407
3408 if (failed)
3409 netif_err(efx, hw, efx->net_dev,
3410 "unable to restore all filters\n");
3411 else
3412 nic_data->must_restore_filters = false;
3413}
3414
Edward Cree0d322412015-05-20 11:10:03 +01003415/* Caller must hold efx->filter_sem for write */
Ben Hutchings8127d662013-08-29 19:19:29 +01003416static void efx_ef10_filter_table_remove(struct efx_nic *efx)
3417{
3418 struct efx_ef10_filter_table *table = efx->filter_state;
3419 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN);
3420 struct efx_filter_spec *spec;
3421 unsigned int filter_idx;
3422 int rc;
3423
Edward Cree0d322412015-05-20 11:10:03 +01003424 efx->filter_state = NULL;
3425 if (!table)
3426 return;
3427
Ben Hutchings8127d662013-08-29 19:19:29 +01003428 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
3429 spec = efx_ef10_filter_entry_spec(table, filter_idx);
3430 if (!spec)
3431 continue;
3432
3433 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3434 efx_ef10_filter_is_exclusive(spec) ?
3435 MC_CMD_FILTER_OP_IN_OP_REMOVE :
3436 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
3437 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
3438 table->entry[filter_idx].handle);
3439 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
3440 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003441 if (rc)
3442 netdev_WARN(efx->net_dev,
3443 "filter_idx=%#x handle=%#llx\n",
3444 filter_idx,
3445 table->entry[filter_idx].handle);
Ben Hutchings8127d662013-08-29 19:19:29 +01003446 kfree(spec);
3447 }
3448
3449 vfree(table->entry);
3450 kfree(table);
3451}
3452
Edward Cree0d322412015-05-20 11:10:03 +01003453/* Caller must hold efx->filter_sem for read if race against
3454 * efx_ef10_filter_table_remove() is possible
3455 */
Ben Hutchings8127d662013-08-29 19:19:29 +01003456static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
3457{
3458 struct efx_ef10_filter_table *table = efx->filter_state;
3459 struct net_device *net_dev = efx->net_dev;
3460 struct efx_filter_spec spec;
3461 bool remove_failed = false;
3462 struct netdev_hw_addr *uc;
3463 struct netdev_hw_addr *mc;
3464 unsigned int filter_idx;
3465 int i, n, rc;
3466
3467 if (!efx_dev_registered(efx))
3468 return;
3469
Edward Cree0d322412015-05-20 11:10:03 +01003470 if (!table)
3471 return;
3472
Ben Hutchings8127d662013-08-29 19:19:29 +01003473 /* Mark old filters that may need to be removed */
3474 spin_lock_bh(&efx->filter_lock);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003475 n = table->dev_uc_count < 0 ? 1 : table->dev_uc_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_uc_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 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003480 n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01003481 for (i = 0; i < n; i++) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003482 filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS;
3483 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01003484 }
3485 spin_unlock_bh(&efx->filter_lock);
3486
3487 /* Copy/convert the address lists; add the primary station
3488 * address and broadcast address
3489 */
3490 netif_addr_lock_bh(net_dev);
3491 if (net_dev->flags & IFF_PROMISC ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003492 netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) {
3493 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003494 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003495 table->dev_uc_count = 1 + netdev_uc_count(net_dev);
Edward Creecd84ff42014-03-07 18:27:41 +00003496 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003497 i = 1;
3498 netdev_for_each_uc_addr(uc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003499 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003500 i++;
3501 }
3502 }
3503 if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003504 netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) {
3505 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003506 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003507 table->dev_mc_count = 1 + netdev_mc_count(net_dev);
3508 eth_broadcast_addr(table->dev_mc_list[0].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003509 i = 1;
3510 netdev_for_each_mc_addr(mc, net_dev) {
Edward Creecd84ff42014-03-07 18:27:41 +00003511 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003512 i++;
3513 }
3514 }
3515 netif_addr_unlock_bh(net_dev);
3516
3517 /* Insert/renew unicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003518 if (table->dev_uc_count >= 0) {
3519 for (i = 0; i < table->dev_uc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003520 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3521 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003522 0);
3523 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003524 table->dev_uc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003525 rc = efx_ef10_filter_insert(efx, &spec, true);
3526 if (rc < 0) {
3527 /* Fall back to unicast-promisc */
3528 while (i--)
3529 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003530 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003531 table->dev_uc_list[i].id);
3532 table->dev_uc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003533 break;
3534 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003535 table->dev_uc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003536 }
3537 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003538 if (table->dev_uc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003539 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3540 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003541 0);
3542 efx_filter_set_uc_def(&spec);
3543 rc = efx_ef10_filter_insert(efx, &spec, true);
3544 if (rc < 0) {
3545 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003546 table->dev_uc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003547 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003548 table->dev_uc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003549 }
3550 }
3551
3552 /* Insert/renew multicast filters */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003553 if (table->dev_mc_count >= 0) {
3554 for (i = 0; i < table->dev_mc_count; i++) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003555 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3556 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003557 0);
3558 efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003559 table->dev_mc_list[i].addr);
Ben Hutchings8127d662013-08-29 19:19:29 +01003560 rc = efx_ef10_filter_insert(efx, &spec, true);
3561 if (rc < 0) {
3562 /* Fall back to multicast-promisc */
3563 while (i--)
3564 efx_ef10_filter_remove_safe(
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003565 efx, EFX_FILTER_PRI_AUTO,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003566 table->dev_mc_list[i].id);
3567 table->dev_mc_count = -1;
Ben Hutchings8127d662013-08-29 19:19:29 +01003568 break;
3569 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003570 table->dev_mc_list[i].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003571 }
3572 }
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003573 if (table->dev_mc_count < 0) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003574 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
3575 EFX_FILTER_FLAG_RX_RSS,
Ben Hutchings8127d662013-08-29 19:19:29 +01003576 0);
3577 efx_filter_set_mc_def(&spec);
3578 rc = efx_ef10_filter_insert(efx, &spec, true);
3579 if (rc < 0) {
3580 WARN_ON(1);
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003581 table->dev_mc_count = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003582 } else {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003583 table->dev_mc_list[0].id = rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003584 }
3585 }
3586
3587 /* Remove filters that weren't renewed. Since nothing else
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003588 * changes the AUTO_OLD flag or removes these filters, we
Ben Hutchings8127d662013-08-29 19:19:29 +01003589 * don't need to hold the filter_lock while scanning for
3590 * these filters.
3591 */
3592 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
3593 if (ACCESS_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00003594 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00003595 if (efx_ef10_filter_remove_internal(
Ben Hutchingsfbd79122013-11-21 19:15:03 +00003596 efx, 1U << EFX_FILTER_PRI_AUTO,
3597 i, true) < 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01003598 remove_failed = true;
3599 }
3600 }
3601 WARN_ON(remove_failed);
3602}
3603
Shradha Shah910c8782015-05-20 11:12:48 +01003604static int efx_ef10_set_mac_address(struct efx_nic *efx)
3605{
3606 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
3607 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3608 bool was_enabled = efx->port_enabled;
3609 int rc;
3610
3611 efx_device_detach_sync(efx);
3612 efx_net_stop(efx->net_dev);
3613 down_write(&efx->filter_sem);
3614 efx_ef10_filter_table_remove(efx);
3615
3616 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
3617 efx->net_dev->dev_addr);
3618 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
3619 nic_data->vport_id);
3620 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
3621 sizeof(inbuf), NULL, 0, NULL);
3622
3623 efx_ef10_filter_table_probe(efx);
3624 up_write(&efx->filter_sem);
3625 if (was_enabled)
3626 efx_net_open(efx->net_dev);
3627 netif_device_attach(efx->net_dev);
3628
3629#if !defined(CONFIG_SFC_SRIOV)
3630 if (rc == -EPERM)
3631 netif_err(efx, drv, efx->net_dev,
3632 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3633 " on this interface\n");
3634#else
3635 if (rc == -EPERM) {
3636 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3637
3638 /* Switch to PF and change MAC address on vport */
3639 if (efx->pci_dev->is_virtfn && pci_dev_pf) {
3640 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3641
3642 if (!efx_ef10_sriov_set_vf_mac(efx_pf,
3643 nic_data->vf_index,
3644 efx->net_dev->dev_addr))
3645 return 0;
3646 }
3647 netif_err(efx, drv, efx->net_dev,
3648 "Cannot change MAC address; use sfboot to enable mac-spoofing"
3649 " on this interface\n");
3650 } else if (efx->pci_dev->is_virtfn) {
3651 /* Successfully changed by VF (with MAC spoofing), so update the
3652 * parent PF if possible.
3653 */
3654 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
3655
3656 if (pci_dev_pf) {
3657 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
3658 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
3659 unsigned int i;
3660
3661 for (i = 0; i < efx_pf->vf_count; ++i) {
3662 struct ef10_vf *vf = nic_data->vf + i;
3663
3664 if (vf->efx == efx) {
3665 ether_addr_copy(vf->mac,
3666 efx->net_dev->dev_addr);
3667 return 0;
3668 }
3669 }
3670 }
3671 }
3672#endif
3673 return rc;
3674}
3675
Ben Hutchings8127d662013-08-29 19:19:29 +01003676static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
3677{
3678 efx_ef10_filter_sync_rx_mode(efx);
3679
3680 return efx_mcdi_set_mac(efx);
3681}
3682
Shradha Shah862f8942015-05-20 11:08:56 +01003683static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
3684{
3685 efx_ef10_filter_sync_rx_mode(efx);
3686
3687 return 0;
3688}
3689
Jon Cooper74cd60a2013-09-16 14:18:51 +01003690static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
3691{
3692 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
3693
3694 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
3695 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
3696 NULL, 0, NULL);
3697}
3698
3699/* MC BISTs follow a different poll mechanism to phy BISTs.
3700 * The BIST is done in the poll handler on the MC, and the MCDI command
3701 * will block until the BIST is done.
3702 */
3703static int efx_ef10_poll_bist(struct efx_nic *efx)
3704{
3705 int rc;
3706 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
3707 size_t outlen;
3708 u32 result;
3709
3710 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
3711 outbuf, sizeof(outbuf), &outlen);
3712 if (rc != 0)
3713 return rc;
3714
3715 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
3716 return -EIO;
3717
3718 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
3719 switch (result) {
3720 case MC_CMD_POLL_BIST_PASSED:
3721 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
3722 return 0;
3723 case MC_CMD_POLL_BIST_TIMEOUT:
3724 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
3725 return -EIO;
3726 case MC_CMD_POLL_BIST_FAILED:
3727 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
3728 return -EIO;
3729 default:
3730 netif_err(efx, hw, efx->net_dev,
3731 "BIST returned unknown result %u", result);
3732 return -EIO;
3733 }
3734}
3735
3736static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
3737{
3738 int rc;
3739
3740 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
3741
3742 rc = efx_ef10_start_bist(efx, bist_type);
3743 if (rc != 0)
3744 return rc;
3745
3746 return efx_ef10_poll_bist(efx);
3747}
3748
3749static int
3750efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
3751{
3752 int rc, rc2;
3753
3754 efx_reset_down(efx, RESET_TYPE_WORLD);
3755
3756 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
3757 NULL, 0, NULL, 0, NULL);
3758 if (rc != 0)
3759 goto out;
3760
3761 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
3762 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
3763
3764 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
3765
3766out:
3767 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
3768 return rc ? rc : rc2;
3769}
3770
Ben Hutchings8127d662013-08-29 19:19:29 +01003771#ifdef CONFIG_SFC_MTD
3772
3773struct efx_ef10_nvram_type_info {
3774 u16 type, type_mask;
3775 u8 port;
3776 const char *name;
3777};
3778
3779static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
3780 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
3781 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
3782 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
3783 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
3784 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
3785 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
3786 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
3787 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
3788 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01003789 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01003790 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
3791};
3792
3793static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
3794 struct efx_mcdi_mtd_partition *part,
3795 unsigned int type)
3796{
3797 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
3798 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
3799 const struct efx_ef10_nvram_type_info *info;
3800 size_t size, erase_size, outlen;
3801 bool protected;
3802 int rc;
3803
3804 for (info = efx_ef10_nvram_types; ; info++) {
3805 if (info ==
3806 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
3807 return -ENODEV;
3808 if ((type & ~info->type_mask) == info->type)
3809 break;
3810 }
3811 if (info->port != efx_port_num(efx))
3812 return -ENODEV;
3813
3814 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
3815 if (rc)
3816 return rc;
3817 if (protected)
3818 return -ENODEV; /* hide it */
3819
3820 part->nvram_type = type;
3821
3822 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
3823 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
3824 outbuf, sizeof(outbuf), &outlen);
3825 if (rc)
3826 return rc;
3827 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
3828 return -EIO;
3829 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
3830 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
3831 part->fw_subtype = MCDI_DWORD(outbuf,
3832 NVRAM_METADATA_OUT_SUBTYPE);
3833
3834 part->common.dev_type_name = "EF10 NVRAM manager";
3835 part->common.type_name = info->name;
3836
3837 part->common.mtd.type = MTD_NORFLASH;
3838 part->common.mtd.flags = MTD_CAP_NORFLASH;
3839 part->common.mtd.size = size;
3840 part->common.mtd.erasesize = erase_size;
3841
3842 return 0;
3843}
3844
3845static int efx_ef10_mtd_probe(struct efx_nic *efx)
3846{
3847 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
3848 struct efx_mcdi_mtd_partition *parts;
3849 size_t outlen, n_parts_total, i, n_parts;
3850 unsigned int type;
3851 int rc;
3852
3853 ASSERT_RTNL();
3854
3855 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
3856 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
3857 outbuf, sizeof(outbuf), &outlen);
3858 if (rc)
3859 return rc;
3860 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
3861 return -EIO;
3862
3863 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
3864 if (n_parts_total >
3865 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
3866 return -EIO;
3867
3868 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
3869 if (!parts)
3870 return -ENOMEM;
3871
3872 n_parts = 0;
3873 for (i = 0; i < n_parts_total; i++) {
3874 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
3875 i);
3876 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
3877 if (rc == 0)
3878 n_parts++;
3879 else if (rc != -ENODEV)
3880 goto fail;
3881 }
3882
3883 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
3884fail:
3885 if (rc)
3886 kfree(parts);
3887 return rc;
3888}
3889
3890#endif /* CONFIG_SFC_MTD */
3891
3892static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
3893{
3894 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
3895}
3896
Shradha Shah02246a72015-05-06 00:58:14 +01003897static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
3898 u32 host_time) {}
3899
Jon Cooperbd9a2652013-11-18 12:54:41 +00003900static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
3901 bool temp)
3902{
3903 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
3904 int rc;
3905
3906 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
3907 channel->sync_events_state == SYNC_EVENTS_VALID ||
3908 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
3909 return 0;
3910 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
3911
3912 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
3913 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3914 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
3915 channel->channel);
3916
3917 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3918 inbuf, sizeof(inbuf), NULL, 0, NULL);
3919
3920 if (rc != 0)
3921 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3922 SYNC_EVENTS_DISABLED;
3923
3924 return rc;
3925}
3926
3927static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
3928 bool temp)
3929{
3930 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
3931 int rc;
3932
3933 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
3934 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
3935 return 0;
3936 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
3937 channel->sync_events_state = SYNC_EVENTS_DISABLED;
3938 return 0;
3939 }
3940 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
3941 SYNC_EVENTS_DISABLED;
3942
3943 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
3944 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
3945 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
3946 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
3947 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
3948 channel->channel);
3949
3950 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
3951 inbuf, sizeof(inbuf), NULL, 0, NULL);
3952
3953 return rc;
3954}
3955
3956static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
3957 bool temp)
3958{
3959 int (*set)(struct efx_channel *channel, bool temp);
3960 struct efx_channel *channel;
3961
3962 set = en ?
3963 efx_ef10_rx_enable_timestamping :
3964 efx_ef10_rx_disable_timestamping;
3965
3966 efx_for_each_channel(channel, efx) {
3967 int rc = set(channel, temp);
3968 if (en && rc != 0) {
3969 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
3970 return rc;
3971 }
3972 }
3973
3974 return 0;
3975}
3976
Shradha Shah02246a72015-05-06 00:58:14 +01003977static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
3978 struct hwtstamp_config *init)
3979{
3980 return -EOPNOTSUPP;
3981}
3982
Jon Cooperbd9a2652013-11-18 12:54:41 +00003983static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
3984 struct hwtstamp_config *init)
3985{
3986 int rc;
3987
3988 switch (init->rx_filter) {
3989 case HWTSTAMP_FILTER_NONE:
3990 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
3991 /* if TX timestamping is still requested then leave PTP on */
3992 return efx_ptp_change_mode(efx,
3993 init->tx_type != HWTSTAMP_TX_OFF, 0);
3994 case HWTSTAMP_FILTER_ALL:
3995 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3996 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3997 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3998 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3999 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
4000 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
4001 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
4002 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
4003 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
4004 case HWTSTAMP_FILTER_PTP_V2_EVENT:
4005 case HWTSTAMP_FILTER_PTP_V2_SYNC:
4006 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
4007 init->rx_filter = HWTSTAMP_FILTER_ALL;
4008 rc = efx_ptp_change_mode(efx, true, 0);
4009 if (!rc)
4010 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
4011 if (rc)
4012 efx_ptp_change_mode(efx, false, 0);
4013 return rc;
4014 default:
4015 return -ERANGE;
4016 }
4017}
4018
Shradha Shah02246a72015-05-06 00:58:14 +01004019const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004020 .is_vf = true,
Shradha Shah02246a72015-05-06 00:58:14 +01004021 .mem_bar = EFX_MEM_VF_BAR,
Ben Hutchings8127d662013-08-29 19:19:29 +01004022 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01004023 .probe = efx_ef10_probe_vf,
4024 .remove = efx_ef10_remove,
4025 .dimension_resources = efx_ef10_dimension_resources,
4026 .init = efx_ef10_init_nic,
4027 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004028 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01004029 .map_reset_flags = efx_ef10_map_reset_flags,
4030 .reset = efx_ef10_reset,
4031 .probe_port = efx_mcdi_port_probe,
4032 .remove_port = efx_mcdi_port_remove,
4033 .fini_dmaq = efx_ef10_fini_dmaq,
4034 .prepare_flr = efx_ef10_prepare_flr,
4035 .finish_flr = efx_port_dummy_op_void,
4036 .describe_stats = efx_ef10_describe_stats,
4037 .update_stats = efx_ef10_update_stats,
4038 .start_stats = efx_port_dummy_op_void,
4039 .pull_stats = efx_port_dummy_op_void,
4040 .stop_stats = efx_port_dummy_op_void,
4041 .set_id_led = efx_mcdi_set_id_led,
4042 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01004043 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004044 .check_mac_fault = efx_mcdi_mac_check_fault,
4045 .reconfigure_port = efx_mcdi_port_reconfigure,
4046 .get_wol = efx_ef10_get_wol_vf,
4047 .set_wol = efx_ef10_set_wol_vf,
4048 .resume_wol = efx_port_dummy_op_void,
4049 .mcdi_request = efx_ef10_mcdi_request,
4050 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4051 .mcdi_read_response = efx_ef10_mcdi_read_response,
4052 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4053 .irq_enable_master = efx_port_dummy_op_void,
4054 .irq_test_generate = efx_ef10_irq_test_generate,
4055 .irq_disable_non_ev = efx_port_dummy_op_void,
4056 .irq_handle_msi = efx_ef10_msi_interrupt,
4057 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4058 .tx_probe = efx_ef10_tx_probe,
4059 .tx_init = efx_ef10_tx_init,
4060 .tx_remove = efx_ef10_tx_remove,
4061 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004062 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01004063 .rx_probe = efx_ef10_rx_probe,
4064 .rx_init = efx_ef10_rx_init,
4065 .rx_remove = efx_ef10_rx_remove,
4066 .rx_write = efx_ef10_rx_write,
4067 .rx_defer_refill = efx_ef10_rx_defer_refill,
4068 .ev_probe = efx_ef10_ev_probe,
4069 .ev_init = efx_ef10_ev_init,
4070 .ev_fini = efx_ef10_ev_fini,
4071 .ev_remove = efx_ef10_ev_remove,
4072 .ev_process = efx_ef10_ev_process,
4073 .ev_read_ack = efx_ef10_ev_read_ack,
4074 .ev_test_generate = efx_ef10_ev_test_generate,
4075 .filter_table_probe = efx_ef10_filter_table_probe,
4076 .filter_table_restore = efx_ef10_filter_table_restore,
4077 .filter_table_remove = efx_ef10_filter_table_remove,
4078 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4079 .filter_insert = efx_ef10_filter_insert,
4080 .filter_remove_safe = efx_ef10_filter_remove_safe,
4081 .filter_get_safe = efx_ef10_filter_get_safe,
4082 .filter_clear_rx = efx_ef10_filter_clear_rx,
4083 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4084 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4085 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4086#ifdef CONFIG_RFS_ACCEL
4087 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4088 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4089#endif
4090#ifdef CONFIG_SFC_MTD
4091 .mtd_probe = efx_port_dummy_op_int,
4092#endif
4093 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
4094 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
4095#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004096 .vswitching_probe = efx_ef10_vswitching_probe_vf,
4097 .vswitching_restore = efx_ef10_vswitching_restore_vf,
4098 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01004099#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004100 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01004101 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004102
Shradha Shah02246a72015-05-06 00:58:14 +01004103 .revision = EFX_REV_HUNT_A0,
4104 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4105 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4106 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
4107 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
4108 .can_rx_scatter = true,
4109 .always_rx_scatter = true,
4110 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4111 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4112 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4113 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4114 .mcdi_max_ver = 2,
4115 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
4116 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4117 1 << HWTSTAMP_FILTER_ALL,
4118};
4119
4120const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01004121 .is_vf = false,
Shradha Shah02246a72015-05-06 00:58:14 +01004122 .mem_bar = EFX_MEM_BAR,
4123 .mem_map_size = efx_ef10_mem_map_size,
4124 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01004125 .remove = efx_ef10_remove,
4126 .dimension_resources = efx_ef10_dimension_resources,
4127 .init = efx_ef10_init_nic,
4128 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01004129 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01004130 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00004131 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01004132 .probe_port = efx_mcdi_port_probe,
4133 .remove_port = efx_mcdi_port_remove,
4134 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01004135 .prepare_flr = efx_ef10_prepare_flr,
4136 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01004137 .describe_stats = efx_ef10_describe_stats,
4138 .update_stats = efx_ef10_update_stats,
4139 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01004140 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01004141 .stop_stats = efx_mcdi_mac_stop_stats,
4142 .set_id_led = efx_mcdi_set_id_led,
4143 .push_irq_moderation = efx_ef10_push_irq_moderation,
4144 .reconfigure_mac = efx_ef10_mac_reconfigure,
4145 .check_mac_fault = efx_mcdi_mac_check_fault,
4146 .reconfigure_port = efx_mcdi_port_reconfigure,
4147 .get_wol = efx_ef10_get_wol,
4148 .set_wol = efx_ef10_set_wol,
4149 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01004150 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01004151 .test_nvram = efx_mcdi_nvram_test_all,
4152 .mcdi_request = efx_ef10_mcdi_request,
4153 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
4154 .mcdi_read_response = efx_ef10_mcdi_read_response,
4155 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
4156 .irq_enable_master = efx_port_dummy_op_void,
4157 .irq_test_generate = efx_ef10_irq_test_generate,
4158 .irq_disable_non_ev = efx_port_dummy_op_void,
4159 .irq_handle_msi = efx_ef10_msi_interrupt,
4160 .irq_handle_legacy = efx_ef10_legacy_interrupt,
4161 .tx_probe = efx_ef10_tx_probe,
4162 .tx_init = efx_ef10_tx_init,
4163 .tx_remove = efx_ef10_tx_remove,
4164 .tx_write = efx_ef10_tx_write,
Jon Cooper267c0152015-05-06 00:59:38 +01004165 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01004166 .rx_probe = efx_ef10_rx_probe,
4167 .rx_init = efx_ef10_rx_init,
4168 .rx_remove = efx_ef10_rx_remove,
4169 .rx_write = efx_ef10_rx_write,
4170 .rx_defer_refill = efx_ef10_rx_defer_refill,
4171 .ev_probe = efx_ef10_ev_probe,
4172 .ev_init = efx_ef10_ev_init,
4173 .ev_fini = efx_ef10_ev_fini,
4174 .ev_remove = efx_ef10_ev_remove,
4175 .ev_process = efx_ef10_ev_process,
4176 .ev_read_ack = efx_ef10_ev_read_ack,
4177 .ev_test_generate = efx_ef10_ev_test_generate,
4178 .filter_table_probe = efx_ef10_filter_table_probe,
4179 .filter_table_restore = efx_ef10_filter_table_restore,
4180 .filter_table_remove = efx_ef10_filter_table_remove,
4181 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
4182 .filter_insert = efx_ef10_filter_insert,
4183 .filter_remove_safe = efx_ef10_filter_remove_safe,
4184 .filter_get_safe = efx_ef10_filter_get_safe,
4185 .filter_clear_rx = efx_ef10_filter_clear_rx,
4186 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
4187 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
4188 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
4189#ifdef CONFIG_RFS_ACCEL
4190 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
4191 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
4192#endif
4193#ifdef CONFIG_SFC_MTD
4194 .mtd_probe = efx_ef10_mtd_probe,
4195 .mtd_rename = efx_mcdi_mtd_rename,
4196 .mtd_read = efx_mcdi_mtd_read,
4197 .mtd_erase = efx_mcdi_mtd_erase,
4198 .mtd_write = efx_mcdi_mtd_write,
4199 .mtd_sync = efx_mcdi_mtd_sync,
4200#endif
4201 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004202 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
4203 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004204#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01004205 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004206 .sriov_init = efx_ef10_sriov_init,
4207 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00004208 .sriov_wanted = efx_ef10_sriov_wanted,
4209 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004210 .sriov_flr = efx_ef10_sriov_flr,
4211 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
4212 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
4213 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
4214 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01004215 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01004216 .vswitching_probe = efx_ef10_vswitching_probe_pf,
4217 .vswitching_restore = efx_ef10_vswitching_restore_pf,
4218 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01004219#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01004220 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01004221 .set_mac_address = efx_ef10_set_mac_address,
Ben Hutchings8127d662013-08-29 19:19:29 +01004222
4223 .revision = EFX_REV_HUNT_A0,
4224 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
4225 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
4226 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004227 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01004228 .can_rx_scatter = true,
4229 .always_rx_scatter = true,
4230 .max_interrupt_mode = EFX_INT_MODE_MSIX,
4231 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
4232 .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4233 NETIF_F_RXHASH | NETIF_F_NTUPLE),
4234 .mcdi_max_ver = 2,
4235 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00004236 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
4237 1 << HWTSTAMP_FILTER_ALL,
Ben Hutchings8127d662013-08-29 19:19:29 +01004238};