blob: 774e9cd14302cadd2d1777402d5caac7fdbd652a [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
Edward Cree12fb0da2015-07-21 15:11:00 +010052#define EFX_EF10_FILTER_ID_INVALID 0xffff
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010053
54#define EFX_EF10_FILTER_DEV_UC_MAX 32
55#define EFX_EF10_FILTER_DEV_MC_MAX 256
56
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010057/* VLAN list entry */
58struct efx_ef10_vlan {
59 struct list_head list;
60 u16 vid;
61};
62
Edward Cree9b410802017-01-27 15:02:52 +000063enum efx_ef10_default_filters {
64 EFX_EF10_BCAST,
65 EFX_EF10_UCDEF,
66 EFX_EF10_MCDEF,
67 EFX_EF10_VXLAN4_UCDEF,
68 EFX_EF10_VXLAN4_MCDEF,
69 EFX_EF10_VXLAN6_UCDEF,
70 EFX_EF10_VXLAN6_MCDEF,
71 EFX_EF10_NVGRE4_UCDEF,
72 EFX_EF10_NVGRE4_MCDEF,
73 EFX_EF10_NVGRE6_UCDEF,
74 EFX_EF10_NVGRE6_MCDEF,
75 EFX_EF10_GENEVE4_UCDEF,
76 EFX_EF10_GENEVE4_MCDEF,
77 EFX_EF10_GENEVE6_UCDEF,
78 EFX_EF10_GENEVE6_MCDEF,
79
80 EFX_EF10_NUM_DEFAULT_FILTERS
81};
82
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010083/* Per-VLAN filters information */
84struct efx_ef10_filter_vlan {
Andrew Rybchenko34813fe2016-06-15 17:48:14 +010085 struct list_head list;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +010086 u16 vid;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010087 u16 uc[EFX_EF10_FILTER_DEV_UC_MAX];
88 u16 mc[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree9b410802017-01-27 15:02:52 +000089 u16 default_filters[EFX_EF10_NUM_DEFAULT_FILTERS];
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +010090};
91
Daniel Pieczko822b96f2015-07-21 15:10:27 +010092struct efx_ef10_dev_addr {
93 u8 addr[ETH_ALEN];
Daniel Pieczko822b96f2015-07-21 15:10:27 +010094};
95
Ben Hutchings8127d662013-08-29 19:19:29 +010096struct efx_ef10_filter_table {
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +010097/* The MCDI match masks supported by this fw & hw, in order of priority */
98 u32 rx_match_mcdi_flags[
Edward Cree9b410802017-01-27 15:02:52 +000099 MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM * 2];
Ben Hutchings8127d662013-08-29 19:19:29 +0100100 unsigned int rx_match_count;
101
102 struct {
103 unsigned long spec; /* pointer to spec plus flag bits */
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000104/* BUSY flag indicates that an update is in progress. AUTO_OLD is
105 * used to mark and sweep MAC filters for the device address lists.
Ben Hutchings8127d662013-08-29 19:19:29 +0100106 */
107#define EFX_EF10_FILTER_FLAG_BUSY 1UL
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +0000108#define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL
Ben Hutchings8127d662013-08-29 19:19:29 +0100109#define EFX_EF10_FILTER_FLAGS 3UL
110 u64 handle; /* firmware handle */
111 } *entry;
112 wait_queue_head_t waitq;
113/* Shadow of net_device address lists, guarded by mac_lock */
Daniel Pieczko822b96f2015-07-21 15:10:27 +0100114 struct efx_ef10_dev_addr dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX];
115 struct efx_ef10_dev_addr dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX];
Edward Cree12fb0da2015-07-21 15:11:00 +0100116 int dev_uc_count;
117 int dev_mc_count;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +0100118 bool uc_promisc;
119 bool mc_promisc;
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +0100120/* Whether in multicast promiscuous mode when last changed */
121 bool mc_promisc_last;
Edward Cree148cbab2017-04-04 17:02:49 +0100122 bool mc_overflow; /* Too many MC addrs; should always imply mc_promisc */
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100123 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100124 struct list_head vlan_list;
Ben Hutchings8127d662013-08-29 19:19:29 +0100125};
126
127/* An arbitrary search limit for the software hash table */
128#define EFX_EF10_FILTER_SEARCH_LIMIT 200
129
Ben Hutchings8127d662013-08-29 19:19:29 +0100130static void efx_ef10_rx_free_indir_table(struct efx_nic *efx);
131static void efx_ef10_filter_table_remove(struct efx_nic *efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100132static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid);
133static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
134 struct efx_ef10_filter_vlan *vlan);
135static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid);
Jon Coopere5fbd972017-02-08 16:52:10 +0000136static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading);
Ben Hutchings8127d662013-08-29 19:19:29 +0100137
Jon Cooper0ccb9982017-02-17 15:49:13 +0000138static u32 efx_ef10_filter_get_unsafe_id(u32 filter_id)
139{
140 WARN_ON_ONCE(filter_id == EFX_EF10_FILTER_ID_INVALID);
141 return filter_id & (HUNT_FILTER_TBL_ROWS - 1);
142}
143
144static unsigned int efx_ef10_filter_get_unsafe_pri(u32 filter_id)
145{
146 return filter_id / (HUNT_FILTER_TBL_ROWS * 2);
147}
148
149static u32 efx_ef10_make_filter_id(unsigned int pri, u16 idx)
150{
151 return pri * HUNT_FILTER_TBL_ROWS * 2 + idx;
152}
153
Ben Hutchings8127d662013-08-29 19:19:29 +0100154static int efx_ef10_get_warm_boot_count(struct efx_nic *efx)
155{
156 efx_dword_t reg;
157
158 efx_readd(efx, &reg, ER_DZ_BIU_MC_SFT_STATUS);
159 return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
160 EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
161}
162
Edward Cree03714bb2017-12-18 16:55:50 +0000163/* On all EF10s up to and including SFC9220 (Medford1), all PFs use BAR 0 for
164 * I/O space and BAR 2(&3) for memory. On SFC9250 (Medford2), there is no I/O
165 * bar; PFs use BAR 0/1 for memory.
166 */
167static unsigned int efx_ef10_pf_mem_bar(struct efx_nic *efx)
168{
169 switch (efx->pci_dev->device) {
170 case 0x0b03: /* SFC9250 PF */
171 return 0;
172 default:
173 return 2;
174 }
175}
176
177/* All VFs use BAR 0/1 for memory */
178static unsigned int efx_ef10_vf_mem_bar(struct efx_nic *efx)
179{
180 return 0;
181}
182
Ben Hutchings8127d662013-08-29 19:19:29 +0100183static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx)
184{
Shradha Shah02246a72015-05-06 00:58:14 +0100185 int bar;
186
Edward Cree03714bb2017-12-18 16:55:50 +0000187 bar = efx->type->mem_bar(efx);
Shradha Shah02246a72015-05-06 00:58:14 +0100188 return resource_size(&efx->pci_dev->resource[bar]);
Ben Hutchings8127d662013-08-29 19:19:29 +0100189}
190
Daniel Pieczko7a186f42015-07-07 11:37:19 +0100191static bool efx_ef10_is_vf(struct efx_nic *efx)
192{
193 return efx->type->is_vf;
194}
195
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100196static int efx_ef10_get_pf_index(struct efx_nic *efx)
197{
198 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
199 struct efx_ef10_nic_data *nic_data = efx->nic_data;
200 size_t outlen;
201 int rc;
202
203 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
204 sizeof(outbuf), &outlen);
205 if (rc)
206 return rc;
207 if (outlen < sizeof(outbuf))
208 return -EIO;
209
210 nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF);
211 return 0;
212}
213
Shradha Shah88a37de2015-05-20 11:09:15 +0100214#ifdef CONFIG_SFC_SRIOV
215static int efx_ef10_get_vf_index(struct efx_nic *efx)
216{
217 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN);
218 struct efx_ef10_nic_data *nic_data = efx->nic_data;
219 size_t outlen;
220 int rc;
221
222 rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf,
223 sizeof(outbuf), &outlen);
224 if (rc)
225 return rc;
226 if (outlen < sizeof(outbuf))
227 return -EIO;
228
229 nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF);
230 return 0;
231}
232#endif
233
Ben Hutchingse5a25382013-09-05 22:50:59 +0100234static int efx_ef10_init_datapath_caps(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +0100235{
Edward Creec1be4822017-12-21 09:00:26 +0000236 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V4_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +0100237 struct efx_ef10_nic_data *nic_data = efx->nic_data;
238 size_t outlen;
239 int rc;
240
241 BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
242
243 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
244 outbuf, sizeof(outbuf), &outlen);
245 if (rc)
246 return rc;
Bert Kenwardca889a02016-08-11 13:01:35 +0100247 if (outlen < MC_CMD_GET_CAPABILITIES_OUT_LEN) {
Ben Hutchingse5a25382013-09-05 22:50:59 +0100248 netif_err(efx, drv, efx->net_dev,
249 "unable to read datapath firmware capabilities\n");
250 return -EIO;
251 }
Ben Hutchings8127d662013-08-29 19:19:29 +0100252
Ben Hutchingse5a25382013-09-05 22:50:59 +0100253 nic_data->datapath_caps =
254 MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1);
255
Edward Creec6347002017-01-13 21:20:29 +0000256 if (outlen >= MC_CMD_GET_CAPABILITIES_V2_OUT_LEN) {
Bert Kenwardca889a02016-08-11 13:01:35 +0100257 nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
258 GET_CAPABILITIES_V2_OUT_FLAGS2);
Edward Creec6347002017-01-13 21:20:29 +0000259 nic_data->piobuf_size = MCDI_WORD(outbuf,
260 GET_CAPABILITIES_V2_OUT_SIZE_PIO_BUFF);
261 } else {
Bert Kenwardca889a02016-08-11 13:01:35 +0100262 nic_data->datapath_caps2 = 0;
Edward Creec6347002017-01-13 21:20:29 +0000263 nic_data->piobuf_size = ER_DZ_TX_PIOBUF_SIZE;
264 }
Bert Kenwardca889a02016-08-11 13:01:35 +0100265
Daniel Pieczko8d9f9dd2015-05-06 00:56:55 +0100266 /* record the DPCPU firmware IDs to determine VEB vswitching support.
267 */
268 nic_data->rx_dpcpu_fw_id =
269 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID);
270 nic_data->tx_dpcpu_fw_id =
271 MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID);
272
Ben Hutchingse5a25382013-09-05 22:50:59 +0100273 if (!(nic_data->datapath_caps &
Ben Hutchingse5a25382013-09-05 22:50:59 +0100274 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) {
275 netif_err(efx, probe, efx->net_dev,
276 "current firmware does not support an RX prefix\n");
277 return -ENODEV;
Ben Hutchings8127d662013-08-29 19:19:29 +0100278 }
279
Edward Cree71827442017-12-18 16:56:19 +0000280 if (outlen >= MC_CMD_GET_CAPABILITIES_V3_OUT_LEN) {
281 u8 vi_window_mode = MCDI_BYTE(outbuf,
282 GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
283
284 switch (vi_window_mode) {
285 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_8K:
286 efx->vi_stride = 8192;
287 break;
288 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_16K:
289 efx->vi_stride = 16384;
290 break;
291 case MC_CMD_GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE_64K:
292 efx->vi_stride = 65536;
293 break;
294 default:
295 netif_err(efx, probe, efx->net_dev,
296 "Unrecognised VI window mode %d\n",
297 vi_window_mode);
298 return -EIO;
299 }
300 netif_dbg(efx, probe, efx->net_dev, "vi_stride = %u\n",
301 efx->vi_stride);
302 } else {
303 /* keep default VI stride */
304 netif_dbg(efx, probe, efx->net_dev,
305 "firmware did not report VI window mode, assuming vi_stride = %u\n",
306 efx->vi_stride);
307 }
308
Edward Creec1be4822017-12-21 09:00:26 +0000309 if (outlen >= MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
310 efx->num_mac_stats = MCDI_WORD(outbuf,
311 GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
312 netif_dbg(efx, probe, efx->net_dev,
313 "firmware reports num_mac_stats = %u\n",
314 efx->num_mac_stats);
315 } else {
316 /* leave num_mac_stats as the default value, MC_CMD_MAC_NSTATS */
317 netif_dbg(efx, probe, efx->net_dev,
318 "firmware did not report num_mac_stats, assuming %u\n",
319 efx->num_mac_stats);
320 }
321
Ben Hutchings8127d662013-08-29 19:19:29 +0100322 return 0;
323}
324
325static int efx_ef10_get_sysclk_freq(struct efx_nic *efx)
326{
327 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN);
328 int rc;
329
330 rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0,
331 outbuf, sizeof(outbuf), NULL);
332 if (rc)
333 return rc;
334 rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ);
335 return rc > 0 ? rc : -ERANGE;
336}
337
Bert Kenwardd95e3292016-08-11 13:02:36 +0100338static int efx_ef10_get_timer_workarounds(struct efx_nic *efx)
339{
340 struct efx_ef10_nic_data *nic_data = efx->nic_data;
341 unsigned int implemented;
342 unsigned int enabled;
343 int rc;
344
345 nic_data->workaround_35388 = false;
346 nic_data->workaround_61265 = false;
347
348 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
349
350 if (rc == -ENOSYS) {
351 /* Firmware without GET_WORKAROUNDS - not a problem. */
352 rc = 0;
353 } else if (rc == 0) {
354 /* Bug61265 workaround is always enabled if implemented. */
355 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG61265)
356 nic_data->workaround_61265 = true;
357
358 if (enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
359 nic_data->workaround_35388 = true;
360 } else if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG35388) {
361 /* Workaround is implemented but not enabled.
362 * Try to enable it.
363 */
364 rc = efx_mcdi_set_workaround(efx,
365 MC_CMD_WORKAROUND_BUG35388,
366 true, NULL);
367 if (rc == 0)
368 nic_data->workaround_35388 = true;
369 /* If we failed to set the workaround just carry on. */
370 rc = 0;
371 }
372 }
373
374 netif_dbg(efx, probe, efx->net_dev,
375 "workaround for bug 35388 is %sabled\n",
376 nic_data->workaround_35388 ? "en" : "dis");
377 netif_dbg(efx, probe, efx->net_dev,
378 "workaround for bug 61265 is %sabled\n",
379 nic_data->workaround_61265 ? "en" : "dis");
380
381 return rc;
382}
383
384static void efx_ef10_process_timer_config(struct efx_nic *efx,
385 const efx_dword_t *data)
386{
387 unsigned int max_count;
388
389 if (EFX_EF10_WORKAROUND_61265(efx)) {
390 efx->timer_quantum_ns = MCDI_DWORD(data,
391 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_STEP_NS);
392 efx->timer_max_ns = MCDI_DWORD(data,
393 GET_EVQ_TMR_PROPERTIES_OUT_MCDI_TMR_MAX_NS);
394 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
395 efx->timer_quantum_ns = MCDI_DWORD(data,
396 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_NS_PER_COUNT);
397 max_count = MCDI_DWORD(data,
398 GET_EVQ_TMR_PROPERTIES_OUT_BUG35388_TMR_MAX_COUNT);
399 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
400 } else {
401 efx->timer_quantum_ns = MCDI_DWORD(data,
402 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_NS_PER_COUNT);
403 max_count = MCDI_DWORD(data,
404 GET_EVQ_TMR_PROPERTIES_OUT_TMR_REG_MAX_COUNT);
405 efx->timer_max_ns = max_count * efx->timer_quantum_ns;
406 }
407
408 netif_dbg(efx, probe, efx->net_dev,
409 "got timer properties from MC: quantum %u ns; max %u ns\n",
410 efx->timer_quantum_ns, efx->timer_max_ns);
411}
412
413static int efx_ef10_get_timer_config(struct efx_nic *efx)
414{
415 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN);
416 int rc;
417
418 rc = efx_ef10_get_timer_workarounds(efx);
419 if (rc)
420 return rc;
421
422 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES, NULL, 0,
423 outbuf, sizeof(outbuf), NULL);
424
425 if (rc == 0) {
426 efx_ef10_process_timer_config(efx, outbuf);
427 } else if (rc == -ENOSYS || rc == -EPERM) {
428 /* Not available - fall back to Huntington defaults. */
429 unsigned int quantum;
430
431 rc = efx_ef10_get_sysclk_freq(efx);
432 if (rc < 0)
433 return rc;
434
435 quantum = 1536000 / rc; /* 1536 cycles */
436 efx->timer_quantum_ns = quantum;
437 efx->timer_max_ns = efx->type->timer_period_max * quantum;
438 rc = 0;
439 } else {
440 efx_mcdi_display_error(efx, MC_CMD_GET_EVQ_TMR_PROPERTIES,
441 MC_CMD_GET_EVQ_TMR_PROPERTIES_OUT_LEN,
442 NULL, 0, rc);
443 }
444
445 return rc;
446}
447
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100448static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address)
Ben Hutchings8127d662013-08-29 19:19:29 +0100449{
450 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN);
451 size_t outlen;
452 int rc;
453
454 BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
455
456 rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0,
457 outbuf, sizeof(outbuf), &outlen);
458 if (rc)
459 return rc;
460 if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN)
461 return -EIO;
462
Edward Creecd84ff42014-03-07 18:27:41 +0000463 ether_addr_copy(mac_address,
464 MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE));
Ben Hutchings8127d662013-08-29 19:19:29 +0100465 return 0;
466}
467
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100468static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address)
469{
470 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN);
471 MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX);
472 size_t outlen;
473 int num_addrs, rc;
474
475 MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID,
476 EVB_PORT_ID_ASSIGNED);
477 rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf,
478 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
479
480 if (rc)
481 return rc;
482 if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN)
483 return -EIO;
484
485 num_addrs = MCDI_DWORD(outbuf,
486 VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT);
487
488 WARN_ON(num_addrs != 1);
489
490 ether_addr_copy(mac_address,
491 MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR));
492
493 return 0;
494}
495
Shradha Shah0f5c0842015-06-02 11:37:58 +0100496static ssize_t efx_ef10_show_link_control_flag(struct device *dev,
497 struct device_attribute *attr,
498 char *buf)
499{
500 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
501
502 return sprintf(buf, "%d\n",
503 ((efx->mcdi->fn_flags) &
504 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
505 ? 1 : 0);
506}
507
508static ssize_t efx_ef10_show_primary_flag(struct device *dev,
509 struct device_attribute *attr,
510 char *buf)
511{
512 struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
513
514 return sprintf(buf, "%d\n",
515 ((efx->mcdi->fn_flags) &
516 (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY))
517 ? 1 : 0);
518}
519
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100520static struct efx_ef10_vlan *efx_ef10_find_vlan(struct efx_nic *efx, u16 vid)
521{
522 struct efx_ef10_nic_data *nic_data = efx->nic_data;
523 struct efx_ef10_vlan *vlan;
524
525 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
526
527 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
528 if (vlan->vid == vid)
529 return vlan;
530 }
531
532 return NULL;
533}
534
535static int efx_ef10_add_vlan(struct efx_nic *efx, u16 vid)
536{
537 struct efx_ef10_nic_data *nic_data = efx->nic_data;
538 struct efx_ef10_vlan *vlan;
539 int rc;
540
541 mutex_lock(&nic_data->vlan_lock);
542
543 vlan = efx_ef10_find_vlan(efx, vid);
544 if (vlan) {
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100545 /* We add VID 0 on init. 8021q adds it on module init
546 * for all interfaces with VLAN filtring feature.
547 */
548 if (vid == 0)
549 goto done_unlock;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100550 netif_warn(efx, drv, efx->net_dev,
551 "VLAN %u already added\n", vid);
552 rc = -EALREADY;
553 goto fail_exist;
554 }
555
556 rc = -ENOMEM;
557 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
558 if (!vlan)
559 goto fail_alloc;
560
561 vlan->vid = vid;
562
563 list_add_tail(&vlan->list, &nic_data->vlan_list);
564
565 if (efx->filter_state) {
566 mutex_lock(&efx->mac_lock);
567 down_write(&efx->filter_sem);
568 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
569 up_write(&efx->filter_sem);
570 mutex_unlock(&efx->mac_lock);
571 if (rc)
572 goto fail_filter_add_vlan;
573 }
574
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100575done_unlock:
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100576 mutex_unlock(&nic_data->vlan_lock);
577 return 0;
578
579fail_filter_add_vlan:
580 list_del(&vlan->list);
581 kfree(vlan);
582fail_alloc:
583fail_exist:
584 mutex_unlock(&nic_data->vlan_lock);
585 return rc;
586}
587
588static void efx_ef10_del_vlan_internal(struct efx_nic *efx,
589 struct efx_ef10_vlan *vlan)
590{
591 struct efx_ef10_nic_data *nic_data = efx->nic_data;
592
593 WARN_ON(!mutex_is_locked(&nic_data->vlan_lock));
594
595 if (efx->filter_state) {
596 down_write(&efx->filter_sem);
597 efx_ef10_filter_del_vlan(efx, vlan->vid);
598 up_write(&efx->filter_sem);
599 }
600
601 list_del(&vlan->list);
602 kfree(vlan);
603}
604
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100605static int efx_ef10_del_vlan(struct efx_nic *efx, u16 vid)
606{
607 struct efx_ef10_nic_data *nic_data = efx->nic_data;
608 struct efx_ef10_vlan *vlan;
609 int rc = 0;
610
611 /* 8021q removes VID 0 on module unload for all interfaces
612 * with VLAN filtering feature. We need to keep it to receive
613 * untagged traffic.
614 */
615 if (vid == 0)
616 return 0;
617
618 mutex_lock(&nic_data->vlan_lock);
619
620 vlan = efx_ef10_find_vlan(efx, vid);
621 if (!vlan) {
622 netif_err(efx, drv, efx->net_dev,
623 "VLAN %u to be deleted not found\n", vid);
624 rc = -ENOENT;
625 } else {
626 efx_ef10_del_vlan_internal(efx, vlan);
627 }
628
629 mutex_unlock(&nic_data->vlan_lock);
630
631 return rc;
632}
633
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100634static void efx_ef10_cleanup_vlans(struct efx_nic *efx)
635{
636 struct efx_ef10_nic_data *nic_data = efx->nic_data;
637 struct efx_ef10_vlan *vlan, *next_vlan;
638
639 mutex_lock(&nic_data->vlan_lock);
640 list_for_each_entry_safe(vlan, next_vlan, &nic_data->vlan_list, list)
641 efx_ef10_del_vlan_internal(efx, vlan);
642 mutex_unlock(&nic_data->vlan_lock);
643}
644
Shradha Shah0f5c0842015-06-02 11:37:58 +0100645static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag,
646 NULL);
647static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL);
648
Ben Hutchings8127d662013-08-29 19:19:29 +0100649static int efx_ef10_probe(struct efx_nic *efx)
650{
651 struct efx_ef10_nic_data *nic_data;
652 int i, rc;
653
Ben Hutchings8127d662013-08-29 19:19:29 +0100654 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
655 if (!nic_data)
656 return -ENOMEM;
657 efx->nic_data = nic_data;
658
Edward Cree75aba2a2015-05-27 13:13:54 +0100659 /* we assume later that we can copy from this buffer in dwords */
660 BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
661
Ben Hutchings8127d662013-08-29 19:19:29 +0100662 rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf,
663 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL);
664 if (rc)
665 goto fail1;
666
667 /* Get the MC's warm boot count. In case it's rebooting right
668 * now, be prepared to retry.
669 */
670 i = 0;
671 for (;;) {
672 rc = efx_ef10_get_warm_boot_count(efx);
673 if (rc >= 0)
674 break;
675 if (++i == 5)
676 goto fail2;
677 ssleep(1);
678 }
679 nic_data->warm_boot_count = rc;
680
681 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
682
Daniel Pieczko45b24492015-05-06 00:57:14 +0100683 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
684
Ben Hutchings8127d662013-08-29 19:19:29 +0100685 /* In case we're recovering from a crash (kexec), we want to
686 * cancel any outstanding request by the previous user of this
687 * function. We send a special message using the least
688 * significant bits of the 'high' (doorbell) register.
689 */
690 _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD);
691
692 rc = efx_mcdi_init(efx);
693 if (rc)
694 goto fail2;
695
Jon Coopere5fbd972017-02-08 16:52:10 +0000696 mutex_init(&nic_data->udp_tunnels_lock);
697
Ben Hutchings8127d662013-08-29 19:19:29 +0100698 /* Reset (most) configuration for this function */
699 rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
700 if (rc)
701 goto fail3;
702
703 /* Enable event logging */
704 rc = efx_mcdi_log_ctrl(efx, true, false, 0);
705 if (rc)
706 goto fail3;
707
Shradha Shah0f5c0842015-06-02 11:37:58 +0100708 rc = device_create_file(&efx->pci_dev->dev,
709 &dev_attr_link_control_flag);
Daniel Pieczko1cd9ecb2015-05-06 00:57:53 +0100710 if (rc)
711 goto fail3;
712
Shradha Shah0f5c0842015-06-02 11:37:58 +0100713 rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
714 if (rc)
715 goto fail4;
716
717 rc = efx_ef10_get_pf_index(efx);
718 if (rc)
719 goto fail5;
720
Ben Hutchingse5a25382013-09-05 22:50:59 +0100721 rc = efx_ef10_init_datapath_caps(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100722 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100723 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100724
Edward Cree71827442017-12-18 16:56:19 +0000725 /* We can have one VI for each vi_stride-byte region.
726 * However, until we use TX option descriptors we need two TX queues
727 * per channel.
728 */
729 efx->max_channels = min_t(unsigned int,
730 EFX_MAX_CHANNELS,
731 efx_ef10_mem_map_size(efx) /
732 (efx->vi_stride * EFX_TXQ_TYPES));
733 efx->max_tx_channels = efx->max_channels;
734 if (WARN_ON(efx->max_channels == 0)) {
735 rc = -EIO;
736 goto fail5;
737 }
738
Ben Hutchings8127d662013-08-29 19:19:29 +0100739 efx->rx_packet_len_offset =
740 ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE;
741
Edward Cree69787292017-10-31 14:29:47 +0000742 if (nic_data->datapath_caps &
743 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_INCLUDE_FCS_LBN))
744 efx->net_dev->hw_features |= NETIF_F_RXFCS;
745
Ben Hutchings8127d662013-08-29 19:19:29 +0100746 rc = efx_mcdi_port_get_number(efx);
747 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100748 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100749 efx->port_num = rc;
750
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +0100751 rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr);
Ben Hutchings8127d662013-08-29 19:19:29 +0100752 if (rc)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100753 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100754
Bert Kenwardd95e3292016-08-11 13:02:36 +0100755 rc = efx_ef10_get_timer_config(efx);
Ben Hutchings8127d662013-08-29 19:19:29 +0100756 if (rc < 0)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100757 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100758
Ben Hutchings8127d662013-08-29 19:19:29 +0100759 rc = efx_mcdi_mon_probe(efx);
Edward Cree267d9d72015-05-06 00:59:18 +0100760 if (rc && rc != -EPERM)
Shradha Shah0f5c0842015-06-02 11:37:58 +0100761 goto fail5;
Ben Hutchings8127d662013-08-29 19:19:29 +0100762
Edward Creeacaef3c12017-12-18 16:56:58 +0000763 rc = efx_ptp_probe(efx, NULL);
764 /* Failure to probe PTP is not fatal.
765 * In the case of EPERM, efx_ptp_probe will print its own message (in
766 * efx_ptp_get_attributes()), so we don't need to.
767 */
768 if (rc && rc != -EPERM)
769 netif_warn(efx, drv, efx->net_dev,
770 "Failed to probe PTP, rc=%d\n", rc);
Ben Hutchings9aecda92013-12-05 21:28:42 +0000771
Shradha Shah1d051e02015-06-02 11:38:16 +0100772#ifdef CONFIG_SFC_SRIOV
773 if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) {
774 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
775 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
776
777 efx_pf->type->get_mac_address(efx_pf, nic_data->port_id);
778 } else
779#endif
780 ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr);
781
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100782 INIT_LIST_HEAD(&nic_data->vlan_list);
783 mutex_init(&nic_data->vlan_lock);
784
785 /* Add unspecified VID to support VLAN filtering being disabled */
786 rc = efx_ef10_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
787 if (rc)
788 goto fail_add_vid_unspec;
789
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100790 /* If VLAN filtering is enabled, we need VID 0 to get untagged
791 * traffic. It is added automatically if 8021q module is loaded,
792 * but we can't rely on it since module may be not loaded.
793 */
794 rc = efx_ef10_add_vlan(efx, 0);
795 if (rc)
796 goto fail_add_vid_0;
797
Ben Hutchings8127d662013-08-29 19:19:29 +0100798 return 0;
799
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +0100800fail_add_vid_0:
801 efx_ef10_cleanup_vlans(efx);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +0100802fail_add_vid_unspec:
803 mutex_destroy(&nic_data->vlan_lock);
804 efx_ptp_remove(efx);
805 efx_mcdi_mon_remove(efx);
Shradha Shah0f5c0842015-06-02 11:37:58 +0100806fail5:
807 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
808fail4:
809 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
Ben Hutchings8127d662013-08-29 19:19:29 +0100810fail3:
Jon Coopere5fbd972017-02-08 16:52:10 +0000811 efx_mcdi_detach(efx);
812
813 mutex_lock(&nic_data->udp_tunnels_lock);
814 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
815 (void)efx_ef10_set_udp_tnl_ports(efx, true);
816 mutex_unlock(&nic_data->udp_tunnels_lock);
817 mutex_destroy(&nic_data->udp_tunnels_lock);
818
Ben Hutchings8127d662013-08-29 19:19:29 +0100819 efx_mcdi_fini(efx);
820fail2:
821 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
822fail1:
823 kfree(nic_data);
824 efx->nic_data = NULL;
825 return rc;
826}
827
828static int efx_ef10_free_vis(struct efx_nic *efx)
829{
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100830 MCDI_DECLARE_BUF_ERR(outbuf);
Edward Cree1e0b8122013-05-31 18:36:12 +0100831 size_t outlen;
832 int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0,
833 outbuf, sizeof(outbuf), &outlen);
Ben Hutchings8127d662013-08-29 19:19:29 +0100834
835 /* -EALREADY means nothing to free, so ignore */
836 if (rc == -EALREADY)
837 rc = 0;
Edward Cree1e0b8122013-05-31 18:36:12 +0100838 if (rc)
839 efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen,
840 rc);
Ben Hutchings8127d662013-08-29 19:19:29 +0100841 return rc;
842}
843
Ben Hutchings183233b2013-06-28 21:47:12 +0100844#ifdef EFX_USE_PIO
845
846static void efx_ef10_free_piobufs(struct efx_nic *efx)
847{
848 struct efx_ef10_nic_data *nic_data = efx->nic_data;
849 MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN);
850 unsigned int i;
851 int rc;
852
853 BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0);
854
855 for (i = 0; i < nic_data->n_piobufs; i++) {
856 MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE,
857 nic_data->piobuf_handle[i]);
858 rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf),
859 NULL, 0, NULL);
860 WARN_ON(rc);
861 }
862
863 nic_data->n_piobufs = 0;
864}
865
866static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
867{
868 struct efx_ef10_nic_data *nic_data = efx->nic_data;
869 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN);
870 unsigned int i;
871 size_t outlen;
872 int rc = 0;
873
874 BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0);
875
876 for (i = 0; i < n; i++) {
Bert Kenward09a04202015-12-23 08:58:15 +0000877 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0,
878 outbuf, sizeof(outbuf), &outlen);
879 if (rc) {
880 /* Don't display the MC error if we didn't have space
881 * for a VF.
882 */
883 if (!(efx_ef10_is_vf(efx) && rc == -ENOSPC))
884 efx_mcdi_display_error(efx, MC_CMD_ALLOC_PIOBUF,
885 0, outbuf, outlen, rc);
Ben Hutchings183233b2013-06-28 21:47:12 +0100886 break;
Bert Kenward09a04202015-12-23 08:58:15 +0000887 }
Ben Hutchings183233b2013-06-28 21:47:12 +0100888 if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) {
889 rc = -EIO;
890 break;
891 }
892 nic_data->piobuf_handle[i] =
893 MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE);
894 netif_dbg(efx, probe, efx->net_dev,
895 "allocated PIO buffer %u handle %x\n", i,
896 nic_data->piobuf_handle[i]);
897 }
898
899 nic_data->n_piobufs = i;
900 if (rc)
901 efx_ef10_free_piobufs(efx);
902 return rc;
903}
904
905static int efx_ef10_link_piobufs(struct efx_nic *efx)
906{
907 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Creed0346b02017-03-03 15:22:09 +0000908 MCDI_DECLARE_BUF(inbuf, MC_CMD_LINK_PIOBUF_IN_LEN);
Ben Hutchings183233b2013-06-28 21:47:12 +0100909 struct efx_channel *channel;
910 struct efx_tx_queue *tx_queue;
911 unsigned int offset, index;
912 int rc;
913
914 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0);
915 BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0);
916
917 /* Link a buffer to each VI in the write-combining mapping */
918 for (index = 0; index < nic_data->n_piobufs; ++index) {
919 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE,
920 nic_data->piobuf_handle[index]);
921 MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE,
922 nic_data->pio_write_vi_base + index);
923 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
924 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
925 NULL, 0, NULL);
926 if (rc) {
927 netif_err(efx, drv, efx->net_dev,
928 "failed to link VI %u to PIO buffer %u (%d)\n",
929 nic_data->pio_write_vi_base + index, index,
930 rc);
931 goto fail;
932 }
933 netif_dbg(efx, probe, efx->net_dev,
934 "linked VI %u to PIO buffer %u\n",
935 nic_data->pio_write_vi_base + index, index);
936 }
937
938 /* Link a buffer to each TX queue */
939 efx_for_each_channel(channel, efx) {
940 efx_for_each_channel_tx_queue(tx_queue, channel) {
941 /* We assign the PIO buffers to queues in
942 * reverse order to allow for the following
943 * special case.
944 */
945 offset = ((efx->tx_channel_offset + efx->n_tx_channels -
946 tx_queue->channel->channel - 1) *
947 efx_piobuf_size);
Edward Creec6347002017-01-13 21:20:29 +0000948 index = offset / nic_data->piobuf_size;
949 offset = offset % nic_data->piobuf_size;
Ben Hutchings183233b2013-06-28 21:47:12 +0100950
951 /* When the host page size is 4K, the first
952 * host page in the WC mapping may be within
953 * the same VI page as the last TX queue. We
954 * can only link one buffer to each VI.
955 */
956 if (tx_queue->queue == nic_data->pio_write_vi_base) {
957 BUG_ON(index != 0);
958 rc = 0;
959 } else {
960 MCDI_SET_DWORD(inbuf,
961 LINK_PIOBUF_IN_PIOBUF_HANDLE,
962 nic_data->piobuf_handle[index]);
963 MCDI_SET_DWORD(inbuf,
964 LINK_PIOBUF_IN_TXQ_INSTANCE,
965 tx_queue->queue);
966 rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF,
967 inbuf, MC_CMD_LINK_PIOBUF_IN_LEN,
968 NULL, 0, NULL);
969 }
970
971 if (rc) {
972 /* This is non-fatal; the TX path just
973 * won't use PIO for this queue
974 */
975 netif_err(efx, drv, efx->net_dev,
976 "failed to link VI %u to PIO buffer %u (%d)\n",
977 tx_queue->queue, index, rc);
978 tx_queue->piobuf = NULL;
979 } else {
980 tx_queue->piobuf =
981 nic_data->pio_write_base +
Edward Cree71827442017-12-18 16:56:19 +0000982 index * efx->vi_stride + offset;
Ben Hutchings183233b2013-06-28 21:47:12 +0100983 tx_queue->piobuf_offset = offset;
984 netif_dbg(efx, probe, efx->net_dev,
985 "linked VI %u to PIO buffer %u offset %x addr %p\n",
986 tx_queue->queue, index,
987 tx_queue->piobuf_offset,
988 tx_queue->piobuf);
989 }
990 }
991 }
992
993 return 0;
994
995fail:
Edward Creed0346b02017-03-03 15:22:09 +0000996 /* inbuf was defined for MC_CMD_LINK_PIOBUF. We can use the same
997 * buffer for MC_CMD_UNLINK_PIOBUF because it's shorter.
998 */
999 BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_IN_LEN < MC_CMD_UNLINK_PIOBUF_IN_LEN);
Ben Hutchings183233b2013-06-28 21:47:12 +01001000 while (index--) {
1001 MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE,
1002 nic_data->pio_write_vi_base + index);
1003 efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF,
1004 inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN,
1005 NULL, 0, NULL);
1006 }
1007 return rc;
1008}
1009
Edward Creec0795bf2016-05-24 18:53:36 +01001010static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1011{
1012 struct efx_channel *channel;
1013 struct efx_tx_queue *tx_queue;
1014
1015 /* All our existing PIO buffers went away */
1016 efx_for_each_channel(channel, efx)
1017 efx_for_each_channel_tx_queue(tx_queue, channel)
1018 tx_queue->piobuf = NULL;
1019}
1020
Ben Hutchings183233b2013-06-28 21:47:12 +01001021#else /* !EFX_USE_PIO */
1022
1023static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n)
1024{
1025 return n == 0 ? 0 : -ENOBUFS;
1026}
1027
1028static int efx_ef10_link_piobufs(struct efx_nic *efx)
1029{
1030 return 0;
1031}
1032
1033static void efx_ef10_free_piobufs(struct efx_nic *efx)
1034{
1035}
1036
Edward Creec0795bf2016-05-24 18:53:36 +01001037static void efx_ef10_forget_old_piobufs(struct efx_nic *efx)
1038{
1039}
1040
Ben Hutchings183233b2013-06-28 21:47:12 +01001041#endif /* EFX_USE_PIO */
1042
Ben Hutchings8127d662013-08-29 19:19:29 +01001043static void efx_ef10_remove(struct efx_nic *efx)
1044{
1045 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1046 int rc;
1047
Shradha Shahf1122a32015-05-20 11:09:46 +01001048#ifdef CONFIG_SFC_SRIOV
1049 struct efx_ef10_nic_data *nic_data_pf;
1050 struct pci_dev *pci_dev_pf;
1051 struct efx_nic *efx_pf;
1052 struct ef10_vf *vf;
1053
1054 if (efx->pci_dev->is_virtfn) {
1055 pci_dev_pf = efx->pci_dev->physfn;
1056 if (pci_dev_pf) {
1057 efx_pf = pci_get_drvdata(pci_dev_pf);
1058 nic_data_pf = efx_pf->nic_data;
1059 vf = nic_data_pf->vf + nic_data->vf_index;
1060 vf->efx = NULL;
1061 } else
1062 netif_info(efx, drv, efx->net_dev,
1063 "Could not get the PF id from VF\n");
1064 }
1065#endif
1066
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01001067 efx_ef10_cleanup_vlans(efx);
1068 mutex_destroy(&nic_data->vlan_lock);
1069
Ben Hutchings9aecda92013-12-05 21:28:42 +00001070 efx_ptp_remove(efx);
1071
Ben Hutchings8127d662013-08-29 19:19:29 +01001072 efx_mcdi_mon_remove(efx);
1073
Ben Hutchings8127d662013-08-29 19:19:29 +01001074 efx_ef10_rx_free_indir_table(efx);
1075
Ben Hutchings183233b2013-06-28 21:47:12 +01001076 if (nic_data->wc_membase)
1077 iounmap(nic_data->wc_membase);
1078
Ben Hutchings8127d662013-08-29 19:19:29 +01001079 rc = efx_ef10_free_vis(efx);
1080 WARN_ON(rc != 0);
1081
Ben Hutchings183233b2013-06-28 21:47:12 +01001082 if (!nic_data->must_restore_piobufs)
1083 efx_ef10_free_piobufs(efx);
1084
Shradha Shah0f5c0842015-06-02 11:37:58 +01001085 device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag);
1086 device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag);
1087
Jon Coopere5fbd972017-02-08 16:52:10 +00001088 efx_mcdi_detach(efx);
1089
1090 memset(nic_data->udp_tunnels, 0, sizeof(nic_data->udp_tunnels));
1091 mutex_lock(&nic_data->udp_tunnels_lock);
1092 (void)efx_ef10_set_udp_tnl_ports(efx, true);
1093 mutex_unlock(&nic_data->udp_tunnels_lock);
1094
1095 mutex_destroy(&nic_data->udp_tunnels_lock);
1096
Ben Hutchings8127d662013-08-29 19:19:29 +01001097 efx_mcdi_fini(efx);
1098 efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
1099 kfree(nic_data);
1100}
1101
Shradha Shah88a37de2015-05-20 11:09:15 +01001102static int efx_ef10_probe_pf(struct efx_nic *efx)
1103{
1104 return efx_ef10_probe(efx);
1105}
1106
Andrew Rybchenko38d27f32016-06-15 17:52:08 +01001107int efx_ef10_vadaptor_query(struct efx_nic *efx, unsigned int port_id,
1108 u32 *port_flags, u32 *vadaptor_flags,
1109 unsigned int *vlan_tags)
1110{
1111 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1112 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_QUERY_IN_LEN);
1113 MCDI_DECLARE_BUF(outbuf, MC_CMD_VADAPTOR_QUERY_OUT_LEN);
1114 size_t outlen;
1115 int rc;
1116
1117 if (nic_data->datapath_caps &
1118 (1 << MC_CMD_GET_CAPABILITIES_OUT_VADAPTOR_QUERY_LBN)) {
1119 MCDI_SET_DWORD(inbuf, VADAPTOR_QUERY_IN_UPSTREAM_PORT_ID,
1120 port_id);
1121
1122 rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_QUERY, inbuf, sizeof(inbuf),
1123 outbuf, sizeof(outbuf), &outlen);
1124 if (rc)
1125 return rc;
1126
1127 if (outlen < sizeof(outbuf)) {
1128 rc = -EIO;
1129 return rc;
1130 }
1131 }
1132
1133 if (port_flags)
1134 *port_flags = MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_PORT_FLAGS);
1135 if (vadaptor_flags)
1136 *vadaptor_flags =
1137 MCDI_DWORD(outbuf, VADAPTOR_QUERY_OUT_VADAPTOR_FLAGS);
1138 if (vlan_tags)
1139 *vlan_tags =
1140 MCDI_DWORD(outbuf,
1141 VADAPTOR_QUERY_OUT_NUM_AVAILABLE_VLAN_TAGS);
1142
1143 return 0;
1144}
1145
Daniel Pieczko7a186f42015-07-07 11:37:19 +01001146int efx_ef10_vadaptor_alloc(struct efx_nic *efx, unsigned int port_id)
1147{
1148 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_ALLOC_IN_LEN);
1149
1150 MCDI_SET_DWORD(inbuf, VADAPTOR_ALLOC_IN_UPSTREAM_PORT_ID, port_id);
1151 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_ALLOC, inbuf, sizeof(inbuf),
1152 NULL, 0, NULL);
1153}
1154
1155int efx_ef10_vadaptor_free(struct efx_nic *efx, unsigned int port_id)
1156{
1157 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_FREE_IN_LEN);
1158
1159 MCDI_SET_DWORD(inbuf, VADAPTOR_FREE_IN_UPSTREAM_PORT_ID, port_id);
1160 return efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_FREE, inbuf, sizeof(inbuf),
1161 NULL, 0, NULL);
1162}
1163
1164int efx_ef10_vport_add_mac(struct efx_nic *efx,
1165 unsigned int port_id, u8 *mac)
1166{
1167 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_ADD_MAC_ADDRESS_IN_LEN);
1168
1169 MCDI_SET_DWORD(inbuf, VPORT_ADD_MAC_ADDRESS_IN_VPORT_ID, port_id);
1170 ether_addr_copy(MCDI_PTR(inbuf, VPORT_ADD_MAC_ADDRESS_IN_MACADDR), mac);
1171
1172 return efx_mcdi_rpc(efx, MC_CMD_VPORT_ADD_MAC_ADDRESS, inbuf,
1173 sizeof(inbuf), NULL, 0, NULL);
1174}
1175
1176int efx_ef10_vport_del_mac(struct efx_nic *efx,
1177 unsigned int port_id, u8 *mac)
1178{
1179 MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN);
1180
1181 MCDI_SET_DWORD(inbuf, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID, port_id);
1182 ether_addr_copy(MCDI_PTR(inbuf, VPORT_DEL_MAC_ADDRESS_IN_MACADDR), mac);
1183
1184 return efx_mcdi_rpc(efx, MC_CMD_VPORT_DEL_MAC_ADDRESS, inbuf,
1185 sizeof(inbuf), NULL, 0, NULL);
1186}
1187
Shradha Shah88a37de2015-05-20 11:09:15 +01001188#ifdef CONFIG_SFC_SRIOV
1189static int efx_ef10_probe_vf(struct efx_nic *efx)
1190{
1191 int rc;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001192 struct pci_dev *pci_dev_pf;
1193
1194 /* If the parent PF has no VF data structure, it doesn't know about this
1195 * VF so fail probe. The VF needs to be re-created. This can happen
1196 * if the PF driver is unloaded while the VF is assigned to a guest.
1197 */
1198 pci_dev_pf = efx->pci_dev->physfn;
1199 if (pci_dev_pf) {
1200 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
1201 struct efx_ef10_nic_data *nic_data_pf = efx_pf->nic_data;
1202
1203 if (!nic_data_pf->vf) {
1204 netif_info(efx, drv, efx->net_dev,
1205 "The VF cannot link to its parent PF; "
1206 "please destroy and re-create the VF\n");
1207 return -EBUSY;
1208 }
1209 }
Shradha Shah88a37de2015-05-20 11:09:15 +01001210
1211 rc = efx_ef10_probe(efx);
1212 if (rc)
1213 return rc;
1214
1215 rc = efx_ef10_get_vf_index(efx);
1216 if (rc)
1217 goto fail;
1218
Shradha Shahf1122a32015-05-20 11:09:46 +01001219 if (efx->pci_dev->is_virtfn) {
1220 if (efx->pci_dev->physfn) {
1221 struct efx_nic *efx_pf =
1222 pci_get_drvdata(efx->pci_dev->physfn);
1223 struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data;
1224 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1225
1226 nic_data_p->vf[nic_data->vf_index].efx = efx;
Daniel Pieczko6598dad2015-06-02 11:41:00 +01001227 nic_data_p->vf[nic_data->vf_index].pci_dev =
1228 efx->pci_dev;
Shradha Shahf1122a32015-05-20 11:09:46 +01001229 } else
1230 netif_info(efx, drv, efx->net_dev,
1231 "Could not get the PF id from VF\n");
1232 }
1233
Shradha Shah88a37de2015-05-20 11:09:15 +01001234 return 0;
1235
1236fail:
1237 efx_ef10_remove(efx);
1238 return rc;
1239}
1240#else
1241static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused)))
1242{
1243 return 0;
1244}
1245#endif
1246
Ben Hutchings8127d662013-08-29 19:19:29 +01001247static int efx_ef10_alloc_vis(struct efx_nic *efx,
1248 unsigned int min_vis, unsigned int max_vis)
1249{
1250 MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN);
1251 MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN);
1252 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1253 size_t outlen;
1254 int rc;
1255
1256 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis);
1257 MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis);
1258 rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf),
1259 outbuf, sizeof(outbuf), &outlen);
1260 if (rc != 0)
1261 return rc;
1262
1263 if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN)
1264 return -EIO;
1265
1266 netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n",
1267 MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE));
1268
1269 nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE);
1270 nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT);
1271 return 0;
1272}
1273
Ben Hutchings183233b2013-06-28 21:47:12 +01001274/* Note that the failure path of this function does not free
1275 * resources, as this will be done by efx_ef10_remove().
1276 */
Ben Hutchings8127d662013-08-29 19:19:29 +01001277static int efx_ef10_dimension_resources(struct efx_nic *efx)
1278{
Ben Hutchings183233b2013-06-28 21:47:12 +01001279 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1280 unsigned int uc_mem_map_size, wc_mem_map_size;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001281 unsigned int min_vis = max(EFX_TXQ_TYPES,
1282 efx_separate_tx_channels ? 2 : 1);
1283 unsigned int channel_vis, pio_write_vi_base, max_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001284 void __iomem *membase;
1285 int rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01001286
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001287 channel_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
Ben Hutchings183233b2013-06-28 21:47:12 +01001288
1289#ifdef EFX_USE_PIO
1290 /* Try to allocate PIO buffers if wanted and if the full
1291 * number of PIO buffers would be sufficient to allocate one
1292 * copy-buffer per TX channel. Failure is non-fatal, as there
1293 * are only a small number of PIO buffers shared between all
1294 * functions of the controller.
1295 */
1296 if (efx_piobuf_size != 0 &&
Edward Creec6347002017-01-13 21:20:29 +00001297 nic_data->piobuf_size / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >=
Ben Hutchings183233b2013-06-28 21:47:12 +01001298 efx->n_tx_channels) {
1299 unsigned int n_piobufs =
1300 DIV_ROUND_UP(efx->n_tx_channels,
Edward Creec6347002017-01-13 21:20:29 +00001301 nic_data->piobuf_size / efx_piobuf_size);
Ben Hutchings183233b2013-06-28 21:47:12 +01001302
1303 rc = efx_ef10_alloc_piobufs(efx, n_piobufs);
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001304 if (rc == -ENOSPC)
1305 netif_dbg(efx, probe, efx->net_dev,
1306 "out of PIO buffers; cannot allocate more\n");
1307 else if (rc == -EPERM)
1308 netif_dbg(efx, probe, efx->net_dev,
1309 "not permitted to allocate PIO buffers\n");
1310 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001311 netif_err(efx, probe, efx->net_dev,
1312 "failed to allocate PIO buffers (%d)\n", rc);
1313 else
1314 netif_dbg(efx, probe, efx->net_dev,
1315 "allocated %u PIO buffers\n", n_piobufs);
1316 }
1317#else
1318 nic_data->n_piobufs = 0;
1319#endif
1320
1321 /* PIO buffers should be mapped with write-combining enabled,
1322 * and we want to make single UC and WC mappings rather than
1323 * several of each (in fact that's the only option if host
1324 * page size is >4K). So we may allocate some extra VIs just
1325 * for writing PIO buffers through.
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001326 *
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001327 * The UC mapping contains (channel_vis - 1) complete VIs and the
Edward Cree71827442017-12-18 16:56:19 +00001328 * first 4K of the next VI. Then the WC mapping begins with
1329 * the remainder of this last VI.
Ben Hutchings183233b2013-06-28 21:47:12 +01001330 */
Edward Cree71827442017-12-18 16:56:19 +00001331 uc_mem_map_size = PAGE_ALIGN((channel_vis - 1) * efx->vi_stride +
Ben Hutchings183233b2013-06-28 21:47:12 +01001332 ER_DZ_TX_PIOBUF);
1333 if (nic_data->n_piobufs) {
Daniel Pieczko52ad7622014-04-01 13:10:34 +01001334 /* pio_write_vi_base rounds down to give the number of complete
1335 * VIs inside the UC mapping.
1336 */
Edward Cree71827442017-12-18 16:56:19 +00001337 pio_write_vi_base = uc_mem_map_size / efx->vi_stride;
Ben Hutchings183233b2013-06-28 21:47:12 +01001338 wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base +
1339 nic_data->n_piobufs) *
Edward Cree71827442017-12-18 16:56:19 +00001340 efx->vi_stride) -
Ben Hutchings183233b2013-06-28 21:47:12 +01001341 uc_mem_map_size);
1342 max_vis = pio_write_vi_base + nic_data->n_piobufs;
1343 } else {
1344 pio_write_vi_base = 0;
1345 wc_mem_map_size = 0;
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001346 max_vis = channel_vis;
Ben Hutchings183233b2013-06-28 21:47:12 +01001347 }
1348
1349 /* In case the last attached driver failed to free VIs, do it now */
1350 rc = efx_ef10_free_vis(efx);
1351 if (rc != 0)
1352 return rc;
1353
1354 rc = efx_ef10_alloc_vis(efx, min_vis, max_vis);
1355 if (rc != 0)
1356 return rc;
1357
Shradha Shahb0fbdae2015-08-28 10:55:42 +01001358 if (nic_data->n_allocated_vis < channel_vis) {
1359 netif_info(efx, drv, efx->net_dev,
1360 "Could not allocate enough VIs to satisfy RSS"
1361 " requirements. Performance may not be optimal.\n");
1362 /* We didn't get the VIs to populate our channels.
1363 * We could keep what we got but then we'd have more
1364 * interrupts than we need.
1365 * Instead calculate new max_channels and restart
1366 */
1367 efx->max_channels = nic_data->n_allocated_vis;
1368 efx->max_tx_channels =
1369 nic_data->n_allocated_vis / EFX_TXQ_TYPES;
1370
1371 efx_ef10_free_vis(efx);
1372 return -EAGAIN;
1373 }
1374
Ben Hutchings183233b2013-06-28 21:47:12 +01001375 /* If we didn't get enough VIs to map all the PIO buffers, free the
1376 * PIO buffers
1377 */
1378 if (nic_data->n_piobufs &&
1379 nic_data->n_allocated_vis <
1380 pio_write_vi_base + nic_data->n_piobufs) {
1381 netif_dbg(efx, probe, efx->net_dev,
1382 "%u VIs are not sufficient to map %u PIO buffers\n",
1383 nic_data->n_allocated_vis, nic_data->n_piobufs);
1384 efx_ef10_free_piobufs(efx);
1385 }
1386
1387 /* Shrink the original UC mapping of the memory BAR */
1388 membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size);
1389 if (!membase) {
1390 netif_err(efx, probe, efx->net_dev,
1391 "could not shrink memory BAR to %x\n",
1392 uc_mem_map_size);
1393 return -ENOMEM;
1394 }
1395 iounmap(efx->membase);
1396 efx->membase = membase;
1397
1398 /* Set up the WC mapping if needed */
1399 if (wc_mem_map_size) {
1400 nic_data->wc_membase = ioremap_wc(efx->membase_phys +
1401 uc_mem_map_size,
1402 wc_mem_map_size);
1403 if (!nic_data->wc_membase) {
1404 netif_err(efx, probe, efx->net_dev,
1405 "could not allocate WC mapping of size %x\n",
1406 wc_mem_map_size);
1407 return -ENOMEM;
1408 }
1409 nic_data->pio_write_vi_base = pio_write_vi_base;
1410 nic_data->pio_write_base =
1411 nic_data->wc_membase +
Edward Cree71827442017-12-18 16:56:19 +00001412 (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF -
Ben Hutchings183233b2013-06-28 21:47:12 +01001413 uc_mem_map_size);
1414
1415 rc = efx_ef10_link_piobufs(efx);
1416 if (rc)
1417 efx_ef10_free_piobufs(efx);
1418 }
1419
1420 netif_dbg(efx, probe, efx->net_dev,
1421 "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n",
1422 &efx->membase_phys, efx->membase, uc_mem_map_size,
1423 nic_data->wc_membase, wc_mem_map_size);
1424
1425 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01001426}
1427
1428static int efx_ef10_init_nic(struct efx_nic *efx)
1429{
1430 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1431 int rc;
1432
Ben Hutchingsa915ccc2013-09-05 22:51:55 +01001433 if (nic_data->must_check_datapath_caps) {
1434 rc = efx_ef10_init_datapath_caps(efx);
1435 if (rc)
1436 return rc;
1437 nic_data->must_check_datapath_caps = false;
1438 }
1439
Ben Hutchings8127d662013-08-29 19:19:29 +01001440 if (nic_data->must_realloc_vis) {
1441 /* We cannot let the number of VIs change now */
1442 rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis,
1443 nic_data->n_allocated_vis);
1444 if (rc)
1445 return rc;
1446 nic_data->must_realloc_vis = false;
1447 }
1448
Ben Hutchings183233b2013-06-28 21:47:12 +01001449 if (nic_data->must_restore_piobufs && nic_data->n_piobufs) {
1450 rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs);
1451 if (rc == 0) {
1452 rc = efx_ef10_link_piobufs(efx);
1453 if (rc)
1454 efx_ef10_free_piobufs(efx);
1455 }
1456
Tomáš Pilař6eacfb52017-01-25 13:48:17 +00001457 /* Log an error on failure, but this is non-fatal.
1458 * Permission errors are less important - we've presumably
1459 * had the PIO buffer licence removed.
1460 */
1461 if (rc == -EPERM)
1462 netif_dbg(efx, drv, efx->net_dev,
1463 "not permitted to restore PIO buffers\n");
1464 else if (rc)
Ben Hutchings183233b2013-06-28 21:47:12 +01001465 netif_err(efx, drv, efx->net_dev,
1466 "failed to restore PIO buffers (%d)\n", rc);
1467 nic_data->must_restore_piobufs = false;
1468 }
1469
Jon Cooper267c0152015-05-06 00:59:38 +01001470 /* don't fail init if RSS setup doesn't work */
Edward Creef74d1992017-01-17 12:01:53 +00001471 rc = efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table, NULL);
Edward Cree4fdda952017-01-04 15:10:56 +00001472 efx->rss_active = (rc == 0);
Jon Cooper267c0152015-05-06 00:59:38 +01001473
Ben Hutchings8127d662013-08-29 19:19:29 +01001474 return 0;
1475}
1476
Jon Cooper3e336262014-01-17 19:48:06 +00001477static void efx_ef10_reset_mc_allocations(struct efx_nic *efx)
1478{
1479 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001480#ifdef CONFIG_SFC_SRIOV
1481 unsigned int i;
1482#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001483
1484 /* All our allocations have been reset */
1485 nic_data->must_realloc_vis = true;
1486 nic_data->must_restore_filters = true;
1487 nic_data->must_restore_piobufs = true;
Edward Creec0795bf2016-05-24 18:53:36 +01001488 efx_ef10_forget_old_piobufs(efx);
Jon Cooper3e336262014-01-17 19:48:06 +00001489 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
Daniel Pieczko774ad032015-07-31 11:15:22 +01001490
1491 /* Driver-created vswitches and vports must be re-created */
1492 nic_data->must_probe_vswitching = true;
1493 nic_data->vport_id = EVB_PORT_ID_ASSIGNED;
1494#ifdef CONFIG_SFC_SRIOV
1495 if (nic_data->vf)
1496 for (i = 0; i < efx->vf_count; i++)
1497 nic_data->vf[i].vport_id = 0;
1498#endif
Jon Cooper3e336262014-01-17 19:48:06 +00001499}
1500
Jon Cooper087e9022015-05-20 11:11:35 +01001501static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason)
1502{
1503 if (reason == RESET_TYPE_MC_FAILURE)
1504 return RESET_TYPE_DATAPATH;
1505
1506 return efx_mcdi_map_reset_reason(reason);
1507}
1508
Ben Hutchings8127d662013-08-29 19:19:29 +01001509static int efx_ef10_map_reset_flags(u32 *flags)
1510{
1511 enum {
1512 EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) <<
1513 ETH_RESET_SHARED_SHIFT),
1514 EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER |
1515 ETH_RESET_OFFLOAD | ETH_RESET_MAC |
1516 ETH_RESET_PHY | ETH_RESET_MGMT) <<
1517 ETH_RESET_SHARED_SHIFT)
1518 };
1519
1520 /* We assume for now that our PCI function is permitted to
1521 * reset everything.
1522 */
1523
1524 if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) {
1525 *flags &= ~EF10_RESET_MC;
1526 return RESET_TYPE_WORLD;
1527 }
1528
1529 if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) {
1530 *flags &= ~EF10_RESET_PORT;
1531 return RESET_TYPE_ALL;
1532 }
1533
1534 /* no invisible reset implemented */
1535
1536 return -EINVAL;
1537}
1538
Jon Cooper3e336262014-01-17 19:48:06 +00001539static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type)
1540{
1541 int rc = efx_mcdi_reset(efx, reset_type);
1542
Daniel Pieczko27324822015-07-31 11:14:54 +01001543 /* Unprivileged functions return -EPERM, but need to return success
1544 * here so that the datapath is brought back up.
1545 */
1546 if (reset_type == RESET_TYPE_WORLD && rc == -EPERM)
1547 rc = 0;
1548
Jon Cooper3e336262014-01-17 19:48:06 +00001549 /* If it was a port reset, trigger reallocation of MC resources.
1550 * Note that on an MC reset nothing needs to be done now because we'll
1551 * detect the MC reset later and handle it then.
Edward Creee2835462014-04-16 19:27:48 +01001552 * For an FLR, we never get an MC reset event, but the MC has reset all
1553 * resources assigned to us, so we have to trigger reallocation now.
Jon Cooper3e336262014-01-17 19:48:06 +00001554 */
Edward Creee2835462014-04-16 19:27:48 +01001555 if ((reset_type == RESET_TYPE_ALL ||
1556 reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc)
Jon Cooper3e336262014-01-17 19:48:06 +00001557 efx_ef10_reset_mc_allocations(efx);
1558 return rc;
1559}
1560
Ben Hutchings8127d662013-08-29 19:19:29 +01001561#define EF10_DMA_STAT(ext_name, mcdi_name) \
1562 [EF10_STAT_ ## ext_name] = \
1563 { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1564#define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \
1565 [EF10_STAT_ ## int_name] = \
1566 { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
1567#define EF10_OTHER_STAT(ext_name) \
1568 [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Edward Creee4d112e2014-07-15 11:58:12 +01001569#define GENERIC_SW_STAT(ext_name) \
1570 [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 }
Ben Hutchings8127d662013-08-29 19:19:29 +01001571
1572static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = {
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001573 EF10_DMA_STAT(port_tx_bytes, TX_BYTES),
1574 EF10_DMA_STAT(port_tx_packets, TX_PKTS),
1575 EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
1576 EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS),
1577 EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
1578 EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
1579 EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
1580 EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
1581 EF10_DMA_STAT(port_tx_64, TX_64_PKTS),
1582 EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
1583 EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
1584 EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
1585 EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
1586 EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
1587 EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
1588 EF10_DMA_STAT(port_rx_bytes, RX_BYTES),
1589 EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES),
1590 EF10_OTHER_STAT(port_rx_good_bytes),
1591 EF10_OTHER_STAT(port_rx_bad_bytes),
1592 EF10_DMA_STAT(port_rx_packets, RX_PKTS),
1593 EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
1594 EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
1595 EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
1596 EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS),
1597 EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
1598 EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
1599 EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
1600 EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
1601 EF10_DMA_STAT(port_rx_64, RX_64_PKTS),
1602 EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
1603 EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
1604 EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
1605 EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
1606 EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
1607 EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
1608 EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
1609 EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
1610 EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
1611 EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
1612 EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
1613 EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
Edward Creee4d112e2014-07-15 11:58:12 +01001614 GENERIC_SW_STAT(rx_nodesc_trunc),
1615 GENERIC_SW_STAT(rx_noskb_drops),
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001616 EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW),
1617 EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW),
1618 EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL),
1619 EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL),
1620 EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB),
1621 EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB),
1622 EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING),
1623 EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS),
1624 EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS),
1625 EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS),
1626 EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS),
1627 EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS),
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001628 EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS),
1629 EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES),
1630 EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS),
1631 EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES),
1632 EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS),
1633 EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES),
1634 EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS),
1635 EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES),
1636 EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW),
1637 EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS),
1638 EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES),
1639 EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS),
1640 EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES),
1641 EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS),
1642 EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES),
1643 EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS),
1644 EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES),
1645 EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW),
Edward Creef411b542017-12-21 09:00:36 +00001646 EF10_DMA_STAT(fec_uncorrected_errors, FEC_UNCORRECTED_ERRORS),
1647 EF10_DMA_STAT(fec_corrected_errors, FEC_CORRECTED_ERRORS),
1648 EF10_DMA_STAT(fec_corrected_symbols_lane0, FEC_CORRECTED_SYMBOLS_LANE0),
1649 EF10_DMA_STAT(fec_corrected_symbols_lane1, FEC_CORRECTED_SYMBOLS_LANE1),
1650 EF10_DMA_STAT(fec_corrected_symbols_lane2, FEC_CORRECTED_SYMBOLS_LANE2),
1651 EF10_DMA_STAT(fec_corrected_symbols_lane3, FEC_CORRECTED_SYMBOLS_LANE3),
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001652 EF10_DMA_STAT(ctpio_dmabuf_start, CTPIO_DMABUF_START),
1653 EF10_DMA_STAT(ctpio_vi_busy_fallback, CTPIO_VI_BUSY_FALLBACK),
1654 EF10_DMA_STAT(ctpio_long_write_success, CTPIO_LONG_WRITE_SUCCESS),
1655 EF10_DMA_STAT(ctpio_missing_dbell_fail, CTPIO_MISSING_DBELL_FAIL),
1656 EF10_DMA_STAT(ctpio_overflow_fail, CTPIO_OVERFLOW_FAIL),
1657 EF10_DMA_STAT(ctpio_underflow_fail, CTPIO_UNDERFLOW_FAIL),
1658 EF10_DMA_STAT(ctpio_timeout_fail, CTPIO_TIMEOUT_FAIL),
1659 EF10_DMA_STAT(ctpio_noncontig_wr_fail, CTPIO_NONCONTIG_WR_FAIL),
1660 EF10_DMA_STAT(ctpio_frm_clobber_fail, CTPIO_FRM_CLOBBER_FAIL),
1661 EF10_DMA_STAT(ctpio_invalid_wr_fail, CTPIO_INVALID_WR_FAIL),
1662 EF10_DMA_STAT(ctpio_vi_clobber_fallback, CTPIO_VI_CLOBBER_FALLBACK),
1663 EF10_DMA_STAT(ctpio_unqualified_fallback, CTPIO_UNQUALIFIED_FALLBACK),
1664 EF10_DMA_STAT(ctpio_runt_fallback, CTPIO_RUNT_FALLBACK),
1665 EF10_DMA_STAT(ctpio_success, CTPIO_SUCCESS),
1666 EF10_DMA_STAT(ctpio_fallback, CTPIO_FALLBACK),
1667 EF10_DMA_STAT(ctpio_poison, CTPIO_POISON),
1668 EF10_DMA_STAT(ctpio_erase, CTPIO_ERASE),
Ben Hutchings8127d662013-08-29 19:19:29 +01001669};
1670
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001671#define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \
1672 (1ULL << EF10_STAT_port_tx_packets) | \
1673 (1ULL << EF10_STAT_port_tx_pause) | \
1674 (1ULL << EF10_STAT_port_tx_unicast) | \
1675 (1ULL << EF10_STAT_port_tx_multicast) | \
1676 (1ULL << EF10_STAT_port_tx_broadcast) | \
1677 (1ULL << EF10_STAT_port_rx_bytes) | \
1678 (1ULL << \
1679 EF10_STAT_port_rx_bytes_minus_good_bytes) | \
1680 (1ULL << EF10_STAT_port_rx_good_bytes) | \
1681 (1ULL << EF10_STAT_port_rx_bad_bytes) | \
1682 (1ULL << EF10_STAT_port_rx_packets) | \
1683 (1ULL << EF10_STAT_port_rx_good) | \
1684 (1ULL << EF10_STAT_port_rx_bad) | \
1685 (1ULL << EF10_STAT_port_rx_pause) | \
1686 (1ULL << EF10_STAT_port_rx_control) | \
1687 (1ULL << EF10_STAT_port_rx_unicast) | \
1688 (1ULL << EF10_STAT_port_rx_multicast) | \
1689 (1ULL << EF10_STAT_port_rx_broadcast) | \
1690 (1ULL << EF10_STAT_port_rx_lt64) | \
1691 (1ULL << EF10_STAT_port_rx_64) | \
1692 (1ULL << EF10_STAT_port_rx_65_to_127) | \
1693 (1ULL << EF10_STAT_port_rx_128_to_255) | \
1694 (1ULL << EF10_STAT_port_rx_256_to_511) | \
1695 (1ULL << EF10_STAT_port_rx_512_to_1023) |\
1696 (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\
1697 (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\
1698 (1ULL << EF10_STAT_port_rx_gtjumbo) | \
1699 (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\
1700 (1ULL << EF10_STAT_port_rx_overflow) | \
1701 (1ULL << EF10_STAT_port_rx_nodesc_drops) |\
Edward Creee4d112e2014-07-15 11:58:12 +01001702 (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \
1703 (1ULL << GENERIC_STAT_rx_noskb_drops))
Ben Hutchings8127d662013-08-29 19:19:29 +01001704
Edward Cree69b365c2016-08-26 15:12:41 +01001705/* On 7000 series NICs, these statistics are only provided by the 10G MAC.
1706 * For a 10G/40G switchable port we do not expose these because they might
1707 * not include all the packets they should.
1708 * On 8000 series NICs these statistics are always provided.
Ben Hutchings8127d662013-08-29 19:19:29 +01001709 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001710#define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \
1711 (1ULL << EF10_STAT_port_tx_lt64) | \
1712 (1ULL << EF10_STAT_port_tx_64) | \
1713 (1ULL << EF10_STAT_port_tx_65_to_127) |\
1714 (1ULL << EF10_STAT_port_tx_128_to_255) |\
1715 (1ULL << EF10_STAT_port_tx_256_to_511) |\
1716 (1ULL << EF10_STAT_port_tx_512_to_1023) |\
1717 (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\
1718 (1ULL << EF10_STAT_port_tx_15xx_to_jumbo))
Ben Hutchings8127d662013-08-29 19:19:29 +01001719
1720/* These statistics are only provided by the 40G MAC. For a 10G/40G
1721 * switchable port we do expose these because the errors will otherwise
1722 * be silent.
1723 */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001724#define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\
1725 (1ULL << EF10_STAT_port_rx_length_error))
Ben Hutchings8127d662013-08-29 19:19:29 +01001726
Edward Cree568d7a02013-09-25 17:32:09 +01001727/* These statistics are only provided if the firmware supports the
1728 * capability PM_AND_RXDP_COUNTERS.
1729 */
1730#define HUNT_PM_AND_RXDP_STAT_MASK ( \
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001731 (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \
1732 (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \
1733 (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \
1734 (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \
1735 (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \
1736 (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \
1737 (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \
1738 (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \
1739 (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \
1740 (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \
1741 (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \
1742 (1ULL << EF10_STAT_port_rx_dp_hlb_wait))
Ben Hutchings8127d662013-08-29 19:19:29 +01001743
Edward Creef411b542017-12-21 09:00:36 +00001744/* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V2,
1745 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V2 in
1746 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1747 * These bits are in the second u64 of the raw mask.
1748 */
1749#define EF10_FEC_STAT_MASK ( \
1750 (1ULL << (EF10_STAT_fec_uncorrected_errors - 64)) | \
1751 (1ULL << (EF10_STAT_fec_corrected_errors - 64)) | \
1752 (1ULL << (EF10_STAT_fec_corrected_symbols_lane0 - 64)) | \
1753 (1ULL << (EF10_STAT_fec_corrected_symbols_lane1 - 64)) | \
1754 (1ULL << (EF10_STAT_fec_corrected_symbols_lane2 - 64)) | \
1755 (1ULL << (EF10_STAT_fec_corrected_symbols_lane3 - 64)))
1756
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001757/* These statistics are only provided if the NIC supports MC_CMD_MAC_STATS_V3,
1758 * indicated by returning a value >= MC_CMD_MAC_NSTATS_V3 in
1759 * MC_CMD_GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS.
1760 * These bits are in the second u64 of the raw mask.
1761 */
1762#define EF10_CTPIO_STAT_MASK ( \
1763 (1ULL << (EF10_STAT_ctpio_dmabuf_start - 64)) | \
1764 (1ULL << (EF10_STAT_ctpio_vi_busy_fallback - 64)) | \
1765 (1ULL << (EF10_STAT_ctpio_long_write_success - 64)) | \
1766 (1ULL << (EF10_STAT_ctpio_missing_dbell_fail - 64)) | \
1767 (1ULL << (EF10_STAT_ctpio_overflow_fail - 64)) | \
1768 (1ULL << (EF10_STAT_ctpio_underflow_fail - 64)) | \
1769 (1ULL << (EF10_STAT_ctpio_timeout_fail - 64)) | \
1770 (1ULL << (EF10_STAT_ctpio_noncontig_wr_fail - 64)) | \
1771 (1ULL << (EF10_STAT_ctpio_frm_clobber_fail - 64)) | \
1772 (1ULL << (EF10_STAT_ctpio_invalid_wr_fail - 64)) | \
1773 (1ULL << (EF10_STAT_ctpio_vi_clobber_fallback - 64)) | \
1774 (1ULL << (EF10_STAT_ctpio_unqualified_fallback - 64)) | \
1775 (1ULL << (EF10_STAT_ctpio_runt_fallback - 64)) | \
1776 (1ULL << (EF10_STAT_ctpio_success - 64)) | \
1777 (1ULL << (EF10_STAT_ctpio_fallback - 64)) | \
1778 (1ULL << (EF10_STAT_ctpio_poison - 64)) | \
1779 (1ULL << (EF10_STAT_ctpio_erase - 64)))
1780
Edward Cree4bae9132013-09-27 18:52:49 +01001781static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001782{
Edward Cree4bae9132013-09-27 18:52:49 +01001783 u64 raw_mask = HUNT_COMMON_STAT_MASK;
Ben Hutchings8127d662013-08-29 19:19:29 +01001784 u32 port_caps = efx_mcdi_phy_get_caps(efx);
Edward Cree568d7a02013-09-25 17:32:09 +01001785 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01001786
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001787 if (!(efx->mcdi->fn_flags &
1788 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL))
1789 return 0;
1790
Edward Cree69b365c2016-08-26 15:12:41 +01001791 if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) {
Edward Cree4bae9132013-09-27 18:52:49 +01001792 raw_mask |= HUNT_40G_EXTRA_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001793 /* 8000 series have everything even at 40G */
1794 if (nic_data->datapath_caps2 &
1795 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_MAC_STATS_40G_TX_SIZE_BINS_LBN))
1796 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
1797 } else {
Edward Cree4bae9132013-09-27 18:52:49 +01001798 raw_mask |= HUNT_10G_ONLY_STAT_MASK;
Edward Cree69b365c2016-08-26 15:12:41 +01001799 }
Edward Cree568d7a02013-09-25 17:32:09 +01001800
1801 if (nic_data->datapath_caps &
1802 (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN))
1803 raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK;
1804
Edward Cree4bae9132013-09-27 18:52:49 +01001805 return raw_mask;
1806}
1807
1808static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask)
1809{
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001810 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001811 u64 raw_mask[2];
1812
1813 raw_mask[0] = efx_ef10_raw_stat_mask(efx);
1814
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001815 /* Only show vadaptor stats when EVB capability is present */
1816 if (nic_data->datapath_caps &
1817 (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) {
1818 raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1);
Edward Creef411b542017-12-21 09:00:36 +00001819 raw_mask[1] = (1ULL << (EF10_STAT_V1_COUNT - 64)) - 1;
Daniel Pieczkod94619c2015-06-02 11:40:05 +01001820 } else {
1821 raw_mask[1] = 0;
1822 }
Edward Creef411b542017-12-21 09:00:36 +00001823 /* Only show FEC stats when NIC supports MC_CMD_MAC_STATS_V2 */
1824 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V2)
1825 raw_mask[1] |= EF10_FEC_STAT_MASK;
Edward Cree4bae9132013-09-27 18:52:49 +01001826
Bert Kenward2c0b6ee2017-12-21 09:00:41 +00001827 /* CTPIO stats appear in V3. Only show them on devices that actually
1828 * support CTPIO. Although this driver doesn't use CTPIO others might,
1829 * and we may be reporting the stats for the underlying port.
1830 */
1831 if (efx->num_mac_stats >= MC_CMD_MAC_NSTATS_V3 &&
1832 (nic_data->datapath_caps2 &
1833 (1 << MC_CMD_GET_CAPABILITIES_V4_OUT_CTPIO_LBN)))
1834 raw_mask[1] |= EF10_CTPIO_STAT_MASK;
1835
Edward Cree4bae9132013-09-27 18:52:49 +01001836#if BITS_PER_LONG == 64
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001837 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 2);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001838 mask[0] = raw_mask[0];
1839 mask[1] = raw_mask[1];
Edward Cree4bae9132013-09-27 18:52:49 +01001840#else
Andrew Rybchenkoe70c70c32016-08-26 11:19:34 +01001841 BUILD_BUG_ON(BITS_TO_LONGS(EF10_STAT_COUNT) != 3);
Daniel Pieczko3c36a2a2015-06-02 11:39:06 +01001842 mask[0] = raw_mask[0] & 0xffffffff;
1843 mask[1] = raw_mask[0] >> 32;
1844 mask[2] = raw_mask[1] & 0xffffffff;
Edward Cree4bae9132013-09-27 18:52:49 +01001845#endif
Ben Hutchings8127d662013-08-29 19:19:29 +01001846}
1847
1848static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names)
1849{
Edward Cree4bae9132013-09-27 18:52:49 +01001850 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1851
1852 efx_ef10_get_stat_mask(efx, mask);
Ben Hutchings8127d662013-08-29 19:19:29 +01001853 return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT,
Edward Cree4bae9132013-09-27 18:52:49 +01001854 mask, names);
Ben Hutchings8127d662013-08-29 19:19:29 +01001855}
1856
Daniel Pieczkod7788192015-06-02 11:39:20 +01001857static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats,
1858 struct rtnl_link_stats64 *core_stats)
1859{
1860 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1861 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1862 u64 *stats = nic_data->stats;
1863 size_t stats_count = 0, index;
1864
1865 efx_ef10_get_stat_mask(efx, mask);
1866
1867 if (full_stats) {
1868 for_each_set_bit(index, mask, EF10_STAT_COUNT) {
1869 if (efx_ef10_stat_desc[index].name) {
1870 *full_stats++ = stats[index];
1871 ++stats_count;
1872 }
1873 }
1874 }
1875
Bert Kenwardfbe43072015-08-26 16:39:03 +01001876 if (!core_stats)
1877 return stats_count;
1878
1879 if (nic_data->datapath_caps &
1880 1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN) {
1881 /* Use vadaptor stats. */
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001882 core_stats->rx_packets = stats[EF10_STAT_rx_unicast] +
1883 stats[EF10_STAT_rx_multicast] +
1884 stats[EF10_STAT_rx_broadcast];
1885 core_stats->tx_packets = stats[EF10_STAT_tx_unicast] +
1886 stats[EF10_STAT_tx_multicast] +
1887 stats[EF10_STAT_tx_broadcast];
1888 core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] +
1889 stats[EF10_STAT_rx_multicast_bytes] +
1890 stats[EF10_STAT_rx_broadcast_bytes];
1891 core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] +
1892 stats[EF10_STAT_tx_multicast_bytes] +
1893 stats[EF10_STAT_tx_broadcast_bytes];
1894 core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] +
Daniel Pieczkod7788192015-06-02 11:39:20 +01001895 stats[GENERIC_STAT_rx_noskb_drops];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01001896 core_stats->multicast = stats[EF10_STAT_rx_multicast];
1897 core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad];
1898 core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow];
1899 core_stats->rx_errors = core_stats->rx_crc_errors;
1900 core_stats->tx_errors = stats[EF10_STAT_tx_bad];
Bert Kenwardfbe43072015-08-26 16:39:03 +01001901 } else {
1902 /* Use port stats. */
1903 core_stats->rx_packets = stats[EF10_STAT_port_rx_packets];
1904 core_stats->tx_packets = stats[EF10_STAT_port_tx_packets];
1905 core_stats->rx_bytes = stats[EF10_STAT_port_rx_bytes];
1906 core_stats->tx_bytes = stats[EF10_STAT_port_tx_bytes];
1907 core_stats->rx_dropped = stats[EF10_STAT_port_rx_nodesc_drops] +
1908 stats[GENERIC_STAT_rx_nodesc_trunc] +
1909 stats[GENERIC_STAT_rx_noskb_drops];
1910 core_stats->multicast = stats[EF10_STAT_port_rx_multicast];
1911 core_stats->rx_length_errors =
1912 stats[EF10_STAT_port_rx_gtjumbo] +
1913 stats[EF10_STAT_port_rx_length_error];
1914 core_stats->rx_crc_errors = stats[EF10_STAT_port_rx_bad];
1915 core_stats->rx_frame_errors =
1916 stats[EF10_STAT_port_rx_align_error];
1917 core_stats->rx_fifo_errors = stats[EF10_STAT_port_rx_overflow];
1918 core_stats->rx_errors = (core_stats->rx_length_errors +
1919 core_stats->rx_crc_errors +
1920 core_stats->rx_frame_errors);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001921 }
1922
1923 return stats_count;
1924}
1925
1926static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01001927{
1928 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Edward Cree4bae9132013-09-27 18:52:49 +01001929 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
Ben Hutchings8127d662013-08-29 19:19:29 +01001930 __le64 generation_start, generation_end;
1931 u64 *stats = nic_data->stats;
1932 __le64 *dma_stats;
1933
Edward Cree4bae9132013-09-27 18:52:49 +01001934 efx_ef10_get_stat_mask(efx, mask);
1935
Ben Hutchings8127d662013-08-29 19:19:29 +01001936 dma_stats = efx->stats_buffer.addr;
Ben Hutchings8127d662013-08-29 19:19:29 +01001937
Edward Creec1be4822017-12-21 09:00:26 +00001938 generation_end = dma_stats[efx->num_mac_stats - 1];
Ben Hutchings8127d662013-08-29 19:19:29 +01001939 if (generation_end == EFX_MC_STATS_GENERATION_INVALID)
1940 return 0;
1941 rmb();
Edward Cree4bae9132013-09-27 18:52:49 +01001942 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
Ben Hutchings8127d662013-08-29 19:19:29 +01001943 stats, efx->stats_buffer.addr, false);
Jon Cooperd546a892013-09-27 18:26:30 +01001944 rmb();
Ben Hutchings8127d662013-08-29 19:19:29 +01001945 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
1946 if (generation_end != generation_start)
1947 return -EAGAIN;
1948
1949 /* Update derived statistics */
Daniel Pieczkoe80ca0132015-06-02 11:38:34 +01001950 efx_nic_fix_nodesc_drop_stat(efx,
1951 &stats[EF10_STAT_port_rx_nodesc_drops]);
1952 stats[EF10_STAT_port_rx_good_bytes] =
1953 stats[EF10_STAT_port_rx_bytes] -
1954 stats[EF10_STAT_port_rx_bytes_minus_good_bytes];
1955 efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes],
1956 stats[EF10_STAT_port_rx_bytes_minus_good_bytes]);
Edward Creee4d112e2014-07-15 11:58:12 +01001957 efx_update_sw_stats(efx, stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01001958 return 0;
1959}
1960
1961
Daniel Pieczkod7788192015-06-02 11:39:20 +01001962static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats,
1963 struct rtnl_link_stats64 *core_stats)
Ben Hutchings8127d662013-08-29 19:19:29 +01001964{
Ben Hutchings8127d662013-08-29 19:19:29 +01001965 int retry;
1966
1967 /* If we're unlucky enough to read statistics during the DMA, wait
1968 * up to 10ms for it to finish (typically takes <500us)
1969 */
1970 for (retry = 0; retry < 100; ++retry) {
Daniel Pieczkod7788192015-06-02 11:39:20 +01001971 if (efx_ef10_try_update_nic_stats_pf(efx) == 0)
Ben Hutchings8127d662013-08-29 19:19:29 +01001972 break;
1973 udelay(100);
1974 }
1975
Daniel Pieczkod7788192015-06-02 11:39:20 +01001976 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
1977}
1978
1979static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx)
1980{
1981 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1982 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1983 DECLARE_BITMAP(mask, EF10_STAT_COUNT);
1984 __le64 generation_start, generation_end;
1985 u64 *stats = nic_data->stats;
Edward Creec1be4822017-12-21 09:00:26 +00001986 u32 dma_len = efx->num_mac_stats * sizeof(u64);
Daniel Pieczkod7788192015-06-02 11:39:20 +01001987 struct efx_buffer stats_buf;
1988 __le64 *dma_stats;
1989 int rc;
1990
Daniel Pieczkof00bf232015-06-02 11:40:18 +01001991 spin_unlock_bh(&efx->stats_lock);
1992
1993 if (in_interrupt()) {
1994 /* If in atomic context, cannot update stats. Just update the
1995 * software stats and return so the caller can continue.
1996 */
1997 spin_lock_bh(&efx->stats_lock);
1998 efx_update_sw_stats(efx, stats);
1999 return 0;
2000 }
2001
Daniel Pieczkod7788192015-06-02 11:39:20 +01002002 efx_ef10_get_stat_mask(efx, mask);
2003
2004 rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC);
Daniel Pieczkof00bf232015-06-02 11:40:18 +01002005 if (rc) {
2006 spin_lock_bh(&efx->stats_lock);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002007 return rc;
Daniel Pieczkof00bf232015-06-02 11:40:18 +01002008 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002009
2010 dma_stats = stats_buf.addr;
Edward Creec1be4822017-12-21 09:00:26 +00002011 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
Daniel Pieczkod7788192015-06-02 11:39:20 +01002012
2013 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr);
2014 MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD,
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002015 MAC_STATS_IN_DMA, 1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002016 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
2017 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED);
2018
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002019 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
2020 NULL, 0, NULL);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002021 spin_lock_bh(&efx->stats_lock);
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002022 if (rc) {
2023 /* Expect ENOENT if DMA queues have not been set up */
2024 if (rc != -ENOENT || atomic_read(&efx->active_queues))
2025 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS,
2026 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002027 goto out;
Daniel Pieczko6dd48592015-06-02 11:39:49 +01002028 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002029
Edward Creec1be4822017-12-21 09:00:26 +00002030 generation_end = dma_stats[efx->num_mac_stats - 1];
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002031 if (generation_end == EFX_MC_STATS_GENERATION_INVALID) {
2032 WARN_ON_ONCE(1);
Daniel Pieczkod7788192015-06-02 11:39:20 +01002033 goto out;
Daniel Pieczko0fc95fc2015-06-02 11:39:33 +01002034 }
Daniel Pieczkod7788192015-06-02 11:39:20 +01002035 rmb();
2036 efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask,
2037 stats, stats_buf.addr, false);
2038 rmb();
2039 generation_start = dma_stats[MC_CMD_MAC_GENERATION_START];
2040 if (generation_end != generation_start) {
2041 rc = -EAGAIN;
2042 goto out;
Ben Hutchings8127d662013-08-29 19:19:29 +01002043 }
2044
Daniel Pieczkod7788192015-06-02 11:39:20 +01002045 efx_update_sw_stats(efx, stats);
2046out:
2047 efx_nic_free_buffer(efx, &stats_buf);
2048 return rc;
2049}
Ben Hutchings8127d662013-08-29 19:19:29 +01002050
Daniel Pieczkod7788192015-06-02 11:39:20 +01002051static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats,
2052 struct rtnl_link_stats64 *core_stats)
2053{
2054 if (efx_ef10_try_update_nic_stats_vf(efx))
2055 return 0;
2056
2057 return efx_ef10_update_stats_common(efx, full_stats, core_stats);
Ben Hutchings8127d662013-08-29 19:19:29 +01002058}
2059
2060static void efx_ef10_push_irq_moderation(struct efx_channel *channel)
2061{
2062 struct efx_nic *efx = channel->efx;
Bert Kenward539de7c2016-08-11 13:02:09 +01002063 unsigned int mode, usecs;
Ben Hutchings8127d662013-08-29 19:19:29 +01002064 efx_dword_t timer_cmd;
2065
Bert Kenward539de7c2016-08-11 13:02:09 +01002066 if (channel->irq_moderation_us) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002067 mode = 3;
Bert Kenward539de7c2016-08-11 13:02:09 +01002068 usecs = channel->irq_moderation_us;
Ben Hutchings8127d662013-08-29 19:19:29 +01002069 } else {
2070 mode = 0;
Bert Kenward539de7c2016-08-11 13:02:09 +01002071 usecs = 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002072 }
2073
Bert Kenward539de7c2016-08-11 13:02:09 +01002074 if (EFX_EF10_WORKAROUND_61265(efx)) {
2075 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_EVQ_TMR_IN_LEN);
2076 unsigned int ns = usecs * 1000;
2077
2078 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_INSTANCE,
2079 channel->channel);
2080 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_LOAD_REQ_NS, ns);
2081 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_RELOAD_REQ_NS, ns);
2082 MCDI_SET_DWORD(inbuf, SET_EVQ_TMR_IN_TMR_MODE, mode);
2083
2084 efx_mcdi_rpc_async(efx, MC_CMD_SET_EVQ_TMR,
2085 inbuf, sizeof(inbuf), 0, NULL, 0);
2086 } else if (EFX_EF10_WORKAROUND_35388(efx)) {
2087 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2088
Ben Hutchings8127d662013-08-29 19:19:29 +01002089 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS,
2090 EFE_DD_EVQ_IND_TIMER_FLAGS,
2091 ERF_DD_EVQ_IND_TIMER_MODE, mode,
Bert Kenward539de7c2016-08-11 13:02:09 +01002092 ERF_DD_EVQ_IND_TIMER_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002093 efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT,
2094 channel->channel);
2095 } else {
Bert Kenward539de7c2016-08-11 13:02:09 +01002096 unsigned int ticks = efx_usecs_to_ticks(efx, usecs);
2097
Bert Kenward0bc959a2017-12-18 16:57:41 +00002098 EFX_POPULATE_DWORD_3(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode,
2099 ERF_DZ_TC_TIMER_VAL, ticks,
2100 ERF_FZ_TC_TMR_REL_VAL, ticks);
Ben Hutchings8127d662013-08-29 19:19:29 +01002101 efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR,
2102 channel->channel);
2103 }
2104}
2105
Shradha Shah02246a72015-05-06 00:58:14 +01002106static void efx_ef10_get_wol_vf(struct efx_nic *efx,
2107 struct ethtool_wolinfo *wol) {}
2108
2109static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type)
2110{
2111 return -EOPNOTSUPP;
2112}
2113
Ben Hutchings8127d662013-08-29 19:19:29 +01002114static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol)
2115{
2116 wol->supported = 0;
2117 wol->wolopts = 0;
2118 memset(&wol->sopass, 0, sizeof(wol->sopass));
2119}
2120
2121static int efx_ef10_set_wol(struct efx_nic *efx, u32 type)
2122{
2123 if (type != 0)
2124 return -EINVAL;
2125 return 0;
2126}
2127
2128static void efx_ef10_mcdi_request(struct efx_nic *efx,
2129 const efx_dword_t *hdr, size_t hdr_len,
2130 const efx_dword_t *sdu, size_t sdu_len)
2131{
2132 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2133 u8 *pdu = nic_data->mcdi_buf.addr;
2134
2135 memcpy(pdu, hdr, hdr_len);
2136 memcpy(pdu + hdr_len, sdu, sdu_len);
2137 wmb();
2138
2139 /* The hardware provides 'low' and 'high' (doorbell) registers
2140 * for passing the 64-bit address of an MCDI request to
2141 * firmware. However the dwords are swapped by firmware. The
2142 * least significant bits of the doorbell are then 0 for all
2143 * MCDI requests due to alignment.
2144 */
2145 _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32),
2146 ER_DZ_MC_DB_LWRD);
2147 _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr),
2148 ER_DZ_MC_DB_HWRD);
2149}
2150
2151static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx)
2152{
2153 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2154 const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr;
2155
2156 rmb();
2157 return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
2158}
2159
2160static void
2161efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf,
2162 size_t offset, size_t outlen)
2163{
2164 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2165 const u8 *pdu = nic_data->mcdi_buf.addr;
2166
2167 memcpy(outbuf, pdu + offset, outlen);
2168}
2169
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002170static void efx_ef10_mcdi_reboot_detected(struct efx_nic *efx)
2171{
2172 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2173
2174 /* All our allocations have been reset */
2175 efx_ef10_reset_mc_allocations(efx);
2176
2177 /* The datapath firmware might have been changed */
2178 nic_data->must_check_datapath_caps = true;
2179
2180 /* MAC statistics have been cleared on the NIC; clear the local
2181 * statistic that we update with efx_update_diff_stat().
2182 */
2183 nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0;
2184}
2185
Ben Hutchings8127d662013-08-29 19:19:29 +01002186static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx)
2187{
2188 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2189 int rc;
2190
2191 rc = efx_ef10_get_warm_boot_count(efx);
2192 if (rc < 0) {
2193 /* The firmware is presumably in the process of
2194 * rebooting. However, we are supposed to report each
2195 * reboot just once, so we must only do that once we
2196 * can read and store the updated warm boot count.
2197 */
2198 return 0;
2199 }
2200
2201 if (rc == nic_data->warm_boot_count)
2202 return 0;
2203
2204 nic_data->warm_boot_count = rc;
Daniel Pieczkoc577e592015-10-09 10:40:35 +01002205 efx_ef10_mcdi_reboot_detected(efx);
Ben Hutchings869070c2013-09-05 22:46:10 +01002206
Ben Hutchings8127d662013-08-29 19:19:29 +01002207 return -EIO;
2208}
2209
2210/* Handle an MSI interrupt
2211 *
2212 * Handle an MSI hardware interrupt. This routine schedules event
2213 * queue processing. No interrupt acknowledgement cycle is necessary.
2214 * Also, we never need to check that the interrupt is for us, since
2215 * MSI interrupts cannot be shared.
2216 */
2217static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id)
2218{
2219 struct efx_msi_context *context = dev_id;
2220 struct efx_nic *efx = context->efx;
2221
2222 netif_vdbg(efx, intr, efx->net_dev,
2223 "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
2224
Mark Rutland6aa7de02017-10-23 14:07:29 -07002225 if (likely(READ_ONCE(efx->irq_soft_enabled))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01002226 /* Note test interrupts */
2227 if (context->index == efx->irq_level)
2228 efx->last_irq_cpu = raw_smp_processor_id();
2229
2230 /* Schedule processing of the channel */
2231 efx_schedule_channel_irq(efx->channel[context->index]);
2232 }
2233
2234 return IRQ_HANDLED;
2235}
2236
2237static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id)
2238{
2239 struct efx_nic *efx = dev_id;
Mark Rutland6aa7de02017-10-23 14:07:29 -07002240 bool soft_enabled = READ_ONCE(efx->irq_soft_enabled);
Ben Hutchings8127d662013-08-29 19:19:29 +01002241 struct efx_channel *channel;
2242 efx_dword_t reg;
2243 u32 queues;
2244
2245 /* Read the ISR which also ACKs the interrupts */
2246 efx_readd(efx, &reg, ER_DZ_BIU_INT_ISR);
2247 queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG);
2248
2249 if (queues == 0)
2250 return IRQ_NONE;
2251
2252 if (likely(soft_enabled)) {
2253 /* Note test interrupts */
2254 if (queues & (1U << efx->irq_level))
2255 efx->last_irq_cpu = raw_smp_processor_id();
2256
2257 efx_for_each_channel(channel, efx) {
2258 if (queues & 1)
2259 efx_schedule_channel_irq(channel);
2260 queues >>= 1;
2261 }
2262 }
2263
2264 netif_vdbg(efx, intr, efx->net_dev,
2265 "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
2266 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
2267
2268 return IRQ_HANDLED;
2269}
2270
Jon Cooper942e2982016-08-26 15:13:30 +01002271static int efx_ef10_irq_test_generate(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01002272{
2273 MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
2274
Jon Cooper942e2982016-08-26 15:13:30 +01002275 if (efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG41750, true,
2276 NULL) == 0)
2277 return -ENOTSUPP;
2278
Ben Hutchings8127d662013-08-29 19:19:29 +01002279 BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
2280
2281 MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
Jon Cooper942e2982016-08-26 15:13:30 +01002282 return efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT,
Ben Hutchings8127d662013-08-29 19:19:29 +01002283 inbuf, sizeof(inbuf), NULL, 0, NULL);
2284}
2285
2286static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue)
2287{
2288 return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf,
2289 (tx_queue->ptr_mask + 1) *
2290 sizeof(efx_qword_t),
2291 GFP_KERNEL);
2292}
2293
2294/* This writes to the TX_DESC_WPTR and also pushes data */
2295static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue,
2296 const efx_qword_t *txd)
2297{
2298 unsigned int write_ptr;
2299 efx_oword_t reg;
2300
2301 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2302 EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr);
2303 reg.qword[0] = *txd;
2304 efx_writeo_page(tx_queue->efx, &reg,
2305 ER_DZ_TX_DESC_UPD, tx_queue->queue);
2306}
2307
Bert Kenwarde9117e52016-11-17 10:51:54 +00002308/* Add Firmware-Assisted TSO v2 option descriptors to a queue.
2309 */
2310static int efx_ef10_tx_tso_desc(struct efx_tx_queue *tx_queue,
2311 struct sk_buff *skb,
2312 bool *data_mapped)
2313{
2314 struct efx_tx_buffer *buffer;
2315 struct tcphdr *tcp;
2316 struct iphdr *ip;
2317
2318 u16 ipv4_id;
2319 u32 seqnum;
2320 u32 mss;
2321
Edward Creee01b16a2016-12-02 15:51:33 +00002322 EFX_WARN_ON_ONCE_PARANOID(tx_queue->tso_version != 2);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002323
2324 mss = skb_shinfo(skb)->gso_size;
2325
2326 if (unlikely(mss < 4)) {
2327 WARN_ONCE(1, "MSS of %u is too small for TSO v2\n", mss);
2328 return -EINVAL;
2329 }
2330
2331 ip = ip_hdr(skb);
2332 if (ip->version == 4) {
2333 /* Modify IPv4 header if needed. */
2334 ip->tot_len = 0;
2335 ip->check = 0;
Edward Cree6d431312017-03-03 15:22:27 +00002336 ipv4_id = ntohs(ip->id);
Bert Kenwarde9117e52016-11-17 10:51:54 +00002337 } else {
2338 /* Modify IPv6 header if needed. */
2339 struct ipv6hdr *ipv6 = ipv6_hdr(skb);
2340
2341 ipv6->payload_len = 0;
2342 ipv4_id = 0;
2343 }
2344
2345 tcp = tcp_hdr(skb);
2346 seqnum = ntohl(tcp->seq);
2347
2348 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2349
2350 buffer->flags = EFX_TX_BUF_OPTION;
2351 buffer->len = 0;
2352 buffer->unmap_len = 0;
2353 EFX_POPULATE_QWORD_5(buffer->option,
2354 ESF_DZ_TX_DESC_IS_OPT, 1,
2355 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2356 ESF_DZ_TX_TSO_OPTION_TYPE,
2357 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2A,
2358 ESF_DZ_TX_TSO_IP_ID, ipv4_id,
2359 ESF_DZ_TX_TSO_TCP_SEQNO, seqnum
2360 );
2361 ++tx_queue->insert_count;
2362
2363 buffer = efx_tx_queue_get_insert_buffer(tx_queue);
2364
2365 buffer->flags = EFX_TX_BUF_OPTION;
2366 buffer->len = 0;
2367 buffer->unmap_len = 0;
2368 EFX_POPULATE_QWORD_4(buffer->option,
2369 ESF_DZ_TX_DESC_IS_OPT, 1,
2370 ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_TSO,
2371 ESF_DZ_TX_TSO_OPTION_TYPE,
2372 ESE_DZ_TX_TSO_OPTION_DESC_FATSO2B,
2373 ESF_DZ_TX_TSO_TCP_MSS, mss
2374 );
2375 ++tx_queue->insert_count;
2376
2377 return 0;
2378}
2379
Edward Cree46d1efd2016-11-17 10:52:36 +00002380static u32 efx_ef10_tso_versions(struct efx_nic *efx)
2381{
2382 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2383 u32 tso_versions = 0;
2384
2385 if (nic_data->datapath_caps &
2386 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))
2387 tso_versions |= BIT(1);
2388 if (nic_data->datapath_caps2 &
2389 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN))
2390 tso_versions |= BIT(2);
2391 return tso_versions;
2392}
2393
Ben Hutchings8127d662013-08-29 19:19:29 +01002394static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue)
2395{
2396 MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2397 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002398 bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
2399 size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE;
2400 struct efx_channel *channel = tx_queue->channel;
2401 struct efx_nic *efx = tx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002402 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwarde9117e52016-11-17 10:51:54 +00002403 bool tso_v2 = false;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002404 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002405 dma_addr_t dma_addr;
2406 efx_qword_t *txd;
2407 int rc;
2408 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002409 BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01002410
Bert Kenwarde9117e52016-11-17 10:51:54 +00002411 /* TSOv2 is a limited resource that can only be configured on a limited
2412 * number of queues. TSO without checksum offload is not really a thing,
2413 * so we only enable it for those queues.
Martin Habetsb9b603d42018-01-25 17:24:43 +00002414 * TSOv2 cannot be used with Hardware timestamping.
Bert Kenwarde9117e52016-11-17 10:51:54 +00002415 */
2416 if (csum_offload && (nic_data->datapath_caps2 &
Martin Habetsb9b603d42018-01-25 17:24:43 +00002417 (1 << MC_CMD_GET_CAPABILITIES_V2_OUT_TX_TSO_V2_LBN)) &&
2418 !tx_queue->timestamping) {
Bert Kenwarde9117e52016-11-17 10:51:54 +00002419 tso_v2 = true;
2420 netif_dbg(efx, hw, efx->net_dev, "Using TSOv2 for channel %u\n",
2421 channel->channel);
2422 }
2423
Ben Hutchings8127d662013-08-29 19:19:29 +01002424 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1);
2425 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel);
2426 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue);
2427 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002428 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002429 MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01002430
2431 dma_addr = tx_queue->txd.buf.dma_addr;
2432
2433 netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n",
2434 tx_queue->queue, entries, (u64)dma_addr);
2435
2436 for (i = 0; i < entries; ++i) {
2437 MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr);
2438 dma_addr += EFX_BUF_SIZE;
2439 }
2440
2441 inlen = MC_CMD_INIT_TXQ_IN_LEN(entries);
2442
Edward Creee638ee12016-11-17 10:52:07 +00002443 do {
Martin Habetsb9b603d42018-01-25 17:24:43 +00002444 MCDI_POPULATE_DWORD_4(inbuf, INIT_TXQ_IN_FLAGS,
Edward Creee638ee12016-11-17 10:52:07 +00002445 /* This flag was removed from mcdi_pcol.h for
2446 * the non-_EXT version of INIT_TXQ. However,
2447 * firmware still honours it.
2448 */
2449 INIT_TXQ_EXT_IN_FLAG_TSOV2_EN, tso_v2,
2450 INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload,
Martin Habetsb9b603d42018-01-25 17:24:43 +00002451 INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload,
2452 INIT_TXQ_EXT_IN_FLAG_TIMESTAMP,
2453 tx_queue->timestamping);
Edward Creee638ee12016-11-17 10:52:07 +00002454
2455 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_INIT_TXQ, inbuf, inlen,
2456 NULL, 0, NULL);
2457 if (rc == -ENOSPC && tso_v2) {
2458 /* Retry without TSOv2 if we're short on contexts. */
2459 tso_v2 = false;
2460 netif_warn(efx, probe, efx->net_dev,
2461 "TSOv2 context not available to segment in hardware. TCP performance may be reduced.\n");
2462 } else if (rc) {
2463 efx_mcdi_display_error(efx, MC_CMD_INIT_TXQ,
2464 MC_CMD_INIT_TXQ_EXT_IN_LEN,
2465 NULL, 0, rc);
2466 goto fail;
2467 }
2468 } while (rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002469
2470 /* A previous user of this TX queue might have set us up the
2471 * bomb by writing a descriptor to the TX push collector but
2472 * not the doorbell. (Each collector belongs to a port, not a
2473 * queue or function, so cannot easily be reset.) We must
2474 * attempt to push a no-op descriptor in its place.
2475 */
2476 tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION;
2477 tx_queue->insert_count = 1;
2478 txd = efx_tx_desc(tx_queue, 0);
Martin Habetsb9b603d42018-01-25 17:24:43 +00002479 EFX_POPULATE_QWORD_5(*txd,
Ben Hutchings8127d662013-08-29 19:19:29 +01002480 ESF_DZ_TX_DESC_IS_OPT, true,
2481 ESF_DZ_TX_OPTION_TYPE,
2482 ESE_DZ_TX_OPTION_DESC_CRC_CSUM,
2483 ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload,
Martin Habetsb9b603d42018-01-25 17:24:43 +00002484 ESF_DZ_TX_OPTION_IP_CSUM, csum_offload,
2485 ESF_DZ_TX_TIMESTAMP, tx_queue->timestamping);
Ben Hutchings8127d662013-08-29 19:19:29 +01002486 tx_queue->write_count = 1;
Bert Kenward93171b12015-11-30 09:05:35 +00002487
Bert Kenwarde9117e52016-11-17 10:51:54 +00002488 if (tso_v2) {
2489 tx_queue->handle_tso = efx_ef10_tx_tso_desc;
2490 tx_queue->tso_version = 2;
2491 } else if (nic_data->datapath_caps &
2492 (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN)) {
Bert Kenward93171b12015-11-30 09:05:35 +00002493 tx_queue->tso_version = 1;
2494 }
2495
Ben Hutchings8127d662013-08-29 19:19:29 +01002496 wmb();
2497 efx_ef10_push_tx_desc(tx_queue, txd);
2498
2499 return;
2500
2501fail:
Ben Hutchings48ce5632013-11-01 16:42:44 +00002502 netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n",
2503 tx_queue->queue);
Ben Hutchings8127d662013-08-29 19:19:29 +01002504}
2505
2506static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue)
2507{
2508 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002509 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01002510 struct efx_nic *efx = tx_queue->efx;
2511 size_t outlen;
2512 int rc;
2513
2514 MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE,
2515 tx_queue->queue);
2516
Edward Cree1e0b8122013-05-31 18:36:12 +01002517 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01002518 outbuf, sizeof(outbuf), &outlen);
2519
2520 if (rc && rc != -EALREADY)
2521 goto fail;
2522
2523 return;
2524
2525fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01002526 efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN,
2527 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01002528}
2529
2530static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue)
2531{
2532 efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf);
2533}
2534
2535/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
2536static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue)
2537{
2538 unsigned int write_ptr;
2539 efx_dword_t reg;
2540
2541 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2542 EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr);
2543 efx_writed_page(tx_queue->efx, &reg,
2544 ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue);
2545}
2546
Bert Kenwarde9117e52016-11-17 10:51:54 +00002547#define EFX_EF10_MAX_TX_DESCRIPTOR_LEN 0x3fff
2548
2549static unsigned int efx_ef10_tx_limit_len(struct efx_tx_queue *tx_queue,
2550 dma_addr_t dma_addr, unsigned int len)
2551{
2552 if (len > EFX_EF10_MAX_TX_DESCRIPTOR_LEN) {
2553 /* If we need to break across multiple descriptors we should
2554 * stop at a page boundary. This assumes the length limit is
2555 * greater than the page size.
2556 */
2557 dma_addr_t end = dma_addr + EFX_EF10_MAX_TX_DESCRIPTOR_LEN;
2558
2559 BUILD_BUG_ON(EFX_EF10_MAX_TX_DESCRIPTOR_LEN < EFX_PAGE_SIZE);
2560 len = (end & (~(EFX_PAGE_SIZE - 1))) - dma_addr;
2561 }
2562
2563 return len;
2564}
2565
Ben Hutchings8127d662013-08-29 19:19:29 +01002566static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue)
2567{
2568 unsigned int old_write_count = tx_queue->write_count;
2569 struct efx_tx_buffer *buffer;
2570 unsigned int write_ptr;
2571 efx_qword_t *txd;
2572
Martin Habetsb2663a42015-11-02 12:51:31 +00002573 tx_queue->xmit_more_available = false;
2574 if (unlikely(tx_queue->write_count == tx_queue->insert_count))
2575 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01002576
2577 do {
2578 write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
2579 buffer = &tx_queue->buffer[write_ptr];
2580 txd = efx_tx_desc(tx_queue, write_ptr);
2581 ++tx_queue->write_count;
2582
2583 /* Create TX descriptor ring entry */
2584 if (buffer->flags & EFX_TX_BUF_OPTION) {
2585 *txd = buffer->option;
Edward Creede1deff2017-01-13 21:20:14 +00002586 if (EFX_QWORD_FIELD(*txd, ESF_DZ_TX_OPTION_TYPE) == 1)
2587 /* PIO descriptor */
2588 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002589 } else {
Edward Creede1deff2017-01-13 21:20:14 +00002590 tx_queue->packet_write_count = tx_queue->write_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01002591 BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
2592 EFX_POPULATE_QWORD_3(
2593 *txd,
2594 ESF_DZ_TX_KER_CONT,
2595 buffer->flags & EFX_TX_BUF_CONT,
2596 ESF_DZ_TX_KER_BYTE_CNT, buffer->len,
2597 ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr);
2598 }
2599 } while (tx_queue->write_count != tx_queue->insert_count);
2600
2601 wmb(); /* Ensure descriptors are written before they are fetched */
2602
2603 if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
2604 txd = efx_tx_desc(tx_queue,
2605 old_write_count & tx_queue->ptr_mask);
2606 efx_ef10_push_tx_desc(tx_queue, txd);
2607 ++tx_queue->pushes;
2608 } else {
2609 efx_ef10_notify_tx_desc(tx_queue);
2610 }
2611}
2612
Edward Creea33a4c72016-11-03 22:12:27 +00002613#define RSS_MODE_HASH_ADDRS (1 << RSS_MODE_HASH_SRC_ADDR_LBN |\
2614 1 << RSS_MODE_HASH_DST_ADDR_LBN)
2615#define RSS_MODE_HASH_PORTS (1 << RSS_MODE_HASH_SRC_PORT_LBN |\
2616 1 << RSS_MODE_HASH_DST_PORT_LBN)
2617#define RSS_CONTEXT_FLAGS_DEFAULT (1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV4_EN_LBN |\
2618 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV4_EN_LBN |\
2619 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_IPV6_EN_LBN |\
2620 1 << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TOEPLITZ_TCPV6_EN_LBN |\
2621 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV4_RSS_MODE_LBN |\
2622 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN |\
2623 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV4_RSS_MODE_LBN |\
2624 (RSS_MODE_HASH_ADDRS | RSS_MODE_HASH_PORTS) << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_TCP_IPV6_RSS_MODE_LBN |\
2625 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN |\
2626 RSS_MODE_HASH_ADDRS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_OTHER_IPV6_RSS_MODE_LBN)
2627
2628static int efx_ef10_get_rss_flags(struct efx_nic *efx, u32 context, u32 *flags)
2629{
2630 /* Firmware had a bug (sfc bug 61952) where it would not actually
2631 * fill in the flags field in the response to MC_CMD_RSS_CONTEXT_GET_FLAGS.
2632 * This meant that it would always contain whatever was previously
2633 * in the MCDI buffer. Fortunately, all firmware versions with
2634 * this bug have the same default flags value for a newly-allocated
2635 * RSS context, and the only time we want to get the flags is just
2636 * after allocating. Moreover, the response has a 32-bit hole
2637 * where the context ID would be in the request, so we can use an
2638 * overlength buffer in the request and pre-fill the flags field
2639 * with what we believe the default to be. Thus if the firmware
2640 * has the bug, it will leave our pre-filled value in the flags
2641 * field of the response, and we will get the right answer.
2642 *
2643 * However, this does mean that this function should NOT be used if
2644 * the RSS context flags might not be their defaults - it is ONLY
2645 * reliably correct for a newly-allocated RSS context.
2646 */
2647 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2648 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN);
2649 size_t outlen;
2650 int rc;
2651
2652 /* Check we have a hole for the context ID */
2653 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_FLAGS_IN_LEN != MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_FLAGS_OFST);
2654 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_IN_RSS_CONTEXT_ID, context);
2655 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS,
2656 RSS_CONTEXT_FLAGS_DEFAULT);
2657 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_FLAGS, inbuf,
2658 sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
2659 if (rc == 0) {
2660 if (outlen < MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_LEN)
2661 rc = -EIO;
2662 else
2663 *flags = MCDI_DWORD(outbuf, RSS_CONTEXT_GET_FLAGS_OUT_FLAGS);
2664 }
2665 return rc;
2666}
2667
2668/* Attempt to enable 4-tuple UDP hashing on the specified RSS context.
2669 * If we fail, we just leave the RSS context at its default hash settings,
2670 * which is safe but may slightly reduce performance.
2671 * Defaults are 4-tuple for TCP and 2-tuple for UDP and other-IP, so we
2672 * just need to set the UDP ports flags (for both IP versions).
2673 */
2674static void efx_ef10_set_rss_flags(struct efx_nic *efx, u32 context)
2675{
2676 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_SET_FLAGS_IN_LEN);
2677 u32 flags;
2678
2679 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_SET_FLAGS_OUT_LEN != 0);
2680
2681 if (efx_ef10_get_rss_flags(efx, context, &flags) != 0)
2682 return;
2683 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_RSS_CONTEXT_ID, context);
2684 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV4_RSS_MODE_LBN;
2685 flags |= RSS_MODE_HASH_PORTS << MC_CMD_RSS_CONTEXT_GET_FLAGS_OUT_UDP_IPV6_RSS_MODE_LBN;
2686 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_SET_FLAGS_IN_FLAGS, flags);
Edward Creeb718c882016-11-03 22:12:58 +00002687 if (!efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_FLAGS, inbuf, sizeof(inbuf),
2688 NULL, 0, NULL))
2689 /* Succeeded, so UDP 4-tuple is now enabled */
2690 efx->rx_hash_udp_4tuple = true;
Edward Creea33a4c72016-11-03 22:12:27 +00002691}
2692
Jon Cooper267c0152015-05-06 00:59:38 +01002693static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context,
2694 bool exclusive, unsigned *context_size)
Ben Hutchings8127d662013-08-29 19:19:29 +01002695{
2696 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN);
2697 MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN);
Daniel Pieczko45b24492015-05-06 00:57:14 +01002698 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01002699 size_t outlen;
2700 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002701 u32 alloc_type = exclusive ?
2702 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE :
2703 MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED;
2704 unsigned rss_spread = exclusive ?
2705 efx->rss_spread :
2706 min(rounddown_pow_of_two(efx->rss_spread),
2707 EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE);
2708
2709 if (!exclusive && rss_spread == 1) {
2710 *context = EFX_EF10_RSS_CONTEXT_INVALID;
2711 if (context_size)
2712 *context_size = 1;
2713 return 0;
2714 }
Ben Hutchings8127d662013-08-29 19:19:29 +01002715
Jon Cooperdcb41232016-04-25 16:51:00 +01002716 if (nic_data->datapath_caps &
2717 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_RSS_LIMITED_LBN)
2718 return -EOPNOTSUPP;
2719
Ben Hutchings8127d662013-08-29 19:19:29 +01002720 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID,
Daniel Pieczko45b24492015-05-06 00:57:14 +01002721 nic_data->vport_id);
Jon Cooper267c0152015-05-06 00:59:38 +01002722 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type);
2723 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread);
Ben Hutchings8127d662013-08-29 19:19:29 +01002724
2725 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf),
2726 outbuf, sizeof(outbuf), &outlen);
2727 if (rc != 0)
2728 return rc;
2729
2730 if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN)
2731 return -EIO;
2732
2733 *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID);
2734
Jon Cooper267c0152015-05-06 00:59:38 +01002735 if (context_size)
2736 *context_size = rss_spread;
2737
Edward Creea33a4c72016-11-03 22:12:27 +00002738 if (nic_data->datapath_caps &
2739 1 << MC_CMD_GET_CAPABILITIES_OUT_ADDITIONAL_RSS_MODES_LBN)
2740 efx_ef10_set_rss_flags(efx, *context);
2741
Ben Hutchings8127d662013-08-29 19:19:29 +01002742 return 0;
2743}
2744
2745static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context)
2746{
2747 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN);
2748 int rc;
2749
2750 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID,
2751 context);
2752
2753 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf),
2754 NULL, 0, NULL);
2755 WARN_ON(rc != 0);
2756}
2757
Jon Cooper267c0152015-05-06 00:59:38 +01002758static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context,
Edward Creef74d1992017-01-17 12:01:53 +00002759 const u32 *rx_indir_table, const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002760{
2761 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN);
2762 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN);
2763 int i, rc;
2764
2765 MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID,
2766 context);
2767 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2768 MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN);
2769
Edward Creef74d1992017-01-17 12:01:53 +00002770 /* This iterates over the length of efx->rx_indir_table, but copies
2771 * bytes from rx_indir_table. That's because the latter is a pointer
2772 * rather than an array, but should have the same length.
2773 * The efx->rx_hash_key loop below is similar.
2774 */
Ben Hutchings8127d662013-08-29 19:19:29 +01002775 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i)
2776 MCDI_PTR(tablebuf,
2777 RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] =
Jon Cooper267c0152015-05-06 00:59:38 +01002778 (u8) rx_indir_table[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002779
2780 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf,
2781 sizeof(tablebuf), NULL, 0, NULL);
2782 if (rc != 0)
2783 return rc;
2784
2785 MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID,
2786 context);
2787 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2788 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2789 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
Edward Creef74d1992017-01-17 12:01:53 +00002790 MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = key[i];
Ben Hutchings8127d662013-08-29 19:19:29 +01002791
2792 return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf,
2793 sizeof(keybuf), NULL, 0, NULL);
2794}
2795
2796static void efx_ef10_rx_free_indir_table(struct efx_nic *efx)
2797{
2798 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2799
2800 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2801 efx_ef10_free_rss_context(efx, nic_data->rx_rss_context);
2802 nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID;
2803}
2804
Jon Cooper267c0152015-05-06 00:59:38 +01002805static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx,
2806 unsigned *context_size)
2807{
2808 u32 new_rx_rss_context;
2809 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2810 int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2811 false, context_size);
2812
2813 if (rc != 0)
2814 return rc;
2815
2816 nic_data->rx_rss_context = new_rx_rss_context;
2817 nic_data->rx_rss_context_exclusive = false;
2818 efx_set_default_rx_indir_table(efx);
2819 return 0;
2820}
2821
2822static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx,
Edward Creef74d1992017-01-17 12:01:53 +00002823 const u32 *rx_indir_table,
2824 const u8 *key)
Ben Hutchings8127d662013-08-29 19:19:29 +01002825{
2826 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2827 int rc;
Jon Cooper267c0152015-05-06 00:59:38 +01002828 u32 new_rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002829
Jon Cooper267c0152015-05-06 00:59:38 +01002830 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID ||
2831 !nic_data->rx_rss_context_exclusive) {
2832 rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context,
2833 true, NULL);
2834 if (rc == -EOPNOTSUPP)
2835 return rc;
2836 else if (rc != 0)
2837 goto fail1;
2838 } else {
2839 new_rx_rss_context = nic_data->rx_rss_context;
Ben Hutchings8127d662013-08-29 19:19:29 +01002840 }
2841
Jon Cooper267c0152015-05-06 00:59:38 +01002842 rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context,
Edward Creef74d1992017-01-17 12:01:53 +00002843 rx_indir_table, key);
Ben Hutchings8127d662013-08-29 19:19:29 +01002844 if (rc != 0)
Jon Cooper267c0152015-05-06 00:59:38 +01002845 goto fail2;
Ben Hutchings8127d662013-08-29 19:19:29 +01002846
Jon Cooper267c0152015-05-06 00:59:38 +01002847 if (nic_data->rx_rss_context != new_rx_rss_context)
2848 efx_ef10_rx_free_indir_table(efx);
2849 nic_data->rx_rss_context = new_rx_rss_context;
2850 nic_data->rx_rss_context_exclusive = true;
2851 if (rx_indir_table != efx->rx_indir_table)
2852 memcpy(efx->rx_indir_table, rx_indir_table,
2853 sizeof(efx->rx_indir_table));
Edward Creef74d1992017-01-17 12:01:53 +00002854 if (key != efx->rx_hash_key)
2855 memcpy(efx->rx_hash_key, key, efx->type->rx_hash_key_size);
2856
Jon Cooper267c0152015-05-06 00:59:38 +01002857 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01002858
Jon Cooper267c0152015-05-06 00:59:38 +01002859fail2:
2860 if (new_rx_rss_context != nic_data->rx_rss_context)
2861 efx_ef10_free_rss_context(efx, new_rx_rss_context);
2862fail1:
Ben Hutchings8127d662013-08-29 19:19:29 +01002863 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
Jon Cooper267c0152015-05-06 00:59:38 +01002864 return rc;
2865}
2866
Edward Creea707d182017-01-17 12:02:12 +00002867static int efx_ef10_rx_pull_rss_config(struct efx_nic *efx)
2868{
2869 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2870 MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN);
2871 MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN);
2872 MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN);
2873 size_t outlen;
2874 int rc, i;
2875
2876 BUILD_BUG_ON(MC_CMD_RSS_CONTEXT_GET_TABLE_IN_LEN !=
2877 MC_CMD_RSS_CONTEXT_GET_KEY_IN_LEN);
2878
2879 if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
2880 return -ENOENT;
2881
2882 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_TABLE_IN_RSS_CONTEXT_ID,
2883 nic_data->rx_rss_context);
2884 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
2885 MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE_LEN);
2886 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_TABLE, inbuf, sizeof(inbuf),
2887 tablebuf, sizeof(tablebuf), &outlen);
2888 if (rc != 0)
2889 return rc;
2890
2891 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_TABLE_OUT_LEN))
2892 return -EIO;
2893
2894 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
2895 efx->rx_indir_table[i] = MCDI_PTR(tablebuf,
2896 RSS_CONTEXT_GET_TABLE_OUT_INDIRECTION_TABLE)[i];
2897
2898 MCDI_SET_DWORD(inbuf, RSS_CONTEXT_GET_KEY_IN_RSS_CONTEXT_ID,
2899 nic_data->rx_rss_context);
2900 BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) !=
2901 MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN);
2902 rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_GET_KEY, inbuf, sizeof(inbuf),
2903 keybuf, sizeof(keybuf), &outlen);
2904 if (rc != 0)
2905 return rc;
2906
2907 if (WARN_ON(outlen != MC_CMD_RSS_CONTEXT_GET_KEY_OUT_LEN))
2908 return -EIO;
2909
2910 for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i)
2911 efx->rx_hash_key[i] = MCDI_PTR(
2912 keybuf, RSS_CONTEXT_GET_KEY_OUT_TOEPLITZ_KEY)[i];
2913
2914 return 0;
2915}
2916
Jon Cooper267c0152015-05-06 00:59:38 +01002917static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user,
Edward Creef74d1992017-01-17 12:01:53 +00002918 const u32 *rx_indir_table,
2919 const u8 *key)
Jon Cooper267c0152015-05-06 00:59:38 +01002920{
2921 int rc;
2922
2923 if (efx->rss_spread == 1)
2924 return 0;
2925
Edward Creef74d1992017-01-17 12:01:53 +00002926 if (!key)
2927 key = efx->rx_hash_key;
2928
2929 rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table, key);
Jon Cooper267c0152015-05-06 00:59:38 +01002930
2931 if (rc == -ENOBUFS && !user) {
2932 unsigned context_size;
2933 bool mismatch = false;
2934 size_t i;
2935
2936 for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch;
2937 i++)
2938 mismatch = rx_indir_table[i] !=
2939 ethtool_rxfh_indir_default(i, efx->rss_spread);
2940
2941 rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size);
2942 if (rc == 0) {
2943 if (context_size != efx->rss_spread)
2944 netif_warn(efx, probe, efx->net_dev,
2945 "Could not allocate an exclusive RSS"
2946 " context; allocated a shared one of"
2947 " different size."
2948 " Wanted %u, got %u.\n",
2949 efx->rss_spread, context_size);
2950 else if (mismatch)
2951 netif_warn(efx, probe, efx->net_dev,
2952 "Could not allocate an exclusive RSS"
2953 " context; allocated a shared one but"
2954 " could not apply custom"
2955 " indirection.\n");
2956 else
2957 netif_info(efx, probe, efx->net_dev,
2958 "Could not allocate an exclusive RSS"
2959 " context; allocated a shared one.\n");
2960 }
2961 }
2962 return rc;
2963}
2964
2965static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user,
2966 const u32 *rx_indir_table
Edward Creef74d1992017-01-17 12:01:53 +00002967 __attribute__ ((unused)),
2968 const u8 *key
Jon Cooper267c0152015-05-06 00:59:38 +01002969 __attribute__ ((unused)))
2970{
2971 struct efx_ef10_nic_data *nic_data = efx->nic_data;
2972
2973 if (user)
2974 return -EOPNOTSUPP;
2975 if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID)
2976 return 0;
2977 return efx_ef10_rx_push_shared_rss_config(efx, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01002978}
2979
2980static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue)
2981{
2982 return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf,
2983 (rx_queue->ptr_mask + 1) *
2984 sizeof(efx_qword_t),
2985 GFP_KERNEL);
2986}
2987
2988static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue)
2989{
2990 MCDI_DECLARE_BUF(inbuf,
2991 MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 /
2992 EFX_BUF_SIZE));
Ben Hutchings8127d662013-08-29 19:19:29 +01002993 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
2994 size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE;
2995 struct efx_nic *efx = rx_queue->efx;
Daniel Pieczko45b24492015-05-06 00:57:14 +01002996 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01002997 size_t inlen;
Ben Hutchings8127d662013-08-29 19:19:29 +01002998 dma_addr_t dma_addr;
2999 int rc;
3000 int i;
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003001 BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01003002
3003 rx_queue->scatter_n = 0;
3004 rx_queue->scatter_len = 0;
3005
3006 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1);
3007 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel);
3008 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue));
3009 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE,
3010 efx_rx_queue_index(rx_queue));
Jon Cooperbd9a2652013-11-18 12:54:41 +00003011 MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS,
3012 INIT_RXQ_IN_FLAG_PREFIX, 1,
3013 INIT_RXQ_IN_FLAG_TIMESTAMP, 1);
Ben Hutchings8127d662013-08-29 19:19:29 +01003014 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0);
Daniel Pieczko45b24492015-05-06 00:57:14 +01003015 MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01003016
3017 dma_addr = rx_queue->rxd.buf.dma_addr;
3018
3019 netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n",
3020 efx_rx_queue_index(rx_queue), entries, (u64)dma_addr);
3021
3022 for (i = 0; i < entries; ++i) {
3023 MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr);
3024 dma_addr += EFX_BUF_SIZE;
3025 }
3026
3027 inlen = MC_CMD_INIT_RXQ_IN_LEN(entries);
3028
3029 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen,
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003030 NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00003031 if (rc)
3032 netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n",
3033 efx_rx_queue_index(rx_queue));
Ben Hutchings8127d662013-08-29 19:19:29 +01003034}
3035
3036static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue)
3037{
3038 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN);
Jon Cooperaa09a3d2015-05-20 11:10:41 +01003039 MCDI_DECLARE_BUF_ERR(outbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01003040 struct efx_nic *efx = rx_queue->efx;
3041 size_t outlen;
3042 int rc;
3043
3044 MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE,
3045 efx_rx_queue_index(rx_queue));
3046
Edward Cree1e0b8122013-05-31 18:36:12 +01003047 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf),
Ben Hutchings8127d662013-08-29 19:19:29 +01003048 outbuf, sizeof(outbuf), &outlen);
3049
3050 if (rc && rc != -EALREADY)
3051 goto fail;
3052
3053 return;
3054
3055fail:
Edward Cree1e0b8122013-05-31 18:36:12 +01003056 efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN,
3057 outbuf, outlen, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01003058}
3059
3060static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue)
3061{
3062 efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf);
3063}
3064
3065/* This creates an entry in the RX descriptor queue */
3066static inline void
3067efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
3068{
3069 struct efx_rx_buffer *rx_buf;
3070 efx_qword_t *rxd;
3071
3072 rxd = efx_rx_desc(rx_queue, index);
3073 rx_buf = efx_rx_buffer(rx_queue, index);
3074 EFX_POPULATE_QWORD_2(*rxd,
3075 ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len,
3076 ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
3077}
3078
3079static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue)
3080{
3081 struct efx_nic *efx = rx_queue->efx;
3082 unsigned int write_count;
3083 efx_dword_t reg;
3084
3085 /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */
3086 write_count = rx_queue->added_count & ~7;
3087 if (rx_queue->notified_count == write_count)
3088 return;
3089
3090 do
3091 efx_ef10_build_rx_desc(
3092 rx_queue,
3093 rx_queue->notified_count & rx_queue->ptr_mask);
3094 while (++rx_queue->notified_count != write_count);
3095
3096 wmb();
3097 EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR,
3098 write_count & rx_queue->ptr_mask);
3099 efx_writed_page(efx, &reg, ER_DZ_RX_DESC_UPD,
3100 efx_rx_queue_index(rx_queue));
3101}
3102
3103static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete;
3104
3105static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue)
3106{
3107 struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
3108 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3109 efx_qword_t event;
3110
3111 EFX_POPULATE_QWORD_2(event,
3112 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3113 ESF_DZ_EV_DATA, EFX_EF10_REFILL);
3114
3115 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3116
3117 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3118 * already swapped the data to little-endian order.
3119 */
3120 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3121 sizeof(efx_qword_t));
3122
3123 efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT,
3124 inbuf, sizeof(inbuf), 0,
3125 efx_ef10_rx_defer_refill_complete, 0);
3126}
3127
3128static void
3129efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie,
3130 int rc, efx_dword_t *outbuf,
3131 size_t outlen_actual)
3132{
3133 /* nothing to do */
3134}
3135
3136static int efx_ef10_ev_probe(struct efx_channel *channel)
3137{
3138 return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf,
3139 (channel->eventq_mask + 1) *
3140 sizeof(efx_qword_t),
3141 GFP_KERNEL);
3142}
3143
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003144static void efx_ef10_ev_fini(struct efx_channel *channel)
3145{
3146 MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN);
3147 MCDI_DECLARE_BUF_ERR(outbuf);
3148 struct efx_nic *efx = channel->efx;
3149 size_t outlen;
3150 int rc;
3151
3152 MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel);
3153
3154 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf),
3155 outbuf, sizeof(outbuf), &outlen);
3156
3157 if (rc && rc != -EALREADY)
3158 goto fail;
3159
3160 return;
3161
3162fail:
3163 efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN,
3164 outbuf, outlen, rc);
3165}
3166
Ben Hutchings8127d662013-08-29 19:19:29 +01003167static int efx_ef10_ev_init(struct efx_channel *channel)
3168{
3169 MCDI_DECLARE_BUF(inbuf,
Bert Kenwarda9955602016-08-11 13:01:54 +01003170 MC_CMD_INIT_EVQ_V2_IN_LEN(EFX_MAX_EVQ_SIZE * 8 /
3171 EFX_BUF_SIZE));
3172 MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_V2_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01003173 size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE;
3174 struct efx_nic *efx = channel->efx;
3175 struct efx_ef10_nic_data *nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003176 size_t inlen, outlen;
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003177 unsigned int enabled, implemented;
Ben Hutchings8127d662013-08-29 19:19:29 +01003178 dma_addr_t dma_addr;
3179 int rc;
3180 int i;
3181
3182 nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003183
3184 /* Fill event queue with all ones (i.e. empty events) */
3185 memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
3186
3187 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1);
3188 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel);
3189 /* INIT_EVQ expects index in vector table, not absolute */
3190 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel);
Ben Hutchings8127d662013-08-29 19:19:29 +01003191 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE,
3192 MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS);
3193 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0);
3194 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0);
3195 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE,
3196 MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS);
3197 MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0);
3198
Bert Kenwarda9955602016-08-11 13:01:54 +01003199 if (nic_data->datapath_caps2 &
3200 1 << MC_CMD_GET_CAPABILITIES_V2_OUT_INIT_EVQ_V2_LBN) {
3201 /* Use the new generic approach to specifying event queue
3202 * configuration, requesting lower latency or higher throughput.
3203 * The options that actually get used appear in the output.
3204 */
3205 MCDI_POPULATE_DWORD_2(inbuf, INIT_EVQ_V2_IN_FLAGS,
3206 INIT_EVQ_V2_IN_FLAG_INTERRUPTING, 1,
3207 INIT_EVQ_V2_IN_FLAG_TYPE,
3208 MC_CMD_INIT_EVQ_V2_IN_FLAG_TYPE_AUTO);
3209 } else {
3210 bool cut_thru = !(nic_data->datapath_caps &
3211 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN);
3212
3213 MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS,
3214 INIT_EVQ_IN_FLAG_INTERRUPTING, 1,
3215 INIT_EVQ_IN_FLAG_RX_MERGE, 1,
3216 INIT_EVQ_IN_FLAG_TX_MERGE, 1,
3217 INIT_EVQ_IN_FLAG_CUT_THRU, cut_thru);
3218 }
3219
Ben Hutchings8127d662013-08-29 19:19:29 +01003220 dma_addr = channel->eventq.buf.dma_addr;
3221 for (i = 0; i < entries; ++i) {
3222 MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr);
3223 dma_addr += EFX_BUF_SIZE;
3224 }
3225
3226 inlen = MC_CMD_INIT_EVQ_IN_LEN(entries);
3227
3228 rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen,
3229 outbuf, sizeof(outbuf), &outlen);
Bert Kenwarda9955602016-08-11 13:01:54 +01003230
3231 if (outlen >= MC_CMD_INIT_EVQ_V2_OUT_LEN)
3232 netif_dbg(efx, drv, efx->net_dev,
3233 "Channel %d using event queue flags %08x\n",
3234 channel->channel,
3235 MCDI_DWORD(outbuf, INIT_EVQ_V2_OUT_FLAGS));
3236
Ben Hutchings8127d662013-08-29 19:19:29 +01003237 /* IRQ return is ignored */
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003238 if (channel->channel || rc)
3239 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003240
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003241 /* Successfully created event queue on channel 0 */
3242 rc = efx_mcdi_get_workarounds(efx, &implemented, &enabled);
Edward Cree832dc9e2015-07-21 15:09:31 +01003243 if (rc == -ENOSYS) {
Bert Kenwardd95e3292016-08-11 13:02:36 +01003244 /* GET_WORKAROUNDS was implemented before this workaround,
3245 * thus it must be unavailable in this firmware.
Edward Cree832dc9e2015-07-21 15:09:31 +01003246 */
3247 nic_data->workaround_26807 = false;
3248 rc = 0;
3249 } else if (rc) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003250 goto fail;
Edward Cree832dc9e2015-07-21 15:09:31 +01003251 } else {
3252 nic_data->workaround_26807 =
3253 !!(enabled & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807);
Ben Hutchings8127d662013-08-29 19:19:29 +01003254
Edward Cree832dc9e2015-07-21 15:09:31 +01003255 if (implemented & MC_CMD_GET_WORKAROUNDS_OUT_BUG26807 &&
3256 !nic_data->workaround_26807) {
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003257 unsigned int flags;
3258
Daniel Pieczko34ccfe62015-07-21 15:09:43 +01003259 rc = efx_mcdi_set_workaround(efx,
3260 MC_CMD_WORKAROUND_BUG26807,
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003261 true, &flags);
3262
3263 if (!rc) {
3264 if (flags &
3265 1 << MC_CMD_WORKAROUND_EXT_OUT_FLR_DONE_LBN) {
3266 netif_info(efx, drv, efx->net_dev,
3267 "other functions on NIC have been reset\n");
Daniel Pieczkoabd86a52015-12-04 08:48:39 +00003268
3269 /* With MCFW v4.6.x and earlier, the
3270 * boot count will have incremented,
3271 * so re-read the warm_boot_count
3272 * value now to ensure this function
3273 * doesn't think it has changed next
3274 * time it checks.
3275 */
3276 rc = efx_ef10_get_warm_boot_count(efx);
3277 if (rc >= 0) {
3278 nic_data->warm_boot_count = rc;
3279 rc = 0;
3280 }
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003281 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003282 nic_data->workaround_26807 = true;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003283 } else if (rc == -EPERM) {
Edward Cree832dc9e2015-07-21 15:09:31 +01003284 rc = 0;
Daniel Pieczko5a55a722015-07-21 15:10:02 +01003285 }
Edward Cree832dc9e2015-07-21 15:09:31 +01003286 }
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003287 }
3288
3289 if (!rc)
3290 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01003291
3292fail:
Daniel Pieczko46e612b2015-07-21 15:09:18 +01003293 efx_ef10_ev_fini(channel);
3294 return rc;
Ben Hutchings8127d662013-08-29 19:19:29 +01003295}
3296
3297static void efx_ef10_ev_remove(struct efx_channel *channel)
3298{
3299 efx_nic_free_buffer(channel->efx, &channel->eventq.buf);
3300}
3301
3302static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue,
3303 unsigned int rx_queue_label)
3304{
3305 struct efx_nic *efx = rx_queue->efx;
3306
3307 netif_info(efx, hw, efx->net_dev,
3308 "rx event arrived on queue %d labeled as queue %u\n",
3309 efx_rx_queue_index(rx_queue), rx_queue_label);
3310
3311 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3312}
3313
3314static void
3315efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue,
3316 unsigned int actual, unsigned int expected)
3317{
3318 unsigned int dropped = (actual - expected) & rx_queue->ptr_mask;
3319 struct efx_nic *efx = rx_queue->efx;
3320
3321 netif_info(efx, hw, efx->net_dev,
3322 "dropped %d events (index=%d expected=%d)\n",
3323 dropped, actual, expected);
3324
3325 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
3326}
3327
3328/* partially received RX was aborted. clean up. */
3329static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue)
3330{
3331 unsigned int rx_desc_ptr;
3332
Ben Hutchings8127d662013-08-29 19:19:29 +01003333 netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev,
3334 "scattered RX aborted (dropping %u buffers)\n",
3335 rx_queue->scatter_n);
3336
3337 rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
3338
3339 efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n,
3340 0, EFX_RX_PKT_DISCARD);
3341
3342 rx_queue->removed_count += rx_queue->scatter_n;
3343 rx_queue->scatter_n = 0;
3344 rx_queue->scatter_len = 0;
3345 ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc;
3346}
3347
Jon Coopera0ee3542017-02-08 16:50:40 +00003348static u16 efx_ef10_handle_rx_event_errors(struct efx_channel *channel,
3349 unsigned int n_packets,
3350 unsigned int rx_encap_hdr,
3351 unsigned int rx_l3_class,
3352 unsigned int rx_l4_class,
3353 const efx_qword_t *event)
3354{
3355 struct efx_nic *efx = channel->efx;
Edward Cree69787292017-10-31 14:29:47 +00003356 bool handled = false;
Jon Coopera0ee3542017-02-08 16:50:40 +00003357
3358 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR)) {
Edward Cree69787292017-10-31 14:29:47 +00003359 if (!(efx->net_dev->features & NETIF_F_RXALL)) {
3360 if (!efx->loopback_selftest)
3361 channel->n_rx_eth_crc_err += n_packets;
3362 return EFX_RX_PKT_DISCARD;
3363 }
3364 handled = true;
Jon Coopera0ee3542017-02-08 16:50:40 +00003365 }
3366 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR)) {
3367 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3368 rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3369 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3370 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3371 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3372 netdev_WARN(efx->net_dev,
3373 "invalid class for RX_IPCKSUM_ERR: event="
3374 EFX_QWORD_FMT "\n",
3375 EFX_QWORD_VAL(*event));
3376 if (!efx->loopback_selftest)
3377 *(rx_encap_hdr ?
3378 &channel->n_rx_outer_ip_hdr_chksum_err :
3379 &channel->n_rx_ip_hdr_chksum_err) += n_packets;
3380 return 0;
3381 }
3382 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_TCPUDP_CKSUM_ERR)) {
3383 if (unlikely(rx_encap_hdr != ESE_EZ_ENCAP_HDR_VXLAN &&
3384 ((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3385 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003386 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3387 rx_l4_class != ESE_FZ_L4_CLASS_UDP))))
Jon Coopera0ee3542017-02-08 16:50:40 +00003388 netdev_WARN(efx->net_dev,
3389 "invalid class for RX_TCPUDP_CKSUM_ERR: event="
3390 EFX_QWORD_FMT "\n",
3391 EFX_QWORD_VAL(*event));
3392 if (!efx->loopback_selftest)
3393 *(rx_encap_hdr ?
3394 &channel->n_rx_outer_tcp_udp_chksum_err :
3395 &channel->n_rx_tcp_udp_chksum_err) += n_packets;
3396 return 0;
3397 }
3398 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_IP_INNER_CHKSUM_ERR)) {
3399 if (unlikely(!rx_encap_hdr))
3400 netdev_WARN(efx->net_dev,
3401 "invalid encapsulation type for RX_IP_INNER_CHKSUM_ERR: event="
3402 EFX_QWORD_FMT "\n",
3403 EFX_QWORD_VAL(*event));
3404 else if (unlikely(rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3405 rx_l3_class != ESE_DZ_L3_CLASS_IP4_FRAG &&
3406 rx_l3_class != ESE_DZ_L3_CLASS_IP6 &&
3407 rx_l3_class != ESE_DZ_L3_CLASS_IP6_FRAG))
3408 netdev_WARN(efx->net_dev,
3409 "invalid class for RX_IP_INNER_CHKSUM_ERR: event="
3410 EFX_QWORD_FMT "\n",
3411 EFX_QWORD_VAL(*event));
3412 if (!efx->loopback_selftest)
3413 channel->n_rx_inner_ip_hdr_chksum_err += n_packets;
3414 return 0;
3415 }
3416 if (EFX_QWORD_FIELD(*event, ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR)) {
3417 if (unlikely(!rx_encap_hdr))
3418 netdev_WARN(efx->net_dev,
3419 "invalid encapsulation type for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3420 EFX_QWORD_FMT "\n",
3421 EFX_QWORD_VAL(*event));
3422 else if (unlikely((rx_l3_class != ESE_DZ_L3_CLASS_IP4 &&
3423 rx_l3_class != ESE_DZ_L3_CLASS_IP6) ||
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003424 (rx_l4_class != ESE_FZ_L4_CLASS_TCP &&
3425 rx_l4_class != ESE_FZ_L4_CLASS_UDP)))
Jon Coopera0ee3542017-02-08 16:50:40 +00003426 netdev_WARN(efx->net_dev,
3427 "invalid class for RX_TCP_UDP_INNER_CHKSUM_ERR: event="
3428 EFX_QWORD_FMT "\n",
3429 EFX_QWORD_VAL(*event));
3430 if (!efx->loopback_selftest)
3431 channel->n_rx_inner_tcp_udp_chksum_err += n_packets;
3432 return 0;
3433 }
3434
Edward Cree69787292017-10-31 14:29:47 +00003435 WARN_ON(!handled); /* No error bits were recognised */
Jon Coopera0ee3542017-02-08 16:50:40 +00003436 return 0;
3437}
3438
Ben Hutchings8127d662013-08-29 19:19:29 +01003439static int efx_ef10_handle_rx_event(struct efx_channel *channel,
3440 const efx_qword_t *event)
3441{
Jon Coopera0ee3542017-02-08 16:50:40 +00003442 unsigned int rx_bytes, next_ptr_lbits, rx_queue_label;
3443 unsigned int rx_l3_class, rx_l4_class, rx_encap_hdr;
Ben Hutchings8127d662013-08-29 19:19:29 +01003444 unsigned int n_descs, n_packets, i;
3445 struct efx_nic *efx = channel->efx;
Jon Coopera0ee3542017-02-08 16:50:40 +00003446 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Ben Hutchings8127d662013-08-29 19:19:29 +01003447 struct efx_rx_queue *rx_queue;
Jon Coopera0ee3542017-02-08 16:50:40 +00003448 efx_qword_t errors;
Ben Hutchings8127d662013-08-29 19:19:29 +01003449 bool rx_cont;
3450 u16 flags = 0;
3451
Mark Rutland6aa7de02017-10-23 14:07:29 -07003452 if (unlikely(READ_ONCE(efx->reset_pending)))
Ben Hutchings8127d662013-08-29 19:19:29 +01003453 return 0;
3454
3455 /* Basic packet information */
3456 rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES);
3457 next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS);
3458 rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL);
Jon Coopera0ee3542017-02-08 16:50:40 +00003459 rx_l3_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L3_CLASS);
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003460 rx_l4_class = EFX_QWORD_FIELD(*event, ESF_FZ_RX_L4_CLASS);
Ben Hutchings8127d662013-08-29 19:19:29 +01003461 rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT);
Jon Coopera0ee3542017-02-08 16:50:40 +00003462 rx_encap_hdr =
3463 nic_data->datapath_caps &
3464 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN) ?
3465 EFX_QWORD_FIELD(*event, ESF_EZ_RX_ENCAP_HDR) :
3466 ESE_EZ_ENCAP_HDR_NONE;
Ben Hutchings8127d662013-08-29 19:19:29 +01003467
Ben Hutchings48ce5632013-11-01 16:42:44 +00003468 if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT))
3469 netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event="
3470 EFX_QWORD_FMT "\n",
3471 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003472
3473 rx_queue = efx_channel_get_rx_queue(channel);
3474
3475 if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue)))
3476 efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label);
3477
3478 n_descs = ((next_ptr_lbits - rx_queue->removed_count) &
3479 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3480
3481 if (n_descs != rx_queue->scatter_n + 1) {
Ben Hutchings92a04162013-09-24 23:21:57 +01003482 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3483
Ben Hutchings8127d662013-08-29 19:19:29 +01003484 /* detect rx abort */
3485 if (unlikely(n_descs == rx_queue->scatter_n)) {
Ben Hutchings48ce5632013-11-01 16:42:44 +00003486 if (rx_queue->scatter_n == 0 || rx_bytes != 0)
3487 netdev_WARN(efx->net_dev,
3488 "invalid RX abort: scatter_n=%u event="
3489 EFX_QWORD_FMT "\n",
3490 rx_queue->scatter_n,
3491 EFX_QWORD_VAL(*event));
Ben Hutchings8127d662013-08-29 19:19:29 +01003492 efx_ef10_handle_rx_abort(rx_queue);
3493 return 0;
3494 }
3495
Ben Hutchings92a04162013-09-24 23:21:57 +01003496 /* Check that RX completion merging is valid, i.e.
3497 * the current firmware supports it and this is a
3498 * non-scattered packet.
3499 */
3500 if (!(nic_data->datapath_caps &
3501 (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) ||
3502 rx_queue->scatter_n != 0 || rx_cont) {
Ben Hutchings8127d662013-08-29 19:19:29 +01003503 efx_ef10_handle_rx_bad_lbits(
3504 rx_queue, next_ptr_lbits,
3505 (rx_queue->removed_count +
3506 rx_queue->scatter_n + 1) &
3507 ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1));
3508 return 0;
3509 }
3510
3511 /* Merged completion for multiple non-scattered packets */
3512 rx_queue->scatter_n = 1;
3513 rx_queue->scatter_len = 0;
3514 n_packets = n_descs;
3515 ++channel->n_rx_merge_events;
3516 channel->n_rx_merge_packets += n_packets;
3517 flags |= EFX_RX_PKT_PREFIX_LEN;
3518 } else {
3519 ++rx_queue->scatter_n;
3520 rx_queue->scatter_len += rx_bytes;
3521 if (rx_cont)
3522 return 0;
3523 n_packets = 1;
3524 }
3525
Jon Coopera0ee3542017-02-08 16:50:40 +00003526 EFX_POPULATE_QWORD_5(errors, ESF_DZ_RX_ECRC_ERR, 1,
3527 ESF_DZ_RX_IPCKSUM_ERR, 1,
3528 ESF_DZ_RX_TCPUDP_CKSUM_ERR, 1,
3529 ESF_EZ_RX_IP_INNER_CHKSUM_ERR, 1,
3530 ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR, 1);
3531 EFX_AND_QWORD(errors, *event, errors);
3532 if (unlikely(!EFX_QWORD_IS_ZERO(errors))) {
3533 flags |= efx_ef10_handle_rx_event_errors(channel, n_packets,
Edward Cree90d2ea92017-02-10 17:34:59 +00003534 rx_encap_hdr,
Jon Coopera0ee3542017-02-08 16:50:40 +00003535 rx_l3_class, rx_l4_class,
Edward Cree90d2ea92017-02-10 17:34:59 +00003536 event);
Jon Coopera0ee3542017-02-08 16:50:40 +00003537 } else {
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003538 bool tcpudp = rx_l4_class == ESE_FZ_L4_CLASS_TCP ||
3539 rx_l4_class == ESE_FZ_L4_CLASS_UDP;
Jon Cooperda50ae22017-02-08 16:51:02 +00003540
3541 switch (rx_encap_hdr) {
3542 case ESE_EZ_ENCAP_HDR_VXLAN: /* VxLAN or GENEVE */
3543 flags |= EFX_RX_PKT_CSUMMED; /* outer UDP csum */
3544 if (tcpudp)
3545 flags |= EFX_RX_PKT_CSUM_LEVEL; /* inner L4 */
3546 break;
3547 case ESE_EZ_ENCAP_HDR_GRE:
3548 case ESE_EZ_ENCAP_HDR_NONE:
3549 if (tcpudp)
3550 flags |= EFX_RX_PKT_CSUMMED;
3551 break;
3552 default:
3553 netdev_WARN(efx->net_dev,
3554 "unknown encapsulation type: event="
3555 EFX_QWORD_FMT "\n",
3556 EFX_QWORD_VAL(*event));
3557 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003558 }
3559
Bert Kenwardd8d8ccf2017-12-18 16:57:18 +00003560 if (rx_l4_class == ESE_FZ_L4_CLASS_TCP)
Ben Hutchings8127d662013-08-29 19:19:29 +01003561 flags |= EFX_RX_PKT_TCP;
3562
3563 channel->irq_mod_score += 2 * n_packets;
3564
3565 /* Handle received packet(s) */
3566 for (i = 0; i < n_packets; i++) {
3567 efx_rx_packet(rx_queue,
3568 rx_queue->removed_count & rx_queue->ptr_mask,
3569 rx_queue->scatter_n, rx_queue->scatter_len,
3570 flags);
3571 rx_queue->removed_count += rx_queue->scatter_n;
3572 }
3573
3574 rx_queue->scatter_n = 0;
3575 rx_queue->scatter_len = 0;
3576
3577 return n_packets;
3578}
3579
Martin Habetsb9b603d42018-01-25 17:24:43 +00003580static u32 efx_ef10_extract_event_ts(efx_qword_t *event)
3581{
3582 u32 tstamp;
3583
3584 tstamp = EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_HI);
3585 tstamp <<= 16;
3586 tstamp |= EFX_QWORD_FIELD(*event, TX_TIMESTAMP_EVENT_TSTAMP_DATA_LO);
3587
3588 return tstamp;
3589}
3590
Bert Kenward5227ecc2018-01-25 17:24:20 +00003591static void
Ben Hutchings8127d662013-08-29 19:19:29 +01003592efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
3593{
3594 struct efx_nic *efx = channel->efx;
3595 struct efx_tx_queue *tx_queue;
3596 unsigned int tx_ev_desc_ptr;
3597 unsigned int tx_ev_q_label;
Martin Habetsb9b603d42018-01-25 17:24:43 +00003598 unsigned int tx_ev_type;
3599 u64 ts_part;
Ben Hutchings8127d662013-08-29 19:19:29 +01003600
Mark Rutland6aa7de02017-10-23 14:07:29 -07003601 if (unlikely(READ_ONCE(efx->reset_pending)))
Bert Kenward5227ecc2018-01-25 17:24:20 +00003602 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01003603
3604 if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT)))
Bert Kenward5227ecc2018-01-25 17:24:20 +00003605 return;
Ben Hutchings8127d662013-08-29 19:19:29 +01003606
Martin Habetsb9b603d42018-01-25 17:24:43 +00003607 /* Get the transmit queue */
Ben Hutchings8127d662013-08-29 19:19:29 +01003608 tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL);
3609 tx_queue = efx_channel_get_tx_queue(channel,
3610 tx_ev_q_label % EFX_TXQ_TYPES);
Martin Habetsb9b603d42018-01-25 17:24:43 +00003611
3612 if (!tx_queue->timestamping) {
3613 /* Transmit completion */
3614 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX);
3615 efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask);
3616 return;
3617 }
3618
3619 /* Transmit timestamps are only available for 8XXX series. They result
3620 * in three events per packet. These occur in order, and are:
3621 * - the normal completion event
3622 * - the low part of the timestamp
3623 * - the high part of the timestamp
3624 *
3625 * Each part of the timestamp is itself split across two 16 bit
3626 * fields in the event.
3627 */
3628 tx_ev_type = EFX_QWORD_FIELD(*event, ESF_EZ_TX_SOFT1);
3629
3630 switch (tx_ev_type) {
3631 case TX_TIMESTAMP_EVENT_TX_EV_COMPLETION:
3632 /* In case of Queue flush or FLR, we might have received
3633 * the previous TX completion event but not the Timestamp
3634 * events.
3635 */
3636 if (tx_queue->completed_desc_ptr != tx_queue->ptr_mask)
3637 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3638
3639 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event,
3640 ESF_DZ_TX_DESCR_INDX);
3641 tx_queue->completed_desc_ptr =
3642 tx_ev_desc_ptr & tx_queue->ptr_mask;
3643 break;
3644
3645 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_LO:
3646 ts_part = efx_ef10_extract_event_ts(event);
3647 tx_queue->completed_timestamp_minor = ts_part;
3648 break;
3649
3650 case TX_TIMESTAMP_EVENT_TX_EV_TSTAMP_HI:
3651 ts_part = efx_ef10_extract_event_ts(event);
3652 tx_queue->completed_timestamp_major = ts_part;
3653
3654 efx_xmit_done(tx_queue, tx_queue->completed_desc_ptr);
3655 tx_queue->completed_desc_ptr = tx_queue->ptr_mask;
3656 break;
3657
3658 default:
3659 netif_err(efx, hw, efx->net_dev,
3660 "channel %d unknown tx event type %d (data "
3661 EFX_QWORD_FMT ")\n",
3662 channel->channel, tx_ev_type,
3663 EFX_QWORD_VAL(*event));
3664 break;
3665 }
Ben Hutchings8127d662013-08-29 19:19:29 +01003666}
3667
3668static void
3669efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
3670{
3671 struct efx_nic *efx = channel->efx;
3672 int subcode;
3673
3674 subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE);
3675
3676 switch (subcode) {
3677 case ESE_DZ_DRV_TIMER_EV:
3678 case ESE_DZ_DRV_WAKE_UP_EV:
3679 break;
3680 case ESE_DZ_DRV_START_UP_EV:
3681 /* event queue init complete. ok. */
3682 break;
3683 default:
3684 netif_err(efx, hw, efx->net_dev,
3685 "channel %d unknown driver event type %d"
3686 " (data " EFX_QWORD_FMT ")\n",
3687 channel->channel, subcode,
3688 EFX_QWORD_VAL(*event));
3689
3690 }
3691}
3692
3693static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel,
3694 efx_qword_t *event)
3695{
3696 struct efx_nic *efx = channel->efx;
3697 u32 subcode;
3698
3699 subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0);
3700
3701 switch (subcode) {
3702 case EFX_EF10_TEST:
3703 channel->event_test_cpu = raw_smp_processor_id();
3704 break;
3705 case EFX_EF10_REFILL:
3706 /* The queue must be empty, so we won't receive any rx
3707 * events, so efx_process_channel() won't refill the
3708 * queue. Refill it here
3709 */
Jon Coopercce28792013-10-02 11:04:14 +01003710 efx_fast_push_rx_descriptors(&channel->rx_queue, true);
Ben Hutchings8127d662013-08-29 19:19:29 +01003711 break;
3712 default:
3713 netif_err(efx, hw, efx->net_dev,
3714 "channel %d unknown driver event type %u"
3715 " (data " EFX_QWORD_FMT ")\n",
3716 channel->channel, (unsigned) subcode,
3717 EFX_QWORD_VAL(*event));
3718 }
3719}
3720
3721static int efx_ef10_ev_process(struct efx_channel *channel, int quota)
3722{
3723 struct efx_nic *efx = channel->efx;
3724 efx_qword_t event, *p_event;
3725 unsigned int read_ptr;
3726 int ev_code;
Ben Hutchings8127d662013-08-29 19:19:29 +01003727 int spent = 0;
3728
Eric W. Biederman75363a42014-03-14 18:11:22 -07003729 if (quota <= 0)
3730 return spent;
3731
Ben Hutchings8127d662013-08-29 19:19:29 +01003732 read_ptr = channel->eventq_read_ptr;
3733
3734 for (;;) {
3735 p_event = efx_event(channel, read_ptr);
3736 event = *p_event;
3737
3738 if (!efx_event_present(&event))
3739 break;
3740
3741 EFX_SET_QWORD(*p_event);
3742
3743 ++read_ptr;
3744
3745 ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE);
3746
3747 netif_vdbg(efx, drv, efx->net_dev,
3748 "processing event on %d " EFX_QWORD_FMT "\n",
3749 channel->channel, EFX_QWORD_VAL(event));
3750
3751 switch (ev_code) {
3752 case ESE_DZ_EV_CODE_MCDI_EV:
3753 efx_mcdi_process_event(channel, &event);
3754 break;
3755 case ESE_DZ_EV_CODE_RX_EV:
3756 spent += efx_ef10_handle_rx_event(channel, &event);
3757 if (spent >= quota) {
3758 /* XXX can we split a merged event to
3759 * avoid going over-quota?
3760 */
3761 spent = quota;
3762 goto out;
3763 }
3764 break;
3765 case ESE_DZ_EV_CODE_TX_EV:
Bert Kenward5227ecc2018-01-25 17:24:20 +00003766 efx_ef10_handle_tx_event(channel, &event);
Ben Hutchings8127d662013-08-29 19:19:29 +01003767 break;
3768 case ESE_DZ_EV_CODE_DRIVER_EV:
3769 efx_ef10_handle_driver_event(channel, &event);
3770 if (++spent == quota)
3771 goto out;
3772 break;
3773 case EFX_EF10_DRVGEN_EV:
3774 efx_ef10_handle_driver_generated_event(channel, &event);
3775 break;
3776 default:
3777 netif_err(efx, hw, efx->net_dev,
3778 "channel %d unknown event type %d"
3779 " (data " EFX_QWORD_FMT ")\n",
3780 channel->channel, ev_code,
3781 EFX_QWORD_VAL(event));
3782 }
3783 }
3784
3785out:
3786 channel->eventq_read_ptr = read_ptr;
3787 return spent;
3788}
3789
3790static void efx_ef10_ev_read_ack(struct efx_channel *channel)
3791{
3792 struct efx_nic *efx = channel->efx;
3793 efx_dword_t rptr;
3794
3795 if (EFX_EF10_WORKAROUND_35388(efx)) {
3796 BUILD_BUG_ON(EFX_MIN_EVQ_SIZE <
3797 (1 << ERF_DD_EVQ_IND_RPTR_WIDTH));
3798 BUILD_BUG_ON(EFX_MAX_EVQ_SIZE >
3799 (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH));
3800
3801 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3802 EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH,
3803 ERF_DD_EVQ_IND_RPTR,
3804 (channel->eventq_read_ptr &
3805 channel->eventq_mask) >>
3806 ERF_DD_EVQ_IND_RPTR_WIDTH);
3807 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3808 channel->channel);
3809 EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS,
3810 EFE_DD_EVQ_IND_RPTR_FLAGS_LOW,
3811 ERF_DD_EVQ_IND_RPTR,
3812 channel->eventq_read_ptr &
3813 ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1));
3814 efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT,
3815 channel->channel);
3816 } else {
3817 EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR,
3818 channel->eventq_read_ptr &
3819 channel->eventq_mask);
3820 efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel);
3821 }
3822}
3823
3824static void efx_ef10_ev_test_generate(struct efx_channel *channel)
3825{
3826 MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
3827 struct efx_nic *efx = channel->efx;
3828 efx_qword_t event;
3829 int rc;
3830
3831 EFX_POPULATE_QWORD_2(event,
3832 ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV,
3833 ESF_DZ_EV_DATA, EFX_EF10_TEST);
3834
3835 MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
3836
3837 /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
3838 * already swapped the data to little-endian order.
3839 */
3840 memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
3841 sizeof(efx_qword_t));
3842
3843 rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
3844 NULL, 0, NULL);
3845 if (rc != 0)
3846 goto fail;
3847
3848 return;
3849
3850fail:
3851 WARN_ON(true);
3852 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
3853}
3854
3855void efx_ef10_handle_drain_event(struct efx_nic *efx)
3856{
3857 if (atomic_dec_and_test(&efx->active_queues))
3858 wake_up(&efx->flush_wq);
3859
3860 WARN_ON(atomic_read(&efx->active_queues) < 0);
3861}
3862
3863static int efx_ef10_fini_dmaq(struct efx_nic *efx)
3864{
3865 struct efx_ef10_nic_data *nic_data = efx->nic_data;
3866 struct efx_channel *channel;
3867 struct efx_tx_queue *tx_queue;
3868 struct efx_rx_queue *rx_queue;
3869 int pending;
3870
3871 /* If the MC has just rebooted, the TX/RX queues will have already been
3872 * torn down, but efx->active_queues needs to be set to zero.
3873 */
3874 if (nic_data->must_realloc_vis) {
3875 atomic_set(&efx->active_queues, 0);
3876 return 0;
3877 }
3878
3879 /* Do not attempt to write to the NIC during EEH recovery */
3880 if (efx->state != STATE_RECOVERY) {
3881 efx_for_each_channel(channel, efx) {
3882 efx_for_each_channel_rx_queue(rx_queue, channel)
3883 efx_ef10_rx_fini(rx_queue);
3884 efx_for_each_channel_tx_queue(tx_queue, channel)
3885 efx_ef10_tx_fini(tx_queue);
3886 }
3887
3888 wait_event_timeout(efx->flush_wq,
3889 atomic_read(&efx->active_queues) == 0,
3890 msecs_to_jiffies(EFX_MAX_FLUSH_TIME));
3891 pending = atomic_read(&efx->active_queues);
3892 if (pending) {
3893 netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n",
3894 pending);
3895 return -ETIMEDOUT;
3896 }
3897 }
3898
3899 return 0;
3900}
3901
Edward Creee2835462014-04-16 19:27:48 +01003902static void efx_ef10_prepare_flr(struct efx_nic *efx)
3903{
3904 atomic_set(&efx->active_queues, 0);
3905}
3906
Ben Hutchings8127d662013-08-29 19:19:29 +01003907static bool efx_ef10_filter_equal(const struct efx_filter_spec *left,
3908 const struct efx_filter_spec *right)
3909{
3910 if ((left->match_flags ^ right->match_flags) |
3911 ((left->flags ^ right->flags) &
3912 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)))
3913 return false;
3914
3915 return memcmp(&left->outer_vid, &right->outer_vid,
3916 sizeof(struct efx_filter_spec) -
3917 offsetof(struct efx_filter_spec, outer_vid)) == 0;
3918}
3919
3920static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec)
3921{
3922 BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3);
3923 return jhash2((const u32 *)&spec->outer_vid,
3924 (sizeof(struct efx_filter_spec) -
3925 offsetof(struct efx_filter_spec, outer_vid)) / 4,
3926 0);
3927 /* XXX should we randomise the initval? */
3928}
3929
3930/* Decide whether a filter should be exclusive or else should allow
3931 * delivery to additional recipients. Currently we decide that
3932 * filters for specific local unicast MAC and IP addresses are
3933 * exclusive.
3934 */
3935static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec)
3936{
3937 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC &&
3938 !is_multicast_ether_addr(spec->loc_mac))
3939 return true;
3940
3941 if ((spec->match_flags &
3942 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) ==
3943 (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) {
3944 if (spec->ether_type == htons(ETH_P_IP) &&
3945 !ipv4_is_multicast(spec->loc_host[0]))
3946 return true;
3947 if (spec->ether_type == htons(ETH_P_IPV6) &&
3948 ((const u8 *)spec->loc_host)[0] != 0xff)
3949 return true;
3950 }
3951
3952 return false;
3953}
3954
3955static struct efx_filter_spec *
3956efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table,
3957 unsigned int filter_idx)
3958{
3959 return (struct efx_filter_spec *)(table->entry[filter_idx].spec &
3960 ~EFX_EF10_FILTER_FLAGS);
3961}
3962
3963static unsigned int
3964efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table,
3965 unsigned int filter_idx)
3966{
3967 return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS;
3968}
3969
3970static void
3971efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table,
3972 unsigned int filter_idx,
3973 const struct efx_filter_spec *spec,
3974 unsigned int flags)
3975{
3976 table->entry[filter_idx].spec = (unsigned long)spec | flags;
3977}
3978
Edward Cree9b410802017-01-27 15:02:52 +00003979static void
3980efx_ef10_filter_push_prep_set_match_fields(struct efx_nic *efx,
3981 const struct efx_filter_spec *spec,
3982 efx_dword_t *inbuf)
3983{
3984 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
3985 u32 match_fields = 0, uc_match, mc_match;
3986
3987 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
3988 efx_ef10_filter_is_exclusive(spec) ?
3989 MC_CMD_FILTER_OP_IN_OP_INSERT :
3990 MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE);
3991
3992 /* Convert match flags and values. Unlike almost
3993 * everything else in MCDI, these fields are in
3994 * network byte order.
3995 */
3996#define COPY_VALUE(value, mcdi_field) \
3997 do { \
3998 match_fields |= \
3999 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \
4000 mcdi_field ## _LBN; \
4001 BUILD_BUG_ON( \
4002 MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \
4003 sizeof(value)); \
4004 memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \
4005 &value, sizeof(value)); \
4006 } while (0)
4007#define COPY_FIELD(gen_flag, gen_field, mcdi_field) \
4008 if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \
4009 COPY_VALUE(spec->gen_field, mcdi_field); \
4010 }
4011 /* Handle encap filters first. They will always be mismatch
4012 * (unknown UC or MC) filters
4013 */
4014 if (encap_type) {
4015 /* ether_type and outer_ip_proto need to be variables
4016 * because COPY_VALUE wants to memcpy them
4017 */
4018 __be16 ether_type =
4019 htons(encap_type & EFX_ENCAP_FLAG_IPV6 ?
4020 ETH_P_IPV6 : ETH_P_IP);
4021 u8 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_GENEVE;
4022 u8 outer_ip_proto;
4023
4024 switch (encap_type & EFX_ENCAP_TYPES_MASK) {
4025 case EFX_ENCAP_TYPE_VXLAN:
4026 vni_type = MC_CMD_FILTER_OP_EXT_IN_VNI_TYPE_VXLAN;
4027 /* fallthrough */
4028 case EFX_ENCAP_TYPE_GENEVE:
4029 COPY_VALUE(ether_type, ETHER_TYPE);
4030 outer_ip_proto = IPPROTO_UDP;
4031 COPY_VALUE(outer_ip_proto, IP_PROTO);
4032 /* We always need to set the type field, even
4033 * though we're not matching on the TNI.
4034 */
4035 MCDI_POPULATE_DWORD_1(inbuf,
4036 FILTER_OP_EXT_IN_VNI_OR_VSID,
4037 FILTER_OP_EXT_IN_VNI_TYPE,
4038 vni_type);
4039 break;
4040 case EFX_ENCAP_TYPE_NVGRE:
4041 COPY_VALUE(ether_type, ETHER_TYPE);
4042 outer_ip_proto = IPPROTO_GRE;
4043 COPY_VALUE(outer_ip_proto, IP_PROTO);
4044 break;
4045 default:
4046 WARN_ON(1);
4047 }
4048
4049 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4050 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4051 } else {
4052 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4053 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4054 }
4055
4056 if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG)
4057 match_fields |=
4058 is_multicast_ether_addr(spec->loc_mac) ?
4059 1 << mc_match :
4060 1 << uc_match;
4061 COPY_FIELD(REM_HOST, rem_host, SRC_IP);
4062 COPY_FIELD(LOC_HOST, loc_host, DST_IP);
4063 COPY_FIELD(REM_MAC, rem_mac, SRC_MAC);
4064 COPY_FIELD(REM_PORT, rem_port, SRC_PORT);
4065 COPY_FIELD(LOC_MAC, loc_mac, DST_MAC);
4066 COPY_FIELD(LOC_PORT, loc_port, DST_PORT);
4067 COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE);
4068 COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN);
4069 COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN);
4070 COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO);
4071#undef COPY_FIELD
4072#undef COPY_VALUE
4073 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS,
4074 match_fields);
4075}
4076
Ben Hutchings8127d662013-08-29 19:19:29 +01004077static void efx_ef10_filter_push_prep(struct efx_nic *efx,
4078 const struct efx_filter_spec *spec,
4079 efx_dword_t *inbuf, u64 handle,
4080 bool replacing)
4081{
4082 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooperdcb41232016-04-25 16:51:00 +01004083 u32 flags = spec->flags;
Ben Hutchings8127d662013-08-29 19:19:29 +01004084
Edward Cree9b410802017-01-27 15:02:52 +00004085 memset(inbuf, 0, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004086
Jon Cooperdcb41232016-04-25 16:51:00 +01004087 /* Remove RSS flag if we don't have an RSS context. */
4088 if (flags & EFX_FILTER_FLAG_RX_RSS &&
4089 spec->rss_context == EFX_FILTER_RSS_CONTEXT_DEFAULT &&
4090 nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID)
4091 flags &= ~EFX_FILTER_FLAG_RX_RSS;
4092
Ben Hutchings8127d662013-08-29 19:19:29 +01004093 if (replacing) {
4094 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4095 MC_CMD_FILTER_OP_IN_OP_REPLACE);
4096 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle);
4097 } else {
Edward Cree9b410802017-01-27 15:02:52 +00004098 efx_ef10_filter_push_prep_set_match_fields(efx, spec, inbuf);
Ben Hutchings8127d662013-08-29 19:19:29 +01004099 }
4100
Daniel Pieczko45b24492015-05-06 00:57:14 +01004101 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004102 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST,
4103 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4104 MC_CMD_FILTER_OP_IN_RX_DEST_DROP :
4105 MC_CMD_FILTER_OP_IN_RX_DEST_HOST);
Shradha Shahe3d36292015-05-06 00:56:24 +01004106 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0);
Ben Hutchings8127d662013-08-29 19:19:29 +01004107 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST,
4108 MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT);
Ben Hutchingsa0bc3482013-12-16 18:56:24 +00004109 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE,
4110 spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ?
4111 0 : spec->dmaq_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004112 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE,
Jon Cooperdcb41232016-04-25 16:51:00 +01004113 (flags & EFX_FILTER_FLAG_RX_RSS) ?
Ben Hutchings8127d662013-08-29 19:19:29 +01004114 MC_CMD_FILTER_OP_IN_RX_MODE_RSS :
4115 MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE);
Jon Cooperdcb41232016-04-25 16:51:00 +01004116 if (flags & EFX_FILTER_FLAG_RX_RSS)
Ben Hutchings8127d662013-08-29 19:19:29 +01004117 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT,
4118 spec->rss_context !=
4119 EFX_FILTER_RSS_CONTEXT_DEFAULT ?
4120 spec->rss_context : nic_data->rx_rss_context);
4121}
4122
4123static int efx_ef10_filter_push(struct efx_nic *efx,
4124 const struct efx_filter_spec *spec,
4125 u64 *handle, bool replacing)
4126{
Edward Cree9b410802017-01-27 15:02:52 +00004127 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
4128 MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_EXT_OUT_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004129 int rc;
4130
4131 efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing);
4132 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4133 outbuf, sizeof(outbuf), NULL);
4134 if (rc == 0)
4135 *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
Ben Hutchings065e64c2013-10-09 14:17:27 +01004136 if (rc == -ENOSPC)
4137 rc = -EBUSY; /* to match efx_farch_filter_insert() */
Ben Hutchings8127d662013-08-29 19:19:29 +01004138 return rc;
4139}
4140
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004141static u32 efx_ef10_filter_mcdi_flags_from_spec(const struct efx_filter_spec *spec)
Ben Hutchings8127d662013-08-29 19:19:29 +01004142{
Edward Cree9b410802017-01-27 15:02:52 +00004143 enum efx_encap_type encap_type = efx_filter_get_encap_type(spec);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004144 unsigned int match_flags = spec->match_flags;
Edward Cree9b410802017-01-27 15:02:52 +00004145 unsigned int uc_match, mc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004146 u32 mcdi_flags = 0;
4147
Edward Cree9b410802017-01-27 15:02:52 +00004148#define MAP_FILTER_TO_MCDI_FLAG(gen_flag, mcdi_field, encap) { \
4149 unsigned int old_match_flags = match_flags; \
4150 match_flags &= ~EFX_FILTER_MATCH_ ## gen_flag; \
4151 if (match_flags != old_match_flags) \
4152 mcdi_flags |= \
4153 (1 << ((encap) ? \
4154 MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_ ## \
4155 mcdi_field ## _LBN : \
4156 MC_CMD_FILTER_OP_EXT_IN_MATCH_ ##\
4157 mcdi_field ## _LBN)); \
4158 }
4159 /* inner or outer based on encap type */
4160 MAP_FILTER_TO_MCDI_FLAG(REM_HOST, SRC_IP, encap_type);
4161 MAP_FILTER_TO_MCDI_FLAG(LOC_HOST, DST_IP, encap_type);
4162 MAP_FILTER_TO_MCDI_FLAG(REM_MAC, SRC_MAC, encap_type);
4163 MAP_FILTER_TO_MCDI_FLAG(REM_PORT, SRC_PORT, encap_type);
4164 MAP_FILTER_TO_MCDI_FLAG(LOC_MAC, DST_MAC, encap_type);
4165 MAP_FILTER_TO_MCDI_FLAG(LOC_PORT, DST_PORT, encap_type);
4166 MAP_FILTER_TO_MCDI_FLAG(ETHER_TYPE, ETHER_TYPE, encap_type);
4167 MAP_FILTER_TO_MCDI_FLAG(IP_PROTO, IP_PROTO, encap_type);
4168 /* always outer */
4169 MAP_FILTER_TO_MCDI_FLAG(INNER_VID, INNER_VLAN, false);
4170 MAP_FILTER_TO_MCDI_FLAG(OUTER_VID, OUTER_VLAN, false);
4171#undef MAP_FILTER_TO_MCDI_FLAG
4172
4173 /* special handling for encap type, and mismatch */
4174 if (encap_type) {
4175 match_flags &= ~EFX_FILTER_MATCH_ENCAP_TYPE;
4176 mcdi_flags |=
4177 (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4178 mcdi_flags |= (1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4179
4180 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_UCAST_DST_LBN;
4181 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_IFRM_UNKNOWN_MCAST_DST_LBN;
4182 } else {
4183 uc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_UCAST_DST_LBN;
4184 mc_match = MC_CMD_FILTER_OP_EXT_IN_MATCH_UNKNOWN_MCAST_DST_LBN;
4185 }
4186
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004187 if (match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) {
4188 match_flags &= ~EFX_FILTER_MATCH_LOC_MAC_IG;
4189 mcdi_flags |=
4190 is_multicast_ether_addr(spec->loc_mac) ?
Edward Cree9b410802017-01-27 15:02:52 +00004191 1 << mc_match :
4192 1 << uc_match;
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004193 }
4194
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004195 /* Did we map them all? */
4196 WARN_ON_ONCE(match_flags);
4197
4198 return mcdi_flags;
4199}
4200
4201static int efx_ef10_filter_pri(struct efx_ef10_filter_table *table,
4202 const struct efx_filter_spec *spec)
4203{
4204 u32 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004205 unsigned int match_pri;
4206
4207 for (match_pri = 0;
4208 match_pri < table->rx_match_count;
4209 match_pri++)
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004210 if (table->rx_match_mcdi_flags[match_pri] == mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004211 return match_pri;
4212
4213 return -EPROTONOSUPPORT;
4214}
4215
4216static s32 efx_ef10_filter_insert(struct efx_nic *efx,
4217 struct efx_filter_spec *spec,
4218 bool replace_equal)
4219{
4220 struct efx_ef10_filter_table *table = efx->filter_state;
4221 DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4222 struct efx_filter_spec *saved_spec;
4223 unsigned int match_pri, hash;
4224 unsigned int priv_flags;
4225 bool replacing = false;
4226 int ins_index = -1;
4227 DEFINE_WAIT(wait);
4228 bool is_mc_recip;
4229 s32 rc;
4230
4231 /* For now, only support RX filters */
4232 if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) !=
4233 EFX_FILTER_FLAG_RX)
4234 return -EINVAL;
4235
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004236 rc = efx_ef10_filter_pri(table, spec);
Ben Hutchings8127d662013-08-29 19:19:29 +01004237 if (rc < 0)
4238 return rc;
4239 match_pri = rc;
4240
4241 hash = efx_ef10_filter_hash(spec);
4242 is_mc_recip = efx_filter_is_mc_recipient(spec);
4243 if (is_mc_recip)
4244 bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT);
4245
4246 /* Find any existing filters with the same match tuple or
4247 * else a free slot to insert at. If any of them are busy,
4248 * we have to wait and retry.
4249 */
4250 for (;;) {
4251 unsigned int depth = 1;
4252 unsigned int i;
4253
4254 spin_lock_bh(&efx->filter_lock);
4255
4256 for (;;) {
4257 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4258 saved_spec = efx_ef10_filter_entry_spec(table, i);
4259
4260 if (!saved_spec) {
4261 if (ins_index < 0)
4262 ins_index = i;
4263 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4264 if (table->entry[i].spec &
4265 EFX_EF10_FILTER_FLAG_BUSY)
4266 break;
4267 if (spec->priority < saved_spec->priority &&
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004268 spec->priority != EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004269 rc = -EPERM;
4270 goto out_unlock;
4271 }
4272 if (!is_mc_recip) {
4273 /* This is the only one */
4274 if (spec->priority ==
4275 saved_spec->priority &&
4276 !replace_equal) {
4277 rc = -EEXIST;
4278 goto out_unlock;
4279 }
4280 ins_index = i;
4281 goto found;
4282 } else if (spec->priority >
4283 saved_spec->priority ||
4284 (spec->priority ==
4285 saved_spec->priority &&
4286 replace_equal)) {
4287 if (ins_index < 0)
4288 ins_index = i;
4289 else
4290 __set_bit(depth, mc_rem_map);
4291 }
4292 }
4293
4294 /* Once we reach the maximum search depth, use
4295 * the first suitable slot or return -EBUSY if
4296 * there was none
4297 */
4298 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4299 if (ins_index < 0) {
4300 rc = -EBUSY;
4301 goto out_unlock;
4302 }
4303 goto found;
4304 }
4305
4306 ++depth;
4307 }
4308
4309 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4310 spin_unlock_bh(&efx->filter_lock);
4311 schedule();
4312 }
4313
4314found:
4315 /* Create a software table entry if necessary, and mark it
4316 * busy. We might yet fail to insert, but any attempt to
4317 * insert a conflicting filter while we're waiting for the
4318 * firmware must find the busy entry.
4319 */
4320 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4321 if (saved_spec) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004322 if (spec->priority == EFX_FILTER_PRI_AUTO &&
4323 saved_spec->priority >= EFX_FILTER_PRI_AUTO) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004324 /* Just make sure it won't be removed */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004325 if (saved_spec->priority > EFX_FILTER_PRI_AUTO)
4326 saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004327 table->entry[ins_index].spec &=
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004328 ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings8127d662013-08-29 19:19:29 +01004329 rc = ins_index;
4330 goto out_unlock;
4331 }
4332 replacing = true;
4333 priv_flags = efx_ef10_filter_entry_flags(table, ins_index);
4334 } else {
4335 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4336 if (!saved_spec) {
4337 rc = -ENOMEM;
4338 goto out_unlock;
4339 }
4340 *saved_spec = *spec;
4341 priv_flags = 0;
4342 }
4343 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4344 priv_flags | EFX_EF10_FILTER_FLAG_BUSY);
4345
4346 /* Mark lower-priority multicast recipients busy prior to removal */
4347 if (is_mc_recip) {
4348 unsigned int depth, i;
4349
4350 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4351 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4352 if (test_bit(depth, mc_rem_map))
4353 table->entry[i].spec |=
4354 EFX_EF10_FILTER_FLAG_BUSY;
4355 }
4356 }
4357
4358 spin_unlock_bh(&efx->filter_lock);
4359
4360 rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle,
4361 replacing);
4362
4363 /* Finalise the software table entry */
4364 spin_lock_bh(&efx->filter_lock);
4365 if (rc == 0) {
4366 if (replacing) {
4367 /* Update the fields that may differ */
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004368 if (saved_spec->priority == EFX_FILTER_PRI_AUTO)
4369 saved_spec->flags |=
4370 EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004371 saved_spec->priority = spec->priority;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004372 saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004373 saved_spec->flags |= spec->flags;
4374 saved_spec->rss_context = spec->rss_context;
4375 saved_spec->dmaq_id = spec->dmaq_id;
4376 }
4377 } else if (!replacing) {
4378 kfree(saved_spec);
4379 saved_spec = NULL;
4380 }
4381 efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags);
4382
4383 /* Remove and finalise entries for lower-priority multicast
4384 * recipients
4385 */
4386 if (is_mc_recip) {
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004387 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004388 unsigned int depth, i;
4389
4390 memset(inbuf, 0, sizeof(inbuf));
4391
4392 for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) {
4393 if (!test_bit(depth, mc_rem_map))
4394 continue;
4395
4396 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4397 saved_spec = efx_ef10_filter_entry_spec(table, i);
4398 priv_flags = efx_ef10_filter_entry_flags(table, i);
4399
4400 if (rc == 0) {
4401 spin_unlock_bh(&efx->filter_lock);
4402 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4403 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4404 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4405 table->entry[i].handle);
4406 rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP,
4407 inbuf, sizeof(inbuf),
4408 NULL, 0, NULL);
4409 spin_lock_bh(&efx->filter_lock);
4410 }
4411
4412 if (rc == 0) {
4413 kfree(saved_spec);
4414 saved_spec = NULL;
4415 priv_flags = 0;
4416 } else {
4417 priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY;
4418 }
4419 efx_ef10_filter_set_entry(table, i, saved_spec,
4420 priv_flags);
4421 }
4422 }
4423
4424 /* If successful, return the inserted filter ID */
4425 if (rc == 0)
Jon Cooper0ccb9982017-02-17 15:49:13 +00004426 rc = efx_ef10_make_filter_id(match_pri, ins_index);
Ben Hutchings8127d662013-08-29 19:19:29 +01004427
4428 wake_up_all(&table->waitq);
4429out_unlock:
4430 spin_unlock_bh(&efx->filter_lock);
4431 finish_wait(&table->waitq, &wait);
4432 return rc;
4433}
4434
Fengguang Wu9fd8095d2013-08-31 06:54:05 +08004435static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx)
Ben Hutchings8127d662013-08-29 19:19:29 +01004436{
4437 /* no need to do anything here on EF10 */
4438}
4439
4440/* Remove a filter.
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004441 * If !by_index, remove by ID
4442 * If by_index, remove by index
Ben Hutchings8127d662013-08-29 19:19:29 +01004443 * Filter ID may come from userland and must be range-checked.
4444 */
4445static int efx_ef10_filter_remove_internal(struct efx_nic *efx,
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004446 unsigned int priority_mask,
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004447 u32 filter_id, bool by_index)
Ben Hutchings8127d662013-08-29 19:19:29 +01004448{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004449 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004450 struct efx_ef10_filter_table *table = efx->filter_state;
4451 MCDI_DECLARE_BUF(inbuf,
4452 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4453 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4454 struct efx_filter_spec *spec;
4455 DEFINE_WAIT(wait);
4456 int rc;
4457
4458 /* Find the software table entry and mark it busy. Don't
4459 * remove it yet; any attempt to update while we're waiting
4460 * for the firmware must find the busy entry.
4461 */
4462 for (;;) {
4463 spin_lock_bh(&efx->filter_lock);
4464 if (!(table->entry[filter_idx].spec &
4465 EFX_EF10_FILTER_FLAG_BUSY))
4466 break;
4467 prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE);
4468 spin_unlock_bh(&efx->filter_lock);
4469 schedule();
4470 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004471
Ben Hutchings8127d662013-08-29 19:19:29 +01004472 spec = efx_ef10_filter_entry_spec(table, filter_idx);
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004473 if (!spec ||
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004474 (!by_index &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004475 efx_ef10_filter_pri(table, spec) !=
Jon Cooper0ccb9982017-02-17 15:49:13 +00004476 efx_ef10_filter_get_unsafe_pri(filter_id))) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004477 rc = -ENOENT;
4478 goto out_unlock;
4479 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004480
4481 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO &&
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004482 priority_mask == (1U << EFX_FILTER_PRI_AUTO)) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004483 /* Just remove flags */
4484 spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO;
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004485 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD;
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004486 rc = 0;
4487 goto out_unlock;
4488 }
4489
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004490 if (!(priority_mask & (1U << spec->priority))) {
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004491 rc = -ENOENT;
4492 goto out_unlock;
4493 }
4494
Ben Hutchings8127d662013-08-29 19:19:29 +01004495 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4496 spin_unlock_bh(&efx->filter_lock);
4497
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004498 if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) {
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00004499 /* Reset to an automatic filter */
Ben Hutchings8127d662013-08-29 19:19:29 +01004500
4501 struct efx_filter_spec new_spec = *spec;
4502
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004503 new_spec.priority = EFX_FILTER_PRI_AUTO;
Ben Hutchings8127d662013-08-29 19:19:29 +01004504 new_spec.flags = (EFX_FILTER_FLAG_RX |
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00004505 (efx_rss_enabled(efx) ?
4506 EFX_FILTER_FLAG_RX_RSS : 0));
Ben Hutchings8127d662013-08-29 19:19:29 +01004507 new_spec.dmaq_id = 0;
4508 new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT;
4509 rc = efx_ef10_filter_push(efx, &new_spec,
4510 &table->entry[filter_idx].handle,
4511 true);
4512
4513 spin_lock_bh(&efx->filter_lock);
4514 if (rc == 0)
4515 *spec = new_spec;
4516 } else {
4517 /* Really remove the filter */
4518
4519 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4520 efx_ef10_filter_is_exclusive(spec) ?
4521 MC_CMD_FILTER_OP_IN_OP_REMOVE :
4522 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
4523 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4524 table->entry[filter_idx].handle);
Bert Kenward105eac62017-02-17 15:50:12 +00004525 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP,
4526 inbuf, sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings8127d662013-08-29 19:19:29 +01004527
4528 spin_lock_bh(&efx->filter_lock);
Bert Kenward105eac62017-02-17 15:50:12 +00004529 if ((rc == 0) || (rc == -ENOENT)) {
4530 /* Filter removed OK or didn't actually exist */
Ben Hutchings8127d662013-08-29 19:19:29 +01004531 kfree(spec);
4532 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
Bert Kenward105eac62017-02-17 15:50:12 +00004533 } else {
4534 efx_mcdi_display_error(efx, MC_CMD_FILTER_OP,
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004535 MC_CMD_FILTER_OP_EXT_IN_LEN,
Bert Kenward105eac62017-02-17 15:50:12 +00004536 NULL, 0, rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01004537 }
4538 }
Ben Hutchings7665d1a2013-11-21 19:02:18 +00004539
Ben Hutchings8127d662013-08-29 19:19:29 +01004540 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4541 wake_up_all(&table->waitq);
4542out_unlock:
4543 spin_unlock_bh(&efx->filter_lock);
4544 finish_wait(&table->waitq, &wait);
4545 return rc;
4546}
4547
4548static int efx_ef10_filter_remove_safe(struct efx_nic *efx,
4549 enum efx_filter_priority priority,
4550 u32 filter_id)
4551{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004552 return efx_ef10_filter_remove_internal(efx, 1U << priority,
4553 filter_id, false);
Ben Hutchings8127d662013-08-29 19:19:29 +01004554}
4555
Edward Cree8c915622016-06-15 17:49:05 +01004556static void efx_ef10_filter_remove_unsafe(struct efx_nic *efx,
4557 enum efx_filter_priority priority,
4558 u32 filter_id)
Edward Cree12fb0da2015-07-21 15:11:00 +01004559{
Edward Cree8c915622016-06-15 17:49:05 +01004560 if (filter_id == EFX_EF10_FILTER_ID_INVALID)
4561 return;
4562 efx_ef10_filter_remove_internal(efx, 1U << priority, filter_id, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01004563}
4564
Ben Hutchings8127d662013-08-29 19:19:29 +01004565static int efx_ef10_filter_get_safe(struct efx_nic *efx,
4566 enum efx_filter_priority priority,
4567 u32 filter_id, struct efx_filter_spec *spec)
4568{
Jon Cooper0ccb9982017-02-17 15:49:13 +00004569 unsigned int filter_idx = efx_ef10_filter_get_unsafe_id(filter_id);
Ben Hutchings8127d662013-08-29 19:19:29 +01004570 struct efx_ef10_filter_table *table = efx->filter_state;
4571 const struct efx_filter_spec *saved_spec;
4572 int rc;
4573
4574 spin_lock_bh(&efx->filter_lock);
4575 saved_spec = efx_ef10_filter_entry_spec(table, filter_idx);
4576 if (saved_spec && saved_spec->priority == priority &&
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004577 efx_ef10_filter_pri(table, saved_spec) ==
Jon Cooper0ccb9982017-02-17 15:49:13 +00004578 efx_ef10_filter_get_unsafe_pri(filter_id)) {
Ben Hutchings8127d662013-08-29 19:19:29 +01004579 *spec = *saved_spec;
4580 rc = 0;
4581 } else {
4582 rc = -ENOENT;
4583 }
4584 spin_unlock_bh(&efx->filter_lock);
4585 return rc;
4586}
4587
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004588static int efx_ef10_filter_clear_rx(struct efx_nic *efx,
Ben Hutchings8127d662013-08-29 19:19:29 +01004589 enum efx_filter_priority priority)
4590{
Ben Hutchingsfbd79122013-11-21 19:15:03 +00004591 unsigned int priority_mask;
4592 unsigned int i;
4593 int rc;
4594
4595 priority_mask = (((1U << (priority + 1)) - 1) &
4596 ~(1U << EFX_FILTER_PRI_AUTO));
4597
4598 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
4599 rc = efx_ef10_filter_remove_internal(efx, priority_mask,
4600 i, true);
4601 if (rc && rc != -ENOENT)
4602 return rc;
4603 }
4604
4605 return 0;
Ben Hutchings8127d662013-08-29 19:19:29 +01004606}
4607
4608static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx,
4609 enum efx_filter_priority priority)
4610{
4611 struct efx_ef10_filter_table *table = efx->filter_state;
4612 unsigned int filter_idx;
4613 s32 count = 0;
4614
4615 spin_lock_bh(&efx->filter_lock);
4616 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4617 if (table->entry[filter_idx].spec &&
4618 efx_ef10_filter_entry_spec(table, filter_idx)->priority ==
4619 priority)
4620 ++count;
4621 }
4622 spin_unlock_bh(&efx->filter_lock);
4623 return count;
4624}
4625
4626static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx)
4627{
4628 struct efx_ef10_filter_table *table = efx->filter_state;
4629
Jon Cooper0ccb9982017-02-17 15:49:13 +00004630 return table->rx_match_count * HUNT_FILTER_TBL_ROWS * 2;
Ben Hutchings8127d662013-08-29 19:19:29 +01004631}
4632
4633static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx,
4634 enum efx_filter_priority priority,
4635 u32 *buf, u32 size)
4636{
4637 struct efx_ef10_filter_table *table = efx->filter_state;
4638 struct efx_filter_spec *spec;
4639 unsigned int filter_idx;
4640 s32 count = 0;
4641
4642 spin_lock_bh(&efx->filter_lock);
4643 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
4644 spec = efx_ef10_filter_entry_spec(table, filter_idx);
4645 if (spec && spec->priority == priority) {
4646 if (count == size) {
4647 count = -EMSGSIZE;
4648 break;
4649 }
Jon Cooper0ccb9982017-02-17 15:49:13 +00004650 buf[count++] =
4651 efx_ef10_make_filter_id(
4652 efx_ef10_filter_pri(table, spec),
Ben Hutchings8127d662013-08-29 19:19:29 +01004653 filter_idx);
4654 }
4655 }
4656 spin_unlock_bh(&efx->filter_lock);
4657 return count;
4658}
4659
4660#ifdef CONFIG_RFS_ACCEL
4661
4662static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete;
4663
4664static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx,
4665 struct efx_filter_spec *spec)
4666{
4667 struct efx_ef10_filter_table *table = efx->filter_state;
Martin Habetsbb53f4d2017-06-22 10:50:41 +01004668 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01004669 struct efx_filter_spec *saved_spec;
4670 unsigned int hash, i, depth = 1;
4671 bool replacing = false;
4672 int ins_index = -1;
4673 u64 cookie;
4674 s32 rc;
4675
4676 /* Must be an RX filter without RSS and not for a multicast
4677 * destination address (RFS only works for connected sockets).
4678 * These restrictions allow us to pass only a tiny amount of
4679 * data through to the completion function.
4680 */
4681 EFX_WARN_ON_PARANOID(spec->flags !=
4682 (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER));
4683 EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT);
4684 EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec));
4685
4686 hash = efx_ef10_filter_hash(spec);
4687
4688 spin_lock_bh(&efx->filter_lock);
4689
4690 /* Find any existing filter with the same match tuple or else
4691 * a free slot to insert at. If an existing filter is busy,
4692 * we have to give up.
4693 */
4694 for (;;) {
4695 i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1);
4696 saved_spec = efx_ef10_filter_entry_spec(table, i);
4697
4698 if (!saved_spec) {
4699 if (ins_index < 0)
4700 ins_index = i;
4701 } else if (efx_ef10_filter_equal(spec, saved_spec)) {
4702 if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) {
4703 rc = -EBUSY;
4704 goto fail_unlock;
4705 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004706 if (spec->priority < saved_spec->priority) {
4707 rc = -EPERM;
4708 goto fail_unlock;
4709 }
4710 ins_index = i;
4711 break;
4712 }
4713
4714 /* Once we reach the maximum search depth, use the
4715 * first suitable slot or return -EBUSY if there was
4716 * none
4717 */
4718 if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) {
4719 if (ins_index < 0) {
4720 rc = -EBUSY;
4721 goto fail_unlock;
4722 }
4723 break;
4724 }
4725
4726 ++depth;
4727 }
4728
4729 /* Create a software table entry if necessary, and mark it
4730 * busy. We might yet fail to insert, but any attempt to
4731 * insert a conflicting filter while we're waiting for the
4732 * firmware must find the busy entry.
4733 */
4734 saved_spec = efx_ef10_filter_entry_spec(table, ins_index);
4735 if (saved_spec) {
4736 replacing = true;
4737 } else {
4738 saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC);
4739 if (!saved_spec) {
4740 rc = -ENOMEM;
4741 goto fail_unlock;
4742 }
4743 *saved_spec = *spec;
4744 }
4745 efx_ef10_filter_set_entry(table, ins_index, saved_spec,
4746 EFX_EF10_FILTER_FLAG_BUSY);
4747
4748 spin_unlock_bh(&efx->filter_lock);
4749
4750 /* Pack up the variables needed on completion */
4751 cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id;
4752
4753 efx_ef10_filter_push_prep(efx, spec, inbuf,
4754 table->entry[ins_index].handle, replacing);
4755 efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf),
4756 MC_CMD_FILTER_OP_OUT_LEN,
4757 efx_ef10_filter_rfs_insert_complete, cookie);
4758
4759 return ins_index;
4760
4761fail_unlock:
4762 spin_unlock_bh(&efx->filter_lock);
4763 return rc;
4764}
4765
4766static void
4767efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie,
4768 int rc, efx_dword_t *outbuf,
4769 size_t outlen_actual)
4770{
4771 struct efx_ef10_filter_table *table = efx->filter_state;
4772 unsigned int ins_index, dmaq_id;
4773 struct efx_filter_spec *spec;
4774 bool replacing;
4775
4776 /* Unpack the cookie */
4777 replacing = cookie >> 31;
4778 ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1);
4779 dmaq_id = cookie & 0xffff;
4780
4781 spin_lock_bh(&efx->filter_lock);
4782 spec = efx_ef10_filter_entry_spec(table, ins_index);
4783 if (rc == 0) {
4784 table->entry[ins_index].handle =
4785 MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE);
4786 if (replacing)
4787 spec->dmaq_id = dmaq_id;
4788 } else if (!replacing) {
4789 kfree(spec);
4790 spec = NULL;
4791 }
4792 efx_ef10_filter_set_entry(table, ins_index, spec, 0);
4793 spin_unlock_bh(&efx->filter_lock);
4794
4795 wake_up_all(&table->waitq);
4796}
4797
4798static void
4799efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4800 unsigned long filter_idx,
4801 int rc, efx_dword_t *outbuf,
4802 size_t outlen_actual);
4803
4804static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id,
4805 unsigned int filter_idx)
4806{
4807 struct efx_ef10_filter_table *table = efx->filter_state;
4808 struct efx_filter_spec *spec =
4809 efx_ef10_filter_entry_spec(table, filter_idx);
4810 MCDI_DECLARE_BUF(inbuf,
4811 MC_CMD_FILTER_OP_IN_HANDLE_OFST +
4812 MC_CMD_FILTER_OP_IN_HANDLE_LEN);
4813
4814 if (!spec ||
4815 (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) ||
4816 spec->priority != EFX_FILTER_PRI_HINT ||
4817 !rps_may_expire_flow(efx->net_dev, spec->dmaq_id,
4818 flow_id, filter_idx))
4819 return false;
4820
4821 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
4822 MC_CMD_FILTER_OP_IN_OP_REMOVE);
4823 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
4824 table->entry[filter_idx].handle);
4825 if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0,
4826 efx_ef10_filter_rfs_expire_complete, filter_idx))
4827 return false;
4828
4829 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
4830 return true;
4831}
4832
4833static void
4834efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx,
4835 unsigned long filter_idx,
4836 int rc, efx_dword_t *outbuf,
4837 size_t outlen_actual)
4838{
4839 struct efx_ef10_filter_table *table = efx->filter_state;
4840 struct efx_filter_spec *spec =
4841 efx_ef10_filter_entry_spec(table, filter_idx);
4842
4843 spin_lock_bh(&efx->filter_lock);
4844 if (rc == 0) {
4845 kfree(spec);
4846 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
4847 }
4848 table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY;
4849 wake_up_all(&table->waitq);
4850 spin_unlock_bh(&efx->filter_lock);
4851}
4852
4853#endif /* CONFIG_RFS_ACCEL */
4854
Edward Cree9b410802017-01-27 15:02:52 +00004855static int efx_ef10_filter_match_flags_from_mcdi(bool encap, u32 mcdi_flags)
Ben Hutchings8127d662013-08-29 19:19:29 +01004856{
4857 int match_flags = 0;
4858
Edward Cree9b410802017-01-27 15:02:52 +00004859#define MAP_FLAG(gen_flag, mcdi_field) do { \
Ben Hutchings8127d662013-08-29 19:19:29 +01004860 u32 old_mcdi_flags = mcdi_flags; \
Edward Cree9b410802017-01-27 15:02:52 +00004861 mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ ## \
4862 mcdi_field ## _LBN); \
Ben Hutchings8127d662013-08-29 19:19:29 +01004863 if (mcdi_flags != old_mcdi_flags) \
4864 match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \
Edward Cree9b410802017-01-27 15:02:52 +00004865 } while (0)
4866
4867 if (encap) {
4868 /* encap filters must specify encap type */
4869 match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
4870 /* and imply ethertype and ip proto */
4871 mcdi_flags &=
4872 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_IP_PROTO_LBN);
4873 mcdi_flags &=
4874 ~(1 << MC_CMD_FILTER_OP_EXT_IN_MATCH_ETHER_TYPE_LBN);
4875 /* VLAN tags refer to the outer packet */
4876 MAP_FLAG(INNER_VID, INNER_VLAN);
4877 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4878 /* everything else refers to the inner packet */
4879 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_UCAST_DST);
4880 MAP_FLAG(LOC_MAC_IG, IFRM_UNKNOWN_MCAST_DST);
4881 MAP_FLAG(REM_HOST, IFRM_SRC_IP);
4882 MAP_FLAG(LOC_HOST, IFRM_DST_IP);
4883 MAP_FLAG(REM_MAC, IFRM_SRC_MAC);
4884 MAP_FLAG(REM_PORT, IFRM_SRC_PORT);
4885 MAP_FLAG(LOC_MAC, IFRM_DST_MAC);
4886 MAP_FLAG(LOC_PORT, IFRM_DST_PORT);
4887 MAP_FLAG(ETHER_TYPE, IFRM_ETHER_TYPE);
4888 MAP_FLAG(IP_PROTO, IFRM_IP_PROTO);
4889 } else {
4890 MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST);
4891 MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST);
4892 MAP_FLAG(REM_HOST, SRC_IP);
4893 MAP_FLAG(LOC_HOST, DST_IP);
4894 MAP_FLAG(REM_MAC, SRC_MAC);
4895 MAP_FLAG(REM_PORT, SRC_PORT);
4896 MAP_FLAG(LOC_MAC, DST_MAC);
4897 MAP_FLAG(LOC_PORT, DST_PORT);
4898 MAP_FLAG(ETHER_TYPE, ETHER_TYPE);
4899 MAP_FLAG(INNER_VID, INNER_VLAN);
4900 MAP_FLAG(OUTER_VID, OUTER_VLAN);
4901 MAP_FLAG(IP_PROTO, IP_PROTO);
Ben Hutchings8127d662013-08-29 19:19:29 +01004902 }
Ben Hutchings8127d662013-08-29 19:19:29 +01004903#undef MAP_FLAG
4904
4905 /* Did we map them all? */
4906 if (mcdi_flags)
4907 return -EINVAL;
4908
4909 return match_flags;
4910}
4911
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01004912static void efx_ef10_filter_cleanup_vlans(struct efx_nic *efx)
4913{
4914 struct efx_ef10_filter_table *table = efx->filter_state;
4915 struct efx_ef10_filter_vlan *vlan, *next_vlan;
4916
4917 /* See comment in efx_ef10_filter_table_remove() */
4918 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
4919 return;
4920
4921 if (!table)
4922 return;
4923
4924 list_for_each_entry_safe(vlan, next_vlan, &table->vlan_list, list)
4925 efx_ef10_filter_del_vlan_internal(efx, vlan);
4926}
4927
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004928static bool efx_ef10_filter_match_supported(struct efx_ef10_filter_table *table,
Edward Cree9b410802017-01-27 15:02:52 +00004929 bool encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004930 enum efx_filter_match_flags match_flags)
4931{
4932 unsigned int match_pri;
4933 int mf;
4934
4935 for (match_pri = 0;
4936 match_pri < table->rx_match_count;
4937 match_pri++) {
Edward Cree9b410802017-01-27 15:02:52 +00004938 mf = efx_ef10_filter_match_flags_from_mcdi(encap,
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004939 table->rx_match_mcdi_flags[match_pri]);
4940 if (mf == match_flags)
4941 return true;
4942 }
4943
4944 return false;
4945}
4946
Edward Cree9b410802017-01-27 15:02:52 +00004947static int
4948efx_ef10_filter_table_probe_matches(struct efx_nic *efx,
4949 struct efx_ef10_filter_table *table,
4950 bool encap)
Ben Hutchings8127d662013-08-29 19:19:29 +01004951{
4952 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN);
4953 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX);
4954 unsigned int pd_match_pri, pd_match_count;
Ben Hutchings8127d662013-08-29 19:19:29 +01004955 size_t outlen;
4956 int rc;
4957
Ben Hutchings8127d662013-08-29 19:19:29 +01004958 /* Find out which RX filter types are supported, and their priorities */
4959 MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP,
Edward Cree9b410802017-01-27 15:02:52 +00004960 encap ?
4961 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_ENCAP_RX_MATCHES :
Ben Hutchings8127d662013-08-29 19:19:29 +01004962 MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES);
4963 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO,
4964 inbuf, sizeof(inbuf), outbuf, sizeof(outbuf),
4965 &outlen);
4966 if (rc)
Edward Cree9b410802017-01-27 15:02:52 +00004967 return rc;
4968
Ben Hutchings8127d662013-08-29 19:19:29 +01004969 pd_match_count = MCDI_VAR_ARRAY_LEN(
4970 outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES);
Ben Hutchings8127d662013-08-29 19:19:29 +01004971
4972 for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) {
4973 u32 mcdi_flags =
4974 MCDI_ARRAY_DWORD(
4975 outbuf,
4976 GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES,
4977 pd_match_pri);
Edward Cree9b410802017-01-27 15:02:52 +00004978 rc = efx_ef10_filter_match_flags_from_mcdi(encap, mcdi_flags);
Ben Hutchings8127d662013-08-29 19:19:29 +01004979 if (rc < 0) {
4980 netif_dbg(efx, probe, efx->net_dev,
4981 "%s: fw flags %#x pri %u not supported in driver\n",
4982 __func__, mcdi_flags, pd_match_pri);
4983 } else {
4984 netif_dbg(efx, probe, efx->net_dev,
4985 "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n",
4986 __func__, mcdi_flags, pd_match_pri,
4987 rc, table->rx_match_count);
Andrew Rybchenko7ac0dd92016-06-15 17:49:30 +01004988 table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags;
4989 table->rx_match_count++;
Ben Hutchings8127d662013-08-29 19:19:29 +01004990 }
4991 }
4992
Edward Cree9b410802017-01-27 15:02:52 +00004993 return 0;
4994}
4995
4996static int efx_ef10_filter_table_probe(struct efx_nic *efx)
4997{
4998 struct efx_ef10_nic_data *nic_data = efx->nic_data;
4999 struct net_device *net_dev = efx->net_dev;
5000 struct efx_ef10_filter_table *table;
5001 struct efx_ef10_vlan *vlan;
5002 int rc;
5003
5004 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5005 return -EINVAL;
5006
5007 if (efx->filter_state) /* already probed */
5008 return 0;
5009
5010 table = kzalloc(sizeof(*table), GFP_KERNEL);
5011 if (!table)
5012 return -ENOMEM;
5013
5014 table->rx_match_count = 0;
5015 rc = efx_ef10_filter_table_probe_matches(efx, table, false);
5016 if (rc)
5017 goto fail;
5018 if (nic_data->datapath_caps &
5019 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5020 rc = efx_ef10_filter_table_probe_matches(efx, table, true);
5021 if (rc)
5022 goto fail;
Martin Habetse4478ad2016-06-15 17:51:07 +01005023 if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) &&
Edward Cree9b410802017-01-27 15:02:52 +00005024 !(efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01005025 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) &&
Edward Cree9b410802017-01-27 15:02:52 +00005026 efx_ef10_filter_match_supported(table, false,
Martin Habetse4478ad2016-06-15 17:51:07 +01005027 (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC_IG)))) {
5028 netif_info(efx, probe, net_dev,
5029 "VLAN filters are not supported in this firmware variant\n");
5030 net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5031 efx->fixed_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5032 net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
5033 }
5034
Ben Hutchings8127d662013-08-29 19:19:29 +01005035 table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry));
5036 if (!table->entry) {
5037 rc = -ENOMEM;
5038 goto fail;
5039 }
5040
Andrew Rybchenkob071c3a2016-06-15 17:43:00 +01005041 table->mc_promisc_last = false;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005042 table->vlan_filter =
5043 !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005044 INIT_LIST_HEAD(&table->vlan_list);
Edward Cree12fb0da2015-07-21 15:11:00 +01005045
Ben Hutchings8127d662013-08-29 19:19:29 +01005046 efx->filter_state = table;
5047 init_waitqueue_head(&table->waitq);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005048
5049 list_for_each_entry(vlan, &nic_data->vlan_list, list) {
5050 rc = efx_ef10_filter_add_vlan(efx, vlan->vid);
5051 if (rc)
5052 goto fail_add_vlan;
5053 }
5054
Ben Hutchings8127d662013-08-29 19:19:29 +01005055 return 0;
5056
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005057fail_add_vlan:
5058 efx_ef10_filter_cleanup_vlans(efx);
5059 efx->filter_state = NULL;
Ben Hutchings8127d662013-08-29 19:19:29 +01005060fail:
5061 kfree(table);
5062 return rc;
5063}
5064
Edward Cree0d322412015-05-20 11:10:03 +01005065/* Caller must hold efx->filter_sem for read if race against
5066 * efx_ef10_filter_table_remove() is possible
5067 */
Ben Hutchings8127d662013-08-29 19:19:29 +01005068static void efx_ef10_filter_table_restore(struct efx_nic *efx)
5069{
5070 struct efx_ef10_filter_table *table = efx->filter_state;
5071 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005072 unsigned int invalid_filters = 0, failed = 0;
5073 struct efx_ef10_filter_vlan *vlan;
Ben Hutchings8127d662013-08-29 19:19:29 +01005074 struct efx_filter_spec *spec;
5075 unsigned int filter_idx;
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005076 u32 mcdi_flags;
5077 int match_pri;
Edward Cree9b410802017-01-27 15:02:52 +00005078 int rc, i;
Ben Hutchings8127d662013-08-29 19:19:29 +01005079
Edward Cree0d322412015-05-20 11:10:03 +01005080 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5081
Ben Hutchings8127d662013-08-29 19:19:29 +01005082 if (!nic_data->must_restore_filters)
5083 return;
5084
Edward Cree0d322412015-05-20 11:10:03 +01005085 if (!table)
5086 return;
5087
Ben Hutchings8127d662013-08-29 19:19:29 +01005088 spin_lock_bh(&efx->filter_lock);
5089
5090 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5091 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5092 if (!spec)
5093 continue;
5094
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005095 mcdi_flags = efx_ef10_filter_mcdi_flags_from_spec(spec);
5096 match_pri = 0;
5097 while (match_pri < table->rx_match_count &&
5098 table->rx_match_mcdi_flags[match_pri] != mcdi_flags)
5099 ++match_pri;
5100 if (match_pri >= table->rx_match_count) {
5101 invalid_filters++;
5102 goto not_restored;
5103 }
5104 if (spec->rss_context != EFX_FILTER_RSS_CONTEXT_DEFAULT &&
5105 spec->rss_context != nic_data->rx_rss_context)
5106 netif_warn(efx, drv, efx->net_dev,
5107 "Warning: unable to restore a filter with specific RSS context.\n");
5108
Ben Hutchings8127d662013-08-29 19:19:29 +01005109 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY;
5110 spin_unlock_bh(&efx->filter_lock);
5111
5112 rc = efx_ef10_filter_push(efx, spec,
5113 &table->entry[filter_idx].handle,
5114 false);
5115 if (rc)
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005116 failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005117 spin_lock_bh(&efx->filter_lock);
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005118
Ben Hutchings8127d662013-08-29 19:19:29 +01005119 if (rc) {
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005120not_restored:
Edward Cree9b410802017-01-27 15:02:52 +00005121 list_for_each_entry(vlan, &table->vlan_list, list)
5122 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; ++i)
5123 if (vlan->default_filters[i] == filter_idx)
5124 vlan->default_filters[i] =
5125 EFX_EF10_FILTER_ID_INVALID;
5126
Ben Hutchings8127d662013-08-29 19:19:29 +01005127 kfree(spec);
5128 efx_ef10_filter_set_entry(table, filter_idx, NULL, 0);
5129 } else {
5130 table->entry[filter_idx].spec &=
5131 ~EFX_EF10_FILTER_FLAG_BUSY;
5132 }
5133 }
5134
5135 spin_unlock_bh(&efx->filter_lock);
5136
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005137 /* This can happen validly if the MC's capabilities have changed, so
5138 * is not an error.
5139 */
5140 if (invalid_filters)
5141 netif_dbg(efx, drv, efx->net_dev,
5142 "Did not restore %u filters that are now unsupported.\n",
5143 invalid_filters);
5144
Ben Hutchings8127d662013-08-29 19:19:29 +01005145 if (failed)
5146 netif_err(efx, hw, efx->net_dev,
Jon Cooper2d3d4ec2017-01-27 15:02:11 +00005147 "unable to restore %u filters\n", failed);
Ben Hutchings8127d662013-08-29 19:19:29 +01005148 else
5149 nic_data->must_restore_filters = false;
5150}
5151
5152static void efx_ef10_filter_table_remove(struct efx_nic *efx)
5153{
5154 struct efx_ef10_filter_table *table = efx->filter_state;
Martin Habetsbb53f4d2017-06-22 10:50:41 +01005155 MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_EXT_IN_LEN);
Ben Hutchings8127d662013-08-29 19:19:29 +01005156 struct efx_filter_spec *spec;
5157 unsigned int filter_idx;
5158 int rc;
5159
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005160 efx_ef10_filter_cleanup_vlans(efx);
Edward Cree0d322412015-05-20 11:10:03 +01005161 efx->filter_state = NULL;
Edward Creedd987082016-06-15 17:43:43 +01005162 /* If we were called without locking, then it's not safe to free
5163 * the table as others might be using it. So we just WARN, leak
5164 * the memory, and potentially get an inconsistent filter table
5165 * state.
5166 * This should never actually happen.
5167 */
5168 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5169 return;
5170
Edward Cree0d322412015-05-20 11:10:03 +01005171 if (!table)
5172 return;
5173
Ben Hutchings8127d662013-08-29 19:19:29 +01005174 for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) {
5175 spec = efx_ef10_filter_entry_spec(table, filter_idx);
5176 if (!spec)
5177 continue;
5178
5179 MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP,
5180 efx_ef10_filter_is_exclusive(spec) ?
5181 MC_CMD_FILTER_OP_IN_OP_REMOVE :
5182 MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE);
5183 MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE,
5184 table->entry[filter_idx].handle);
Bert Kenwarde65a5102015-12-23 08:57:36 +00005185 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FILTER_OP, inbuf,
5186 sizeof(inbuf), NULL, 0, NULL);
Ben Hutchings48ce5632013-11-01 16:42:44 +00005187 if (rc)
Bert Kenwarde65a5102015-12-23 08:57:36 +00005188 netif_info(efx, drv, efx->net_dev,
5189 "%s: filter %04x remove failed\n",
5190 __func__, filter_idx);
Ben Hutchings8127d662013-08-29 19:19:29 +01005191 kfree(spec);
5192 }
5193
5194 vfree(table->entry);
5195 kfree(table);
5196}
5197
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005198static void efx_ef10_filter_mark_one_old(struct efx_nic *efx, uint16_t *id)
5199{
5200 struct efx_ef10_filter_table *table = efx->filter_state;
5201 unsigned int filter_idx;
5202
5203 if (*id != EFX_EF10_FILTER_ID_INVALID) {
Jon Cooper0ccb9982017-02-17 15:49:13 +00005204 filter_idx = efx_ef10_filter_get_unsafe_id(*id);
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005205 if (!table->entry[filter_idx].spec)
5206 netif_dbg(efx, drv, efx->net_dev,
5207 "marked null spec old %04x:%04x\n", *id,
5208 filter_idx);
5209 table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD;
5210 *id = EFX_EF10_FILTER_ID_INVALID;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005211 }
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005212}
5213
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005214/* Mark old per-VLAN filters that may need to be removed */
5215static void _efx_ef10_filter_vlan_mark_old(struct efx_nic *efx,
5216 struct efx_ef10_filter_vlan *vlan)
Ben Hutchings8127d662013-08-29 19:19:29 +01005217{
5218 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko6a379582016-06-15 17:44:20 +01005219 unsigned int i;
Ben Hutchings8127d662013-08-29 19:19:29 +01005220
Edward Cree12fb0da2015-07-21 15:11:00 +01005221 for (i = 0; i < table->dev_uc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005222 efx_ef10_filter_mark_one_old(efx, &vlan->uc[i]);
Edward Cree12fb0da2015-07-21 15:11:00 +01005223 for (i = 0; i < table->dev_mc_count; i++)
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005224 efx_ef10_filter_mark_one_old(efx, &vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005225 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5226 efx_ef10_filter_mark_one_old(efx, &vlan->default_filters[i]);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005227}
5228
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005229/* Mark old filters that may need to be removed.
5230 * Caller must hold efx->filter_sem for read if race against
5231 * efx_ef10_filter_table_remove() is possible
5232 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005233static void efx_ef10_filter_mark_old(struct efx_nic *efx)
5234{
5235 struct efx_ef10_filter_table *table = efx->filter_state;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005236 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005237
5238 spin_lock_bh(&efx->filter_lock);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005239 list_for_each_entry(vlan, &table->vlan_list, list)
5240 _efx_ef10_filter_vlan_mark_old(efx, vlan);
Ben Hutchings8127d662013-08-29 19:19:29 +01005241 spin_unlock_bh(&efx->filter_lock);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005242}
Ben Hutchings8127d662013-08-29 19:19:29 +01005243
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005244static void efx_ef10_filter_uc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005245{
5246 struct efx_ef10_filter_table *table = efx->filter_state;
5247 struct net_device *net_dev = efx->net_dev;
5248 struct netdev_hw_addr *uc;
5249 unsigned int i;
5250
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005251 table->uc_promisc = !!(net_dev->flags & IFF_PROMISC);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005252 ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr);
5253 i = 1;
5254 netdev_for_each_uc_addr(uc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005255 if (i >= EFX_EF10_FILTER_DEV_UC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005256 table->uc_promisc = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005257 break;
5258 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005259 ether_addr_copy(table->dev_uc_list[i].addr, uc->addr);
5260 i++;
5261 }
Bert Kenwardc70d6812017-07-12 17:19:41 +01005262
5263 table->dev_uc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005264}
5265
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005266static void efx_ef10_filter_mc_addr_list(struct efx_nic *efx)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005267{
5268 struct efx_ef10_filter_table *table = efx->filter_state;
5269 struct net_device *net_dev = efx->net_dev;
5270 struct netdev_hw_addr *mc;
Bert Kenwardc70d6812017-07-12 17:19:41 +01005271 unsigned int i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005272
Edward Cree148cbab2017-04-04 17:02:49 +01005273 table->mc_overflow = false;
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005274 table->mc_promisc = !!(net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI));
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005275
Edward Cree12fb0da2015-07-21 15:11:00 +01005276 i = 0;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005277 netdev_for_each_mc_addr(mc, net_dev) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005278 if (i >= EFX_EF10_FILTER_DEV_MC_MAX) {
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005279 table->mc_promisc = true;
Edward Cree148cbab2017-04-04 17:02:49 +01005280 table->mc_overflow = true;
Edward Cree12fb0da2015-07-21 15:11:00 +01005281 break;
5282 }
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005283 ether_addr_copy(table->dev_mc_list[i].addr, mc->addr);
5284 i++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005285 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005286
5287 table->dev_mc_count = i;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005288}
Ben Hutchings8127d662013-08-29 19:19:29 +01005289
Edward Cree12fb0da2015-07-21 15:11:00 +01005290static int efx_ef10_filter_insert_addr_list(struct efx_nic *efx,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005291 struct efx_ef10_filter_vlan *vlan,
5292 bool multicast, bool rollback)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005293{
5294 struct efx_ef10_filter_table *table = efx->filter_state;
5295 struct efx_ef10_dev_addr *addr_list;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005296 enum efx_filter_flags filter_flags;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005297 struct efx_filter_spec spec;
Edward Cree12fb0da2015-07-21 15:11:00 +01005298 u8 baddr[ETH_ALEN];
5299 unsigned int i, j;
5300 int addr_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005301 u16 *ids;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005302 int rc;
5303
5304 if (multicast) {
5305 addr_list = table->dev_mc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005306 addr_count = table->dev_mc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005307 ids = vlan->mc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005308 } else {
5309 addr_list = table->dev_uc_list;
Edward Cree12fb0da2015-07-21 15:11:00 +01005310 addr_count = table->dev_uc_count;
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005311 ids = vlan->uc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005312 }
5313
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005314 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5315
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005316 /* Insert/renew filters */
Edward Cree12fb0da2015-07-21 15:11:00 +01005317 for (i = 0; i < addr_count; i++) {
Edward Creed58299a2017-06-29 16:50:06 +01005318 EFX_WARN_ON_PARANOID(ids[i] != EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005319 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005320 efx_filter_set_eth_local(&spec, vlan->vid, addr_list[i].addr);
Jon Cooperb6f568e2015-07-21 15:10:15 +01005321 rc = efx_ef10_filter_insert(efx, &spec, true);
5322 if (rc < 0) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005323 if (rollback) {
5324 netif_info(efx, drv, efx->net_dev,
5325 "efx_ef10_filter_insert failed rc=%d\n",
5326 rc);
5327 /* Fall back to promiscuous */
5328 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005329 efx_ef10_filter_remove_unsafe(
5330 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005331 ids[j]);
5332 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005333 }
5334 return rc;
5335 } else {
Edward Creed58299a2017-06-29 16:50:06 +01005336 /* keep invalid ID, and carry on */
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005337 }
Edward Creed58299a2017-06-29 16:50:06 +01005338 } else {
5339 ids[i] = efx_ef10_filter_get_unsafe_id(rc);
Ben Hutchings8127d662013-08-29 19:19:29 +01005340 }
5341 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005342
Edward Cree12fb0da2015-07-21 15:11:00 +01005343 if (multicast && rollback) {
5344 /* Also need an Ethernet broadcast filter */
Edward Cree9b410802017-01-27 15:02:52 +00005345 EFX_WARN_ON_PARANOID(vlan->default_filters[EFX_EF10_BCAST] !=
5346 EFX_EF10_FILTER_ID_INVALID);
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005347 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005348 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005349 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005350 rc = efx_ef10_filter_insert(efx, &spec, true);
Edward Cree12fb0da2015-07-21 15:11:00 +01005351 if (rc < 0) {
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005352 netif_warn(efx, drv, efx->net_dev,
Edward Cree12fb0da2015-07-21 15:11:00 +01005353 "Broadcast filter insert failed rc=%d\n", rc);
5354 /* Fall back to promiscuous */
5355 for (j = 0; j < i; j++) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005356 efx_ef10_filter_remove_unsafe(
5357 efx, EFX_FILTER_PRI_AUTO,
Andrew Rybchenkodc3273e2016-06-15 17:45:36 +01005358 ids[j]);
5359 ids[j] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005360 }
5361 return rc;
5362 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005363 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005364 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005365 }
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005366 }
Edward Cree12fb0da2015-07-21 15:11:00 +01005367
5368 return 0;
5369}
5370
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005371static int efx_ef10_filter_insert_def(struct efx_nic *efx,
5372 struct efx_ef10_filter_vlan *vlan,
Edward Cree9b410802017-01-27 15:02:52 +00005373 enum efx_encap_type encap_type,
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005374 bool multicast, bool rollback)
Edward Cree12fb0da2015-07-21 15:11:00 +01005375{
Edward Cree12fb0da2015-07-21 15:11:00 +01005376 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005377 enum efx_filter_flags filter_flags;
Edward Cree12fb0da2015-07-21 15:11:00 +01005378 struct efx_filter_spec spec;
5379 u8 baddr[ETH_ALEN];
5380 int rc;
Edward Cree9b410802017-01-27 15:02:52 +00005381 u16 *id;
Edward Cree12fb0da2015-07-21 15:11:00 +01005382
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005383 filter_flags = efx_rss_enabled(efx) ? EFX_FILTER_FLAG_RX_RSS : 0;
5384
5385 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005386
5387 if (multicast)
5388 efx_filter_set_mc_def(&spec);
5389 else
5390 efx_filter_set_uc_def(&spec);
5391
Edward Cree9b410802017-01-27 15:02:52 +00005392 if (encap_type) {
5393 if (nic_data->datapath_caps &
5394 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))
5395 efx_filter_set_encap_type(&spec, encap_type);
5396 else
5397 /* don't insert encap filters on non-supporting
5398 * platforms. ID will be left as INVALID.
5399 */
5400 return 0;
5401 }
5402
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005403 if (vlan->vid != EFX_FILTER_VID_UNSPEC)
5404 efx_filter_set_eth_local(&spec, vlan->vid, NULL);
5405
Edward Cree12fb0da2015-07-21 15:11:00 +01005406 rc = efx_ef10_filter_insert(efx, &spec, true);
5407 if (rc < 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005408 const char *um = multicast ? "Multicast" : "Unicast";
5409 const char *encap_name = "";
5410 const char *encap_ipv = "";
5411
5412 if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5413 EFX_ENCAP_TYPE_VXLAN)
5414 encap_name = "VXLAN ";
5415 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5416 EFX_ENCAP_TYPE_NVGRE)
5417 encap_name = "NVGRE ";
5418 else if ((encap_type & EFX_ENCAP_TYPES_MASK) ==
5419 EFX_ENCAP_TYPE_GENEVE)
5420 encap_name = "GENEVE ";
5421 if (encap_type & EFX_ENCAP_FLAG_IPV6)
5422 encap_ipv = "IPv6 ";
5423 else if (encap_type)
5424 encap_ipv = "IPv4 ";
5425
5426 /* unprivileged functions can't insert mismatch filters
5427 * for encapsulated or unicast traffic, so downgrade
5428 * those warnings to debug.
5429 */
Jon Cooper34e7aef2017-01-27 15:02:39 +00005430 netif_cond_dbg(efx, drv, efx->net_dev,
Edward Cree9b410802017-01-27 15:02:52 +00005431 rc == -EPERM && (encap_type || !multicast), warn,
5432 "%s%s%s mismatch filter insert failed rc=%d\n",
5433 encap_name, encap_ipv, um, rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005434 } else if (multicast) {
Edward Cree9b410802017-01-27 15:02:52 +00005435 /* mapping from encap types to default filter IDs (multicast) */
5436 static enum efx_ef10_default_filters map[] = {
5437 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_MCDEF,
5438 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_MCDEF,
5439 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_MCDEF,
5440 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_MCDEF,
5441 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5442 EFX_EF10_VXLAN6_MCDEF,
5443 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5444 EFX_EF10_NVGRE6_MCDEF,
5445 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5446 EFX_EF10_GENEVE6_MCDEF,
5447 };
5448
5449 /* quick bounds check (BCAST result impossible) */
5450 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Colin Ian Kinge9904992017-01-31 16:30:02 +00005451 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005452 WARN_ON(1);
5453 return -EINVAL;
5454 }
5455 /* then follow map */
5456 id = &vlan->default_filters[map[encap_type]];
5457
5458 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
Jon Cooper0ccb9982017-02-17 15:49:13 +00005459 *id = efx_ef10_filter_get_unsafe_id(rc);
Edward Cree9b410802017-01-27 15:02:52 +00005460 if (!nic_data->workaround_26807 && !encap_type) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005461 /* Also need an Ethernet broadcast filter */
5462 efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO,
Bert Kenwardf1c2ef42015-12-11 09:39:32 +00005463 filter_flags, 0);
Edward Cree12fb0da2015-07-21 15:11:00 +01005464 eth_broadcast_addr(baddr);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005465 efx_filter_set_eth_local(&spec, vlan->vid, baddr);
Edward Cree12fb0da2015-07-21 15:11:00 +01005466 rc = efx_ef10_filter_insert(efx, &spec, true);
5467 if (rc < 0) {
5468 netif_warn(efx, drv, efx->net_dev,
5469 "Broadcast filter insert failed rc=%d\n",
5470 rc);
5471 if (rollback) {
5472 /* Roll back the mc_def filter */
5473 efx_ef10_filter_remove_unsafe(
5474 efx, EFX_FILTER_PRI_AUTO,
Edward Cree9b410802017-01-27 15:02:52 +00005475 *id);
5476 *id = EFX_EF10_FILTER_ID_INVALID;
Edward Cree12fb0da2015-07-21 15:11:00 +01005477 return rc;
5478 }
5479 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005480 EFX_WARN_ON_PARANOID(
5481 vlan->default_filters[EFX_EF10_BCAST] !=
5482 EFX_EF10_FILTER_ID_INVALID);
5483 vlan->default_filters[EFX_EF10_BCAST] =
Jon Cooper0ccb9982017-02-17 15:49:13 +00005484 efx_ef10_filter_get_unsafe_id(rc);
Edward Cree12fb0da2015-07-21 15:11:00 +01005485 }
5486 }
5487 rc = 0;
5488 } else {
Edward Cree9b410802017-01-27 15:02:52 +00005489 /* mapping from encap types to default filter IDs (unicast) */
5490 static enum efx_ef10_default_filters map[] = {
5491 [EFX_ENCAP_TYPE_NONE] = EFX_EF10_UCDEF,
5492 [EFX_ENCAP_TYPE_VXLAN] = EFX_EF10_VXLAN4_UCDEF,
5493 [EFX_ENCAP_TYPE_NVGRE] = EFX_EF10_NVGRE4_UCDEF,
5494 [EFX_ENCAP_TYPE_GENEVE] = EFX_EF10_GENEVE4_UCDEF,
5495 [EFX_ENCAP_TYPE_VXLAN | EFX_ENCAP_FLAG_IPV6] =
5496 EFX_EF10_VXLAN6_UCDEF,
5497 [EFX_ENCAP_TYPE_NVGRE | EFX_ENCAP_FLAG_IPV6] =
5498 EFX_EF10_NVGRE6_UCDEF,
5499 [EFX_ENCAP_TYPE_GENEVE | EFX_ENCAP_FLAG_IPV6] =
5500 EFX_EF10_GENEVE6_UCDEF,
5501 };
5502
5503 /* quick bounds check (BCAST result impossible) */
5504 BUILD_BUG_ON(EFX_EF10_BCAST != 0);
Dan Carpenteree467fb2017-02-07 10:44:31 +03005505 if (encap_type >= ARRAY_SIZE(map) || map[encap_type] == 0) {
Edward Cree9b410802017-01-27 15:02:52 +00005506 WARN_ON(1);
5507 return -EINVAL;
5508 }
5509 /* then follow map */
5510 id = &vlan->default_filters[map[encap_type]];
5511 EFX_WARN_ON_PARANOID(*id != EFX_EF10_FILTER_ID_INVALID);
5512 *id = rc;
Edward Cree12fb0da2015-07-21 15:11:00 +01005513 rc = 0;
5514 }
5515 return rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005516}
5517
5518/* Remove filters that weren't renewed. Since nothing else changes the AUTO_OLD
5519 * flag or removes these filters, we don't need to hold the filter_lock while
5520 * scanning for these filters.
5521 */
5522static void efx_ef10_filter_remove_old(struct efx_nic *efx)
5523{
5524 struct efx_ef10_filter_table *table = efx->filter_state;
Bert Kenwarde65a5102015-12-23 08:57:36 +00005525 int remove_failed = 0;
5526 int remove_noent = 0;
5527 int rc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005528 int i;
5529
Ben Hutchings8127d662013-08-29 19:19:29 +01005530 for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07005531 if (READ_ONCE(table->entry[i].spec) &
Ben Hutchingsb59e6ef2013-11-21 19:02:22 +00005532 EFX_EF10_FILTER_FLAG_AUTO_OLD) {
Bert Kenwarde65a5102015-12-23 08:57:36 +00005533 rc = efx_ef10_filter_remove_internal(efx,
5534 1U << EFX_FILTER_PRI_AUTO, i, true);
5535 if (rc == -ENOENT)
5536 remove_noent++;
5537 else if (rc)
5538 remove_failed++;
Ben Hutchings8127d662013-08-29 19:19:29 +01005539 }
5540 }
Bert Kenwarde65a5102015-12-23 08:57:36 +00005541
5542 if (remove_failed)
5543 netif_info(efx, drv, efx->net_dev,
5544 "%s: failed to remove %d filters\n",
5545 __func__, remove_failed);
5546 if (remove_noent)
5547 netif_info(efx, drv, efx->net_dev,
5548 "%s: failed to remove %d non-existent filters\n",
5549 __func__, remove_noent);
Ben Hutchings8127d662013-08-29 19:19:29 +01005550}
5551
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005552static int efx_ef10_vport_set_mac_address(struct efx_nic *efx)
5553{
5554 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5555 u8 mac_old[ETH_ALEN];
5556 int rc, rc2;
5557
5558 /* Only reconfigure a PF-created vport */
5559 if (is_zero_ether_addr(nic_data->vport_mac))
5560 return 0;
5561
5562 efx_device_detach_sync(efx);
5563 efx_net_stop(efx->net_dev);
5564 down_write(&efx->filter_sem);
5565 efx_ef10_filter_table_remove(efx);
5566 up_write(&efx->filter_sem);
5567
5568 rc = efx_ef10_vadaptor_free(efx, nic_data->vport_id);
5569 if (rc)
5570 goto restore_filters;
5571
5572 ether_addr_copy(mac_old, nic_data->vport_mac);
5573 rc = efx_ef10_vport_del_mac(efx, nic_data->vport_id,
5574 nic_data->vport_mac);
5575 if (rc)
5576 goto restore_vadaptor;
5577
5578 rc = efx_ef10_vport_add_mac(efx, nic_data->vport_id,
5579 efx->net_dev->dev_addr);
5580 if (!rc) {
5581 ether_addr_copy(nic_data->vport_mac, efx->net_dev->dev_addr);
5582 } else {
5583 rc2 = efx_ef10_vport_add_mac(efx, nic_data->vport_id, mac_old);
5584 if (rc2) {
5585 /* Failed to add original MAC, so clear vport_mac */
5586 eth_zero_addr(nic_data->vport_mac);
5587 goto reset_nic;
5588 }
5589 }
5590
5591restore_vadaptor:
5592 rc2 = efx_ef10_vadaptor_alloc(efx, nic_data->vport_id);
5593 if (rc2)
5594 goto reset_nic;
5595restore_filters:
5596 down_write(&efx->filter_sem);
5597 rc2 = efx_ef10_filter_table_probe(efx);
5598 up_write(&efx->filter_sem);
5599 if (rc2)
5600 goto reset_nic;
5601
5602 rc2 = efx_net_open(efx->net_dev);
5603 if (rc2)
5604 goto reset_nic;
5605
Peter Dunning9c568fd2017-02-17 15:50:43 +00005606 efx_device_attach_if_not_resetting(efx);
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005607
5608 return rc;
5609
5610reset_nic:
5611 netif_err(efx, drv, efx->net_dev,
5612 "Failed to restore when changing MAC address - scheduling reset\n");
5613 efx_schedule_reset(efx, RESET_TYPE_DATAPATH);
5614
5615 return rc ? rc : rc2;
5616}
5617
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005618/* Caller must hold efx->filter_sem for read if race against
5619 * efx_ef10_filter_table_remove() is possible
5620 */
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005621static void efx_ef10_filter_vlan_sync_rx_mode(struct efx_nic *efx,
5622 struct efx_ef10_filter_vlan *vlan)
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005623{
5624 struct efx_ef10_filter_table *table = efx->filter_state;
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005625 struct efx_ef10_nic_data *nic_data = efx->nic_data;
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005626
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005627 /* Do not install unspecified VID if VLAN filtering is enabled.
5628 * Do not install all specified VIDs if VLAN filtering is disabled.
5629 */
5630 if ((vlan->vid == EFX_FILTER_VID_UNSPEC) == table->vlan_filter)
5631 return;
5632
Edward Cree12fb0da2015-07-21 15:11:00 +01005633 /* Insert/renew unicast filters */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005634 if (table->uc_promisc) {
Edward Cree9b410802017-01-27 15:02:52 +00005635 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NONE,
5636 false, false);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005637 efx_ef10_filter_insert_addr_list(efx, vlan, false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005638 } else {
5639 /* If any of the filters failed to insert, fall back to
5640 * promiscuous mode - add in the uc_def filter. But keep
5641 * our individual unicast filters.
5642 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005643 if (efx_ef10_filter_insert_addr_list(efx, vlan, false, false))
Edward Cree9b410802017-01-27 15:02:52 +00005644 efx_ef10_filter_insert_def(efx, vlan,
5645 EFX_ENCAP_TYPE_NONE,
5646 false, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005647 }
Edward Cree9b410802017-01-27 15:02:52 +00005648 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5649 false, false);
5650 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5651 EFX_ENCAP_FLAG_IPV6,
5652 false, false);
5653 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5654 false, false);
5655 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5656 EFX_ENCAP_FLAG_IPV6,
5657 false, false);
5658 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5659 false, false);
5660 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5661 EFX_ENCAP_FLAG_IPV6,
5662 false, false);
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005663
Edward Cree12fb0da2015-07-21 15:11:00 +01005664 /* Insert/renew multicast filters */
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005665 /* If changing promiscuous state with cascaded multicast filters, remove
5666 * old filters first, so that packets are dropped rather than duplicated
5667 */
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005668 if (nic_data->workaround_26807 &&
5669 table->mc_promisc_last != table->mc_promisc)
Daniel Pieczkoab8b1f7c2015-07-21 15:10:44 +01005670 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005671 if (table->mc_promisc) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005672 if (nic_data->workaround_26807) {
5673 /* If we failed to insert promiscuous filters, rollback
5674 * and fall back to individual multicast filters
5675 */
Edward Cree9b410802017-01-27 15:02:52 +00005676 if (efx_ef10_filter_insert_def(efx, vlan,
5677 EFX_ENCAP_TYPE_NONE,
5678 true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005679 /* Changing promisc state, so remove old filters */
5680 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005681 efx_ef10_filter_insert_addr_list(efx, vlan,
5682 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005683 }
5684 } else {
5685 /* If we failed to insert promiscuous filters, don't
Edward Cree148cbab2017-04-04 17:02:49 +01005686 * rollback. Regardless, also insert the mc_list,
5687 * unless it's incomplete due to overflow
Edward Cree12fb0da2015-07-21 15:11:00 +01005688 */
Edward Cree9b410802017-01-27 15:02:52 +00005689 efx_ef10_filter_insert_def(efx, vlan,
5690 EFX_ENCAP_TYPE_NONE,
5691 true, false);
Edward Cree148cbab2017-04-04 17:02:49 +01005692 if (!table->mc_overflow)
5693 efx_ef10_filter_insert_addr_list(efx, vlan,
5694 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005695 }
5696 } else {
5697 /* If any filters failed to insert, rollback and fall back to
5698 * promiscuous mode - mc_def filter and maybe broadcast. If
5699 * that fails, roll back again and insert as many of our
5700 * individual multicast filters as we can.
5701 */
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005702 if (efx_ef10_filter_insert_addr_list(efx, vlan, true, true)) {
Edward Cree12fb0da2015-07-21 15:11:00 +01005703 /* Changing promisc state, so remove old filters */
5704 if (nic_data->workaround_26807)
5705 efx_ef10_filter_remove_old(efx);
Edward Cree9b410802017-01-27 15:02:52 +00005706 if (efx_ef10_filter_insert_def(efx, vlan,
5707 EFX_ENCAP_TYPE_NONE,
5708 true, true))
Andrew Rybchenkob3a3c032016-06-15 17:47:36 +01005709 efx_ef10_filter_insert_addr_list(efx, vlan,
5710 true, false);
Edward Cree12fb0da2015-07-21 15:11:00 +01005711 }
5712 }
Edward Cree9b410802017-01-27 15:02:52 +00005713 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN,
5714 true, false);
5715 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_VXLAN |
5716 EFX_ENCAP_FLAG_IPV6,
5717 true, false);
5718 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE,
5719 true, false);
5720 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_NVGRE |
5721 EFX_ENCAP_FLAG_IPV6,
5722 true, false);
5723 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE,
5724 true, false);
5725 efx_ef10_filter_insert_def(efx, vlan, EFX_ENCAP_TYPE_GENEVE |
5726 EFX_ENCAP_FLAG_IPV6,
5727 true, false);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005728}
5729
5730/* Caller must hold efx->filter_sem for read if race against
5731 * efx_ef10_filter_table_remove() is possible
5732 */
5733static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx)
5734{
5735 struct efx_ef10_filter_table *table = efx->filter_state;
5736 struct net_device *net_dev = efx->net_dev;
5737 struct efx_ef10_filter_vlan *vlan;
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005738 bool vlan_filter;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005739
5740 if (!efx_dev_registered(efx))
5741 return;
5742
5743 if (!table)
5744 return;
5745
5746 efx_ef10_filter_mark_old(efx);
5747
5748 /* Copy/convert the address lists; add the primary station
5749 * address and broadcast address
5750 */
5751 netif_addr_lock_bh(net_dev);
5752 efx_ef10_filter_uc_addr_list(efx);
5753 efx_ef10_filter_mc_addr_list(efx);
5754 netif_addr_unlock_bh(net_dev);
5755
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01005756 /* If VLAN filtering changes, all old filters are finally removed.
5757 * Do it in advance to avoid conflicts for unicast untagged and
5758 * VLAN 0 tagged filters.
5759 */
5760 vlan_filter = !!(net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER);
5761 if (table->vlan_filter != vlan_filter) {
5762 table->vlan_filter = vlan_filter;
5763 efx_ef10_filter_remove_old(efx);
5764 }
5765
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005766 list_for_each_entry(vlan, &table->vlan_list, list)
5767 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005768
5769 efx_ef10_filter_remove_old(efx);
Andrew Rybchenkoafa4ce12016-06-15 17:45:56 +01005770 table->mc_promisc_last = table->mc_promisc;
Daniel Pieczko822b96f2015-07-21 15:10:27 +01005771}
5772
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005773static struct efx_ef10_filter_vlan *efx_ef10_filter_find_vlan(struct efx_nic *efx, u16 vid)
5774{
5775 struct efx_ef10_filter_table *table = efx->filter_state;
5776 struct efx_ef10_filter_vlan *vlan;
5777
5778 WARN_ON(!rwsem_is_locked(&efx->filter_sem));
5779
5780 list_for_each_entry(vlan, &table->vlan_list, list) {
5781 if (vlan->vid == vid)
5782 return vlan;
5783 }
5784
5785 return NULL;
5786}
5787
5788static int efx_ef10_filter_add_vlan(struct efx_nic *efx, u16 vid)
5789{
5790 struct efx_ef10_filter_table *table = efx->filter_state;
5791 struct efx_ef10_filter_vlan *vlan;
5792 unsigned int i;
5793
5794 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5795 return -EINVAL;
5796
5797 vlan = efx_ef10_filter_find_vlan(efx, vid);
5798 if (WARN_ON(vlan)) {
5799 netif_err(efx, drv, efx->net_dev,
5800 "VLAN %u already added\n", vid);
5801 return -EALREADY;
5802 }
5803
5804 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
5805 if (!vlan)
5806 return -ENOMEM;
5807
5808 vlan->vid = vid;
5809
5810 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
5811 vlan->uc[i] = EFX_EF10_FILTER_ID_INVALID;
5812 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
5813 vlan->mc[i] = EFX_EF10_FILTER_ID_INVALID;
Edward Cree9b410802017-01-27 15:02:52 +00005814 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5815 vlan->default_filters[i] = EFX_EF10_FILTER_ID_INVALID;
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005816
5817 list_add_tail(&vlan->list, &table->vlan_list);
5818
5819 if (efx_dev_registered(efx))
5820 efx_ef10_filter_vlan_sync_rx_mode(efx, vlan);
5821
5822 return 0;
5823}
5824
5825static void efx_ef10_filter_del_vlan_internal(struct efx_nic *efx,
5826 struct efx_ef10_filter_vlan *vlan)
5827{
5828 unsigned int i;
5829
5830 /* See comment in efx_ef10_filter_table_remove() */
5831 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5832 return;
5833
5834 list_del(&vlan->list);
5835
Edward Cree8c915622016-06-15 17:49:05 +01005836 for (i = 0; i < ARRAY_SIZE(vlan->uc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005837 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005838 vlan->uc[i]);
5839 for (i = 0; i < ARRAY_SIZE(vlan->mc); i++)
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005840 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
Edward Cree8c915622016-06-15 17:49:05 +01005841 vlan->mc[i]);
Edward Cree9b410802017-01-27 15:02:52 +00005842 for (i = 0; i < EFX_EF10_NUM_DEFAULT_FILTERS; i++)
5843 if (vlan->default_filters[i] != EFX_EF10_FILTER_ID_INVALID)
5844 efx_ef10_filter_remove_unsafe(efx, EFX_FILTER_PRI_AUTO,
5845 vlan->default_filters[i]);
Andrew Rybchenko34813fe2016-06-15 17:48:14 +01005846
5847 kfree(vlan);
5848}
5849
5850static void efx_ef10_filter_del_vlan(struct efx_nic *efx, u16 vid)
5851{
5852 struct efx_ef10_filter_vlan *vlan;
5853
5854 /* See comment in efx_ef10_filter_table_remove() */
5855 if (!efx_rwsem_assert_write_locked(&efx->filter_sem))
5856 return;
5857
5858 vlan = efx_ef10_filter_find_vlan(efx, vid);
5859 if (!vlan) {
5860 netif_err(efx, drv, efx->net_dev,
5861 "VLAN %u not found in filter state\n", vid);
5862 return;
5863 }
5864
5865 efx_ef10_filter_del_vlan_internal(efx, vlan);
5866}
5867
Shradha Shah910c8782015-05-20 11:12:48 +01005868static int efx_ef10_set_mac_address(struct efx_nic *efx)
5869{
5870 MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN);
5871 struct efx_ef10_nic_data *nic_data = efx->nic_data;
5872 bool was_enabled = efx->port_enabled;
5873 int rc;
5874
5875 efx_device_detach_sync(efx);
5876 efx_net_stop(efx->net_dev);
Martin Habetsd2489532016-06-15 17:48:49 +01005877
5878 mutex_lock(&efx->mac_lock);
Shradha Shah910c8782015-05-20 11:12:48 +01005879 down_write(&efx->filter_sem);
5880 efx_ef10_filter_table_remove(efx);
5881
5882 ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR),
5883 efx->net_dev->dev_addr);
5884 MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID,
5885 nic_data->vport_id);
Daniel Pieczko535a6172015-07-07 11:37:33 +01005886 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf,
5887 sizeof(inbuf), NULL, 0, NULL);
Shradha Shah910c8782015-05-20 11:12:48 +01005888
5889 efx_ef10_filter_table_probe(efx);
5890 up_write(&efx->filter_sem);
Martin Habetsd2489532016-06-15 17:48:49 +01005891 mutex_unlock(&efx->mac_lock);
5892
Shradha Shah910c8782015-05-20 11:12:48 +01005893 if (was_enabled)
5894 efx_net_open(efx->net_dev);
Peter Dunning9c568fd2017-02-17 15:50:43 +00005895 efx_device_attach_if_not_resetting(efx);
Shradha Shah910c8782015-05-20 11:12:48 +01005896
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005897#ifdef CONFIG_SFC_SRIOV
5898 if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) {
Shradha Shah910c8782015-05-20 11:12:48 +01005899 struct pci_dev *pci_dev_pf = efx->pci_dev->physfn;
5900
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005901 if (rc == -EPERM) {
5902 struct efx_nic *efx_pf;
Shradha Shah910c8782015-05-20 11:12:48 +01005903
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005904 /* Switch to PF and change MAC address on vport */
5905 efx_pf = pci_get_drvdata(pci_dev_pf);
5906
5907 rc = efx_ef10_sriov_set_vf_mac(efx_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01005908 nic_data->vf_index,
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005909 efx->net_dev->dev_addr);
5910 } else if (!rc) {
Shradha Shah910c8782015-05-20 11:12:48 +01005911 struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf);
5912 struct efx_ef10_nic_data *nic_data = efx_pf->nic_data;
5913 unsigned int i;
5914
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005915 /* MAC address successfully changed by VF (with MAC
5916 * spoofing) so update the parent PF if possible.
5917 */
Shradha Shah910c8782015-05-20 11:12:48 +01005918 for (i = 0; i < efx_pf->vf_count; ++i) {
5919 struct ef10_vf *vf = nic_data->vf + i;
5920
5921 if (vf->efx == efx) {
5922 ether_addr_copy(vf->mac,
5923 efx->net_dev->dev_addr);
5924 return 0;
5925 }
5926 }
5927 }
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005928 } else
Shradha Shah910c8782015-05-20 11:12:48 +01005929#endif
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005930 if (rc == -EPERM) {
5931 netif_err(efx, drv, efx->net_dev,
5932 "Cannot change MAC address; use sfboot to enable"
5933 " mac-spoofing on this interface\n");
Daniel Pieczko7a186f42015-07-07 11:37:19 +01005934 } else if (rc == -ENOSYS && !efx_ef10_is_vf(efx)) {
5935 /* If the active MCFW does not support MC_CMD_VADAPTOR_SET_MAC
5936 * fall-back to the method of changing the MAC address on the
5937 * vport. This only applies to PFs because such versions of
5938 * MCFW do not support VFs.
5939 */
5940 rc = efx_ef10_vport_set_mac_address(efx);
Robert Stonehousecbad52e2017-11-07 17:30:30 +00005941 } else if (rc) {
Daniel Pieczko535a6172015-07-07 11:37:33 +01005942 efx_mcdi_display_error(efx, MC_CMD_VADAPTOR_SET_MAC,
5943 sizeof(inbuf), NULL, 0, rc);
Daniel Pieczko9e9f6652015-07-07 11:37:00 +01005944 }
5945
Shradha Shah910c8782015-05-20 11:12:48 +01005946 return rc;
5947}
5948
Ben Hutchings8127d662013-08-29 19:19:29 +01005949static int efx_ef10_mac_reconfigure(struct efx_nic *efx)
5950{
5951 efx_ef10_filter_sync_rx_mode(efx);
5952
5953 return efx_mcdi_set_mac(efx);
5954}
5955
Shradha Shah862f8942015-05-20 11:08:56 +01005956static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx)
5957{
5958 efx_ef10_filter_sync_rx_mode(efx);
5959
5960 return 0;
5961}
5962
Jon Cooper74cd60a2013-09-16 14:18:51 +01005963static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type)
5964{
5965 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
5966
5967 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type);
5968 return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf),
5969 NULL, 0, NULL);
5970}
5971
5972/* MC BISTs follow a different poll mechanism to phy BISTs.
5973 * The BIST is done in the poll handler on the MC, and the MCDI command
5974 * will block until the BIST is done.
5975 */
5976static int efx_ef10_poll_bist(struct efx_nic *efx)
5977{
5978 int rc;
5979 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN);
5980 size_t outlen;
5981 u32 result;
5982
5983 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
5984 outbuf, sizeof(outbuf), &outlen);
5985 if (rc != 0)
5986 return rc;
5987
5988 if (outlen < MC_CMD_POLL_BIST_OUT_LEN)
5989 return -EIO;
5990
5991 result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
5992 switch (result) {
5993 case MC_CMD_POLL_BIST_PASSED:
5994 netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n");
5995 return 0;
5996 case MC_CMD_POLL_BIST_TIMEOUT:
5997 netif_err(efx, hw, efx->net_dev, "BIST timed out\n");
5998 return -EIO;
5999 case MC_CMD_POLL_BIST_FAILED:
6000 netif_err(efx, hw, efx->net_dev, "BIST failed.\n");
6001 return -EIO;
6002 default:
6003 netif_err(efx, hw, efx->net_dev,
6004 "BIST returned unknown result %u", result);
6005 return -EIO;
6006 }
6007}
6008
6009static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type)
6010{
6011 int rc;
6012
6013 netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type);
6014
6015 rc = efx_ef10_start_bist(efx, bist_type);
6016 if (rc != 0)
6017 return rc;
6018
6019 return efx_ef10_poll_bist(efx);
6020}
6021
6022static int
6023efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests)
6024{
6025 int rc, rc2;
6026
6027 efx_reset_down(efx, RESET_TYPE_WORLD);
6028
6029 rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST,
6030 NULL, 0, NULL, 0, NULL);
6031 if (rc != 0)
6032 goto out;
6033
6034 tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1;
6035 tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1;
6036
6037 rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD);
6038
6039out:
Daniel Pieczko27324822015-07-31 11:14:54 +01006040 if (rc == -EPERM)
6041 rc = 0;
Jon Cooper74cd60a2013-09-16 14:18:51 +01006042 rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0);
6043 return rc ? rc : rc2;
6044}
6045
Ben Hutchings8127d662013-08-29 19:19:29 +01006046#ifdef CONFIG_SFC_MTD
6047
6048struct efx_ef10_nvram_type_info {
6049 u16 type, type_mask;
6050 u8 port;
6051 const char *name;
6052};
6053
6054static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = {
6055 { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" },
6056 { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" },
6057 { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" },
6058 { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" },
6059 { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" },
6060 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" },
6061 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" },
6062 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" },
6063 { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" },
Ben Hutchingsa84f3bf92013-10-09 14:14:41 +01006064 { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" },
Ben Hutchings8127d662013-08-29 19:19:29 +01006065 { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" },
6066};
6067
6068static int efx_ef10_mtd_probe_partition(struct efx_nic *efx,
6069 struct efx_mcdi_mtd_partition *part,
6070 unsigned int type)
6071{
6072 MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN);
6073 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX);
6074 const struct efx_ef10_nvram_type_info *info;
6075 size_t size, erase_size, outlen;
6076 bool protected;
6077 int rc;
6078
6079 for (info = efx_ef10_nvram_types; ; info++) {
6080 if (info ==
6081 efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types))
6082 return -ENODEV;
6083 if ((type & ~info->type_mask) == info->type)
6084 break;
6085 }
6086 if (info->port != efx_port_num(efx))
6087 return -ENODEV;
6088
6089 rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected);
6090 if (rc)
6091 return rc;
6092 if (protected)
6093 return -ENODEV; /* hide it */
6094
6095 part->nvram_type = type;
6096
6097 MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type);
6098 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf),
6099 outbuf, sizeof(outbuf), &outlen);
6100 if (rc)
6101 return rc;
6102 if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN)
6103 return -EIO;
6104 if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) &
6105 (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN))
6106 part->fw_subtype = MCDI_DWORD(outbuf,
6107 NVRAM_METADATA_OUT_SUBTYPE);
6108
6109 part->common.dev_type_name = "EF10 NVRAM manager";
6110 part->common.type_name = info->name;
6111
6112 part->common.mtd.type = MTD_NORFLASH;
6113 part->common.mtd.flags = MTD_CAP_NORFLASH;
6114 part->common.mtd.size = size;
6115 part->common.mtd.erasesize = erase_size;
6116
6117 return 0;
6118}
6119
6120static int efx_ef10_mtd_probe(struct efx_nic *efx)
6121{
6122 MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX);
6123 struct efx_mcdi_mtd_partition *parts;
6124 size_t outlen, n_parts_total, i, n_parts;
6125 unsigned int type;
6126 int rc;
6127
6128 ASSERT_RTNL();
6129
6130 BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0);
6131 rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0,
6132 outbuf, sizeof(outbuf), &outlen);
6133 if (rc)
6134 return rc;
6135 if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN)
6136 return -EIO;
6137
6138 n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS);
6139 if (n_parts_total >
6140 MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID))
6141 return -EIO;
6142
6143 parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL);
6144 if (!parts)
6145 return -ENOMEM;
6146
6147 n_parts = 0;
6148 for (i = 0; i < n_parts_total; i++) {
6149 type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID,
6150 i);
6151 rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type);
6152 if (rc == 0)
6153 n_parts++;
6154 else if (rc != -ENODEV)
6155 goto fail;
6156 }
6157
6158 rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts));
6159fail:
6160 if (rc)
6161 kfree(parts);
6162 return rc;
6163}
6164
6165#endif /* CONFIG_SFC_MTD */
6166
6167static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time)
6168{
6169 _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD);
6170}
6171
Shradha Shah02246a72015-05-06 00:58:14 +01006172static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx,
6173 u32 host_time) {}
6174
Jon Cooperbd9a2652013-11-18 12:54:41 +00006175static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel,
6176 bool temp)
6177{
6178 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN);
6179 int rc;
6180
6181 if (channel->sync_events_state == SYNC_EVENTS_REQUESTED ||
6182 channel->sync_events_state == SYNC_EVENTS_VALID ||
6183 (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED))
6184 return 0;
6185 channel->sync_events_state = SYNC_EVENTS_REQUESTED;
6186
6187 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE);
6188 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6189 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE,
6190 channel->channel);
6191
6192 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6193 inbuf, sizeof(inbuf), NULL, 0, NULL);
6194
6195 if (rc != 0)
6196 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6197 SYNC_EVENTS_DISABLED;
6198
6199 return rc;
6200}
6201
6202static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel,
6203 bool temp)
6204{
6205 MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN);
6206 int rc;
6207
6208 if (channel->sync_events_state == SYNC_EVENTS_DISABLED ||
6209 (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT))
6210 return 0;
6211 if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) {
6212 channel->sync_events_state = SYNC_EVENTS_DISABLED;
6213 return 0;
6214 }
6215 channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT :
6216 SYNC_EVENTS_DISABLED;
6217
6218 MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE);
6219 MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0);
6220 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL,
6221 MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE);
6222 MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE,
6223 channel->channel);
6224
6225 rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP,
6226 inbuf, sizeof(inbuf), NULL, 0, NULL);
6227
6228 return rc;
6229}
6230
6231static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en,
6232 bool temp)
6233{
6234 int (*set)(struct efx_channel *channel, bool temp);
6235 struct efx_channel *channel;
6236
6237 set = en ?
6238 efx_ef10_rx_enable_timestamping :
6239 efx_ef10_rx_disable_timestamping;
6240
6241 efx_for_each_channel(channel, efx) {
6242 int rc = set(channel, temp);
6243 if (en && rc != 0) {
6244 efx_ef10_ptp_set_ts_sync_events(efx, false, temp);
6245 return rc;
6246 }
6247 }
6248
6249 return 0;
6250}
6251
Shradha Shah02246a72015-05-06 00:58:14 +01006252static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx,
6253 struct hwtstamp_config *init)
6254{
6255 return -EOPNOTSUPP;
6256}
6257
Jon Cooperbd9a2652013-11-18 12:54:41 +00006258static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx,
6259 struct hwtstamp_config *init)
6260{
6261 int rc;
6262
6263 switch (init->rx_filter) {
6264 case HWTSTAMP_FILTER_NONE:
6265 efx_ef10_ptp_set_ts_sync_events(efx, false, false);
6266 /* if TX timestamping is still requested then leave PTP on */
6267 return efx_ptp_change_mode(efx,
6268 init->tx_type != HWTSTAMP_TX_OFF, 0);
6269 case HWTSTAMP_FILTER_ALL:
6270 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
6271 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
6272 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
6273 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
6274 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
6275 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
6276 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
6277 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
6278 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
6279 case HWTSTAMP_FILTER_PTP_V2_EVENT:
6280 case HWTSTAMP_FILTER_PTP_V2_SYNC:
6281 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Miroslav Lichvare3412572017-05-19 17:52:36 +02006282 case HWTSTAMP_FILTER_NTP_ALL:
Jon Cooperbd9a2652013-11-18 12:54:41 +00006283 init->rx_filter = HWTSTAMP_FILTER_ALL;
6284 rc = efx_ptp_change_mode(efx, true, 0);
6285 if (!rc)
6286 rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false);
6287 if (rc)
6288 efx_ptp_change_mode(efx, false, 0);
6289 return rc;
6290 default:
6291 return -ERANGE;
6292 }
6293}
6294
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006295static int efx_ef10_get_phys_port_id(struct efx_nic *efx,
6296 struct netdev_phys_item_id *ppid)
6297{
6298 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6299
6300 if (!is_valid_ether_addr(nic_data->port_id))
6301 return -EOPNOTSUPP;
6302
6303 ppid->id_len = ETH_ALEN;
6304 memcpy(ppid->id, nic_data->port_id, ppid->id_len);
6305
6306 return 0;
6307}
6308
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006309static int efx_ef10_vlan_rx_add_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6310{
6311 if (proto != htons(ETH_P_8021Q))
6312 return -EINVAL;
6313
6314 return efx_ef10_add_vlan(efx, vid);
6315}
6316
6317static int efx_ef10_vlan_rx_kill_vid(struct efx_nic *efx, __be16 proto, u16 vid)
6318{
6319 if (proto != htons(ETH_P_8021Q))
6320 return -EINVAL;
6321
6322 return efx_ef10_del_vlan(efx, vid);
6323}
6324
Jon Coopere5fbd972017-02-08 16:52:10 +00006325/* We rely on the MCDI wiping out our TX rings if it made any changes to the
6326 * ports table, ensuring that any TSO descriptors that were made on a now-
6327 * removed tunnel port will be blown away and won't break things when we try
6328 * to transmit them using the new ports table.
6329 */
6330static int efx_ef10_set_udp_tnl_ports(struct efx_nic *efx, bool unloading)
6331{
6332 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6333 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LENMAX);
6334 MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_LEN);
6335 bool will_reset = false;
6336 size_t num_entries = 0;
6337 size_t inlen, outlen;
6338 size_t i;
6339 int rc;
6340 efx_dword_t flags_and_num_entries;
6341
6342 WARN_ON(!mutex_is_locked(&nic_data->udp_tunnels_lock));
6343
6344 nic_data->udp_tunnels_dirty = false;
6345
6346 if (!(nic_data->datapath_caps &
6347 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN))) {
Peter Dunning9c568fd2017-02-17 15:50:43 +00006348 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006349 return 0;
6350 }
6351
6352 BUILD_BUG_ON(ARRAY_SIZE(nic_data->udp_tunnels) >
6353 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES_MAXNUM);
6354
6355 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6356 if (nic_data->udp_tunnels[i].count &&
6357 nic_data->udp_tunnels[i].port) {
6358 efx_dword_t entry;
6359
6360 EFX_POPULATE_DWORD_2(entry,
6361 TUNNEL_ENCAP_UDP_PORT_ENTRY_UDP_PORT,
6362 ntohs(nic_data->udp_tunnels[i].port),
6363 TUNNEL_ENCAP_UDP_PORT_ENTRY_PROTOCOL,
6364 nic_data->udp_tunnels[i].type);
6365 *_MCDI_ARRAY_DWORD(inbuf,
6366 SET_TUNNEL_ENCAP_UDP_PORTS_IN_ENTRIES,
6367 num_entries++) = entry;
6368 }
6369 }
6370
6371 BUILD_BUG_ON((MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_OFST -
6372 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS_OFST) * 8 !=
6373 EFX_WORD_1_LBN);
6374 BUILD_BUG_ON(MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_NUM_ENTRIES_LEN * 8 !=
6375 EFX_WORD_1_WIDTH);
6376 EFX_POPULATE_DWORD_2(flags_and_num_entries,
6377 MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_UNLOADING,
6378 !!unloading,
6379 EFX_WORD_1, num_entries);
6380 *_MCDI_DWORD(inbuf, SET_TUNNEL_ENCAP_UDP_PORTS_IN_FLAGS) =
6381 flags_and_num_entries;
6382
6383 inlen = MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_IN_LEN(num_entries);
6384
6385 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS,
6386 inbuf, inlen, outbuf, sizeof(outbuf), &outlen);
6387 if (rc == -EIO) {
6388 /* Most likely the MC rebooted due to another function also
6389 * setting its tunnel port list. Mark the tunnel port list as
6390 * dirty, so it will be pushed upon coming up from the reboot.
6391 */
6392 nic_data->udp_tunnels_dirty = true;
6393 return 0;
6394 }
6395
6396 if (rc) {
6397 /* expected not available on unprivileged functions */
6398 if (rc != -EPERM)
6399 netif_warn(efx, drv, efx->net_dev,
6400 "Unable to set UDP tunnel ports; rc=%d.\n", rc);
6401 } else if (MCDI_DWORD(outbuf, SET_TUNNEL_ENCAP_UDP_PORTS_OUT_FLAGS) &
6402 (1 << MC_CMD_SET_TUNNEL_ENCAP_UDP_PORTS_OUT_RESETTING_LBN)) {
6403 netif_info(efx, drv, efx->net_dev,
6404 "Rebooting MC due to UDP tunnel port list change\n");
6405 will_reset = true;
6406 if (unloading)
6407 /* Delay for the MC reset to complete. This will make
6408 * unloading other functions a bit smoother. This is a
6409 * race, but the other unload will work whichever way
6410 * it goes, this just avoids an unnecessary error
6411 * message.
6412 */
6413 msleep(100);
6414 }
6415 if (!will_reset && !unloading) {
6416 /* The caller will have detached, relying on the MC reset to
6417 * trigger a re-attach. Since there won't be an MC reset, we
6418 * have to do the attach ourselves.
6419 */
Peter Dunning9c568fd2017-02-17 15:50:43 +00006420 efx_device_attach_if_not_resetting(efx);
Jon Coopere5fbd972017-02-08 16:52:10 +00006421 }
6422
6423 return rc;
6424}
6425
6426static int efx_ef10_udp_tnl_push_ports(struct efx_nic *efx)
6427{
6428 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6429 int rc = 0;
6430
6431 mutex_lock(&nic_data->udp_tunnels_lock);
6432 if (nic_data->udp_tunnels_dirty) {
6433 /* Make sure all TX are stopped while we modify the table, else
6434 * we might race against an efx_features_check().
6435 */
6436 efx_device_detach_sync(efx);
6437 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6438 }
6439 mutex_unlock(&nic_data->udp_tunnels_lock);
6440 return rc;
6441}
6442
6443static struct efx_udp_tunnel *__efx_ef10_udp_tnl_lookup_port(struct efx_nic *efx,
6444 __be16 port)
6445{
6446 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6447 size_t i;
6448
6449 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i) {
6450 if (!nic_data->udp_tunnels[i].count)
6451 continue;
6452 if (nic_data->udp_tunnels[i].port == port)
6453 return &nic_data->udp_tunnels[i];
6454 }
6455 return NULL;
6456}
6457
6458static int efx_ef10_udp_tnl_add_port(struct efx_nic *efx,
6459 struct efx_udp_tunnel tnl)
6460{
6461 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6462 struct efx_udp_tunnel *match;
6463 char typebuf[8];
6464 size_t i;
6465 int rc;
6466
6467 if (!(nic_data->datapath_caps &
6468 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6469 return 0;
6470
6471 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6472 netif_dbg(efx, drv, efx->net_dev, "Adding UDP tunnel (%s) port %d\n",
6473 typebuf, ntohs(tnl.port));
6474
6475 mutex_lock(&nic_data->udp_tunnels_lock);
6476 /* Make sure all TX are stopped while we add to the table, else we
6477 * might race against an efx_features_check().
6478 */
6479 efx_device_detach_sync(efx);
6480
6481 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6482 if (match != NULL) {
6483 if (match->type == tnl.type) {
6484 netif_dbg(efx, drv, efx->net_dev,
6485 "Referencing existing tunnel entry\n");
6486 match->count++;
6487 /* No need to cause an MCDI update */
6488 rc = 0;
6489 goto unlock_out;
6490 }
6491 efx_get_udp_tunnel_type_name(match->type,
6492 typebuf, sizeof(typebuf));
6493 netif_dbg(efx, drv, efx->net_dev,
6494 "UDP port %d is already in use by %s\n",
6495 ntohs(tnl.port), typebuf);
6496 rc = -EEXIST;
6497 goto unlock_out;
6498 }
6499
6500 for (i = 0; i < ARRAY_SIZE(nic_data->udp_tunnels); ++i)
6501 if (!nic_data->udp_tunnels[i].count) {
6502 nic_data->udp_tunnels[i] = tnl;
6503 nic_data->udp_tunnels[i].count = 1;
6504 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6505 goto unlock_out;
6506 }
6507
6508 netif_dbg(efx, drv, efx->net_dev,
6509 "Unable to add UDP tunnel (%s) port %d; insufficient resources.\n",
6510 typebuf, ntohs(tnl.port));
6511
6512 rc = -ENOMEM;
6513
6514unlock_out:
6515 mutex_unlock(&nic_data->udp_tunnels_lock);
6516 return rc;
6517}
6518
6519/* Called under the TX lock with the TX queue running, hence no-one can be
6520 * in the middle of updating the UDP tunnels table. However, they could
6521 * have tried and failed the MCDI, in which case they'll have set the dirty
6522 * flag before dropping their locks.
6523 */
6524static bool efx_ef10_udp_tnl_has_port(struct efx_nic *efx, __be16 port)
6525{
6526 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6527
6528 if (!(nic_data->datapath_caps &
6529 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6530 return false;
6531
6532 if (nic_data->udp_tunnels_dirty)
6533 /* SW table may not match HW state, so just assume we can't
6534 * use any UDP tunnel offloads.
6535 */
6536 return false;
6537
6538 return __efx_ef10_udp_tnl_lookup_port(efx, port) != NULL;
6539}
6540
6541static int efx_ef10_udp_tnl_del_port(struct efx_nic *efx,
6542 struct efx_udp_tunnel tnl)
6543{
6544 struct efx_ef10_nic_data *nic_data = efx->nic_data;
6545 struct efx_udp_tunnel *match;
6546 char typebuf[8];
6547 int rc;
6548
6549 if (!(nic_data->datapath_caps &
6550 (1 << MC_CMD_GET_CAPABILITIES_OUT_VXLAN_NVGRE_LBN)))
6551 return 0;
6552
6553 efx_get_udp_tunnel_type_name(tnl.type, typebuf, sizeof(typebuf));
6554 netif_dbg(efx, drv, efx->net_dev, "Removing UDP tunnel (%s) port %d\n",
6555 typebuf, ntohs(tnl.port));
6556
6557 mutex_lock(&nic_data->udp_tunnels_lock);
6558 /* Make sure all TX are stopped while we remove from the table, else we
6559 * might race against an efx_features_check().
6560 */
6561 efx_device_detach_sync(efx);
6562
6563 match = __efx_ef10_udp_tnl_lookup_port(efx, tnl.port);
6564 if (match != NULL) {
6565 if (match->type == tnl.type) {
6566 if (--match->count) {
6567 /* Port is still in use, so nothing to do */
6568 netif_dbg(efx, drv, efx->net_dev,
6569 "UDP tunnel port %d remains active\n",
6570 ntohs(tnl.port));
6571 rc = 0;
6572 goto out_unlock;
6573 }
6574 rc = efx_ef10_set_udp_tnl_ports(efx, false);
6575 goto out_unlock;
6576 }
6577 efx_get_udp_tunnel_type_name(match->type,
6578 typebuf, sizeof(typebuf));
6579 netif_warn(efx, drv, efx->net_dev,
6580 "UDP port %d is actually in use by %s, not removing\n",
6581 ntohs(tnl.port), typebuf);
6582 }
6583 rc = -ENOENT;
6584
6585out_unlock:
6586 mutex_unlock(&nic_data->udp_tunnels_lock);
6587 return rc;
6588}
6589
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006590#define EF10_OFFLOAD_FEATURES \
6591 (NETIF_F_IP_CSUM | \
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006592 NETIF_F_HW_VLAN_CTAG_FILTER | \
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006593 NETIF_F_IPV6_CSUM | \
6594 NETIF_F_RXHASH | \
6595 NETIF_F_NTUPLE)
6596
Shradha Shah02246a72015-05-06 00:58:14 +01006597const struct efx_nic_type efx_hunt_a0_vf_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006598 .is_vf = true,
Edward Cree03714bb2017-12-18 16:55:50 +00006599 .mem_bar = efx_ef10_vf_mem_bar,
Ben Hutchings8127d662013-08-29 19:19:29 +01006600 .mem_map_size = efx_ef10_mem_map_size,
Shradha Shah02246a72015-05-06 00:58:14 +01006601 .probe = efx_ef10_probe_vf,
6602 .remove = efx_ef10_remove,
6603 .dimension_resources = efx_ef10_dimension_resources,
6604 .init = efx_ef10_init_nic,
6605 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006606 .map_reset_reason = efx_ef10_map_reset_reason,
Shradha Shah02246a72015-05-06 00:58:14 +01006607 .map_reset_flags = efx_ef10_map_reset_flags,
6608 .reset = efx_ef10_reset,
6609 .probe_port = efx_mcdi_port_probe,
6610 .remove_port = efx_mcdi_port_remove,
6611 .fini_dmaq = efx_ef10_fini_dmaq,
6612 .prepare_flr = efx_ef10_prepare_flr,
6613 .finish_flr = efx_port_dummy_op_void,
6614 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006615 .update_stats = efx_ef10_update_stats_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006616 .start_stats = efx_port_dummy_op_void,
6617 .pull_stats = efx_port_dummy_op_void,
6618 .stop_stats = efx_port_dummy_op_void,
6619 .set_id_led = efx_mcdi_set_id_led,
6620 .push_irq_moderation = efx_ef10_push_irq_moderation,
Shradha Shah862f8942015-05-20 11:08:56 +01006621 .reconfigure_mac = efx_ef10_mac_reconfigure_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006622 .check_mac_fault = efx_mcdi_mac_check_fault,
6623 .reconfigure_port = efx_mcdi_port_reconfigure,
6624 .get_wol = efx_ef10_get_wol_vf,
6625 .set_wol = efx_ef10_set_wol_vf,
6626 .resume_wol = efx_port_dummy_op_void,
6627 .mcdi_request = efx_ef10_mcdi_request,
6628 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6629 .mcdi_read_response = efx_ef10_mcdi_read_response,
6630 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006631 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Shradha Shah02246a72015-05-06 00:58:14 +01006632 .irq_enable_master = efx_port_dummy_op_void,
6633 .irq_test_generate = efx_ef10_irq_test_generate,
6634 .irq_disable_non_ev = efx_port_dummy_op_void,
6635 .irq_handle_msi = efx_ef10_msi_interrupt,
6636 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6637 .tx_probe = efx_ef10_tx_probe,
6638 .tx_init = efx_ef10_tx_init,
6639 .tx_remove = efx_ef10_tx_remove,
6640 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006641 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006642 .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006643 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Shradha Shah02246a72015-05-06 00:58:14 +01006644 .rx_probe = efx_ef10_rx_probe,
6645 .rx_init = efx_ef10_rx_init,
6646 .rx_remove = efx_ef10_rx_remove,
6647 .rx_write = efx_ef10_rx_write,
6648 .rx_defer_refill = efx_ef10_rx_defer_refill,
6649 .ev_probe = efx_ef10_ev_probe,
6650 .ev_init = efx_ef10_ev_init,
6651 .ev_fini = efx_ef10_ev_fini,
6652 .ev_remove = efx_ef10_ev_remove,
6653 .ev_process = efx_ef10_ev_process,
6654 .ev_read_ack = efx_ef10_ev_read_ack,
6655 .ev_test_generate = efx_ef10_ev_test_generate,
6656 .filter_table_probe = efx_ef10_filter_table_probe,
6657 .filter_table_restore = efx_ef10_filter_table_restore,
6658 .filter_table_remove = efx_ef10_filter_table_remove,
6659 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6660 .filter_insert = efx_ef10_filter_insert,
6661 .filter_remove_safe = efx_ef10_filter_remove_safe,
6662 .filter_get_safe = efx_ef10_filter_get_safe,
6663 .filter_clear_rx = efx_ef10_filter_clear_rx,
6664 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6665 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6666 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6667#ifdef CONFIG_RFS_ACCEL
6668 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6669 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6670#endif
6671#ifdef CONFIG_SFC_MTD
6672 .mtd_probe = efx_port_dummy_op_int,
6673#endif
6674 .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf,
6675 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006676 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6677 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Shradha Shah02246a72015-05-06 00:58:14 +01006678#ifdef CONFIG_SFC_SRIOV
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006679 .vswitching_probe = efx_ef10_vswitching_probe_vf,
6680 .vswitching_restore = efx_ef10_vswitching_restore_vf,
6681 .vswitching_remove = efx_ef10_vswitching_remove_vf,
Shradha Shah02246a72015-05-06 00:58:14 +01006682#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006683 .get_mac_address = efx_ef10_get_mac_address_vf,
Shradha Shah910c8782015-05-20 11:12:48 +01006684 .set_mac_address = efx_ef10_set_mac_address,
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006685
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006686 .get_phys_port_id = efx_ef10_get_phys_port_id,
Shradha Shah02246a72015-05-06 00:58:14 +01006687 .revision = EFX_REV_HUNT_A0,
6688 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6689 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6690 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
6691 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
6692 .can_rx_scatter = true,
6693 .always_rx_scatter = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006694 .min_interrupt_mode = EFX_INT_MODE_MSIX,
Shradha Shah02246a72015-05-06 00:58:14 +01006695 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6696 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006697 .offload_features = EF10_OFFLOAD_FEATURES,
Shradha Shah02246a72015-05-06 00:58:14 +01006698 .mcdi_max_ver = 2,
6699 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
6700 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6701 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006702 .rx_hash_key_size = 40,
Shradha Shah02246a72015-05-06 00:58:14 +01006703};
6704
6705const struct efx_nic_type efx_hunt_a0_nic_type = {
Shradha Shah6f7f8aa2015-05-06 01:00:07 +01006706 .is_vf = false,
Edward Cree03714bb2017-12-18 16:55:50 +00006707 .mem_bar = efx_ef10_pf_mem_bar,
Shradha Shah02246a72015-05-06 00:58:14 +01006708 .mem_map_size = efx_ef10_mem_map_size,
6709 .probe = efx_ef10_probe_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006710 .remove = efx_ef10_remove,
6711 .dimension_resources = efx_ef10_dimension_resources,
6712 .init = efx_ef10_init_nic,
6713 .fini = efx_port_dummy_op_void,
Jon Cooper087e9022015-05-20 11:11:35 +01006714 .map_reset_reason = efx_ef10_map_reset_reason,
Ben Hutchings8127d662013-08-29 19:19:29 +01006715 .map_reset_flags = efx_ef10_map_reset_flags,
Jon Cooper3e336262014-01-17 19:48:06 +00006716 .reset = efx_ef10_reset,
Ben Hutchings8127d662013-08-29 19:19:29 +01006717 .probe_port = efx_mcdi_port_probe,
6718 .remove_port = efx_mcdi_port_remove,
6719 .fini_dmaq = efx_ef10_fini_dmaq,
Edward Creee2835462014-04-16 19:27:48 +01006720 .prepare_flr = efx_ef10_prepare_flr,
6721 .finish_flr = efx_port_dummy_op_void,
Ben Hutchings8127d662013-08-29 19:19:29 +01006722 .describe_stats = efx_ef10_describe_stats,
Daniel Pieczkod7788192015-06-02 11:39:20 +01006723 .update_stats = efx_ef10_update_stats_pf,
Ben Hutchings8127d662013-08-29 19:19:29 +01006724 .start_stats = efx_mcdi_mac_start_stats,
Jon Cooperf8f3b5a2013-09-30 17:36:50 +01006725 .pull_stats = efx_mcdi_mac_pull_stats,
Ben Hutchings8127d662013-08-29 19:19:29 +01006726 .stop_stats = efx_mcdi_mac_stop_stats,
6727 .set_id_led = efx_mcdi_set_id_led,
6728 .push_irq_moderation = efx_ef10_push_irq_moderation,
6729 .reconfigure_mac = efx_ef10_mac_reconfigure,
6730 .check_mac_fault = efx_mcdi_mac_check_fault,
6731 .reconfigure_port = efx_mcdi_port_reconfigure,
6732 .get_wol = efx_ef10_get_wol,
6733 .set_wol = efx_ef10_set_wol,
6734 .resume_wol = efx_port_dummy_op_void,
Jon Cooper74cd60a2013-09-16 14:18:51 +01006735 .test_chip = efx_ef10_test_chip,
Ben Hutchings8127d662013-08-29 19:19:29 +01006736 .test_nvram = efx_mcdi_nvram_test_all,
6737 .mcdi_request = efx_ef10_mcdi_request,
6738 .mcdi_poll_response = efx_ef10_mcdi_poll_response,
6739 .mcdi_read_response = efx_ef10_mcdi_read_response,
6740 .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot,
Daniel Pieczkoc577e592015-10-09 10:40:35 +01006741 .mcdi_reboot_detected = efx_ef10_mcdi_reboot_detected,
Ben Hutchings8127d662013-08-29 19:19:29 +01006742 .irq_enable_master = efx_port_dummy_op_void,
6743 .irq_test_generate = efx_ef10_irq_test_generate,
6744 .irq_disable_non_ev = efx_port_dummy_op_void,
6745 .irq_handle_msi = efx_ef10_msi_interrupt,
6746 .irq_handle_legacy = efx_ef10_legacy_interrupt,
6747 .tx_probe = efx_ef10_tx_probe,
6748 .tx_init = efx_ef10_tx_init,
6749 .tx_remove = efx_ef10_tx_remove,
6750 .tx_write = efx_ef10_tx_write,
Bert Kenwarde9117e52016-11-17 10:51:54 +00006751 .tx_limit_len = efx_ef10_tx_limit_len,
Jon Cooper267c0152015-05-06 00:59:38 +01006752 .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config,
Edward Creea707d182017-01-17 12:02:12 +00006753 .rx_pull_rss_config = efx_ef10_rx_pull_rss_config,
Ben Hutchings8127d662013-08-29 19:19:29 +01006754 .rx_probe = efx_ef10_rx_probe,
6755 .rx_init = efx_ef10_rx_init,
6756 .rx_remove = efx_ef10_rx_remove,
6757 .rx_write = efx_ef10_rx_write,
6758 .rx_defer_refill = efx_ef10_rx_defer_refill,
6759 .ev_probe = efx_ef10_ev_probe,
6760 .ev_init = efx_ef10_ev_init,
6761 .ev_fini = efx_ef10_ev_fini,
6762 .ev_remove = efx_ef10_ev_remove,
6763 .ev_process = efx_ef10_ev_process,
6764 .ev_read_ack = efx_ef10_ev_read_ack,
6765 .ev_test_generate = efx_ef10_ev_test_generate,
6766 .filter_table_probe = efx_ef10_filter_table_probe,
6767 .filter_table_restore = efx_ef10_filter_table_restore,
6768 .filter_table_remove = efx_ef10_filter_table_remove,
6769 .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter,
6770 .filter_insert = efx_ef10_filter_insert,
6771 .filter_remove_safe = efx_ef10_filter_remove_safe,
6772 .filter_get_safe = efx_ef10_filter_get_safe,
6773 .filter_clear_rx = efx_ef10_filter_clear_rx,
6774 .filter_count_rx_used = efx_ef10_filter_count_rx_used,
6775 .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit,
6776 .filter_get_rx_ids = efx_ef10_filter_get_rx_ids,
6777#ifdef CONFIG_RFS_ACCEL
6778 .filter_rfs_insert = efx_ef10_filter_rfs_insert,
6779 .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one,
6780#endif
6781#ifdef CONFIG_SFC_MTD
6782 .mtd_probe = efx_ef10_mtd_probe,
6783 .mtd_rename = efx_mcdi_mtd_rename,
6784 .mtd_read = efx_mcdi_mtd_read,
6785 .mtd_erase = efx_mcdi_mtd_erase,
6786 .mtd_write = efx_mcdi_mtd_write,
6787 .mtd_sync = efx_mcdi_mtd_sync,
6788#endif
6789 .ptp_write_host_time = efx_ef10_ptp_write_host_time,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006790 .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events,
6791 .ptp_set_ts_config = efx_ef10_ptp_set_ts_config,
Andrew Rybchenko4a53ea82016-06-15 17:48:32 +01006792 .vlan_rx_add_vid = efx_ef10_vlan_rx_add_vid,
6793 .vlan_rx_kill_vid = efx_ef10_vlan_rx_kill_vid,
Jon Coopere5fbd972017-02-08 16:52:10 +00006794 .udp_tnl_push_ports = efx_ef10_udp_tnl_push_ports,
6795 .udp_tnl_add_port = efx_ef10_udp_tnl_add_port,
6796 .udp_tnl_has_port = efx_ef10_udp_tnl_has_port,
6797 .udp_tnl_del_port = efx_ef10_udp_tnl_del_port,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006798#ifdef CONFIG_SFC_SRIOV
Shradha Shah834e23d2015-05-06 00:55:58 +01006799 .sriov_configure = efx_ef10_sriov_configure,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006800 .sriov_init = efx_ef10_sriov_init,
6801 .sriov_fini = efx_ef10_sriov_fini,
Shradha Shahd98a4ff2014-11-05 12:16:46 +00006802 .sriov_wanted = efx_ef10_sriov_wanted,
6803 .sriov_reset = efx_ef10_sriov_reset,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006804 .sriov_flr = efx_ef10_sriov_flr,
6805 .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac,
6806 .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan,
6807 .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk,
6808 .sriov_get_vf_config = efx_ef10_sriov_get_vf_config,
Edward Cree4392dc62015-05-20 11:12:13 +01006809 .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state,
Shradha Shah7b8c7b52015-05-06 00:58:54 +01006810 .vswitching_probe = efx_ef10_vswitching_probe_pf,
6811 .vswitching_restore = efx_ef10_vswitching_restore_pf,
6812 .vswitching_remove = efx_ef10_vswitching_remove_pf,
Shradha Shah7fa8d542015-05-06 00:55:13 +01006813#endif
Daniel Pieczko0d5e0fb2015-05-20 11:10:20 +01006814 .get_mac_address = efx_ef10_get_mac_address_pf,
Shradha Shah910c8782015-05-20 11:12:48 +01006815 .set_mac_address = efx_ef10_set_mac_address,
Edward Cree46d1efd2016-11-17 10:52:36 +00006816 .tso_versions = efx_ef10_tso_versions,
Ben Hutchings8127d662013-08-29 19:19:29 +01006817
Bert Kenward08a7b29b2017-01-10 16:23:33 +00006818 .get_phys_port_id = efx_ef10_get_phys_port_id,
Ben Hutchings8127d662013-08-29 19:19:29 +01006819 .revision = EFX_REV_HUNT_A0,
6820 .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH),
6821 .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE,
6822 .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006823 .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST,
Ben Hutchings8127d662013-08-29 19:19:29 +01006824 .can_rx_scatter = true,
6825 .always_rx_scatter = true,
Edward Creede1deff2017-01-13 21:20:14 +00006826 .option_descriptors = true,
Andrew Rybchenko6f9f6ec2017-02-13 14:57:39 +00006827 .min_interrupt_mode = EFX_INT_MODE_LEGACY,
Ben Hutchings8127d662013-08-29 19:19:29 +01006828 .max_interrupt_mode = EFX_INT_MODE_MSIX,
6829 .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH,
Andrew Rybchenko100a9db2016-06-15 17:42:26 +01006830 .offload_features = EF10_OFFLOAD_FEATURES,
Ben Hutchings8127d662013-08-29 19:19:29 +01006831 .mcdi_max_ver = 2,
6832 .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS,
Jon Cooperbd9a2652013-11-18 12:54:41 +00006833 .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE |
6834 1 << HWTSTAMP_FILTER_ALL,
Edward Creef74d1992017-01-17 12:01:53 +00006835 .rx_hash_key_size = 40,
Ben Hutchings8127d662013-08-29 19:19:29 +01006836};